feat: add support --conditions flag (#9106)

* feat(options): add possibility to append a custom esm condition

* feat(cli): parse --conditions flag

* test: add case for custom conditions

* fix(cli): not get short-hand --conditions flag

* test: add case using cjs with custom condition

* fix(options): address possible memory issues for esm conditions

* refactor(cli): remove -c alias for --conditions flag

* test: add cases for multiple --conditions specified

* test(bundler): add support to test --conditions

* chore(cli): fix grammar mistakes in --conditions

---------

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
This commit is contained in:
Igor Wessel
2024-03-01 23:57:45 -03:00
committed by GitHub
parent 3134ae1ada
commit dcf6f244a4
7 changed files with 180 additions and 2 deletions

View File

@@ -182,6 +182,7 @@ pub const Arguments = struct {
clap.parseParam("--prefer-latest Use the latest matching versions of packages in the Bun runtime, always checking npm") catch unreachable,
clap.parseParam("-p, --port <STR> Set the default port for Bun.serve") catch unreachable,
clap.parseParam("-u, --origin <STR>") catch unreachable,
clap.parseParam("--conditions <STR>... Pass custom conditions to resolve") catch unreachable,
};
const auto_only_params = [_]ParamType{
@@ -229,6 +230,7 @@ pub const Arguments = struct {
clap.parseParam("--minify-whitespace Minify whitespace") catch unreachable,
clap.parseParam("--minify-identifiers Minify identifiers") catch unreachable,
clap.parseParam("--dump-environment-variables") catch unreachable,
clap.parseParam("--conditions <STR>... Pass custom conditions to resolve") catch unreachable,
};
pub const build_params = build_only_params ++ transpiler_params_ ++ base_params_;
@@ -516,6 +518,12 @@ pub const Arguments = struct {
ctx.passthrough = args.remaining();
if (cmd == .AutoCommand or cmd == .RunCommand or cmd == .BuildCommand) {
if (args.options("--conditions").len > 0) {
opts.conditions = args.options("--conditions");
}
}
// runtime commands
if (cmd == .AutoCommand or cmd == .RunCommand or cmd == .TestCommand or cmd == .RunAsNodeCommand) {
const preloads = args.options("--preload");