node-modules-tools 0.5.6 → 0.6.0
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/chunks/index.mjs
CHANGED
|
@@ -3,6 +3,10 @@ import YAML from 'js-yaml';
|
|
|
3
3
|
import { relative, dirname, join } from 'pathe';
|
|
4
4
|
import { x } from 'tinyexec';
|
|
5
5
|
import { CLUSTER_DEP_PROD, CLUSTER_DEP_DEV } from '../constants.mjs';
|
|
6
|
+
import { JsonParseStreamError } from './json-parse-stream.mjs';
|
|
7
|
+
import 'stream';
|
|
8
|
+
import 'string_decoder';
|
|
9
|
+
import 'events';
|
|
6
10
|
|
|
7
11
|
async function resolveRoot(options) {
|
|
8
12
|
let raw;
|
|
@@ -50,7 +54,17 @@ async function getDependenciesTree(options) {
|
|
|
50
54
|
cwd: options.cwd
|
|
51
55
|
}
|
|
52
56
|
});
|
|
53
|
-
const json = await import('./json-parse-stream.mjs').then((r) => r.parseJsonStreamWithConcatArrays(process.process.stdout))
|
|
57
|
+
const json = await import('./json-parse-stream.mjs').then((r) => r.parseJsonStreamWithConcatArrays(process.process.stdout, "pnpm ls")).catch((err) => {
|
|
58
|
+
if (err instanceof JsonParseStreamError) {
|
|
59
|
+
try {
|
|
60
|
+
if (err.data.error?.message === "Invalid string length") {
|
|
61
|
+
console.error(`pnpm ls output is too large to parse, please try using the --depth=${String(Math.ceil(options.depth / 3 * 2))} option to limit the depth of the dependency tree`);
|
|
62
|
+
}
|
|
63
|
+
} catch {
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
throw err;
|
|
67
|
+
});
|
|
54
68
|
if (!Array.isArray(json))
|
|
55
69
|
throw new Error(`Failed to parse \`pnpm ls\` output, expected an array but got: ${String(json)}`);
|
|
56
70
|
return json;
|
package/dist/chunks/index2.mjs
CHANGED
|
@@ -34,7 +34,7 @@ async function queryDependencies(options, query, lockfileOnly = false) {
|
|
|
34
34
|
cwd: options.cwd
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
|
-
const json = await import('./json-parse-stream.mjs').then((r) => r.parseJsonStreamWithConcatArrays(process.process.stdout));
|
|
37
|
+
const json = await import('./json-parse-stream.mjs').then((r) => r.parseJsonStreamWithConcatArrays(process.process.stdout, "npm query"));
|
|
38
38
|
if (!Array.isArray(json))
|
|
39
39
|
throw new Error(`Failed to parse \`npm query\` output, expected an array but got: ${String(json)}`);
|
|
40
40
|
return json;
|
|
@@ -820,6 +820,12 @@ function requireAssembler () {
|
|
|
820
820
|
var AssemblerExports = requireAssembler();
|
|
821
821
|
const Assembler = /*@__PURE__*/getDefaultExportFromCjs(AssemblerExports);
|
|
822
822
|
|
|
823
|
+
class JsonParseStreamError extends Error {
|
|
824
|
+
constructor(message, data) {
|
|
825
|
+
super(message);
|
|
826
|
+
this.data = data;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
823
829
|
function parseJsonStream(stream) {
|
|
824
830
|
const assembler = new Assembler();
|
|
825
831
|
const parser = StreamJSON.parser();
|
|
@@ -833,7 +839,7 @@ function parseJsonStream(stream) {
|
|
|
833
839
|
});
|
|
834
840
|
});
|
|
835
841
|
}
|
|
836
|
-
function parseJsonStreamWithConcatArrays(stream) {
|
|
842
|
+
function parseJsonStreamWithConcatArrays(stream, sourceName) {
|
|
837
843
|
const assembler = new Assembler();
|
|
838
844
|
const parser = StreamJSON.parser({
|
|
839
845
|
jsonStreaming: true
|
|
@@ -843,8 +849,11 @@ function parseJsonStreamWithConcatArrays(stream) {
|
|
|
843
849
|
parser.on("data", (chunk) => {
|
|
844
850
|
assembler[chunk.name]?.(chunk.value);
|
|
845
851
|
if (assembler.done) {
|
|
846
|
-
if (!Array.isArray(assembler.current))
|
|
847
|
-
|
|
852
|
+
if (!Array.isArray(assembler.current)) {
|
|
853
|
+
console.error(`Failed to parse JSON output from ${sourceName}`);
|
|
854
|
+
console.dir(assembler.current, { depth: 3 });
|
|
855
|
+
throw new JsonParseStreamError(`Failed to parse JSON output from ${sourceName}`, assembler.current);
|
|
856
|
+
}
|
|
848
857
|
values.push(...assembler.current);
|
|
849
858
|
}
|
|
850
859
|
});
|
|
@@ -855,4 +864,4 @@ function parseJsonStreamWithConcatArrays(stream) {
|
|
|
855
864
|
});
|
|
856
865
|
}
|
|
857
866
|
|
|
858
|
-
export { parseJsonStream, parseJsonStreamWithConcatArrays };
|
|
867
|
+
export { JsonParseStreamError, parseJsonStream, parseJsonStreamWithConcatArrays };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-modules-tools",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"description": "Tools for inspecting node_modules",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"js-yaml": "^4.1.0",
|
|
31
31
|
"p-limit": "^6.2.0",
|
|
32
|
-
"package-manager-detector": "^1.
|
|
32
|
+
"package-manager-detector": "^1.1.0",
|
|
33
33
|
"pathe": "^2.0.3",
|
|
34
34
|
"pkg-types": "^2.1.0",
|
|
35
35
|
"publint": "^0.3.9",
|
|
36
36
|
"semver": "^7.7.1",
|
|
37
|
-
"tinyexec": "^0.
|
|
37
|
+
"tinyexec": "^1.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@pnpm/list": "^1000.0.
|
|
40
|
+
"@pnpm/list": "^1000.0.12",
|
|
41
41
|
"@pnpm/types": "^1000.2.1",
|
|
42
42
|
"@types/js-yaml": "^4.0.9",
|
|
43
43
|
"@types/stream-json": "^1.7.8",
|