UNPKG

vite-plugin-zephyr

Version:

Vite plugin for Zephyr

30 lines (29 loc) • 1.42 kB
import { ZeErrors, ZephyrError } from "zephyr-agent"; import { normalizeVitePath } from "../utils/normalize-vite-path.mjs"; function outputBytes(asset) { if ('chunk' === asset.type) return Buffer.from(asset.code, 'utf8'); return 'string' == typeof asset.source ? Buffer.from(asset.source, 'utf8') : Buffer.from(asset.source); } function hasSameBytes(left, right) { return outputBytes(left).equals(outputBytes(right)); } function mergeViteOutputAssets(bundle, assets, { target } = {}) { for (const [assetPath, asset] of assets){ const normalizedPath = normalizeVitePath(assetPath); if ('tap-app' === target && assetPath !== normalizedPath) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, { message: `Vite TAP artifact path must use its canonical snapshot spelling: ${JSON.stringify(assetPath)} (expected ${JSON.stringify(normalizedPath)}).` }); if ('tap-app' === target) { const existing = bundle[normalizedPath]; if (existing) { if (!hasSameBytes(existing, asset)) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, { message: `Vite emitted conflicting assets for "${normalizedPath}".` }); continue; } } bundle[normalizedPath] = asset; } } export { mergeViteOutputAssets }; //# sourceMappingURL=merge_vite_output_assets.mjs.map