aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-01 22:16:09 -0800
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-01 22:16:09 -0800
commit2ccb063d206cf26037db4df42f813e207fe9ca13 (patch)
tree576a6903bfe3c0eb962836cd19fba6f3d48e1b88
parent710303be7ae12302193be3ce90da2eec61f4203e (diff)
downloadbun-2ccb063d206cf26037db4df42f813e207fe9ca13.tar.gz
bun-2ccb063d206cf26037db4df42f813e207fe9ca13.tar.zst
bun-2ccb063d206cf26037db4df42f813e207fe9ca13.zip
[bun.js] Allow disabling runtime imports so bun can build for node
-rw-r--r--src/js_parser/js_parser.zig7
-rw-r--r--src/options.zig5
-rw-r--r--src/runtime.zig4
3 files changed, 11 insertions, 5 deletions
diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig
index 236e3b0a5..358ae165a 100644
--- a/src/js_parser/js_parser.zig
+++ b/src/js_parser/js_parser.zig
@@ -2742,7 +2742,10 @@ pub const Parser = struct {
// - don't import runtime if we're bundling, it's already included
// - when HMR is enabled, we always need to import the runtime for HMRClient and HMRModule.
// - when HMR is not enabled, we only need any runtime imports if we're importing require()
- if (!p.options.enable_bundling and (p.has_called_runtime or p.options.features.hot_module_reloading or has_cjs_imports)) {
+ if (p.options.features.allow_runtime and
+ !p.options.enable_bundling and
+ (p.has_called_runtime or p.options.features.hot_module_reloading or has_cjs_imports))
+ {
const before_start = before.items.len;
if (p.options.features.hot_module_reloading) p.resolveHMRSymbols();
@@ -15928,7 +15931,7 @@ fn NewParser_(
logger.Loc.Empty,
);
part.stmts = new_stmts_list;
- } else if (p.options.features.hot_module_reloading) {
+ } else if (p.options.features.hot_module_reloading and p.options.features.allow_runtime) {
var named_exports_count: usize = p.named_exports.count();
const named_imports: js_ast.Ast.NamedImports = p.named_imports;
diff --git a/src/options.zig b/src/options.zig
index aea7d13d1..c0808d96e 100644
--- a/src/options.zig
+++ b/src/options.zig
@@ -25,7 +25,7 @@ const default_allocator = _global.default_allocator;
const C = _global.C;
const StoredFileDescriptorType = _global.StoredFileDescriptorType;
const JSC = @import("javascript_core");
-
+const Runtime = @import("./runtime.zig").Runtime;
const Analytics = @import("./analytics/analytics_thread.zig");
const MacroRemap = @import("./resolver/package_json.zig").MacroMap;
const DotEnv = @import("./env_loader.zig");
@@ -1087,6 +1087,8 @@ pub const BundleOptions = struct {
loaders: std.StringHashMap(Loader),
resolve_dir: string = "/",
jsx: JSX.Pragma = JSX.Pragma{},
+ auto_import_jsx: bool = true,
+ allow_runtime: bool = true,
hot_module_reloading: bool = false,
inject: ?[]string = null,
@@ -1285,6 +1287,7 @@ pub const BundleOptions = struct {
switch (opts.platform) {
.node => {
opts.import_path_format = .relative_nodejs;
+ opts.allow_runtime = false;
},
.bun => {
// If we're doing SSR, we want all the URLs to be the same as what it would be in the browser
diff --git a/src/runtime.zig b/src/runtime.zig
index 627615799..32f45ffad 100644
--- a/src/runtime.zig
+++ b/src/runtime.zig
@@ -240,10 +240,10 @@ pub const Runtime = struct {
pub const Features = struct {
react_fast_refresh: bool = false,
hot_module_reloading: bool = false,
- hot_module_reloading_entry: bool = false,
- keep_names_for_arrow_functions: bool = true,
is_macro_runtime: bool = false,
top_level_await: bool = false,
+ auto_import_jsx: bool = false,
+ allow_runtime: bool = true,
};
pub const Names = struct {