Skip to content

Commit

Permalink
fix(react): fix creating a react library with cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Oct 19, 2023
1 parent d798126 commit 5cb03a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

Expand Down
10 changes: 9 additions & 1 deletion packages/react/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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, {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5cb03a2

Please sign in to comment.