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 21, 2023
1 parent 8de17ab commit 335fbe0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
16 changes: 11 additions & 5 deletions e2e/workspace-create/src/create-nx-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand All @@ -44,9 +47,9 @@ describe('create-nx-plugin', () => {
runCLI(`build ${pluginName}`);

checkFilesExist(
`dist/package.json`,
`dist/generators.json`,
`dist/executors.json`
`dist/${pluginName}/package.json`,
`dist/${pluginName}/generators.json`,
`dist/${pluginName}/executors.json`
);
});

Expand All @@ -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`);
Expand Down
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, destinationDir);
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 335fbe0

Please sign in to comment.