(worker: boolean)
| 41 | }); |
| 42 | } |
| 43 | const plugin = (worker: boolean): Plugin => ({ |
| 44 | name: `cbm-license-inventory-${worker ? 'worker' : 'app'}`, |
| 45 | apply: 'build', |
| 46 | configResolved(config) { |
| 47 | if (!worker) outDir = resolve(config.root, config.build.outDir); |
| 48 | }, |
| 49 | buildStart() { |
| 50 | if (worker) { workerBuilds++; return; } |
| 51 | rmSync(proofPath, { force: true }); |
| 52 | modules.clear(); externals.clear(); chunks.clear(); |
| 53 | for (const key of Object.keys(inputs)) delete inputs[key]; |
| 54 | for (const key of Object.keys(generatedAssets)) delete generatedAssets[key]; |
| 55 | workerBuilds = 0; |
| 56 | failed = false; |
| 57 | for (const file of ['vite.config.ts', 'tools/license-build-inventory.ts', 'package.json', |
| 58 | 'node_modules/@huggingface/transformers/package.json']) record(join(root, file)); |
| 59 | }, |
| 60 | buildEnd(error) { if (error) failed = true; }, |
| 61 | generateBundle: { order: 'post', handler(_options, bundle) { |
| 62 | for (const id of this.getModuleIds()) { |
| 63 | const info = this.getModuleInfo(id); |
| 64 | if (info?.isExternal) externals.add(id); |
| 65 | else modules.add(record(id) ?? id); |
| 66 | } |
| 67 | for (const path of this.getWatchFiles()) record(path); |
| 68 | for (const [name, output] of Object.entries(bundle)) { |
| 69 | if (output.type === 'chunk') chunks.add(name); |
| 70 | else if (name === 'index.html' || name.endsWith('.css')) { |
| 71 | // Only bundler outputs qualify. Files copied from public never |
| 72 | // enter this hook; record bytes before inspecting the dist tree. |
| 73 | generatedAssets[name] = createHash('sha256').update(output.source).digest('hex'); |
| 74 | } |
| 75 | } |
| 76 | } }, |
| 77 | closeBundle() { |
| 78 | if (worker || failed || !existsSync(outDir)) return; |
| 79 | const outputs: Record<string, string> = {}; |
| 80 | const runtimeInputs: Record<string, string> = {}; |
| 81 | // Vite emits ONNX's runtime through new URL(..., import.meta.url). Match |
| 82 | // bytes to its installed input, rather than trusting an output filename. |
| 83 | const ortDir = join(root, 'node_modules/onnxruntime-web/dist'); |
| 84 | const runtimeSources = existsSync(ortDir) ? files(ortDir).filter(path => /\.(wasm|m?js)$/.test(path)) : []; |
| 85 | const runtimeHashes = new Map(runtimeSources.map(path => [hash(path), path])); |
| 86 | for (const path of files(outDir).sort()) { |
| 87 | const name = slash(relative(outDir, path)); |
| 88 | outputs[name] = hash(path); |
| 89 | if (/\.(wasm|m?js)$/.test(name)) { |
| 90 | const source = runtimeHashes.get(outputs[name]); |
| 91 | if (source) runtimeInputs[name] = record(source)!; |
| 92 | } |
| 93 | } |
| 94 | // Public copies are not Rollup modules. Record their inputs, while the |
| 95 | // verifier still rejects copied executable payloads outside the graph. |
| 96 | const publicDir = join(root, 'public'); |
| 97 | if (existsSync(publicDir)) for (const path of files(publicDir)) record(path); |
| 98 | mkdirSync(join(root, '.vite'), { recursive: true }); |
| 99 | writeFileSync(proofPath, JSON.stringify({ |
| 100 | version: 1, |
no outgoing calls
no test coverage detected