node-modules-tools 0.5.7 → 0.6.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.
@@ -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;
@@ -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
- throw new Error(`Expected an array but got: ${String(assembler.current)}`);
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/dist/index.d.mts CHANGED
@@ -3,7 +3,7 @@ import { P as PackageNodeRaw, a as PackageNodeBase, b as PackageNode } from './s
3
3
  export { d as CLUSTER_DEP_DEV, e as CLUSTER_DEP_OPTIONAL, C as CLUSTER_DEP_PROD, F as FileCategory, N as NpmMeta, h as NpmMetaLatest, i as PackageInstallSizeInfo, g as PackageModuleType, f as PackageModuleTypeSimple, c as PackageModuleTypes } from './shared/node-modules-tools.rYmxZoRW.mjs';
4
4
  export { PackageJson } from 'pkg-types';
5
5
  export { Message as PublintMessage } from 'publint';
6
- export { NormalizedFunding, PackageNodeLike, ParsedFunding, constructPackageFilter, constructPackageFilters, normalizePkgAuthors, normalizePkgFundings, normalizePkgRepository, parseAuthor, parseFunding } from './utils.mjs';
6
+ export { NormalizedFunding, PackageNodeLike, ParsedFunding, ParsedLicense, constructPackageFilter, constructPackageFilters, normalizePkgAuthors, normalizePkgFundings, normalizePkgLicense, normalizePkgRepository, parseAuthor, parseFunding } from './utils.mjs';
7
7
 
8
8
  interface BaseOptions {
9
9
  /**
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import { P as PackageNodeRaw, a as PackageNodeBase, b as PackageNode } from './s
3
3
  export { d as CLUSTER_DEP_DEV, e as CLUSTER_DEP_OPTIONAL, C as CLUSTER_DEP_PROD, F as FileCategory, N as NpmMeta, h as NpmMetaLatest, i as PackageInstallSizeInfo, g as PackageModuleType, f as PackageModuleTypeSimple, c as PackageModuleTypes } from './shared/node-modules-tools.rYmxZoRW.js';
4
4
  export { PackageJson } from 'pkg-types';
5
5
  export { Message as PublintMessage } from 'publint';
6
- export { NormalizedFunding, PackageNodeLike, ParsedFunding, constructPackageFilter, constructPackageFilters, normalizePkgAuthors, normalizePkgFundings, normalizePkgRepository, parseAuthor, parseFunding } from './utils.js';
6
+ export { NormalizedFunding, PackageNodeLike, ParsedFunding, ParsedLicense, constructPackageFilter, constructPackageFilters, normalizePkgAuthors, normalizePkgFundings, normalizePkgLicense, normalizePkgRepository, parseAuthor, parseFunding } from './utils.js';
7
7
 
8
8
  interface BaseOptions {
9
9
  /**
package/dist/index.mjs CHANGED
@@ -2,8 +2,8 @@ export { CLUSTER_DEP_DEV, CLUSTER_DEP_OPTIONAL, CLUSTER_DEP_PROD, PackageModuleT
2
2
  import pLimit from 'p-limit';
3
3
  import { detect } from 'package-manager-detector';
4
4
  import fs from 'node:fs/promises';
5
- import { o as objectPick } from './shared/node-modules-tools.ByQH5a4n.mjs';
6
- export { c as constructPackageFilter, a as constructPackageFilters, d as normalizePkgAuthors, n as normalizePkgFundings, e as normalizePkgRepository, b as parseAuthor, p as parseFunding } from './shared/node-modules-tools.ByQH5a4n.mjs';
5
+ import { o as objectPick } from './shared/node-modules-tools.CC43M-MZ.mjs';
6
+ export { c as constructPackageFilter, a as constructPackageFilters, e as normalizePkgAuthors, b as normalizePkgFundings, n as normalizePkgLicense, f as normalizePkgRepository, d as parseAuthor, p as parseFunding } from './shared/node-modules-tools.CC43M-MZ.mjs';
7
7
  import { join as join$1 } from 'pathe';
8
8
  import { relative, join } from 'node:path';
9
9
  import 'semver';
@@ -308,6 +308,7 @@ const PACKAGE_JSON_KEYS = [
308
308
  "imports",
309
309
  "keywords",
310
310
  "license",
311
+ "licenses",
311
312
  "main",
312
313
  "module",
313
314
  "name",
@@ -68,6 +68,23 @@ function parseFunding(funding) {
68
68
  avatar
69
69
  };
70
70
  }
71
+ function normalizePkgLicense(json) {
72
+ const _json = json;
73
+ switch (typeof _json.license) {
74
+ case "string":
75
+ return _json.license;
76
+ case "object":
77
+ return _json.license.type;
78
+ }
79
+ if (Array.isArray(_json.licenses)) {
80
+ if (!_json.licenses.length)
81
+ return;
82
+ if (_json.licenses.length === 1) {
83
+ return _json.licenses[0].type;
84
+ }
85
+ return `(${_json.licenses.map((l) => l.type).join(" OR ")})`;
86
+ }
87
+ }
71
88
  function normalizePkgFundings(json) {
72
89
  const rawFunding = json.funding;
73
90
  let fundings;
@@ -144,4 +161,4 @@ function normalizePkgRepository(json) {
144
161
  };
145
162
  }
146
163
 
147
- export { constructPackageFilters as a, parseAuthor as b, constructPackageFilter as c, normalizePkgAuthors as d, normalizePkgRepository as e, normalizePkgFundings as n, objectPick as o, parseFunding as p };
164
+ export { constructPackageFilters as a, normalizePkgFundings as b, constructPackageFilter as c, parseAuthor as d, normalizePkgAuthors as e, normalizePkgRepository as f, normalizePkgLicense as n, objectPick as o, parseFunding as p };
package/dist/utils.d.mts CHANGED
@@ -28,6 +28,8 @@ interface ParsedFunding {
28
28
  avatar?: string;
29
29
  }
30
30
  declare function parseFunding(funding: NormalizedFunding): ParsedFunding;
31
+ type ParsedLicense = string;
32
+ declare function normalizePkgLicense(json: PackageJson): ParsedLicense | undefined;
31
33
  declare function normalizePkgFundings(json: PackageJson): ParsedFunding[] | undefined;
32
34
  declare function parseAuthor(author?: string): undefined;
33
35
  declare function normalizePkgAuthors(json: PackageJson): {
@@ -41,4 +43,4 @@ declare function normalizePkgRepository(json: PackageJson): {
41
43
  org: string | undefined;
42
44
  } | undefined;
43
45
 
44
- export { type NormalizedFunding, type PackageNodeLike, type ParsedFunding, constructPackageFilter, constructPackageFilters, normalizePkgAuthors, normalizePkgFundings, normalizePkgRepository, parseAuthor, parseFunding };
46
+ export { type NormalizedFunding, type PackageNodeLike, type ParsedFunding, type ParsedLicense, constructPackageFilter, constructPackageFilters, normalizePkgAuthors, normalizePkgFundings, normalizePkgLicense, normalizePkgRepository, parseAuthor, parseFunding };
package/dist/utils.d.ts CHANGED
@@ -28,6 +28,8 @@ interface ParsedFunding {
28
28
  avatar?: string;
29
29
  }
30
30
  declare function parseFunding(funding: NormalizedFunding): ParsedFunding;
31
+ type ParsedLicense = string;
32
+ declare function normalizePkgLicense(json: PackageJson): ParsedLicense | undefined;
31
33
  declare function normalizePkgFundings(json: PackageJson): ParsedFunding[] | undefined;
32
34
  declare function parseAuthor(author?: string): undefined;
33
35
  declare function normalizePkgAuthors(json: PackageJson): {
@@ -41,4 +43,4 @@ declare function normalizePkgRepository(json: PackageJson): {
41
43
  org: string | undefined;
42
44
  } | undefined;
43
45
 
44
- export { type NormalizedFunding, type PackageNodeLike, type ParsedFunding, constructPackageFilter, constructPackageFilters, normalizePkgAuthors, normalizePkgFundings, normalizePkgRepository, parseAuthor, parseFunding };
46
+ export { type NormalizedFunding, type PackageNodeLike, type ParsedFunding, type ParsedLicense, constructPackageFilter, constructPackageFilters, normalizePkgAuthors, normalizePkgFundings, normalizePkgLicense, normalizePkgRepository, parseAuthor, parseFunding };
package/dist/utils.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export { c as constructPackageFilter, a as constructPackageFilters, d as normalizePkgAuthors, n as normalizePkgFundings, e as normalizePkgRepository, b as parseAuthor, p as parseFunding } from './shared/node-modules-tools.ByQH5a4n.mjs';
1
+ export { c as constructPackageFilter, a as constructPackageFilters, e as normalizePkgAuthors, b as normalizePkgFundings, n as normalizePkgLicense, f as normalizePkgRepository, d as parseAuthor, p as parseFunding } from './shared/node-modules-tools.CC43M-MZ.mjs';
2
2
  import 'semver';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-modules-tools",
3
3
  "type": "module",
4
- "version": "0.5.7",
4
+ "version": "0.6.1",
5
5
  "description": "Tools for inspecting node_modules",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -32,13 +32,13 @@
32
32
  "package-manager-detector": "^1.1.0",
33
33
  "pathe": "^2.0.3",
34
34
  "pkg-types": "^2.1.0",
35
- "publint": "^0.3.9",
35
+ "publint": "^0.3.10",
36
36
  "semver": "^7.7.1",
37
- "tinyexec": "^1.0.0"
37
+ "tinyexec": "^1.0.1"
38
38
  },
39
39
  "devDependencies": {
40
- "@pnpm/list": "^1000.0.12",
41
- "@pnpm/types": "^1000.2.1",
40
+ "@pnpm/list": "^1000.0.13",
41
+ "@pnpm/types": "^1000.3.0",
42
42
  "@types/js-yaml": "^4.0.9",
43
43
  "@types/stream-json": "^1.7.8",
44
44
  "stream-json": "^1.9.1",