-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix tsc
setup to report project-relative paths in error messages
#1010
Comments
Cross-posting my comment from #977. FWIW: this used to work before, I suspect #682 broke it. The trick is that we need to run
I have some ideas how to fix this (basically introduce a new |
Take the following error report as an example:
The line above error report specifies the package path, we need some discussion on the current error report flavor and the one @bajtos suggests in this issue. BTW, please note the latest vscode shows files with compile error. |
From the discussion in today's estimation meeting, @raymondfeng thinks this is working as expected. The package name can be found 2 lines above the error. See @jannyHou 's example above What's needed to be discussed is whether it should be a bug. @raymondfeng and @bajtos seem to have different views. |
To be accurate, I don't think there is a right/wrong answer here. It's about preference. The current build runs While I feel the current behavior is fine, I'm open to see @bajtos's idea. But I don't think we have to do it for MVP. |
I am afraid this is not true. IDE can catch errors only in the files you are editing, it does not report errors in other files. Project-wide refactorings like #1050 are difficult in the current setup. When a widely-used entity (e.g.
I understand some people may prefer to see package-relative paths in However, I still want a working PROBLEMS window in VS Code. If there is a way how to get that functionality using package-relative paths then I am fine with keeping package-relative paths. |
Have you tried to click on the line in PROBLEMS window? Does it open the file for you, or does it print an error about an unknown file? This is kind of errors I am getting (my monorepo root is
I think the first problem happens when lerna groups multiple error message from the same package and prints the package name prefix on the first line only. The second problem comes from a line that includes package name prefix from lerna. |
I am proposing to modify In my proposal, people running Only when invoking @raymondfeng thoughts/objections? |
@bajtos I cannot find an elegant way to do what you want. Here is what I have tried to implement with
Please note the location of There is a conflict of interest:
|
The idea is to execute
In my experience so far, any configuration provided in Below is the hard-coded solution that I am using as a workaround right now, it seems to work flawlessly to me. index a5c8ec7e..ed7f5f12 100755
--- a/packages/build/bin/compile-package.js
+++ b/packages/build/bin/compile-package.js
@@ -98,10 +98,12 @@ function run(argv, options) {
}
}
+ // TODO: replace with LERNA_ROOT_PATH
+ const cwd = path.resolve(path.dirname(tsConfigFile), '../..');
+
const args = [];
if (tsConfigFile) {
- args.push('-p', tsConfigFile);
+ args.push('-p', path.relative(cwd, tsConfigFile));
}
if (outDir) {
@@ -114,7 +116,7 @@ function run(argv, options) {
args.push(...compilerOpts);
- return utils.runCLI('typescript/lib/tsc', args, options);
+ return utils.runCLI('typescript/lib/tsc', args, {cwd, ...options});
} In order to allow VSCode's problem matcher to parse compiler errors, I am disabling parallel mode: +++ b/package.json
@@ -35,7 +35,7 @@
"prettier:fix": "npm run prettier:cli -- --write",
"clean": "lerna run clean --loglevel=silent --parallel",
"clean:lerna": "lerna clean --yes --parallel --loglevel=silent",
- "build": "lerna run build --parallel --loglevel=silent",
+ "build": "lerna run build --loglevel=silent",
"build:full": "npm run clean:lerna && npm run bootstrap && npm test",
"pretest": "npm run clean && npm run build",
"test": "node packages/build/bin/run-nyc npm run mocha --scripts-prepend-node-path", With these two changes in place, both acceptance criteria are met, at the cost of a much slower build step. |
The monorepo-root level tsconfig.json file is intended only for TypeScriptServer run by VisualStudio Code, not for the actual build.
As I commented above, you can tell |
Do you run the script from inside VSCode? Is there a possibility to set an env var? If so, we can improve |
I have implemented it in #1189. The
|
Right now, when typescript compiler encounters an error, it reports file paths relative to individual packages (e.g.
src/index.ts
) instead of paths relative to monorepo root (e.g. `packages/core/index.ts).This makes fixing error tedious, because one has to parse text around the error message to find out which package the problematic file belongs to.
Another issue is that VS Code's problem matcher is not able to associate the error message with the specific file (and location in that file).
We need to fix the output of
npm test
to report paths relative to monorepo root, and preferably also fix the problem matcher in VS Code to deal with the prefix added to error messages by lerna when running in parallel mode.Acceptance criteria
When I run
npm test
and the compiler reports compilation errors, these errors contain file names relative to monorepo root (not to individual packages). See Verify TypeScript setup in DEVELOPING.When I run "Build, test and lint" task from VS Code and the compiler reports compilation errors, these errors are shown in VSCode's PROBLEMS window. When I click on an error, VSCode jumps to the exact line causing the error. See Verify TypeScript setup >> Compilation Errors in VSCODE.
The text was updated successfully, but these errors were encountered: