我试图为ts-node-dev
的输出编写一个简单的问题匹配器,但由于某种原因VSCode从未检测到输出中的问题。
下面是我想要匹配的终端输出;它包含一条错误消息和一个堆栈跟踪。我从VSCode的终端窗格中的任务输出中复制了它:
Please migrate your code to use AWS SDK for JavaScript (v3).
For more information, check the migration guide at https://a.co/7PzMCcy
(Use `node --trace-warnings ...` to show where the warning was created)
[INFO] 15:58:00 Restarting: /Users/myname/dev/workspaces/ts_workspace/code/api/src/graphql/schemas/dataDiagnostic.ts has been modified
trying to use docker executor...but configured as cannot.
Error: Unknown type "DataDiagnosticSverity". Did you mean "DataDiagnosticSeverity", "DataDiagnosticEdge", "DataDiagnostic", or "DataDiagnosticConnection"?
at assertValidSDL (/Users/myname/dev/workspaces/ts_workspace/code/node_modules/graphql/validation/validate.js:135:11)
at buildASTSchema (/Users/myname/dev/workspaces/ts_workspace/code/node_modules/graphql/utilities/buildASTSchema.js:44:34)
at makeExecutableSchema (/Users/myname/dev/workspaces/ts_workspace/code/node_modules/@graphql-tools/schema/cjs/makeExecutableSchema.js:73:47)
at Object.<anonymous> (/Users/myname/dev/workspaces/ts_workspace/code/api/src/apolloServer.ts:12:36)
at Module._compile (node:internal/modules/cjs/loader:1155:14)
at Module._compile (/Users/myname/dev/workspaces/ts_workspace/code/node_modules/source-map-support/source-map-support.js:568:25)
at Module.m._compile (/private/var/folders/fr/gxs3qpcs2zxby__p9lm9h_rm0000gn/T/ts-node-dev-hook-6064780755344261.js:69:33)
at Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
at require.extensions..jsx.require.extensions..js (/private/var/folders/fr/gxs3qpcs2zxby__p9lm9h_rm0000gn/T/ts-node-dev-hook-6064780755344261.js:114:20)
at require.extensions.<computed> (/private/var/folders/fr/gxs3qpcs2zxby__p9lm9h_rm0000gn/T/ts-node-dev-hook-6064780755344261.js:71:20)
[ERROR] 15:58:01 Error: Unknown type "DataDiagnosticSverity". Did you mean "DataDiagnosticSeverity", "DataDiagnosticEdge", "DataDiagnostic", or "DataDiagnosticConnection"?
(node:54671) NOTE: We are formalizing our plans to enter AWS SDK for JavaScript (v2) into maintenance mode in 2023.
下面是给出上述输出的任务的problemMatcher:
"problemMatcher": [
{
"fileLocation": "absolute",
"pattern": {
"regexp": "^(Error|Warning):\s*(.*)[\n\r]+\s+at\s+(.*)\s+\((.*):(\d+):(\d+)\)",
"severity": 1,
"message": 2,
"file": 4,
"line": 5,
"column": 6
}
}
]
我在regex101.com上设计了正则表达式,然后通过JSON转义器传递它以获得所需的额外斜杠。您可以在这里看到regex与它的所有捕获一起正确地工作。我还将输出粘贴到VSCode中,并手动运行正则表达式以确保它在那里匹配。
尽管如此,当我在VSCode中启动任务时,没有检测到问题。除了我已经做过的,我没有看到任何调试或测试problemMatcher的选项。
我如何更改我的problemMatcher,以便它正确检测上面显示的输出中的问题?
最后我不得不改变我的模式正确工作;我无法让多行正则表达式工作,而是为每一行编写了一个单独的模式来匹配:
"problemMatcher": {
"owner": "node-builder",
"fileLocation": "absolute",
"pattern": [
{
"regexp": "^(Error|Warning):\s*(.*)",
"severity": 1,
"message": 2,
},
{
"regexp": "^\s*at\s+(.*)\s+\((.*):(\d+):(\d+)\)",
"file": 2,
"line": 3,
"column": 4
},
]
},
我开发这个的真正问题是在使用VSCode时遇到的一个实际问题。任务被定义为另一个任务的依赖项,该任务将许多构建步骤组合在一起。我使用组合构建任务运行了所有任务,然后通过再次运行组合任务来杀死我正在编辑和重新启动其patternMatcher
的子任务,该子任务运行尚未运行的依赖任务。这样做会产生任务。json而不是被重新加载,因此我所做的任何事情都没有任何效果。任务必须自己运行才能执行任务。