Skip to content

Commit de6e7b1

Browse files
authored
Merge pull request #481 from Kaggle/improve-core-watch
Improve build behavior around watching/iterating on web/core
2 parents 95c3a70 + b3c0506 commit de6e7b1

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ temp.*
147147
# node.js files
148148
node_modules
149149
**/node_modules
150+
**/tsconfig.tsbuildinfo
150151

151152
# Java class files
152153
*.class

web/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"scripts": {
2222
"build": "tsc && vite build",
23-
"preview": "vite preview"
23+
"dev": "tsc --build --watch"
2424
},
2525
"devDependencies": {
2626
"typescript": "^5.0.0",

web/core/tsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
{
22
"extends": "../tsconfig.base.json",
3+
"compilerOptions": {
4+
"composite": true,
5+
"declaration": true,
6+
"noEmit": false,
7+
"outDir": "./dist",
8+
"rootDir": "./src"
9+
},
310
"include": ["src"]
411
}

web/scripts/find-games.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,53 @@ if (gameVisualizers.length === 0) {
3333
}
3434

3535
/**
36-
* Runs a command for a single package. Used for 'dev' or building one visualizer at a time.
36+
* Runs a command for a package.
37+
* - For 'dev', it first builds all dependencies, then runs dev servers in parallel.
38+
* - For 'build', it runs the command only for the selected package.
3739
*/
3840
const runCommand = (pkg) => {
3941
const packageName = pkg.name;
4042
const relativePath = path.relative(process.cwd(), pkg.path);
4143

42-
// Clear the screen only for the 'dev' command to mimic Vite's behavior
44+
// Clear the screen only for 'dev' to mimic Vite's behavior
4345
if (command === 'dev') {
4446
console.clear();
4547
}
4648

47-
console.log(`Running "pnpm ${command}" in ${relativePath}...`);
49+
let cmdToRun, cmdArgs, cwd;
4850

49-
const child = spawn('pnpm', [command], {
51+
if (command === 'dev') {
52+
try {
53+
// STEP 1: Build all dependencies of the target package first.
54+
// The `...^` syntax targets all dependencies, but NOT the package itself.
55+
console.log(`[1/2] Building dependencies for ${packageName}...`);
56+
execSync(`pnpm --filter ${packageName}...^ build`, {
57+
stdio: 'inherit',
58+
cwd: process.cwd()
59+
});
60+
console.log(`✅ Dependencies built successfully.`);
61+
} catch (e) {
62+
console.error('\n❌ Initial build of dependencies failed. Aborting.');
63+
process.exit(1);
64+
}
65+
66+
// STEP 2: Now, run the parallel dev/watch commands.
67+
console.log(`\n[2/2] Starting dev servers for ${packageName} and its dependencies...`);
68+
cmdToRun = 'pnpm';
69+
cmdArgs = ['--parallel', '--filter', `${packageName}...`, 'dev'];
70+
cwd = process.cwd(); // Run from the monorepo root
71+
} else {
72+
// For 'build' of a single package, the original logic is fine.
73+
console.log(`Running "pnpm ${command}" in ${relativePath}...`);
74+
cmdToRun = 'pnpm';
75+
cmdArgs = [command];
76+
cwd = pkg.path; // Run inside the specific package directory
77+
}
78+
79+
const child = spawn(cmdToRun, cmdArgs, {
5080
stdio: 'inherit',
51-
shell: true, // Use shell: true to ensure pnpm is found in the path
52-
cwd: pkg.path,
81+
shell: true,
82+
cwd: cwd,
5383
env: {
5484
...process.env,
5585
VITE_CUSTOM_HEADER_NAME: packageName,
@@ -64,7 +94,6 @@ const runCommand = (pkg) => {
6494
child.on('exit', (code) => {
6595
if (code !== 0) {
6696
console.error(`\n'${packageName} ${command}' process exited with code ${code}`);
67-
// Propagate the error code for CI/CD environments
6897
process.exit(code);
6998
}
7099
});

0 commit comments

Comments
 (0)