diff --git a/crates/turbopack-ecmascript/js/src/runtime.js b/crates/turbopack-ecmascript/js/src/runtime.js index cbe2a99ca8b53..8d3c2450e56c4 100644 --- a/crates/turbopack-ecmascript/js/src/runtime.js +++ b/crates/turbopack-ecmascript/js/src/runtime.js @@ -109,6 +109,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -327,6 +339,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-ecmascript/src/chunk/mod.rs b/crates/turbopack-ecmascript/src/chunk/mod.rs index a30f7878a0ae1..25eb9d572ee6e 100644 --- a/crates/turbopack-ecmascript/src/chunk/mod.rs +++ b/crates/turbopack-ecmascript/src/chunk/mod.rs @@ -515,6 +515,7 @@ async fn module_factory(content: EcmascriptChunkItemContentVc) -> Result "v: __turbopack_export_value__", "c: __turbopack_cache__", "l: __turbopack_load__", + "j: __turbopack_cjs__", "p: process", "g: global", // HACK diff --git a/crates/turbopack-ecmascript/src/references/esm/base.rs b/crates/turbopack-ecmascript/src/references/esm/base.rs index faab7a8b8293a..7eed68b9532d4 100644 --- a/crates/turbopack-ecmascript/src/references/esm/base.rs +++ b/crates/turbopack-ecmascript/src/references/esm/base.rs @@ -37,19 +37,23 @@ pub enum ReferencedAsset { impl ReferencedAsset { pub async fn get_ident(&self) -> Result> { Ok(match self { - ReferencedAsset::Some(asset) => { - let path = asset.path().to_string().await?; - Some(magic_identifier::encode(&format!( - "imported module {}", - path - ))) - } + ReferencedAsset::Some(asset) => Some(Self::get_ident_from_placeable(asset).await?), ReferencedAsset::OriginalReferenceTypeExternal(request) => { Some(magic_identifier::encode(&format!("external {}", request))) } ReferencedAsset::None => None, }) } + + pub(crate) async fn get_ident_from_placeable( + asset: &EcmascriptChunkPlaceableVc, + ) -> Result { + let path = asset.path().to_string().await?; + Ok(magic_identifier::encode(&format!( + "imported module {}", + path + ))) + } } #[turbo_tasks::value_impl] diff --git a/crates/turbopack-ecmascript/src/references/esm/export.rs b/crates/turbopack-ecmascript/src/references/esm/export.rs index 050725a6a2fd4..fd3e2b7c88890 100644 --- a/crates/turbopack-ecmascript/src/references/esm/export.rs +++ b/crates/turbopack-ecmascript/src/references/esm/export.rs @@ -8,16 +8,12 @@ use serde::{Deserialize, Serialize}; use swc_core::{ common::DUMMY_SP, ecma::ast::{ - ComputedPropName, Expr, Ident, KeyValueProp, Lit, MemberExpr, MemberProp, Module, - ModuleItem, ObjectLit, Program, Prop, PropName, PropOrSpread, Script, Str, + ComputedPropName, Expr, ExprStmt, Ident, KeyValueProp, Lit, MemberExpr, MemberProp, Module, + ModuleItem, ObjectLit, Program, Prop, PropName, PropOrSpread, Script, Stmt, Str, }, - quote, -}; -use turbo_tasks::{ - primitives::{StringVc, StringsVc}, - trace::TraceRawVcs, - ValueToString, + quote, quote_expr, }; +use turbo_tasks::{primitives::StringVc, trace::TraceRawVcs, ValueToString}; use turbopack_core::{ asset::Asset, chunk::ChunkingContextVc, @@ -29,6 +25,7 @@ use crate::{ chunk::{EcmascriptChunkPlaceableVc, EcmascriptExports}, code_gen::{CodeGenerateable, CodeGenerateableVc, CodeGeneration, CodeGenerationVc}, create_visitor, + references::esm::base::insert_hoisted_stmt, }; #[derive(Clone, Hash, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs)] @@ -39,9 +36,16 @@ pub enum EsmExport { Error, } +#[turbo_tasks::value] +struct ExpandResults { + star_exports: Vec, + has_cjs_exports: bool, +} + #[turbo_tasks::function] -async fn expand_star_exports(root_asset: EcmascriptChunkPlaceableVc) -> Result { +async fn expand_star_exports(root_asset: EcmascriptChunkPlaceableVc) -> Result { let mut set = HashSet::new(); + let mut has_cjs_exports = false; let mut checked_assets = HashSet::new(); checked_assets.insert(root_asset); let mut queue = vec![(root_asset, root_asset.get_exports())]; @@ -92,26 +96,33 @@ async fn expand_star_exports(root_asset: EcmascriptChunkPlaceableVc) -> Result AnalyzeIssue { - code: None, - category: StringVc::cell("analyze".to_string()), - message: StringVc::cell(format!( - "export * used with module {} which is a CommonJS module with exports only \ - available at runtime\nList all export names manually (`export {{ a, b, c }} \ - from \"...\") or rewrite the module to ESM.`", - asset.path().to_string().await? - )), - path: asset.path(), - severity: IssueSeverity::Warning.into(), - source: None, - title: StringVc::cell("unexpected export *".to_string()), + EcmascriptExports::CommonJs => { + has_cjs_exports = true; + AnalyzeIssue { + code: None, + category: StringVc::cell("analyze".to_string()), + message: StringVc::cell(format!( + "export * used with module {} which is a CommonJS module with exports \ + only available at runtime\nList all export names manually (`export {{ a, \ + b, c }} from \"...\") or rewrite the module to ESM, to avoid the \ + additional runtime code.`", + asset.path().to_string().await? + )), + path: asset.path(), + severity: IssueSeverity::Warning.into(), + source: None, + title: StringVc::cell("unexpected export *".to_string()), + } + .cell() + .as_issue() + .emit() } - .cell() - .as_issue() - .emit(), } } - Ok(StringsVc::cell(set.into_iter().collect())) + Ok(ExpandResultsVc::cell(ExpandResults { + star_exports: set.into_iter().collect(), + has_cjs_exports, + })) } #[turbo_tasks::value(shared)] @@ -137,9 +148,12 @@ impl CodeGenerateable for EsmExports { .map(|(k, v)| (Cow::::Borrowed(k), Cow::Borrowed(v))) .collect(); let mut props = Vec::new(); + let mut cjs_exports = Vec::>::new(); + for esm_ref in this.star_exports.iter() { if let ReferencedAsset::Some(asset) = &*esm_ref.get_referenced_asset().await? { - let export_names = expand_star_exports(*asset).await?; + let export_info = expand_star_exports(*asset).await?; + let export_names = &export_info.star_exports; for export in export_names.iter() { if !all_exports.contains_key(&Cow::::Borrowed(export)) { all_exports.insert( @@ -148,6 +162,15 @@ impl CodeGenerateable for EsmExports { ); } } + + if export_info.has_cjs_exports { + let ident = ReferencedAsset::get_ident_from_placeable(asset).await?; + + cjs_exports.push(quote_expr!( + "__turbopack__cjs__($arg)", + arg: Expr = Ident::new(ident.into(), DUMMY_SP).into() + )); + } } } for (exported, local) in all_exports.into_iter() { @@ -204,6 +227,14 @@ impl CodeGenerateable for EsmExports { span: DUMMY_SP, props, }); + let cjs_stmt = if !cjs_exports.is_empty() { + Some(Stmt::Expr(ExprStmt { + span: DUMMY_SP, + expr: Expr::from_exprs(cjs_exports), + })) + } else { + None + }; visitors.push(create_visitor!(visit_mut_program(program: &mut Program) { let stmt = quote!("__turbopack_esm__($getters);" as Stmt, @@ -217,6 +248,9 @@ impl CodeGenerateable for EsmExports { body.insert(0, stmt); } } + if let Some(cjs_stmt) = cjs_stmt.clone() { + insert_hoisted_stmt(program, cjs_stmt); + } })); Ok(CodeGeneration { visitors }.into()) diff --git a/crates/turbopack-ecmascript/src/references/mod.rs b/crates/turbopack-ecmascript/src/references/mod.rs index a3840d3864195..8c3dcce3e4733 100644 --- a/crates/turbopack-ecmascript/src/references/mod.rs +++ b/crates/turbopack-ecmascript/src/references/mod.rs @@ -401,10 +401,10 @@ pub(crate) async fn analyze_ecmascript_module( .into(); analysis.add_code_gen(esm_exports); EcmascriptExports::EsmExports(esm_exports) - } else if let Program::Module(_) = program { - EcmascriptExports::None - } else { + } else if has_cjs_export(program) { EcmascriptExports::CommonJs + } else { + EcmascriptExports::None }; analysis.set_exports(exports); @@ -1933,3 +1933,45 @@ async fn resolve_as_webpack_runtime( // TODO enable serialization #[turbo_tasks::value(transparent, serialization = "none")] pub struct AstPath(#[turbo_tasks(trace_ignore)] Vec); + +fn has_cjs_export(p: &Program) -> bool { + use swc_core::ecma::visit::{visit_obj_and_computed, Visit, VisitWith}; + + if let Program::Module(m) = p { + // Check for imports/exports + if m.body.iter().any(ModuleItem::is_module_decl) { + return false; + } + } + + struct Visitor { + found: bool, + } + + impl Visit for Visitor { + visit_obj_and_computed!(); + + fn visit_ident(&mut self, i: &Ident) { + if &*i.sym == "module" || &*i.sym == "exports" { + self.found = true; + } + } + fn visit_expr(&mut self, n: &Expr) { + if self.found { + return; + } + n.visit_children_with(self); + } + + fn visit_stmt(&mut self, n: &Stmt) { + if self.found { + return; + } + n.visit_children_with(self); + } + } + + let mut v = Visitor { found: false }; + p.visit_with(&mut v); + v.found +} diff --git a/crates/turbopack-tests/tests/snapshot.rs b/crates/turbopack-tests/tests/snapshot.rs index 218e393be7359..a0ddac9a7fee7 100644 --- a/crates/turbopack-tests/tests/snapshot.rs +++ b/crates/turbopack-tests/tests/snapshot.rs @@ -412,7 +412,12 @@ async fn handle_issues(source: FileSystemPathVc) -> Result<()> { let plain_issue = issue.into_plain(); let hash = encode_hex(*plain_issue.internal_hash().await?); - let path = issues_path.join(&format!("{}-{}.txt", plain_issue.await?.title, &hash[0..6])); + // We replace "*" because it's not allowed for filename on Windows. + let path = issues_path.join(&format!( + "{}-{}.txt", + plain_issue.await?.title.replace('*', "__star__"), + &hash[0..6] + )); seen.insert(path); // Annoyingly, the PlainIssue.source -> PlainIssueSource.asset -> diff --git a/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/20803_foo_index.js b/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/20803_foo_index.js index 3d60635b26ac6..8936f5ee92f3e 100644 --- a/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/20803_foo_index.js +++ b/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/20803_foo_index.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/20803_foo_index.js", { -"[project]/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/node_modules/foo/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/node_modules/foo/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { __turbopack_esm__({ "foo": ()=>foo diff --git a/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/79fb1_turbopack-tests_tests_snapshot_basic_async_chunk_input_import.js_manifest-chunk.js b/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/79fb1_turbopack-tests_tests_snapshot_basic_async_chunk_input_import.js_manifest-chunk.js index aff1c0f7d00a8..3fbaf844a2958 100644 --- a/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/79fb1_turbopack-tests_tests_snapshot_basic_async_chunk_input_import.js_manifest-chunk.js +++ b/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/79fb1_turbopack-tests_tests_snapshot_basic_async_chunk_input_import.js_manifest-chunk.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/79fb1_turbopack-tests_tests_snapshot_basic_async_chunk_input_import.js_manifest-chunk.js", { -"[project]/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/import.js/manifest-chunk.js": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/import.js/manifest-chunk.js": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { const chunks = [ "output/crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_import.js", diff --git a/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_import.js b/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_import.js index 0124f713233f5..74a2b45893bc2 100644 --- a/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_import.js +++ b/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_import.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_import.js", { -"[project]/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/import.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/import.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2f$async_chunk$2f$input$2f$node_modules$2f$foo$2f$index$2e$js__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/node_modules/foo/index.js (ecmascript)"); "__TURBOPACK__ecmascript__hoisting__location__"; diff --git a/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_index_9be35c.js b/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_index_9be35c.js index 7c8c1d2e0c0ac..6daec75406e01 100644 --- a/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_index_9be35c.js +++ b/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_index_9be35c.js @@ -1,13 +1,13 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_index_9be35c.js", { -"[project]/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { __turbopack_require__("[project]/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/import.js/manifest-loader.js")(__turbopack_import__).then(({ foo })=>{ foo(true); }); }.call(this) }), -"[project]/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/import.js/manifest-loader.js": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/import.js/manifest-loader.js": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { __turbopack_export_value__((__turbopack_import__) => { @@ -172,6 +172,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -390,6 +402,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/basic/chunked/output/39e84_foo_index.js b/crates/turbopack-tests/tests/snapshot/basic/chunked/output/39e84_foo_index.js index 82ab2eb6b91e5..ef5532ab97bc7 100644 --- a/crates/turbopack-tests/tests/snapshot/basic/chunked/output/39e84_foo_index.js +++ b/crates/turbopack-tests/tests/snapshot/basic/chunked/output/39e84_foo_index.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/39e84_foo_index.js", { -"[project]/crates/turbopack-tests/tests/snapshot/basic/chunked/input/node_modules/foo/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/basic/chunked/input/node_modules/foo/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { __turbopack_esm__({ "foo": ()=>foo diff --git a/crates/turbopack-tests/tests/snapshot/basic/chunked/output/crates_turbopack-tests_tests_snapshot_basic_chunked_input_index_b11d49.js b/crates/turbopack-tests/tests/snapshot/basic/chunked/output/crates_turbopack-tests_tests_snapshot_basic_chunked_input_index_b11d49.js index 0c834e3dc7ec0..c20453eec5bc2 100644 --- a/crates/turbopack-tests/tests/snapshot/basic/chunked/output/crates_turbopack-tests_tests_snapshot_basic_chunked_input_index_b11d49.js +++ b/crates/turbopack-tests/tests/snapshot/basic/chunked/output/crates_turbopack-tests_tests_snapshot_basic_chunked_input_index_b11d49.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_basic_chunked_input_index_b11d49.js", { -"[project]/crates/turbopack-tests/tests/snapshot/basic/chunked/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/basic/chunked/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2f$chunked$2f$input$2f$node_modules$2f$foo$2f$index$2e$js__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/basic/chunked/input/node_modules/foo/index.js (ecmascript)"); "__TURBOPACK__ecmascript__hoisting__location__"; @@ -164,6 +164,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -382,6 +394,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/output/crates_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_e03a4b.js b/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/output/crates_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_e03a4b.js index 74bd46d6a706e..1dd2fc18e820f 100644 --- a/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/output/crates_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_e03a4b.js +++ b/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/output/crates_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_e03a4b.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_e03a4b.js", { -"[project]/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { ; @@ -161,6 +161,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -379,6 +391,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/css/css/output/8697f_foo_style.module.css.js b/crates/turbopack-tests/tests/snapshot/css/css/output/8697f_foo_style.module.css.js index 83e3f4ed76e61..b4b94feae7f94 100644 --- a/crates/turbopack-tests/tests/snapshot/css/css/output/8697f_foo_style.module.css.js +++ b/crates/turbopack-tests/tests/snapshot/css/css/output/8697f_foo_style.module.css.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/8697f_foo_style.module.css.js", { -"[project]/crates/turbopack-tests/tests/snapshot/css/css/input/node_modules/foo/style.module.css (css module)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/css/css/input/node_modules/foo/style.module.css (css module)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { __turbopack_export_value__({ "foo-module-style": "foo-module-style◽[project]/crates/turbopack-tests/tests/snapshot/css/css/input/node_modules/foo/style.module.css", diff --git a/crates/turbopack-tests/tests/snapshot/css/css/output/crates_turbopack-tests_tests_snapshot_css_css_input_index_907a50.js b/crates/turbopack-tests/tests/snapshot/css/css/output/crates_turbopack-tests_tests_snapshot_css_css_input_index_907a50.js index bf167adf14233..a1850e1f9cb21 100644 --- a/crates/turbopack-tests/tests/snapshot/css/css/output/crates_turbopack-tests_tests_snapshot_css_css_input_index_907a50.js +++ b/crates/turbopack-tests/tests/snapshot/css/css/output/crates_turbopack-tests_tests_snapshot_css_css_input_index_907a50.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_css_css_input_index_907a50.js", { -"[project]/crates/turbopack-tests/tests/snapshot/css/css/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/css/css/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$css$2f$css$2f$input$2f$node_modules$2f$foo$2f$style$2e$module$2e$css__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/css/css/input/node_modules/foo/style.module.css (css module)"); var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$css$2f$css$2f$input$2f$style$2e$module$2e$css__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/css/css/input/style.module.css (css module)"); @@ -13,7 +13,7 @@ var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests console.log(__TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$css$2f$css$2f$input$2f$style$2e$module$2e$css__["default"], __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$css$2f$css$2f$input$2f$node_modules$2f$foo$2f$style$2e$module$2e$css__["default"]); })()), -"[project]/crates/turbopack-tests/tests/snapshot/css/css/input/style.module.css (css module)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/css/css/input/style.module.css (css module)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { __turbopack_export_value__({ "inner": "inner◽[project]/crates/turbopack-tests/tests/snapshot/css/css/input/style.module.css", @@ -177,6 +177,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -395,6 +407,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/63a02_@emotion_react_index.js b/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/63a02_@emotion_react_index.js index 91cdad7251fdd..bef20d3f18344 100644 --- a/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/63a02_@emotion_react_index.js +++ b/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/63a02_@emotion_react_index.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/63a02_@emotion_react_index.js", { -"[project]/crates/turbopack-tests/tests/node_modules/@emotion/react/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/node_modules/@emotion/react/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { "purposefully empty stub"; "@emtion/react/index.js"; diff --git a/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/63a02_@emotion_react_jsx-dev-runtime.js b/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/63a02_@emotion_react_jsx-dev-runtime.js index a2513fdf45671..25e470b2c2fca 100644 --- a/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/63a02_@emotion_react_jsx-dev-runtime.js +++ b/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/63a02_@emotion_react_jsx-dev-runtime.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/63a02_@emotion_react_jsx-dev-runtime.js", { -"[project]/crates/turbopack-tests/tests/node_modules/@emotion/react/jsx-dev-runtime.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/node_modules/@emotion/react/jsx-dev-runtime.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { "purposefully empty stub"; "@emtion/react/jsx-dev-runtime.js"; diff --git a/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/63a02_@emotion_styled_index.js b/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/63a02_@emotion_styled_index.js index 1c064a96c1c69..c2ec3e7d7308f 100644 --- a/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/63a02_@emotion_styled_index.js +++ b/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/63a02_@emotion_styled_index.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/63a02_@emotion_styled_index.js", { -"[project]/crates/turbopack-tests/tests/node_modules/@emotion/styled/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/node_modules/@emotion/styled/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { "purposefully empty stub"; "@emtion/styled/index.js"; diff --git a/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/crates_turbopack-tests_tests_snapshot_emotion_emotion_input_index_b6dbf3.js b/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/crates_turbopack-tests_tests_snapshot_emotion_emotion_input_index_b6dbf3.js index 6eb3bccb27098..7b6bedff35583 100644 --- a/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/crates_turbopack-tests_tests_snapshot_emotion_emotion_input_index_b6dbf3.js +++ b/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/crates_turbopack-tests_tests_snapshot_emotion_emotion_input_index_b6dbf3.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_emotion_emotion_input_index_b6dbf3.js", { -"[project]/crates/turbopack-tests/tests/snapshot/emotion/emotion/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/emotion/emotion/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$node_modules$2f40$emotion$2f$react$2f$jsx$2d$dev$2d$runtime$2e$js__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/node_modules/@emotion/react/jsx-dev-runtime.js (ecmascript)"); var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$node_modules$2f40$emotion$2f$react$2f$index$2e$js__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/node_modules/@emotion/react/index.js (ecmascript)"); @@ -184,6 +184,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -402,6 +414,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/env/env/output/crates_turbopack-tests_tests_snapshot_env_env_input_480486.js b/crates/turbopack-tests/tests/snapshot/env/env/output/crates_turbopack-tests_tests_snapshot_env_env_input_480486.js index 41f36b60f5ed8..d6048c170caa4 100644 --- a/crates/turbopack-tests/tests/snapshot/env/env/output/crates_turbopack-tests_tests_snapshot_env_env_input_480486.js +++ b/crates/turbopack-tests/tests/snapshot/env/env/output/crates_turbopack-tests_tests_snapshot_env_env_input_480486.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_env_env_input_480486.js", { -"[project]/crates/turbopack-tests/tests/snapshot/env/env/input/.env/.env.js": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/env/env/input/.env/.env.js": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { const env = process.env = {...process.env}; @@ -8,7 +8,7 @@ env["FOO"] = foo; env["FOOBAR"] = foobar; })()), -"[project]/crates/turbopack-tests/tests/snapshot/env/env/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/env/env/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { console.log(process.env.FOOBAR); @@ -170,6 +170,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -388,6 +400,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/evaluated_entrry/runtime_entry/output/a587c_tests_snapshot_evaluated_entrry_runtime_entry_input_index_50fbca.js b/crates/turbopack-tests/tests/snapshot/evaluated_entrry/runtime_entry/output/a587c_tests_snapshot_evaluated_entrry_runtime_entry_input_index_50fbca.js index 3dd7322c4a938..896b44c6ce525 100644 --- a/crates/turbopack-tests/tests/snapshot/evaluated_entrry/runtime_entry/output/a587c_tests_snapshot_evaluated_entrry_runtime_entry_input_index_50fbca.js +++ b/crates/turbopack-tests/tests/snapshot/evaluated_entrry/runtime_entry/output/a587c_tests_snapshot_evaluated_entrry_runtime_entry_input_index_50fbca.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/a587c_tests_snapshot_evaluated_entrry_runtime_entry_input_index_50fbca.js", { -"[project]/crates/turbopack-tests/tests/snapshot/evaluated_entrry/runtime_entry/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/evaluated_entrry/runtime_entry/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { console.log("hello world"); @@ -161,6 +161,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -379,6 +391,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/example/example/output/crates_turbopack-tests_tests_snapshot_example_example_input_index_a7beb7.js b/crates/turbopack-tests/tests/snapshot/example/example/output/crates_turbopack-tests_tests_snapshot_example_example_input_index_a7beb7.js index 7926564cb45b0..16f4881ef9295 100644 --- a/crates/turbopack-tests/tests/snapshot/example/example/output/crates_turbopack-tests_tests_snapshot_example_example_input_index_a7beb7.js +++ b/crates/turbopack-tests/tests/snapshot/example/example/output/crates_turbopack-tests_tests_snapshot_example_example_input_index_a7beb7.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_example_example_input_index_a7beb7.js", { -"[project]/crates/turbopack-tests/tests/snapshot/example/example/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/example/example/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { console.log("hello world"); @@ -161,6 +161,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -379,6 +391,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/b.js b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/b.js new file mode 100644 index 0000000000000..55591793dce25 --- /dev/null +++ b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/b.js @@ -0,0 +1,4 @@ +// b.js +export * from "./c"; +// This would not be handled, but still need __turbopack__cjs__ +// as there are properties dynamically added by __turbopack__cjs__ in c.js diff --git a/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/c.js b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/c.js new file mode 100644 index 0000000000000..9d4bfd782ed88 --- /dev/null +++ b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/c.js @@ -0,0 +1,3 @@ +// c.js +export * from "./commonjs.js"; +// This would be handled by existing logic diff --git a/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/commonjs.js b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/commonjs.js new file mode 100644 index 0000000000000..70410e762b19a --- /dev/null +++ b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/commonjs.js @@ -0,0 +1,3 @@ +// commonjs.js +exports.hello = "World"; + diff --git a/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/index.js b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/index.js new file mode 100644 index 0000000000000..7079fea2e886e --- /dev/null +++ b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/index.js @@ -0,0 +1,3 @@ +// a.js +import * as B from "./b"; +console.log(B); \ No newline at end of file diff --git a/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/issues/unexpected export __star__-d9d1ce.txt b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/issues/unexpected export __star__-d9d1ce.txt new file mode 100644 index 0000000000000..7de7775fba841 --- /dev/null +++ b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/issues/unexpected export __star__-d9d1ce.txt @@ -0,0 +1,11 @@ +PlainIssue { + severity: Warning, + context: "[project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/commonjs.js", + category: "analyze", + title: "unexpected export *", + description: "export * used with module [project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/commonjs.js which is a CommonJS module with exports only available at runtime\nList all export names manually (`export { a, b, c } from \"...\") or rewrite the module to ESM, to avoid the additional runtime code.`", + detail: "", + documentation_link: "", + source: None, + sub_issues: [], +} \ No newline at end of file diff --git a/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-2_input_index_176583.js b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-2_input_index_176583.js new file mode 100644 index 0000000000000..d55d8243b522a --- /dev/null +++ b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-2_input_index_176583.js @@ -0,0 +1,1082 @@ +(self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-2_input_index_176583.js", { + +"[project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { + +var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$export$2d$alls$2f$cjs$2d$2$2f$input$2f$b$2e$js__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/b.js (ecmascript)"); +"__TURBOPACK__ecmascript__hoisting__location__"; +; +console.log(__TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$export$2d$alls$2f$cjs$2d$2$2f$input$2f$b$2e$js__); + +}.call(this) }), +"[project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/b.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { + +__turbopack_esm__({}); +var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$export$2d$alls$2f$cjs$2d$2$2f$input$2f$c$2e$js__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/c.js (ecmascript)"); +__turbopack__cjs__(__TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$export$2d$alls$2f$cjs$2d$2$2f$input$2f$c$2e$js__); +"__TURBOPACK__ecmascript__hoisting__location__"; +; + +})()), +"[project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/c.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { + +__turbopack_esm__({}); +var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$export$2d$alls$2f$cjs$2d$2$2f$input$2f$commonjs$2e$js__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/commonjs.js (ecmascript)"); +__turbopack__cjs__(__TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$export$2d$alls$2f$cjs$2d$2$2f$input$2f$commonjs$2e$js__); +"__TURBOPACK__ecmascript__hoisting__location__"; +; + +})()), +"[project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/commonjs.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { + +exports.hello = "World"; + +}.call(this) }), +}, ({ loadedChunks, instantiateRuntimeModule }) => { + if(!(true && loadedChunks.has("output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-2_input_index_8b9f40.js"))) return true; + instantiateRuntimeModule("[project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/index.js (ecmascript)"); +}]); +(() => { +if (!Array.isArray(globalThis.TURBOPACK)) { + return; +} +/** @typedef {import('../types/backend').RuntimeBackend} RuntimeBackend */ + +/** @type {RuntimeBackend} */ +const BACKEND = { + loadChunk(chunkPath, _from) { + return new Promise((resolve, reject) => { + if (chunkPath.endsWith(".css")) { + const link = document.createElement("link"); + link.rel = "stylesheet"; + link.href = `/${chunkPath}`; + link.onerror = () => { + reject(); + }; + link.onload = () => { + // CSS chunks do not register themselves, and as such must be marked as + // loaded instantly. + resolve(); + }; + document.body.appendChild(link); + } else if (chunkPath.endsWith(".js")) { + const script = document.createElement("script"); + script.src = `/${chunkPath}`; + // We'll only mark the chunk as loaded once the script has been executed, + // which happens in `registerChunk`. Hence the absence of `resolve()` in + // this branch. + script.onerror = () => { + reject(); + }; + document.body.appendChild(script); + } else { + throw new Error(`can't infer type of chunk from path ${chunkPath}`); + } + }); + }, + + restart: () => self.location.reload(), +}; +/* eslint-disable @next/next/no-assign-module-variable */ + +/** @typedef {import('../types').ChunkRegistration} ChunkRegistration */ +/** @typedef {import('../types').ModuleFactory} ModuleFactory */ + +/** @typedef {import('../types').ChunkPath} ChunkPath */ +/** @typedef {import('../types').ModuleId} ModuleId */ +/** @typedef {import('../types').GetFirstModuleChunk} GetFirstModuleChunk */ + +/** @typedef {import('../types').Module} Module */ +/** @typedef {import('../types').Exports} Exports */ +/** @typedef {import('../types').EsmInteropNamespace} EsmInteropNamespace */ +/** @typedef {import('../types').Runnable} Runnable */ + +/** @typedef {import('../types').Runtime} Runtime */ + +/** @typedef {import('../types').RefreshHelpers} RefreshHelpers */ +/** @typedef {import('../types/hot').Hot} Hot */ +/** @typedef {import('../types/hot').HotData} HotData */ +/** @typedef {import('../types/hot').AcceptCallback} AcceptCallback */ +/** @typedef {import('../types/hot').AcceptErrorHandler} AcceptErrorHandler */ +/** @typedef {import('../types/hot').HotState} HotState */ +/** @typedef {import('../types/protocol').EcmascriptChunkUpdate} EcmascriptChunkUpdate */ +/** @typedef {import('../types/protocol').HmrUpdateEntry} HmrUpdateEntry */ + +/** @typedef {import('../types/runtime').Loader} Loader */ +/** @typedef {import('../types/runtime').ModuleEffect} ModuleEffect */ + +/** @type {Array} */ +let runnable = []; +/** @type {Object.} */ +const moduleFactories = { __proto__: null }; +/** @type {Object.} */ +const moduleCache = { __proto__: null }; +/** + * Contains the IDs of all chunks that have been loaded. + * + * @type {Set} + */ +const loadedChunks = new Set(); +/** + * Maps a chunk ID to the chunk's loader if the chunk is currently being loaded. + * + * @type {Map} + */ +const chunkLoaders = new Map(); +/** + * Maps module IDs to persisted data between executions of their hot module + * implementation (`hot.data`). + * + * @type {Map} + */ +const moduleHotData = new Map(); +/** + * Maps module instances to their hot module state. + * + * @type {Map} + */ +const moduleHotState = new Map(); +/** + * Module IDs that are instantiated as part of the runtime of a chunk. + * + * @type {Set} + */ +const runtimeModules = new Set(); +/** + * Map from module ID to the chunks that contain this module. + * + * In HMR, we need to keep track of which modules are contained in which so + * chunks. This is so we don't eagerly dispose of a module when it is removed + * from chunk A, but still exists in chunk B. + * + * @type {Map>} + */ +const moduleChunksMap = new Map(); +const hOP = Object.prototype.hasOwnProperty; +const _process = + typeof process !== "undefined" + ? process + : { + env: {}, + // Some modules rely on `process.browser` to execute browser-specific code. + // NOTE: `process.browser` is specific to Webpack. + browser: true, + }; + +const toStringTag = typeof Symbol !== "undefined" && Symbol.toStringTag; + +/** + * @param {any} obj + * @param {PropertyKey} name + * @param {PropertyDescriptor & ThisType} options + */ +function defineProp(obj, name, options) { + if (!hOP.call(obj, name)) Object.defineProperty(obj, name, options); +} + +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record any>} getters + */ +function esm(exports, getters) { + defineProp(exports, "__esModule", { value: true }); + if (toStringTag) defineProp(exports, toStringTag, { value: "Module" }); + for (const key in getters) { + defineProp(exports, key, { get: getters[key], enumerable: true }); + } +} + +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + +/** + * @param {Module} module + * @param {any} value + */ +function exportValue(module, value) { + module.exports = value; +} + +/** + * @param {Record} obj + * @param {string} key + */ +function createGetter(obj, key) { + return () => obj[key]; +} + +/** + * @param {Exports} raw + * @param {EsmInteropNamespace} ns + * @param {boolean} [allowExportDefault] + */ +function interopEsm(raw, ns, allowExportDefault) { + /** @type {Object. any>} */ + const getters = { __proto__: null }; + for (const key in raw) { + getters[key] = createGetter(raw, key); + } + if (!(allowExportDefault && "default" in getters)) { + getters["default"] = () => raw; + } + esm(ns, getters); +} + +/** + * @param {Module} sourceModule + * @param {ModuleId} id + * @param {boolean} allowExportDefault + * @returns {EsmInteropNamespace} + */ +function esmImport(sourceModule, id, allowExportDefault) { + const module = getOrInstantiateModuleFromParent(id, sourceModule); + const raw = module.exports; + if (raw.__esModule) return raw; + if (module.interopNamespace) return module.interopNamespace; + const ns = (module.interopNamespace = {}); + interopEsm(raw, ns, allowExportDefault); + return ns; +} + +/** + * @param {Module} sourceModule + * @param {ModuleId} id + * @returns {Exports} + */ +function commonJsRequire(sourceModule, id) { + return getOrInstantiateModuleFromParent(id, sourceModule).exports; +} + +function externalRequire(id, esm) { + let raw; + try { + raw = require(id); + } catch (err) { + // TODO(alexkirsz) This can happen when a client-side module tries to load + // an external module we don't provide a shim for (e.g. querystring, url). + // For now, we fail semi-silently, but in the future this should be a + // compilation error. + throw new Error(`Failed to load external module ${id}: ${err}`); + } + if (!esm || raw.__esModule) { + return raw; + } + const ns = {}; + interopEsm(raw, ns, true); + return ns; +} + +/** + * @param {ModuleId} from + * @param {string} chunkPath + * @returns {Promise | undefined} + */ +function loadChunk(from, chunkPath) { + if (loadedChunks.has(chunkPath)) { + return Promise.resolve(); + } + + const chunkLoader = getOrCreateChunkLoader(chunkPath, from); + + return chunkLoader.promise; +} + +/** + * @param {string} chunkPath + * @param {ModuleId} from + * @returns {Loader} + */ +function getOrCreateChunkLoader(chunkPath, from) { + let chunkLoader = chunkLoaders.get(chunkPath); + if (chunkLoader) { + return chunkLoader; + } + + let resolve; + let reject; + const promise = new Promise((innerResolve, innerReject) => { + resolve = innerResolve; + reject = innerReject; + }); + + const onError = (error) => { + chunkLoaders.delete(chunkPath); + reject( + new Error( + `Failed to load chunk from ${chunkPath}${error ? `: ${error}` : ""}` + ) + ); + }; + + const onLoad = () => { + loadedChunks.add(chunkPath); + chunkLoaders.delete(chunkPath); + resolve(); + }; + + chunkLoader = { + promise, + onLoad, + }; + chunkLoaders.set(chunkPath, chunkLoader); + + BACKEND.loadChunk(chunkPath, from).then(onLoad, onError); + + return chunkLoader; +} + +/** + * @enum {number} + */ +const SourceType = { + /** + * The module was instantiated because it was included in an evaluated chunk's + * runtime. + */ + Runtime: 0, + /** + * The module was instantiated because a parent module imported it. + */ + Parent: 1, + /** + * The module was instantiated because it was included in a chunk's hot module + * update. + */ + Update: 2, +}; + +/** + * + * @param {ModuleId} id + * @param {SourceType} sourceType + * @param {ModuleId} [sourceId] + * @returns {Module} + */ +function instantiateModule(id, sourceType, sourceId) { + const moduleFactory = moduleFactories[id]; + if (typeof moduleFactory !== "function") { + // This can happen if modules incorrectly handle HMR disposes/updates, + // e.g. when they keep a `setTimeout` around which still executes old code + // and contains e.g. a `require("something")` call. + let instantiationReason; + switch (sourceType) { + case SourceType.Runtime: + instantiationReason = "as a runtime entry"; + break; + case SourceType.Parent: + instantiationReason = `because it was required from module ${sourceId}`; + break; + case SourceType.Update: + instantiationReason = "because of an HMR update"; + break; + } + throw new Error( + `Module ${id} was instantiated ${instantiationReason}, but the module factory is not available. It might have been deleted in an HMR update.` + ); + } + + const hotData = moduleHotData.get(id); + const { hot, hotState } = createModuleHot(hotData); + + /** @type {Module} */ + const module = { + exports: {}, + loaded: false, + id, + parents: [], + children: [], + interopNamespace: undefined, + hot, + }; + moduleCache[id] = module; + moduleHotState.set(module, hotState); + + if (sourceType === SourceType.Runtime) { + runtimeModules.add(id); + } else if (sourceType === SourceType.Parent) { + module.parents.push(sourceId); + + // No need to add this module as a child of the parent module here, this + // has already been taken care of in `getOrInstantiateModuleFromParent`. + } + + runModuleExecutionHooks(module, () => { + moduleFactory.call(module.exports, { + e: module.exports, + r: commonJsRequire.bind(null, module), + x: externalRequire, + i: esmImport.bind(null, module), + s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), + v: exportValue.bind(null, module), + m: module, + c: moduleCache, + l: loadChunk.bind(null, id), + p: _process, + g: globalThis, + __dirname: module.id.replace(/(^|\/)[\/]+$/, ""), + }); + }); + + module.loaded = true; + if (module.interopNamespace) { + // in case of a circular dependency: cjs1 -> esm2 -> cjs1 + interopEsm(module.exports, module.interopNamespace); + } + + return module; +} + +/** + * NOTE(alexkirsz) Webpack has an "module execution" interception hook that + * Next.js' React Refresh runtime hooks into to add module context to the + * refresh registry. + * + * @param {Module} module + * @param {() => void} executeModule + */ +function runModuleExecutionHooks(module, executeModule) { + const cleanupReactRefreshIntercept = + typeof globalThis.$RefreshInterceptModuleExecution$ === "function" + ? globalThis.$RefreshInterceptModuleExecution$(module.id) + : () => {}; + + executeModule(); + + if ("$RefreshHelpers$" in globalThis) { + // This pattern can also be used to register the exports of + // a module with the React Refresh runtime. + registerExportsAndSetupBoundaryForReactRefresh( + module, + globalThis.$RefreshHelpers$ + ); + } + + cleanupReactRefreshIntercept(); +} + +/** + * Retrieves a module from the cache, or instantiate it if it is not cached. + * + * @param {ModuleId} id + * @param {Module} sourceModule + * @returns {Module} + */ +function getOrInstantiateModuleFromParent(id, sourceModule) { + if (!sourceModule.hot.active) { + console.warn( + `Unexpected import of module ${id} from module ${sourceModule.id}, which was deleted by an HMR update` + ); + } + + const module = moduleCache[id]; + + if (sourceModule.children.indexOf(id) === -1) { + sourceModule.children.push(id); + } + + if (module) { + if (module.parents.indexOf(sourceModule.id) === -1) { + module.parents.push(sourceModule.id); + } + + return module; + } + + return instantiateModule(id, SourceType.Parent, sourceModule.id); +} + +/** + * This is adapted from https://github.com/vercel/next.js/blob/3466862d9dc9c8bb3131712134d38757b918d1c0/packages/react-refresh-utils/internal/ReactRefreshModule.runtime.ts + * + * @param {Module} module + * @param {RefreshHelpers} helpers + */ +function registerExportsAndSetupBoundaryForReactRefresh(module, helpers) { + const currentExports = module.exports; + const prevExports = module.hot.data.prevExports ?? null; + + helpers.registerExportsForReactRefresh(currentExports, module.id); + + // A module can be accepted automatically based on its exports, e.g. when + // it is a Refresh Boundary. + if (helpers.isReactRefreshBoundary(currentExports)) { + // Save the previous exports on update so we can compare the boundary + // signatures. + module.hot.dispose((data) => { + data.prevExports = currentExports; + }); + // Unconditionally accept an update to this module, we'll check if it's + // still a Refresh Boundary later. + module.hot.accept(); + + // This field is set when the previous version of this module was a + // Refresh Boundary, letting us know we need to check for invalidation or + // enqueue an update. + if (prevExports !== null) { + // A boundary can become ineligible if its exports are incompatible + // with the previous exports. + // + // For example, if you add/remove/change exports, we'll want to + // re-execute the importing modules, and force those components to + // re-render. Similarly, if you convert a class component to a + // function, we want to invalidate the boundary. + if ( + helpers.shouldInvalidateReactRefreshBoundary( + prevExports, + currentExports + ) + ) { + module.hot.invalidate(); + } else { + helpers.scheduleUpdate(); + } + } + } else { + // Since we just executed the code for the module, it's possible that the + // new exports made it ineligible for being a boundary. + // We only care about the case when we were _previously_ a boundary, + // because we already accepted this update (accidental side effect). + const isNoLongerABoundary = prevExports !== null; + if (isNoLongerABoundary) { + module.hot.invalidate(); + } + } +} + +/** + * @param {ModuleId[]} dependencyChain + * @returns {string} + */ +function formatDependencyChain(dependencyChain) { + return `Dependency chain: ${dependencyChain.join(" -> ")}`; +} + +/** + * @param {HmrUpdateEntry} factory + * @returns {ModuleFactory} + * @private + */ +function _eval({ code, url, map }) { + code += `\n\n//# sourceURL=${location.origin}${url}`; + if (map) code += `\n//# sourceMappingURL=${map}`; + return eval(code); +} + +/** + * @param {EcmascriptChunkUpdate} update + * @returns {{outdatedModules: Set, newModuleFactories: Map}} + */ +function computeOutdatedModules(update) { + const outdatedModules = new Set(); + const newModuleFactories = new Map(); + + for (const [moduleId, factory] of Object.entries(update.added)) { + newModuleFactories.set(moduleId, _eval(factory)); + } + + for (const [moduleId, factory] of Object.entries(update.modified)) { + const effect = getAffectedModuleEffects(moduleId); + + switch (effect.type) { + case "unaccepted": + throw new Error( + `cannot apply update: unaccepted module. ${formatDependencyChain( + effect.dependencyChain + )}.` + ); + case "self-declined": + throw new Error( + `cannot apply update: self-declined module. ${formatDependencyChain( + effect.dependencyChain + )}.` + ); + case "accepted": + newModuleFactories.set(moduleId, _eval(factory)); + for (const outdatedModuleId of effect.outdatedModules) { + outdatedModules.add(outdatedModuleId); + } + break; + // TODO(alexkirsz) Dependencies: handle dependencies effects. + } + } + + return { outdatedModules, newModuleFactories }; +} + +/** + * @param {Iterable} outdatedModules + * @returns {{ moduleId: ModuleId, errorHandler: true | Function }[]} + */ +function computeOutdatedSelfAcceptedModules(outdatedModules) { + const outdatedSelfAcceptedModules = []; + for (const moduleId of outdatedModules) { + const module = moduleCache[moduleId]; + const hotState = moduleHotState.get(module); + if (module && hotState.selfAccepted && !hotState.selfInvalidated) { + outdatedSelfAcceptedModules.push({ + moduleId, + errorHandler: hotState.selfAccepted, + }); + } + } + return outdatedSelfAcceptedModules; +} + +/** + * @param {ChunkPath} chunkPath + * @param {Iterable} outdatedModules + * @param {Iterable} deletedModules + */ +function disposePhase(chunkPath, outdatedModules, deletedModules) { + for (const moduleId of outdatedModules) { + const module = moduleCache[moduleId]; + if (!module) { + continue; + } + + const data = disposeModule(module); + + moduleHotData.set(moduleId, data); + } + + for (const moduleId of deletedModules) { + const module = moduleCache[moduleId]; + if (!module) { + continue; + } + + const noRemainingChunks = removeModuleFromChunk(moduleId, chunkPath); + + if (noRemainingChunks) { + disposeModule(module); + + moduleHotData.delete(moduleId); + } + } + + // TODO(alexkirsz) Dependencies: remove outdated dependency from module + // children. +} + +/** + * Disposes of an instance of a module. + * + * Returns the persistent hot data that should be kept for the next module + * instance. + * + * @param {Module} module + * @returns {{}} + */ +function disposeModule(module) { + const hotState = moduleHotState.get(module); + const data = {}; + + // Run the `hot.dispose` handler, if any, passing in the persistent + // `hot.data` object. + for (const disposeHandler of hotState.disposeHandlers) { + disposeHandler(data); + } + + // This used to warn in `getOrInstantiateModuleFromParent` when a disposed + // module is still importing other modules. + module.hot.active = false; + + delete moduleCache[module.id]; + moduleHotState.delete(module); + + // TODO(alexkirsz) Dependencies: delete the module from outdated deps. + + // Remove the disposed module from its children's parents list. + // It will be added back once the module re-instantiates and imports its + // children again. + for (const childId of module.children) { + const child = moduleCache[childId]; + if (!child) { + continue; + } + + const idx = child.parents.indexOf(module.id); + if (idx >= 0) { + child.parents.splice(idx, 1); + } + } + + return data; +} + +/** + * + * @param {ChunkPath} chunkPath + * @param {{ moduleId: ModuleId, errorHandler: true | Function }[]} outdatedSelfAcceptedModules + * @param {Map} newModuleFactories + */ +function applyPhase( + chunkPath, + outdatedSelfAcceptedModules, + newModuleFactories +) { + // Update module factories. + for (const [moduleId, factory] of newModuleFactories.entries()) { + moduleFactories[moduleId] = factory; + addModuleToChunk(moduleId, chunkPath); + } + + // TODO(alexkirsz) Run new runtime entries here. + + // TODO(alexkirsz) Dependencies: call accept handlers for outdated deps. + + // Re-instantiate all outdated self-accepted modules. + for (const { moduleId, errorHandler } of outdatedSelfAcceptedModules) { + try { + instantiateModule(moduleId, SourceType.Update); + } catch (err) { + if (typeof errorHandler === "function") { + try { + errorHandler(err, { moduleId, module: moduleCache[moduleId] }); + } catch (_) { + // Ignore error. + } + } + } + } +} + +/** + * + * @param {ChunkPath} chunkPath + * @param {EcmascriptChunkUpdate} update + */ +function applyUpdate(chunkPath, update) { + const { outdatedModules, newModuleFactories } = + computeOutdatedModules(update); + + const deletedModules = new Set(update.deleted); + + const outdatedSelfAcceptedModules = + computeOutdatedSelfAcceptedModules(outdatedModules); + + disposePhase(chunkPath, outdatedModules, deletedModules); + applyPhase(chunkPath, outdatedSelfAcceptedModules, newModuleFactories); +} + +/** + * + * @param {ModuleId} moduleId + * @returns {ModuleEffect} + */ +function getAffectedModuleEffects(moduleId) { + const outdatedModules = new Set(); + + /** @typedef {{moduleId?: ModuleId, dependencyChain: ModuleId[]}} QueueItem */ + + /** @type {QueueItem[]} */ + const queue = [ + { + moduleId, + dependencyChain: [], + }, + ]; + + while (queue.length > 0) { + const { moduleId, dependencyChain } = + /** @type {QueueItem} */ queue.shift(); + outdatedModules.add(moduleId); + + // We've arrived at the runtime of the chunk, which means that nothing + // else above can accept this update. + if (moduleId === undefined) { + return { + type: "unaccepted", + dependencyChain, + }; + } + + const module = moduleCache[moduleId]; + const hotState = moduleHotState.get(module); + + if ( + // The module is not in the cache. Since this is a "modified" update, + // it means that the module was never instantiated before. + !module || // The module accepted itself without invalidating globalThis. + // TODO is that right? + (hotState.selfAccepted && !hotState.selfInvalidated) + ) { + continue; + } + + if (hotState.selfDeclined) { + return { + type: "self-declined", + dependencyChain, + moduleId, + }; + } + + if (runtimeModules.has(moduleId)) { + queue.push({ + moduleId: undefined, + dependencyChain: [...dependencyChain, moduleId], + }); + continue; + } + + for (const parentId of module.parents) { + const parent = moduleCache[parentId]; + + if (!parent) { + // TODO(alexkirsz) Is this even possible? + continue; + } + + // TODO(alexkirsz) Dependencies: check accepted and declined + // dependencies here. + + queue.push({ + moduleId: parentId, + dependencyChain: [...dependencyChain, moduleId], + }); + } + } + + return { + type: "accepted", + moduleId, + outdatedModules, + }; +} + +/** + * @param {ChunkPath} chunkPath + * @param {import('../types/protocol').ServerMessage} update + */ +function handleApply(chunkPath, update) { + switch (update.type) { + case "partial": + applyUpdate(chunkPath, update.instruction); + break; + case "restart": + BACKEND.restart(); + break; + default: + throw new Error(`Unknown update type: ${update.type}`); + } +} + +/** + * @param {HotData} [hotData] + * @returns {{hotState: HotState, hot: Hot}} + */ +function createModuleHot(hotData) { + /** @type {HotState} */ + const hotState = { + selfAccepted: false, + selfDeclined: false, + selfInvalidated: false, + disposeHandlers: [], + }; + + /** + * TODO(alexkirsz) Support full (dep, callback, errorHandler) form. + * + * @param {string | string[] | AcceptErrorHandler} [dep] + * @param {AcceptCallback} [_callback] + * @param {AcceptErrorHandler} [_errorHandler] + */ + function accept(dep, _callback, _errorHandler) { + if (dep === undefined) { + hotState.selfAccepted = true; + } else if (typeof dep === "function") { + hotState.selfAccepted = dep; + } else { + throw new Error("unsupported `accept` signature"); + } + } + + /** @type {Hot} */ + const hot = { + // TODO(alexkirsz) This is not defined in the HMR API. It was used to + // decide whether to warn whenever an HMR-disposed module required other + // modules. We might want to remove it. + active: true, + + data: hotData ?? {}, + + accept: accept, + + decline: (dep) => { + if (dep === undefined) { + hotState.selfDeclined = true; + } else { + throw new Error("unsupported `decline` signature"); + } + }, + + dispose: (callback) => { + hotState.disposeHandlers.push(callback); + }, + + addDisposeHandler: (callback) => { + hotState.disposeHandlers.push(callback); + }, + + removeDisposeHandler: (callback) => { + const idx = hotState.disposeHandlers.indexOf(callback); + if (idx >= 0) { + hotState.disposeHandlers.splice(idx, 1); + } + }, + + invalidate: () => { + hotState.selfInvalidated = true; + // TODO(alexkirsz) The original HMR code had management-related code + // here. + }, + + // NOTE(alexkirsz) This is part of the management API, which we don't + // implement, but the Next.js React Refresh runtime uses this to decide + // whether to schedule an update. + status: () => "idle", + + // NOTE(alexkirsz) Since we always return "idle" for now, these are no-ops. + addStatusHandler: (_handler) => {}, + removeStatusHandler: (_handler) => {}, + }; + + return { hot, hotState }; +} + +/** + * Adds a module to a chunk. + * + * @param {ModuleId} moduleId + * @param {ChunkPath} chunkPath + */ +function addModuleToChunk(moduleId, chunkPath) { + let moduleChunks = moduleChunksMap.get(moduleId); + if (!moduleChunks) { + moduleChunks = new Set([chunkPath]); + moduleChunksMap.set(moduleId, moduleChunks); + } else { + moduleChunks.add(chunkPath); + } +} + +/** + * Returns the first chunk that included a module. + * + * @type {GetFirstModuleChunk} + */ +function getFirstModuleChunk(moduleId) { + const moduleChunkPaths = moduleChunksMap.get(moduleId); + if (moduleChunkPaths == null) { + return null; + } + + return moduleChunkPaths.values().next().value; +} + +/** + * Removes a module from a chunk. Returns true there are no remaining chunks + * including this module. + * + * @param {ModuleId} moduleId + * @param {ChunkPath} chunkPath + * @returns {boolean} + */ +function removeModuleFromChunk(moduleId, chunkPath) { + const moduleChunks = moduleChunksMap.get(moduleId); + moduleChunks.delete(chunkPath); + + if (moduleChunks.size > 0) { + return false; + } + + moduleChunksMap.delete(moduleId); + return true; +} + +/** + * Instantiates a runtime module. + */ +/** + * + * @param {ModuleId} moduleId + * @returns {Module} + */ +function instantiateRuntimeModule(moduleId) { + return instantiateModule(moduleId, SourceType.Runtime); +} + +/** + * Subscribes to chunk updates from the update server and applies them. + * + * @param {ChunkPath} chunkPath + */ +function subscribeToChunkUpdates(chunkPath) { + // This adds a chunk update listener once the handler code has been loaded + globalThis.TURBOPACK_CHUNK_UPDATE_LISTENERS.push([ + chunkPath, + handleApply.bind(null, chunkPath), + ]); +} + +function markChunkAsLoaded(chunkPath) { + const chunkLoader = chunkLoaders.get(chunkPath); + if (!chunkLoader) { + loadedChunks.add(chunkPath); + + // This happens for all initial chunks that are loaded directly from + // the HTML. + return; + } + + // Only chunks that are loaded via `loadChunk` will have a loader. + chunkLoader.onLoad(); +} + +/** @type {Runtime} */ +const runtime = { + loadedChunks, + modules: moduleFactories, + cache: moduleCache, + instantiateRuntimeModule, +}; + +/** + * @param {ChunkRegistration} chunkRegistration + */ +function registerChunk([chunkPath, chunkModules, ...run]) { + markChunkAsLoaded(chunkPath); + subscribeToChunkUpdates(chunkPath); + for (const [moduleId, moduleFactory] of Object.entries(chunkModules)) { + if (!moduleFactories[moduleId]) { + moduleFactories[moduleId] = moduleFactory; + } + addModuleToChunk(moduleId, chunkPath); + } + runnable.push(...run); + runnable = runnable.filter((r) => r(runtime)); +} + +globalThis.TURBOPACK_CHUNK_UPDATE_LISTENERS = + globalThis.TURBOPACK_CHUNK_UPDATE_LISTENERS || []; + +globalThis.TURBOPACK.forEach(registerChunk); +globalThis.TURBOPACK = { + push: registerChunk, +}; +})(); + + +//# sourceMappingURL=crates_turbopack-tests_tests_snapshot_export-alls_cjs-2_input_index_176583.js.map \ No newline at end of file diff --git a/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-2_input_index_176583.js.map b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-2_input_index_176583.js.map new file mode 100644 index 0000000000000..a3277787716c1 --- /dev/null +++ b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-2_input_index_176583.js.map @@ -0,0 +1,12 @@ +{ + "version": 3, + "sections": [ + {"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/index.js"],"sourcesContent":["// a.js\nimport * as B from \"./b\";\nconsole.log(B);"],"names":[],"mappings":"AACA;;;AACA,QAAQ,GAAG"}}, + {"offset": {"line": 8, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}, + {"offset": {"line": 12, "column": 0}, "map": {"version":3,"sources":["/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/b.js"],"sourcesContent":["// b.js\nexport * from \"./c\";\n// This would not be handled, but still need __turbopack__cjs__\n// as there are properties dynamically added by __turbopack__cjs__ in c.js\n"],"names":[],"mappings":"AACA"}}, + {"offset": {"line": 17, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}, + {"offset": {"line": 21, "column": 0}, "map": {"version":3,"sources":["/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/c.js"],"sourcesContent":["// c.js\nexport * from \"./commonjs.js\";\n// This would be handled by existing logic\n"],"names":[],"mappings":"AACA"}}, + {"offset": {"line": 26, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}, + {"offset": {"line": 30, "column": 0}, "map": {"version":3,"sources":["/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/commonjs.js"],"sourcesContent":["// commonjs.js\nexports.hello = \"World\";\n\n"],"names":[],"mappings":"AACA,QAAQ,KAAK,GAAG"}}, + {"offset": {"line": 31, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}] +} \ No newline at end of file diff --git a/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/exported.cjs b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/exported.cjs new file mode 100644 index 0000000000000..bd3b8ed298729 --- /dev/null +++ b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/exported.cjs @@ -0,0 +1 @@ +module.exports = { foo: 1, bar: 2 } \ No newline at end of file diff --git a/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/index.js b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/index.js new file mode 100644 index 0000000000000..1f075aa1599cc --- /dev/null +++ b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/index.js @@ -0,0 +1,3 @@ +import * as foo from './mod.js'; + +console.log(foo) \ No newline at end of file diff --git a/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/mod.js b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/mod.js new file mode 100644 index 0000000000000..78e69d953770e --- /dev/null +++ b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/mod.js @@ -0,0 +1,4 @@ + +export * from './exported.cjs' + +console.log('Hoist test') \ No newline at end of file diff --git a/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/issues/unexpected export __star__-88ee1b.txt b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/issues/unexpected export __star__-88ee1b.txt new file mode 100644 index 0000000000000..85a00f161c13f --- /dev/null +++ b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/issues/unexpected export __star__-88ee1b.txt @@ -0,0 +1,11 @@ +PlainIssue { + severity: Warning, + context: "[project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/exported.cjs", + category: "analyze", + title: "unexpected export *", + description: "export * used with module [project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/exported.cjs which is a CommonJS module with exports only available at runtime\nList all export names manually (`export { a, b, c } from \"...\") or rewrite the module to ESM, to avoid the additional runtime code.`", + detail: "", + documentation_link: "", + source: None, + sub_issues: [], +} \ No newline at end of file diff --git a/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-script_input_index_32f385.js b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-script_input_index_32f385.js new file mode 100644 index 0000000000000..d1f7f209ac8e1 --- /dev/null +++ b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-script_input_index_32f385.js @@ -0,0 +1,1077 @@ +(self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-script_input_index_32f385.js", { + +"[project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { + +var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$export$2d$alls$2f$cjs$2d$script$2f$input$2f$mod$2e$js__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/mod.js (ecmascript)"); +"__TURBOPACK__ecmascript__hoisting__location__"; +; +console.log(__TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$export$2d$alls$2f$cjs$2d$script$2f$input$2f$mod$2e$js__); + +}.call(this) }), +"[project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/mod.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { + +__turbopack_esm__({}); +var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$export$2d$alls$2f$cjs$2d$script$2f$input$2f$exported$2e$cjs__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/exported.cjs (ecmascript)"); +__turbopack__cjs__(__TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$export$2d$alls$2f$cjs$2d$script$2f$input$2f$exported$2e$cjs__); +"__TURBOPACK__ecmascript__hoisting__location__"; +; +console.log('Hoist test'); + +})()), +"[project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/exported.cjs (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { + +module.exports = { + foo: 1, + bar: 2 +}; + +}.call(this) }), +}, ({ loadedChunks, instantiateRuntimeModule }) => { + if(!(true && loadedChunks.has("output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-script_input_index_fd8765.js"))) return true; + instantiateRuntimeModule("[project]/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/index.js (ecmascript)"); +}]); +(() => { +if (!Array.isArray(globalThis.TURBOPACK)) { + return; +} +/** @typedef {import('../types/backend').RuntimeBackend} RuntimeBackend */ + +/** @type {RuntimeBackend} */ +const BACKEND = { + loadChunk(chunkPath, _from) { + return new Promise((resolve, reject) => { + if (chunkPath.endsWith(".css")) { + const link = document.createElement("link"); + link.rel = "stylesheet"; + link.href = `/${chunkPath}`; + link.onerror = () => { + reject(); + }; + link.onload = () => { + // CSS chunks do not register themselves, and as such must be marked as + // loaded instantly. + resolve(); + }; + document.body.appendChild(link); + } else if (chunkPath.endsWith(".js")) { + const script = document.createElement("script"); + script.src = `/${chunkPath}`; + // We'll only mark the chunk as loaded once the script has been executed, + // which happens in `registerChunk`. Hence the absence of `resolve()` in + // this branch. + script.onerror = () => { + reject(); + }; + document.body.appendChild(script); + } else { + throw new Error(`can't infer type of chunk from path ${chunkPath}`); + } + }); + }, + + restart: () => self.location.reload(), +}; +/* eslint-disable @next/next/no-assign-module-variable */ + +/** @typedef {import('../types').ChunkRegistration} ChunkRegistration */ +/** @typedef {import('../types').ModuleFactory} ModuleFactory */ + +/** @typedef {import('../types').ChunkPath} ChunkPath */ +/** @typedef {import('../types').ModuleId} ModuleId */ +/** @typedef {import('../types').GetFirstModuleChunk} GetFirstModuleChunk */ + +/** @typedef {import('../types').Module} Module */ +/** @typedef {import('../types').Exports} Exports */ +/** @typedef {import('../types').EsmInteropNamespace} EsmInteropNamespace */ +/** @typedef {import('../types').Runnable} Runnable */ + +/** @typedef {import('../types').Runtime} Runtime */ + +/** @typedef {import('../types').RefreshHelpers} RefreshHelpers */ +/** @typedef {import('../types/hot').Hot} Hot */ +/** @typedef {import('../types/hot').HotData} HotData */ +/** @typedef {import('../types/hot').AcceptCallback} AcceptCallback */ +/** @typedef {import('../types/hot').AcceptErrorHandler} AcceptErrorHandler */ +/** @typedef {import('../types/hot').HotState} HotState */ +/** @typedef {import('../types/protocol').EcmascriptChunkUpdate} EcmascriptChunkUpdate */ +/** @typedef {import('../types/protocol').HmrUpdateEntry} HmrUpdateEntry */ + +/** @typedef {import('../types/runtime').Loader} Loader */ +/** @typedef {import('../types/runtime').ModuleEffect} ModuleEffect */ + +/** @type {Array} */ +let runnable = []; +/** @type {Object.} */ +const moduleFactories = { __proto__: null }; +/** @type {Object.} */ +const moduleCache = { __proto__: null }; +/** + * Contains the IDs of all chunks that have been loaded. + * + * @type {Set} + */ +const loadedChunks = new Set(); +/** + * Maps a chunk ID to the chunk's loader if the chunk is currently being loaded. + * + * @type {Map} + */ +const chunkLoaders = new Map(); +/** + * Maps module IDs to persisted data between executions of their hot module + * implementation (`hot.data`). + * + * @type {Map} + */ +const moduleHotData = new Map(); +/** + * Maps module instances to their hot module state. + * + * @type {Map} + */ +const moduleHotState = new Map(); +/** + * Module IDs that are instantiated as part of the runtime of a chunk. + * + * @type {Set} + */ +const runtimeModules = new Set(); +/** + * Map from module ID to the chunks that contain this module. + * + * In HMR, we need to keep track of which modules are contained in which so + * chunks. This is so we don't eagerly dispose of a module when it is removed + * from chunk A, but still exists in chunk B. + * + * @type {Map>} + */ +const moduleChunksMap = new Map(); +const hOP = Object.prototype.hasOwnProperty; +const _process = + typeof process !== "undefined" + ? process + : { + env: {}, + // Some modules rely on `process.browser` to execute browser-specific code. + // NOTE: `process.browser` is specific to Webpack. + browser: true, + }; + +const toStringTag = typeof Symbol !== "undefined" && Symbol.toStringTag; + +/** + * @param {any} obj + * @param {PropertyKey} name + * @param {PropertyDescriptor & ThisType} options + */ +function defineProp(obj, name, options) { + if (!hOP.call(obj, name)) Object.defineProperty(obj, name, options); +} + +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record any>} getters + */ +function esm(exports, getters) { + defineProp(exports, "__esModule", { value: true }); + if (toStringTag) defineProp(exports, toStringTag, { value: "Module" }); + for (const key in getters) { + defineProp(exports, key, { get: getters[key], enumerable: true }); + } +} + +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + +/** + * @param {Module} module + * @param {any} value + */ +function exportValue(module, value) { + module.exports = value; +} + +/** + * @param {Record} obj + * @param {string} key + */ +function createGetter(obj, key) { + return () => obj[key]; +} + +/** + * @param {Exports} raw + * @param {EsmInteropNamespace} ns + * @param {boolean} [allowExportDefault] + */ +function interopEsm(raw, ns, allowExportDefault) { + /** @type {Object. any>} */ + const getters = { __proto__: null }; + for (const key in raw) { + getters[key] = createGetter(raw, key); + } + if (!(allowExportDefault && "default" in getters)) { + getters["default"] = () => raw; + } + esm(ns, getters); +} + +/** + * @param {Module} sourceModule + * @param {ModuleId} id + * @param {boolean} allowExportDefault + * @returns {EsmInteropNamespace} + */ +function esmImport(sourceModule, id, allowExportDefault) { + const module = getOrInstantiateModuleFromParent(id, sourceModule); + const raw = module.exports; + if (raw.__esModule) return raw; + if (module.interopNamespace) return module.interopNamespace; + const ns = (module.interopNamespace = {}); + interopEsm(raw, ns, allowExportDefault); + return ns; +} + +/** + * @param {Module} sourceModule + * @param {ModuleId} id + * @returns {Exports} + */ +function commonJsRequire(sourceModule, id) { + return getOrInstantiateModuleFromParent(id, sourceModule).exports; +} + +function externalRequire(id, esm) { + let raw; + try { + raw = require(id); + } catch (err) { + // TODO(alexkirsz) This can happen when a client-side module tries to load + // an external module we don't provide a shim for (e.g. querystring, url). + // For now, we fail semi-silently, but in the future this should be a + // compilation error. + throw new Error(`Failed to load external module ${id}: ${err}`); + } + if (!esm || raw.__esModule) { + return raw; + } + const ns = {}; + interopEsm(raw, ns, true); + return ns; +} + +/** + * @param {ModuleId} from + * @param {string} chunkPath + * @returns {Promise | undefined} + */ +function loadChunk(from, chunkPath) { + if (loadedChunks.has(chunkPath)) { + return Promise.resolve(); + } + + const chunkLoader = getOrCreateChunkLoader(chunkPath, from); + + return chunkLoader.promise; +} + +/** + * @param {string} chunkPath + * @param {ModuleId} from + * @returns {Loader} + */ +function getOrCreateChunkLoader(chunkPath, from) { + let chunkLoader = chunkLoaders.get(chunkPath); + if (chunkLoader) { + return chunkLoader; + } + + let resolve; + let reject; + const promise = new Promise((innerResolve, innerReject) => { + resolve = innerResolve; + reject = innerReject; + }); + + const onError = (error) => { + chunkLoaders.delete(chunkPath); + reject( + new Error( + `Failed to load chunk from ${chunkPath}${error ? `: ${error}` : ""}` + ) + ); + }; + + const onLoad = () => { + loadedChunks.add(chunkPath); + chunkLoaders.delete(chunkPath); + resolve(); + }; + + chunkLoader = { + promise, + onLoad, + }; + chunkLoaders.set(chunkPath, chunkLoader); + + BACKEND.loadChunk(chunkPath, from).then(onLoad, onError); + + return chunkLoader; +} + +/** + * @enum {number} + */ +const SourceType = { + /** + * The module was instantiated because it was included in an evaluated chunk's + * runtime. + */ + Runtime: 0, + /** + * The module was instantiated because a parent module imported it. + */ + Parent: 1, + /** + * The module was instantiated because it was included in a chunk's hot module + * update. + */ + Update: 2, +}; + +/** + * + * @param {ModuleId} id + * @param {SourceType} sourceType + * @param {ModuleId} [sourceId] + * @returns {Module} + */ +function instantiateModule(id, sourceType, sourceId) { + const moduleFactory = moduleFactories[id]; + if (typeof moduleFactory !== "function") { + // This can happen if modules incorrectly handle HMR disposes/updates, + // e.g. when they keep a `setTimeout` around which still executes old code + // and contains e.g. a `require("something")` call. + let instantiationReason; + switch (sourceType) { + case SourceType.Runtime: + instantiationReason = "as a runtime entry"; + break; + case SourceType.Parent: + instantiationReason = `because it was required from module ${sourceId}`; + break; + case SourceType.Update: + instantiationReason = "because of an HMR update"; + break; + } + throw new Error( + `Module ${id} was instantiated ${instantiationReason}, but the module factory is not available. It might have been deleted in an HMR update.` + ); + } + + const hotData = moduleHotData.get(id); + const { hot, hotState } = createModuleHot(hotData); + + /** @type {Module} */ + const module = { + exports: {}, + loaded: false, + id, + parents: [], + children: [], + interopNamespace: undefined, + hot, + }; + moduleCache[id] = module; + moduleHotState.set(module, hotState); + + if (sourceType === SourceType.Runtime) { + runtimeModules.add(id); + } else if (sourceType === SourceType.Parent) { + module.parents.push(sourceId); + + // No need to add this module as a child of the parent module here, this + // has already been taken care of in `getOrInstantiateModuleFromParent`. + } + + runModuleExecutionHooks(module, () => { + moduleFactory.call(module.exports, { + e: module.exports, + r: commonJsRequire.bind(null, module), + x: externalRequire, + i: esmImport.bind(null, module), + s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), + v: exportValue.bind(null, module), + m: module, + c: moduleCache, + l: loadChunk.bind(null, id), + p: _process, + g: globalThis, + __dirname: module.id.replace(/(^|\/)[\/]+$/, ""), + }); + }); + + module.loaded = true; + if (module.interopNamespace) { + // in case of a circular dependency: cjs1 -> esm2 -> cjs1 + interopEsm(module.exports, module.interopNamespace); + } + + return module; +} + +/** + * NOTE(alexkirsz) Webpack has an "module execution" interception hook that + * Next.js' React Refresh runtime hooks into to add module context to the + * refresh registry. + * + * @param {Module} module + * @param {() => void} executeModule + */ +function runModuleExecutionHooks(module, executeModule) { + const cleanupReactRefreshIntercept = + typeof globalThis.$RefreshInterceptModuleExecution$ === "function" + ? globalThis.$RefreshInterceptModuleExecution$(module.id) + : () => {}; + + executeModule(); + + if ("$RefreshHelpers$" in globalThis) { + // This pattern can also be used to register the exports of + // a module with the React Refresh runtime. + registerExportsAndSetupBoundaryForReactRefresh( + module, + globalThis.$RefreshHelpers$ + ); + } + + cleanupReactRefreshIntercept(); +} + +/** + * Retrieves a module from the cache, or instantiate it if it is not cached. + * + * @param {ModuleId} id + * @param {Module} sourceModule + * @returns {Module} + */ +function getOrInstantiateModuleFromParent(id, sourceModule) { + if (!sourceModule.hot.active) { + console.warn( + `Unexpected import of module ${id} from module ${sourceModule.id}, which was deleted by an HMR update` + ); + } + + const module = moduleCache[id]; + + if (sourceModule.children.indexOf(id) === -1) { + sourceModule.children.push(id); + } + + if (module) { + if (module.parents.indexOf(sourceModule.id) === -1) { + module.parents.push(sourceModule.id); + } + + return module; + } + + return instantiateModule(id, SourceType.Parent, sourceModule.id); +} + +/** + * This is adapted from https://github.com/vercel/next.js/blob/3466862d9dc9c8bb3131712134d38757b918d1c0/packages/react-refresh-utils/internal/ReactRefreshModule.runtime.ts + * + * @param {Module} module + * @param {RefreshHelpers} helpers + */ +function registerExportsAndSetupBoundaryForReactRefresh(module, helpers) { + const currentExports = module.exports; + const prevExports = module.hot.data.prevExports ?? null; + + helpers.registerExportsForReactRefresh(currentExports, module.id); + + // A module can be accepted automatically based on its exports, e.g. when + // it is a Refresh Boundary. + if (helpers.isReactRefreshBoundary(currentExports)) { + // Save the previous exports on update so we can compare the boundary + // signatures. + module.hot.dispose((data) => { + data.prevExports = currentExports; + }); + // Unconditionally accept an update to this module, we'll check if it's + // still a Refresh Boundary later. + module.hot.accept(); + + // This field is set when the previous version of this module was a + // Refresh Boundary, letting us know we need to check for invalidation or + // enqueue an update. + if (prevExports !== null) { + // A boundary can become ineligible if its exports are incompatible + // with the previous exports. + // + // For example, if you add/remove/change exports, we'll want to + // re-execute the importing modules, and force those components to + // re-render. Similarly, if you convert a class component to a + // function, we want to invalidate the boundary. + if ( + helpers.shouldInvalidateReactRefreshBoundary( + prevExports, + currentExports + ) + ) { + module.hot.invalidate(); + } else { + helpers.scheduleUpdate(); + } + } + } else { + // Since we just executed the code for the module, it's possible that the + // new exports made it ineligible for being a boundary. + // We only care about the case when we were _previously_ a boundary, + // because we already accepted this update (accidental side effect). + const isNoLongerABoundary = prevExports !== null; + if (isNoLongerABoundary) { + module.hot.invalidate(); + } + } +} + +/** + * @param {ModuleId[]} dependencyChain + * @returns {string} + */ +function formatDependencyChain(dependencyChain) { + return `Dependency chain: ${dependencyChain.join(" -> ")}`; +} + +/** + * @param {HmrUpdateEntry} factory + * @returns {ModuleFactory} + * @private + */ +function _eval({ code, url, map }) { + code += `\n\n//# sourceURL=${location.origin}${url}`; + if (map) code += `\n//# sourceMappingURL=${map}`; + return eval(code); +} + +/** + * @param {EcmascriptChunkUpdate} update + * @returns {{outdatedModules: Set, newModuleFactories: Map}} + */ +function computeOutdatedModules(update) { + const outdatedModules = new Set(); + const newModuleFactories = new Map(); + + for (const [moduleId, factory] of Object.entries(update.added)) { + newModuleFactories.set(moduleId, _eval(factory)); + } + + for (const [moduleId, factory] of Object.entries(update.modified)) { + const effect = getAffectedModuleEffects(moduleId); + + switch (effect.type) { + case "unaccepted": + throw new Error( + `cannot apply update: unaccepted module. ${formatDependencyChain( + effect.dependencyChain + )}.` + ); + case "self-declined": + throw new Error( + `cannot apply update: self-declined module. ${formatDependencyChain( + effect.dependencyChain + )}.` + ); + case "accepted": + newModuleFactories.set(moduleId, _eval(factory)); + for (const outdatedModuleId of effect.outdatedModules) { + outdatedModules.add(outdatedModuleId); + } + break; + // TODO(alexkirsz) Dependencies: handle dependencies effects. + } + } + + return { outdatedModules, newModuleFactories }; +} + +/** + * @param {Iterable} outdatedModules + * @returns {{ moduleId: ModuleId, errorHandler: true | Function }[]} + */ +function computeOutdatedSelfAcceptedModules(outdatedModules) { + const outdatedSelfAcceptedModules = []; + for (const moduleId of outdatedModules) { + const module = moduleCache[moduleId]; + const hotState = moduleHotState.get(module); + if (module && hotState.selfAccepted && !hotState.selfInvalidated) { + outdatedSelfAcceptedModules.push({ + moduleId, + errorHandler: hotState.selfAccepted, + }); + } + } + return outdatedSelfAcceptedModules; +} + +/** + * @param {ChunkPath} chunkPath + * @param {Iterable} outdatedModules + * @param {Iterable} deletedModules + */ +function disposePhase(chunkPath, outdatedModules, deletedModules) { + for (const moduleId of outdatedModules) { + const module = moduleCache[moduleId]; + if (!module) { + continue; + } + + const data = disposeModule(module); + + moduleHotData.set(moduleId, data); + } + + for (const moduleId of deletedModules) { + const module = moduleCache[moduleId]; + if (!module) { + continue; + } + + const noRemainingChunks = removeModuleFromChunk(moduleId, chunkPath); + + if (noRemainingChunks) { + disposeModule(module); + + moduleHotData.delete(moduleId); + } + } + + // TODO(alexkirsz) Dependencies: remove outdated dependency from module + // children. +} + +/** + * Disposes of an instance of a module. + * + * Returns the persistent hot data that should be kept for the next module + * instance. + * + * @param {Module} module + * @returns {{}} + */ +function disposeModule(module) { + const hotState = moduleHotState.get(module); + const data = {}; + + // Run the `hot.dispose` handler, if any, passing in the persistent + // `hot.data` object. + for (const disposeHandler of hotState.disposeHandlers) { + disposeHandler(data); + } + + // This used to warn in `getOrInstantiateModuleFromParent` when a disposed + // module is still importing other modules. + module.hot.active = false; + + delete moduleCache[module.id]; + moduleHotState.delete(module); + + // TODO(alexkirsz) Dependencies: delete the module from outdated deps. + + // Remove the disposed module from its children's parents list. + // It will be added back once the module re-instantiates and imports its + // children again. + for (const childId of module.children) { + const child = moduleCache[childId]; + if (!child) { + continue; + } + + const idx = child.parents.indexOf(module.id); + if (idx >= 0) { + child.parents.splice(idx, 1); + } + } + + return data; +} + +/** + * + * @param {ChunkPath} chunkPath + * @param {{ moduleId: ModuleId, errorHandler: true | Function }[]} outdatedSelfAcceptedModules + * @param {Map} newModuleFactories + */ +function applyPhase( + chunkPath, + outdatedSelfAcceptedModules, + newModuleFactories +) { + // Update module factories. + for (const [moduleId, factory] of newModuleFactories.entries()) { + moduleFactories[moduleId] = factory; + addModuleToChunk(moduleId, chunkPath); + } + + // TODO(alexkirsz) Run new runtime entries here. + + // TODO(alexkirsz) Dependencies: call accept handlers for outdated deps. + + // Re-instantiate all outdated self-accepted modules. + for (const { moduleId, errorHandler } of outdatedSelfAcceptedModules) { + try { + instantiateModule(moduleId, SourceType.Update); + } catch (err) { + if (typeof errorHandler === "function") { + try { + errorHandler(err, { moduleId, module: moduleCache[moduleId] }); + } catch (_) { + // Ignore error. + } + } + } + } +} + +/** + * + * @param {ChunkPath} chunkPath + * @param {EcmascriptChunkUpdate} update + */ +function applyUpdate(chunkPath, update) { + const { outdatedModules, newModuleFactories } = + computeOutdatedModules(update); + + const deletedModules = new Set(update.deleted); + + const outdatedSelfAcceptedModules = + computeOutdatedSelfAcceptedModules(outdatedModules); + + disposePhase(chunkPath, outdatedModules, deletedModules); + applyPhase(chunkPath, outdatedSelfAcceptedModules, newModuleFactories); +} + +/** + * + * @param {ModuleId} moduleId + * @returns {ModuleEffect} + */ +function getAffectedModuleEffects(moduleId) { + const outdatedModules = new Set(); + + /** @typedef {{moduleId?: ModuleId, dependencyChain: ModuleId[]}} QueueItem */ + + /** @type {QueueItem[]} */ + const queue = [ + { + moduleId, + dependencyChain: [], + }, + ]; + + while (queue.length > 0) { + const { moduleId, dependencyChain } = + /** @type {QueueItem} */ queue.shift(); + outdatedModules.add(moduleId); + + // We've arrived at the runtime of the chunk, which means that nothing + // else above can accept this update. + if (moduleId === undefined) { + return { + type: "unaccepted", + dependencyChain, + }; + } + + const module = moduleCache[moduleId]; + const hotState = moduleHotState.get(module); + + if ( + // The module is not in the cache. Since this is a "modified" update, + // it means that the module was never instantiated before. + !module || // The module accepted itself without invalidating globalThis. + // TODO is that right? + (hotState.selfAccepted && !hotState.selfInvalidated) + ) { + continue; + } + + if (hotState.selfDeclined) { + return { + type: "self-declined", + dependencyChain, + moduleId, + }; + } + + if (runtimeModules.has(moduleId)) { + queue.push({ + moduleId: undefined, + dependencyChain: [...dependencyChain, moduleId], + }); + continue; + } + + for (const parentId of module.parents) { + const parent = moduleCache[parentId]; + + if (!parent) { + // TODO(alexkirsz) Is this even possible? + continue; + } + + // TODO(alexkirsz) Dependencies: check accepted and declined + // dependencies here. + + queue.push({ + moduleId: parentId, + dependencyChain: [...dependencyChain, moduleId], + }); + } + } + + return { + type: "accepted", + moduleId, + outdatedModules, + }; +} + +/** + * @param {ChunkPath} chunkPath + * @param {import('../types/protocol').ServerMessage} update + */ +function handleApply(chunkPath, update) { + switch (update.type) { + case "partial": + applyUpdate(chunkPath, update.instruction); + break; + case "restart": + BACKEND.restart(); + break; + default: + throw new Error(`Unknown update type: ${update.type}`); + } +} + +/** + * @param {HotData} [hotData] + * @returns {{hotState: HotState, hot: Hot}} + */ +function createModuleHot(hotData) { + /** @type {HotState} */ + const hotState = { + selfAccepted: false, + selfDeclined: false, + selfInvalidated: false, + disposeHandlers: [], + }; + + /** + * TODO(alexkirsz) Support full (dep, callback, errorHandler) form. + * + * @param {string | string[] | AcceptErrorHandler} [dep] + * @param {AcceptCallback} [_callback] + * @param {AcceptErrorHandler} [_errorHandler] + */ + function accept(dep, _callback, _errorHandler) { + if (dep === undefined) { + hotState.selfAccepted = true; + } else if (typeof dep === "function") { + hotState.selfAccepted = dep; + } else { + throw new Error("unsupported `accept` signature"); + } + } + + /** @type {Hot} */ + const hot = { + // TODO(alexkirsz) This is not defined in the HMR API. It was used to + // decide whether to warn whenever an HMR-disposed module required other + // modules. We might want to remove it. + active: true, + + data: hotData ?? {}, + + accept: accept, + + decline: (dep) => { + if (dep === undefined) { + hotState.selfDeclined = true; + } else { + throw new Error("unsupported `decline` signature"); + } + }, + + dispose: (callback) => { + hotState.disposeHandlers.push(callback); + }, + + addDisposeHandler: (callback) => { + hotState.disposeHandlers.push(callback); + }, + + removeDisposeHandler: (callback) => { + const idx = hotState.disposeHandlers.indexOf(callback); + if (idx >= 0) { + hotState.disposeHandlers.splice(idx, 1); + } + }, + + invalidate: () => { + hotState.selfInvalidated = true; + // TODO(alexkirsz) The original HMR code had management-related code + // here. + }, + + // NOTE(alexkirsz) This is part of the management API, which we don't + // implement, but the Next.js React Refresh runtime uses this to decide + // whether to schedule an update. + status: () => "idle", + + // NOTE(alexkirsz) Since we always return "idle" for now, these are no-ops. + addStatusHandler: (_handler) => {}, + removeStatusHandler: (_handler) => {}, + }; + + return { hot, hotState }; +} + +/** + * Adds a module to a chunk. + * + * @param {ModuleId} moduleId + * @param {ChunkPath} chunkPath + */ +function addModuleToChunk(moduleId, chunkPath) { + let moduleChunks = moduleChunksMap.get(moduleId); + if (!moduleChunks) { + moduleChunks = new Set([chunkPath]); + moduleChunksMap.set(moduleId, moduleChunks); + } else { + moduleChunks.add(chunkPath); + } +} + +/** + * Returns the first chunk that included a module. + * + * @type {GetFirstModuleChunk} + */ +function getFirstModuleChunk(moduleId) { + const moduleChunkPaths = moduleChunksMap.get(moduleId); + if (moduleChunkPaths == null) { + return null; + } + + return moduleChunkPaths.values().next().value; +} + +/** + * Removes a module from a chunk. Returns true there are no remaining chunks + * including this module. + * + * @param {ModuleId} moduleId + * @param {ChunkPath} chunkPath + * @returns {boolean} + */ +function removeModuleFromChunk(moduleId, chunkPath) { + const moduleChunks = moduleChunksMap.get(moduleId); + moduleChunks.delete(chunkPath); + + if (moduleChunks.size > 0) { + return false; + } + + moduleChunksMap.delete(moduleId); + return true; +} + +/** + * Instantiates a runtime module. + */ +/** + * + * @param {ModuleId} moduleId + * @returns {Module} + */ +function instantiateRuntimeModule(moduleId) { + return instantiateModule(moduleId, SourceType.Runtime); +} + +/** + * Subscribes to chunk updates from the update server and applies them. + * + * @param {ChunkPath} chunkPath + */ +function subscribeToChunkUpdates(chunkPath) { + // This adds a chunk update listener once the handler code has been loaded + globalThis.TURBOPACK_CHUNK_UPDATE_LISTENERS.push([ + chunkPath, + handleApply.bind(null, chunkPath), + ]); +} + +function markChunkAsLoaded(chunkPath) { + const chunkLoader = chunkLoaders.get(chunkPath); + if (!chunkLoader) { + loadedChunks.add(chunkPath); + + // This happens for all initial chunks that are loaded directly from + // the HTML. + return; + } + + // Only chunks that are loaded via `loadChunk` will have a loader. + chunkLoader.onLoad(); +} + +/** @type {Runtime} */ +const runtime = { + loadedChunks, + modules: moduleFactories, + cache: moduleCache, + instantiateRuntimeModule, +}; + +/** + * @param {ChunkRegistration} chunkRegistration + */ +function registerChunk([chunkPath, chunkModules, ...run]) { + markChunkAsLoaded(chunkPath); + subscribeToChunkUpdates(chunkPath); + for (const [moduleId, moduleFactory] of Object.entries(chunkModules)) { + if (!moduleFactories[moduleId]) { + moduleFactories[moduleId] = moduleFactory; + } + addModuleToChunk(moduleId, chunkPath); + } + runnable.push(...run); + runnable = runnable.filter((r) => r(runtime)); +} + +globalThis.TURBOPACK_CHUNK_UPDATE_LISTENERS = + globalThis.TURBOPACK_CHUNK_UPDATE_LISTENERS || []; + +globalThis.TURBOPACK.forEach(registerChunk); +globalThis.TURBOPACK = { + push: registerChunk, +}; +})(); + + +//# sourceMappingURL=crates_turbopack-tests_tests_snapshot_export-alls_cjs-script_input_index_32f385.js.map \ No newline at end of file diff --git a/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-script_input_index_32f385.js.map b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-script_input_index_32f385.js.map new file mode 100644 index 0000000000000..372f7045fa92e --- /dev/null +++ b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-script_input_index_32f385.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "sections": [ + {"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/index.js"],"sourcesContent":["import * as foo from './mod.js';\n\nconsole.log(foo)"],"names":[],"mappings":"AAAA;;;AAEA,QAAQ,GAAG"}}, + {"offset": {"line": 8, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}, + {"offset": {"line": 12, "column": 0}, "map": {"version":3,"sources":["/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/mod.js"],"sourcesContent":["\nexport * from './exported.cjs'\n\nconsole.log('Hoist test')"],"names":[],"mappings":"AACA;;;;;AAEA,QAAQ,GAAG,CAAC"}}, + {"offset": {"line": 18, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}, + {"offset": {"line": 22, "column": 0}, "map": {"version":3,"sources":["/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/exported.cjs"],"sourcesContent":["module.exports = { foo: 1, bar: 2 }"],"names":[],"mappings":"AAAA,OAAO,OAAO,GAAG;IAAE,KAAK;IAAG,KAAK;AAAE"}}, + {"offset": {"line": 26, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}] +} \ No newline at end of file diff --git a/crates/turbopack-tests/tests/snapshot/import-meta/cjs/output/crates_turbopack-tests_tests_snapshot_import-meta_cjs_input_index_859774.js b/crates/turbopack-tests/tests/snapshot/import-meta/cjs/output/crates_turbopack-tests_tests_snapshot_import-meta_cjs_input_index_859774.js index c357e1e94df78..eec1f464362c6 100644 --- a/crates/turbopack-tests/tests/snapshot/import-meta/cjs/output/crates_turbopack-tests_tests_snapshot_import-meta_cjs_input_index_859774.js +++ b/crates/turbopack-tests/tests/snapshot/import-meta/cjs/output/crates_turbopack-tests_tests_snapshot_import-meta_cjs_input_index_859774.js @@ -1,13 +1,13 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_import-meta_cjs_input_index_859774.js", { -"[project]/crates/turbopack-tests/tests/snapshot/import-meta/cjs/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/import-meta/cjs/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$import$2d$meta$2f$cjs$2f$input$2f$mod$2e$cjs__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/import-meta/cjs/input/mod.cjs (ecmascript)"); "__TURBOPACK__ecmascript__hoisting__location__"; ; }.call(this) }), -"[project]/crates/turbopack-tests/tests/snapshot/import-meta/cjs/input/mod.cjs (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/import-meta/cjs/input/mod.cjs (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { const __TURBOPACK__import$2e$meta__ = { url: "file:///ROOT/crates/turbopack-tests/tests/snapshot/import-meta/cjs/input/mod.cjs" @@ -172,6 +172,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -390,6 +402,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/output/79fb1_turbopack-tests_tests_snapshot_import-meta_esm-multiple_input_index_a53493.js b/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/output/79fb1_turbopack-tests_tests_snapshot_import-meta_esm-multiple_input_index_a53493.js index 2d2775531f5d0..5b7ae58b56439 100644 --- a/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/output/79fb1_turbopack-tests_tests_snapshot_import-meta_esm-multiple_input_index_a53493.js +++ b/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/output/79fb1_turbopack-tests_tests_snapshot_import-meta_esm-multiple_input_index_a53493.js @@ -1,13 +1,13 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/79fb1_turbopack-tests_tests_snapshot_import-meta_esm-multiple_input_index_a53493.js", { -"[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$import$2d$meta$2f$esm$2d$multiple$2f$input$2f$mod$2e$mjs__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/input/mod.mjs (ecmascript)"); "__TURBOPACK__ecmascript__hoisting__location__"; ; }.call(this) }), -"[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/input/mod.mjs (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/input/mod.mjs (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { const __TURBOPACK__import$2e$meta__ = { url: "file:///ROOT/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/input/mod.mjs" @@ -179,6 +179,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -397,6 +409,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/output/crates_turbopack-tests_tests_snapshot_import-meta_esm-mutable_input_index_bbd10b.js b/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/output/crates_turbopack-tests_tests_snapshot_import-meta_esm-mutable_input_index_bbd10b.js index 92d2d3fa3db9a..f461c241d5610 100644 --- a/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/output/crates_turbopack-tests_tests_snapshot_import-meta_esm-mutable_input_index_bbd10b.js +++ b/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/output/crates_turbopack-tests_tests_snapshot_import-meta_esm-mutable_input_index_bbd10b.js @@ -1,13 +1,13 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_import-meta_esm-mutable_input_index_bbd10b.js", { -"[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$import$2d$meta$2f$esm$2d$mutable$2f$input$2f$mod$2e$mjs__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/input/mod.mjs (ecmascript)"); "__TURBOPACK__ecmascript__hoisting__location__"; ; }.call(this) }), -"[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/input/mod.mjs (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/input/mod.mjs (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { const __TURBOPACK__import$2e$meta__ = { url: "file:///ROOT/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/input/mod.mjs" @@ -172,6 +172,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -390,6 +402,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/output/crates_turbopack-tests_tests_snapshot_import-meta_esm-object_input_index_31d622.js b/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/output/crates_turbopack-tests_tests_snapshot_import-meta_esm-object_input_index_31d622.js index 84e527229b9f0..a8ed88ac68092 100644 --- a/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/output/crates_turbopack-tests_tests_snapshot_import-meta_esm-object_input_index_31d622.js +++ b/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/output/crates_turbopack-tests_tests_snapshot_import-meta_esm-object_input_index_31d622.js @@ -1,13 +1,13 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_import-meta_esm-object_input_index_31d622.js", { -"[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$import$2d$meta$2f$esm$2d$object$2f$input$2f$mod$2e$mjs__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/input/mod.mjs (ecmascript)"); "__TURBOPACK__ecmascript__hoisting__location__"; ; }.call(this) }), -"[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/input/mod.mjs (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/input/mod.mjs (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { const __TURBOPACK__import$2e$meta__ = { url: "file:///ROOT/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/input/mod.mjs" @@ -172,6 +172,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -390,6 +402,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/import-meta/esm/output/crates_turbopack-tests_tests_snapshot_import-meta_esm_input_index_7072f9.js b/crates/turbopack-tests/tests/snapshot/import-meta/esm/output/crates_turbopack-tests_tests_snapshot_import-meta_esm_input_index_7072f9.js index c1efd25cfeaaa..6d1f6ec92bae0 100644 --- a/crates/turbopack-tests/tests/snapshot/import-meta/esm/output/crates_turbopack-tests_tests_snapshot_import-meta_esm_input_index_7072f9.js +++ b/crates/turbopack-tests/tests/snapshot/import-meta/esm/output/crates_turbopack-tests_tests_snapshot_import-meta_esm_input_index_7072f9.js @@ -1,13 +1,13 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_import-meta_esm_input_index_7072f9.js", { -"[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$import$2d$meta$2f$esm$2f$input$2f$mod$2e$mjs__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm/input/mod.mjs (ecmascript)"); "__TURBOPACK__ecmascript__hoisting__location__"; ; }.call(this) }), -"[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm/input/mod.mjs (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/import-meta/esm/input/mod.mjs (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { const __TURBOPACK__import$2e$meta__ = { url: "file:///ROOT/crates/turbopack-tests/tests/snapshot/import-meta/esm/input/mod.mjs" @@ -172,6 +172,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -390,6 +402,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/import-meta/url/output/crates_turbopack-tests_tests_snapshot_import-meta_url_input_index_94525c.js b/crates/turbopack-tests/tests/snapshot/import-meta/url/output/crates_turbopack-tests_tests_snapshot_import-meta_url_input_index_94525c.js index 54d2d1c22699b..a43d210c35e5d 100644 --- a/crates/turbopack-tests/tests/snapshot/import-meta/url/output/crates_turbopack-tests_tests_snapshot_import-meta_url_input_index_94525c.js +++ b/crates/turbopack-tests/tests/snapshot/import-meta/url/output/crates_turbopack-tests_tests_snapshot_import-meta_url_input_index_94525c.js @@ -1,13 +1,13 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_import-meta_url_input_index_94525c.js", { -"[project]/crates/turbopack-tests/tests/snapshot/import-meta/url/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/import-meta/url/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$import$2d$meta$2f$url$2f$input$2f$mod$2e$mjs__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/import-meta/url/input/mod.mjs (ecmascript)"); "__TURBOPACK__ecmascript__hoisting__location__"; ; }.call(this) }), -"[project]/crates/turbopack-tests/tests/snapshot/import-meta/url/input/mod.mjs (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/import-meta/url/input/mod.mjs (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { const __TURBOPACK__import$2e$meta__ = { url: "file:///ROOT/crates/turbopack-tests/tests/snapshot/import-meta/url/input/mod.mjs" @@ -18,7 +18,7 @@ console.log(assetUrl); fetch(assetUrl).then((res)=>res.text()).then(console.log); }.call(this) }), -"[project]/crates/turbopack-tests/tests/snapshot/import-meta/url/input/asset.txt (static)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/import-meta/url/input/asset.txt (static)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { __turbopack_export_value__("/crates/turbopack-tests/tests/snapshot/import-meta/url/static/05254cf29a922ae2.txt"); })()), @@ -178,6 +178,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -396,6 +408,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/imports/dynamic/output/79fb1_turbopack-tests_tests_snapshot_imports_dynamic_input_vercel.mjs_manifest-chunk.js b/crates/turbopack-tests/tests/snapshot/imports/dynamic/output/79fb1_turbopack-tests_tests_snapshot_imports_dynamic_input_vercel.mjs_manifest-chunk.js index 019bf34ad3f8a..f1f2b408744b4 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/dynamic/output/79fb1_turbopack-tests_tests_snapshot_imports_dynamic_input_vercel.mjs_manifest-chunk.js +++ b/crates/turbopack-tests/tests/snapshot/imports/dynamic/output/79fb1_turbopack-tests_tests_snapshot_imports_dynamic_input_vercel.mjs_manifest-chunk.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/79fb1_turbopack-tests_tests_snapshot_imports_dynamic_input_vercel.mjs_manifest-chunk.js", { -"[project]/crates/turbopack-tests/tests/snapshot/imports/dynamic/input/vercel.mjs/manifest-chunk.js": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/imports/dynamic/input/vercel.mjs/manifest-chunk.js": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { const chunks = [ "output/crates_turbopack-tests_tests_snapshot_imports_dynamic_input_vercel.mjs.js", diff --git a/crates/turbopack-tests/tests/snapshot/imports/dynamic/output/crates_turbopack-tests_tests_snapshot_imports_dynamic_input_index_2bf706.js b/crates/turbopack-tests/tests/snapshot/imports/dynamic/output/crates_turbopack-tests_tests_snapshot_imports_dynamic_input_index_2bf706.js index 4c74149db2325..37659bb622b50 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/dynamic/output/crates_turbopack-tests_tests_snapshot_imports_dynamic_input_index_2bf706.js +++ b/crates/turbopack-tests/tests/snapshot/imports/dynamic/output/crates_turbopack-tests_tests_snapshot_imports_dynamic_input_index_2bf706.js @@ -1,11 +1,11 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_imports_dynamic_input_index_2bf706.js", { -"[project]/crates/turbopack-tests/tests/snapshot/imports/dynamic/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/imports/dynamic/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { __turbopack_require__("[project]/crates/turbopack-tests/tests/snapshot/imports/dynamic/input/vercel.mjs/manifest-loader.js")(__turbopack_import__).then(console.log); }.call(this) }), -"[project]/crates/turbopack-tests/tests/snapshot/imports/dynamic/input/vercel.mjs/manifest-loader.js": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/imports/dynamic/input/vercel.mjs/manifest-loader.js": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { __turbopack_export_value__((__turbopack_import__) => { @@ -170,6 +170,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -388,6 +400,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/imports/dynamic/output/crates_turbopack-tests_tests_snapshot_imports_dynamic_input_vercel.mjs.js b/crates/turbopack-tests/tests/snapshot/imports/dynamic/output/crates_turbopack-tests_tests_snapshot_imports_dynamic_input_vercel.mjs.js index 852717aa7dbb7..1af15da65651c 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/dynamic/output/crates_turbopack-tests_tests_snapshot_imports_dynamic_input_vercel.mjs.js +++ b/crates/turbopack-tests/tests/snapshot/imports/dynamic/output/crates_turbopack-tests_tests_snapshot_imports_dynamic_input_vercel.mjs.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_imports_dynamic_input_vercel.mjs.js", { -"[project]/crates/turbopack-tests/tests/snapshot/imports/dynamic/input/vercel.mjs (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/imports/dynamic/input/vercel.mjs (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { __turbopack_esm__({ "default": ()=>__TURBOPACK__default__export__ diff --git a/crates/turbopack-tests/tests/snapshot/imports/json/output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_e24981.js b/crates/turbopack-tests/tests/snapshot/imports/json/output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_e24981.js index a963b0ee20455..4a4021867a87c 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/json/output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_e24981.js +++ b/crates/turbopack-tests/tests/snapshot/imports/json/output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_e24981.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_e24981.js", { -"[project]/crates/turbopack-tests/tests/snapshot/imports/json/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/imports/json/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$imports$2f$json$2f$input$2f$package$2e$json__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/imports/json/input/package.json (json)"); var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$imports$2f$json$2f$input$2f$invalid$2e$json__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/imports/json/input/invalid.json (json)"); @@ -11,11 +11,11 @@ console.log(__TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$ console.log(__TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$imports$2f$json$2f$input$2f$invalid$2e$json__["default"]["this-is"]); })()), -"[project]/crates/turbopack-tests/tests/snapshot/imports/json/input/package.json (json)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/imports/json/input/package.json (json)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { __turbopack_export_value__(JSON.parse("{\"name\":\"json-snapshot\"}")); })()), -"[project]/crates/turbopack-tests/tests/snapshot/imports/json/input/invalid.json (json)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/imports/json/input/invalid.json (json)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { throw new Error("An error occurred while importing a JSON module: \"File is not valid JSON\"") })()), @@ -175,6 +175,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -393,6 +405,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/imports/resolve_error_cjs/output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_cjs_input_index_e00120.js b/crates/turbopack-tests/tests/snapshot/imports/resolve_error_cjs/output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_cjs_input_index_e00120.js index 97fe19301fbe1..676aaba22331a 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/resolve_error_cjs/output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_cjs_input_index_e00120.js +++ b/crates/turbopack-tests/tests/snapshot/imports/resolve_error_cjs/output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_cjs_input_index_e00120.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_cjs_input_index_e00120.js", { -"[project]/crates/turbopack-tests/tests/snapshot/imports/resolve_error_cjs/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/snapshot/imports/resolve_error_cjs/input/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { const dne = __turbopack_require__((()=>{ const e = new Error("Cannot find module 'does-not-exist/path'"); @@ -166,6 +166,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -384,6 +396,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/imports/resolve_error_esm/output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_esm_input_index_1a5dd4.js b/crates/turbopack-tests/tests/snapshot/imports/resolve_error_esm/output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_esm_input_index_1a5dd4.js index 200406cfeb0a0..10d86807b4213 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/resolve_error_esm/output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_esm_input_index_1a5dd4.js +++ b/crates/turbopack-tests/tests/snapshot/imports/resolve_error_esm/output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_esm_input_index_1a5dd4.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_esm_input_index_1a5dd4.js", { -"[project]/crates/turbopack-tests/tests/snapshot/imports/resolve_error_esm/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/imports/resolve_error_esm/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { (()=>{ const e = new Error("Cannot find module 'does-not-exist/path'"); @@ -169,6 +169,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -387,6 +399,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/output/79fb1_turbopack-tests_tests_snapshot_imports_static-and-dynamic_input_index_bbeff3.js b/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/output/79fb1_turbopack-tests_tests_snapshot_imports_static-and-dynamic_input_index_bbeff3.js index 43a9f172b6b99..de8e14ce01924 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/output/79fb1_turbopack-tests_tests_snapshot_imports_static-and-dynamic_input_index_bbeff3.js +++ b/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/output/79fb1_turbopack-tests_tests_snapshot_imports_static-and-dynamic_input_index_bbeff3.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/79fb1_turbopack-tests_tests_snapshot_imports_static-and-dynamic_input_index_bbeff3.js", { -"[project]/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$imports$2f$static$2d$and$2d$dynamic$2f$input$2f$vercel$2e$mjs__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/input/vercel.mjs (ecmascript)"); "__TURBOPACK__ecmascript__hoisting__location__"; @@ -9,7 +9,7 @@ console.log(__TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$ __turbopack_require__("[project]/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/input/vercel.mjs/manifest-loader.js")(__turbopack_import__).then(console.log); })()), -"[project]/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/input/vercel.mjs (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/input/vercel.mjs (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { __turbopack_esm__({ "default": ()=>__TURBOPACK__default__export__ @@ -17,7 +17,7 @@ __turbopack_esm__({ const __TURBOPACK__default__export__ = "turbopack"; })()), -"[project]/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/input/vercel.mjs/manifest-loader.js": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/input/vercel.mjs/manifest-loader.js": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { __turbopack_export_value__((__turbopack_import__) => { @@ -182,6 +182,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -400,6 +412,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/output/79fb1_turbopack-tests_tests_snapshot_imports_static-and-dynamic_input_vercel.mjs.js b/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/output/79fb1_turbopack-tests_tests_snapshot_imports_static-and-dynamic_input_vercel.mjs.js index 27298e0247840..f8b92fba55957 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/output/79fb1_turbopack-tests_tests_snapshot_imports_static-and-dynamic_input_vercel.mjs.js +++ b/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/output/79fb1_turbopack-tests_tests_snapshot_imports_static-and-dynamic_input_vercel.mjs.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/79fb1_turbopack-tests_tests_snapshot_imports_static-and-dynamic_input_vercel.mjs.js", { -"[project]/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/input/vercel.mjs (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/input/vercel.mjs (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { __turbopack_esm__({ "default": ()=>__TURBOPACK__default__export__ diff --git a/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/output/a587c_tests_snapshot_imports_static-and-dynamic_input_vercel.mjs_manifest-chunk.js b/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/output/a587c_tests_snapshot_imports_static-and-dynamic_input_vercel.mjs_manifest-chunk.js index 8d687b8edc932..f58787db3bf83 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/output/a587c_tests_snapshot_imports_static-and-dynamic_input_vercel.mjs_manifest-chunk.js +++ b/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/output/a587c_tests_snapshot_imports_static-and-dynamic_input_vercel.mjs_manifest-chunk.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/a587c_tests_snapshot_imports_static-and-dynamic_input_vercel.mjs_manifest-chunk.js", { -"[project]/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/input/vercel.mjs/manifest-chunk.js": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/input/vercel.mjs/manifest-chunk.js": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { const chunks = [ "output/79fb1_turbopack-tests_tests_snapshot_imports_static-and-dynamic_input_vercel.mjs.js", diff --git a/crates/turbopack-tests/tests/snapshot/imports/static/output/crates_turbopack-tests_tests_snapshot_imports_static_input_index_b8717b.js b/crates/turbopack-tests/tests/snapshot/imports/static/output/crates_turbopack-tests_tests_snapshot_imports_static_input_index_b8717b.js index ebf1090d8846c..760486ef40e15 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/static/output/crates_turbopack-tests_tests_snapshot_imports_static_input_index_b8717b.js +++ b/crates/turbopack-tests/tests/snapshot/imports/static/output/crates_turbopack-tests_tests_snapshot_imports_static_input_index_b8717b.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_imports_static_input_index_b8717b.js", { -"[project]/crates/turbopack-tests/tests/snapshot/imports/static/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/imports/static/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$imports$2f$static$2f$input$2f$vercel$2e$svg__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/imports/static/input/vercel.svg (static)"); "__TURBOPACK__ecmascript__hoisting__location__"; @@ -8,7 +8,7 @@ var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests console.log(__TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$imports$2f$static$2f$input$2f$vercel$2e$svg__["default"]); })()), -"[project]/crates/turbopack-tests/tests/snapshot/imports/static/input/vercel.svg (static)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/imports/static/input/vercel.svg (static)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { __turbopack_export_value__("/crates/turbopack-tests/tests/snapshot/imports/static/static/957b9b162f8447f9.svg"); })()), @@ -168,6 +168,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -386,6 +398,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/node/node_protocol_external/output/79fb1_turbopack-tests_tests_snapshot_node_node_protocol_external_input_index_6a3d80.js b/crates/turbopack-tests/tests/snapshot/node/node_protocol_external/output/79fb1_turbopack-tests_tests_snapshot_node_node_protocol_external_input_index_6a3d80.js index 8c3825a4da7aa..aa40edc1c89c9 100644 --- a/crates/turbopack-tests/tests/snapshot/node/node_protocol_external/output/79fb1_turbopack-tests_tests_snapshot_node_node_protocol_external_input_index_6a3d80.js +++ b/crates/turbopack-tests/tests/snapshot/node/node_protocol_external/output/79fb1_turbopack-tests_tests_snapshot_node_node_protocol_external_input_index_6a3d80.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/79fb1_turbopack-tests_tests_snapshot_node_node_protocol_external_input_index_6a3d80.js", { -"[project]/crates/turbopack-tests/tests/snapshot/node/node_protocol_external/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/node/node_protocol_external/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { var __TURBOPACK__external__node$3a$fs__ = __turbopack_external_require__("node:fs", true); "__TURBOPACK__ecmascript__hoisting__location__"; @@ -163,6 +163,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -381,6 +393,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/styled_components/styled_components/output/63a02_styled-components_index.js b/crates/turbopack-tests/tests/snapshot/styled_components/styled_components/output/63a02_styled-components_index.js index b1c779ed7dc0d..b21d071e4ccb4 100644 --- a/crates/turbopack-tests/tests/snapshot/styled_components/styled_components/output/63a02_styled-components_index.js +++ b/crates/turbopack-tests/tests/snapshot/styled_components/styled_components/output/63a02_styled-components_index.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/63a02_styled-components_index.js", { -"[project]/crates/turbopack-tests/tests/node_modules/styled-components/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/node_modules/styled-components/index.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { "purposefully empty stub"; "styled-components/index.js"; diff --git a/crates/turbopack-tests/tests/snapshot/styled_components/styled_components/output/a587c_tests_snapshot_styled_components_styled_components_input_index_7b57d9.js b/crates/turbopack-tests/tests/snapshot/styled_components/styled_components/output/a587c_tests_snapshot_styled_components_styled_components_input_index_7b57d9.js index 325371526dd93..425afed85400b 100644 --- a/crates/turbopack-tests/tests/snapshot/styled_components/styled_components/output/a587c_tests_snapshot_styled_components_styled_components_input_index_7b57d9.js +++ b/crates/turbopack-tests/tests/snapshot/styled_components/styled_components/output/a587c_tests_snapshot_styled_components_styled_components_input_index_7b57d9.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/a587c_tests_snapshot_styled_components_styled_components_input_index_7b57d9.js", { -"[project]/crates/turbopack-tests/tests/snapshot/styled_components/styled_components/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/styled_components/styled_components/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$node_modules$2f$styled$2d$components$2f$index$2e$js__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/node_modules/styled-components/index.js (ecmascript)"); "__TURBOPACK__ecmascript__hoisting__location__"; @@ -170,6 +170,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -388,6 +400,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/63a02_react_jsx-dev-runtime.js b/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/63a02_react_jsx-dev-runtime.js index b10c6dbbb5c5d..0612b8265bb49 100644 --- a/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/63a02_react_jsx-dev-runtime.js +++ b/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/63a02_react_jsx-dev-runtime.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/63a02_react_jsx-dev-runtime.js", { -"[project]/crates/turbopack-tests/tests/node_modules/react/jsx-dev-runtime.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/node_modules/react/jsx-dev-runtime.js (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { "purposefully empty stub"; "react/jsx-dev-runtime.js"; diff --git a/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/7b7bf_third_party_component_index.js b/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/7b7bf_third_party_component_index.js index 55e3ea1eb70f6..0a30cd5abc869 100644 --- a/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/7b7bf_third_party_component_index.js +++ b/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/7b7bf_third_party_component_index.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/7b7bf_third_party_component_index.js", { -"[project]/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/input/node_modules/third_party_component/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/input/node_modules/third_party_component/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { __turbopack_esm__({ "default": ()=>ThirdPartyComponent diff --git a/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/a587c_tests_snapshot_swc_transforms_mono_transforms_input_packages_app_index_739f58.js b/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/a587c_tests_snapshot_swc_transforms_mono_transforms_input_packages_app_index_739f58.js index 2fa99d7577dd3..d9d5d8a5dde1d 100644 --- a/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/a587c_tests_snapshot_swc_transforms_mono_transforms_input_packages_app_index_739f58.js +++ b/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/a587c_tests_snapshot_swc_transforms_mono_transforms_input_packages_app_index_739f58.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/a587c_tests_snapshot_swc_transforms_mono_transforms_input_packages_app_index_739f58.js", { -"[project]/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/input/packages/app/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/input/packages/app/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$swc_transforms$2f$mono_transforms$2f$input$2f$packages$2f$component$2f$index$2e$js__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/input/packages/component/index.js (ecmascript)"); var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$swc_transforms$2f$mono_transforms$2f$input$2f$node_modules$2f$third_party_component$2f$index$2e$js__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/input/node_modules/third_party_component/index.js (ecmascript)"); @@ -166,6 +166,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -384,6 +396,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/a587c_tests_snapshot_swc_transforms_mono_transforms_input_packages_component_index.js b/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/a587c_tests_snapshot_swc_transforms_mono_transforms_input_packages_component_index.js index 5fef7f36208e0..200d55159a01e 100644 --- a/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/a587c_tests_snapshot_swc_transforms_mono_transforms_input_packages_component_index.js +++ b/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/a587c_tests_snapshot_swc_transforms_mono_transforms_input_packages_component_index.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/a587c_tests_snapshot_swc_transforms_mono_transforms_input_packages_component_index.js", { -"[project]/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/input/packages/component/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/input/packages/component/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { __turbopack_esm__({ "default": ()=>MyApp diff --git a/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env/output/63a02_@swc_helpers_src__class_call_check.mjs.js b/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env/output/63a02_@swc_helpers_src__class_call_check.mjs.js index 5480eeeb09450..b48ebc147b371 100644 --- a/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env/output/63a02_@swc_helpers_src__class_call_check.mjs.js +++ b/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env/output/63a02_@swc_helpers_src__class_call_check.mjs.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/63a02_@swc_helpers_src__class_call_check.mjs.js", { -"[project]/crates/turbopack-tests/tests/node_modules/@swc/helpers/src/_class_call_check.mjs (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { +"[project]/crates/turbopack-tests/tests/node_modules/@swc/helpers/src/_class_call_check.mjs (ecmascript)": (function({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname, m: module, e: exports }) { !function() { "purposefully empty stub"; "@swc/helpers/src/_class_call_check.mjs"; diff --git a/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env/output/79fb1_turbopack-tests_tests_snapshot_swc_transforms_preset_env_input_index_44c34f.js b/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env/output/79fb1_turbopack-tests_tests_snapshot_swc_transforms_preset_env_input_index_44c34f.js index 7329ed074423c..2a8594c145eba 100644 --- a/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env/output/79fb1_turbopack-tests_tests_snapshot_swc_transforms_preset_env_input_index_44c34f.js +++ b/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env/output/79fb1_turbopack-tests_tests_snapshot_swc_transforms_preset_env_input_index_44c34f.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/79fb1_turbopack-tests_tests_snapshot_swc_transforms_preset_env_input_index_44c34f.js", { -"[project]/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$node_modules$2f40$swc$2f$helpers$2f$src$2f$_class_call_check$2e$mjs__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/node_modules/@swc/helpers/src/_class_call_check.mjs (ecmascript)"); "__TURBOPACK__ecmascript__hoisting__location__"; @@ -168,6 +168,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -386,6 +398,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache, diff --git a/crates/turbopack-tests/tests/snapshot/tsconfig/baseurl/output/crates_turbopack-tests_tests_snapshot_tsconfig_baseurl_input_index_5906e5.js b/crates/turbopack-tests/tests/snapshot/tsconfig/baseurl/output/crates_turbopack-tests_tests_snapshot_tsconfig_baseurl_input_index_5906e5.js index 3cf9939172c24..bbe6b5b19fef8 100644 --- a/crates/turbopack-tests/tests/snapshot/tsconfig/baseurl/output/crates_turbopack-tests_tests_snapshot_tsconfig_baseurl_input_index_5906e5.js +++ b/crates/turbopack-tests/tests/snapshot/tsconfig/baseurl/output/crates_turbopack-tests_tests_snapshot_tsconfig_baseurl_input_index_5906e5.js @@ -1,6 +1,6 @@ (self.TURBOPACK = self.TURBOPACK || []).push(["output/crates_turbopack-tests_tests_snapshot_tsconfig_baseurl_input_index_5906e5.js", { -"[project]/crates/turbopack-tests/tests/snapshot/tsconfig/baseurl/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, p: process, g: global, __dirname }) => (() => { +"[project]/crates/turbopack-tests/tests/snapshot/tsconfig/baseurl/input/index.js (ecmascript)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { const e = new Error("Could not parse module '[project]/crates/turbopack-tests/tests/snapshot/tsconfig/baseurl/input/index.js'"); e.code = 'MODULE_UNPARSEABLE'; @@ -162,6 +162,18 @@ function esm(exports, getters) { } } +/** + * Adds the getters to the exports object + * + * @param {Exports} exports + * @param {Record} props + */ +function cjs(exports, props) { + for (const key in props) { + defineProp(exports, key, { get: () => props[key], enumerable: true }); + } +} + /** * @param {Module} module * @param {any} value @@ -380,6 +392,7 @@ function instantiateModule(id, sourceType, sourceId) { x: externalRequire, i: esmImport.bind(null, module), s: esm.bind(null, module.exports), + j: cjs.bind(null, module.exports), v: exportValue.bind(null, module), m: module, c: moduleCache,