Skip to content

Commit

Permalink
fix asset check
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed May 16, 2024
1 parent 6621d6b commit 12e5793
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions packages/addon-dev/src/rollup-incremental-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ import { existsSync } from 'fs-extra';
export default function incremental(): Plugin {
const changed = new Set();
const generatedAssets = new Map();

function isEqual(v1: string | Uint8Array, v2: string | Uint8Array): boolean {
if (typeof v1 === 'string' && typeof v2 === 'string') {
return v1 === v2;
}
if (Buffer.isBuffer(v1) && Buffer.isBuffer(v2)) {
return v1.equals(v2);
}
return false;
}

return {
name: 'clean',
transform(_code, id) {
Expand Down Expand Up @@ -44,16 +55,22 @@ export default function incremental(): Plugin {
}
if (
bundle[checkKey]?.type === 'asset' &&
(bundle[checkKey] as OutputAsset).source ===
generatedAssets.get(checkKey)
generatedAssets.has(checkKey)
) {
delete bundle[key];
continue;
} else {
generatedAssets.set(
checkKey,
(bundle[checkKey] as OutputAsset).source
);
if (
isEqual(
(bundle[checkKey] as OutputAsset).source,
generatedAssets.get(checkKey)
)
) {
delete bundle[key];
continue;
} else {
generatedAssets.set(
checkKey,
(bundle[checkKey] as OutputAsset).source
);
}
}
if (
(bundle[checkKey] as any)?.moduleIds?.every(
Expand Down

0 comments on commit 12e5793

Please sign in to comment.