Skip to content

Commit efad4af

Browse files
arbrandesclaude
andcommitted
feat: support npm workspaces for local development
Add workspaces configuration and workspace-aware scripts for developing with local packages (such as frontend-base). Decouple clean from build in the Makefile so watch mode can rebuild without wiping dist/. Part of openedx/frontend-base#184 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d63d9b7 commit efad4af

5 files changed

Lines changed: 65 additions & 4 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ npm-debug.log
33
coverage
44
module.config.js
55
dist/
6+
packages/
7+
/.turbo
8+
/turbo.json
69
/*.tgz
710

811
### i18n ###

Makefile

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ transifex_input = $(i18n)/transifex_input.json
1010
# This directory must match .babelrc .
1111
transifex_temp = ./temp/babel-plugin-formatjs
1212

13+
TURBO = TURBO_TELEMETRY_DISABLED=1 turbo --dangerously-disable-package-manager-check
14+
1315
NPM_TESTS=build i18n_extract lint test
1416

1517
.PHONY: test
@@ -24,10 +26,27 @@ test.npm.%: validate-no-uncommitted-package-lock-changes
2426
requirements: ## install ci requirements
2527
npm ci
2628

29+
# turbo.site.json is the standalone turbo config for this package. It is
30+
# renamed to avoid conflicts with turbo v2's workspace validation, which
31+
# rejects root task syntax (//#) and requires "extends" in package-level
32+
# turbo.json files, such as when running in a site repository. The targets
33+
# below copy it into place before running turbo and clean up after.
34+
turbo.json: turbo.site.json
35+
cp $< $@
36+
37+
build-packages: turbo.json
38+
$(TURBO) run build; rm -f turbo.json
39+
40+
clean-packages: turbo.json
41+
$(TURBO) run clean; rm -f turbo.json
42+
43+
dev-packages: turbo.json
44+
$(TURBO) run watch:build dev:site; rm -f turbo.json
45+
2746
clean:
2847
rm -rf dist
2948

30-
build: clean
49+
build:
3150
tsc --project tsconfig.build.json
3251
tsc-alias -p tsconfig.build.json
3352
find src -type f \( -name '*.scss' -o -name '*.png' -o -name '*.svg' \) -exec sh -c '\

nodemon.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"watch": [
3+
"src"
4+
],
5+
"ext": "js,jsx,ts,tsx,scss,png,svg"
6+
}

package.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"files": [
1414
"/dist"
1515
],
16+
"workspaces": [
17+
"packages/*"
18+
],
1619
"browserslist": [
1720
"extends @edx/browserslist-config"
1821
],
@@ -22,13 +25,18 @@
2225
],
2326
"scripts": {
2427
"build": "make build",
28+
"build:packages": "make build-packages",
2529
"clean": "make clean",
30+
"clean:packages": "make clean-packages",
2631
"dev": "PORT=1996 PUBLIC_PATH=/learner-dashboard openedx dev",
32+
"dev:site": "npm run dev",
33+
"dev:packages": "make dev-packages",
2734
"i18n_extract": "openedx formatjs extract",
2835
"lint": "openedx lint .",
2936
"lint:fix": "openedx lint --fix .",
30-
"prepack": "npm run build",
31-
"test": "openedx test --coverage --passWithNoTests"
37+
"prepack": "npm run clean && npm run build",
38+
"test": "openedx test --coverage --passWithNoTests",
39+
"watch:build": "nodemon --exec 'npm run build'"
3240
},
3341
"author": "Open edX",
3442
"license": "AGPL-3.0",
@@ -69,10 +77,12 @@
6977
"jest-environment-jsdom": "^29.7.0",
7078
"jest-expect-message": "^1.1.3",
7179
"jest-when": "^3.6.0",
80+
"nodemon": "^3",
7281
"react-dev-utils": "^12.0.0",
7382
"react-test-renderer": "^18.3.1",
7483
"redux-mock-store": "^1.5.4",
75-
"tsc-alias": "^1.8.16"
84+
"tsc-alias": "^1.8.16",
85+
"turbo": "^2.8.16"
7686
},
7787
"peerDependencies": {
7888
"@openedx/frontend-base": "^1.0.0-alpha.13",

turbo.site.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "https://turbo.build/schema.json",
3+
"tasks": {
4+
"build": {
5+
"dependsOn": ["^build"],
6+
"outputs": ["dist/**"],
7+
"cache": false
8+
},
9+
"clean": {
10+
"cache": false
11+
},
12+
"watch:build": {
13+
"dependsOn": ["^build"],
14+
"persistent": true,
15+
"cache": false
16+
},
17+
"//#dev:site": {
18+
"dependsOn": ["^build"],
19+
"persistent": true,
20+
"cache": false
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)