|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | 2 |
|
3 | | -import { generateAddonSetupCode } from './codegen-set-addon-channel'; |
4 | 3 | import { generateModernIframeScriptCodeFromPreviews } from './codegen-modern-iframe-script'; |
| 4 | +import { generateAddonSetupCode } from './codegen-set-addon-channel'; |
5 | 5 | import { optimizeViteDeps } from './preset'; |
6 | 6 |
|
7 | 7 | describe('generateModernIframeScriptCodeFromPreviews', () => { |
@@ -137,16 +137,21 @@ describe('generateModernIframeScriptCodeFromPreviews', () => { |
137 | 137 | /** |
138 | 138 | * Extract bare package import specifiers from a block of generated JavaScript/TypeScript code. |
139 | 139 | * Captures both `import ... from 'pkg'` and `import 'pkg'` forms, excluding: |
140 | | - * - relative paths (start with `.`) |
141 | | - * - virtual module IDs (start with `virtual:`) |
142 | | - * - absolute paths (start with `/`) |
| 140 | + * |
| 141 | + * - Relative paths (start with `.`) |
| 142 | + * - Virtual module IDs (start with `virtual:`) |
| 143 | + * - Absolute paths (start with `/`) |
143 | 144 | */ |
144 | 145 | function extractPackageImports(code: string): string[] { |
145 | 146 | const importRegex = /import\s+(?:[^'"]*\s+from\s+)?['"]([^'"]+)['"]/g; |
146 | 147 | const specifiers = new Set<string>(); |
147 | 148 | for (const match of code.matchAll(importRegex)) { |
148 | 149 | const specifier = match[1]; |
149 | | - if (!specifier.startsWith('.') && !specifier.startsWith('virtual:') && !specifier.startsWith('/')) { |
| 150 | + if ( |
| 151 | + !specifier.startsWith('.') && |
| 152 | + !specifier.startsWith('virtual:') && |
| 153 | + !specifier.startsWith('/') |
| 154 | + ) { |
150 | 155 | specifiers.add(specifier); |
151 | 156 | } |
152 | 157 | } |
|
0 commit comments