Skip to content

Commit 121d997

Browse files
authored
fix(core): run init generators from extended collections during nx add (#30280)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- 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 --> When the `init` generator is in an extended collection, `nx add` will not run it. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> When the `init` generator is in an extended collection, `nx add` will run it. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
1 parent 5b03496 commit 121d997

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

packages/nx/src/command-line/init/configure-plugins.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import { output } from '../../utils/output';
1010
import { GeneratorsJsonEntry } from '../../config/misc-interfaces';
1111
import { workspaceRoot } from '../../utils/workspace-root';
1212
import { addDepsToPackageJson, runInstall } from './implementation/utils';
13-
import { getPluginCapabilities } from '../../utils/plugins';
1413
import { isAngularPluginInstalled } from '../../adapter/angular-json';
1514
import {
1615
isAggregateCreateNodesError,
1716
isProjectConfigurationsError,
1817
isProjectsWithNoNameError,
1918
} from '../../project-graph/error-types';
19+
import { getGeneratorInformation } from '../generate/generator-utils';
2020

2121
export function runPackageManagerInstallPlugins(
2222
repoRoot: string,
@@ -46,29 +46,25 @@ export async function installPlugin(
4646
verbose: boolean = false,
4747
pmc: PackageManagerCommands = getPackageManagerCommand()
4848
): Promise<void> {
49-
const capabilities = await getPluginCapabilities(repoRoot, plugin, {});
50-
const generators = capabilities?.generators;
51-
if (!generators) {
52-
throw new Error(`No generators found in ${plugin}.`);
53-
}
54-
55-
const initGenerator = findInitGenerator(generators);
56-
if (!initGenerator) {
49+
try {
50+
getGeneratorInformation(plugin, 'init', workspaceRoot, {});
51+
execSync(
52+
`${pmc.exec} nx g ${plugin}:init --keepExistingVersions ${
53+
updatePackageScripts ? '--updatePackageScripts' : ''
54+
} ${verbose ? '--verbose' : ''}`,
55+
{
56+
stdio: [0, 1, 2],
57+
cwd: repoRoot,
58+
windowsHide: false,
59+
}
60+
);
61+
} catch {
62+
// init generator does not exist, so this function should noop
5763
output.log({
5864
title: `No "init" generator found in ${plugin}. Skipping initialization.`,
5965
});
6066
return;
6167
}
62-
execSync(
63-
`${pmc.exec} nx g ${plugin}:init --keepExistingVersions ${
64-
updatePackageScripts ? '--updatePackageScripts' : ''
65-
} ${verbose ? '--verbose' : ''}`,
66-
{
67-
stdio: [0, 1, 2],
68-
cwd: repoRoot,
69-
windowsHide: false,
70-
}
71-
);
7268
}
7369

7470
/**

0 commit comments

Comments
 (0)