From 815e5f65b0ef1f29f6a31b7ca20b5fe3659d3915 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 --- packages/js/src/generators/library/library.ts | 17 ++++++++++++++--- packages/plugin/src/generators/plugin/plugin.ts | 10 ++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/js/src/generators/library/library.ts b/packages/js/src/generators/library/library.ts index 458ff7ec44a422..9c91e55fd43b0b 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); 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 b16a7c2bda3dcd..d63d04572e771f 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: '.', },