-
Notifications
You must be signed in to change notification settings - Fork 253
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-5048): webpack unable to bundle import with leading 'node:' #564
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as before, I don't think we should officially document this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is documentation for us to know the flags changed from the default config