Skip to content

Commit

Permalink
cli: add -C alias for --conditions flag
Browse files Browse the repository at this point in the history
PR-URL: #38755
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
  • Loading branch information
guybedford authored and danielleadams committed May 31, 2021
1 parent 80c32b7 commit bc84001
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
13 changes: 10 additions & 3 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ $ node --completion-bash > node_bash_completion
$ source node_bash_completion
```

### `--conditions=condition`
### `-C=condition`, `--conditions=condition`
<!-- YAML
added:
- v14.9.0
Expand All @@ -89,14 +89,20 @@ added:

> Stability: 1 - Experimental
Enable experimental support for custom conditional exports resolution
Enable experimental support for custom [conditional exports][] resolution
conditions.

Any number of custom string condition names are permitted.

The default Node.js conditions of `"node"`, `"default"`, `"import"`, and
`"require"` will always apply as defined.

For example, to run a module with "development" resolutions:

```console
$ node -C=development app.js
```

### `--cpu-prof`
<!-- YAML
added: v12.0.0
Expand Down Expand Up @@ -1368,7 +1374,7 @@ node --require "./a.js" --require "./b.js"

Node.js options that are allowed are:
<!-- node-options-node start -->
* `--conditions`
* `--conditions`, `-C`
* `--diagnostic-dir`
* `--disable-proto`
* `--enable-fips`
Expand Down Expand Up @@ -1764,6 +1770,7 @@ $ node --max-old-space-size=1536 index.js
[`tls.DEFAULT_MIN_VERSION`]: tls.md#tls_tls_default_min_version
[`unhandledRejection`]: process.md#process_event_unhandledrejection
[`worker_threads.threadId`]: worker_threads.md#worker_threads_worker_threadid
[conditional exports]: packages.md#packages_conditional_exports
[context-aware]: addons.md#addons_context_aware_addons
[customizing ESM specifier resolution]: esm.md#esm_customizing_esm_specifier_resolution_algorithm
[debugger]: debugger.md
Expand Down
2 changes: 1 addition & 1 deletion doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Aborting instead of exiting causes a core file to be generated for analysis.
.It Fl -completion-bash
Print source-able bash completion script for Node.js.
.
.It Fl -conditions Ar string
.It Fl C , Fl -conditions Ar string
Use custom conditional exports conditions.
.Ar string
.
Expand Down
1 change: 1 addition & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"additional user conditions for conditional exports and imports",
&EnvironmentOptions::conditions,
kAllowedInEnvironment);
AddAlias("-C", "--conditions");
AddOption("--diagnostic-dir",
"set dir for all output files"
" (default: current working directory)",
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-custom-exports.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --conditions=custom-condition --conditions another
// Flags: --conditions=custom-condition -C another
import { mustCall } from '../common/index.mjs';
import { strictEqual } from 'assert';
import { requireFixture, importFixture } from '../fixtures/pkgexports.mjs';
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-process-env-allowed-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const assert = require('assert');
// Assert all "canonical" flags begin with dash(es)
{
process.allowedNodeEnvironmentFlags.forEach((flag) => {
assert(/^--?[a-z0-9._-]+$/.test(flag),
assert(/^--?[a-zA-Z0-9._-]+$/.test(flag),
`Unexpected format for flag ${flag}`);
});
}
Expand Down

0 comments on commit bc84001

Please sign in to comment.