Skip to content

Commit

Permalink
chore: merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Dec 16, 2022
1 parent 76e6a0f commit fd1df0c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
12 changes: 6 additions & 6 deletions packages/web-worker/src/shared-worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { MessageChannel, type MessagePort as NodeMessagePort } from 'worker_threads'
import { toFilePath } from 'vite-node/utils'
import type { InlineWorkerContext, Procedure } from './types'
import { InlineWorkerRunner } from './runner'
import { debug, getRunnerOptions } from './utils'
Expand Down Expand Up @@ -104,14 +103,14 @@ export function createSharedWorkerConstructor(): typeof SharedWorker {

const id = (url instanceof URL ? url.toString() : url).replace(/^file:\/+/, '/')

const fsPath = toFilePath(id, runnerOptions.root)
this._vw_name = id

this._vw_name = name ?? fsPath
runner.resolveUrl(id).then(([, fsPath]) => {
this._vw_name = name ?? fsPath

debug('initialize shared worker %s', this._vw_name)
debug('initialize shared worker %s', this._vw_name)

runner.executeFile(fsPath)
.then(() => {
runner.executeFile(fsPath).then(() => {
// worker should be new every time, invalidate its sub dependency
runnerOptions.moduleCache.invalidateSubDepTree([fsPath, `mock:${fsPath}`])
this._vw_workerTarget.dispatchEvent(
Expand All @@ -131,6 +130,7 @@ export function createSharedWorkerConstructor(): typeof SharedWorker {
this.onerror?.(error)
console.error(e)
})
})
}
}
}
12 changes: 6 additions & 6 deletions packages/web-worker/src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { toFilePath } from 'vite-node/utils'
import type { CloneOption, DefineWorkerOptions, InlineWorkerContext, Procedure } from './types'
import { InlineWorkerRunner } from './runner'
import { createMessageEvent, debug, getRunnerOptions } from './utils'
Expand Down Expand Up @@ -69,14 +68,14 @@ export function createWorkerConstructor(options?: DefineWorkerOptions): typeof W

const id = (url instanceof URL ? url.toString() : url).replace(/^file:\/+/, '/')

const fsPath = toFilePath(id, runnerOptions.root)
this._vw_name = id

this._vw_name = options?.name ?? fsPath
runner.resolveUrl(id).then(([, fsPath]) => {
this._vw_name = options?.name ?? fsPath

debug('initialize worker %s', this._vw_name)
debug('initialize worker %s', this._vw_name)

runner.executeFile(fsPath)
.then(() => {
runner.executeFile(fsPath).then(() => {
// worker should be new every time, invalidate its sub dependency
runnerOptions.moduleCache.invalidateSubDepTree([fsPath, `mock:${fsPath}`])
const q = this._vw_messageQueue
Expand All @@ -95,6 +94,7 @@ export function createWorkerConstructor(options?: DefineWorkerOptions): typeof W
this.onerror?.(error)
console.error(e)
})
})
}

addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void {
Expand Down
35 changes: 15 additions & 20 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 fd1df0c

Please sign in to comment.