fix(react): fix creating a react library with cwd (#19721)

This commit is contained in:
Emily Xiong 2023-10-19 13:10:01 -04:00 committed by GitHub
parent f619c80151
commit 85bda9ab8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -404,7 +404,7 @@ function isTTY(): boolean {
return !!process.stdout.isTTY && process.env['CI'] !== 'true';
}
function getRelativeCwd(): string {
export function getRelativeCwd(): string {
return normalizePath(relative(workspaceRoot, getCwd()));
}

View File

@ -8,6 +8,7 @@ import {
Tree,
updateJson,
} from '@nx/devkit';
import { getRelativeCwd } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
import { addTsConfigPath } from '@nx/js';
@ -24,6 +25,7 @@ import { createFiles } from './lib/create-files';
import { extractTsConfigBase } from '../../utils/create-ts-config';
import { installCommonDependencies } from './lib/install-common-dependencies';
import { setDefaults } from './lib/set-defaults';
import { relative } from 'path';
export async function libraryGenerator(host: Tree, schema: Schema) {
return await libraryGeneratorInternal(host, {
@ -171,9 +173,15 @@ export async function libraryGeneratorInternal(host: Tree, schema: Schema) {
}
if (options.component) {
const relativeCwd = getRelativeCwd();
const name = joinPathFragments(
options.projectRoot,
'src/lib',
options.fileName
);
const componentTask = await componentGenerator(host, {
nameAndDirectoryFormat: 'as-provided',
name: joinPathFragments(options.projectRoot, 'src/lib', options.fileName),
name: relativeCwd ? relative(relativeCwd, name) : name,
project: options.name,
flat: true,
style: options.style,