UNPKG

wxt

Version:

⚡ Next-gen Web Extension Framework

54 lines (53 loc) 1.99 kB
import { wxt } from "../../wxt.mjs"; import { buildEntrypoints } from "./build-entrypoints.mjs"; import { generateWxtDir } from "../../generate-wxt-dir.mjs"; import { generateManifest, writeManifest } from "../manifest.mjs"; import { createSpinner } from "nanospinner"; //#region src/core/utils/building/rebuild.ts /** * Given a configuration, list of entrypoints, and an existing, partial output, * build the entrypoints and merge the new output with the existing output. * * This function will: * * 1. Generate the .wxt directory's types * 2. Build the `entrypointGroups` (and copies public files) * 3. Generate the latest manifest for all entrypoints * 4. Write the new manifest to the file system * * @param config Internal config containing all the project information. * @param allEntrypoints List of entrypoints used to generate the types inside * .wxt directory. * @param entrypointGroups The list of entrypoint groups to build. * @param existingOutput The previous output to combine the rebuild results * into. An empty array if this is the first build. */ async function rebuild(allEntrypoints, entrypointGroups, existingOutput = { steps: [], publicAssets: [] }) { const spinner = createSpinner("Preparing...").start(); await generateWxtDir(allEntrypoints).catch((err) => { wxt.logger.warn("Failed to update .wxt directory:", err); if (wxt.config.command === "build") throw err; }); const newOutput = await buildEntrypoints(entrypointGroups, spinner); const mergedOutput = { steps: [...existingOutput.steps, ...newOutput.steps], publicAssets: newOutput.publicAssets }; const { manifest: newManifest, warnings: manifestWarnings } = await generateManifest(allEntrypoints, mergedOutput); const finalOutput = { manifest: newManifest, ...mergedOutput }; await writeManifest(newManifest, finalOutput); spinner.clear().stop(); return { output: finalOutput, manifest: newManifest, warnings: manifestWarnings }; } //#endregion export { rebuild };