Skip to content

Commit c22fa7d

Browse files
committedJun 15, 2024·
fix(cjs): make transformers overwritable
fix #590
1 parent 6e117c2 commit c22fa7d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed
 

‎src/cjs/api/module-extensions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export const createExtensions = (
120120
* If not, only expose if it's not namespaced
121121
*/
122122
enumerable: descriptor?.enumerable || !namespace,
123+
writable: true,
123124
});
124125
}
125126

‎tests/specs/api.ts

+15
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ export default testSuite(({ describe }, node: NodeApis) => {
7979
expect(stdout).toContain('index.ts:3:22');
8080
});
8181

82+
test('loader overwritable from Module', async () => {
83+
await using fixture = await createFixture({
84+
'index.mjs': `
85+
import Module from 'node:module';
86+
const _require = Module.createRequire(import.meta.url);
87+
_require.extensions['.ts'] = () => {};
88+
`,
89+
});
90+
91+
await execaNode(fixture.getPath('index.mjs'), {
92+
nodePath: node.path,
93+
nodeOptions: ['--require', tsxCjsPath],
94+
});
95+
});
96+
8297
test('register / unregister', async () => {
8398
await using fixture = await createFixture({
8499
'register.cjs': `

0 commit comments

Comments
 (0)
Please sign in to comment.