Skip to content

Commit

Permalink
fix(js): generate correct build options for rollup bundler; by defaul…
Browse files Browse the repository at this point in the history
…t and with swc compiler
  • Loading branch information
nartc committed Feb 23, 2023
1 parent cbf33c4 commit bb51136
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
29 changes: 29 additions & 0 deletions packages/js/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,35 @@ describe('lib', () => {
});
});

describe('bundler=rollup', () => {
it('should generate correct options for build', async () => {
await libraryGenerator(tree, {
...defaultOptions,
name: 'myLib',
buildable: true,
bundler: 'rollup',
});

const config = readProjectConfiguration(tree, 'my-lib');
expect(config.targets.build.options.project).toEqual(
`libs/my-lib/package.json`
);
});

it('should set compiler to swc', async () => {
await libraryGenerator(tree, {
...defaultOptions,
name: 'myLib',
buildable: true,
bundler: 'rollup',
compiler: 'swc',
});

const config = readProjectConfiguration(tree, 'my-lib');
expect(config.targets.build.options.compiler).toEqual('swc');
});
});

describe('--publishable', () => {
it('should generate the build target', async () => {
await libraryGenerator(tree, {
Expand Down
9 changes: 8 additions & 1 deletion packages/js/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export async function projectGenerator(
});
tasks.push(viteTask);
}
if (schema.bundler === 'rollup') {
if (options.bundler === 'rollup') {
ensureBabelRootConfigExists(tree);
}

Expand Down Expand Up @@ -160,6 +160,13 @@ function addProject(
},
};

if (options.bundler === 'rollup') {
projectConfiguration.targets.build.options.project = `${options.projectRoot}/package.json`;
if (options.compiler === 'swc') {
projectConfiguration.targets.build.options.compiler = 'swc';
}
}

if (options.compiler === 'swc' && options.skipTypeCheck) {
projectConfiguration.targets.build.options.skipTypeCheck = true;
}
Expand Down

0 comments on commit bb51136

Please sign in to comment.