Skip to content
Closed
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
5 changes: 4 additions & 1 deletion src/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
import { run } from "@stricli/core";
import { buildContext } from "~/context";
import { app } from "~/app";
await run(app, process.argv.slice(2), buildContext(process));
const plainOutput = process.argv.includes("--plain-output");
const inputs = process.argv.slice(2).filter((arg) => arg !== "--plain-output");

await run(app, inputs, buildContext(process, plainOutput));
11 changes: 8 additions & 3 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface Context extends CommandContext {
readonly fetch: typeof globalThis.fetch;
readonly open: typeof open;
readonly http: typeof http;
readonly makeTaskLogger: TaskLogger;
makeTaskLogger: TaskLogger;
readonly env: ParsedEnv;
}

Expand All @@ -50,7 +50,10 @@ export async function exists(
}
}

export function buildContext(process: NodeJS.Process): Context {
export function buildContext(
process: NodeJS.Process,
plainOutput = false,
): Context {
const env = getParsedEnv();
return {
process,
Expand All @@ -63,6 +66,8 @@ export function buildContext(process: NodeJS.Process): Context {
path,
fetch,
makeTaskLogger:
env.NO_COLOR === true ? plainTaskLogger() : fancyTaskLogger(),
plainOutput || env.NO_COLOR === true
? plainTaskLogger()
: fancyTaskLogger(),
};
}
2 changes: 1 addition & 1 deletion src/gm-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export async function readGmOptions(
gmOptions = parseResults.options;
} else {
throw new KnownError(
"Failed to parse 'gm-options.json file. Errors:\n{parseResults.error}",
`Failed to parse 'gm-options.json file. Errors:\n${parseResults.error}`,
);
}

Expand Down
20 changes: 16 additions & 4 deletions src/gms2/install-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,22 @@ export async function installRuntimeIfNeeded(
});
let runtimeLocation = await findRuntimeLocation(ctx, runtimeDir, version);

// FIXME: if this fails, we should delete the runtime dir and try again
const installedModules = runtimeLocation
? await getInstalledRuntimeModules(ctx, runtimeLocation)
: [];
// A runtime directory can be left behind by an interrupted or failed
// installation. In that case receipt.json may be missing or corrupt.
// Treat the cached runtime as invalid and reinstall it instead of failing
// every subsequent build.
let installedModules: Module[] = [];
if (runtimeLocation) {
try {
installedModules = await getInstalledRuntimeModules(ctx, runtimeLocation);
} catch {
log.message(
`Cached runtime at '${runtimeLocation}' is invalid; reinstalling...`,
);
await ctx.fs.rm(runtimeLocation, { recursive: true, force: true });
runtimeLocation = undefined;
}
}

if (runtimeLocation && installedModules.includes(target)) {
log.success("Runtime found");
Expand Down
10 changes: 10 additions & 0 deletions src/gms2/use-gms2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ export async function useGms2(
);
igorAction = action;
extraArgs = ["-tf", targetFile, ...packageArgs];

// Igor uses the build cache output directory for intermediate package files.
// Clear those intermediates before every package operation so a previous
// package with a different output name cannot leave a file that Igor tries
// to move again. See https://github.com/YoYoGames/gm-cli/issues/243.
await ctx.fs.rm(ctx.path.join(buildCacheDir, "output"), {
recursive: true,
force: true,
});

successMessage = `Package created: ${targetFile}`;
}

Expand Down