@vizhub/runtime 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/buildHTML.js +71 -0
- package/dist/cjs/common/packageJson.js +81 -0
- package/dist/cjs/common/packageJson.test.js +148 -0
- package/dist/cjs/common/sucrasePlugin.js +27 -0
- package/dist/cjs/common/virtualFileSystem.js +79 -0
- package/dist/cjs/determineRuntimeVersion.js +26 -0
- package/dist/cjs/determineRuntimeVersion.test.js +103 -0
- package/dist/cjs/index.js +9 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/test/fixtures/v1/basicHTML.js +18 -0
- package/dist/cjs/test/fixtures/v1/fetchProxy.js +15 -0
- package/dist/cjs/test/fixtures/v1/index.js +15 -0
- package/dist/cjs/test/fixtures/v1/jsScriptTag.js +12 -0
- package/dist/cjs/test/fixtures/v1/protocolTest.js +18 -0
- package/dist/cjs/test/fixtures/v1/styleTest.js +18 -0
- package/dist/cjs/test/fixtures/v1/xmlTest.js +22 -0
- package/dist/cjs/test/fixtures/v2/basicBundle.js +8 -0
- package/dist/cjs/test/fixtures/v2/basicBundleNoExtension.js +8 -0
- package/dist/cjs/test/fixtures/v2/d3Import.js +10 -0
- package/dist/cjs/test/fixtures/v2/d3ImportPkg.js +22 -0
- package/dist/cjs/test/fixtures/v2/d3RosettaImportPkg.js +22 -0
- package/dist/cjs/test/fixtures/v2/es6Preserve.js +9 -0
- package/dist/cjs/test/fixtures/v2/generatorSupport.js +9 -0
- package/dist/cjs/test/fixtures/v2/index.js +45 -0
- package/dist/cjs/test/fixtures/v2/jsxTranspile.js +9 -0
- package/dist/cjs/test/fixtures/v2/reactDomImport.js +11 -0
- package/dist/cjs/test/fixtures/v2/reactDomImportPkg.js +27 -0
- package/dist/cjs/test/fixtures/v2/reactImport.js +10 -0
- package/dist/cjs/test/fixtures/v2/reactImportPkg.js +20 -0
- package/dist/cjs/test/fixtures/v2/sourceMapErrorFixture.js +22 -0
- package/dist/cjs/test/fixtures/v2/unicodeSupport.js +9 -0
- package/dist/cjs/test/fixtures/v3/basicIndexJS.js +10 -0
- package/dist/cjs/test/fixtures/v3/cssImport.js +12 -0
- package/dist/cjs/test/fixtures/v3/csvImport.js +14 -0
- package/dist/cjs/test/fixtures/v3/csvStrangeChars.js +15 -0
- package/dist/cjs/test/fixtures/v3/index.js +25 -0
- package/dist/cjs/test/fixtures/v3/jsExport.js +13 -0
- package/dist/cjs/test/fixtures/v3/sourcemap.js +13 -0
- package/dist/cjs/test/fixtures/v3/svelte.js +21 -0
- package/dist/cjs/test/fixtures/v3/vizContent.js +14 -0
- package/dist/cjs/test/fixtures/v3/vizImport.js +88 -0
- package/dist/cjs/test/fixtures/v4/d3Usage.js +34 -0
- package/dist/cjs/test/fixtures/v4/esmBuild.js +21 -0
- package/dist/cjs/test/fixtures/v4/fetchInterception.js +21 -0
- package/dist/cjs/test/fixtures/v4/index.js +21 -0
- package/dist/cjs/test/fixtures/v4/jsScriptTagTypeModule.js +21 -0
- package/dist/cjs/test/fixtures/v4/jsScriptTagTypeModules.js +15 -0
- package/dist/cjs/test/fixtures/v4/reactHooks.js +50 -0
- package/dist/cjs/test/fixtures/v4/reactJsx.js +37 -0
- package/dist/cjs/test/fixtures/v4/threeJsUsage.js +27 -0
- package/dist/cjs/test/fixtures/v4/typeScriptSupport.js +32 -0
- package/dist/cjs/test/testInBrowser.js +50 -0
- package/dist/cjs/test/testStackTrace.js +58 -0
- package/dist/cjs/test/v1.test.js +70 -0
- package/dist/cjs/test/v2.test.js +124 -0
- package/dist/cjs/test/v3.test.js +119 -0
- package/dist/cjs/test/v4.test.js +105 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils/vizContentToFileCollection.js +23 -0
- package/dist/cjs/utils/vizContentToFileCollection.test.js +77 -0
- package/dist/cjs/v2/computeBundleJSV2.js +33 -0
- package/dist/cjs/v2/getComputedIndexHtml.js +86 -0
- package/dist/cjs/v2/getComputedIndexHtml.test.js +136 -0
- package/dist/cjs/v2/index.js +5 -0
- package/dist/cjs/v2/v2Build.js +15 -0
- package/dist/cjs/v3/cleanRollupErrorMessage.js +13 -0
- package/dist/cjs/v3/computeBundleJSV3.js +52 -0
- package/dist/cjs/v3/createVizContent.js +27 -0
- package/dist/cjs/v3/extractVizImport.js +27 -0
- package/dist/cjs/v3/extractVizImport.test.js +32 -0
- package/dist/cjs/v3/htmlTemplate.js +93 -0
- package/dist/cjs/v3/index.js +5 -0
- package/dist/cjs/v3/parseId.js +9 -0
- package/dist/cjs/v3/parseId.test.js +27 -0
- package/dist/cjs/v3/setupV3Runtime.js +345 -0
- package/dist/cjs/v3/slugCache.js +39 -0
- package/dist/cjs/v3/slugCache.test.js +107 -0
- package/dist/cjs/v3/transformDSV/dsvParseSrc.js +124 -0
- package/dist/cjs/v3/transformDSV/index.js +44 -0
- package/dist/cjs/v3/transformSvelte.js +81 -0
- package/dist/cjs/v3/types.js +2 -0
- package/dist/cjs/v3/v3Build.js +34 -0
- package/dist/cjs/v3/vizCache.js +40 -0
- package/dist/cjs/v3/vizCache.test.js +100 -0
- package/dist/cjs/v3/vizLoad.js +50 -0
- package/dist/cjs/v3/vizResolve.js +73 -0
- package/dist/cjs/v4/index.js +138 -0
- package/dist/esm/buildHTML.js +67 -0
- package/dist/esm/common/packageJson.js +71 -0
- package/dist/esm/common/packageJson.test.js +146 -0
- package/dist/esm/common/sucrasePlugin.js +24 -0
- package/dist/esm/common/virtualFileSystem.js +75 -0
- package/dist/esm/determineRuntimeVersion.js +22 -0
- package/dist/esm/determineRuntimeVersion.test.js +101 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/test/fixtures/v1/basicHTML.js +15 -0
- package/dist/esm/test/fixtures/v1/fetchProxy.js +12 -0
- package/dist/esm/test/fixtures/v1/index.js +6 -0
- package/dist/esm/test/fixtures/v1/jsScriptTag.js +9 -0
- package/dist/esm/test/fixtures/v1/protocolTest.js +15 -0
- package/dist/esm/test/fixtures/v1/styleTest.js +15 -0
- package/dist/esm/test/fixtures/v1/xmlTest.js +19 -0
- package/dist/esm/test/fixtures/v2/basicBundle.js +5 -0
- package/dist/esm/test/fixtures/v2/basicBundleNoExtension.js +5 -0
- package/dist/esm/test/fixtures/v2/d3Import.js +7 -0
- package/dist/esm/test/fixtures/v2/d3ImportPkg.js +19 -0
- package/dist/esm/test/fixtures/v2/d3RosettaImportPkg.js +19 -0
- package/dist/esm/test/fixtures/v2/es6Preserve.js +6 -0
- package/dist/esm/test/fixtures/v2/generatorSupport.js +6 -0
- package/dist/esm/test/fixtures/v2/index.js +15 -0
- package/dist/esm/test/fixtures/v2/jsxTranspile.js +6 -0
- package/dist/esm/test/fixtures/v2/reactDomImport.js +8 -0
- package/dist/esm/test/fixtures/v2/reactDomImportPkg.js +24 -0
- package/dist/esm/test/fixtures/v2/reactImport.js +7 -0
- package/dist/esm/test/fixtures/v2/reactImportPkg.js +17 -0
- package/dist/esm/test/fixtures/v2/sourceMapErrorFixture.js +19 -0
- package/dist/esm/test/fixtures/v2/unicodeSupport.js +6 -0
- package/dist/esm/test/fixtures/v3/basicIndexJS.js +7 -0
- package/dist/esm/test/fixtures/v3/cssImport.js +9 -0
- package/dist/esm/test/fixtures/v3/csvImport.js +11 -0
- package/dist/esm/test/fixtures/v3/csvStrangeChars.js +12 -0
- package/dist/esm/test/fixtures/v3/index.js +9 -0
- package/dist/esm/test/fixtures/v3/jsExport.js +10 -0
- package/dist/esm/test/fixtures/v3/sourcemap.js +10 -0
- package/dist/esm/test/fixtures/v3/svelte.js +18 -0
- package/dist/esm/test/fixtures/v3/vizContent.js +11 -0
- package/dist/esm/test/fixtures/v3/vizImport.js +85 -0
- package/dist/esm/test/fixtures/v4/d3Usage.js +31 -0
- package/dist/esm/test/fixtures/v4/esmBuild.js +18 -0
- package/dist/esm/test/fixtures/v4/fetchInterception.js +18 -0
- package/dist/esm/test/fixtures/v4/index.js +9 -0
- package/dist/esm/test/fixtures/v4/jsScriptTagTypeModule.js +18 -0
- package/dist/esm/test/fixtures/v4/jsScriptTagTypeModules.js +12 -0
- package/dist/esm/test/fixtures/v4/reactHooks.js +47 -0
- package/dist/esm/test/fixtures/v4/reactJsx.js +34 -0
- package/dist/esm/test/fixtures/v4/threeJsUsage.js +24 -0
- package/dist/esm/test/fixtures/v4/typeScriptSupport.js +29 -0
- package/dist/esm/test/testInBrowser.js +47 -0
- package/dist/esm/test/testStackTrace.js +55 -0
- package/dist/esm/test/v1.test.js +65 -0
- package/dist/esm/test/v2.test.js +121 -0
- package/dist/esm/test/v3.test.js +114 -0
- package/dist/esm/test/v4.test.js +100 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils/vizContentToFileCollection.js +19 -0
- package/dist/esm/utils/vizContentToFileCollection.test.js +75 -0
- package/dist/esm/v2/computeBundleJSV2.js +29 -0
- package/dist/esm/v2/getComputedIndexHtml.js +81 -0
- package/dist/esm/v2/getComputedIndexHtml.test.js +134 -0
- package/dist/esm/v2/index.js +1 -0
- package/dist/esm/v2/v2Build.js +11 -0
- package/dist/esm/v3/cleanRollupErrorMessage.js +9 -0
- package/dist/esm/v3/computeBundleJSV3.js +48 -0
- package/dist/esm/v3/createVizContent.js +23 -0
- package/dist/esm/v3/extractVizImport.js +23 -0
- package/dist/esm/v3/extractVizImport.test.js +30 -0
- package/dist/esm/v3/htmlTemplate.js +89 -0
- package/dist/esm/v3/index.js +1 -0
- package/dist/esm/v3/parseId.js +5 -0
- package/dist/esm/v3/parseId.test.js +25 -0
- package/dist/esm/v3/setupV3Runtime.js +341 -0
- package/dist/esm/v3/slugCache.js +35 -0
- package/dist/esm/v3/slugCache.test.js +105 -0
- package/dist/esm/v3/transformDSV/dsvParseSrc.js +121 -0
- package/dist/esm/v3/transformDSV/index.js +40 -0
- package/dist/esm/v3/transformSvelte.js +77 -0
- package/dist/esm/v3/types.js +1 -0
- package/dist/esm/v3/v3Build.js +30 -0
- package/dist/esm/v3/vizCache.js +36 -0
- package/dist/esm/v3/vizCache.test.js +98 -0
- package/dist/esm/v3/vizLoad.js +46 -0
- package/dist/esm/v3/vizResolve.js +69 -0
- package/dist/esm/v4/index.js +134 -0
- package/dist/types/buildHTML.d.ts +14 -0
- package/dist/types/common/packageJson.d.ts +39 -0
- package/dist/types/common/packageJson.test.d.ts +1 -0
- package/dist/types/common/sucrasePlugin.d.ts +2 -0
- package/dist/types/common/virtualFileSystem.d.ts +3 -0
- package/dist/types/determineRuntimeVersion.d.ts +3 -0
- package/dist/types/determineRuntimeVersion.test.d.ts +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/test/fixtures/v1/basicHTML.d.ts +3 -0
- package/dist/types/test/fixtures/v1/fetchProxy.d.ts +5 -0
- package/dist/types/test/fixtures/v1/index.d.ts +6 -0
- package/dist/types/test/fixtures/v1/jsScriptTag.d.ts +4 -0
- package/dist/types/test/fixtures/v1/protocolTest.d.ts +3 -0
- package/dist/types/test/fixtures/v1/styleTest.d.ts +4 -0
- package/dist/types/test/fixtures/v1/xmlTest.d.ts +4 -0
- package/dist/types/test/fixtures/v2/basicBundle.d.ts +5 -0
- package/dist/types/test/fixtures/v2/basicBundleNoExtension.d.ts +5 -0
- package/dist/types/test/fixtures/v2/d3Import.d.ts +4 -0
- package/dist/types/test/fixtures/v2/d3ImportPkg.d.ts +5 -0
- package/dist/types/test/fixtures/v2/d3RosettaImportPkg.d.ts +5 -0
- package/dist/types/test/fixtures/v2/es6Preserve.d.ts +4 -0
- package/dist/types/test/fixtures/v2/generatorSupport.d.ts +4 -0
- package/dist/types/test/fixtures/v2/index.d.ts +14 -0
- package/dist/types/test/fixtures/v2/jsxTranspile.d.ts +4 -0
- package/dist/types/test/fixtures/v2/reactDomImport.d.ts +4 -0
- package/dist/types/test/fixtures/v2/reactDomImportPkg.d.ts +5 -0
- package/dist/types/test/fixtures/v2/reactImport.d.ts +4 -0
- package/dist/types/test/fixtures/v2/reactImportPkg.d.ts +5 -0
- package/dist/types/test/fixtures/v2/sourceMapErrorFixture.d.ts +5 -0
- package/dist/types/test/fixtures/v2/unicodeSupport.d.ts +4 -0
- package/dist/types/test/fixtures/v3/basicIndexJS.d.ts +3 -0
- package/dist/types/test/fixtures/v3/cssImport.d.ts +4 -0
- package/dist/types/test/fixtures/v3/csvImport.d.ts +4 -0
- package/dist/types/test/fixtures/v3/csvStrangeChars.d.ts +4 -0
- package/dist/types/test/fixtures/v3/index.d.ts +9 -0
- package/dist/types/test/fixtures/v3/jsExport.d.ts +4 -0
- package/dist/types/test/fixtures/v3/sourcemap.d.ts +3 -0
- package/dist/types/test/fixtures/v3/svelte.d.ts +4 -0
- package/dist/types/test/fixtures/v3/vizContent.d.ts +2 -0
- package/dist/types/test/fixtures/v3/vizImport.d.ts +6 -0
- package/dist/types/test/fixtures/v4/d3Usage.d.ts +5 -0
- package/dist/types/test/fixtures/v4/esmBuild.d.ts +5 -0
- package/dist/types/test/fixtures/v4/fetchInterception.d.ts +5 -0
- package/dist/types/test/fixtures/v4/index.d.ts +9 -0
- package/dist/types/test/fixtures/v4/jsScriptTagTypeModule.d.ts +4 -0
- package/dist/types/test/fixtures/v4/jsScriptTagTypeModules.d.ts +5 -0
- package/dist/types/test/fixtures/v4/reactHooks.d.ts +6 -0
- package/dist/types/test/fixtures/v4/reactJsx.d.ts +6 -0
- package/dist/types/test/fixtures/v4/threeJsUsage.d.ts +4 -0
- package/dist/types/test/fixtures/v4/typeScriptSupport.d.ts +5 -0
- package/dist/types/test/testInBrowser.d.ts +15 -0
- package/dist/types/test/testStackTrace.d.ts +9 -0
- package/dist/types/test/v1.test.d.ts +1 -0
- package/dist/types/test/v2.test.d.ts +1 -0
- package/dist/types/test/v3.test.d.ts +1 -0
- package/dist/types/test/v4.test.d.ts +1 -0
- package/dist/types/types.d.ts +1 -0
- package/dist/types/utils/vizContentToFileCollection.d.ts +7 -0
- package/dist/types/utils/vizContentToFileCollection.test.d.ts +1 -0
- package/dist/types/v2/computeBundleJSV2.d.ts +7 -0
- package/dist/types/v2/getComputedIndexHtml.d.ts +4 -0
- package/dist/types/v2/getComputedIndexHtml.test.d.ts +1 -0
- package/dist/types/v2/index.d.ts +1 -0
- package/dist/types/v2/v2Build.d.ts +7 -0
- package/dist/types/v3/cleanRollupErrorMessage.d.ts +4 -0
- package/dist/types/v3/computeBundleJSV3.d.ts +17 -0
- package/dist/types/v3/createVizContent.d.ts +8 -0
- package/dist/types/v3/extractVizImport.d.ts +6 -0
- package/dist/types/v3/extractVizImport.test.d.ts +1 -0
- package/dist/types/v3/htmlTemplate.d.ts +5 -0
- package/dist/types/v3/index.d.ts +1 -0
- package/dist/types/v3/parseId.d.ts +6 -0
- package/dist/types/v3/parseId.test.d.ts +1 -0
- package/dist/types/v3/setupV3Runtime.d.ts +15 -0
- package/dist/types/v3/slugCache.d.ts +11 -0
- package/dist/types/v3/slugCache.test.d.ts +1 -0
- package/dist/types/v3/transformDSV/dsvParseSrc.d.ts +1 -0
- package/dist/types/v3/transformDSV/index.d.ts +2 -0
- package/dist/types/v3/transformSvelte.d.ts +8 -0
- package/dist/types/v3/types.d.ts +65 -0
- package/dist/types/v3/v3Build.d.ts +14 -0
- package/dist/types/v3/vizCache.d.ts +10 -0
- package/dist/types/v3/vizCache.test.d.ts +1 -0
- package/dist/types/v3/vizLoad.d.ts +7 -0
- package/dist/types/v3/vizResolve.d.ts +7 -0
- package/dist/types/v4/index.d.ts +10 -0
- package/package.json +14 -7
@@ -0,0 +1,138 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.v4Build = void 0;
|
4
|
+
const jsdom_1 = require("jsdom");
|
5
|
+
const virtualFileSystem_1 = require("../common/virtualFileSystem");
|
6
|
+
const sucrasePlugin_1 = require("../common/sucrasePlugin");
|
7
|
+
const packageJson_1 = require("../common/packageJson");
|
8
|
+
const DEBUG = false;
|
9
|
+
/**
|
10
|
+
* Extract module script entry points from index.html
|
11
|
+
*/
|
12
|
+
const extractModuleEntryPoints = (html) => {
|
13
|
+
const dom = new jsdom_1.JSDOM(html);
|
14
|
+
const document = dom.window.document;
|
15
|
+
const moduleScripts = document.querySelectorAll('script[type="module"]');
|
16
|
+
const entryPoints = [];
|
17
|
+
moduleScripts.forEach((script) => {
|
18
|
+
const src = script.getAttribute("src");
|
19
|
+
if (src) {
|
20
|
+
entryPoints.push(src);
|
21
|
+
}
|
22
|
+
});
|
23
|
+
return entryPoints;
|
24
|
+
};
|
25
|
+
/**
|
26
|
+
* Bundle an ES module entry point
|
27
|
+
*/
|
28
|
+
const bundleESModule = async ({ entryPoint, files, rollup, enableSourcemap = true, }) => {
|
29
|
+
const inputOptions = {
|
30
|
+
input: `./${entryPoint}`,
|
31
|
+
plugins: [(0, virtualFileSystem_1.virtualFileSystem)(files), (0, sucrasePlugin_1.sucrasePlugin)()],
|
32
|
+
onwarn(warning, warn) {
|
33
|
+
// Suppress "treating module as external dependency" warnings
|
34
|
+
if (warning.code === "UNRESOLVED_IMPORT")
|
35
|
+
return;
|
36
|
+
warn(warning);
|
37
|
+
},
|
38
|
+
};
|
39
|
+
const bundle = await rollup(inputOptions);
|
40
|
+
const outputOptions = {
|
41
|
+
format: "es",
|
42
|
+
sourcemap: enableSourcemap,
|
43
|
+
};
|
44
|
+
const { output } = await bundle.generate(outputOptions);
|
45
|
+
return output[0].code;
|
46
|
+
};
|
47
|
+
/**
|
48
|
+
* Generate an import map for all dependencies
|
49
|
+
*/
|
50
|
+
const generateImportMap = (files) => {
|
51
|
+
const deps = (0, packageJson_1.dependencies)(files);
|
52
|
+
if (Object.keys(deps).length === 0) {
|
53
|
+
return null;
|
54
|
+
}
|
55
|
+
const libraries = (0, packageJson_1.getConfiguredLibraries)(files);
|
56
|
+
const imports = {};
|
57
|
+
Object.entries(deps).forEach(([name, version]) => {
|
58
|
+
const url = (0, packageJson_1.dependencySource)({ name, version }, libraries);
|
59
|
+
imports[name] = url;
|
60
|
+
});
|
61
|
+
return JSON.stringify({ imports }, null, 2);
|
62
|
+
};
|
63
|
+
/**
|
64
|
+
* Update HTML to include import map and bundled modules
|
65
|
+
*/
|
66
|
+
const updateHTML = (files, bundledModules) => {
|
67
|
+
const html = files["index.html"] || "";
|
68
|
+
if (!html) {
|
69
|
+
return "";
|
70
|
+
}
|
71
|
+
const dom = new jsdom_1.JSDOM(html);
|
72
|
+
const document = dom.window.document;
|
73
|
+
// Replace script src with bundled content
|
74
|
+
bundledModules.forEach((code, src) => {
|
75
|
+
const scripts = document.querySelectorAll(`script[src="${src}"]`);
|
76
|
+
scripts.forEach((script) => {
|
77
|
+
const newScript = document.createElement("script");
|
78
|
+
newScript.setAttribute("type", "module");
|
79
|
+
newScript.textContent = code;
|
80
|
+
script.parentNode?.replaceChild(newScript, script);
|
81
|
+
});
|
82
|
+
});
|
83
|
+
// Add import map if needed
|
84
|
+
const importMap = generateImportMap(files);
|
85
|
+
if (importMap) {
|
86
|
+
// Check if import map already exists
|
87
|
+
const existingImportMap = document.querySelector('script[type="importmap"]');
|
88
|
+
if (!existingImportMap) {
|
89
|
+
const importMapScript = document.createElement("script");
|
90
|
+
importMapScript.setAttribute("type", "importmap");
|
91
|
+
importMapScript.textContent = importMap;
|
92
|
+
const head = document.head || document.querySelector("head");
|
93
|
+
if (head) {
|
94
|
+
head.prepend(importMapScript);
|
95
|
+
}
|
96
|
+
else {
|
97
|
+
const html = document.documentElement;
|
98
|
+
const newHead = document.createElement("head");
|
99
|
+
newHead.appendChild(importMapScript);
|
100
|
+
html.insertBefore(newHead, html.firstChild);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
return `<!DOCTYPE html>${document.documentElement.outerHTML}`;
|
105
|
+
};
|
106
|
+
/**
|
107
|
+
* Build for v4 runtime
|
108
|
+
*/
|
109
|
+
const v4Build = async ({ files, rollup, enableSourcemap = true, }) => {
|
110
|
+
// Extract entry points
|
111
|
+
const html = files["index.html"] || "";
|
112
|
+
const entryPoints = extractModuleEntryPoints(html);
|
113
|
+
if (entryPoints.length === 0) {
|
114
|
+
DEBUG &&
|
115
|
+
console.log("[v4Build] No module entry points found");
|
116
|
+
// Fall back to a default approach if no module entry points
|
117
|
+
// Just return the HTML as-is if there are no module scripts
|
118
|
+
return files;
|
119
|
+
}
|
120
|
+
// Bundle each entry point
|
121
|
+
const bundledModules = new Map();
|
122
|
+
for (const entryPoint of entryPoints) {
|
123
|
+
const code = await bundleESModule({
|
124
|
+
entryPoint,
|
125
|
+
files,
|
126
|
+
rollup,
|
127
|
+
enableSourcemap,
|
128
|
+
});
|
129
|
+
bundledModules.set(entryPoint, code);
|
130
|
+
}
|
131
|
+
// Update HTML with bundled modules and import map
|
132
|
+
const updatedHTML = updateHTML(files, bundledModules);
|
133
|
+
return {
|
134
|
+
...files,
|
135
|
+
"index.html": updatedHTML,
|
136
|
+
};
|
137
|
+
};
|
138
|
+
exports.v4Build = v4Build;
|
@@ -0,0 +1,67 @@
|
|
1
|
+
import { magicSandbox } from "magic-sandbox";
|
2
|
+
import { determineRuntimeVersion } from "./determineRuntimeVersion";
|
3
|
+
import { v2Build } from "./v2";
|
4
|
+
import { v3Build } from "./v3";
|
5
|
+
import { v4Build } from "./v4";
|
6
|
+
import { createVizCache } from "./v3/vizCache";
|
7
|
+
import { createVizContent } from "./v3/createVizContent";
|
8
|
+
import { vizContentToFileCollection } from "./utils/vizContentToFileCollection";
|
9
|
+
const DEBUG = false;
|
10
|
+
export const buildHTML = async ({ files, rollup, enableSourcemap = true, vizCache, vizId, slugCache, getSvelteCompiler, }) => {
|
11
|
+
if (!files && !vizCache) {
|
12
|
+
throw new Error("Either files or vizCache is required");
|
13
|
+
}
|
14
|
+
if (!files && vizCache && !vizId) {
|
15
|
+
throw new Error("vizId is required when using vizCache");
|
16
|
+
}
|
17
|
+
if (!files && vizCache && vizId) {
|
18
|
+
files = vizContentToFileCollection(await vizCache.get(vizId));
|
19
|
+
}
|
20
|
+
if (!files) {
|
21
|
+
throw new Error("Upable to extract viz files");
|
22
|
+
}
|
23
|
+
const version = determineRuntimeVersion(files);
|
24
|
+
DEBUG && console.log("[buildHTML] version:", version);
|
25
|
+
if (version === "v1") {
|
26
|
+
return magicSandbox(files);
|
27
|
+
}
|
28
|
+
if (version === "v2") {
|
29
|
+
if (!rollup) {
|
30
|
+
throw new Error("Rollup is required for v2 runtime");
|
31
|
+
}
|
32
|
+
return magicSandbox(await v2Build({ files, rollup, enableSourcemap }));
|
33
|
+
}
|
34
|
+
if (version === "v3") {
|
35
|
+
if (!rollup) {
|
36
|
+
throw new Error("Rollup is required for v3 runtime");
|
37
|
+
}
|
38
|
+
if (!vizCache && !vizId) {
|
39
|
+
const vizContent = createVizContent(files);
|
40
|
+
vizId = vizContent.id;
|
41
|
+
vizCache = createVizCache({
|
42
|
+
initialContents: [vizContent],
|
43
|
+
handleCacheMiss: async () => {
|
44
|
+
throw new Error("Cache miss handler not implemented");
|
45
|
+
},
|
46
|
+
});
|
47
|
+
}
|
48
|
+
if (!vizCache || !vizId) {
|
49
|
+
throw new Error("vizCache and vizId are required for v3 runtime");
|
50
|
+
}
|
51
|
+
return await v3Build({
|
52
|
+
files,
|
53
|
+
rollup,
|
54
|
+
vizCache,
|
55
|
+
vizId,
|
56
|
+
slugCache,
|
57
|
+
getSvelteCompiler,
|
58
|
+
});
|
59
|
+
}
|
60
|
+
if (version === "v4") {
|
61
|
+
if (!rollup) {
|
62
|
+
throw new Error("Rollup is required for v4 runtime");
|
63
|
+
}
|
64
|
+
return magicSandbox(await v4Build({ files, rollup, enableSourcemap }));
|
65
|
+
}
|
66
|
+
throw new Error(`Unsupported runtime version: ${version}`);
|
67
|
+
};
|
@@ -0,0 +1,71 @@
|
|
1
|
+
const EMPTY_PKG_JSON = {
|
2
|
+
dependencies: {},
|
3
|
+
vizhub: {},
|
4
|
+
license: "MIT",
|
5
|
+
};
|
6
|
+
const DEBUG = false;
|
7
|
+
export const packageJSON = (files) => {
|
8
|
+
const packageJsonText = files["package.json"];
|
9
|
+
DEBUG &&
|
10
|
+
console.log("[packageJSON] packageJsonText:", packageJsonText);
|
11
|
+
try {
|
12
|
+
const pkg = packageJsonText
|
13
|
+
? JSON.parse(packageJsonText)
|
14
|
+
: EMPTY_PKG_JSON;
|
15
|
+
DEBUG &&
|
16
|
+
console.log("[packageJSON] pkg:", JSON.stringify(pkg, null, 2));
|
17
|
+
return pkg;
|
18
|
+
}
|
19
|
+
catch {
|
20
|
+
DEBUG &&
|
21
|
+
console.log("[packageJSON] Error parsing package.json");
|
22
|
+
return EMPTY_PKG_JSON;
|
23
|
+
}
|
24
|
+
};
|
25
|
+
export const dependencies = (files) => packageJSON(files).dependencies || {};
|
26
|
+
export const getConfiguredLibraries = (files) => {
|
27
|
+
const vizhubConfig = packageJSON(files).vizhub || {};
|
28
|
+
return vizhubConfig.libraries || {};
|
29
|
+
};
|
30
|
+
export const dependencySource = ({ name, version }, libraries, cdn = "jsdelivr") => {
|
31
|
+
const path = libraries[name]
|
32
|
+
? libraries[name].path || ""
|
33
|
+
: "";
|
34
|
+
const src = cdn === "jsdelivr"
|
35
|
+
? `https://cdn.jsdelivr.net/npm/${name}@${version}${path}`
|
36
|
+
: `https://unpkg.com/${name}@${version}${path}`;
|
37
|
+
return src;
|
38
|
+
};
|
39
|
+
export const getLicense = (files) => {
|
40
|
+
const license = packageJSON(files).license;
|
41
|
+
if (typeof license === "object" &&
|
42
|
+
license !== null &&
|
43
|
+
"type" in license) {
|
44
|
+
return license.type;
|
45
|
+
}
|
46
|
+
return license || EMPTY_PKG_JSON.license;
|
47
|
+
};
|
48
|
+
export const getConfiguredGlobals = (pkg) => {
|
49
|
+
const libraries = pkg?.vizhub?.libraries;
|
50
|
+
if (libraries) {
|
51
|
+
return Object.entries(libraries).reduce((accumulator, [packageName, config]) => {
|
52
|
+
if (config.global) {
|
53
|
+
accumulator[packageName] = config.global;
|
54
|
+
}
|
55
|
+
return accumulator;
|
56
|
+
}, {});
|
57
|
+
}
|
58
|
+
return {};
|
59
|
+
};
|
60
|
+
const defaultGlobals = {
|
61
|
+
d3: "d3",
|
62
|
+
react: "React",
|
63
|
+
"react-dom": "ReactDOM",
|
64
|
+
};
|
65
|
+
export const getGlobals = (pkg) => {
|
66
|
+
const configuredGlobals = getConfiguredGlobals(pkg);
|
67
|
+
return {
|
68
|
+
...defaultGlobals,
|
69
|
+
...configuredGlobals,
|
70
|
+
};
|
71
|
+
};
|
@@ -0,0 +1,146 @@
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
2
|
+
import { packageJSON, dependencies, getConfiguredLibraries, dependencySource, getLicense, } from "./packageJson";
|
3
|
+
describe("packageJson", () => {
|
4
|
+
const mockFiles = {
|
5
|
+
"package.json": JSON.stringify({
|
6
|
+
dependencies: {
|
7
|
+
react: "17.0.2",
|
8
|
+
d3: "7.0.0",
|
9
|
+
},
|
10
|
+
vizhub: {
|
11
|
+
libraries: {
|
12
|
+
d3: { path: "/dist/d3.min.js" },
|
13
|
+
},
|
14
|
+
},
|
15
|
+
license: "Apache-2.0",
|
16
|
+
}),
|
17
|
+
};
|
18
|
+
const emptyFiles = {};
|
19
|
+
const invalidFiles = {
|
20
|
+
"package.json": "invalid json",
|
21
|
+
};
|
22
|
+
describe("packageJSON", () => {
|
23
|
+
it("should parse valid package.json", () => {
|
24
|
+
const result = packageJSON(mockFiles);
|
25
|
+
expect(result).toHaveProperty("dependencies");
|
26
|
+
expect(result.dependencies).toHaveProperty("react", "17.0.2");
|
27
|
+
});
|
28
|
+
it("should return empty object for missing package.json", () => {
|
29
|
+
const result = packageJSON(emptyFiles);
|
30
|
+
expect(result).toEqual({
|
31
|
+
dependencies: {},
|
32
|
+
vizhub: {},
|
33
|
+
license: "MIT",
|
34
|
+
});
|
35
|
+
});
|
36
|
+
it("should handle invalid JSON", () => {
|
37
|
+
const result = packageJSON(invalidFiles);
|
38
|
+
expect(result).toEqual({
|
39
|
+
dependencies: {},
|
40
|
+
vizhub: {},
|
41
|
+
license: "MIT",
|
42
|
+
});
|
43
|
+
});
|
44
|
+
});
|
45
|
+
describe("dependencies", () => {
|
46
|
+
it("should return dependencies from package.json", () => {
|
47
|
+
const result = dependencies(mockFiles);
|
48
|
+
expect(result).toEqual({
|
49
|
+
react: "17.0.2",
|
50
|
+
d3: "7.0.0",
|
51
|
+
});
|
52
|
+
});
|
53
|
+
it("should return empty object when no dependencies", () => {
|
54
|
+
const result = dependencies(emptyFiles);
|
55
|
+
expect(result).toEqual({});
|
56
|
+
});
|
57
|
+
});
|
58
|
+
describe("getConfiguredLibraries", () => {
|
59
|
+
it("should return configured libraries", () => {
|
60
|
+
const result = getConfiguredLibraries(mockFiles);
|
61
|
+
expect(result).toEqual({
|
62
|
+
d3: { path: "/dist/d3.min.js" },
|
63
|
+
});
|
64
|
+
});
|
65
|
+
it("should return empty object when no libraries configured", () => {
|
66
|
+
const result = getConfiguredLibraries(emptyFiles);
|
67
|
+
expect(result).toEqual({});
|
68
|
+
});
|
69
|
+
});
|
70
|
+
describe("dependencySource", () => {
|
71
|
+
it("should generate correct URL with path - jsdelivr", () => {
|
72
|
+
const dependency = { name: "d3", version: "7.0.0" };
|
73
|
+
const libraries = { d3: { path: "/dist/d3.min.js" } };
|
74
|
+
const result = dependencySource(dependency, libraries);
|
75
|
+
expect(result).toBe("https://cdn.jsdelivr.net/npm/d3@7.0.0/dist/d3.min.js");
|
76
|
+
});
|
77
|
+
it("should generate correct URL without path - jsdelivr", () => {
|
78
|
+
const dependency = {
|
79
|
+
name: "react",
|
80
|
+
version: "17.0.2",
|
81
|
+
};
|
82
|
+
const libraries = {};
|
83
|
+
const result = dependencySource(dependency, libraries);
|
84
|
+
expect(result).toBe("https://cdn.jsdelivr.net/npm/react@17.0.2");
|
85
|
+
});
|
86
|
+
it("should generate correct URL with path - unpkg", () => {
|
87
|
+
const dependency = { name: "d3", version: "7.0.0" };
|
88
|
+
const libraries = { d3: { path: "/dist/d3.min.js" } };
|
89
|
+
const result = dependencySource(dependency, libraries, "unpkg");
|
90
|
+
expect(result).toBe("https://unpkg.com/d3@7.0.0/dist/d3.min.js");
|
91
|
+
});
|
92
|
+
it("should generate correct URL without path - unpkg", () => {
|
93
|
+
const dependency = {
|
94
|
+
name: "react",
|
95
|
+
version: "17.0.2",
|
96
|
+
};
|
97
|
+
const libraries = {};
|
98
|
+
const result = dependencySource(dependency, libraries, "unpkg");
|
99
|
+
expect(result).toBe("https://unpkg.com/react@17.0.2");
|
100
|
+
});
|
101
|
+
});
|
102
|
+
describe("getLicense", () => {
|
103
|
+
it("should return license from package.json", () => {
|
104
|
+
const result = getLicense(mockFiles);
|
105
|
+
expect(result).toBe("Apache-2.0");
|
106
|
+
});
|
107
|
+
it("should return default MIT license when not specified", () => {
|
108
|
+
const result = getLicense(emptyFiles);
|
109
|
+
expect(result).toBe("MIT");
|
110
|
+
});
|
111
|
+
});
|
112
|
+
describe("Edge cases", () => {
|
113
|
+
it("should handle malformed library configuration", () => {
|
114
|
+
const malformedFiles = {
|
115
|
+
"package.json": JSON.stringify({
|
116
|
+
dependencies: { d3: "7.0.0" },
|
117
|
+
vizhub: { libraries: { d3: null } },
|
118
|
+
}),
|
119
|
+
};
|
120
|
+
const result = getConfiguredLibraries(malformedFiles);
|
121
|
+
expect(result).toEqual({ d3: null });
|
122
|
+
});
|
123
|
+
it("should handle empty version strings", () => {
|
124
|
+
const dependency = { name: "react", version: "" };
|
125
|
+
const result = dependencySource(dependency, {});
|
126
|
+
expect(result).toBe("https://cdn.jsdelivr.net/npm/react@");
|
127
|
+
});
|
128
|
+
it("should handle special characters in dependency names", () => {
|
129
|
+
const specialCharDep = {
|
130
|
+
name: "@angular/core",
|
131
|
+
version: "14.0.0",
|
132
|
+
};
|
133
|
+
const result = dependencySource(specialCharDep, {});
|
134
|
+
expect(result).toBe("https://cdn.jsdelivr.net/npm/@angular/core@14.0.0");
|
135
|
+
});
|
136
|
+
it("should handle unusual license formats", () => {
|
137
|
+
const unusualLicenseFiles = {
|
138
|
+
"package.json": JSON.stringify({
|
139
|
+
license: { type: "MIT" },
|
140
|
+
}),
|
141
|
+
};
|
142
|
+
const result = getLicense(unusualLicenseFiles);
|
143
|
+
expect(result).toBe("MIT");
|
144
|
+
});
|
145
|
+
});
|
146
|
+
});
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { transform } from "sucrase";
|
2
|
+
export function sucrasePlugin() {
|
3
|
+
return {
|
4
|
+
name: "sucrase",
|
5
|
+
transform(code, id) {
|
6
|
+
// Transform .js, .jsx, and .tsx files
|
7
|
+
if (!id.match(/\.(?:js|[jt]sx)$/)) {
|
8
|
+
return null;
|
9
|
+
}
|
10
|
+
const result = transform(code, {
|
11
|
+
transforms: ["jsx", "typescript"],
|
12
|
+
filePath: id, // For source maps
|
13
|
+
sourceMapOptions: {
|
14
|
+
compiledFilename: "bundle.js",
|
15
|
+
},
|
16
|
+
production: true,
|
17
|
+
});
|
18
|
+
return {
|
19
|
+
code: result.code,
|
20
|
+
map: result.sourceMap,
|
21
|
+
};
|
22
|
+
},
|
23
|
+
};
|
24
|
+
}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
const normalizePath = (filepath) => {
|
2
|
+
// Remove leading ./
|
3
|
+
let normalized = filepath.replace(/^\.\//, "");
|
4
|
+
// Replace multiple slashes with single slash
|
5
|
+
normalized = normalized.replace(/\/+/g, "/");
|
6
|
+
// Remove trailing slash
|
7
|
+
normalized = normalized.replace(/\/$/, "");
|
8
|
+
return normalized;
|
9
|
+
};
|
10
|
+
const joinPaths = (base, relative) => {
|
11
|
+
// Get directory name of base path
|
12
|
+
const baseDir = base.includes("/")
|
13
|
+
? base.slice(0, base.lastIndexOf("/"))
|
14
|
+
: "";
|
15
|
+
// Handle .. by removing one directory level
|
16
|
+
const parts = relative.split("/");
|
17
|
+
const resultParts = baseDir
|
18
|
+
? baseDir.split("/")
|
19
|
+
: [];
|
20
|
+
for (const part of parts) {
|
21
|
+
if (part === "..") {
|
22
|
+
resultParts.pop();
|
23
|
+
}
|
24
|
+
else if (part !== "." && part !== "") {
|
25
|
+
resultParts.push(part);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
return resultParts.join("/");
|
29
|
+
};
|
30
|
+
export const virtualFileSystem = (files) => {
|
31
|
+
return {
|
32
|
+
name: "virtual-file-system",
|
33
|
+
resolveId(source, importer) {
|
34
|
+
// Handle relative paths
|
35
|
+
if (source.startsWith("./") ||
|
36
|
+
source.startsWith("../")) {
|
37
|
+
const resolvedPath = importer
|
38
|
+
? normalizePath(joinPaths(importer, source))
|
39
|
+
: normalizePath(source);
|
40
|
+
// Try exact match first
|
41
|
+
if (files[resolvedPath]) {
|
42
|
+
return resolvedPath;
|
43
|
+
}
|
44
|
+
// Try with extensions if no exact match is found
|
45
|
+
const extensions = [".js", ".jsx", ".ts", ".tsx"];
|
46
|
+
for (const ext of extensions) {
|
47
|
+
const pathWithExt = resolvedPath + ext;
|
48
|
+
if (files[pathWithExt]) {
|
49
|
+
return pathWithExt;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
// Handle bare module imports
|
54
|
+
if (files[source]) {
|
55
|
+
return source;
|
56
|
+
}
|
57
|
+
// Try bare imports with extensions
|
58
|
+
const extensions = [".js", ".jsx", ".ts", ".tsx"];
|
59
|
+
for (const ext of extensions) {
|
60
|
+
const pathWithExt = source + ext;
|
61
|
+
if (files[pathWithExt]) {
|
62
|
+
return pathWithExt;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
return null;
|
66
|
+
},
|
67
|
+
load(id) {
|
68
|
+
// Return the contents if the file exists in our virtual system
|
69
|
+
if (files[id]) {
|
70
|
+
return files[id];
|
71
|
+
}
|
72
|
+
return null;
|
73
|
+
},
|
74
|
+
};
|
75
|
+
};
|
@@ -0,0 +1,22 @@
|
|
1
|
+
export const determineRuntimeVersion = (files) => {
|
2
|
+
if (Object.keys(files).length === 0) {
|
3
|
+
return null;
|
4
|
+
}
|
5
|
+
const hasIndexHTML = "index.html" in files;
|
6
|
+
const hasIndexJS = "index.js" in files;
|
7
|
+
const hasIndexJSX = "index.jsx" in files;
|
8
|
+
if (hasIndexHTML) {
|
9
|
+
const hasModuleScript = files["index.html"].includes('type="module"');
|
10
|
+
if (hasModuleScript) {
|
11
|
+
return "v4";
|
12
|
+
}
|
13
|
+
if (hasIndexJS || hasIndexJSX) {
|
14
|
+
return "v2";
|
15
|
+
}
|
16
|
+
return "v1";
|
17
|
+
}
|
18
|
+
if (!hasIndexHTML && hasIndexJS) {
|
19
|
+
return "v3";
|
20
|
+
}
|
21
|
+
return null;
|
22
|
+
};
|
@@ -0,0 +1,101 @@
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
2
|
+
import { determineRuntimeVersion } from "./determineRuntimeVersion";
|
3
|
+
import { jsScriptTagTypeModule, jsScriptTagTypeModules, fetchInterception, esmBuild, } from "./test/fixtures/v4";
|
4
|
+
describe("determineRuntimeVersion", () => {
|
5
|
+
it("should return null when there are no files", () => {
|
6
|
+
const mockFiles = {};
|
7
|
+
const result = determineRuntimeVersion(mockFiles);
|
8
|
+
expect(result).toBe(null);
|
9
|
+
});
|
10
|
+
it("should return v1 when only index.html exists", () => {
|
11
|
+
const mockFiles = {
|
12
|
+
"index.html": "<html></html>",
|
13
|
+
};
|
14
|
+
const result = determineRuntimeVersion(mockFiles);
|
15
|
+
expect(result).toBe("v1");
|
16
|
+
});
|
17
|
+
it("should return v2 when both index.html and index.js exist", () => {
|
18
|
+
const mockFiles = {
|
19
|
+
"index.html": "<html></html>",
|
20
|
+
"index.js": 'console.log("Hello");',
|
21
|
+
};
|
22
|
+
const result = determineRuntimeVersion(mockFiles);
|
23
|
+
expect(result).toBe("v2");
|
24
|
+
});
|
25
|
+
it("should return v2 when both index.html and index.jsx exist", () => {
|
26
|
+
const mockFiles = {
|
27
|
+
"index.html": "<html></html>",
|
28
|
+
"index.jsx": 'console.log("Hello");',
|
29
|
+
};
|
30
|
+
const result = determineRuntimeVersion(mockFiles);
|
31
|
+
expect(result).toBe("v2");
|
32
|
+
});
|
33
|
+
it("should return v3 when only index.js exists", () => {
|
34
|
+
const mockFiles = {
|
35
|
+
"index.js": 'console.log("Hello");',
|
36
|
+
};
|
37
|
+
const result = determineRuntimeVersion(mockFiles);
|
38
|
+
expect(result).toBe("v3");
|
39
|
+
});
|
40
|
+
it("should return null when only index.jsx exists (no v3 support for JSX)", () => {
|
41
|
+
const mockFiles = {
|
42
|
+
"index.jsx": 'console.log("Hello");',
|
43
|
+
};
|
44
|
+
const result = determineRuntimeVersion(mockFiles);
|
45
|
+
expect(result).toBe(null);
|
46
|
+
});
|
47
|
+
it("should return v4 when index.html contains script type=module with importmap", () => {
|
48
|
+
const mockFiles = {
|
49
|
+
"index.html": `
|
50
|
+
<!DOCTYPE html>
|
51
|
+
<html>
|
52
|
+
<head>
|
53
|
+
<script type="importmap">
|
54
|
+
{ "imports": { "test": "./test.js" } }
|
55
|
+
</script>
|
56
|
+
</head>
|
57
|
+
<body>
|
58
|
+
<script type="module" src="index.js"></script>
|
59
|
+
</body>
|
60
|
+
</html>
|
61
|
+
`,
|
62
|
+
"index.js": 'import { hello } from "test"; console.log(hello);',
|
63
|
+
"test.js": 'export const hello = "world";',
|
64
|
+
};
|
65
|
+
const result = determineRuntimeVersion(mockFiles);
|
66
|
+
expect(result).toBe("v4");
|
67
|
+
});
|
68
|
+
it("should return v4 when multiple module scripts are present", () => {
|
69
|
+
const mockFiles = {
|
70
|
+
"index.html": `
|
71
|
+
<!DOCTYPE html>
|
72
|
+
<html>
|
73
|
+
<body>
|
74
|
+
<script type="module" src="index.js"></script>
|
75
|
+
</body>
|
76
|
+
</html>
|
77
|
+
`,
|
78
|
+
"index.js": 'import { hello } from "./utils.js"; console.log(hello);',
|
79
|
+
"utils.js": 'export const hello = "world";',
|
80
|
+
};
|
81
|
+
const result = determineRuntimeVersion(mockFiles);
|
82
|
+
expect(result).toBe("v4");
|
83
|
+
});
|
84
|
+
// Test v4 fixtures
|
85
|
+
it("should detect v4 for jsScriptTagTypeModule fixture", () => {
|
86
|
+
const result = determineRuntimeVersion(jsScriptTagTypeModule);
|
87
|
+
expect(result).toBe("v4");
|
88
|
+
});
|
89
|
+
it("should detect v4 for jsScriptTagTypeModules fixture", () => {
|
90
|
+
const result = determineRuntimeVersion(jsScriptTagTypeModules);
|
91
|
+
expect(result).toBe("v4");
|
92
|
+
});
|
93
|
+
it("should detect v4 for fetchInterception fixture", () => {
|
94
|
+
const result = determineRuntimeVersion(fetchInterception);
|
95
|
+
expect(result).toBe("v4");
|
96
|
+
});
|
97
|
+
it("should detect v4 for esmBuild fixture", () => {
|
98
|
+
const result = determineRuntimeVersion(esmBuild);
|
99
|
+
expect(result).toBe("v4");
|
100
|
+
});
|
101
|
+
});
|
@@ -0,0 +1,15 @@
|
|
1
|
+
export const basicHTML = {
|
2
|
+
"index.html": `<!DOCTYPE html>
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<title>My HTML Document</title>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<h1>Hello, World!</h1>
|
9
|
+
<p>This is my first HTML document.</p>
|
10
|
+
<script>
|
11
|
+
console.log('Hello, World!');
|
12
|
+
</script>
|
13
|
+
</body>
|
14
|
+
</html>`,
|
15
|
+
};
|
@@ -0,0 +1,12 @@
|
|
1
|
+
export const fetchProxy = {
|
2
|
+
"index.html": `<!DOCTYPE html>
|
3
|
+
<html>
|
4
|
+
<body>
|
5
|
+
<script src="index.js"></script>
|
6
|
+
</body>
|
7
|
+
</html>`,
|
8
|
+
"index.js": `fetch("data.csv")
|
9
|
+
.then((response) => response.text())
|
10
|
+
.then(console.log);`,
|
11
|
+
"data.csv": `Hello, Fetch!`,
|
12
|
+
};
|