Skip to content

Commit

Permalink
fix(NODE-6732): test and fix webpack bundling (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
durran authored Feb 10, 2025
1 parent 35749ba commit 81bf1a7
Show file tree
Hide file tree
Showing 11 changed files with 8,927 additions and 3 deletions.
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 kerberos into Webpack bundle test package"
shell: bash
working-directory: ./test/bundling/webpack
run: |
npm run install:kerberos
- name: "Run webpack build"
shell: bash
working-directory: ./test/bundling/webpack
run: |
npm run build
1 change: 0 additions & 1 deletion lib/kerberos.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const { loadBindings, defineOperation } = require('./util');


const kerberos = loadBindings();
const KerberosClient = kerberos.KerberosClient;
const KerberosServer = kerberos.KerberosServer;
Expand Down
9 changes: 8 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ function loadBindings() {
try {
return require('../build/Release/kerberos.node');
} catch {
return require('../build/Debug/kerberos.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/kerberos.node');
} catch (error) {
throw error;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"check:lint": "ESLINT_USE_FLAT_CONFIG=false eslint lib test",
"precommit": "check-clang-format",
"docs": "jsdoc2md --template etc/README.hbs --plugin dmd-clear --files lib/kerberos.js > README.md",
"test": "mocha test",
"test": "mocha 'test/*_tests.js'",
"prebuild": "prebuild --runtime napi --strip --verbose --all"
},
"engines": {
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_kerberos.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 kerberosRoot = resolve(__dirname, '../../..');
console.log(`kerberos package root: ${kerberosRoot}`);

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

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

xtrace(`npm install --no-save kerberos-${kerberosVersion}.tgz`);

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

0 comments on commit 81bf1a7

Please sign in to comment.