Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let promises = [];
for (const file of answer) {
if (Object.keys(dependencyMap).includes(file)) {
const projectFilePath = path.resolve(projectDir, file);
// copy the file from template
promises.push(
fs.copy(
require.resolve(path.join('@expo/webpack-config/template', file)),
projectFilePath,
{ overwrite: true, recursive: true }
)
);
if (file in dependencyMap) {
const packageManager = PackageManager.createForProject(projectDir, { log });
for (const dependency of dependencyMap[file]) {
promises.push(packageManager.addDevAsync(dependency));
}
}
} else {
const fileName = path.basename(file);
const src = path.resolve(templateFolder, fileName);
const dest = path.resolve(projectDir, staticPath, fileName);
if (await fs.pathExists(src)) {
promises.push(fs.copy(src, dest, { overwrite: true, recursive: true }));
} else {
throw new Error(`Expected template file for ${fileName} doesn't exist at path: ${src}`);
}
}
}
await Promise.all(promises);
async function ensureDependenciesAreInstalledAsync(projectRoot: string): Promise {
const { dependencies, devDependencies } = getDependencies(projectRoot);
const all = [...dependencies, ...devDependencies];
if (!all.length) {
console.log(chalk.yellow(`\u203A All of the required dependencies are installed already.`));
return;
} else {
console.log(chalk.magenta(`\u203A Installing the missing dependencies: ${all.join(', ')}.`));
}
const packageManager = createForProject(projectRoot);
if (dependencies.length) await packageManager.addAsync(...dependencies);
if (devDependencies.length) await packageManager.addDevAsync(...devDependencies);
}
async onSelectAsync({ projectRoot }): Promise {
const { dependencies, devDependencies } = getDependencies(projectRoot);
const all = [...dependencies, ...devDependencies];
if (!all.length) {
console.log(
chalk.magenta.dim(`\u203A All of the required dependencies are installed already`)
);
return;
} else {
console.log(chalk.magenta(`\u203A Installing the missing dependencies: ${all.join(', ')}`));
}
const packageManager = createForProject(projectRoot);
if (dependencies.length) await packageManager.addAsync(...dependencies);
if (devDependencies.length) await packageManager.addDevAsync(...devDependencies);
},
},
async function installAsync(packages: string[], options: PackageManager.CreateForProjectOptions) {
const { projectRoot, workflow } = await findProjectRootAsync(process.cwd());
const packageManager = PackageManager.createForProject(projectRoot, {
npm: options.npm,
yarn: options.yarn,
log,
});
if (workflow === 'bare') {
return await packageManager.addAsync(...packages);
}
const { exp } = await ConfigUtils.readConfigJsonAsync(projectRoot);
if (!Versions.gteSdkVersion(exp, '33.0.0')) {
throw new CommandError(
'UNSUPPORTED_SDK_VERSION',
`expo install is only available for managed apps using Expo SDK version 33 or higher. Current version: ${exp.sdkVersion}.`
);
}
}
`;
await fse.writeFile(path.resolve('index.js'), indexjs);
log(chalk.green('Added new entry points!'));
log(
chalk.grey(
`Note that using \`${npmOrYarn} start\` will now require you to run Xcode and/or Android Studio to build the native code for your project.`
)
);
log('Removing node_modules...');
await fse.remove('node_modules');
log('Installing new packages...');
const packageManager = PackageManager.createForProject(projectRoot, { log });
await packageManager.installAsync();
log.newLine();
}
default: false,
});
if (answer.upgradeAndroid) {
let result = await Android.upgradeExpoAsync();
if (!result) {
log.error(
"The upgrade of your Android client didn't go as planned. You might have to reinstall it manually with expo client:install:android."
);
}
}
log.newLine();
}
let packageManager = PackageManager.createForProject(projectRoot, {
npm: options.npm,
yarn: options.yarn,
log,
});
log.addNewLineIfNone();
log(chalk.underline.bold('Installing the expo package...'));
log.addNewLineIfNone();
await packageManager.addAsync(`expo@^${targetSdkVersionString}`);
log.addNewLineIfNone();
log(chalk.underline.bold('Updating sdkVersion in app.json...'));
await ConfigUtils.writeConfigJsonAsync(projectRoot, { sdkVersion: targetSdkVersionString });
log(chalk.bold.underline('Updating packages to compatible versions (where known)...'));
log.addNewLineIfNone();