Skip to content

Commit

Permalink
fix: use pathToFileUrl for hooks for Windows ES module support (#8069)
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzroeder authored Feb 21, 2024
1 parent 5681777 commit 538dd86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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 { readdir } from "fs/promises"
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 @@ async function resolveModule<T>(type: string | undefined, name: string): Promise
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

0 comments on commit 538dd86

Please sign in to comment.