Skip to content

Commit 1bc517a

Browse files
nirinchevaddaleax
andauthored
fix: suppress experimental warning for node 23 MONGOSH-1895 (#2258)
Co-authored-by: Anna Henningsen <[email protected]>
1 parent 2895fe2 commit 1bc517a

File tree

10 files changed

+84
-14
lines changed

10 files changed

+84
-14
lines changed

.evergreen.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7132,7 +7132,7 @@ functions:
71327132
{
71337133
export NODE_JS_VERSION=${node_js_version}
71347134
source .evergreen/setup-env.sh
7135-
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
7135+
export PUPPETEER_SKIP_DOWNLOAD="true"
71367136
npm run evergreen-release draft
71377137
}
71387138

@@ -7150,7 +7150,7 @@ functions:
71507150
node_js_version: ${node_js_version}
71517151
script: |
71527152
set -e
7153-
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
7153+
export PUPPETEER_SKIP_DOWNLOAD="true"
71547154
.evergreen/run-evergreen-release.sh download-and-list-artifacts
71557155
- command: shell.exec
71567156
params:
@@ -7179,7 +7179,7 @@ functions:
71797179
node_js_version: ${node_js_version}
71807180
script: |
71817181
set -e
7182-
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
7182+
export PUPPETEER_SKIP_DOWNLOAD="true"
71837183
.evergreen/run-evergreen-release.sh publish -- --dry-run
71847184

71857185
release_publish:
@@ -7198,7 +7198,7 @@ functions:
71987198
node_js_version: ${node_js_version}
71997199
script: |
72007200
set -e
7201-
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
7201+
export PUPPETEER_SKIP_DOWNLOAD="true"
72027202
.evergreen/run-evergreen-release.sh publish
72037203

72047204
run_perf_tests:

.evergreen/compile-artifact.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ elif [ -n "$MONGOSH_SHARED_OPENSSL" ]; then
7373
export LD_LIBRARY_PATH=/tmp/m/opt/lib
7474
fi
7575

76-
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
76+
export PUPPETEER_SKIP_DOWNLOAD="true"
7777
npm run evergreen-release compile
7878
dist/mongosh --version
7979
dist/mongosh --build-info

.evergreen/evergreen.yml.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ functions:
967967
{
968968
export NODE_JS_VERSION=${node_js_version}
969969
source .evergreen/setup-env.sh
970-
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
970+
export PUPPETEER_SKIP_DOWNLOAD="true"
971971
npm run evergreen-release draft
972972
}
973973

@@ -985,7 +985,7 @@ functions:
985985
node_js_version: ${node_js_version}
986986
script: |
987987
set -e
988-
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
988+
export PUPPETEER_SKIP_DOWNLOAD="true"
989989
.evergreen/run-evergreen-release.sh download-and-list-artifacts
990990
- command: shell.exec
991991
params:
@@ -1014,7 +1014,7 @@ functions:
10141014
node_js_version: ${node_js_version}
10151015
script: |
10161016
set -e
1017-
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
1017+
export PUPPETEER_SKIP_DOWNLOAD="true"
10181018
.evergreen/run-evergreen-release.sh publish -- --dry-run
10191019

10201020
release_publish:
@@ -1033,7 +1033,7 @@ functions:
10331033
node_js_version: ${node_js_version}
10341034
script: |
10351035
set -e
1036-
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
1036+
export PUPPETEER_SKIP_DOWNLOAD="true"
10371037
.evergreen/run-evergreen-release.sh publish
10381038

10391039
run_perf_tests:

.evergreen/package-and-upload-artifact.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if [ "$(uname)" == Linux ]; then
1313
cp "$(pwd)/../tmp/expansions.yaml" tmp/expansions.yaml
1414
(cd scripts/docker && bash "$BASEDIR/retry-with-backoff.sh" docker build -t rocky8-package -f rocky8-package.Dockerfile .)
1515
echo Starting Docker container packaging
16-
docker run -e PUPPETEER_SKIP_CHROMIUM_DOWNLOAD \
16+
docker run -e PUPPETEER_SKIP_DOWNLOAD \
1717
-e EVERGREEN_EXPANSIONS_PATH=/tmp/build/tmp/expansions.yaml \
1818
-e NODE_JS_VERSION \
1919
-e PACKAGE_VARIANT \

.evergreen/run-evergreen-release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ echo "//registry.npmjs.org/:_authToken=${devtoolsbot_npm_token}" > .npmrc
55
set -x
66
export NODE_JS_VERSION=${node_js_version}
77
source .evergreen/setup-env.sh
8-
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
8+
export PUPPETEER_SKIP_DOWNLOAD="true"
99
npm run evergreen-release $@

.github/workflows/smoke-tests.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: "Run Smoke Tests"
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
jobs:
9+
smoke-tests:
10+
name: "OS: ${{ matrix.runner }}, node@${{ matrix.node }}"
11+
strategy:
12+
matrix:
13+
runner: [ubuntu, macos, windows]
14+
node: [20.x, 22.x, 23.x]
15+
fail-fast: false
16+
runs-on: ${{ matrix.runner }}-latest
17+
timeout-minutes: 15
18+
env:
19+
npm_config_loglevel: verbose
20+
npm_config_foreground_scripts: "true"
21+
PUPPETEER_SKIP_DOWNLOAD: "true"
22+
steps:
23+
- uses: actions/checkout@v4
24+
- uses: actions/setup-node@v4
25+
with:
26+
node-version: ${{ matrix.node }}
27+
cache: "npm"
28+
29+
- name: Install npm@10
30+
run: npm install -g npm@10
31+
32+
- name: Install dependencies
33+
run: npm ci
34+
35+
- name: Run smoke tests
36+
run: npx mongodb-runner exec -- sh -c 'env MONGOSH_SMOKE_TEST_SERVER=$MONGODB_URI npm run test-smoke'

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"author": "Compass Team <[email protected]>",
1010
"scripts": {
1111
"bootstrap-with-chromium": "npm install && npm run compile",
12-
"bootstrap": "npx cross-env PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1 npm install && npm run compile",
12+
"bootstrap": "npx cross-env PUPPETEER_SKIP_DOWNLOAD=1 npm install && npm run compile",
1313
"clean": "lerna clean -y && rm -Rf node_modules",
1414
"check": "lerna run check --since HEAD --exclude-dependents",
1515
"check-ci": "npm run check --workspaces --if-present",
@@ -26,6 +26,8 @@
2626
"test-evergreen-expansions": "bash .evergreen/compilation-context-expansions.test.sh",
2727
"replace-package": "node scripts/replace-package.js",
2828
"test-nodedriver": "bash .evergreen/test-node-driver.sh",
29+
"pretest-smoke": "npm run compile-cli",
30+
"test-smoke": "npm run test-smoke -w @mongosh/cli-repl",
2931
"compile": "npm run compile --workspaces --if-present",
3032
"compile-cli": "lerna run compile --scope @mongosh/cli-repl --include-dependencies",
3133
"prestart-cli": "npm run compile-cli",

packages/cli-repl/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"test-coverage": "nyc --no-clean --cwd ../.. --reporter=none npm run test",
2727
"test-ci-coverage": "nyc --no-clean --cwd ../.. --reporter=none npm run test-ci",
2828
"test-apistrict-ci": "cross-env MONGOSH_TEST_FORCE_API_STRICT=1 npm run test-ci",
29+
"test-smoke": "node bin/mongosh.js --smokeTests",
2930
"eslint": "eslint",
3031
"lint": "npm run eslint . && npm run prettier -- --check .",
3132
"check": "npm run lint && npm run depcheck",

packages/cli-repl/src/run.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ if ((v8 as any)?.startupSnapshot?.isBuildingSnapshot?.()) {
6969
// eslint-disable-next-line complexity
7070
async function main() {
7171
markTime(TimingCategories.Main, 'entered main');
72+
suppressExperimentalWarnings();
7273
if (process.env.MONGOSH_RUN_NODE_SCRIPT) {
7374
// For uncompiled mongosh: node /path/to/this/file script ... -> node script ...
7475
// FOr compiled mongosh: mongosh mongosh script ... -> mongosh script ...
@@ -311,3 +312,32 @@ async function ask(prompt: string): Promise<string> {
311312
process.stdin.unpipe(stdinCopy);
312313
}
313314
}
315+
316+
/**
317+
* Helper to suppress experimental warnings emitted by node if necessary.
318+
*
319+
* In Node.js 23 require()ing ESM modules will work, but emit an experimental warning like
320+
* CommonJS module ABC is loading ES Module XYZ using require(). This is causing problems for
321+
* the way we import fetch - see relevant comments here:
322+
* https://github.com/mongodb-js/devtools-shared/blob/29ceeb5f51d29883d4a69c83e68ad37b0965d49e/packages/devtools-proxy-support/src/fetch.ts#L12-L17
323+
*/
324+
function suppressExperimentalWarnings() {
325+
const nodeMajorVersion = process.versions.node.split('.').map(Number)[0];
326+
if (nodeMajorVersion >= 23) {
327+
const originalEmit = process.emitWarning;
328+
process.emitWarning = (warning, ...args: any[]): void => {
329+
if (args[0] === 'ExperimentalWarning') {
330+
return;
331+
}
332+
333+
if (
334+
typeof args[0] === 'object' &&
335+
args[0].type === 'ExperimentalWarning'
336+
) {
337+
return;
338+
}
339+
340+
return originalEmit(warning, ...args);
341+
};
342+
}
343+
}

packages/cli-repl/src/smoke-tests.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ async function runSmokeTest({
397397
// eslint-disable-next-line
398398
const { spawn } = require('child_process') as typeof import('child_process');
399399
const proc = spawn(executable, [...args], {
400-
stdio: ['pipe', 'pipe', includeStderr ? 'pipe' : 'inherit'],
400+
stdio: 'pipe',
401401
});
402402
let stdout = '';
403403
let stderr = '';
@@ -420,13 +420,14 @@ async function runSmokeTest({
420420
input,
421421
output,
422422
stdout,
423-
stderr,
423+
stderr: includeStderr ? stderr : '',
424424
executable,
425425
actualExitCode,
426426
args: args.map((arg) => redactURICredentials(arg)),
427427
};
428428
try {
429429
assert.match(includeStderr ? `${stdout}\n${stderr}` : stdout, output);
430+
assert.doesNotMatch(stderr, /ExperimentalWarning/);
430431
if (exitCode !== undefined) {
431432
assert.strictEqual(actualExitCode, exitCode);
432433
}

0 commit comments

Comments
 (0)