Skip to content

Commit 49a248c

Browse files
fix: build system improvements for package-level scripts (#263)
## **Description** This PR improves the build system across the monorepo to properly handle individual package build scripts and ensure consistent building behavior. Key improvements: 1. Updates root build script to use Yarn workspaces for better package management 2. Ensures CSS files are properly built and placed in dist directories 3. Fixes issues with individual package builds using `yarn workspace` 4. Standardizes build scripts across packages ## **Related issues** Fixes: #262 ## **Manual testing steps** 1. Clean all builds: `yarn build:clean` 2. Run root build: `yarn build` 3. Run build types: `yarn build:types` 4. Verify CSS files are present in design-tokens/dist 5. Test individual package build: `yarn workspace @metamask/design-tokens run build` 6. Verify all build artifacts are generated correctly ## **Screen recordings** ### Before Preview build of design tokens doesn't work because stylesheet is not included in build <img width="1350" alt="Screenshot 2024-12-02 at 7 33 42 AM" src="https://github.com/user-attachments/assets/63e5be37-1951-4ffc-9818-ad9db8dce6c7"> Styles not being built in design tokens and not all types being built https://github.com/user-attachments/assets/238f1b2d-02dd-4d06-bdb5-3475bbd5cd62 ### After Preview build of design tokens works because stylesheet is included in build <img width="1386" alt="Screenshot 2024-12-02 at 7 35 05 AM" src="https://github.com/user-attachments/assets/a9baa4a7-b9d8-4656-8aad-fd40f9d18087"> Build scripts working as expected and stylesheeet in design tokens package being built https://github.com/user-attachments/assets/236078ed-2584-437c-ac37-b957edcab8f6 ## **Pre-merge author checklist** - [x] I've followed MetaMask Contributor Docs - [x] I've completed the PR template - [x] I've included tests (build verification) - [x] I've documented the build process - [x] I've applied appropriate labels ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR - [ ] I confirm this PR addresses all acceptance criteria
1 parent f518b80 commit 49a248c

File tree

10 files changed

+15
-20
lines changed

10 files changed

+15
-20
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"packages/*"
1414
],
1515
"scripts": {
16-
"build": "yarn ts-bridge --project tsconfig.build.json --verbose && yarn workspace @metamask/design-system-twrnc-preset build && yarn workspace @metamask/design-system-react-native build",
17-
"build:clean": "rimraf dist '**/*.tsbuildinfo' && yarn build",
16+
"build": "yarn workspaces foreach --all --topological-dev run build",
17+
"build:clean": "rimraf 'packages/*/dist' '**/*.tsbuildinfo' && yarn build",
1818
"build:types": "tsc --build tsconfig.build.json --verbose",
1919
"changelog:update": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run changelog:update",
2020
"changelog:validate": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run changelog:validate",
@@ -59,7 +59,6 @@
5959
"@metamask/eslint-config-nodejs": "^12.1.0",
6060
"@metamask/eslint-config-typescript": "^12.1.0",
6161
"@metamask/utils": "^9.1.0",
62-
"@ts-bridge/cli": "^0.5.1",
6362
"@types/jest": "^27.4.1",
6463
"@types/lodash": "^4.14.191",
6564
"@types/node": "^16.18.54",

packages/design-system-react-native/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
},
4444
"dependencies": {
4545
"@metamask/design-system-twrnc-preset": "workspace:^",
46-
"@types/react": "^18.2.0",
4746
"react": "^18.2.0",
4847
"react-native": "^0.72.15"
4948
},
@@ -57,6 +56,7 @@
5756
"@testing-library/react-native": "^12.8.1",
5857
"@types/babel__preset-env": "^7",
5958
"@types/jest": "^27.4.1",
59+
"@types/react": "^18.2.0",
6060
"@types/react-test-renderer": "^18",
6161
"babel-jest": "^29.7.0",
6262
"deepmerge": "^4.2.2",

packages/design-system-react-native/tsconfig.build.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
"emitDeclarationOnly": false
1010
},
1111
"references": [
12-
{
13-
"path": "../design-system-twrnc-preset/tsconfig.build.json"
14-
}
12+
{ "path": "../design-system-twrnc-preset/tsconfig.build.json" }
1513
],
1614
"include": ["./src"]
1715
}

packages/design-system-react/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@storybook/test": "^8.3.5",
5757
"@testing-library/jest-dom": "^6.6.3",
5858
"@testing-library/react": "^16.0.1",
59+
"@ts-bridge/cli": "^0.5.1",
5960
"@types/jest": "^27.4.1",
6061
"@types/react": "^18.2.0",
6162
"@types/react-dom": "^18.2.0",

packages/design-system-tailwind-preset/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
},
4848
"devDependencies": {
4949
"@metamask/auto-changelog": "^3.4.4",
50+
"@ts-bridge/cli": "^0.5.1",
5051
"@types/jest": "^27.4.1",
5152
"@types/node": "^16.18.54",
5253
"deepmerge": "^4.2.2",

packages/design-system-twrnc-preset/tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"types": ["react-native", "jest"],
99
"emitDeclarationOnly": false
1010
},
11-
"references": [],
11+
"references": [{ "path": "../design-tokens/tsconfig.build.json" }],
1212
"include": ["./src"]
1313
}

packages/design-tokens/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@
3333
"module": "./dist/index.mjs",
3434
"types": "./dist/index.d.cts",
3535
"files": [
36-
"dist",
3736
"dist/"
3837
],
3938
"scripts": {
4039
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references && yarn build:css",
4140
"build:css": "cleancss -o dist/styles.css src/css/index.css",
42-
"build:types": "tsc --project tsconfig.build.json",
4341
"changelog:update": "../../scripts/update-changelog.sh @metamask/design-tokens",
4442
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/design-tokens",
4543
"publish:preview": "yarn npm publish --tag preview",
@@ -52,6 +50,7 @@
5250
"devDependencies": {
5351
"@metamask/auto-changelog": "^3.4.4",
5452
"@metamask/design-system-react": "workspace:^",
53+
"@ts-bridge/cli": "^0.5.1",
5554
"@types/jest": "^27.4.1",
5655
"@types/node": "^16.18.54",
5756
"clean-css-cli": "^5.6.3",

scripts/prepare-preview-builds.jq

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@
88
# This is just for testing, it doesn't need to strictly follow SemVer.
99
.version |= split("-")[0] + "-preview.\($hash)" |
1010

11-
# Update the build script in the root package.json to use the preview scope
12-
if .scripts and .scripts.build then
13-
.scripts.build |= gsub("@metamask/"; "\($npm_scope)/")
14-
else
15-
.
16-
end |
17-
1811
# The workspace dependencies are updated to point to the exact preview build
1912
# version, so that Yarn does not try to resolve a different version from the
2013
# registry.

tsconfig.build.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"references": [
3-
{ "path": "./packages/design-system-react/tsconfig.build.json" },
3+
{ "path": "./packages/design-tokens/tsconfig.build.json" },
4+
{ "path": "./packages/design-system-twrnc-preset/tsconfig.build.json" },
45
{ "path": "./packages/design-system-tailwind-preset/tsconfig.build.json" },
5-
{ "path": "./packages/design-tokens/tsconfig.build.json" }
6+
{ "path": "./packages/design-system-react-native/tsconfig.build.json" },
7+
{ "path": "./packages/design-system-react/tsconfig.build.json" }
68
],
79
"files": [],
810
"include": []

yarn.lock

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3208,6 +3208,7 @@ __metadata:
32083208
"@storybook/test": "npm:^8.3.5"
32093209
"@testing-library/jest-dom": "npm:^6.6.3"
32103210
"@testing-library/react": "npm:^16.0.1"
3211+
"@ts-bridge/cli": "npm:^0.5.1"
32113212
"@types/jest": "npm:^27.4.1"
32123213
"@types/react": "npm:^18.2.0"
32133214
"@types/react-dom": "npm:^18.2.0"
@@ -3230,6 +3231,7 @@ __metadata:
32303231
resolution: "@metamask/design-system-tailwind-preset@workspace:packages/design-system-tailwind-preset"
32313232
dependencies:
32323233
"@metamask/auto-changelog": "npm:^3.4.4"
3234+
"@ts-bridge/cli": "npm:^0.5.1"
32333235
"@types/jest": "npm:^27.4.1"
32343236
"@types/node": "npm:^16.18.54"
32353237
deepmerge: "npm:^4.2.2"
@@ -3277,6 +3279,7 @@ __metadata:
32773279
dependencies:
32783280
"@metamask/auto-changelog": "npm:^3.4.4"
32793281
"@metamask/design-system-react": "workspace:^"
3282+
"@ts-bridge/cli": "npm:^0.5.1"
32803283
"@types/jest": "npm:^27.4.1"
32813284
"@types/node": "npm:^16.18.54"
32823285
clean-css-cli: "npm:^5.6.3"
@@ -3352,7 +3355,6 @@ __metadata:
33523355
"@metamask/eslint-config-nodejs": "npm:^12.1.0"
33533356
"@metamask/eslint-config-typescript": "npm:^12.1.0"
33543357
"@metamask/utils": "npm:^9.1.0"
3355-
"@ts-bridge/cli": "npm:^0.5.1"
33563358
"@types/jest": "npm:^27.4.1"
33573359
"@types/lodash": "npm:^4.14.191"
33583360
"@types/node": "npm:^16.18.54"

0 commit comments

Comments
 (0)