There is no named export for the plugin, encountered this when trying to dynamically import the plugin into an ESM file. This change copies the export style of @fastify/cookie. I presume that this was not caught by tests because something (Vitest? Node?) is helping with CJS compatibility that masks the problem when running tests.
I have not included tests for this for two reasons, first because it does not seem to be tested for in various other Fastify packages and secondly because the test I produced feels very hacky. I have included it below.
index.test.mjs
import { expect, test } from 'vitest'
test('esm - should import plugin dynamically with default and named', async () => {
const FastifyVite = await import('./index.js')
expect(FastifyVite.default).toBeDefined()
expect(FastifyVite.fastifyVite).toBeDefined()
})
Needing two flags to recreate this phenomenon and the potential side effects that may cause is why I'm on the side of caution and haven't included a test for this. The cost might outweigh the benefits.
Description
There is no named export for the plugin, encountered this when trying to dynamically import the plugin into an ESM file. This change copies the export style of
@fastify/cookie
. I presume that this was not caught by tests because something (Vitest? Node?) is helping with CJS compatibility that masks the problem when running tests.I have not included tests for this for two reasons, first because it does not seem to be tested for in various other Fastify packages and secondly because the test I produced feels very hacky. I have included it below.
index.test.mjs
vitest.config.js
Needing two flags to recreate this phenomenon and the potential side effects that may cause is why I'm on the side of caution and haven't included a test for this. The cost might outweigh the benefits.
Checklist
npm run test
andnpm run benchmark