Skip to content
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

TypeScript errors terminate watch mode #138

Closed
2 tasks done
blm768 opened this issue May 14, 2022 · 1 comment
Closed
2 tasks done

TypeScript errors terminate watch mode #138

blm768 opened this issue May 14, 2022 · 1 comment

Comments

@blm768
Copy link

blm768 commented May 14, 2022

Describe the bug

When working in watch mode, if the plugin encounters a TypeScript error, it terminates the build process immediately.

Reproduction

In any existing Vite + TypeScript project that is configured to use vite-plugin-checker:

  1. Run vite build --watch.
  2. Modify a TypeScript file in such a way that tsc would report an error.

Expected behavior

While in watch mode, it'd be helpful for the build process to continue running even after encountering an error.

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (12) x64 Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
    Memory: 12.43 GB / 31.95 GB
  Binaries:
    Node: 16.15.0 - ~\scoop\apps\nodejs-lts\current\node.EXE
    npm: 8.5.5 - ~\scoop\apps\nodejs-lts\current\npm.CMD
  Browsers:
    Chrome: 101.0.4951.67
    Edge: Spartan (44.19041.1266.0), Chromium (101.0.1210.39)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    vite-plugin-checker: ^0.4.6 => 0.4.6

Additional context

The following patch seems to help with the issue. Even if I just remove process.exit, though, the build process does seem to exit, just not necessarily with the same exit code as the child process. I also have no idea if this is actually a reliable way to detect watch mode.

diff --git a/packages/vite-plugin-checker/src/main.ts b/packages/vite-plugin-checker/src/main.ts
index 8e70a76..9cc5327 100644
--- a/packages/vite-plugin-checker/src/main.ts
+++ b/packages/vite-plugin-checker/src/main.ts
@@ -144,7 +144,7 @@ export default function Plugin(userConfig: UserPluginConfig): Plugin {
         ]
       }
     },
-    buildStart: () => {
+    buildStart: function() {
       // for build mode
       // run a bin command in a separated process
       if (viteMode !== 'build') return
@@ -164,7 +164,9 @@ export default function Plugin(userConfig: UserPluginConfig): Plugin {
           checkers.map((checker) => spawnChecker(checker, userConfig, localEnv))
         )
         const exitCode = exitCodes.find((code) => code !== 0) ?? 0
-        if (exitCode !== 0) process.exit(exitCode)
+        if (exitCode !== 0 && this.getWatchFiles().length === 0) {
+          process.exit(exitCode)
+        }
       })()
     },
     configureServer(server) {

Validations

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@fi3ework
Copy link
Owner

😅 I don't know Vite has a watch mode for build command before. Thanks for letting me know. I do like to adopt the behavior as described.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants