@@ -90,6 +90,34 @@ const resolveQuickJsWasmPath = (): string => {
9090 return wasmPath ;
9191} ;
9292
93+ const resolvePGliteAssetPaths = ( ) : {
94+ dataPath : string ;
95+ wasmPath : string ;
96+ } => {
97+ const requireFromControlPlane = createRequire (
98+ join ( repoRoot , "packages/control-plane/package.json" ) ,
99+ ) ;
100+ const pglitePackagePath = requireFromControlPlane . resolve (
101+ "@electric-sql/pglite/package.json" ,
102+ ) ;
103+ const pgliteDistDir = join ( dirname ( pglitePackagePath ) , "dist" ) ;
104+ const dataPath = join ( pgliteDistDir , "pglite.data" ) ;
105+ const wasmPath = join ( pgliteDistDir , "pglite.wasm" ) ;
106+
107+ if ( ! existsSync ( dataPath ) ) {
108+ throw new Error ( `Unable to locate PGlite data asset at ${ dataPath } ` ) ;
109+ }
110+
111+ if ( ! existsSync ( wasmPath ) ) {
112+ throw new Error ( `Unable to locate PGlite wasm asset at ${ wasmPath } ` ) ;
113+ }
114+
115+ return {
116+ dataPath,
117+ wasmPath,
118+ } ;
119+ } ;
120+
93121const createPackageJson = ( input : {
94122 packageName : string ;
95123 packageVersion : string ;
@@ -150,6 +178,7 @@ export const buildDistributionPackage = async (
150178 const bundlePath = join ( binDir , "executor.mjs" ) ;
151179 const launcherPath = join ( binDir , "executor.js" ) ;
152180 const quickJsWasmPath = resolveQuickJsWasmPath ( ) ;
181+ const pgliteAssets = resolvePGliteAssetPaths ( ) ;
153182 const webDistDir = join ( repoRoot , "apps/web/dist" ) ;
154183 const readmePath = join ( repoRoot , "README.md" ) ;
155184 const packageName = options . packageName ?? defaults . name ;
@@ -185,6 +214,8 @@ export const buildDistributionPackage = async (
185214
186215 await cp ( webDistDir , webDir , { recursive : true } ) ;
187216 await cp ( quickJsWasmPath , join ( binDir , "emscripten-module.wasm" ) ) ;
217+ await cp ( pgliteAssets . dataPath , join ( binDir , "pglite.data" ) ) ;
218+ await cp ( pgliteAssets . wasmPath , join ( binDir , "pglite.wasm" ) ) ;
188219 await mkdir ( join ( binDir , "openapi-extractor-wasm" ) , { recursive : true } ) ;
189220 await cp (
190221 join ( repoRoot , "packages/codemode-openapi/src/openapi-extractor-wasm/openapi_extractor_bg.wasm" ) ,
0 commit comments