Skip to content

Commit

Permalink
fix(react): None buildable libs should not have a build target (#29175)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndcunningham authored Dec 3, 2024
1 parent 3cc321d commit dd14f39
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
21 changes: 21 additions & 0 deletions e2e/react/src/react.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ describe('React Applications', () => {
}
}, 250_000);

it('None buildable libs using (useTsSolution = true) should be excluded from js/ts plugin', async () => {
const appName = uniq('app');
const libName = uniq('lib');

runCLI(
`generate @nx/react:app apps/${appName} --name=${appName} --useTsSolution true --bundler=vite --no-interactive --skipFormat --linter=eslint --unitTestRunner=vitest`
);
runCLI(
`generate @nx/react:lib ${libName} --bundler=none --no-interactive --unit-test-runner=vitest --skipFormat --linter=eslint`
);

const nxJson = JSON.parse(readFile('nx.json'));

const jsTypescriptPlugin = nxJson.plugins.find(
(plugin) => plugin.plugin === '@nx/js/typescript'
);
expect(jsTypescriptPlugin).toBeDefined();

expect(jsTypescriptPlugin.exclude.includes(`${libName}/*`)).toBeTruthy();
}, 250_000);

it('should be able to use Rspack to build and test apps', async () => {
const appName = uniq('app');
const libName = uniq('lib');
Expand Down
7 changes: 7 additions & 0 deletions packages/react/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {
GeneratorCallback,
installPackagesTask,
joinPathFragments,
readNxJson,
runTasksInSerial,
Tree,
updateJson,
updateNxJson,
writeJson,
} from '@nx/devkit';
import { getRelativeCwd } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
Expand All @@ -30,6 +32,7 @@ import { extractTsConfigBase } from '../../utils/create-ts-config';
import { installCommonDependencies } from './lib/install-common-dependencies';
import { setDefaults } from './lib/set-defaults';
import { updateTsconfigFiles } from '@nx/js/src/utils/typescript/ts-solution-setup';
import { ensureProjectIsExcludedFromPluginRegistrations } from '@nx/js/src/utils/typescript/plugin';

export async function libraryGenerator(host: Tree, schema: Schema) {
return await libraryGeneratorInternal(host, {
Expand Down Expand Up @@ -137,6 +140,10 @@ export async function libraryGeneratorInternal(host: Tree, schema: Schema) {
} else if (options.buildable && options.bundler === 'rollup') {
const rollupTask = await addRollupBuildTarget(host, options);
tasks.push(rollupTask);
} else if (options.bundler === 'none' && options.addPlugin) {
const nxJson = readNxJson(host);
ensureProjectIsExcludedFromPluginRegistrations(nxJson, options.projectRoot);
updateNxJson(host, nxJson);
}

// Set up test target
Expand Down

0 comments on commit dd14f39

Please sign in to comment.