snyk-nodejs-lockfile-parser 2.7.1 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/c-map.js +1 -2
- package/dist/c-map.js.map +1 -1
- package/dist/cli-parsers/index.js +2 -1
- package/dist/cli-parsers/index.js.map +1 -1
- package/dist/cli-parsers/yarn-info-parser.js +1 -2
- package/dist/cli-parsers/yarn-info-parser.js.map +1 -1
- package/dist/dep-graph-builders/npm-lock-v2/extract-npm-lock-v2-pkgs.js +2 -1
- package/dist/dep-graph-builders/npm-lock-v2/extract-npm-lock-v2-pkgs.js.map +1 -1
- package/dist/dep-graph-builders/npm-lock-v2/index.js +15 -3
- package/dist/dep-graph-builders/npm-lock-v2/index.js.map +1 -1
- package/dist/dep-graph-builders/pnpm/build-dep-graph-pnpm.js +20 -12
- package/dist/dep-graph-builders/pnpm/build-dep-graph-pnpm.js.map +1 -1
- package/dist/dep-graph-builders/pnpm/lockfile-parser/lockfile-parser.js +11 -6
- package/dist/dep-graph-builders/pnpm/lockfile-parser/lockfile-parser.js.map +1 -1
- package/dist/dep-graph-builders/pnpm/lockfile-parser/lockfile-v5.js +2 -2
- package/dist/dep-graph-builders/pnpm/lockfile-parser/lockfile-v5.js.map +1 -1
- package/dist/dep-graph-builders/pnpm/lockfile-parser/lockfile-v6.js +4 -4
- package/dist/dep-graph-builders/pnpm/lockfile-parser/lockfile-v6.js.map +1 -1
- package/dist/dep-graph-builders/pnpm/lockfile-parser/lockfile-v9.js +6 -1
- package/dist/dep-graph-builders/pnpm/lockfile-parser/lockfile-v9.js.map +1 -1
- package/dist/dep-graph-builders/pnpm/parse-project.js +1 -2
- package/dist/dep-graph-builders/pnpm/parse-project.js.map +1 -1
- package/dist/dep-graph-builders/pnpm/utils.js +5 -1
- package/dist/dep-graph-builders/pnpm/utils.js.map +1 -1
- package/dist/dep-graph-builders/types.d.ts +7 -0
- package/dist/dep-graph-builders/util.js +28 -24
- package/dist/dep-graph-builders/util.js.map +1 -1
- package/dist/dep-graph-builders/yarn-lock-v1/build-depgraph-simple.js +31 -17
- package/dist/dep-graph-builders/yarn-lock-v1/build-depgraph-simple.js.map +1 -1
- package/dist/dep-graph-builders/yarn-lock-v2/build-depgraph-simple.js +35 -21
- package/dist/dep-graph-builders/yarn-lock-v2/build-depgraph-simple.js.map +1 -1
- package/dist/dep-graph-builders/yarn-lock-v2/utils.d.ts +2 -2
- package/dist/dep-graph-builders/yarn-lock-v2/utils.js +95 -17
- package/dist/dep-graph-builders/yarn-lock-v2/utils.js.map +1 -1
- package/dist/errors/invalid-user-input-error.js +2 -2
- package/dist/errors/invalid-user-input-error.js.map +1 -1
- package/dist/errors/out-of-sync-error.js +4 -2
- package/dist/errors/out-of-sync-error.js.map +1 -1
- package/dist/errors/tree-size-limit-error.js +3 -2
- package/dist/errors/tree-size-limit-error.js.map +1 -1
- package/dist/errors/unsupported-error.js +2 -2
- package/dist/errors/unsupported-error.js.map +1 -1
- package/dist/errors/unsupported-runtime-error.js +2 -2
- package/dist/errors/unsupported-runtime-error.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/dist/parsers/index.js +13 -11
- package/dist/parsers/index.js.map +1 -1
- package/dist/parsers/lock-parser-base.js +40 -15
- package/dist/parsers/lock-parser-base.js.map +1 -1
- package/dist/parsers/package-lock-parser.js +16 -18
- package/dist/parsers/package-lock-parser.js.map +1 -1
- package/dist/parsers/yarn-lock-parser.js +12 -3
- package/dist/parsers/yarn-lock-parser.js.map +1 -1
- package/dist/parsers/yarn2-lock-parser.js +12 -3
- package/dist/parsers/yarn2-lock-parser.js.map +1 -1
- package/dist/utils.d.ts +17 -0
- package/dist/utils.js +58 -15
- package/dist/utils.js.map +1 -1
- package/package.json +12 -7
package/dist/utils.js
CHANGED
|
@@ -4,6 +4,8 @@ exports.getLockfileVersionFromFile = exports.NodeLockfileVersion = void 0;
|
|
|
4
4
|
exports.getPnpmLockfileVersion = getPnpmLockfileVersion;
|
|
5
5
|
exports.getYarnLockfileVersion = getYarnLockfileVersion;
|
|
6
6
|
exports.getNpmLockfileVersion = getNpmLockfileVersion;
|
|
7
|
+
exports.parseJsonFile = parseJsonFile;
|
|
8
|
+
exports.describeLikelyJsonCause = describeLikelyJsonCause;
|
|
7
9
|
const fs_1 = require("fs");
|
|
8
10
|
const js_yaml_1 = require("js-yaml");
|
|
9
11
|
const errors_1 = require("./errors");
|
|
@@ -64,24 +66,65 @@ function getYarnLockfileVersion(lockFileContents) {
|
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
function getNpmLockfileVersion(lockFileContents) {
|
|
69
|
+
// Parse first; surfacing the real JSON error happens inside parseJsonFile.
|
|
70
|
+
const lockfileJson = parseJsonFile(lockFileContents, 'package-lock.json');
|
|
71
|
+
// The version check runs *outside* the parse try/catch so that an
|
|
72
|
+
// unsupported (but otherwise valid JSON) lockfile is not mis-reported as a
|
|
73
|
+
// JSON syntax error.
|
|
74
|
+
const lockfileVersion = lockfileJson.lockfileVersion || null;
|
|
75
|
+
switch (lockfileVersion) {
|
|
76
|
+
case null:
|
|
77
|
+
case 1:
|
|
78
|
+
return NodeLockfileVersion.NpmLockV1;
|
|
79
|
+
case 2:
|
|
80
|
+
return NodeLockfileVersion.NpmLockV2;
|
|
81
|
+
case 3:
|
|
82
|
+
return NodeLockfileVersion.NpmLockV3;
|
|
83
|
+
default:
|
|
84
|
+
throw new errors_1.InvalidUserInputError(`Unsupported npm lockfile version "${lockfileVersion}" in package-lock.json. ` +
|
|
85
|
+
'Please provide a package-lock.json with lockfileVersion 1, 2 or 3');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Parse JSON from a manifest or lockfile. On failure throws an
|
|
90
|
+
* InvalidUserInputError that preserves the underlying parser message
|
|
91
|
+
* (including the position of the syntax error) and appends a best-effort hint
|
|
92
|
+
* about the likely cause.
|
|
93
|
+
*
|
|
94
|
+
* `fileLabel` is the file kind shown in the error, e.g. 'package.json' or
|
|
95
|
+
* 'package-lock.json'.
|
|
96
|
+
*/
|
|
97
|
+
function parseJsonFile(content, fileLabel) {
|
|
67
98
|
try {
|
|
68
|
-
|
|
69
|
-
const lockfileVersion = lockfileJson.lockfileVersion || null;
|
|
70
|
-
switch (lockfileVersion) {
|
|
71
|
-
case null:
|
|
72
|
-
case 1:
|
|
73
|
-
return NodeLockfileVersion.NpmLockV1;
|
|
74
|
-
case 2:
|
|
75
|
-
return NodeLockfileVersion.NpmLockV2;
|
|
76
|
-
case 3:
|
|
77
|
-
return NodeLockfileVersion.NpmLockV3;
|
|
78
|
-
default:
|
|
79
|
-
throw new errors_1.InvalidUserInputError(`Unsupported npm lockfile version in package-lock.json. ` +
|
|
80
|
-
'Please provide a package-lock.json with lockfileVersion 1, 2 or 3');
|
|
81
|
-
}
|
|
99
|
+
return JSON.parse(content);
|
|
82
100
|
}
|
|
83
101
|
catch (e) {
|
|
84
|
-
throw new errors_1.InvalidUserInputError(
|
|
102
|
+
throw new errors_1.InvalidUserInputError(`${fileLabel} parsing failed with error ${e.message}` +
|
|
103
|
+
describeLikelyJsonCause(content));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Best-effort, allocation-light hint describing the most likely reason a JSON
|
|
108
|
+
* parse failed. Inspects only the leading characters of the content, never
|
|
109
|
+
* throws, and returns '' when nothing recognisable is found - so it is always
|
|
110
|
+
* safe to append to a parse-error message.
|
|
111
|
+
*/
|
|
112
|
+
function describeLikelyJsonCause(content) {
|
|
113
|
+
if (!content) {
|
|
114
|
+
return ' The file is empty.';
|
|
115
|
+
}
|
|
116
|
+
// A byte-order mark (UTF-8/UTF-16/UTF-32) decoded into the string.
|
|
117
|
+
if (content.charCodeAt(0) === 0xfeff) {
|
|
118
|
+
return ' The file begins with a byte-order mark (BOM); re-save it as UTF-8 without a BOM.';
|
|
119
|
+
}
|
|
120
|
+
// NUL bytes strongly suggest the file is UTF-16/UTF-32 encoded.
|
|
121
|
+
if (content.includes('\x00')) {
|
|
122
|
+
return ' The file contains NUL bytes; it may be UTF-16/UTF-32 encoded. Re-save it as UTF-8.';
|
|
123
|
+
}
|
|
124
|
+
// Unresolved git merge-conflict markers.
|
|
125
|
+
if (/^(<{7}|={7}|>{7})( |$)/m.test(content)) {
|
|
126
|
+
return ' The file appears to contain unresolved git merge-conflict markers.';
|
|
85
127
|
}
|
|
128
|
+
return '';
|
|
86
129
|
}
|
|
87
130
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../lib/utils.ts"],"names":[],"mappings":";;;AAkCA,wDAsBC;AAED,wDAQC;AAED,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../lib/utils.ts"],"names":[],"mappings":";;;AAkCA,wDAsBC;AAED,wDAQC;AAED,sDA2BC;AAWD,sCASC;AAQD,0DAiBC;AA5ID,2BAAkC;AAClC,qCAAgD;AAChD,qCAAiD;AACjD,mFAAyE;AAEzE,IAAY,mBASX;AATD,WAAY,mBAAmB;IAC7B,gDAAyB,CAAA;IACzB,gDAAyB,CAAA;IACzB,gDAAyB,CAAA;IACzB,kDAA2B,CAAA;IAC3B,kDAA2B,CAAA;IAC3B,kDAA2B,CAAA;IAC3B,kDAA2B,CAAA;IAC3B,kDAA2B,CAAA;AAC7B,CAAC,EATW,mBAAmB,mCAAnB,mBAAmB,QAS9B;AAEM,MAAM,0BAA0B,GAAG,CACxC,UAAkB,EACG,EAAE;IACvB,MAAM,gBAAgB,GAAG,IAAA,iBAAY,EAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC3D,IAAI,UAAU,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC;QAC7C,OAAO,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;IACjD,CAAC;SAAM,IAAI,UAAU,CAAC,QAAQ,CAAC,WA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AAqF,CAAC;IAC/F,CAAC;IACD,yCAAyC;IACzC,IAAI,yBAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5C,OAAO,qEAAqE,CAAC;IAC/E,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
package/package.json
CHANGED
|
@@ -22,8 +22,13 @@
|
|
|
22
22
|
},
|
|
23
23
|
"author": "snyk.io",
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"registry": "https://registry.npmjs.org/",
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
25
29
|
"engines": {
|
|
26
|
-
"node": ">=
|
|
30
|
+
"node": "^20.19.0 || ^22.13.0 || >=24.0.0",
|
|
31
|
+
"npm": ">=10"
|
|
27
32
|
},
|
|
28
33
|
"files": [
|
|
29
34
|
"bin",
|
|
@@ -53,13 +58,13 @@
|
|
|
53
58
|
"devDependencies": {
|
|
54
59
|
"@types/jest": "^28.1.3",
|
|
55
60
|
"@types/lodash": "^4.17.20",
|
|
56
|
-
"@types/node": "^
|
|
61
|
+
"@types/node": "^24",
|
|
57
62
|
"@types/semver": "^7.3.6",
|
|
58
63
|
"@types/uuid": "^8.3.0",
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
60
|
-
"@typescript-eslint/parser": "^
|
|
61
|
-
"eslint": "
|
|
62
|
-
"eslint-config-prettier": "^
|
|
64
|
+
"@typescript-eslint/eslint-plugin": "^8.60.0",
|
|
65
|
+
"@typescript-eslint/parser": "^8.60.0",
|
|
66
|
+
"eslint": "^8.57.1",
|
|
67
|
+
"eslint-config-prettier": "^9.1.0",
|
|
63
68
|
"jest": "^28.1.3",
|
|
64
69
|
"prettier": "^2.7.1",
|
|
65
70
|
"tap": "^15.0.4",
|
|
@@ -71,5 +76,5 @@
|
|
|
71
76
|
"tar": "7.5.11"
|
|
72
77
|
},
|
|
73
78
|
"packageManager": "yarn@2.4.1",
|
|
74
|
-
"version": "2.
|
|
79
|
+
"version": "2.8.1"
|
|
75
80
|
}
|