Skip to content

Commit 640ee9b

Browse files
authored
fix: use file paths for dynamic imports (#1844)
1 parent 999a2a7 commit 640ee9b

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

src/common.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,10 @@ export async function validateElectronApp(
152152
}
153153

154154
export async function hostInfo() {
155-
const packageJsonPath = path.resolve(import.meta.dirname, '../package.json');
156-
157-
const { default: metadata } = await import(packageJsonPath, {
158-
with: { type: 'json' },
159-
});
155+
const packageJSONPath = path.resolve(import.meta.dirname, '../package.json');
156+
const metadata = JSON.parse(
157+
await fs.promises.readFile(packageJSONPath, 'utf8'),
158+
);
160159

161160
return (
162161
`Electron Packager ${metadata.version}\n` +

src/packager.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import path from 'node:path';
2+
import url from 'node:url';
3+
14
import {
25
baseTempDir,
36
debug,
@@ -12,7 +15,6 @@ import fs from 'graceful-fs';
1215
import { promisifiedGracefulFs } from './util.js';
1316
import { getMetadataFromPackageJSON } from './infer.js';
1417
import { runHooks } from './hooks.js';
15-
import path from 'node:path';
1618
import {
1719
createPlatformArchPairs,
1820
osModules,
@@ -28,7 +30,6 @@ import type {
2830
Options,
2931
ProcessedOptions,
3032
} from './types.js';
31-
import { App } from './platform.js';
3233

3334
async function debugHostInfo() {
3435
debug(await hostInfo());
@@ -192,10 +193,16 @@ export class Packager {
192193
debug(`Creating ${buildDir}`);
193194
await fs.promises.mkdir(buildDir, { recursive: true });
194195
await this.extractElectronZip(comboOpts, zipPath, buildDir);
195-
const os = await import(
196-
`${osModules[comboOpts.platform as OfficialPlatform]}.js`
197-
);
198-
const app = new os.App(comboOpts, buildDir) as App;
196+
const osPackagerPath = url
197+
.pathToFileURL(
198+
path.resolve(
199+
import.meta.dirname,
200+
`${osModules[comboOpts.platform]}.js`,
201+
),
202+
)
203+
.toString();
204+
const osPackager = await import(osPackagerPath);
205+
const app = new osPackager.App(comboOpts, buildDir);
199206
return app.create();
200207
}
201208

test/infer.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'node:fs';
22
import os from 'node:os';
33
import path from 'node:path';
4+
import url from 'node:url';
45
import { getMetadataFromPackageJSON } from '../src/infer.js';
56
import { Options } from '../src/types.js';
67
import semver from 'semver';
@@ -16,7 +17,9 @@ describe('getMetadataFromPackageJSON', () => {
1617
const opts: Options = {
1718
dir,
1819
};
19-
const packageJSON = await import(path.join(dir, 'package.json'));
20+
const packageJSON = await import(
21+
url.pathToFileURL(path.join(dir, 'package.json')).toString()
22+
);
2023
const result = await getMetadataFromPackageJSON([], opts, opts.dir);
2124
expect(result.electronVersion).toBeDefined();
2225
expect(

0 commit comments

Comments
 (0)