@vendure/dashboard 3.2.2 → 3.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/plugin/utils/ast-utils.d.ts +10 -0
  2. package/dist/plugin/utils/ast-utils.js +96 -0
  3. package/dist/plugin/utils/ast-utils.spec.d.ts +1 -0
  4. package/dist/plugin/utils/ast-utils.spec.js +120 -0
  5. package/dist/plugin/{config-loader.d.ts → utils/config-loader.d.ts} +22 -8
  6. package/dist/plugin/utils/config-loader.js +325 -0
  7. package/dist/plugin/{schema-generator.d.ts → utils/schema-generator.d.ts} +5 -0
  8. package/dist/plugin/{schema-generator.js → utils/schema-generator.js} +6 -0
  9. package/dist/plugin/{ui-config.js → utils/ui-config.js} +2 -2
  10. package/dist/plugin/vite-plugin-admin-api-schema.js +2 -2
  11. package/dist/plugin/vite-plugin-config-loader.d.ts +2 -3
  12. package/dist/plugin/vite-plugin-config-loader.js +18 -9
  13. package/dist/plugin/vite-plugin-dashboard-metadata.js +12 -14
  14. package/dist/plugin/vite-plugin-gql-tada.js +2 -2
  15. package/dist/plugin/vite-plugin-ui-config.js +3 -2
  16. package/package.json +8 -6
  17. package/src/app/app-providers.tsx +8 -8
  18. package/src/app/main.tsx +1 -1
  19. package/src/app/routes/_authenticated/_assets/assets.graphql.ts +26 -0
  20. package/src/app/routes/_authenticated/_assets/assets.tsx +2 -2
  21. package/src/app/routes/_authenticated/_assets/assets_.$id.tsx +156 -0
  22. package/src/app/routes/_authenticated/_orders/components/customer-address-selector.tsx +104 -0
  23. package/src/app/routes/_authenticated/_orders/components/edit-order-table.tsx +228 -0
  24. package/src/app/routes/_authenticated/_orders/components/money-gross-net.tsx +18 -0
  25. package/src/app/routes/_authenticated/_orders/components/order-address.tsx +2 -1
  26. package/src/app/routes/_authenticated/_orders/components/order-line-custom-fields-form.tsx +38 -0
  27. package/src/app/routes/_authenticated/_orders/components/order-table-totals.tsx +53 -0
  28. package/src/app/routes/_authenticated/_orders/components/order-table.tsx +8 -49
  29. package/src/app/routes/_authenticated/_orders/components/shipping-method-selector.tsx +65 -0
  30. package/src/app/routes/_authenticated/_orders/orders.graphql.ts +187 -1
  31. package/src/app/routes/_authenticated/_orders/orders.tsx +39 -18
  32. package/src/app/routes/_authenticated/_orders/orders_.$id.tsx +31 -9
  33. package/src/app/routes/_authenticated/_orders/orders_.draft.$id.tsx +418 -0
  34. package/src/app/routes/_authenticated/_products/products.tsx +1 -1
  35. package/src/app/routes/_authenticated.tsx +12 -1
  36. package/src/lib/components/data-table/add-filter-menu.tsx +61 -0
  37. package/src/lib/components/data-table/data-table-column-header.tsx +0 -13
  38. package/src/lib/components/data-table/data-table-filter-badge.tsx +75 -0
  39. package/src/lib/components/data-table/data-table-filter-dialog.tsx +27 -28
  40. package/src/lib/components/data-table/data-table-types.ts +1 -0
  41. package/src/lib/components/data-table/data-table-view-options.tsx +72 -23
  42. package/src/lib/components/data-table/data-table.tsx +23 -24
  43. package/src/lib/components/data-table/filters/data-table-boolean-filter.tsx +57 -0
  44. package/src/lib/components/data-table/filters/data-table-datetime-filter.tsx +93 -0
  45. package/src/lib/components/data-table/filters/data-table-id-filter.tsx +58 -0
  46. package/src/lib/components/data-table/filters/data-table-number-filter.tsx +119 -0
  47. package/src/lib/components/data-table/filters/data-table-string-filter.tsx +62 -0
  48. package/src/lib/components/data-table/human-readable-operator.tsx +65 -0
  49. package/src/lib/components/layout/nav-user.tsx +4 -4
  50. package/src/lib/components/shared/asset/asset-focal-point-editor.tsx +93 -0
  51. package/src/lib/components/shared/{asset-gallery.tsx → asset/asset-gallery.tsx} +51 -20
  52. package/src/lib/components/shared/{asset-picker-dialog.tsx → asset/asset-picker-dialog.tsx} +1 -1
  53. package/src/lib/components/shared/{asset-preview-dialog.tsx → asset/asset-preview-dialog.tsx} +1 -7
  54. package/src/lib/components/shared/asset/asset-preview-selector.tsx +34 -0
  55. package/src/lib/components/shared/asset/asset-preview.tsx +128 -0
  56. package/src/lib/components/shared/asset/asset-properties.tsx +46 -0
  57. package/src/lib/components/shared/{focal-point-control.tsx → asset/focal-point-control.tsx} +1 -1
  58. package/src/lib/components/shared/custom-fields-form.tsx +4 -3
  59. package/src/lib/components/shared/customer-selector.tsx +13 -14
  60. package/src/lib/components/shared/detail-page-button.tsx +2 -2
  61. package/src/lib/components/shared/entity-assets.tsx +3 -3
  62. package/src/lib/components/shared/navigation-confirmation.tsx +39 -0
  63. package/src/lib/components/shared/paginated-list-data-table.tsx +9 -1
  64. package/src/lib/components/shared/product-variant-selector.tsx +111 -0
  65. package/src/lib/components/shared/vendure-image.tsx +1 -1
  66. package/src/lib/components/ui/calendar.tsx +508 -63
  67. package/src/lib/framework/document-introspection/get-document-structure.spec.ts +113 -3
  68. package/src/lib/framework/document-introspection/get-document-structure.ts +70 -11
  69. package/src/lib/framework/form-engine/use-generated-form.tsx +8 -7
  70. package/src/lib/framework/layout-engine/page-layout.tsx +4 -0
  71. package/src/lib/framework/page/list-page.tsx +23 -4
  72. package/src/lib/framework/page/use-detail-page.ts +1 -0
  73. package/src/lib/graphql/fragments.tsx +8 -0
  74. package/src/lib/index.ts +5 -5
  75. package/src/lib/providers/auth.tsx +12 -9
  76. package/src/lib/providers/channel-provider.tsx +1 -0
  77. package/src/lib/providers/server-config.tsx +7 -1
  78. package/src/lib/providers/user-settings.tsx +24 -0
  79. package/vite/utils/ast-utils.spec.ts +128 -0
  80. package/vite/utils/ast-utils.ts +119 -0
  81. package/vite/utils/config-loader.ts +410 -0
  82. package/vite/{schema-generator.ts → utils/schema-generator.ts} +7 -1
  83. package/vite/{ui-config.ts → utils/ui-config.ts} +2 -2
  84. package/vite/vite-plugin-admin-api-schema.ts +2 -2
  85. package/vite/vite-plugin-config-loader.ts +25 -13
  86. package/vite/vite-plugin-dashboard-metadata.ts +19 -15
  87. package/vite/vite-plugin-gql-tada.ts +2 -2
  88. package/vite/vite-plugin-ui-config.ts +3 -2
  89. package/dist/plugin/config-loader.js +0 -141
  90. package/src/lib/components/shared/asset-preview.tsx +0 -345
  91. package/vite/config-loader.ts +0 -181
  92. /package/dist/plugin/{ui-config.d.ts → utils/ui-config.d.ts} +0 -0
@@ -1,345 +0,0 @@
1
- import { Button } from '@/components/ui/button.js';
2
- import { Card, CardContent, CardHeader } from '@/components/ui/card.js';
3
- import { FormControl, FormField, FormItem, FormLabel } from '@/components/ui/form.js';
4
- import { Input } from '@/components/ui/input.js';
5
- import { Label } from '@/components/ui/label.js';
6
- import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select.js';
7
- import { VendureImage } from '@/components/shared/vendure-image.js';
8
- import { AssetFragment } from '@/graphql/fragments.js';
9
- import { cn, formatFileSize } from '@/lib/utils.js';
10
- import { ChevronLeft, ChevronRight, Crosshair, Edit, ExternalLink, X } from 'lucide-react';
11
- import { useEffect, useRef, useState } from 'react';
12
- import { useForm } from 'react-hook-form';
13
- import { FocalPointControl } from './focal-point-control.js';
14
-
15
- export type PreviewPreset = 'tiny' | 'thumb' | 'small' | 'medium' | 'large' | '';
16
-
17
- interface Point {
18
- x: number;
19
- y: number;
20
- }
21
-
22
- export type AssetWithTags = AssetFragment & { tags?: { value: string }[] };
23
-
24
- interface AssetPreviewProps {
25
- asset: AssetWithTags;
26
- assets?: AssetWithTags[];
27
- editable?: boolean;
28
- customFields?: any[];
29
- onAssetChange?: (asset: Partial<AssetWithTags>) => void;
30
- onEditClick?: () => void;
31
- }
32
-
33
- export function AssetPreview({
34
- asset,
35
- assets,
36
- editable = false,
37
- customFields = [],
38
- onAssetChange,
39
- onEditClick,
40
- }: AssetPreviewProps) {
41
- const [size, setSize] = useState<PreviewPreset>('medium');
42
- const [width, setWidth] = useState(0);
43
- const [height, setHeight] = useState(0);
44
- const [centered, setCentered] = useState(true);
45
- const [settingFocalPoint, setSettingFocalPoint] = useState(false);
46
- const [lastFocalPoint, setLastFocalPoint] = useState<Point>();
47
- const [assetIndex, setAssetIndex] = useState(assets?.indexOf(asset) || 0);
48
-
49
- const imageRef = useRef<HTMLImageElement>(null);
50
- const containerRef = useRef<HTMLDivElement>(null);
51
- const sizePriorToFocalPoint = useRef<PreviewPreset>('medium');
52
-
53
- const form = useForm({
54
- defaultValues: {
55
- name: asset.name,
56
- tags: asset.tags?.map(t => t.value) || [],
57
- },
58
- });
59
- const activeAsset = assets?.[assetIndex] ?? asset;
60
-
61
- useEffect(() => {
62
- if (assets?.length) {
63
- const index = assets.findIndex(a => a.id === asset.id);
64
- setAssetIndex(index === -1 ? 0 : index);
65
- }
66
- }, [assets, asset.id]);
67
-
68
- useEffect(() => {
69
- const handleResize = () => {
70
- updateDimensions();
71
- };
72
-
73
- window.addEventListener('resize', handleResize);
74
- return () => window.removeEventListener('resize', handleResize);
75
- }, []);
76
-
77
- const updateDimensions = () => {
78
- if (!imageRef.current || !containerRef.current) return;
79
-
80
- const img = imageRef.current;
81
- const container = containerRef.current;
82
- const imgWidth = img.naturalWidth;
83
- const imgHeight = img.naturalHeight;
84
- const containerWidth = container.offsetWidth;
85
- const containerHeight = container.offsetHeight;
86
-
87
- if (settingFocalPoint) {
88
- const controlsMarginPx = 48 * 2;
89
- const availableHeight = containerHeight - controlsMarginPx;
90
- const availableWidth = containerWidth;
91
- const hRatio = imgHeight / availableHeight;
92
- const wRatio = imgWidth / availableWidth;
93
-
94
- if (1 < hRatio || 1 < wRatio) {
95
- const factor = hRatio < wRatio ? wRatio : hRatio;
96
- setWidth(Math.round(imgWidth / factor));
97
- setHeight(Math.round(imgHeight / factor));
98
- setCentered(true);
99
- return;
100
- }
101
- }
102
-
103
- setWidth(imgWidth);
104
- setHeight(imgHeight);
105
- setCentered(imgWidth <= containerWidth && imgHeight <= containerHeight);
106
- };
107
-
108
- const handleFocalPointStart = () => {
109
- sizePriorToFocalPoint.current = size;
110
- setSize('medium');
111
- setSettingFocalPoint(true);
112
- setLastFocalPoint(asset.focalPoint || { x: 0.5, y: 0.5 });
113
- updateDimensions();
114
- };
115
-
116
- const handleFocalPointChange = (point: Point) => {
117
- setLastFocalPoint(point);
118
- };
119
-
120
- const handleFocalPointCancel = () => {
121
- setSettingFocalPoint(false);
122
- setLastFocalPoint(undefined);
123
- setSize(sizePriorToFocalPoint.current);
124
- };
125
-
126
- const handleFocalPointSet = async () => {
127
- if (!lastFocalPoint) return;
128
-
129
- try {
130
- // TODO: Implement API call to update focal point
131
- await onAssetChange?.({
132
- id: asset.id,
133
- focalPoint: lastFocalPoint,
134
- });
135
- setSettingFocalPoint(false);
136
- setSize(sizePriorToFocalPoint.current);
137
- // Show success toast
138
- } catch (err) {
139
- // Show error toast
140
- }
141
- };
142
-
143
- const handleRemoveFocalPoint = async () => {
144
- try {
145
- // TODO: Implement API call to remove focal point
146
- await onAssetChange?.({
147
- id: asset.id,
148
- focalPoint: null,
149
- });
150
- // Show success toast
151
- } catch (err) {
152
- // Show error toast
153
- }
154
- };
155
-
156
- return (
157
- <div className="grid grid-cols-1 md:grid-cols-[300px_1fr] gap-4 h-full">
158
- <div className="space-y-4">
159
- <Card>
160
- <CardContent className="space-y-4 pt-6">
161
- {!editable && onEditClick && (
162
- <Button variant="ghost" className="w-full justify-start" onClick={onEditClick}>
163
- <Edit className="mr-2 h-4 w-4" />
164
- Edit
165
- <ChevronRight className="ml-auto h-4 w-4" />
166
- </Button>
167
- )}
168
-
169
- {editable ? (
170
- <FormField
171
- control={form.control}
172
- name="name"
173
- render={({ field }) => (
174
- <FormItem>
175
- <FormLabel>Name</FormLabel>
176
- <FormControl>
177
- <Input {...field} />
178
- </FormControl>
179
- </FormItem>
180
- )}
181
- />
182
- ) : (
183
- <div>
184
- <Label>Name</Label>
185
- <p className="truncate text-sm text-muted-foreground">{activeAsset.name}</p>
186
- </div>
187
- )}
188
-
189
- <div>
190
- <Label>Source File</Label>
191
- <a
192
- href={activeAsset.source}
193
- target="_blank"
194
- rel="noopener noreferrer"
195
- className="text-sm text-primary hover:underline flex items-center"
196
- >
197
- {activeAsset.source.split('/').pop()}
198
- <ExternalLink className="ml-1 h-3 w-3" />
199
- </a>
200
- </div>
201
-
202
- <div>
203
- <Label>File Size</Label>
204
- <p className="text-sm text-muted-foreground">
205
- {formatFileSize(activeAsset.fileSize)}
206
- </p>
207
- </div>
208
-
209
- <div>
210
- <Label>Dimensions</Label>
211
- <p className="text-sm text-muted-foreground">
212
- {activeAsset.width} x {activeAsset.height}
213
- </p>
214
- </div>
215
-
216
- <div>
217
- <Label>Focal Point</Label>
218
- <div className="space-y-2">
219
- <p className="text-sm text-muted-foreground">
220
- {activeAsset.focalPoint ? (
221
- <span className="flex items-center">
222
- <Crosshair className="mr-1 h-4 w-4" />
223
- x: {activeAsset.focalPoint.x.toFixed(2)}, y:{' '}
224
- {activeAsset.focalPoint.y.toFixed(2)}
225
- </span>
226
- ) : (
227
- 'Not set'
228
- )}
229
- </p>
230
- <div className="flex gap-2">
231
- <Button
232
- variant="secondary"
233
- size="sm"
234
- disabled={settingFocalPoint}
235
- onClick={handleFocalPointStart}
236
- >
237
- {activeAsset.focalPoint ? 'Update' : 'Set'} Focal Point
238
- </Button>
239
- {activeAsset.focalPoint && (
240
- <Button
241
- variant="secondary"
242
- size="sm"
243
- disabled={settingFocalPoint}
244
- onClick={handleRemoveFocalPoint}
245
- >
246
- Remove
247
- </Button>
248
- )}
249
- </div>
250
- </div>
251
- </div>
252
- </CardContent>
253
- </Card>
254
-
255
- <Card>
256
- <CardHeader>Preview Options</CardHeader>
257
- <CardContent className="space-y-4">
258
- <Select value={size} onValueChange={value => setSize(value as PreviewPreset)}>
259
- <SelectTrigger>
260
- <SelectValue placeholder="Select size" />
261
- </SelectTrigger>
262
- <SelectContent>
263
- <SelectItem value="tiny">Tiny</SelectItem>
264
- <SelectItem value="thumb">Thumb</SelectItem>
265
- <SelectItem value="small">Small</SelectItem>
266
- <SelectItem value="medium">Medium</SelectItem>
267
- <SelectItem value="large">Large</SelectItem>
268
- <SelectItem value="full">Full Size</SelectItem>
269
- </SelectContent>
270
- </Select>
271
- <p className="text-sm text-muted-foreground">
272
- {width} x {height}
273
- </p>
274
- </CardContent>
275
- </Card>
276
- </div>
277
-
278
- <div className="relative flex items-center justify-center bg-muted/30 rounded-lg">
279
- {assets && assets.length > 1 && (
280
- <>
281
- <Button
282
- variant="ghost"
283
- size="icon"
284
- className="absolute left-4 z-10"
285
- onClick={() => setAssetIndex(i => i - 1)}
286
- disabled={assetIndex === 0}
287
- >
288
- <ChevronLeft className="h-4 w-4" />
289
- </Button>
290
- <Button
291
- variant="ghost"
292
- size="icon"
293
- className="absolute right-4 z-10"
294
- onClick={() => setAssetIndex(i => i + 1)}
295
- disabled={assetIndex === assets.length - 1}
296
- >
297
- <ChevronRight className="h-4 w-4" />
298
- </Button>
299
- </>
300
- )}
301
-
302
- <div
303
- ref={containerRef}
304
- className={cn(
305
- 'relative',
306
- centered && 'flex items-center justify-center',
307
- settingFocalPoint && 'cursor-crosshair',
308
- )}
309
- >
310
- <div className="relative" style={{ width: `${width}px`, height: `${height}px` }}>
311
- <VendureImage
312
- ref={imageRef}
313
- asset={activeAsset}
314
- preset={size || undefined}
315
- mode="resize"
316
- onLoad={updateDimensions}
317
- className="max-w-full max-h-full object-contain"
318
- />
319
- {settingFocalPoint && lastFocalPoint && (
320
- <FocalPointControl
321
- width={width}
322
- height={height}
323
- point={lastFocalPoint}
324
- onChange={handleFocalPointChange}
325
- />
326
- )}
327
- </div>
328
-
329
- {settingFocalPoint && (
330
- <div className="absolute bottom-4 left-1/2 -translate-x-1/2 flex gap-2">
331
- <Button variant="secondary" onClick={handleFocalPointCancel}>
332
- <X className="mr-2 h-4 w-4" />
333
- Cancel
334
- </Button>
335
- <Button onClick={handleFocalPointSet}>
336
- <Crosshair className="mr-2 h-4 w-4" />
337
- Set Focal Point
338
- </Button>
339
- </div>
340
- )}
341
- </div>
342
- </div>
343
- </div>
344
- );
345
- }
@@ -1,181 +0,0 @@
1
- import { Options, parse, transform } from '@swc/core';
2
- import { BindingIdentifier, ModuleItem, Pattern, Statement } from '@swc/types';
3
- import { VendureConfig } from '@vendure/core';
4
- import fs from 'fs-extra';
5
- import path from 'path';
6
- import { pathToFileURL } from 'url';
7
-
8
- export interface ConfigLoaderOptions {
9
- vendureConfigPath: string;
10
- tempDir: string;
11
- vendureConfigExport?: string;
12
- }
13
-
14
- /**
15
- * @description
16
- * This function compiles the given Vendure config file and any imported relative files (i.e.
17
- * project files, not npm packages) into a temporary directory, and returns the compiled config.
18
- *
19
- * The reason we need to do this is that Vendure code makes use of TypeScript experimental decorators
20
- * (e.g. for NestJS decorators and TypeORM column decorators) which are not supported by esbuild.
21
- *
22
- * In Vite, when we load some TypeScript into the top-level Vite config file (in the end-user project), Vite
23
- * internally uses esbuild to temporarily compile that TypeScript code. Unfortunately, esbuild does not support
24
- * these experimental decorators, errors will be thrown as soon as e.g. a TypeORM column decorator is encountered.
25
- *
26
- * To work around this, we compile the Vendure config file and all its imports using SWC, which does support
27
- * these experimental decorators. The compiled files are then loaded by Vite, which is able to handle the compiled
28
- * JavaScript output.
29
- */
30
- export async function loadVendureConfig(
31
- options: ConfigLoaderOptions,
32
- ): Promise<{ vendureConfig: VendureConfig; exportedSymbolName: string }> {
33
- const { vendureConfigPath, vendureConfigExport, tempDir } = options;
34
- const outputPath = tempDir;
35
- const configFileName = path.basename(vendureConfigPath);
36
- const inputRootDir = path.dirname(vendureConfigPath);
37
- await fs.remove(outputPath);
38
- await compileFile(inputRootDir, vendureConfigPath, outputPath);
39
- const compiledConfigFilePath = pathToFileURL(path.join(outputPath, configFileName)).href.replace(
40
- /.ts$/,
41
- '.js',
42
- );
43
- // create package.json with type commonjs and save it to the output dir
44
- await fs.writeFile(path.join(outputPath, 'package.json'), JSON.stringify({ type: 'commonjs' }, null, 2));
45
-
46
- // We need to figure out the symbol exported by the config file by
47
- // analyzing the AST and finding an export with the type "VendureConfig"
48
- const ast = await parse(await fs.readFile(vendureConfigPath, 'utf-8'), {
49
- syntax: 'typescript',
50
- decorators: true,
51
- });
52
- const detectedExportedSymbolName = findConfigExport(ast.body);
53
- const configExportedSymbolName = detectedExportedSymbolName || vendureConfigExport;
54
- if (!configExportedSymbolName) {
55
- throw new Error(
56
- `Could not find a variable exported as VendureConfig. Please specify the name of the exported variable using the "vendureConfigExport" option.`,
57
- );
58
- }
59
- const config = await import(compiledConfigFilePath).then(m => m[configExportedSymbolName]);
60
- if (!config) {
61
- throw new Error(
62
- `Could not find a variable exported as VendureConfig with the name "${configExportedSymbolName}".`,
63
- );
64
- }
65
- return { vendureConfig: config, exportedSymbolName: configExportedSymbolName };
66
- }
67
-
68
- /**
69
- * Given the AST of a TypeScript file, finds the name of the variable exported as VendureConfig.
70
- */
71
- function findConfigExport(statements: ModuleItem[]): string | undefined {
72
- for (const statement of statements) {
73
- if (statement.type === 'ExportDeclaration') {
74
- if (statement.declaration.type === 'VariableDeclaration') {
75
- for (const declaration of statement.declaration.declarations) {
76
- if (isBindingIdentifier(declaration.id)) {
77
- const typeRef = declaration.id.typeAnnotation?.typeAnnotation;
78
- if (typeRef?.type === 'TsTypeReference') {
79
- if (
80
- typeRef.typeName.type === 'Identifier' &&
81
- typeRef.typeName.value === 'VendureConfig'
82
- ) {
83
- return declaration.id.value;
84
- }
85
- }
86
- }
87
- }
88
- }
89
- }
90
- }
91
- return undefined;
92
- }
93
-
94
- function isBindingIdentifier(id: Pattern): id is BindingIdentifier {
95
- return id.type === 'Identifier' && !!(id as BindingIdentifier).typeAnnotation;
96
- }
97
-
98
- export async function compileFile(
99
- inputRootDir: string,
100
- inputPath: string,
101
- outputDir: string,
102
- compiledFiles = new Set<string>(),
103
- ): Promise<void> {
104
- if (compiledFiles.has(inputPath)) {
105
- return;
106
- }
107
- compiledFiles.add(inputPath);
108
-
109
- // Ensure output directory exists
110
- await fs.ensureDir(outputDir);
111
-
112
- // Read the source file
113
- const source = await fs.readFile(inputPath, 'utf-8');
114
-
115
- // Transform config
116
- const config: Options = {
117
- filename: inputPath,
118
- sourceMaps: true,
119
- jsc: {
120
- parser: {
121
- syntax: 'typescript',
122
- tsx: false,
123
- decorators: true,
124
- },
125
- target: 'es2020',
126
- loose: false,
127
- transform: {
128
- legacyDecorator: true,
129
- decoratorMetadata: true,
130
- },
131
- },
132
- module: {
133
- type: 'commonjs',
134
- strict: true,
135
- strictMode: true,
136
- lazy: false,
137
- noInterop: false,
138
- },
139
- };
140
-
141
- // Transform the code using SWC
142
- const result = await transform(source, config);
143
-
144
- // Generate output file path
145
- const relativePath = path.relative(inputRootDir, inputPath);
146
- const outputPath = path.join(outputDir, relativePath).replace(/\.ts$/, '.js');
147
-
148
- // Ensure the subdirectory for the output file exists
149
- await fs.ensureDir(path.dirname(outputPath));
150
-
151
- // Write the transformed code
152
- await fs.writeFile(outputPath, result.code);
153
-
154
- // Write source map if available
155
- if (result.map) {
156
- await fs.writeFile(`${outputPath}.map`, JSON.stringify(result.map));
157
- }
158
-
159
- // Parse the source to find relative imports
160
- const ast = await parse(source, { syntax: 'typescript', decorators: true });
161
- const importPaths = new Set<string>();
162
-
163
- function collectImports(node: any) {
164
- if (node.type === 'ImportDeclaration' && node.source.value.startsWith('.')) {
165
- const importPath = path.resolve(path.dirname(inputPath), node.source.value);
166
- importPaths.add(importPath + '.ts');
167
- }
168
- for (const key in node) {
169
- if (node[key] && typeof node[key] === 'object') {
170
- collectImports(node[key]);
171
- }
172
- }
173
- }
174
-
175
- collectImports(ast);
176
-
177
- // Recursively compile all relative imports
178
- for (const importPath of importPaths) {
179
- await compileFile(inputRootDir, importPath, outputDir, compiledFiles);
180
- }
181
- }