snyk-nodejs-lockfile-parser
Version:
Generate a dep tree given a lockfile
36 lines • 1.79 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPnpmLockfileParser = getPnpmLockfileParser;
const js_yaml_1 = require("js-yaml");
const lockfile_v6_1 = require("./lockfile-v6");
const lockfile_v5_1 = require("./lockfile-v5");
const lockfile_v9_1 = require("./lockfile-v9");
const error_catalog_nodejs_public_1 = require("@snyk/error-catalog-nodejs-public");
const utils_1 = require("../../../utils");
function getPnpmLockfileParser(pnpmLockContent, lockfileVersion, workspaceArgs) {
// In case of no dependencies, pnpm@7 (lokfile version 5)
// does not create a lockfile at `pnpm install`
// so if there is no lockfile content, default to lockfile version 5
if (!pnpmLockContent) {
return new lockfile_v5_1.LockfileV5Parser(pnpmLockContent, workspaceArgs);
}
const rawPnpmLock = (0, js_yaml_1.load)(pnpmLockContent, {
json: true,
schema: js_yaml_1.FAILSAFE_SCHEMA,
});
const version = rawPnpmLock.lockfileVersion;
if (lockfileVersion === utils_1.NodeLockfileVersion.PnpmLockV5 ||
version.startsWith('5')) {
return new lockfile_v5_1.LockfileV5Parser(rawPnpmLock, workspaceArgs);
}
if (lockfileVersion === utils_1.NodeLockfileVersion.PnpmLockV6 ||
version.startsWith('6')) {
return new lockfile_v6_1.LockfileV6Parser(rawPnpmLock, workspaceArgs);
}
if (lockfileVersion === utils_1.NodeLockfileVersion.PnpmLockV9 ||
version.startsWith('9')) {
return new lockfile_v9_1.LockfileV9Parser(rawPnpmLock, workspaceArgs);
}
throw new error_catalog_nodejs_public_1.OpenSourceEcosystems.PnpmUnsupportedLockfileVersionError(`The pnpm-lock.yaml lockfile version ${lockfileVersion} is not supported`);
}
//# sourceMappingURL=index.js.map
;