node-modules-tools 1.3.1 → 1.4.0
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/README.md +1 -1
- package/dist/constants.d.mts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/index.d.mts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.mjs +68 -83
- package/dist/shared/{node-modules-tools.Ct6sDSTQ.d.mts → node-modules-tools.BWZx79LE.d.mts} +8 -2
- package/dist/shared/{node-modules-tools.Ct6sDSTQ.d.ts → node-modules-tools.BWZx79LE.d.ts} +8 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
<p align="center">
|
|
12
12
|
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
|
|
13
|
-
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
|
|
13
|
+
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg' alt='Sponsors' />
|
|
14
14
|
</a>
|
|
15
15
|
</p>
|
|
16
16
|
|
package/dist/constants.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { C as CLUSTER_DEP_DEV,
|
|
1
|
+
export { C as CLUSTER_DEP_DEV, d as CLUSTER_DEP_OPTIONAL, e as CLUSTER_DEP_PROD, i as PackageModuleTypes } from './shared/node-modules-tools.BWZx79LE.mjs';
|
|
2
2
|
import 'pkg-types';
|
|
3
3
|
import 'publint';
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { C as CLUSTER_DEP_DEV,
|
|
1
|
+
export { C as CLUSTER_DEP_DEV, d as CLUSTER_DEP_OPTIONAL, e as CLUSTER_DEP_PROD, i as PackageModuleTypes } from './shared/node-modules-tools.BWZx79LE.js';
|
|
2
2
|
import 'pkg-types';
|
|
3
3
|
import 'publint';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +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 { C as CLUSTER_DEP_DEV,
|
|
4
|
-
|
|
2
|
+
import { P as PackageNodeRaw, a as PackageNodeBase, b as PackageNode, c as PackageModuleType } from './shared/node-modules-tools.BWZx79LE.mjs';
|
|
3
|
+
export { A as AuditLevelString, C as CLUSTER_DEP_DEV, d as CLUSTER_DEP_OPTIONAL, e as CLUSTER_DEP_PROD, F as FileCategory, N as NpmMeta, f as NpmMetaLatest, g as PackageInstallSizeInfo, h as PackageModuleTypeSimple, i as PackageModuleTypes } from './shared/node-modules-tools.BWZx79LE.mjs';
|
|
4
|
+
import { PackageJson } from 'pkg-types';
|
|
5
5
|
export { PackageJson } from 'pkg-types';
|
|
6
|
+
export { NormalizedFunding, PackageNodeLike, ParsedFunding, ParsedLicense, constructPackageFilter, constructPackageFilters, normalizePkgAuthors, normalizePkgFundings, normalizePkgLicense, normalizePkgRepository, parseAuthor, parseFunding } from './utils.mjs';
|
|
6
7
|
export { Message as PublintMessage } from 'publint';
|
|
7
8
|
|
|
8
9
|
interface BaseOptions {
|
|
@@ -56,6 +57,8 @@ declare function getPackageManager(options: BaseOptions): Promise<AgentName>;
|
|
|
56
57
|
*/
|
|
57
58
|
declare function listPackageDependenciesRaw(manager: AgentName, options: ListPackageDependenciesOptions): Promise<ListPackageDependenciesBaseResult>;
|
|
58
59
|
|
|
60
|
+
declare function analyzePackageModuleType(pkgJson: PackageJson): PackageModuleType;
|
|
61
|
+
|
|
59
62
|
declare function listPackageDependencies(options: ListPackageDependenciesOptions): Promise<ListPackageDependenciesResult>;
|
|
60
63
|
|
|
61
64
|
/**
|
|
@@ -66,5 +69,5 @@ declare function listPackageDependencies(options: ListPackageDependenciesOptions
|
|
|
66
69
|
*/
|
|
67
70
|
declare function resolvePackage(_packageManager: AgentName, pkg: PackageNodeBase, _options: BaseOptions): Promise<PackageNode>;
|
|
68
71
|
|
|
69
|
-
export { PackageNode, PackageNodeBase, PackageNodeRaw, getPackageManager, listPackageDependencies, listPackageDependenciesRaw, resolvePackage };
|
|
72
|
+
export { PackageModuleType, PackageNode, PackageNodeBase, PackageNodeRaw, analyzePackageModuleType, getPackageManager, listPackageDependencies, listPackageDependenciesRaw, resolvePackage };
|
|
70
73
|
export type { BaseOptions, ListPackageDependenciesBaseResult, ListPackageDependenciesOptions, ListPackageDependenciesRawResult, ListPackageDependenciesResult };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +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 { C as CLUSTER_DEP_DEV,
|
|
4
|
-
|
|
2
|
+
import { P as PackageNodeRaw, a as PackageNodeBase, b as PackageNode, c as PackageModuleType } from './shared/node-modules-tools.BWZx79LE.js';
|
|
3
|
+
export { A as AuditLevelString, C as CLUSTER_DEP_DEV, d as CLUSTER_DEP_OPTIONAL, e as CLUSTER_DEP_PROD, F as FileCategory, N as NpmMeta, f as NpmMetaLatest, g as PackageInstallSizeInfo, h as PackageModuleTypeSimple, i as PackageModuleTypes } from './shared/node-modules-tools.BWZx79LE.js';
|
|
4
|
+
import { PackageJson } from 'pkg-types';
|
|
5
5
|
export { PackageJson } from 'pkg-types';
|
|
6
|
+
export { NormalizedFunding, PackageNodeLike, ParsedFunding, ParsedLicense, constructPackageFilter, constructPackageFilters, normalizePkgAuthors, normalizePkgFundings, normalizePkgLicense, normalizePkgRepository, parseAuthor, parseFunding } from './utils.js';
|
|
6
7
|
export { Message as PublintMessage } from 'publint';
|
|
7
8
|
|
|
8
9
|
interface BaseOptions {
|
|
@@ -56,6 +57,8 @@ declare function getPackageManager(options: BaseOptions): Promise<AgentName>;
|
|
|
56
57
|
*/
|
|
57
58
|
declare function listPackageDependenciesRaw(manager: AgentName, options: ListPackageDependenciesOptions): Promise<ListPackageDependenciesBaseResult>;
|
|
58
59
|
|
|
60
|
+
declare function analyzePackageModuleType(pkgJson: PackageJson): PackageModuleType;
|
|
61
|
+
|
|
59
62
|
declare function listPackageDependencies(options: ListPackageDependenciesOptions): Promise<ListPackageDependenciesResult>;
|
|
60
63
|
|
|
61
64
|
/**
|
|
@@ -66,5 +69,5 @@ declare function listPackageDependencies(options: ListPackageDependenciesOptions
|
|
|
66
69
|
*/
|
|
67
70
|
declare function resolvePackage(_packageManager: AgentName, pkg: PackageNodeBase, _options: BaseOptions): Promise<PackageNode>;
|
|
68
71
|
|
|
69
|
-
export { PackageNode, PackageNodeBase, PackageNodeRaw, getPackageManager, listPackageDependencies, listPackageDependenciesRaw, resolvePackage };
|
|
72
|
+
export { PackageModuleType, PackageNode, PackageNodeBase, PackageNodeRaw, analyzePackageModuleType, getPackageManager, listPackageDependencies, listPackageDependenciesRaw, resolvePackage };
|
|
70
73
|
export type { BaseOptions, ListPackageDependenciesBaseResult, ListPackageDependenciesOptions, ListPackageDependenciesRawResult, ListPackageDependenciesResult };
|
package/dist/index.mjs
CHANGED
|
@@ -106,96 +106,81 @@ function populateRawResult(input) {
|
|
|
106
106
|
return result;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
function
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (exports$1) {
|
|
120
|
-
|
|
109
|
+
function analyzeExports(exports$1, depth = 0) {
|
|
110
|
+
const result = {
|
|
111
|
+
hasImport: false,
|
|
112
|
+
hasRequire: false,
|
|
113
|
+
hasModule: false
|
|
114
|
+
};
|
|
115
|
+
if (depth > 10)
|
|
116
|
+
return result;
|
|
117
|
+
if (exports$1 == null)
|
|
118
|
+
return result;
|
|
119
|
+
if (typeof exports$1 === "string") {
|
|
120
|
+
if (exports$1.endsWith(".mjs") || exports$1.endsWith(".mts"))
|
|
121
|
+
result.hasImport = true;
|
|
122
|
+
else if (exports$1.endsWith(".cjs") || exports$1.endsWith(".cts"))
|
|
123
|
+
result.hasRequire = true;
|
|
124
|
+
return result;
|
|
121
125
|
}
|
|
122
|
-
if (
|
|
123
|
-
|
|
126
|
+
if (Array.isArray(exports$1)) {
|
|
127
|
+
for (const item of exports$1)
|
|
128
|
+
mergeAnalysis(result, analyzeExports(item, depth + 1));
|
|
129
|
+
return result;
|
|
124
130
|
}
|
|
125
|
-
if (
|
|
126
|
-
|
|
131
|
+
if (typeof exports$1 === "object") {
|
|
132
|
+
for (const [key, value] of Object.entries(exports$1)) {
|
|
133
|
+
if (key === "import")
|
|
134
|
+
result.hasImport = true;
|
|
135
|
+
else if (key === "require")
|
|
136
|
+
result.hasRequire = true;
|
|
137
|
+
else if (key === "module")
|
|
138
|
+
result.hasModule = true;
|
|
139
|
+
mergeAnalysis(result, analyzeExports(value, depth + 1));
|
|
140
|
+
}
|
|
127
141
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
function mergeAnalysis(target, source) {
|
|
145
|
+
target.hasImport = target.hasImport || source.hasImport;
|
|
146
|
+
target.hasRequire = target.hasRequire || source.hasRequire;
|
|
147
|
+
target.hasModule = target.hasModule || source.hasModule;
|
|
148
|
+
}
|
|
149
|
+
function analyzePackageModuleType(pkgJson) {
|
|
150
|
+
if (pkgJson.name?.startsWith("@types/"))
|
|
151
|
+
return "dts";
|
|
152
|
+
const hasExports = pkgJson.exports != null;
|
|
153
|
+
const hasModule = !!pkgJson.module;
|
|
154
|
+
const hasMain = !!pkgJson.main;
|
|
155
|
+
const isTypeModule = pkgJson.type === "module";
|
|
156
|
+
if (hasExports && pkgJson.exports) {
|
|
157
|
+
const exportInfo = analyzeExports(pkgJson.exports);
|
|
158
|
+
if (exportInfo.hasImport && exportInfo.hasRequire)
|
|
159
|
+
return "dual";
|
|
160
|
+
if (exportInfo.hasImport || exportInfo.hasModule) {
|
|
161
|
+
if (hasMain && !isTypeModule)
|
|
162
|
+
return "dual";
|
|
163
|
+
return "esm";
|
|
164
|
+
}
|
|
165
|
+
if (exportInfo.hasRequire) {
|
|
166
|
+
if (hasModule)
|
|
167
|
+
return "dual";
|
|
168
|
+
return "cjs";
|
|
133
169
|
}
|
|
134
170
|
}
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (
|
|
171
|
+
if (hasModule && hasMain) {
|
|
172
|
+
const mainIsCJS = pkgJson.main?.endsWith(".cjs") || pkgJson.main?.endsWith(".js") && !isTypeModule;
|
|
173
|
+
return mainIsCJS ? "faux" : "esm";
|
|
174
|
+
}
|
|
175
|
+
if (hasModule)
|
|
140
176
|
return "faux";
|
|
141
|
-
if (
|
|
177
|
+
if (isTypeModule || hasMain && pkgJson.main?.endsWith(".mjs"))
|
|
178
|
+
return "esm";
|
|
179
|
+
if (hasMain)
|
|
180
|
+
return "cjs";
|
|
181
|
+
if (pkgJson.types || pkgJson.typings)
|
|
142
182
|
return "dts";
|
|
143
183
|
return "cjs";
|
|
144
|
-
function analyzeThing(value, path) {
|
|
145
|
-
if (value && typeof value === "object") {
|
|
146
|
-
if (Array.isArray(value)) {
|
|
147
|
-
const values = (
|
|
148
|
-
/** @type {Array<unknown>} */
|
|
149
|
-
value
|
|
150
|
-
);
|
|
151
|
-
let index = -1;
|
|
152
|
-
while (++index < values.length) {
|
|
153
|
-
analyzeThing(values[index], `${path}[${index}]`);
|
|
154
|
-
}
|
|
155
|
-
} else {
|
|
156
|
-
const record = (
|
|
157
|
-
/** @type {Record<string, unknown>} */
|
|
158
|
-
value
|
|
159
|
-
);
|
|
160
|
-
let dots = false;
|
|
161
|
-
for (const [key, subvalue] of Object.entries(record)) {
|
|
162
|
-
if (key.charAt(0) !== ".")
|
|
163
|
-
break;
|
|
164
|
-
analyzeThing(subvalue, `${path}["${key}"]`);
|
|
165
|
-
dots = true;
|
|
166
|
-
}
|
|
167
|
-
if (dots)
|
|
168
|
-
return;
|
|
169
|
-
let explicit = false;
|
|
170
|
-
const conditionImport = Boolean("import" in record && record.import);
|
|
171
|
-
const conditionRequire = Boolean("require" in record && record.require);
|
|
172
|
-
const conditionDefault = Boolean("default" in record && record.default);
|
|
173
|
-
if (conditionImport || conditionRequire) {
|
|
174
|
-
explicit = true;
|
|
175
|
-
}
|
|
176
|
-
if (conditionImport || conditionRequire && conditionDefault) {
|
|
177
|
-
esm = true;
|
|
178
|
-
}
|
|
179
|
-
if (conditionRequire || conditionImport && conditionDefault) {
|
|
180
|
-
cjs = true;
|
|
181
|
-
}
|
|
182
|
-
const defaults = record.node || record.default;
|
|
183
|
-
if (typeof defaults === "string" && !explicit) {
|
|
184
|
-
if (/\.mjs$/.test(defaults))
|
|
185
|
-
esm = true;
|
|
186
|
-
if (/\.cjs$/.test(defaults))
|
|
187
|
-
cjs = true;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
} else if (typeof value === "string") {
|
|
191
|
-
if (/\.mjs$/.test(value))
|
|
192
|
-
esm = true;
|
|
193
|
-
if (/\.cjs$/.test(value))
|
|
194
|
-
cjs = true;
|
|
195
|
-
} else if (value === null) ; else {
|
|
196
|
-
console.error("unknown:", [value], path);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
184
|
}
|
|
200
185
|
|
|
201
186
|
async function getPackageInstallSize(pkg) {
|
|
@@ -351,4 +336,4 @@ async function listPackageDependencies(options) {
|
|
|
351
336
|
return result;
|
|
352
337
|
}
|
|
353
338
|
|
|
354
|
-
export { getPackageManager, listPackageDependencies, listPackageDependenciesRaw, resolvePackage };
|
|
339
|
+
export { analyzePackageModuleType, getPackageManager, listPackageDependencies, listPackageDependenciesRaw, resolvePackage };
|
|
@@ -63,10 +63,16 @@ interface PackageNode extends PackageNodeBase {
|
|
|
63
63
|
publint?: Message[] | null;
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
+
type AuditLevelString = 'low' | 'moderate' | 'high' | 'critical';
|
|
66
67
|
interface NpmMeta {
|
|
67
68
|
publishedAt: number;
|
|
68
69
|
deprecated?: string;
|
|
69
70
|
provenance?: 'trustedPublisher' | boolean;
|
|
71
|
+
vulnerability?: {
|
|
72
|
+
level: AuditLevelString;
|
|
73
|
+
title: string;
|
|
74
|
+
url?: string;
|
|
75
|
+
};
|
|
70
76
|
}
|
|
71
77
|
/**
|
|
72
78
|
* Npm meta of the latest version of a certain package
|
|
@@ -91,5 +97,5 @@ declare const CLUSTER_DEP_PROD = "dep:prod";
|
|
|
91
97
|
declare const CLUSTER_DEP_DEV = "dep:dev";
|
|
92
98
|
declare const CLUSTER_DEP_OPTIONAL = "dep:optional";
|
|
93
99
|
|
|
94
|
-
export { CLUSTER_DEP_DEV as C, CLUSTER_DEP_OPTIONAL as
|
|
95
|
-
export type { FileCategory as F, NpmMeta as N, PackageNodeRaw as P, PackageNodeBase as a, PackageNode as b,
|
|
100
|
+
export { CLUSTER_DEP_DEV as C, CLUSTER_DEP_OPTIONAL as d, CLUSTER_DEP_PROD as e, PackageModuleTypes as i };
|
|
101
|
+
export type { AuditLevelString as A, FileCategory as F, NpmMeta as N, PackageNodeRaw as P, PackageNodeBase as a, PackageNode as b, PackageModuleType as c, NpmMetaLatest as f, PackageInstallSizeInfo as g, PackageModuleTypeSimple as h };
|
|
@@ -63,10 +63,16 @@ interface PackageNode extends PackageNodeBase {
|
|
|
63
63
|
publint?: Message[] | null;
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
+
type AuditLevelString = 'low' | 'moderate' | 'high' | 'critical';
|
|
66
67
|
interface NpmMeta {
|
|
67
68
|
publishedAt: number;
|
|
68
69
|
deprecated?: string;
|
|
69
70
|
provenance?: 'trustedPublisher' | boolean;
|
|
71
|
+
vulnerability?: {
|
|
72
|
+
level: AuditLevelString;
|
|
73
|
+
title: string;
|
|
74
|
+
url?: string;
|
|
75
|
+
};
|
|
70
76
|
}
|
|
71
77
|
/**
|
|
72
78
|
* Npm meta of the latest version of a certain package
|
|
@@ -91,5 +97,5 @@ declare const CLUSTER_DEP_PROD = "dep:prod";
|
|
|
91
97
|
declare const CLUSTER_DEP_DEV = "dep:dev";
|
|
92
98
|
declare const CLUSTER_DEP_OPTIONAL = "dep:optional";
|
|
93
99
|
|
|
94
|
-
export { CLUSTER_DEP_DEV as C, CLUSTER_DEP_OPTIONAL as
|
|
95
|
-
export type { FileCategory as F, NpmMeta as N, PackageNodeRaw as P, PackageNodeBase as a, PackageNode as b,
|
|
100
|
+
export { CLUSTER_DEP_DEV as C, CLUSTER_DEP_OPTIONAL as d, CLUSTER_DEP_PROD as e, PackageModuleTypes as i };
|
|
101
|
+
export type { AuditLevelString as A, FileCategory as F, NpmMeta as N, PackageNodeRaw as P, PackageNodeBase as a, PackageNode as b, PackageModuleType as c, NpmMetaLatest as f, PackageInstallSizeInfo as g, PackageModuleTypeSimple as h };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-modules-tools",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"description": "Tools for inspecting node_modules",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -28,16 +28,16 @@
|
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"js-yaml": "^4.1.1",
|
|
31
|
-
"p-limit": "^7.
|
|
31
|
+
"p-limit": "^7.3.0",
|
|
32
32
|
"package-manager-detector": "^1.6.0",
|
|
33
33
|
"pathe": "^2.0.3",
|
|
34
34
|
"pkg-types": "^2.3.0",
|
|
35
|
-
"publint": "^0.3.
|
|
36
|
-
"semver": "^7.7.
|
|
35
|
+
"publint": "^0.3.18",
|
|
36
|
+
"semver": "^7.7.4",
|
|
37
37
|
"tinyexec": "^1.0.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@pnpm/list": "^1000.2
|
|
40
|
+
"@pnpm/list": "^1000.3.2",
|
|
41
41
|
"@pnpm/types": "^1001.3.0",
|
|
42
42
|
"@types/js-yaml": "^4.0.9",
|
|
43
43
|
"@types/stream-json": "^1.7.8",
|