From 226503e0e670848460895725940508854166f0d4 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Mon, 8 Jan 2024 15:38:52 +0000 Subject: [PATCH] expand nightly to the exact version, force install --- .evergreen/install-npm-deps.sh | 1 + scripts/replace-package.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.evergreen/install-npm-deps.sh b/.evergreen/install-npm-deps.sh index 88846145e..b1b8373bb 100644 --- a/.evergreen/install-npm-deps.sh +++ b/.evergreen/install-npm-deps.sh @@ -9,6 +9,7 @@ echo "MONOGDB_DRIVER_VERSION_OVERRIDE:$MONOGDB_DRIVER_VERSION_OVERRIDE" if [[ -n "$MONOGDB_DRIVER_VERSION_OVERRIDE" ]]; then export REPLACE_PACKAGE="mongodb:$MONOGDB_DRIVER_VERSION_OVERRIDE" npm run replace-package + npm ci --verbose --force # force because of issues with peer deps and semver pre-releases fi # if we rewrote this script in javascript using just builtin node modules we could skip the npm ci above diff --git a/scripts/replace-package.js b/scripts/replace-package.js index d4db2fc16..9f2262d98 100644 --- a/scripts/replace-package.js +++ b/scripts/replace-package.js @@ -5,6 +5,7 @@ 'use strict'; const fs = require('fs'); const path = require('path'); +const { execSync } = require('child_process'); const replacement = process.env.REPLACE_PACKAGE; if (!replacement) { @@ -15,7 +16,17 @@ if (!parsed || !parsed.groups.from || !parsed.groups.to) { throw new Error('Invalid format for REPLACE_PACKAGE'); } -const { from, to } = parsed.groups; +function resolveTag(from, to) { + return execSync(`npm dist-tag ls ${from}@${to} | awk -F ': ' '/^${to}/ {print \$2}'`).toString().trim(); +} + +const { from, to: _to } = parsed.groups; + +// npm install doesn't seem to do anything if you're updating a +// package-lock.json file that already has the dep to a tag like nightly, but it +// does do something if you change it to the exact version. +const to = _to === 'nightly' ? resolveTag(from, _to) : _to; + for (const dir of ['.', ...fs.readdirSync('packages').map(dir => path.join('packages', dir))]) { const packageJson = path.join(dir, 'package.json'); if (fs.existsSync(packageJson)) {