@pnpm/fs.packlist 1100.0.9 → 1100.0.10
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/CHANGELOG.md +9 -0
- package/lib/bundleDependencyResolver.d.ts +16 -0
- package/lib/bundleDependencyResolver.js +70 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +20 -62
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @pnpm/fs.packlist
|
|
2
2
|
|
|
3
|
+
## 1100.0.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- `pnpm pack` and `pnpm publish` again include the files of a `publishConfig.directory` that is reached through a symlink, together with its bundled dependencies [pnpm/pnpm#17390](https://github.com/pnpm/pnpm/issues/17390).
|
|
8
|
+
|
|
9
|
+
- Updated dependencies:
|
|
10
|
+
- @pnpm/workspace.project-manifest-reader@1100.1.5
|
|
11
|
+
|
|
3
12
|
## 1100.0.9
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface ResolvedDependency {
|
|
2
|
+
dir: string;
|
|
3
|
+
realDir: string;
|
|
4
|
+
}
|
|
5
|
+
export interface PackBoundaries {
|
|
6
|
+
root: string;
|
|
7
|
+
dirs: string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The node_modules directory that holds depName when resolved from fromDir:
|
|
11
|
+
* fromDir and its ancestors up to the boundary that contains it, then root
|
|
12
|
+
* when fromDir lies outside it. A dependency whose real directory lies
|
|
13
|
+
* outside every boundary is not bundled.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveDependency(depName: string, fromDir: string, boundaries: PackBoundaries): ResolvedDependency | undefined;
|
|
16
|
+
export declare function isSafeBundleName(name: unknown): name is string;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { isError } from '@pnpm/error';
|
|
4
|
+
import { isSubdir } from 'is-subdir';
|
|
5
|
+
/**
|
|
6
|
+
* The node_modules directory that holds depName when resolved from fromDir:
|
|
7
|
+
* fromDir and its ancestors up to the boundary that contains it, then root
|
|
8
|
+
* when fromDir lies outside it. A dependency whose real directory lies
|
|
9
|
+
* outside every boundary is not bundled.
|
|
10
|
+
*/
|
|
11
|
+
export function resolveDependency(depName, fromDir, boundaries) {
|
|
12
|
+
if (!isSafeBundleName(depName))
|
|
13
|
+
return undefined;
|
|
14
|
+
for (const dir of getDependencySearchDirs(fromDir, boundaries)) {
|
|
15
|
+
const found = findInNodeModulesOf(dir, depName);
|
|
16
|
+
if (found != null)
|
|
17
|
+
return keepWithinBoundaries(found, boundaries.dirs);
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
// Bundle names come from package.json, so reject paths before joining them under node_modules.
|
|
22
|
+
export function isSafeBundleName(name) {
|
|
23
|
+
if (typeof name !== 'string' || name.includes('\\'))
|
|
24
|
+
return false;
|
|
25
|
+
const parts = name.split('/');
|
|
26
|
+
if (parts.length > 2 || (parts.length === 2 && !parts[0].startsWith('@')))
|
|
27
|
+
return false;
|
|
28
|
+
return parts.every((part) => part !== '' && part !== '.' && part !== '..');
|
|
29
|
+
}
|
|
30
|
+
function* getDependencySearchDirs(fromDir, { root, dirs }) {
|
|
31
|
+
let dir = fromDir;
|
|
32
|
+
while (isWithinAnyBoundary(dir, dirs)) {
|
|
33
|
+
yield dir;
|
|
34
|
+
const parent = path.dirname(dir);
|
|
35
|
+
if (parent === dir || !isWithinAnyBoundary(parent, dirs))
|
|
36
|
+
break;
|
|
37
|
+
dir = parent;
|
|
38
|
+
}
|
|
39
|
+
if (!isWithinBoundary(fromDir, root))
|
|
40
|
+
yield root;
|
|
41
|
+
}
|
|
42
|
+
function isWithinAnyBoundary(dir, boundaries) {
|
|
43
|
+
return boundaries.some((boundary) => isWithinBoundary(dir, boundary));
|
|
44
|
+
}
|
|
45
|
+
function isWithinBoundary(dir, boundary) {
|
|
46
|
+
return dir === boundary || isSubdir(boundary, dir);
|
|
47
|
+
}
|
|
48
|
+
function keepWithinBoundaries(resolved, boundaries) {
|
|
49
|
+
return boundaries.some((boundary) => isWithinBoundary(resolved.realDir, boundary)) ? resolved : undefined;
|
|
50
|
+
}
|
|
51
|
+
function findInNodeModulesOf(dir, depName) {
|
|
52
|
+
if (path.basename(dir) === 'node_modules')
|
|
53
|
+
return undefined;
|
|
54
|
+
const candidate = path.join(dir, 'node_modules', depName);
|
|
55
|
+
const realDir = realpathOfPackageDir(candidate);
|
|
56
|
+
return realDir == null ? undefined : { dir: candidate, realDir };
|
|
57
|
+
}
|
|
58
|
+
function realpathOfPackageDir(dir) {
|
|
59
|
+
try {
|
|
60
|
+
if (!fs.statSync(path.join(dir, 'package.json')).isFile())
|
|
61
|
+
return undefined;
|
|
62
|
+
return fs.realpathSync(dir);
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
if (!isError(err) || !('code' in err) || err.code !== 'ENOENT')
|
|
66
|
+
throw err;
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=bundleDependencyResolver.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare function packlist(pkgDir: string, opts?: PacklistOptions): Promis
|
|
|
13
13
|
* Maps each packed path to the file it is read from. Bundled dependencies
|
|
14
14
|
* resolve from pkgDir upward, and never above the workspace root when pkgDir
|
|
15
15
|
* is a workspace package, or above bundledDependenciesDir (default pkgDir)
|
|
16
|
-
* otherwise.
|
|
16
|
+
* otherwise. When pkgDir resolves to a directory outside that root, both
|
|
17
|
+
* real directories bound the packed files and the bundled dependencies.
|
|
17
18
|
*/
|
|
18
19
|
export declare function packlistWithSources(pkgDir: string, opts?: PacklistOptions): Promise<Map<string, string>>;
|
package/lib/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { isError } from '@pnpm/error';
|
|
|
4
4
|
import { safeReadProjectManifestOnly } from '@pnpm/workspace.project-manifest-reader';
|
|
5
5
|
import { isSubdir } from 'is-subdir';
|
|
6
6
|
import npmPacklist from 'npm-packlist';
|
|
7
|
+
import { isSafeBundleName, resolveDependency } from './bundleDependencyResolver.js';
|
|
7
8
|
const ALTERNATE_MANIFEST_NAMES = ['package.yaml', 'package.json5'];
|
|
8
9
|
/**
|
|
9
10
|
* npm-packlist applies the manifest rules (`files`, `main`, `bin`, and the
|
|
@@ -84,7 +85,8 @@ export async function packlist(pkgDir, opts) {
|
|
|
84
85
|
* Maps each packed path to the file it is read from. Bundled dependencies
|
|
85
86
|
* resolve from pkgDir upward, and never above the workspace root when pkgDir
|
|
86
87
|
* is a workspace package, or above bundledDependenciesDir (default pkgDir)
|
|
87
|
-
* otherwise.
|
|
88
|
+
* otherwise. When pkgDir resolves to a directory outside that root, both
|
|
89
|
+
* real directories bound the packed files and the bundled dependencies.
|
|
88
90
|
*/
|
|
89
91
|
export async function packlistWithSources(pkgDir, opts) {
|
|
90
92
|
const resolvedPkgDir = path.resolve(pkgDir);
|
|
@@ -92,13 +94,14 @@ export async function packlistWithSources(pkgDir, opts) {
|
|
|
92
94
|
const pkg = opts?.manifest ?? await safeReadProjectManifestOnly(resolvedPkgDir) ?? {};
|
|
93
95
|
const hasWorkspaceContext = workspaceDir != null && workspaceDir !== resolvedPkgDir && isSubdir(workspaceDir, resolvedPkgDir);
|
|
94
96
|
const boundary = hasWorkspaceContext ? workspaceDir : path.resolve(opts?.bundledDependenciesDir ?? resolvedPkgDir);
|
|
95
|
-
const
|
|
97
|
+
const boundaries = getBoundaries(boundary, resolvedPkgDir);
|
|
98
|
+
const { tree, packedDirs } = buildRootTree(resolvedPkgDir, pkg, boundaries);
|
|
96
99
|
const packlistOpts = hasWorkspaceContext && !await hasNpmIgnoreFile(resolvedPkgDir)
|
|
97
100
|
? { prefix: workspaceDir, workspaces: [resolvedPkgDir] }
|
|
98
101
|
: undefined;
|
|
99
102
|
const files = (await walkPackage(tree, packlistOpts))
|
|
100
103
|
.map((file) => file.replace(/^\.[/\\]/, ''))
|
|
101
|
-
.filter((file) => isInternalFileOrSymlink(resolvedPkgDir, file,
|
|
104
|
+
.filter((file) => isInternalFileOrSymlink(resolvedPkgDir, file, boundaries));
|
|
102
105
|
return mapToPackedPaths(resolvedPkgDir, files, packedDirs);
|
|
103
106
|
}
|
|
104
107
|
async function hasNpmIgnoreFile(pkgDir) {
|
|
@@ -122,16 +125,16 @@ async function walkPackage(tree, packlistOpts) {
|
|
|
122
125
|
function isEscapingRelativePath(rel) {
|
|
123
126
|
return rel === '..' || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel);
|
|
124
127
|
}
|
|
125
|
-
function isInternalFileOrSymlink(pkgDir, relFile,
|
|
128
|
+
function isInternalFileOrSymlink(pkgDir, relFile, boundaries) {
|
|
126
129
|
const absPath = path.join(pkgDir, relFile);
|
|
127
130
|
const lstat = lstatIfExists(absPath, ['ENOENT']);
|
|
128
131
|
if (lstat == null) {
|
|
129
132
|
return false;
|
|
130
133
|
}
|
|
131
134
|
if (!lstat.isSymbolicLink()) {
|
|
132
|
-
return !realTargetEscapes(
|
|
135
|
+
return !realTargetEscapes(boundaries, absPath, false);
|
|
133
136
|
}
|
|
134
|
-
return isInternalSymlink(pkgDir, relFile, absPath,
|
|
137
|
+
return isInternalSymlink(pkgDir, relFile, absPath, boundaries);
|
|
135
138
|
}
|
|
136
139
|
function lstatIfExists(filePath, missingCodes) {
|
|
137
140
|
try {
|
|
@@ -143,7 +146,7 @@ function lstatIfExists(filePath, missingCodes) {
|
|
|
143
146
|
throw err;
|
|
144
147
|
}
|
|
145
148
|
}
|
|
146
|
-
function isInternalSymlink(pkgDir, relFile, absPath,
|
|
149
|
+
function isInternalSymlink(pkgDir, relFile, absPath, boundaries) {
|
|
147
150
|
let linkTarget = fs.readlinkSync(absPath);
|
|
148
151
|
if (path.isAbsolute(linkTarget)) {
|
|
149
152
|
linkTarget = path.relative(path.dirname(absPath), linkTarget);
|
|
@@ -156,7 +159,7 @@ function isInternalSymlink(pkgDir, relFile, absPath, boundary = pkgDir) {
|
|
|
156
159
|
if (isEscapingRelativePath(relToPkg)) {
|
|
157
160
|
return false;
|
|
158
161
|
}
|
|
159
|
-
return !realTargetEscapes(
|
|
162
|
+
return !realTargetEscapes(boundaries, absPath, true);
|
|
160
163
|
}
|
|
161
164
|
function archivedLinkEscapes(relFile, linkTarget) {
|
|
162
165
|
const relPosix = process.platform === 'win32' ? relFile.replace(/\\/g, '/') : relFile;
|
|
@@ -167,11 +170,10 @@ function archivedLinkEscapes(relFile, linkTarget) {
|
|
|
167
170
|
const normalizedArchive = path.posix.normalize(path.posix.join(path.posix.dirname(relPosix), posixTarget));
|
|
168
171
|
return normalizedArchive === '..' || normalizedArchive.startsWith('../');
|
|
169
172
|
}
|
|
170
|
-
function realTargetEscapes(
|
|
171
|
-
const realBoundary = realpathOrUndefined(boundary) ?? boundary;
|
|
173
|
+
function realTargetEscapes(boundaries, absPath, isSymlink = true) {
|
|
172
174
|
try {
|
|
173
175
|
const realTarget = fs.realpathSync(absPath);
|
|
174
|
-
return isEscapingRelativePath(path.relative(
|
|
176
|
+
return boundaries.dirs.every((dir) => isEscapingRelativePath(path.relative(dir, realTarget)));
|
|
175
177
|
}
|
|
176
178
|
catch (err) {
|
|
177
179
|
if (!isError(err) || !('code' in err) || err.code !== 'ENOENT') {
|
|
@@ -207,7 +209,7 @@ function mapToPackedPaths(pkgDir, files, packedDirs) {
|
|
|
207
209
|
* real directory rather than under the link, so the packed location is chosen
|
|
208
210
|
* separately by packedLocation().
|
|
209
211
|
*/
|
|
210
|
-
function buildRootTree(pkgDir, pkg,
|
|
212
|
+
function buildRootTree(pkgDir, pkg, boundaries) {
|
|
211
213
|
const bundledDeps = getRootBundledDeps(pkg).filter(isSafeBundleName);
|
|
212
214
|
// npm-packlist's gatherBundles() iterates package.bundleDependencies directly,
|
|
213
215
|
// so the field must be an array. Normalize true/undefined to an explicit list.
|
|
@@ -218,7 +220,7 @@ function buildRootTree(pkgDir, pkg, boundary) {
|
|
|
218
220
|
const walk = {
|
|
219
221
|
pkgDir,
|
|
220
222
|
realPkgDir: fs.realpathSync(pkgDir),
|
|
221
|
-
|
|
223
|
+
boundaries,
|
|
222
224
|
rootDependencyNames: new Set(getNestedBundledDeps(pkg)),
|
|
223
225
|
slots: new Map(),
|
|
224
226
|
nodes: new Map(),
|
|
@@ -239,7 +241,7 @@ function buildRootTree(pkgDir, pkg, boundary) {
|
|
|
239
241
|
return { tree: root, packedDirs: walk.packedDirs };
|
|
240
242
|
}
|
|
241
243
|
function placeBundledDependency(walk, task) {
|
|
242
|
-
const resolved = resolveDependency(task.name, task.parent.realDir, walk.
|
|
244
|
+
const resolved = resolveDependency(task.name, task.parent.realDir, walk.boundaries);
|
|
243
245
|
if (resolved == null)
|
|
244
246
|
return undefined;
|
|
245
247
|
const packed = packedLocation(walk, task.name, task.parent.packed, resolved.realDir);
|
|
@@ -342,54 +344,6 @@ function getNestedBundledDeps(pkg) {
|
|
|
342
344
|
const optionalDependencies = (pkg.optionalDependencies ?? {});
|
|
343
345
|
return [...Object.keys(dependencies), ...Object.keys(optionalDependencies)].filter(isSafeBundleName);
|
|
344
346
|
}
|
|
345
|
-
function resolveDependency(depName, fromDir, boundary) {
|
|
346
|
-
if (!isSafeBundleName(depName))
|
|
347
|
-
return undefined;
|
|
348
|
-
let currentDir = fromDir;
|
|
349
|
-
while (true) {
|
|
350
|
-
const found = findInNodeModulesOf(currentDir, depName);
|
|
351
|
-
if (found != null)
|
|
352
|
-
return keepWithinBoundary(found, boundary);
|
|
353
|
-
if (currentDir === boundary)
|
|
354
|
-
return undefined;
|
|
355
|
-
const parent = path.dirname(currentDir);
|
|
356
|
-
if (parent === currentDir)
|
|
357
|
-
return undefined;
|
|
358
|
-
currentDir = parent;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
function keepWithinBoundary(resolved, boundary) {
|
|
362
|
-
return resolved.realDir === boundary || isSubdir(boundary, resolved.realDir) ? resolved : undefined;
|
|
363
|
-
}
|
|
364
|
-
function findInNodeModulesOf(dir, depName) {
|
|
365
|
-
if (path.basename(dir) === 'node_modules')
|
|
366
|
-
return undefined;
|
|
367
|
-
const candidate = path.join(dir, 'node_modules', depName);
|
|
368
|
-
const realDir = realpathOfPackageDir(candidate);
|
|
369
|
-
return realDir == null ? undefined : { dir: candidate, realDir };
|
|
370
|
-
}
|
|
371
|
-
function realpathOfPackageDir(dir) {
|
|
372
|
-
try {
|
|
373
|
-
if (!fs.statSync(path.join(dir, 'package.json')).isFile())
|
|
374
|
-
return undefined;
|
|
375
|
-
return fs.realpathSync(dir);
|
|
376
|
-
}
|
|
377
|
-
catch (err) {
|
|
378
|
-
if (!isError(err) || !('code' in err) || err.code !== 'ENOENT') {
|
|
379
|
-
throw err;
|
|
380
|
-
}
|
|
381
|
-
return undefined;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
// Bundle names come from package.json, so reject paths before joining them under node_modules.
|
|
385
|
-
function isSafeBundleName(name) {
|
|
386
|
-
if (typeof name !== 'string' || name.includes('\\'))
|
|
387
|
-
return false;
|
|
388
|
-
const parts = name.split('/');
|
|
389
|
-
if (parts.length > 2 || (parts.length === 2 && !parts[0].startsWith('@')))
|
|
390
|
-
return false;
|
|
391
|
-
return parts.every((part) => part !== '' && part !== '.' && part !== '..');
|
|
392
|
-
}
|
|
393
347
|
function realpathOrUndefined(dir) {
|
|
394
348
|
try {
|
|
395
349
|
return fs.realpathSync(dir);
|
|
@@ -400,6 +354,10 @@ function realpathOrUndefined(dir) {
|
|
|
400
354
|
throw err;
|
|
401
355
|
}
|
|
402
356
|
}
|
|
357
|
+
function getBoundaries(resolutionRoot, pkgDir) {
|
|
358
|
+
const root = realpathOrUndefined(resolutionRoot) ?? resolutionRoot;
|
|
359
|
+
return { root, dirs: Array.from(new Set([root, realpathOrUndefined(pkgDir) ?? pkgDir])) };
|
|
360
|
+
}
|
|
403
361
|
function readPackageJson(dir) {
|
|
404
362
|
try {
|
|
405
363
|
return JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/fs.packlist",
|
|
3
|
-
"version": "1100.0.
|
|
3
|
+
"version": "1100.0.10",
|
|
4
4
|
"description": "Get a list of the files to add from a directory into an npm package",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@pnpm/error": "1100.2.2",
|
|
31
|
-
"@pnpm/workspace.project-manifest-reader": "1100.1.
|
|
31
|
+
"@pnpm/workspace.project-manifest-reader": "1100.1.5",
|
|
32
32
|
"is-subdir": "^2.0.1",
|
|
33
33
|
"npm-packlist": "10.0.4"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@pnpm/fs.packlist": "1100.0.
|
|
36
|
+
"@pnpm/fs.packlist": "1100.0.10"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
39
39
|
"node": ">=22.13"
|