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

fix: use pathToFileUrl for hooks for Windows ES module support #8069

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/orange-goats-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": patch
---

fix: use `pathToFileUrl` for hooks for Windows ES module support
4 changes: 3 additions & 1 deletion packages/app-builder-lib/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { Lazy } from "lazy-val"
import { Minimatch } from "minimatch"
import * as path from "path"
import { pathToFileURL } from "url"
import { AppInfo } from "./appInfo"
import { checkFileInArchive } from "./asar/asarFileChecker"
import { AsarPackager } from "./asar/asarUtil"
Expand Down Expand Up @@ -761,7 +762,8 @@
const isModuleType = type === "module"
try {
if (extension === ".mjs" || (extension === ".js" && isModuleType)) {
return await eval("import('" + name + "')")
const fileUrl = pathToFileURL(name).href;

Check warning on line 765 in packages/app-builder-lib/src/platformPackager.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Delete `;`

Check warning on line 765 in packages/app-builder-lib/src/platformPackager.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Delete `;`
return await eval("import('" + fileUrl + "')")
}
} catch (error) {
log.debug({ moduleName: name }, "Unable to dynamically import hook, falling back to `require`")
Expand Down
Loading