实现示例type MapV3 = { version: number; file?: string; sources: string[]; mappings: string } function validVersion(v: number): boolean { return v === 3 } function safeSources(s: string[]): boolean { return s.every(x => !/^([A-Za-z]:\\|\\\\|\/)\S+/.test(x)) } function hasMappings(m?: string): boolean { return !!m && m.length > 0 } function evaluate(map: MapV3, env: 'prod' | 'dev'): { ok: boolean; errors: string[] } { const errors: string[] = [] if (!validVersion(map.version)) errors.push('version') if (!hasMappings(map.mappings)) errors.push('mappings') if (!safeSources(map.sources)) errors.push('sources') if (env === 'prod' && map.file && /\.ts$/.test(map.file)) errors.push('prod-file') return { ok: errors.length === 0, errors } } 审计与发布治理生产环境禁止包含绝对路径与源码泄露;发布前执行校验并归档。Map 文件按版本与哈希记录;异常阻断并回退。

发表评论 取消回复