@prozilla-os/dev-tools 1.1.17 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/interactiveListPrompt-CsphCZPx.js +42 -0
- package/dist/chunks/interactiveListPrompt-CsphCZPx.js.map +1 -0
- package/dist/chunks/site-DHHrF1BY.js +673 -0
- package/dist/chunks/site-DHHrF1BY.js.map +1 -0
- package/dist/main.d.ts +271 -20
- package/dist/main.js +44 -12358
- package/dist/main.js.map +1 -1
- package/dist/prompts.d.ts +57 -0
- package/dist/prompts.js +5 -0
- package/dist/prompts.js.map +1 -0
- package/dist/test.d.ts +202 -0
- package/dist/test.js +80 -0
- package/dist/test.js.map +1 -0
- package/dist/vite.d.ts +123 -0
- package/dist/vite.js +9 -0
- package/dist/vite.js.map +1 -0
- package/package.json +28 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-DHHrF1BY.js","sources":["../../src/plugins/site/stageSite.ts","../../src/plugins/app/appMetadata.ts","../../src/plugins/_utils/package.utils.ts","../../src/plugins/app/app.ts","../../src/plugins/site/importMap.ts","../../src/plugins/site/site.ts"],"sourcesContent":["import type { AppsConfig } from \"@prozilla-os/core\";\nimport { Logger } from \"@prozilla-os/shared\";\nimport type { PluginContext } from \"rollup\";\nimport type { Plugin } from \"vite\";\n\n/**\n * Options for the {@link stageSitePlugin}.\n */\nexport interface StageOptions {\n\tappsConfig: AppsConfig;\n\n\t/**\n\t * Favicon of the website.\n\t */\n\tfavicon: string;\n\n\t/**\n\t * Name of the website.\n\t * @example \"ProzillaOS\"\n\t */\n\tsiteName: string;\n\n\t/**\n\t * Tag line of the website.\n\t * @example \"Web-based Operating System\"\n\t*/\n\tsiteTagLine: string;\n\n\t/**\n\t * Domain of the live website.\n\t * \n\t * A CNAME file will be generated with this value.\n\t * @example \"os.prozilla.dev\"\n\t */\n\tdomain: string;\n\n\t/**\n\t * Array of image URLs that will be added to the sitemap.\n\t */\n\timageUrls?: string[];\n}\n\ninterface StageOptionsExtended extends StageOptions {\n\timageUrls: string[];\n\tbaseUrl: string;\n\tpaths: FilePaths;\n}\n\ninterface FilePaths {\n\tsitemapXml: string;\n\trobotsTxt: string;\n\tindexHtml: string;\n\tcname: string;\n}\n\nconst logger = new Logger();\n\nfunction normalizeLineEndings(text: string) {\n\treturn text.replace(/\\r\\n/g, \"\\n\");\n}\n\nfunction generateSitemapXml(options: StageOptionsExtended) {\n\tconst { imageUrls, appsConfig, baseUrl } = options;\n\n\tconst date = new Date();\n\n\tconst year = date.getFullYear();\n\tconst month = date.getMonth() + 1;\n\tconst day = date.getDate();\n\n\tconst monthString = month >= 10 ? month.toString() : \"0\" + month;\n\tconst dayString = day >= 10 ? day.toString() : \"0\" + day;\n\n\tconst lastModified = `${year}-${monthString}-${dayString}`;\n\n\tconst images = imageUrls.map((path) => `\n\t\t<image:image>\n\t\t\t<image:loc>${baseUrl.slice(0, -1) + path}</image:loc>\n\t\t</image:image>`\n\t);\n\n\tconst pages = appsConfig.apps.map(({ id }) => `\n\t<url>\n\t\t<loc>${baseUrl + id}</loc>\n\t\t<lastmod>${lastModified}</lastmod>\n\t</url>`\n\t);\n\n\tconst sitemap = `\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE xml>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n\txmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\">\n\t<url>\n\t\t<loc>${baseUrl}</loc>\n\t\t<lastmod>${lastModified}</lastmod>\n\t\t${images.join(\"\")}\n\t</url>\n\t${pages.join(\"\")}\n</urlset>`;\n\n\treturn normalizeLineEndings(sitemap.trim());\n}\n\nfunction generateRobotsTxt(options: StageOptionsExtended) {\n\tconst { baseUrl } = options;\n\n\treturn normalizeLineEndings(`# https://www.robotstxt.org/robotstxt.html\nUser-agent: *\nDisallow:\nSitemap: ${baseUrl}sitemap.xml`);\n}\n\nfunction generateCname(options: StageOptionsExtended) {\n\treturn options.domain;\n}\n\nfunction generateTemplate(html: string, options: StageOptionsExtended) {\n\tconst { baseUrl } = options;\n\n\tconst baseUrlRegex = /(?<=\")https?:\\/\\/[a-z0-9-]+(\\.)([a-zA-Z0-9-]+(\\.))*[a-z]{2,3}\\/(?=.*\")/gi;\n\thtml = html.replaceAll(baseUrlRegex, baseUrl);\n\n\tconst commentsRegex = /<!--.*?-->/g;\n\thtml = html.replaceAll(commentsRegex, \"\");\n\n\tconst emptyLinesRegex = /^\\s*$\\n/gm;\n\thtml = html.replaceAll(emptyLinesRegex, \"\");\n\n\treturn normalizeLineEndings(html);\n}\n\n/**\n * To avoid GitHub pages rendering certain pages that are only defined by React router as a 404 page, \n * we copy the content of our index file to the 404 page, letting React router properly handle routing on every page.\n */\nfunction generate404Page(context: PluginContext, template: string) {\n\tcontext.emitFile({\n\t\ttype: \"asset\",\n\t\tfileName: \"404.html\",\n\t\tsource: template,\n\t});\n}\n\n/**\n * Add an HTML file for every app page so they can be properly crawled and indexed.\n */\nfunction generateAppPages(context: PluginContext, template: string, options: StageOptionsExtended) {\n\tconst { appsConfig, favicon, siteName, siteTagLine, baseUrl } = options;\n\n\tfor (const app of appsConfig.apps) {\n\t\tconst appId = app.id;\n\t\tconst appName = app.name;\n\t\tconst appDescription = app.description ?? siteTagLine;\n\t\tconst appIcon = app.iconUrl ?? favicon;\n\n\t\tif (appId === \"index\") {\n\t\t\tlogger.error(`Invalid app ID found: ${appId}`);\n\t\t\treturn;\n\t\t}\n\n\t\tlet html = template;\n\t\t\n\t\tconst titleRegex = /(?<=(<title>|<meta property=\"og:title\" content=\"|<meta name=\"twitter:title\" content=\"))(([a-zA-Z|-]|\\s)+)(?=(<\\/title>|\"\\/?>))/g;\n\t\thtml = html.replaceAll(titleRegex, `${appName} | ${siteName}`);\n\n\t\tconst descriptionRegex = /(?<=(<meta name=\"description\" content=\"|<meta property=\"og:description\" content=\"|<meta name=\"twitter:description\" content=\"))(([a-zA-Z-.]|\\s)+)(?=(\"\\/?>))/g;\n\t\thtml = html.replaceAll(descriptionRegex, appDescription);\n\n\t\tconst canonicalRegex = /(?<=(<link rel=\"canonical\" href=\"|<meta name=\"twitter:url\" content=\"|<meta property=\"og:url\" content=\"))(http(s)?:\\/\\/[a-zA-Z-.]+\\/)(?=(\"\\/?>))/g;\n\t\thtml = html.replaceAll(canonicalRegex, baseUrl + appId);\n\n\t\tconst iconRegex = /(?<=<link [^>]*rel=\"(apple-touch-)?icon\" [^>]*href=\")[^\"]+(?=\"[^>]*>)/g;\n\t\thtml = html.replaceAll(iconRegex, `${appIcon}?x=${Math.round(Date.now() / 3_600_000)}`);\n\n\t\tconst faqRegex = /(<!-- FAQ -->.*?)?<script type=\"application\\/ld\\+json\">.*?<\\/script>/gs;\n\t\thtml = html.replaceAll(faqRegex, \"\");\n\n\t\tcontext.emitFile({\n\t\t\ttype: \"asset\",\n\t\t\tfileName: `${appId}.html`,\n\t\t\tsource: html,\n\t\t});\n\t}\n}\n\nfunction stageSite(context: PluginContext, htmlTemplate: string | null, { appsConfig, favicon, siteName, siteTagLine, domain, imageUrls = [] }: StageOptions) {\n\ttry {\n\t\tlogger.pending(\"Staging build...\");\n\n\t\tconst baseUrl = `https://${domain}/`;\n\n\t\tconst paths: FilePaths = {\n\t\t\tsitemapXml: \"sitemap.xml\",\n\t\t\trobotsTxt: \"robots.txt\",\n\t\t\tindexHtml: \"index.html\",\n\t\t\tcname: \"CNAME\",\n\t\t};\n\t\n\t\tconst files: [string, (options: StageOptionsExtended) => string][] = [\n\t\t\t[paths.sitemapXml, generateSitemapXml],\n\t\t\t[paths.robotsTxt, generateRobotsTxt],\n\t\t\t[paths.cname, generateCname],\n\t\t];\n\n\t\tconst extendedOptions = {\n\t\t\tappsConfig,\n\t\t\tfavicon,\n\t\t\tsiteName,\n\t\t\tsiteTagLine,\n\t\t\tdomain,\n\t\t\tbaseUrl,\n\t\t\timageUrls,\n\t\t\tpaths,\n\t\t};\n\t\n\t\tfiles.forEach(([path, generateContent]) => {\n\t\t\tcontext.emitFile({\n\t\t\t\ttype: \"asset\",\n\t\t\t\tfileName: path,\n\t\t\t\tsource: generateContent(extendedOptions),\n\t\t\t});\n\t\t});\n\n\t\tif (htmlTemplate != null) {\n\t\t\tconst template = generateTemplate(htmlTemplate, extendedOptions);\n\n\t\t\tcontext.emitFile({\n\t\t\t\ttype: \"asset\",\n\t\t\t\tfileName: \"index.html\",\n\t\t\t\tsource: template, \n\t\t\t});\n\n\t\t\tgenerate404Page(context, template);\n\t\t\tgenerateAppPages(context, template, extendedOptions);\n\t\t}\n\t\n\t\tlogger.success(\"Staging complete\");\n\t} catch (error) {\n\t\tlogger.error(error).error(\"Staging failed\");\n\t\tprocess.exit(1);\n\t}\n}\n\n/**\n * Vite plugin that prepares the build of a website that uses ProzillaOS.\n */\nexport function stageSitePlugin(options: StageOptions): Plugin {\n\tlet htmlTemplate: string | null = null;\n\n\treturn {\n\t\tname: \"vite-plugin-stage-site\",\n\n\t\ttransformIndexHtml(html) {\n\t\t\thtmlTemplate = html;\n\t\t\treturn;\n\t\t},\n\n\t\tgenerateBundle() {\n\t\t\tstageSite(this, htmlTemplate, options);\n\t\t},\n\t};\n}\n","import MagicString from \"magic-string\";\nimport { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { RollupError } from \"rollup\";\nimport { Plugin } from \"vite\";\n\ninterface PackageJson {\n name: string;\n version: string;\n author?: string | { name: string };\n homepage?: string;\n}\n\n/**\n * Options for the {@link appMetadataPlugin}.\n */\nexport interface AppMetadataPluginOptions {\n\t/** Path to the app's entry file, relative to the project root. */\n entryPath: string;\n\t/**\n\t * Name of the app class.\n\t * @default \"App\"\n\t */\n appClass?: string;\n}\n\n/**\n * Vite plugin that automatically adds metadata to ProzillaOS apps.\n */\nexport function appMetadataPlugin({ entryPath, appClass = \"App\" }: AppMetadataPluginOptions): Plugin {\n\treturn {\n\t\tname: \"vite-plugin-app-metadata\",\n\t\tapply: \"build\",\n\t\ttransform(code, id) {\n\t\t\tif (!id.includes(entryPath)) return null;\n\n\t\t\tconst rootDir = process.cwd();\n\t\t\tconst packageJsonPath = resolve(rootDir, \"package.json\");\n\n\t\t\tlet packageJson: PackageJson | null = null;\n\t\t\ttry {\n\t\t\t\tconst packageJsonContent = readFileSync(packageJsonPath, \"utf-8\");\n\t\t\t\tpackageJson = JSON.parse(packageJsonContent) as PackageJson | null;\n\t\t\t} catch (error) {\n\t\t\t\tthis.error(error as RollupError);\n\t\t\t}\n\t\t\tif (packageJson === null) return null;\n\n\t\t\tconst { name, version, homepage } = packageJson;\n\t\t\tlet { author = \"Unknown\" } = packageJson;\n\t\t\tif (typeof author === \"string\") {\n\t\t\t\tauthor = author.replace(/<[^>]*>|\\([^)]*\\)/g, \"\").trim();\n\t\t\t} else {\n\t\t\t\tauthor = author.name;\n\t\t\t}\n\n\t\t\t// Find instance of app class\n\t\t\tconst appInstanceRegex = new RegExp(`const\\\\s+(\\\\w+)\\\\s*=\\\\s*new\\\\s+${appClass}(?:<[\\\\w\\\\s,]+>)?\\\\s*\\\\(([^;]*)\\\\)\\\\s*(\\\\.[\\\\w]+\\\\([^)]*\\\\)\\\\s*)*;`);\n\t\t\tconst match = code.match(appInstanceRegex);\n\n\t\t\tif (match == null || match.index == null) {\n\t\t\t\treturn this.error(\"No App instance found in the entry file.\");\n\t\t\t}\n\n\t\t\tconst appInstanceName = match[1];\n\n\t\t\t// Inject code to set metadata of app\n\t\t\tconst metadataFields = [`name: \"${name}\"`, `version: \"${version}\"`, `author: \"${author}\"`];\n\t\t\tif (homepage) {\n\t\t\t\tmetadataFields.push(`website: \"${homepage}\"`);\n\t\t\t}\n\t\t\tconst injectCode = `\\n${appInstanceName}.setMetadata({ ${metadataFields.join(\", \")} });\\n`;\n\n\t\t\tconst insertPosition = match.index + match[0].length;\n\t\t\tconst magicString = new MagicString(code);\n\t\t\tmagicString.appendLeft(insertPosition, injectCode);\n\n\t\t\treturn {\n\t\t\t\tcode: magicString.toString(),\n\t\t\t\tmap: magicString.generateMap({ hires: true }),\n\t\t\t};\n\t\t},\n\t};\n}","import { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { isObject } from \"@prozilla-os/shared/utils\";\n\nexport const PROZILLA_OS_SCOPE = \"@prozilla-os/\";\nexport const ALWAYS_SHARED_SPECIFIERS = new Set([\"react\", \"react-dom\", \"react/jsx-runtime\"]);\n\nexport interface PackageJson {\n\tdependencies?: Record<string, string>;\n\tpeerDependencies?: Record<string, string>;\n\texports?: unknown;\n\tmodule?: string;\n\tmain?: string;\n}\n\nexport function readPackageJson(directory: string): PackageJson | null {\n\ttry {\n\t\tconst content = readFileSync(resolve(directory, \"package.json\"), \"utf-8\");\n\t\tconst parsed: unknown = JSON.parse(content);\n\n\t\tif (!isObject(parsed))\n\t\t\treturn null;\n\n\t\tconst result: PackageJson = {};\n\t\tif (isStringRecord(parsed.dependencies))\n\t\t\tresult.dependencies = parsed.dependencies;\n\t\tif (isStringRecord(parsed.peerDependencies))\n\t\t\tresult.peerDependencies = parsed.peerDependencies;\n\n\t\tresult.exports = parsed.exports;\n\t\tresult.module = typeof parsed.module === \"string\" ? parsed.module : undefined;\n\t\tresult.main = typeof parsed.main === \"string\" ? parsed.main : undefined;\n\n\t\treturn result;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction isStringRecord(value: unknown): value is Record<string, string> {\n\treturn isObject(value)\n\t\t&& Object.values(value).every((value) => typeof value === \"string\");\n}\n\nexport function collectDependencyNames(packageJson: PackageJson) {\n\treturn [\n\t\t...Object.keys(packageJson.dependencies ?? {}),\n\t\t...Object.keys(packageJson.peerDependencies ?? {}),\n\t];\n}\n\nexport function discoverSharedSpecifiers(projectRoot: string) {\n\tconst projectPackage = readPackageJson(projectRoot);\n\tif (projectPackage == null)\n\t\treturn [];\n\n\tconst allDependencyNames = collectDependencyNames(projectPackage);\n\tconst specifiers = new Set(ALWAYS_SHARED_SPECIFIERS);\n\n\tfor (const dependencyName of allDependencyNames) {\n\t\tif (dependencyName.startsWith(PROZILLA_OS_SCOPE))\n\t\t\tspecifiers.add(dependencyName);\n\t}\n\n\treturn Array.from(specifiers);\n}","import { resolve } from \"node:path\";\nimport { PluginOption } from \"vite\";\nimport react from \"@vitejs/plugin-react-swc\";\nimport dts from \"vite-plugin-dts\";\nimport cssInjectedByJs from \"vite-plugin-css-injected-by-js\";\nimport { appMetadataPlugin } from \"./appMetadata\";\nimport { discoverSharedSpecifiers } from \"../_utils/package.utils\";\n\n/**\n * Options for the {@link appPlugin}.\n */\nexport interface AppPluginOptions {\n\t/** Path to the app's entry file, relative to the project root. */\n\tentryPath: string;\n\t/** CSS class name for the app's root element. */\n\tappClass?: string;\n\t/** Path to the TypeScript build config. Defaults to \"tsconfig.build.json\". */\n\ttsconfigPath?: string;\n\t/** Shared package specifiers to mark as external. Auto-discovered from package.json when omitted. */\n\tsharedPackages?: string[];\n\t/** Additional external patterns (strings or RegExps) beyond the shared package specifiers. */\n\texternalPatterns?: (string | RegExp)[];\n}\n\n/**\n * Vite plugin for building ProzillaOS apps.\n * @example\n * ```ts\n * import { defineConfig } from \"vite\";\n * import { appPlugin } from \"@prozilla-os/dev-tools\";\n *\n * export default defineConfig({\n * plugins: [appPlugin({ entryPath: \"src/main.ts\" })],\n * });\n * ```\n */\nexport function appPlugin(options: AppPluginOptions): PluginOption[] {\n\tconst {\n\t\tentryPath,\n\t\tappClass,\n\t\ttsconfigPath = \"tsconfig.build.json\",\n\t\tsharedPackages,\n\t\texternalPatterns = [],\n\t} = options;\n\n\treturn [\n\t\tappMetadataPlugin({ entryPath, appClass }),\n\t\treact(),\n\t\tcssInjectedByJs(),\n\t\tdts({\n\t\t\toutDir: \"dist\",\n\t\t\trollupTypes: true,\n\t\t\tstrictOutput: true,\n\t\t\tpathsToAliases: false,\n\t\t\ttsconfigPath,\n\t\t}),\n\t\t{\n\t\t\tname: \"prozilla-os-app\",\n\t\t\tconfig(config) {\n\t\t\t\tconst root = config.root ?? process.cwd();\n\t\t\t\tconst entryFile = resolve(root, entryPath);\n\n\t\t\t\tconst resolvedSpecifiers = sharedPackages ?? discoverSharedSpecifiers(root);\n\n\t\t\t\treturn {\n\t\t\t\t\tbuild: {\n\t\t\t\t\t\tlib: {\n\t\t\t\t\t\t\tentry: entryFile,\n\t\t\t\t\t\t\tformats: [\"es\"],\n\t\t\t\t\t\t},\n\t\t\t\t\t\trollupOptions: {\n\t\t\t\t\t\t\texternal: [\n\t\t\t\t\t\t\t\t...resolvedSpecifiers,\n\t\t\t\t\t\t\t\t...externalPatterns,\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\toutput: {\n\t\t\t\t\t\t\t\tassetFileNames: \"assets/[name][extname]\",\n\t\t\t\t\t\t\t\tchunkFileNames: \"chunks/[name]-[hash].js\",\n\t\t\t\t\t\t\t\tentryFileNames: \"[name].js\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsourcemap: true,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t},\n\t\t},\n\t];\n}","import { mkdirSync, readFileSync, writeFileSync, readdirSync } from \"node:fs\";\nimport { basename, dirname, resolve } from \"node:path\";\nimport { createRequire } from \"node:module\";\nimport type { ManualChunkMeta, OutputBundle, OutputOptions } from \"rollup\";\nimport type { Connect, PluginOption, ViteDevServer } from \"vite\";\nimport { IncomingMessage, ServerResponse } from \"node:http\";\nimport { isObject } from \"@prozilla-os/shared/utils\";\nimport { ALWAYS_SHARED_SPECIFIERS, PROZILLA_OS_SCOPE, collectDependencyNames, readPackageJson } from \"../_utils/package.utils\";\n\nconst SHIM_PATH_PREFIX = \"/__shim/\";\nconst SHARED_PATH_PREFIX = \"/__shared/\";\nconst ASSETS_DIRECTORY = \"assets\";\nconst SHIM_DIRECTORY_NAME = \"__shim\";\nconst VITE_DEPS_PREFIX = \"/node_modules/.vite/deps/\";\nconst PLACEHOLDER_PREFIX = \"IMPORT_MAP_PLACEHOLDER_\";\n\nconst IMPORT_MAP_SCRIPT_TAG = \"script\" as const;\nconst IMPORT_MAP_SCRIPT_TYPE = \"importmap\" as const;\n\nconst SHIM_URL_PATTERN = /^\\/__shim\\/(.+)\\.js$/;\nconst SHARED_URL_PATTERN = /^\\/__shared\\/(.+)\\.js$/;\nconst RELATIVE_IMPORT_PATTERN = /[\"']((\\.\\.?\\/)[^\"']+)[\"']/g;\n\nconst PRODUCTION_ENV_REPLACEMENT = \"\\\"production\\\"\" as const;\nconst DEVELOPMENT_ENV_REPLACEMENT = \"\\\"development\\\"\" as const;\nconst NODE_ENV_REGEX = /process\\.env\\.NODE_ENV/g;\n\nconst NODE_MODULES_MATCH_PREFIX = \"/node_modules/\";\n\nconst COMMON_JS_PACKAGE_CONFIGS = new Map<string, { chunkName: string; isCommonJS: true }>([\n\t[\"react\", { chunkName: \"react\", isCommonJS: true }],\n\t[\"react/jsx-runtime\", { chunkName: \"react-jsx-runtime\", isCommonJS: true }],\n\t[\"react-dom\", { chunkName: \"react-dom\", isCommonJS: true }],\n]);\n\nconst EXPORT_ORDER = [\"module\", \"import\", \"default\"] as const;\nconst MAX_EXPORT_DEPTH = 3;\nconst EXCLUDED_EXPORT_KEYS = new Set([\"__esModule\", \"default\"]);\n\nexport interface SharedPackage {\n\tspecifier: string;\n\tchunkName?: string;\n\tisCommonJS?: boolean;\n}\n\ninterface ShimEntry {\n\turlName: string;\n\tspecifier: string;\n}\n\ninterface ShimFile {\n\tpath: string;\n\tcode: string;\n}\n\ninterface DerivedData {\n\tshimEntries: ShimEntry[];\n\tchunkPatterns: ChunkPattern[];\n\tnonChunkEntries: ShimEntry[];\n}\n\ninterface ChunkPattern {\n\tchunkName: string;\n\tsubpath: string | undefined;\n\tpattern: RegExp;\n}\n\n/**\n * Options for the {@link importMapPlugin}.\n */\nexport interface ImportMapPluginOptions {\n\t/** Packages to expose via import map. When omitted, auto-discovered from the project's package.json. */\n\tsharedPackages?: SharedPackage[];\n\t/** Dev-mode import map overrides for packages not handled by CommonJS shims. */\n\tdevImports?: Record<string, string>;\n}\n\n/**\n * Vite plugin that generates an import map in order to support dynamically installing apps into ProzillaOS.\n */\nexport function importMapPlugin(options: ImportMapPluginOptions = {}): PluginOption {\n\tconst { sharedPackages, devImports: userDevImports = {} } = options;\n\n\tlet isDev = false;\n\tlet projectRoot = \"\";\n\n\tconst chunkUrlBySpecifier = new Map<string, string>();\n\tconst viteUrlBySpecifier = new Map<string, string>();\n\tconst pendingShimFiles: ShimFile[] = [];\n\n\tconst resolvedPackages: SharedPackage[] = sharedPackages ?? [];\n\n\tconst derivedData: DerivedData = {\n\t\tshimEntries: buildShimEntries(resolvedPackages),\n\t\tchunkPatterns: computeChunkPatterns(resolvedPackages),\n\t\tnonChunkEntries: computeNonChunkEntries(resolvedPackages),\n\t};\n\n\tconst exportsCache: Record<string, string[] | undefined> = {};\n\n\treturn {\n\t\tname: \"import-map\",\n\n\t\tconfigResolved(config) {\n\t\t\tisDev = config.command === \"serve\";\n\t\t\tprojectRoot = config.root;\n\n\t\t\tif (sharedPackages != null)\n\t\t\t\treturn;\n\n\t\t\tconst discovered = discoverSharedPackages(projectRoot);\n\t\t\tresolvedPackages.length = 0;\n\t\t\tresolvedPackages.push(...discovered);\n\n\t\t\tderivedData.shimEntries = buildShimEntries(resolvedPackages);\n\t\t\tderivedData.chunkPatterns = computeChunkPatterns(resolvedPackages);\n\t\t\tderivedData.nonChunkEntries = computeNonChunkEntries(resolvedPackages);\n\t\t},\n\n\t\tconfig(config, _env) {\n\t\t\tconst existingOutputs = normalizeOutputOptions(config.build?.rollupOptions?.output);\n\t\t\tconst existingInclude = config.optimizeDeps?.include ?? [];\n\n\t\t\tconst wrappedOutputs = existingOutputs.map((existingOutput: OutputOptions) => ({\n\t\t\t\t...existingOutput,\n\t\t\t\tmanualChunks: (id: string, meta: ManualChunkMeta) => {\n\t\t\t\t\tif (typeof existingOutput.manualChunks === \"function\") {\n\t\t\t\t\t\tconst result = existingOutput.manualChunks(id, meta);\n\t\t\t\t\t\tif (result)\n\t\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn matchChunkPattern(id, derivedData.chunkPatterns);\n\t\t\t\t},\n\t\t\t}));\n\n\t\t\treturn {\n\t\t\t\toptimizeDeps: {\n\t\t\t\t\tinclude: [...new Set([\n\t\t\t\t\t\t...existingInclude,\n\t\t\t\t\t\t...derivedData.shimEntries.map((entry) => entry.specifier),\n\t\t\t\t\t])],\n\t\t\t\t},\n\t\t\t\tbuild: {\n\t\t\t\t\trollupOptions: {\n\t\t\t\t\t\toutput: wrappedOutputs,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\n\t\tasync configureServer(server) {\n\t\t\tawait resolveNonChunkViteUrls(server, derivedData.nonChunkEntries, viteUrlBySpecifier, projectRoot);\n\n\t\t\tserver.middlewares.use((request, response, nextMiddleware) => {\n\t\t\t\thandleSharedRequest(\n\t\t\t\t\trequest,\n\t\t\t\t\tresponse,\n\t\t\t\t\tprojectRoot,\n\t\t\t\t\tderivedData.nonChunkEntries,\n\t\t\t\t\tserver\n\t\t\t\t).then((handled) => {\n\t\t\t\t\tif (handled)\n\t\t\t\t\t\treturn;\n\n\t\t\t\t\thandleShimRequest(\n\t\t\t\t\t\trequest,\n\t\t\t\t\t\tresponse,\n\t\t\t\t\t\tnextMiddleware,\n\t\t\t\t\t\tprojectRoot,\n\t\t\t\t\t\tderivedData.shimEntries,\n\t\t\t\t\t\texportsCache\n\t\t\t\t\t);\n\t\t\t\t}).catch(() => {\n\t\t\t\t\tnextMiddleware();\n\t\t\t\t});\n\t\t\t});\n\t\t},\n\n\t\ttransformIndexHtml() {\n\t\t\treturn [buildImportMapScript(isDev\n\t\t\t\t? buildDevImportMap(userDevImports, derivedData, viteUrlBySpecifier)\n\t\t\t\t: buildBuildImportMap(resolvedPackages)),\n\t\t\t];\n\t\t},\n\n\t\tgenerateBundle(options, bundle) {\n\t\t\tpendingShimFiles.length = 0;\n\n\t\t\tcollectChunkUrls(resolvedPackages, bundle, chunkUrlBySpecifier);\n\t\t\tcollectPendingShims(resolvedPackages, chunkUrlBySpecifier, derivedData.shimEntries, projectRoot, options.dir, pendingShimFiles, exportsCache);\n\n\t\t\tfor (const sharedPackage of resolvedPackages) {\n\t\t\t\tif (sharedPackage.chunkName)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tconst entryPath = resolveEsmEntry(sharedPackage.specifier, projectRoot);\n\t\t\t\tconst collected = collectAssetFiles(entryPath);\n\n\t\t\t\tfor (const filePath of collected.filePaths) {\n\t\t\t\t\tif (filePath === entryPath)\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tthis.emitFile({\n\t\t\t\t\t\ttype: \"asset\",\n\t\t\t\t\t\tname: basename(filePath),\n\t\t\t\t\t\tsource: collected.codeByPath.get(filePath),\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst assetReference = this.emitFile({\n\t\t\t\t\ttype: \"asset\",\n\t\t\t\t\tname: collected.entryAssetName,\n\t\t\t\t\tsource: collected.codeByPath.get(entryPath),\n\t\t\t\t});\n\n\t\t\t\tconst assetFileName = this.getFileName(assetReference);\n\t\t\t\tconst assetUrl = \"/\" + assetFileName.replace(/\\\\/g, \"/\");\n\t\t\t\tchunkUrlBySpecifier.set(sharedPackage.specifier, assetUrl);\n\t\t\t}\n\t\t},\n\n\t\twriteBundle(options) {\n\t\t\tif (isDev || !options.dir)\n\t\t\t\treturn;\n\n\t\t\twriteShimFiles(pendingShimFiles, options.dir);\n\t\t\tconst resolvedImports = resolveChunkImports(resolvedPackages, chunkUrlBySpecifier, derivedData.shimEntries);\n\t\t\treplacePlaceholdersInHtmlFiles(options.dir, resolvedImports);\n\t\t},\n\t};\n}\n\nfunction buildDevImportMap(userImports: Record<string, string>, derivedData: DerivedData, urlMap: Map<string, string>) {\n\tconst result: Record<string, string> = { ...userImports };\n\tfor (const entry of derivedData.shimEntries) {\n\t\tresult[entry.specifier] = `${SHIM_PATH_PREFIX}${entry.urlName}.js`;\n\t}\n\tfor (const entry of derivedData.nonChunkEntries) {\n\t\tconst resolvedUrl = urlMap.get(entry.specifier);\n\t\tresult[entry.specifier] = resolvedUrl ?? `${SHARED_PATH_PREFIX}${entry.urlName}.js`;\n\t}\n\treturn result;\n}\n\nfunction buildBuildImportMap(resolvedPackages: SharedPackage[]) {\n\tconst result: Record<string, string> = {};\n\tfor (const sharedPackage of resolvedPackages) {\n\t\tresult[sharedPackage.specifier] = toPlaceholder(sharedPackage.specifier);\n\t}\n\treturn result;\n}\n\nfunction buildImportMapScript(imports: Record<string, string>) {\n\treturn {\n\t\ttag: IMPORT_MAP_SCRIPT_TAG,\n\t\tattrs: { type: IMPORT_MAP_SCRIPT_TYPE },\n\t\tchildren: JSON.stringify({ imports }),\n\t};\n}\n\nfunction resolveChunkImports(resolvedPackages: SharedPackage[], chunkUrlBySpecifier: Map<string, string>, shimEntries: ShimEntry[]) {\n\tconst imports: Record<string, string> = {};\n\n\tfor (const sharedPackage of resolvedPackages) {\n\t\tconst chunkUrl = chunkUrlBySpecifier.get(sharedPackage.specifier);\n\t\tif (!chunkUrl)\n\t\t\tcontinue;\n\n\t\tif (sharedPackage.isCommonJS) {\n\t\t\tconst entry = shimEntries.find((entry) => entry.specifier === sharedPackage.specifier);\n\t\t\tif (entry)\n\t\t\t\timports[sharedPackage.specifier] = `${SHIM_PATH_PREFIX}${entry.urlName}.js`;\n\t\t} else {\n\t\t\timports[sharedPackage.specifier] = chunkUrl;\n\t\t}\n\t}\n\n\treturn imports;\n}\n\nfunction writeShimFiles(shimFiles: ShimFile[], outputDirectory: string) {\n\tconst shimDirectory = resolve(outputDirectory, SHIM_DIRECTORY_NAME);\n\tmkdirSync(shimDirectory, { recursive: true });\n\n\tfor (const shim of shimFiles) {\n\t\twriteFileSync(shim.path, shim.code);\n\t}\n}\n\nfunction replacePlaceholdersInHtmlFiles(directory: string, imports: Record<string, string>) {\n\tif (!Object.keys(imports).length)\n\t\treturn;\n\n\tlet htmlFiles: string[];\n\ttry {\n\t\tconst files = readdirSync(directory);\n\t\thtmlFiles = files\n\t\t\t.filter((file) => file.endsWith(\".html\"))\n\t\t\t.map((file) => resolve(directory, file));\n\t} catch {\n\t\treturn;\n\t}\n\n\tif (!htmlFiles.length)\n\t\treturn;\n\n\tfor (const htmlPath of htmlFiles) {\n\t\tlet html: string;\n\t\ttry {\n\t\t\thtml = readFileSync(htmlPath, \"utf-8\");\n\t\t} catch {\n\t\t\tcontinue;\n\t\t}\n\n\t\tfor (const [specifier, url] of Object.entries(imports)) {\n\t\t\thtml = html.split(toPlaceholder(specifier)).join(url);\n\t\t}\n\n\t\twriteFileSync(htmlPath, html);\n\t}\n}\n\nasync function resolveNonChunkViteUrls(\n\tserver: ViteDevServer,\n\tnonChunkEntries: ShimEntry[],\n\turlMap: Map<string, string>,\n\tprojectRoot: string\n) {\n\tfor (const entry of nonChunkEntries) {\n\t\ttry {\n\t\t\tconst resolved = await server.pluginContainer.resolveId(entry.specifier, undefined);\n\t\t\tif (resolved?.id != null)\n\t\t\t\turlMap.set(entry.specifier, toViteUrl(resolved.id, projectRoot));\n\t\t} catch { /* empty */ }\n\t}\n}\n\nfunction collectChunkUrls(resolvedPackages: SharedPackage[], bundle: OutputBundle, urlMap: Map<string, string>) {\n\tfor (const sharedPackage of resolvedPackages) {\n\t\tif (sharedPackage.chunkName == null)\n\t\t\tcontinue;\n\n\t\tfor (const chunk of Object.values(bundle)) {\n\t\t\tif (chunk.type !== \"chunk\" || chunk.name !== sharedPackage.chunkName)\n\t\t\t\tcontinue;\n\n\t\t\tconst chunkFileName = chunk.fileName;\n\t\t\tconst chunkUrl = \"/\" + chunkFileName.split(\"\\\\\").join(\"/\");\n\t\t\turlMap.set(sharedPackage.specifier, chunkUrl);\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nfunction collectPendingShims(\n\tresolvedPackages: SharedPackage[],\n\tchunkUrlMap: Map<string, string>,\n\tshimEntries: ShimEntry[],\n\tprojectRoot: string,\n\toutputDirectory: string | undefined,\n\tpendingShims: ShimFile[],\n\texportsCache: Record<string, string[] | undefined>\n) {\n\tfor (const sharedPackage of resolvedPackages) {\n\t\tif (!sharedPackage.isCommonJS || !sharedPackage.chunkName)\n\t\t\tcontinue;\n\n\t\tconst chunkUrl = chunkUrlMap.get(sharedPackage.specifier);\n\t\tif (!chunkUrl)\n\t\t\tcontinue;\n\n\t\tconst shimEntry = shimEntries.find((entry) => entry.specifier === sharedPackage.specifier);\n\t\tif (!shimEntry)\n\t\t\tcontinue;\n\n\t\tconst exportNames = getExportNames(shimEntry.specifier, projectRoot, exportsCache);\n\t\tif (!exportNames.length)\n\t\t\tcontinue;\n\n\t\tconst resolvedDirectory = outputDirectory ?? \"dist\";\n\t\tpendingShims.push({\n\t\t\tpath: resolve(resolvedDirectory, SHIM_DIRECTORY_NAME, `${shimEntry.urlName}.js`),\n\t\t\tcode: generateShimCode(chunkUrl, exportNames),\n\t\t});\n\t}\n}\n\nfunction collectAssetFiles(entryPath: string) {\n\tconst entryCode = readFileSync(entryPath, \"utf-8\")\n\t\t.replace(NODE_ENV_REGEX, PRODUCTION_ENV_REPLACEMENT);\n\n\tconst entryAssetName = toUrlName(basename(entryPath, \".js\")) + \".js\";\n\tconst entryAssetUrl = `/${ASSETS_DIRECTORY}/${entryAssetName}`;\n\n\tconst assetUrlByPath = new Map<string, string>();\n\tconst codeByPath = new Map<string, string>();\n\tassetUrlByPath.set(entryPath, entryAssetUrl);\n\tcodeByPath.set(entryPath, entryCode);\n\n\tconst pendingFiles = [entryPath];\n\tconst visitedFiles = new Set<string>([entryPath]);\n\n\twhile (pendingFiles.length) {\n\t\tconst currentPath = pendingFiles.shift();\n\t\tif (!currentPath)\n\t\t\tbreak;\n\n\t\tconst currentDirectory = dirname(currentPath);\n\t\tconst currentCode = codeByPath.get(currentPath);\n\t\tif (!currentCode)\n\t\t\tcontinue;\n\n\t\tlet importMatch: RegExpExecArray | null;\n\t\twhile ((importMatch = RELATIVE_IMPORT_PATTERN.exec(currentCode)) !== null) {\n\t\t\tconst capturedPath = importMatch[1];\n\t\t\tconst resolvedPath = resolve(currentDirectory, capturedPath);\n\n\t\t\tif (visitedFiles.has(resolvedPath))\n\t\t\t\tcontinue;\n\n\t\t\tvisitedFiles.add(resolvedPath);\n\n\t\t\ttry {\n\t\t\t\tconst chunkCode = readFileSync(resolvedPath, \"utf-8\");\n\t\t\t\tcodeByPath.set(resolvedPath, chunkCode);\n\t\t\t\tassetUrlByPath.set(resolvedPath, `/${ASSETS_DIRECTORY}/${basename(resolvedPath)}`);\n\t\t\t\tpendingFiles.push(resolvedPath);\n\t\t\t} catch { /* empty */ }\n\t\t}\n\t}\n\n\tfor (const [filePath, code] of codeByPath) {\n\t\tcodeByPath.set(filePath, rewriteRelativeImports(code, dirname(filePath), assetUrlByPath));\n\t}\n\n\treturn {\n\t\tentryAssetName,\n\t\tfilePaths: Array.from(codeByPath.keys()),\n\t\tcodeByPath,\n\t};\n}\n\nfunction rewriteRelativeImports(code: string, fileDirectory: string, assetUrlByPath: Map<string, string>) {\n\treturn code.replace(RELATIVE_IMPORT_PATTERN, (match: string, capturedPath: string) => {\n\t\tconst resolvedPath = resolve(fileDirectory, capturedPath);\n\t\tconst assetUrl = assetUrlByPath.get(resolvedPath);\n\t\treturn assetUrl != null ? `\"${assetUrl}\"` : match;\n\t});\n}\n\nfunction generateShimCode(chunkUrl: string, exportNames: string[]) {\n\treturn [\n\t\t`import * as __raw from \"${chunkUrl}\";`,\n\t\t\"const __mod = __raw.default ?? Object.values(__raw)[0] ?? __raw;\",\n\t\t`const { ${exportNames.join(\", \")} } = __mod;`,\n\t\t`export { ${exportNames.join(\", \")} };`,\n\t\t\"export default __mod;\",\n\t].join(\"\\n\");\n}\n\nfunction matchChunkPattern(id: string, patterns: ChunkPattern[]) {\n\tfor (const { chunkName, pattern, subpath } of patterns) {\n\t\tif (pattern.test(id) && (!subpath || id.includes(subpath)))\n\t\t\treturn chunkName;\n\t}\n\treturn null;\n}\n\nfunction normalizeOutputOptions(output: OutputOptions | OutputOptions[] | undefined) {\n\tif (!output)\n\t\treturn [{}];\n\treturn Array.isArray(output) ? output : [output];\n}\n\nfunction toUrlName(specifier: string) {\n\treturn specifier.replace(/^@/, \"\").replace(/[^a-zA-Z0-9]/g, \"_\");\n}\n\nfunction toViteDependencyName(specifier: string) {\n\treturn specifier.replace(/^@/, \"\").replace(/\\//g, \"_\");\n}\n\nfunction toViteUrl(resolvedId: string, projectRoot: string) {\n\tconst normalizedId = resolvedId.replace(/\\\\/g, \"/\");\n\tconst normalizedRoot = projectRoot.replace(/\\\\/g, \"/\") + \"/\";\n\treturn normalizedId.startsWith(normalizedRoot)\n\t\t? \"/\" + normalizedId.slice(normalizedRoot.length)\n\t\t: \"/@fs/\" + normalizedId;\n}\n\nfunction toPlaceholder(specifier: string) {\n\tconst safe = specifier.replace(/[^a-zA-Z0-9]/g, \"_\");\n\treturn `__${PLACEHOLDER_PREFIX}${safe}__`;\n}\n\nfunction buildShimEntries(sharedPackages: SharedPackage[]): ShimEntry[] {\n\treturn sharedPackages\n\t\t.filter((sharedPackage) => sharedPackage.isCommonJS)\n\t\t.map((sharedPackage) => ({\n\t\t\turlName: toUrlName(sharedPackage.specifier),\n\t\t\tspecifier: sharedPackage.specifier,\n\t\t}));\n}\n\nfunction computeChunkPatterns(sharedPackages: SharedPackage[]): ChunkPattern[] {\n\treturn sharedPackages\n\t\t.filter(({ chunkName }) => chunkName != null)\n\t\t.sort((a, b) => b.specifier.length - a.specifier.length)\n\t\t.map(({ specifier, chunkName }) => {\n\t\t\tconst hasSubpath = specifier.includes(\"/\");\n\t\t\tconst matchSpecifier = hasSubpath ? specifier.split(\"/\")[0] : specifier;\n\t\t\tconst subpath = hasSubpath ? specifier.slice(matchSpecifier.length + 1) : undefined;\n\t\t\tconst escapedSpecifier = matchSpecifier.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\t\t\treturn {\n\t\t\t\tchunkName: chunkName!,\n\t\t\t\tsubpath,\n\t\t\t\tpattern: new RegExp(`${NODE_MODULES_MATCH_PREFIX}${escapedSpecifier}(?=[/.])`),\n\t\t\t};\n\t\t});\n}\n\nfunction computeNonChunkEntries(sharedPackages: SharedPackage[]) {\n\treturn sharedPackages\n\t\t.filter(({ chunkName }) => chunkName == null)\n\t\t.map(({ specifier }) => ({\n\t\t\turlName: toUrlName(specifier),\n\t\t\tspecifier,\n\t\t}));\n}\n\nfunction discoverSharedPackages(projectRoot: string): SharedPackage[] {\n\tconst packageJson = readPackageJson(projectRoot);\n\tif (!packageJson)\n\t\treturn [];\n\n\tconst dependencies = collectDependencyNames(packageJson);\n\tconst specifiers = new Set(ALWAYS_SHARED_SPECIFIERS);\n\n\tfor (const dependency of dependencies) {\n\t\tif (!dependency.startsWith(PROZILLA_OS_SCOPE))\n\t\t\tcontinue;\n\n\t\tspecifiers.add(dependency);\n\t\tconst dependencyPackage = readPackageJson(resolve(projectRoot, \"node_modules\", dependency));\n\t\tif (dependencyPackage) {\n\t\t\tfor (const transitiveName of collectDependencyNames(dependencyPackage)) {\n\t\t\t\tspecifiers.add(transitiveName);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn Array.from(specifiers).map((specifier) => {\n\t\tconst commonJsConfig = COMMON_JS_PACKAGE_CONFIGS.get(specifier);\n\t\treturn commonJsConfig != null ? { specifier, ...commonJsConfig } : { specifier };\n\t});\n}\n\nfunction findExportEntryValue(exportObject: Record<string, unknown>, depth = 0): string | null {\n\tif (depth > MAX_EXPORT_DEPTH)\n\t\treturn null;\n\n\tfor (const key of EXPORT_ORDER) {\n\t\tconst value = exportObject[key];\n\t\tif (typeof value === \"string\")\n\t\t\treturn value;\n\n\t\tif (isObject(value)) {\n\t\t\tconst nested = findExportEntryValue(value, depth + 1);\n\t\t\tif (nested != null)\n\t\t\t\treturn nested;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nfunction resolveEsmEntry(specifier: string, projectRoot: string) {\n\tconst require = createRequire(resolve(projectRoot, \"package.json\"));\n\tconst packageDirectory = resolve(require.resolve(`${specifier}/package.json`), \"..\");\n\tconst packageJson = readPackageJson(packageDirectory);\n\tif (!packageJson)\n\t\treturn resolve(packageDirectory, \"index.js\");\n\n\tconst exportsField = packageJson.exports;\n\tif (isObject(exportsField)) {\n\t\tconst dotExports = exportsField[\".\"];\n\t\tif (isObject(dotExports)) {\n\t\t\tconst fromExports = findExportEntryValue(dotExports);\n\t\t\tif (fromExports != null)\n\t\t\t\treturn resolve(packageDirectory, fromExports);\n\t\t}\n\t}\n\n\tif (packageJson.module != null)\n\t\treturn resolve(packageDirectory, packageJson.module);\n\n\treturn resolve(packageDirectory, packageJson.main ?? \"index.js\");\n}\n\nfunction getExportNames(specifier: string, root: string, exportsCache: Record<string, string[] | undefined>) {\n\tconst cached = exportsCache[specifier];\n\tif (cached != null)\n\t\treturn cached;\n\n\ttry {\n\t\tconst projectRequire = createRequire(resolve(root));\n\t\tconst required: unknown = projectRequire(specifier);\n\t\tconst names = isObject(required)\n\t\t\t? Object.keys(required).filter((key) => !EXCLUDED_EXPORT_KEYS.has(key))\n\t\t\t: [];\n\n\t\texportsCache[specifier] = names;\n\t\treturn names;\n\t} catch {\n\t\texportsCache[specifier] = [];\n\t\treturn [];\n\t}\n}\n\nfunction handleShimRequest(\n\trequest: Connect.IncomingMessage,\n\tresponse: ServerResponse<IncomingMessage>,\n\tnextMiddleware: Connect.NextFunction,\n\tprojectRoot: string,\n\tshimEntries: ShimEntry[],\n\texportsCache: Record<string, string[] | undefined>\n) {\n\tconst match = request.url?.match(SHIM_URL_PATTERN);\n\tif (!match) {\n\t\tnextMiddleware();\n\t\treturn;\n\t}\n\n\tconst entry = shimEntries.find((entry) => entry.urlName === match[1]);\n\tif (!entry) {\n\t\tnextMiddleware();\n\t\treturn;\n\t}\n\n\tconst names = getExportNames(entry.specifier, projectRoot, exportsCache);\n\tif (!names.length) {\n\t\tnextMiddleware();\n\t\treturn;\n\t}\n\n\tconst dependencyUrl = `${VITE_DEPS_PREFIX}${toViteDependencyName(entry.specifier)}.js`;\n\tconst code = [\n\t\t`import __mod from \"${dependencyUrl}\";`,\n\t\t`const { ${names.join(\", \")} } = __mod;`,\n\t\t`export { ${names.join(\", \")} };`,\n\t\t\"export default __mod;\",\n\t].join(\"\\n\");\n\n\tresponse.setHeader(\"Content-Type\", \"application/javascript\");\n\tresponse.end(code);\n}\n\nasync function handleSharedRequest(\n\trequest: Connect.IncomingMessage,\n\tresponse: ServerResponse<IncomingMessage>,\n\tprojectRoot: string,\n\tnonChunkEntries: ShimEntry[],\n\tserver?: ViteDevServer\n) {\n\tconst match = request.url?.match(SHARED_URL_PATTERN);\n\tif (!match)\n\t\treturn false;\n\n\tconst entry = nonChunkEntries.find((entry) => entry.urlName === match[1]);\n\tif (!entry)\n\t\treturn false;\n\n\ttry {\n\t\tconst entryPath = resolveEsmEntry(entry.specifier, projectRoot);\n\n\t\tif (server) {\n\t\t\tconst viteUrl = toViteUrl(entryPath, projectRoot);\n\t\t\tconst transformed = await server.transformRequest(viteUrl);\n\n\t\t\tif (transformed) {\n\t\t\t\tresponse.setHeader(\"Content-Type\", \"application/javascript\");\n\t\t\t\tresponse.end(transformed.code);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\tconst code = readFileSync(entryPath, \"utf-8\")\n\t\t\t.replace(NODE_ENV_REGEX, DEVELOPMENT_ENV_REPLACEMENT);\n\n\t\tresponse.setHeader(\"Content-Type\", \"application/javascript\");\n\t\tresponse.end(code);\n\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}","import { PluginOption } from \"vite\";\nimport { importMapPlugin, type ImportMapPluginOptions } from \"./importMap\";\nimport { stageSitePlugin, StageOptions } from \"./stageSite\";\nimport react from \"@vitejs/plugin-react-swc\";\n\n/**\n * Options for the {@link sitePlugin}.\n */\nexport type SitePluginOptions = StageOptions & ImportMapPluginOptions;\n\n/**\n * Vite plugin that combines `@vitejs/plugin-react-swc`, {@link importMapPlugin} and {@link stageSitePlugin}.\n * \n * This plugin can be used to build a website with ProzillaOS.\n */\nexport function sitePlugin(options: SitePluginOptions): PluginOption[] {\n\tconst { sharedPackages, devImports, ...stageOptions } = options;\n\n\treturn [\n\t\treact(),\n\t\timportMapPlugin({ sharedPackages, devImports }),\n\t\tstageSitePlugin(stageOptions),\n\t];\n}\n"],"names":["logger","Logger","normalizeLineEndings","text","generateSitemapXml","options","imageUrls","appsConfig","baseUrl","date","year","month","day","monthString","dayString","lastModified","images","path","pages","id","sitemap","generateRobotsTxt","generateCname","generateTemplate","html","baseUrlRegex","commentsRegex","emptyLinesRegex","generate404Page","context","template","generateAppPages","favicon","siteName","siteTagLine","app","appId","appName","appDescription","appIcon","titleRegex","descriptionRegex","canonicalRegex","iconRegex","faqRegex","stageSite","htmlTemplate","domain","paths","files","extendedOptions","generateContent","error","stageSitePlugin","appMetadataPlugin","entryPath","appClass","code","rootDir","packageJsonPath","resolve","packageJson","packageJsonContent","readFileSync","name","version","homepage","author","appInstanceRegex","match","appInstanceName","metadataFields","injectCode","insertPosition","magicString","MagicString","PROZILLA_OS_SCOPE","ALWAYS_SHARED_SPECIFIERS","readPackageJson","directory","content","parsed","isObject","result","isStringRecord","value","collectDependencyNames","discoverSharedSpecifiers","projectRoot","projectPackage","allDependencyNames","specifiers","dependencyName","appPlugin","tsconfigPath","sharedPackages","externalPatterns","react","cssInjectedByJs","dts","config","root","entryFile","resolvedSpecifiers","SHIM_PATH_PREFIX","SHARED_PATH_PREFIX","ASSETS_DIRECTORY","SHIM_DIRECTORY_NAME","VITE_DEPS_PREFIX","PLACEHOLDER_PREFIX","IMPORT_MAP_SCRIPT_TAG","IMPORT_MAP_SCRIPT_TYPE","SHIM_URL_PATTERN","SHARED_URL_PATTERN","RELATIVE_IMPORT_PATTERN","PRODUCTION_ENV_REPLACEMENT","DEVELOPMENT_ENV_REPLACEMENT","NODE_ENV_REGEX","NODE_MODULES_MATCH_PREFIX","COMMON_JS_PACKAGE_CONFIGS","EXPORT_ORDER","MAX_EXPORT_DEPTH","EXCLUDED_EXPORT_KEYS","importMapPlugin","userDevImports","isDev","chunkUrlBySpecifier","viteUrlBySpecifier","pendingShimFiles","resolvedPackages","derivedData","buildShimEntries","computeChunkPatterns","computeNonChunkEntries","exportsCache","discovered","discoverSharedPackages","_env","existingOutputs","normalizeOutputOptions","existingInclude","wrappedOutputs","existingOutput","meta","matchChunkPattern","entry","server","resolveNonChunkViteUrls","request","response","nextMiddleware","handleSharedRequest","handled","handleShimRequest","buildImportMapScript","buildDevImportMap","buildBuildImportMap","bundle","collectChunkUrls","collectPendingShims","sharedPackage","resolveEsmEntry","collected","collectAssetFiles","filePath","basename","assetReference","assetUrl","writeShimFiles","resolvedImports","resolveChunkImports","replacePlaceholdersInHtmlFiles","userImports","urlMap","resolvedUrl","toPlaceholder","imports","shimEntries","chunkUrl","shimFiles","outputDirectory","shimDirectory","mkdirSync","shim","writeFileSync","htmlFiles","readdirSync","file","htmlPath","specifier","url","nonChunkEntries","resolved","toViteUrl","chunk","chunkUrlMap","pendingShims","shimEntry","exportNames","getExportNames","resolvedDirectory","generateShimCode","entryCode","entryAssetName","toUrlName","entryAssetUrl","assetUrlByPath","codeByPath","pendingFiles","visitedFiles","currentPath","currentDirectory","dirname","currentCode","importMatch","capturedPath","resolvedPath","chunkCode","rewriteRelativeImports","fileDirectory","patterns","chunkName","pattern","subpath","output","toViteDependencyName","resolvedId","normalizedId","normalizedRoot","safe","a","b","hasSubpath","matchSpecifier","escapedSpecifier","dependencies","dependency","dependencyPackage","transitiveName","commonJsConfig","findExportEntryValue","exportObject","depth","key","nested","require","createRequire","packageDirectory","exportsField","dotExports","fromExports","cached","required","names","viteUrl","transformed","sitePlugin","devImports","stageOptions"],"mappings":";;;;;;;;;AAuDA,MAAMA,IAAS,IAAIC,GAAA;AAEnB,SAASC,EAAqBC,GAAc;AAC3C,SAAOA,EAAK,QAAQ,SAAS;AAAA,CAAI;AAClC;AAEA,SAASC,GAAmBC,GAA+B;AAC1D,QAAM,EAAE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AA,CAAI;AAEX,EAAAxG,EAAS,UAAU,gBAAgB,wBAAwB,GAC3DA,EAAS,IAAI5F,CAAI;AAClB;AAEA,eAAe8F,GACdH,GACAC,GACA7D,GACAuG,GACA7C,GACC;AACD,QAAM7E,IAAQ+E,EAAQ,KAAK,MAAMnC,EAAkB;AACnD,MAAI,CAAC5C;AACJ,WAAO;AAER,QAAM4E,IAAQ8C,EAAgB,KAAK,CAAC9C,MAAUA,EAAM,YAAY5E,EAAM,CAAC,CAAC;AACxE,MAAI,CAAC4E;AACJ,WAAO;AAER,MAAI;AACH,UAAM1F,IAAY0G,EAAgBhB,EAAM,WAAWzD,CAAW;AAE9D,QAAI0D,GAAQ;AACX,YAAM4G,IAAU7D,EAAU1I,GAAWiC,CAAW,GAC1CuK,IAAc,MAAM7G,EAAO,iBAAiB4G,CAAO;AAEzD,UAAIC;AACH,eAAA1G,EAAS,UAAU,gBAAgB,wBAAwB,GAC3DA,EAAS,IAAI0G,EAAY,IAAI,GACtB;AAAA,IAET;AAEA,UAAMtM,IAAOM,EAAaR,GAAW,OAAO,EAC1C,QAAQ8D,GAAgBD,EAA2B;AAErD,WAAAiC,EAAS,UAAU,gBAAgB,wBAAwB,GAC3DA,EAAS,IAAI5F,CAAI,GAEV;AAAA,EACR,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AC1qBO,SAASuM,GAAW3P,GAA4C;AACtE,QAAM,EAAE,gBAAA0F,GAAgB,YAAAkK,GAAY,GAAGC,MAAiB7P;AAExD,SAAO;AAAA,IACN4F,EAAA;AAAA,IACA0B,GAAgB,EAAE,gBAAA5B,GAAgB,YAAAkK,GAAY;AAAA,IAC9C5M,GAAgB6M,CAAY;AAAA,EAAA;AAE9B;"}
|
package/dist/main.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { AppsConfig } from '@prozilla-os/core';
|
|
2
|
+
import { Assertion } from 'vitest';
|
|
3
|
+
import { InspectionOptions } from '@prozilla-os/shared/logging';
|
|
2
4
|
import { Plugin as Plugin_2 } from 'vite';
|
|
3
5
|
import { PluginOption } from 'vite';
|
|
4
6
|
import { TestAPI } from 'vitest';
|
|
@@ -9,10 +11,16 @@ import { UserConfig } from 'vite';
|
|
|
9
11
|
*/
|
|
10
12
|
export declare function appMetadataPlugin({ entryPath, appClass }: AppMetadataPluginOptions): Plugin_2;
|
|
11
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Options for the {@link appMetadataPlugin}.
|
|
16
|
+
*/
|
|
12
17
|
export declare interface AppMetadataPluginOptions {
|
|
13
18
|
/** Path to the app's entry file, relative to the project root. */
|
|
14
19
|
entryPath: string;
|
|
15
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Name of the app class.
|
|
22
|
+
* @default "App"
|
|
23
|
+
*/
|
|
16
24
|
appClass?: string;
|
|
17
25
|
}
|
|
18
26
|
|
|
@@ -30,15 +38,18 @@ export declare interface AppMetadataPluginOptions {
|
|
|
30
38
|
*/
|
|
31
39
|
export declare function appPlugin(options: AppPluginOptions): PluginOption[];
|
|
32
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Options for the {@link appPlugin}.
|
|
43
|
+
*/
|
|
33
44
|
export declare interface AppPluginOptions {
|
|
34
45
|
/** Path to the app's entry file, relative to the project root. */
|
|
35
46
|
entryPath: string;
|
|
36
47
|
/** CSS class name for the app's root element. */
|
|
37
48
|
appClass?: string;
|
|
38
|
-
/** Path to the TypeScript config
|
|
49
|
+
/** Path to the TypeScript build config. Defaults to "tsconfig.build.json". */
|
|
39
50
|
tsconfigPath?: string;
|
|
40
|
-
/** Shared
|
|
41
|
-
sharedPackages?:
|
|
51
|
+
/** Shared package specifiers to mark as external. Auto-discovered from package.json when omitted. */
|
|
52
|
+
sharedPackages?: string[];
|
|
42
53
|
/** Additional external patterns (strings or RegExps) beyond the shared package specifiers. */
|
|
43
54
|
externalPatterns?: (string | RegExp)[];
|
|
44
55
|
}
|
|
@@ -55,38 +66,281 @@ export declare interface AppPluginOptions {
|
|
|
55
66
|
*/
|
|
56
67
|
export declare const appViteConfig: (basePath: string, entryPath: string, appClass?: string) => UserConfig;
|
|
57
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Defines the matching criteria for a test case using an assertion.
|
|
71
|
+
* @see {@link Matcher}
|
|
72
|
+
* @see {@link CustomTestAPI.assert}
|
|
73
|
+
*/
|
|
74
|
+
export declare interface AssertionMatcher<R> {
|
|
75
|
+
readonly [MATCH_ASSERTION]: true;
|
|
76
|
+
/** The assertion that defines the matching criteria for this test. */
|
|
77
|
+
readonly assert: (actual: Assertion<R>) => void;
|
|
78
|
+
/** The name of this assertion. */
|
|
79
|
+
readonly name?: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Utility functions built on top of Vitest's API to make writing tests easier.
|
|
84
|
+
* @see {@link extend}
|
|
85
|
+
*/
|
|
58
86
|
export declare interface CustomTestAPI {
|
|
59
|
-
|
|
60
|
-
|
|
87
|
+
/**
|
|
88
|
+
* A shorthand for {@link CustomTestAPI.cases} that tests a function with a single parameter.
|
|
89
|
+
* @param func - The function to test.
|
|
90
|
+
* @param cases - An array of tuples. Each tuple consisting of a parameter and the corresponding matching criteria.
|
|
91
|
+
* @typeParam A - The type of parameter the function accepts.
|
|
92
|
+
* @typeParam R - The type of value the function returns.
|
|
93
|
+
* @example
|
|
94
|
+
* test.simpleCases(isEven, [
|
|
95
|
+
* [0, true],
|
|
96
|
+
* [1, false],
|
|
97
|
+
* [2, true],
|
|
98
|
+
* ]);
|
|
99
|
+
*/
|
|
100
|
+
simpleCases: <A = unknown, R = undefined>(func: (arg: A) => R, cases: [A, Matcher<R>][]) => void;
|
|
101
|
+
/**
|
|
102
|
+
* A shorthand for {@link CustomTestAPI.case} that tests a function with a single parameter.
|
|
103
|
+
* @param func - The function to test.
|
|
104
|
+
* @param arg - The parameter to pass to the function.
|
|
105
|
+
* @param matcher - The matching criteria.
|
|
106
|
+
* @typeParam A - The type of parameter the function accepts.
|
|
107
|
+
* @typeParam R - The type of value the function returns.
|
|
108
|
+
*/
|
|
109
|
+
simpleCase: <A = unknown, R = undefined>(func: (arg: A) => R, arg: A, matcher: Matcher<R>) => void;
|
|
110
|
+
/**
|
|
111
|
+
* Tests each case in the array by calling the function with the first element of the tuple and checking its behaviour
|
|
112
|
+
* or return value against the matching criteria in the second element.
|
|
113
|
+
*
|
|
114
|
+
* This is a wrapper around {@link TestAPI.each} that handles test naming, function calling and assertions for you,
|
|
115
|
+
* so you can write more parameterized tests with less code.
|
|
116
|
+
* @param func - The function to test.
|
|
117
|
+
* @param cases - An array of tuples. Each tuple consisting of an array of parameters and the corresponding matching criteria.
|
|
118
|
+
* @typeParam A - The types of parameters the function accepts.
|
|
119
|
+
* @typeParam R - The type of value the function returns.
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* test.cases(isEqual, [
|
|
123
|
+
* [[0, 1], false],
|
|
124
|
+
* [[2, 3], false],
|
|
125
|
+
* [[4, 4], true],
|
|
126
|
+
* ]);
|
|
127
|
+
* ```
|
|
128
|
+
* ### Comparison with Vitest
|
|
129
|
+
* Most functions will have simple unit tests like this:
|
|
130
|
+
* ```ts
|
|
131
|
+
* test.each([
|
|
132
|
+
* [1, 1, 2],
|
|
133
|
+
* [1, 2, 3],
|
|
134
|
+
* [2, 1, 3],
|
|
135
|
+
* ])("add(%i, %i) -> %i", (a, b, expected) => {
|
|
136
|
+
* expect(a + b).toBe(expected)
|
|
137
|
+
* })
|
|
138
|
+
* ```
|
|
139
|
+
* This is the same test, but using the `cases` wrapper instead:
|
|
140
|
+
* ```ts
|
|
141
|
+
* test.cases(add, [
|
|
142
|
+
* [[1, 1], 2],
|
|
143
|
+
* [[1, 2], 3],
|
|
144
|
+
* [[2, 1], 3]
|
|
145
|
+
* ]);
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
cases: <A extends unknown[] = [], R = undefined>(func: (...args: A) => R, cases: [A, Matcher<R>][]) => void;
|
|
149
|
+
/**
|
|
150
|
+
* Tests a single case by calling the function with the given parameters and checking its behaviour
|
|
151
|
+
* or return value against the matching criteria.
|
|
152
|
+
*
|
|
153
|
+
* This is the equivalent of {@link CustomTestAPI.cases}, but for a single test case.
|
|
154
|
+
* @param func - The function to test.
|
|
155
|
+
* @param args - The parameters to pass to the function.
|
|
156
|
+
* @param matcher - The matching criteria.
|
|
157
|
+
* @typeParam A - The types of parameters the function accepts.
|
|
158
|
+
* @typeParam R - The type of value the function returns.
|
|
159
|
+
*/
|
|
160
|
+
case: <A extends unknown[] = [], R = undefined>(func: (...args: A) => R, args: A, matcher: Matcher<R>) => void;
|
|
161
|
+
/**
|
|
162
|
+
* Creates matching criteria for a test case that expects an error to be thrown.
|
|
163
|
+
* @param error - The type of error to expect.
|
|
164
|
+
* @param message - The error message to expect.
|
|
165
|
+
* @see {@link CustomTestAPI.cases}
|
|
166
|
+
*/
|
|
167
|
+
throws: (error: new (...args: never[]) => Error, message?: string | RegExp) => ErrorMatcher;
|
|
168
|
+
/**
|
|
169
|
+
* Creates matching criteria for a test case where the actual value is verified by the given assertion,
|
|
170
|
+
* instead of simply being compared with an expected return value.
|
|
171
|
+
* @param assert - The function that verifies the actual return value.
|
|
172
|
+
* @param name - The name of the assertion.
|
|
173
|
+
* @see {@link CustomTestAPI.cases}
|
|
174
|
+
*/
|
|
175
|
+
assert: <R>(assert: (actual: Assertion<R>) => void, name?: string) => AssertionMatcher<R>;
|
|
176
|
+
/** Creates matching criteria for a test case that expects the actual value to be nullish (`null` or `undefined`). */
|
|
177
|
+
nullish: <R>() => AssertionMatcher<R>;
|
|
178
|
+
/** Creates matching criteria for a test case that expects the actual value to be [`falsy`](https://developer.mozilla.org/en-US/docs/Glossary/Falsy). */
|
|
179
|
+
falsy: <R>() => AssertionMatcher<R>;
|
|
180
|
+
/** Creates matching criteria for a test case that expects the actual value to be [`truthy`](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). */
|
|
181
|
+
truthy: <R>() => AssertionMatcher<R>;
|
|
182
|
+
/** Negates the proceding matching criteria for a test case. */
|
|
183
|
+
not: Pick<CustomTestAPI, "nullish" | "falsy" | "truthy">;
|
|
61
184
|
}
|
|
62
185
|
|
|
63
|
-
|
|
186
|
+
/**
|
|
187
|
+
* Configuration options for the {@link CustomTestAPI}.
|
|
188
|
+
*/
|
|
189
|
+
export declare interface CustomTestConfig {
|
|
190
|
+
/** Options for the formatting of test names. */
|
|
191
|
+
format?: InspectionOptions;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Defines the matching criteria for a test case that expects the function to throw an error.
|
|
196
|
+
* @see {@link Matcher}
|
|
197
|
+
* @see {@link CustomTestAPI.throws}
|
|
198
|
+
*/
|
|
199
|
+
export declare interface ErrorMatcher {
|
|
200
|
+
readonly [MATCH_ERROR]: true;
|
|
201
|
+
/** The type of error the function should throw. */
|
|
202
|
+
readonly error: new (...args: never[]) => Error;
|
|
203
|
+
/** The message the error thrown by the function should have. */
|
|
204
|
+
readonly message?: string | RegExp;
|
|
205
|
+
}
|
|
64
206
|
|
|
65
207
|
/**
|
|
66
208
|
* Extends Vitest's {@link TestAPI} with functions from the {@link CustomTestAPI}.
|
|
67
209
|
* @param test - The Vitest test API.
|
|
210
|
+
* @param config - The configuration options.
|
|
68
211
|
* @returns The extended test API.
|
|
69
212
|
* @example
|
|
213
|
+
* You can call this function in one file and export the result.
|
|
214
|
+
* ```ts
|
|
215
|
+
* // index.ts
|
|
216
|
+
* import { test as base } from "vitest";
|
|
217
|
+
*
|
|
218
|
+
* export const test = extend(base);
|
|
219
|
+
* ```
|
|
220
|
+
* Then import and use it across your test files.
|
|
221
|
+
* ```ts
|
|
222
|
+
* // isEven.test.ts
|
|
223
|
+
* import { test } from "./index";
|
|
224
|
+
*
|
|
225
|
+
* test.simpleCases(isEven, [
|
|
226
|
+
* [0, true],
|
|
227
|
+
* [1, false],
|
|
228
|
+
* [2, true],
|
|
229
|
+
* ]);
|
|
230
|
+
* ```
|
|
231
|
+
* ### With configuration
|
|
232
|
+
* ```ts
|
|
70
233
|
* import { test as base } from "vitest";
|
|
71
234
|
*
|
|
72
|
-
* const test = extend(base
|
|
235
|
+
* export const test = extend(base, {
|
|
236
|
+
* format: {
|
|
237
|
+
* colors: false,
|
|
238
|
+
* singleQuotes: true,
|
|
239
|
+
* spaceAfterComma: false,
|
|
240
|
+
* },
|
|
241
|
+
* });
|
|
242
|
+
* ```
|
|
73
243
|
*/
|
|
74
|
-
export declare function extend(test: TestAPI): ExtendedTestAPI
|
|
244
|
+
export declare function extend<C = object>(test: TestAPI<C>, config?: CustomTestConfig): ExtendedTestAPI<C>;
|
|
75
245
|
|
|
76
|
-
|
|
246
|
+
/**
|
|
247
|
+
* The combination of Vitest's {@link TestAPI} and the {@link CustomTestAPI}.
|
|
248
|
+
*/
|
|
249
|
+
export declare type ExtendedTestAPI<ExtraContext = object> = TestAPI<ExtraContext> & CustomTestAPI;
|
|
77
250
|
|
|
78
251
|
/**
|
|
79
252
|
* Vite plugin that generates an import map in order to support dynamically installing apps into ProzillaOS.
|
|
80
253
|
*/
|
|
81
254
|
export declare function importMapPlugin(options?: ImportMapPluginOptions): PluginOption;
|
|
82
255
|
|
|
256
|
+
/**
|
|
257
|
+
* Options for the {@link importMapPlugin}.
|
|
258
|
+
*/
|
|
83
259
|
export declare interface ImportMapPluginOptions {
|
|
84
|
-
/** Packages to expose via import map.
|
|
260
|
+
/** Packages to expose via import map. When omitted, auto-discovered from the project's package.json. */
|
|
85
261
|
sharedPackages?: SharedPackage[];
|
|
86
262
|
/** Dev-mode import map overrides for packages not handled by CommonJS shims. */
|
|
87
263
|
devImports?: Record<string, string>;
|
|
88
264
|
}
|
|
89
265
|
|
|
266
|
+
/**
|
|
267
|
+
* Represents a choice in an {@link interactiveListPrompt}.
|
|
268
|
+
*/
|
|
269
|
+
export declare interface InteractiveListChoice {
|
|
270
|
+
/** The name to display in the list. */
|
|
271
|
+
name: string;
|
|
272
|
+
/** The value to return if this is submitted. */
|
|
273
|
+
value: string;
|
|
274
|
+
/** The keyboard shortcut that submits this choice. */
|
|
275
|
+
key: string;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Configuration for {@link interactiveListPrompt}.
|
|
280
|
+
*/
|
|
281
|
+
export declare interface InteractiveListConfig {
|
|
282
|
+
/** The message to display at the top of the list. */
|
|
283
|
+
message: string;
|
|
284
|
+
/** The list of choices. */
|
|
285
|
+
choices: Array<InteractiveListChoice>;
|
|
286
|
+
/** The default value to select. Defaults to the first choice. A value of `null` represents no selection. */
|
|
287
|
+
default?: string | null;
|
|
288
|
+
/** Function that renders the selected choice. */
|
|
289
|
+
renderSelected?: (choice: InteractiveListChoice, index: number) => string;
|
|
290
|
+
/** Functions that renders the unselected choices. */
|
|
291
|
+
renderUnselected?: (choice: InteractiveListChoice, index: number) => string;
|
|
292
|
+
/**
|
|
293
|
+
* Whether to hide the cursor during selection.
|
|
294
|
+
* @default true
|
|
295
|
+
*/
|
|
296
|
+
hideCursor?: boolean;
|
|
297
|
+
/**
|
|
298
|
+
* Whether to horizontally align the shortcuts in the list of choices.
|
|
299
|
+
* @default false
|
|
300
|
+
*/
|
|
301
|
+
alignShortcuts?: boolean;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Creates an interactive list of choices that supports selection via arrow keys + enter or via pressing a key associated with a choice.
|
|
306
|
+
*
|
|
307
|
+
* This is based on {@link https://github.com/pgibler/inquirer-interactive-list-prompt pgibler/inquirer-interactive-list-prompt}.
|
|
308
|
+
* @example
|
|
309
|
+
* ```ts
|
|
310
|
+
* const answer = await interactiveListPrompt({
|
|
311
|
+
* message: "Select an option:",
|
|
312
|
+
* choices: [
|
|
313
|
+
* { name: "Option A", value: "A", key: "a" },
|
|
314
|
+
* { name: "Option B", value: "B", key: "b" },
|
|
315
|
+
* { name: "Option C", value: "C", key: "c" },
|
|
316
|
+
* ],
|
|
317
|
+
* });
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
export declare const interactiveListPrompt: (config: InteractiveListConfig) => Promise<string>;
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Returns a list of all files and folders in a directory.
|
|
324
|
+
* @param path - The path of the directory.
|
|
325
|
+
* @returns The contents of the directory.
|
|
326
|
+
*/
|
|
327
|
+
export declare function listDirectory(path: string): string[];
|
|
328
|
+
|
|
329
|
+
declare const MATCH_ASSERTION: unique symbol;
|
|
330
|
+
|
|
331
|
+
declare const MATCH_ERROR: unique symbol;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Defines the matching criteria for a test case.
|
|
335
|
+
*
|
|
336
|
+
* This can either be a plain return value, in which case the test will fail if the function returns a different value,
|
|
337
|
+
* or more complex criteria that determines whether the test will fail.
|
|
338
|
+
* E.g., an {@link ErrorMatcher} will fail if the function does not throw an error of a certain type and with a certain message.
|
|
339
|
+
* @param R - The type of value the function being tested returns.
|
|
340
|
+
* @see {@link CustomTestAPI.cases}
|
|
341
|
+
*/
|
|
342
|
+
export declare type Matcher<R = undefined> = R | ErrorMatcher | AssertionMatcher<R>;
|
|
343
|
+
|
|
90
344
|
/**
|
|
91
345
|
* @deprecated Use {@link @prozilla-os/shared!Logger | Logger} instead.
|
|
92
346
|
*/
|
|
@@ -94,17 +348,8 @@ declare function print_2(message: string, status?: Status, newLine?: boolean): v
|
|
|
94
348
|
export { print_2 as print }
|
|
95
349
|
|
|
96
350
|
export declare interface SharedPackage {
|
|
97
|
-
/** Package specifier (e.g. `"react"`, `"@prozilla-os/core"`). */
|
|
98
351
|
specifier: string;
|
|
99
|
-
/**
|
|
100
|
-
* When set, the package is treated as a manual chunk with this name.
|
|
101
|
-
* When omitted, the package's pre-built entry file is emitted as a
|
|
102
|
-
* static asset for the import map. Chunk-name packages are bundled
|
|
103
|
-
* naturally by Rollup in the site build; asset packages are served
|
|
104
|
-
* directly from disk to dynamically-loaded apps.
|
|
105
|
-
*/
|
|
106
352
|
chunkName?: string;
|
|
107
|
-
/** When `true`, a CJS-to-ESM shim is generated for the package's chunk. */
|
|
108
353
|
isCommonJS?: boolean;
|
|
109
354
|
}
|
|
110
355
|
|
|
@@ -115,8 +360,14 @@ export declare interface SharedPackage {
|
|
|
115
360
|
*/
|
|
116
361
|
export declare function sitePlugin(options: SitePluginOptions): PluginOption[];
|
|
117
362
|
|
|
363
|
+
/**
|
|
364
|
+
* Options for the {@link sitePlugin}.
|
|
365
|
+
*/
|
|
118
366
|
export declare type SitePluginOptions = StageOptions & ImportMapPluginOptions;
|
|
119
367
|
|
|
368
|
+
/**
|
|
369
|
+
* Options for the {@link stageSitePlugin}.
|
|
370
|
+
*/
|
|
120
371
|
export declare interface StageOptions {
|
|
121
372
|
appsConfig: AppsConfig;
|
|
122
373
|
/**
|