node-modules-tools 0.1.9 → 0.2.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/chunks/index.mjs +15 -4
- package/dist/chunks/json-parse-stream.mjs +22 -1
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/package.json +1 -1
package/dist/chunks/index.mjs
CHANGED
|
@@ -3,15 +3,24 @@ import { x } from 'tinyexec';
|
|
|
3
3
|
|
|
4
4
|
async function resolveRoot(options) {
|
|
5
5
|
let raw;
|
|
6
|
-
|
|
7
|
-
raw = (await x("pnpm", ["root", "-w"], { throwOnError: true, nodeOptions: { cwd: options.cwd } })).stdout.trim();
|
|
8
|
-
} catch {
|
|
6
|
+
if (options.workspace === false) {
|
|
9
7
|
try {
|
|
10
8
|
raw = (await x("pnpm", ["root"], { throwOnError: true, nodeOptions: { cwd: options.cwd } })).stdout.trim();
|
|
11
9
|
} catch (err) {
|
|
12
10
|
console.error("Failed to resolve root directory");
|
|
13
11
|
console.error(err);
|
|
14
12
|
}
|
|
13
|
+
} else {
|
|
14
|
+
try {
|
|
15
|
+
raw = (await x("pnpm", ["root", "-w"], { throwOnError: true, nodeOptions: { cwd: options.cwd } })).stdout.trim();
|
|
16
|
+
} catch {
|
|
17
|
+
try {
|
|
18
|
+
raw = (await x("pnpm", ["root"], { throwOnError: true, nodeOptions: { cwd: options.cwd } })).stdout.trim();
|
|
19
|
+
} catch (err) {
|
|
20
|
+
console.error("Failed to resolve root directory");
|
|
21
|
+
console.error(err);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
15
24
|
}
|
|
16
25
|
return raw ? dirname(raw) : options.cwd;
|
|
17
26
|
}
|
|
@@ -29,6 +38,8 @@ async function getDependenciesTree(options) {
|
|
|
29
38
|
const args = ["ls", "--json", "--no-optional", "--depth", String(options.depth)];
|
|
30
39
|
if (options.monorepo)
|
|
31
40
|
args.push("--recursive");
|
|
41
|
+
if (options.workspace === false)
|
|
42
|
+
args.push("--ignore-workspace");
|
|
32
43
|
const process = x("pnpm", args, {
|
|
33
44
|
throwOnError: true,
|
|
34
45
|
nodeOptions: {
|
|
@@ -36,7 +47,7 @@ async function getDependenciesTree(options) {
|
|
|
36
47
|
cwd: options.cwd
|
|
37
48
|
}
|
|
38
49
|
});
|
|
39
|
-
const json = await import('./json-parse-stream.mjs').then((r) => r.
|
|
50
|
+
const json = await import('./json-parse-stream.mjs').then((r) => r.parseJsonStreamWithConcatArrays(process.process.stdout));
|
|
40
51
|
if (!Array.isArray(json))
|
|
41
52
|
throw new Error(`Failed to parse \`pnpm ls\` output, expected an array but got: ${String(json)}`);
|
|
42
53
|
return json;
|
|
@@ -833,5 +833,26 @@ function parseJsonStream(stream) {
|
|
|
833
833
|
});
|
|
834
834
|
});
|
|
835
835
|
}
|
|
836
|
+
function parseJsonStreamWithConcatArrays(stream) {
|
|
837
|
+
const assembler = new Assembler();
|
|
838
|
+
const parser = StreamJSON.parser({
|
|
839
|
+
jsonStreaming: true
|
|
840
|
+
});
|
|
841
|
+
const values = [];
|
|
842
|
+
return new Promise((resolve) => {
|
|
843
|
+
parser.on("data", (chunk) => {
|
|
844
|
+
assembler[chunk.name]?.(chunk.value);
|
|
845
|
+
if (assembler.done) {
|
|
846
|
+
if (!Array.isArray(assembler.current))
|
|
847
|
+
throw new Error(`Expected an array but got: ${String(assembler.current)}`);
|
|
848
|
+
values.push(...assembler.current);
|
|
849
|
+
}
|
|
850
|
+
});
|
|
851
|
+
stream.pipe(parser);
|
|
852
|
+
parser.on("end", () => {
|
|
853
|
+
resolve(values);
|
|
854
|
+
});
|
|
855
|
+
});
|
|
856
|
+
}
|
|
836
857
|
|
|
837
|
-
export { parseJsonStream };
|
|
858
|
+
export { parseJsonStream, parseJsonStreamWithConcatArrays };
|
package/dist/index.d.mts
CHANGED
|
@@ -78,6 +78,10 @@ interface ListPackageDependenciesOptions extends BaseOptions {
|
|
|
78
78
|
* Filter if a package should be included and continue traversing
|
|
79
79
|
*/
|
|
80
80
|
traverseFilter?: (node: PackageNodeRaw) => boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Filter if workspace should be recognized
|
|
83
|
+
*/
|
|
84
|
+
workspace?: boolean;
|
|
81
85
|
/**
|
|
82
86
|
* Filter whether a package's dependencies should be included
|
|
83
87
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -78,6 +78,10 @@ interface ListPackageDependenciesOptions extends BaseOptions {
|
|
|
78
78
|
* Filter if a package should be included and continue traversing
|
|
79
79
|
*/
|
|
80
80
|
traverseFilter?: (node: PackageNodeRaw) => boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Filter if workspace should be recognized
|
|
83
|
+
*/
|
|
84
|
+
workspace?: boolean;
|
|
81
85
|
/**
|
|
82
86
|
* Filter whether a package's dependencies should be included
|
|
83
87
|
*/
|