node-modules-tools 0.0.12 → 0.0.13
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 +2 -4
- package/dist/index.d.ts +2 -4
- package/dist/index.mjs +9 -15
- package/dist/shared/node-modules-tools.BJ7We4bS.mjs +18 -0
- package/dist/utils.d.mts +17 -0
- package/dist/utils.d.ts +17 -0
- package/dist/utils.mjs +2 -0
- package/package.json +4 -10
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AgentName } from 'package-manager-detector';
|
|
2
|
+
export { PackageNodeLike, constructPackageFilter, constructPackageFilters } from './utils.mjs';
|
|
2
3
|
|
|
3
4
|
interface BaseOptions {
|
|
4
5
|
/**
|
|
@@ -111,7 +112,4 @@ declare function listPackageDependencies(options: ListPackageDependenciesOptions
|
|
|
111
112
|
*/
|
|
112
113
|
declare function resolvePackage(_packageManager: AgentName, pkg: PackageNodeBase, _options: BaseOptions): Promise<PackageNode>;
|
|
113
114
|
|
|
114
|
-
|
|
115
|
-
declare function warnOnce(message: string): void;
|
|
116
|
-
|
|
117
|
-
export { type BaseOptions, type FileCategory, type ListPackageDependenciesBaseResult, type ListPackageDependenciesOptions, type ListPackageDependenciesRawResult, type ListPackageDependenciesResult, type PackageInstallSizeInfo, type PackageModuleType, type PackageModuleTypeSimple, PackageModuleTypes, type PackageNode, type PackageNodeBase, type PackageNodeRaw, getPackageManager, listPackageDependencies, listPackageDependenciesRaw, resolvePackage, stripBomTag, warnOnce };
|
|
115
|
+
export { type BaseOptions, type FileCategory, type ListPackageDependenciesBaseResult, type ListPackageDependenciesOptions, type ListPackageDependenciesRawResult, type ListPackageDependenciesResult, type PackageInstallSizeInfo, type PackageModuleType, type PackageModuleTypeSimple, PackageModuleTypes, type PackageNode, type PackageNodeBase, type PackageNodeRaw, getPackageManager, listPackageDependencies, listPackageDependenciesRaw, resolvePackage };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AgentName } from 'package-manager-detector';
|
|
2
|
+
export { PackageNodeLike, constructPackageFilter, constructPackageFilters } from './utils.js';
|
|
2
3
|
|
|
3
4
|
interface BaseOptions {
|
|
4
5
|
/**
|
|
@@ -111,7 +112,4 @@ declare function listPackageDependencies(options: ListPackageDependenciesOptions
|
|
|
111
112
|
*/
|
|
112
113
|
declare function resolvePackage(_packageManager: AgentName, pkg: PackageNodeBase, _options: BaseOptions): Promise<PackageNode>;
|
|
113
114
|
|
|
114
|
-
|
|
115
|
-
declare function warnOnce(message: string): void;
|
|
116
|
-
|
|
117
|
-
export { type BaseOptions, type FileCategory, type ListPackageDependenciesBaseResult, type ListPackageDependenciesOptions, type ListPackageDependenciesRawResult, type ListPackageDependenciesResult, type PackageInstallSizeInfo, type PackageModuleType, type PackageModuleTypeSimple, PackageModuleTypes, type PackageNode, type PackageNodeBase, type PackageNodeRaw, getPackageManager, listPackageDependencies, listPackageDependenciesRaw, resolvePackage, stripBomTag, warnOnce };
|
|
115
|
+
export { type BaseOptions, type FileCategory, type ListPackageDependenciesBaseResult, type ListPackageDependenciesOptions, type ListPackageDependenciesRawResult, type ListPackageDependenciesResult, type PackageInstallSizeInfo, type PackageModuleType, type PackageModuleTypeSimple, PackageModuleTypes, type PackageNode, type PackageNodeBase, type PackageNodeRaw, getPackageManager, listPackageDependencies, listPackageDependenciesRaw, resolvePackage };
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,8 @@ import { detect } from 'package-manager-detector';
|
|
|
3
3
|
import fs from 'node:fs/promises';
|
|
4
4
|
import { join as join$1 } from 'pathe';
|
|
5
5
|
import { relative, join } from 'node:path';
|
|
6
|
+
export { c as constructPackageFilter, a as constructPackageFilters } from './shared/node-modules-tools.BJ7We4bS.mjs';
|
|
7
|
+
import 'semver';
|
|
6
8
|
|
|
7
9
|
async function getPackageManager(options) {
|
|
8
10
|
const manager = await detect({
|
|
@@ -279,20 +281,6 @@ function guessFileCategory(file) {
|
|
|
279
281
|
return "other";
|
|
280
282
|
}
|
|
281
283
|
|
|
282
|
-
function stripBomTag(content) {
|
|
283
|
-
if (content.charCodeAt(0) === 65279) {
|
|
284
|
-
return content.slice(1);
|
|
285
|
-
}
|
|
286
|
-
return content;
|
|
287
|
-
}
|
|
288
|
-
const warned = /* @__PURE__ */ new Set();
|
|
289
|
-
function warnOnce(message) {
|
|
290
|
-
if (warned.has(message))
|
|
291
|
-
return;
|
|
292
|
-
warned.add(message);
|
|
293
|
-
console.warn(message);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
284
|
async function resolvePackage(_packageManager, pkg, _options) {
|
|
297
285
|
const _pkg = pkg;
|
|
298
286
|
if (_pkg.resolved)
|
|
@@ -320,6 +308,12 @@ async function resolvePackage(_packageManager, pkg, _options) {
|
|
|
320
308
|
};
|
|
321
309
|
return _pkg;
|
|
322
310
|
}
|
|
311
|
+
function stripBomTag(content) {
|
|
312
|
+
if (content.charCodeAt(0) === 65279) {
|
|
313
|
+
return content.slice(1);
|
|
314
|
+
}
|
|
315
|
+
return content;
|
|
316
|
+
}
|
|
323
317
|
|
|
324
318
|
async function listPackageDependencies(options) {
|
|
325
319
|
const packageManager = await getPackageManager(options);
|
|
@@ -329,4 +323,4 @@ async function listPackageDependencies(options) {
|
|
|
329
323
|
return result;
|
|
330
324
|
}
|
|
331
325
|
|
|
332
|
-
export { PackageModuleTypes, getPackageManager, listPackageDependencies, listPackageDependenciesRaw, resolvePackage
|
|
326
|
+
export { PackageModuleTypes, getPackageManager, listPackageDependencies, listPackageDependenciesRaw, resolvePackage };
|
|
@@ -0,0 +1,18 @@
|
|
|
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(constructPackageFilter);
|
|
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 };
|
package/dist/utils.d.mts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface PackageNodeLike {
|
|
2
|
+
name: string;
|
|
3
|
+
version: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Construct a filter to match a package name
|
|
7
|
+
*
|
|
8
|
+
* - @foo/bar@1.0.0 or foobar@1.0.0 -> Exact match
|
|
9
|
+
* - @foo/bar@* or @foo/bar -> Any version of the package
|
|
10
|
+
* - @foo/bar@^1.0.0 -> Any version that matches the semver range
|
|
11
|
+
* - bar-* -> Any version that matches the prefix
|
|
12
|
+
* - *eslint* -> Any version that matches the wildcard
|
|
13
|
+
*/
|
|
14
|
+
declare function constructPackageFilter(range: string): (pkg: PackageNodeLike) => boolean;
|
|
15
|
+
declare function constructPackageFilters(ranges: string[], mode: 'some' | 'every'): (pkg: PackageNodeLike) => boolean;
|
|
16
|
+
|
|
17
|
+
export { type PackageNodeLike, constructPackageFilter, constructPackageFilters };
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface PackageNodeLike {
|
|
2
|
+
name: string;
|
|
3
|
+
version: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Construct a filter to match a package name
|
|
7
|
+
*
|
|
8
|
+
* - @foo/bar@1.0.0 or foobar@1.0.0 -> Exact match
|
|
9
|
+
* - @foo/bar@* or @foo/bar -> Any version of the package
|
|
10
|
+
* - @foo/bar@^1.0.0 -> Any version that matches the semver range
|
|
11
|
+
* - bar-* -> Any version that matches the prefix
|
|
12
|
+
* - *eslint* -> Any version that matches the wildcard
|
|
13
|
+
*/
|
|
14
|
+
declare function constructPackageFilter(range: string): (pkg: PackageNodeLike) => boolean;
|
|
15
|
+
declare function constructPackageFilters(ranges: string[], mode: 'some' | 'every'): (pkg: PackageNodeLike) => boolean;
|
|
16
|
+
|
|
17
|
+
export { type PackageNodeLike, constructPackageFilter, constructPackageFilters };
|
package/dist/utils.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-modules-tools",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.13",
|
|
5
5
|
"description": "Tools for inspecting node_modules",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -16,19 +16,12 @@
|
|
|
16
16
|
"keywords": [],
|
|
17
17
|
"sideEffects": false,
|
|
18
18
|
"exports": {
|
|
19
|
-
".": "./dist/index.mjs"
|
|
19
|
+
".": "./dist/index.mjs",
|
|
20
|
+
"./utils": "./dist/utils.mjs"
|
|
20
21
|
},
|
|
21
22
|
"main": "./dist/index.mjs",
|
|
22
23
|
"module": "./dist/index.mjs",
|
|
23
24
|
"types": "./dist/index.d.mts",
|
|
24
|
-
"typesVersions": {
|
|
25
|
-
"*": {
|
|
26
|
-
"*": [
|
|
27
|
-
"./dist/*",
|
|
28
|
-
"./dist/index.d.ts"
|
|
29
|
-
]
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
25
|
"files": [
|
|
33
26
|
"dist"
|
|
34
27
|
],
|
|
@@ -36,6 +29,7 @@
|
|
|
36
29
|
"p-limit": "^6.2.0",
|
|
37
30
|
"package-manager-detector": "^0.2.9",
|
|
38
31
|
"pathe": "^2.0.2",
|
|
32
|
+
"semver": "^7.7.1",
|
|
39
33
|
"tinyexec": "^0.3.2"
|
|
40
34
|
},
|
|
41
35
|
"devDependencies": {
|