-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…564) Co-authored-by: Bailey Pearson <bailey.pearson@mongodb.com>
- Loading branch information
1 parent
50e90fc
commit 3aed24a
Showing
11 changed files
with
159 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#! /usr/bin/env bash | ||
|
||
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" | ||
|
||
set -o xtrace | ||
set -o errexit | ||
|
||
pushd test/bundling/webpack | ||
|
||
npm install | ||
npm run install:bson | ||
npm run build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 bsonRoot = resolve(__dirname, '../../..'); | ||
console.log(`bson package root: ${bsonRoot}`); | ||
|
||
const bsonVersion = JSON.parse( | ||
readFileSync(resolve(bsonRoot, 'package.json'), { encoding: 'utf8' }) | ||
).version; | ||
console.log(`bsonVersion: ${bsonVersion}`); | ||
|
||
xtrace('npm pack --pack-destination test/bundling/webpack', { cwd: bsonRoot }); | ||
|
||
xtrace(`npm install --no-save bson-${bsonVersion}.tgz`); | ||
|
||
console.log('bson installed!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "my-webpack-project", | ||
"version": "1.0.0", | ||
"private": true, | ||
"description": "My webpack project", | ||
"main": "index.js", | ||
"scripts": { | ||
"install:bson": "node install_bson.cjs", | ||
"test": "webpack", | ||
"build": "webpack --mode=production --node-env=production", | ||
"build:dev": "webpack --mode=development", | ||
"build:prod": "webpack --mode=production --node-env=production", | ||
"watch": "webpack --watch" | ||
}, | ||
"devDependencies": { | ||
"@webpack-cli/generators": "^3.0.1", | ||
"ts-loader": "^9.4.2", | ||
"typescript": "^4.9.5", | ||
"webpack": "^5.75.0", | ||
"webpack-cli": "^5.0.1" | ||
}, | ||
"dependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Webpack BSON setup example | ||
|
||
In order to use BSON with webpack there are two changes beyond the default config file needed: | ||
- Set `experiments: { topLevelAwait: true }` in the top-level config object | ||
- Set `resolve: { fallback: { crypto: false } }` in the top-level config object | ||
|
||
## Testing | ||
|
||
To use this bundler test: | ||
- Make changes to bson | ||
- run `npm run build` in the root of the repo to rebuild the BSON src | ||
- in this directory run `npm run install:bson` to install BSON as if it were from npm | ||
- We use a `.tgz` install to make sure we're using exactly what will be published to npm | ||
- run `npm run build` to check that webpack can pull in the changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { BSON } from 'bson'; | ||
|
||
console.log(new BSON.ObjectId()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowSyntheticDefaultImports": true, | ||
"noImplicitAny": true, | ||
"module": "es6", | ||
"target": "es5", | ||
"allowJs": true | ||
}, | ||
"files": ["src/index.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Generated using webpack-cli https://github.com/webpack/webpack-cli | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
||
const isProduction = process.env.NODE_ENV === 'production'; | ||
|
||
const config = { | ||
entry: './src/index.ts', | ||
output: { | ||
path: path.resolve(__dirname, 'dist') | ||
}, | ||
plugins: [ | ||
// Add your plugins here | ||
// Learn more about plugins from https://webpack.js.org/configuration/plugins/ | ||
], | ||
experiments: { topLevelAwait: true }, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(ts|tsx)$/i, | ||
loader: 'ts-loader', | ||
exclude: ['/node_modules/'] | ||
}, | ||
{ | ||
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i, | ||
type: 'asset' | ||
} | ||
|
||
// Add your rules for custom modules here | ||
// Learn more about loaders from https://webpack.js.org/loaders/ | ||
] | ||
}, | ||
resolve: { | ||
extensions: ['.tsx', '.ts', '.jsx', '.js', '...'], | ||
fallback: { crypto: false } | ||
} | ||
}; | ||
|
||
module.exports = () => { | ||
if (isProduction) { | ||
config.mode = 'production'; | ||
} else { | ||
config.mode = 'development'; | ||
} | ||
return config; | ||
}; |