Skip to content

Commit

Permalink
feat(core): add interactive env var (#14994)
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Feb 16, 2023
1 parent 497a90e commit 40deb00
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/shared/reference/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
| NX_SKIP_NX_CACHE | boolean | Rerun the tasks even when the results are available in the cache |
| NX_TASKS_RUNNER_DYNAMIC_OUTPUT | boolean | If set to `false`, will use non-dynamic terminal output strategy (what you see in CI), even when you terminal can support the dynamic version |
| NX_VERBOSE_LOGGING | boolean | If set to `true`, will print debug information useful for troubleshooting |
| NX_DRY_RUN | boolean | If set to `true`, will perform a dry run of the generator. No files will be created and no packages will be installed. |
| NX_INTERACTIVE | boolean | If set to `true`, will allow Nx to prompt you in the terminal to answer some further questions when running generators. |
3 changes: 2 additions & 1 deletion packages/devkit/src/utils/package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ export async function ensurePackage(
): Promise<void> {
// Read package and version from root package.json file.
const dev = options.dev ?? true;
const throwOnMissing = options.throwOnMissing ?? !!process.env.NX_DRY_RUN; // NX_DRY_RUN is set in `packages/nx/src/command-line/generate.ts`
const throwOnMissing =
options.throwOnMissing ?? process.env.NX_DRY_RUN === 'true'; // NX_DRY_RUN is set in `packages/nx/src/command-line/nx-commands.ts`
const pmc = getPackageManagerCommand();

let version = getPackageVersion(pkg);
Expand Down
4 changes: 1 addition & 3 deletions packages/nx/src/command-line/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,7 @@ export async function generate(cwd: string, args: { [k: string]: any }) {
'generate',
projectsConfigurations
);
if (opts.dryRun) {
process.env.NX_DRY_RUN = 'true';
}

const {
normalizedGeneratorName,
schema,
Expand Down
13 changes: 13 additions & 0 deletions packages/nx/src/command-line/nx-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const commandsObject = yargs
handler: async (args) => {
// Remove the command from the args
args._ = args._.slice(1);

process.exit(
await (await import('./generate')).generate(process.cwd(), args)
);
Expand Down Expand Up @@ -732,6 +733,18 @@ function withGenerateOptions(yargs: yargs.Argv) {
'Prints additional information about the commands (e.g., stack traces)',
type: 'boolean',
default: false,
})
.middleware((args) => {
if (process.env.NX_INTERACTIVE !== 'false') {
args.interactive = true;
} else {
process.env.NX_INTERACTIVE = `${args.interactive}`;
}
if (process.env.NX_DRY_RUN === 'true') {
args.dryRun = true;
} else {
process.env.NX_DRY_RUN = `${args.dryRun}`;
}
});

if (generatorWillShowHelp) {
Expand Down

1 comment on commit 40deb00

@vercel
Copy link

@vercel vercel bot commented on 40deb00 Feb 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev

Please sign in to comment.