Skip to content

Commit

Permalink
fix(cjs): make transformers overwritable
Browse files Browse the repository at this point in the history
fix #590
  • Loading branch information
privatenumber committed Jun 15, 2024
1 parent 6e117c2 commit c22fa7d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cjs/api/module-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const createExtensions = (
* If not, only expose if it's not namespaced
*/
enumerable: descriptor?.enumerable || !namespace,
writable: true,
});
}

Expand Down
15 changes: 15 additions & 0 deletions tests/specs/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ export default testSuite(({ describe }, node: NodeApis) => {
expect(stdout).toContain('index.ts:3:22');
});

test('loader overwritable from Module', async () => {
await using fixture = await createFixture({
'index.mjs': `
import Module from 'node:module';
const _require = Module.createRequire(import.meta.url);
_require.extensions['.ts'] = () => {};
`,
});

await execaNode(fixture.getPath('index.mjs'), {
nodePath: node.path,
nodeOptions: ['--require', tsxCjsPath],
});
});

test('register / unregister', async () => {
await using fixture = await createFixture({
'register.cjs': `
Expand Down

0 comments on commit c22fa7d

Please sign in to comment.