fix(react): routing option to library generator (#31328)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
When we try to generate a library with react it fails because `name` is
required.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
This should work out of the box.
## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #30721
This commit is contained in:
Nicholas Cunningham 2025-05-26 06:14:00 -06:00 committed by GitHub
parent ac226ef62b
commit 07baaafb43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 0 deletions

View File

@ -533,6 +533,23 @@ describe('lib', () => {
}); });
}); });
describe('--routing', () => {
it('should be able to generate a library with routing', async () => {
await libraryGenerator(tree, {
...defaultSchema,
routing: true,
});
const content = tree.read('my-lib/src/lib/my-lib.tsx', 'utf-8');
expect(content).toContain('react-router-dom');
expect(content).toMatch(/<Link\s*to="\/">my-lib root<\/Link>/);
expect(content).toMatch(
/<Route\s*path="\/"\s*element={<div>This is the my-lib root route.<\/div>} \/>/
);
});
});
describe('--buildable', () => { describe('--buildable', () => {
it('should default to rollup bundler', async () => { it('should default to rollup bundler', async () => {
await libraryGenerator(tree, { await libraryGenerator(tree, {

View File

@ -248,6 +248,7 @@ export async function libraryGeneratorInternal(host: Tree, schema: Schema) {
export: true, export: true,
routing: options.routing, routing: options.routing,
js: options.js, js: options.js,
name: options.name,
inSourceTests: options.inSourceTests, inSourceTests: options.inSourceTests,
skipFormat: true, skipFormat: true,
globalCss: options.globalCss, globalCss: options.globalCss,