Skip to content

Commit

Permalink
fix: suppress experimental warning for node 23 MONGOSH-1895 (#2258)
Browse files Browse the repository at this point in the history
Co-authored-by: Anna Henningsen <[email protected]>
  • Loading branch information
nirinchev and addaleax authored Nov 12, 2024
1 parent 2895fe2 commit 1bc517a
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 14 deletions.
8 changes: 4 additions & 4 deletions .evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7132,7 +7132,7 @@ functions:
{
export NODE_JS_VERSION=${node_js_version}
source .evergreen/setup-env.sh
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
export PUPPETEER_SKIP_DOWNLOAD="true"
npm run evergreen-release draft
}

Expand All @@ -7150,7 +7150,7 @@ functions:
node_js_version: ${node_js_version}
script: |
set -e
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
export PUPPETEER_SKIP_DOWNLOAD="true"
.evergreen/run-evergreen-release.sh download-and-list-artifacts
- command: shell.exec
params:
Expand Down Expand Up @@ -7179,7 +7179,7 @@ functions:
node_js_version: ${node_js_version}
script: |
set -e
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
export PUPPETEER_SKIP_DOWNLOAD="true"
.evergreen/run-evergreen-release.sh publish -- --dry-run

release_publish:
Expand All @@ -7198,7 +7198,7 @@ functions:
node_js_version: ${node_js_version}
script: |
set -e
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
export PUPPETEER_SKIP_DOWNLOAD="true"
.evergreen/run-evergreen-release.sh publish

run_perf_tests:
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/compile-artifact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ elif [ -n "$MONGOSH_SHARED_OPENSSL" ]; then
export LD_LIBRARY_PATH=/tmp/m/opt/lib
fi

export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
export PUPPETEER_SKIP_DOWNLOAD="true"
npm run evergreen-release compile
dist/mongosh --version
dist/mongosh --build-info
Expand Down
8 changes: 4 additions & 4 deletions .evergreen/evergreen.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ functions:
{
export NODE_JS_VERSION=${node_js_version}
source .evergreen/setup-env.sh
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
export PUPPETEER_SKIP_DOWNLOAD="true"
npm run evergreen-release draft
}

Expand All @@ -985,7 +985,7 @@ functions:
node_js_version: ${node_js_version}
script: |
set -e
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
export PUPPETEER_SKIP_DOWNLOAD="true"
.evergreen/run-evergreen-release.sh download-and-list-artifacts
- command: shell.exec
params:
Expand Down Expand Up @@ -1014,7 +1014,7 @@ functions:
node_js_version: ${node_js_version}
script: |
set -e
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
export PUPPETEER_SKIP_DOWNLOAD="true"
.evergreen/run-evergreen-release.sh publish -- --dry-run

release_publish:
Expand All @@ -1033,7 +1033,7 @@ functions:
node_js_version: ${node_js_version}
script: |
set -e
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
export PUPPETEER_SKIP_DOWNLOAD="true"
.evergreen/run-evergreen-release.sh publish

run_perf_tests:
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/package-and-upload-artifact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if [ "$(uname)" == Linux ]; then
cp "$(pwd)/../tmp/expansions.yaml" tmp/expansions.yaml
(cd scripts/docker && bash "$BASEDIR/retry-with-backoff.sh" docker build -t rocky8-package -f rocky8-package.Dockerfile .)
echo Starting Docker container packaging
docker run -e PUPPETEER_SKIP_CHROMIUM_DOWNLOAD \
docker run -e PUPPETEER_SKIP_DOWNLOAD \
-e EVERGREEN_EXPANSIONS_PATH=/tmp/build/tmp/expansions.yaml \
-e NODE_JS_VERSION \
-e PACKAGE_VARIANT \
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/run-evergreen-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ echo "//registry.npmjs.org/:_authToken=${devtoolsbot_npm_token}" > .npmrc
set -x
export NODE_JS_VERSION=${node_js_version}
source .evergreen/setup-env.sh
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
export PUPPETEER_SKIP_DOWNLOAD="true"
npm run evergreen-release $@
36 changes: 36 additions & 0 deletions .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: "Run Smoke Tests"
on:
push:
branches:
- main
pull_request:

jobs:
smoke-tests:
name: "OS: ${{ matrix.runner }}, node@${{ matrix.node }}"
strategy:
matrix:
runner: [ubuntu, macos, windows]
node: [20.x, 22.x, 23.x]
fail-fast: false
runs-on: ${{ matrix.runner }}-latest
timeout-minutes: 15
env:
npm_config_loglevel: verbose
npm_config_foreground_scripts: "true"
PUPPETEER_SKIP_DOWNLOAD: "true"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: "npm"

- name: Install npm@10
run: npm install -g npm@10

- name: Install dependencies
run: npm ci

- name: Run smoke tests
run: npx mongodb-runner exec -- sh -c 'env MONGOSH_SMOKE_TEST_SERVER=$MONGODB_URI npm run test-smoke'
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Compass Team <[email protected]>",
"scripts": {
"bootstrap-with-chromium": "npm install && npm run compile",
"bootstrap": "npx cross-env PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1 npm install && npm run compile",
"bootstrap": "npx cross-env PUPPETEER_SKIP_DOWNLOAD=1 npm install && npm run compile",
"clean": "lerna clean -y && rm -Rf node_modules",
"check": "lerna run check --since HEAD --exclude-dependents",
"check-ci": "npm run check --workspaces --if-present",
Expand All @@ -26,6 +26,8 @@
"test-evergreen-expansions": "bash .evergreen/compilation-context-expansions.test.sh",
"replace-package": "node scripts/replace-package.js",
"test-nodedriver": "bash .evergreen/test-node-driver.sh",
"pretest-smoke": "npm run compile-cli",
"test-smoke": "npm run test-smoke -w @mongosh/cli-repl",
"compile": "npm run compile --workspaces --if-present",
"compile-cli": "lerna run compile --scope @mongosh/cli-repl --include-dependencies",
"prestart-cli": "npm run compile-cli",
Expand Down
1 change: 1 addition & 0 deletions packages/cli-repl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"test-coverage": "nyc --no-clean --cwd ../.. --reporter=none npm run test",
"test-ci-coverage": "nyc --no-clean --cwd ../.. --reporter=none npm run test-ci",
"test-apistrict-ci": "cross-env MONGOSH_TEST_FORCE_API_STRICT=1 npm run test-ci",
"test-smoke": "node bin/mongosh.js --smokeTests",
"eslint": "eslint",
"lint": "npm run eslint . && npm run prettier -- --check .",
"check": "npm run lint && npm run depcheck",
Expand Down
30 changes: 30 additions & 0 deletions packages/cli-repl/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ if ((v8 as any)?.startupSnapshot?.isBuildingSnapshot?.()) {
// eslint-disable-next-line complexity
async function main() {
markTime(TimingCategories.Main, 'entered main');
suppressExperimentalWarnings();
if (process.env.MONGOSH_RUN_NODE_SCRIPT) {
// For uncompiled mongosh: node /path/to/this/file script ... -> node script ...
// FOr compiled mongosh: mongosh mongosh script ... -> mongosh script ...
Expand Down Expand Up @@ -311,3 +312,32 @@ async function ask(prompt: string): Promise<string> {
process.stdin.unpipe(stdinCopy);
}
}

/**
* Helper to suppress experimental warnings emitted by node if necessary.
*
* In Node.js 23 require()ing ESM modules will work, but emit an experimental warning like
* CommonJS module ABC is loading ES Module XYZ using require(). This is causing problems for
* the way we import fetch - see relevant comments here:
* https://github.com/mongodb-js/devtools-shared/blob/29ceeb5f51d29883d4a69c83e68ad37b0965d49e/packages/devtools-proxy-support/src/fetch.ts#L12-L17
*/
function suppressExperimentalWarnings() {
const nodeMajorVersion = process.versions.node.split('.').map(Number)[0];
if (nodeMajorVersion >= 23) {
const originalEmit = process.emitWarning;
process.emitWarning = (warning, ...args: any[]): void => {
if (args[0] === 'ExperimentalWarning') {
return;
}

if (
typeof args[0] === 'object' &&
args[0].type === 'ExperimentalWarning'
) {
return;
}

return originalEmit(warning, ...args);
};
}
}
5 changes: 3 additions & 2 deletions packages/cli-repl/src/smoke-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ async function runSmokeTest({
// eslint-disable-next-line
const { spawn } = require('child_process') as typeof import('child_process');
const proc = spawn(executable, [...args], {
stdio: ['pipe', 'pipe', includeStderr ? 'pipe' : 'inherit'],
stdio: 'pipe',
});
let stdout = '';
let stderr = '';
Expand All @@ -420,13 +420,14 @@ async function runSmokeTest({
input,
output,
stdout,
stderr,
stderr: includeStderr ? stderr : '',
executable,
actualExitCode,
args: args.map((arg) => redactURICredentials(arg)),
};
try {
assert.match(includeStderr ? `${stdout}\n${stderr}` : stdout, output);
assert.doesNotMatch(stderr, /ExperimentalWarning/);
if (exitCode !== undefined) {
assert.strictEqual(actualExitCode, exitCode);
}
Expand Down

0 comments on commit 1bc517a

Please sign in to comment.