'use strict'; const node_crypto = require('node:crypto'); const fs = require('fs-extra'); const promises = require('node:fs/promises'); const path = require('node:path'); const vite = require('vite'); const parse = require('content-security-policy-parser'); const getEtag = require('etag'); const os = require('node:os'); const node_child_process = require('node:child_process'); const MagicString = require('magic-string'); function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; } const fs__default = /*#__PURE__*/_interopDefaultCompat(fs); const path__default = /*#__PURE__*/_interopDefaultCompat(path); const parse__default = /*#__PURE__*/_interopDefaultCompat(parse); const getEtag__default = /*#__PURE__*/_interopDefaultCompat(getEtag); const os__default = /*#__PURE__*/_interopDefaultCompat(os); const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString); const addHmrSupportToCsp = (hmrServerOrigin, inlineScriptHashes, contentSecurityPolicyStr) => { const inlineScriptHashesArr = Array.from(inlineScriptHashes); const scriptSrcs = ["'self'", hmrServerOrigin].concat( inlineScriptHashesArr || [] ); const contentSecurityPolicy = parse__default(contentSecurityPolicyStr || ""); contentSecurityPolicy["script-src"] = scriptSrcs.concat( contentSecurityPolicy["script-src"] ); contentSecurityPolicy["object-src"] = ["'self'"].concat( contentSecurityPolicy["object-src"] ); return Object.keys(contentSecurityPolicy).map((key) => { return `${key} ` + contentSecurityPolicy[key].filter((c, idx) => contentSecurityPolicy[key].indexOf(c) === idx).join(" "); }).join("; "); }; function getNormalizedFileName(fileName, includeExt = true) { let { dir, name, ext } = path__default.parse(vite.normalizePath(path__default.normalize(fileName))); if (!dir) { return `${name}${includeExt ? ext : ""}`; } dir = dir.startsWith("/") ? dir.slice(1) : dir; return `${dir}/${name}${includeExt ? ext : ""}`; } function getInputFileName(inputFileName, root) { return `${root}/${getNormalizedFileName(inputFileName, true)}`; } function getOutputFileName(inputFileName) { return getNormalizedFileName(inputFileName, false); } function getAdditionalInputAsWebAccessibleResource(input) { if (!input.webAccessible) { return null; } return { matches: input.webAccessible.matches, extension_ids: input.webAccessible.extensionIds, use_dynamic_url: true }; } function getNormalizedAdditionalInput(input) { const webAccessibleDefaults = { matches: [""], excludeEntryFile: false }; if (typeof input === "string") { return { fileName: input, webAccessible: webAccessibleDefaults }; } if (typeof input.webAccessible === "boolean") { return { ...input, webAccessible: input.webAccessible ? webAccessibleDefaults : null }; } return { ...input, webAccessible: { excludeEntryFile: webAccessibleDefaults.excludeEntryFile, ...input.webAccessible } }; } function getScriptHtmlLoaderFile(name, scriptSrcs) { const scriptsHtml = scriptSrcs.map((scriptSrc) => { return `