Skip to content

Commit

Permalink
chore: add a verification that the change can occurs to avoid future …
Browse files Browse the repository at this point in the history
…breaking change
  • Loading branch information
immortal-tofu committed Dec 16, 2024
1 parent b22d880 commit 2a3765f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions config/vite.replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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*\);/;

Expand All @@ -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);

Expand Down

0 comments on commit 2a3765f

Please sign in to comment.