mirror of
https://github.com/mastodon/mastodon.git
synced 2025-05-14 21:51:13 +00:00
add asset integrity key to file
This commit is contained in:
parent
b19966e529
commit
a0eb0b9ee1
|
@ -18,6 +18,7 @@ export interface Options {
|
||||||
declare module 'vite' {
|
declare module 'vite' {
|
||||||
interface ManifestChunk {
|
interface ManifestChunk {
|
||||||
integrity: string;
|
integrity: string;
|
||||||
|
assetIntegrity: Record<string, string>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,17 +47,30 @@ async function augmentManifest(
|
||||||
.readFile(manifestPath, 'utf-8')
|
.readFile(manifestPath, 'utf-8')
|
||||||
.then((file) => JSON.parse(file) as Manifest);
|
.then((file) => JSON.parse(file) as Manifest);
|
||||||
|
|
||||||
if (manifest) {
|
if (!manifest) {
|
||||||
await Promise.all(
|
throw new Error(`Manifest file not found at ${manifestPath}`);
|
||||||
Object.values(manifest).map(async (chunk) => {
|
|
||||||
chunk.integrity = integrityForAsset(
|
|
||||||
await fs.readFile(resolveInOutDir(chunk.file)),
|
|
||||||
algorithms,
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2));
|
|
||||||
}
|
}
|
||||||
|
await Promise.all(
|
||||||
|
Object.values(manifest).map(async (chunk) => {
|
||||||
|
chunk.integrity = integrityForAsset(
|
||||||
|
await fs.readFile(resolveInOutDir(chunk.file)),
|
||||||
|
algorithms,
|
||||||
|
);
|
||||||
|
if (!chunk.assets && !chunk.css) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
chunk.assetIntegrity = {};
|
||||||
|
await Promise.all(
|
||||||
|
(chunk.assets ?? []).concat(chunk.css ?? []).map(async (asset) => {
|
||||||
|
chunk.assetIntegrity[asset] = integrityForAsset(
|
||||||
|
await fs.readFile(resolveInOutDir(asset)),
|
||||||
|
algorithms,
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
function integrityForAsset(source: Buffer, algorithms: string[]) {
|
function integrityForAsset(source: Buffer, algorithms: string[]) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user