Skip to content

Commit

Permalink
fix: ES Module compatibility for dirname (#366)
Browse files Browse the repository at this point in the history
Prevent "undefined in ES module scope" errors in type:module projects
  • Loading branch information
rmarescu authored Feb 26, 2025
1 parent 5dd5841 commit fea1339
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/shortest/src/core/compiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ export class TestCompiler {
js: `
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import { createRequire } from 'module';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
import { createRequire } from "module";
const require = createRequire(import.meta.url);
`,
},
Expand Down Expand Up @@ -70,7 +71,15 @@ export class TestCompiler {
},
resolveExtensions: [".ts", ".js", ".mjs"],
banner: {
js: 'import { createRequire } from "module";const require = createRequire(import.meta.url);',
js: `
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import { createRequire } from 'module';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const require = createRequire(import.meta.url);
`,
},
});

Expand Down

0 comments on commit fea1339

Please sign in to comment.