-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Move components to components/ui and support intra-generator references #613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
64afee9
636fde1
e416a04
fee37a2
304c7ef
76b4dd7
72c2065
4a9f151
613ecd8
3295219
ec2ac78
62fa9c1
2d45599
bdb0503
cbfcae7
1f3062e
69d12f9
139f017
1148054
913ad5c
2f638f7
d3767a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| --- | ||
| '@baseplate-dev/react-generators': patch | ||
| --- | ||
|
|
||
| Reorganize components folder structure in generated codebases | ||
|
|
||
| The components folder structure has been reorganized to improve organization and reduce bundle size: | ||
|
|
||
| **Breaking Changes:** | ||
|
|
||
| - Removed bundle export at `components/index.ts` to prevent importing all components at once | ||
| - Moved all UI components from `components/` to `components/ui/` folder | ||
|
|
||
| **New Structure:** | ||
|
|
||
| ``` | ||
| components/ | ||
| ├── ui/ # UI components | ||
| │ ├── button.tsx | ||
| │ ├── input.tsx | ||
| │ └── ... | ||
| └── [other-components] # Custom application components | ||
| ``` | ||
|
|
||
| **Migration:** | ||
|
|
||
| - Replace `import { Button } from '@src/components'` with `import { Button } from '@src/components/ui/button'` | ||
| - Update imports to use specific component paths instead of barrel exports | ||
| - UI components are now co-located in the `ui/` subfolder for better organization | ||
|
|
||
| This change improves tree-shaking, reduces bundle size, and provides clearer separation between UI library components and custom application components. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| --- | ||
| '@baseplate-dev/core-generators': patch | ||
| --- | ||
|
|
||
| Add $templateName syntax for intra-generator template references | ||
|
|
||
| Templates can now reference other templates within the same generator using the `$templateName` syntax. This enables templates to access file paths of other templates in the same generator during generation. | ||
|
|
||
| Key features: | ||
|
|
||
| - Use `$templateName` in template files to reference other generator templates | ||
| - Kebab-case template names are automatically converted to camelCase (e.g., `session-constants` → `sessionConstants`) | ||
| - Configure referenced templates using the `referencedGeneratorTemplates` field in extractor.json | ||
| - Works seamlessly with existing variable replacement and import maps | ||
| - Provides clear error messages for missing template references | ||
|
|
||
| Example usage: | ||
|
|
||
| ```typescript | ||
| // In template file | ||
| import { Constants } from '$sessionConstants'; | ||
| import { Utils } from '$authUtils'; | ||
|
|
||
| // In extractor.json | ||
| { | ||
| "user-service": { | ||
| "sourceFile": "services/user.service.ts", | ||
| "referencedGeneratorTemplates": ["session-constants", "auth-utils"] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| This feature is designed for intra-generator template references only. For cross-generator references, continue using import map providers. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { ResolverFactory } from 'oxc-resolver'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { SourceFile } from 'ts-morph'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { camelCase } from 'es-toolkit'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { isBuiltin } from 'node:module'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import path from 'node:path'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Node, Project, SyntaxKind } from 'ts-morph'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -28,9 +29,9 @@ export interface TsTemplateImportLookupContext { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| outputDirectory: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The output relative paths of the files that are generated by the generator. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * A map of output relative paths to the name of the template in the generator. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internalOutputRelativePaths: string[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internalOutputRelativePaths: Map<string, string>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The resolver factory to use to resolve imports. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -75,6 +76,24 @@ function toTypesPackageName(pkgName: string): string | undefined { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return `@types/${pkgName}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The result of organizing the imports in a Typescript template file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interface OrganizeTsTemplateImportsResult { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The contents of the file with the imports converted to template paths. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| contents: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The project exports that are used in the file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usedProjectExports: TsProjectExport[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The generator files that are used in the file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| referencedGeneratorTemplates: Set<string>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+82
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Export the Per the coding guidelines, interfaces should be exported if they're used as return types of exported functions. -interface OrganizeTsTemplateImportsResult {
+export interface OrganizeTsTemplateImportsResult {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Organizes the imports in a Typescript template file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * - Removes unused imports | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -96,10 +115,7 @@ export async function organizeTsTemplateImports( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| resolver, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| outputDirectory, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }: TsTemplateImportLookupContext, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): Promise<{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| contents: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usedProjectExports: TsProjectExport[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): Promise<OrganizeTsTemplateImportsResult> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const project = new Project({ useInMemoryFileSystem: true }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const sourceFile = project.createSourceFile(filePath, contents); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -163,6 +179,7 @@ export async function organizeTsTemplateImports( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const usedProjectExports: TsProjectExport[] = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const referencedGeneratorTemplates = new Set<string>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const updatedImportDeclarations = await Promise.all( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tsImportDeclarations.map(async (importDeclaration) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -198,16 +215,14 @@ export async function organizeTsTemplateImports( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Don't modify imports for files in the generator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const relativeOutputPath = path.relative(outputDirectory, resolvedPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (internalOutputRelativePaths.includes(relativeOutputPath)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const relativeImportPath = path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .relative(path.dirname(filePath), resolvedPath) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .replace(/\.(t|j)sx?$/, '.js'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const internalTemplateName = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internalOutputRelativePaths.get(relativeOutputPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (internalTemplateName) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| referencedGeneratorTemplates.add(internalTemplateName); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const fixedImportDeclaration: TsImportDeclaration = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...importDeclaration, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // convert to relative path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| moduleSpecifier: relativeImportPath.startsWith('.') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? relativeImportPath | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : `./${relativeImportPath}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // convert to internal template name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| moduleSpecifier: `$${camelCase(internalTemplateName)}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [fixedImportDeclaration]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -291,5 +306,6 @@ export async function organizeTsTemplateImports( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| contents: sourceFile.getFullText(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usedProjectExports, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| referencedGeneratorTemplates, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Use a normal string index signature instead of
Record<'', string>.Record<'', string>creates a type with the single key"", which is almost certainly not what you mean and may trip type-checking or autocomplete later on.Either remove the cast altogether or cast to
Record<string, string>:📝 Committable suggestion
🤖 Prompt for AI Agents