@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,105 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const puppeteer_1 = __importDefault(require("puppeteer"));
|
7
|
+
const vitest_1 = require("vitest");
|
8
|
+
const testInBrowser_1 = require("./testInBrowser");
|
9
|
+
const v4_1 = require("./fixtures/v4");
|
10
|
+
let browser;
|
11
|
+
(0, vitest_1.beforeAll)(async () => {
|
12
|
+
browser = await puppeteer_1.default.launch();
|
13
|
+
});
|
14
|
+
(0, vitest_1.afterAll)(async () => {
|
15
|
+
await browser.close();
|
16
|
+
});
|
17
|
+
(0, vitest_1.describe)("VizHub Runtime v4", () => {
|
18
|
+
(0, vitest_1.it)("should handle script type=module with import maps", async () => {
|
19
|
+
await (0, testInBrowser_1.testInBrowser)({
|
20
|
+
browser,
|
21
|
+
files: v4_1.jsScriptTagTypeModule,
|
22
|
+
expectedLog: "Hello, ES Module!",
|
23
|
+
});
|
24
|
+
});
|
25
|
+
(0, vitest_1.it)("should handle script type=module with file imports", async () => {
|
26
|
+
await (0, testInBrowser_1.testInBrowser)({
|
27
|
+
browser,
|
28
|
+
files: v4_1.jsScriptTagTypeModules,
|
29
|
+
expectedLog: "Hello, ES Module File!",
|
30
|
+
});
|
31
|
+
});
|
32
|
+
(0, vitest_1.it)("should handle fetch interception", async () => {
|
33
|
+
await (0, testInBrowser_1.testInBrowser)({
|
34
|
+
browser,
|
35
|
+
files: v4_1.fetchInterception,
|
36
|
+
expectedLog: "Fetch intercepted successfully",
|
37
|
+
});
|
38
|
+
});
|
39
|
+
vitest_1.it.skip("should handle ESM builds from npm packages", async () => {
|
40
|
+
await (0, testInBrowser_1.testInBrowser)({
|
41
|
+
browser,
|
42
|
+
files: v4_1.esmBuild,
|
43
|
+
expectedLog: new RegExp(/\d{4}-\d{2}-\d{2}/), // matches date format yyyy-MM-dd
|
44
|
+
});
|
45
|
+
});
|
46
|
+
vitest_1.it.skip("should handle React JSX", async () => {
|
47
|
+
await (0, testInBrowser_1.testInBrowser)({
|
48
|
+
browser,
|
49
|
+
files: v4_1.reactJsx,
|
50
|
+
expectedLog: "Hello React JSX!",
|
51
|
+
evaluateInBrowser: async (page) => {
|
52
|
+
return await page.evaluate(() => {
|
53
|
+
return document.querySelector("#root div")
|
54
|
+
?.textContent;
|
55
|
+
});
|
56
|
+
},
|
57
|
+
});
|
58
|
+
});
|
59
|
+
vitest_1.it.skip("should handle D3 usage", async () => {
|
60
|
+
await (0, testInBrowser_1.testInBrowser)({
|
61
|
+
browser,
|
62
|
+
files: v4_1.d3Usage,
|
63
|
+
expectedLog: "D3 chart rendered successfully",
|
64
|
+
evaluateInBrowser: async (page) => {
|
65
|
+
return await page.evaluate(() => {
|
66
|
+
return (document.querySelector("#chart svg circle") !==
|
67
|
+
null);
|
68
|
+
});
|
69
|
+
},
|
70
|
+
});
|
71
|
+
});
|
72
|
+
(0, vitest_1.it)("should handle Three.js usage", async () => {
|
73
|
+
await (0, testInBrowser_1.testInBrowser)({
|
74
|
+
browser,
|
75
|
+
files: v4_1.threeJsUsage,
|
76
|
+
expectedLog: "Three.js imports: object function",
|
77
|
+
});
|
78
|
+
});
|
79
|
+
vitest_1.it.skip("should handle React hooks", async () => {
|
80
|
+
await (0, testInBrowser_1.testInBrowser)({
|
81
|
+
browser,
|
82
|
+
files: v4_1.reactHooks,
|
83
|
+
expectedLog: "React Hooks working: count is 0",
|
84
|
+
evaluateInBrowser: async (page) => {
|
85
|
+
return await page.evaluate(() => {
|
86
|
+
return (document.querySelector("#root p")
|
87
|
+
?.textContent === "You clicked 0 times");
|
88
|
+
});
|
89
|
+
},
|
90
|
+
});
|
91
|
+
});
|
92
|
+
vitest_1.it.skip("should handle TypeScript support", async () => {
|
93
|
+
await (0, testInBrowser_1.testInBrowser)({
|
94
|
+
browser,
|
95
|
+
files: v4_1.typeScriptSupport,
|
96
|
+
expectedLog: "TypeScript is working",
|
97
|
+
evaluateInBrowser: async (page) => {
|
98
|
+
return await page.evaluate(() => {
|
99
|
+
return (document.querySelector("#app h1")
|
100
|
+
?.textContent === "Hello, John Doe!");
|
101
|
+
});
|
102
|
+
},
|
103
|
+
});
|
104
|
+
});
|
105
|
+
});
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.vizContentToFileCollection = void 0;
|
4
|
+
/**
|
5
|
+
* Converts VizContent format to FileCollection format
|
6
|
+
* VizContent has files as {id: {name, text}} structure
|
7
|
+
* FileCollection is a simple {name: text} structure
|
8
|
+
*/
|
9
|
+
const vizContentToFileCollection = (vizContent) => {
|
10
|
+
const fileCollection = {};
|
11
|
+
// Extract files from vizContent
|
12
|
+
const { files } = vizContent;
|
13
|
+
// Return empty object if files is undefined
|
14
|
+
if (!files) {
|
15
|
+
return fileCollection;
|
16
|
+
}
|
17
|
+
// Convert each VizFile to the FileCollection format
|
18
|
+
Object.values(files).forEach((file) => {
|
19
|
+
fileCollection[file.name] = file.text;
|
20
|
+
});
|
21
|
+
return fileCollection;
|
22
|
+
};
|
23
|
+
exports.vizContentToFileCollection = vizContentToFileCollection;
|
@@ -0,0 +1,77 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const vitest_1 = require("vitest");
|
4
|
+
const vizContentToFileCollection_1 = require("./vizContentToFileCollection");
|
5
|
+
(0, vitest_1.describe)("vizContentToFileCollection", () => {
|
6
|
+
(0, vitest_1.it)("should convert VizContent files to FileCollection format", () => {
|
7
|
+
const mockVizContent = {
|
8
|
+
id: "test-viz-123",
|
9
|
+
files: {
|
10
|
+
file1: {
|
11
|
+
name: "index.html",
|
12
|
+
text: "<html>Test</html>",
|
13
|
+
},
|
14
|
+
file2: {
|
15
|
+
name: "script.js",
|
16
|
+
text: 'console.log("Hello");',
|
17
|
+
},
|
18
|
+
},
|
19
|
+
};
|
20
|
+
const result = (0, vizContentToFileCollection_1.vizContentToFileCollection)(mockVizContent);
|
21
|
+
(0, vitest_1.expect)(result).toEqual({
|
22
|
+
"index.html": "<html>Test</html>",
|
23
|
+
"script.js": 'console.log("Hello");',
|
24
|
+
});
|
25
|
+
});
|
26
|
+
(0, vitest_1.it)("should return an empty object when no files exist", () => {
|
27
|
+
const mockVizContent = {
|
28
|
+
id: "empty-viz",
|
29
|
+
files: {},
|
30
|
+
};
|
31
|
+
const result = (0, vizContentToFileCollection_1.vizContentToFileCollection)(mockVizContent);
|
32
|
+
(0, vitest_1.expect)(result).toEqual({});
|
33
|
+
});
|
34
|
+
(0, vitest_1.it)("should return an empty object when no files property", () => {
|
35
|
+
const mockVizContent = {
|
36
|
+
id: "empty-viz",
|
37
|
+
// @ts-ignore
|
38
|
+
files: undefined,
|
39
|
+
};
|
40
|
+
const result = (0, vizContentToFileCollection_1.vizContentToFileCollection)(mockVizContent);
|
41
|
+
(0, vitest_1.expect)(result).toEqual({});
|
42
|
+
});
|
43
|
+
(0, vitest_1.it)("should handle files with special characters in names", () => {
|
44
|
+
const mockVizContent = {
|
45
|
+
id: "special-chars-viz",
|
46
|
+
files: {
|
47
|
+
fileId1: {
|
48
|
+
name: "file with spaces.txt",
|
49
|
+
text: "content",
|
50
|
+
},
|
51
|
+
fileId2: { name: "data.csv", text: "a,b,c\n1,2,3" },
|
52
|
+
},
|
53
|
+
};
|
54
|
+
const result = (0, vizContentToFileCollection_1.vizContentToFileCollection)(mockVizContent);
|
55
|
+
(0, vitest_1.expect)(result).toEqual({
|
56
|
+
"file with spaces.txt": "content",
|
57
|
+
"data.csv": "a,b,c\n1,2,3",
|
58
|
+
});
|
59
|
+
});
|
60
|
+
(0, vitest_1.it)("should preserve file content exactly", () => {
|
61
|
+
const longText = `function complex() {
|
62
|
+
return {
|
63
|
+
nested: {
|
64
|
+
data: [1, 2, 3]
|
65
|
+
}
|
66
|
+
};
|
67
|
+
}`;
|
68
|
+
const mockVizContent = {
|
69
|
+
id: "preserve-content-viz",
|
70
|
+
files: {
|
71
|
+
fileId: { name: "complex.js", text: longText },
|
72
|
+
},
|
73
|
+
};
|
74
|
+
const result = (0, vizContentToFileCollection_1.vizContentToFileCollection)(mockVizContent);
|
75
|
+
(0, vitest_1.expect)(result["complex.js"]).toBe(longText);
|
76
|
+
});
|
77
|
+
});
|
@@ -0,0 +1,33 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.computeBundleJSV2 = void 0;
|
4
|
+
const virtualFileSystem_1 = require("../common/virtualFileSystem");
|
5
|
+
const sucrasePlugin_1 = require("../common/sucrasePlugin");
|
6
|
+
const packageJson_1 = require("../common/packageJson");
|
7
|
+
const computeBundleJSV2 = async ({ files, rollup, enableSourcemap = true, }) => {
|
8
|
+
const indexJSContent = files["index.js"];
|
9
|
+
if (!indexJSContent) {
|
10
|
+
throw new Error("Missing index.js");
|
11
|
+
}
|
12
|
+
const inputOptions = {
|
13
|
+
input: "./index.js",
|
14
|
+
plugins: [(0, virtualFileSystem_1.virtualFileSystem)(files), (0, sucrasePlugin_1.sucrasePlugin)()],
|
15
|
+
onwarn(warning, warn) {
|
16
|
+
// Suppress "treating module as external dependency" warnings
|
17
|
+
if (warning.code === "UNRESOLVED_IMPORT")
|
18
|
+
return;
|
19
|
+
warn(warning);
|
20
|
+
},
|
21
|
+
};
|
22
|
+
const bundle = await rollup(inputOptions);
|
23
|
+
const pkg = (0, packageJson_1.packageJSON)(files);
|
24
|
+
const globals = (0, packageJson_1.getGlobals)(pkg);
|
25
|
+
const outputOptions = {
|
26
|
+
format: "iife",
|
27
|
+
globals,
|
28
|
+
sourcemap: enableSourcemap,
|
29
|
+
};
|
30
|
+
const { output } = await bundle.generate(outputOptions);
|
31
|
+
return output[0].code;
|
32
|
+
};
|
33
|
+
exports.computeBundleJSV2 = computeBundleJSV2;
|
@@ -0,0 +1,86 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getComputedIndexHtml = exports.setJSDOM = void 0;
|
4
|
+
const packageJson_1 = require("../common/packageJson");
|
5
|
+
let parser;
|
6
|
+
const DEBUG = false;
|
7
|
+
// Expose a way to inject a DOMParser implementation
|
8
|
+
// when we're in a Node environment (tests, API server).
|
9
|
+
const setJSDOM = (JSDOMInstance) => {
|
10
|
+
const dom = new JSDOMInstance();
|
11
|
+
parser = new dom.window.DOMParser();
|
12
|
+
};
|
13
|
+
exports.setJSDOM = setJSDOM;
|
14
|
+
// If we're in the browser, use native DOMParser.
|
15
|
+
if (typeof window !== "undefined") {
|
16
|
+
parser = new DOMParser();
|
17
|
+
}
|
18
|
+
const injectScripts = (htmlTemplate, files) => {
|
19
|
+
if (!parser) {
|
20
|
+
throw new Error("DOM parser is not defined. Did you forget to call setJSDOM()?");
|
21
|
+
}
|
22
|
+
const doc = parser.parseFromString(htmlTemplate, "text/html");
|
23
|
+
// Ensure we have a head element
|
24
|
+
if (!doc.head) {
|
25
|
+
const head = doc.createElement("head");
|
26
|
+
doc.documentElement.insertBefore(head, doc.documentElement.firstChild);
|
27
|
+
}
|
28
|
+
// Ensure we have a body element
|
29
|
+
if (!doc.body) {
|
30
|
+
const body = doc.createElement("body");
|
31
|
+
doc.documentElement.appendChild(body);
|
32
|
+
}
|
33
|
+
// Handle dependencies first (in head)
|
34
|
+
const deps = Object.entries((0, packageJson_1.dependencies)(files));
|
35
|
+
if (deps.length > 0) {
|
36
|
+
const libraries = (0, packageJson_1.getConfiguredLibraries)(files);
|
37
|
+
// Remove any existing dependency scripts
|
38
|
+
deps.forEach(([name]) => {
|
39
|
+
const selector = `script[src*="${name}@"]`;
|
40
|
+
const existingScripts = doc.querySelectorAll(selector);
|
41
|
+
existingScripts.forEach((script) => script.remove());
|
42
|
+
});
|
43
|
+
// Add dependency scripts in order
|
44
|
+
deps
|
45
|
+
.map(([name, version]) => (0, packageJson_1.dependencySource)({ name, version }, libraries))
|
46
|
+
.forEach((url) => {
|
47
|
+
const scriptTag = doc.createElement("script");
|
48
|
+
scriptTag.src = url;
|
49
|
+
doc.head.appendChild(scriptTag);
|
50
|
+
});
|
51
|
+
}
|
52
|
+
// Handle bundle.js (in body)
|
53
|
+
if (files["bundle.js"] || files["index.js"]) {
|
54
|
+
// Remove any existing bundle.js script tags
|
55
|
+
const existingScripts = doc.querySelectorAll('script[src="bundle.js"]');
|
56
|
+
existingScripts.forEach((script) => script.remove());
|
57
|
+
const bundleScriptTag = doc.createElement("script");
|
58
|
+
bundleScriptTag.src = "bundle.js";
|
59
|
+
doc.body.appendChild(bundleScriptTag);
|
60
|
+
}
|
61
|
+
return `<!DOCTYPE html>${doc.documentElement.outerHTML}`;
|
62
|
+
};
|
63
|
+
// Compute the index.html file from the files.
|
64
|
+
// Includes:
|
65
|
+
// - bundle.js script tag
|
66
|
+
// - dependencies script tag(s)
|
67
|
+
const getComputedIndexHtml = (files) => {
|
68
|
+
// Isolate the index.html file.
|
69
|
+
const htmlTemplate = files["index.html"];
|
70
|
+
// If there is no index.html file, return an empty string.
|
71
|
+
if (!htmlTemplate &&
|
72
|
+
!files["index.js"] &&
|
73
|
+
!files["bundle.js"]) {
|
74
|
+
DEBUG &&
|
75
|
+
console.log("[getComputedIndexHtml] No index.html file found");
|
76
|
+
return "";
|
77
|
+
}
|
78
|
+
// If index.html is empty but we have JS files, create a minimal HTML template
|
79
|
+
const template = htmlTemplate ||
|
80
|
+
"<!DOCTYPE html><html><head></head><body></body></html>";
|
81
|
+
const indexHtml = injectScripts(template, files);
|
82
|
+
DEBUG &&
|
83
|
+
console.log("[getComputedIndexHtml] indexHtml", indexHtml);
|
84
|
+
return indexHtml;
|
85
|
+
};
|
86
|
+
exports.getComputedIndexHtml = getComputedIndexHtml;
|
@@ -0,0 +1,136 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const vitest_1 = require("vitest");
|
4
|
+
const getComputedIndexHtml_1 = require("./getComputedIndexHtml");
|
5
|
+
const jsdom_1 = require("jsdom");
|
6
|
+
const d3ImportPkg_1 = require("../test/fixtures/v2/d3ImportPkg");
|
7
|
+
(0, getComputedIndexHtml_1.setJSDOM)(jsdom_1.JSDOM);
|
8
|
+
(0, vitest_1.describe)("v2 getComputedIndexHtml", () => {
|
9
|
+
(0, vitest_1.it)("should return empty string if missing index.html", async () => {
|
10
|
+
const files = {};
|
11
|
+
(0, vitest_1.expect)((0, getComputedIndexHtml_1.getComputedIndexHtml)(files)).toEqual(``);
|
12
|
+
});
|
13
|
+
(0, vitest_1.it)("should preserve existing index.html if no bundle and no package.json", async () => {
|
14
|
+
const text = "<!DOCTYPE html><html><head></head><body><h1>Hello World</h1></body></html>";
|
15
|
+
const files = { "index.html": text };
|
16
|
+
(0, vitest_1.expect)((0, getComputedIndexHtml_1.getComputedIndexHtml)(files)).toEqual(text);
|
17
|
+
});
|
18
|
+
(0, vitest_1.it)("should add bundle.js, no package.json", async () => {
|
19
|
+
const text = '<!DOCTYPE html><html><head></head><body><script src="bundle.js"></script></body></html>';
|
20
|
+
const files = {
|
21
|
+
"index.html": text,
|
22
|
+
"index.js": 'console.log("Hello")',
|
23
|
+
};
|
24
|
+
// console.log(JSON.stringify(getComputedIndexHtml(files), null, 2));
|
25
|
+
(0, vitest_1.expect)((0, getComputedIndexHtml_1.getComputedIndexHtml)(files)).toEqual(text);
|
26
|
+
});
|
27
|
+
(0, vitest_1.it)("should handle d3 dependency from package.json", async () => {
|
28
|
+
const files = d3ImportPkg_1.d3ImportPkg;
|
29
|
+
const result = (0, getComputedIndexHtml_1.getComputedIndexHtml)(files);
|
30
|
+
// Create a DOM to parse and check the result
|
31
|
+
const dom = new jsdom_1.JSDOM(result);
|
32
|
+
const document = dom.window.document;
|
33
|
+
// Check that we have the d3 script in the head
|
34
|
+
const d3Script = document.querySelector('head script[src*="d3@6.7.0"]');
|
35
|
+
(0, vitest_1.expect)(d3Script).not.toBeNull();
|
36
|
+
// Check that we have the bundle.js script in the body
|
37
|
+
const bundleScript = document.querySelector('body script[src="bundle.js"]');
|
38
|
+
(0, vitest_1.expect)(bundleScript).not.toBeNull();
|
39
|
+
// Verify the order: d3 in head, bundle.js in body
|
40
|
+
(0, vitest_1.expect)(result.indexOf("d3@6.7.0")).toBeLessThan(result.indexOf("<body>"));
|
41
|
+
(0, vitest_1.expect)(result.indexOf("<body>")).toBeLessThan(result.indexOf("bundle.js"));
|
42
|
+
});
|
43
|
+
// Edge cases and degenerate inputs
|
44
|
+
(0, vitest_1.it)("should handle malformed HTML in index.html", async () => {
|
45
|
+
const malformedHtml = "<html><head>No closing head tag<body>No closing body tag";
|
46
|
+
const files = {
|
47
|
+
"index.html": malformedHtml,
|
48
|
+
"index.js": 'console.log("Hello")',
|
49
|
+
};
|
50
|
+
const result = (0, getComputedIndexHtml_1.getComputedIndexHtml)(files);
|
51
|
+
// Should still have both head and body tags
|
52
|
+
(0, vitest_1.expect)(result).toContain("<head>");
|
53
|
+
(0, vitest_1.expect)(result).toContain("</head>");
|
54
|
+
(0, vitest_1.expect)(result).toContain("<body>");
|
55
|
+
(0, vitest_1.expect)(result).toContain("</body>");
|
56
|
+
// Should have bundle.js in the body
|
57
|
+
const dom = new jsdom_1.JSDOM(result);
|
58
|
+
const bundleScript = dom.window.document.querySelector('body script[src="bundle.js"]');
|
59
|
+
(0, vitest_1.expect)(bundleScript).not.toBeNull();
|
60
|
+
});
|
61
|
+
(0, vitest_1.it)("should handle HTML without html, head, or body tags", async () => {
|
62
|
+
const minimalHtml = "<div>Just a div</div>";
|
63
|
+
const files = {
|
64
|
+
"index.html": minimalHtml,
|
65
|
+
"index.js": 'console.log("Hello")',
|
66
|
+
"package.json": JSON.stringify({
|
67
|
+
dependencies: {
|
68
|
+
d3: "6.7.0",
|
69
|
+
},
|
70
|
+
}),
|
71
|
+
};
|
72
|
+
const result = (0, getComputedIndexHtml_1.getComputedIndexHtml)(files);
|
73
|
+
// Should create proper HTML structure
|
74
|
+
(0, vitest_1.expect)(result).toContain("<html>");
|
75
|
+
(0, vitest_1.expect)(result).toContain("<head>");
|
76
|
+
(0, vitest_1.expect)(result).toContain("<body>");
|
77
|
+
// Should have d3 in head and bundle.js in body
|
78
|
+
const dom = new jsdom_1.JSDOM(result);
|
79
|
+
const document = dom.window.document;
|
80
|
+
const d3Script = document.querySelector('head script[src*="d3@6.7.0"]');
|
81
|
+
(0, vitest_1.expect)(d3Script).not.toBeNull();
|
82
|
+
const bundleScript = document.querySelector('body script[src="bundle.js"]');
|
83
|
+
(0, vitest_1.expect)(bundleScript).not.toBeNull();
|
84
|
+
// Original content should be preserved
|
85
|
+
(0, vitest_1.expect)(result).toContain("<div>Just a div</div>");
|
86
|
+
});
|
87
|
+
(0, vitest_1.it)("should handle empty index.html", async () => {
|
88
|
+
const files = {
|
89
|
+
"index.html": "",
|
90
|
+
"index.js": 'console.log("Hello")',
|
91
|
+
};
|
92
|
+
const result = (0, getComputedIndexHtml_1.getComputedIndexHtml)(files);
|
93
|
+
// Should create a minimal HTML structure with bundle.js
|
94
|
+
(0, vitest_1.expect)(result).toContain("<html>");
|
95
|
+
(0, vitest_1.expect)(result).toContain("<body>");
|
96
|
+
(0, vitest_1.expect)(result).toContain('script src="bundle.js"');
|
97
|
+
});
|
98
|
+
(0, vitest_1.it)("should handle multiple existing script tags", async () => {
|
99
|
+
const html = `
|
100
|
+
<!DOCTYPE html>
|
101
|
+
<html>
|
102
|
+
<head>
|
103
|
+
<script src="existing1.js"></script>
|
104
|
+
<script src="bundle.js"></script>
|
105
|
+
</head>
|
106
|
+
<body>
|
107
|
+
<script src="existing2.js"></script>
|
108
|
+
<script src="bundle.js"></script>
|
109
|
+
</body>
|
110
|
+
</html>
|
111
|
+
`;
|
112
|
+
const files = {
|
113
|
+
"index.html": html,
|
114
|
+
"index.js": 'console.log("Hello")',
|
115
|
+
"package.json": JSON.stringify({
|
116
|
+
dependencies: {
|
117
|
+
d3: "6.7.0",
|
118
|
+
},
|
119
|
+
}),
|
120
|
+
};
|
121
|
+
const result = (0, getComputedIndexHtml_1.getComputedIndexHtml)(files);
|
122
|
+
// Create DOM to analyze the result
|
123
|
+
const dom = new jsdom_1.JSDOM(result);
|
124
|
+
const document = dom.window.document;
|
125
|
+
// Should keep existing scripts
|
126
|
+
(0, vitest_1.expect)(document.querySelectorAll('script[src="existing1.js"]').length).toBe(1);
|
127
|
+
(0, vitest_1.expect)(document.querySelectorAll('script[src="existing2.js"]').length).toBe(1);
|
128
|
+
// Should have exactly one bundle.js script in the body
|
129
|
+
const bundleScripts = document.querySelectorAll('script[src="bundle.js"]');
|
130
|
+
(0, vitest_1.expect)(bundleScripts.length).toBe(1);
|
131
|
+
(0, vitest_1.expect)(bundleScripts[0].parentElement).toBe(document.body);
|
132
|
+
// Should have d3 script in the head
|
133
|
+
const d3Script = document.querySelector('head script[src*="d3@6.7.0"]');
|
134
|
+
(0, vitest_1.expect)(d3Script).not.toBeNull();
|
135
|
+
});
|
136
|
+
});
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.v2Build = void 0;
|
4
|
+
const getComputedIndexHtml_1 = require("./getComputedIndexHtml");
|
5
|
+
const computeBundleJSV2_1 = require("./computeBundleJSV2");
|
6
|
+
const v2Build = async ({ files, rollup, enableSourcemap, }) => ({
|
7
|
+
...files,
|
8
|
+
"bundle.js": await (0, computeBundleJSV2_1.computeBundleJSV2)({
|
9
|
+
files,
|
10
|
+
rollup,
|
11
|
+
enableSourcemap,
|
12
|
+
}),
|
13
|
+
"index.html": (0, getComputedIndexHtml_1.getComputedIndexHtml)(files),
|
14
|
+
});
|
15
|
+
exports.v2Build = v2Build;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.cleanRollupErrorMessage = void 0;
|
4
|
+
// We want to remove the vizId from the error message
|
5
|
+
// to make it more user-friendly.
|
6
|
+
// Example error message before and after:
|
7
|
+
// Before: "7f0b69fcb754479699172d1887817027/index.js (14:8): Expected ';', '}' or <eof>"
|
8
|
+
// After: "./index.js (14:8): Expected ';', '}' or <eof>"
|
9
|
+
const cleanRollupErrorMessage = ({ rawMessage, vizId, }) => {
|
10
|
+
const regex = new RegExp(vizId, "g");
|
11
|
+
return rawMessage?.replace(regex, ".");
|
12
|
+
};
|
13
|
+
exports.cleanRollupErrorMessage = cleanRollupErrorMessage;
|
@@ -0,0 +1,52 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.computeBundleJSV3 = void 0;
|
4
|
+
const sucrasePlugin_1 = require("../common/sucrasePlugin");
|
5
|
+
const packageJson_1 = require("../common/packageJson");
|
6
|
+
const transformDSV_1 = require("./transformDSV");
|
7
|
+
const vizResolve_1 = require("./vizResolve");
|
8
|
+
const vizLoad_1 = require("./vizLoad");
|
9
|
+
const transformSvelte_1 = require("./transformSvelte");
|
10
|
+
const computeBundleJSV3 = async ({ files, rollup, enableSourcemap = true, vizCache, vizId, slugCache, getSvelteCompiler, }) => {
|
11
|
+
// Track CSS imports
|
12
|
+
const cssFilesSet = new Set();
|
13
|
+
const trackCSSImport = (cssFile) => {
|
14
|
+
cssFilesSet.add(cssFile);
|
15
|
+
};
|
16
|
+
const indexJSContent = files["index.js"];
|
17
|
+
if (!indexJSContent) {
|
18
|
+
throw new Error("Missing index.js");
|
19
|
+
}
|
20
|
+
const inputOptions = {
|
21
|
+
input: "./index.js",
|
22
|
+
plugins: [
|
23
|
+
(0, vizResolve_1.vizResolve)({ vizId, slugCache }),
|
24
|
+
(0, transformDSV_1.transformDSV)(),
|
25
|
+
(0, sucrasePlugin_1.sucrasePlugin)(),
|
26
|
+
(0, transformSvelte_1.transformSvelte)({ getSvelteCompiler }),
|
27
|
+
(0, vizLoad_1.vizLoad)({ vizCache, trackCSSImport }),
|
28
|
+
],
|
29
|
+
onwarn(warning, warn) {
|
30
|
+
// Suppress "treating module as external dependency" warnings
|
31
|
+
if (warning.code === "UNRESOLVED_IMPORT")
|
32
|
+
return;
|
33
|
+
warn(warning);
|
34
|
+
},
|
35
|
+
};
|
36
|
+
const bundle = await rollup(inputOptions);
|
37
|
+
const pkg = (0, packageJson_1.packageJSON)(files);
|
38
|
+
const globals = (0, packageJson_1.getGlobals)(pkg);
|
39
|
+
const outputOptions = {
|
40
|
+
format: "umd",
|
41
|
+
name: "Viz",
|
42
|
+
sourcemap: enableSourcemap ? true : false,
|
43
|
+
compact: true,
|
44
|
+
globals,
|
45
|
+
};
|
46
|
+
const { output } = await bundle.generate(outputOptions);
|
47
|
+
return {
|
48
|
+
src: output[0].code,
|
49
|
+
cssFiles: Array.from(cssFilesSet),
|
50
|
+
};
|
51
|
+
};
|
52
|
+
exports.computeBundleJSV3 = computeBundleJSV3;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createVizContent = void 0;
|
4
|
+
const uuid_1 = require("uuid");
|
5
|
+
/**
|
6
|
+
* Creates a VizContent object with the given files
|
7
|
+
* @param files An object with file names as keys and file content as values
|
8
|
+
* @param title Optional title for the content
|
9
|
+
* @returns A VizContent object with randomly generated IDs
|
10
|
+
*/
|
11
|
+
const createVizContent = (files, title = "Sample Content for Exporting") => {
|
12
|
+
const contentId = (0, uuid_1.v4)().replace(/-/g, "");
|
13
|
+
const contentFiles = {};
|
14
|
+
Object.entries(files).forEach(([fileName, fileContent]) => {
|
15
|
+
const fileId = Math.floor(Math.random() * 10000000).toString();
|
16
|
+
contentFiles[fileId] = {
|
17
|
+
name: fileName,
|
18
|
+
text: fileContent,
|
19
|
+
};
|
20
|
+
});
|
21
|
+
return {
|
22
|
+
id: contentId,
|
23
|
+
files: contentFiles,
|
24
|
+
title,
|
25
|
+
};
|
26
|
+
};
|
27
|
+
exports.createVizContent = createVizContent;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.extractVizImport = void 0;
|
4
|
+
const extractVizImport = (str) => {
|
5
|
+
// Updated regular expression pattern
|
6
|
+
// Username: Alphanumeric characters, including underscores and hyphens
|
7
|
+
// ID: Alphanumeric characters, including underscores, hyphens, and possibly other special characters
|
8
|
+
const pattern = /^@([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)$/;
|
9
|
+
const match = str.match(pattern);
|
10
|
+
if (match) {
|
11
|
+
// Extract the username and id
|
12
|
+
return {
|
13
|
+
userName: match[1],
|
14
|
+
idOrSlug: match[2],
|
15
|
+
};
|
16
|
+
}
|
17
|
+
else {
|
18
|
+
// Return null if the string does not match
|
19
|
+
return null;
|
20
|
+
}
|
21
|
+
};
|
22
|
+
exports.extractVizImport = extractVizImport;
|
23
|
+
// // Example usages
|
24
|
+
// const result1 = extractDetails("@curran/21f72bf74ef04ea0b9c9b82aaaec859a");
|
25
|
+
// console.log(result1); // { username: "curran", id: "21f72bf74ef04ea0b9c9b82aaaec859a" }
|
26
|
+
// const result2 = extractDetails("@curran/scatter-plot");
|
27
|
+
// console.log(result2); // { username: "curran", id: "scatter-plot" }
|
@@ -0,0 +1,32 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const vitest_1 = require("vitest");
|
4
|
+
const extractVizImport_1 = require("./extractVizImport");
|
5
|
+
(0, vitest_1.describe)("v3 extractVizImport", () => {
|
6
|
+
(0, vitest_1.it)("should correctly extract username and viz id", () => {
|
7
|
+
const result = (0, extractVizImport_1.extractVizImport)("@curran/21f72bf74ef04ea0b9c9b82aaaec859a");
|
8
|
+
(0, vitest_1.expect)(result).toEqual({
|
9
|
+
userName: "curran",
|
10
|
+
idOrSlug: "21f72bf74ef04ea0b9c9b82aaaec859a",
|
11
|
+
});
|
12
|
+
});
|
13
|
+
(0, vitest_1.it)("should correctly extract username and alphanumeric id", () => {
|
14
|
+
const result = (0, extractVizImport_1.extractVizImport)("@curran/scatter-plot");
|
15
|
+
(0, vitest_1.expect)(result).toEqual({
|
16
|
+
userName: "curran",
|
17
|
+
idOrSlug: "scatter-plot",
|
18
|
+
});
|
19
|
+
});
|
20
|
+
(0, vitest_1.it)("should return null for non-matching strings", () => {
|
21
|
+
const result = (0, extractVizImport_1.extractVizImport)("not-a-matching-string");
|
22
|
+
(0, vitest_1.expect)(result).toBeNull();
|
23
|
+
});
|
24
|
+
(0, vitest_1.it)("should handle cases with invalid characters in username", () => {
|
25
|
+
const result = (0, extractVizImport_1.extractVizImport)("@c!urran/valid-id");
|
26
|
+
(0, vitest_1.expect)(result).toBeNull();
|
27
|
+
});
|
28
|
+
(0, vitest_1.it)("should handle cases with invalid characters in id", () => {
|
29
|
+
const result = (0, extractVizImport_1.extractVizImport)("@curran/invalid id");
|
30
|
+
(0, vitest_1.expect)(result).toBeNull();
|
31
|
+
});
|
32
|
+
});
|