@pnpm/fs.indexed-pkg-importer 1100.0.30 → 1100.0.31
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 +21 -0
- package/lib/importIndexedDir.d.ts +2 -0
- package/lib/importIndexedDir.js +75 -21
- package/lib/index.js +136 -23
- package/lib/removeQuarantine.js +2 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @pnpm/fs.indexed-pkg-importer
|
|
2
2
|
|
|
3
|
+
## 1100.0.31
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- `pnpm install` no longer fails for an injected workspace dependency whose package publishes from a `publishConfig.directory` that its own `prepare` script builds. The injected copy now picks up that directory once `prepare` finishes building it. `pnpm install --frozen-lockfile` no longer reports the dependency as outdated while the directory has not been built yet. [pnpm/pnpm#7811](https://github.com/pnpm/pnpm/issues/7811)
|
|
8
|
+
|
|
9
|
+
- Files imported from the store now follow the umask of the install that writes them. Installing with a umask of `077` no longer leaves imported files readable by the group and others [#3807](https://github.com/pnpm/pnpm/issues/3807).
|
|
10
|
+
|
|
11
|
+
- The side-effects cache now restores the symlinks that a build script creates inside a package. A warm install used to replace each of them with a copy of its target [#12859](https://github.com/pnpm/pnpm/issues/12859).
|
|
12
|
+
|
|
13
|
+
After upgrading, every package with a build script is built once more.
|
|
14
|
+
|
|
15
|
+
- A fresh install reusing a warm global virtual store skips reimporting packages whose target directory is already complete [#11112](https://github.com/pnpm/pnpm/issues/11112).
|
|
16
|
+
|
|
17
|
+
- `pnpm install` now works in StackBlitz WebContainers on projects without a lockfile. It used to fail there with `ENOENT ... pnpm-lock.yaml`, because pnpm did not recognize the errors that WebContainers return from asynchronous file system calls [#15649](https://github.com/pnpm/pnpm/issues/15649).
|
|
18
|
+
|
|
19
|
+
- Updated dependencies:
|
|
20
|
+
- @pnpm/error@1100.2.1
|
|
21
|
+
- @pnpm/fs.graceful-fs@1100.2.4
|
|
22
|
+
- @pnpm/store.controller-types@1101.3.2
|
|
23
|
+
|
|
3
24
|
## 1100.0.30
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -12,5 +12,7 @@ export interface ImportIndexedDirOptions {
|
|
|
12
12
|
*/
|
|
13
13
|
safeToSkip?: boolean;
|
|
14
14
|
resolvedFrom?: ResolvedFrom;
|
|
15
|
+
/** Symlinks to create in the package, keyed by their path relative to it, with their targets. */
|
|
16
|
+
symlinks?: Map<string, string>;
|
|
15
17
|
}
|
|
16
18
|
export declare function importIndexedDir(importer: Importer, newDir: string, filenames: Map<string, string>, opts: ImportIndexedDirOptions): void;
|
package/lib/importIndexedDir.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import
|
|
3
|
+
import { isError } from '@pnpm/error';
|
|
4
4
|
import gfs, { lstatWithRetry, renameFileWithRetry, unlinkWithRetry, withFileLockRetry } from '@pnpm/fs.graceful-fs';
|
|
5
5
|
import { globalInfo, globalWarn, logger } from '@pnpm/logger';
|
|
6
6
|
import { rimrafSync } from '@zkochan/rimraf';
|
|
@@ -34,7 +34,10 @@ export function importIndexedDir(importer, newDir, filenames, opts) {
|
|
|
34
34
|
// handling (EEXIST dedup, ENOENT sanitized-filename retry, etc.) and
|
|
35
35
|
// atomically swaps in a complete directory.
|
|
36
36
|
// keepModulesDir needs the staging path to preserve the existing node_modules.
|
|
37
|
-
if (!opts.keepModulesDir && tryExclusiveImport(importer, newDir, filenames,
|
|
37
|
+
if (!opts.keepModulesDir && tryExclusiveImport(importer, newDir, filenames, {
|
|
38
|
+
links: symlinkDirs(opts, filenames, { writtenDir: newDir, finalDir: newDir }),
|
|
39
|
+
symlinks: opts.symlinks,
|
|
40
|
+
})) {
|
|
38
41
|
return;
|
|
39
42
|
}
|
|
40
43
|
// Staging path: create in temp dir, then atomically rename.
|
|
@@ -43,7 +46,10 @@ export function importIndexedDir(importer, newDir, filenames, opts) {
|
|
|
43
46
|
const stage = pathTemp(newDir);
|
|
44
47
|
try {
|
|
45
48
|
makeEmptyDirSync(stage, { recursive: true });
|
|
46
|
-
tryImportIndexedDir({ importFile: importer.importFile, importFileAtomic: importer.importFile }, stage, filenames,
|
|
49
|
+
tryImportIndexedDir({ importFile: importer.importFile, importFileAtomic: importer.importFile }, stage, filenames, {
|
|
50
|
+
links: symlinkDirs(opts, filenames, { writtenDir: stage, finalDir: newDir }),
|
|
51
|
+
symlinks: opts.symlinks,
|
|
52
|
+
});
|
|
47
53
|
if (opts.keepModulesDir) {
|
|
48
54
|
// Keeping node_modules is needed only when the hoisted node linker is used.
|
|
49
55
|
moveOrMergeModulesDirs(path.join(newDir, 'node_modules'), path.join(stage, 'node_modules'));
|
|
@@ -85,7 +91,7 @@ export function importIndexedDir(importer, newDir, filenames, opts) {
|
|
|
85
91
|
// then puts the completion marker on top of it — after which the directory
|
|
86
92
|
// looks finished to every later install and is never repaired.
|
|
87
93
|
function importIntoSharedDir(dirImport) {
|
|
88
|
-
const { importer, newDir, filenames } = dirImport;
|
|
94
|
+
const { importer, newDir, filenames, opts } = dirImport;
|
|
89
95
|
fs.mkdirSync(path.dirname(newDir), { recursive: true });
|
|
90
96
|
let created = false;
|
|
91
97
|
try {
|
|
@@ -93,12 +99,12 @@ function importIntoSharedDir(dirImport) {
|
|
|
93
99
|
created = true;
|
|
94
100
|
}
|
|
95
101
|
catch (err) {
|
|
96
|
-
if (!
|
|
102
|
+
if (!isError(err) || !('code' in err) || err.code !== 'EEXIST')
|
|
97
103
|
throw err;
|
|
98
104
|
}
|
|
99
105
|
if (created) {
|
|
100
106
|
try {
|
|
101
|
-
tryImportIndexedDir(importer, newDir, filenames);
|
|
107
|
+
tryImportIndexedDir(importer, newDir, filenames, { symlinks: opts.symlinks });
|
|
102
108
|
return;
|
|
103
109
|
}
|
|
104
110
|
catch (err) {
|
|
@@ -109,7 +115,7 @@ function importIntoSharedDir(dirImport) {
|
|
|
109
115
|
// replacement for it.
|
|
110
116
|
}
|
|
111
117
|
}
|
|
112
|
-
if (allFilesMatch(newDir, filenames))
|
|
118
|
+
if (allFilesMatch(newDir, filenames) && allSymlinksMatch(newDir, opts.symlinks))
|
|
113
119
|
return;
|
|
114
120
|
try {
|
|
115
121
|
repairIndexedDir(dirImport);
|
|
@@ -124,7 +130,7 @@ function importIntoSharedDir(dirImport) {
|
|
|
124
130
|
// entry. Files the package does not declare are left alone: a build output
|
|
125
131
|
// belongs to whoever put it there, and a slot other installs are reading is
|
|
126
132
|
// not somewhere to delete from speculatively.
|
|
127
|
-
function repairIndexedDir({ importer, newDir, filenames }) {
|
|
133
|
+
function repairIndexedDir({ importer, newDir, filenames, opts }) {
|
|
128
134
|
makeFileMapDirs(newDir, filenames, { clearBlockers: true });
|
|
129
135
|
let packageJsonSrc;
|
|
130
136
|
for (const [f, src] of filenames) {
|
|
@@ -134,6 +140,12 @@ function repairIndexedDir({ importer, newDir, filenames }) {
|
|
|
134
140
|
}
|
|
135
141
|
replaceFileIfDifferent(importer.importFile, src, path.join(newDir, f));
|
|
136
142
|
}
|
|
143
|
+
for (const [f, target] of opts.symlinks ?? []) {
|
|
144
|
+
const dir = path.posix.dirname(f);
|
|
145
|
+
if (dir !== '.')
|
|
146
|
+
clearDirentBlockingDir(newDir, dir);
|
|
147
|
+
replaceSymlinkIfDifferent(target, path.join(newDir, f));
|
|
148
|
+
}
|
|
137
149
|
if (packageJsonSrc !== undefined) {
|
|
138
150
|
replaceFileIfDifferent(importer.importFile, packageJsonSrc, path.join(newDir, 'package.json'));
|
|
139
151
|
}
|
|
@@ -169,6 +181,26 @@ function replaceFileIfDifferent(importFile, src, dest) {
|
|
|
169
181
|
throw err;
|
|
170
182
|
}
|
|
171
183
|
}
|
|
184
|
+
function replaceSymlinkIfDifferent(target, dest) {
|
|
185
|
+
if (symlinkMatches(dest, target))
|
|
186
|
+
return;
|
|
187
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
188
|
+
const tmp = pathTemp(dest);
|
|
189
|
+
fs.symlinkSync(target, tmp);
|
|
190
|
+
try {
|
|
191
|
+
clearDirBlockingFile(dest);
|
|
192
|
+
renameFileWithRetry(tmp, dest);
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
try {
|
|
196
|
+
fs.unlinkSync(tmp);
|
|
197
|
+
}
|
|
198
|
+
catch { } // eslint-disable-line:no-empty
|
|
199
|
+
if (symlinkMatches(dest, target))
|
|
200
|
+
return;
|
|
201
|
+
throw err;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
172
204
|
// Whether a package directory can go at `dir` now: nothing is there, or
|
|
173
205
|
// what is there is already a directory.
|
|
174
206
|
//
|
|
@@ -182,7 +214,7 @@ function dirFitsAt(dir) {
|
|
|
182
214
|
return lstatWithRetry(dir).isDirectory();
|
|
183
215
|
}
|
|
184
216
|
catch (err) {
|
|
185
|
-
return
|
|
217
|
+
return isError(err) && 'code' in err && err.code === 'ENOENT';
|
|
186
218
|
}
|
|
187
219
|
}
|
|
188
220
|
// A rename cannot put a file where a directory is (EISDIR), so one standing in
|
|
@@ -197,7 +229,7 @@ function clearDirBlockingFile(dest) {
|
|
|
197
229
|
stats = lstatWithRetry(dest);
|
|
198
230
|
}
|
|
199
231
|
catch (err) {
|
|
200
|
-
if (
|
|
232
|
+
if (isError(err) && 'code' in err && err.code === 'ENOENT')
|
|
201
233
|
return;
|
|
202
234
|
throw err;
|
|
203
235
|
}
|
|
@@ -218,7 +250,7 @@ function clearDirentBlockingDir(newDir, relativeDir) {
|
|
|
218
250
|
stats = lstatWithRetry(dir);
|
|
219
251
|
}
|
|
220
252
|
catch (err) {
|
|
221
|
-
if (
|
|
253
|
+
if (isError(err) && 'code' in err && err.code === 'ENOENT')
|
|
222
254
|
return;
|
|
223
255
|
throw err;
|
|
224
256
|
}
|
|
@@ -241,7 +273,7 @@ function clearDirentBlockingDir(newDir, relativeDir) {
|
|
|
241
273
|
// failure.
|
|
242
274
|
function retryWithFixedFileMap(err, dirImport) {
|
|
243
275
|
const { importer, newDir, filenames, opts } = dirImport;
|
|
244
|
-
if (!
|
|
276
|
+
if (!isError(err) || !('code' in err))
|
|
245
277
|
return false;
|
|
246
278
|
if (err.code === 'EEXIST') {
|
|
247
279
|
const { uniqueFileMap, conflictingFileNames } = getUniqueFileMap(filenames);
|
|
@@ -275,13 +307,13 @@ function retryWithFixedFileMap(err, dirImport) {
|
|
|
275
307
|
// otherwise leave a partial package behind: if the surviving files include the
|
|
276
308
|
// package.json completion marker, every later install treats the broken
|
|
277
309
|
// directory as complete and never repairs it.
|
|
278
|
-
function tryExclusiveImport(importer, newDir, filenames,
|
|
310
|
+
function tryExclusiveImport(importer, newDir, filenames, entries) {
|
|
279
311
|
fs.mkdirSync(path.dirname(newDir), { recursive: true });
|
|
280
312
|
try {
|
|
281
313
|
fs.mkdirSync(newDir);
|
|
282
314
|
}
|
|
283
315
|
catch (err) {
|
|
284
|
-
if (
|
|
316
|
+
if (isError(err) && 'code' in err && err.code === 'EEXIST')
|
|
285
317
|
return false;
|
|
286
318
|
throw err;
|
|
287
319
|
}
|
|
@@ -291,7 +323,7 @@ function tryExclusiveImport(importer, newDir, filenames, links) {
|
|
|
291
323
|
// back to staging, so the next attempt — including this process's own method
|
|
292
324
|
// fallbacks (clone → hardlink → copy) — can fast-path again.
|
|
293
325
|
try {
|
|
294
|
-
tryImportIndexedDir(importer, newDir, filenames,
|
|
326
|
+
tryImportIndexedDir(importer, newDir, filenames, entries);
|
|
295
327
|
return true;
|
|
296
328
|
}
|
|
297
329
|
catch {
|
|
@@ -317,6 +349,23 @@ function allFilesMatch(dir, filenames) {
|
|
|
317
349
|
}
|
|
318
350
|
return true;
|
|
319
351
|
}
|
|
352
|
+
function allSymlinksMatch(dir, symlinks) {
|
|
353
|
+
for (const [f, target] of symlinks ?? []) {
|
|
354
|
+
if (!symlinkMatches(path.join(dir, f), target)) {
|
|
355
|
+
globalInfo(`Re-importing "${dir}" because symlink "${f}" does not point to "${target}"`);
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return true;
|
|
360
|
+
}
|
|
361
|
+
function symlinkMatches(dest, target) {
|
|
362
|
+
try {
|
|
363
|
+
return fs.readlinkSync(dest) === target;
|
|
364
|
+
}
|
|
365
|
+
catch {
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
320
369
|
function fileMatches(dir, f, src) {
|
|
321
370
|
const reason = mismatchReason(path.join(dir, f), src);
|
|
322
371
|
if (reason === undefined)
|
|
@@ -398,7 +447,7 @@ function sanitizeFilenames(filenames) {
|
|
|
398
447
|
}
|
|
399
448
|
return { sanitizedFilenames, invalidFilenames };
|
|
400
449
|
}
|
|
401
|
-
function tryImportIndexedDir({ importFile, importFileAtomic }, newDir, filenames, links) {
|
|
450
|
+
function tryImportIndexedDir({ importFile, importFileAtomic }, newDir, filenames, { links, symlinks } = {}) {
|
|
402
451
|
makeFileMapDirs(newDir, filenames);
|
|
403
452
|
// Write package.json last so it acts as a completion marker.
|
|
404
453
|
// pkgExistsAtTargetDir() checks for package.json to decide if a package
|
|
@@ -412,6 +461,11 @@ function tryImportIndexedDir({ importFile, importFileAtomic }, newDir, filenames
|
|
|
412
461
|
}
|
|
413
462
|
importEntry(importFile, src, path.join(newDir, f), links);
|
|
414
463
|
}
|
|
464
|
+
for (const [f, target] of symlinks ?? []) {
|
|
465
|
+
const dest = path.join(newDir, f);
|
|
466
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
467
|
+
fs.symlinkSync(target, dest);
|
|
468
|
+
}
|
|
415
469
|
if (packageJsonSrc !== undefined) {
|
|
416
470
|
importEntry(importFileAtomic, packageJsonSrc, path.join(newDir, 'package.json'), links);
|
|
417
471
|
}
|
|
@@ -462,7 +516,7 @@ function copyInternalSymlink(src, dest, links) {
|
|
|
462
516
|
catch (err) {
|
|
463
517
|
// Creating a symlink on Windows needs a privilege that a junction does
|
|
464
518
|
// not, and a file has no junction to fall back to.
|
|
465
|
-
if (!
|
|
519
|
+
if (!isError(err) || !('code' in err) || err.code !== 'EPERM')
|
|
466
520
|
throw err;
|
|
467
521
|
if (!isDir)
|
|
468
522
|
return false;
|
|
@@ -475,7 +529,7 @@ function realpathOrSelf(file) {
|
|
|
475
529
|
return fs.realpathSync(file);
|
|
476
530
|
}
|
|
477
531
|
catch (err) {
|
|
478
|
-
if (
|
|
532
|
+
if (isError(err) && 'code' in err && err.code === 'ENOENT')
|
|
479
533
|
return file;
|
|
480
534
|
throw err;
|
|
481
535
|
}
|
|
@@ -485,7 +539,7 @@ function isDirectory(file) {
|
|
|
485
539
|
return fs.statSync(file).isDirectory();
|
|
486
540
|
}
|
|
487
541
|
catch (err) {
|
|
488
|
-
if (
|
|
542
|
+
if (isError(err) && 'code' in err && err.code === 'ENOENT')
|
|
489
543
|
return false;
|
|
490
544
|
throw err;
|
|
491
545
|
}
|
|
@@ -534,7 +588,7 @@ function moveOrMergeModulesDirs(src, dest) {
|
|
|
534
588
|
renameEvenAcrossDevices(src, dest);
|
|
535
589
|
}
|
|
536
590
|
catch (err) {
|
|
537
|
-
switch (
|
|
591
|
+
switch (isError(err) && 'code' in err && err.code) {
|
|
538
592
|
case 'ENOENT':
|
|
539
593
|
// If src directory doesn't exist, there is nothing to do
|
|
540
594
|
return;
|
|
@@ -553,7 +607,7 @@ function renameEvenAcrossDevices(src, dest) {
|
|
|
553
607
|
gfs.renameSync(src, dest);
|
|
554
608
|
}
|
|
555
609
|
catch (err) {
|
|
556
|
-
if (!(
|
|
610
|
+
if (!(isError(err) && 'code' in err && err.code === 'EXDEV'))
|
|
557
611
|
throw err;
|
|
558
612
|
fsx.copySync(src, dest);
|
|
559
613
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
|
-
import { constants, existsSync } from 'node:fs';
|
|
2
|
+
import { chmodSync, constants, existsSync } from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import util from 'node:util';
|
|
5
4
|
import { packageImportMethodLogger } from '@pnpm/core-loggers';
|
|
5
|
+
import { isError } from '@pnpm/error';
|
|
6
6
|
import fs from '@pnpm/fs.graceful-fs';
|
|
7
7
|
import { globalInfo, globalWarn } from '@pnpm/logger';
|
|
8
8
|
import { fastPathTemp as pathTemp } from 'path-temp';
|
|
@@ -10,6 +10,10 @@ import { renameOverwriteSync } from 'rename-overwrite';
|
|
|
10
10
|
import { importIndexedDir } from './importIndexedDir.js';
|
|
11
11
|
import { isNativeBinary, removeQuarantine } from './removeQuarantine.js';
|
|
12
12
|
export {};
|
|
13
|
+
const BASE_FILE_MODE = 0o666;
|
|
14
|
+
const EXEC_FILE_MODE = 0o755;
|
|
15
|
+
const CAFS_EXEC_SUFFIX = '-exec';
|
|
16
|
+
const CAFS_DIGEST_MIN_LENGTH = 40;
|
|
13
17
|
export function createIndexedPkgImporter(packageImportMethod, opts) {
|
|
14
18
|
const importPackage = createImportPackage(packageImportMethod, opts);
|
|
15
19
|
return importPackage;
|
|
@@ -70,7 +74,7 @@ function createAutoImporter(createOpts) {
|
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
try {
|
|
73
|
-
if (!hardlinkPkg(
|
|
77
|
+
if (!hardlinkPkg(linkOrThrowOnLinkFailure, to, opts))
|
|
74
78
|
return undefined;
|
|
75
79
|
if (!createOpts?.disableLogging)
|
|
76
80
|
packageImportMethodLogger.debug({ method: 'hardlink' });
|
|
@@ -78,7 +82,7 @@ function createAutoImporter(createOpts) {
|
|
|
78
82
|
return 'hardlink';
|
|
79
83
|
}
|
|
80
84
|
catch (err) {
|
|
81
|
-
assert(
|
|
85
|
+
assert(isError(err));
|
|
82
86
|
if (err.message.startsWith('EXDEV: cross-device link not permitted')) {
|
|
83
87
|
globalWarn(err.message);
|
|
84
88
|
globalInfo('Falling back to copying packages from store');
|
|
@@ -116,6 +120,12 @@ function createCloneOrCopyImporter(createOpts) {
|
|
|
116
120
|
return auto(to, opts);
|
|
117
121
|
}
|
|
118
122
|
}
|
|
123
|
+
function alignedClone(clone) {
|
|
124
|
+
return (src, dest) => {
|
|
125
|
+
clone(src, dest);
|
|
126
|
+
alignStoreFileMode(src, dest);
|
|
127
|
+
};
|
|
128
|
+
}
|
|
119
129
|
/**
|
|
120
130
|
* Import a single package using a raw clone function (no ENOTSUP fallback).
|
|
121
131
|
* Used by auto-mode to probe whether the filesystem supports cloning.
|
|
@@ -123,8 +133,8 @@ function createCloneOrCopyImporter(createOpts) {
|
|
|
123
133
|
* through to a faster method (e.g. hardlinks).
|
|
124
134
|
*/
|
|
125
135
|
function tryClonePkg(to, opts) {
|
|
126
|
-
if (
|
|
127
|
-
const clone = createCloneFunction();
|
|
136
|
+
if (shouldImportPkg(to, opts)) {
|
|
137
|
+
const clone = alignedClone(createCloneFunction());
|
|
128
138
|
importIndexedDir({ importFile: clone, importFileAtomic: clone }, to, opts.filesMap, opts);
|
|
129
139
|
removeQuarantineFromNativeBinaries(to, opts);
|
|
130
140
|
return 'clone';
|
|
@@ -140,13 +150,13 @@ function tryClonePkg(to, opts) {
|
|
|
140
150
|
* atomic.
|
|
141
151
|
*/
|
|
142
152
|
function createClonePkg() {
|
|
143
|
-
const clone = createCloneFunction();
|
|
153
|
+
const clone = alignedClone(createCloneFunction());
|
|
144
154
|
const withFallback = (fallback) => (src, dest) => {
|
|
145
155
|
try {
|
|
146
156
|
clone(src, dest);
|
|
147
157
|
}
|
|
148
158
|
catch (err) {
|
|
149
|
-
if (
|
|
159
|
+
if (isError(err) && 'code' in err && err.code === 'ENOTSUP') {
|
|
150
160
|
fallback(src, dest);
|
|
151
161
|
return;
|
|
152
162
|
}
|
|
@@ -158,7 +168,7 @@ function createClonePkg() {
|
|
|
158
168
|
importFileAtomic: withFallback(atomicCopyFileSync),
|
|
159
169
|
};
|
|
160
170
|
return (to, opts) => {
|
|
161
|
-
if (
|
|
171
|
+
if (shouldImportPkg(to, opts)) {
|
|
162
172
|
importIndexedDir(importer, to, opts.filesMap, opts);
|
|
163
173
|
removeQuarantineFromNativeBinaries(to, opts);
|
|
164
174
|
return 'clone';
|
|
@@ -166,6 +176,18 @@ function createClonePkg() {
|
|
|
166
176
|
return undefined;
|
|
167
177
|
};
|
|
168
178
|
}
|
|
179
|
+
// Whether to (re)import via clone or copy. A directory dependency's source
|
|
180
|
+
// can change without the lockfile changing, so these methods import it
|
|
181
|
+
// unconditionally by default, the same way `shouldRelinkPkg` does for the
|
|
182
|
+
// hardlink path below, including the same guard against wiping an
|
|
183
|
+
// already-materialized target when a `publishConfig.directory` source has
|
|
184
|
+
// not been built yet.
|
|
185
|
+
function shouldImportPkg(to, opts) {
|
|
186
|
+
if (opts.resolvedFrom === 'local-dir' && opts.sourceExists === false) {
|
|
187
|
+
return targetHasNothingToLose(to);
|
|
188
|
+
}
|
|
189
|
+
return opts.resolvedFrom !== 'store' || opts.force || !pkgExistsAtTargetDir(to, opts.filesMap);
|
|
190
|
+
}
|
|
169
191
|
function pkgExistsAtTargetDir(targetDir, filesMap) {
|
|
170
192
|
return existsSync(path.join(targetDir, pickFileFromFilesMap(filesMap)));
|
|
171
193
|
}
|
|
@@ -198,7 +220,7 @@ function createCloneFunction() {
|
|
|
198
220
|
// If the file already exists, then we just proceed.
|
|
199
221
|
// This will probably only happen if the package's index file contains the same file twice.
|
|
200
222
|
// For instance: { "index.js": "hash", "./index.js": "hash" }
|
|
201
|
-
if (!
|
|
223
|
+
if (!isError(err) || !('code' in err) || err.code !== 'EEXIST')
|
|
202
224
|
throw err;
|
|
203
225
|
}
|
|
204
226
|
};
|
|
@@ -209,7 +231,7 @@ function createCloneFunction() {
|
|
|
209
231
|
fs.copyFileSync(src, dest, constants.COPYFILE_FICLONE_FORCE);
|
|
210
232
|
}
|
|
211
233
|
catch (err) {
|
|
212
|
-
if (!(
|
|
234
|
+
if (!(isError(err) && 'code' in err && err.code === 'EEXIST'))
|
|
213
235
|
throw err;
|
|
214
236
|
}
|
|
215
237
|
};
|
|
@@ -217,6 +239,10 @@ function createCloneFunction() {
|
|
|
217
239
|
return _cloneFunction;
|
|
218
240
|
}
|
|
219
241
|
function hardlinkPkg(importFile, to, opts) {
|
|
242
|
+
// Checked ahead of `opts.force`: a caller-requested force must not be able
|
|
243
|
+
// to bypass the missing-source preservation below.
|
|
244
|
+
if (missingSourceHasSomethingToPreserve(to, opts))
|
|
245
|
+
return undefined;
|
|
220
246
|
if (opts.force || shouldRelinkPkg(to, opts)) {
|
|
221
247
|
importIndexedDir({ importFile, importFileAtomic: importFile }, to, opts.filesMap, opts);
|
|
222
248
|
removeQuarantineFromNativeBinaries(to, opts);
|
|
@@ -226,24 +252,100 @@ function hardlinkPkg(importFile, to, opts) {
|
|
|
226
252
|
}
|
|
227
253
|
function shouldRelinkPkg(to, opts) {
|
|
228
254
|
if (opts.disableRelinkLocalDirDeps && opts.resolvedFrom === 'local-dir') {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
255
|
+
return targetHasNothingToLose(to);
|
|
256
|
+
}
|
|
257
|
+
// A directory dependency relinks on every install by default, since its
|
|
258
|
+
// source can change without the lockfile changing. But when the source is
|
|
259
|
+
// a `publishConfig.directory` its own `prepare` script has not (re)built
|
|
260
|
+
// yet, the fetcher tolerates the missing directory and comes back with an
|
|
261
|
+
// empty `filesMap`; relinking from that would wipe an already-materialized
|
|
262
|
+
// target. Only skip the relink when there is something in the target
|
|
263
|
+
// worth preserving — an empty or missing target has nothing to lose, and
|
|
264
|
+
// still needs the relink to create it so the post-build resync has
|
|
265
|
+
// somewhere to write into. `hardlinkPkg` checks this same condition ahead
|
|
266
|
+
// of its own `opts.force`, so this only runs once that has already passed.
|
|
267
|
+
if (opts.resolvedFrom === 'local-dir' && opts.sourceExists === false) {
|
|
268
|
+
return targetHasNothingToLose(to);
|
|
236
269
|
}
|
|
237
270
|
return opts.resolvedFrom !== 'store' || !pkgLinkedToStore(opts.filesMap, to);
|
|
238
271
|
}
|
|
272
|
+
// See `shouldRelinkPkg`'s comment on the missing-source case. Pulled out so
|
|
273
|
+
// `hardlinkPkg` can apply the same guard ahead of its `opts.force` check,
|
|
274
|
+
// which would otherwise bypass it.
|
|
275
|
+
function missingSourceHasSomethingToPreserve(to, opts) {
|
|
276
|
+
return opts.resolvedFrom === 'local-dir' && opts.sourceExists === false && !targetHasNothingToLose(to);
|
|
277
|
+
}
|
|
278
|
+
function targetHasNothingToLose(to) {
|
|
279
|
+
try {
|
|
280
|
+
const files = fs.readdirSync(to);
|
|
281
|
+
return files.length === 0 || files.length === 1 && files[0] === 'node_modules';
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
// The CLI never changes its own umask and the import path asks for it once
|
|
288
|
+
// per file, so read it once.
|
|
289
|
+
let umask;
|
|
290
|
+
function storeEntryMode(executable) {
|
|
291
|
+
umask ??= process.umask();
|
|
292
|
+
return ((executable ? EXEC_FILE_MODE : BASE_FILE_MODE) & ~umask) & 0o777;
|
|
293
|
+
}
|
|
294
|
+
// The exact inverse of the CAFS layout `<store>/v<N>/files/<2 hex digits>/<digest>[-exec]`.
|
|
295
|
+
// This importer also materializes local-directory dependencies, whose files keep
|
|
296
|
+
// the modes their project gives them, so only a real store entry is re-derived.
|
|
297
|
+
function isCafsFile(src) {
|
|
298
|
+
const nameSep = src.lastIndexOf(path.sep);
|
|
299
|
+
if (nameSep < 0)
|
|
300
|
+
return false;
|
|
301
|
+
const shardSep = src.lastIndexOf(path.sep, nameSep - 1);
|
|
302
|
+
if (shardSep < 0 || nameSep - shardSep - 1 !== 2 || !isLowerHex(src, shardSep + 1, nameSep))
|
|
303
|
+
return false;
|
|
304
|
+
const filesSep = src.lastIndexOf(path.sep, shardSep - 1);
|
|
305
|
+
if (filesSep < 0 || shardSep - filesSep - 1 !== 'files'.length || !src.startsWith('files', filesSep + 1))
|
|
306
|
+
return false;
|
|
307
|
+
const digestEnd = src.endsWith(CAFS_EXEC_SUFFIX) ? src.length - CAFS_EXEC_SUFFIX.length : src.length;
|
|
308
|
+
return digestEnd - nameSep - 1 >= CAFS_DIGEST_MIN_LENGTH && isLowerHex(src, nameSep + 1, digestEnd);
|
|
309
|
+
}
|
|
310
|
+
function isLowerHex(value, from, to) {
|
|
311
|
+
for (let i = from; i < to; i++) {
|
|
312
|
+
const code = value.charCodeAt(i);
|
|
313
|
+
if (!((code >= 0x30 && code <= 0x39) || (code >= 0x61 && code <= 0x66)))
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
// A store file carries the umask that was active when it was written, so
|
|
319
|
+
// importing has to apply the current one as though the entry were just
|
|
320
|
+
// written (pnpm/pnpm#3807). POSIX mode bits do not apply on Windows.
|
|
321
|
+
function storeEntryModeForSource(src) {
|
|
322
|
+
if (process.platform === 'win32')
|
|
323
|
+
return undefined;
|
|
324
|
+
return isCafsFile(src) ? storeEntryMode(src.endsWith(CAFS_EXEC_SUFFIX)) : undefined;
|
|
325
|
+
}
|
|
326
|
+
function alignStoreFileMode(src, dest) {
|
|
327
|
+
const mode = storeEntryModeForSource(src);
|
|
328
|
+
if (mode === undefined)
|
|
329
|
+
return;
|
|
330
|
+
chmodSync(dest, mode);
|
|
331
|
+
}
|
|
332
|
+
function storeModeDiffers(existingPath) {
|
|
333
|
+
const storeMode = storeEntryModeForSource(existingPath);
|
|
334
|
+
return storeMode !== undefined && (fs.statSync(existingPath).mode & 0o777) !== storeMode;
|
|
335
|
+
}
|
|
239
336
|
function linkOrCopy(existingPath, newPath) {
|
|
337
|
+
// A hardlink would pin the store-population mode onto the import.
|
|
338
|
+
if (storeModeDiffers(existingPath)) {
|
|
339
|
+
resilientCopyFileSync(existingPath, newPath);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
240
342
|
try {
|
|
241
343
|
fs.linkSync(existingPath, newPath);
|
|
242
344
|
}
|
|
243
345
|
catch (err) {
|
|
244
346
|
// If a hard link to the same file already exists
|
|
245
347
|
// then trying to copy it will make an empty file from it.
|
|
246
|
-
if (
|
|
348
|
+
if (isError(err) && 'code' in err && err.code === 'EEXIST')
|
|
247
349
|
return;
|
|
248
350
|
// In some VERY rare cases (1 in a thousand), hard-link creation fails on Windows.
|
|
249
351
|
// In that case, we just fall back to copying.
|
|
@@ -251,16 +353,27 @@ function linkOrCopy(existingPath, newPath) {
|
|
|
251
353
|
resilientCopyFileSync(existingPath, newPath);
|
|
252
354
|
}
|
|
253
355
|
}
|
|
356
|
+
// The auto-mode hardlink probe: a filesystem that cannot hardlink must keep
|
|
357
|
+
// failing here, so auto backs off to copy.
|
|
358
|
+
function linkOrThrowOnLinkFailure(existingPath, newPath) {
|
|
359
|
+
if (storeModeDiffers(existingPath)) {
|
|
360
|
+
resilientCopyFileSync(existingPath, newPath);
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
fs.linkSync(existingPath, newPath);
|
|
364
|
+
}
|
|
254
365
|
// On Linux CI, the kernel's copy_file_range/sendfile can transiently fail
|
|
255
366
|
// with ENOTSUP under heavy parallel I/O on the same store files.
|
|
256
367
|
// Fall back to manual read+write which uses plain read/write syscalls.
|
|
257
368
|
function resilientCopyFileSync(src, dest) {
|
|
258
369
|
try {
|
|
259
370
|
fs.copyFileSync(src, dest);
|
|
371
|
+
alignStoreFileMode(src, dest);
|
|
260
372
|
}
|
|
261
373
|
catch (err) {
|
|
262
|
-
if (
|
|
263
|
-
const
|
|
374
|
+
if (isError(err) && 'code' in err && err.code === 'ENOTSUP') {
|
|
375
|
+
const storeMode = storeEntryModeForSource(src);
|
|
376
|
+
const srcMode = storeMode ?? fs.statSync(src).mode;
|
|
264
377
|
fs.writeFileSync(dest, fs.readFileSync(src), { mode: srcMode });
|
|
265
378
|
}
|
|
266
379
|
else {
|
|
@@ -276,7 +389,7 @@ function pkgLinkedToStore(filesMap, linkedPkgDir) {
|
|
|
276
389
|
stats0 = fs.statSync(linkedFile);
|
|
277
390
|
}
|
|
278
391
|
catch (err) {
|
|
279
|
-
if (
|
|
392
|
+
if (isError(err) && 'code' in err && err.code === 'ENOENT')
|
|
280
393
|
return false;
|
|
281
394
|
}
|
|
282
395
|
const stats1 = fs.statSync(filesMap.get(filename));
|
|
@@ -286,7 +399,7 @@ function pkgLinkedToStore(filesMap, linkedPkgDir) {
|
|
|
286
399
|
return false;
|
|
287
400
|
}
|
|
288
401
|
export function copyPkg(to, opts) {
|
|
289
|
-
if (
|
|
402
|
+
if (shouldImportPkg(to, opts)) {
|
|
290
403
|
// copyFileSync is not atomic on non-COW filesystems: a crash mid-copy
|
|
291
404
|
// can leave a partially-written file. package.json is the completion
|
|
292
405
|
// marker, so it must be written atomically via temp file + rename.
|
package/lib/removeQuarantine.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { isError } from '@pnpm/error';
|
|
3
4
|
import { globalWarn } from '@pnpm/logger';
|
|
4
5
|
const QUARANTINE_ATTR = 'com.apple.quarantine';
|
|
5
6
|
// Quarantine removal only ever runs on macOS, so the set lists the binary
|
|
@@ -85,6 +86,6 @@ function getStderr(err) {
|
|
|
85
86
|
if (stderr != null)
|
|
86
87
|
return stderr.toString();
|
|
87
88
|
}
|
|
88
|
-
return err
|
|
89
|
+
return isError(err) ? err.message : String(err);
|
|
89
90
|
}
|
|
90
91
|
//# sourceMappingURL=removeQuarantine.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/fs.indexed-pkg-importer",
|
|
3
|
-
"version": "1100.0.
|
|
3
|
+
"version": "1100.0.31",
|
|
4
4
|
"description": "Replicates indexed directories using hard links, copies, or cloning",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -38,8 +38,9 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@pnpm/core-loggers": "1101.0.1",
|
|
41
|
-
"@pnpm/
|
|
42
|
-
"@pnpm/
|
|
41
|
+
"@pnpm/error": "1100.2.1",
|
|
42
|
+
"@pnpm/fs.graceful-fs": "1100.2.4",
|
|
43
|
+
"@pnpm/store.controller-types": "1101.3.2",
|
|
43
44
|
"@reflink/reflink": "0.1.19",
|
|
44
45
|
"@zkochan/rimraf": "^4.0.0",
|
|
45
46
|
"fs-extra": "^11.4.1",
|
|
@@ -54,9 +55,9 @@
|
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
57
|
"@jest/globals": "30.4.1",
|
|
57
|
-
"@pnpm/fs.indexed-pkg-importer": "1100.0.
|
|
58
|
+
"@pnpm/fs.indexed-pkg-importer": "1100.0.31",
|
|
58
59
|
"@pnpm/logger": "1100.0.0",
|
|
59
|
-
"@pnpm/prepare": "1100.0.
|
|
60
|
+
"@pnpm/prepare": "1100.0.33",
|
|
60
61
|
"@types/fs-extra": "^11.0.4"
|
|
61
62
|
},
|
|
62
63
|
"engines": {
|