Skip to content

Commit

Permalink
remove illegal colons in path names on Windows (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenesvk committed Jun 5, 2022
1 parent 74f42c8 commit 61b47be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { bgCyan, black } from 'kolorist'
export const port = parseInt(process.env.PORT || '') || 3303
export const r = (...args: string[]) => resolve(__dirname, '..', ...args)
export const isDev = process.env.NODE_ENV !== 'production'
export const isWin = process.platform === "win32";

export function log(name: string, message: string) {
// eslint-disable-next-line no-console
Expand Down
16 changes: 13 additions & 3 deletions vite-mv3-hmr.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { dirname, join } from 'path'
import type { HMRPayload, PluginOption } from 'vite'
import fs from 'fs-extra'
import { r } from './scripts/utils'
import { r, isWin } from './scripts/utils'

const targetDir = r('extension')

Expand Down Expand Up @@ -48,7 +48,10 @@ export const MV3Hmr = (): PluginOption => {

if (importedModules) {
for (const mod of importedModules) {
code = code.replace(mod.url, normalizeViteUrl(mod.url, mod.type))
code = code.replace(mod.url, normalizeViteUrl(isWin
? mod.url.replace(/[A-Z]:\//,'').replace(/:/,'.')
: mod.url,
mod.type)) // fix invalid colon in /@fs/C:, /@id/plugin-vue:export-helper
writeToDisk(mod.url)
}
}
Expand All @@ -57,8 +60,15 @@ export const MV3Hmr = (): PluginOption => {
code = code
.replace(/\/@vite\/client/g, '/dist/mv3client.mjs')
.replace(/(\/\.vite\/deps\/\S+?)\?v=\w+/g, '$1')
if (isWin) { code = code
.replace(/(from\s+["']\/@fs\/)[A-Z]:\//g, '$1')
};

const targetFile = normalizeFsUrl(urlModule.url, urlModule.type)

const targetFile = normalizeFsUrl(isWin
? urlModule.url.replace(/[A-Z]:\//,'').replace(/:/,'.')
: urlModule.url,
urlModule.type) // fix invalid colon in /@fs/C:, /@id/plugin-vue:export-helper
await fs.ensureDir(dirname(targetFile))
await fs.writeFile(targetFile, code)
}
Expand Down

0 comments on commit 61b47be

Please sign in to comment.