How to use @expo/package-manager - 6 common examples

To help you get started, we’ve selected a few @expo/package-manager examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github expo / expo-cli / packages / expo-cli / src / commands / customize.ts View on Github external
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);
github expo / expo-cli / packages / electron-adapter / src / Config.ts View on Github external
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);
}
github expo / expo-cli / packages / next-adapter / src / customize / manifest.ts View on Github external
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);
    },
  },
github expo / expo-cli / packages / expo-cli / src / commands / install.ts View on Github external
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}.`
    );
  }
github expo / expo-cli / packages / expo-cli / src / commands / eject / Eject.ts View on Github external
}
`;
  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();
}
github expo / expo-cli / packages / expo-cli / src / commands / upgrade.ts View on Github external
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();

@expo/package-manager

A library for installing and finding packages in a project

MIT
Latest version published 7 months ago

Package Health Score

88 / 100
Full package analysis

Popular @expo/package-manager functions