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 #
This commit is contained in:
parent
5b034965d8
commit
121d9973a8
@ -10,13 +10,13 @@ import { output } from '../../utils/output';
|
|||||||
import { GeneratorsJsonEntry } from '../../config/misc-interfaces';
|
import { GeneratorsJsonEntry } from '../../config/misc-interfaces';
|
||||||
import { workspaceRoot } from '../../utils/workspace-root';
|
import { workspaceRoot } from '../../utils/workspace-root';
|
||||||
import { addDepsToPackageJson, runInstall } from './implementation/utils';
|
import { addDepsToPackageJson, runInstall } from './implementation/utils';
|
||||||
import { getPluginCapabilities } from '../../utils/plugins';
|
|
||||||
import { isAngularPluginInstalled } from '../../adapter/angular-json';
|
import { isAngularPluginInstalled } from '../../adapter/angular-json';
|
||||||
import {
|
import {
|
||||||
isAggregateCreateNodesError,
|
isAggregateCreateNodesError,
|
||||||
isProjectConfigurationsError,
|
isProjectConfigurationsError,
|
||||||
isProjectsWithNoNameError,
|
isProjectsWithNoNameError,
|
||||||
} from '../../project-graph/error-types';
|
} from '../../project-graph/error-types';
|
||||||
|
import { getGeneratorInformation } from '../generate/generator-utils';
|
||||||
|
|
||||||
export function runPackageManagerInstallPlugins(
|
export function runPackageManagerInstallPlugins(
|
||||||
repoRoot: string,
|
repoRoot: string,
|
||||||
@ -46,29 +46,25 @@ export async function installPlugin(
|
|||||||
verbose: boolean = false,
|
verbose: boolean = false,
|
||||||
pmc: PackageManagerCommands = getPackageManagerCommand()
|
pmc: PackageManagerCommands = getPackageManagerCommand()
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const capabilities = await getPluginCapabilities(repoRoot, plugin, {});
|
try {
|
||||||
const generators = capabilities?.generators;
|
getGeneratorInformation(plugin, 'init', workspaceRoot, {});
|
||||||
if (!generators) {
|
execSync(
|
||||||
throw new Error(`No generators found in ${plugin}.`);
|
`${pmc.exec} nx g ${plugin}:init --keepExistingVersions ${
|
||||||
}
|
updatePackageScripts ? '--updatePackageScripts' : ''
|
||||||
|
} ${verbose ? '--verbose' : ''}`,
|
||||||
const initGenerator = findInitGenerator(generators);
|
{
|
||||||
if (!initGenerator) {
|
stdio: [0, 1, 2],
|
||||||
|
cwd: repoRoot,
|
||||||
|
windowsHide: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
// init generator does not exist, so this function should noop
|
||||||
output.log({
|
output.log({
|
||||||
title: `No "init" generator found in ${plugin}. Skipping initialization.`,
|
title: `No "init" generator found in ${plugin}. Skipping initialization.`,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
execSync(
|
|
||||||
`${pmc.exec} nx g ${plugin}:init --keepExistingVersions ${
|
|
||||||
updatePackageScripts ? '--updatePackageScripts' : ''
|
|
||||||
} ${verbose ? '--verbose' : ''}`,
|
|
||||||
{
|
|
||||||
stdio: [0, 1, 2],
|
|
||||||
cwd: repoRoot,
|
|
||||||
windowsHide: false,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user