mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Detection of the Meteor project through process.cwd() fails when used in Atom Editor. Use filename i
28 lines
650 B
JavaScript
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
|
|
}
|