From 62e8be1c34b858de63fd71d9dfad2c7a297e7ed3 Mon Sep 17 00:00:00 2001
From: alex8088 <244096523@qq.com>
Date: Sat, 7 Jan 2023 12:57:09 +0800
Subject: [PATCH] chore(worker): use toRelativePath helper

---
 src/plugins/worker.ts | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/plugins/worker.ts b/src/plugins/worker.ts
index 3dea1cd..fda4c6d 100644
--- a/src/plugins/worker.ts
+++ b/src/plugins/worker.ts
@@ -1,8 +1,7 @@
-import path from 'node:path'
 import type { Plugin } from 'vite'
 import type { SourceMapInput } from 'rollup'
 import MagicString from 'magic-string'
-import { cleanUrl, parseRequest } from '../utils'
+import { cleanUrl, parseRequest, toRelativePath } from '../utils'
 
 const nodeWorkerAssetUrlRE = /__VITE_NODE_WORKER_ASSET__([a-z\d]{8})__/g
 
@@ -47,10 +46,7 @@ export default function workerPlugin(): Plugin {
         while ((match = nodeWorkerAssetUrlRE.exec(code))) {
           const [full, hash] = match
           const filename = this.getFileName(hash)
-          let outputFilepath = path.posix.relative(path.dirname(chunk.fileName), filename)
-          if (!outputFilepath.startsWith('.')) {
-            outputFilepath = './' + outputFilepath
-          }
+          const outputFilepath = toRelativePath(filename, chunk.fileName)
           const replacement = JSON.stringify(outputFilepath)
           s.overwrite(match.index, match.index + full.length, replacement, {
             contentOnly: true