Skip to content

Commit 16dd65c

Browse files
authored
Update chokidar (#464)
* 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 d2a7b31 commit 16dd65c

File tree

6 files changed

+87
-107
lines changed

6 files changed

+87
-107
lines changed

build/lib/copyAndWatch.js

+2-1
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

+18-3
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,32 @@ import { mkdirSync } from 'fs';
33

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

6-
spawn('npm', ['run', 'watch'], {
6+
const spawns = new Set();
7+
8+
function spawnAndCheck(cmd, args, options) {
9+
const s = spawn(cmd, args, options);
10+
spawns.add(s);
11+
s.on('close', (code) => {
12+
spawns.delete(s);
13+
if (code !== 0) {
14+
console.error(cmd, 'exited with code:', code);
15+
[...spawns].forEach((s) => s.kill());
16+
process.exit(code);
17+
}
18+
});
19+
}
20+
21+
spawnAndCheck('npm', ['run', 'watch'], {
722
shell: true,
823
stdio: 'inherit',
924
});
1025

11-
spawn('node', ['build/tools/copy.js', '1'], {
26+
spawnAndCheck('node', ['build/tools/copy.js', '1'], {
1227
shell: true,
1328
stdio: 'inherit',
1429
});
1530

16-
spawn('npm', ['run', 'server'], {
31+
spawnAndCheck('npm', ['run', 'server'], {
1732
shell: true,
1833
stdio: 'inherit',
1934
});

package-lock.json

+58-101
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
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

+6
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

+1
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)