MCPcopy
hub / github.com/sveltejs/kit / create_function_bundle

Function create_function_bundle

packages/adapter-vercel/index.js:633–746  ·  view source on GitHub ↗

* @param {import('@sveltejs/kit').Builder} builder * @param {string} entry * @param {string} dir * @param {import('./index.js').ServerlessConfig} config

(builder, entry, dir, config)

Source from the content-addressed store, hash-verified

631 * @param {import('./index.js').ServerlessConfig} config
632 */
633async function create_function_bundle(builder, entry, dir, config) {
634 fs.rmSync(dir, { force: true, recursive: true });
635
636 let base = entry;
637 while (base !== (base = path.dirname(base)));
638
639 const traced = await nodeFileTrace([entry], { base });
640
641 /** @type {Map<string, string[]>} */
642 const resolution_failures = new Map();
643
644 traced.warnings.forEach((error) => {
645 // pending https://github.com/vercel/nft/issues/284
646 if (error.message.startsWith('Failed to resolve dependency node:')) return;
647
648 // parse errors are likely not js and can safely be ignored,
649 // such as this html file in "main" meant for nw instead of node:
650 // https://github.com/vercel/nft/issues/311
651 if (error.message.startsWith('Failed to parse')) return;
652
653 if (error.message.startsWith('Failed to resolve dependency')) {
654 const match = /Cannot find module '(.+?)' loaded from (.+)/;
655 const [, module, importer] = match.exec(error.message) ?? [, error.message, '(unknown)'];
656
657 if (!resolution_failures.has(importer)) {
658 resolution_failures.set(importer, []);
659 }
660
661 /** @type {string[]} */ (resolution_failures.get(importer)).push(module);
662 } else {
663 throw error;
664 }
665 });
666
667 if (resolution_failures.size > 0) {
668 const cwd = process.cwd();
669 builder.log.warn(
670 'Warning: The following modules failed to locate dependencies that may (or may not) be required for your app to work:'
671 );
672
673 for (const [importer, modules] of resolution_failures) {
674 console.error(` ${path.relative(cwd, importer)}`);
675 for (const module of modules) {
676 console.error(` - \u001B[1m\u001B[36m${module}\u001B[39m\u001B[22m`);
677 }
678 }
679 }
680
681 const files = Array.from(traced.fileList);
682
683 // find common ancestor directory
684 /** @type {string[]} */
685 let common_parts = files[0]?.split(path.sep) ?? [];
686
687 for (let i = 1; i < files.length; i += 1) {
688 const file = files[i];
689 const parts = file.split(path.sep);
690

Callers 1

Calls 4

setMethod · 0.80
writeFunction · 0.70
warnMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected