node-modules-tools 0.2.0 → 0.2.2

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.
@@ -3,15 +3,24 @@ import { x } from 'tinyexec';
3
3
 
4
4
  async function resolveRoot(options) {
5
5
  let raw;
6
- try {
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.parseJsonStream(process.process.stdout));
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
@@ -57,7 +57,10 @@ interface PackageNode extends PackageNodeBase {
57
57
  license?: string;
58
58
  author?: string;
59
59
  repository?: string;
60
- funding?: string;
60
+ funding?: {
61
+ url?: string;
62
+ type?: string;
63
+ };
61
64
  homepage?: string;
62
65
  engines?: Record<string, string>;
63
66
  installSize?: PackageInstallSizeInfo;
@@ -78,6 +81,10 @@ interface ListPackageDependenciesOptions extends BaseOptions {
78
81
  * Filter if a package should be included and continue traversing
79
82
  */
80
83
  traverseFilter?: (node: PackageNodeRaw) => boolean;
84
+ /**
85
+ * Filter if workspace should be recognized
86
+ */
87
+ workspace?: boolean;
81
88
  /**
82
89
  * Filter whether a package's dependencies should be included
83
90
  */
package/dist/index.d.ts CHANGED
@@ -57,7 +57,10 @@ interface PackageNode extends PackageNodeBase {
57
57
  license?: string;
58
58
  author?: string;
59
59
  repository?: string;
60
- funding?: string;
60
+ funding?: {
61
+ url?: string;
62
+ type?: string;
63
+ };
61
64
  homepage?: string;
62
65
  engines?: Record<string, string>;
63
66
  installSize?: PackageInstallSizeInfo;
@@ -78,6 +81,10 @@ interface ListPackageDependenciesOptions extends BaseOptions {
78
81
  * Filter if a package should be included and continue traversing
79
82
  */
80
83
  traverseFilter?: (node: PackageNodeRaw) => boolean;
84
+ /**
85
+ * Filter if workspace should be recognized
86
+ */
87
+ workspace?: boolean;
81
88
  /**
82
89
  * Filter whether a package's dependencies should be included
83
90
  */
package/dist/index.mjs CHANGED
@@ -298,12 +298,15 @@ async function resolvePackage(_packageManager, pkg, _options) {
298
298
  repository = `https://${repository.slice(6)}`;
299
299
  if (json.repository && typeof json.repository !== "string" && json.repository.directory)
300
300
  repository += `/tree/HEAD/${json.repository.directory}`;
301
+ let funding = json.funding;
302
+ if (typeof funding === "string")
303
+ funding = { url: funding };
301
304
  _pkg.resolved = {
302
305
  module: analyzePackageModuleType(json),
303
306
  engines: json.engines,
304
307
  license: json.license,
305
308
  author: typeof json.author === "string" ? json.author : json.author?.url,
306
- funding: json.funding,
309
+ funding,
307
310
  repository,
308
311
  homepage: json.homepage,
309
312
  installSize: await getPackageInstallSize(_pkg)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-modules-tools",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.2.2",
5
5
  "description": "Tools for inspecting node_modules",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -27,18 +27,18 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "p-limit": "^6.2.0",
30
- "package-manager-detector": "^0.2.9",
30
+ "package-manager-detector": "^0.2.10",
31
31
  "pathe": "^2.0.3",
32
32
  "semver": "^7.7.1",
33
33
  "tinyexec": "^0.3.2"
34
34
  },
35
35
  "devDependencies": {
36
- "@pnpm/list": "^1000.0.8",
37
- "@pnpm/types": "^1000.1.1",
36
+ "@pnpm/list": "^1000.0.9",
37
+ "@pnpm/types": "^1000.2.0",
38
38
  "@types/stream-json": "^1.7.8",
39
- "pkg-types": "^1.3.1",
39
+ "pkg-types": "^2.0.0",
40
40
  "stream-json": "^1.9.1",
41
- "unbuild": "^3.3.1"
41
+ "unbuild": "^3.5.0"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "unbuild",