How to use the @expo/json-file.read function in @expo/json-file

To help you get started, we’ve selected a few @expo/json-file 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 / eject / Eject.ts View on Github external
await fse.writeFile(path.resolve('app.json'), JSON.stringify(appJson, null, 2));
  log(chalk.green('Wrote to app.json, please update it manually in the future.'));

  // This is validated later...
  let defaultDependencies: any = {};
  let defaultDevDependencies: any = {};

  /**
   * Extract the template and copy it over
   */
  try {
    const tempDir = temporary.directory();
    await Exp.extractTemplateAppAsync(templateSpec, tempDir, appJson);
    fse.copySync(path.join(tempDir, 'ios'), path.join(projectRoot, 'ios'));
    fse.copySync(path.join(tempDir, 'android'), path.join(projectRoot, 'android'));
    const { dependencies, devDependencies } = JsonFile.read(path.join(tempDir, 'package.json'));
    defaultDependencies = ensureDependenciesMap(dependencies);
    defaultDevDependencies = devDependencies;
    log('Successfully copied template native code.');
  } catch (e) {
    log(chalk.red(e.message));
    log(chalk.red(`Eject failed, see above output for any issues.`));
    log(chalk.yellow('You may want to delete the `ios` and/or `android` directories.'));
    process.exit(1);
  }

  log(`Updating your package.json...`);
  if (!pkg.scripts) {
    pkg.scripts = {};
  }
  delete pkg.scripts.eject;
  pkg.scripts.start = 'react-native start';
github expo / expo-cli / packages / config / src / getConfig.ts View on Github external
function evalConfig(configFile: string, request: ConfigContext): Partial {
  let result: any;
  let format: string = '';
  if (configFile.endsWith('.json5') || configFile.endsWith('.json')) {
    format = 'json';
    result = JsonFile.read(configFile, { json5: true });
  } else {
    format = 'js';
    result = require(configFile);
    if (result.default != null) {
      result = result.default;
    }
    if (typeof result === 'function') {
      result = result(request);
    }
  }
  /*
  } else if (configFile.endsWith('.ts')) {
    format = 'ts';
    const ts = require('typescript');
    // const ts = require(projectHasModule('typescript', request.projectRoot, {})!);
    const tsconfig = require(projectHasModule('./tsconfig', request.projectRoot, {})!);
github expo / expo-cli / packages / config / src / Project.ts View on Github external
export function getExpoSDKVersion(
  projectRoot: string,
  exp: Pick
): string {
  if (exp && exp.sdkVersion) {
    return exp.sdkVersion;
  }
  const packageJsonPath = projectHasModule('expo/package.json', projectRoot, exp);
  if (packageJsonPath) {
    const expoPackageJson = JsonFile.read(packageJsonPath, { json5: true });
    const { version: packageVersion } = expoPackageJson;
    if (typeof packageVersion === 'string') {
      const majorVersion = packageVersion.split('.').shift();
      return `${majorVersion}.0.0`;
    }
  }
  throw new ConfigError(
    `Cannot determine which native SDK version your project uses because the module \`expo\` is not installed. Please install it with \`yarn add expo\` and try again.`,
    'MODULE_NOT_FOUND'
  );
}
github expo / expo-cli / packages / config / src / Config.ts View on Github external
export function readConfigJson(
  projectRoot: string,
  skipValidation: boolean = false,
  skipNativeValidation: boolean = false
): ProjectConfig {
  const { configPath } = findConfigFile(projectRoot);
  let rawConfig: JSONObject | null = null;
  try {
    rawConfig = JsonFile.read(configPath, { json5: true });
  } catch (_) {}
  const { rootConfig, exp } = parseAndValidateRootConfig(rawConfig, skipValidation);
  const packageJsonPath = getRootPackageJsonPath(projectRoot, exp);
  const pkg = JsonFile.read(packageJsonPath);

  return {
    ...ensureConfigHasDefaultValues(projectRoot, exp, pkg, skipNativeValidation),
    rootConfig: rootConfig as AppJSONConfig,
  };
}
github expo / expo-cli / packages / config / src / Config.ts View on Github external
export function readConfigJson(
  projectRoot: string,
  skipValidation: boolean = false,
  skipNativeValidation: boolean = false
): ProjectConfig {
  const { configPath } = findConfigFile(projectRoot);
  let rawConfig: JSONObject | null = null;
  try {
    rawConfig = JsonFile.read(configPath, { json5: true });
  } catch (_) {}
  const { rootConfig, exp } = parseAndValidateRootConfig(rawConfig, skipValidation);
  const packageJsonPath = getRootPackageJsonPath(projectRoot, exp);
  const pkg = JsonFile.read(packageJsonPath);

  return {
    ...ensureConfigHasDefaultValues(projectRoot, exp, pkg, skipNativeValidation),
    rootConfig: rootConfig as AppJSONConfig,
  };
}
github expo / expo-cli / packages / config / src / Web.ts View on Github external
export function createEnvironmentConstants(appManifest: ExpoConfig, pwaManifestLocation: string) {
  let web;
  try {
    web = JsonFile.read(pwaManifestLocation);
  } catch (e) {
    web = {};
  }

  return {
    ...appManifest,
    name: appManifest.displayName || appManifest.name,
    /**
     * Omit app.json properties that get removed during the native turtle build
     *
     * `facebookScheme`
     * `facebookAppId`
     * `facebookDisplayName`
     */
    facebookScheme: undefined,
    facebookAppId: undefined,

@expo/json-file

A module for reading, writing, and manipulating JSON files

MIT
Latest version published 7 months ago

Package Health Score

88 / 100
Full package analysis