Skip to content

Commit cc9e993

Browse files
authored
fix(core): only add keep existing versions if init generator supports it (#30352)
<!-- 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 --> Nx plugins which do not support `keepExistingPackages` fail to initialize via `nx init` or `nx add` ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Nx plugins which do not support `keepExistingPackages` initializes properly via `nx init` and `nx add` ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
1 parent 77c1dda commit cc9e993

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,28 @@ export async function installPlugin(
4747
pmc: PackageManagerCommands = getPackageManagerCommand()
4848
): Promise<void> {
4949
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-
}
50+
const { schema } = getGeneratorInformation(
51+
plugin,
52+
'init',
53+
workspaceRoot,
54+
{}
6055
);
56+
57+
let command = `${pmc.exec} nx g ${plugin}:init ${
58+
verbose ? '--verbose' : ''
59+
}`;
60+
61+
if (!!schema.properties['keepExistingVersions']) {
62+
command += ` --keepExistingVersions`;
63+
}
64+
if (updatePackageScripts && !!schema.properties['updatePackageScripts']) {
65+
command += ` --updatePackageScripts`;
66+
}
67+
execSync(command, {
68+
stdio: [0, 1, 2],
69+
cwd: repoRoot,
70+
windowsHide: false,
71+
});
6172
} catch {
6273
// init generator does not exist, so this function should noop
6374
output.log({

0 commit comments

Comments
 (0)