node-modules-tools 0.5.0 → 0.5.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.
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.Bnm4jx4C.mjs';
4
4
  export { PackageJson } from 'pkg-types';
5
5
  export { Message as PublintMessage } from 'publint';
6
- export { NormalizedFunding, PackageNodeLike, ParsedFunding, constructPackageFilter, constructPackageFilters, normalizePkgAuthor, normalizePkgFundings, normalizePkgRepository, parseAuthor, parseFunding } from './utils.mjs';
6
+ export { NormalizedFunding, PackageNodeLike, ParsedFunding, constructPackageFilter, constructPackageFilters, normalizePkgAuthors, normalizePkgFundings, 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.Bnm4jx4C.js';
4
4
  export { PackageJson } from 'pkg-types';
5
5
  export { Message as PublintMessage } from 'publint';
6
- export { NormalizedFunding, PackageNodeLike, ParsedFunding, constructPackageFilter, constructPackageFilters, normalizePkgAuthor, normalizePkgFundings, normalizePkgRepository, parseAuthor, parseFunding } from './utils.js';
6
+ export { NormalizedFunding, PackageNodeLike, ParsedFunding, constructPackageFilter, constructPackageFilters, normalizePkgAuthors, normalizePkgFundings, normalizePkgRepository, parseAuthor, parseFunding } from './utils.js';
7
7
 
8
8
  interface BaseOptions {
9
9
  /**
package/dist/index.mjs CHANGED
@@ -2,9 +2,10 @@ 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
7
  import { join as join$1 } from 'pathe';
6
8
  import { relative, join } from 'node:path';
7
- export { c as constructPackageFilter, a as constructPackageFilters, d as normalizePkgAuthor, n as normalizePkgFundings, e as normalizePkgRepository, b as parseAuthor, p as parseFunding } from './shared/node-modules-tools.D5TyCC_Y.mjs';
8
9
  import 'semver';
9
10
 
10
11
  async function getPackageManager(options) {
@@ -96,16 +97,6 @@ function populateRawResult(input) {
96
97
  return result;
97
98
  }
98
99
 
99
- function objectPick(obj, keys, omitUndefined = false) {
100
- return keys.reduce((n, k) => {
101
- if (k in obj) {
102
- if (!omitUndefined || obj[k] !== void 0)
103
- n[k] = obj[k];
104
- }
105
- return n;
106
- }, {});
107
- }
108
-
109
100
  function analyzePackageModuleType(pkgJson) {
110
101
  if (pkgJson.name?.startsWith("@types/"))
111
102
  return "dts";
@@ -297,6 +288,7 @@ function guessFileCategory(file) {
297
288
 
298
289
  const PACKAGE_JSON_KEYS = [
299
290
  "author",
291
+ "authors",
300
292
  "bin",
301
293
  "bugs",
302
294
  "dependencies",
@@ -305,6 +297,7 @@ const PACKAGE_JSON_KEYS = [
305
297
  "engines",
306
298
  "exports",
307
299
  "funding",
300
+ "fundings",
308
301
  "homepage",
309
302
  "imports",
310
303
  "keywords",
@@ -1,5 +1,19 @@
1
1
  import { satisfies } from 'semver';
2
2
 
3
+ function toArray(array) {
4
+ array = array ?? [];
5
+ return Array.isArray(array) ? array : [array];
6
+ }
7
+ function objectPick(obj, keys, omitUndefined = false) {
8
+ return keys.reduce((n, k) => {
9
+ if (k in obj) {
10
+ if (!omitUndefined || obj[k] !== void 0)
11
+ n[k] = obj[k];
12
+ }
13
+ return n;
14
+ }, {});
15
+ }
16
+
3
17
  function constructPackageFilter(range) {
4
18
  const [name, version = "*"] = range.split(/\b@/);
5
19
  const hasWildcard = name?.includes("*");
@@ -72,40 +86,62 @@ function parseAuthor(author) {
72
86
  if (!author)
73
87
  return void 0;
74
88
  }
75
- function normalizePkgAuthor(json) {
76
- const author = json.author;
77
- if (!author)
89
+ function normalizePkgAuthors(json) {
90
+ const authors = [
91
+ ...toArray(json.authors),
92
+ ...toArray(json.author)
93
+ ].filter(Boolean);
94
+ if (!authors.length)
78
95
  return void 0;
79
- if (typeof author === "string") {
80
- let url;
81
- const name = author.replace(/<.*>/, "").replace(/\(.*\)/, "").replace(/^https?:\/\//, "");
82
- return {
83
- name,
84
- url
85
- };
86
- }
87
- return {
88
- name: author.name,
89
- url: author.url
90
- };
96
+ return authors.map((author) => {
97
+ if (typeof author === "string") {
98
+ let url;
99
+ const name = author.replace(/<.*>/, "").replace(/\(.*\)/, "").replace(/^https?:\/\//, "").trim();
100
+ return {
101
+ name,
102
+ url
103
+ };
104
+ } else {
105
+ return {
106
+ name: author.name,
107
+ url: author.url
108
+ };
109
+ }
110
+ });
91
111
  }
92
112
  function normalizePkgRepository(json) {
93
- if (!json.repository)
113
+ if (!json.repository && !json.bugs)
94
114
  return void 0;
95
115
  let url = typeof json.repository === "string" ? json.repository : json.repository?.url;
96
- if (url?.startsWith("git+"))
97
- url = url.slice(4);
98
- if (url?.endsWith(".git"))
99
- url = url.slice(0, -4);
100
- if (url?.startsWith("git://"))
101
- url = `https://${url.slice(6)}`;
116
+ url = url?.replace(/^github:/, "").replace(/^git@github\.com:/, "");
117
+ if (url && /^[a-z0-9][-.\w]*\/[a-z0-9][-.\w]*$/i.test(url))
118
+ url = `https://github.com/${url}`;
119
+ url = url?.replace(/^git\+/, "").replace(/\.git$/, "").replace(/^git:\/\//, "https://").replace(/^ssh:\/\//, "https://").replace(/git@github\.com/, "github.com");
102
120
  if (json.repository && typeof json.repository !== "string" && json.repository.directory)
103
121
  url += `/tree/HEAD/${json.repository.directory}`;
104
- if (/^[a-z0-9]+(?:[-_.][a-z0-9]+)*\/[a-z0-9]+(?:[-_.][a-z0-9]+)*$/i.test(url))
105
- url = `https://github.com/${url}`;
122
+ if (!url) {
123
+ const bugsUrl = typeof json.bugs === "string" ? json.bugs : json.bugs?.url;
124
+ if (bugsUrl && bugsUrl.startsWith("https://github.com/"))
125
+ url = bugsUrl.replace(/\/issues$/, "");
126
+ }
127
+ if (!url)
128
+ return void 0;
129
+ url = url.trim();
130
+ let repo;
131
+ let org;
132
+ let repoName;
133
+ const gitHubUrlMatch = url.match(/^https?:\/\/(?:www\.)?github\.com\/([^/]+)\/([^/]+)/);
134
+ if (gitHubUrlMatch) {
135
+ org = gitHubUrlMatch[1];
136
+ repoName = gitHubUrlMatch[2];
137
+ repo = `${org}/${repoName}`;
138
+ }
106
139
  return {
107
- url
140
+ url,
141
+ repo,
142
+ repoName,
143
+ org
108
144
  };
109
145
  }
110
146
 
111
- export { constructPackageFilters as a, parseAuthor as b, constructPackageFilter as c, normalizePkgAuthor as d, normalizePkgRepository as e, normalizePkgFundings as n, parseFunding as p };
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 };
package/dist/utils.d.mts CHANGED
@@ -30,12 +30,15 @@ interface ParsedFunding {
30
30
  declare function parseFunding(funding: NormalizedFunding): ParsedFunding;
31
31
  declare function normalizePkgFundings(json: PackageJson): ParsedFunding[] | undefined;
32
32
  declare function parseAuthor(author?: string): undefined;
33
- declare function normalizePkgAuthor(json: PackageJson): {
34
- name: string;
35
- url: string | undefined;
36
- } | undefined;
33
+ declare function normalizePkgAuthors(json: PackageJson): {
34
+ name: any;
35
+ url: any;
36
+ }[] | undefined;
37
37
  declare function normalizePkgRepository(json: PackageJson): {
38
38
  url: string;
39
+ repo: string | undefined;
40
+ repoName: string | undefined;
41
+ org: string | undefined;
39
42
  } | undefined;
40
43
 
41
- export { type NormalizedFunding, type PackageNodeLike, type ParsedFunding, constructPackageFilter, constructPackageFilters, normalizePkgAuthor, normalizePkgFundings, normalizePkgRepository, parseAuthor, parseFunding };
44
+ export { type NormalizedFunding, type PackageNodeLike, type ParsedFunding, constructPackageFilter, constructPackageFilters, normalizePkgAuthors, normalizePkgFundings, normalizePkgRepository, parseAuthor, parseFunding };
package/dist/utils.d.ts CHANGED
@@ -30,12 +30,15 @@ interface ParsedFunding {
30
30
  declare function parseFunding(funding: NormalizedFunding): ParsedFunding;
31
31
  declare function normalizePkgFundings(json: PackageJson): ParsedFunding[] | undefined;
32
32
  declare function parseAuthor(author?: string): undefined;
33
- declare function normalizePkgAuthor(json: PackageJson): {
34
- name: string;
35
- url: string | undefined;
36
- } | undefined;
33
+ declare function normalizePkgAuthors(json: PackageJson): {
34
+ name: any;
35
+ url: any;
36
+ }[] | undefined;
37
37
  declare function normalizePkgRepository(json: PackageJson): {
38
38
  url: string;
39
+ repo: string | undefined;
40
+ repoName: string | undefined;
41
+ org: string | undefined;
39
42
  } | undefined;
40
43
 
41
- export { type NormalizedFunding, type PackageNodeLike, type ParsedFunding, constructPackageFilter, constructPackageFilters, normalizePkgAuthor, normalizePkgFundings, normalizePkgRepository, parseAuthor, parseFunding };
44
+ export { type NormalizedFunding, type PackageNodeLike, type ParsedFunding, constructPackageFilter, constructPackageFilters, normalizePkgAuthors, normalizePkgFundings, normalizePkgRepository, parseAuthor, parseFunding };
package/dist/utils.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export { c as constructPackageFilter, a as constructPackageFilters, d as normalizePkgAuthor, n as normalizePkgFundings, e as normalizePkgRepository, b as parseAuthor, p as parseFunding } from './shared/node-modules-tools.D5TyCC_Y.mjs';
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';
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.0",
4
+ "version": "0.5.2",
5
5
  "description": "Tools for inspecting node_modules",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -37,7 +37,7 @@
37
37
  "tinyexec": "^0.3.2"
38
38
  },
39
39
  "devDependencies": {
40
- "@pnpm/list": "^1000.0.10",
40
+ "@pnpm/list": "^1000.0.11",
41
41
  "@pnpm/types": "^1000.2.1",
42
42
  "@types/js-yaml": "^4.0.9",
43
43
  "@types/stream-json": "^1.7.8",