Open pi0 opened 1 year ago
/cc @antfu If you have any ideas.
I image that we could have a magic comment in the stub file, and then with a Vite plugin to transform it back to a redirect. For example:
// @jiti-stub /path/to/source.ts
module.exports = jiti()('/path/to/source.ts')
export const jitiStubPlugin() {
return {
name: 'jiti:stub',
transform(code, id) {
if (!code.includes('@jiti-stub')) return
const match = /REGEX/.match(code)
return `export * from "${match[1]}"`
}
}
}
Do you think would it be possible to magically making jiti+vite working together out of the box without custom user/framework plugins?
I can't think of one at this moment (without changes in Vite core, which is unlikely to happen)
Can we detect vite environment in a reliable way or having an export condition by default in vite? This way i was thinking jiti instead can change it's internal behavior for vite(st) compatibility.
FWIW — Im able to get the tests to run fine in vitest using this little unplugin resolver i wrote (main issue was the file://
protocol doesnt seem to work in vite): https://github.com/justin-schroeder/unplugin-file-url
It works fine — the remaining issue is (in the context of a monorepo at least) making changes in stubbed packageA does not trigger vitest to re-run in the context of
packageB/teststhat depend on the stubbed
packageA`
Any news on this?
Any news on this?
+1
not work in vite yet
While this is not a direct purpose of jiti, when it is used in testing environments (unbuild dist in stub mode) we might need to detect vite environment and bypass transforms.