ls-exports
Version:
CLI for `list-exports`: Given a package name and a version number, or a path to a package.json, what specifiers does it expose?
20 lines (13 loc) • 465 B
JavaScript
import { promisify } from 'util';
import path from 'path';
import npa from 'npm-package-arg';
import pacote from 'pacote';
import { dir } from 'tmp';
const tmpDir = promisify(dir);
export default async function getPackageJSONPath(specifier) {
const { name } = npa(specifier);
const cwd = await tmpDir();
const packageDir = path.join(cwd, 'node_modules', name);
await pacote.extract(specifier, packageDir);
return path.join(packageDir, 'package.json');
}