diff --git a/packages/react/src/generators/library/lib/normalize-options.spec.ts b/packages/react/src/generators/library/lib/normalize-options.spec.ts index 5fa93893549a68..b545cb5a3f8025 100644 --- a/packages/react/src/generators/library/lib/normalize-options.spec.ts +++ b/packages/react/src/generators/library/lib/normalize-options.spec.ts @@ -85,4 +85,37 @@ describe('normalizeOptions', () => { unitTestRunner: 'jest', }); }); + + it('should set bundler to rollup if buildable is true not no bundler is passed', () => { + const options = normalizeOptions(tree, { + name: 'test', + style: 'css', + linter: Linter.None, + buildable: true, + unitTestRunner: 'jest', + }); + + expect(options).toMatchObject({ + buildable: true, + bundler: 'rollup', + unitTestRunner: 'jest', + }); + }); + + it('should set bundler to rollup if buildable is true and bundler is none ', () => { + const options = normalizeOptions(tree, { + name: 'test', + style: 'css', + linter: Linter.None, + buildable: true, + bundler: 'none', + unitTestRunner: 'jest', + }); + + expect(options).toMatchObject({ + buildable: true, + bundler: 'rollup', + unitTestRunner: 'jest', + }); + }); }); diff --git a/packages/react/src/generators/library/lib/normalize-options.ts b/packages/react/src/generators/library/lib/normalize-options.ts index 1118a9888878bd..6af9b914345afa 100644 --- a/packages/react/src/generators/library/lib/normalize-options.ts +++ b/packages/react/src/generators/library/lib/normalize-options.ts @@ -4,6 +4,7 @@ import { getProjects, getWorkspaceLayout, joinPathFragments, + logger, names, normalizePath, Tree, @@ -36,12 +37,26 @@ export function normalizeOptions( const importPath = options.importPath || getImportPath(npmScope, fullProjectDirectory); + let bundler = options.bundler ?? 'none'; + + if (bundler === 'none') { + if (options.publishable) { + throw new Error( + `Publishable libraries cannot be used with bundler: 'none'.` + ); + } + if (options.buildable) { + logger.warn( + `Buildable libraries cannot be used with bundler: 'none'. Defaulting to 'rollup'.` + ); + bundler = 'rollup'; + } + } + const normalized = { ...options, compiler: options.compiler ?? 'babel', - bundler: - options.bundler ?? - (options.buildable || options.publishable ? 'rollup' : 'none'), + bundler, fileName, routePath: `/${name}`, name: projectName,