Skip to content

Commit

Permalink
fix: fix compatibility with latest versions of ts-node
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danez committed Jun 9, 2022
1 parent 5eaee3c commit 1663b1d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 135 deletions.
166 changes: 36 additions & 130 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"strip-ansi": "^7.0.0",
"supports-color": "^9.0.0",
"tmp-promise": "^3.0.2",
"ts-node": "10.4.0",
"ts-node": "^10.6.0",
"typescript": "^4.5.4",
"update-notifier": "^5.0.0",
"uuid": "^8.0.0",
Expand Down
10 changes: 9 additions & 1 deletion packages/build/src/error/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ const assignErrorProp = function (error, name, value) {
}

// Inverse of `jsonToError()`.
export const errorToJson = function ({ name, message, stack, [CUSTOM_ERROR_KEY]: customError, ...errorProps }) {
export const errorToJson = function (error) {
const { name, message, stack, [CUSTOM_ERROR_KEY]: customError, ...errorProps } = error

// diagnosticText is not enumerable in TSError so we need to grab it manually. destructuring won't work.
if (error.diagnosticText) {
// eslint-disable-next-line fp/no-mutation
errorProps.diagnosticText = error.diagnosticText
}

return {
...safeJsonStringify.ensureProperties(errorProps),
...safeJsonStringify.ensureProperties({ name, message, stack, [CUSTOM_ERROR_KEY]: customError }),
Expand Down
8 changes: 7 additions & 1 deletion packages/build/src/plugins/child/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ export const addTsErrorInfo = function (error, tsNodeService) {
config: {
raw: { compilerOptions },
},
options: tsNodeOptions,
options: realTsNodeOptions,
} = tsNodeService

// filter out functions as they cannot be serialized
const tsNodeOptions = Object.fromEntries(
Object.entries(realTsNodeOptions).filter(([, val]) => typeof val !== 'function'),
)

addErrorInfo(error, { tsConfig: { compilerOptions, tsNodeOptions } })
}

Expand Down
4 changes: 2 additions & 2 deletions packages/build/tests/plugins/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -2519,8 +2519,8 @@ Generated by [AVA](https://avajs.dev).
Error properties␊
{␊
diagnosticText: 'plugin.ts(8,3): error TS2554: Expected 1-2 arguments, but got 0./n',␊
diagnosticCodes: [ 2554 ]
diagnosticCodes: [ 2554 ],␊
diagnosticText: 'plugin.ts(8,3): error TS2554: Expected 1-2 arguments, but got 0./n'
}␊
Resolved config␊
Expand Down
Binary file modified packages/build/tests/plugins/snapshots/tests.js.snap
Binary file not shown.

0 comments on commit 1663b1d

Please sign in to comment.