fix(react): component generator should work without sourceRoot (#20094)
This commit is contained in:
parent
d4f4d73129
commit
8a9f43f074
@ -1,5 +1,11 @@
|
|||||||
import { installedCypressVersion } from '@nx/cypress/src/utils/cypress-version';
|
import { installedCypressVersion } from '@nx/cypress/src/utils/cypress-version';
|
||||||
import { logger, readJson, Tree } from '@nx/devkit';
|
import {
|
||||||
|
logger,
|
||||||
|
readJson,
|
||||||
|
readProjectConfiguration,
|
||||||
|
Tree,
|
||||||
|
updateProjectConfiguration,
|
||||||
|
} from '@nx/devkit';
|
||||||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
||||||
import { createApp, createLib } from '../../utils/testing-generators';
|
import { createApp, createLib } from '../../utils/testing-generators';
|
||||||
import { componentGenerator } from './component';
|
import { componentGenerator } from './component';
|
||||||
@ -140,6 +146,22 @@ describe('component', () => {
|
|||||||
|
|
||||||
expect(indexContent).not.toMatch(/lib\/hello/);
|
expect(indexContent).not.toMatch(/lib\/hello/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should work for projects without sourceRoot', async () => {
|
||||||
|
const projectConfig = readProjectConfiguration(appTree, 'my-lib');
|
||||||
|
delete projectConfig.sourceRoot;
|
||||||
|
updateProjectConfiguration(appTree, 'my-lib', projectConfig);
|
||||||
|
|
||||||
|
await componentGenerator(appTree, {
|
||||||
|
name: 'my-lib/src/lib/hello',
|
||||||
|
style: 'css',
|
||||||
|
export: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const indexContent = appTree.read('my-lib/src/index.ts', 'utf-8');
|
||||||
|
|
||||||
|
expect(indexContent).not.toMatch(/lib\/hello/);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('--pascalCaseFiles', () => {
|
describe('--pascalCaseFiles', () => {
|
||||||
|
|||||||
@ -36,7 +36,11 @@ export async function normalizeOptions(
|
|||||||
|
|
||||||
const { className } = names(name);
|
const { className } = names(name);
|
||||||
|
|
||||||
const { sourceRoot: projectSourceRoot, projectType } = project;
|
const {
|
||||||
|
sourceRoot: projectSourceRoot,
|
||||||
|
root: projectRoot,
|
||||||
|
projectType,
|
||||||
|
} = project;
|
||||||
|
|
||||||
const styledModule = /^(css|scss|less|none)$/.test(options.style)
|
const styledModule = /^(css|scss|less|none)$/.test(options.style)
|
||||||
? null
|
? null
|
||||||
@ -62,6 +66,6 @@ export async function normalizeOptions(
|
|||||||
className,
|
className,
|
||||||
fileName,
|
fileName,
|
||||||
filePath,
|
filePath,
|
||||||
projectSourceRoot,
|
projectSourceRoot: projectSourceRoot ?? projectRoot,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user