Skip to content

Commit eb27474

Browse files
authored
Fix monorepo build pipeline (#449)
1 parent 1c0f7de commit eb27474

33 files changed

Lines changed: 128 additions & 79 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
**/dist
2-
**/*__GENERATED*
2+
**/*__GENERATED__*
33

44
# sed backup files
55
*.*-e

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,26 @@ This is currently the only way to use `@lavamoat/allow-scripts` in monorepos.
1414

1515
### Building
1616

17-
For local development, you should run `yarn build:clean` in the project root directory.
18-
This will always build the packages in the correct order.
17+
Run `yarn build` to build all packages in correct order.
18+
If you encounter any errors, try `yarn build:clean`, and if that fails, check the TypeScript configuration (see below).
1919

20-
You can also run `yarn build` in a workspace, although you have to ensure that the projects are built in the correct order.
20+
You can also run `yarn build` in a specific package / workspace, although you have to ensure that its dependencies have been built.
2121

2222
Repository-wide watching is currently not possible due to the build processes of some packages.
2323

24+
#### Configuring TypeScript
25+
26+
The TypeScript configuration of this monorepo is brittle, and requires manual maintenance.
27+
It uses TypeScript [project references](https://www.typescriptlang.org/docs/handbook/project-references.html) and `composite` sub-projects (i.e. monorepo package).
28+
In short, the [root `tsconfig.json`](./tsconfig.json) must contain an empty `files` array, and `references` to each interdependent project with a `tsconfig.json` in its root directory.
29+
Meanwhile, every sub-project must explicitly declare the relative paths to its local dependencies via its `references` array.
30+
31+
If building from the monorepo root suddenly starts to fail, check if the errors are referring to monorepo packages, and verify that their `tsconfig.json` files are configured correctly.
32+
33+
Some packages do not require a `tsconfig.json` file.
34+
These packages must be explicitly ignored in the [TypeScript config lint script](./scripts/verify-tsconfig.mjs).
35+
If a package is neither referenced nor ignored, linting will fail.
36+
2437
### Testing and Linting
2538

2639
Run `yarn test` and `yarn lint` in the project root directory, or in a workspace.

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
"lint:eslint": "eslint . --cache --ext js,ts",
1818
"lint:misc": "prettier '**/*.json' '**/*.md' '!**/CHANGELOG.md' '**/*.yml' --ignore-path .gitignore",
1919
"lint:changelogs": "yarn workspaces run lint:changelog",
20-
"lint": "yarn lint:eslint && yarn lint:misc --check",
21-
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
22-
"build:tsc": "tsc --build --force tsconfig.json",
23-
"build": "yarn workspaces run build:pre-tsc && yarn build:tsc && yarn workspaces run build:post-tsc",
20+
"lint:tsconfig": "node scripts/verify-tsconfig.mjs",
21+
"lint": "yarn lint:tsconfig && yarn lint:eslint && yarn lint:misc --check",
22+
"lint:fix": "yarn lint:tsconfig && yarn lint:eslint --fix && yarn lint:misc --write",
23+
"build": "yarn build:pre-tsc && yarn build:tsc && yarn build:post-tsc",
2424
"build:clean": "yarn clean && yarn build",
25+
"build:tsc": "tsc --build",
26+
"build:pre-tsc": "yarn workspaces run build:pre-tsc ",
27+
"build:post-tsc": "yarn workspaces run build:post-tsc",
2528
"clean": "yarn workspaces run clean",
2629
"test": "yarn workspaces run test",
2730
"test:ci": "yarn workspaces run test:ci"

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"build:post-tsc": "yarn build:chmod && yarn build:readme",
2727
"build:clean": "yarn clean && yarn build",
2828
"build:watch": "tsc-watch --onSuccess 'yarn build:chmod'",
29-
"clean": "rimraf dist/* src/**/*__GENERATED__*",
29+
"clean": "rimraf *.tsbuildinfo dist/* src/**/*__GENERATED__*",
3030
"test": "yarn build:init-template && jest",
3131
"posttest": "jest-it-up",
3232
"test:watch": "yarn test --watch",

packages/cli/tsconfig.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
{
22
"extends": "../../tsconfig.packages.json",
33
"compilerOptions": {
4-
"composite": true,
5-
"forceConsistentCasingInFileNames": true,
64
"inlineSources": true,
75
"lib": ["DOM", "ES2020"],
8-
"outDir": "dist",
9-
"rootDir": "src",
6+
"outDir": "./dist",
107
"resolveJsonModule": true,
8+
"rootDir": "./src",
119
"skipLibCheck": false,
1210
"typeRoots": [
1311
"../../node_modules/@types",
@@ -16,5 +14,8 @@
1614
]
1715
},
1816
"include": ["./src/**/*.ts", "./src/**/*.json"],
19-
"exclude": ["./src/**/*.test.ts"]
17+
"references": [
18+
{ "path": "../controllers" },
19+
{ "path": "../plugin-browserify" }
20+
]
2021
}

packages/controllers/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
coveragePathIgnorePatterns: ['/node_modules/', '/mocks/', '/test/'],
99
coverageThreshold: {
1010
global: {
11-
branches: 66.67,
11+
branches: 64.44,
1212
functions: 82.11,
1313
lines: 82.17,
1414
statements: 82.23,

packages/controllers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"build:ajv": "./scripts/build-ajv.sh",
2424
"build": "yarn build:pre-tsc && yarn build:tsc",
2525
"build:clean": "yarn clean && yarn build",
26-
"clean": "rimraf dist/*",
26+
"clean": "rimraf *.tsbuildinfo dist/*",
2727
"lint:eslint": "eslint . --cache --ext js,ts",
2828
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path ../../.gitignore",
2929
"lint": "yarn lint:eslint && yarn lint:misc --check",

packages/controllers/tsconfig.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
{
22
"extends": "../../tsconfig.packages.json",
3-
"references": [{ "path": "../execution-environments" }],
43
"compilerOptions": {
54
"allowJs": true,
6-
"composite": true,
75
"lib": ["DOM", "ES2020"],
8-
"outDir": "dist",
6+
"outDir": "./dist",
97
"resolveJsonModule": true,
10-
"rootDir": "src",
8+
"rootDir": "./src",
119
"typeRoots": ["../../node_modules/@types", "./node_modules/@types"]
1210
},
1311
"include": ["./src", "./src/snaps/json-schemas"],
14-
"exclude": ["**/*.test.ts"]
12+
"references": [{ "path": "../execution-environments" }]
1513
}

packages/examples/examples/notifications/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"build:website": "node ./scripts/build-website.js",
1919
"build": "mm-snap build",
2020
"serve": "mm-snap serve",
21-
"clean": "rimraf dist/*",
21+
"clean": "rimraf *.tsbuildinfo dist/*",
2222
"test": "echo 'TODO'",
2323
"lint:eslint": "eslint . --cache --ext js,ts",
2424
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path .gitignore",

packages/execution-environments/jest.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ module.exports = {
66
coverageReporters: ['clover', 'json', 'lcov', 'text', 'json-summary'],
77
coverageThreshold: {
88
global: {
9-
branches: 29.82,
9+
branches: 34.69,
1010
functions: 38.89,
11-
lines: 34.87,
12-
statements: 35.47,
11+
lines: 34.62,
12+
statements: 34.98,
1313
},
1414
},
1515
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],

0 commit comments

Comments
 (0)