Skip to content

Commit

Permalink
fix: generate valid file URL on Windows (netlify/edge-bundler#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Dec 7, 2022
1 parent 1cc6551 commit 40e0b67
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/edge-bundler/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

0 comments on commit 40e0b67

Please sign in to comment.