@@ -2,7 +2,8 @@ import { createHpccViteConfig, browserConfig, nodeConfig } from "@hpcc-js/esbuil
22import pkg from "./package.json" with { type : "json" } ;
33
44const aliasPlugin = {
5- name : 'alias-plugin' ,
5+ name : "alias-plugin" ,
6+ // esbuild plugin interface
67 setup ( build ) {
78 const aliases = [
89 {
@@ -19,17 +20,46 @@ const aliasPlugin = {
1920 for ( const alias of aliases ) {
2021 const match = args . path . match ( alias . find ) ;
2122 if ( match ) {
22- const resolved = alias . replacement . replace ( '$1' , match [ 1 ] ) ;
23+ const resolved = alias . replacement . replace ( "$1" , match [ 1 ] ) ;
2324 return { path : resolved , external : true } ;
2425 }
2526 }
2627 } ) ;
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 ;
2750 }
2851} ;
2952
3053const myBrowserConfig = { ...browserConfig } ;
3154myBrowserConfig . 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+ ]
3363} ;
3464
3565const myNodeConfig = { ...nodeConfig } ;
@@ -40,8 +70,67 @@ myNodeConfig.optimizeDeps = {
4070const config = createHpccViteConfig ( pkg , {
4171 plugins : [ aliasPlugin ] ,
4272 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+ } ,
43101 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+ }
45134 }
46135 }
47136} ) ;
0 commit comments