Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function importFromGit({
db,
repo,
branch = 'master',
tmpDir = `${dir}/tmp`,
checkout,
}) {
if (!(await fs.exists(dir))) {
await fs.mkdir(dir);
}
console.log(chalk.yellow('Starting mongodb import'));
console.log(chalk.cyan('Cleaning up (in case of errors)'));
await run(`rm -rf ${tmpDir}`);
console.log(chalk.cyan('Cloning backup repository'));
try {
await run(`eval \`ssh-agent -s\` &&
ssh-add ~/.ssh/id_rsa`);
} catch (e) {} // eslint-disable-line no-empty
async function main(): Promise {
// Linting sub-projects requires the latest Sucrase types, so require a build first.
if (!(await exists("./dist"))) {
console.log("Must run build before lint, running build...");
await run("yarn build");
}
await Promise.all([
checkSucrase(),
checkProject("./integrations/gulp-plugin"),
checkProject("./integrations/jest-plugin"),
checkProject("./integrations/webpack-loader"),
checkProject("./integrations/webpack-object-rest-spread-plugin"),
checkProject("./website"),
]);
}
if (result.error) {
return await renderScriptError(ctx, page, result.error);
} else if (result.compilationError) {
return await renderScriptError(ctx, page, result.compilationError);
}
} else {
const p = join(
this.dir,
this.dist,
'bundles',
'page',
`/${page.replace(/^\//i, '') || 'index'}.js`
);
// [production] If the page is not exists, we need to send a proper Next.js style 404
// Otherwise, it'll affect the multi-zones feature.
if (!await fsAsync.exists(p)) {
return await renderScriptError(ctx, page, { code: 'ENOENT' });
}
}
await renderScript(ctx, page, this.renderOpts);
},
};
async function replaceHostInFile(pkg, filepath, binaryMirror, options) {
const exists = await fs.exists(filepath);
if (!exists) {
return;
}
let content = await fs.readFile(filepath, 'utf8');
let replaceHostMap;
// support RegExp string
if (binaryMirror.replaceHostRegExpMap) {
replaceHostMap = binaryMirror.replaceHostRegExpMap;
for (const replaceHost in replaceHostMap) {
const replaceAllRE = new RegExp(replaceHost, 'g');
const targetHost = replaceHostMap[replaceHost];
debug('replace %j(%s) => %s', replaceHost, replaceAllRE, targetHost);
content = content.replace(replaceAllRE, targetHost);
}
} else {
async function resolveBinary(binaryName) {
let nodeModulesPath = `./node_modules/.bin/${binaryName}`;
if (await exists(nodeModulesPath)) {
return nodeModulesPath;
} else {
try {
await exec(`which ${binaryName}`);
return binaryName;
} catch (e) {
console.log(`${binaryName} binary not found on the PATH or in node_modules.`);
let rl = readline.createInterface(process.stdin, process.stdout);
let answer = await rl.question(`Run "npm install -g ${binaryName}"? [Y/n] `);
rl.close();
if (answer.toLowerCase().startsWith('n')) {
throw new CLIError(`${binaryName} must be installed.`);
}
console.log(`Installing ${binaryName} globally...`);
await execLive(`npm install -g ${binaryName}`);
console.log(`Successfully installed ${binaryName}\n`);
run(function* () {
let projects = [];
if (yield fs.exists(setting)) {
const body = yield fs.readFile(setting, 'utf8');
projects = yield parseCson(body);
console.log('Read %s', setting);
}
if (checkPath(cwd, projects)) {
console.log('%s exist', cwd);
return;
}
projects.push({
title,
paths: [ cwd ],
});
const body = yield stringifyCson(projects);
gulp.task('build:workspace:npm', () => {
return fs.exists(npmPath)
.then(exists => {
if (exists) return
gutil.log(`${npmPath} not found, fetching`)
return http.get(`https://github.com/npm/npm/archive/v${config.npmVersion}.tar.gz`)
.then(res => {
return new Promise((ok, fail) => {
let gunzip = zlib.createGunzip().on('error', fail)
let extractor = tar.Extract({path: './tmp/heroku/lib'}).on('error', fail).on('end', ok)
res.pipe(gunzip).pipe(extractor)
})
})
})
})
this.stack.push(async ctx => {
if (!await fs.exists(file)) {
throw new Error(`The file "${file}" does not exist. Make sure that you set an absolute path or a relative path to the root of your project`);
}
return new Promise((resolve, reject) => {
ctx.res.sendFile(file, opts, err => err ? reject(err) : resolve());
});
});
async function closestModule(dir, name) {
const fpath = path.join(dir, 'node_modules', name)
if (await exists(fpath)) {
return fpath
} else if (dir.includes('/node_modules/')) {
while (path.basename(dir) !== 'node_modules') {
dir = path.resolve(dir, '..')
}
return await closestModule(path.resolve(dir, '..'), name)
} else {
throw new Error(`Unable to find module '${name}' by traversing ${dir}`)
}
}
async function resolvePath(names, root) {
for (const name of names) {
for (const dir of root) {
const filename = path.join(dir, name);
if (await fs.exists(filename)) {
if (inpath(dir, filename)) {
return filename;
}
}
}
}
}