From 17ef4a2a7af181d3445127ecf1b293c902dbd618 Mon Sep 17 00:00:00 2001 From: Alois Klink <alois@mermaidchart.com> Date: Tue, 28 Nov 2023 15:17:35 +0000 Subject: [PATCH 1/3] ci(build): run GitHub Actions on MacOS and Windows --- .github/workflows/build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5eebca4..22c1819 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,8 +10,9 @@ jobs: matrix: node: ['18.18.x'] pkg: ['sdk', 'cli'] + os: [ubuntu-latest, windows-latest, macos-latest] runs-on: - labels: ubuntu-latest + labels: ${{ matrix.os }} steps: - name: Checkout uses: actions/checkout@v4 From 79451c15383a7628802afa66a3457829234a5780 Mon Sep 17 00:00:00 2001 From: Alois Klink <alois@mermaidchart.com> Date: Mon, 22 Apr 2024 18:50:42 +0900 Subject: [PATCH 2/3] fix(cli): handle frontmatter ending with CRLF MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Windows, lines usually end with `\r\n`/CRLF/␍␊. Although YAML supports this as a line-break, our regex was incorrectly breaking this up, which was causing the `\r` character to be appending into some strings, instead of `\r\n`. --- packages/cli/src/frontmatter.spec.ts | 10 ++++++++++ packages/cli/src/frontmatter.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 packages/cli/src/frontmatter.spec.ts diff --git a/packages/cli/src/frontmatter.spec.ts b/packages/cli/src/frontmatter.spec.ts new file mode 100644 index 0000000..f40ed13 --- /dev/null +++ b/packages/cli/src/frontmatter.spec.ts @@ -0,0 +1,10 @@ +import { describe, expect, it } from 'vitest'; +import { extractFrontMatter } from './frontmatter.js'; + +describe('extractFrontMatter()', () => { + it(String.raw`should handle \r\n (␍␊)`, () => { + const text = '---\r\nid: test\r\n---\r\ninfo\r\n'; + const result = extractFrontMatter(text); + expect(result.metadata.id).toBe('test'); + }); +}); diff --git a/packages/cli/src/frontmatter.ts b/packages/cli/src/frontmatter.ts index eb72aaa..49cbbf4 100644 --- a/packages/cli/src/frontmatter.ts +++ b/packages/cli/src/frontmatter.ts @@ -3,7 +3,7 @@ */ import { parseDocument, type Document, YAMLMap, isMap } from 'yaml'; -const frontMatterRegex = /^-{3}\s*[\n\r](.*?)[\n\r]-{3}\s*[\n\r]+/s; +const frontMatterRegex = /^-{3}\s*[\n\r](.*?[\n\r])-{3}\s*[\n\r]+/s; const urlIDRegex = /(?<baseURL>.*)\/d\/(?<documentID>[\w-]+)/; type UrlID = `${string}/d/${string}`; From dce5bfaa7f4f64d77fd372b269784b0d0508f83c Mon Sep 17 00:00:00 2001 From: Alois Klink <alois@mermaidchart.com> Date: Tue, 23 Apr 2024 14:50:11 +0900 Subject: [PATCH 3/3] test(cli): handle CRLF in test fixture files On Windows, files are normally checked-out with `git config core.autocrlf true`, which will replace `'\n'`/LF chars with `'\r\n'`/CRLF chars. We should handle this in our unit tests, otherwise tests will fail on Windows CI. --- packages/cli/src/commander.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commander.test.ts b/packages/cli/src/commander.test.ts index 9a1f797..0691575 100644 --- a/packages/cli/src/commander.test.ts +++ b/packages/cli/src/commander.test.ts @@ -390,8 +390,10 @@ describe('link', () => { expect(file).toMatch(idLineRegex); // other than the added `id: xxxx` field, everything else should be identical, // although in practice, we'd expect some formatting changes - expect(file.replace(idLineRegex, '')).toStrictEqual( - await readFile(UNUSUAL_MARKDOWN_FILE, { encoding: 'utf8' }), + // + // We also normalize line endings to LF to avoid issues with CRLF on Windows + expect(file.replace(idLineRegex, '').replaceAll('\r\n', '\n')).toStrictEqual( + (await readFile(UNUSUAL_MARKDOWN_FILE, { encoding: 'utf8' })).replaceAll('\r\n', '\n'), ); }); });