import { DEFAULT_IN_PATH, DEFAULT_OUT_PATH, getBundle, writeBundle } from './bundler.js'; import { getSourceMapFileName, SourceMapExtension, SourceMaps } from '../server/web/sourcemaps.js'; import deepEqual from 'fast-deep-equal'; async function main(inPath: string = DEFAULT_IN_PATH, outPath: string = DEFAULT_OUT_PATH) { const bundle = await getBundle(inPath) const errors: string[] = [] for (const [name, {hash, sourceMap}] of bundle.css) { const filename = getSourceMapFileName(name, hash, SourceMapExtension.CSS) const existingMap = SourceMaps.get(filename) if (!existingMap) { errors.push(`source map for ${filename} is missing; add this line to server/web/sourcemaps.ts:\n\t\t${JSON.stringify([filename, sourceMap])},\n\n`) } else if (!deepEqual(sourceMap, existingMap)) { errors.push(`source map for ${filename} is incorrect; replace this line in server/web/sourcemaps.ts:\n\t\t${JSON.stringify([filename, existingMap])},\n\nwith this line:\n\t\t${JSON.stringify([filename, sourceMap])},\n\n`) } } if (errors.length > 0) { throw Error(errors.join('\n')) } await writeBundle(bundle, outPath) } main(...process.argv.slice(2)).then(() => { console.info('generated client helpers and confirmed sourcemaps are present'); }).catch((err) => { console.error('could not generate client helpers or confirm sourcemaps are present'); console.error(err && 'stack' in err ? err.stack : err); throw err; }).catch(() => { process.exit(1); });