Skip to content

Commit 68ee1a2

Browse files
committed
DRY-er
1 parent e4ea69c commit 68ee1a2

File tree

28 files changed

+113
-466
lines changed

28 files changed

+113
-466
lines changed

scripts/simplify-nx-configs.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env node
2+
/*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*/
20+
21+
const fs = require('fs');
22+
const path = require('path');
23+
24+
// Minimal project.json that inherits everything from nx.json targetDefaults
25+
const minimalProjectConfig = (name) => ({
26+
name,
27+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
28+
"targets": {
29+
"build": {} // Empty object inherits all defaults from nx.json
30+
}
31+
});
32+
33+
// Find all project.json files
34+
const packagesDir = path.join(__dirname, '..', 'superset-frontend', 'packages');
35+
const pluginsDir = path.join(__dirname, '..', 'superset-frontend', 'plugins');
36+
37+
function updateProjectJson(dir) {
38+
const items = fs.readdirSync(dir);
39+
items.forEach(item => {
40+
const itemPath = path.join(dir, item);
41+
const projectJsonPath = path.join(itemPath, 'project.json');
42+
43+
if (fs.existsSync(projectJsonPath)) {
44+
const projectName = item;
45+
const minimalConfig = minimalProjectConfig(projectName);
46+
47+
fs.writeFileSync(
48+
projectJsonPath,
49+
JSON.stringify(minimalConfig, null, 2) + '\n'
50+
);
51+
console.log(`✓ Simplified ${projectJsonPath}`);
52+
}
53+
});
54+
}
55+
56+
console.log('Simplifying Nx project.json files to use targetDefaults from nx.json...\n');
57+
58+
updateProjectJson(packagesDir);
59+
updateProjectJson(pluginsDir);
60+
61+
console.log('\n✅ All project.json files have been simplified!');
62+
console.log('The common configuration now lives in nx.json targetDefaults.');

superset-frontend/PR_DESCRIPTION.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ This PR revolutionizes Superset's frontend build system by combining Bun's fast
77
- **10-20x faster typical builds** (only rebuild what changed)
88
- **25% faster full builds** with Bun optimizations
99
- **Local caching** - no cloud dependencies
10+
- **Fixed TypeScript error reporting** that was silently failing
11+
- **DRY configuration** - reduced 325+ lines of repetitive config
1012

1113
## Key Changes
1214

@@ -34,6 +36,12 @@ This PR revolutionizes Superset's frontend build system by combining Bun's fast
3436
- All new scripts include proper ASF headers
3537
- Prevents commits with missing license headers
3638

39+
### 5. DRY Configuration with Nx
40+
- Moved all repetitive build configuration to `nx.json` `targetDefaults`
41+
- Reduced each `project.json` from 20 lines to just 7 lines
42+
- Eliminated ~325 lines of duplicate configuration
43+
- Single source of truth for build settings
44+
3745
## Performance Results
3846

3947
### Real-World Benchmarks
@@ -86,28 +94,35 @@ npx nx affected:build --dry-run
8694

8795
#### Core Build System
8896
- `package.json` - Added Nx dependency, updated `plugins:build` to use Nx
89-
- `nx.json` - Nx configuration (caching rules, build pipeline)
90-
- `scripts/build-package-nx.sh` - Build script for individual packages
97+
- `nx.json` - Nx configuration with centralized `targetDefaults` for DRY principles
98+
- `scripts/build-package-nx.sh` - Build script for individual packages with parallel Babel compilation
9199
- `scripts/clean-packages.js` - Simplified clean script with Nx cache reset
92-
- `scripts/tsc.sh` - Fixed critical bug in TypeScript error handling
100+
- `scripts/tsc.sh` - Fixed critical bug in TypeScript error handling (exit codes now properly captured)
101+
- `scripts/simplify-nx-configs.js` - Script to reduce repetition in project.json files
93102

94103
#### License Compliance
95-
- `scripts/check_license_pre_commit.sh` - Fast license header checker for changed files
104+
- `scripts/check_license_pre_commit.sh` - Fast license header checker for changed files only
96105
- `.pre-commit-config.yaml` - Added license-check hook
97106

98107
#### Package Configurations (all 25 packages)
99-
- `project.json` - Nx project configuration for each package
108+
- `project.json` - Minimal Nx configuration (7 lines each, inheriting from nx.json)
100109
- `package.json` - Added `build:nx` script for Nx builds
101110

111+
#### Repository Cleanup
112+
- `.gitignore` - Added `.nx/` cache directory exclusion
113+
- Removed all unnecessary cache/workspace files from git tracking
114+
102115
## Testing
103116

104117
✅ All 25 packages build successfully
105118
✅ Cache properly invalidates on file changes
106-
✅ TypeScript errors are now properly reported
119+
✅ TypeScript errors are now properly reported (fixed tsc.sh bug)
107120
✅ Build outputs identical to previous system
108121
✅ CI/CD compatible (no external dependencies)
109122
✅ License headers verified on all new files
110123
✅ Pre-commit hooks installed and working
124+
✅ DRY configuration tested - builds work with minimal project.json files
125+
✅ Repository clean - no cache files in git
111126

112127
## Migration Notes
113128

superset-frontend/nx.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
},
1313
"targetDefaults": {
1414
"build": {
15+
"executor": "nx:run-script",
16+
"options": {
17+
"script": "build:nx"
18+
},
19+
"cache": true,
1520
"dependsOn": ["^build"],
1621
"inputs": ["production", "^production"],
1722
"outputs": [

superset-frontend/packages/generator-superset/project.json

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,6 @@
22
"name": "generator-superset",
33
"$schema": "../../node_modules/nx/schemas/project-schema.json",
44
"targets": {
5-
"build": {
6-
"executor": "nx:run-script",
7-
"options": {
8-
"script": "build:nx"
9-
},
10-
"cache": true,
11-
"dependsOn": [
12-
"^build"
13-
],
14-
"inputs": [
15-
"production"
16-
],
17-
"outputs": [
18-
"{projectRoot}/lib",
19-
"{projectRoot}/esm",
20-
"{projectRoot}/types",
21-
"{projectRoot}/tsconfig.tsbuildinfo"
22-
]
23-
}
5+
"build": {}
246
}
257
}

superset-frontend/packages/superset-core/project.json

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,6 @@
22
"name": "superset-core",
33
"$schema": "../../node_modules/nx/schemas/project-schema.json",
44
"targets": {
5-
"build": {
6-
"executor": "nx:run-script",
7-
"options": {
8-
"script": "build:nx"
9-
},
10-
"cache": true,
11-
"dependsOn": [
12-
"^build"
13-
],
14-
"inputs": [
15-
"production"
16-
],
17-
"outputs": [
18-
"{projectRoot}/lib",
19-
"{projectRoot}/esm",
20-
"{projectRoot}/types",
21-
"{projectRoot}/tsconfig.tsbuildinfo"
22-
]
23-
}
5+
"build": {}
246
}
257
}

superset-frontend/packages/superset-ui-chart-controls/project.json

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,6 @@
22
"name": "superset-ui-chart-controls",
33
"$schema": "../../node_modules/nx/schemas/project-schema.json",
44
"targets": {
5-
"build": {
6-
"executor": "nx:run-script",
7-
"options": {
8-
"script": "build:nx"
9-
},
10-
"cache": true,
11-
"dependsOn": [
12-
"^build"
13-
],
14-
"inputs": [
15-
"production"
16-
],
17-
"outputs": [
18-
"{projectRoot}/lib",
19-
"{projectRoot}/esm",
20-
"{projectRoot}/types",
21-
"{projectRoot}/tsconfig.tsbuildinfo"
22-
]
23-
}
5+
"build": {}
246
}
257
}

superset-frontend/packages/superset-ui-core/project.json

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,6 @@
22
"name": "superset-ui-core",
33
"$schema": "../../node_modules/nx/schemas/project-schema.json",
44
"targets": {
5-
"build": {
6-
"executor": "nx:run-script",
7-
"options": {
8-
"script": "build:nx"
9-
},
10-
"cache": true,
11-
"dependsOn": [],
12-
"inputs": ["production"],
13-
"outputs": [
14-
"{projectRoot}/lib",
15-
"{projectRoot}/esm",
16-
"{projectRoot}/types"
17-
]
18-
}
5+
"build": {}
196
}
207
}

superset-frontend/packages/superset-ui-demo/project.json

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,6 @@
22
"name": "superset-ui-demo",
33
"$schema": "../../node_modules/nx/schemas/project-schema.json",
44
"targets": {
5-
"build": {
6-
"executor": "nx:run-script",
7-
"options": {
8-
"script": "build:nx"
9-
},
10-
"cache": true,
11-
"dependsOn": [
12-
"^build"
13-
],
14-
"inputs": [
15-
"production"
16-
],
17-
"outputs": [
18-
"{projectRoot}/lib",
19-
"{projectRoot}/esm",
20-
"{projectRoot}/types",
21-
"{projectRoot}/tsconfig.tsbuildinfo"
22-
]
23-
}
5+
"build": {}
246
}
257
}

superset-frontend/packages/superset-ui-switchboard/project.json

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,6 @@
22
"name": "superset-ui-switchboard",
33
"$schema": "../../node_modules/nx/schemas/project-schema.json",
44
"targets": {
5-
"build": {
6-
"executor": "nx:run-script",
7-
"options": {
8-
"script": "build:nx"
9-
},
10-
"cache": true,
11-
"dependsOn": [
12-
"^build"
13-
],
14-
"inputs": [
15-
"production"
16-
],
17-
"outputs": [
18-
"{projectRoot}/lib",
19-
"{projectRoot}/esm",
20-
"{projectRoot}/types",
21-
"{projectRoot}/tsconfig.tsbuildinfo"
22-
]
23-
}
5+
"build": {}
246
}
257
}

superset-frontend/plugins/legacy-plugin-chart-calendar/project.json

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,6 @@
22
"name": "legacy-plugin-chart-calendar",
33
"$schema": "../../node_modules/nx/schemas/project-schema.json",
44
"targets": {
5-
"build": {
6-
"executor": "nx:run-script",
7-
"options": {
8-
"script": "build:nx"
9-
},
10-
"cache": true,
11-
"dependsOn": [
12-
"^build"
13-
],
14-
"inputs": [
15-
"production"
16-
],
17-
"outputs": [
18-
"{projectRoot}/lib",
19-
"{projectRoot}/esm",
20-
"{projectRoot}/types",
21-
"{projectRoot}/tsconfig.tsbuildinfo"
22-
]
23-
}
5+
"build": {}
246
}
257
}

0 commit comments

Comments
 (0)