fix(nx-plugin): generated root plugin should not have wonky paths (#16445)

This commit is contained in:
Craigory Coppola 2023-04-21 13:25:22 -04:00 committed by GitHub
parent a908ef586a
commit 219ad67e74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 12 deletions

View File

@ -32,7 +32,10 @@ describe('create-nx-plugin', () => {
runCLI(`build ${pluginName}`); runCLI(`build ${pluginName}`);
checkFilesExist(`dist/package.json`, `dist/src/index.js`); checkFilesExist(
`dist/${pluginName}/package.json`,
`dist/${pluginName}/src/index.js`
);
runCLI( runCLI(
`generate @nrwl/nx-plugin:generator ${generatorName} --project=${pluginName}` `generate @nrwl/nx-plugin:generator ${generatorName} --project=${pluginName}`
@ -44,9 +47,9 @@ describe('create-nx-plugin', () => {
runCLI(`build ${pluginName}`); runCLI(`build ${pluginName}`);
checkFilesExist( checkFilesExist(
`dist/package.json`, `dist/${pluginName}/package.json`,
`dist/generators.json`, `dist/${pluginName}/generators.json`,
`dist/executors.json` `dist/${pluginName}/executors.json`
); );
}); });
@ -59,7 +62,10 @@ describe('create-nx-plugin', () => {
}); });
runCLI(`build ${pluginName}`); runCLI(`build ${pluginName}`);
checkFilesExist(`dist/package.json`, `dist/generators.json`); checkFilesExist(
`dist/${pluginName}/package.json`,
`dist/${pluginName}/generators.json`
);
runCLI(`build create-${pluginName}-package`); runCLI(`build create-${pluginName}-package`);
checkFilesExist(`dist/create-${pluginName}-package/bin/index.js`); checkFilesExist(`dist/create-${pluginName}-package/bin/index.js`);

View File

@ -157,9 +157,7 @@ function addProject(
options.bundler !== 'none' && options.bundler !== 'none' &&
options.config !== 'npm-scripts' options.config !== 'npm-scripts'
) { ) {
const outputPath = destinationDir const outputPath = getOutputPath(options, destinationDir);
? `dist/${destinationDir}/${options.projectDirectory}`
: `dist/${options.projectDirectory}`;
projectConfiguration.targets.build = { projectConfiguration.targets.build = {
executor: getBuildExecutor(options.bundler), executor: getBuildExecutor(options.bundler),
outputs: ['{options.outputPath}'], outputs: ['{options.outputPath}'],
@ -580,5 +578,18 @@ function ensureBabelRootConfigExists(tree: Tree) {
}); });
} }
function getOutputPath(options: NormalizedSchema, destinationDir?: string) {
const parts = ['dist'];
if (destinationDir) {
parts.push(destinationDir);
}
if (options.projectDirectory === '.') {
parts.push(options.name);
} else {
parts.push(options.projectDirectory);
}
return joinPathFragments(...parts);
}
export default libraryGenerator; export default libraryGenerator;
export const librarySchematic = convertNxGenerator(libraryGenerator); export const librarySchematic = convertNxGenerator(libraryGenerator);

View File

@ -44,25 +44,27 @@ function updatePluginConfig(host: Tree, options: NormalizedSchema) {
if (project.targets.build) { if (project.targets.build) {
project.targets.build.options.assets ??= []; project.targets.build.options.assets ??= [];
const root =
options.projectRoot === '.' ? './' : './' + options.projectRoot;
project.targets.build.options.assets = [ project.targets.build.options.assets = [
...project.targets.build.options.assets, ...project.targets.build.options.assets,
{ {
input: `./${options.projectRoot}/src`, input: `${root}/src`,
glob: '**/!(*.ts)', glob: '**/!(*.ts)',
output: './src', output: './src',
}, },
{ {
input: `./${options.projectRoot}/src`, input: `${root}/src`,
glob: '**/*.d.ts', glob: '**/*.d.ts',
output: './src', output: './src',
}, },
{ {
input: `./${options.projectRoot}`, input: root,
glob: 'generators.json', glob: 'generators.json',
output: '.', output: '.',
}, },
{ {
input: `./${options.projectRoot}`, input: root,
glob: 'executors.json', glob: 'executors.json',
output: '.', output: '.',
}, },