From a5fe632384eb23cc260e3aaf85dfa1f79bbf2bfd Mon Sep 17 00:00:00 2001 From: marcopiraccini Date: Mon, 13 May 2024 10:37:23 +0200 Subject: [PATCH] Fix for prepare folder win Signed-off-by: marcopiraccini --- src/main/lib/import-or-local.mjs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/main/lib/import-or-local.mjs b/src/main/lib/import-or-local.mjs index d87a3aaa..044db752 100644 --- a/src/main/lib/import-or-local.mjs +++ b/src/main/lib/import-or-local.mjs @@ -1,12 +1,8 @@ +import { pathToFileURL } from 'node:url' import path from 'node:path' import { createRequire } from 'module' import { npmInstall } from './run-npm.mjs' -const getFilePathWithVersion = (file) => { - const ext = path.extname(file) - return `${file}?version=${Date.now()}${ext}` -} - async function importOrLocal ({ projectDir, pkg, logger }) { if (pkg) { pkg = pkg.trim() @@ -23,19 +19,14 @@ async function importOrLocal ({ projectDir, pkg, logger }) { try { const fileToImport = _require.resolve(pkg) - const fileWithVersion = getFilePathWithVersion(fileToImport) - return await import(fileWithVersion) + return await import(pathToFileURL(fileToImport)) } catch (err) {} await npmInstall(pkg, { cwd: projectDir }, logger) logger.info({ name: pkg, path: projectDir }, 'Installed!') const fileToImport = _require.resolve(pkg) - - // adding a date to the URL to avoid using the cached module - const fileWithVersion = getFilePathWithVersion(fileToImport) - const ret = await import(fileWithVersion) - return ret + return await import(pathToFileURL(fileToImport)) } }