node-modules-tools 0.4.3 → 0.5.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/constants.d.mts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +27 -26
- package/dist/shared/{node-modules-tools.CX5_YEVA.d.mts → node-modules-tools.Bnm4jx4C.d.mts} +2 -11
- package/dist/shared/{node-modules-tools.CX5_YEVA.d.ts → node-modules-tools.Bnm4jx4C.d.ts} +2 -11
- package/dist/shared/node-modules-tools.ByQH5a4n.mjs +147 -0
- package/dist/utils.d.mts +28 -1
- package/dist/utils.d.ts +28 -1
- package/dist/utils.mjs +1 -1
- package/package.json +2 -2
- package/dist/shared/node-modules-tools.DT_mm7wI.mjs +0 -18
package/dist/constants.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { d as CLUSTER_DEP_DEV, e as CLUSTER_DEP_OPTIONAL, C as CLUSTER_DEP_PROD, c as PackageModuleTypes } from './shared/node-modules-tools.
|
|
1
|
+
export { d as CLUSTER_DEP_DEV, e as CLUSTER_DEP_OPTIONAL, C as CLUSTER_DEP_PROD, c as PackageModuleTypes } from './shared/node-modules-tools.Bnm4jx4C.mjs';
|
|
2
2
|
import 'pkg-types';
|
|
3
3
|
import 'publint';
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { d as CLUSTER_DEP_DEV, e as CLUSTER_DEP_OPTIONAL, C as CLUSTER_DEP_PROD, c as PackageModuleTypes } from './shared/node-modules-tools.
|
|
1
|
+
export { d as CLUSTER_DEP_DEV, e as CLUSTER_DEP_OPTIONAL, C as CLUSTER_DEP_PROD, c as PackageModuleTypes } from './shared/node-modules-tools.Bnm4jx4C.js';
|
|
2
2
|
import 'pkg-types';
|
|
3
3
|
import 'publint';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AgentName } from 'package-manager-detector';
|
|
2
|
-
import { P as PackageNodeRaw, a as PackageNodeBase, b as PackageNode } from './shared/node-modules-tools.
|
|
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.
|
|
2
|
+
import { P as PackageNodeRaw, a as PackageNodeBase, b as PackageNode } from './shared/node-modules-tools.Bnm4jx4C.mjs';
|
|
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
|
+
export { PackageJson } from 'pkg-types';
|
|
4
5
|
export { Message as PublintMessage } from 'publint';
|
|
5
|
-
export { PackageNodeLike, constructPackageFilter, constructPackageFilters } from './utils.mjs';
|
|
6
|
-
import 'pkg-types';
|
|
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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AgentName } from 'package-manager-detector';
|
|
2
|
-
import { P as PackageNodeRaw, a as PackageNodeBase, b as PackageNode } from './shared/node-modules-tools.
|
|
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.
|
|
2
|
+
import { P as PackageNodeRaw, a as PackageNodeBase, b as PackageNode } from './shared/node-modules-tools.Bnm4jx4C.js';
|
|
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
|
+
export { PackageJson } from 'pkg-types';
|
|
4
5
|
export { Message as PublintMessage } from 'publint';
|
|
5
|
-
export { PackageNodeLike, constructPackageFilter, constructPackageFilters } from './utils.js';
|
|
6
|
-
import 'pkg-types';
|
|
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 } from './shared/node-modules-tools.DT_mm7wI.mjs';
|
|
8
9
|
import 'semver';
|
|
9
10
|
|
|
10
11
|
async function getPackageManager(options) {
|
|
@@ -285,39 +286,39 @@ function guessFileCategory(file) {
|
|
|
285
286
|
return "other";
|
|
286
287
|
}
|
|
287
288
|
|
|
289
|
+
const PACKAGE_JSON_KEYS = [
|
|
290
|
+
"author",
|
|
291
|
+
"authors",
|
|
292
|
+
"bin",
|
|
293
|
+
"bugs",
|
|
294
|
+
"dependencies",
|
|
295
|
+
"description",
|
|
296
|
+
"devDependencies",
|
|
297
|
+
"engines",
|
|
298
|
+
"exports",
|
|
299
|
+
"funding",
|
|
300
|
+
"fundings",
|
|
301
|
+
"homepage",
|
|
302
|
+
"imports",
|
|
303
|
+
"keywords",
|
|
304
|
+
"license",
|
|
305
|
+
"main",
|
|
306
|
+
"module",
|
|
307
|
+
"name",
|
|
308
|
+
"optionalDependencies",
|
|
309
|
+
"repository",
|
|
310
|
+
"types",
|
|
311
|
+
"version"
|
|
312
|
+
];
|
|
288
313
|
async function resolvePackage(_packageManager, pkg, _options) {
|
|
289
314
|
const _pkg = pkg;
|
|
290
315
|
if (_pkg.resolved)
|
|
291
316
|
return _pkg;
|
|
292
317
|
const content = await fs.readFile(join$1(pkg.filepath, "package.json"), "utf-8");
|
|
293
318
|
const json = JSON.parse(stripBomTag(content));
|
|
294
|
-
let repository = typeof json.repository === "string" ? json.repository : json.repository?.url;
|
|
295
|
-
if (repository?.startsWith("git+"))
|
|
296
|
-
repository = repository.slice(4);
|
|
297
|
-
if (repository?.endsWith(".git"))
|
|
298
|
-
repository = repository.slice(0, -4);
|
|
299
|
-
if (repository?.startsWith("git://"))
|
|
300
|
-
repository = `https://${repository.slice(6)}`;
|
|
301
|
-
if (json.repository && typeof json.repository !== "string" && json.repository.directory)
|
|
302
|
-
repository += `/tree/HEAD/${json.repository.directory}`;
|
|
303
|
-
const rawFunding = json.funding;
|
|
304
|
-
let fundings;
|
|
305
|
-
if (typeof rawFunding === "string") {
|
|
306
|
-
fundings = [{ url: rawFunding }];
|
|
307
|
-
} else if (Array.isArray(rawFunding)) {
|
|
308
|
-
fundings = rawFunding.map((f) => typeof f === "string" ? { url: f } : f);
|
|
309
|
-
} else {
|
|
310
|
-
fundings = rawFunding ? [rawFunding] : [];
|
|
311
|
-
}
|
|
312
319
|
_pkg.resolved = {
|
|
313
320
|
module: analyzePackageModuleType(json),
|
|
314
|
-
|
|
315
|
-
license: json.license,
|
|
316
|
-
author: typeof json.author === "string" ? json.author : json.author?.url,
|
|
317
|
-
fundings,
|
|
318
|
-
exports: json.exports,
|
|
319
|
-
repository,
|
|
320
|
-
homepage: json.homepage,
|
|
321
|
+
packageJson: objectPick(json, PACKAGE_JSON_KEYS),
|
|
321
322
|
installSize: await getPackageInstallSize(_pkg)
|
|
322
323
|
};
|
|
323
324
|
return _pkg;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PackageJson } from 'pkg-types';
|
|
2
2
|
import { Message } from 'publint';
|
|
3
3
|
|
|
4
4
|
interface PackageInstallSizeInfo {
|
|
@@ -51,16 +51,7 @@ interface PackageNodeBase extends PackageNodeRaw {
|
|
|
51
51
|
interface PackageNode extends PackageNodeBase {
|
|
52
52
|
resolved: {
|
|
53
53
|
module: PackageModuleType;
|
|
54
|
-
|
|
55
|
-
author?: string;
|
|
56
|
-
repository?: string;
|
|
57
|
-
fundings?: {
|
|
58
|
-
url: string;
|
|
59
|
-
type?: string;
|
|
60
|
-
}[];
|
|
61
|
-
exports?: PackageJsonExports;
|
|
62
|
-
homepage?: string;
|
|
63
|
-
engines?: Record<string, string>;
|
|
54
|
+
packageJson: PackageJson;
|
|
64
55
|
installSize?: PackageInstallSizeInfo;
|
|
65
56
|
npmMeta?: NpmMeta;
|
|
66
57
|
npmMetaLatest?: NpmMetaLatest;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PackageJson } from 'pkg-types';
|
|
2
2
|
import { Message } from 'publint';
|
|
3
3
|
|
|
4
4
|
interface PackageInstallSizeInfo {
|
|
@@ -51,16 +51,7 @@ interface PackageNodeBase extends PackageNodeRaw {
|
|
|
51
51
|
interface PackageNode extends PackageNodeBase {
|
|
52
52
|
resolved: {
|
|
53
53
|
module: PackageModuleType;
|
|
54
|
-
|
|
55
|
-
author?: string;
|
|
56
|
-
repository?: string;
|
|
57
|
-
fundings?: {
|
|
58
|
-
url: string;
|
|
59
|
-
type?: string;
|
|
60
|
-
}[];
|
|
61
|
-
exports?: PackageJsonExports;
|
|
62
|
-
homepage?: string;
|
|
63
|
-
engines?: Record<string, string>;
|
|
54
|
+
packageJson: PackageJson;
|
|
64
55
|
installSize?: PackageInstallSizeInfo;
|
|
65
56
|
npmMeta?: NpmMeta;
|
|
66
57
|
npmMetaLatest?: NpmMetaLatest;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { satisfies } from 'semver';
|
|
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
|
+
|
|
17
|
+
function constructPackageFilter(range) {
|
|
18
|
+
const [name, version = "*"] = range.split(/\b@/);
|
|
19
|
+
const hasWildcard = name?.includes("*");
|
|
20
|
+
const nameMatch = hasWildcard ? new RegExp(`^${Array.from(name).map((char) => char === "*" ? ".*" : char === "." ? "\\." : char).join("")}$`) : name;
|
|
21
|
+
return (pkg) => {
|
|
22
|
+
const isNameMatch = nameMatch instanceof RegExp ? nameMatch.test(pkg.name) : pkg.name === name;
|
|
23
|
+
const isVersionMatch = version === "*" || pkg.version === version || satisfies(pkg.version, version);
|
|
24
|
+
return isNameMatch && isVersionMatch;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function constructPackageFilters(ranges, mode) {
|
|
28
|
+
const filters = ranges.map((x) => typeof x === "string" ? constructPackageFilter(x) : x);
|
|
29
|
+
return (pkg) => mode === "some" ? filters.some((filter) => filter(pkg)) : filters.every((filter) => filter(pkg));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function parseFunding(funding) {
|
|
33
|
+
const url = funding.url;
|
|
34
|
+
let name = "";
|
|
35
|
+
let type = funding.type || "link";
|
|
36
|
+
let avatar;
|
|
37
|
+
let match = url.match(/^(?:https?:\/\/)?(?:www\.)?github\.com\/sponsors\/([\w.-]+)/i);
|
|
38
|
+
if (match) {
|
|
39
|
+
name = match[1];
|
|
40
|
+
type = "github";
|
|
41
|
+
}
|
|
42
|
+
if (!name) {
|
|
43
|
+
match = url.match(/^(?:https?:\/\/)?(?:www\.)?github\.com\/([\w.-]+)/i);
|
|
44
|
+
if (match) {
|
|
45
|
+
name = match[1];
|
|
46
|
+
type = "github";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!name) {
|
|
50
|
+
match = url.match(/^(?:https?:\/\/)?(?:www\.)?opencollective\.com\/([\w.-]+)/i);
|
|
51
|
+
if (match) {
|
|
52
|
+
name = match[1];
|
|
53
|
+
type = "opencollective";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!name)
|
|
57
|
+
name = url.replace(/^(?:https?:\/\/)?(?:www\.)?/, "").replace(/\/$/, "");
|
|
58
|
+
if (type === "github" && name)
|
|
59
|
+
avatar = `https://avatars.antfu.dev/gh/${name}`;
|
|
60
|
+
if (type === "opencollective" && name)
|
|
61
|
+
avatar = `https://opencollective.com/${name}/avatar.png`;
|
|
62
|
+
const entry = `${type}@${name}`;
|
|
63
|
+
return {
|
|
64
|
+
url,
|
|
65
|
+
type,
|
|
66
|
+
entry,
|
|
67
|
+
name,
|
|
68
|
+
avatar
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function normalizePkgFundings(json) {
|
|
72
|
+
const rawFunding = json.funding;
|
|
73
|
+
let fundings;
|
|
74
|
+
if (typeof rawFunding === "string") {
|
|
75
|
+
fundings = [{ url: rawFunding }];
|
|
76
|
+
} else if (Array.isArray(rawFunding)) {
|
|
77
|
+
fundings = rawFunding.map((f) => typeof f === "string" ? { url: f } : f);
|
|
78
|
+
} else {
|
|
79
|
+
fundings = rawFunding ? [rawFunding] : [];
|
|
80
|
+
}
|
|
81
|
+
if (fundings.length === 0)
|
|
82
|
+
return void 0;
|
|
83
|
+
return fundings.map((f) => parseFunding(f)).filter(Boolean);
|
|
84
|
+
}
|
|
85
|
+
function parseAuthor(author) {
|
|
86
|
+
if (!author)
|
|
87
|
+
return void 0;
|
|
88
|
+
}
|
|
89
|
+
function normalizePkgAuthors(json) {
|
|
90
|
+
const authors = [
|
|
91
|
+
...toArray(json.authors),
|
|
92
|
+
...toArray(json.author)
|
|
93
|
+
].filter(Boolean);
|
|
94
|
+
if (!authors.length)
|
|
95
|
+
return void 0;
|
|
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
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function normalizePkgRepository(json) {
|
|
113
|
+
if (!json.repository && !json.bugs)
|
|
114
|
+
return void 0;
|
|
115
|
+
let url = typeof json.repository === "string" ? json.repository : json.repository?.url;
|
|
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");
|
|
120
|
+
if (json.repository && typeof json.repository !== "string" && json.repository.directory)
|
|
121
|
+
url += `/tree/HEAD/${json.repository.directory}`;
|
|
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
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
url,
|
|
141
|
+
repo,
|
|
142
|
+
repoName,
|
|
143
|
+
org
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { PackageJson } from 'pkg-types';
|
|
2
|
+
|
|
1
3
|
interface PackageNodeLike {
|
|
2
4
|
name: string;
|
|
3
5
|
version: string;
|
|
@@ -14,4 +16,29 @@ interface PackageNodeLike {
|
|
|
14
16
|
declare function constructPackageFilter(range: string): (pkg: PackageNodeLike) => boolean;
|
|
15
17
|
declare function constructPackageFilters<Node extends PackageNodeLike = PackageNodeLike>(ranges: (string | ((pkg: Node) => boolean))[], mode: 'some' | 'every'): (pkg: Node) => boolean;
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
interface NormalizedFunding {
|
|
20
|
+
url: string;
|
|
21
|
+
type?: string;
|
|
22
|
+
}
|
|
23
|
+
interface ParsedFunding {
|
|
24
|
+
url: string;
|
|
25
|
+
type: string;
|
|
26
|
+
name: string;
|
|
27
|
+
entry: string;
|
|
28
|
+
avatar?: string;
|
|
29
|
+
}
|
|
30
|
+
declare function parseFunding(funding: NormalizedFunding): ParsedFunding;
|
|
31
|
+
declare function normalizePkgFundings(json: PackageJson): ParsedFunding[] | undefined;
|
|
32
|
+
declare function parseAuthor(author?: string): undefined;
|
|
33
|
+
declare function normalizePkgAuthors(json: PackageJson): {
|
|
34
|
+
name: any;
|
|
35
|
+
url: any;
|
|
36
|
+
}[] | undefined;
|
|
37
|
+
declare function normalizePkgRepository(json: PackageJson): {
|
|
38
|
+
url: string;
|
|
39
|
+
repo: string | undefined;
|
|
40
|
+
repoName: string | undefined;
|
|
41
|
+
org: string | undefined;
|
|
42
|
+
} | undefined;
|
|
43
|
+
|
|
44
|
+
export { type NormalizedFunding, type PackageNodeLike, type ParsedFunding, constructPackageFilter, constructPackageFilters, normalizePkgAuthors, normalizePkgFundings, normalizePkgRepository, parseAuthor, parseFunding };
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { PackageJson } from 'pkg-types';
|
|
2
|
+
|
|
1
3
|
interface PackageNodeLike {
|
|
2
4
|
name: string;
|
|
3
5
|
version: string;
|
|
@@ -14,4 +16,29 @@ interface PackageNodeLike {
|
|
|
14
16
|
declare function constructPackageFilter(range: string): (pkg: PackageNodeLike) => boolean;
|
|
15
17
|
declare function constructPackageFilters<Node extends PackageNodeLike = PackageNodeLike>(ranges: (string | ((pkg: Node) => boolean))[], mode: 'some' | 'every'): (pkg: Node) => boolean;
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
interface NormalizedFunding {
|
|
20
|
+
url: string;
|
|
21
|
+
type?: string;
|
|
22
|
+
}
|
|
23
|
+
interface ParsedFunding {
|
|
24
|
+
url: string;
|
|
25
|
+
type: string;
|
|
26
|
+
name: string;
|
|
27
|
+
entry: string;
|
|
28
|
+
avatar?: string;
|
|
29
|
+
}
|
|
30
|
+
declare function parseFunding(funding: NormalizedFunding): ParsedFunding;
|
|
31
|
+
declare function normalizePkgFundings(json: PackageJson): ParsedFunding[] | undefined;
|
|
32
|
+
declare function parseAuthor(author?: string): undefined;
|
|
33
|
+
declare function normalizePkgAuthors(json: PackageJson): {
|
|
34
|
+
name: any;
|
|
35
|
+
url: any;
|
|
36
|
+
}[] | undefined;
|
|
37
|
+
declare function normalizePkgRepository(json: PackageJson): {
|
|
38
|
+
url: string;
|
|
39
|
+
repo: string | undefined;
|
|
40
|
+
repoName: string | undefined;
|
|
41
|
+
org: string | undefined;
|
|
42
|
+
} | undefined;
|
|
43
|
+
|
|
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 } from './shared/node-modules-tools.
|
|
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.
|
|
4
|
+
"version": "0.5.1",
|
|
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.
|
|
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",
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { satisfies } from 'semver';
|
|
2
|
-
|
|
3
|
-
function constructPackageFilter(range) {
|
|
4
|
-
const [name, version = "*"] = range.split(/\b@/);
|
|
5
|
-
const hasWildcard = name?.includes("*");
|
|
6
|
-
const nameMatch = hasWildcard ? new RegExp(`^${Array.from(name).map((char) => char === "*" ? ".*" : char === "." ? "\\." : char).join("")}$`) : name;
|
|
7
|
-
return (pkg) => {
|
|
8
|
-
const isNameMatch = nameMatch instanceof RegExp ? nameMatch.test(pkg.name) : pkg.name === name;
|
|
9
|
-
const isVersionMatch = version === "*" || pkg.version === version || satisfies(pkg.version, version);
|
|
10
|
-
return isNameMatch && isVersionMatch;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function constructPackageFilters(ranges, mode) {
|
|
14
|
-
const filters = ranges.map((x) => typeof x === "string" ? constructPackageFilter(x) : x);
|
|
15
|
-
return (pkg) => mode === "some" ? filters.some((filter) => filter(pkg)) : filters.every((filter) => filter(pkg));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { constructPackageFilters as a, constructPackageFilter as c };
|