From c00aaebfd5915c180cc8e5b3b8c2bb8ab7265553 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Sun, 10 Jul 2022 19:20:49 -0400 Subject: [PATCH] feat: capture watch mode when called via the Rollup API - `process.env.ROLLUP_WATCH` is only set when using the CLI - when using watch mode through the Rollup API (https://rollupjs.org/guide/en/#rollupwatch), this is not set - but since Rollup 2.14.0 (https://github.com/rollup/rollup/blob/master/CHANGELOG.md#2140), `this.meta.watchMode` is available - still check the env variable for backward-compat on older Rollup versions - notably, this is needed to test watch mode, since the tests are done via the Rollup API --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 0977063b..43895d07 100644 --- a/src/index.ts +++ b/src/index.ts @@ -95,7 +95,7 @@ const typescript: PluginImpl = (options) => rollupOptions = {... config}; context = new ConsoleContext(pluginOptions.verbosity, "rpt2: "); - watchMode = process.env.ROLLUP_WATCH === "true"; + watchMode = process.env.ROLLUP_WATCH === "true" || !!this.meta.watchMode; // meta.watchMode was added in 2.14.0 to capture watch via Rollup API (i.e. no env var) (c.f. https://github.com/rollup/rollup/blob/master/CHANGELOG.md#2140) ({ parsedTsConfig: parsedConfig, fileName: tsConfigPath } = parseTsConfig(context, pluginOptions)); if (generateRound === 0)