Skip to content

Commit 3e36bde

Browse files
authored
Merge pull request #1476 from TomStrepsil/support_babel_ignores
Support files being ignored by babel configuration
2 parents b07053c + c9cce8d commit 3e36bde

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

Diff for: CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
## Main
1616

1717
<!-- Your comment below this -->
18+
Ensure that [babel ignores](https://babeljs.io/docs/options#ignore) do not cause the transpiler to fall over, by supporting the
19+
`null` return from `loadOptions` which occurs when a file is ignored.
1820
<!-- Your comment above this -->
1921

2022
## 12.3.3
@@ -2118,6 +2120,7 @@ Not usable for others, only stubs of classes etc. - [@orta]
21182120
[@tibdex]: https://github.com/tibdex
21192121
[@tim3trick]: https://github.com/tim3trick
21202122
[@thawankeane]: https://github.com/thawankeane
2123+
[@tomstrepsil: https://github.com/TomStrepsil]
21212124
[@tychota]: https://github.com/tychota
21222125
[@urkle]: https://github.com/urkle
21232126
[@valscion]: https://github.com/valscion

Diff for: source/platforms/_tests/fixtures/bbc-dsl-input.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2542,7 +2542,8 @@
25422542
"settings": {
25432543
"github": {
25442544
"accessToken": "12345",
2545-
"additionalHeaders": {}
2545+
"additionalHeaders": {},
2546+
"baseURL": "https://api.github.com"
25462547
},
25472548
"cliArgs": {}
25482549
}

Diff for: source/platforms/_tests/fixtures/bbs-dsl-input.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,8 @@
10871087
"settings": {
10881088
"github": {
10891089
"accessToken": "12345",
1090-
"additionalHeaders": {}
1090+
"additionalHeaders": {},
1091+
"baseURL": "https://api.github.com"
10911092
},
10921093
"cliArgs": {}
10931094
}

Diff for: source/runner/runners/utils/_tests/_transpiler.test.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ jest.mock("fs", () => ({
22
readFileSync: jest.fn(),
33
realpathSync: {},
44
existsSync: jest.fn(),
5+
statSync: jest.fn(),
6+
stat: jest.fn(),
57
}))
68
jest.mock("path", () => {
79
const path = jest.requireActual("path")
810
return { ...path, resolve: jest.fn(path.resolve) }
911
})
1012

11-
import { typescriptify, lookupTSConfig, dirContains } from "../transpiler"
13+
import { typescriptify, lookupTSConfig, dirContains, babelify } from "../transpiler"
1214
import * as fs from "fs"
1315
import * as path from "path"
1416

@@ -87,3 +89,25 @@ describe("dirContains", () => {
8789
})
8890
}
8991
})
92+
93+
describe("babelify", () => {
94+
it("does not throw when a filepath is ignored due to babel options, and should return the content unchanged", () => {
95+
const dangerfile = `import { a } from 'lodash';
96+
a();`
97+
98+
const existsSyncMock = fs.existsSync as jest.Mock
99+
const actualFs = jest.requireActual("fs") as typeof fs
100+
existsSyncMock.mockImplementation((path) => path === "/a/b/babel.config.js" || actualFs.existsSync(path))
101+
jest.mock(
102+
"/a/b/babel.config.js",
103+
() => {
104+
return { ignore: ["/a/b"] }
105+
},
106+
{ virtual: true }
107+
)
108+
const act = () => babelify(dangerfile, "a/b/", [])
109+
110+
expect(act).not.toThrow()
111+
expect(act()).toEqual(dangerfile)
112+
})
113+
})

Diff for: source/runner/runners/utils/transpiler.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export const babelify = (content: string, filename: string, extraPlugins: string
172172
return content
173173
}
174174

175-
const options = babel.loadOptions ? babel.loadOptions({ filename }) : { plugins: [] }
175+
const options = babel.loadOptions?.({ filename }) ?? { plugins: [] }
176176

177177
const fileOpts = {
178178
filename,
@@ -186,7 +186,7 @@ export const babelify = (content: string, filename: string, extraPlugins: string
186186
const result = transformSync(content, fileOpts)
187187
d("Result from Babel:")
188188
d(result)
189-
return result.code
189+
return result?.code ?? content
190190
}
191191

192192
export default (code: string, filename: string, remoteFile: boolean = false) => {

0 commit comments

Comments
 (0)