Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
name: string,
target: string,
packageDir?: string,
): Promise {
if (!target) {
throw new Error(`Error in getPackage: Please provide a target`)
}
packageDir =
packageDir ||
resolvePkg(name, { cwd: __dirname }) ||
resolvePkg(name, { cwd: target })
debug({ packageDir })
if (!packageDir) {
const pkg = await readPkgUp({
cwd: target,
})
if (pkg && pkg.packageJson.name === name) {
packageDir = path.dirname(pkg.path)
}
}
if (!packageDir) {
throw new Error(
`Error in getPackage: Could not resolve package ${name} from ${__dirname}`,
)
}
const tmpDir = tempy.directory() // thanks Sindre
const archivePath = path.join(tmpDir, `package.tgz`)
// pack into a .tgz in a tmp dir
export function checkUpdate (): void {
readPkgUp({ cwd: __dirname })
.then(pack => {
if (!pack) {
throw new Error('package.json not found')
}
const pkg = pack.package
// 1 week
const updateCheckInterval = 1000 * 60 * 60 * 24 * 7
const notifier = new UpdateNotifier({
pkg,
updateCheckInterval,
})
notifier.notify()
return null
})
async addModule(contextPath, modulePath, {env}) {
const isModuleExcluded = this.exclude.includes(modulePath) ||
(this.only && !this.only.includes(modulePath));
if (isModuleExcluded) {
return false;
}
const moduleName = modulePath.match(moduleRegex)[1];
const {pkg: {version, peerDependencies}} = await readPkgUp({cwd: resolvePkg(moduleName, {cwd: contextPath})});
const isModuleAlreadyLoaded = Boolean(this.modulesFromCdn[modulePath]);
if (isModuleAlreadyLoaded) {
const isSameVersion = this.modulesFromCdn[modulePath].version === version;
if (isSameVersion) {
return this.modulesFromCdn[modulePath].var;
}
return false;
}
const cdnConfig = await this.resolver(modulePath, version, {env});
if (cdnConfig == null) {
if (this.verbose) {
console.log(`❌ '${modulePath}' couldn't be found, please add it to https://github.com/mastilver/module-to-cdn/blob/master/modules.json`);
async function printDependenciesVersion() {
const { pkg } = await readPkgUp({ cwd: baseFolder });
for (let [key, value] of Object.entries(pkg.dependencies)) {
console.log(` - ${key}: ${value}`);
}
}
export async function _flowSemverForRootPath(
rootPath: string,
reporter: Reporter,
): Promise {
const configDir = await flowConfigCache.getConfigDir(rootPath);
reporter.info('Determining the version of flow for your project...');
if (!configDir) {
reporter.error(
'No valid .flowconfig was found. Use `flow init` in the root of your project to create one.',
);
return null;
}
const configPath = path.join(configDir, '.flowconfig');
const {pkg} = await readPkgUp({cwd: rootPath});
let packageFlowVersion;
const depRange = idx(pkg, _ => _.dependencies['flow-bin']);
const devDepRange = idx(pkg, _ => _.devDependencies['flow-bin']);
if (depRange && semver.validRange(depRange)) {
packageFlowVersion = depRange;
} else if (devDepRange && semver.validRange(devDepRange)) {
packageFlowVersion = devDepRange;
}
if (packageFlowVersion) {
reporter.info(
`Found flow version requirement ${packageFlowVersion} in your package.json`,
);
}
let configFlowVersion;
export async function _flowSemverForRootPath(rootPath: string, reporter: Reporter): Promise {
const configDir = await flowConfigCache.getConfigDir(rootPath);
reporter.info('Determining the version of flow for your project...');
if (!configDir) {
reporter.error('No valid .flowconfig was found. Use `flow init` in the root of your project to create one.');
return;
}
const configPath = path.join(configDir, '.flowconfig');
const {pkg, path: pkgPath} = await readPkgUp({cwd: rootPath});
let packageFlowVersion;
const depRange = idx(pkg, _ => _.dependencies['flow-bin']);
const devDepRange = idx(pkg, _ => _.devDependencies['flow-bin']);
if (depRange && semver.validRange(depRange)) {
packageFlowVersion = depRange;
} else if (devDepRange && semver.validRange(devDepRange)) {
packageFlowVersion = devDepRange;
}
if (packageFlowVersion) {
reporter.info(`Found flow version requirement ${packageFlowVersion} in your package.json`);
}
let configFlowVersion;
if (configDir) {
try {