diff --git a/packages/nx-plugin/src/generators/plugin/plugin.spec.ts b/packages/nx-plugin/src/generators/plugin/plugin.spec.ts index cbb6f21bec38b..0a8daac42e4a3 100644 --- a/packages/nx-plugin/src/generators/plugin/plugin.spec.ts +++ b/packages/nx-plugin/src/generators/plugin/plugin.spec.ts @@ -187,6 +187,23 @@ describe('NxPlugin Plugin Generator', () => { expect(name).toEqual('@proj/my-plugin'); }); + it('should correctly setup npmScope less workspaces', async () => { + // remove the npmScope from nx.json + const nxJson = JSON.parse(tree.read('nx.json')!.toString()); + delete nxJson.npmScope; + tree.write('nx.json', JSON.stringify(nxJson)); + + await pluginGenerator(tree, getSchema()); + + const { root } = readProjectConfiguration(tree, 'my-plugin'); + const { name } = readJson<{ name: string }>( + tree, + joinPathFragments(root, 'package.json') + ); + + expect(name).toEqual('my-plugin'); + }); + it('should use importPath as the package.json name', async () => { await pluginGenerator( tree, diff --git a/packages/nx-plugin/src/generators/plugin/plugin.ts b/packages/nx-plugin/src/generators/plugin/plugin.ts index 7e416439bfc86..cd6d3ef5d801d 100644 --- a/packages/nx-plugin/src/generators/plugin/plugin.ts +++ b/packages/nx-plugin/src/generators/plugin/plugin.ts @@ -47,7 +47,8 @@ function normalizeOptions(host: Tree, options: Schema): NormalizedSchema { ? options.tags.split(',').map((s) => s.trim()) : []; - const npmPackageName = options.importPath || `@${npmScope}/${name}`; + const npmPackageName = + options.importPath || resolvePackageName(npmScope, name); return { ...options, @@ -163,5 +164,13 @@ export async function pluginGenerator(host: Tree, schema: Schema) { return runTasksInSerial(...tasks); } +function resolvePackageName(npmScope: string, name: string): string { + if (npmScope && npmScope !== '') { + return `@${npmScope}/${name}`; + } else { + return name; + } +} + export default pluginGenerator; export const pluginSchematic = convertNxGenerator(pluginGenerator);