Skip to content
Draft
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,5 @@ uri.txt
crypt_shared.sh

*keytab
driver.bundle.js
test/tools/runner/bundle/
21 changes: 21 additions & 0 deletions etc/build-runtime-barrel.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

// eslint-disable-next-line no-restricted-globals
const useBundled = process.env.MONGODB_BUNDLED === 'true';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const rootDir = path.join(__dirname, '..');
const outputBarrelFile = path.join(rootDir, 'test/mongodb_runtime-testing.ts');
const source = useBundled ? './mongodb_bundled' : './mongodb';

const contents =
`// This file is auto-generated. Do not edit.\n` +
`// Run 'npm run build:runtime-barrel' to regenerate.\n` +
`export const runNodelessTests = ${useBundled};\n` +
`export * from '${source}';\n`;
await fs.writeFile(outputBarrelFile, contents);

// eslint-disable-next-line no-console
console.log(`✓ ${outputBarrelFile} now re-exports from ${source}`);
52 changes: 52 additions & 0 deletions etc/bundle-driver.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env node
import fs from 'node:fs/promises';
import { isBuiltin } from 'node:module';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import * as esbuild from 'esbuild';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const rootDir = path.join(__dirname, '..');

const outdir = path.join(rootDir, 'test/tools/runner/bundle/');
await fs.rm(outdir, { recursive: true, force: true });

const outputBundleFile = path.join(outdir, 'driver-bundle.js');
await esbuild.build({
entryPoints: [path.join(rootDir, 'test/mongodb.ts')],
bundle: true,
outfile: outputBundleFile,
platform: 'node',
format: 'cjs',
target: 'node20',
external: [
'bson',
'mongodb-connection-string-url',
'@mongodb-js/saslprep',
'@mongodb-js/zstd',
'mongodb-client-encryption',
'snappy',
'@napi-rs/snappy*',
'kerberos',
'gcp-metadata',
'@aws-sdk/credential-providers'
],
plugins: [
{
name: 'externalize-node-builtins',
setup(build) {
build.onResolve({ filter: /.*/ }, args => {
if (isBuiltin(args.path)) {
return { path: args.path, external: true };
}
});
}
}
],
sourcemap: 'inline',
logLevel: 'info'
});

// eslint-disable-next-line no-console
console.log(`✓ Driver bundle created at ${outputBundleFile}`);
Loading