From 2b94e3c8279a5c3dba969fb40d1672ec8b41ad5c Mon Sep 17 00:00:00 2001 From: ayoayco Date: Sat, 17 Aug 2024 10:14:39 +0200 Subject: [PATCH] feat: inject types for __assets, __version, __prefix --- index.js | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index b47adc5..8f0019e 100644 --- a/index.js +++ b/index.js @@ -79,26 +79,13 @@ export default function serviceWorker(config) { if (command === 'build') { injectScript('page', registrationScript); } - - const injectedTypeDefinitions = ` -/*** - * @ayco/astro-sw injected variables - */ + }, + 'astro:config:done': async ({injectTypes, logger}) => { + let injectedTypes = ` declare const __assets: string; declare const __version: string; -declare const __prefix: string; - ` - - const envTs = path.join(__dirname, 'src/env.d.ts'); - try { - await writeFile( - envTs, - injectedTypeDefinitions, - { flag: 'a+' } - ); - } catch (err) { - logger.error(err.toString()) - } +declare const __prefix: string;` + injectTypes({filename: 'caching.d.ts', content: injectedTypes}) }, 'astro:build:ssr': ({ manifest }) => { const files = manifest.routes.map(route => route.file.replaceAll('/', ''));