Skip to content

Commit 5a61895

Browse files
committed
fix: remove node protocol for internal polyfill
closes #276
1 parent ada8262 commit 5a61895

File tree

5 files changed

+125
-76
lines changed

5 files changed

+125
-76
lines changed

pnpm-lock.yaml

Lines changed: 88 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ catalogs:
3838
diff: ^8.0.2
3939
empathic: ^1.1.0
4040
hookable: ^5.5.3
41-
rolldown: 1.0.0-beta.9-commit.273d50e
41+
rolldown: https://pkg.pr.new/rolldown@c7d1545
4242
rolldown-plugin-dts: ^0.13.5
4343
semver: ^7.7.2
4444
tinyexec: ^1.0.1

src/features/external.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isBuiltin } from 'node:module'
12
import Debug from 'debug'
23
import { toArray } from '../utils/general'
34
import type { ResolvedOptions } from '../options'
@@ -42,7 +43,12 @@ export function ExternalPlugin(options: ResolvedOptions): Plugin {
4243

4344
if (shouldExternal) {
4445
debug('External dependency:', id)
45-
return { id, external: shouldExternal }
46+
return {
47+
id,
48+
external: shouldExternal,
49+
moduleSideEffects:
50+
id.startsWith('node:') || isBuiltin(id) ? false : undefined,
51+
}
4652
}
4753
},
4854
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## index.js
2+
3+
```js
4+
import { createRequire } from "module";
5+
6+
//#region rolldown:runtime
7+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
8+
9+
//#endregion
10+
//#region index.ts
11+
const fn = __require.resolve;
12+
13+
//#endregion
14+
export { fn };
15+
```

tests/index.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,20 @@ test('remove node protocol', async (context) => {
322322
expect(snapshot).not.contains('node:')
323323
})
324324

325+
test('remove node protocol for require polyfill', async (context) => {
326+
const files = {
327+
'index.ts': `export const fn = require.resolve`,
328+
}
329+
const { snapshot } = await testBuild({
330+
context,
331+
files,
332+
options: {
333+
removeNodeProtocol: true,
334+
},
335+
})
336+
expect(snapshot).not.contains('node:')
337+
})
338+
325339
test('without hash and filename conflict', async (context) => {
326340
const files = {
327341
'index.ts': `

0 commit comments

Comments
 (0)