Skip to content

Commit

Permalink
feat: allow passing generatorOpts down to Babel (#323)
Browse files Browse the repository at this point in the history
* feat: allow passing generatorOpts down to Babel

* fix: add babel generator options type
  • Loading branch information
olaf-k authored Jan 17, 2025
1 parent 4921ae0 commit c58d180
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Creates the vite plugin from a set of optional plugin options.
- `opts.checkProd {boolean}` - Optional boolean to enforce the plugin to skip instrumentation for production environments. Looks at Vite's **isProduction** key from the `ResolvedConfig`.
- `opts.forceBuildInstrument {boolean}` - Optional boolean to enforce the plugin to add instrumentation in build mode. Defaults to false.
- `opts.nycrcPath {string}` - Path to specific nyc config to use instead of automatically searching for a nycconfig. This parameter is just passed down to `@istanbuljs/load-nyc-config`.
- `opts.generatorOpts {GeneratorOptions}` - A set of generator options that are passed down to the Babel transformer. See [here](https://babeljs.io/docs/babel-generator#options) for reference. Defaults to empty object.

Notes
--------------------------
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@ianvs/prettier-plugin-sort-imports": "4.4.1",
"@semantic-release/changelog": "6.0.3",
"@semantic-release/git": "10.0.1",
"@types/babel__generator": "7.6.8",
"@types/node": "22.10.5",
"@types/ws": "8.5.13",
"husky": "9.1.7",
Expand Down
24 changes: 13 additions & 11 deletions pnpm-lock.yaml

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

3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { loadNycConfig } from '@istanbuljs/load-nyc-config';
import type { GeneratorOptions } from 'babel__generator';
import { createInstrumenter } from 'istanbul-lib-instrument';
import picocolors from 'picocolors';
import type { ExistingRawSourceMap } from 'rollup';
Expand All @@ -25,6 +26,7 @@ export interface IstanbulPluginOptions {
forceBuildInstrument?: boolean;
cwd?: string;
nycrcPath?: string;
generatorOpts?: GeneratorOptions;
}

// Custom extensions to include .vue files
Expand Down Expand Up @@ -117,6 +119,7 @@ export default function istanbulPlugin(
autoWrap: true,
esModules: true,
compact: false,
generatorOpts: { ...opts?.generatorOpts },
});

// Lazy check the active status of the plugin
Expand Down
2 changes: 2 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
declare module 'istanbul-lib-instrument' {
import { ExistingRawSourceMap } from 'rollup';
import { GeneratorOptions } from 'babel__generator';

interface Instrumenter {
instrumentSync(
Expand All @@ -24,6 +25,7 @@ declare module 'istanbul-lib-instrument' {
parserPlugins?: any[];
coverageGlobalScope?: string;
coverageGlobalScopeFunc?: boolean;
generatorOpts?: GeneratorOptions;
}): Instrumenter;
}

Expand Down

0 comments on commit c58d180

Please sign in to comment.