@pnpm/fs.indexed-pkg-importer 1100.0.33 → 1100.0.34
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 +10 -0
- package/lib/hardlinkedDirMatches.d.ts +3 -0
- package/lib/hardlinkedDirMatches.js +77 -0
- package/lib/importIndexedDir.js +3 -2
- package/lib/index.js +15 -2
- package/lib/repairIndexedDir.js +2 -5
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @pnpm/fs.indexed-pkg-importer
|
|
2
2
|
|
|
3
|
+
## 1100.0.34
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- `pnpm install` hardlinks files from a group-writable or world-writable store again. Before this fix, pnpm copied every file from such a store into `node_modules` [#16677](https://github.com/pnpm/pnpm/issues/16677).
|
|
8
|
+
|
|
9
|
+
- Sped up frozen installs of unchanged injected workspace packages that use hardlinks.
|
|
10
|
+
|
|
11
|
+
- The warning about renamed package files with invalid names no longer prints control characters from those file names.
|
|
12
|
+
|
|
3
13
|
## 1100.0.33
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import fs, {} from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export function hardlinkedDirMatches(dir, files, keepModulesDir) {
|
|
4
|
+
if (files.size === 0)
|
|
5
|
+
return false;
|
|
6
|
+
const directories = expectedDirectories(files);
|
|
7
|
+
if (!directories)
|
|
8
|
+
return false;
|
|
9
|
+
try {
|
|
10
|
+
const rootStat = fs.lstatSync(dir);
|
|
11
|
+
if (!rootStat.isDirectory() || rootStat.isSymbolicLink())
|
|
12
|
+
return false;
|
|
13
|
+
return treeMatches(dir, { files, directories, keepModulesDir });
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function expectedDirectories(files) {
|
|
20
|
+
const directories = new Set();
|
|
21
|
+
for (const relative of files.keys()) {
|
|
22
|
+
if (!isReusableFilePath(relative))
|
|
23
|
+
return undefined;
|
|
24
|
+
for (let parent = path.posix.dirname(relative); parent !== '.'; parent = path.posix.dirname(parent))
|
|
25
|
+
directories.add(parent);
|
|
26
|
+
}
|
|
27
|
+
return directories;
|
|
28
|
+
}
|
|
29
|
+
function isReusableFilePath(relative) {
|
|
30
|
+
if (relative === 'node_modules' || relative.startsWith('node_modules/'))
|
|
31
|
+
return false;
|
|
32
|
+
if (path.isAbsolute(relative) || relative.includes('\\'))
|
|
33
|
+
return false;
|
|
34
|
+
return relative.split('/').every(part => part !== '' && part !== '.' && part !== '..');
|
|
35
|
+
}
|
|
36
|
+
function treeMatches(root, expected) {
|
|
37
|
+
const pending = [''];
|
|
38
|
+
let matched = 0;
|
|
39
|
+
for (let relative = pending.pop(); relative !== undefined; relative = pending.pop()) {
|
|
40
|
+
const count = matchingFilesInDirectory(root, relative, { expected, pending });
|
|
41
|
+
if (count === undefined)
|
|
42
|
+
return false;
|
|
43
|
+
matched += count;
|
|
44
|
+
}
|
|
45
|
+
return matched === expected.files.size;
|
|
46
|
+
}
|
|
47
|
+
function matchingFilesInDirectory(root, relative, { expected, pending }) {
|
|
48
|
+
let matched = 0;
|
|
49
|
+
for (const entry of fs.readdirSync(path.join(root, relative), { withFileTypes: true })) {
|
|
50
|
+
const entryPath = relative ? `${relative}/${entry.name}` : entry.name;
|
|
51
|
+
const kind = matchingEntryKind(path.join(root, entryPath), entryPath, expected);
|
|
52
|
+
if (!kind)
|
|
53
|
+
return undefined;
|
|
54
|
+
if (kind === 'directory')
|
|
55
|
+
pending.push(entryPath);
|
|
56
|
+
if (kind === 'file')
|
|
57
|
+
matched++;
|
|
58
|
+
}
|
|
59
|
+
return matched;
|
|
60
|
+
}
|
|
61
|
+
function matchingEntryKind(targetPath, relative, expected) {
|
|
62
|
+
const target = fs.lstatSync(targetPath, { bigint: true });
|
|
63
|
+
if (target.isSymbolicLink())
|
|
64
|
+
return undefined;
|
|
65
|
+
if (target.isDirectory()) {
|
|
66
|
+
if (expected.keepModulesDir && relative === 'node_modules')
|
|
67
|
+
return 'preserved';
|
|
68
|
+
return expected.directories.has(relative) ? 'directory' : undefined;
|
|
69
|
+
}
|
|
70
|
+
const source = expected.files.get(relative);
|
|
71
|
+
return source && filesHaveSameIdentity(target, fs.lstatSync(source, { bigint: true })) ? 'file' : undefined;
|
|
72
|
+
}
|
|
73
|
+
export function filesHaveSameIdentity(target, source) {
|
|
74
|
+
return target.isFile() && source.isFile() && target.ino !== 0n && target.dev !== 0n &&
|
|
75
|
+
target.ino === source.ino && target.dev === source.dev;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=hardlinkedDirMatches.js.map
|
package/lib/importIndexedDir.js
CHANGED
|
@@ -3,6 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import { isError } from '@pnpm/error';
|
|
4
4
|
import { withFileLockRetry } from '@pnpm/fs.graceful-fs';
|
|
5
5
|
import { globalWarn, logger } from '@pnpm/logger';
|
|
6
|
+
import { sanitizeInline } from '@pnpm/text.sanitize';
|
|
6
7
|
import { rimrafSync } from '@zkochan/rimraf';
|
|
7
8
|
import { makeEmptyDirSync } from 'make-empty-dir';
|
|
8
9
|
import { fastPathTemp as pathTemp } from 'path-temp';
|
|
@@ -147,8 +148,8 @@ function retryWithSanitizedFilenames({ importer, newDir, filenames, opts }) {
|
|
|
147
148
|
if (invalidFilenames.length === 0)
|
|
148
149
|
return false;
|
|
149
150
|
globalWarn(`\
|
|
150
|
-
The package linked to "${path.relative(process.cwd(), newDir)}" had \
|
|
151
|
-
files with invalid names: ${invalidFilenames.join(', ')}. \
|
|
151
|
+
The package linked to "${sanitizeInline(path.relative(process.cwd(), newDir))}" had \
|
|
152
|
+
files with invalid names: ${invalidFilenames.map((filename) => sanitizeInline(filename)).join(', ')}. \
|
|
152
153
|
They were renamed.`);
|
|
153
154
|
importIndexedDir(importer, newDir, sanitizedFilenames, opts);
|
|
154
155
|
return true;
|
package/lib/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import fs from '@pnpm/fs.graceful-fs';
|
|
|
7
7
|
import { globalInfo, globalWarn } from '@pnpm/logger';
|
|
8
8
|
import { fastPathTemp as pathTemp } from 'path-temp';
|
|
9
9
|
import { renameOverwriteSync } from 'rename-overwrite';
|
|
10
|
+
import { hardlinkedDirMatches } from './hardlinkedDirMatches.js';
|
|
10
11
|
import { importIndexedDir } from './importIndexedDir.js';
|
|
11
12
|
import { isNativeBinary, removeQuarantine } from './removeQuarantine.js';
|
|
12
13
|
export {};
|
|
@@ -248,7 +249,11 @@ function hardlinkPkg(importFile, to, opts) {
|
|
|
248
249
|
if (missingSourceHasSomethingToPreserve(to, opts))
|
|
249
250
|
return undefined;
|
|
250
251
|
if (opts.force || shouldRelinkPkg(to, opts)) {
|
|
251
|
-
|
|
252
|
+
const reuseHardlinks = !opts.force && opts.resolvedFrom === 'local-dir' && !opts.symlinks?.size &&
|
|
253
|
+
hardlinkedDirMatches(to, opts.filesMap, opts.keepModulesDir ?? false);
|
|
254
|
+
if (!reuseHardlinks) {
|
|
255
|
+
importIndexedDir({ importFile, importFileAtomic: importFile }, to, opts.filesMap, opts);
|
|
256
|
+
}
|
|
252
257
|
removeQuarantineFromNativeBinaries(to, opts);
|
|
253
258
|
return 'hardlink';
|
|
254
259
|
}
|
|
@@ -332,7 +337,15 @@ function alignStoreFileMode(src, dest) {
|
|
|
332
337
|
}
|
|
333
338
|
function storeModeDiffers(existingPath) {
|
|
334
339
|
const storeMode = storeEntryModeForSource(existingPath);
|
|
335
|
-
return storeMode !== undefined && (fs.statSync(existingPath).mode
|
|
340
|
+
return storeMode !== undefined && !isLinkableStoreMode(fs.statSync(existingPath).mode, storeMode);
|
|
341
|
+
}
|
|
342
|
+
// Group- and other-write may be missing, and group-write may be extra: a
|
|
343
|
+
// store write takes those bits from its shard directory, not from the umask,
|
|
344
|
+
// and the shared inode already grants them through the store. Every other bit
|
|
345
|
+
// must match, so a store populated under a wider umask is still not linked.
|
|
346
|
+
function isLinkableStoreMode(mode, storeMode) {
|
|
347
|
+
const groupOtherWrite = 0o022;
|
|
348
|
+
return ((mode ^ storeMode) & 0o777 & ~groupOtherWrite) === 0 && (mode & ~storeMode & 0o002) === 0;
|
|
336
349
|
}
|
|
337
350
|
function linkOrCopy(existingPath, newPath) {
|
|
338
351
|
// A hardlink would pin the store-population mode onto the import.
|
package/lib/repairIndexedDir.js
CHANGED
|
@@ -5,6 +5,7 @@ import { globalInfo } from '@pnpm/logger';
|
|
|
5
5
|
import { fastPathTemp as pathTemp } from 'path-temp';
|
|
6
6
|
import { clearDirBlockingFile, clearDirentBlockingDir, makeFileMapDirs } from './dirUtils.js';
|
|
7
7
|
import { filesHaveEqualContents } from './filesHaveEqualContents.js';
|
|
8
|
+
import { filesHaveSameIdentity } from './hardlinkedDirMatches.js';
|
|
8
9
|
export function repairIndexedDir({ importer, newDir, filenames, opts }) {
|
|
9
10
|
makeFileMapDirs(newDir, filenames, { clearBlockers: true });
|
|
10
11
|
let packageJsonSrc;
|
|
@@ -115,11 +116,7 @@ export function mismatchReason(target, src) {
|
|
|
115
116
|
if (!targetStat.isFile())
|
|
116
117
|
return 'is not a regular file';
|
|
117
118
|
const srcStat = gfs.statSync(src, { bigint: true });
|
|
118
|
-
|
|
119
|
-
targetStat.dev !== 0n &&
|
|
120
|
-
targetStat.ino === srcStat.ino &&
|
|
121
|
-
targetStat.dev === srcStat.dev;
|
|
122
|
-
if (hasSameFileIdentity)
|
|
119
|
+
if (filesHaveSameIdentity(targetStat, srcStat))
|
|
123
120
|
return undefined;
|
|
124
121
|
if (targetStat.size !== srcStat.size)
|
|
125
122
|
return 'has a different size';
|
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.34",
|
|
4
4
|
"description": "Replicates indexed directories using hard links, copies, or cloning",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"@pnpm/error": "1100.2.2",
|
|
42
42
|
"@pnpm/fs.graceful-fs": "1100.2.5",
|
|
43
43
|
"@pnpm/store.controller-types": "1101.3.3",
|
|
44
|
+
"@pnpm/text.sanitize": "1100.0.1",
|
|
44
45
|
"@reflink/reflink": "0.1.19",
|
|
45
46
|
"@zkochan/rimraf": "^4.0.0",
|
|
46
47
|
"fs-extra": "^11.4.1",
|
|
@@ -55,9 +56,9 @@
|
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
57
58
|
"@jest/globals": "30.4.1",
|
|
58
|
-
"@pnpm/fs.indexed-pkg-importer": "1100.0.
|
|
59
|
+
"@pnpm/fs.indexed-pkg-importer": "1100.0.34",
|
|
59
60
|
"@pnpm/logger": "1100.0.0",
|
|
60
|
-
"@pnpm/prepare": "1100.0.
|
|
61
|
+
"@pnpm/prepare": "1100.0.37",
|
|
61
62
|
"@types/fs-extra": "^11.0.4"
|
|
62
63
|
},
|
|
63
64
|
"engines": {
|