{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n                   🗲 Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website:                  https://stormsoftware.com\n Repository:               https://github.com/storm-software/powerlines\n Documentation:            https://docs.stormsoftware.com/projects/powerlines\n Contact:                  https://stormsoftware.com/contact\n\n SPDX-License-Identifier:  Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { createUnplugin } from \"@powerlines/core\";\nimport { resolveOptions } from \"@powerlines/unplugin/vite\";\nimport defu from \"defu\";\nimport type { Context, Plugin } from \"powerlines\";\nimport { formatConfig } from \"powerlines/plugin-utils\";\nimport { createVitePlugin } from \"unplugin\";\nimport { build, InlineConfig } from \"vite\";\nimport type { VitePluginContext, VitePluginOptions } from \"./types/plugin\";\n\nexport type * from \"./types\";\n\ndeclare module \"powerlines\" {\n  interface Config {\n    vite?: VitePluginOptions;\n  }\n}\n\n/**\n * A Powerlines plugin to assist in developing other Powerlines plugins.\n */\nexport const plugin = <TContext extends VitePluginContext = VitePluginContext>(\n  options: VitePluginOptions = {}\n): Plugin<TContext> => {\n  return {\n    name: \"vite\",\n    config() {\n      this.trace(\n        \"Providing default configuration for the Powerlines `vite` build plugin.\"\n      );\n\n      return {\n        output: {\n          format: [\"cjs\", \"esm\"]\n        },\n        vite: {\n          ...options\n        },\n        singleBuild: true\n      };\n    },\n    async build() {\n      this.debug(\"Starting Vite build process...\");\n\n      const environments = this.environment.unstable_execution.environments;\n      if (!environments || Object.keys(environments).length === 0) {\n        throw new Error(\n          `No environments found in the Powerlines context. At least one environment should have been generated - please report this issue to https://github.com/storm-software/powerlines/issues.`\n        );\n      }\n\n      this.trace(\n        `Running Vite for ${Object.keys(environments).length} environments.`\n      );\n\n      const resolved = resolveOptions(this);\n      const options = defu(this.config.vite, {\n        ...resolved,\n        config: false,\n        entry: this.entry,\n        environments: Object.fromEntries(\n          Object.entries(environments).map(([name, env]) => [\n            name,\n            defu(this.config.vite, resolveOptions(env as Context))\n          ])\n        ),\n        plugins: [\n          createVitePlugin(\n            createUnplugin(this, {\n              silenceHookLogging: true,\n              name: \"vite\"\n            })\n          )()\n        ]\n      }) as InlineConfig;\n\n      this.debug({\n        meta: {\n          category: \"config\"\n        },\n        message: `Resolved Vite configuration: \\n${formatConfig(options)}`\n      });\n\n      await build(options);\n    }\n  };\n};\n\n"],"mappings":";;;;;;;;;;;AAsCA,MAAa,UACX,UAA6B,CAAC,MACT;CACrB,OAAO;EACL,MAAM;EACN,SAAS;GACP,KAAK,MACH,yEACF;GAEA,OAAO;IACL,QAAQ,EACN,QAAQ,CAAC,OAAO,KAAK,EACvB;IACA,MAAM,EACJ,GAAG,QACL;IACA,aAAa;GACf;EACF;EACA,MAAM,QAAQ;GACZ,KAAK,MAAM,gCAAgC;GAE3C,MAAM,eAAe,KAAK,YAAY,mBAAmB;GACzD,IAAI,CAAC,gBAAgB,OAAO,KAAK,YAAY,CAAC,CAAC,WAAW,GACxD,MAAM,IAAI,MACR,yLACF;GAGF,KAAK,MACH,oBAAoB,OAAO,KAAK,YAAY,CAAC,CAAC,OAAO,eACvD;GAEA,MAAM,WAAW,eAAe,IAAI;GACpC,MAAM,UAAU,KAAK,KAAK,OAAO,MAAM;IACrC,GAAG;IACH,QAAQ;IACR,OAAO,KAAK;IACZ,cAAc,OAAO,YACnB,OAAO,QAAQ,YAAY,CAAC,CAAC,KAAK,CAAC,MAAM,SAAS,CAChD,MACA,KAAK,KAAK,OAAO,MAAM,eAAe,GAAc,CAAC,CACvD,CAAC,CACH;IACA,SAAS,CACP,iBACE,eAAe,MAAM;KACnB,oBAAoB;KACpB,MAAM;IACR,CAAC,CACH,CAAC,CAAC,CACJ;GACF,CAAC;GAED,KAAK,MAAM;IACT,MAAM,EACJ,UAAU,SACZ;IACA,SAAS,kCAAkC,aAAa,OAAO;GACjE,CAAC;GAED,MAAM,MAAM,OAAO;EACrB;CACF;AACF"}