Files
meteor/lib/util/internal/getRootPath.js
Dominik Ferber 650d61efd7 refactor(internal): Detect project based on filename instead of process.cwd
Detection of the Meteor project through process.cwd() fails when used in Atom Editor. Use filename i
2015-10-04 19:41:47 +02:00

28 lines
650 B
JavaScript

import find from 'lodash.find'
import isMeteorProject from './isMeteorProject'
var findOneUpwards = require('./findOneUpwards')
function hasFile (parent, filename) {
return filename.substr(0, parent.length) === parent
}
// cache for root paths
const rootPaths = []
export default function (filename) {
// check whether the project root is already known or not
let rootPath = find(rootPaths, function (currentPath) {
return hasFile(currentPath, filename)
})
if (!rootPath) {
// project root is unkown. search for it
rootPath = findOneUpwards(filename, isMeteorProject)
rootPaths.push(rootPath)
}
return rootPath
}