aboutsummaryrefslogtreecommitdiff
path: root/src/cli.zig
diff options
context:
space:
mode:
authorGravatar dave caruso <me@paperdave.net> 2023-05-09 00:55:21 -0400
committerGravatar GitHub <noreply@github.com> 2023-05-08 21:55:21 -0700
commit5e366872f659abf116b903e5cece999a04cd018b (patch)
treed06b5ccd28ea49a7a5e050868ff27e676e0d56f7 /src/cli.zig
parent1a411e201b71374f515d1f6cdbb1b36186ee48b0 (diff)
downloadbun-5e366872f659abf116b903e5cece999a04cd018b.tar.gz
bun-5e366872f659abf116b903e5cece999a04cd018b.tar.zst
bun-5e366872f659abf116b903e5cece999a04cd018b.zip
implement build api `define` and `loaders` (#2805)
* parse error logs * clean up types * remove --jsx-production. use NODE_ENV instead * add define to js api * add loaders to js api * fixups * sourcemap * typo fix * remove label, comment dir just for now * test tweaks * test work * make optional enums actually optional. allows `sourcemap: undefined` * overload host ram test * string tests * tests * test for 2815 * requested changes * sort this list * remove this test file now that it passes * oops * add --format * finish ts tests * doc typos related to define and loader
Diffstat (limited to 'src/cli.zig')
-rw-r--r--src/cli.zig25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/cli.zig b/src/cli.zig
index 3f796e798..171593246 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -141,7 +141,6 @@ pub const Arguments = struct {
clap.parseParam("--jsx-factory <STR> Changes the function called when compiling JSX elements using the classic JSX runtime") catch unreachable,
clap.parseParam("--jsx-fragment <STR> Changes the function called when compiling JSX fragments") catch unreachable,
clap.parseParam("--jsx-import-source <STR> Declares the module specifier to be used for importing the jsx and jsxs factory functions. Default: \"react\"") catch unreachable,
- clap.parseParam("--jsx-production Use jsx instead of jsxDEV (default) for the automatic runtime") catch unreachable,
clap.parseParam("--jsx-runtime <STR> \"automatic\" (default) or \"classic\"") catch unreachable,
clap.parseParam("-r, --preload <STR>... Import a module before other modules are loaded") catch unreachable,
clap.parseParam("--main-fields <STR>... Main fields to lookup in package.json. Defaults to --target dependent") catch unreachable,
@@ -194,6 +193,7 @@ pub const Arguments = struct {
pub const params = public_params ++ debug_params;
const build_only_params = [_]ParamType{
+ clap.parseParam("--format <STR> Specifies the module format to build to. Only esm is supported.") catch unreachable,
clap.parseParam("--outdir <STR> Default to \"dist\" if multiple files") catch unreachable,
clap.parseParam("--outfile <STR> Write to a file") catch unreachable,
clap.parseParam("--splitting Enable code splitting") catch unreachable,
@@ -489,6 +489,20 @@ pub const Arguments = struct {
}
}
+ if (args.option("--format")) |format_str| {
+ const format = options.Format.fromString(format_str) orelse {
+ Output.prettyErrorln("<r><red>error<r>: Invalid format - must be esm, cjs, or iife", .{});
+ Global.crash();
+ };
+ switch (format) {
+ .esm => {},
+ else => {
+ Output.prettyErrorln("<r><red>error<r>: Formats besides 'esm' are not implemented", .{});
+ Global.crash();
+ },
+ }
+ }
+
if (args.flag("--splitting")) {
ctx.bundler_options.code_splitting = true;
}
@@ -569,9 +583,8 @@ pub const Arguments = struct {
var jsx_fragment = args.option("--jsx-fragment");
var jsx_import_source = args.option("--jsx-import-source");
var jsx_runtime = args.option("--jsx-runtime");
- var jsx_production = args.flag("--jsx-production");
const react_fast_refresh = switch (comptime cmd) {
- .DevCommand => !(args.flag("--disable-react-fast-refresh") or jsx_production),
+ .DevCommand => !args.flag("--disable-react-fast-refresh"),
else => true,
};
@@ -689,7 +702,7 @@ pub const Arguments = struct {
jsx_fragment != null or
jsx_import_source != null or
jsx_runtime != null or
- jsx_production or !react_fast_refresh)
+ !react_fast_refresh)
{
var default_factory = "".*;
var default_fragment = "".*;
@@ -700,7 +713,7 @@ pub const Arguments = struct {
.fragment = constStrToU8(jsx_fragment orelse &default_fragment),
.import_source = constStrToU8(jsx_import_source orelse &default_import_source),
.runtime = if (jsx_runtime != null) try resolve_jsx_runtime(jsx_runtime.?) else Api.JsxRuntime.automatic,
- .development = !jsx_production,
+ .development = false,
.react_fast_refresh = react_fast_refresh,
};
} else {
@@ -709,7 +722,7 @@ pub const Arguments = struct {
.fragment = constStrToU8(jsx_fragment orelse opts.jsx.?.fragment),
.import_source = constStrToU8(jsx_import_source orelse opts.jsx.?.import_source),
.runtime = if (jsx_runtime != null) try resolve_jsx_runtime(jsx_runtime.?) else opts.jsx.?.runtime,
- .development = !jsx_production,
+ .development = false,
.react_fast_refresh = react_fast_refresh,
};
}