How to use the @expo/json-file.readAsync 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 / xdl / src / Project.js View on Github external
const putJsonInMemory = async (indexPath, accumulator) => {
      const index = await JsonFile.readAsync(indexPath);
      if (!index.sdkVersion) {
        throw new XDLError(
          ErrorCode.INVALID_MANIFEST,
          `Invalid index.json, must specify an sdkVersion at ${indexPath}`
        );
      }
      if (Array.isArray(index)) {
        // index.json could also be an array
        accumulator.push(...index);
      } else {
        accumulator.push(index);
      }
    };
github expo / expo-cli / dev / xdl / src / project / ProjectUtils.js View on Github external
export async function readConfigJsonAsync(
  projectRoot: string
): Promise<{ exp: ?Object, pkg: ?Object, rootConfig: ?Object }> {
  let exp;
  let pkg;
  let rootConfig;

  const { configPath, configName, configNamespace } = await findConfigFileAsync(projectRoot);

  try {
    exp = await JsonFile.readAsync(configPath, { json5: true });

    if (configNamespace) {
      // if we're not using exp.json, then we've stashed everything under an expo key
      rootConfig = exp;
      exp = exp[configNamespace];
    }
  } catch (e) {
    if (e.code === 'ENOENT') {
      // config missing. might be in package.json
    } else if (e.isJsonFileError) {
      logError(projectRoot, 'expo', e.message);
      return { exp: null, pkg: null };
    }
  }

  try {
github expo / expo-cli / packages / expo-cli / src / commands / install.ts View on Github external
}

  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}.`
    );
  }

  if (!fs.existsSync(path.join(exp.nodeModulesPath || projectRoot, 'node_modules'))) {
    log.warn(`node_modules not found, running ${packageManager.name} install command.`);
    await packageManager.installAsync();
  }

  const bundledNativeModules = await JsonFile.readAsync(
    ConfigUtils.resolveModule('expo/bundledNativeModules.json', projectRoot, exp)
  );

  const nativeModules = [];
  const others = [];
  const versionedPackages = packages.map(arg => {
    const spec = npmPackageArg(arg);
    const { name } = spec;
    if (['tag', 'version', 'range'].includes(spec.type) && name && bundledNativeModules[name]) {
      // Unimodule packages from npm registry are modified to use the bundled version.
      const version = bundledNativeModules[name];
      const modifiedSpec = `${name}@${version}`;
      nativeModules.push(modifiedSpec);
      return modifiedSpec;
    } else {
      // Other packages are passed through unmodified.
github expo / expo-cli / packages / config / src / Config.ts View on Github external
export async function readConfigJsonAsync(
  projectRoot: string,
  skipValidation: boolean = false,
  skipNativeValidation: boolean = false
): Promise {
  const { configPath } = findConfigFile(projectRoot);
  let rawConfig: JSONObject | null = null;
  try {
    rawConfig = await JsonFile.readAsync(configPath, { json5: true });
  } catch (_) {}
  const { rootConfig, exp } = parseAndValidateRootConfig(rawConfig, skipValidation);
  const packageJsonPath = getRootPackageJsonPath(projectRoot, exp);
  const pkg = await JsonFile.readAsync(packageJsonPath);

  return {
    ...ensureConfigHasDefaultValues(projectRoot, exp, pkg, skipNativeValidation),
    rootConfig: rootConfig as AppJSONConfig,
  };
}
github expo / expo-cli / packages / expo-cli / src / commands / start.js View on Github external
return;
  }

  const bundleNativeModulesPath = attempt(() =>
    ConfigUtils.resolveModule('expo/bundledNativeModules.json', projectDir, exp)
  );
  if (isError(bundleNativeModulesPath)) {
    log.warn(
      `Your project is in SDK version >= 33.0.0, but the ${chalk.underline(
        'expo'
      )} package version seems to be older.`
    );
    return;
  }

  const bundledNativeModules = await JsonFile.readAsync(bundleNativeModulesPath);
  const bundledNativeModulesNames = Object.keys(bundledNativeModules);
  const projectDependencies = Object.keys(pkg.dependencies);

  const modulesToCheck = intersection(bundledNativeModulesNames, projectDependencies);
  const incorrectDeps = [];
  for (const moduleName of modulesToCheck) {
    const expectedRange = bundledNativeModules[moduleName];
    const actualRange = pkg.dependencies[moduleName];
    if (
      (semver.valid(actualRange) || semver.validRange(actualRange)) &&
      !semver.intersects(expectedRange, actualRange)
    ) {
      incorrectDeps.push({
        moduleName,
        expectedRange,
        actualRange,
github expo / expo / tools / expotools / src / ProjectVersions.ts View on Github external
export async function getSDKVersionsAsync(platform: Platform): Promise {
  switch (platform) {
    case Platform.IOS:
      const sdkVersionsPath = path.join(EXPO_DIR, 'exponent-view-template', 'ios', 'exponent-view-template', 'Supporting', 'sdkVersions.json');

      if (!await fs.pathExists(sdkVersionsPath)) {
        throw new Error(`File ${sdkVersionsPath} does not exist. It's needed for extracting available SDK versions on iOS.`);
      }

      const { sdkVersions } = await JsonFile.readAsync(sdkVersionsPath) as { sdkVersions: string[] };
      return sdkVersions;

    case Platform.Android: {
      const buildGradlePath = path.join(EXPO_DIR, 'android', 'app', 'build.gradle');

      if (!await fs.pathExists(buildGradlePath)) {
        throw new Error(`File ${buildGradlePath} does not exists. It's neede for reading available SDK version on Android.`);
      }

      function nonNullPredicate(value: T | null): value is T {
        return value !== null;
      }

      const buildGradleContent = await fs.readFile(buildGradlePath, 'utf-8');
      const matches = buildGradleContent.match(/project\(["']:expoview-abi((\d)+_(\d)+_(\d)+)['"]\)/g) || [];
      const versions = matches
github expo / expo / tools / expotools / src / commands / IosUpdateExpoKit.ts View on Github external
async function getSdkVersionAsync() {
  const expoSdkVersion = (await JsonFile.readAsync(
    path.join(EXPO_DIR, 'packages/expo/package.json')
  )).version;
  return `${semver.major(expoSdkVersion)}.0.0`;
}
github expo / expo / tools / expotools / src / ProjectVersions.ts View on Github external
export async function sdkVersionAsync(): Promise {
  const packageJson = await JsonFile.readAsync(path.join(EXPO_DIR, 'packages/expo/package.json'));
  return packageJson.version as string;
}

@expo/json-file

A module for reading, writing, and manipulating JSON files

MIT
Latest version published 27 days ago

Package Health Score

92 / 100
Full package analysis