Skip to content

Commit

Permalink
fix(misc): respect useInferencePlugin in nx.json when generating apps…
Browse files Browse the repository at this point in the history
… and libs (#26703)

The `@nx/vue:app` and `@nx/vue:lib` generators do not respect
`useInferencePlugins` set in `nx.json`. This PR fixes the generators.
Same for `@nx/rollup:init`.
<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
  • Loading branch information
jaysoo committed Jun 28, 2024
1 parent fdd89a6 commit e292500
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/rollup/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
createProjectGraphAsync,
formatFiles,
GeneratorCallback,
readNxJson,
Tree,
} from '@nx/devkit';
import { nxVersion, rollupVersion } from '../../utils/versions';
Expand All @@ -12,7 +13,10 @@ import { createNodes } from '../../plugins/plugin';

export async function rollupInitGenerator(tree: Tree, schema: Schema) {
let task: GeneratorCallback = () => {};
schema.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
const nxJson = readNxJson(tree);
schema.addPlugin ??=
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;

if (!schema.skipPackageJson) {
const devDependencies = { '@nx/rollup': nxVersion };
Expand Down
7 changes: 6 additions & 1 deletion packages/vue/src/generators/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
addProjectConfiguration,
formatFiles,
GeneratorCallback,
readNxJson,
runTasksInSerial,
toJS,
Tree,
Expand All @@ -28,7 +29,11 @@ export async function applicationGeneratorInternal(
_options: Schema
): Promise<GeneratorCallback> {
const options = await normalizeOptions(tree, _options);
options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
const nxJson = readNxJson(tree);

options.addPlugin ??=
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;

const tasks: GeneratorCallback[] = [];

Expand Down
15 changes: 13 additions & 2 deletions packages/vue/src/generators/library/lib/normalize-options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { getProjects, logger, normalizePath, Tree } from '@nx/devkit';
import {
getProjects,
logger,
normalizePath,
readNxJson,
Tree,
} from '@nx/devkit';
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { NormalizedSchema, Schema } from '../schema';

Expand Down Expand Up @@ -36,9 +42,14 @@ export async function normalizeOptions(
bundler = 'vite';
}
}
const nxJson = readNxJson(host);

const addPlugin =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;

const normalized = {
addPlugin: process.env.NX_ADD_PLUGINS !== 'false',
addPlugin,
...options,
bundler,
fileName,
Expand Down

0 comments on commit e292500

Please sign in to comment.