MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / createBundle

Function createBundle

vmm/ui/build.mjs:94–103  ·  view source on GitHub ↗
(modules, entryId)

Source from the content-addressed store, hash-verified

92}
93
94function createBundle(modules, entryId) {
95 const moduleEntries = [];
96 for (const [id, info] of modules.entries()) {
97 const deps = JSON.stringify(info.dependencyMap || {});
98 moduleEntries.push(
99 `'${id}': { factory: function(module, exports, require) {\n${info.code}\n}, map: ${deps} }`,
100 );
101 }
102 return `(function(){\n const modules = {\n${moduleEntries.join(',\n')}\n };\n const cache = {};\n function load(id) {\n if (cache[id]) {\n return cache[id];\n }\n const entry = modules[id];\n if (!entry) {\n throw new Error('Unknown module ' + id);\n }\n const module = { exports: {} };\n cache[id] = module.exports;\n entry.factory(module, module.exports, createRequire(id));\n cache[id] = module.exports;\n return cache[id];\n }\n function createRequire(parentId) {\n return function(request) {\n const parent = modules[parentId];\n if (!parent) {\n throw new Error('Unknown parent module ' + parentId);\n }\n const resolved = parent.map && parent.map[request];\n if (!resolved) {\n throw new Error('Cannot resolve module ' + request + ' from ' + parentId);\n }\n return load(resolved);\n };\n }\n load('${entryId}');\n})();`;
103}
104
105async function inlineStyles(html, baseDir) {
106 const linkRegex = /<link\s+rel=["']stylesheet["']\s+href=["'](.+?)["']\s*\/?>(?:\s*<\/link>)?/gi;

Callers 1

buildFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected