From 0bd6410d9f06a5286c9af381e83598c0edf5de46 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 12 May 2023 16:41:40 +0100 Subject: [PATCH] avoid lazy race conditions (#1364) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We had a few issues with lazy race conditions failing CI. This came from scripts configured to invoke lazy again, rather than through expressing dependencies between scripts. This diff reconfigures lazy to articulate these sorts of things as dependencies instead of through self-invocation. Instead of having lots of separate `build-package`, `build-docs`, etc commands, we now just have a build command with package overrides to express more specific options ### Change Type - [x] `internal` — Any other changes that don't affect the published package (will not publish a new version) ### Release Notes [internal only] --- .github/workflows/checks.yml | 6 ++-- apps/docs/package.json | 6 ++-- apps/vscode/editor/package.json | 1 - apps/webdriver/package.json | 2 +- lazy.config.ts | 45 ++++++++++++++--------------- package.json | 6 ++-- packages/editor/package.json | 3 +- packages/file-format/package.json | 2 +- packages/polyfills/package.json | 2 +- packages/primitives/package.json | 2 +- packages/tldraw/package.json | 3 +- packages/tlschema/package.json | 2 +- packages/tlstore/package.json | 2 +- packages/tlsync-client/package.json | 2 +- packages/tlvalidate/package.json | 2 +- packages/ui/package.json | 2 +- packages/utils/package.json | 2 +- scripts/check-scripts.ts | 4 +-- scripts/prepack.ts | 2 +- 19 files changed, 44 insertions(+), 52 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 692b62272..1d51651ab 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -49,13 +49,13 @@ jobs: - name: Check API declarations and docs work as intended run: yarn api-check - - name: Pack public packages - run: "yarn lazy pack-tarball | sed -E 's/^.*? ::/::/'" - - name: Build all projects # the sed pipe makes sure that github annotations come through without # turbo's prefix run: "yarn build | sed -E 's/^.*? ::/::/'" + - name: Pack public packages + run: "yarn lazy pack-tarball | sed -E 's/^.*? ::/::/'" + - name: Test run: yarn test diff --git a/apps/docs/package.json b/apps/docs/package.json index 71c1ac8de..2c4a42482 100644 --- a/apps/docs/package.json +++ b/apps/docs/package.json @@ -27,10 +27,8 @@ "infinite" ], "scripts": { - "dev": "lazy dev-docs", - "dev-docs": "next dev", - "build": "lazy build-docs", - "build-docs": "next build", + "dev": "next dev", + "build": "next build", "start": "next start", "lint": "yarn run -T tsx ../../scripts/lint.ts", "docs-content": "ts-node --project tsconfig.content.json ./scripts/index.ts", diff --git a/apps/vscode/editor/package.json b/apps/vscode/editor/package.json index 32c1b2405..109c03f6d 100644 --- a/apps/vscode/editor/package.json +++ b/apps/vscode/editor/package.json @@ -28,7 +28,6 @@ ], "scripts": { "build": "yarn run -T tsx scripts/build.ts", - "build:vscode-editor": "yarn run -T tsx scripts/build.ts", "dev": "yarn run -T tsx scripts/dev.ts", "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist", "lint": "yarn run -T tsx ../../../scripts/lint.ts" diff --git a/apps/webdriver/package.json b/apps/webdriver/package.json index d8259b86d..12013a465 100755 --- a/apps/webdriver/package.json +++ b/apps/webdriver/package.json @@ -25,7 +25,7 @@ "infinite" ], "scripts": { - "dev-webdriver": "concurrently --names \"tsc,esbuild\" \"yarn run -T tsx ../../scripts/typecheck.ts --build --watch --preserveWatchOutput\" \"node ./scripts/dev.mjs\"", + "dev": "concurrently --names \"tsc,esbuild\" \"yarn run -T tsx ../../scripts/typecheck.ts --build --watch --preserveWatchOutput\" \"node ./scripts/dev.mjs\"", "lint": "yarn run -T tsx ../../scripts/lint.ts" }, "devDependencies": { diff --git a/lazy.config.ts b/lazy.config.ts index a31ea5df2..abb3d47b3 100644 --- a/lazy.config.ts +++ b/lazy.config.ts @@ -3,23 +3,31 @@ import { LazyConfig } from 'lazyrepo' export function generateSharedScripts(bublic: '' | '/bublic') { return { build: { - runsAfter: { 'build-package': {}, prebuild: {} }, - }, - 'build:vscode-editor': { - runsAfter: { 'refresh-assets': {} }, + baseCommand: 'exit 0', + runsAfter: { prebuild: {}, 'refresh-assets': {} }, + workspaceOverrides: { + '{bublic/,}apps/docs': { runsAfter: { 'docs-content': {} } }, + '{bublic/,}apps/vscode/*': { runsAfter: { 'refresh-assets': {} } }, + '{bublic/,}packages/*': { + runsAfter: { 'build-api': { in: 'self-only' }, prebuild: { in: 'self-only' } }, + cache: { + inputs: ['api/**/*', 'src/**/*'], + }, + }, + }, }, dev: { execution: 'independent', runsAfter: { 'refresh-assets': {} }, cache: 'none', - }, - 'dev-vscode': { - runsAfter: { 'build:vscode-editor': {} }, - }, - 'dev-webdriver': { - execution: 'independent', - runsAfter: { 'refresh-assets': {}, prebuild: {}, 'build:vscode-editor': {} }, - cache: 'none', + workspaceOverrides: { + '{bublic/,}apps/docs': { runsAfter: { 'docs-content': { in: 'self-only' } } }, + '{bublic/,}apps/vscode/*': { runsAfter: { build: { in: 'self-only' } } }, + '{bublic/,}apps/webdriver': { + runsAfter: { 'refresh-assets': {}, prebuild: {} }, + cache: 'none', + }, + }, }, test: { baseCommand: 'yarn run -T jest', @@ -27,6 +35,7 @@ export function generateSharedScripts(bublic: '' | '/bublic') }, 'test-coverage': { baseCommand: 'yarn run -T jest --coverage', + runsAfter: { 'refresh-assets': {} }, }, lint: { execution: 'independent', @@ -37,12 +46,6 @@ export function generateSharedScripts(bublic: '' | '/bublic') }, }, }, - 'build-package': { - runsAfter: { 'build-api': {}, prebuild: {} }, - cache: { - inputs: ['api/**/*', 'src/**/*'], - }, - }, 'pack-tarball': { parallel: false, }, @@ -84,12 +87,6 @@ export function generateSharedScripts(bublic: '' | '/bublic') }, }, }, - 'build-docs': { - runsAfter: { 'docs-content': {} }, - }, - 'dev-docs': { - runsAfter: { 'docs-content': {} }, - }, 'docs-content': { runsAfter: { 'build-api': {} }, cache: { diff --git a/package.json b/package.json index 30c05d0d4..d7956a321 100644 --- a/package.json +++ b/package.json @@ -37,11 +37,11 @@ "postinstall": "husky install && yarn refresh-assets", "refresh-assets": "lazy refresh-assets", "build": "lazy build", - "build-docs": "lazy build-docs", + "build-docs": "lazy build --filter='apps/docs'", "dev": "lazy run dev --filter='{,bublic/}apps/examples' --filter='{,bublic/}packages/tldraw'", - "dev-docs": "lazy run dev-docs", + "dev-docs": "lazy run dev --filter='apps/docs'", "dev-vscode": "code ./apps/vscode/extension && lazy run dev --filter='{,bublic/}apps/vscode/{extension,editor}'", - "dev-webdriver": "lazy run dev-webdriver --filter='apps/webdriver'", + "dev-webdriver": "lazy run dev --filter='apps/webdriver' --filter='{,bublic/}apps/vscode/*'", "build-types": "lazy inherit", "build-api": "lazy build-api", "build-package": "lazy build-package", diff --git a/packages/editor/package.json b/packages/editor/package.json index a6ca26ed7..fb1d1c614 100644 --- a/packages/editor/package.json +++ b/packages/editor/package.json @@ -37,8 +37,7 @@ "test": "lazy inherit", "benchmark": "yarn run -T tsx ./scripts/benchmark.ts", "test-coverage": "lazy inherit", - "build": "lazy build-package", - "build-package": "yarn run -T tsx ../../scripts/build-package.ts", + "build": "yarn run -T tsx ../../scripts/build-package.ts", "build-api": "yarn run -T tsx ../../scripts/build-api.ts", "prepack": "yarn run -T tsx ../../scripts/prepack.ts", "postpack": "../../scripts/postpack.sh", diff --git a/packages/file-format/package.json b/packages/file-format/package.json index dc34d8983..c5e64e9e1 100644 --- a/packages/file-format/package.json +++ b/packages/file-format/package.json @@ -33,7 +33,7 @@ "scripts": { "test": "lazy inherit", "test-coverage": "lazy inherit", - "build-package": "yarn run -T tsx ../../scripts/build-package.ts", + "build": "yarn run -T tsx ../../scripts/build-package.ts", "build-api": "yarn run -T tsx ../../scripts/build-api.ts", "prepack": "yarn run -T tsx ../../scripts/prepack.ts", "postpack": "../../scripts/postpack.sh", diff --git a/packages/polyfills/package.json b/packages/polyfills/package.json index b678dc800..85b2654ab 100644 --- a/packages/polyfills/package.json +++ b/packages/polyfills/package.json @@ -31,7 +31,7 @@ "/* GOTCHA */": "files will include ./dist and index.d.ts by default, add any others you want to include in here", "files": [], "scripts": { - "build-package": "yarn run -T tsx ../../scripts/build-package.ts", + "build": "yarn run -T tsx ../../scripts/build-package.ts", "build-api": "yarn run -T tsx ../../scripts/build-api.ts", "prepack": "yarn run -T tsx ../../scripts/prepack.ts", "postpack": "../../scripts/postpack.sh", diff --git a/packages/primitives/package.json b/packages/primitives/package.json index 21f904c4e..e4723b432 100644 --- a/packages/primitives/package.json +++ b/packages/primitives/package.json @@ -33,7 +33,7 @@ "scripts": { "test": "lazy inherit", "test-coverage": "lazy inherit", - "build-package": "yarn run -T tsx ../../scripts/build-package.ts", + "build": "yarn run -T tsx ../../scripts/build-package.ts", "build-api": "yarn run -T tsx ../../scripts/build-api.ts", "prepack": "yarn run -T tsx ../../scripts/prepack.ts", "postpack": "../../scripts/postpack.sh", diff --git a/packages/tldraw/package.json b/packages/tldraw/package.json index eaeb9f049..932a1e877 100644 --- a/packages/tldraw/package.json +++ b/packages/tldraw/package.json @@ -33,8 +33,7 @@ "test-coverage": "lazy inherit", "dev": "chokidar '../{editor,ui}/*.css' -c 'node ./scripts/copy-css-files.mjs' --initial", "prebuild": "node ./scripts/copy-css-files.mjs", - "build": "node ./scripts/copy-css-files.mjs", - "build-package": "yarn run -T tsx ../../scripts/build-package.ts", + "build": "yarn run -T tsx ../../scripts/build-package.ts", "build-api": "yarn run -T tsx ../../scripts/build-api.ts", "prepack": "yarn run -T tsx ../../scripts/prepack.ts", "postpack": "../../scripts/postpack.sh", diff --git a/packages/tlschema/package.json b/packages/tlschema/package.json index de6be484c..4173111a9 100644 --- a/packages/tlschema/package.json +++ b/packages/tlschema/package.json @@ -38,7 +38,7 @@ "new-asset": "node ./scripts/new-asset.js", "index": "node ./scripts/build-index.js && yarn format", "format": "yarn run -T prettier --write \"src/**/*.{ts,tsx,js,jsx,json,md}\"", - "build-package": "yarn run -T tsx ../../scripts/build-package.ts", + "build": "yarn run -T tsx ../../scripts/build-package.ts", "build-api": "yarn run -T tsx ../../scripts/build-api.ts", "prepack": "yarn run -T tsx ../../scripts/prepack.ts", "postpack": "../../scripts/postpack.sh", diff --git a/packages/tlstore/package.json b/packages/tlstore/package.json index 25e2820de..b9ab64c50 100644 --- a/packages/tlstore/package.json +++ b/packages/tlstore/package.json @@ -33,7 +33,7 @@ "scripts": { "test": "lazy inherit", "test-coverage": "lazy inherit", - "build-package": "yarn run -T tsx ../../scripts/build-package.ts", + "build": "yarn run -T tsx ../../scripts/build-package.ts", "build-api": "yarn run -T tsx ../../scripts/build-api.ts", "prepack": "yarn run -T tsx ../../scripts/prepack.ts", "postpack": "../../scripts/postpack.sh", diff --git a/packages/tlsync-client/package.json b/packages/tlsync-client/package.json index 5862b2fa0..579a6ec55 100644 --- a/packages/tlsync-client/package.json +++ b/packages/tlsync-client/package.json @@ -33,7 +33,7 @@ "scripts": { "test": "lazy inherit", "test-coverage": "lazy inherit", - "build-package": "yarn run -T tsx ../../scripts/build-package.ts", + "build": "yarn run -T tsx ../../scripts/build-package.ts", "build-api": "yarn run -T tsx ../../scripts/build-api.ts", "prepack": "yarn run -T tsx ../../scripts/prepack.ts", "postpack": "../../scripts/postpack.sh", diff --git a/packages/tlvalidate/package.json b/packages/tlvalidate/package.json index 032af844a..87ab5a576 100644 --- a/packages/tlvalidate/package.json +++ b/packages/tlvalidate/package.json @@ -33,7 +33,7 @@ "scripts": { "test": "lazy inherit", "test-coverage": "lazy inherit", - "build-package": "yarn run -T tsx ../../scripts/build-package.ts", + "build": "yarn run -T tsx ../../scripts/build-package.ts", "build-api": "yarn run -T tsx ../../scripts/build-api.ts", "prepack": "yarn run -T tsx ../../scripts/prepack.ts", "postpack": "../../scripts/postpack.sh", diff --git a/packages/ui/package.json b/packages/ui/package.json index bb8da17bc..e6537c4ab 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -36,7 +36,7 @@ "scripts": { "test": "lazy inherit --passWithNoTests", "test-coverage": "yarn run -T jest --passWithNoTests --coverage", - "build-package": "yarn run -T tsx ../../scripts/build-package.ts", + "build": "yarn run -T tsx ../../scripts/build-package.ts", "build-api": "yarn run -T tsx ../../scripts/build-api.ts", "prepack": "yarn run -T tsx ../../scripts/prepack.ts", "postpack": "../../scripts/postpack.sh", diff --git a/packages/utils/package.json b/packages/utils/package.json index 5e76a782a..26a66e728 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -33,7 +33,7 @@ "scripts": { "test": "lazy inherit", "test-coverage": "lazy inherit", - "build-package": "yarn run -T tsx ../../scripts/build-package.ts", + "build": "yarn run -T tsx ../../scripts/build-package.ts", "build-api": "yarn run -T tsx ../../scripts/build-api.ts", "prepack": "yarn run -T tsx ../../scripts/prepack.ts", "postpack": "../../scripts/postpack.sh", diff --git a/scripts/check-scripts.ts b/scripts/check-scripts.ts index 802fe3b8a..cd38fe570 100644 --- a/scripts/check-scripts.ts +++ b/scripts/check-scripts.ts @@ -25,7 +25,7 @@ const expectedPackageScripts = { // published packages should have these scripts const expectedPublishedPackageScripts = { ...expectedPackageScripts, - 'build-package': tsScript('build-package.ts'), + build: tsScript('build-package.ts'), 'build-api': tsScript('build-api.ts'), prepack: tsScript('prepack.ts'), postpack: (packageDir: string) => scriptPath(packageDir, 'postpack.sh'), @@ -57,7 +57,7 @@ const perPackageExceptions: Record string | undefin }, '@tldraw/assets': { test: () => undefined, - 'build-package': () => undefined, + build: () => undefined, 'build-api': () => undefined, prepack: () => undefined, postpack: () => undefined, diff --git a/scripts/prepack.ts b/scripts/prepack.ts index efe0170cc..8c1b49232 100644 --- a/scripts/prepack.ts +++ b/scripts/prepack.ts @@ -12,7 +12,7 @@ export async function preparePackage({ sourcePackageDir }: { sourcePackageDir: s const manifest = JSON.parse(readFileSync(path.join(sourcePackageDir, 'package.json'), 'utf8')) - execSync('yarn run -T lazy build-package', { cwd: sourcePackageDir, stdio: 'inherit' }) + execSync('yarn run -T lazy build', { cwd: sourcePackageDir, stdio: 'inherit' }) // save package.json and reinstate it in postpack copyFileSync(