Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'pkg-up' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
// @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;
},
export default async function build (name, env = process.env, forceDocker) {
let root = dirname(await pkgUp())
if (!name) name = basename(root)
let bin = forceDocker ? 'docker' : await detectDocker()
let customDocker = join(root, 'Dockerfile')
let localDocker = join(CONFIGS, 'Dockerfile')
let customIgnore = join(root, '.dockerignore')
let localIgnore = join(CONFIGS, '.dockerignore')
let nginxPath = join(root, 'nginx.conf')
let dockerfile = localDocker
if (existsSync(customDocker)) dockerfile = customDocker
let args = ['build', '-f', dockerfile, '-t', name, '.']
debugCmd(bin + ' ' + args.join(' '))
let text = 'Building Docker image'