@pnpm/fs.packlist 1100.0.12 → 1100.0.14

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,23 @@
1
1
  # @pnpm/fs.packlist
2
2
 
3
+ ## 1100.0.14
4
+
5
+ ### Patch Changes
6
+
7
+ - `pnpm pack` and `pnpm publish` in a workspace now keep the workspace's ignore rules when a package's `.npmignore` is removed while pnpm lists the package's files.
8
+
9
+ - Installing an injected local package no longer fails with a "no such file or directory" error when another process renames or removes files in that package while pnpm lists them. This happened most often on macOS in workspaces with `sharedWorkspaceLockfile: false`, where the install of the package itself writes its lockfile at the same time.
10
+
11
+ - Updated dependencies:
12
+ - @pnpm/workspace.project-manifest-reader@1100.1.7
13
+
14
+ ## 1100.0.13
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies:
19
+ - @pnpm/workspace.project-manifest-reader@1100.1.6
20
+
3
21
  ## 1100.0.12
4
22
 
5
23
  ### Patch Changes
@@ -0,0 +1,13 @@
1
+ import npmPacklist from 'npm-packlist';
2
+ /**
3
+ * npm-packlist's walker, except that an entry another process removes while
4
+ * the walk reads it is skipped, as it is not part of the package. A missing
5
+ * package root still fails the walk.
6
+ */
7
+ export declare class VanishedEntriesWalker extends npmPacklist.Walker {
8
+ start(): this;
9
+ private readdir;
10
+ private onListingNotFound;
11
+ stat(opts: Omit<npmPacklist.StatOptions, 'isSymbolicLink' | 'st'>, callback: () => void): void;
12
+ addIgnoreFile(file: string, callback: () => void): void;
13
+ }
@@ -0,0 +1,83 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import npmPacklist from 'npm-packlist';
4
+ // How many times a directory whose listing keeps failing with ENOENT is read.
5
+ const LISTING_ATTEMPTS = 8;
6
+ /**
7
+ * npm-packlist's walker, except that an entry another process removes while
8
+ * the walk reads it is skipped, as it is not part of the package. A missing
9
+ * package root still fails the walk.
10
+ */
11
+ export class VanishedEntriesWalker extends npmPacklist.Walker {
12
+ start() {
13
+ this.readdir(LISTING_ATTEMPTS);
14
+ return this;
15
+ }
16
+ // On macOS, listings of a directory that still exists have failed with
17
+ // ENOENT while another process renamed one of its entries, so such a
18
+ // listing is read again, and one that keeps failing is an error.
19
+ readdir(attemptsLeft) {
20
+ fs.readdir(this.path, (err, entries) => {
21
+ if (err == null) {
22
+ this.onReaddir(entries);
23
+ return;
24
+ }
25
+ if (err.code === 'ENOENT') {
26
+ this.onListingNotFound(err, attemptsLeft);
27
+ }
28
+ else {
29
+ this.emit('error', err);
30
+ }
31
+ });
32
+ }
33
+ onListingNotFound(err, attemptsLeft) {
34
+ fs.lstat(this.path, (statErr) => {
35
+ if (statErr?.code === 'ENOENT' && this.parent != null) {
36
+ this.onReaddir([]);
37
+ }
38
+ else if (statErr == null && attemptsLeft > 1) {
39
+ this.readdir(attemptsLeft - 1);
40
+ }
41
+ else {
42
+ this.emit('error', err);
43
+ }
44
+ });
45
+ }
46
+ // ignore-walk's stat, as npm-packlist configures it: no symlinks followed,
47
+ // and names with `*` skipped, which node-tar cannot pack on Windows.
48
+ stat(opts, callback) {
49
+ if (opts.entry.includes('*')) {
50
+ callback();
51
+ return;
52
+ }
53
+ fs.lstat(`${this.path}/${opts.entry}`, (err, st) => {
54
+ if (err == null) {
55
+ this.onstat({ ...opts, isSymbolicLink: st.isSymbolicLink(), st }, callback);
56
+ }
57
+ else if (err.code === 'ENOENT') {
58
+ callback();
59
+ }
60
+ else {
61
+ this.emit('error', err);
62
+ }
63
+ });
64
+ }
65
+ addIgnoreFile(file, callback) {
66
+ if (file === 'package.json' && this.isPackage) {
67
+ super.addIgnoreFile(file, callback);
68
+ return;
69
+ }
70
+ fs.readFile(path.resolve(this.path, file), 'utf8', (err, data) => {
71
+ if (err == null) {
72
+ this.onReadIgnoreFile(file, data, callback);
73
+ }
74
+ else if (err.code === 'ENOENT') {
75
+ callback();
76
+ }
77
+ else {
78
+ this.emit('error', err);
79
+ }
80
+ });
81
+ }
82
+ }
83
+ //# sourceMappingURL=VanishedEntriesWalker.js.map
package/lib/index.js CHANGED
@@ -5,6 +5,7 @@ import { safeReadProjectManifestOnly } from '@pnpm/workspace.project-manifest-re
5
5
  import { isSubdir } from 'is-subdir';
6
6
  import npmPacklist from 'npm-packlist';
7
7
  import { isSafeBundleName, resolveDependency } from './bundleDependencyResolver.js';
8
+ import { VanishedEntriesWalker } from './VanishedEntriesWalker.js';
8
9
  const ALTERNATE_MANIFEST_NAMES = ['package.yaml', 'package.json5'];
9
10
  /**
10
11
  * npm-packlist applies the manifest rules (`files`, `main`, `bin`, and the
@@ -17,7 +18,33 @@ const ALTERNATE_MANIFEST_NAMES = ['package.yaml', 'package.json5'];
17
18
  * symlinks named in `files`, and leaves it to packlistWithSources to exclude the
18
19
  * ones that point outside the package.
19
20
  */
20
- class PackWalker extends npmPacklist.Walker {
21
+ class PackWalker extends VanishedEntriesWalker {
22
+ workspace;
23
+ constructor(tree, opts) {
24
+ super(tree, opts);
25
+ this.workspace = opts?.workspace;
26
+ }
27
+ // A workspace package inherits the ignore files of the workspace
28
+ // directories above it unless the walk read an .npmignore in its root.
29
+ filterEntries() {
30
+ if (this.workspace != null && this.ignoreRules['.npmignore'] == null) {
31
+ try {
32
+ this.inheritWorkspaceRules(this.workspace);
33
+ }
34
+ catch (err) {
35
+ this.emit('error', err);
36
+ return;
37
+ }
38
+ }
39
+ super.filterEntries();
40
+ }
41
+ // npm-packlist's constructor injects only the default rules, which include
42
+ // the workspace's ignore files when given prefix and workspaces. It reads
43
+ // them synchronously and throws on a read error other than ENOENT.
44
+ inheritWorkspaceRules(workspace) {
45
+ const workspaceWalker = new npmPacklist.Walker(this.tree, { ...workspace, path: this.path, isPackage: true });
46
+ Object.assign(this.ignoreRules, workspaceWalker.ignoreRules);
47
+ }
21
48
  onReaddir(entries) {
22
49
  if (this.isPackage) {
23
50
  entries = entries.filter((entry) => !isLockfileStagingFile(entry));
@@ -111,27 +138,15 @@ export async function packlistWithSources(pkgDir, opts) {
111
138
  const boundary = hasWorkspaceContext ? workspaceDir : path.resolve(opts?.bundledDependenciesDir ?? resolvedPkgDir);
112
139
  const boundaries = getBoundaries(boundary, resolvedPkgDir);
113
140
  const { tree, packedDirs } = buildRootTree(resolvedPkgDir, pkg, boundaries);
114
- const packlistOpts = hasWorkspaceContext && !await hasNpmIgnoreFile(resolvedPkgDir)
115
- ? { prefix: workspaceDir, workspaces: [resolvedPkgDir] }
116
- : undefined;
117
- const files = (await walkPackage(tree, packlistOpts))
141
+ const workspace = hasWorkspaceContext ? { prefix: workspaceDir, workspaces: [resolvedPkgDir] } : undefined;
142
+ const files = (await walkPackage(tree, workspace))
118
143
  .map((file) => file.replace(/^\.[/\\]/, ''))
119
144
  .filter((file) => isInternalFileOrSymlink(resolvedPkgDir, file, boundaries));
120
145
  return mapToPackedPaths(resolvedPkgDir, files, packedDirs);
121
146
  }
122
- async function hasNpmIgnoreFile(pkgDir) {
123
- try {
124
- return (await fs.promises.stat(path.join(pkgDir, '.npmignore'))).isFile();
125
- }
126
- catch (err) {
127
- if (!isError(err) || !('code' in err) || err.code !== 'ENOENT')
128
- throw err;
129
- return false;
130
- }
131
- }
132
- async function walkPackage(tree, packlistOpts) {
147
+ async function walkPackage(tree, workspace) {
133
148
  return new Promise((resolve, reject) => {
134
- new PackWalker(tree, { ...packlistOpts, isPackage: true })
149
+ new PackWalker(tree, { workspace, isPackage: true })
135
150
  .on('done', resolve)
136
151
  .on('error', reject)
137
152
  .start();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnpm/fs.packlist",
3
- "version": "1100.0.12",
3
+ "version": "1100.0.14",
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.5",
31
+ "@pnpm/workspace.project-manifest-reader": "1100.1.7",
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.12"
36
+ "@pnpm/fs.packlist": "1100.0.14"
37
37
  },
38
38
  "engines": {
39
39
  "node": ">=22.13"
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "scripts": {
45
45
  "lint": "eslint \"src/**/*.ts\"",
46
- "compile": "tsgo --build && pn lint --fix",
46
+ "compile": "tsc --build && pn lint --fix",
47
47
  "test": "pn compile"
48
48
  }
49
49
  }