Fix import of port-data-source.js on Windows.

This commit is contained in:
Johannes Maas 2022-03-20 14:28:49 +01:00
parent b3f0ebba9d
commit 10cf930226

View File

@ -1,4 +1,5 @@
const path = require("path"); const path = require("path");
const url = require("url");
const fetch = require("node-fetch"); const fetch = require("node-fetch");
const objectHash = require("object-hash"); const objectHash = require("object-hash");
const kleur = require("kleur"); const kleur = require("kleur");
@ -55,7 +56,9 @@ function lookupOrPerform(portsFile, mode, rawRequest, hasFsAccess) {
let portDataSource = {}; let portDataSource = {};
let portDataSourceFound = false; let portDataSourceFound = false;
try { try {
portDataSource = await import(path.join(process.cwd(), portsFile)); const portDataSourcePath = path.join(process.cwd(), portsFile);
// On Windows, we need cannot use paths directly and instead must use a file:// URL.
portDataSource = await import(url.pathToFileURL(portDataSourcePath).href);
portDataSourceFound = true; portDataSourceFound = true;
} catch (e) {} } catch (e) {}