Kaynağa Gözat

test: Dashboard plugin detection with pnpm

Oliver Streisselberger 19 saat önce
ebeveyn
işleme
03a7108033

+ 1 - 0
packages/dashboard/vite/tests/fixtures-pnpm-plugin/fake_node_modules/test-plugin

@@ -0,0 +1 @@
+.pnpm/test-plugin@1.0.0/node_modules/test-plugin

+ 7 - 0
packages/dashboard/vite/tests/fixtures-pnpm-plugin/package.json

@@ -0,0 +1,7 @@
+{
+  "name": "fixtures-pnpm-plugin",
+  "version": "1.0.0",
+  "dependencies": {
+    "test-plugin": "1.0.0"
+  }
+}

+ 18 - 0
packages/dashboard/vite/tests/fixtures-pnpm-plugin/vendure-config.ts

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

+ 58 - 0
packages/dashboard/vite/tests/pnpm-plugin.spec.ts

@@ -0,0 +1,58 @@
+import { rm } from 'node:fs/promises';
+import { join } from 'node:path';
+import tsconfigPaths from 'tsconfig-paths';
+import { describe, expect, it } from 'vitest';
+
+import { compile } from '../utils/compiler.js';
+import { debugLogger, noopLogger } from '../utils/logger.js';
+import { findVendurePluginFiles } from '../utils/plugin-discovery.js';
+
+describe('detecting plugins in pnpm packages', () => {
+    it('should detect plugins in pnpm node_modules structure', { timeout: 60_000 }, async () => {
+        const tempDir = join(__dirname, './__temp/pnpm-plugin');
+        await rm(tempDir, { recursive: true, force: true });
+        const nodeModulesRoot = join(__dirname, 'fixtures-pnpm-plugin', 'fake_node_modules');
+
+        tsconfigPaths.register({
+            baseUrl: nodeModulesRoot,
+            paths: {
+                'test-plugin': [join(nodeModulesRoot, 'test-plugin')],
+            },
+        });
+
+        const result = await compile({
+            outputPath: tempDir,
+            vendureConfigPath: join(__dirname, 'fixtures-pnpm-plugin', 'vendure-config.ts'),
+            logger: process.env.LOG ? debugLogger : noopLogger,
+            pluginPackageScanner: {
+                nodeModulesRoot,
+            },
+        });
+
+        expect(result.pluginInfo).toHaveLength(1);
+        expect(result.pluginInfo[0].name).toBe('TestPlugin');
+        expect(result.pluginInfo[0].dashboardEntryPath).toBe('./dashboard/index.tsx');
+        expect(result.pluginInfo[0].sourcePluginPath).toBeUndefined();
+        // Plugin found via pnpm symlink
+        expect(result.pluginInfo[0].pluginPath).toBe(join(nodeModulesRoot, 'test-plugin', 'index.js'));
+    });
+
+    it('should not filter out files in pnpm nested node_modules paths', async () => {
+        const nodeModulesRoot = join(__dirname, 'fixtures-pnpm-plugin', 'fake_node_modules');
+        const pnpmPath = '.pnpm/test-plugin@1.0.0/node_modules/test-plugin';
+
+        // Directly scan the .pnpm directory to verify files with nested node_modules
+        // paths are not filtered out by glob ignore patterns
+        const files = await findVendurePluginFiles({
+            outputPath: join(__dirname, './__temp/pnpm-ignore-test'),
+            vendureConfigPath: join(__dirname, 'fixtures-pnpm-plugin', 'vendure-config.ts'),
+            logger: noopLogger,
+            nodeModulesRoot,
+            packageGlobs: [pnpmPath + '/**/*.js'],
+        });
+
+        expect(files).toHaveLength(1);
+        expect(files[0]).toContain('.pnpm');
+        expect(files[0]).toContain('node_modules/test-plugin');
+    });
+});