Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollback for load always a new ESM module for generator #687

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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