From 2a3765fec7256c0d60f06a1be7237b84508fd70b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20=27birdy=27=20Danjou?= Date: Mon, 16 Dec 2024 12:48:09 +0100 Subject: [PATCH] chore: add a verification that the change can occurs to avoid future breaking change --- config/vite.replace.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/config/vite.replace.js b/config/vite.replace.js index 898d13b..083d33e 100644 --- a/config/vite.replace.js +++ b/config/vite.replace.js @@ -4,12 +4,6 @@ export const changeLoadingWorker = (basePath) => ({ transform(code, id) { // Only apply transformations to .js files (or other specific conditions) if (id.endsWith('.js')) { - // const worker = new Worker( - // new URL('workerHelpers.worker.js', import.meta.url), - // { - // type: 'module', - // }, - // ); const searchValue = /const worker = new Worker\(\s*new URL\(['"]\.?\/?workerHelpers\.worker\.js['"],\s*import\.meta\.url\),\s*\{\s*type:\s*'module',?\s*\},?\s*\);/; @@ -28,6 +22,15 @@ export const changeLoadingWorker = (basePath) => ({ worker = new Worker(blobUrl); }`; + // Check that the worker change works. + if (id.match('lib/web.js')) { + const match = code.match(searchValue); + if (!match) + throw new Error( + 'Impossible to replace Worker with iife implementation. Source code (lib/web.js) changed.', + ); + } + // Replace occurrences according to the regex pattern const newCode = code.replace(searchValue, replacement);