diff --git a/src/docker/piWebDockerDocs.test.ts b/src/docker/piWebDockerDocs.test.ts index 682f112..3dbc3d8 100644 --- a/src/docker/piWebDockerDocs.test.ts +++ b/src/docker/piWebDockerDocs.test.ts @@ -48,7 +48,8 @@ describe("pi-web-docker documentation", () => { }); function readDockerCommandMatrix(dockerReadme: string): string[] { - const commandMatrixSection = dockerReadme.split("### Command matrix\n")[1]?.split("\n### Installer options")[0] ?? ""; + const normalizedReadme = normalizeLineEndings(dockerReadme); + const commandMatrixSection = normalizedReadme.split("### Command matrix\n")[1]?.split("\n### Installer options")[0] ?? ""; return Array.from(commandMatrixSection.matchAll(/^\| `([^`]+)` \|/gm), (match) => { const command = match[1]; if (command === undefined) throw new Error("Docker command matrix row did not include a command"); @@ -57,7 +58,8 @@ function readDockerCommandMatrix(dockerReadme: string): string[] { } function readEntrypointCommandCases(dockerEntrypoint: string): Set { - const commandCaseBlock = dockerEntrypoint.slice(dockerEntrypoint.indexOf('case "$command_name" in')); + const normalizedEntrypoint = normalizeLineEndings(dockerEntrypoint); + const commandCaseBlock = normalizedEntrypoint.slice(normalizedEntrypoint.indexOf('case "$command_name" in')); const commandCases = new Set(); for (const line of commandCaseBlock.split("\n")) { const match = /^ {2}([a-z][a-z-]*(?:\|[a-z][a-z-]*)*)(?:\|__run-detached)?\)$/.exec(line); @@ -67,6 +69,10 @@ function readEntrypointCommandCases(dockerEntrypoint: string): Set { return commandCases; } +function normalizeLineEndings(content: string): string { + return content.replace(/\r\n?/g, "\n"); +} + async function readRepoFile(relativePath: string): Promise { return await readFile(join(repoRoot, relativePath), "utf8"); }