Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// @flow
import pkgUp from 'pkg-up';
const boltPkgPath = pkgUp.sync(__dirname);
// $FlowFixMe
const boltPkg = require(boltPkgPath);
export const DEPENDENCY_TYPES = [
'dependencies',
'devDependencies',
'peerDependencies',
'bundledDependencies',
'optionalDependencies'
];
export const DEPENDENCY_TYPE_FLAGS_MAP = {
dev: 'devDependencies',
peer: 'peerDependencies',
optional: 'optionalDependencies',
function getProjectId(rootDir: string) {
const pkgPath = pkgUp.sync({ cwd: rootDir });
if (!pkgPath) {
return rootDir.split('/').pop();
}
const pkg = require(pkgPath);
return pkg.name || '';
}
module.exports = (grunt, options = {}) => {
const pattern = arrify(options.pattern || ['grunt-*', '@*/grunt-*']);
const scope = arrify(options.scope || ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']);
let cwd = process.cwd();
let config = options.config || pkgUp.sync();
if (config === null) {
grunt.fail.fatal('package.json not found. Make sure to create a package.json and install dependencies before you run Grunt.');
}
if (typeof config === 'string') {
const configPath = path.resolve(config);
cwd = path.dirname(configPath);
config = require(configPath);
}
pattern.push('!grunt', '!grunt-cli');
const names = scope.reduce((result, property) => {
const dependencies = config[property] || [];
return result.concat(Array.isArray(dependencies) ? dependencies : Object.keys(dependencies));
export function getPkgPath(filePath) {
const dir = dirname(filePath);
if (dir in pkgPathCache) return pkgPathCache[dir];
pkgPathCache[dir] = pkgUp.sync({ cwd: filePath });
return pkgPathCache[dir];
}
packagejson: startPath => pkgUp.sync({ cwd: startPath }),
};
get root(): string {
return dirname(pkgUpSync(this.app.project.root)!);
}
export function getRootDir(cwd: string = process.cwd()): string {
if (rootDir) return rootDir;
const rootPkgJSON = pkgUp.sync({ cwd });
if (!rootPkgJSON) {
throw new Error('Unable to find root directory, run in the root of the repo');
}
if (_getRootInfo(rootPkgJSON) != null) {
rootDir = path.dirname(rootPkgJSON);
return rootDir;
}
const upOne = path.join(path.dirname(rootPkgJSON), '..');
if (!fse.existsSync(upOne) || !fse.statSync(upOne).isDirectory()) {
throw new Error('Unable to find root directory');
}
return getRootDir(upOne);
}
function stop() {
found = pkgUp.sync(startDir);
if (found && !closest) {
closest = found;
}
dir = found ? path.dirname(found) : found;
var stop = !dir || !isDappCmd(embarkJson.cmd);
if (!stop) {
startDir = path.join(dir, '..');
}
return stop;
}
while (!stop()) {
matcher(file) {
const pkgPath = pkgUp.sync(file);
const root = path.dirname(pkgPath);
const pkg = readJSON(pkgPath);
const matches = root !== process.cwd()
&& pkg.name.startsWith('@financial-times/x-')
&& pkg.name !== '@financial-times/x-build';
return !!matches;
},