1+ import OS from 'node:os' ;
2+ import path from 'node:path' ;
13import { createRequire } from 'node:module' ;
24
35import type { ForgeConfig } from '@electron-forge/shared-types' ;
@@ -9,10 +11,12 @@ import { AutoUnpackNativesPlugin } from '@electron-forge/plugin-auto-unpack-nati
911import { WebpackPlugin } from '@electron-forge/plugin-webpack' ;
1012import type { Configuration , ModuleOptions } from 'webpack' ;
1113import type IForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin' ;
14+ import type ICopyPlugin from 'copy-webpack-plugin' ;
1215
1316const require = createRequire ( import . meta. url ) ;
1417
1518const ForkTsCheckerWebpackPlugin : typeof IForkTsCheckerWebpackPlugin = require ( 'fork-ts-checker-webpack-plugin' ) ;
19+ const CopyPlugin : typeof ICopyPlugin = require ( 'copy-webpack-plugin' ) ;
1620
1721const webpackPlugins = [
1822 new ForkTsCheckerWebpackPlugin ( {
@@ -52,6 +56,18 @@ const defaultWebpackRules: () => Required<ModuleOptions>['rules'] = () => {
5256 ] ;
5357} ;
5458
59+ const platform = OS . platform ( ) ;
60+ let extensionPath : string ;
61+ if ( platform === 'win32' ) {
62+ extensionPath = 'powersync.dll' ;
63+ } else if ( platform === 'linux' ) {
64+ extensionPath = 'libpowersync.so' ;
65+ } else if ( platform === 'darwin' ) {
66+ extensionPath = 'libpowersync.dylib' ;
67+ } else {
68+ throw 'Unknown platform, PowerSync for Node.js currently supports Windows, Linux and macOS.' ;
69+ }
70+
5571const mainConfig : Configuration = {
5672 /**
5773 * This is the main entry point for your application, it's the first file
@@ -62,7 +78,15 @@ const mainConfig: Configuration = {
6278 module : {
6379 rules : defaultWebpackRules ( ) ,
6480 } ,
65- plugins : webpackPlugins ,
81+ plugins : [
82+ ...webpackPlugins ,
83+ new CopyPlugin ( {
84+ patterns : [ {
85+ from : path . resolve ( require . resolve ( '@powersync/node/package.json' ) , `../lib/${ extensionPath } ` ) ,
86+ to : extensionPath ,
87+ } ] ,
88+ } ) ,
89+ ] ,
6690 resolve : {
6791 extensions : [ '.js' , '.ts' , '.jsx' , '.tsx' , '.css' , '.json' ]
6892 }
0 commit comments