Skip to content

Commit 664e656

Browse files
committed
Update chokidar to v4
chokidar v3 is no longer supported. v4 requires node 20 so 1. Added a check for v20+ 2. Make script exit if any spawn gets an error. This required watching for processes to exit and killing the other processes. 3. Update to use glob as chokidar v4 no longer does it Also fixed a minor warning in sample/utis.ts
1 parent 4f5bed8 commit 664e656

File tree

6 files changed

+84
-107
lines changed

6 files changed

+84
-107
lines changed

build/lib/copyAndWatch.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import chokidar from 'chokidar';
22
import fs from 'fs';
33
import path from 'path';
4+
import { globSync } from 'glob';
45

56
const debug = console.log; //() => {};
67
const removeLeadingSlash = (s) => s.replace(/^\//, '');
@@ -20,7 +21,7 @@ const removeLeadingSlash = (s) => s.replace(/^\//, '');
2021
*/
2122
export function copyAndWatch(paths, { watch } = { watch: true }) {
2223
for (const { src, srcPrefix, dst } of paths) {
23-
const watcher = chokidar.watch(src, {
24+
const watcher = chokidar.watch(globSync(src), {
2425
ignored: /(^|[\/\\])\../, // ignore dot files
2526
persistent: watch,
2627
});

build/tools/serve.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,29 @@ import { mkdirSync } from 'fs';
33

44
mkdirSync('out', { recursive: true });
55

6-
spawn('npm', ['run', 'watch'], {
6+
const spawns = [];
7+
8+
function spawnAndCheck(cmd, args, options) {
9+
const s = spawn(cmd, args, options);
10+
spawns.push(s);
11+
s.on('close', (code) => {
12+
console.log(cmd, 'exited with code:', code);
13+
spawns.forEach((s) => s.kill());
14+
process.exit(code);
15+
});
16+
}
17+
18+
spawnAndCheck('npm', ['run', 'watch'], {
719
shell: true,
820
stdio: 'inherit',
921
});
1022

11-
spawn('node', ['build/tools/copy.js', '1'], {
23+
spawnAndCheck('node', ['build/tools/copy.js', '1'], {
1224
shell: true,
1325
stdio: 'inherit',
1426
});
1527

16-
spawn('npm', ['run', 'server'], {
28+
spawnAndCheck('npm', ['run', 'server'], {
1729
shell: true,
1830
stdio: 'inherit',
1931
});

package-lock.json

Lines changed: 58 additions & 101 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@
4343
"@types/stats.js": "^0.17.3",
4444
"@typescript-eslint/eslint-plugin": "^7.18.0",
4545
"@webgpu/types": "^0.1.49",
46-
"chokidar": "^3.6.0",
46+
"chokidar": "^4.0.1",
4747
"eslint": "^8.57.1",
4848
"eslint-config-prettier": "^8.10.0",
4949
"eslint-plugin-html": "^8.1.2",
5050
"eslint-plugin-prettier": "^4.2.1",
51-
"glob": "^10.4.5",
51+
"glob": "^11.0.0",
5252
"prettier": "^2.8.8",
5353
"rollup": "^4.24.0",
5454
"rollup-plugin-copy": "^3.5.0",

rollup.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import typescript from '@rollup/plugin-typescript';
55
import commonjs from '@rollup/plugin-commonjs';
66
import { readDirSyncRecursive } from './build/lib/readdir.js';
77

8+
const nodeVersion = parseInt(process.version.substring(1));
9+
if (isNaN(nodeVersion) || nodeVersion < 20) {
10+
console.error('need node >= v20');
11+
process.exit(1);
12+
}
13+
814
const outPath = 'out';
915

1016
function wgslPlugin() {

sample/util.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export function quitIfWebGPUNotAvailable(
2222
if (!device) {
2323
quitIfAdapterNotAvailable(adapter);
2424
fail('Unable to get a device for an unknown reason');
25+
return;
2526
}
2627

2728
device.lost.then((reason) => {

0 commit comments

Comments
 (0)