···6565const VIRTUAL_ENTRY_ID = '\0virtual:entry';
66666767/**
6868- * checks if a file likely has a default export.
6969- * looks for common patterns in ESM and CJS.
7070- */
7171-function hasDefaultExport(source: string): boolean {
7272- // ESM patterns
7373- if (/\bexport\s+default\b/.test(source)) {
7474- return true;
7575- }
7676- if (/\bexport\s*\{\s*[^}]*\bdefault\b/.test(source)) {
7777- return true;
7878- }
7979- // CJS patterns (bundlers typically convert these to default exports)
8080- if (/\bmodule\.exports\s*=/.test(source)) {
8181- return true;
8282- }
8383- if (/\bexports\.default\s*=/.test(source)) {
8484- return true;
8585- }
8686- return false;
8787-}
8888-8989-/**
9068 * creates a virtual entry point that imports and re-exports from a specific subpath.
9169 *
9270 * @param packageName the package name
···225203 if (resolved) {
226204 try {
227205 const source = volume.readFileSync(resolved.id, 'utf8') as string;
228228- includeDefault = hasDefaultExport(source);
206206+ const ast = this.parse(source);
207207+208208+ for (const node of ast.body) {
209209+ // export default ...
210210+ if (node.type === 'ExportDefaultDeclaration') {
211211+ includeDefault = true;
212212+ break;
213213+ }
214214+215215+ // export { default } from '...' or export { foo as default }
216216+ if (node.type === 'ExportNamedDeclaration') {
217217+ for (const spec of node.specifiers) {
218218+ const exported = spec.exported;
219219+ const name = exported.type === 'Literal' ? exported.value : exported.name;
220220+221221+ if (name === 'default') {
222222+ includeDefault = true;
223223+ break;
224224+ }
225225+ }
226226+227227+ if (includeDefault) {
228228+ break;
229229+ }
230230+ }
231231+ }
229232 } catch {
230230- // couldn't read file, skip default export
233233+ // couldn't read/parse file, skip default export
231234 }
232235 }
233236 }
+1
src/npm/worker.ts
···22import * as v from 'valibot';
3344import { stripAnsi } from '../lib/strings';
55+56import { bundlePackage, type BundleOptions } from './bundler';
67import { progress } from './events';
78import { fetchPackagesToVolume } from './fetch';