1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getFileContents = exports.getPnpmChildNode = void 0;
|
4 | const path = require("path");
|
5 | const fs = require("fs");
|
6 | const __1 = require("../..");
|
7 | const util_1 = require("../util");
|
8 | const semver_1 = require("semver");
|
9 | const error_catalog_nodejs_public_1 = require("@snyk/error-catalog-nodejs-public");
|
10 | const out_of_sync_error_1 = require("../../errors/out-of-sync-error");
|
11 | const debugModule = require("debug");
|
12 | const debug = debugModule('snyk-pnpm-workspaces');
|
13 | const getPnpmChildNode = (name, depInfo, pkgs, strictOutOfSync, includeOptionalDeps, includeDevDeps, lockfileParser) => {
|
14 | let resolvedVersion = (0, semver_1.valid)(depInfo.version) || depInfo.version === undefined
|
15 | ? depInfo.version
|
16 | : lockfileParser.excludeTransPeerDepsVersions(depInfo.version);
|
17 | let childNodeKey = `${name}@${resolvedVersion}`;
|
18 |
|
19 |
|
20 | if (lockfileParser.resolvedPackages[depInfo.version]) {
|
21 | childNodeKey = lockfileParser.resolvedPackages[depInfo.version];
|
22 | const pkgData = pkgs[childNodeKey];
|
23 | name = pkgData.name;
|
24 | resolvedVersion = pkgData.version;
|
25 | }
|
26 | if (!pkgs[childNodeKey]) {
|
27 | if (strictOutOfSync && !/^file:/.test(depInfo.version)) {
|
28 | const errMessage = `Dependency ${childNodeKey} was not found in ` +
|
29 | `${out_of_sync_error_1.LOCK_FILE_NAME[__1.LockfileType.pnpm]}. Your package.json and ` +
|
30 | `${out_of_sync_error_1.LOCK_FILE_NAME[__1.LockfileType.pnpm]} are probably out of sync. Please run ` +
|
31 | `"${out_of_sync_error_1.INSTALL_COMMAND[__1.LockfileType.pnpm]}" and try again.`;
|
32 | debug(errMessage);
|
33 | throw new error_catalog_nodejs_public_1.OpenSourceEcosystems.PnpmOutOfSyncError(errMessage);
|
34 | }
|
35 | else {
|
36 | return {
|
37 | id: childNodeKey,
|
38 | name: name,
|
39 | version: resolvedVersion,
|
40 | dependencies: {},
|
41 | isDev: depInfo.isDev,
|
42 | missingLockFileEntry: true,
|
43 | };
|
44 | }
|
45 | }
|
46 | else {
|
47 | const depData = pkgs[childNodeKey];
|
48 | const dependencies = (0, util_1.getGraphDependencies)(depData.dependencies || {}, depInfo.isDev);
|
49 | const devDependencies = includeDevDeps
|
50 | ? (0, util_1.getGraphDependencies)(depData.devDependencies || {}, true)
|
51 | : {};
|
52 | const optionalDependencies = includeOptionalDeps
|
53 | ? (0, util_1.getGraphDependencies)(depData.optionalDependencies || {}, depInfo.isDev)
|
54 | : {};
|
55 | return {
|
56 | id: `${name}@${depData.version}`,
|
57 | name: name,
|
58 | version: resolvedVersion,
|
59 | dependencies: Object.assign(Object.assign(Object.assign({}, dependencies), optionalDependencies), devDependencies),
|
60 | isDev: depInfo.isDev,
|
61 | };
|
62 | }
|
63 | };
|
64 | exports.getPnpmChildNode = getPnpmChildNode;
|
65 | function getFileContents(root, fileName) {
|
66 | const fullPath = path.resolve(root, fileName);
|
67 | if (!fs.existsSync(fullPath)) {
|
68 | throw new Error('Manifest ' + fileName + ' not found at location: ' + fileName);
|
69 | }
|
70 | const content = fs.readFileSync(fullPath, 'utf-8');
|
71 | return {
|
72 | content,
|
73 | fileName,
|
74 | };
|
75 | }
|
76 | exports.getFileContents = getFileContents;
|
77 |
|
\ | No newline at end of file |