Skip to content
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
9 changes: 4 additions & 5 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,10 @@ export async function validateElectronApp(
}

export async function hostInfo() {
const packageJsonPath = path.resolve(import.meta.dirname, '../package.json');

const { default: metadata } = await import(packageJsonPath, {
with: { type: 'json' },
});
const packageJSONPath = path.resolve(import.meta.dirname, '../package.json');
const metadata = JSON.parse(
await fs.promises.readFile(packageJSONPath, 'utf8'),
);

return (
`Electron Packager ${metadata.version}\n` +
Expand Down
19 changes: 13 additions & 6 deletions src/packager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import path from 'node:path';
import url from 'node:url';

import {
baseTempDir,
debug,
Expand All @@ -12,7 +15,6 @@ import fs from 'graceful-fs';
import { promisifiedGracefulFs } from './util.js';
import { getMetadataFromPackageJSON } from './infer.js';
import { runHooks } from './hooks.js';
import path from 'node:path';
import {
createPlatformArchPairs,
osModules,
Expand All @@ -28,7 +30,6 @@ import type {
Options,
ProcessedOptions,
} from './types.js';
import { App } from './platform.js';

async function debugHostInfo() {
debug(await hostInfo());
Expand Down Expand Up @@ -192,10 +193,16 @@ export class Packager {
debug(`Creating ${buildDir}`);
await fs.promises.mkdir(buildDir, { recursive: true });
await this.extractElectronZip(comboOpts, zipPath, buildDir);
const os = await import(
`${osModules[comboOpts.platform as OfficialPlatform]}.js`
);
const app = new os.App(comboOpts, buildDir) as App;
const osPackagerPath = url
.pathToFileURL(
path.resolve(
import.meta.dirname,
`${osModules[comboOpts.platform]}.js`,
),
)
.toString();
const osPackager = await import(osPackagerPath);
const app = new osPackager.App(comboOpts, buildDir);
return app.create();
}

Expand Down
5 changes: 4 additions & 1 deletion test/infer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import url from 'node:url';
import { getMetadataFromPackageJSON } from '../src/infer.js';
import { Options } from '../src/types.js';
import semver from 'semver';
Expand All @@ -16,7 +17,9 @@ describe('getMetadataFromPackageJSON', () => {
const opts: Options = {
dir,
};
const packageJSON = await import(path.join(dir, 'package.json'));
const packageJSON = await import(
url.pathToFileURL(path.join(dir, 'package.json')).toString()
);
const result = await getMetadataFromPackageJSON([], opts, opts.dir);
expect(result.electronVersion).toBeDefined();
expect(
Expand Down