-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): not exit when one plugin installation failed
- Loading branch information
Showing
8 changed files
with
511 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
packages/nx/src/command-line/import/utils/configure-plugins.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { bold } from 'chalk'; | ||
import { | ||
checkCompatibleWithPlugins, | ||
updatePluginsInNxJson, | ||
} from './check-compatible-with-plugins'; | ||
import { output } from '../../../utils/output'; | ||
import { PackageManagerCommands } from '../../../utils/package-manager'; | ||
import { GitRepository } from '../../../utils/git-utils'; | ||
import { installPlugins } from '../../init/init-v2'; | ||
|
||
/** | ||
* Configures plugins | ||
* @param repoRoot | ||
* @param plugins | ||
* @param updatePackageScripts | ||
* @param verbose | ||
* @returns | ||
*/ | ||
export async function configurePlugins( | ||
repoRoot: string, | ||
plugins: string[], | ||
updatePackageScripts: boolean, | ||
pmc: PackageManagerCommands, | ||
destinationGitClient: GitRepository, | ||
verbose: boolean = false | ||
): Promise<{ | ||
succeededPlugins: string[]; | ||
failedPlugins: { [plugin: string]: Error }; | ||
incompatiblePlugins: { [plugin: string]: Set<string> }; | ||
}> { | ||
if (plugins.length === 0) { | ||
return; | ||
} | ||
|
||
let { succeededPlugins, failedPlugins } = await installPlugins( | ||
repoRoot, | ||
plugins, | ||
updatePackageScripts, | ||
verbose | ||
); | ||
|
||
let incompatiblePlugins: { [plugin: string]: Set<string> } = {}; | ||
if (succeededPlugins.length > 0) { | ||
destinationGitClient.amendCommit(); | ||
incompatiblePlugins = await checkCompatibleWithPlugins( | ||
succeededPlugins.map((plugin) => plugin + '/plugin'), // succeededPlugins are the package names, but we need the plugin names | ||
repoRoot | ||
); | ||
if (Object.keys(incompatiblePlugins).length > 0) { | ||
// Remove incompatible plugins from the list of succeeded plugins | ||
succeededPlugins = succeededPlugins.filter( | ||
(plugin) => !incompatiblePlugins[plugin + '/plugin'] | ||
); | ||
if (succeededPlugins.length > 0) { | ||
output.success({ | ||
title: 'Installed Plugins', | ||
bodyLines: succeededPlugins.map((p) => `- ${bold(p)}`), | ||
}); | ||
} | ||
updatePluginsInNxJson(repoRoot, incompatiblePlugins); | ||
destinationGitClient.amendCommit(); | ||
output.warn({ | ||
title: `Imcompatible plugins found`, | ||
bodyLines: [ | ||
'The following plugins were not compatible:', | ||
...Object.keys(incompatiblePlugins).map((p) => `- ${bold(p)}`), | ||
`Please review the files and remove them from the exclude list if they are compatible with the plugin.`, | ||
], | ||
}); | ||
|
||
Object.entries(incompatiblePlugins).forEach( | ||
([pluginName, excludeFiles]) => { | ||
if (excludeFiles.size === 0) { | ||
return; | ||
} | ||
output.warn({ | ||
title: `Incompatible files found for ${pluginName}`, | ||
bodyLines: [ | ||
`Added the following files to the exclude list for ${pluginName}:`, | ||
...Array.from(excludeFiles).map((file) => ` - ${bold(file)}`), | ||
], | ||
}); | ||
} | ||
); | ||
} | ||
} | ||
if (Object.keys(failedPlugins).length > 0) { | ||
output.error({ | ||
title: `Failed to install plugins`, | ||
bodyLines: [ | ||
'The following plugins were not installed:', | ||
...Object.keys(failedPlugins).map((p) => `- ${bold(p)}`), | ||
], | ||
}); | ||
Object.entries(failedPlugins).forEach(([plugin, error]) => { | ||
output.error({ | ||
title: `Failed to install ${plugin}`, | ||
bodyLines: [error.stack ?? error.message ?? error.toString()], | ||
}); | ||
}); | ||
output.error({ | ||
title: `To install the plugins manually`, | ||
bodyLines: [ | ||
'You may need to run commands to install the plugins:', | ||
...Object.keys(failedPlugins).map( | ||
(p) => `- ${bold(pmc.exec + ' nx add ' + p)}` | ||
), | ||
], | ||
}); | ||
} | ||
return { succeededPlugins, failedPlugins, incompatiblePlugins }; | ||
} |
3 changes: 1 addition & 2 deletions
3
packages/nx/src/command-line/import/utils/prepare-source-repo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.