Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-6730): allow webpack bundling #67

Merged
merged 10 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/webpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Webpack

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js LTS
uses: actions/setup-node@v4
with:
node-version: 'lts/*'

- name: "Build libmongocrypt"
shell: bash
run: |
npm run install:libmongocrypt

- name: "Install dependencies"
shell: bash
run: |
npm install

- name: "Install dependencies in the Webpack bundle test package"
shell: bash
working-directory: ./test/bundling/webpack
run: |
npm install

- name: "Install local mongodb-client-encryption into Webpack bundle test package"
shell: bash
working-directory: ./test/bundling/webpack
run: |
npm run install:ce

- name: "Run webpack build"
shell: bash
working-directory: ./test/bundling/webpack
run: |
npm run build
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"clang-format": "clang-format --style=file:.clang-format --Werror -i addon/*",
"check:eslint": "ESLINT_USE_FLAT_CONFIG=false eslint src test",
"check:clang-format": "clang-format --style=file:.clang-format --dry-run --Werror addon/*",
"test": "mocha --v8-expose-gc test",
"test": "mocha --v8-expose-gc test/unit",
"prepare": "tsc",
"rebuild": "node-gyp rebuild",
"prebuild": "prebuild --runtime napi --strip --verbose --all"
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ function load() {
try {
return require('../build/Release/mongocrypt.node');
} catch {
return require('../build/Debug/mongocrypt.node');
// Webpack will fail when just returning the require, so we need to wrap
// in a try/catch and rethrow.
/* eslint no-useless-catch: 0 */
try {
return require('../build/Debug/mongocrypt.node');
} catch (error) {
throw error;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions test/bundling/webpack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/*
24 changes: 24 additions & 0 deletions test/bundling/webpack/install_ce.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const { execSync } = require('node:child_process');
const { readFileSync } = require('node:fs');
const { resolve } = require('node:path');

const xtrace = (...args) => {
console.log(`running: ${args[0]}`);
return execSync(...args);
};

const ceRoot = resolve(__dirname, '../../..');
console.log(`mongodb-client-encryption package root: ${ceRoot}`);

const ceVersion = JSON.parse(
readFileSync(resolve(ceRoot, 'package.json'), { encoding: 'utf8' })
).version;
console.log(`mongodb-client-encryption Version: ${ceVersion}`);

xtrace('npm pack --pack-destination test/bundling/webpack', { cwd: ceRoot });

xtrace(`npm install --no-save mongodb-client-encryption-${ceVersion}.tgz`);

console.log('mongodb-client-encryption installed!');
Loading
Loading