Commit 1071207
committed
fix: inject ESM globals for TypeScript files using __dirname/__filename
Problem:
When TypeScript files use __dirname or __filename (CommonJS globals),
they fail after transpilation to ESM with:
'ReferenceError: __dirname is not defined in ES module scope'
Solution:
- Detect usage of __dirname/__filename in transpiled code
- Automatically inject ESM equivalents at the top of transpiled files:
* import { fileURLToPath } from 'url'
* import { dirname } from 'path'
* const __filename = fileURLToPath(import.meta.url)
* const __dirname = dirname(__filename)
Testing:
- Added test case with TypeScript file using __dirname/__filename
- All 481 container tests pass
- Verified transpiled code works without ReferenceError
Version: 4.0.0-beta.10 -> 4.0.0-beta.111 parent 482aba4 commit 1071207
File tree
4 files changed
+46
-2
lines changed- lib
- test
- data/typescript-support
- unit
4 files changed
+46
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
690 | 690 | | |
691 | 691 | | |
692 | 692 | | |
693 | | - | |
| 693 | + | |
694 | 694 | | |
695 | 695 | | |
696 | 696 | | |
697 | 697 | | |
698 | 698 | | |
699 | 699 | | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
700 | 714 | | |
701 | 715 | | |
702 | 716 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
323 | 338 | | |
324 | 339 | | |
0 commit comments