esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

Support file:// URLs where paths as are supported.

Open remcohaszing opened this issue 2 years ago • 0 comments

When dealing with paths in Node.js, people often use URL instances. This is especially true when writing ESM scripts, where import.meta.url is available, but not __dirname, or __filename. The Node.js fs APIs already support URL instances where paths are allowed.

I think it might would be useful for esbuild to also support file URLs where paths are expected. Currently they need to be converted to strings using fileURLToPath.

I.e.

  onResolve({ filter: /\/schemaSelectionHandlers$/ }, () => ({
-   path: fileURLToPath(new URL('src/fillers/schemaSelectionHandlers.ts', import.meta.url)),
+   path: new URL('src/fillers/schemaSelectionHandlers.ts', import.meta.url),
  }));

remcohaszing avatar Sep 02 '22 11:09 remcohaszing