Skip to content

Commit 418355b

Browse files
committed
fix: fix compatibility with latest versions of ts-node
TSError now sets diagnosticText to be non-enumerable so we need to grab it manually In 10.5.0 ts-node added a new config option tsTrace which is a function. Functions are not serializable so we need to filter functions out.
1 parent 5eaee3c commit 418355b

File tree

8 files changed

+57
-137
lines changed

8 files changed

+57
-137
lines changed

package-lock.json

Lines changed: 36 additions & 130 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/build/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"strip-ansi": "^7.0.0",
104104
"supports-color": "^9.0.0",
105105
"tmp-promise": "^3.0.2",
106-
"ts-node": "10.4.0",
106+
"ts-node": "^10.6.0",
107107
"typescript": "^4.5.4",
108108
"update-notifier": "^5.0.0",
109109
"uuid": "^8.0.0",

packages/build/src/error/build.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ const assignErrorProp = function (error, name, value) {
3434
}
3535

3636
// Inverse of `jsonToError()`.
37-
export const errorToJson = function ({ name, message, stack, [CUSTOM_ERROR_KEY]: customError, ...errorProps }) {
37+
export const errorToJson = function (error) {
38+
const { name, message, stack, [CUSTOM_ERROR_KEY]: customError, ...errorProps } = error
39+
40+
// diagnosticText is not enumerable in TSError so we need to grab it manually. destructuring won't work.
41+
if (error.diagnosticText) {
42+
// eslint-disable-next-line fp/no-mutation
43+
errorProps.diagnosticText = error.diagnosticText
44+
}
45+
3846
return {
3947
...safeJsonStringify.ensureProperties(errorProps),
4048
...safeJsonStringify.ensureProperties({ name, message, stack, [CUSTOM_ERROR_KEY]: customError }),

packages/build/src/plugins/child/typescript.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ export const addTsErrorInfo = function (error, tsNodeService) {
2727
config: {
2828
raw: { compilerOptions },
2929
},
30-
options: tsNodeOptions,
30+
options: realTsNodeOptions,
3131
} = tsNodeService
32+
33+
// filter out functions as they cannot be serialized
34+
const tsNodeOptions = Object.fromEntries(
35+
Object.entries(realTsNodeOptions).filter(([, val]) => typeof val !== 'function'),
36+
)
37+
3238
addErrorInfo(error, { tsConfig: { compilerOptions, tsNodeOptions } })
3339
}
3440

packages/build/tests/monitor/snapshots/tests.js.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -970,9 +970,9 @@ Generated by [AVA](https://avajs.dev).
970970
971971
Error properties␊
972972
{␊
973+
diagnosticCodes: [ 2307, 7031 ],␊
973974
diagnosticText: "plugin.ts(1,28): error TS2307: Cannot find module '@netlify/build' or its corresponding type declarations./n" +␊
974-
"plugin.ts(3,51): error TS7031: Binding element 'constants' implicitly has an 'any' type./n",␊
975-
diagnosticCodes: [ 2307, 7031 ]␊
975+
"plugin.ts(3,51): error TS7031: Binding element 'constants' implicitly has an 'any' type./n"␊
976976
}␊
977977
978978
Resolved config␊
2 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)