Keep single-tag rollback on the legacy worker path

This commit is contained in:
Jonathan Sykes
2026-10-07 23:58:29 +08:00
parent 5b25ccaa86
commit bb446c717f
2 changed files with 6 additions and 0 deletions

View File

@@ -27,6 +27,8 @@ export function stampIndex(source, files, { hashing = true, buildTag = '__BUILD_
} }
export function createAssetManifest(publicDir = './public', { hashing = true, buildTag: override, assetSync = true } = {}) { export function createAssetManifest(publicDir = './public', { hashing = true, buildTag: override, assetSync = true } = {}) {
// Single-tag URLs cannot be verified against per-file URL hashes.
assetSync = hashing && assetSync;
const bytes = new Map(); const bytes = new Map();
const legacy = createHash('sha256'); const legacy = createHash('sha256');
function walk(dir, prefix = '') { function walk(dir, prefix = '') {

View File

@@ -68,3 +68,7 @@ test('sync rollback changes build identity and injected worker byte hash', () =>
expect(on.manifest.buildTag).not.toBe(off.manifest.buildTag); expect(on.manifest.buildTag).not.toBe(off.manifest.buildTag);
expect(off.manifest.files['/sw.js'].h).toBe(hash(off.sw)); expect(off.manifest.files['/sw.js'].h).toBe(hash(off.sw));
})); }));
test('single-tag hashing rollback also selects the legacy worker', () => fixture(dir => {
writeFileSync(join(dir,'sw.js'), "const VERSION = typeof __BUILD_TAG__ !== 'undefined' ? __BUILD_TAG__ : 'old'; const SYNC = typeof __ASSET_SYNC__ !== 'undefined' ? __ASSET_SYNC__ : true;");
expect(createAssetManifest(dir,{hashing:false}).sw).toContain('const SYNC = false');
}));