diff --git a/packages/web-worker/src/shared-worker.ts b/packages/web-worker/src/shared-worker.ts index 49028bbb5e17..2de074d21a41 100644 --- a/packages/web-worker/src/shared-worker.ts +++ b/packages/web-worker/src/shared-worker.ts @@ -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' @@ -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( @@ -131,6 +130,7 @@ export function createSharedWorkerConstructor(): typeof SharedWorker { this.onerror?.(error) console.error(e) }) + }) } } } diff --git a/packages/web-worker/src/worker.ts b/packages/web-worker/src/worker.ts index d77c9bf8f9be..07f38812d90f 100644 --- a/packages/web-worker/src/worker.ts +++ b/packages/web-worker/src/worker.ts @@ -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' @@ -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 @@ -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 { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 33d86c1d73e4..686767d8ccf7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -58,7 +58,7 @@ importers: '@rollup/plugin-node-resolve': 15.0.1_rollup@2.79.1 '@types/fs-extra': 9.0.13 '@types/lodash': 4.14.191 - '@types/node': 18.11.15 + '@types/node': 18.11.14 '@types/ws': 8.5.3 '@vitest/browser': link:packages/browser '@vitest/coverage-c8': link:packages/coverage-c8 @@ -84,10 +84,10 @@ importers: rollup-plugin-esbuild: 4.10.2_itddgjfly6okm3gulavqgvimcq rollup-plugin-license: 2.9.1_rollup@2.79.1 simple-git-hooks: 2.8.1 - ts-node: 10.9.1_ewfw2lwfc3dwdvz7r6yz2ssqyi + ts-node: 10.9.1_jxffkbksrxcpjftzfp475m3gy4 tsup: 6.5.0_z6wznmtyb6ovnulj6iujpct7um typescript: 4.9.4 - vite: 4.0.0_@types+node@18.11.15 + vite: 4.0.0_@types+node@18.11.14 vitest: link:packages/vitest docs: @@ -1850,11 +1850,6 @@ packages: resolution: {integrity: sha512-O4KCvQA6lLiMU9l2eawBPMf1xPP8xPfB3iEQw150hOVTqj/rfXz0ThTb4HEzqQfs2Bmo5Ay8BzxfzVtBrr9dVg==} dev: true - /@babel/helper-plugin-utils/7.19.0: - resolution: {integrity: sha512-40Ryx7I8mT+0gaNxm8JGTZFUITNqdLAgdg0hXzeVZxVD6nFsdhQvip6v8dqkRHzsz1VFpFAaOCHNn0vKBL7Czw==} - engines: {node: '>=6.9.0'} - dev: true - /@babel/helper-plugin-utils/7.20.2: resolution: {integrity: sha512-8RvlJG2mj4huQ4pZ+rU9lqKi9ZKiRmuvGuM2HlWmkmgOhbs6zEAw6IEiJ5cQqGbDzGZOhwuOQNtZMi/ENLjZoQ==} engines: {node: '>=6.9.0'} @@ -3484,7 +3479,7 @@ packages: '@babel/core': ^7.0.0-0 dependencies: '@babel/core': 7.18.13 - '@babel/helper-plugin-utils': 7.19.0 + '@babel/helper-plugin-utils': 7.20.2 dev: true /@babel/plugin-transform-react-jsx-source/7.19.6_@babel+core@7.19.6: @@ -3516,7 +3511,7 @@ packages: '@babel/core': 7.18.13 '@babel/helper-annotate-as-pure': 7.18.6 '@babel/helper-module-imports': 7.18.6 - '@babel/helper-plugin-utils': 7.19.0 + '@babel/helper-plugin-utils': 7.20.2 '@babel/plugin-syntax-jsx': 7.18.6_@babel+core@7.18.13 '@babel/types': 7.20.0 dev: true @@ -3530,7 +3525,7 @@ packages: '@babel/core': 7.18.13 '@babel/helper-annotate-as-pure': 7.18.6 '@babel/helper-module-imports': 7.18.6 - '@babel/helper-plugin-utils': 7.19.0 + '@babel/helper-plugin-utils': 7.20.2 '@babel/plugin-syntax-jsx': 7.18.6_@babel+core@7.18.13 '@babel/types': 7.20.0 dev: true @@ -3544,7 +3539,7 @@ packages: '@babel/core': 7.19.6 '@babel/helper-annotate-as-pure': 7.18.6 '@babel/helper-module-imports': 7.18.6 - '@babel/helper-plugin-utils': 7.19.0 + '@babel/helper-plugin-utils': 7.20.2 '@babel/plugin-syntax-jsx': 7.18.6_@babel+core@7.19.6 '@babel/types': 7.20.0 dev: true @@ -3558,7 +3553,7 @@ packages: '@babel/core': 7.20.5 '@babel/helper-annotate-as-pure': 7.18.6 '@babel/helper-module-imports': 7.18.6 - '@babel/helper-plugin-utils': 7.19.0 + '@babel/helper-plugin-utils': 7.20.2 '@babel/plugin-syntax-jsx': 7.18.6_@babel+core@7.20.5 '@babel/types': 7.20.0 dev: true @@ -7400,8 +7395,8 @@ packages: resolution: {integrity: sha512-aFcUkv7EddxxOa/9f74DINReQ/celqH8DiB3fRYgVDM2Xm5QJL8sl80QKuAnGvwAsMn+H3IFA6WCrQh1CY7m1A==} dev: true - /@types/node/18.11.15: - resolution: {integrity: sha512-VkhBbVo2+2oozlkdHXLrb3zjsRkpdnaU2bXmX8Wgle3PUi569eLRaHGlgETQHR7lLL1w7GiG3h9SnePhxNDecw==} + /@types/node/18.11.14: + resolution: {integrity: sha512-0KXV57tENYmmJMl+FekeW9V3O/rlcqGQQJ/hNh9r8pKIj304pskWuEd8fCyNT86g/TpO0gcOTiLzsHLEURFMIQ==} dev: true /@types/node/18.11.15: @@ -16970,7 +16965,7 @@ packages: optional: true dependencies: lilconfig: 2.0.6 - ts-node: 10.9.1_ewfw2lwfc3dwdvz7r6yz2ssqyi + ts-node: 10.9.1_jxffkbksrxcpjftzfp475m3gy4 yaml: 1.10.2 dev: true @@ -19692,7 +19687,7 @@ packages: tslib: 2.4.1 dev: false - /ts-node/10.9.1_ewfw2lwfc3dwdvz7r6yz2ssqyi: + /ts-node/10.9.1_jxffkbksrxcpjftzfp475m3gy4: resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true peerDependencies: @@ -19711,7 +19706,7 @@ packages: '@tsconfig/node12': 1.0.11 '@tsconfig/node14': 1.0.3 '@tsconfig/node16': 1.0.3 - '@types/node': 18.11.15 + '@types/node': 18.11.14 acorn: 8.8.1 acorn-walk: 8.2.0 arg: 4.1.3 @@ -20669,7 +20664,7 @@ packages: optionalDependencies: fsevents: 2.3.2 - /vite/4.0.0_@types+node@18.11.15: + /vite/4.0.0_@types+node@18.11.14: resolution: {integrity: sha512-ynad+4kYs8Jcnn8J7SacS9vAbk7eMy0xWg6E7bAhS1s79TK+D7tVFGXVZ55S7RNLRROU1rxoKlvZ/qjaB41DGA==} engines: {node: ^14.18.0 || >=16.0.0} hasBin: true @@ -20694,7 +20689,7 @@ packages: terser: optional: true dependencies: - '@types/node': 18.11.15 + '@types/node': 18.11.14 esbuild: 0.16.3 postcss: 8.4.19 resolve: 1.22.1