Skip to content

Commit 10bfd06

Browse files
committed
maker-appimage: Add and document debug logging.
• project: Document debug logging. • maker-appimage: Implement debug logging, via Node's `debug().enabled`.
1 parent d8f633e commit 10bfd06

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

docs/Troubleshooting.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Troubleshooting ReForged project
2+
3+
This document describes necessary steps to properly troubleshoot ReForged
4+
project's behaviour and collect
5+
6+
## vs Electron Forge (TL;DR)
7+
8+
- Unlike to Forge, ReForged aims to eliminate third-party dependencies unless
9+
it is greatly beneficial to use them, has no Node.js API or standard language
10+
equivalent and it is counter-productive to re-implement their feature-set.
11+
- For the reasons above, ReForged doesn't rely on `debug` module. It prefers
12+
Node's implementation of debug logging via `util`.
13+
- There's code for compatibility with `debug`'s `DEBUG` env variable, yet it
14+
might not support all wildcard formats (eg. exclusion).
15+
16+
## General documentation
17+
18+
ReForged has support for logging via `NODE_DEBUG` environment variable.
19+
You can find more information in [Node.js documentation][docs] about its
20+
syntax.
21+
22+
In general, you might log the ReForge-related components using following
23+
sections and wildcards:
24+
25+
- `reforged:*` – show debug logs of all ReForged-related components.
26+
- `reforged:[module-name]` – show debug log of the specific component,
27+
eg. `maker-appimage`.
28+
29+
For convenience, you might also use `DEBUG` env variable, yet it might have
30+
for now limited support for the wildcard usage.
31+
32+
Also see [Forge's `Support.md`][forge] for more information about the logging
33+
of each Forge's components.
34+
35+
[docs]: https://nodejs.org/api/util.html#utildebuglogsection-callback "util.debuglog in Node.js API Documentation"

makers/appimage/src/main.ts

+27-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from "fs/promises";
1919
import { EventEmitter } from "events";
2020

21+
import { debug, format } from "util";
2122
import { MakerBase } from "@electron-forge/maker-base";
2223
import sanitizeName from "@spacingbat3/lss";
2324

@@ -34,6 +35,7 @@ import {
3435

3536
import type MakerAppImageConfig from "../types/config.d.ts";
3637
import type { MakerMeta } from "./utils.js";
38+
import type { DebugLoggerFunction } from "util";
3739

3840
const enum RemoteDefaults {
3941
MirrorHost = 'https://github.com/AppImage/',
@@ -46,6 +48,18 @@ const enum RemoteDefaults {
4648
FileName = "{{ filename }}-{{ arch }}",
4749
}
4850

51+
const d:DebugLoggerFunction = (() => {
52+
if(debug("reforged:maker-appimage").enabled || /(?:^|,)(?:\*|reforged:(?:\*|maker-appimage))(?:$|,)/
53+
.test(process.env["DEBUG"]??""))
54+
// Function that logs similarly to debugLog.
55+
return (...args:unknown[]) => console.error(
56+
"@reforged/maker-appimage %o: %s",
57+
process.pid,
58+
format(...args)
59+
);
60+
// NO-OP function
61+
return () => {};
62+
})()
4963

5064
/**
5165
* An AppImage maker for Electron Forge.
@@ -90,8 +104,9 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
90104
override requiredExternalBinaries:["mksquashfs"] = ["mksquashfs"];
91105
override isSupportedOnCurrentPlatform:()=>true = ()=>true;
92106
override async make({
93-
appName, dir, makeDir, packageJSON, targetArch
107+
appName, dir, makeDir, packageJSON, targetArch, forgeConfig:forge
94108
}: MakerMeta, ...vendorExt: unknown[]): Promise<[AppImagePath:string]> {
109+
d("Initializing maker metadata.")
95110
const {
96111
actions, categories, compressor, genericName, flagsFile, type2runtime
97112
} = (this.config.options ?? {});
@@ -149,6 +164,7 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
149164
runtime: Object.freeze({
150165
data: fetch(parseMirror(`${remote.mirror.runtime}${remote.dir}/${remote.file}`,currentTag,"runtime"))
151166
.then(response => {
167+
d("Fetched AppImage runtime from mirror.")
152168
if(response.ok)
153169
return response.arrayBuffer()
154170
else
@@ -160,6 +176,7 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
160176
AppRun: Object.freeze({
161177
data: fetch(parseMirror(`${remote.mirror.AppRun}${remote.dir}/${remote.file}`,currentTag,"AppRun"))
162178
.then(response => {
179+
d("Fetched AppImage AppRun from mirror.")
163180
if(response.ok)
164181
return response.arrayBuffer()
165182
else
@@ -240,6 +257,7 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
240257
)
241258
}
242259
const iconPath = icon ? resolve(workDir, name+extname(icon)) : undefined;
260+
d("Queuing asynchronous jobs batches.")
243261
/** First-step jobs, which does not depend on any other job. */
244262
const earlyJobs = [
245263
// Create further directory tree (0,1,2)
@@ -249,9 +267,9 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
249267
.then(path => path ? mkdir(path, {recursive: true, mode: 0o755}).then(() => path) : undefined),
250268
// Save `.desktop` to file (3)
251269
sources.desktop
252-
.then(data => writeFile(
270+
.then(data => (d("Writing '.desktop' file to 'workDir'."),writeFile(
253271
resolve(workDir, productName+'.desktop'), data, {mode:0o755, encoding: "utf-8"})
254-
),
272+
)),
255273
// Verify and save `AppRun` to file (4)
256274
sources.AppRun.data
257275
.then(data => {
@@ -265,6 +283,7 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
265283
if(hash !== sources.AppRun.md5)
266284
throw new Error("AppRun hash mismatch.");
267285
}
286+
d("Writing AppRun to file.")
268287
return writeFile(resolve(workDir, 'AppRun'), buffer, {mode: 0o755});
269288
}),
270289
// Save icon to file and symlink it as `.DirIcon` (5)
@@ -284,7 +303,7 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
284303
}),
285304
// Copy Electron app to AppImage directories
286305
earlyJobs[0]
287-
.then(() => copyPath(dir, directories.data, 0o755)),
306+
.then(() => (d("Copying Electron app data."),copyPath(dir, directories.data, 0o755))),
288307
// Copy icon to `usr` directory whenever possible
289308
Promise.all([earlyJobs[2],earlyJobs[5]])
290309
.then(([path]) => icon && path ?
@@ -294,8 +313,10 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
294313
// Ensure that root folder has proper file mode
295314
chmod(workDir, 0o755)
296315
] as const;
316+
d("Waiting for queued jobs to finish.")
297317
// Wait for early/late jobs to finish
298318
await(Promise.all([...earlyJobs,...lateJobs]));
319+
d("Preparing 'mksquashfs' arguments for data image generation.")
299320
// Run `mksquashfs` and wait for it to finish
300321
const mkSquashFsArgs = [workDir, outFile];
301322
const mkSquashFsVer = getSquashFsVer();
@@ -325,6 +346,7 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
325346
"-b",
326347
"16384"
327348
);
349+
d("Queuing 'mksquashfs' task.")
328350
await new Promise((resolve, reject) => {
329351
this.ensureFile(outFile).then(() => {
330352
const evtCh = mkSquashFs(...mkSquashFsArgs)
@@ -340,6 +362,7 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
340362
evtCh.on("progress", percent => vndCh.emit("progress", percent));
341363
}).catch(error => reject(error));
342364
});
365+
d("Merging AppImage data and runtime into single file.")
343366
// Append runtime to SquashFS image and wait for that task to finish
344367
await sources.runtime.data
345368
//TODO: Find how properly embed MD5 or SHA256 signatures

0 commit comments

Comments
 (0)