How to use package-json - 10 common examples

To help you get started, we’ve selected a few package-json 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 jupyterlab / jupyterlab-data-explorer / jupyterlab / buildutils / src / update-dist-tag.ts View on Github external
packagePath = path.join(packagePath, 'package.json');
  let data: any;
  try {
    data = utils.readJSONFile(packagePath);
  } catch (e) {
    console.log('Skipping package ' + packagePath);
    return cmds;
  }

  if (data.private) {
    return cmds;
  }

  const pkg = data.name;

  let npmData = await packageJson(pkg, { allVersions: true });
  let versions = Object.keys(npmData.versions).sort(semver.rcompare);
  let tags = npmData['dist-tags'];

  // Go through the versions. The latest prerelease is 'next', the latest
  // non-prerelease should be 'stable'.
  let next = semver.prerelease(versions[0]) ? versions[0] : undefined;
  let latest = versions.find(i => !semver.prerelease(i));

  if (latest && latest !== tags.latest) {
    cmds.push(`npm dist-tag add ${pkg}@${latest} latest`);
  }

  // If next is defined, but not supposed to be, remove it. If next is supposed
  // to be defined, but is not the same as the current next, change it.
  if (!next && tags.next) {
    cmds.push(`npm dist-tag rm ${pkg} next`);
github jupyterlab / jupyterlab / buildutils / src / update-dist-tag.ts View on Github external
packagePath = path.join(packagePath, 'package.json');
  let data: any;
  try {
    data = utils.readJSONFile(packagePath);
  } catch (e) {
    console.log('Skipping package ' + packagePath);
    return cmds;
  }

  if (data.private) {
    return cmds;
  }

  const pkg = data.name;

  let npmData = await packageJson(pkg, { allVersions: true });
  let versions = Object.keys(npmData.versions).sort(semver.rcompare);
  let tags = npmData['dist-tags'];

  // Go through the versions. The latest prerelease is 'next', the latest
  // non-prerelease should be 'stable'.
  let next = semver.prerelease(versions[0]) ? versions[0] : undefined;
  let latest = versions.find(i => !semver.prerelease(i));

  if (latest && latest !== tags.latest) {
    cmds.push(`npm dist-tag add ${pkg}@${latest} latest`);
  }

  // If next is defined, but not supposed to be, remove it. If next is supposed
  // to be defined, but is not the same as the current next, change it.
  if (!next && tags.next) {
    cmds.push(`npm dist-tag rm ${pkg} next`);
github jupyterlab / jupyterlab / buildutils / src / update-dependency.ts View on Github external
async function getVersion(pkg: string, specifier: string) {
  let key = JSON.stringify([pkg, specifier]);
  if (versionCache.has(key)) {
    return versionCache.get(key);
  }
  if (semver.validRange(specifier) === null) {
    // We have a tag, with possibly a range specifier, such as ^latest
    let match = specifier.match(tags);
    if (match === null) {
      throw Error(`Invalid version specifier: ${specifier}`);
    }

    // Look up the actual version corresponding to the tag
    let { version } = await packageJson(pkg, { version: match[2] });
    specifier = match[1] + version;
  }
  versionCache.set(key, specifier);
  return specifier;
}
github jupyterlab / jupyterlab-data-explorer / buildutils / src / update-dependency.ts View on Github external
async function getVersion(pkg: string, specifier: string) {
  let key = JSON.stringify([pkg, specifier]);
  if (versionCache.has(key)) {
    return versionCache.get(key);
  }
  if (semver.validRange(specifier) === null) {
    // We have a tag, with possibly a range specifier, such as ^latest
    let match = specifier.match(tags);
    if (match === null) {
      throw Error(`Invalid version specifier: ${specifier}`);
    }

    // Look up the actual version corresponding to the tag
    let { version } = await packageJson(pkg, { version: match[2] });
    specifier = match[1] + version;
  }
  versionCache.set(key, specifier);
  return specifier;
}
github alibaba / ice / packages / iceworks-server / src / lib / getTarballURLByMaterielSource.ts View on Github external
export default async (source: IMaterialNpmSource, iceVersion?: string): Promise => {
  let version: string = source.version;

  // TODO special material logic
  if (iceVersion === '1.x') {
    version = source['version-0.x'] || source.version;
  }

  const registryUrl = typeof source.npm === 'string' && source.npm.startsWith('@icedesign')
    ? 'https://registry.npm.taobao.org'
    : ((storage.get('npmClient') === 'custom' && storage.get('registry')) || source.registry);

  const packageData: any = await packageJSON(source.npm, {
    version,
    registryUrl,
  });

  return packageData.dist.tarball;
};
github jupyterlab / jupyterlab / buildutils / src / update-dependency.ts View on Github external
async function getVersion(pkg: string, specifier: string) {
  let key = JSON.stringify([pkg, specifier]);
  if (versionCache.has(key)) {
    return versionCache.get(key);
  }
  if (semver.validRange(specifier) === null) {
    // We have a tag, with possibly a range specifier, such as ^latest
    let match = specifier.match(tags);
    if (match === null) {
      throw Error(`Invalid version specifier: ${specifier}`);
    }

    // Look up the actual version corresponding to the tag
    let { version } = await packageJson(pkg, { version: match[2] });
    specifier = match[1] + version;
  }
  versionCache.set(key, specifier);
  return specifier;
}
github polkadot-js / client / packages / client / src / clientId.spec.js View on Github external
it('queries the registry, showing newer', () => {
      npmJson.mockImplementation(() => {
        return Promise.resolve({ version: '0.0.0' });
      });

      return clientId.getNpmStatus().then((version) => {
        expect(version).toEqual('newer, 0.0.0 published');
      });
    });
  });
github expo / expo-cli / packages / xdl / src / tools / ModuleVersion.ts View on Github external
async () => {
      const pkgJson = await pTimeout(npmPackageJson(name, { version: currentVersion }), 2000);
      return {
        latestVersion: await pTimeout(latestVersionAsync(name), 2000),
        deprecated: pkgJson.deprecated,
      };
    },
    `${name}-updates.json`,
github react-zeroconfig / react-zeroconfig / src / packageScripts / createPackagePublishOptions.ts View on Github external
const getNpmRemotePackageJson: GetRemotePackageJson = ({name, ...options}) => {
  return getPackageJson(name, options)
    .then(value => value && typeof value.version === 'string' ? value as PackageJson : undefined)
    .catch(() => undefined);
};
github react-zeroconfig / react-zeroconfig / src / utils / module / createPublishOptions.ts View on Github external
function getNpmRemoteVersion(name: string, version: string): Promise {
  return getPackageJson(name, {version})
    .then((value: AbbreviatedMetadata) => {
      return value && typeof value.version === 'string' ? value.version : undefined;
    })
    .catch(() => {
      return undefined;
    });
}

package-json

Get metadata of a package from the npm registry

MIT
Latest version published 5 months ago

Package Health Score

78 / 100
Full package analysis