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-6731): fix and test webpack bundling #71

Merged
merged 1 commit into from
Feb 10, 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
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
Loading