Skip to content

Commit be919e0

Browse files
committed
check if bump is necessary for installs
1 parent 45469f9 commit be919e0

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
lines changed

.evergreen/install-npm-deps.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,5 @@ npm run mark-ci-required-optional-dependencies
3131
# along with its types, but npm wouldn't try and compile the addon
3232
(npm ci && test -e node_modules/mongodb-client-encryption) || npm ci --ignore-scripts
3333

34-
npm run evergreen-release bump
35-
3634
echo "npm packages after installation"
3735
npm ls || true

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"prepare": "husky",
7272
"precommit": "precommit",
7373
"preinstall": "node scripts/sort-workspaces.js",
74-
"bump-packages": "npm run bump --workspace @mongosh/build"
74+
"bump-packages": "npm run bump-packages --workspace @mongosh/build"
7575
},
7676
"config": {
7777
"unsafe-perm": true
Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,64 @@
11
import { spawnSync } from '../helpers';
22
import { PROJECT_ROOT } from './constants';
33

4-
const PACKAGES_TO_SKIP_BUMPING = ['mongosh', '@mongosh/cli-repl'];
4+
import { promises as fs } from 'fs';
5+
import path from 'path';
6+
import { getPackagesInTopologicalOrder } from '@mongodb-js/monorepo-tools';
57

8+
/** Packages which get bumped only as part of the mongosh release. */
9+
const MONGOSH_RELEASE_PACKAGES = ['mongosh', '@mongosh/cli-repl'];
10+
11+
/** This bumps only the main mongosh release packages to the set version. */
12+
export async function bumpMongosh(version: string): Promise<void> {
13+
console.info(`mongosh: Bumping package versions to ${version}`);
14+
const monorepoRootPath = path.resolve(__dirname, '..', '..', '..', '..');
15+
const packages = await getPackagesInTopologicalOrder(monorepoRootPath);
16+
17+
const workspaceNames = packages
18+
.map((p) => p.name)
19+
.filter((name) => MONGOSH_RELEASE_PACKAGES.includes(name));
20+
21+
const locations = [monorepoRootPath, ...packages.map((p) => p.location)];
22+
23+
for (const location of locations) {
24+
const packageJsonPath = path.join(location, 'package.json');
25+
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
26+
27+
packageJson.version = version;
28+
for (const grouping of [
29+
'dependencies',
30+
'devDependencies',
31+
'optionalDependencies',
32+
'peerDependencies',
33+
]) {
34+
if (!packageJson[grouping]) {
35+
continue;
36+
}
37+
38+
for (const name of Object.keys(packageJson[grouping])) {
39+
if (!workspaceNames.includes(name)) {
40+
continue;
41+
}
42+
packageJson[grouping][name] = version;
43+
}
44+
}
45+
46+
await fs.writeFile(
47+
packageJsonPath,
48+
JSON.stringify(packageJson, null, 2) + '\n'
49+
);
50+
}
51+
}
52+
53+
/** Bump packages without setting a new version of mongosh. */
654
export function bumpNpmPackages() {
7-
spawnSync('npx', ['bump-monorepo-packages'], {
55+
spawnSync('bump-monorepo-packages', [], {
856
stdio: 'inherit',
957
cwd: PROJECT_ROOT,
1058
encoding: 'utf8',
1159
env: {
1260
...process.env,
13-
SKIP_BUMP_PACKAGES: PACKAGES_TO_SKIP_BUMPING.join(','),
61+
SKIP_BUMP_PACKAGES: MONGOSH_RELEASE_PACKAGES.join(','),
1462
},
1563
});
1664
}

packages/build/src/release.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ import { runUpload } from './run-upload';
2222
import { runSign } from './packaging/run-sign';
2323
import { runDownloadAndListArtifacts } from './run-download-and-list-artifacts';
2424
import { runDownloadCryptLibrary } from './packaging/run-download-crypt-library';
25+
import { bumpMongosh } from './npm-packages/bump';
2526

2627
export type ReleaseCommand =
2728
| 'bump'
29+
| 'bump-packages'
2830
| 'compile'
2931
| 'package'
3032
| 'sign'
@@ -55,6 +57,10 @@ export async function release(
5557
);
5658

5759
if (command === 'bump') {
60+
await bumpMongosh(config.version);
61+
bumpNpmPackages();
62+
return;
63+
} else if (command === 'bump-packages') {
5864
// updates the version of internal packages to reflect the tagged one
5965
bumpNpmPackages();
6066
return;

0 commit comments

Comments
 (0)