Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react): default bundler to vite when deprecated buildable option is used #13857

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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',
});
});
});
22 changes: 19 additions & 3 deletions packages/react/src/generators/library/lib/normalize-options.ts
Expand Up @@ -4,6 +4,7 @@ import {
getProjects,
getWorkspaceLayout,
joinPathFragments,
logger,
names,
normalizePath,
Tree,
Expand Down Expand Up @@ -36,12 +37,27 @@ export function normalizeOptions(
const importPath =
options.importPath || getImportPath(npmScope, fullProjectDirectory);

let bundler = options.bundler ?? 'none';

if (bundler === 'none') {
if (options.publishable) {
logger.warn(
`Publishable libraries cannot be used with bundler: 'none'. Defaulting to 'rollup'.`
);
bundler = 'rollup';
}
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,
Expand Down