From ecee32c23114914157fa01662b2c5da134be28df Mon Sep 17 00:00:00 2001 From: bzp2010 Date: Fri, 15 Nov 2024 00:19:29 +0800 Subject: [PATCH 1/6] feat: renew shadcn ui init process --- .../shadcn-ui/src/generators/init/init.impl.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/shadcn-ui/src/generators/init/init.impl.ts b/packages/shadcn-ui/src/generators/init/init.impl.ts index d6629985..ca244e09 100644 --- a/packages/shadcn-ui/src/generators/init/init.impl.ts +++ b/packages/shadcn-ui/src/generators/init/init.impl.ts @@ -50,7 +50,8 @@ export default async function (tree: Tree, options: ShadecnUiSchema) { skipFormat: true, style: 'css', linter: Linter.EsLint, - directory: uiLibOptions.projectRoot + directory: uiLibOptions.projectRoot, + skipTsConfig: true }) const utilsLibOptions = await determineProjectNameAndRootOptions(tree, { @@ -64,9 +65,12 @@ export default async function (tree: Tree, options: ShadecnUiSchema) { skipFormat: true, style: 'css', linter: Linter.EsLint, - directory: utilsLibOptions.projectRoot + directory: utilsLibOptions.projectRoot, + skipTsConfig: true }) + addTsConfigPath(tree, `${uiLibOptions.importPath}`, [`${uiLibOptions.projectRoot}/src`]) + addTsConfigPath(tree, `${utilsLibOptions.importPath}`, [`${utilsLibOptions.projectRoot}/src`]) addTsConfigPath(tree, `${uiLibOptions.importPath}/*`, [`${uiLibOptions.projectRoot}/src/*`]) addTsConfigPath(tree, `${utilsLibOptions.importPath}/*`, [`${utilsLibOptions.projectRoot}/src/*`]) cleanupLib(tree, uiLibOptions.projectRoot) @@ -79,14 +83,15 @@ export default async function (tree: Tree, options: ShadecnUiSchema) { 'style': 'default', 'rsc': false, 'tailwind': { - 'config': join(utilsLibOptions.projectRoot, 'tailwind.config.js'), - 'css': join(utilsLibOptions.projectRoot, 'global.css'), + 'config': join(utilsLibOptions.projectRoot, 'src/tailwind.config.ts'), + 'css': join(utilsLibOptions.projectRoot, 'src/global.css'), 'baseColor': 'neutral', 'cssVariables': true }, 'aliases': { 'components': uiLibOptions.importPath, - 'utils': utilsLibOptions.importPath + 'utils': utilsLibOptions.importPath, + "hooks": `${uiLibOptions.importPath}/hooks` } }) From c662b850043141b0a715889ab719d8efd3b50388 Mon Sep 17 00:00:00 2001 From: bzp2010 Date: Fri, 15 Nov 2024 00:19:53 +0800 Subject: [PATCH 2/6] test: shadcn ui init e2e --- e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts b/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts index e76af9c5..fba6f2ef 100644 --- a/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts +++ b/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts @@ -1,6 +1,6 @@ import { ensureNxProject } from '../../utils/workspace' import { runNxCommandAsync } from '../../utils/run-nx-command-async' -import { checkFilesExist } from '@nx/plugin/testing' +import { checkFilesExist, readJson } from '@nx/plugin/testing' describe('shadcn/ui e2e', () => { @@ -22,14 +22,15 @@ describe('shadcn/ui e2e', () => { `${utilsLibName}/src/index.ts`, 'components.json' )).not.toThrow() - }) - // it('should be able add a button', async () => { - // await runNxCommandAsync(`add ${uiLibName} button`) - // - // expect(() => checkFilesExist( - // `${uiLibName}/src/button.tsx`, - // )).not.toThrow() - // }) + const componentsJSON = readJson('components.json') + expect(componentsJSON.tailwind.config).toEqual(`${utilsLibName}/src/tailwind.config.ts`) + expect(componentsJSON.tailwind.css).toEqual(`${utilsLibName}/src/global.css`) + expect(componentsJSON.aliases.hooks).toEqual(`@proj/${uiLibName}/hooks`) + + const tsconfigJSON = readJson('tsconfig.base.json') + expect(tsconfigJSON.compilerOptions.paths[`@proj/${uiLibName}`][0]).toEqual(`${uiLibName}/src`) + expect(tsconfigJSON.compilerOptions.paths[`@proj/${utilsLibName}`][0]).toEqual(`${utilsLibName}/src`) + }) }) From d60558bc192c4a7695848c3c5abf602564915e3d Mon Sep 17 00:00:00 2001 From: bzp2010 Date: Fri, 15 Nov 2024 00:22:40 +0800 Subject: [PATCH 3/6] feat: renew shadcn ui add process --- packages/shadcn-ui/src/executors/add/add.impl.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/shadcn-ui/src/executors/add/add.impl.ts b/packages/shadcn-ui/src/executors/add/add.impl.ts index 89fe5897..f96ab98c 100644 --- a/packages/shadcn-ui/src/executors/add/add.impl.ts +++ b/packages/shadcn-ui/src/executors/add/add.impl.ts @@ -10,15 +10,11 @@ export async function addExecutor( options: ExecutorSchema, context: ExecutorContext ): Promise<{ success: boolean }> { - const { root } = context.projectsConfigurations.projects[context.projectName] - return execPackageManagerCommand( buildCommand([ - 'shadcn-ui@0.8.0 add', + 'shadcn@latest add', (options.component ?? '').length === 0 ? '--all' : options.component, - options.overwrite && '--overwrite', - '--path=src', - `--cwd=${root}` + options.overwrite && '--overwrite' ]), {} ) From 92153912b69aa820a7d2e167e01f05f9b51a7657 Mon Sep 17 00:00:00 2001 From: bzp2010 Date: Fri, 15 Nov 2024 00:49:27 +0800 Subject: [PATCH 4/6] feat: add TS_NODE_PROJECT env for specify tsconfig file name --- packages/shadcn-ui/src/executors/add/add.impl.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/shadcn-ui/src/executors/add/add.impl.ts b/packages/shadcn-ui/src/executors/add/add.impl.ts index f96ab98c..1b8f72b0 100644 --- a/packages/shadcn-ui/src/executors/add/add.impl.ts +++ b/packages/shadcn-ui/src/executors/add/add.impl.ts @@ -16,7 +16,11 @@ export async function addExecutor( (options.component ?? '').length === 0 ? '--all' : options.component, options.overwrite && '--overwrite' ]), - {} + { + env: { + TS_NODE_PROJECT: 'tsconfig.base.json' + } + } ) } From 202c46168375f43fa52ffd6d2b71d9c05e8d4bc2 Mon Sep 17 00:00:00 2001 From: bzp2010 Date: Fri, 15 Nov 2024 16:02:11 +0800 Subject: [PATCH 5/6] test: add-component e2e --- e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts | 17 +++++++++++++++++ .../shadcn-ui/src/executors/add/add.impl.ts | 1 + 2 files changed, 18 insertions(+) diff --git a/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts b/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts index fba6f2ef..08c88e00 100644 --- a/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts +++ b/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts @@ -33,4 +33,21 @@ describe('shadcn/ui e2e', () => { expect(tsconfigJSON.compilerOptions.paths[`@proj/${utilsLibName}`][0]).toEqual(`${utilsLibName}/src`) }) + it('should be able add button ui', async () => { + await runNxCommandAsync(`add-component ${uiLibName} button`) + + expect(() => checkFilesExist( + `${uiLibName}/src/ui/button.tsx`, + )).not.toThrow() + }) + + it('should be able add sidebar ui', async () => { + await runNxCommandAsync(`add-component ${uiLibName} sidebar`) + + expect(() => checkFilesExist( + `${uiLibName}/src/ui/sidebar.tsx`, + `${uiLibName}/src/hooks/use-mobile.tsx`, + )).not.toThrow() + }) + }) diff --git a/packages/shadcn-ui/src/executors/add/add.impl.ts b/packages/shadcn-ui/src/executors/add/add.impl.ts index 1b8f72b0..11857e07 100644 --- a/packages/shadcn-ui/src/executors/add/add.impl.ts +++ b/packages/shadcn-ui/src/executors/add/add.impl.ts @@ -18,6 +18,7 @@ export async function addExecutor( ]), { env: { + ...process.env, TS_NODE_PROJECT: 'tsconfig.base.json' } } From 8c4a8d851649e5f62cf193c2eae9dc94e0facddf Mon Sep 17 00:00:00 2001 From: bzp2010 Date: Fri, 15 Nov 2024 18:50:25 +0800 Subject: [PATCH 6/6] test: fix conflict caused timeout --- e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts b/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts index 08c88e00..3e7424fa 100644 --- a/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts +++ b/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts @@ -42,7 +42,7 @@ describe('shadcn/ui e2e', () => { }) it('should be able add sidebar ui', async () => { - await runNxCommandAsync(`add-component ${uiLibName} sidebar`) + await runNxCommandAsync(`add-component ${uiLibName} sidebar --overwrite`) // Overwrites are needed because of button ui conflicts expect(() => checkFilesExist( `${uiLibName}/src/ui/sidebar.tsx`,