Skip to content

Commit

Permalink
Fix for prepare folder win (#687)
Browse files Browse the repository at this point in the history
Signed-off-by: marcopiraccini <[email protected]>
  • Loading branch information
marcopiraccini authored May 13, 2024
1 parent 0759141 commit 917acde
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/main/lib/import-or-local.mjs
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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))
}
}

Expand Down

0 comments on commit 917acde

Please sign in to comment.