@pnpm/fs.packlist 1000.0.0 → 1100.0.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/LICENSE +1 -1
- package/README.md +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +119 -18
- package/package.json +22 -20
- package/lib/index.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2015-2016 Rico Sta. Cruz and other contributors
|
|
4
|
-
Copyright (c) 2016-
|
|
4
|
+
Copyright (c) 2016-2026 Zoltan Kochan and other contributors
|
|
5
5
|
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
> Get a list of the files to add from a directory into an npm package
|
|
4
4
|
|
|
5
5
|
<!--@shields('npm')-->
|
|
6
|
-
[](https://
|
|
6
|
+
[](https://npmx.dev/package/@pnpm/fs.packlist)
|
|
7
7
|
<!--/@-->
|
|
8
8
|
|
|
9
9
|
## Installation
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,20 +1,121 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import util from 'node:util';
|
|
4
|
+
import npmPacklist from 'npm-packlist';
|
|
5
|
+
export async function packlist(pkgDir, opts) {
|
|
6
|
+
const pkg = opts?.manifest ?? readPackageJson(pkgDir);
|
|
7
|
+
const tree = buildRootTree(pkgDir, pkg);
|
|
8
|
+
const files = await npmPacklist(tree);
|
|
9
|
+
return files.map((file) => file.replace(/^\.[/\\]/, ''));
|
|
10
|
+
}
|
|
11
|
+
function buildRootTree(pkgDir, pkg) {
|
|
12
|
+
const bundledDeps = getRootBundledDeps(pkg);
|
|
13
|
+
// npm-packlist's gatherBundles() iterates package.bundleDependencies directly,
|
|
14
|
+
// so the field must be an array. Normalize true/undefined to an explicit list.
|
|
15
|
+
const normalizedPkg = normalizePackage(pkg);
|
|
16
|
+
normalizedPkg.bundleDependencies = bundledDeps;
|
|
17
|
+
delete normalizedPkg.bundledDependencies;
|
|
18
|
+
const root = makeNode(pkgDir, normalizedPkg, true);
|
|
19
|
+
const seen = new Map([[pkgDir, root]]);
|
|
20
|
+
populateEdges(root, bundledDeps, seen);
|
|
21
|
+
return root;
|
|
22
|
+
}
|
|
23
|
+
function buildBundledTree(pkgDir, seen) {
|
|
24
|
+
const cached = seen.get(pkgDir);
|
|
25
|
+
if (cached)
|
|
26
|
+
return cached;
|
|
27
|
+
const pkg = readPackageJson(pkgDir);
|
|
28
|
+
const node = makeNode(pkgDir, normalizePackage(pkg), false);
|
|
29
|
+
seen.set(pkgDir, node);
|
|
30
|
+
populateEdges(node, getNestedBundledDeps(pkg), seen);
|
|
31
|
+
return node;
|
|
32
|
+
}
|
|
33
|
+
function populateEdges(node, deps, seen) {
|
|
34
|
+
for (const dep of deps) {
|
|
35
|
+
const depDir = resolveDependency(dep, node.path);
|
|
36
|
+
if (!depDir)
|
|
37
|
+
continue;
|
|
38
|
+
const depNode = buildBundledTree(depDir, seen);
|
|
39
|
+
node.edgesOut.set(dep, { to: depNode, peer: false, dev: false });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function makeNode(pkgDir, pkg, isProjectRoot) {
|
|
43
|
+
const node = {
|
|
44
|
+
path: pkgDir,
|
|
45
|
+
package: pkg,
|
|
46
|
+
isProjectRoot,
|
|
47
|
+
isLink: false,
|
|
48
|
+
edgesOut: new Map(),
|
|
49
|
+
};
|
|
50
|
+
node.target = node;
|
|
51
|
+
return node;
|
|
52
|
+
}
|
|
53
|
+
function getRootBundledDeps(pkg) {
|
|
54
|
+
const bundle = pkg.bundleDependencies ?? pkg.bundledDependencies;
|
|
55
|
+
if (Array.isArray(bundle))
|
|
56
|
+
return bundle;
|
|
57
|
+
if (bundle === true) {
|
|
58
|
+
return Object.keys((pkg.dependencies ?? {}));
|
|
59
|
+
}
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
function getNestedBundledDeps(pkg) {
|
|
63
|
+
const dependencies = (pkg.dependencies ?? {});
|
|
64
|
+
const optionalDependencies = (pkg.optionalDependencies ?? {});
|
|
65
|
+
return [...Object.keys(dependencies), ...Object.keys(optionalDependencies)];
|
|
66
|
+
}
|
|
67
|
+
function resolveDependency(depName, fromDir) {
|
|
68
|
+
let currentDir = fromDir;
|
|
69
|
+
while (true) {
|
|
70
|
+
const candidate = path.join(currentDir, 'node_modules', depName);
|
|
71
|
+
try {
|
|
72
|
+
const stat = fs.statSync(path.join(candidate, 'package.json'));
|
|
73
|
+
if (stat.isFile())
|
|
74
|
+
return candidate;
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
if (!util.types.isNativeError(err) || !('code' in err) || err.code !== 'ENOENT') {
|
|
78
|
+
throw err;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const parent = path.dirname(currentDir);
|
|
82
|
+
if (parent === currentDir)
|
|
83
|
+
return undefined;
|
|
84
|
+
currentDir = parent;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function readPackageJson(dir) {
|
|
88
|
+
try {
|
|
89
|
+
return JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
if (util.types.isNativeError(err) && 'code' in err && err.code === 'ENOENT') {
|
|
93
|
+
return {};
|
|
94
|
+
}
|
|
95
|
+
throw err;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function stripDotSlash(p) {
|
|
99
|
+
return p.replace(/^\.[/\\]/, '');
|
|
100
|
+
}
|
|
101
|
+
function normalizePackage(pkg) {
|
|
102
|
+
const normalized = { ...pkg };
|
|
103
|
+
if (typeof normalized.main === 'string') {
|
|
104
|
+
normalized.main = stripDotSlash(normalized.main);
|
|
105
|
+
}
|
|
106
|
+
if (typeof normalized.browser === 'string') {
|
|
107
|
+
normalized.browser = stripDotSlash(normalized.browser);
|
|
108
|
+
}
|
|
109
|
+
if (typeof normalized.bin === 'string') {
|
|
110
|
+
normalized.bin = stripDotSlash(normalized.bin);
|
|
111
|
+
}
|
|
112
|
+
else if (normalized.bin != null && typeof normalized.bin === 'object') {
|
|
113
|
+
const bin = {};
|
|
114
|
+
for (const [key, value] of Object.entries(normalized.bin)) {
|
|
115
|
+
bin[key] = stripDotSlash(value);
|
|
116
|
+
}
|
|
117
|
+
normalized.bin = bin;
|
|
118
|
+
}
|
|
119
|
+
return normalized;
|
|
19
120
|
}
|
|
20
121
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,41 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/fs.packlist",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1100.0.1",
|
|
4
4
|
"description": "Get a list of the files to add from a directory into an npm package",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"files": [
|
|
7
|
-
"lib",
|
|
8
|
-
"!*.map"
|
|
9
|
-
],
|
|
10
|
-
"types": "lib/index.d.ts",
|
|
11
|
-
"repository": "https://github.com/pnpm/pnpm/blob/main/fs/packlist",
|
|
12
5
|
"keywords": [
|
|
13
|
-
"
|
|
6
|
+
"pnpm",
|
|
7
|
+
"pnpm11"
|
|
14
8
|
],
|
|
15
|
-
"engines": {
|
|
16
|
-
"node": ">=18.12"
|
|
17
|
-
},
|
|
18
9
|
"license": "MIT",
|
|
10
|
+
"funding": "https://opencollective.com/pnpm",
|
|
11
|
+
"repository": "https://github.com/pnpm/pnpm/tree/main/fs/packlist",
|
|
12
|
+
"homepage": "https://github.com/pnpm/pnpm/tree/main/fs/packlist#readme",
|
|
19
13
|
"bugs": {
|
|
20
14
|
"url": "https://github.com/pnpm/pnpm/issues"
|
|
21
15
|
},
|
|
22
|
-
"
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "lib/index.js",
|
|
18
|
+
"types": "lib/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./lib/index.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"lib",
|
|
24
|
+
"!*.map"
|
|
25
|
+
],
|
|
23
26
|
"dependencies": {
|
|
24
|
-
"npm-packlist": "
|
|
27
|
+
"npm-packlist": "10.0.4"
|
|
25
28
|
},
|
|
26
|
-
"funding": "https://opencollective.com/pnpm",
|
|
27
29
|
"devDependencies": {
|
|
28
|
-
"@pnpm/fs.packlist": "
|
|
30
|
+
"@pnpm/fs.packlist": "1100.0.1"
|
|
29
31
|
},
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=22.13"
|
|
32
34
|
},
|
|
33
35
|
"jest": {
|
|
34
36
|
"preset": "@pnpm/jest-config"
|
|
35
37
|
},
|
|
36
38
|
"scripts": {
|
|
37
39
|
"lint": "eslint \"src/**/*.ts\"",
|
|
38
|
-
"compile": "
|
|
39
|
-
"test": "
|
|
40
|
+
"compile": "tsgo --build && pn lint --fix",
|
|
41
|
+
"test": "pn compile"
|
|
40
42
|
}
|
|
41
43
|
}
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAEA,4BAaC;AAfD,gEAAsC;AAE/B,KAAK,UAAU,QAAQ,CAAE,MAAc,EAAE,IAE/C;IACC,MAAM,mBAAmB,GAAG,IAAI,EAAE,gBAAgB;QAChD,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAChD,CAAC,CAAC,SAAS,CAAA;IACb,MAAM,KAAK,GAAG,MAAM,IAAA,sBAAW,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,CAAC,CAAA;IACxF,yDAAyD;IACzD,mCAAmC;IACnC,0DAA0D;IAC1D,+CAA+C;IAC/C,gDAAgD;IAChD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;AAC/E,CAAC"}
|