Ver código fonte

fix(dashboard): Correctly handle object-type dashboard reference

Michael Bromley 3 meses atrás
pai
commit
e4c1dab678

+ 6 - 0
packages/dashboard/vite/tests/fixtures-with-translations/package.json

@@ -0,0 +1,6 @@
+{
+    "type": "commonjs",
+    "name": "with-translations",
+    "version": "0.0.1",
+    "main": "index.ts"
+}

+ 8 - 0
packages/dashboard/vite/tests/fixtures-with-translations/src/my.plugin.ts

@@ -0,0 +1,8 @@
+import { PluginCommonModule, VendurePlugin } from '@vendure/core';
+
+@VendurePlugin({
+    imports: [PluginCommonModule],
+    providers: [],
+    dashboard: { location: './dashboard/index.tsx' },
+})
+export class MyPlugin {}

+ 19 - 0
packages/dashboard/vite/tests/fixtures-with-translations/vendure-config.ts

@@ -0,0 +1,19 @@
+import { VendureConfig } from '@vendure/core';
+
+import { MyPlugin } from './src/my.plugin';
+
+export const config: VendureConfig = {
+    apiOptions: {
+        port: 3000,
+    },
+    authOptions: {
+        tokenMethod: 'bearer',
+    },
+    dbConnectionOptions: {
+        type: 'postgres',
+    },
+    paymentOptions: {
+        paymentMethodHandlers: [],
+    },
+    plugins: [MyPlugin],
+};

+ 26 - 0
packages/dashboard/vite/tests/with-translations.spec.ts

@@ -0,0 +1,26 @@
+import { rm } from 'node:fs/promises';
+import { join } from 'node:path';
+import { describe, expect, it } from 'vitest';
+
+import { compile } from '../utils/compiler.js';
+import { debugLogger, noopLogger } from '../utils/logger.js';
+
+describe('detecting plugins with translations', () => {
+    it('should detect plugins with translations', { timeout: 60_000 }, async () => {
+        const tempDir = join(__dirname, './__temp/with-translations');
+        await rm(tempDir, { recursive: true, force: true });
+        const result = await compile({
+            outputPath: tempDir,
+            vendureConfigPath: join(__dirname, 'fixtures-with-translations', 'vendure-config.ts'),
+            logger: process.env.LOG ? debugLogger : noopLogger,
+        });
+
+        expect(result.pluginInfo).toHaveLength(1);
+        expect(result.pluginInfo[0].name).toBe('MyPlugin');
+        expect(result.pluginInfo[0].dashboardEntryPath).toBe('./dashboard/index.tsx');
+        expect(result.pluginInfo[0].sourcePluginPath).toBe(
+            join(__dirname, 'fixtures-with-translations', 'src', 'my.plugin.ts'),
+        );
+        expect(result.pluginInfo[0].pluginPath).toBe(join(tempDir, 'src', 'my.plugin.js'));
+    });
+});

+ 15 - 5
packages/dashboard/vite/utils/plugin-discovery.ts

@@ -83,11 +83,21 @@ export async function discoverPlugins({
                             for (const decorator of decorators.elements) {
                                 const props = getDecoratorObjectProps(decorator);
                                 for (const prop of props) {
-                                    const isDashboardProd =
-                                        prop.key.name === 'dashboard' && prop.value.type === 'Literal';
-                                    if (isDashboardProd) {
-                                        dashboardPath = prop.value.value;
-                                        hasVendurePlugin = true;
+                                    if (prop.key.name === 'dashboard') {
+                                        if (prop.value.type === 'Literal') {
+                                            // Handle string format: dashboard: './path/to/dashboard'
+                                            dashboardPath = prop.value.value;
+                                            hasVendurePlugin = true;
+                                        } else if (prop.value.type === 'ObjectExpression') {
+                                            // Handle object format: dashboard: { location: './path/to/dashboard' }
+                                            const locationProp = prop.value.properties?.find(
+                                                (p: any) => p.key?.name === 'location',
+                                            );
+                                            if (locationProp && locationProp.value.type === 'Literal') {
+                                                dashboardPath = locationProp.value.value;
+                                                hasVendurePlugin = true;
+                                            }
+                                        }
                                     }
                                 }
                             }