@pnpm/fs.indexed-pkg-importer 1100.0.36 → 1100.0.38

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @pnpm/fs.indexed-pkg-importer
2
2
 
3
+ ## 1100.0.38
4
+
5
+ ### Patch Changes
6
+
7
+ - `pnpm deploy` now keeps a symlink in the project whose target is missing from the source, such as a link into a `node_modules` directory that was removed after the build. Deploy used to fail with `ENOENT` on such a link [#17571](https://github.com/pnpm/pnpm/issues/17571).
8
+
9
+ ## 1100.0.37
10
+
11
+ ### Patch Changes
12
+
13
+ - `pnpm prune --prod` no longer fails with `ERR_PNPM_EXDEV` when `node_modules` was copied from an earlier Docker build stage [#17424](https://github.com/pnpm/pnpm/issues/17424).
14
+
3
15
  ## 1100.0.36
4
16
 
5
17
  ### Patch Changes
@@ -17,9 +17,10 @@ export function copyInternalSymlink(src, dest, links) {
17
17
  if (escapesDir(links.writtenDir, resolved))
18
18
  return false;
19
19
  if (!links.imported.has(path.relative(links.writtenDir, resolved).split(path.sep).join('/'))) {
20
- const isDir = isDirectory(src);
21
- if (links.symlinkTargets !== 'internal' || !isDir)
22
- return isDir;
20
+ if (targetKind(src) === 'other')
21
+ return false;
22
+ if (links.symlinkTargets !== 'internal')
23
+ return true;
23
24
  }
24
25
  if (process.platform !== 'win32') {
25
26
  fs.symlinkSync(target, dest);
@@ -29,7 +30,9 @@ export function copyInternalSymlink(src, dest, links) {
29
30
  }
30
31
  function copyInternalSymlinkWindows(opts) {
31
32
  const { dest, links, resolved, src, target } = opts;
32
- const isDir = isDirectory(src);
33
+ // A missing target is linked as a directory: under `internal` it is typically
34
+ // a directory the deploy installs, such as `node_modules/<pkg>`.
35
+ const isDir = targetKind(src) !== 'other';
33
36
  try {
34
37
  fs.symlinkSync(target, dest, isDir ? 'dir' : 'file');
35
38
  return true;
@@ -53,13 +56,13 @@ function realpathOrSelf(file) {
53
56
  throw err;
54
57
  }
55
58
  }
56
- function isDirectory(file) {
59
+ function targetKind(file) {
57
60
  try {
58
- return fs.statSync(file).isDirectory();
61
+ return fs.statSync(file).isDirectory() ? 'directory' : 'other';
59
62
  }
60
63
  catch (err) {
61
64
  if (isError(err) && 'code' in err && err.code === 'ENOENT')
62
- return false;
65
+ return 'missing';
63
66
  throw err;
64
67
  }
65
68
  }
@@ -85,21 +85,35 @@ function backupAndRemoveTargetAfterFailedDisplace(newDir, aside, err) {
85
85
  switch (err.code) {
86
86
  case 'ENOENT':
87
87
  return undefined;
88
- // Windows refuses to rename a directory a process runs from; copy a
88
+ // Windows refuses to rename a directory a process runs from, and an
89
+ // overlay filesystem refuses to rename one from a lower layer; copy a
89
90
  // backup to `aside` before removing `newDir` in place so a failed
90
91
  // stage rename can still restore the previous package.
91
92
  case 'EPERM':
92
93
  case 'EACCES':
93
94
  case 'EBUSY':
95
+ case 'EXDEV':
94
96
  try {
95
97
  fs.cpSync(newDir, aside, { recursive: true, verbatimSymlinks: true });
96
- rimrafSync(newDir);
97
- return aside;
98
98
  }
99
- catch (fallbackErr) {
99
+ catch (copyErr) {
100
100
  removeQuietly(aside);
101
- throw fallbackErr;
101
+ throw copyErr;
102
+ }
103
+ try {
104
+ rimrafSync(newDir);
105
+ }
106
+ catch (removeErr) {
107
+ // `newDir` may be partly deleted; copy the missing entries back from
108
+ // `aside`, and keep `aside` on disk if even that fails.
109
+ try {
110
+ fs.cpSync(aside, newDir, { recursive: true, verbatimSymlinks: true, force: false });
111
+ removeQuietly(aside);
112
+ }
113
+ catch { }
114
+ throw removeErr;
102
115
  }
116
+ return aside;
103
117
  default:
104
118
  throw err;
105
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnpm/fs.indexed-pkg-importer",
3
- "version": "1100.0.36",
3
+ "version": "1100.0.38",
4
4
  "description": "Replicates indexed directories using hard links, copies, or cloning",
5
5
  "keywords": [
6
6
  "pnpm",
@@ -56,7 +56,7 @@
56
56
  },
57
57
  "devDependencies": {
58
58
  "@jest/globals": "30.4.1",
59
- "@pnpm/fs.indexed-pkg-importer": "1100.0.36",
59
+ "@pnpm/fs.indexed-pkg-importer": "1100.0.38",
60
60
  "@pnpm/logger": "1100.0.0",
61
61
  "@pnpm/prepare": "1100.0.39",
62
62
  "@types/fs-extra": "^11.0.4"