electron-cli 0.3.0-alpha.13 → 0.3.0-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Cargo.lock CHANGED
@@ -376,7 +376,7 @@ checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e"
376
376
 
377
377
  [[package]]
378
378
  name = "electron-cli"
379
- version = "0.3.0-alpha.13"
379
+ version = "0.3.0-alpha.15"
380
380
  dependencies = [
381
381
  "anyhow",
382
382
  "apple-dmg",
@@ -386,6 +386,7 @@ dependencies = [
386
386
  "fatfs",
387
387
  "flate2",
388
388
  "fscommon",
389
+ "json5",
389
390
  "md5",
390
391
  "msi",
391
392
  "plist",
@@ -805,6 +806,16 @@ dependencies = [
805
806
  "wasm-bindgen",
806
807
  ]
807
808
 
809
+ [[package]]
810
+ name = "json5"
811
+ version = "1.3.1"
812
+ source = "registry+https://github.com/rust-lang/crates.io-index"
813
+ checksum = "733a844dbd6fef128e98cb4487b887cb55454d92cd9994b1bafe004fabbe670c"
814
+ dependencies = [
815
+ "serde",
816
+ "ucd-trie",
817
+ ]
818
+
808
819
  [[package]]
809
820
  name = "keccak"
810
821
  version = "0.1.6"
@@ -1448,6 +1459,12 @@ version = "1.20.1"
1448
1459
  source = "registry+https://github.com/rust-lang/crates.io-index"
1449
1460
  checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
1450
1461
 
1462
+ [[package]]
1463
+ name = "ucd-trie"
1464
+ version = "0.1.7"
1465
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1466
+ checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971"
1467
+
1451
1468
  [[package]]
1452
1469
  name = "unicode-ident"
1453
1470
  version = "1.0.24"
package/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "electron-cli"
3
- version = "0.3.0-alpha.13"
3
+ version = "0.3.0-alpha.15"
4
4
  edition = "2021"
5
5
  description = "Experimental Rust CLI for Electron project diagnostics and workflow automation"
6
6
  license = "MIT"
@@ -15,6 +15,7 @@ clap = { version = "4.6", features = ["derive"] }
15
15
  fatfs = "0.3"
16
16
  flate2 = { version = "1.1", default-features = false, features = ["rust_backend"] }
17
17
  fscommon = "0.1"
18
+ json5 = "1"
18
19
  md5 = "0.7"
19
20
  msi = "0.10"
20
21
  plist = "1"
package/README.md CHANGED
@@ -35,11 +35,11 @@ The Rust-native flow currently owns:
35
35
 
36
36
  - `init --template minimal`: writes a local Electron starter without Electron Forge.
37
37
  - `start`: launches the installed Electron runtime directly.
38
- - `package`: copies the installed Electron runtime, app files, installed production dependency closure, app metadata, macOS icon, and extra resources into a local app bundle for the current platform and architecture.
39
- - `make`: runs `package` and writes distributables under `out/make/<target>/<platform>/<arch>/`; it reads JSON-shaped `config.forge.makers` / `electronCli.makers` arrays when `--target` is omitted, and `--target` still forces one maker. ZIP works on all platforms, `--target dmg` writes a basic macOS disk image, `--target deb` / `--target rpm` write Linux packages, and `--target msi` writes a basic Windows Installer package.
40
- - `publish`: runs `make` and publishes the distributable to a local directory with a manifest or to GitHub Releases.
38
+ - `package`: copies the installed Electron runtime, app files, installed production dependency closure, app metadata, macOS icon, and extra resources into a local app bundle for the current platform and architecture; it reads package metadata from `package.json`, JSON-shaped Forge config, and static Forge config files.
39
+ - `make`: runs `package` and writes distributables under `out/make/<target>/<platform>/<arch>/`; it reads JSON-shaped `config.forge.makers` / `electronCli.makers` arrays and static Forge config files when `--target` is omitted, and `--target` still forces one maker. ZIP works on all platforms, `--target dmg` writes a basic macOS disk image, `--target deb` / `--target rpm` write Linux packages, and `--target msi` writes a basic Windows Installer package.
40
+ - `publish`: runs `make` and publishes distributables to a local directory with a manifest or to GitHub Releases; it reads JSON-shaped `config.forge.publishers` / `electronCli.publishers` arrays and static Forge config files when `--publisher` is omitted, and `--publisher` still forces one publisher.
41
41
 
42
- The GitHub publisher creates or reuses a release, uploads the selected make artifact, and can replace an existing asset with `--force`. It reads `GITHUB_TOKEN` or `GH_TOKEN` and can infer `OWNER/REPO` from `package.json` `repository`, or you can pass `--github-repo`.
42
+ The GitHub publisher creates or reuses a release, uploads selected make artifacts, and can replace an existing asset with `--force`. It reads `GITHUB_TOKEN` or `GH_TOKEN` and can infer `OWNER/REPO` from package metadata, Forge GitHub publisher config, or `package.json` `repository`. You can also pass `--github-repo`.
43
43
 
44
44
  The DMG maker is currently a pure-Rust FAT32 image with the app bundle and an Applications entry. The MSI maker writes a compressed embedded CAB, Windows Installer database tables, and a Start Menu shortcut when the packaged executable is present. HFS+/APFS DMG layout customization, installer UI customization, Windows/Linux icon embedding, signing, and notarization are still TODO.
45
45
 
@@ -61,19 +61,35 @@ Package metadata can be configured in `package.json`:
61
61
  { "name": "@electron-forge/maker-deb", "platforms": ["linux"] },
62
62
  { "name": "@electron-forge/maker-rpm", "platforms": ["linux"] },
63
63
  { "name": "@electron-forge/maker-wix", "platforms": ["win32"] }
64
+ ],
65
+ "publishers": [
66
+ { "name": "local", "config": { "to": "out/publish/local", "channel": "alpha" } },
67
+ {
68
+ "name": "@electron-forge/publisher-github",
69
+ "config": {
70
+ "repository": { "owner": "example", "name": "my-app" },
71
+ "draft": true,
72
+ "prerelease": true
73
+ }
74
+ }
64
75
  ]
65
76
  },
66
77
  "config": {
67
78
  "forge": {
68
79
  "makers": [
69
80
  { "name": "@electron-forge/maker-zip" }
81
+ ],
82
+ "publishers": [
83
+ { "name": "@electron-forge/publisher-github" }
70
84
  ]
71
85
  }
72
86
  }
73
87
  }
74
88
  ```
75
89
 
76
- The package command also reads JSON-shaped `config.forge.packagerConfig` and `electronPackagerConfig` entries for the same fields. The make command maps JSON-shaped Forge maker names to the Rust-native targets it supports: zip, dmg, deb, rpm, and wix/msi. JavaScript Forge config files are not evaluated.
90
+ The package command also reads JSON-shaped `config.forge.packagerConfig` and `electronPackagerConfig` entries for the same fields. The make command maps JSON-shaped Forge maker names to the Rust-native targets it supports: zip, dmg, deb, rpm, and wix/msi. The publish command maps JSON-shaped publisher names to local and GitHub.
91
+
92
+ Static `forge.config.js`, `forge.config.cjs`, `forge.config.mjs`, and `forge.config.ts` files are parsed in Rust when they export an object literal directly or via a local `const`/`let`/`var` identifier. Dynamic JavaScript config that calls functions, reads environment state, or computes the config at runtime is not evaluated.
77
93
 
78
94
  ## Install
79
95
 
@@ -139,7 +155,7 @@ The inspection and planning commands support `--json` so agents and scripts can
139
155
  `start --dry-run --json` shows the Electron executable that will be launched.
140
156
  `package --dry-run --json` shows the runtime, app file, metadata, icon, and extra-resource copy plan.
141
157
  `make --dry-run --json` shows the package prerequisite and selected maker artifact path.
142
- `publish --dry-run --json` shows the make prerequisite plus either the local destination/manifest path or the GitHub release/upload plan.
158
+ `publish --dry-run --json` shows the make prerequisite plus either the local destination/manifest path or the GitHub release/upload plan. When multiple configured makers or publishers apply, the JSON output contains a `publishes` array.
143
159
 
144
160
  ```sh
145
161
  electron-cli plan --json
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electron-cli",
3
- "version": "0.3.0-alpha.13",
3
+ "version": "0.3.0-alpha.15",
4
4
  "description": "Experimental Rust CLI for Electron project diagnostics and workflow automation",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/cli.rs CHANGED
@@ -207,17 +207,17 @@ pub struct PublishArgs {
207
207
  #[arg(long)]
208
208
  pub arch: Option<String>,
209
209
 
210
- /// Maker target whose artifact should be published.
211
- #[arg(long, value_enum, default_value_t = MakeTarget::Zip)]
212
- pub target: MakeTarget,
210
+ /// Maker target whose artifact should be published. Overrides configured makers when provided.
211
+ #[arg(long, value_enum)]
212
+ pub target: Option<MakeTarget>,
213
213
 
214
- /// Publisher target to use.
215
- #[arg(long, value_enum, default_value_t = PublishTarget::Local)]
216
- pub publisher: PublishTarget,
214
+ /// Publisher target to use. Overrides configured publishers when provided.
215
+ #[arg(long, value_enum)]
216
+ pub publisher: Option<PublishTarget>,
217
217
 
218
218
  /// Destination for local published artifacts.
219
- #[arg(long, default_value = "out/publish/local", value_name = "PATH")]
220
- pub to: PathBuf,
219
+ #[arg(long, value_name = "PATH")]
220
+ pub to: Option<PathBuf>,
221
221
 
222
222
  /// GitHub repository to publish to, in OWNER/REPO form.
223
223
  #[arg(long, value_name = "OWNER/REPO")]
@@ -240,12 +240,12 @@ pub struct PublishArgs {
240
240
  pub github_prerelease: bool,
241
241
 
242
242
  /// GitHub API base URL, useful for GitHub Enterprise.
243
- #[arg(long, default_value = "https://api.github.com", value_name = "URL")]
244
- pub github_api_url: String,
243
+ #[arg(long, value_name = "URL")]
244
+ pub github_api_url: Option<String>,
245
245
 
246
246
  /// Release channel label written into the publish manifest.
247
- #[arg(long, default_value = "default")]
248
- pub channel: String,
247
+ #[arg(long)]
248
+ pub channel: Option<String>,
249
249
 
250
250
  /// Reuse an existing make artifact instead of running package and make first.
251
251
  #[arg(long)]
@@ -306,7 +306,7 @@ impl MakeTarget {
306
306
  }
307
307
  }
308
308
 
309
- #[derive(Debug, Clone, Copy, ValueEnum)]
309
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
310
310
  #[value(rename_all = "lower")]
311
311
  pub enum PublishTarget {
312
312
  Github,
@@ -27,7 +27,7 @@ use crate::{
27
27
  project::ProjectSnapshot,
28
28
  };
29
29
 
30
- #[derive(Debug, Serialize)]
30
+ #[derive(Clone, Debug, Serialize)]
31
31
  pub(crate) struct MakeReport {
32
32
  package: PackageReport,
33
33
  target: String,
@@ -74,6 +74,7 @@ pub fn run(args: MakeArgs) -> Result<()> {
74
74
  print_reports(&reports, args.json, MakeStatus::Made)
75
75
  }
76
76
 
77
+ #[cfg(test)]
77
78
  pub(crate) fn build_report(args: &MakeArgs) -> Result<MakeReport> {
78
79
  let reports = build_reports(args)?;
79
80
  if reports.len() != 1 {
@@ -227,24 +228,13 @@ fn resolve_make_targets(
227
228
  }
228
229
 
229
230
  fn configured_makers(snapshot: &ProjectSnapshot) -> Result<Vec<ConfiguredMaker>> {
230
- let Some(package_json_path) = &snapshot.package_json else {
231
- return Ok(Vec::new());
232
- };
233
- let package_json_path = Path::new(package_json_path.as_str());
234
- let raw = fs::read_to_string(package_json_path)
235
- .with_context(|| format!("Could not read {}", package_json_path.display()))?;
236
- let package = serde_json::from_str::<JsonValue>(&raw)
237
- .with_context(|| format!("Could not parse {}", package_json_path.display()))?;
231
+ let project_config = crate::forge_config::read(snapshot)?;
238
232
 
239
233
  let mut makers = Vec::new();
240
234
  for value in [
241
- package
242
- .get("config")
243
- .and_then(|config| config.get("forge"))
244
- .and_then(|forge| forge.get("makers")),
245
- package
246
- .get("electronCli")
247
- .or_else(|| package.get("electron-cli"))
235
+ project_config.forge().and_then(|forge| forge.get("makers")),
236
+ project_config
237
+ .electron_cli()
248
238
  .and_then(|config| config.get("makers")),
249
239
  ]
250
240
  .into_iter()
@@ -345,6 +335,7 @@ fn current_platform_label() -> String {
345
335
  }
346
336
  }
347
337
 
338
+ #[cfg(test)]
348
339
  pub(crate) fn execute_make(report: &mut MakeReport, args: &MakeArgs) -> Result<()> {
349
340
  ensure_package_ready(std::slice::from_mut(report), args)?;
350
341
  execute_make_artifact(report, args)?;
@@ -2419,6 +2410,46 @@ mod tests {
2419
2410
  let _ = fs::remove_dir_all(root);
2420
2411
  }
2421
2412
 
2413
+ #[test]
2414
+ fn builds_make_reports_from_static_forge_config_js() {
2415
+ let root = unique_temp_dir("configured-makers-js");
2416
+ write_package_json(&root);
2417
+ fs::write(
2418
+ root.join("forge.config.js"),
2419
+ r#"
2420
+ module.exports = {
2421
+ makers: [
2422
+ { name: '@electron-forge/maker-zip' },
2423
+ { name: '@electron-forge/maker-rpm', platforms: ['linux'] },
2424
+ ],
2425
+ };
2426
+ "#,
2427
+ )
2428
+ .expect("forge config should be written");
2429
+ write_app_file(&root);
2430
+ write_fake_electron_dist(&root);
2431
+
2432
+ let args = MakeArgs {
2433
+ cwd: root.clone(),
2434
+ out_dir: PathBuf::from("out"),
2435
+ name: None,
2436
+ platform: Some("linux".to_string()),
2437
+ arch: Some("x64".to_string()),
2438
+ target: None,
2439
+ skip_package: false,
2440
+ force: false,
2441
+ dry_run: true,
2442
+ json: true,
2443
+ };
2444
+ let reports = build_reports(&args).expect("reports should build");
2445
+
2446
+ assert_eq!(reports.len(), 2);
2447
+ assert_eq!(reports[0].target(), "zip");
2448
+ assert_eq!(reports[1].target(), "rpm");
2449
+
2450
+ let _ = fs::remove_dir_all(root);
2451
+ }
2452
+
2422
2453
  #[test]
2423
2454
  fn explicit_make_target_overrides_configured_makers() {
2424
2455
  let root = unique_temp_dir("target-override");
@@ -12,7 +12,7 @@ use serde_json::Value as JsonValue;
12
12
 
13
13
  use crate::{cli::PackageArgs, output, project::ProjectSnapshot};
14
14
 
15
- #[derive(Debug, Serialize)]
15
+ #[derive(Clone, Debug, Serialize)]
16
16
  pub(crate) struct PackageReport {
17
17
  project: ProjectSnapshot,
18
18
  app_name: String,
@@ -31,13 +31,13 @@ pub(crate) struct PackageReport {
31
31
  warnings: Vec<String>,
32
32
  }
33
33
 
34
- #[derive(Debug, Serialize)]
34
+ #[derive(Clone, Debug, Serialize)]
35
35
  struct CopyStep {
36
36
  from: Utf8PathBuf,
37
37
  to: Utf8PathBuf,
38
38
  }
39
39
 
40
- #[derive(Debug, Serialize)]
40
+ #[derive(Clone, Debug, Serialize)]
41
41
  struct PackageMetadata {
42
42
  bundle_identifier: String,
43
43
  app_version: Option<String>,
@@ -49,13 +49,13 @@ struct PackageMetadata {
49
49
  darwin_dark_mode_support: bool,
50
50
  }
51
51
 
52
- #[derive(Debug, Serialize)]
52
+ #[derive(Clone, Debug, Serialize)]
53
53
  struct IconResource {
54
54
  from: Utf8PathBuf,
55
55
  to: Utf8PathBuf,
56
56
  }
57
57
 
58
- #[derive(Debug, Serialize)]
58
+ #[derive(Clone, Copy, Debug, Serialize)]
59
59
  #[serde(rename_all = "kebab-case")]
60
60
  enum PackageStatus {
61
61
  Planned,
@@ -67,6 +67,7 @@ struct PackageJsonConfig {
67
67
  product_name: Option<String>,
68
68
  app_version: Option<String>,
69
69
  packager: PackagerConfig,
70
+ warnings: Vec<String>,
70
71
  }
71
72
 
72
73
  #[derive(Debug, Default)]
@@ -133,7 +134,7 @@ pub(crate) fn build_report(snapshot: ProjectSnapshot, args: &PackageArgs) -> Res
133
134
  &platform,
134
135
  )?;
135
136
 
136
- let mut warnings = Vec::new();
137
+ let mut warnings = package_config.warnings.clone();
137
138
  if snapshot.package_json.is_none() {
138
139
  warnings.push("No package.json found.".to_string());
139
140
  }
@@ -346,44 +347,40 @@ fn print_report(report: &PackageReport, json: bool) -> Result<()> {
346
347
  }
347
348
 
348
349
  fn read_package_json_config(snapshot: &ProjectSnapshot) -> Result<PackageJsonConfig> {
349
- let Some(package_json_path) = &snapshot.package_json else {
350
- return Ok(PackageJsonConfig::default());
351
- };
352
-
353
- let package_json_path = Path::new(package_json_path.as_str());
354
- let raw = fs::read_to_string(package_json_path)
355
- .with_context(|| format!("Could not read {}", package_json_path.display()))?;
356
- let package = serde_json::from_str::<JsonValue>(&raw)
357
- .with_context(|| format!("Could not parse {}", package_json_path.display()))?;
350
+ let project_config = crate::forge_config::read(snapshot)?;
358
351
 
359
352
  let mut packager = PackagerConfig::default();
360
- if let Some(config) = package
361
- .get("config")
362
- .and_then(|config| config.get("forge"))
353
+ if let Some(config) = project_config
354
+ .forge()
363
355
  .and_then(|forge| forge.get("packagerConfig"))
364
356
  {
365
357
  packager.merge(parse_packager_config(config));
366
358
  }
367
- if let Some(config) = package.get("electronPackagerConfig") {
359
+ if let Some(config) = project_config
360
+ .package()
361
+ .and_then(|package| package.get("electronPackagerConfig"))
362
+ {
368
363
  packager.merge(parse_packager_config(config));
369
364
  }
370
- if let Some(config) = package
371
- .get("electronCli")
372
- .or_else(|| package.get("electron-cli"))
365
+ if let Some(config) = project_config
366
+ .electron_cli()
373
367
  .and_then(|config| config.get("packagerConfig"))
374
368
  {
375
369
  packager.merge(parse_packager_config(config));
376
370
  }
377
371
 
378
372
  Ok(PackageJsonConfig {
379
- product_name: package
380
- .get("productName")
373
+ product_name: project_config
374
+ .package()
375
+ .and_then(|package| package.get("productName"))
381
376
  .and_then(JsonValue::as_str)
382
377
  .map(ToOwned::to_owned),
383
- app_version: package
384
- .get("version")
378
+ app_version: project_config
379
+ .package()
380
+ .and_then(|package| package.get("version"))
385
381
  .and_then(JsonValue::as_str)
386
382
  .map(ToOwned::to_owned),
383
+ warnings: project_config.warnings().to_vec(),
387
384
  packager,
388
385
  })
389
386
  }
@@ -1380,6 +1377,52 @@ mod tests {
1380
1377
  let _ = fs::remove_dir_all(root);
1381
1378
  }
1382
1379
 
1380
+ #[test]
1381
+ fn plans_packager_metadata_from_forge_config_js() {
1382
+ let root = unique_temp_dir("forge-config-metadata");
1383
+ write_package_json(&root);
1384
+ fs::write(
1385
+ root.join("forge.config.js"),
1386
+ r#"
1387
+ module.exports = {
1388
+ packagerConfig: {
1389
+ name: 'Forge Config App',
1390
+ executableName: 'ForgeExec',
1391
+ appBundleId: 'com.example.forge-config',
1392
+ },
1393
+ };
1394
+ "#,
1395
+ )
1396
+ .expect("forge config should be written");
1397
+ write_app_file(&root);
1398
+ write_fake_electron_dist(&root);
1399
+
1400
+ let args = PackageArgs {
1401
+ cwd: root.clone(),
1402
+ out_dir: PathBuf::from("out"),
1403
+ name: None,
1404
+ platform: None,
1405
+ arch: None,
1406
+ force: false,
1407
+ dry_run: true,
1408
+ json: true,
1409
+ };
1410
+ let snapshot = crate::project::inspect(&root).expect("project should inspect");
1411
+ let report = build_report(snapshot, &args).expect("report should build");
1412
+
1413
+ assert_eq!(report.app_name, "Forge Config App");
1414
+ assert_eq!(
1415
+ report.executable_name,
1416
+ executable_name("ForgeExec", &report.platform)
1417
+ );
1418
+ assert_eq!(
1419
+ report.metadata.bundle_identifier,
1420
+ "com.example.forge-config"
1421
+ );
1422
+
1423
+ let _ = fs::remove_dir_all(root);
1424
+ }
1425
+
1383
1426
  #[test]
1384
1427
  fn packages_macos_info_plist_metadata() {
1385
1428
  if current_platform() != "darwin" {