-
-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhance] Modify to let the plugin do the build completion detection …
…not file system. (#265)
- Loading branch information
1 parent
560c835
commit dbe8b00
Showing
11 changed files
with
49 additions
and
75 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
import type { PluginOption } from 'vite'; | ||
import { resolve } from 'path'; | ||
import { WebSocket } from 'ws'; | ||
import MessageInterpreter from '../reload/interpreter'; | ||
import { LOCAL_RELOAD_SOCKET_URL } from '../reload/constant'; | ||
|
||
const rootDir = resolve(__dirname, '..', '..'); | ||
const manifestFile = resolve(rootDir, 'manifest.ts'); | ||
const viteConfigFile = resolve(rootDir, 'vite.config.ts'); | ||
|
||
export default function watchRebuild(): PluginOption { | ||
const ws = new WebSocket(LOCAL_RELOAD_SOCKET_URL); | ||
return { | ||
name: 'watch-rebuild', | ||
async buildStart() { | ||
buildStart() { | ||
this.addWatchFile(manifestFile); | ||
this.addWatchFile(viteConfigFile); | ||
}, | ||
writeBundle() { | ||
/** | ||
* When the build is complete, send a message to the reload server. | ||
* The reload server will send a message to the client to reload or refresh the extension. | ||
*/ | ||
ws.send(MessageInterpreter.send({ type: 'build_complete' })); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
export const LOCAL_RELOAD_SOCKET_PORT = 8081; | ||
export const LOCAL_RELOAD_SOCKET_URL = `ws://localhost:${LOCAL_RELOAD_SOCKET_PORT}`; | ||
export const UPDATE_PENDING_MESSAGE = 'wait_update'; | ||
export const UPDATE_REQUEST_MESSAGE = 'do_update'; | ||
export const UPDATE_COMPLETE_MESSAGE = 'done_update'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import type { ReloadMessage, SerializedMessage } from './types'; | ||
import type { WebSocketMessage, SerializedMessage } from './types'; | ||
|
||
export default class MessageInterpreter { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
private constructor() {} | ||
|
||
static send(message: ReloadMessage): SerializedMessage { | ||
static send(message: WebSocketMessage): SerializedMessage { | ||
return JSON.stringify(message); | ||
} | ||
static receive(serializedMessage: SerializedMessage): ReloadMessage { | ||
static receive(serializedMessage: SerializedMessage): WebSocketMessage { | ||
return JSON.parse(serializedMessage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
import { UPDATE_COMPLETE_MESSAGE, UPDATE_PENDING_MESSAGE, UPDATE_REQUEST_MESSAGE } from '../constant'; | ||
|
||
type UpdatePendingMessage = { | ||
type: typeof UPDATE_PENDING_MESSAGE; | ||
type: 'wait_update'; | ||
path: string; | ||
}; | ||
|
||
type UpdateRequestMessage = { | ||
type: typeof UPDATE_REQUEST_MESSAGE; | ||
type: 'do_update'; | ||
}; | ||
|
||
type UpdateCompleteMessage = { type: typeof UPDATE_COMPLETE_MESSAGE }; | ||
type UpdateCompleteMessage = { type: 'done_update' }; | ||
type BuildCompletionMessage = { type: 'build_complete' }; | ||
|
||
export type SerializedMessage = string; | ||
export type ReloadMessage = UpdateCompleteMessage | UpdateRequestMessage | UpdatePendingMessage; | ||
export type WebSocketMessage = | ||
| UpdateCompleteMessage | ||
| UpdateRequestMessage | ||
| UpdatePendingMessage | ||
| BuildCompletionMessage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters