Skip to content

Commit

Permalink
fix: Make content script array orders consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Jun 25, 2023
1 parent 573ef80 commit f380378
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/utils/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,22 +279,27 @@ function addEntrypoints(
});
manifest.host_permissions = Array.from(hostPermissions).sort();
} else {
const hashToEntrypointsMap = contentScripts.reduce<
Record<string, ContentScriptEntrypoint[]>
>((map, script) => {
const hashToEntrypointsMap = contentScripts.reduce((map, script) => {
const hash = JSON.stringify(script.options);
map[hash] ??= [];
map[hash].push(script);
if (!map.has(hash)) {
map.set(hash, [script]);
} else {
map.get(hash)?.push(script);
}
return map;
}, {});
}, new Map<string, ContentScriptEntrypoint[]>());

manifest.content_scripts = Object.entries(hashToEntrypointsMap).map(
manifest.content_scripts = Array.from(hashToEntrypointsMap.entries()).map(
([, scripts]) => ({
...scripts[0].options,
css: getContentScriptCssFiles(scripts, buildOutput),
js: scripts.map((entry) =>
getEntrypointBundlePath(entry, config.outDir, '.js'),
),
// TOOD: Sorting css and js arrays here so we get consistent test results... but we
// shouldn't have to. Where is the inconsistency coming from?
css: getContentScriptCssFiles(scripts, buildOutput)?.sort(),
js: scripts
.map((entry) =>
getEntrypointBundlePath(entry, config.outDir, '.js'),
)
.sort(),
}),
);
}
Expand Down

0 comments on commit f380378

Please sign in to comment.