// Run only when updating the Fuc runtime bundles. Never modifies shared dependencies. import fs from 'node:fs'; import path from 'node:path'; import {createRequire} from 'node:module'; import {fileURLToPath} from 'node:url'; import {createHash} from 'node:crypto'; const root=fileURLToPath(new URL('../../',import.meta.url)); const require=createRequire(path.join(root,'theme/package.json')); const versions={esbuild:'0.25.12',qrcode:'1.5.4',marked:'15.0.12',dompurify:'3.4.17'}; for(const [name,version] of Object.entries(versions)){ const actual=JSON.parse(fs.readFileSync(path.join(root,'theme/node_modules',name,'package.json'),'utf8')).version; if(actual!==version)throw Error(`${name}: expected ${version}, found ${actual}; review dependency update first`); } const {build}=require('esbuild');const output=path.join(root,'theme/Fuc/assets/vendor');fs.mkdirSync(output,{recursive:true}); for(const [name,contents] of Object.entries({qrcode:"export {default} from 'qrcode/lib/browser.js';",richtext:"export {marked} from 'marked'; export {default as DOMPurify} from 'dompurify';"})){ await build({stdin:{contents,resolveDir:path.join(root,'theme')},bundle:true,format:'esm',platform:'browser',minify:true,outfile:path.join(output,name+'.mjs')}); } for(const [name,file] of [['qrcode','license'],['marked','LICENSE.md'],['dompurify','LICENSE']])fs.copyFileSync(path.join(root,'theme/node_modules',name,file),path.join(output,name+'.LICENSE')); const hashes=Object.fromEntries(['qrcode.mjs','richtext.mjs'].map(name=>[name,createHash('sha256').update(fs.readFileSync(path.join(output,name))).digest('hex')])); fs.writeFileSync(path.join(output,'manifest.json'),JSON.stringify({versions,sha256:hashes},null,2)+'\n'); console.log('Fuc vendor bundles and license provenance updated');