Skip to content

Commit

Permalink
wip: fix plugin-vue fail
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jul 5, 2023
1 parent 1be6760 commit f385f20
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
},
"//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!",
"dependencies": {
"@parcel/watcher": "^2.2.0",
"@parcel/watcher": "^2.2.1-alpha.0",
"esbuild": "^0.18.10",
"postcss": "^8.4.24",
"rollup": "^3.25.2"
Expand Down
38 changes: 38 additions & 0 deletions packages/vite/src/node/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ export class Watcher {
constructor(private opts: Options) {}

on(eventHandler: WatchEventHandler): void {
if (arguments.length > 1) {
// eslint-disable-next-line prefer-rest-params
eventHandler = handleChokidarArgs(arguments)
}
this.eventHandlers.add(eventHandler)
}

off(eventHandler: WatchEventHandler): void {
if (arguments.length > 1) {
// eslint-disable-next-line prefer-rest-params
eventHandler = handleChokidarArgs(arguments)
}
this.eventHandlers.delete(eventHandler)
}

Expand Down Expand Up @@ -97,3 +105,33 @@ export function resolveWatchOptions(

return resolvedWatchOptions
}

// Temporary code to handle chokidar style events for tests to pass
const createChokidarEvents = ['add', 'addDir']
const updateChokidarEvents = ['change']
const deleteChokidarEvents = ['unlink', 'unlinkDir']
function handleChokidarArgs(args: IArguments): WatchEventHandler {
const [chokidarEvent, chokidarHandler] = args
return (event) => {
switch (event.type) {
case 'create':
if (createChokidarEvents.includes(chokidarEvent)) {
chokidarHandler(event.path)
}
break
case 'update':
if (updateChokidarEvents.includes(chokidarEvent)) {
chokidarHandler(event.path)
}
break
case 'delete':
if (deleteChokidarEvents.includes(chokidarEvent)) {
chokidarHandler(event.path)
}
break
default:
// Unsupported: 'ready', 'raw', 'error'
break
}
}
}
68 changes: 34 additions & 34 deletions pnpm-lock.yaml

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

0 comments on commit f385f20

Please sign in to comment.