@pnpm/fs.indexed-pkg-importer 1100.0.30 → 1100.0.32
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 +29 -0
- package/lib/copyInternalSymlink.d.ts +6 -0
- package/lib/copyInternalSymlink.js +61 -0
- package/lib/dirUtils.d.ts +5 -0
- package/lib/dirUtils.js +72 -0
- package/lib/fileMapUtils.d.ts +11 -0
- package/lib/fileMapUtils.js +72 -0
- package/lib/filesHaveEqualContents.d.ts +1 -0
- package/lib/filesHaveEqualContents.js +32 -0
- package/lib/importIndexedDir.d.ts +8 -0
- package/lib/importIndexedDir.js +65 -443
- package/lib/index.js +205 -91
- package/lib/removeQuarantine.js +2 -1
- package/lib/repairIndexedDir.d.ts +8 -0
- package/lib/repairIndexedDir.js +134 -0
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @pnpm/fs.indexed-pkg-importer
|
|
2
2
|
|
|
3
|
+
## 1100.0.32
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies:
|
|
8
|
+
- @pnpm/core-loggers@1101.0.2
|
|
9
|
+
- @pnpm/store.controller-types@1101.3.3
|
|
10
|
+
|
|
11
|
+
## 1100.0.31
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- `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)
|
|
16
|
+
|
|
17
|
+
- 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).
|
|
18
|
+
|
|
19
|
+
- 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).
|
|
20
|
+
|
|
21
|
+
After upgrading, every package with a build script is built once more.
|
|
22
|
+
|
|
23
|
+
- 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).
|
|
24
|
+
|
|
25
|
+
- `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).
|
|
26
|
+
|
|
27
|
+
- Updated dependencies:
|
|
28
|
+
- @pnpm/error@1100.2.1
|
|
29
|
+
- @pnpm/fs.graceful-fs@1100.2.4
|
|
30
|
+
- @pnpm/store.controller-types@1101.3.2
|
|
31
|
+
|
|
3
32
|
## 1100.0.30
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { isError } from '@pnpm/error';
|
|
4
|
+
export function copyInternalSymlink(src, dest, links) {
|
|
5
|
+
let target = fs.readlinkSync(src);
|
|
6
|
+
if (path.isAbsolute(target)) {
|
|
7
|
+
target = path.relative(realpathOrSelf(path.dirname(src)), realpathOrSelf(target));
|
|
8
|
+
}
|
|
9
|
+
const resolved = path.resolve(path.dirname(dest), target);
|
|
10
|
+
if (escapesDir(links.writtenDir, resolved))
|
|
11
|
+
return false;
|
|
12
|
+
if (!links.imported.has(path.relative(links.writtenDir, resolved).split(path.sep).join('/'))) {
|
|
13
|
+
return isDirectory(src);
|
|
14
|
+
}
|
|
15
|
+
if (process.platform !== 'win32') {
|
|
16
|
+
fs.symlinkSync(target, dest);
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return copyInternalSymlinkWindows({ dest, links, resolved, src, target });
|
|
20
|
+
}
|
|
21
|
+
function copyInternalSymlinkWindows(opts) {
|
|
22
|
+
const { dest, links, resolved, src, target } = opts;
|
|
23
|
+
const isDir = isDirectory(src);
|
|
24
|
+
try {
|
|
25
|
+
fs.symlinkSync(target, dest, isDir ? 'dir' : 'file');
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
if (!isError(err) || !('code' in err) || err.code !== 'EPERM')
|
|
30
|
+
throw err;
|
|
31
|
+
if (!isDir)
|
|
32
|
+
return false;
|
|
33
|
+
fs.symlinkSync(path.join(links.finalDir, path.relative(links.writtenDir, resolved)), dest, 'junction');
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function realpathOrSelf(file) {
|
|
38
|
+
try {
|
|
39
|
+
return fs.realpathSync(file);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (isError(err) && 'code' in err && err.code === 'ENOENT')
|
|
43
|
+
return file;
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function isDirectory(file) {
|
|
48
|
+
try {
|
|
49
|
+
return fs.statSync(file).isDirectory();
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
if (isError(err) && 'code' in err && err.code === 'ENOENT')
|
|
53
|
+
return false;
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function escapesDir(rootDir, targetPath) {
|
|
58
|
+
const rel = path.relative(rootDir, targetPath);
|
|
59
|
+
return rel === '..' || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel);
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=copyInternalSymlink.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function clearDirentBlockingDir(newDir: string, relativeDir: string): void;
|
|
2
|
+
export declare function clearDirBlockingFile(dest: string): void;
|
|
3
|
+
export declare function makeFileMapDirs(newDir: string, filenames: Map<string, string>, opts?: {
|
|
4
|
+
clearBlockers: boolean;
|
|
5
|
+
}): void;
|
package/lib/dirUtils.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { isError } from '@pnpm/error';
|
|
4
|
+
import { lstatWithRetry, unlinkWithRetry } from '@pnpm/fs.graceful-fs';
|
|
5
|
+
import { rimrafSync } from '@zkochan/rimraf';
|
|
6
|
+
export function clearDirentBlockingDir(newDir, relativeDir) {
|
|
7
|
+
let dir = newDir;
|
|
8
|
+
for (const segment of relativeDir.split(/[\\/]/)) {
|
|
9
|
+
dir = path.join(dir, segment);
|
|
10
|
+
if (!clearDirentSegment(dir))
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function clearDirentSegment(dir) {
|
|
15
|
+
let stats;
|
|
16
|
+
try {
|
|
17
|
+
stats = lstatWithRetry(dir);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
if (isError(err) && 'code' in err && err.code === 'ENOENT')
|
|
21
|
+
return false;
|
|
22
|
+
throw err;
|
|
23
|
+
}
|
|
24
|
+
if (stats.isDirectory())
|
|
25
|
+
return true;
|
|
26
|
+
try {
|
|
27
|
+
unlinkWithRetry(dir);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
if (!dirFitsAt(dir))
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
function dirFitsAt(dir) {
|
|
36
|
+
try {
|
|
37
|
+
return lstatWithRetry(dir).isDirectory();
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
return isError(err) && 'code' in err && err.code === 'ENOENT';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function clearDirBlockingFile(dest) {
|
|
44
|
+
let stats;
|
|
45
|
+
try {
|
|
46
|
+
stats = lstatWithRetry(dest);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
if (isError(err) && 'code' in err && err.code === 'ENOENT')
|
|
50
|
+
return;
|
|
51
|
+
throw err;
|
|
52
|
+
}
|
|
53
|
+
if (stats.isDirectory()) {
|
|
54
|
+
rimrafSync(dest);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export function makeFileMapDirs(newDir, filenames, opts) {
|
|
58
|
+
const allDirs = new Set();
|
|
59
|
+
for (const relativePath of filenames.keys()) {
|
|
60
|
+
const dir = path.dirname(relativePath);
|
|
61
|
+
if (dir === '.')
|
|
62
|
+
continue;
|
|
63
|
+
allDirs.add(dir);
|
|
64
|
+
}
|
|
65
|
+
for (const dir of Array.from(allDirs).sort((d1, d2) => d1.length - d2.length)) {
|
|
66
|
+
if (opts?.clearBlockers) {
|
|
67
|
+
clearDirentBlockingDir(newDir, dir);
|
|
68
|
+
}
|
|
69
|
+
fs.mkdirSync(path.join(newDir, dir), { recursive: true });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=dirUtils.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface GetUniqueFileMapResult {
|
|
2
|
+
conflictingFileNames: Map<string, string>;
|
|
3
|
+
uniqueFileMap: Map<string, string>;
|
|
4
|
+
}
|
|
5
|
+
export declare function getUniqueFileMap(fileMap: Map<string, string>): GetUniqueFileMapResult;
|
|
6
|
+
export interface SanitizeFilenamesResult {
|
|
7
|
+
sanitizedFilenames: Map<string, string>;
|
|
8
|
+
invalidFilenames: string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function sanitizeFilenames(filenames: Map<string, string>): SanitizeFilenamesResult;
|
|
11
|
+
export declare function moveOrMergeModulesDirs(src: string, dest: string): void;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { isError } from '@pnpm/error';
|
|
4
|
+
import gfs from '@pnpm/fs.graceful-fs';
|
|
5
|
+
import fsx from 'fs-extra';
|
|
6
|
+
import sanitizeFilename from 'sanitize-filename';
|
|
7
|
+
export function getUniqueFileMap(fileMap) {
|
|
8
|
+
const lowercaseFiles = new Map();
|
|
9
|
+
const conflictingFileNames = new Map();
|
|
10
|
+
const uniqueFileMap = new Map();
|
|
11
|
+
for (const filename of Array.from(fileMap.keys()).sort()) {
|
|
12
|
+
const lowercaseFilename = filename.toLowerCase();
|
|
13
|
+
if (lowercaseFiles.has(lowercaseFilename)) {
|
|
14
|
+
conflictingFileNames.set(filename, lowercaseFiles.get(lowercaseFilename));
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
lowercaseFiles.set(lowercaseFilename, filename);
|
|
18
|
+
uniqueFileMap.set(filename, fileMap.get(filename));
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
conflictingFileNames,
|
|
22
|
+
uniqueFileMap,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function sanitizeFilenames(filenames) {
|
|
26
|
+
const sanitizedFilenames = new Map();
|
|
27
|
+
const invalidFilenames = [];
|
|
28
|
+
for (const [filename, src] of filenames) {
|
|
29
|
+
const sanitizedFilename = filename.split('/').map((f) => sanitizeFilename(f)).join('/');
|
|
30
|
+
if (sanitizedFilename !== filename) {
|
|
31
|
+
invalidFilenames.push(filename);
|
|
32
|
+
}
|
|
33
|
+
sanitizedFilenames.set(sanitizedFilename, src);
|
|
34
|
+
}
|
|
35
|
+
return { sanitizedFilenames, invalidFilenames };
|
|
36
|
+
}
|
|
37
|
+
export function moveOrMergeModulesDirs(src, dest) {
|
|
38
|
+
try {
|
|
39
|
+
renameEvenAcrossDevices(src, dest);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
switch (isError(err) && 'code' in err && err.code) {
|
|
43
|
+
case 'ENOENT':
|
|
44
|
+
return;
|
|
45
|
+
case 'ENOTEMPTY':
|
|
46
|
+
case 'EPERM':
|
|
47
|
+
mergeModulesDirs(src, dest);
|
|
48
|
+
return;
|
|
49
|
+
default:
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function renameEvenAcrossDevices(src, dest) {
|
|
55
|
+
try {
|
|
56
|
+
gfs.renameSync(src, dest);
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
if (!(isError(err) && 'code' in err && err.code === 'EXDEV'))
|
|
60
|
+
throw err;
|
|
61
|
+
fsx.copySync(src, dest);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function mergeModulesDirs(src, dest) {
|
|
65
|
+
const srcFiles = fs.readdirSync(src);
|
|
66
|
+
const destFiles = new Set(fs.readdirSync(dest));
|
|
67
|
+
const filesToMove = srcFiles.filter((file) => !destFiles.has(file));
|
|
68
|
+
for (const file of filesToMove) {
|
|
69
|
+
renameEvenAcrossDevices(path.join(src, file), path.join(dest, file));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=fileMapUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function filesHaveEqualContents(left: string, right: string): boolean;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
const FILE_COMPARE_BUFFER_SIZE = 64 * 1024;
|
|
3
|
+
export function filesHaveEqualContents(left, right) {
|
|
4
|
+
const leftBuffer = Buffer.allocUnsafe(FILE_COMPARE_BUFFER_SIZE);
|
|
5
|
+
const rightBuffer = Buffer.allocUnsafe(FILE_COMPARE_BUFFER_SIZE);
|
|
6
|
+
const leftFd = fs.openSync(left, 'r');
|
|
7
|
+
try {
|
|
8
|
+
const rightFd = fs.openSync(right, 'r');
|
|
9
|
+
try {
|
|
10
|
+
return compareOpenFiles(leftFd, rightFd, leftBuffer, rightBuffer);
|
|
11
|
+
}
|
|
12
|
+
finally {
|
|
13
|
+
fs.closeSync(rightFd);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
finally {
|
|
17
|
+
fs.closeSync(leftFd);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function compareOpenFiles(leftFd, rightFd, leftBuffer, rightBuffer) {
|
|
21
|
+
for (;;) {
|
|
22
|
+
const leftBytes = fs.readSync(leftFd, leftBuffer, 0, leftBuffer.length, null);
|
|
23
|
+
const rightBytes = fs.readSync(rightFd, rightBuffer, 0, rightBuffer.length, null);
|
|
24
|
+
if (leftBytes !== rightBytes)
|
|
25
|
+
return false;
|
|
26
|
+
if (leftBytes === 0)
|
|
27
|
+
return true;
|
|
28
|
+
if (!leftBuffer.subarray(0, leftBytes).equals(rightBuffer.subarray(0, rightBytes)))
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=filesHaveEqualContents.js.map
|
|
@@ -12,5 +12,13 @@ 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>;
|
|
17
|
+
}
|
|
18
|
+
export interface IndexedDirImport {
|
|
19
|
+
importer: Importer;
|
|
20
|
+
newDir: string;
|
|
21
|
+
filenames: Map<string, string>;
|
|
22
|
+
opts: ImportIndexedDirOptions;
|
|
15
23
|
}
|
|
16
24
|
export declare function importIndexedDir(importer: Importer, newDir: string, filenames: Map<string, string>, opts: ImportIndexedDirOptions): void;
|