MCPcopy
hub / github.com/sveltejs/svelte / bundle

Function bundle

packages/svelte/scripts/generate-browser-support.ts:292–329  ·  view source on GitHub ↗

* Bundle an entry the way users receive it, so we scan the same code the * browser does. Mirrors `check-treeshakeability.js`. * * `entry_code` is virtual module source: typically `export * from * 'svelte/...'` for a runtime entry, or compiled fixture JS for a per-feature * scan. `silent` suppre

(entry_code: string, options: { silent?: boolean } = {})

Source from the content-addressed store, hash-verified

290 * fixture bundles where they're known and noisy.
291 */
292async function bundle(entry_code: string, options: { silent?: boolean } = {}): Promise<string> {
293 const built = await rollup({
294 input: '__entry__',
295 plugins: [
296 virtual({ __entry__: entry_code }),
297 {
298 name: 'resolve-svelte',
299 resolveId(id: string) {
300 if (id.startsWith('svelte')) {
301 const entry = pkg.exports[id.replace('svelte', '.')];
302 if (!entry) return;
303 if (typeof entry === 'string') return path.resolve(pkg_dir, entry);
304 const file = entry.browser ?? entry.default;
305 if (file) return path.resolve(pkg_dir, file);
306 }
307 }
308 },
309 nodeResolve({ exportConditions: ['production', 'import', 'browser', 'default'] })
310 ],
311 // Treat optional peers / Node-only branches as external so we only scan
312 // code that actually runs in the browser.
313 external: ['esm-env'],
314 onwarn: options.silent
315 ? () => {}
316 : (warning, handler) => {
317 if (warning.code === 'CIRCULAR_DEPENDENCY') return;
318 handler(warning);
319 }
320 });
321
322 const { output } = await built.generate({ format: 'esm' });
323 await built.close();
324
325 return output
326 .filter((chunk): chunk is OutputChunk => chunk.type === 'chunk')
327 .map((chunk) => chunk.code)
328 .join('\n');
329}
330
331/**
332 * Read every compiler-emitted client file from the snapshot tests. These

Callers 2

bundle_fixtureFunction · 0.85
mainFunction · 0.85

Calls 3

generateMethod · 0.80
closeMethod · 0.80
handlerFunction · 0.50

Tested by

no test coverage detected