aboutsummaryrefslogtreecommitdiff
path: root/src/bundler.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-05-29 11:23:10 -0700
committerGravatar GitHub <noreply@github.com> 2023-05-29 11:23:10 -0700
commite2de1f5c133ed3aac6fcea7e8e7c5fcd771d65f9 (patch)
tree219ad30067db8641999811b67744ce665f45dd46 /src/bundler.zig
parent2b04ef4fae088b6f39628da312643cf4c54921ad (diff)
downloadbun-e2de1f5c133ed3aac6fcea7e8e7c5fcd771d65f9.tar.gz
bun-e2de1f5c133ed3aac6fcea7e8e7c5fcd771d65f9.tar.zst
bun-e2de1f5c133ed3aac6fcea7e8e7c5fcd771d65f9.zip
Natively support CommonJS at runtime (#3104)
* Natively support CommonJS at runtime * cleanup how getters are handled, add fast path * more consistent with node * use * As * Remove thrown modules on exception * Handle exception better --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bundler.zig')
-rw-r--r--src/bundler.zig5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/bundler.zig b/src/bundler.zig
index 9650f7f60..f3296134e 100644
--- a/src/bundler.zig
+++ b/src/bundler.zig
@@ -1203,6 +1203,7 @@ pub const Bundler = struct {
.minify_syntax = bundler.options.minify_syntax,
.minify_identifiers = bundler.options.minify_identifiers,
.transform_only = bundler.options.transform_only,
+ .module_type = if (ast.exports_kind == .cjs) .cjs else .esm,
},
enable_source_map,
),
@@ -1224,6 +1225,7 @@ pub const Bundler = struct {
.minify_syntax = bundler.options.minify_syntax,
.minify_identifiers = bundler.options.minify_identifiers,
.transform_only = bundler.options.transform_only,
+ .module_type = if (ast.exports_kind == .cjs) .cjs else .esm,
},
enable_source_map,
),
@@ -1287,6 +1289,7 @@ pub const Bundler = struct {
inject_jest_globals: bool = false,
dont_bundle_twice: bool = false,
+ allow_commonjs: bool = false,
};
pub fn parse(
@@ -1390,6 +1393,8 @@ pub const Bundler = struct {
// @bun annotation
opts.features.dont_bundle_twice = this_parse.dont_bundle_twice;
+ opts.features.commonjs_at_runtime = this_parse.allow_commonjs;
+
opts.can_import_from_bundle = bundler.options.node_modules_bundle != null;
opts.tree_shaking = bundler.options.tree_shaking;