avoid lazy race conditions (#1364)

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]
This commit is contained in:
alex 2023-05-12 16:41:40 +01:00 committed by GitHub
parent 6aa7f9957f
commit 0bd6410d9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 44 additions and 52 deletions

View file

@ -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

View file

@ -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",

View file

@ -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"

View file

@ -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": {

View file

@ -3,30 +3,39 @@ import { LazyConfig } from 'lazyrepo'
export function generateSharedScripts(bublic: '<rootDir>' | '<rootDir>/bublic') {
return {
build: {
runsAfter: { 'build-package': {}, prebuild: {} },
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/**/*'],
},
},
},
'build:vscode-editor': {
runsAfter: { 'refresh-assets': {} },
},
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': {} },
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',
runsAfter: { 'refresh-assets': {} },
},
'test-coverage': {
baseCommand: 'yarn run -T jest --coverage',
runsAfter: { 'refresh-assets': {} },
},
lint: {
execution: 'independent',
@ -37,12 +46,6 @@ export function generateSharedScripts(bublic: '<rootDir>' | '<rootDir>/bublic')
},
},
},
'build-package': {
runsAfter: { 'build-api': {}, prebuild: {} },
cache: {
inputs: ['api/**/*', 'src/**/*'],
},
},
'pack-tarball': {
parallel: false,
},
@ -84,12 +87,6 @@ export function generateSharedScripts(bublic: '<rootDir>' | '<rootDir>/bublic')
},
},
},
'build-docs': {
runsAfter: { 'docs-content': {} },
},
'dev-docs': {
runsAfter: { 'docs-content': {} },
},
'docs-content': {
runsAfter: { 'build-api': {} },
cache: {

View file

@ -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",

View file

@ -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",

View file

@ -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",

View file

@ -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",

View file

@ -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",

View file

@ -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",

View file

@ -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",

View file

@ -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",

View file

@ -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",

View file

@ -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",

View file

@ -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",

View file

@ -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",

View file

@ -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, Record<string, () => string | undefin
},
'@tldraw/assets': {
test: () => undefined,
'build-package': () => undefined,
build: () => undefined,
'build-api': () => undefined,
prepack: () => undefined,
postpack: () => undefined,

View file

@ -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(