fix(core): change to use init generator during import (#30029)
<!-- 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 --> - call init generator using implementationFactory, causing issue because schema.json file isnt respected, and then NX_INTERACTIVE is never set to true ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> - change back to run init command ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
3c0820f707
commit
ef08108f7a
@ -85,6 +85,9 @@ exports[`Webpack Plugin (legacy) ConvertConfigToWebpackPlugin, should convert wi
|
||||
}
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nx/eslint:lint"
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nx/vite:test",
|
||||
"outputs": ["{options.reportsDirectory}"],
|
||||
@ -92,9 +95,6 @@ exports[`Webpack Plugin (legacy) ConvertConfigToWebpackPlugin, should convert wi
|
||||
"reportsDirectory": "../coverage/app3224373"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nx/eslint:lint"
|
||||
},
|
||||
"serve-static": {
|
||||
"executor": "@nx/web:file-server",
|
||||
"dependsOn": ["build"],
|
||||
|
||||
@ -111,29 +111,15 @@ async function initializePlugin(
|
||||
options: AddOptions,
|
||||
nxJson: NxJsonConfiguration
|
||||
): Promise<void> {
|
||||
const parsedCommandArgs: { [key: string]: any } = yargsParser(
|
||||
options.__overrides_unparsed__,
|
||||
{
|
||||
configuration: {
|
||||
'parse-numbers': false,
|
||||
'parse-positional-numbers': false,
|
||||
'dot-notation': false,
|
||||
'camel-case-expansion': false,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (coreNxPluginVersions.has(pkgName)) {
|
||||
parsedCommandArgs.keepExistingVersions = true;
|
||||
|
||||
if (
|
||||
options.updatePackageScripts ||
|
||||
let updatePackageScripts = false;
|
||||
if (
|
||||
coreNxPluginVersions.has(pkgName) &&
|
||||
(options.updatePackageScripts ||
|
||||
(options.updatePackageScripts === undefined &&
|
||||
nxJson.useInferencePlugins !== false &&
|
||||
process.env.NX_ADD_PLUGINS !== 'false')
|
||||
) {
|
||||
parsedCommandArgs.updatePackageScripts = true;
|
||||
}
|
||||
process.env.NX_ADD_PLUGINS !== 'false'))
|
||||
) {
|
||||
updatePackageScripts = true;
|
||||
}
|
||||
|
||||
const spinner = ora(`Initializing ${pkgName}...`);
|
||||
@ -143,8 +129,8 @@ async function initializePlugin(
|
||||
await installPlugin(
|
||||
pkgName,
|
||||
workspaceRoot,
|
||||
options.verbose,
|
||||
parsedCommandArgs
|
||||
updatePackageScripts,
|
||||
options.verbose
|
||||
);
|
||||
} catch (e) {
|
||||
spinner.fail();
|
||||
|
||||
@ -1,19 +1,13 @@
|
||||
import * as createSpinner from 'ora';
|
||||
import { bold } from 'chalk';
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
import {
|
||||
getPackageManagerCommand,
|
||||
PackageManagerCommands,
|
||||
} from '../../utils/package-manager';
|
||||
import { GitRepository } from '../../utils/git-utils';
|
||||
import { output } from '../../utils/output';
|
||||
import { flushChanges, FsTree } from '../../generators/tree';
|
||||
import {
|
||||
Generator as NxGenerator,
|
||||
GeneratorCallback,
|
||||
GeneratorsJsonEntry,
|
||||
} from '../../config/misc-interfaces';
|
||||
import { getGeneratorInformation } from '../generate/generator-utils';
|
||||
import { GeneratorsJsonEntry } from '../../config/misc-interfaces';
|
||||
import { workspaceRoot } from '../../utils/workspace-root';
|
||||
import { addDepsToPackageJson, runInstall } from './implementation/utils';
|
||||
import { getPluginCapabilities } from '../../utils/plugins';
|
||||
@ -40,17 +34,18 @@ export function runPackageManagerInstallPlugins(
|
||||
* Installs a plugin by running its init generator. It will change the file system tree passed in.
|
||||
* @param plugin The name of the plugin to install
|
||||
* @param repoRoot repo root
|
||||
* @param verbose verbose
|
||||
* @param options options passed to init generator
|
||||
* @param pmc package manager commands
|
||||
* @param updatePackageScripts whether to update package scripts
|
||||
* @param verbose whether to run in verbose mode
|
||||
* @returns void
|
||||
*/
|
||||
export async function installPlugin(
|
||||
plugin: string,
|
||||
repoRoot: string = workspaceRoot,
|
||||
updatePackageScripts: boolean = false,
|
||||
verbose: boolean = false,
|
||||
options: { [k: string]: any }
|
||||
pmc: PackageManagerCommands = getPackageManagerCommand()
|
||||
): Promise<void> {
|
||||
const host = new FsTree(repoRoot, verbose, `install ${plugin}`);
|
||||
const capabilities = await getPluginCapabilities(repoRoot, plugin, {});
|
||||
const generators = capabilities?.generators;
|
||||
if (!generators) {
|
||||
@ -64,19 +59,16 @@ export async function installPlugin(
|
||||
});
|
||||
return;
|
||||
}
|
||||
const { implementationFactory } = getGeneratorInformation(
|
||||
plugin,
|
||||
initGenerator,
|
||||
repoRoot,
|
||||
{}
|
||||
execSync(
|
||||
`${pmc.exec} nx g ${plugin}:init --keepExistingVersions ${
|
||||
updatePackageScripts ? '--updatePackageScripts' : ''
|
||||
} ${verbose ? '--verbose' : ''}`,
|
||||
{
|
||||
stdio: [0, 1, 2],
|
||||
cwd: repoRoot,
|
||||
windowsHide: false,
|
||||
}
|
||||
);
|
||||
|
||||
const implementation: NxGenerator = implementationFactory();
|
||||
const task: GeneratorCallback | void = await implementation(host, options);
|
||||
flushChanges(repoRoot, host.listChanges());
|
||||
if (task) {
|
||||
await task();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,6 +79,7 @@ export async function installPlugin(
|
||||
export async function installPlugins(
|
||||
plugins: string[],
|
||||
updatePackageScripts: boolean,
|
||||
pmc: PackageManagerCommands,
|
||||
repoRoot: string = workspaceRoot,
|
||||
verbose: boolean = false
|
||||
): Promise<{
|
||||
@ -108,13 +101,7 @@ export async function installPlugins(
|
||||
for (const plugin of plugins) {
|
||||
try {
|
||||
spinner.start('Installing plugin ' + plugin);
|
||||
await installPlugin(plugin, repoRoot, verbose, {
|
||||
keepExistingVersions: true,
|
||||
updatePackageScripts,
|
||||
addPlugin: true,
|
||||
skipFormat: false,
|
||||
skipPackageJson: false,
|
||||
});
|
||||
await installPlugin(plugin, repoRoot, updatePackageScripts, verbose, pmc);
|
||||
succeededPlugins.push(plugin);
|
||||
spinner.succeed('Installed plugin ' + plugin);
|
||||
} catch (e) {
|
||||
@ -154,6 +141,7 @@ export async function configurePlugins(
|
||||
let { succeededPlugins, failedPlugins } = await installPlugins(
|
||||
plugins,
|
||||
updatePackageScripts,
|
||||
pmc,
|
||||
repoRoot,
|
||||
verbose
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user