diff --git a/packages/duckdb-wasm/bundle.mjs b/packages/duckdb-wasm/bundle.mjs index 2f75d8128..428c1ee26 100644 --- a/packages/duckdb-wasm/bundle.mjs +++ b/packages/duckdb-wasm/bundle.mjs @@ -4,7 +4,7 @@ import path from 'path'; import { rimrafSync } from 'rimraf'; import mkdir from 'make-dir'; import { fileURLToPath } from 'url'; -import ifdefPlugin from 'esbuild-ifdef' +import ifdef from 'esbuild-plugin-ifdef' // ------------------------------- // Current bundling strategy @@ -111,11 +111,7 @@ fs.copyFile(path.resolve(src, 'bindings', 'duckdb-coi.wasm'), path.resolve(dist, // Browser bundles const pluginConfig = [ - ifdefPlugin({ - variables: { - EH_BUILD_ENABLED: ehBuildEnabled(), - }, - }) + ifdef(ehBuildEnabled() ? { EH_BUILD_ENABLED: true } : {}), ]; console.log('[ ESBUILD ] duckdb-browser.cjs'); @@ -319,6 +315,7 @@ fs.copyFile(path.resolve(src, 'bindings', 'duckdb-coi.wasm'), path.resolve(dist, bundle: true, sourcemap: is_debug ? 'inline' : true, external: EXTERNALS_TEST_BROWSER, + plugins: pluginConfig, }); console.log('[ ESBUILD ] tests-node.cjs'); @@ -331,8 +328,10 @@ fs.copyFile(path.resolve(src, 'bindings', 'duckdb-coi.wasm'), path.resolve(dist, bundle: true, minify: false, sourcemap: is_debug ? 'inline' : true, - // web-worker polyfill needs to be excluded from bundling due to their dynamic require messing with bundled modules + // web-worker polyfill needs to be excluded from + // bundling due to their dynamic require messing with bundled modules external: [...EXTERNALS_NODE, 'web-worker'], + plugins: pluginConfig, }); // ------------------------------- diff --git a/packages/duckdb-wasm/package.json b/packages/duckdb-wasm/package.json index 0f7665a48..eb0321e4b 100644 --- a/packages/duckdb-wasm/package.json +++ b/packages/duckdb-wasm/package.json @@ -32,6 +32,8 @@ "@typescript-eslint/parser": "^6.7.3", "esbuild": "^0.18.13", "eslint": "^8.50.0", + "esbuild-ifdef": "^0.2.0", + "esbuild-plugin-ifdef": "^1.0.1", "eslint-plugin-jasmine": "^4.1.3", "eslint-plugin-react": "^7.33.2", "fast-glob": "^3.3.1", @@ -56,8 +58,7 @@ "typedoc": "^0.25.0", "typescript": "^5.1.6", "wasm-feature-detect": "^1.5.1", - "web-worker": "^1.2.0", - "esbuild-ifdef": "^0.2.0" + "web-worker": "^1.2.0" }, "scripts": { "build:debug": "node bundle.mjs debug && tsc --emitDeclarationOnly", diff --git a/packages/duckdb-wasm/src/targets/duckdb-browser-blocking.ts b/packages/duckdb-wasm/src/targets/duckdb-browser-blocking.ts index 451836c0e..8d660377f 100644 --- a/packages/duckdb-wasm/src/targets/duckdb-browser-blocking.ts +++ b/packages/duckdb-wasm/src/targets/duckdb-browser-blocking.ts @@ -11,9 +11,9 @@ import { Logger } from '../log'; import { DuckDBRuntime, DuckDBBindings } from '../bindings'; import { DuckDBBundles, getPlatformFeatures } from '../platform'; import { DuckDB as DuckDBMVP } from '../bindings/bindings_browser_mvp'; -/// #if EH_BUILD_ENABLED +//#ifdef EH_BUILD_ENABLED import { DuckDB as DuckDBNext } from '../bindings/bindings_browser_eh'; -/// #endif +//#endif export async function createDuckDB( bundles: DuckDBBundles, @@ -21,12 +21,12 @@ export async function createDuckDB( runtime: DuckDBRuntime, ): Promise { const platform = await getPlatformFeatures(); - /// #if EH_BUILD_ENABLED +//#ifdef EH_BUILD_ENABLED if (platform.wasmExceptions) { if (bundles.eh) { return new DuckDBNext(logger, runtime, bundles.eh!.mainModule); } } - /// #endif +//#endif return new DuckDBMVP(logger, runtime, bundles.mvp.mainModule); } diff --git a/packages/duckdb-wasm/src/targets/duckdb-node-blocking.ts b/packages/duckdb-wasm/src/targets/duckdb-node-blocking.ts index 679fa54e4..9b759382c 100644 --- a/packages/duckdb-wasm/src/targets/duckdb-node-blocking.ts +++ b/packages/duckdb-wasm/src/targets/duckdb-node-blocking.ts @@ -12,9 +12,9 @@ import { DuckDBRuntime } from '../bindings'; import { DuckDBNodeBindings } from '../bindings/bindings_node_base'; import { DuckDBBundles, getPlatformFeatures } from '../platform'; import { DuckDB as DuckDBMVP } from '../bindings/bindings_node_mvp'; -/// #if EH_BUILD_ENABLED +//#ifdef EH_BUILD_ENABLED import { DuckDB as DuckDBNext } from '../bindings/bindings_node_eh'; -/// #endif +//#endif export async function createDuckDB( bundles: DuckDBBundles, @@ -22,12 +22,12 @@ export async function createDuckDB( runtime: DuckDBRuntime, ): Promise { const platform = await getPlatformFeatures(); - /// #if EH_BUILD_ENABLED +//#ifdef EH_BUILD_ENABLED if (platform.wasmExceptions) { if (bundles.eh) { return new DuckDBNext(logger, runtime, bundles.eh!.mainModule); } } - /// #endif +//#endif return new DuckDBMVP(logger, runtime, bundles.mvp.mainModule); }