diff --git a/examples/vite/.testRun.ts b/examples/vite/.testRun.ts index ac91b76f..3d99c5c2 100644 --- a/examples/vite/.testRun.ts +++ b/examples/vite/.testRun.ts @@ -12,6 +12,13 @@ function testRun( run(cmd, { serverIsReadyMessage }) } + { + const isDev = cmd !== 'npm run preview' + if (isDev) { + skipShieldGenerationTest = true + } + } + test('example', async () => { { const html = await fetchHtml('/') diff --git a/telefunc/node/server/runTelefunc/applyShield.ts b/telefunc/node/server/runTelefunc/applyShield.ts index bd4a04d9..aafcbd95 100644 --- a/telefunc/node/server/runTelefunc/applyShield.ts +++ b/telefunc/node/server/runTelefunc/applyShield.ts @@ -9,15 +9,18 @@ function applyShield(runContext: { telefunctionName: string telefunctionArgs: unknown[] logInvalidRequests: boolean + isProduction: boolean }): { isValidRequest: boolean } { const { telefunction } = runContext const hasShield = !shieldIsMissing(telefunction) - assertWarning( - hasShield || telefunction.length === 0, - `The telefunction ${runContext.telefunctionName} accepts arguments yet is missing \`shield()\`, see https://telefunc.com/shield`, - { onlyOnce: true } - ) + if (runContext.isProduction) { + assertWarning( + hasShield || telefunction.length === 0, + `The telefunction ${runContext.telefunctionName} accepts arguments yet is missing \`shield()\`, see https://telefunc.com/shield`, + { onlyOnce: true } + ) + } if (!hasShield) { return { isValidRequest: true } } diff --git a/telefunc/node/vite/transform.ts b/telefunc/node/vite/transform.ts index ea86a40e..40337ab2 100644 --- a/telefunc/node/vite/transform.ts +++ b/telefunc/node/vite/transform.ts @@ -8,6 +8,7 @@ export { transform } function transform(): Plugin { let root: string + let isDev: boolean = false return { name: 'telefunc:transform', enforce: 'pre', @@ -15,6 +16,9 @@ function transform(): Plugin { root = toPosixPath(config.root) assert(root) }, + configureServer() { + isDev = true + }, async transform(code, id, options) { if (!id.includes('.telefunc.')) { return @@ -25,9 +29,11 @@ function transform(): Plugin { if (isClientSide) { code = await transformTelefuncFileClientSide(code, id, root) } else { - code = (await transformTelefuncFileServerSide(code, id, root, true)) - if (id.endsWith('.ts')) { - code = generateShield(code) + code = await transformTelefuncFileServerSide(code, id, root, true) + if (!isDev) { + if (id.endsWith('.ts')) { + code = generateShield(code) + } } }