diff options
author | Kristóf Marussy <kristof@marussy.com> | 2023-08-23 03:36:25 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2023-08-23 03:36:25 +0200 |
commit | 0e54d399424374d497d08a8631c4761dece57ceb (patch) | |
tree | bd0873080b4bc3b81984852def5e435e51292d0d /subprojects/frontend/config | |
parent | fix: predicate value translation (diff) | |
download | refinery-0e54d399424374d497d08a8631c4761dece57ceb.tar.gz refinery-0e54d399424374d497d08a8631c4761dece57ceb.tar.zst refinery-0e54d399424374d497d08a8631c4761dece57ceb.zip |
feat: dot visualization
Diffstat (limited to 'subprojects/frontend/config')
-rw-r--r-- | subprojects/frontend/config/graphvizUMDVitePlugin.ts | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/subprojects/frontend/config/graphvizUMDVitePlugin.ts b/subprojects/frontend/config/graphvizUMDVitePlugin.ts new file mode 100644 index 00000000..7a42560b --- /dev/null +++ b/subprojects/frontend/config/graphvizUMDVitePlugin.ts | |||
@@ -0,0 +1,63 @@ | |||
1 | import { readFile } from 'node:fs/promises'; | ||
2 | import path from 'node:path'; | ||
3 | |||
4 | import pnpapi from 'pnpapi'; | ||
5 | import type { PluginOption, ResolvedConfig } from 'vite'; | ||
6 | |||
7 | // Use a CJS file as the PnP resolution issuer to force resolution to a non-ESM export. | ||
8 | const issuerFileName = 'worker.cjs'; | ||
9 | |||
10 | export default function graphvizUMDVitePlugin(): PluginOption { | ||
11 | let command: ResolvedConfig['command'] = 'build'; | ||
12 | let root: string | undefined; | ||
13 | let url: string | undefined; | ||
14 | |||
15 | return { | ||
16 | name: 'graphviz-umd', | ||
17 | enforce: 'post', | ||
18 | configResolved(config) { | ||
19 | ({ command, root } = config); | ||
20 | }, | ||
21 | async buildStart() { | ||
22 | const issuer = | ||
23 | root === undefined ? issuerFileName : path.join(issuerFileName); | ||
24 | const resolvedPath = pnpapi.resolveRequest( | ||
25 | '@hpcc-js/wasm/graphviz', | ||
26 | issuer, | ||
27 | ); | ||
28 | if (resolvedPath === null) { | ||
29 | return; | ||
30 | } | ||
31 | if (command === 'serve') { | ||
32 | url = `/@fs/${resolvedPath}`; | ||
33 | } else { | ||
34 | const content = await readFile(resolvedPath, null); | ||
35 | url = this.emitFile({ | ||
36 | name: path.basename(resolvedPath), | ||
37 | type: 'asset', | ||
38 | source: content, | ||
39 | }); | ||
40 | } | ||
41 | }, | ||
42 | renderStart() { | ||
43 | if (url !== undefined && command !== 'serve') { | ||
44 | url = this.getFileName(url); | ||
45 | } | ||
46 | }, | ||
47 | transformIndexHtml() { | ||
48 | if (url === undefined) { | ||
49 | return undefined; | ||
50 | } | ||
51 | return [ | ||
52 | { | ||
53 | tag: 'script', | ||
54 | attrs: { | ||
55 | src: url, | ||
56 | type: 'javascript/worker', | ||
57 | }, | ||
58 | injectTo: 'head', | ||
59 | }, | ||
60 | ]; | ||
61 | }, | ||
62 | }; | ||
63 | } | ||