Skip to content

Commit

Permalink
Update chokidar to v4
Browse files Browse the repository at this point in the history
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
  • Loading branch information
greggman committed Oct 16, 2024
1 parent 4f5bed8 commit 664e656
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 107 deletions.
3 changes: 2 additions & 1 deletion build/lib/copyAndWatch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import chokidar from 'chokidar';
import fs from 'fs';
import path from 'path';
import { globSync } from 'glob';

const debug = console.log; //() => {};
const removeLeadingSlash = (s) => s.replace(/^\//, '');
Expand All @@ -20,7 +21,7 @@ const removeLeadingSlash = (s) => s.replace(/^\//, '');
*/
export function copyAndWatch(paths, { watch } = { watch: true }) {
for (const { src, srcPrefix, dst } of paths) {
const watcher = chokidar.watch(src, {
const watcher = chokidar.watch(globSync(src), {
ignored: /(^|[\/\\])\../, // ignore dot files
persistent: watch,
});
Expand Down
18 changes: 15 additions & 3 deletions build/tools/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,29 @@ import { mkdirSync } from 'fs';

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

spawn('npm', ['run', 'watch'], {
const spawns = [];

function spawnAndCheck(cmd, args, options) {
const s = spawn(cmd, args, options);
spawns.push(s);
s.on('close', (code) => {
console.log(cmd, 'exited with code:', code);
spawns.forEach((s) => s.kill());
process.exit(code);
});
}

spawnAndCheck('npm', ['run', 'watch'], {
shell: true,
stdio: 'inherit',
});

spawn('node', ['build/tools/copy.js', '1'], {
spawnAndCheck('node', ['build/tools/copy.js', '1'], {
shell: true,
stdio: 'inherit',
});

spawn('npm', ['run', 'server'], {
spawnAndCheck('npm', ['run', 'server'], {
shell: true,
stdio: 'inherit',
});
159 changes: 58 additions & 101 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
"@types/stats.js": "^0.17.3",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@webgpu/types": "^0.1.49",
"chokidar": "^3.6.0",
"chokidar": "^4.0.1",
"eslint": "^8.57.1",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-html": "^8.1.2",
"eslint-plugin-prettier": "^4.2.1",
"glob": "^10.4.5",
"glob": "^11.0.0",
"prettier": "^2.8.8",
"rollup": "^4.24.0",
"rollup-plugin-copy": "^3.5.0",
Expand Down
6 changes: 6 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import typescript from '@rollup/plugin-typescript';
import commonjs from '@rollup/plugin-commonjs';
import { readDirSyncRecursive } from './build/lib/readdir.js';

const nodeVersion = parseInt(process.version.substring(1));
if (isNaN(nodeVersion) || nodeVersion < 20) {
console.error('need node >= v20');
process.exit(1);
}

const outPath = 'out';

function wgslPlugin() {
Expand Down
1 change: 1 addition & 0 deletions sample/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function quitIfWebGPUNotAvailable(
if (!device) {
quitIfAdapterNotAvailable(adapter);
fail('Unable to get a device for an unknown reason');
return;
}

device.lost.then((reason) => {
Expand Down

0 comments on commit 664e656

Please sign in to comment.