Skip to content

Commit deaf916

Browse files
NormalGaussianNormal Gaussianarcanis
authored
fix: Node 25.7+ EBADF by reading CJS source of zip files (#7070)
Attempts to fix the EBADF encountered due to patching fs by doing the whole read instead. I did this to get my own changes past a client (i.e. convincing them it isn't me that is the issue); I'm not sure this is the right long term choice. ## What's the problem this PR addresses? #7065 Can't load zipped CJS modules in Node 25.7+ ## How did you fix it? Return the source of zipped files instead of letting Node read it. I basically just went off this comment: nodejs/node#62012 (comment) I'm not certain this is the most desirable way to do this, and if it is I'm not sure if there are other places that will need additional fixes. My knowledge of the codebase makes this an uneasy 'this works for me' solution. I suspect that if it is a reasonable solution, there may be some deletion that can be done. ## Checklist - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). - [x] I have set the packages that need to be released for my changes to be effective. - [x] I will check that all automated PR checks pass before the PR gets reviewed. --------- Co-authored-by: Normal Gaussian <[email protected]> Co-authored-by: Maël Nison <[email protected]>
1 parent 888ca61 commit deaf916

5 files changed

Lines changed: 45 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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/plugin-pnp": patch
4+
"@yarnpkg/pnp": patch
5+
6+
declined:
7+
- "@yarnpkg/plugin-compat"
8+
- "@yarnpkg/plugin-constraints"
9+
- "@yarnpkg/plugin-dlx"
10+
- "@yarnpkg/plugin-essentials"
11+
- "@yarnpkg/plugin-init"
12+
- "@yarnpkg/plugin-interactive-tools"
13+
- "@yarnpkg/plugin-nm"
14+
- "@yarnpkg/plugin-npm-cli"
15+
- "@yarnpkg/plugin-pack"
16+
- "@yarnpkg/plugin-patch"
17+
- "@yarnpkg/plugin-pnpm"
18+
- "@yarnpkg/plugin-stage"
19+
- "@yarnpkg/plugin-typescript"
20+
- "@yarnpkg/plugin-version"
21+
- "@yarnpkg/plugin-workspace-tools"
22+
- "@yarnpkg/builder"
23+
- "@yarnpkg/core"
24+
- "@yarnpkg/doctor"
25+
- "@yarnpkg/nm"
26+
- "@yarnpkg/pnpify"
27+
- "@yarnpkg/sdks"

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)