From 0ddbae6b620530a5df42fc5a7b7b1488125e2def Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Thu, 20 Apr 2023 15:05:44 -0400 Subject: [PATCH] fix(nx-plugin): generated root plugin should not have wonky paths --- .../src/create-nx-plugin.test.ts | 10 ++++++++-- packages/js/src/generators/library/library.ts | 17 ++++++++++++++--- packages/plugin/src/generators/plugin/plugin.ts | 10 ++++++---- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/e2e/workspace-create/src/create-nx-plugin.test.ts b/e2e/workspace-create/src/create-nx-plugin.test.ts index e3758b65c155de..d84691d415cb91 100644 --- a/e2e/workspace-create/src/create-nx-plugin.test.ts +++ b/e2e/workspace-create/src/create-nx-plugin.test.ts @@ -32,7 +32,10 @@ describe('create-nx-plugin', () => { runCLI(`build ${pluginName}`); - checkFilesExist(`dist/package.json`, `dist/src/index.js`); + checkFilesExist( + `dist/${pluginName}/package.json`, + `dist/${pluginName}/src/index.js` + ); runCLI( `generate @nrwl/nx-plugin:generator ${generatorName} --project=${pluginName}` @@ -59,7 +62,10 @@ describe('create-nx-plugin', () => { }); runCLI(`build ${pluginName}`); - checkFilesExist(`dist/package.json`, `dist/generators.json`); + checkFilesExist( + `dist/${pluginName}/package.json`, + `dist/${pluginName}/generators.json` + ); runCLI(`build create-${pluginName}-package`); checkFilesExist(`dist/create-${pluginName}-package/bin/index.js`); diff --git a/packages/js/src/generators/library/library.ts b/packages/js/src/generators/library/library.ts index 458ff7ec44a422..456c43f024b909 100644 --- a/packages/js/src/generators/library/library.ts +++ b/packages/js/src/generators/library/library.ts @@ -157,9 +157,7 @@ function addProject( options.bundler !== 'none' && options.config !== 'npm-scripts' ) { - const outputPath = destinationDir - ? `dist/${destinationDir}/${options.projectDirectory}` - : `dist/${options.projectDirectory}`; + const outputPath = getOutputPath(options, destinationDir); projectConfiguration.targets.build = { executor: getBuildExecutor(options.bundler), 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 const librarySchematic = convertNxGenerator(libraryGenerator); diff --git a/packages/plugin/src/generators/plugin/plugin.ts b/packages/plugin/src/generators/plugin/plugin.ts index 053064f33df5d2..ae89ef1be729d2 100644 --- a/packages/plugin/src/generators/plugin/plugin.ts +++ b/packages/plugin/src/generators/plugin/plugin.ts @@ -44,25 +44,27 @@ function updatePluginConfig(host: Tree, options: NormalizedSchema) { if (project.targets.build) { project.targets.build.options.assets ??= []; + const root = + options.projectRoot === '.' ? './' : './' + options.projectRoot; project.targets.build.options.assets = [ ...project.targets.build.options.assets, { - input: `./${options.projectRoot}/src`, + input: `${root}/src`, glob: '**/!(*.ts)', output: './src', }, { - input: `./${options.projectRoot}/src`, + input: `${root}/src`, glob: '**/*.d.ts', output: './src', }, { - input: `./${options.projectRoot}`, + input: root, glob: 'generators.json', output: '.', }, { - input: `./${options.projectRoot}`, + input: root, glob: 'executors.json', output: '.', },