Fix file URL to path conversion in html-language-features esbuild script (#328557)

import.meta.resolve(...).replace('file://', '') is not a correct way
to convert a file:// URL to a filesystem path. It always breaks on
Windows (leaves a leading slash before the drive letter, e.g.
/C:/Users/..., which downstream path.join/fs calls mangle into
C:\C:\Users\...), and it also breaks on any OS whenever the resolved
path contains a character that gets percent-encoded in a URL, most
commonly a space (e.g. file:///home/jane%20doe/... never gets decoded
back to "jane doe", so fs.readFileSync fails with ENOENT there too).

Use fileURLToPath() from node:url instead, which is Node's own
built-in, spec-correct URL-to-path converter and handles both cases.
This commit is contained in:
Jade Ferreira Vieira
2026-08-19 18:11:17 +00:00
committed by GitHub
parent 57ca46fc0d
commit e145e083f0
@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as fs from 'node:fs';
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';
import type * as esbuild from 'esbuild';
import { run } from '../esbuild-extension-common.mts';
@@ -19,7 +20,7 @@ function javaScriptLibsPlugin(): esbuild.Plugin {
name: 'javascript-libs',
setup(build) {
build.onLoad({ filter: /javascriptLibs\.ts$/ }, () => {
const TYPESCRIPT_LIB_SOURCE = path.dirname(import.meta.resolve('typescript').replace('file://', ''));
const TYPESCRIPT_LIB_SOURCE = path.dirname(fileURLToPath(import.meta.resolve('typescript')));
const JQUERY_DTS = path.join(extensionRoot, 'server', 'lib', 'jquery.d.ts');
function getFileName(name: string): string {