Skip to content

Commit

Permalink
fix(nx-plugin): generated root plugin should not have wonky paths
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Apr 20, 2023
1 parent 9163960 commit 815e5f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
17 changes: 14 additions & 3 deletions packages/js/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}'],
Expand Down Expand Up @@ -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);
10 changes: 6 additions & 4 deletions packages/plugin/src/generators/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '.',
},
Expand Down

0 comments on commit 815e5f6

Please sign in to comment.