Skip to content

Commit 086398b

Browse files
committed
Merge tag '1.2.13' into 1.3-maintenance
Fedify 1.2.13
2 parents b2ce0c8 + a9d4f22 commit 086398b

File tree

5 files changed

+119
-22
lines changed

5 files changed

+119
-22
lines changed

.github/workflows/build.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ jobs:
166166
- run: 'cat "$CHANGES_FILE"'
167167
env:
168168
CHANGES_FILE: ${{ steps.extract-changelog.outputs.output-file }}
169+
- uses: actions/upload-artifact@v4
170+
with:
171+
name: dist
172+
path: |
173+
src/npm/*.tgz
174+
cli/fedify-cli-*
169175
- if: github.event_name == 'push' && github.ref_type == 'tag'
170176
uses: softprops/action-gh-release@v1
171177
with:

CHANGES.md

+48
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ Version 1.3.9
88

99
To be released.
1010

11+
- Fixed a bug where the `fedify init` command had failed to locate package
12+
managers on Windows. [[#210]]
13+
14+
- The `fedify` command became aware of `FEDIFY_LOG_FILE` environment variable
15+
to log messages to a file. If the variable is set, the command logs
16+
messages to the file specified by the variable.
17+
1118

1219
Version 1.3.8
1320
-------------
@@ -223,6 +230,19 @@ Released on November 30, 2024.
223230
[#193]: https://github.com/fedify-dev/fedify/issues/193
224231

225232

233+
Version 1.2.13
234+
--------------
235+
236+
Released on February 19, 2025.
237+
238+
- Fixed a bug where the `fedify init` command had failed to locate package
239+
managers on Windows. [[#210]]
240+
241+
- The `fedify` command became aware of `FEDIFY_LOG_FILE` environment variable
242+
to log messages to a file. If the variable is set, the command logs
243+
messages to the file specified by the variable.
244+
245+
226246
Version 1.2.12
227247
--------------
228248

@@ -483,6 +503,19 @@ Released on October 31, 2024.
483503
[#118]: https://github.com/fedify-dev/fedify/issues/118
484504

485505

506+
Version 1.1.13
507+
--------------
508+
509+
Released on February 19, 2025.
510+
511+
- Fixed a bug where the `fedify init` command had failed to locate package
512+
managers on Windows. [[#210]]
513+
514+
- The `fedify` command became aware of `FEDIFY_LOG_FILE` environment variable
515+
to log messages to a file. If the variable is set, the command logs
516+
messages to the file specified by the variable.
517+
518+
486519
Version 1.1.12
487520
--------------
488521

@@ -784,6 +817,21 @@ Released on October 20, 2024.
784817
[#150]: https://github.com/fedify-dev/fedify/issues/150
785818

786819

820+
Version 1.0.16
821+
--------------
822+
823+
Released on February 19, 2025.
824+
825+
- Fixed a bug where the `fedify init` command had failed to locate package
826+
managers on Windows. [[#210]]
827+
828+
- The `fedify` command became aware of `FEDIFY_LOG_FILE` environment variable
829+
to log messages to a file. If the variable is set, the command logs
830+
messages to the file specified by the variable.
831+
832+
[#210]: https://github.com/fedify-dev/fedify/issues/210
833+
834+
787835
Version 1.0.15
788836
--------------
789837

cli/init.ts

+34-13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { basename, dirname, join, normalize } from "@std/path";
88
import { format, greaterThan, parse } from "@std/semver";
99
import metadata from "./deno.json" with { type: "json" };
1010

11+
const logger = getLogger(["fedify", "cli", "init"]);
12+
1113
type Runtime = "deno" | "bun" | "node";
1214

1315
interface RuntimeDescription {
@@ -67,11 +69,11 @@ const packageManagers: Record<PackageManager, PackageManagerDescription> = {
6769
},
6870
};
6971

70-
const packageManagerAvailabilities: Record<PackageManager, boolean> = Object
71-
.fromEntries(
72+
const packageManagerLocations: Record<PackageManager, string | undefined> =
73+
Object.fromEntries(
7274
await Promise.all(
7375
(Object.keys(packageManagers) as PackageManager[])
74-
.map(async (pm) => [pm, await isPackageManagerAvailable(pm)]),
76+
.map(async (pm) => [pm, await locatePackageManager(pm)]),
7577
),
7678
);
7779

@@ -566,8 +568,6 @@ const messageQueues: Record<MessageQueue, MessageQueueDescription> = {
566568
},
567569
} as const;
568570

569-
const logger = getLogger(["fedify", "cli", "init"]);
570-
571571
export const command = new Command()
572572
.type(
573573
"runtime",
@@ -581,7 +581,7 @@ export const command = new Command()
581581
"package-manager",
582582
new EnumType(
583583
(Object.keys(packageManagers) as PackageManager[]).filter((pm) =>
584-
packageManagerAvailabilities[pm]
584+
packageManagerLocations[pm]
585585
),
586586
),
587587
)
@@ -763,7 +763,7 @@ export const command = new Command()
763763
);
764764
Deno.exit(1);
765765
}
766-
if (runtime === "node" && !packageManagerAvailabilities[packageManager]) {
766+
if (runtime === "node" && !packageManagerLocations[packageManager]) {
767767
console.error(`The ${packageManager} is not available on this system.`);
768768
Deno.exit(1);
769769
}
@@ -1306,19 +1306,40 @@ async function isCommandAvailable(
13061306
try {
13071307
const output = await cmd.output();
13081308
const stdout = new TextDecoder().decode(output.stdout);
1309+
logger.debug(
1310+
"The stdout of the command {command} is: {stdout}",
1311+
{ command: checkCommand, stdout },
1312+
);
13091313
return outputPattern.exec(stdout.trim()) ? true : false;
1310-
} catch (e) {
1311-
if (e instanceof Deno.errors.NotFound) return false;
1312-
throw e;
1314+
} catch (error) {
1315+
logger.debug(
1316+
"The command {command} failed with the error: {error}",
1317+
{ command: checkCommand, error },
1318+
);
1319+
if (error instanceof Deno.errors.NotFound) return false;
1320+
throw error;
13131321
}
13141322
}
13151323

13161324
function isRuntimeAvailable(runtime: Runtime): Promise<boolean> {
13171325
return isCommandAvailable(runtimes[runtime]);
13181326
}
13191327

1320-
function isPackageManagerAvailable(pm: PackageManager): Promise<boolean> {
1321-
return isCommandAvailable(packageManagers[pm]);
1328+
async function locatePackageManager(
1329+
pm: PackageManager,
1330+
): Promise<string | undefined> {
1331+
if (await isCommandAvailable(packageManagers[pm])) {
1332+
return packageManagers[pm].checkCommand[0];
1333+
}
1334+
if (Deno.build.os !== "windows") return undefined;
1335+
const cmd: [string, ...string[]] = [
1336+
packageManagers[pm].checkCommand[0] + ".cmd",
1337+
...packageManagers[pm].checkCommand.slice(1),
1338+
];
1339+
if (await isCommandAvailable({ ...packageManagers[pm], checkCommand: cmd })) {
1340+
return cmd[0];
1341+
}
1342+
return undefined;
13221343
}
13231344

13241345
async function addDependencies(
@@ -1344,7 +1365,7 @@ async function addDependencies(
13441365
);
13451366
if (deps.length < 1) return;
13461367
const cmd = new Deno.Command(
1347-
runtime === "node" ? pm : runtime,
1368+
runtime === "node" ? (packageManagerLocations[pm] ?? pm) : runtime,
13481369
{
13491370
args: [
13501371
"add",

cli/log.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {
22
configure,
33
getConsoleSink,
4+
getFileSink,
45
type LogRecord,
56
type Sink,
67
} from "@logtape/logtape";
8+
import { dirname } from "@std/path";
79
import { AsyncLocalStorage } from "node:async_hooks";
810

911
export interface RecordingSink extends Sink {
@@ -31,19 +33,28 @@ export function getRecordingSink(): RecordingSink {
3133

3234
export const recordingSink = getRecordingSink();
3335

36+
export const logFile = Deno.env.get("FEDIFY_LOG_FILE");
37+
if (logFile != null) {
38+
await Deno.mkdir(dirname(logFile), { recursive: true });
39+
}
40+
3441
await configure({
35-
sinks: { console: getConsoleSink(), recording: recordingSink },
42+
sinks: {
43+
console: getConsoleSink(),
44+
recording: recordingSink,
45+
file: logFile == null ? () => undefined : getFileSink(logFile),
46+
},
3647
filters: {},
3748
loggers: [
3849
{
3950
category: "fedify",
4051
lowestLevel: "debug",
41-
sinks: ["recording"],
52+
sinks: ["recording", "file"],
4253
},
4354
{
4455
category: ["logtape", "meta"],
4556
lowestLevel: "warning",
46-
sinks: ["console"],
57+
sinks: ["console", "file"],
4758
},
4859
],
4960
contextLocalStorage: new AsyncLocalStorage(),

cli/mod.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,48 @@
11
import { Command, CompletionsCommand, HelpCommand } from "@cliffy/command";
2-
import { configure, getConsoleSink } from "@logtape/logtape";
2+
import { configure, getConsoleSink, getFileSink } from "@logtape/logtape";
33
import { DEFAULT_CACHE_DIR, setCacheDir } from "./cache.ts";
44
import metadata from "./deno.json" with { type: "json" };
55
import { command as inbox } from "./inbox.tsx";
66
import { command as init } from "./init.ts";
7-
import { recordingSink } from "./log.ts";
7+
import { logFile, recordingSink } from "./log.ts";
88
import { command as lookup } from "./lookup.ts";
99
import { command as node } from "./node.ts";
1010
import { command as tunnel } from "./tunnel.ts";
1111

1212
const command = new Command()
1313
.name("fedify")
1414
.version(metadata.version)
15+
.globalEnv(
16+
"FEDIFY_LOG_FILE=<file:file>",
17+
"An optional file to write logs to. " +
18+
"Regardless of -d/--debug option, " +
19+
"all levels of logs are written to this file. " +
20+
"Note that this does not mute console logs.",
21+
)
1522
.globalOption("-d, --debug", "Enable debug mode.", {
1623
async action() {
1724
await configure({
18-
sinks: { console: getConsoleSink(), recording: recordingSink },
25+
sinks: {
26+
console: getConsoleSink(),
27+
recording: recordingSink,
28+
file: logFile == null ? () => undefined : getFileSink(logFile),
29+
},
1930
filters: {},
2031
loggers: [
2132
{
2233
category: "fedify",
2334
lowestLevel: "debug",
24-
sinks: ["console", "recording"],
35+
sinks: ["console", "recording", "file"],
2536
},
2637
{
2738
category: "localtunnel",
2839
lowestLevel: "debug",
29-
sinks: ["console"],
40+
sinks: ["console", "file"],
3041
},
3142
{
3243
category: ["logtape", "meta"],
3344
lowestLevel: "warning",
34-
sinks: ["console"],
45+
sinks: ["console", "file"],
3546
},
3647
],
3748
reset: true,

0 commit comments

Comments
 (0)