Skip to content

Commit 94999fc

Browse files
X-GuardianSimon Heather
andauthored
chore(deps): replace lerna with nx (#315)
### Description The repo already uses nx as its task runner for `test`, `lint`, and the affected-graph, but still depends on lerna for a handful of orchestration and release chores. This PR removes lerna entirely and routes those chores through nx, then converts the touched shell scripts to ESM Node. **Lerna → nx command mapping:** - `lerna run --scope <glob> <target>` → `nx run-many -t <target> -p <glob>` (root `build`, `package*`, `watch`, `dist-clean` scripts). - `lerna exec --scope <glob> -- <cmd>` → `nx exec -p <glob> -- <cmd>` (`link-packages`, and the `ncu` runs in `pnpm-upgrade.yml`). - `lerna ls -p` (absolute package paths) → `pnpm --recursive exec pwd`. - `lerna list --all --json` / `lerna ls --all --json` (only the package **names** were used) → `nx show projects --json`. - `lerna version <v>` → `nx release version <v>`. This needs a `release` block in `nx.json` (fixed release group of `cdktn`, `cdktn-cli`, `@cdktn/*`); the command is run with `--git-commit/tag/push=false --stage-changes=false` so it only rewrites versions on disk, matching the old `--no-git-tag-version --no-push` behaviour. ### Other Changes **Dead code deleted rather than converted** (both were unreferenced — nothing in the repo or CI invoked them): - `tools/build-unit-test-matrix.sh` — the unit workflows build their matrix inline via `nx show projects --affected`; this script was orphaned. - `tools/setup-prebuild-provider-folder.sh` — a manual utility that scaffolded a workspace of cloned `hashicorp/*` provider repos, which are no longer the canonical source. **Shell/batch scripts converted to ESM Node** (`.mjs`), per the repo's preference for JS ESM tooling: - `tools/align-version.sh` → `tools/align-version.mjs`. Also drops a dead `jq` loop that rewrote `0.0.0` peerDependencies — the only internal peerDep is `cdktn: workspace:*`, which jsii-pacmak resolves to a concrete version at pack time (verified against the built tarball), so the loop matched nothing. - `tools/collect-dist.sh` **and** `tools/collect-dist.bat` → a single cross-platform `tools/collect-dist.mjs` (uses `fs.cpSync(..., { dereference: true })` for the `rsync -aL` behaviour; verified byte-identical output to the old script). The `.bat` was still calling `lerna ls -p`, so this also removes the last stray lerna reference. `package-windows` now runs the same `.mjs` as every other platform. - `tools/build-example.js` → `tools/build-example.mjs` (CJS `require`/`__dirname` → ESM). This leaves no CommonJS in top-level `tools/`. **Lint coverage for `tools/`:** the root `eslint.config.mjs` ignores all `**/*.js` and `**/*.mjs`, and ESLint flat config does not auto-discover nested config files — so the top-level `tools/` scripts were never linted (per-project linting only works because nx invokes ESLint per project). Added `tools/project.json` (`@tools/scripts`) so nx infers a `lint` target and the scripts are picked up by `nx run-many -t lint`, plus `tools/eslint.config.mjs` that lints them as plain ESM JavaScript (no type-aware TS parsing) and defers to the nested `tools/*` projects for their own files. **Callers updated:** `release.yml`, `unit.yml`, `pr-unit.yml`, `examples.yml`, `pnpm-upgrade.yml`, `CONTRIBUTING.md`, and `docs/release-please.md`. Stale `!tools/*.js` negations in `.gitignore` / `.prettierignore` are dropped (the `.mjs` replacements aren't caught by the `*.js` ignore, so they need no negation). ### Checklist - [ ] I have updated the PR title to match [CDKTN's style guide](https://github.com/open-constructs/cdk-terrain/blob/main/CONTRIBUTING.md#pull-requests-1) - [ ] I have run the linter on my code locally - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the [documentation](https://github.com/open-constructs/cdk-terrain-docs/tree/main/content) if applicable - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works if applicable - [ ] New and existing unit tests pass locally with my changes Co-authored-by: Simon Heather <simon.heather@yulife.com>
1 parent d555b82 commit 94999fc

25 files changed

Lines changed: 206 additions & 2273 deletions

.github/workflows/examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ jobs:
164164
mkdir -p packages/cdktn/dist/go
165165
ln -sfn "$PWD/dist/go/cdktn" packages/cdktn/dist/go/cdktn
166166
- name: examples integration tests
167-
run: test/run-against-dist.mjs node tools/build-example.js ${TEST_TARGET}
167+
run: test/run-against-dist.mjs node tools/build-example.mjs ${TEST_TARGET}
168168
env:
169169
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
170170
TEST_TARGET: "${{ matrix.target }}"

.github/workflows/pnpm-upgrade.yml

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ on:
1111
# We special-case @types/fs-extra because the current major (9.x) is broken with @types/node >= 10
1212
# We special-case typescript because it's not semantically versioned
1313
# We special-case constructs because we want to stay in control of the minimum compatible version
14-
# We special-case lerna because we have a patch on it that stops applying if Lerna upgrades. Remove this once https://github.com/lerna/lerna/pull/2874 releases.
1514
# We special-case graphology-types because the newer version has type definitions that are not compatible with our typescript version.
1615
# We special-case @types/prettier because the underlying TS types aren't supported by our TS version anymore since prettier v2.6.1
1716

@@ -41,20 +40,23 @@ jobs:
4140
uses: ./.github/actions/setup-corepack-pnpm
4241
- name: Install Tools
4342
run: |-
44-
npm -g install lerna npm-check-updates@^9.0.0
43+
npm -g install npm-check-updates@^9.0.0
44+
# Install first so `nx` is available for the package listing below.
45+
- name: Run "pnpm install"
46+
run: pnpm install --prefer-offline
4547
- name: List Mono-Repo Packages
4648
id: list-packages
4749
# These need to be ignored from the `ncu` runs!
4850
run: |-
49-
echo "list=$(node -p "$(lerna ls --all --json 2>/dev/null).map(item => item.name).join(',')")" >> $GITHUB_OUTPUT
51+
echo "list=$(pnpm exec nx show projects --json | jq -r 'join(",")')" >> $GITHUB_OUTPUT
5052
- name: Run "ncu -u"
5153
run: |-
5254
# Upgrade dependencies at repository root
5355
ncu --upgrade --filter=@types/fs-extra --target=minor
5456
ncu --upgrade --filter=typescript --target=patch
55-
ncu --upgrade --reject=@types/node,@types/fs-extra,constructs,typescript,lerna,@types/prettier --target=minor
57+
ncu --upgrade --reject=@types/node,@types/fs-extra,constructs,typescript,@types/prettier --target=minor
5658
57-
# This will ensure the current lockfile is up-to-date with the dependency specifications (necessary for "pnpm update" to run)
59+
# Refresh the lockfile after the ncu edits above (necessary for "pnpm update" to run)
5860
- name: Run "pnpm install"
5961
run: pnpm install --prefer-offline
6062

@@ -163,19 +165,22 @@ jobs:
163165
uses: ./.github/actions/setup-corepack-pnpm
164166
- name: Install Tools
165167
run: |-
166-
npm -g install lerna npm-check-updates@^9.0.0
168+
npm -g install npm-check-updates@^9.0.0
169+
# Install first so `nx` is available for the package listing below.
170+
- name: Run "pnpm install"
171+
run: pnpm install --prefer-offline
167172
- name: List Mono-Repo Packages
168173
id: list-packages
169174
# These need to be ignored from the `ncu` runs!
170175
run: |-
171-
echo "list=$(node -p "$(lerna ls --all --json 2>/dev/null).map(item => item.name).join(',')")" >> $GITHUB_OUTPUT
176+
echo "list=$(pnpm exec nx show projects --json | jq -r 'join(",")')" >> $GITHUB_OUTPUT
172177
- name: Run "ncu -u"
173178
run: |-
174179
# Upgrade all the packages
175-
lerna exec --scope='{${{ join(matrix.pr.packages, ',') }}}' ncu -- --upgrade --filter=@types/fs-extra --target=minor
176-
lerna exec --scope='{${{ join(matrix.pr.packages, ',') }}}' ncu -- --upgrade --filter=typescript --target=patch
177-
lerna exec --scope='{${{ join(matrix.pr.packages, ',') }}}' ncu -- --upgrade --reject='@types/node,@types/fs-extra,constructs,typescript,graphology-types,jsii,jsii-pacmak,jsii-rosetta,jsii-docgen,codemaker,${{ steps.list-packages.outputs.list }}' --target=minor
178-
# This will ensure the current lockfile is up-to-date with the dependency specifications (necessary for "pnpm update" to run)
180+
pnpm exec nx exec -p '${{ join(matrix.pr.packages, ',') }}' -- ncu --upgrade --filter=@types/fs-extra --target=minor
181+
pnpm exec nx exec -p '${{ join(matrix.pr.packages, ',') }}' -- ncu --upgrade --filter=typescript --target=patch
182+
pnpm exec nx exec -p '${{ join(matrix.pr.packages, ',') }}' -- ncu --upgrade --reject='@types/node,@types/fs-extra,constructs,typescript,graphology-types,jsii,jsii-pacmak,jsii-rosetta,jsii-docgen,codemaker,${{ steps.list-packages.outputs.list }}' --target=minor
183+
# Refresh the lockfile after the ncu edits above (necessary for "pnpm update" to run)
179184
- name: Run "pnpm install"
180185
run: pnpm install --prefer-offline
181186

@@ -227,17 +232,20 @@ jobs:
227232
uses: ./.github/actions/setup-corepack-pnpm
228233
- name: Install Tools
229234
run: |-
230-
npm -g install lerna npm-check-updates@^9.0.0
235+
npm -g install npm-check-updates@^9.0.0
236+
# Install first so `nx` is available for the package listing below.
237+
- name: Run "pnpm install"
238+
run: pnpm install --prefer-offline
231239
- name: List Mono-Repo Packages
232240
id: list-packages
233241
# These need to be ignored from the `ncu` runs!
234242
run: |-
235-
echo "list=$(node -p "$(lerna ls --all --json 2>/dev/null).map(item => item.name).join(',')")" >> $GITHUB_OUTPUT
243+
echo "list=$(pnpm exec nx show projects --json | jq -r 'join(",")')" >> $GITHUB_OUTPUT
236244
- name: Run "ncu -u"
237245
run: |-
238246
# Upgrade all the packages
239-
lerna exec ncu -- --upgrade --filter='jsii,jsii-pacmak,jsii-rosetta,jsii-docgen,codemaker,constructs' --target=minor
240-
# This will ensure the current lockfile is up-to-date with the dependency specifications (necessary for "pnpm update" to run)
247+
pnpm exec nx exec -- ncu --upgrade --filter='jsii,jsii-pacmak,jsii-rosetta,jsii-docgen,codemaker,constructs' --target=minor
248+
# Refresh the lockfile after the ncu edits above (necessary for "pnpm update" to run)
241249
- name: Run "pnpm install"
242250
run: pnpm install --prefer-offline
243251

.github/workflows/pr-unit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
# @cdktn/hcl2cdk's globalSetup.ts spawns `cdktn init --dist=...` which
6868
# reads jsii tarballs from the workspace-root dist/ directory; that
6969
# output isn't produced by an Nx target chain, only by `pnpm run package`
70-
# + tools/collect-dist.sh. Run it conditionally so unrelated PRs
70+
# + tools/collect-dist.mjs. Run it conditionally so unrelated PRs
7171
# don't pay the multi-language packaging cost.
7272
run: |
7373
if pnpm exec nx show projects --affected --base="$NX_BASE" --head="$NX_HEAD" | grep -qx '@cdktn/hcl2cdk'; then

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
if: steps.get_release_status.outputs.release == 'unreleased'
6969
run: |
7070
pnpm ci
71-
tools/align-version.sh
71+
node tools/align-version.mjs
7272
pnpm run build
7373
pnpm run package
7474
env:
@@ -134,7 +134,7 @@ jobs:
134134
- name: Bump prerelease version
135135
run: |
136136
pnpm prepare-next-release
137-
tools/align-version.sh
137+
node tools/align-version.mjs
138138
- name: version
139139
id: get_version
140140
run: |

.github/workflows/unit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
run: |
6565
pnpm ci
6666
- name: align versions
67-
run: tools/align-version.sh
67+
run: node tools/align-version.mjs
6868
- name: package (when testing @cdktn/hcl2cdk)
6969
# hcl2cdk's globalSetup.ts spawns `cdktn init --dist=...` which reads
7070
# jsii tarballs from the workspace-root dist/ directory.

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
!test.js
88
*.d.ts
99
node_modules
10-
!tools/build-example.js
11-
!tools/lint-examples.js
1210

1311
# CDK asset staging directory
1412
.cdk.staging

.prettierignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ dist
2323
packages/@cdktn/provider-generator/edge-provider-bindings
2424
test/edge-provider-bindings
2525
!tools/documentation-generation/generate-documentation.js
26-
!tools/build-example.js
27-
!tools/lint-examples.js
28-
!tools/update-github-project-board/index.ts
2926
**/go.mod
3027
**/go.sum
3128
**/pnpm-lock.yaml

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ If you get this error message when trying to use a local build of `cdktn`:
324324
Run:
325325
326326
```
327-
./tools/align-version.sh -dev.111212112 && pnpm build && pnpm package
327+
node tools/align-version.mjs -dev.111212112 && pnpm build && pnpm package
328328
```
329329
330330
This builds a package with a development version which skips the tamper check in Python. (We once accidentally released `cdktn 0.0.0` which is the reason why Python knows some valid hashes for that `0.0.0` version and will fail as they won't match.)

docs/release-please.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ untouched and keys off `package.json` as it always has.
1515

1616
This is a **locked-version JSII monorepo**: every package ships at the single
1717
root version. In git the sub-package `package.json`s stay at `0.0.0` and are
18-
aligned at build time by `tools/align-version.sh` (`lerna version`). Therefore
18+
aligned at build time by `tools/align-version.mjs` (`nx release version`). Therefore
1919
release-please manages a **single root release** (the `"."` package in
2020
`release-please-config.json`) — not independent per-package versions.
2121

knip.jsonc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"treatConfigHintsAsErrors": true,
77
"workspaces": {
88
".": {
9+
// The loose scripts under tools/ are invoked from package.json/CI, not imported;
10+
// list them as entries so knip traces their dependencies
11+
"entry": ["tools/*.mjs"],
912
"ignoreDependencies": [
1013
// Required by the tools/extract-changelog script (run from tools/release-github.sh).
1114
"changelog-parser",

0 commit comments

Comments
 (0)