Skip to content

Commit 37d1f56

Browse files
author
Normal Gaussian
committed
Attempt to fix Node 25.7+ EBADF by reading CJS source of zip files ourselves
1 parent 7ccf6e3 commit 37d1f56

5 files changed

Lines changed: 53 additions & 8 deletions

File tree

.pnp.loader.mjs

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.yarn/versions/32e18d27.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
releases:
2+
"@yarnpkg/builder": patch
3+
"@yarnpkg/cli": patch
4+
"@yarnpkg/core": patch
5+
"@yarnpkg/doctor": patch
6+
"@yarnpkg/extensions": patch
7+
"@yarnpkg/nm": patch
8+
"@yarnpkg/plugin-catalog": patch
9+
"@yarnpkg/plugin-compat": patch
10+
"@yarnpkg/plugin-constraints": patch
11+
"@yarnpkg/plugin-dlx": patch
12+
"@yarnpkg/plugin-essentials": patch
13+
"@yarnpkg/plugin-exec": patch
14+
"@yarnpkg/plugin-file": patch
15+
"@yarnpkg/plugin-git": patch
16+
"@yarnpkg/plugin-github": patch
17+
"@yarnpkg/plugin-http": patch
18+
"@yarnpkg/plugin-init": patch
19+
"@yarnpkg/plugin-interactive-tools": patch
20+
"@yarnpkg/plugin-jsr": patch
21+
"@yarnpkg/plugin-link": patch
22+
"@yarnpkg/plugin-nm": patch
23+
"@yarnpkg/plugin-npm": patch
24+
"@yarnpkg/plugin-npm-cli": patch
25+
"@yarnpkg/plugin-pack": patch
26+
"@yarnpkg/plugin-patch": patch
27+
"@yarnpkg/plugin-pnp": patch
28+
"@yarnpkg/plugin-pnpm": patch
29+
"@yarnpkg/plugin-stage": patch
30+
"@yarnpkg/plugin-typescript": patch
31+
"@yarnpkg/plugin-version": patch
32+
"@yarnpkg/plugin-workspace-tools": patch
33+
"@yarnpkg/pnp": patch
34+
"@yarnpkg/pnpify": patch
35+
"@yarnpkg/sdks": patch

packages/yarnpkg-pnp/sources/esm-loader/built-loader.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/yarnpkg-pnp/sources/esm-loader/hooks/load.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {VirtualFS, npath} from '@yarnpkg/fslib';
2-
import fs from 'fs';
3-
import {fileURLToPath, pathToFileURL} from 'url';
1+
import {VirtualFS, npath} from '@yarnpkg/fslib';
2+
import fs from 'fs';
3+
import {fileURLToPath, pathToFileURL} from 'url';
44

5-
import {SUPPORTS_IMPORT_ATTRIBUTES, SUPPORTS_IMPORT_ATTRIBUTES_ONLY, WATCH_MODE_MESSAGE_USES_ARRAYS} from '../loaderFlags';
6-
import * as loaderUtils from '../loaderUtils';
5+
import {HAS_BROKEN_FSTAT_FOR_ZIP_FDS, SUPPORTS_IMPORT_ATTRIBUTES, SUPPORTS_IMPORT_ATTRIBUTES_ONLY, WATCH_MODE_MESSAGE_USES_ARRAYS} from '../loaderFlags';
6+
import * as loaderUtils from '../loaderUtils';
77

88
// The default `load` doesn't support reading from zip files
99
export async function load(
@@ -61,9 +61,14 @@ export async function load(
6161
});
6262
}
6363

64+
const shouldReadSource = format === `commonjs` && HAS_BROKEN_FSTAT_FOR_ZIP_FDS && filePath.includes(`.zip/`);
65+
const source = format !== `commonjs` || shouldReadSource
66+
? await fs.promises.readFile(filePath, `utf8`)
67+
: undefined;
68+
6469
return {
6570
format,
66-
source: format === `commonjs` ? undefined : await fs.promises.readFile(filePath, `utf8`),
71+
source,
6772
shortCircuit: true,
6873
};
6974
}

packages/yarnpkg-pnp/sources/esm-loader/loaderFlags.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ export const SUPPORTS_IMPORT_ATTRIBUTES = major >= 21 || (major === 20 && minor
2020

2121
// https://github.com/nodejs/node/pull/52104
2222
export const SUPPORTS_IMPORT_ATTRIBUTES_ONLY = major >= 22;
23+
24+
export const HAS_BROKEN_FSTAT_FOR_ZIP_FDS = major > 25 || (major === 25 && minor >= 7);

0 commit comments

Comments
 (0)