@pnpm/hooks.pnpmfile 1100.0.25 → 1100.0.26

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,11 @@
1
1
  # @pnpm/pnpmfile
2
2
 
3
+ ## 1100.0.26
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed pnpm failing to start under asynchronous Node.js module loaders when no `.pnpmfile.mjs` exists [pnpm/pnpm#11701](https://github.com/pnpm/pnpm/issues/11701).
8
+
3
9
  ## 1100.0.25
4
10
 
5
11
  ### Patch Changes
@@ -76,16 +76,21 @@ export async function requirePnpmfile(pnpmFilePath, prefix) {
76
76
  console.error(err);
77
77
  process.exit(1);
78
78
  }
79
- if (!util.types.isNativeError(err)) {
80
- throw new PnpmFileFailError(pnpmFilePath, toError(err));
79
+ if (isModuleNotFoundError(err) && !pnpmFileExistsSync(pnpmFilePath)) {
80
+ return undefined;
81
81
  }
82
- if (!('code' in err && (err.code === 'MODULE_NOT_FOUND' || err.code === 'ERR_MODULE_NOT_FOUND')) ||
83
- pnpmFileExistsSync(pnpmFilePath)) {
84
- throw new PnpmFileFailError(pnpmFilePath, err);
85
- }
86
- return undefined;
82
+ throw new PnpmFileFailError(pnpmFilePath, toError(err));
87
83
  }
88
84
  }
85
+ /**
86
+ * Errors are matched by shape, not by class, because asynchronous module customization
87
+ * hooks forward them from their own realm, where `util.types.isNativeError()` returns false.
88
+ * See https://github.com/pnpm/pnpm/issues/11701
89
+ */
90
+ function isModuleNotFoundError(err) {
91
+ return typeof err === 'object' && err !== null && 'code' in err &&
92
+ (err.code === 'MODULE_NOT_FOUND' || err.code === 'ERR_MODULE_NOT_FOUND');
93
+ }
89
94
  function pnpmFileExistsSync(pnpmFilePath) {
90
95
  const pnpmFileRealName = pnpmFilePath.endsWith('.cjs') || pnpmFilePath.endsWith('.mjs')
91
96
  ? pnpmFilePath
@@ -93,7 +98,7 @@ function pnpmFileExistsSync(pnpmFilePath) {
93
98
  return fs.existsSync(pnpmFileRealName);
94
99
  }
95
100
  function toError(err) {
96
- if (err instanceof Error)
101
+ if (util.types.isNativeError(err) || err instanceof Error)
97
102
  return err;
98
103
  try {
99
104
  return new Error(String(err), { cause: err });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnpm/hooks.pnpmfile",
3
- "version": "1100.0.25",
3
+ "version": "1100.0.26",
4
4
  "description": "Reading a .pnpmfile.cjs",
5
5
  "keywords": [
6
6
  "pnpm",
@@ -43,7 +43,7 @@
43
43
  "devDependencies": {
44
44
  "@jest/globals": "30.4.1",
45
45
  "@pnpm/fetching.fetcher-base": "1100.2.7",
46
- "@pnpm/hooks.pnpmfile": "1100.0.25",
46
+ "@pnpm/hooks.pnpmfile": "1100.0.26",
47
47
  "@pnpm/logger": "1100.0.0",
48
48
  "@pnpm/test-fixtures": "1100.0.1"
49
49
  },