privatenumber / pkgroll

📦 Zero-config package bundler for Node.js + TypeScript
MIT License
1.01k stars 23 forks source link

Detect Vitest for in-source testing #9

Open ayuhito opened 2 years ago

ayuhito commented 2 years ago

Love this bundler and I appreciate the peace of mind having not to configure anything for things to just work.

Vitest does support in-source testing which I think is great when writing unit tests, however, since this bundler isn't extensible, it isn't possible for us to modify the Rollup config to tree-shake the testing code out as specified in their docs.

Would it be possible to merge the following replace config into the default Rollup config of this project? Whilst the addition of this shouldn't affect non-Vitest users, we can still include a check just incase to only include it if Vitest is present in the package.json.

// rollup.config.js
+ import replace from '@rollup/plugin-replace'

export default {
  plugins: [
+   replace({
+     'import.meta.vitest': 'undefined',
+   })
  ],
  // other options
}
privatenumber commented 2 years ago

That looks safe but I would rather not build in specific support for other tooling, or also make assumptions about how they need to be used.

I think I would prefer to add a --define CLI flag like the --env flag.