Skip to content

Commit 94449cf

Browse files
authored
fix(NODE-6731): fix and test webpack bundling (#71)
1 parent 275ef82 commit 94449cf

File tree

9 files changed

+8927
-1
lines changed

9 files changed

+8927
-1
lines changed

.github/workflows/webpack.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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: "Install dependencies"
22+
shell: bash
23+
run: |
24+
npm install
25+
26+
- name: "Install dependencies in the Webpack bundle test package"
27+
shell: bash
28+
working-directory: ./test/bundling/webpack
29+
run: |
30+
npm install
31+
32+
- name: "Install local zstd into Webpack bundle test package"
33+
shell: bash
34+
working-directory: ./test/bundling/webpack
35+
run: |
36+
npm run install:zstd
37+
38+
- name: "Run webpack build"
39+
shell: bash
40+
working-directory: ./test/bundling/webpack
41+
run: |
42+
npm run build

lib/index.js

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

test/bundling/webpack/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
*.tgz
+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 zstdRoot = resolve(__dirname, '../../..');
13+
console.log(`zstd package root: ${zstdRoot}`);
14+
15+
const zstdVersion = JSON.parse(
16+
readFileSync(resolve(zstdRoot, 'package.json'), { encoding: 'utf8' })
17+
).version;
18+
console.log(`zstd Version: ${zstdVersion}`);
19+
20+
xtrace('npm pack --pack-destination test/bundling/webpack', { cwd: zstdRoot });
21+
22+
xtrace(`npm install --no-save mongodb-js-zstd-${zstdVersion}.tgz`);
23+
24+
console.log('zstd installed!');

0 commit comments

Comments
 (0)