Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generate valid file URL on Windows #245

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions node/formats/eszip.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { join, relative } from 'path'
import { pathToFileURL } from 'url'

import { virtualRoot } from '../../shared/consts.js'
import type { WriteStage2Options } from '../../shared/stage2.js'
Expand Down Expand Up @@ -69,15 +70,15 @@ const createUserImportMap = async (importMap: ImportMap, basePath: string, distD

await importMap.writeToFile(destPath)

let virtualPath = relative(basePath, destPath)
const virtualPath = relative(basePath, destPath)

// If the dist directory is not a child of the base path, we can't represent
// the relative path as a file URL (because something like 'file://../foo' is
// not valid). This should never happen, but it's best to leave the absolute
// path untransformed to avoid getting a build error due to a missing import
// map.
if (virtualPath.startsWith('..')) {
virtualPath = destPath
return pathToFileURL(destPath).toString()
}

const importMapURL = new URL(virtualPath, virtualRoot)
Expand Down