Skip to content

Commit 7d62789

Browse files
authored
Turbopack: fix __dirname (#76902)
`__dirname` was always `undefined` due to a typo. This was a regression from #75358, the PR restores the behavior of 15.1.7 Closes #76497 Closes PACK-4060
1 parent 24c480e commit 7d62789

File tree

97 files changed

+249
-243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+249
-243
lines changed

turbopack/crates/turbopack-ecmascript/src/chunk/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl EcmascriptChunkItemContent {
9090
let mut args = vec![
9191
"g: global",
9292
// HACK
93-
"d: __dirname",
93+
"__dirname",
9494
];
9595
if self.options.async_module.is_some() {
9696
args.push("a: __turbopack_async_module__");

turbopack/crates/turbopack-ecmascript/src/runtime_functions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ pub const TURBOPACK_REQUIRE_STUB: &TurbopackRuntimeFunctionShortcut =
7979
pub const TURBOPACK_REQUIRE_REAL: &TurbopackRuntimeFunctionShortcut =
8080
&TurbopackRuntimeFunctionShortcut::new("__turbopack_context__.t", "t");
8181

82+
/// Adding an entry to this list will automatically ensure that `__turbopack_XXX__` can be called
83+
/// from user code (by inserting a replacement into free_var_references)
8284
pub const TUBROPACK_RUNTIME_FUNCTION_SHORTCUTS: [(&str, &TurbopackRuntimeFunctionShortcut); 21] = [
8385
("__turbopack_require__", TURBOPACK_REQUIRE),
8486
("__turbopack_module_context__", TURBOPACK_MODULE_CONTEXT),
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
it('__dirname and __filename should be set', () => {
2+
expect(__dirname).toMatch(/^\[project\]\/.*\/code-gen\/dirname-filename\/input\/index\.js \[test\] \(ecmascript\)$/)
3+
expect(__filename).toMatch(/dirname-filename\/output\/.*.js$/);
4+
})

turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/dynamic-import/output/4c35f_tests_snapshot_basic-tree-shake_dynamic-import_input_index_92a5f455.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/dynamic-import/output/4c35f_tests_snapshot_basic-tree-shake_dynamic-import_input_lib_44a9b7f1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/dynamic-import/input/lib.js [test] (ecmascript, async loader)": ((__turbopack_context__) => {
44

5-
var { g: global, d: __dirname } = __turbopack_context__;
5+
var { g: global, __dirname } = __turbopack_context__;
66
{
77
__turbopack_context__.v((parentImport) => {
88
return Promise.all([

turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/dynamic-import/output/4c35f_tests_snapshot_basic-tree-shake_dynamic-import_input_lib_8debd8f1.js

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

turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-named/output/b1abf_turbopack-tests_tests_snapshot_basic-tree-shake_export-named_input_8a727493._.js

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

0 commit comments

Comments
 (0)