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 getLatestRnDiffPurgeVersion(
name: string,
eTag?: string,
): Promise {
const options = {
// https://developer.github.com/v3/#user-agent-required
headers: {'User-Agent': 'React-Native-CLI'} as Headers,
};
if (eTag) {
options.headers['If-None-Match'] = eTag;
}
const {data, status, headers} = await fetch(
'https://api.github.com/repos/react-native-community/rn-diff-purge/tags',
options,
);
// Remote is newer.
if (status === 200) {
const body: Array = data;
const latestVersion = body[0].name.substring(8);
const eTagHeader = headers.get('eTag');
// Update cache only if newer release is stable.
if (!semver.prerelease(latestVersion) && eTagHeader) {
logger.debug(`Saving ${eTagHeader} to cache`);
cacheManager.set(name, 'eTag', eTagHeader);
cacheManager.set(name, 'latestVersion', latestVersion);
}
e => `--exclude=${path.join(relativePathFromRoot, e)}`,
);
await execa('git', [
'apply',
// According to git documentation, `--binary` flag is turned on by
// default. However it's necessary when running `git apply --check` to
// actually accept binary files, maybe a bug in git?
'--binary',
'--check',
tmpPatchFile,
...excludes,
'-p2',
'--3way',
`--directory=${relativePathFromRoot}`,
]);
logger.info('Applying diff...');
} catch (error) {
const errorLines: Array = error.stderr.split('\n');
filesThatDontExist = [
...errorLines
.filter(x => x.includes('does not exist in index'))
.map(x => x.replace(/^error: (.*): does not exist in index$/, '$1')),
].filter(Boolean);
filesThatFailedToApply = errorLines
.filter(x => x.includes('patch does not apply'))
.map(x => x.replace(/^error: (.*): patch does not apply$/, '$1'))
.filter(Boolean);
logger.info('Applying diff...');
logger.warn(
`Excluding files that exist in the template, but not in your project:\n${filesThatDontExist
// when we run `config`, we don't want to output anything to the console. We
// expect it to return valid JSON
if (process.argv.includes('config')) {
logger.disable();
}
const ctx = loadConfig();
logger.enable();
for (const command of [...projectCommands, ...ctx.commands]) {
attachCommand(command, ctx);
}
} catch (e) {
logger.enable();
logger.debug(e.message);
logger.debug(
'Failed to load configuration of your project. Only a subset of commands will be available.',
);
}
commander.parse(process.argv);
if (commander.rawArgs.length === 2) {
commander.outputHelp();
}
// We handle --version as a special case like this because both `commander`
// and `yargs` append it to every command and we don't want to do that.
// E.g. outside command `init` has --version flag and we want to preserve it.
if (commander.args.length === 0 && commander.rawArgs.includes('--version')) {
console.log(pkgJson.version);
export default function getDependenciesFromPodfileLock(
podfileLockPath: string,
) {
logger.debug(`Reading ${podfileLockPath}`);
let fileContent;
try {
fileContent = fs.readFileSync(podfileLockPath, 'utf8');
} catch (err) {
logger.error(
`Could not find "Podfile.lock" at ${chalk.dim(
podfileLockPath,
)}. Did you run "${chalk.bold('pod install')}" in iOS directory?`,
);
return [];
}
// Previous portions of the lock file could be invalid yaml.
// Only parse parts that are valid
const tail = fileContent.split(CHECKSUM_KEY).slice(1);
const checksumTail = CHECKSUM_KEY + tail;
return Object.keys(safeLoad(checksumTail)[CHECKSUM_KEY] || {});
}
);
logger.info(
`React Native CLI will continue to run if your local environment matches what React Native expects. If it does fail, check out "${absolutePath}" and adjust your environment to match it.`,
);
}
}
for (const command of detachedCommands) {
attachCommand(command);
}
try {
// when we run `config`, we don't want to output anything to the console. We
// expect it to return valid JSON
if (process.argv.includes('config')) {
logger.disable();
}
const ctx = loadConfig();
logger.enable();
for (const command of [...projectCommands, ...ctx.commands]) {
attachCommand(command, ctx);
}
} catch (e) {
logger.enable();
logger.debug(e.message);
logger.debug(
'Failed to load configuration of your project. Only a subset of commands will be available.',
);
}
try {
// when we run `config`, we don't want to output anything to the console. We
// expect it to return valid JSON
if (process.argv.includes('config')) {
logger.disable();
}
const ctx = loadConfig();
logger.enable();
for (const command of [...projectCommands, ...ctx.commands]) {
attachCommand(command, ctx);
}
} catch (e) {
logger.enable();
logger.debug(e.message);
logger.debug(
'Failed to load configuration of your project. Only a subset of commands will be available.',
);
}
commander.parse(process.argv);
if (commander.rawArgs.length === 2) {
commander.outputHelp();
}
// We handle --version as a special case like this because both `commander`
// and `yargs` append it to every command and we don't want to do that.
// E.g. outside command `init` has --version flag and we want to preserve it.
if (commander.args.length === 0 && commander.rawArgs.includes('--version')) {
}
for (const command of detachedCommands) {
attachCommand(command);
}
try {
// when we run `config`, we don't want to output anything to the console. We
// expect it to return valid JSON
if (process.argv.includes('config')) {
logger.disable();
}
const ctx = loadConfig();
logger.enable();
for (const command of [...projectCommands, ...ctx.commands]) {
attachCommand(command, ctx);
}
} catch (e) {
logger.enable();
logger.debug(e.message);
logger.debug(
'Failed to load configuration of your project. Only a subset of commands will be available.',
);
}
commander.parse(process.argv);
if (commander.rawArgs.length === 2) {
commander.outputHelp();
async function installTemplateDevDependencies(
templatePath: string,
root: string,
) {
// devDependencies.json is a special file that lists additional develop dependencies
// that are required by this template
const devDependenciesJsonPath = path.resolve(
templatePath,
'devDependencies.json',
);
logger.info('Adding develop dependencies for the project...');
if (!fs.existsSync(devDependenciesJsonPath)) {
logger.info('No additional develop dependencies.');
return;
}
let dependencies: any;
try {
dependencies = require(devDependenciesJsonPath);
} catch (err) {
throw new Error(
`Could not parse the template's devDependencies.json: ${err.message}`,
);
}
const dependenciesToInstall = Object.keys(dependencies).map(
depName => `${depName}@${dependencies[depName]}`,
);
await PackageManager.installDev(dependenciesToInstall, {root});
output: typeof outputBundle = outputBundle,
) {
const config = await loadMetroConfig(ctx, {
maxWorkers: args.maxWorkers,
resetCache: args.resetCache,
config: args.config,
});
if (config.resolver.platforms.indexOf(args.platform) === -1) {
logger.error(
`Invalid platform ${
args.platform ? `"${chalk.bold(args.platform)}" ` : ''
}selected.`,
);
logger.info(
`Available platforms are: ${config.resolver.platforms
.map(x => `"${chalk.bold(x)}"`)
.join(
', ',
)}. If you are trying to bundle for an out-of-tree platform, it may not be installed.`,
);
throw new Error('Bundling failed');
}
// This is used by a bazillion of npm modules we don't control so we don't
// have other choice than defining it as an env variable here.
process.env.NODE_ENV = args.dev ? 'development' : 'production';
let sourceMapUrl = args.sourcemapOutput;
if (sourceMapUrl && !args.sourcemapUseAbsolutePath) {
async function installTemplateDevDependencies(
templatePath: string,
root: string,
) {
// devDependencies.json is a special file that lists additional develop dependencies
// that are required by this template
const devDependenciesJsonPath = path.resolve(
templatePath,
'devDependencies.json',
);
logger.info('Adding develop dependencies for the project...');
if (!fs.existsSync(devDependenciesJsonPath)) {
logger.info('No additional develop dependencies.');
return;
}
let dependencies: any;
try {
dependencies = require(devDependenciesJsonPath);
} catch (err) {
throw new Error(
`Could not parse the template's devDependencies.json: ${err.message}`,
);
}
const dependenciesToInstall = Object.keys(dependencies).map(
depName => `${depName}@${dependencies[depName]}`,