fix(react): None buildable libs should not have a build target (#29175)

This commit is contained in:
Nicholas Cunningham 2024-12-03 16:30:51 -07:00 committed by GitHub
parent 3cc321d4ce
commit dd14f3943c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 0 deletions

View File

@ -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');

View File

@ -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';
@ -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, {
@ -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