@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.
- package/dist/plugin/utils/ast-utils.d.ts +10 -0
- package/dist/plugin/utils/ast-utils.js +96 -0
- package/dist/plugin/utils/ast-utils.spec.d.ts +1 -0
- package/dist/plugin/utils/ast-utils.spec.js +120 -0
- package/dist/plugin/{config-loader.d.ts → utils/config-loader.d.ts} +22 -8
- package/dist/plugin/utils/config-loader.js +325 -0
- package/dist/plugin/{schema-generator.d.ts → utils/schema-generator.d.ts} +5 -0
- package/dist/plugin/{schema-generator.js → utils/schema-generator.js} +6 -0
- package/dist/plugin/{ui-config.js → utils/ui-config.js} +2 -2
- package/dist/plugin/vite-plugin-admin-api-schema.js +2 -2
- package/dist/plugin/vite-plugin-config-loader.d.ts +2 -3
- package/dist/plugin/vite-plugin-config-loader.js +18 -9
- package/dist/plugin/vite-plugin-dashboard-metadata.js +12 -14
- package/dist/plugin/vite-plugin-gql-tada.js +2 -2
- package/dist/plugin/vite-plugin-ui-config.js +3 -2
- package/package.json +8 -6
- package/src/app/app-providers.tsx +8 -8
- package/src/app/main.tsx +1 -1
- package/src/app/routes/_authenticated/_assets/assets.graphql.ts +26 -0
- package/src/app/routes/_authenticated/_assets/assets.tsx +2 -2
- package/src/app/routes/_authenticated/_assets/assets_.$id.tsx +156 -0
- package/src/app/routes/_authenticated/_orders/components/customer-address-selector.tsx +104 -0
- package/src/app/routes/_authenticated/_orders/components/edit-order-table.tsx +228 -0
- package/src/app/routes/_authenticated/_orders/components/money-gross-net.tsx +18 -0
- package/src/app/routes/_authenticated/_orders/components/order-address.tsx +2 -1
- package/src/app/routes/_authenticated/_orders/components/order-line-custom-fields-form.tsx +38 -0
- package/src/app/routes/_authenticated/_orders/components/order-table-totals.tsx +53 -0
- package/src/app/routes/_authenticated/_orders/components/order-table.tsx +8 -49
- package/src/app/routes/_authenticated/_orders/components/shipping-method-selector.tsx +65 -0
- package/src/app/routes/_authenticated/_orders/orders.graphql.ts +187 -1
- package/src/app/routes/_authenticated/_orders/orders.tsx +39 -18
- package/src/app/routes/_authenticated/_orders/orders_.$id.tsx +31 -9
- package/src/app/routes/_authenticated/_orders/orders_.draft.$id.tsx +418 -0
- package/src/app/routes/_authenticated/_products/products.tsx +1 -1
- package/src/app/routes/_authenticated.tsx +12 -1
- package/src/lib/components/data-table/add-filter-menu.tsx +61 -0
- package/src/lib/components/data-table/data-table-column-header.tsx +0 -13
- package/src/lib/components/data-table/data-table-filter-badge.tsx +75 -0
- package/src/lib/components/data-table/data-table-filter-dialog.tsx +27 -28
- package/src/lib/components/data-table/data-table-types.ts +1 -0
- package/src/lib/components/data-table/data-table-view-options.tsx +72 -23
- package/src/lib/components/data-table/data-table.tsx +23 -24
- package/src/lib/components/data-table/filters/data-table-boolean-filter.tsx +57 -0
- package/src/lib/components/data-table/filters/data-table-datetime-filter.tsx +93 -0
- package/src/lib/components/data-table/filters/data-table-id-filter.tsx +58 -0
- package/src/lib/components/data-table/filters/data-table-number-filter.tsx +119 -0
- package/src/lib/components/data-table/filters/data-table-string-filter.tsx +62 -0
- package/src/lib/components/data-table/human-readable-operator.tsx +65 -0
- package/src/lib/components/layout/nav-user.tsx +4 -4
- package/src/lib/components/shared/asset/asset-focal-point-editor.tsx +93 -0
- package/src/lib/components/shared/{asset-gallery.tsx → asset/asset-gallery.tsx} +51 -20
- package/src/lib/components/shared/{asset-picker-dialog.tsx → asset/asset-picker-dialog.tsx} +1 -1
- package/src/lib/components/shared/{asset-preview-dialog.tsx → asset/asset-preview-dialog.tsx} +1 -7
- package/src/lib/components/shared/asset/asset-preview-selector.tsx +34 -0
- package/src/lib/components/shared/asset/asset-preview.tsx +128 -0
- package/src/lib/components/shared/asset/asset-properties.tsx +46 -0
- package/src/lib/components/shared/{focal-point-control.tsx → asset/focal-point-control.tsx} +1 -1
- package/src/lib/components/shared/custom-fields-form.tsx +4 -3
- package/src/lib/components/shared/customer-selector.tsx +13 -14
- package/src/lib/components/shared/detail-page-button.tsx +2 -2
- package/src/lib/components/shared/entity-assets.tsx +3 -3
- package/src/lib/components/shared/navigation-confirmation.tsx +39 -0
- package/src/lib/components/shared/paginated-list-data-table.tsx +9 -1
- package/src/lib/components/shared/product-variant-selector.tsx +111 -0
- package/src/lib/components/shared/vendure-image.tsx +1 -1
- package/src/lib/components/ui/calendar.tsx +508 -63
- package/src/lib/framework/document-introspection/get-document-structure.spec.ts +113 -3
- package/src/lib/framework/document-introspection/get-document-structure.ts +70 -11
- package/src/lib/framework/form-engine/use-generated-form.tsx +8 -7
- package/src/lib/framework/layout-engine/page-layout.tsx +4 -0
- package/src/lib/framework/page/list-page.tsx +23 -4
- package/src/lib/framework/page/use-detail-page.ts +1 -0
- package/src/lib/graphql/fragments.tsx +8 -0
- package/src/lib/index.ts +5 -5
- package/src/lib/providers/auth.tsx +12 -9
- package/src/lib/providers/channel-provider.tsx +1 -0
- package/src/lib/providers/server-config.tsx +7 -1
- package/src/lib/providers/user-settings.tsx +24 -0
- package/vite/utils/ast-utils.spec.ts +128 -0
- package/vite/utils/ast-utils.ts +119 -0
- package/vite/utils/config-loader.ts +410 -0
- package/vite/{schema-generator.ts → utils/schema-generator.ts} +7 -1
- package/vite/{ui-config.ts → utils/ui-config.ts} +2 -2
- package/vite/vite-plugin-admin-api-schema.ts +2 -2
- package/vite/vite-plugin-config-loader.ts +25 -13
- package/vite/vite-plugin-dashboard-metadata.ts +19 -15
- package/vite/vite-plugin-gql-tada.ts +2 -2
- package/vite/vite-plugin-ui-config.ts +3 -2
- package/dist/plugin/config-loader.js +0 -141
- package/src/lib/components/shared/asset-preview.tsx +0 -345
- package/vite/config-loader.ts +0 -181
- /package/dist/plugin/{ui-config.d.ts → utils/ui-config.d.ts} +0 -0
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
import { AdminUiConfig } from '@vendure/common/lib/shared-types';
|
|
7
7
|
import { VendureConfig } from '@vendure/core';
|
|
8
8
|
|
|
9
|
-
import { defaultAvailableLocales } from '
|
|
10
|
-
import { defaultLocale, defaultLanguage, defaultAvailableLanguages } from '
|
|
9
|
+
import { defaultAvailableLocales } from '../constants.js';
|
|
10
|
+
import { defaultLocale, defaultLanguage, defaultAvailableLanguages } from '../constants.js';
|
|
11
11
|
|
|
12
12
|
export function getAdminUiConfig(
|
|
13
13
|
config: VendureConfig,
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
} from 'graphql';
|
|
22
22
|
import { Plugin } from 'vite';
|
|
23
23
|
|
|
24
|
-
import { generateSchema } from './schema-generator.js';
|
|
24
|
+
import { generateSchema } from './utils/schema-generator.js';
|
|
25
25
|
import { ConfigLoaderApi, getConfigLoaderApi } from './vite-plugin-config-loader.js';
|
|
26
26
|
|
|
27
27
|
export type FieldInfoTuple = readonly [
|
|
@@ -61,7 +61,7 @@ export function adminApiSchemaPlugin(): Plugin {
|
|
|
61
61
|
configLoaderApi = getConfigLoaderApi(plugins);
|
|
62
62
|
},
|
|
63
63
|
async buildStart() {
|
|
64
|
-
const vendureConfig = await configLoaderApi.getVendureConfig();
|
|
64
|
+
const { vendureConfig } = await configLoaderApi.getVendureConfig();
|
|
65
65
|
if (!schemaInfo) {
|
|
66
66
|
const safeSchema = await generateSchema({ vendureConfig });
|
|
67
67
|
schemaInfo = generateSchemaInfo(safeSchema);
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { VendureConfig } from '@vendure/core';
|
|
2
1
|
import { Plugin } from 'vite';
|
|
3
2
|
|
|
4
|
-
import { ConfigLoaderOptions, loadVendureConfig } from './config-loader.js';
|
|
3
|
+
import { ConfigLoaderOptions, loadVendureConfig, LoadVendureConfigResult } from './utils/config-loader.js';
|
|
5
4
|
|
|
6
5
|
export interface ConfigLoaderApi {
|
|
7
|
-
getVendureConfig(): Promise<
|
|
6
|
+
getVendureConfig(): Promise<LoadVendureConfigResult>;
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
export const configLoaderName = 'vendure:config-loader';
|
|
@@ -14,20 +13,33 @@ export const configLoaderName = 'vendure:config-loader';
|
|
|
14
13
|
* makes it available to other plugins via the `ConfigLoaderApi`.
|
|
15
14
|
*/
|
|
16
15
|
export function configLoaderPlugin(options: ConfigLoaderOptions): Plugin {
|
|
17
|
-
let
|
|
16
|
+
let result: LoadVendureConfigResult;
|
|
18
17
|
const onConfigLoaded: Array<() => void> = [];
|
|
19
18
|
return {
|
|
20
19
|
name: configLoaderName,
|
|
21
20
|
async buildStart() {
|
|
22
|
-
this.info(
|
|
21
|
+
this.info(
|
|
22
|
+
`Loading Vendure config. This can take a short while depending on the size of your project...`,
|
|
23
|
+
);
|
|
23
24
|
try {
|
|
24
|
-
const
|
|
25
|
+
const startTime = Date.now();
|
|
26
|
+
result = await loadVendureConfig({
|
|
25
27
|
tempDir: options.tempDir,
|
|
26
28
|
vendureConfigPath: options.vendureConfigPath,
|
|
27
29
|
vendureConfigExport: options.vendureConfigExport,
|
|
30
|
+
logger: {
|
|
31
|
+
info: (message: string) => this.info(message),
|
|
32
|
+
warn: (message: string) => this.warn(message),
|
|
33
|
+
debug: (message: string) => this.debug(message),
|
|
34
|
+
},
|
|
28
35
|
});
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
const endTime = Date.now();
|
|
37
|
+
const duration = endTime - startTime;
|
|
38
|
+
const pluginNames = result.pluginInfo.map(p => p.name).join(', ');
|
|
39
|
+
this.info(`Found ${result.pluginInfo.length} plugins: ${pluginNames}`);
|
|
40
|
+
this.info(
|
|
41
|
+
`Vendure config loaded (using export "${result.exportedSymbolName}") in ${duration}ms`,
|
|
42
|
+
);
|
|
31
43
|
} catch (e: unknown) {
|
|
32
44
|
if (e instanceof Error) {
|
|
33
45
|
this.error(`Error loading Vendure config: ${e.message}`);
|
|
@@ -36,13 +48,13 @@ export function configLoaderPlugin(options: ConfigLoaderOptions): Plugin {
|
|
|
36
48
|
onConfigLoaded.forEach(fn => fn());
|
|
37
49
|
},
|
|
38
50
|
api: {
|
|
39
|
-
getVendureConfig(): Promise<
|
|
40
|
-
if (
|
|
41
|
-
return Promise.resolve(
|
|
51
|
+
getVendureConfig(): Promise<LoadVendureConfigResult> {
|
|
52
|
+
if (result) {
|
|
53
|
+
return Promise.resolve(result);
|
|
42
54
|
} else {
|
|
43
|
-
return new Promise<
|
|
55
|
+
return new Promise<LoadVendureConfigResult>(resolve => {
|
|
44
56
|
onConfigLoaded.push(() => {
|
|
45
|
-
resolve(
|
|
57
|
+
resolve(result);
|
|
46
58
|
});
|
|
47
59
|
});
|
|
48
60
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { VendureConfig } from '@vendure/core';
|
|
2
|
-
import { getPluginDashboardExtensions } from '@vendure/core';
|
|
3
1
|
import path from 'path';
|
|
4
2
|
import { Plugin } from 'vite';
|
|
5
3
|
|
|
4
|
+
import { LoadVendureConfigResult } from './utils/config-loader.js';
|
|
6
5
|
import { ConfigLoaderApi, getConfigLoaderApi } from './vite-plugin-config-loader.js';
|
|
7
6
|
|
|
8
7
|
const virtualModuleId = 'virtual:dashboard-extensions';
|
|
@@ -15,7 +14,7 @@ const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
|
15
14
|
*/
|
|
16
15
|
export function dashboardMetadataPlugin(options: { rootDir: string }): Plugin {
|
|
17
16
|
let configLoaderApi: ConfigLoaderApi;
|
|
18
|
-
let
|
|
17
|
+
let loadVendureConfigResult: LoadVendureConfigResult;
|
|
19
18
|
return {
|
|
20
19
|
name: 'vendure:dashboard-extensions-metadata',
|
|
21
20
|
configResolved({ plugins }) {
|
|
@@ -28,22 +27,27 @@ export function dashboardMetadataPlugin(options: { rootDir: string }): Plugin {
|
|
|
28
27
|
},
|
|
29
28
|
async load(id) {
|
|
30
29
|
if (id === resolvedVirtualModuleId) {
|
|
31
|
-
if (!
|
|
32
|
-
|
|
30
|
+
if (!loadVendureConfigResult) {
|
|
31
|
+
loadVendureConfigResult = await configLoaderApi.getVendureConfig();
|
|
33
32
|
}
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
const { pluginInfo } = loadVendureConfigResult;
|
|
34
|
+
const pluginsWithExtensions =
|
|
35
|
+
pluginInfo
|
|
36
|
+
?.map(
|
|
37
|
+
({ dashboardEntryPath, pluginPath }) =>
|
|
38
|
+
dashboardEntryPath && path.join(pluginPath, dashboardEntryPath),
|
|
39
|
+
)
|
|
40
|
+
.filter(x => x != null) ?? [];
|
|
40
41
|
|
|
41
|
-
this.info(`Found ${
|
|
42
|
+
this.info(`Found ${pluginsWithExtensions.length} Dashboard extensions`);
|
|
42
43
|
return `
|
|
43
44
|
export async function runDashboardExtensions() {
|
|
44
|
-
${
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
${pluginsWithExtensions
|
|
46
|
+
.map(extension => {
|
|
47
|
+
return `await import('${extension}');`;
|
|
48
|
+
})
|
|
49
|
+
.join('\n')}
|
|
50
|
+
}`;
|
|
47
51
|
}
|
|
48
52
|
},
|
|
49
53
|
};
|
|
@@ -4,7 +4,7 @@ import { printSchema } from 'graphql';
|
|
|
4
4
|
import * as path from 'path';
|
|
5
5
|
import { Plugin } from 'vite';
|
|
6
6
|
|
|
7
|
-
import { generateSchema } from './schema-generator.js';
|
|
7
|
+
import { generateSchema } from './utils/schema-generator.js';
|
|
8
8
|
import { ConfigLoaderApi, getConfigLoaderApi } from './vite-plugin-config-loader.js';
|
|
9
9
|
|
|
10
10
|
export function gqlTadaPlugin(options: {
|
|
@@ -20,7 +20,7 @@ export function gqlTadaPlugin(options: {
|
|
|
20
20
|
configLoaderApi = getConfigLoaderApi(plugins);
|
|
21
21
|
},
|
|
22
22
|
async buildStart() {
|
|
23
|
-
const vendureConfig = await configLoaderApi.getVendureConfig();
|
|
23
|
+
const { vendureConfig } = await configLoaderApi.getVendureConfig();
|
|
24
24
|
const safeSchema = await generateSchema({ vendureConfig });
|
|
25
25
|
|
|
26
26
|
const tsConfigContent = {
|
|
@@ -2,7 +2,7 @@ import { AdminUiConfig, VendureConfig } from '@vendure/core';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { Plugin } from 'vite';
|
|
4
4
|
|
|
5
|
-
import { getAdminUiConfig } from './ui-config.js';
|
|
5
|
+
import { getAdminUiConfig } from './utils/ui-config.js';
|
|
6
6
|
import { ConfigLoaderApi, getConfigLoaderApi } from './vite-plugin-config-loader.js';
|
|
7
7
|
|
|
8
8
|
const virtualModuleId = 'virtual:vendure-ui-config';
|
|
@@ -38,7 +38,8 @@ export function uiConfigPlugin({ adminUiConfig }: UiConfigPluginOptions): Plugin
|
|
|
38
38
|
async load(id) {
|
|
39
39
|
if (id === resolvedVirtualModuleId) {
|
|
40
40
|
if (!vendureConfig) {
|
|
41
|
-
|
|
41
|
+
const result = await configLoaderApi.getVendureConfig();
|
|
42
|
+
vendureConfig = result.vendureConfig;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
const config = getAdminUiConfig(vendureConfig, adminUiConfig);
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { parse, transform } from '@swc/core';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { pathToFileURL } from 'url';
|
|
5
|
-
/**
|
|
6
|
-
* @description
|
|
7
|
-
* This function compiles the given Vendure config file and any imported relative files (i.e.
|
|
8
|
-
* project files, not npm packages) into a temporary directory, and returns the compiled config.
|
|
9
|
-
*
|
|
10
|
-
* The reason we need to do this is that Vendure code makes use of TypeScript experimental decorators
|
|
11
|
-
* (e.g. for NestJS decorators and TypeORM column decorators) which are not supported by esbuild.
|
|
12
|
-
*
|
|
13
|
-
* In Vite, when we load some TypeScript into the top-level Vite config file (in the end-user project), Vite
|
|
14
|
-
* internally uses esbuild to temporarily compile that TypeScript code. Unfortunately, esbuild does not support
|
|
15
|
-
* these experimental decorators, errors will be thrown as soon as e.g. a TypeORM column decorator is encountered.
|
|
16
|
-
*
|
|
17
|
-
* To work around this, we compile the Vendure config file and all its imports using SWC, which does support
|
|
18
|
-
* these experimental decorators. The compiled files are then loaded by Vite, which is able to handle the compiled
|
|
19
|
-
* JavaScript output.
|
|
20
|
-
*/
|
|
21
|
-
export async function loadVendureConfig(options) {
|
|
22
|
-
const { vendureConfigPath, vendureConfigExport, tempDir } = options;
|
|
23
|
-
const outputPath = tempDir;
|
|
24
|
-
const configFileName = path.basename(vendureConfigPath);
|
|
25
|
-
const inputRootDir = path.dirname(vendureConfigPath);
|
|
26
|
-
await fs.remove(outputPath);
|
|
27
|
-
await compileFile(inputRootDir, vendureConfigPath, outputPath);
|
|
28
|
-
const compiledConfigFilePath = pathToFileURL(path.join(outputPath, configFileName)).href.replace(/.ts$/, '.js');
|
|
29
|
-
// create package.json with type commonjs and save it to the output dir
|
|
30
|
-
await fs.writeFile(path.join(outputPath, 'package.json'), JSON.stringify({ type: 'commonjs' }, null, 2));
|
|
31
|
-
// We need to figure out the symbol exported by the config file by
|
|
32
|
-
// analyzing the AST and finding an export with the type "VendureConfig"
|
|
33
|
-
const ast = await parse(await fs.readFile(vendureConfigPath, 'utf-8'), {
|
|
34
|
-
syntax: 'typescript',
|
|
35
|
-
decorators: true,
|
|
36
|
-
});
|
|
37
|
-
const detectedExportedSymbolName = findConfigExport(ast.body);
|
|
38
|
-
const configExportedSymbolName = detectedExportedSymbolName || vendureConfigExport;
|
|
39
|
-
if (!configExportedSymbolName) {
|
|
40
|
-
throw new Error(`Could not find a variable exported as VendureConfig. Please specify the name of the exported variable using the "vendureConfigExport" option.`);
|
|
41
|
-
}
|
|
42
|
-
const config = await import(compiledConfigFilePath).then(m => m[configExportedSymbolName]);
|
|
43
|
-
if (!config) {
|
|
44
|
-
throw new Error(`Could not find a variable exported as VendureConfig with the name "${configExportedSymbolName}".`);
|
|
45
|
-
}
|
|
46
|
-
return { vendureConfig: config, exportedSymbolName: configExportedSymbolName };
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Given the AST of a TypeScript file, finds the name of the variable exported as VendureConfig.
|
|
50
|
-
*/
|
|
51
|
-
function findConfigExport(statements) {
|
|
52
|
-
var _a;
|
|
53
|
-
for (const statement of statements) {
|
|
54
|
-
if (statement.type === 'ExportDeclaration') {
|
|
55
|
-
if (statement.declaration.type === 'VariableDeclaration') {
|
|
56
|
-
for (const declaration of statement.declaration.declarations) {
|
|
57
|
-
if (isBindingIdentifier(declaration.id)) {
|
|
58
|
-
const typeRef = (_a = declaration.id.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeAnnotation;
|
|
59
|
-
if ((typeRef === null || typeRef === void 0 ? void 0 : typeRef.type) === 'TsTypeReference') {
|
|
60
|
-
if (typeRef.typeName.type === 'Identifier' &&
|
|
61
|
-
typeRef.typeName.value === 'VendureConfig') {
|
|
62
|
-
return declaration.id.value;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
function isBindingIdentifier(id) {
|
|
73
|
-
return id.type === 'Identifier' && !!id.typeAnnotation;
|
|
74
|
-
}
|
|
75
|
-
export async function compileFile(inputRootDir, inputPath, outputDir, compiledFiles = new Set()) {
|
|
76
|
-
if (compiledFiles.has(inputPath)) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
compiledFiles.add(inputPath);
|
|
80
|
-
// Ensure output directory exists
|
|
81
|
-
await fs.ensureDir(outputDir);
|
|
82
|
-
// Read the source file
|
|
83
|
-
const source = await fs.readFile(inputPath, 'utf-8');
|
|
84
|
-
// Transform config
|
|
85
|
-
const config = {
|
|
86
|
-
filename: inputPath,
|
|
87
|
-
sourceMaps: true,
|
|
88
|
-
jsc: {
|
|
89
|
-
parser: {
|
|
90
|
-
syntax: 'typescript',
|
|
91
|
-
tsx: false,
|
|
92
|
-
decorators: true,
|
|
93
|
-
},
|
|
94
|
-
target: 'es2020',
|
|
95
|
-
loose: false,
|
|
96
|
-
transform: {
|
|
97
|
-
legacyDecorator: true,
|
|
98
|
-
decoratorMetadata: true,
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
module: {
|
|
102
|
-
type: 'commonjs',
|
|
103
|
-
strict: true,
|
|
104
|
-
strictMode: true,
|
|
105
|
-
lazy: false,
|
|
106
|
-
noInterop: false,
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
// Transform the code using SWC
|
|
110
|
-
const result = await transform(source, config);
|
|
111
|
-
// Generate output file path
|
|
112
|
-
const relativePath = path.relative(inputRootDir, inputPath);
|
|
113
|
-
const outputPath = path.join(outputDir, relativePath).replace(/\.ts$/, '.js');
|
|
114
|
-
// Ensure the subdirectory for the output file exists
|
|
115
|
-
await fs.ensureDir(path.dirname(outputPath));
|
|
116
|
-
// Write the transformed code
|
|
117
|
-
await fs.writeFile(outputPath, result.code);
|
|
118
|
-
// Write source map if available
|
|
119
|
-
if (result.map) {
|
|
120
|
-
await fs.writeFile(`${outputPath}.map`, JSON.stringify(result.map));
|
|
121
|
-
}
|
|
122
|
-
// Parse the source to find relative imports
|
|
123
|
-
const ast = await parse(source, { syntax: 'typescript', decorators: true });
|
|
124
|
-
const importPaths = new Set();
|
|
125
|
-
function collectImports(node) {
|
|
126
|
-
if (node.type === 'ImportDeclaration' && node.source.value.startsWith('.')) {
|
|
127
|
-
const importPath = path.resolve(path.dirname(inputPath), node.source.value);
|
|
128
|
-
importPaths.add(importPath + '.ts');
|
|
129
|
-
}
|
|
130
|
-
for (const key in node) {
|
|
131
|
-
if (node[key] && typeof node[key] === 'object') {
|
|
132
|
-
collectImports(node[key]);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
collectImports(ast);
|
|
137
|
-
// Recursively compile all relative imports
|
|
138
|
-
for (const importPath of importPaths) {
|
|
139
|
-
await compileFile(inputRootDir, importPath, outputDir, compiledFiles);
|
|
140
|
-
}
|
|
141
|
-
}
|