Skip to content

Commit 8edcbd8

Browse files
committed
chore: automate code-workspace creation with sort-workspaces
1 parent 9ba4e17 commit 8edcbd8

File tree

2 files changed

+100
-56
lines changed

2 files changed

+100
-56
lines changed

mongosh.code-workspace

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,33 @@
55
"path": "."
66
},
77
{
8-
"name": "📦 @mongosh/arg-parser",
9-
"path": "packages/arg-parser"
8+
"name": "📦 @mongodb-js/eslint-config-mongosh",
9+
"path": "configs/eslint-config-mongosh"
1010
},
1111
{
12-
"name": "📦 @mongosh/async-rewriter2",
13-
"path": "packages/async-rewriter2"
12+
"name": "📦 @mongodb-js/tsconfig-mongosh",
13+
"path": "configs/tsconfig-mongosh"
1414
},
1515
{
16-
"name": "📦 @mongosh/autocomplete",
17-
"path": "packages/autocomplete"
16+
"name": "📦 @mongosh/docker-build-scripts",
17+
"path": "scripts/docker"
1818
},
1919
{
20-
"name": "📦 @mongosh/browser-runtime-core",
21-
"path": "packages/browser-runtime-core"
22-
},
23-
{
24-
"name": "📦 @mongosh/browser-runtime-electron",
25-
"path": "packages/browser-runtime-electron"
20+
"name": "📦 @mongosh/async-rewriter2",
21+
"path": "packages/async-rewriter2"
2622
},
2723
{
2824
"name": "📦 @mongosh/build",
2925
"path": "packages/build"
3026
},
31-
{
32-
"name": "📦 @mongosh/cli-repl",
33-
"path": "packages/cli-repl"
34-
},
35-
{
36-
"name": "📦 @mongosh/connectivity-tests",
37-
"path": "packages/connectivity-tests"
38-
},
39-
{
40-
"name": "📦 @mongosh/e2e-tests",
41-
"path": "packages/e2e-tests"
42-
}
43-
{
44-
"name": "📦 @mongosh/editor",
45-
"path": "packages/editor"
46-
},
4727
{
4828
"name": "📦 @mongosh/errors",
4929
"path": "packages/errors"
50-
}
30+
},
5131
{
5232
"name": "📦 @mongosh/history",
5333
"path": "packages/history"
5434
},
55-
{
56-
"name": "📦 @mongosh/i18n",
57-
"path": "packages/i18n"
58-
},
5935
{
6036
"name": "📦 @mongosh/java-shell",
6137
"path": "packages/java-shell"
@@ -64,13 +40,25 @@
6440
"name": "📦 @mongosh/js-multiline-to-singleline",
6541
"path": "packages/js-multiline-to-singleline"
6642
},
43+
{
44+
"name": "📦 @mongosh/types",
45+
"path": "packages/types"
46+
},
47+
{
48+
"name": "📦 @mongosh/i18n",
49+
"path": "packages/i18n"
50+
},
6751
{
6852
"name": "📦 @mongosh/logging",
6953
"path": "packages/logging"
7054
},
7155
{
72-
"name": "📦 @mongosh/node-runtime-worker-thread",
73-
"path": "packages/node-runtime-worker-thread"
56+
"name": "📦 @mongosh/shell-bson",
57+
"path": "packages/shell-bson"
58+
},
59+
{
60+
"name": "📦 @mongosh/arg-parser",
61+
"path": "packages/arg-parser"
7462
},
7563
{
7664
"name": "📦 @mongosh/service-provider-core",
@@ -85,8 +73,8 @@
8573
"path": "packages/shell-api"
8674
},
8775
{
88-
"name": "📦 @mongosh/shell-bson",
89-
"path": "packages/shell-bson"
76+
"name": "📦 @mongosh/autocomplete",
77+
"path": "packages/autocomplete"
9078
},
9179
{
9280
"name": "📦 @mongosh/shell-evaluator",
@@ -97,12 +85,40 @@
9785
"path": "packages/snippet-manager"
9886
},
9987
{
100-
"name": "📦 @mongosh/types",
101-
"path": "packages/types"
88+
"name": "📦 @mongosh/browser-runtime-core",
89+
"path": "packages/browser-runtime-core"
90+
},
91+
{
92+
"name": "📦 @mongosh/editor",
93+
"path": "packages/editor"
94+
},
95+
{
96+
"name": "📦 @mongosh/browser-runtime-electron",
97+
"path": "packages/browser-runtime-electron"
98+
},
99+
{
100+
"name": "📦 @mongosh/cli-repl",
101+
"path": "packages/cli-repl"
102+
},
103+
{
104+
"name": "📦 @mongosh/e2e-tests",
105+
"path": "packages/e2e-tests"
106+
},
107+
{
108+
"name": "📦 mongosh",
109+
"path": "packages/mongosh"
110+
},
111+
{
112+
"name": "📦 @mongosh/node-runtime-worker-thread",
113+
"path": "packages/node-runtime-worker-thread"
102114
},
103115
{
104116
"name": "📦 @mongosh/browser-repl",
105117
"path": "packages/browser-repl"
118+
},
119+
{
120+
"name": "📦 @mongosh/connectivity-tests",
121+
"path": "packages/connectivity-tests"
106122
}
107123
],
108124
"settings": {
@@ -118,6 +134,8 @@
118134
"testExplorer.gutterDecoration": true
119135
},
120136
"extensions": {
121-
"recommendations": ["hbenl.vscode-mocha-test-adapter"]
137+
"recommendations": [
138+
"hbenl.vscode-mocha-test-adapter"
139+
]
122140
}
123141
}

scripts/sort-workspaces.js

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env node
22

3-
const fs = require('fs').promises;
4-
const path = require('path');
5-
const util = require('util');
6-
const exec = util.promisify(require('child_process').exec);
3+
const fs = require("fs").promises;
4+
const path = require("path");
5+
const util = require("util");
6+
const exec = util.promisify(require("child_process").exec);
77

8-
process.on('unhandledRejection', (err) => {
8+
process.on("unhandledRejection", (err) => {
99
console.error();
1010
console.error(err?.stack || err?.message || err);
1111
process.exitCode = 1;
@@ -14,21 +14,47 @@ process.on('unhandledRejection', (err) => {
1414
async function main() {
1515
if (process.env.CI) return;
1616

17-
const monorepoRoot = path.resolve(__dirname, '..');
17+
const monorepoRoot = path.resolve(__dirname, "..");
1818

19-
const packageJSON = JSON.parse(await fs.readFile(
20-
path.join(monorepoRoot, 'package.json'),
21-
'utf8'
22-
));
19+
// Get sorted packages from lerna
20+
const { stdout } = await exec("npx -y lerna ls --all --toposort --json");
21+
const packages = JSON.parse(stdout);
2322

24-
// should use the scopes in lerna.json
25-
const { stdout } = await exec('npx -y lerna ls --all --toposort --json');
26-
packageJSON.workspaces = JSON.parse(stdout).map(({ location }) => path.relative(monorepoRoot, location));
23+
// Update package.json
24+
const packageJSON = JSON.parse(
25+
await fs.readFile(path.join(monorepoRoot, "package.json"), "utf8")
26+
);
27+
28+
packageJSON.workspaces = packages.map(({ location }) =>
29+
path.relative(monorepoRoot, location)
30+
);
31+
32+
await fs.writeFile(
33+
path.join(monorepoRoot, "package.json"),
34+
JSON.stringify(packageJSON, null, 2) + "\n",
35+
"utf8"
36+
);
37+
38+
// Update mongosh.code-workspace
39+
const workspaceFile = path.join(monorepoRoot, "mongosh.code-workspace");
40+
const workspace = JSON.parse(await fs.readFile(workspaceFile, "utf8"));
41+
42+
// Keep the root folder and regenerate package folders in topological order
43+
workspace.folders = [
44+
{
45+
name: "mongosh",
46+
path: ".",
47+
},
48+
...packages.map(({ name, location }) => ({
49+
name: `📦 ${name}`,
50+
path: path.relative(monorepoRoot, location),
51+
})),
52+
];
2753

2854
await fs.writeFile(
29-
path.join(monorepoRoot, 'package.json'),
30-
JSON.stringify(packageJSON, null, 2) + '\n',
31-
'utf8'
55+
workspaceFile,
56+
JSON.stringify(workspace, null, 2) + "\n",
57+
"utf8"
3258
);
3359
}
3460

0 commit comments

Comments
 (0)