@@ -2,7 +2,8 @@ import { createHpccViteConfig, browserConfig, nodeConfig } from "@hpcc-js/esbuil
2
2
import pkg from "./package.json" with { type : "json" } ;
3
3
4
4
const aliasPlugin = {
5
- name : 'alias-plugin' ,
5
+ name : "alias-plugin" ,
6
+ // esbuild plugin interface
6
7
setup ( build ) {
7
8
const aliases = [
8
9
{
@@ -19,17 +20,46 @@ const aliasPlugin = {
19
20
for ( const alias of aliases ) {
20
21
const match = args . path . match ( alias . find ) ;
21
22
if ( match ) {
22
- const resolved = alias . replacement . replace ( '$1' , match [ 1 ] ) ;
23
+ const resolved = alias . replacement . replace ( "$1" , match [ 1 ] ) ;
23
24
return { path : resolved , external : true } ;
24
25
}
25
26
}
26
27
} ) ;
28
+ } ,
29
+ // Rollup plugin interface
30
+ resolveId ( id , importer ) {
31
+ const aliases = [
32
+ {
33
+ find : / ^ n p m : ( .* ) $ / ,
34
+ replacement : "https://cdn.jsdelivr.net/npm/$1/+esm"
35
+ } ,
36
+ {
37
+ find : / ^ j s r : ( .* ) $ / ,
38
+ replacement : "https://esm.sh/jsr/$1"
39
+ }
40
+ ] ;
41
+
42
+ for ( const alias of aliases ) {
43
+ const match = id . match ( alias . find ) ;
44
+ if ( match ) {
45
+ const resolved = alias . replacement . replace ( "$1" , match [ 1 ] ) ;
46
+ return { id : resolved , external : true } ;
47
+ }
48
+ }
49
+ return null ;
27
50
}
28
51
} ;
29
52
30
53
const myBrowserConfig = { ...browserConfig } ;
31
54
myBrowserConfig . optimizeDeps = {
32
- include : [ "acorn" , "acorn-walk" , "@observablehq/parser" ]
55
+ include : [
56
+ "acorn" ,
57
+ "acorn-walk" ,
58
+ "@observablehq/parser" ,
59
+ "@observablehq/stdlib" ,
60
+ "@observablehq/runtime" ,
61
+ "@observablehq/inspector"
62
+ ]
33
63
} ;
34
64
35
65
const myNodeConfig = { ...nodeConfig } ;
@@ -40,8 +70,67 @@ myNodeConfig.optimizeDeps = {
40
70
const config = createHpccViteConfig ( pkg , {
41
71
plugins : [ aliasPlugin ] ,
42
72
configOverrides : {
73
+ // Ensure modern syntax like top-level await is supported during transforms
74
+ esbuild : {
75
+ target : "esnext" ,
76
+ supported : { "top-level-await" : true }
77
+ } ,
78
+ // Make sure dependency optimization (esbuild) also understands our custom schemes
79
+ optimizeDeps : {
80
+ esbuildOptions : {
81
+ target : "esnext" ,
82
+ supported : { "top-level-await" : true } ,
83
+ plugins : [ aliasPlugin as any ]
84
+ }
85
+ } ,
86
+ build : {
87
+ target : "esnext" ,
88
+ rollupOptions : {
89
+ external : [
90
+ "@observablehq/notebook-kit" ,
91
+ "@observablehq/notebook-kit/runtime"
92
+ ] ,
93
+ output : {
94
+ globals : {
95
+ "@observablehq/notebook-kit" : "ObservableNotebookKit" ,
96
+ "@observablehq/notebook-kit/runtime" : "ObservableNotebookKitRuntime"
97
+ }
98
+ }
99
+ }
100
+ } ,
43
101
test : {
44
- projects : [ myBrowserConfig , myNodeConfig ]
102
+ projects : [ myBrowserConfig , myNodeConfig ] ,
103
+ deps : {
104
+ optimizer : {
105
+ web : {
106
+ exclude : [
107
+ "@observablehq/notebook-kit" ,
108
+ "@observablehq/notebook-kit/runtime"
109
+ ] ,
110
+ esbuildOptions : {
111
+ target : "esnext" ,
112
+ supported : { "top-level-await" : true } ,
113
+ plugins : [ aliasPlugin as any ]
114
+ }
115
+ } ,
116
+ ssr : {
117
+ exclude : [
118
+ "@observablehq/notebook-kit" ,
119
+ "@observablehq/notebook-kit/runtime"
120
+ ] ,
121
+ esbuildOptions : {
122
+ target : "esnext" ,
123
+ supported : { "top-level-await" : true } ,
124
+ plugins : [ aliasPlugin as any ]
125
+ }
126
+ }
127
+ }
128
+ } ,
129
+ alias : {
130
+ // Use local stubs to avoid loading notebook-kit in tests
131
+ "@observablehq/notebook-kit" : "/tests/mocks/notebook-kit.stub.ts" ,
132
+ "@observablehq/notebook-kit/runtime" : "/tests/mocks/notebook-kit.stub.ts"
133
+ }
45
134
}
46
135
}
47
136
} ) ;
0 commit comments