From 6b543785c89db98e245361876ae62c1d2dda1947 Mon Sep 17 00:00:00 2001 From: Tom Pereira Date: Sun, 9 Feb 2025 13:55:22 +0000 Subject: [PATCH 1/6] support files ignored by babel --- CHANGELOG.md | 3 +++ package.json | 2 +- .../runners/utils/_tests/_transpiler.test.ts | 25 ++++++++++++++++++- source/runner/runners/utils/transpiler.ts | 4 +-- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09d844f42..b532635d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ ## Main +Ensure that [babel ignores](https://babeljs.io/docs/options#ignore) do not cause the transpiler to fall over, by supporting the +`null` return from `loadOptions` which occurs when a file is ignored. ## 12.3.3 @@ -2118,6 +2120,7 @@ Not usable for others, only stubs of classes etc. - [@orta] [@tibdex]: https://github.com/tibdex [@tim3trick]: https://github.com/tim3trick [@thawankeane]: https://github.com/thawankeane +[@tomstrepsil: https://github.com/TomStrepsil] [@tychota]: https://github.com/tychota [@urkle]: https://github.com/urkle [@valscion]: https://github.com/valscion diff --git a/package.json b/package.json index abf85b9bd..c69258bd3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "danger", - "version": "12.3.3", + "version": "12.3.4", "description": "Unit tests for Team Culture", "main": "distribution/danger.js", "typings": "distribution/danger.d.ts", diff --git a/source/runner/runners/utils/_tests/_transpiler.test.ts b/source/runner/runners/utils/_tests/_transpiler.test.ts index f50324c52..6aaf45085 100644 --- a/source/runner/runners/utils/_tests/_transpiler.test.ts +++ b/source/runner/runners/utils/_tests/_transpiler.test.ts @@ -2,13 +2,15 @@ jest.mock("fs", () => ({ readFileSync: jest.fn(), realpathSync: {}, existsSync: jest.fn(), + statSync: jest.fn(), + stat: jest.fn(), })) jest.mock("path", () => { const path = jest.requireActual("path") return { ...path, resolve: jest.fn(path.resolve) } }) -import { typescriptify, lookupTSConfig, dirContains } from "../transpiler" +import { typescriptify, lookupTSConfig, dirContains, babelify } from "../transpiler" import * as fs from "fs" import * as path from "path" @@ -87,3 +89,24 @@ describe("dirContains", () => { }) } }) + +describe("babelify", () => { + it("does not throw when a filepath is ignored due to babel options, and should return the content unchanged", () => { + const dangerfile = "import {a} from 'lodash'; a()" + + const existsSyncMock = fs.existsSync as jest.Mock + const actualFs = jest.requireActual("fs") as typeof fs + existsSyncMock.mockImplementation((path) => path === "/a/b/babel.config.js" || actualFs.existsSync(path)) + jest.mock( + "/a/b/babel.config.js", + () => { + return { ignore: ["/a/b"] } + }, + { virtual: true } + ) + const act = () => babelify(dangerfile, "a/b/", []) + + expect(act).not.toThrow() + expect(act()).toEqual(dangerfile) + }) +}) diff --git a/source/runner/runners/utils/transpiler.ts b/source/runner/runners/utils/transpiler.ts index 15ca593fd..31e74815a 100644 --- a/source/runner/runners/utils/transpiler.ts +++ b/source/runner/runners/utils/transpiler.ts @@ -172,7 +172,7 @@ export const babelify = (content: string, filename: string, extraPlugins: string return content } - const options = babel.loadOptions ? babel.loadOptions({ filename }) : { plugins: [] } + const options = babel.loadOptions?.({ filename: filename }) ?? { plugins: [] } const fileOpts = { filename, @@ -186,7 +186,7 @@ export const babelify = (content: string, filename: string, extraPlugins: string const result = transformSync(content, fileOpts) d("Result from Babel:") d(result) - return result.code + return result?.code ?? content } export default (code: string, filename: string, remoteFile: boolean = false) => { From 3f5a37721450202050f24081042553b9f247c207 Mon Sep 17 00:00:00 2001 From: Tom Pereira Date: Sun, 9 Feb 2025 14:22:39 +0000 Subject: [PATCH 2/6] cater for unexpected linting in ci? --- source/runner/runners/utils/_tests/_transpiler.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/runner/runners/utils/_tests/_transpiler.test.ts b/source/runner/runners/utils/_tests/_transpiler.test.ts index 6aaf45085..657874467 100644 --- a/source/runner/runners/utils/_tests/_transpiler.test.ts +++ b/source/runner/runners/utils/_tests/_transpiler.test.ts @@ -92,7 +92,8 @@ describe("dirContains", () => { describe("babelify", () => { it("does not throw when a filepath is ignored due to babel options, and should return the content unchanged", () => { - const dangerfile = "import {a} from 'lodash'; a()" + const dangerfile = `import { a } from 'lodash'; +a();` const existsSyncMock = fs.existsSync as jest.Mock const actualFs = jest.requireActual("fs") as typeof fs From 3f3aee79beccf5fbf398397696eebf461c57bca5 Mon Sep 17 00:00:00 2001 From: Tom Pereira Date: Sun, 9 Feb 2025 14:57:29 +0000 Subject: [PATCH 3/6] empty commit to re-start ci From 89e6d3e48aac7a7476296a02731a1466b4042a28 Mon Sep 17 00:00:00 2001 From: Tom Pereira Date: Sun, 9 Feb 2025 15:09:29 +0000 Subject: [PATCH 4/6] revert update of package version, assumed this will be resolved during release process --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c69258bd3..abf85b9bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "danger", - "version": "12.3.4", + "version": "12.3.3", "description": "Unit tests for Team Culture", "main": "distribution/danger.js", "typings": "distribution/danger.d.ts", From feebb9134479e1cec024f81b1390b99b10bd571c Mon Sep 17 00:00:00 2001 From: Tom Pereira Date: Sun, 9 Feb 2025 15:09:52 +0000 Subject: [PATCH 5/6] lint --- source/platforms/_tests/fixtures/bbc-dsl-input.json | 3 ++- source/platforms/_tests/fixtures/bbs-dsl-input.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source/platforms/_tests/fixtures/bbc-dsl-input.json b/source/platforms/_tests/fixtures/bbc-dsl-input.json index ef8bdfae5..d24a73674 100644 --- a/source/platforms/_tests/fixtures/bbc-dsl-input.json +++ b/source/platforms/_tests/fixtures/bbc-dsl-input.json @@ -2542,7 +2542,8 @@ "settings": { "github": { "accessToken": "12345", - "additionalHeaders": {} + "additionalHeaders": {}, + "baseURL": "https://api.github.com" }, "cliArgs": {} } diff --git a/source/platforms/_tests/fixtures/bbs-dsl-input.json b/source/platforms/_tests/fixtures/bbs-dsl-input.json index aa8549c62..4f6c6e773 100644 --- a/source/platforms/_tests/fixtures/bbs-dsl-input.json +++ b/source/platforms/_tests/fixtures/bbs-dsl-input.json @@ -1087,7 +1087,8 @@ "settings": { "github": { "accessToken": "12345", - "additionalHeaders": {} + "additionalHeaders": {}, + "baseURL": "https://api.github.com" }, "cliArgs": {} } From c9cce8d143759fe17385b593257e19b3453d71cf Mon Sep 17 00:00:00 2001 From: Tom Pereira Date: Sun, 9 Feb 2025 18:28:05 +0000 Subject: [PATCH 6/6] restore es6 object format (did the lint change this??) --- source/runner/runners/utils/transpiler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/runner/runners/utils/transpiler.ts b/source/runner/runners/utils/transpiler.ts index 31e74815a..46d325b9e 100644 --- a/source/runner/runners/utils/transpiler.ts +++ b/source/runner/runners/utils/transpiler.ts @@ -172,7 +172,7 @@ export const babelify = (content: string, filename: string, extraPlugins: string return content } - const options = babel.loadOptions?.({ filename: filename }) ?? { plugins: [] } + const options = babel.loadOptions?.({ filename }) ?? { plugins: [] } const fileOpts = { filename,