diff --git a/crates/oxide/src/scanner/mod.rs b/crates/oxide/src/scanner/mod.rs index b7da9aa17..2af2bf3db 100644 --- a/crates/oxide/src/scanner/mod.rs +++ b/crates/oxide/src/scanner/mod.rs @@ -382,9 +382,10 @@ impl Scanner { return (vec![], vec![], vec![]); }; - // Use synchronous walk for the initial build (lower overhead) and parallel - // walk for subsequent calls (watch mode) where the overhead is amortised. - let all_entries = if self.has_scanned_once { + // Use synchronous walk for the initial build (lower overhead). On supported + // platforms, use the parallel walk for subsequent calls where the overhead + // is amortised. + let all_entries = if self.has_scanned_once && cfg!(any(unix, windows)) { walk_parallel(walker) } else { walk_synchronous(walker) diff --git a/integrations/oxide/wasm.test.ts b/integrations/oxide/wasm.test.ts index 2d63c707a..4495d83ac 100644 --- a/integrations/oxide/wasm.test.ts +++ b/integrations/oxide/wasm.test.ts @@ -58,6 +58,83 @@ testFn( }, ) +testFn( + '@tailwindcss/oxide-wasm32-wasi discovers changes across incremental scans', + { + fs: { + 'package.json': json` + { + "dependencies": { + "@tailwindcss/oxide-wasm32-wasi": "workspace:^" + } + } + `, + 'src/index.js': js`const className = 'flex'`, + 'index.mjs': js` + import { Scanner } from '@tailwindcss/oxide-wasm32-wasi' + import { readFileSync, statSync, utimesSync, writeFileSync } from 'node:fs' + import { join, relative } from 'node:path' + + let source = join(process.cwd(), 'src/index.js') + let scanner = new Scanner({ + sources: [ + { + base: join(process.cwd(), 'src'), + pattern: '**/*', + negated: false, + }, + ], + }) + + function scan() { + let candidates = scanner.scan() + + return { + candidates: candidates.filter( + (candidate) => candidate === 'flex' || candidate === 'grid', + ), + files: scanner.files.map((file) => relative(process.cwd(), file)), + scannedFiles: scanner.scannedFiles.map((file) => relative(process.cwd(), file)), + } + } + + let initial = scan() + let unchanged = scan() + + writeFileSync(source, readFileSync(source, 'utf8').replace('flex', 'grid')) + let mtime = statSync(source).mtime + utimesSync(source, mtime, new Date(mtime.getTime() + 2000)) + + let changed = scan() + + console.log(JSON.stringify({ initial, unchanged, changed })) + process.exit() + `, + }, + }, + async ({ expect, exec }) => { + let output = await exec(`node index.mjs`) + + expect(JSON.parse(output)).toEqual({ + initial: { + candidates: ['flex'], + files: ['src/index.js'], + scannedFiles: ['src/index.js'], + }, + unchanged: { + candidates: ['flex'], + files: ['src/index.js'], + scannedFiles: [], + }, + changed: { + candidates: ['flex', 'grid'], + files: ['src/index.js'], + scannedFiles: ['src/index.js'], + }, + }) + }, +) + testFn( '`@tailwindcss/oxide` falls back to the wasm build when no native binding is available', {