Skip to content

Commit

Permalink
fix(NODE-6731): fix and test webpack bundling (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
durran authored Feb 10, 2025
1 parent 275ef82 commit 94449cf
Show file tree
Hide file tree
Showing 9 changed files with 8,927 additions and 1 deletion.
42 changes: 42 additions & 0 deletions .github/workflows/webpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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: "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 zstd into Webpack bundle test package"
shell: bash
working-directory: ./test/bundling/webpack
run: |
npm run install:zstd
- name: "Run webpack build"
shell: bash
working-directory: ./test/bundling/webpack
run: |
npm run build
9 changes: 8 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ function load() {
try {
return require('../build/Release/zstd.node');
} catch {
return require('../build/Debug/zstd.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/zstd.node');
} catch (error) {
throw error;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/bundling/webpack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
*.tgz
24 changes: 24 additions & 0 deletions test/bundling/webpack/install_zstd.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 zstdRoot = resolve(__dirname, '../../..');
console.log(`zstd package root: ${zstdRoot}`);

const zstdVersion = JSON.parse(
readFileSync(resolve(zstdRoot, 'package.json'), { encoding: 'utf8' })
).version;
console.log(`zstd Version: ${zstdVersion}`);

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

xtrace(`npm install --no-save mongodb-js-zstd-${zstdVersion}.tgz`);

console.log('zstd installed!');
Loading

0 comments on commit 94449cf

Please sign in to comment.