Skip to content
Open
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
8 changes: 4 additions & 4 deletions dist/azure/index.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/gitlab/index.mjs

Large diffs are not rendered by default.

25 changes: 23 additions & 2 deletions src/azure/commands.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vite-plus/test";
import { escapeLoggingCommandData } from "./commands.js";
import { describe, expect, it, vi } from "vite-plus/test";
import { escapeLoggingCommandData, logError, logInfo } from "./commands.js";

describe("escapeLoggingCommandData", () => {
it("escapes characters that could terminate logging commands", () => {
Expand Down Expand Up @@ -36,3 +36,24 @@ describe("Azure logging commands", () => {
}
});
});

describe("Azure plain diagnostics", () => {
it.each([
[logInfo, "log"],
[logError, "error"],
] as const)("neutralizes command prefixes in %s", (log, method) => {
const output = vi.spyOn(console, method).mockImplementation(() => {});
try {
log("Resolved Node.js version '22.23.1' from package.json");
log("Inline ##vso[ marker\r\n##[ formatting marker");

expect(output).toHaveBeenNthCalledWith(
1,
"Resolved Node.js version '22.23.1' from package.json",
);
expect(output).toHaveBeenNthCalledWith(2, "Inline # #vso[ marker\r\n# #[ formatting marker");
} finally {
output.mockRestore();
}
});
});
13 changes: 12 additions & 1 deletion src/azure/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ export function logWarning(message: string): void {
process.stdout.write(`##vso[task.logissue type=warning]${escapeLoggingCommandData(message)}\n`);
}

const LOGGING_COMMAND_PREFIX_RE = /##(?=vso\[|\[)/g;

// The Azure agent scans the entire output line, including text after a log prefix.
function escapePlainLog(message: string): string {
return message.replaceAll(LOGGING_COMMAND_PREFIX_RE, "# #");
}

export function logInfo(message: string): void {
console.log(message);
console.log(escapePlainLog(message));
}

export function logError(message: string): void {
console.error(escapePlainLog(message));
}
8 changes: 4 additions & 4 deletions src/azure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { getCommandOutput, run } from "../ci/process.js";
import { parseRunInstall, runInstall } from "../ci/run-install.js";
import { parseInstalledVpVersion } from "../ci/version.js";
import { ENV_CURRENT_ARGS, readEnvCurrent } from "../ci/env-current.js";
import { logInfo, logWarning, prependPath, setVariable } from "./commands.js";
import { logError, logInfo, logWarning, prependPath, setVariable } from "./commands.js";
import { installVitePlus } from "./install-viteplus.js";
import { parseAzureInputs, resolveProjectDirFromInputs } from "./inputs.js";

Expand Down Expand Up @@ -243,7 +243,7 @@ export async function main(phase: string): Promise<void> {
await runFinalize();
return;
}
fail(`invalid phase "${String(phase)}"; expected "prepare" or "finalize"`);
fail(`invalid phase "${phase}"; expected "prepare" or "finalize"`, logError);
}

export function isEntrypoint(argvPath = process.argv[1], moduleUrl = import.meta.url): boolean {
Expand All @@ -253,7 +253,7 @@ export function isEntrypoint(argvPath = process.argv[1], moduleUrl = import.meta
if (isEntrypoint()) {
const phase = process.argv[2];
if (!phase) {
fail('missing phase argument; expected "prepare" or "finalize"');
fail('missing phase argument; expected "prepare" or "finalize"', logError);
}
await main(phase).catch(fail);
await main(phase).catch((error: unknown) => fail(error, logError));
}
5 changes: 3 additions & 2 deletions src/ci/entrypoint.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import path from "node:path";
import { pathToFileURL } from "node:url";
import type { LogFn } from "./types.js";

export function matchesEntrypoint(argvPath: string | undefined, moduleUrl: string): boolean {
return Boolean(argvPath && moduleUrl === pathToFileURL(path.resolve(argvPath)).href);
}

export function fail(error: unknown): never {
console.error(`setup-vp: ${error instanceof Error ? error.message : String(error)}`);
export function fail(error: unknown, log: LogFn = console.error): never {
log(`setup-vp: ${error instanceof Error ? error.message : String(error)}`);
process.exit(1);
}
Loading