From de514ed4e4dbfed6d61f701b56224752e70837ab Mon Sep 17 00:00:00 2001 From: JongHak Seo Date: Sun, 12 Nov 2023 04:13:59 +0900 Subject: [PATCH] fix: windows dynamic import protocol issue (#268) --- utils/plugins/make-manifest.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/utils/plugins/make-manifest.ts b/utils/plugins/make-manifest.ts index fd2ef8ee5..1791d031d 100644 --- a/utils/plugins/make-manifest.ts +++ b/utils/plugins/make-manifest.ts @@ -3,6 +3,8 @@ import * as path from 'path'; import colorLog from '../log'; import ManifestParser from '../manifest-parser'; import type { PluginOption } from 'vite'; +import url from 'url'; +import * as process from 'process'; const { resolve } = path; @@ -10,7 +12,17 @@ const rootDir = resolve(__dirname, '..', '..'); const distDir = resolve(rootDir, 'dist'); const manifestFile = resolve(rootDir, 'manifest.js'); -const getManifestWithCacheBurst = () => import(manifestFile + '?' + Date.now().toString()); +const getManifestWithCacheBurst = (): Promise<{ default: chrome.runtime.ManifestV3 }> => { + const withCacheBurst = (path: string) => `${path}?${Date.now().toString()}`; + /** + * In Windows, import() doesn't work without file:// protocol. + * So, we need to convert path to file:// protocol. (url.pathToFileURL) + */ + if (process.platform === 'win32') { + return import(withCacheBurst(url.pathToFileURL(manifestFile).href)); + } + return import(withCacheBurst(manifestFile)); +}; export default function makeManifest(config: { contentScriptCssKey?: string }): PluginOption { function makeManifest(manifest: chrome.runtime.ManifestV3, to: string) {