chore(assets): assets.json에 group/referencedAt 추가 및 AssetManager 참조 추적
Auto PR / open-pr (push) Successful in 26s
Auto Label PR / add-automerge-label (pull_request) Successful in 7s
CI / test (pull_request) Successful in 59s

This commit is contained in:
2025-11-15 13:44:23 +09:00
parent 176568f976
commit 032372bb01
2 changed files with 17 additions and 0 deletions
+6
View File
@@ -38,6 +38,7 @@ export class AssetManager {
private readonly allowed: Set<string> private readonly allowed: Set<string>
private byHash = new Map<string, AssetRef>() private byHash = new Map<string, AssetRef>()
private byOriginal = new Map<string, string>() // originalName -> path private byOriginal = new Map<string, string>() // originalName -> path
private referenced = new Set<string>() // originalName referenced via rewrite
constructor(opts: AssetManagerOptions) { constructor(opts: AssetManagerOptions) {
this.maxBytes = opts.maxBytes this.maxBytes = opts.maxBytes
@@ -91,8 +92,13 @@ export class AssetManager {
if (urlOrLocalRef.startsWith('local:')) { if (urlOrLocalRef.startsWith('local:')) {
const key = urlOrLocalRef.slice('local:'.length) const key = urlOrLocalRef.slice('local:'.length)
const p = this.byOriginal.get(key) const p = this.byOriginal.get(key)
if (p) this.referenced.add(key)
return p ?? urlOrLocalRef return p ?? urlOrLocalRef
} }
return urlOrLocalRef return urlOrLocalRef
} }
referencedList(): string[] {
return Array.from(this.referenced)
}
} }
+11
View File
@@ -8,13 +8,22 @@ export type AssetMetaItem = {
ext: string ext: string
zipPath: string zipPath: string
integrity: string integrity: string
group: 'images' | 'fonts' | 'other'
referencedAt: string[]
} }
export function buildAssetsMetadata(am: AssetManager): Uint8Array { export function buildAssetsMetadata(am: AssetManager): Uint8Array {
const list = am.list() const list = am.list()
const referenced = new Set(am.referencedList())
const items: AssetMetaItem[] = list.map((ref) => { const items: AssetMetaItem[] = list.map((ref) => {
// Browser-safe synchronous integrity: base64 of bytes as placeholder // Browser-safe synchronous integrity: base64 of bytes as placeholder
const b64 = Buffer.from(ref.bytes).toString('base64') const b64 = Buffer.from(ref.bytes).toString('base64')
const group: 'images' | 'fonts' | 'other' = ref.mimeType.startsWith('image/')
? 'images'
: ref.mimeType.startsWith('font/')
? 'fonts'
: 'other'
const referencedAt = referenced.has(ref.originalName) ? [`local:${ref.originalName}`] : []
return { return {
originalName: ref.originalName, originalName: ref.originalName,
mimeType: ref.mimeType, mimeType: ref.mimeType,
@@ -23,6 +32,8 @@ export function buildAssetsMetadata(am: AssetManager): Uint8Array {
ext: ref.ext, ext: ref.ext,
zipPath: ref.path, zipPath: ref.path,
integrity: `sha256-${b64}`, integrity: `sha256-${b64}`,
group,
referencedAt,
} }
}) })
const json = JSON.stringify({ assets: items }, null, 2) const json = JSON.stringify({ assets: items }, null, 2)