Skip to content

Commit ba709b7

Browse files
committed
chore: bundle the root package.json as an installable package
1 parent 113425c commit ba709b7

File tree

12 files changed

+204
-134
lines changed

12 files changed

+204
-134
lines changed

.circleci/cache-version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Bump this version to force CI to re-create the cache from scratch.
2-
9-18-2025-x2
2+
9-22-2025-root-bundle

.circleci/src/workflows/workflows/@main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ linux-x64:
66
- equal: [ develop, << pipeline.git.branch >> ]
77
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
88
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
9+
- equal: [ 'chore/bundle_package_root', << pipeline.git.branch >> ]
910
- matches:
1011
pattern: /^release\/\d+\.\d+\.\d+$/
1112
value: << pipeline.git.branch >>

.circleci/workflows.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3718,6 +3718,9 @@ workflows:
37183718
- equal:
37193719
- update-v8-snapshot-cache-on-develop
37203720
- << pipeline.git.branch >>
3721+
- equal:
3722+
- chore/bundle_package_root
3723+
- << pipeline.git.branch >>
37213724
- matches:
37223725
pattern: /^release\/\d+\.\d+\.\d+$/
37233726
value: << pipeline.git.branch >>
@@ -3772,6 +3775,9 @@ workflows:
37723775
- equal:
37733776
- update-v8-snapshot-cache-on-develop
37743777
- << pipeline.git.branch >>
3778+
- equal:
3779+
- chore/bundle_package_root
3780+
- << pipeline.git.branch >>
37753781
- matches:
37763782
pattern: /^release\/\d+\.\d+\.\d+$/
37773783
value: << pipeline.git.branch >>
@@ -3837,6 +3843,9 @@ workflows:
38373843
- equal:
38383844
- update-v8-snapshot-cache-on-develop
38393845
- << pipeline.git.branch >>
3846+
- equal:
3847+
- chore/bundle_package_root
3848+
- << pipeline.git.branch >>
38403849
- matches:
38413850
pattern: /^release\/\d+\.\d+\.\d+$/
38423851
value: << pipeline.git.branch >>
@@ -4322,6 +4331,9 @@ workflows:
43224331
- equal:
43234332
- update-v8-snapshot-cache-on-develop
43244333
- << pipeline.git.branch >>
4334+
- equal:
4335+
- chore/bundle_package_root
4336+
- << pipeline.git.branch >>
43254337
- matches:
43264338
pattern: /^release\/\d+\.\d+\.\d+$/
43274339
value: << pipeline.git.branch >>
@@ -5157,6 +5169,9 @@ workflows:
51575169
- equal:
51585170
- update-v8-snapshot-cache-on-develop
51595171
- << pipeline.git.branch >>
5172+
- equal:
5173+
- chore/bundle_package_root
5174+
- << pipeline.git.branch >>
51605175
- matches:
51615176
pattern: /^release\/\d+\.\d+\.\d+$/
51625177
value: << pipeline.git.branch >>

packages/root/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
index.js
2+
index.mjs

packages/root/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Purpose
2+
3+
Bundles the monorepo root `package.json` as an installable package, allowing `@packages/root` to be installed in any context without having a absolute reference ot the root `package.json`
4+
5+
In order to accomplish this, `rollup` is used bundle the `package.json`, as packages may be interpreted in place or be installed inside the `node_modules` directory. This package builds an `index.mjs` file for packages using `vite`/ ES Modules and an `index.js` file for any CommonJS entrypoints.

packages/root/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/root/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import pkg from '../../package.json'
2+
3+
export default pkg

packages/root/package.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
{
22
"name": "@packages/root",
33
"version": "0.0.0-development",
4-
"description": "dummy package pointing at the root package",
4+
"description": "bundles the root package.json as an installable package",
55
"main": "index.js",
6+
"scripts": {
7+
"build": "yarn build:cjs && yarn build:esm",
8+
"build:cjs": "rimraf index.js && rollup -c rollup.config.mjs -f cjs -o index.js",
9+
"build:esm": "rimraf index.mjs && rollup -c rollup.config.mjs -f esm -o index.mjs",
10+
"build:prod": "yarn build"
11+
},
12+
"devDependencies": {
13+
"@rollup/plugin-json": "^6.1.0",
14+
"rimraf": "^6.0.1",
15+
"rollup": "^4.52.0",
16+
"typescript": "^5.6.3"
17+
},
18+
"module": "index.mjs",
619
"nx": {}
720
}

packages/root/rollup.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import json from '@rollup/plugin-json'
2+
3+
export default {
4+
input: 'index.ts',
5+
// inlines the root package.json into the bundle
6+
plugins: [json()],
7+
}

packages/root/tsconfig.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"resolveJsonModule": true,
4+
}
5+
}

0 commit comments

Comments
 (0)