Skip to content

Commit 3787edd

Browse files
durrannbbeeken
andauthored
fix(NODE-6730): allow webpack bundling (#67)
Co-authored-by: Neal Beeken <[email protected]>
1 parent af9a3e7 commit 3787edd

15 files changed

+9000
-6
lines changed

Diff for: .github/workflows/webpack.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Webpack
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Use Node.js LTS
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: 'lts/*'
20+
21+
- name: "Build libmongocrypt"
22+
shell: bash
23+
run: |
24+
npm run install:libmongocrypt
25+
26+
- name: "Install dependencies"
27+
shell: bash
28+
run: |
29+
npm install
30+
31+
- name: "Install dependencies in the Webpack bundle test package"
32+
shell: bash
33+
working-directory: ./test/bundling/webpack
34+
run: |
35+
npm install
36+
37+
- name: "Install local mongodb-client-encryption into Webpack bundle test package"
38+
shell: bash
39+
working-directory: ./test/bundling/webpack
40+
run: |
41+
npm run install:ce
42+
43+
- name: "Run webpack build"
44+
shell: bash
45+
working-directory: ./test/bundling/webpack
46+
run: |
47+
npm run build

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"clang-format": "clang-format --style=file:.clang-format --Werror -i addon/*",
2222
"check:eslint": "ESLINT_USE_FLAT_CONFIG=false eslint src test",
2323
"check:clang-format": "clang-format --style=file:.clang-format --dry-run --Werror addon/*",
24-
"test": "mocha --v8-expose-gc test",
24+
"test": "mocha --v8-expose-gc test/unit",
2525
"prepare": "tsc",
2626
"rebuild": "node-gyp rebuild",
2727
"prebuild": "prebuild --runtime napi --strip --verbose --all"

Diff for: src/index.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ function load() {
55
try {
66
return require('../build/Release/mongocrypt.node');
77
} catch {
8-
return require('../build/Debug/mongocrypt.node');
8+
// Webpack will fail when just returning the require, so we need to wrap
9+
// in a try/catch and rethrow.
10+
/* eslint no-useless-catch: 0 */
11+
try {
12+
return require('../build/Debug/mongocrypt.node');
13+
} catch (error) {
14+
throw error;
15+
}
916
}
1017
}
1118

Diff for: test/bundling/webpack/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/*

Diff for: test/bundling/webpack/install_ce.cjs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const { execSync } = require('node:child_process');
4+
const { readFileSync } = require('node:fs');
5+
const { resolve } = require('node:path');
6+
7+
const xtrace = (...args) => {
8+
console.log(`running: ${args[0]}`);
9+
return execSync(...args);
10+
};
11+
12+
const ceRoot = resolve(__dirname, '../../..');
13+
console.log(`mongodb-client-encryption package root: ${ceRoot}`);
14+
15+
const ceVersion = JSON.parse(
16+
readFileSync(resolve(ceRoot, 'package.json'), { encoding: 'utf8' })
17+
).version;
18+
console.log(`mongodb-client-encryption Version: ${ceVersion}`);
19+
20+
xtrace('npm pack --pack-destination test/bundling/webpack', { cwd: ceRoot });
21+
22+
xtrace(`npm install --no-save mongodb-client-encryption-${ceVersion}.tgz`);
23+
24+
console.log('mongodb-client-encryption installed!');

0 commit comments

Comments
 (0)