Skip to content

Commit

Permalink
fix(nx-plugin): cleanup some paths that are strange when root project (
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder authored Apr 25, 2023
1 parent 3fca88c commit b409095
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
71 changes: 71 additions & 0 deletions packages/plugin/src/generators/plugin/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,77 @@ describe('NxPlugin Plugin Generator', () => {
expect(projectE2e.root).toEqual('apps/plugins/my-plugin-e2e');
});

describe('asset paths', () => {
it('should generate normalized asset paths for plugin in monorepo', async () => {
await pluginGenerator(
tree,
getSchema({
name: 'myPlugin',
})
);
const project = readProjectConfiguration(tree, 'my-plugin');
const assets = project.targets.build.options.assets;
expect(assets).toEqual([
'libs/my-plugin/*.md',
{
input: './libs/my-plugin/src',
glob: '**/!(*.ts)',
output: './src',
},
{
input: './libs/my-plugin/src',
glob: '**/*.d.ts',
output: './src',
},
{
input: './libs/my-plugin',
glob: 'generators.json',
output: '.',
},
{
input: './libs/my-plugin',
glob: 'executors.json',
output: '.',
},
]);
});

it('should generate normalized asset paths for plugin in standalone workspace', async () => {
await pluginGenerator(
tree,
getSchema({
name: 'myPlugin',
rootProject: true,
})
);
const project = readProjectConfiguration(tree, 'my-plugin');
const assets = project.targets.build.options.assets;
expect(assets).toEqual([
'*.md',
{
input: './src',
glob: '**/!(*.ts)',
output: './src',
},
{
input: './src',
glob: '**/*.d.ts',
output: './src',
},
{
input: '.',
glob: 'generators.json',
output: '.',
},
{
input: '.',
glob: 'executors.json',
output: '.',
},
]);
});
});

describe('--unitTestRunner', () => {
describe('none', () => {
it('should not generate test files', async () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/plugin/src/generators/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ function updatePluginConfig(host: Tree, options: NormalizedSchema) {
if (project.targets.build) {
project.targets.build.options.assets ??= [];

const root =
options.projectRoot === '.' ? './' : './' + options.projectRoot;
const root = options.projectRoot === '.' ? '.' : './' + options.projectRoot;
project.targets.build.options.assets = [
...project.targets.build.options.assets,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export function normalizeOptions(
? name
: fullProjectDirectory.replace(new RegExp('/', 'g'), '-');
const fileName = projectName;
const projectRoot = joinPathFragments(libsDir, fullProjectDirectory);
const projectRoot = options.rootProject
? fullProjectDirectory
: joinPathFragments(libsDir, fullProjectDirectory);

const parsedTags = options.tags
? options.tags.split(',').map((s) => s.trim())
Expand Down

0 comments on commit b409095

Please sign in to comment.