@orkestrel/scaffold 0.0.103 → 0.0.104
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/agents/skills/orkestrel-dispatch/scripts/helpers.js +84 -1
- package/dist/agents/skills/orkestrel-dispatch/scripts/launch.js +21 -6
- package/dist/agents/skills/orkestrel-harden/scripts/titles.js +338 -0
- package/dist/agents/skills/orkestrel-publish/scripts/swap.js +3 -39
- package/dist/agents/skills/orkestrel-publish/scripts/wave.js +433 -47
- package/dist/agents/skills/orkestrel-publish/scripts/window.js +2 -1
- package/dist/bin/main.js +16 -9
- package/dist/bin/main.js.map +1 -1
- package/dist/host/agents/orchestration.md +3 -3
- package/dist/host/agents/skills/enterprise-bootstrap/references/components.md +2 -2
- package/dist/host/agents/skills/enterprise-bootstrap/references/inspection.md +1 -1
- package/dist/host/agents/skills/orkestrel-build/SKILL.md +2 -2
- package/dist/host/agents/skills/orkestrel-debrief/SKILL.md +2 -2
- package/dist/host/agents/skills/orkestrel-debrief/references/field-testing.md +1 -1
- package/dist/host/agents/skills/orkestrel-debrief/references/instruction-audit.md +3 -3
- package/dist/host/agents/skills/orkestrel-dispatch/SKILL.md +10 -10
- package/dist/host/agents/skills/orkestrel-dispatch/references/launch.md +1 -0
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/helpers.ts +100 -1
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/launch.ts +27 -6
- package/dist/host/agents/skills/orkestrel-falsify/SKILL.md +4 -4
- package/dist/host/agents/skills/orkestrel-falsify/agents/openai.yaml +1 -1
- package/dist/host/agents/skills/orkestrel-falsify/references/brief.md +8 -7
- package/dist/host/agents/skills/orkestrel-falsify/references/reconcile.md +6 -6
- package/dist/host/agents/skills/orkestrel-harden/SKILL.md +6 -1
- package/dist/host/agents/skills/orkestrel-harden/references/bindings.md +1700 -0
- package/dist/host/agents/skills/orkestrel-harden/references/contract.md +2 -2
- package/dist/host/agents/skills/orkestrel-harden/references/equivalence.md +48 -0
- package/dist/host/agents/skills/orkestrel-harden/references/hardening.md +4 -2
- package/dist/host/agents/skills/orkestrel-harden/scripts/titles.ts +425 -0
- package/dist/host/agents/skills/orkestrel-journey/SKILL.md +2 -2
- package/dist/host/agents/skills/orkestrel-journey/references/captures.md +9 -8
- package/dist/host/agents/skills/orkestrel-polish/SKILL.md +3 -3
- package/dist/host/agents/skills/orkestrel-publish/SKILL.md +2 -2
- package/dist/host/agents/skills/orkestrel-publish/references/release.md +1 -0
- package/dist/host/agents/skills/orkestrel-publish/references/wave.md +56 -13
- package/dist/host/agents/skills/orkestrel-publish/references/window.md +6 -6
- package/dist/host/agents/skills/orkestrel-publish/scripts/swap.ts +5 -49
- package/dist/host/agents/skills/orkestrel-publish/scripts/wave.ts +646 -49
- package/dist/host/agents/skills/orkestrel-publish/scripts/window.ts +2 -1
- package/dist/host/agents/transports/codex.md +1 -1
- package/dist/host/claude/agents/orkestrel.md +54 -53
- package/dist/host/claude/agents/reviewer.md +4 -4
- package/dist/host/claude/rules/documentation.md +2 -1
- package/dist/host/claude/rules/patterns.md +1 -1
- package/dist/host/claude/rules/quality.md +2 -2
- package/dist/host/claude/rules/styles.md +1 -1
- package/dist/host/claude/rules/tests.md +34 -8
- package/dist/host/claude/rules/typescript.md +29 -0
- package/dist/host/claude/rules/workspace.md +32 -22
- package/dist/host/claude/rules/writing.md +34 -26
- package/dist/host/claude/settings.json +2 -0
- package/dist/host/claude/skills/orkestrel-debrief/SKILL.md +1 -1
- package/dist/host/claude/skills/orkestrel-falsify/SKILL.md +1 -1
- package/dist/host/codex/agents/analyst.toml +3 -3
- package/dist/host/codex/agents/reviewer.toml +4 -4
- package/dist/host/configs/policy.ts +13 -2
- package/dist/host/dotfiles/editorconfig +0 -1
- package/dist/host/dotfiles/gitattributes +0 -1
- package/dist/host/dotfiles/gitignore +0 -1
- package/dist/host/dotfiles/oxlintrc.json +24 -0
- package/dist/host/guides/agent.md +1638 -598
- package/dist/host/guides/budget.md +89 -29
- package/dist/host/guides/form.md +477 -91
- package/dist/host/guides/mcp.md +14 -2
- package/dist/host/guides/ollama.md +97 -73
- package/dist/host/guides/probe.md +1 -1
- package/dist/host/guides/scaffold.md +158 -101
- package/dist/host/guides/study.md +2635 -0
- package/dist/host/guides/table.md +225 -15
- package/dist/host/guides/terminal.md +22 -20
- package/dist/host/guides/test.md +689 -255
- package/dist/host/manifest.json +87 -63
- package/dist/host/tests/config.test.ts +136 -82
- package/dist/host/tests/policy.test.ts +39 -1
- package/dist/host/tests/setupPolicy.ts +86 -28
- package/dist/src/core/index.cjs +1387 -611
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +35 -20
- package/dist/src/core/index.d.ts +35 -20
- package/dist/src/core/index.js +1385 -612
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +12 -12
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +12 -12
- package/dist/src/server/index.d.ts +12 -12
- package/dist/src/server/index.js +12 -12
- package/dist/src/server/index.js.map +1 -1
- package/package.json +4 -4
package/dist/src/core/index.d.ts
CHANGED
|
@@ -119,10 +119,10 @@ export declare const ARTIFACT_TEMPLATES: Readonly<{
|
|
|
119
119
|
tests: Readonly<{
|
|
120
120
|
journey: "import {\n\tACCESSIBLE_ROLES,\n\tcreatePortfolio,\n\texpandCaptures,\n\tisRendered,\n\treadRefusal,\n\treadStyle,\n} from '@orkestrel/test/browser'\n{{imports}}import { page } from 'vitest/browser'\nimport { describe, expect, inject, it } from 'vitest'\n\nconst VARIANT = inject('variant')\nconst VARIANTS = inject('variants')\nconst CAPTURE = inject('capture')\n\ndescribe('{{application}} arrival journey', () => {\n\tit('proves the declared arrival families', async () => {\n\t\tconst families = ['Journey', 'Refusal', 'Matrix', ...(CAPTURE ? ['Capture'] : [])]\n\t\tconst proven: string[] = []\n\t\tconst states = ['{{application}}-arrival']\n\t\tconst placed: string[] = []\n\t\tconst portfolio = createPortfolio({\n\t\t\tstates,\n\t\t\tvariants: VARIANTS,\n\t\t\tvariant: VARIANT,\n\t\t\tdirectory: '../../../tmp/captures/states',\n\t\t\tenabled: CAPTURE,\n\t\t})\n{{mount}}\t\ttry {\n{{arrival}}\t\t\tconst heading = page\n\t\t\t\t.getByRole('heading', {\n\t\t\t\t\tname: {{heading}},\n\t\t\t\t\texact: true,\n\t\t\t\t\tlevel: 1,\n\t\t\t\t})\n\t\t\t\t.element()\n\t\t\texpect(isRendered(heading)).toBe(true)\n\t\t\tproven.push('Journey')\n\t\t\tawait portfolio.place('{{application}}-arrival')\n\t\t\tplaced.push('{{application}}-arrival')\n\n\t\t\tfor (const role of ACCESSIBLE_ROLES) expect(page.getByRole(role).elements()).toEqual([])\n\t\t\texpect(readRefusal('Continue')).toBe(\n\t\t\t\t'No interactive element has the accessible name \"Continue\"',\n\t\t\t)\n\t\t\tproven.push('Refusal')\n\n\t\t\tconst measured: string[] = []\n\t\t\tfor (const variant of VARIANTS) {\n\t\t\t\tawait page.viewport(variant.width, variant.height)\n\t\t\t\texpect(readStyle(heading, 'display')).toBe('block')\n\t\t\t\texpect(window.innerWidth).toBe(variant.width)\n\t\t\t\tmeasured.push(variant.name)\n\t\t\t}\n\t\t\texpect(measured).toEqual(VARIANTS.map(({ name }) => name))\n\t\t\tproven.push('Matrix')\n\n\t\t\tconst files = expandCaptures(states, VARIANTS)\n\t\t\texpect(portfolio.files).toEqual(files)\n\t\t\texpect(new Set(files).size).toBe(states.length * VARIANTS.length)\n\t\t\texpect(placed).toEqual(states)\n\t\t\tconst expected = CAPTURE\n\t\t\t\t? expandCaptures(\n\t\t\t\t\t\tstates,\n\t\t\t\t\t\tVARIANTS.filter(({ name }) => name === VARIANT),\n\t\t\t\t\t)\n\t\t\t\t: []\n\t\t\texpect(portfolio.paths.map((path) => path.replaceAll('\\\\', '/').split('/').at(-1))).toEqual(\n\t\t\t\texpected,\n\t\t\t)\n\t\t\tif (CAPTURE) proven.push('Capture')\n\t\t\texpect(proven).toEqual(families)\n\t\t} finally {\n{{cleanup}}\t\t\tconst variant = VARIANTS.find(({ name }) => name === VARIANT)\n\t\t\tif (variant !== undefined) await page.viewport(variant.width, variant.height)\n\t\t}\n\t})\n})\n";
|
|
121
121
|
browser: "import type { JourneyVariant } from '@orkestrel/test'\n\ndeclare module 'vitest' {\n\texport interface ProvidedContext {\n\t\treadonly variant: string\n\t\treadonly variants: readonly JourneyVariant[]\n\t\treadonly capture: boolean\n\t}\n}\n";
|
|
122
|
-
sheet: "import sheet from '{{root}}dist/src/{{name}}/index.css?raw'\nimport {
|
|
122
|
+
sheet: "import sheet from '{{root}}dist/src/{{name}}/index.css?raw'\nimport { adoptSheet, readLayerNames } from '@orkestrel/test/browser'\nimport { describe, expect, it } from 'vitest'\n\ndescribe('{{name}} entry', () => {\n\tit('opens with the declared cascade order', () => {\n\t\tconst adopted = adoptSheet(sheet)\n\t\ttry {\n\t\t\texpect(adopted.sheet.cssRules[0]?.cssText).toBe(\n\t\t\t\t'@layer theme, reset, base, elements, components, utilities;',\n\t\t\t)\n\t\t\texpect(readLayerNames(adopted.sheet).slice(0, 6)).toEqual([\n\t\t\t\t'theme',\n\t\t\t\t'reset',\n\t\t\t\t'base',\n\t\t\t\t'elements',\n\t\t\t\t'components',\n\t\t\t\t'utilities',\n\t\t\t])\n\t\t} finally {\n\t\t\tadopted.release()\n\t\t}\n\t})\n})\n";
|
|
123
123
|
styles: Readonly<{
|
|
124
|
-
module: "
|
|
125
|
-
proof: "
|
|
124
|
+
module: "";
|
|
125
|
+
proof: "";
|
|
126
126
|
}>;
|
|
127
127
|
setup: "";
|
|
128
128
|
global: Readonly<{
|
|
@@ -132,13 +132,15 @@ export declare const ARTIFACT_TEMPLATES: Readonly<{
|
|
|
132
132
|
entry: "import * as entry from {{specifier}}\nimport { describe, expect, it } from 'vitest'\n\ndescribe({{label}}, () => {\n\tit('has no starter exports', () => {\n\t\texpect(Object.keys(entry)).toStrictEqual([])\n\t})\n})\n";
|
|
133
133
|
bin: "import { describe, expect, it } from 'vitest'\n\ndescribe('bin entry', () => {\n\tit('has no starter exports', async () => {\n{{import}}\n\t\texpect(Object.keys(entry)).toStrictEqual([])\n\t})\n})\n";
|
|
134
134
|
distribution: Readonly<{
|
|
135
|
-
proof: "// The artifact a consumer installs, measured rather than described. This workspace\n// is packed and installed into a throwaway consumer, and every following claim is read\n// off that installed tree: the exports map it publishes, the declarations it ships,\n// and the module objects a real runtime hands a consumer. Nothing here names this\n// package, one of its exports, or how many there are, so the proof stays true as\n// the published surface moves.\n{{types}}import type { SpawnSyncReturns } from 'node:child_process'\nimport type { TestContext } from 'vitest'\nimport { spawnSync } from 'node:child_process'\nimport {\n\texistsSync,\n\tmkdirSync,\n\tmkdtempSync,\n\treaddirSync,\n\treadFileSync,\n\trmSync,\n\tstatSync,\n\twriteFileSync,\n} from 'node:fs'\n{{transport}}import { createRequire } from 'node:module'\nimport { tmpdir } from 'node:os'\nimport { dirname, join, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n{{launcher}}import { afterAll, beforeAll, describe, expect, it } from 'vitest'\n\nconst ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')\nconst NPM = process.platform === 'win32' ? 'npm.cmd' : 'npm'\n// The compiler this workspace installs, run as a command rather than called in\n// process: the command and its plain-text diagnostics are the same across the\n// compiler majors this toolchain supports, and its in-process API is not. It is\n// resolved from the workspace under proof, so a consumer of the packed artifact is\n// checked by the same compiler that workspace's own `check` script runs.\nconst TSC = createRequire(join(ROOT, 'package.json')).resolve('typescript/bin/tsc')\n// Windows needs a shell to launch a `.cmd`: Node refuses one directly since the\n// batch-argument hardening, and `spawnSync` returns `EINVAL` with a null status\n// rather than an exit code a caller can read. Every following argument is a literal or\n// a path this file built, so the shell has nothing to escape.\nconst SHELL = process.platform === 'win32'\n// `prepublishOnly` runs this proof as `npm run test:distribution -- --mode release`,\n// and the root configuration's project factories carry that mode into this project.\n// Release is the publish gate, so evidence it cannot obtain fails there and skips\n// everywhere else: a gate that passes on missing evidence proves nothing.\nconst RELEASE = import.meta.env.MODE === 'release'\n// The built output directory convention a browser face may publish from. Every\n// selection reads this prefix off the export target and never off the subpath name. A\n// workspace whose only published face is the browser one publishes that face at the\n// root subpath, so a rule keyed on the subpath name drives a browser bundle through\n// Node and the miss is silent.\nconst BROWSER_OUTPUT = './dist/src/browser/'\nconst ABSENT_SUBPATH = '/no-subpath-is-published-under-this-name'\n// A compiler diagnostic that says where it is: the path relative to the directory\n// the compiler ran in, the 1-based line and column, the code, and the message. The\n// diagnostics are the verdict rather than the exit code, which differs between the\n// compiler majors this toolchain supports, so a reported line matching nothing here\n// came from something other than a check of a consumer module.\nconst DIAGNOSTIC_PATTERN = /^(.+?)\\(\\d+,\\d+\\): error TS\\d+: /u\nconst PING = ['ping', '--fetch-retries=0', '--fetch-timeout=5000', '--loglevel=silent']\nconst ESM_DRIVER = 'drive.mjs'\nconst CJS_DRIVER = 'drive.cjs'\nconst CONSUMER_MANIFEST = `{ \"name\": \"distribution-consumer\", \"private\": true, \"type\": \"module\" }\\n`\nconst ESM_DRIVER_SOURCE = `const entry = await import(process.argv[2])\nprocess.stdout.write(JSON.stringify(Object.keys(entry).sort()))\n`\nconst CJS_DRIVER_SOURCE = `const entry = require(process.argv[2])\nprocess.stdout.write(JSON.stringify(Object.keys(entry).sort()))\n`\n\n// The extensions a JavaScript handler loads as modules. Node loads a native addon\n// through its addon handler instead, so that extension is named separately.\nconst MODULE_EXTENSIONS = ['.js', '.mjs', '.cjs']\nconst ADDON_EXTENSION = '.node'\n// The extensions a declaration file carries. A `require` condition declares\n// `.d.cts` and an ESM-only one `.d.mts`, so the `.d.ts` spelling alone does not\n// name them.\nconst DECLARATION_EXTENSIONS = ['.d.ts', '.d.cts', '.d.mts']\ntype Format = 'module' | 'commonjs'\n\n// The Node import target is resolved with the conditions that driver supplies. The\n// CommonJS compile probe is selected from its declaration's format, and its runtime\n// drive loads the same subpath through Node's require resolver. Vite's production\n// client build enables its module and browser conditions.\nconst RUNTIME_CONDITIONS = Object.freeze({\n\tmodule: Object.freeze(['node-addons', 'node', 'import', 'module-sync']),\n\tcommonjs: Object.freeze(['node-addons', 'node', 'require', 'module-sync']),\n\tbrowser: Object.freeze(['module', 'browser', 'production', 'import']),\n})\n// TypeScript's Node resolutions add `node` to the format condition. Its bundler\n// resolution does not, so a browser drive compares against the declaration a bundler\n// consumer reads rather than borrowing the Node declaration.\nconst BUNDLER_CONDITIONS = Object.freeze({\n\tmodule: ['types', 'import'],\n\tcommonjs: ['types', 'require'],\n})\nconst DECLARATION_CONDITIONS = Object.freeze({\n\tmodule: ['types', 'node', 'import'],\n\tcommonjs: ['types', 'node', 'require'],\n\tbrowser: BUNDLER_CONDITIONS.module,\n})\n\ninterface Resolution {\n\treadonly label: string\n\treadonly resolution: string\n\treadonly module: string\n\treadonly conditions: Readonly<Record<Format, readonly string[]>>\n}\n\ninterface TargetResolution {\n\treadonly target: string\n}\n\n// Each compile driver carries the compiler options its scratch project sets and\n// the conditions TypeScript applies for that resolution and importing format. A\n// `require`-only subpath therefore stays in each CommonJS probe that can resolve it.\n// The option values are the spellings the project file takes, so nothing here needs\n// the compiler's own API to name them.\nconst RESOLUTIONS: readonly Resolution[] = [\n\t{\n\t\tlabel: 'node16',\n\t\tresolution: 'node16',\n\t\tmodule: 'node16',\n\t\tconditions: DECLARATION_CONDITIONS,\n\t},\n\t{\n\t\tlabel: 'nodenext',\n\t\tresolution: 'nodenext',\n\t\tmodule: 'nodenext',\n\t\tconditions: DECLARATION_CONDITIONS,\n\t},\n\t{\n\t\tlabel: 'bundler',\n\t\tresolution: 'bundler',\n\t\tmodule: 'esnext',\n\t\tconditions: BUNDLER_CONDITIONS,\n\t},\n]\n\n// The driver a bundled consumer reads declarations under. A browser application\n// compiles through a bundler, so the browser drive answers under this one alone,\n// and naming it here is what keeps that selection tied to the driver it selects.\nconst BROWSER_DRIVER = RESOLUTIONS.find((candidate) => candidate.label === 'bundler')\nif (BROWSER_DRIVER === undefined) throw new Error(\"RESOLUTIONS carries no 'bundler' row\")\n\nconst FORMATS: ReadonlyArray<readonly [extension: string, format: Format]> = [\n\t['ts', 'module'],\n\t['cts', 'commonjs'],\n]\n\n// One published subpath, resolved to what this proof can drive: the specifier a\n// consumer writes, whether the declarations its consumer formats resolve at all,\n// whether the exports map answers the browser condition with a target of its own,\n// whether it answers `import` and `require` at all, and whether the target that\n// `require` answers with is one that a CommonJS consumer loads.\ninterface Entry {\n\treadonly subpath: string\n\treadonly specifier: string\n\treadonly mapping: unknown\n\treadonly declaration: {\n\t\treadonly importable: boolean\n\t\treadonly requirable: boolean\n\t\treadonly browsable: boolean\n\t}\n\treadonly browsable: boolean\n\treadonly importable: boolean\n\treadonly requirable: boolean\n\treadonly loadable: boolean\n}\n\n// The installed tree every claim is read from. Every subpath the exports map names\n// lands in exactly one of `entries`, `undeclared`, and `excluded`, so a subpath this\n// proof cannot drive is reported rather than dropped.\ninterface Stage {\n\treadonly consumer: string\n\treadonly installed: string\n\treadonly archives: readonly string[]\n\treadonly entries: readonly Entry[]\n\treadonly subpaths: readonly string[]\n\treadonly undeclared: readonly string[]\n\treadonly excluded: readonly string[]\n\treadonly targets: readonly string[]\n}\n\nfunction isRecord(value: unknown): value is Readonly<Record<string, unknown>> {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction isNames(value: unknown): value is readonly string[] {\n\treturn Array.isArray(value) && value.every((name) => typeof name === 'string')\n}\n\n// A fallback list, which is what Node reads an array in an exports entry as. The\n// narrowing is what the following walkers need: `Array.isArray` widens an `unknown`\n// member to `any`, and an entry read that way is not read at all.\nfunction isList(value: unknown): value is readonly unknown[] {\n\treturn Array.isArray(value)\n}\n\n// Whether a string is a valid package target. Node rejects a target outside the\n// package and a target containing a dot, parent, or node_modules segment during\n// package-target resolution. A later module-resolution failure is not the same\n// thing: an array falls through the former and keeps the latter.\nfunction isPackageTarget(target: string): boolean {\n\tif (!target.startsWith('./')) return false\n\tconst refused = ['.', '..', 'node_modules']\n\treturn target\n\t\t.slice(2)\n\t\t.split(/[\\\\/]/u)\n\t\t.every((segment) => {\n\t\t\ttry {\n\t\t\t\treturn !refused.includes(decodeURIComponent(segment).toLowerCase())\n\t\t\t} catch {\n\t\t\t\treturn !refused.includes(segment.toLowerCase())\n\t\t\t}\n\t\t})\n}\n\nfunction readJson(path: string): unknown {\n\tconst parsed: unknown = JSON.parse(readFileSync(path, 'utf8'))\n\treturn parsed\n}\n\nfunction readManifestName(path: string): string {\n\tconst manifest = readJson(path)\n\tif (!isRecord(manifest) || typeof manifest.name !== 'string') {\n\t\tthrow new Error(`The manifest at ${path} declares no package name`)\n\t}\n\treturn manifest.name\n}\n\nfunction writeFile(path: string, content: string): void {\n\tmkdirSync(dirname(path), { recursive: true })\n\twriteFileSync(path, content)\n}\n\nfunction readOutput(result: SpawnSyncReturns<string>): string {\n\treturn `${result.stdout ?? ''}${result.stderr ?? ''}`.trim()\n}\n\nfunction runNpm(args: readonly string[], cwd: string, scratch: string): SpawnSyncReturns<string> {\n\treturn spawnSync(NPM, [...args], {\n\t\tcwd,\n\t\tencoding: 'utf8',\n\t\tenv: { ...process.env, npm_config_cache: join(scratch, 'cache') },\n\t\tshell: SHELL,\n\t\twindowsHide: true,\n\t})\n}\n\nfunction runNode(args: readonly string[], cwd: string): SpawnSyncReturns<string> {\n\treturn spawnSync(process.execPath, [...args], { cwd, encoding: 'utf8', windowsHide: true })\n}\n\n// Node's own condition matching, read in declaration order.\nfunction resolvePackageTarget(\n\tentry: unknown,\n\tconditions: readonly string[],\n): TargetResolution | undefined {\n\tif (typeof entry === 'string') return { target: entry }\n\tif (isList(entry)) {\n\t\tfor (const member of entry) {\n\t\t\tconst resolved = resolvePackageTarget(member, conditions)\n\t\t\tif (resolved !== undefined && isPackageTarget(resolved.target)) return resolved\n\t\t}\n\t\treturn undefined\n\t}\n\tif (!isRecord(entry)) return undefined\n\tfor (const [condition, nested] of Object.entries(entry)) {\n\t\tif (condition !== 'default' && !conditions.includes(condition)) continue\n\t\tconst resolved = resolvePackageTarget(nested, conditions)\n\t\tif (resolved !== undefined) return resolved\n\t}\n\treturn undefined\n}\n\n// A flat entry, a condition-nested entry, and a fallback list all resolve through\n// one walker. An entry may declare `types` beside `default` at its top level\n// rather than inside `import`, so a fixed `entry.import.types` lookup is not\n// equivalent to condition resolution.\nfunction resolveTarget(entry: unknown, conditions: readonly string[]): string | undefined {\n\treturn resolvePackageTarget(entry, conditions)?.target\n}\n\n// Whether a path is a physical file. TypeScript's file-existence check refuses a\n// directory at the same spelling and continues to the outer package scope.\nfunction matchesFile(path: string): boolean {\n\ttry {\n\t\treturn statSync(path).isFile()\n\t} catch {\n\t\treturn false\n\t}\n}\n\n// TypeScript resolves a declaration target by accepting an existing declaration\n// directly or by substituting beside a JavaScript target. A missing target leaves\n// the containing condition or fallback list unresolved, so the walk continues.\nfunction targetToDeclaration(target: string, installed: string): string | undefined {\n\tif (!isPackageTarget(target)) return undefined\n\tconst declaration = target.endsWith('.cjs')\n\t\t? `${target.slice(0, -4)}.d.cts`\n\t\t: target.endsWith('.mjs')\n\t\t\t? `${target.slice(0, -4)}.d.mts`\n\t\t\t: target.endsWith('.js')\n\t\t\t\t? `${target.slice(0, -3)}.d.ts`\n\t\t\t\t: target\n\tif (declaration === target && !isDeclaration(target)) return undefined\n\treturn matchesFile(join(installed, declaration)) ? declaration : undefined\n}\n\n// The declaration TypeScript resolves through one importing format's conditions.\n// Condition objects keep manifest order, and arrays keep fallback order.\nfunction resolveDeclaration(\n\tentry: unknown,\n\tconditions: readonly string[],\n\tinstalled: string,\n): string | undefined {\n\tif (typeof entry === 'string') return targetToDeclaration(entry, installed)\n\tif (isList(entry)) {\n\t\tfor (const member of entry) {\n\t\t\tconst resolved = resolveDeclaration(member, conditions, installed)\n\t\t\tif (resolved !== undefined) return resolved\n\t\t}\n\t\treturn undefined\n\t}\n\tif (!isRecord(entry)) return undefined\n\tfor (const [condition, nested] of Object.entries(entry)) {\n\t\tif (condition !== 'default' && !conditions.includes(condition)) continue\n\t\tconst resolved = resolveDeclaration(nested, conditions, installed)\n\t\tif (resolved !== undefined) return resolved\n\t}\n\treturn undefined\n}\n\n// The nearest package scope that decides a `.d.ts` declaration's module format. A\n// physical nested manifest starts a scope even when it omits `type` or cannot be\n// parsed. A directory at that spelling is not a manifest, so the walk continues.\nfunction readPackageType(installed: string, target: string): unknown {\n\t// One `dirname` per path segment reaches the root from any path. The walk ends at the\n\t// installed package, so no scope above it is consulted.\n\tconst start = dirname(join(installed, target))\n\tconst chain = start\n\t\t.split(/[\\\\/]/u)\n\t\t.reduce<string[]>((climbed) => [...climbed, dirname(climbed.at(-1) ?? start)], [start])\n\tconst end = chain.indexOf(installed)\n\tconst scope = chain\n\t\t.slice(0, end === -1 ? chain.length : end + 1)\n\t\t.find((directory) => matchesFile(join(directory, 'package.json')))\n\tif (scope === undefined) return undefined\n\ttry {\n\t\tconst manifest = readJson(join(scope, 'package.json'))\n\t\treturn isRecord(manifest) ? manifest.type : undefined\n\t} catch {\n\t\treturn undefined\n\t}\n}\n\nfunction resolvesBrowser(entry: unknown): boolean {\n\tconst module = resolveTarget(entry, RUNTIME_CONDITIONS.browser)\n\tif (module !== undefined && module.startsWith(BROWSER_OUTPUT)) return true\n\tif (module === undefined) return false\n\tconst imported = resolveTarget(entry, RUNTIME_CONDITIONS.module)\n\tconst required = resolveTarget(entry, RUNTIME_CONDITIONS.commonjs)\n\treturn module !== imported && module !== required\n}\n\n// Whether the target selected by Node's CommonJS conditions is a module require can\n// load. A JavaScript target takes its own nearest package scope. Native addons and\n// extensionless targets have their own CommonJS handlers.\nfunction resolvesCommonJS(entry: unknown, installed: string): boolean {\n\tconst target = resolveTarget(entry, RUNTIME_CONDITIONS.commonjs)\n\tif (target === undefined) return false\n\tconst name = target.slice(target.lastIndexOf('/') + 1)\n\tif (name.endsWith('.cjs')) return true\n\tif (name.endsWith('.mjs')) return false\n\tif (name.endsWith('.node')) return true\n\tif (!name.includes('.')) return true\n\treturn name.endsWith('.js') && readPackageType(installed, target) !== 'module'\n}\n\n// Whether the declaration selected by a typed CommonJS consumer admits that entry.\n// A `.d.cts` declaration admits and a `.d.mts` declaration refuses. A `.d.ts`\n// declaration takes its own nearest package scope.\nfunction declaresCommonJS(entry: unknown, installed: string): boolean {\n\tconst declaration = resolveDeclaration(entry, DECLARATION_CONDITIONS.commonjs, installed)\n\tif (declaration === undefined) return false\n\tif (declaration.endsWith('.d.cts')) return true\n\tif (declaration.endsWith('.d.mts')) return false\n\treturn declaration.endsWith('.d.ts') && readPackageType(installed, declaration) !== 'module'\n}\n\n// Every target an entry names under any condition. A fallback list omits members\n// Node rejects during package-target validation, because no reader can take them.\nfunction collectTargets(entry: unknown): readonly string[] {\n\tif (typeof entry === 'string') return [entry]\n\tif (isList(entry)) return entry.flatMap(collectTargets).filter(isPackageTarget)\n\tif (!isRecord(entry)) return []\n\treturn Object.values(entry).flatMap((nested) => collectTargets(nested))\n}\n\n// Whether a target is a file a runtime loads for its names, which is what a\n// declaration is owed for. The extension on the target's own file name decides it,\n// and a name carrying no extension is code: `require` reads such a file through its\n// JavaScript handler, so an extensionless target loads and publishes names. Node\n// loads `.node` through its native-addon handler. Every other extension is an asset\n// a consumer reads rather than imports — a stylesheet, a WebAssembly binary, the\n// `\"./package.json\"` manifest pointer, and a declaration alike.\n// The cost is an extensionless file published for a reader, such as a `LICENSE`:\n// that target reports undeclared until it is given an extension or a declaration.\nfunction isModule(target: string): boolean {\n\tconst name = target.slice(target.lastIndexOf('/') + 1)\n\tconst dot = name.lastIndexOf('.')\n\tif (name.endsWith(ADDON_EXTENSION)) return true\n\treturn dot === -1 || MODULE_EXTENSIONS.includes(name.slice(dot))\n}\n\n// Whether a resolved target is a declaration rather than the JavaScript a\n// `default` branch answers with when the entry declares no `types` condition.\nfunction isDeclaration(target: string): boolean {\n\treturn DECLARATION_EXTENSIONS.some((extension) => target.endsWith(extension))\n}\n\n// The declarations the Node module, Node CommonJS, and browser drives compare\n// against. Each field uses the conditions of the TypeScript consumer paired with\n// that runtime. A JavaScript target resolves through TypeScript's adjacent\n// declaration substitution rather than standing in for the declaration itself.\nfunction readDeclaration(\n\tentry: unknown,\n\tinstalled: string,\n): {\n\treadonly module: string | undefined\n\treadonly commonjs: string | undefined\n\treadonly browser: string | undefined\n} {\n\treturn {\n\t\tmodule: resolveDeclaration(entry, DECLARATION_CONDITIONS.module, installed),\n\t\tcommonjs: resolveDeclaration(entry, DECLARATION_CONDITIONS.commonjs, installed),\n\t\tbrowser: resolveDeclaration(entry, DECLARATION_CONDITIONS.browser, installed),\n\t}\n}\n\n// The entries one compile driver can resolve under its own conditions.\nfunction selectEntries(entries: readonly Entry[], conditions: readonly string[]): readonly Entry[] {\n\treturn entries.filter(\n\t\t(entry) =>\n\t\t\tresolveTarget(entry.mapping, conditions) !== undefined &&\n\t\t\t(!conditions.includes('require') || entry.loadable),\n\t)\n}\n\n// The compile drivers whose conditions reach one entry under one importing format.\n// A driver that resolves no target for that entry compiles nothing, so a consumer\n// written under it would report a resolution failure this package never made.\nfunction selectDrivers(entry: Entry, format: Format): readonly Resolution[] {\n\treturn RESOLUTIONS.filter(\n\t\t(driver) => selectEntries([entry], driver.conditions[format]).length > 0,\n\t)\n}\n\n// Requirable entries that declare CommonJS support but a typed CommonJS consumer\n// cannot compile against. A default branch resolving under the require condition\n// set makes no CommonJS claim.\nfunction selectUntypable(entries: readonly Entry[], installed: string): readonly Entry[] {\n\treturn entries.filter(\n\t\t(entry) =>\n\t\t\tentry.requirable &&\n\t\t\tisRecord(entry.mapping) &&\n\t\t\tObject.hasOwn(entry.mapping, 'require') &&\n\t\t\t!declaresCommonJS(entry.mapping, installed),\n\t)\n}\n\n// One surface comparison, written as the consumer module that proves it: the\n// installed entry that consumer imports, the file extension fixing its importing\n// format, the names a real runtime published off it, and the driver whose scratch\n// project compiles it.\ninterface Surface {\n\treadonly entry: Entry\n\treadonly extension: string\n\treadonly published: readonly string[]\n\treadonly driver: Resolution\n}\n\n// A scratch project over named consumer modules, written beside them so their own\n// resolution reaches the installed package. Nothing is emitted and no ambient types\n// are pulled in, so what the check reads is the installed declarations alone.\nfunction writeProject(\n\tstage: Stage,\n\tname: string,\n\tdriver: Resolution,\n\tfiles: readonly string[],\n): string {\n\tconst path = join(stage.consumer, `tsconfig.${name}.json`)\n\tconst project = {\n\t\tcompilerOptions: {\n\t\t\tmodule: driver.module,\n\t\t\tmoduleResolution: driver.resolution,\n\t\t\tnoEmit: true,\n\t\t\tskipLibCheck: true,\n\t\t\tstrict: true,\n\t\t\ttarget: 'esnext',\n\t\t\ttypes: [],\n\t\t},\n\t\tfiles: [...files],\n\t}\n\twriteFile(path, `${JSON.stringify(project, undefined, '\\t')}\\n`)\n\treturn path\n}\n\n// The diagnostics the compiler this workspace installs reports for one scratch\n// project. The compiler runs as a command, so nothing here reaches an API that\n// moves between its majors, and the located lines it prints are the verdict rather\n// than the exit code, which moves between them. A line carrying no location, a line\n// naming the scratch project rather than a consumer module, and anything at all on\n// the error stream are faults of this proof rather than of the package under proof,\n// so each is raised where it happens instead of counted against the package.\nfunction checkProject(stage: Stage, project: string): readonly string[] {\n\tconst result = runNode([TSC, '--noEmit', '--pretty', 'false', '-p', project], stage.consumer)\n\tconst refused = `${result.stderr ?? ''}`.trim()\n\tif (refused.length > 0) {\n\t\tthrow new Error(`The consumer compiler wrote ${refused} to its error stream`)\n\t}\n\tconst lines = `${result.stdout ?? ''}`.split(/\\r\\n|\\n/u).filter((line) => line.trim().length > 0)\n\t// An elaborated diagnostic prints its detail on indented lines under its own\n\t// first line, so each of those joins the diagnostic it elaborates. The first line\n\t// has no diagnostic above it to join, so it opens one whatever its indentation.\n\tconst heads = lines.flatMap((line, index) => (index === 0 || !/^\\s/u.test(line) ? [index] : []))\n\tconst reported = heads.map((head, position) => {\n\t\tconst line = lines[head] ?? ''\n\t\tconst located = DIAGNOSTIC_PATTERN.exec(line)?.[1]\n\t\tif (located === undefined) {\n\t\t\tthrow new Error(`The consumer compiler reported ${line}, which names no location`)\n\t\t}\n\t\tif (resolve(stage.consumer, located) === project) {\n\t\t\tthrow new Error(`The scratch project is itself at fault: ${line}`)\n\t\t}\n\t\treturn [\n\t\t\tline,\n\t\t\t...lines.slice(head + 1, heads[position + 1] ?? lines.length).map((detail) => detail.trim()),\n\t\t].join(' ')\n\t})\n\tif (reported.length === 0 && result.status !== 0) {\n\t\tthrow new Error(`The consumer compiler refused the project: ${readOutput(result)}`)\n\t}\n\treturn reported\n}\n\n// One installed entry's published names checked against its own declarations by\n// the compiler this workspace installs, in the direction each divergence surfaces\n// under. The runtime's key list is written into the consumer as a literal, so the\n// published side comes from a real process and the declared side from the\n// declarations that process's package ships, and the two can disagree. A name the\n// declarations carry and the runtime does not lands on `declared`. A name the\n// runtime carries and the declarations do not, and a name the declarations publish\n// as a type alone, land on `surfaced`: a variable widens into the type\n// `declared` annotates, and only `surfaced` reads the literal's own keys back.\n// Each names the member it is about, so the failure says which export moved.\nfunction checkSurface(stage: Stage, surface: Surface): readonly string[] {\n\tconst slug = surface.entry.subpath.replaceAll(/[^\\w]+/gu, '-')\n\tconst name = `surface.${surface.driver.label}${slug}.${surface.extension}`\n\tconst module = `${name}`\n\tconst keys = surface.published.map((key) => `${JSON.stringify(key)}: true`).join(', ')\n\twriteFile(\n\t\tjoin(stage.consumer, module),\n\t\t`import * as entry from ${JSON.stringify(surface.entry.specifier)}\nconst published = {${keys.length === 0 ? '' : ` ${keys} `}} as const\nconst declared: Record<keyof typeof entry, true> = published\nconst surfaced: Record<keyof typeof published, true> = declared\n`,\n\t)\n\tconst project = writeProject(stage, name, surface.driver, [`./${module}`])\n\treturn checkProject(stage, project).map((line) => `${surface.driver.label}: ${line}`)\n}\n\n// One consumer module importing every installed entry, written where its own\n// resolution finds the installed package.\nfunction writeConsumerProbe(stage: Stage, path: string, specifiers: readonly string[]): void {\n\tconst modules = specifiers.map((specifier, index) => ({\n\t\tbinding: `entry${String(index)}`,\n\t\tspecifier,\n\t}))\n\tconst bindings = modules.map(\n\t\t({ binding, specifier }) => `import * as ${binding} from ${JSON.stringify(specifier)}`,\n\t)\n\tconst names = modules.map(({ binding }) => binding)\n\tconst source = `${bindings.join('\\n')}\\nexport const surface = [${names.join(', ')}]\\n`\n\twriteFile(join(stage.consumer, path), source)\n}\n\n// The runtime key set a real process reads off one installed entry under one\n// condition. The driver is a file rather than an `--eval` string, so the specifier\n// travels as an argument and nothing needs escaping.\nfunction driveRuntime(stage: Stage, specifier: string, driver: string): readonly string[] {\n\tconst result = runNode([join(stage.consumer, driver), specifier], stage.consumer)\n\tif (result.status !== 0) {\n\t\tthrow new Error(`Loading ${specifier} from the consumer failed: ${readOutput(result)}`)\n\t}\n\tconst published: unknown = JSON.parse(result.stdout)\n\tif (!isNames(published)) throw new Error(`The driver printed no name list for ${specifier}`)\n\treturn published\n}\n{{helpers}}\n// Pack this workspace, install the archive into an isolated consumer, and read the\n// published surface back off the installed tree. Every later claim reads this\n// result, so a failure here is raised where it happens rather than once per entry.\nfunction buildStage(scratch: string): Stage {\n\tconst packed = join(scratch, 'packed')\n\tconst consumer = join(scratch, 'consumer')\n\tmkdirSync(packed, { recursive: true })\n\tconst pack = runNpm(['pack', '--ignore-scripts', '--pack-destination', packed], ROOT, scratch)\n\tif (pack.status !== 0) throw new Error(`npm pack refused this workspace: ${readOutput(pack)}`)\n\tconst archives = readdirSync(packed).filter((name) => name.endsWith('.tgz'))\n\tconst archive = archives[0]\n\tif (archives.length !== 1 || archive === undefined) {\n\t\tthrow new Error(`npm pack wrote no single archive: ${archives.join(', ')}`)\n\t}\n\twriteFile(join(consumer, 'package.json'), CONSUMER_MANIFEST)\n\twriteFile(join(consumer, ESM_DRIVER), ESM_DRIVER_SOURCE)\n\twriteFile(join(consumer, CJS_DRIVER), CJS_DRIVER_SOURCE)\n\tconst install = runNpm(\n\t\t['install', '--ignore-scripts', '--no-audit', '--no-fund', join(packed, archive)],\n\t\tconsumer,\n\t\tscratch,\n\t)\n\tif (install.status !== 0) {\n\t\tthrow new Error(`Installing the packed archive failed: ${readOutput(install)}`)\n\t}\n\tconst name = readManifestName(join(ROOT, 'package.json'))\n\tconst installed = join(consumer, 'node_modules', ...name.split('/'))\n\tconst manifest = readJson(join(installed, 'package.json'))\n\tif (!isRecord(manifest) || !isRecord(manifest.exports)) {\n\t\tthrow new Error('The installed manifest publishes no exports map')\n\t}\n\tconst readings = Object.entries(manifest.exports).map(([subpath, mapping]) => {\n\t\tconst files = collectTargets(mapping)\n\t\tconst declaration = readDeclaration(mapping, installed)\n\t\t// A subpath resolving no declaration is partitioned rather than dropped. It is a\n\t\t// defect when a runtime loads one of its targets for names, because a consumer\n\t\t// importing it compiles against nothing under `node16`. It is an excluded\n\t\t// publication otherwise: the `\"./package.json\"` manifest pointer and a stylesheet\n\t\t// are published for a reader rather than an importer.\n\t\tif (\n\t\t\tdeclaration.module === undefined &&\n\t\t\tdeclaration.commonjs === undefined &&\n\t\t\tdeclaration.browser === undefined\n\t\t) {\n\t\t\treturn { subpath, files, entry: undefined }\n\t\t}\n\t\tconst importTarget = resolveTarget(mapping, RUNTIME_CONDITIONS.module)\n\t\tconst requireTarget = resolveTarget(mapping, RUNTIME_CONDITIONS.commonjs)\n\t\tconst browserTarget = resolveTarget(mapping, RUNTIME_CONDITIONS.browser)\n\t\tconst browsable = resolvesBrowser(mapping)\n\t\tconst shadowed = browsable && requireTarget === browserTarget\n\t\tconst requirable = requireTarget !== undefined && !shadowed\n\t\tconst loadable = requirable && resolvesCommonJS(mapping, installed)\n\t\tconst entry: Entry = {\n\t\t\tsubpath,\n\t\t\tspecifier: subpath === '.' ? name : `${name}${subpath.slice(1)}`,\n\t\t\tmapping,\n\t\t\tdeclaration: {\n\t\t\t\timportable: declaration.module !== undefined,\n\t\t\t\trequirable: declaration.commonjs !== undefined,\n\t\t\t\tbrowsable: declaration.browser !== undefined,\n\t\t\t},\n\t\t\tbrowsable,\n\t\t\timportable: importTarget !== undefined && !(browsable && importTarget === browserTarget),\n\t\t\trequirable,\n\t\t\tloadable,\n\t\t}\n\t\treturn { subpath, files, entry }\n\t})\n\tconst entries = readings.flatMap(({ entry }) => (entry === undefined ? [] : [entry]))\n\tconst targets = readings.flatMap(({ files }) => files)\n\tconst subpaths = readings.map(({ subpath }) => subpath)\n\tconst undeclared = readings\n\t\t.filter(({ entry, files }) => entry === undefined && files.some(isModule))\n\t\t.map(({ subpath }) => subpath)\n\tconst excluded = readings\n\t\t.filter(({ entry, files }) => entry === undefined && !files.some(isModule))\n\t\t.map(({ subpath }) => subpath)\n\treturn { consumer, installed, archives, entries, subpaths, undeclared, excluded, targets }\n}\n\n// One file's run: the scratch directory and the staged consumer, which is absent when the\n// registry could not be reached.\ninterface DistributionRun {\n\treadonly scratch: string\n\treadonly stage: Stage | undefined\n}\n\n// The run the start hook binds once for this file and the stop hook releases.\nclass DistributionSuite {\n\t#run: DistributionRun | undefined\n\n\tget scratch(): string {\n\t\tif (this.#run === undefined) {\n\t\t\tthrow new Error('The distribution setup has not allocated its scratch directory')\n\t\t}\n\t\treturn this.#run.scratch\n\t}\n\n\tget stage(): Stage | undefined {\n\t\treturn this.#run?.stage\n\t}\n\n\tstart(): void {\n\t\tif (this.#run !== undefined) {\n\t\t\tthrow new Error('The distribution setup has already allocated its scratch directory')\n\t\t}\n\t\tconst scratch = mkdtempSync(join(tmpdir(), 'distribution-'))\n\t\tthis.#run = { scratch, stage: openStage(scratch) }\n\t}\n\n\tdestroy(): void {\n\t\tif (this.#run !== undefined) {\n\t\t\trmSync(this.#run.scratch, { force: true, recursive: true, maxRetries: 3, retryDelay: 100 })\n\t\t}\n\t\tthis.#run = undefined\n\t}\n}\n\nconst DISTRIBUTION_SUITE = new DistributionSuite()\n\nbeforeAll(() => DISTRIBUTION_SUITE.start())\n\nafterAll(() => DISTRIBUTION_SUITE.destroy())\n\n// Installing the packed archive resolves its own runtime dependencies, so an\n// unreachable registry leaves nothing to measure. Under release that is the gate\n// failing; anywhere else the suite skips and names the mechanism it wanted.\nfunction openStage(scratch: string): Stage | undefined {\n\ttry {\n\t\tmkdirSync(join(scratch, 'cache'), { recursive: true })\n\t\tif (runNpm(PING, ROOT, scratch).status !== 0) {\n\t\t\tif (!RELEASE) return undefined\n\t\t\tthrow new Error(\n\t\t\t\t'The release gate requires a reachable npm registry, and npm ping did not answer',\n\t\t\t)\n\t\t}\n\t\treturn buildStage(scratch)\n\t} catch (error) {\n\t\trmSync(scratch, {\n\t\t\tforce: true,\n\t\t\trecursive: true,\n\t\t\tmaxRetries: 3,\n\t\t\tretryDelay: 100,\n\t\t})\n\t\tthrow error\n\t}\n}\n\ndescribe('distribution classifiers', () => {\n\tit('classifies synthetic export mappings without a registry stage', () => {\n\t\tconst root = join(DISTRIBUTION_SUITE.scratch, 'classifiers')\n\t\twriteFile(\n\t\t\tjoin(root, 'package.json'),\n\t\t\tJSON.stringify({\n\t\t\t\ttype: 'commonjs',\n\t\t\t\texports: {\n\t\t\t\t\tcondition: { browser: './b.js', default: './n.js' },\n\t\t\t\t\tconvention: { default: './dist/src/browser/index.js' },\n\t\t\t\t\tuniversal: { default: './shared.js' },\n\t\t\t\t\t'import-shared': {\n\t\t\t\t\t\tbrowser: './shared.mjs',\n\t\t\t\t\t\timport: './shared.mjs',\n\t\t\t\t\t\tdefault: './node.js',\n\t\t\t\t\t},\n\t\t\t\t\t'require-shared': {\n\t\t\t\t\t\tbrowser: './shared.cjs',\n\t\t\t\t\t\trequire: './shared.cjs',\n\t\t\t\t\t\tdefault: './node.js',\n\t\t\t\t\t},\n\t\t\t\t\tnode: { node: './node.js', default: './node.js' },\n\t\t\t\t\tsilent: { 'module-sync': './x.cjs', import: './x.mjs' },\n\t\t\t\t\tmodule: { require: './x.mjs' },\n\t\t\t\t\t'nested-module': { require: './module/x.js' },\n\t\t\t\t\t'nested-commonjs': { require: './commonjs/x.js' },\n\t\t\t\t\tesm: { import: './x.mjs' },\n\t\t\t\t},\n\t\t\t}),\n\t\t)\n\t\twriteFile(join(root, 'module/package.json'), '{ \"type\": \"module\" }\\n')\n\t\twriteFile(join(root, 'commonjs/package.json'), '{ \"type\": \"commonjs\" }\\n')\n\t\tconst manifest = readJson(join(root, 'package.json'))\n\t\tif (!isRecord(manifest) || !isRecord(manifest.exports)) {\n\t\t\tthrow new Error('The classifier fixture declares no exports map')\n\t\t}\n\t\tconst mappings = manifest.exports\n\t\texpect({\n\t\t\tcondition: resolvesBrowser(mappings.condition),\n\t\t\tconvention: resolvesBrowser(mappings.convention),\n\t\t\tuniversal: resolvesBrowser(mappings.universal),\n\t\t\timport: resolvesBrowser(mappings['import-shared']),\n\t\t\trequire: resolvesBrowser(mappings['require-shared']),\n\t\t\tnode: resolvesBrowser(mappings.node),\n\t\t}).toStrictEqual({\n\t\t\tcondition: true,\n\t\t\tconvention: true,\n\t\t\tuniversal: false,\n\t\t\timport: false,\n\t\t\trequire: false,\n\t\t\tnode: false,\n\t\t})\n\t\texpect({\n\t\t\tsilent: resolvesCommonJS(mappings.silent, root),\n\t\t\tmodule: resolvesCommonJS(mappings.module, root),\n\t\t\tnestedModule: resolvesCommonJS(mappings['nested-module'], root),\n\t\t\tnestedCommonJS: resolvesCommonJS(mappings['nested-commonjs'], root),\n\t\t\tesm: resolvesCommonJS(mappings.esm, root),\n\t\t}).toStrictEqual({\n\t\t\tsilent: true,\n\t\t\tmodule: false,\n\t\t\tnestedModule: false,\n\t\t\tnestedCommonJS: true,\n\t\t\tesm: false,\n\t\t})\n\t})\n})\n\n// The staged consumer, or a skip naming what the run could not reach. `it.skipIf`\n// carries no reason, so the gate sits here where the test context can state one.\nfunction requireStage(context: TestContext): Stage {\n\tconst staged = DISTRIBUTION_SUITE.stage\n\tif (staged === undefined) {\n\t\treturn context.skip('`npm ping` did not answer, so nothing was packed or installed')\n\t}\n\treturn staged\n}\n\ndescribe('installed package consumer', () => {\n\tit('packs one archive and installs it in isolation [requires the registry]', (context) => {\n\t\tconst stage = requireStage(context)\n\t\texpect(stage.archives).toHaveLength(1)\n\t\texpect(existsSync(join(stage.installed, 'package.json'))).toBe(true)\n\t\texpect(stage.entries.length).toBeGreaterThan(0)\n\t})\n\n\tit('ships every relative target its exports map names [requires the registry]', (context) => {\n\t\tconst stage = requireStage(context)\n\t\tconst relative = stage.targets.filter((target) => target.startsWith('./'))\n\t\texpect(relative).not.toStrictEqual([])\n\t\texpect(relative.filter((target) => !existsSync(join(stage.installed, target)))).toStrictEqual(\n\t\t\t[],\n\t\t)\n\t})\n\n\t// Every published subpath is driven, excluded by name, or reported here. A dropped\n\t// one leaves no trace: no runtime test, no declaration comparison, and no place in\n\t// the resolution compile, so the run reports success for a subpath it never\n\t// measured.\n\tit('declares types for every module it publishes [requires the registry]', (context) => {\n\t\tconst stage = requireStage(context)\n\t\tconst partitioned = [\n\t\t\t...stage.entries.map((entry) => entry.subpath),\n\t\t\t...stage.undeclared,\n\t\t\t...stage.excluded,\n\t\t]\n\t\texpect(stage.undeclared).toStrictEqual([])\n\t\texpect(partitioned.sort()).toStrictEqual([...stage.subpaths].sort())\n\t\t// A driven subpath answers a runtime condition. One resolving a declaration and\n\t\t// no Node or browser target compiles for a consumer and throws when that consumer\n\t\t// loads it. Each later drive retires itself for that entry, so this assertion names\n\t\t// the subpath rather than counting it as driven.\n\t\tconst unreachable = stage.entries.filter(\n\t\t\t(entry) => !entry.importable && !entry.requirable && !entry.browsable,\n\t\t)\n\t\texpect(unreachable.map((entry) => entry.subpath)).toStrictEqual([])\n\t\tconst untypable = selectUntypable(stage.entries, stage.installed)\n\t\texpect(untypable.map((entry) => entry.subpath)).toStrictEqual([])\n\t})\n\n\tit('refuses a subpath its exports map does not name [requires the registry]', (context) => {\n\t\tconst stage = requireStage(context)\n\t\tconst name = readManifestName(join(stage.installed, 'package.json'))\n\t\tconst driver = join(stage.consumer, ESM_DRIVER)\n\t\tconst result = runNode([driver, `${name}${ABSENT_SUBPATH}`], stage.consumer)\n\t\texpect(result.status).not.toBe(0)\n\t\texpect(readOutput(result)).toContain('ERR_PACKAGE_PATH_NOT_EXPORTED')\n\t})\n\n\t// The absent subpath is the firing control: a resolution that reports nothing\n\t// for every published entry has not been shown to resolve anything at all. Each\n\t// module format carries its own control, because a format that resolves nothing\n\t// is silent for the same reason a resolution that resolves nothing is.\n\tit('compiles a consumer under every module resolution [requires the registry]', (context) => {\n\t\tconst stage = requireStage(context)\n\t\tconst name = readManifestName(join(stage.installed, 'package.json'))\n\t\tconst readings = RESOLUTIONS.flatMap((driver) =>\n\t\t\tFORMATS.flatMap(([extension, format]) => {\n\t\t\t\tconst written = selectEntries(stage.entries, driver.conditions[format])\n\t\t\t\tif (written.length === 0) return []\n\t\t\t\tconst label = `${driver.label}.${extension}`\n\t\t\t\tconst probe = `probe.${label}`\n\t\t\t\tconst specifiers = written.map((entry) => entry.specifier)\n\t\t\t\twriteConsumerProbe(stage, probe, specifiers)\n\t\t\t\tconst project = writeProject(stage, probe, driver, [`./${probe}`])\n\t\t\t\tconst messages = checkProject(stage, project).map((message) => `${label}: ${message}`)\n\t\t\t\tconst control = `control.${label}`\n\t\t\t\twriteConsumerProbe(stage, control, [`${name}${ABSENT_SUBPATH}`])\n\t\t\t\tconst refused = writeProject(stage, control, driver, [`./${control}`])\n\t\t\t\treturn [{ messages, silent: checkProject(stage, refused).length === 0 ? [label] : [] }]\n\t\t\t}),\n\t\t)\n\t\texpect(readings.flatMap(({ messages }) => messages)).toStrictEqual([])\n\t\texpect(readings.flatMap(({ silent }) => silent)).toStrictEqual([])\n\t})\n{{guard}}})\n\ndescribe('installed entries', () => {\n\tit('publishes what it declares to a Node import, and no more', (context) => {\n\t\tconst stage = requireStage(context)\n\t\tconst entries = stage.entries.filter((entry) => entry.importable)\n\t\tif (entries.length === 0) return context.skip('No installed entry supports Node import')\n\t\tfor (const entry of entries) {\n\t\t\tif (!entry.declaration.importable) {\n\t\t\t\tthrow new Error(`${entry.subpath} publishes no import declaration`)\n\t\t\t}\n\t\t\tconst published = driveRuntime(stage, entry.specifier, ESM_DRIVER)\n\t\t\tconst drivers = selectDrivers(entry, 'module')\n\t\t\texpect(drivers).not.toStrictEqual([])\n\t\t\tconst reported = drivers.flatMap((driver) =>\n\t\t\t\tcheckSurface(stage, { entry, extension: 'ts', published, driver }),\n\t\t\t)\n\t\t\texpect(reported).toStrictEqual([])\n\t\t}\n\t})\n\n\tit('publishes what it declares to a Node require, and no more', (context) => {\n\t\tconst stage = requireStage(context)\n\t\tconst entries = stage.entries.filter((entry) => entry.requirable)\n\t\tif (entries.length === 0) return context.skip('No installed entry supports Node require')\n\t\tfor (const entry of entries) {\n\t\t\tif (!entry.declaration.requirable) {\n\t\t\t\tthrow new Error(`${entry.subpath} publishes no require declaration`)\n\t\t\t}\n\t\t\tconst published = driveRuntime(stage, entry.specifier, CJS_DRIVER)\n\t\t\tconst drivers = selectDrivers(entry, 'commonjs')\n\t\t\texpect(drivers).not.toStrictEqual([])\n\t\t\tconst reported = drivers.flatMap((driver) =>\n\t\t\t\tcheckSurface(stage, { entry, extension: 'cts', published, driver }),\n\t\t\t)\n\t\t\texpect(reported).toStrictEqual([])\n\t\t}\n\t})\n{{drive}}})\n";
|
|
135
|
+
module: "{{types}}import type { SpawnSyncReturns } from 'node:child_process'\nimport type { TestContext } from 'vitest'\nimport { spawnSync } from 'node:child_process'\nimport {\n\texistsSync,\n\tmkdirSync,\n\tmkdtempSync,\n\treaddirSync,\n\treadFileSync,\n\trmSync,\n\tstatSync,\n\twriteFileSync,\n} from 'node:fs'\n{{transport}}import { createRequire } from 'node:module'\nimport { tmpdir } from 'node:os'\nimport { dirname, join, relative as relativePath, resolve, sep } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { isDeepStrictEqual } from 'node:util'\nimport { parseSync } from 'vite'\n{{launcher}}\n/** Defines the lifecycle and installed consumer read by a distribution proof. */\nexport interface DistributionSuiteInterface {\n\treadonly scratch: string\n\tstart(): void\n\tread(context: TestContext): DistributionStage\n\tdestroy(): void\n}\n\n/** Holds the observed and required values for one distribution assertion. */\nexport interface DistributionObservation {\n\treadonly actual: unknown\n\treadonly expected: unknown\n}\n\n/** Defines one independently registered distribution observation. */\nexport interface DistributionCase {\n\treadonly label: string\n\treadonly observe: (\n\t\tcontext: TestContext,\n\t) => DistributionObservation | Promise<DistributionObservation>\n}\n\n/** Holds the installed export map's classified publications. */\nexport interface DistributionClassification {\n\treadonly entries: readonly DistributionEntry[]\n\treadonly subpaths: readonly string[]\n\treadonly undeclared: readonly string[]\n\treadonly excluded: readonly string[]\n\treadonly targets: readonly string[]\n}\n\n/** Names the workspace whose packed artifact the proof consumes. */\nexport const DISTRIBUTION_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')\n/** Names the npm executable on the running host. */\nexport const DISTRIBUTION_NPM = process.platform === 'win32' ? 'npm.cmd' : 'npm'\n// The compiler this workspace installs, run as a command rather than called in\n// process: the command and its plain-text diagnostics are the same across the\n// compiler majors this toolchain supports, and its in-process API is not. It is\n// resolved from the workspace under proof, so a consumer of the packed artifact is\n// checked by the same compiler that workspace's own `check` script runs.\n/** Names the compiler installed by the workspace under proof. */\nexport const DISTRIBUTION_COMPILER = createRequire(join(DISTRIBUTION_ROOT, 'package.json')).resolve(\n\t'typescript/bin/tsc',\n)\n// Windows needs a shell to launch a `.cmd`: Node refuses one directly since the\n// batch-argument hardening, and `spawnSync` returns `EINVAL` with a null status\n// rather than an exit code a caller can read. Every following argument is a literal or\n// a path this file built, so the shell has nothing to escape.\n/** Selects the Windows command-shell route required by the npm shim. */\nexport const DISTRIBUTION_SHELL = process.platform === 'win32'\n// `prepublishOnly` runs this proof as `npm run test:distribution -- --mode release`,\n// and the root configuration's project factories carry that mode into this project.\n// Release is the publish gate, so evidence it cannot obtain fails there and skips\n// everywhere else: a gate that passes on missing evidence proves nothing.\n/** Indicates whether missing prerequisites must fail the publish gate. */\nexport const DISTRIBUTION_RELEASE = import.meta.env?.MODE === 'release'\n// The built output directory convention a browser face may publish from. Every\n// selection reads this prefix off the export target and never off the subpath name. A\n// workspace whose only published face is the browser one publishes that face at the\n// root subpath, so a rule keyed on the subpath name drives a browser bundle through\n// Node and the miss is silent.\n/** Names the conventional output prefix for a browser publication. */\nexport const DISTRIBUTION_BROWSER_OUTPUT = './dist/src/browser/'\n/** Names the unpublished subpath used as a resolution control. */\nexport const DISTRIBUTION_ABSENT_SUBPATH = '/no-subpath-is-published-under-this-name'\n// A compiler diagnostic that says where it is: the path relative to the directory\n// the compiler ran in, the 1-based line and column, the code, and the message. The\n// diagnostics are the verdict rather than the exit code, which differs between the\n// compiler majors this toolchain supports, so a reported line matching nothing here\n// came from something other than a check of a consumer module.\n/** Matches the location prefix of a consumer compiler diagnostic. */\nexport const DISTRIBUTION_DIAGNOSTIC_PATTERN = /^(.+?)\\(\\d+,\\d+\\): error TS\\d+: /u\n/** Lists the bounded registry-readiness command arguments. */\nexport const DISTRIBUTION_PING = Object.freeze([\n\t'ping',\n\t'--fetch-retries=0',\n\t'--fetch-timeout=5000',\n\t'--loglevel=silent',\n])\n/** Names the consumer entry that imports an installed module. */\nexport const DISTRIBUTION_ESM_DRIVER = 'drive.mjs'\n/** Names the consumer entry that requires an installed module. */\nexport const DISTRIBUTION_CJS_DRIVER = 'drive.cjs'\n/** Defines the isolated consumer package manifest. */\nexport const DISTRIBUTION_CONSUMER_MANIFEST =\n\t'{ \"name\": \"distribution-consumer\", \"private\": true, \"type\": \"module\" }\\n'\n/** Reads the names exported by an installed ESM entry. */\nexport const DISTRIBUTION_ESM_DRIVER_SOURCE = `const entry = await import(process.argv[2])\nprocess.stdout.write(JSON.stringify(Object.keys(entry).sort()))\n`\n/** Reads the names exported by an installed CommonJS entry. */\nexport const DISTRIBUTION_CJS_DRIVER_SOURCE = `const entry = require(process.argv[2])\nprocess.stdout.write(JSON.stringify(Object.keys(entry).sort()))\n`\n\n// The extensions a JavaScript handler loads as modules. Node loads a native addon\n// through its addon handler instead, so that extension is named separately.\n/** Lists extensions loaded as JavaScript modules. */\nexport const DISTRIBUTION_MODULE_EXTENSIONS = Object.freeze(['.js', '.mjs', '.cjs'])\n/** Names the extension loaded by the native-addon handler. */\nexport const DISTRIBUTION_ADDON_EXTENSION = '.node'\n// The extensions a declaration file carries. A `require` condition declares\n// `.d.cts` and an ESM-only one `.d.mts`, so the `.d.ts` spelling alone does not\n// name them.\n/** Lists the supported TypeScript declaration extensions. */\nexport const DISTRIBUTION_DECLARATION_EXTENSIONS = Object.freeze(['.d.ts', '.d.cts', '.d.mts'])\n/** Names the module format of a typed consumer. */\nexport type DistributionFormat = 'module' | 'commonjs'\n\n// The Node import target is resolved with the conditions that driver supplies. The\n// CommonJS compile probe is selected from its declaration's format, and its runtime\n// drive loads the same subpath through Node's require resolver. Vite's production\n// client build enables its module and browser conditions.\n/** Defines the conditions each runtime uses to resolve an entry. */\nexport const DISTRIBUTION_RUNTIME_CONDITIONS = Object.freeze({\n\tmodule: Object.freeze(['node-addons', 'node', 'import', 'module-sync']),\n\tcommonjs: Object.freeze(['node-addons', 'node', 'require', 'module-sync']),\n\tbrowser: Object.freeze(['module', 'browser', 'production', 'import']),\n})\n// TypeScript's Node resolutions add `node` to the format condition. Its bundler\n// resolution does not, so a browser drive compares against the declaration a bundler\n// consumer reads rather than borrowing the Node declaration.\n/** Defines the declaration conditions used by bundler consumers. */\nexport const DISTRIBUTION_BUNDLER_CONDITIONS = Object.freeze({\n\tmodule: Object.freeze(['types', 'import']),\n\tcommonjs: Object.freeze(['types', 'require']),\n})\n/** Defines the declaration conditions paired with each runtime. */\nexport const DISTRIBUTION_DECLARATION_CONDITIONS = Object.freeze({\n\tmodule: Object.freeze(['types', 'node', 'import']),\n\tcommonjs: Object.freeze(['types', 'node', 'require']),\n\tbrowser: DISTRIBUTION_BUNDLER_CONDITIONS.module,\n})\n\n/** Describes the compiler options and conditions for one consumer resolution. */\nexport interface DistributionResolution {\n\treadonly label: string\n\treadonly resolution: string\n\treadonly module: string\n\treadonly conditions: Readonly<Record<DistributionFormat, readonly string[]>>\n}\n\n/** Holds the target selected by package condition resolution. */\nexport interface DistributionTargetResult {\n\treadonly target: string\n}\n\n// Each compile driver carries the compiler options its scratch project sets and\n// the conditions TypeScript applies for that resolution and importing format. A\n// `require`-only subpath therefore stays in each CommonJS probe that can resolve it.\n// The option values are the spellings the project file takes, so nothing here needs\n// the compiler's own API to name them.\n/** Lists the compiler resolutions driven against installed declarations. */\nexport const DISTRIBUTION_RESOLUTIONS: readonly DistributionResolution[] = Object.freeze([\n\t{\n\t\tlabel: 'node16',\n\t\tresolution: 'node16',\n\t\tmodule: 'node16',\n\t\tconditions: DISTRIBUTION_DECLARATION_CONDITIONS,\n\t},\n\t{\n\t\tlabel: 'nodenext',\n\t\tresolution: 'nodenext',\n\t\tmodule: 'nodenext',\n\t\tconditions: DISTRIBUTION_DECLARATION_CONDITIONS,\n\t},\n\t{\n\t\tlabel: 'bundler',\n\t\tresolution: 'bundler',\n\t\tmodule: 'esnext',\n\t\tconditions: DISTRIBUTION_BUNDLER_CONDITIONS,\n\t},\n])\n\n// The driver a bundled consumer reads declarations under. A browser application\n// compiles through a bundler, so the browser drive answers under this one alone,\n// and naming it here is what keeps that selection tied to the driver it selects.\n/** Selects the compiler resolution used by a browser consumer. */\nexport const DISTRIBUTION_BROWSER_RESOLUTION = DISTRIBUTION_RESOLUTIONS.find(\n\t(candidate) => candidate.label === 'bundler',\n)\nif (DISTRIBUTION_BROWSER_RESOLUTION === undefined)\n\tthrow new Error(\"DISTRIBUTION_RESOLUTIONS carries no 'bundler' row\")\n\n/** Pairs consumer source extensions with their module formats. */\nexport const DISTRIBUTION_FORMATS: ReadonlyArray<\n\treadonly [extension: string, format: DistributionFormat]\n> = Object.freeze([\n\t['ts', 'module'],\n\t['cts', 'commonjs'],\n])\n\n// One published subpath, resolved to what this proof can drive: the specifier a\n// consumer writes, whether the declarations its consumer formats resolve at all,\n// whether the exports map answers the browser condition with a target of its own,\n// whether it answers `import` and `require` at all, and whether the target that\n// `require` answers with is one that a CommonJS consumer loads.\n/** Describes one published subpath and its runtime and declaration capabilities. */\nexport interface DistributionEntry {\n\treadonly subpath: string\n\treadonly specifier: string\n\treadonly mapping: unknown\n\treadonly declaration: {\n\t\treadonly importable: boolean\n\t\treadonly requirable: boolean\n\t\treadonly browsable: boolean\n\t}\n\treadonly browsable: boolean\n\treadonly importable: boolean\n\treadonly requirable: boolean\n\treadonly loadable: boolean\n}\n\n// The installed tree every claim is read from. Every subpath the exports map names\n// lands in exactly one of `entries`, `undeclared`, and `excluded`, so a subpath this\n// proof cannot drive is reported rather than dropped.\n/** Holds the installed consumer and the partition of its published subpaths. */\nexport interface DistributionStage {\n\treadonly consumer: string\n\treadonly installed: string\n\treadonly archives: readonly string[]\n\treadonly entries: readonly DistributionEntry[]\n\treadonly subpaths: readonly string[]\n\treadonly undeclared: readonly string[]\n\treadonly excluded: readonly string[]\n\treadonly targets: readonly string[]\n}\n\n/**\n * Checks whether a value is a non-null object other than an array.\n *\n * @param value - The value to inspect.\n * @returns True if the value is a record; false otherwise.\n */\nexport function isDistributionRecord(value: unknown): value is Readonly<Record<string, unknown>> {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\n/**\n * Checks whether a value is an array of strings.\n *\n * @param value - The value to inspect.\n * @returns True if every array member is a string; false otherwise.\n */\nexport function isDistributionNames(value: unknown): value is readonly string[] {\n\treturn Array.isArray(value) && value.every((name) => typeof name === 'string')\n}\n\n// A fallback list, which is what Node reads an array in an exports entry as. The\n// narrowing is what the following walkers need: `Array.isArray` widens an `unknown`\n// member to `any`, and an entry read that way is not read at all.\n/**\n * Checks whether a value is a fallback array.\n *\n * @param value - The value to inspect.\n * @returns True if the value is an array; false otherwise.\n */\nexport function isDistributionList(value: unknown): value is readonly unknown[] {\n\treturn Array.isArray(value)\n}\n\n// Whether a string is a valid package target. Node rejects a target outside the\n// package and a target containing a dot, parent, or node_modules segment during\n// package-target resolution. A later module-resolution failure is not the same\n// thing: an array falls through the former and keeps the latter.\n/**\n * Checks whether a relative package target contains only admitted segments.\n *\n * @param target - The package-relative target.\n * @returns True if the target passes package-target validation; false otherwise.\n */\nexport function matchesDistributionPackageTarget(target: string): boolean {\n\tif (!target.startsWith('./')) return false\n\tconst refused = ['.', '..', 'node_modules']\n\treturn target\n\t\t.slice(2)\n\t\t.split(/[\\\\/]/u)\n\t\t.every((segment) => {\n\t\t\ttry {\n\t\t\t\treturn !refused.includes(decodeURIComponent(segment).toLowerCase())\n\t\t\t} catch {\n\t\t\t\treturn !refused.includes(segment.toLowerCase())\n\t\t\t}\n\t\t})\n}\n\n/**\n * Reads and parses a JSON file.\n *\n * @param path - The file to read.\n * @returns The parsed value. Throws when reading or parsing fails.\n */\nexport function readDistributionJSON(path: string): unknown {\n\tconst parsed: unknown = JSON.parse(readFileSync(path, 'utf8'))\n\treturn parsed\n}\n\n/**\n * Reads the package name from a manifest.\n *\n * @param path - The manifest to read.\n * @returns The package name. Throws when the manifest has no string name.\n */\nexport function readDistributionManifestName(path: string): string {\n\tconst manifest = readDistributionJSON(path)\n\tif (!isDistributionRecord(manifest) || typeof manifest.name !== 'string') {\n\t\tthrow new Error(`The manifest at ${path} declares no package name`)\n\t}\n\treturn manifest.name\n}\n\n/**\n * Writes a consumer file after creating its parent directory.\n *\n * @param path - The file to write.\n * @param content - The text to write.\n */\nexport function writeDistributionFile(path: string, content: string): void {\n\tmkdirSync(dirname(path), { recursive: true })\n\twriteFileSync(path, content)\n}\n\n/**\n * Combines the output streams of a completed command.\n *\n * @param result - The completed command.\n * @returns The trimmed diagnostic text.\n */\nexport function readDistributionOutput(result: SpawnSyncReturns<string>): string {\n\treturn `${result.stdout ?? ''}${result.stderr ?? ''}`.trim()\n}\n\n/**\n * Runs npm with a cache inside the owned scratch directory.\n *\n * @param args - The npm arguments.\n * @param cwd - The working directory.\n * @param scratch - The owned scratch root.\n * @returns The command status and captured streams.\n */\nexport function runDistributionNpm(\n\targs: readonly string[],\n\tcwd: string,\n\tscratch: string,\n): SpawnSyncReturns<string> {\n\treturn spawnSync(DISTRIBUTION_NPM, [...args], {\n\t\tcwd,\n\t\tencoding: 'utf8',\n\t\tenv: { ...process.env, npm_config_cache: join(scratch, 'cache') },\n\t\tshell: DISTRIBUTION_SHELL,\n\t\twindowsHide: true,\n\t})\n}\n\n/**\n * Runs a JavaScript entry with the running Node executable.\n *\n * @param args - The Node arguments.\n * @param cwd - The working directory.\n * @returns The command status and captured streams.\n */\nexport function runDistributionNode(\n\targs: readonly string[],\n\tcwd: string,\n): SpawnSyncReturns<string> {\n\treturn spawnSync(process.execPath, [...args], { cwd, encoding: 'utf8', windowsHide: true })\n}\n\n// Node's own condition matching, read in declaration order.\n/**\n * Resolves a package target through conditions and fallback arrays.\n *\n * @param entry - The exports-map entry.\n * @param conditions - The active resolution conditions.\n * @returns The selected target, or undefined when no branch resolves.\n */\nexport function resolveDistributionPackageTarget(\n\tentry: unknown,\n\tconditions: readonly string[],\n): DistributionTargetResult | undefined {\n\tif (typeof entry === 'string') return { target: entry }\n\tif (isDistributionList(entry)) {\n\t\tfor (const member of entry) {\n\t\t\tconst resolved = resolveDistributionPackageTarget(member, conditions)\n\t\t\tif (resolved !== undefined && matchesDistributionPackageTarget(resolved.target))\n\t\t\t\treturn resolved\n\t\t}\n\t\treturn undefined\n\t}\n\tif (!isDistributionRecord(entry)) return undefined\n\tfor (const [condition, nested] of Object.entries(entry)) {\n\t\tif (condition !== 'default' && !conditions.includes(condition)) continue\n\t\tconst resolved = resolveDistributionPackageTarget(nested, conditions)\n\t\tif (resolved !== undefined) return resolved\n\t}\n\treturn undefined\n}\n\n// A flat entry, a condition-nested entry, and a fallback list all resolve through\n// one walker. An entry may declare `types` beside `default` at its top level\n// rather than inside `import`, so a fixed `entry.import.types` lookup is not\n// equivalent to condition resolution.\n/**\n * Resolves the path selected by an exports-map entry.\n *\n * @param entry - The exports-map entry.\n * @param conditions - The active resolution conditions.\n * @returns The selected path, or undefined when no branch resolves.\n */\nexport function resolveDistributionTarget(\n\tentry: unknown,\n\tconditions: readonly string[],\n): string | undefined {\n\treturn resolveDistributionPackageTarget(entry, conditions)?.target\n}\n\n// Whether a path is a physical file. TypeScript's file-existence check refuses a\n// directory at the same spelling and continues to the outer package scope.\n/**\n * Checks whether a path names a physical file.\n *\n * @param path - The filesystem path.\n * @returns True if the path names a file; false otherwise.\n */\nexport function matchesDistributionFile(path: string): boolean {\n\ttry {\n\t\treturn statSync(path).isFile()\n\t} catch {\n\t\treturn false\n\t}\n}\n\n// TypeScript resolves a declaration target by accepting an existing declaration\n// directly or by substituting beside a JavaScript target. A missing target leaves\n// the containing condition or fallback list unresolved, so the walk continues.\n/**\n * Resolves an existing declaration beside a package target.\n *\n * @param target - The package-relative target.\n * @param installed - The installed package root.\n * @returns The declaration target, or undefined when no declaration exists.\n */\nexport function targetToDistributionDeclaration(\n\ttarget: string,\n\tinstalled: string,\n): string | undefined {\n\tif (!matchesDistributionPackageTarget(target)) return undefined\n\tconst declaration = target.endsWith('.cjs')\n\t\t? `${target.slice(0, -4)}.d.cts`\n\t\t: target.endsWith('.mjs')\n\t\t\t? `${target.slice(0, -4)}.d.mts`\n\t\t\t: target.endsWith('.js')\n\t\t\t\t? `${target.slice(0, -3)}.d.ts`\n\t\t\t\t: target\n\tif (declaration === target && !matchesDistributionDeclaration(target)) return undefined\n\treturn matchesDistributionFile(join(installed, declaration)) ? declaration : undefined\n}\n\n// The declaration TypeScript resolves through one importing format's conditions.\n// Condition objects keep manifest order, and arrays keep fallback order.\n/**\n * Resolves an existing declaration through consumer conditions.\n *\n * @param entry - The exports-map entry.\n * @param conditions - The active declaration conditions.\n * @param installed - The installed package root.\n * @returns The declaration target, or undefined when no branch resolves.\n */\nexport function resolveDistributionDeclaration(\n\tentry: unknown,\n\tconditions: readonly string[],\n\tinstalled: string,\n): string | undefined {\n\tif (typeof entry === 'string') return targetToDistributionDeclaration(entry, installed)\n\tif (isDistributionList(entry)) {\n\t\tfor (const member of entry) {\n\t\t\tconst resolved = resolveDistributionDeclaration(member, conditions, installed)\n\t\t\tif (resolved !== undefined) return resolved\n\t\t}\n\t\treturn undefined\n\t}\n\tif (!isDistributionRecord(entry)) return undefined\n\tfor (const [condition, nested] of Object.entries(entry)) {\n\t\tif (condition !== 'default' && !conditions.includes(condition)) continue\n\t\tconst resolved = resolveDistributionDeclaration(nested, conditions, installed)\n\t\tif (resolved !== undefined) return resolved\n\t}\n\treturn undefined\n}\n\n// The nearest package scope that decides a `.d.ts` declaration's module format. A\n// physical nested manifest starts a scope even when it omits `type` or cannot be\n// parsed. A directory at that spelling is not a manifest, so the walk continues.\n/**\n * Reads the nearest package scope for a target inside an installed package.\n *\n * @param installed - The installed package root.\n * @param target - The package-relative target.\n * @returns The manifest type, or undefined when the nearest scope omits it or cannot be read.\n */\nexport function readDistributionPackageType(installed: string, target: string): unknown {\n\t// One `dirname` per path segment reaches the root from any path. The walk ends at the\n\t// installed package, so no scope above it is consulted.\n\tconst start = dirname(join(installed, target))\n\tconst chain = start\n\t\t.split(/[\\\\/]/u)\n\t\t.reduce<string[]>((climbed) => [...climbed, dirname(climbed.at(-1) ?? start)], [start])\n\tconst end = chain.indexOf(installed)\n\tconst scope = chain\n\t\t.slice(0, end === -1 ? chain.length : end + 1)\n\t\t.find((directory) => matchesDistributionFile(join(directory, 'package.json')))\n\tif (scope === undefined) return undefined\n\ttry {\n\t\tconst manifest = readDistributionJSON(join(scope, 'package.json'))\n\t\treturn isDistributionRecord(manifest) ? manifest.type : undefined\n\t} catch {\n\t\treturn undefined\n\t}\n}\n\n/**\n * Checks whether an entry publishes a distinct or conventional browser target.\n *\n * @param entry - The exports-map entry.\n * @returns True if the entry requires a browser drive; false otherwise.\n */\nexport function resolvesDistributionBrowser(entry: unknown): boolean {\n\tconst module = resolveDistributionTarget(entry, DISTRIBUTION_RUNTIME_CONDITIONS.browser)\n\tif (module !== undefined && module.startsWith(DISTRIBUTION_BROWSER_OUTPUT)) return true\n\tif (module === undefined) return false\n\tconst imported = resolveDistributionTarget(entry, DISTRIBUTION_RUNTIME_CONDITIONS.module)\n\tconst required = resolveDistributionTarget(entry, DISTRIBUTION_RUNTIME_CONDITIONS.commonjs)\n\treturn module !== imported && module !== required\n}\n\n// Whether the target selected by Node's CommonJS conditions is a module require can\n// load. A JavaScript target takes its own nearest package scope. Native addons and\n// extensionless targets have their own CommonJS handlers.\n/**\n * Checks whether Node require can load an entry selected by its conditions.\n *\n * @param entry - The exports-map entry.\n * @param installed - The installed package root.\n * @returns True if the target has a CommonJS-compatible format; false otherwise.\n */\nexport function resolvesDistributionCommonJS(entry: unknown, installed: string): boolean {\n\tconst target = resolveDistributionTarget(entry, DISTRIBUTION_RUNTIME_CONDITIONS.commonjs)\n\tif (target === undefined) return false\n\tconst name = target.slice(target.lastIndexOf('/') + 1)\n\tif (name.endsWith('.cjs')) return true\n\tif (name.endsWith('.mjs')) return false\n\tif (name.endsWith('.node')) return true\n\tif (!name.includes('.')) return true\n\treturn name.endsWith('.js') && readDistributionPackageType(installed, target) !== 'module'\n}\n\n// Whether the declaration selected by a typed CommonJS consumer admits that entry.\n// A `.d.cts` declaration admits and a `.d.mts` declaration refuses. A `.d.ts`\n// declaration takes its own nearest package scope.\n/**\n * Checks whether an entry resolves a CommonJS-compatible declaration.\n *\n * @param entry - The exports-map entry.\n * @param installed - The installed package root.\n * @returns True if the selected declaration admits CommonJS consumption; false otherwise.\n */\nexport function declaresDistributionCommonJS(entry: unknown, installed: string): boolean {\n\tconst declaration = resolveDistributionDeclaration(\n\t\tentry,\n\t\tDISTRIBUTION_DECLARATION_CONDITIONS.commonjs,\n\t\tinstalled,\n\t)\n\tif (declaration === undefined) return false\n\tif (declaration.endsWith('.d.cts')) return true\n\tif (declaration.endsWith('.d.mts')) return false\n\treturn (\n\t\tdeclaration.endsWith('.d.ts') &&\n\t\treadDistributionPackageType(installed, declaration) !== 'module'\n\t)\n}\n\n// Every target an entry names under any condition. A fallback list omits members\n// Node rejects during package-target validation, because no reader can take them.\n/**\n * Collects the targets an entry publishes under every condition.\n *\n * @param entry - The exports-map entry.\n * @returns The targets, excluding invalid members of fallback arrays.\n */\nexport function collectDistributionTargets(entry: unknown): readonly string[] {\n\tif (typeof entry === 'string') return [entry]\n\tif (isDistributionList(entry))\n\t\treturn entry.flatMap(collectDistributionTargets).filter(matchesDistributionPackageTarget)\n\tif (!isDistributionRecord(entry)) return []\n\treturn Object.values(entry).flatMap((nested) => collectDistributionTargets(nested))\n}\n\n// Whether a target is a file a runtime loads for its names, which is what a\n// declaration is owed for. The extension on the target's own file name decides it,\n// and a name carrying no extension is code: `require` reads such a file through its\n// JavaScript handler, so an extensionless target loads and publishes names. Node\n// loads `.node` through its native-addon handler. Every other extension is an asset\n// a consumer reads rather than imports — a stylesheet, a WebAssembly binary, the\n// `\"./package.json\"` manifest pointer, and a declaration alike.\n// The cost is an extensionless file published for a reader, such as a `LICENSE`:\n// that target reports undeclared until it is given an extension or a declaration.\n/**\n * Checks whether a target names a runtime module rather than an asset.\n *\n * @param target - The package-relative target.\n * @returns True if the target has a module extension or no extension; false otherwise.\n */\nexport function matchesDistributionModule(target: string): boolean {\n\tconst name = target.slice(target.lastIndexOf('/') + 1)\n\tconst dot = name.lastIndexOf('.')\n\tif (name.endsWith(DISTRIBUTION_ADDON_EXTENSION)) return true\n\treturn dot === -1 || DISTRIBUTION_MODULE_EXTENSIONS.includes(name.slice(dot))\n}\n\n// Whether a resolved target is a declaration rather than the JavaScript a\n// `default` branch answers with when the entry declares no `types` condition.\n/**\n * Checks whether a target names a TypeScript declaration.\n *\n * @param target - The package-relative target.\n * @returns True if the target has a declaration extension; false otherwise.\n */\nexport function matchesDistributionDeclaration(target: string): boolean {\n\treturn DISTRIBUTION_DECLARATION_EXTENSIONS.some((extension) => target.endsWith(extension))\n}\n\n// The declarations the Node module, Node CommonJS, and browser drives compare\n// against. Each field uses the conditions of the TypeScript consumer paired with\n// that runtime. A JavaScript target resolves through TypeScript's adjacent\n// declaration substitution rather than standing in for the declaration itself.\n/**\n * Reads the declarations paired with Node and browser consumers.\n *\n * @param entry - The exports-map entry.\n * @param installed - The installed package root.\n * @returns The declaration selected by each consumer format.\n */\nexport function readDistributionDeclaration(\n\tentry: unknown,\n\tinstalled: string,\n): {\n\treadonly module: string | undefined\n\treadonly commonjs: string | undefined\n\treadonly browser: string | undefined\n} {\n\treturn {\n\t\tmodule: resolveDistributionDeclaration(\n\t\t\tentry,\n\t\t\tDISTRIBUTION_DECLARATION_CONDITIONS.module,\n\t\t\tinstalled,\n\t\t),\n\t\tcommonjs: resolveDistributionDeclaration(\n\t\t\tentry,\n\t\t\tDISTRIBUTION_DECLARATION_CONDITIONS.commonjs,\n\t\t\tinstalled,\n\t\t),\n\t\tbrowser: resolveDistributionDeclaration(\n\t\t\tentry,\n\t\t\tDISTRIBUTION_DECLARATION_CONDITIONS.browser,\n\t\t\tinstalled,\n\t\t),\n\t}\n}\n\n// The entries one compile driver can resolve under its own conditions.\n/**\n * Filters entries to those a consumer can resolve.\n *\n * @param entries - The installed entries.\n * @param conditions - The active consumer conditions.\n * @returns The matching entries in their original order.\n */\nexport function filterDistributionEntries(\n\tentries: readonly DistributionEntry[],\n\tconditions: readonly string[],\n): readonly DistributionEntry[] {\n\treturn entries.filter(\n\t\t(entry) =>\n\t\t\tresolveDistributionTarget(entry.mapping, conditions) !== undefined &&\n\t\t\t(!conditions.includes('require') || entry.loadable),\n\t)\n}\n\n// The compile drivers whose conditions reach one entry under one importing format.\n// A driver that resolves no target for that entry compiles nothing, so a consumer\n// written under it would report a resolution failure this package never made.\n/**\n * Filters compiler resolutions to those that can read an entry.\n *\n * @param entry - The installed entry.\n * @param format - The consumer module format.\n * @returns The matching compiler resolutions.\n */\nexport function filterDistributionResolutions(\n\tentry: DistributionEntry,\n\tformat: DistributionFormat,\n): readonly DistributionResolution[] {\n\treturn DISTRIBUTION_RESOLUTIONS.filter(\n\t\t(driver) => filterDistributionEntries([entry], driver.conditions[format]).length > 0,\n\t)\n}\n\n// Requirable entries that declare CommonJS support but a typed CommonJS consumer\n// cannot compile against. A default branch resolving under the require condition\n// set makes no CommonJS claim.\n/**\n * Filters entries whose require target lacks a compatible declaration.\n *\n * @param entries - The installed entries.\n * @param installed - The installed package root.\n * @returns The entries a CommonJS consumer cannot typecheck.\n */\nexport function filterDistributionUntypable(\n\tentries: readonly DistributionEntry[],\n\tinstalled: string,\n): readonly DistributionEntry[] {\n\treturn entries.filter(\n\t\t(entry) =>\n\t\t\tentry.requirable &&\n\t\t\tisDistributionRecord(entry.mapping) &&\n\t\t\tObject.hasOwn(entry.mapping, 'require') &&\n\t\t\t!declaresDistributionCommonJS(entry.mapping, installed),\n\t)\n}\n\n// One surface comparison, written as the consumer module that proves it: the\n// installed entry that consumer imports, the file extension fixing its importing\n// format, the names a real runtime published off it, and the driver whose scratch\n// project compiles it.\n/** Describes the runtime names and declaration resolution compared for one entry. */\nexport interface DistributionSurface {\n\treadonly entry: DistributionEntry\n\treadonly extension: string\n\treadonly published: readonly string[]\n\treadonly driver: DistributionResolution\n}\n\n// A scratch project over named consumer modules, written beside them so their own\n// resolution reaches the installed package. Nothing is emitted and no ambient types\n// are pulled in, so what the check reads is the installed declarations alone.\n/**\n * Writes a compiler project for a consumer probe.\n *\n * @param stage - The installed consumer.\n * @param name - The project filename suffix.\n * @param driver - The compiler resolution.\n * @param files - The consumer source files.\n * @returns The absolute project path.\n */\nexport function writeDistributionProject(\n\tstage: DistributionStage,\n\tname: string,\n\tdriver: DistributionResolution,\n\tfiles: readonly string[],\n): string {\n\tconst path = join(stage.consumer, `tsconfig.${name}.json`)\n\tconst project = {\n\t\tcompilerOptions: {\n\t\t\tmodule: driver.module,\n\t\t\tmoduleResolution: driver.resolution,\n\t\t\tnoEmit: true,\n\t\t\tskipLibCheck: true,\n\t\t\tstrict: true,\n\t\t\ttarget: 'esnext',\n\t\t\ttypes: [],\n\t\t},\n\t\tfiles: [...files],\n\t}\n\twriteDistributionFile(path, `${JSON.stringify(project, undefined, '\\t')}\\n`)\n\treturn path\n}\n\n// The diagnostics the compiler this workspace installs reports for one scratch\n// project. The compiler runs as a command, so nothing here reaches an API that\n// moves between its majors, and the located lines it prints are the verdict rather\n// than the exit code, which moves between them. A line carrying no location, a line\n// naming the scratch project rather than a consumer module, and anything at all on\n// the error stream are faults of this proof rather than of the package under proof,\n// so each is raised where it happens instead of counted against the package.\n/**\n * Checks a consumer project with the installed TypeScript compiler.\n *\n * @param stage - The installed consumer.\n * @param project - The compiler project path.\n * @returns The located compiler diagnostics. Throws on a tool or project failure.\n */\nexport function checkDistributionProject(\n\tstage: DistributionStage,\n\tproject: string,\n): readonly string[] {\n\tconst result = runDistributionNode(\n\t\t[DISTRIBUTION_COMPILER, '--noEmit', '--pretty', 'false', '-p', project],\n\t\tstage.consumer,\n\t)\n\tconst refused = `${result.stderr ?? ''}`.trim()\n\tif (refused.length > 0) {\n\t\tthrow new Error(`The consumer compiler wrote ${refused} to its error stream`)\n\t}\n\tconst lines = `${result.stdout ?? ''}`.split(/\\r\\n|\\n/u).filter((line) => line.trim().length > 0)\n\t// An elaborated diagnostic prints its detail on indented lines under its own\n\t// first line, so each of those joins the diagnostic it elaborates. The first line\n\t// has no diagnostic above it to join, so it opens one whatever its indentation.\n\tconst heads = lines.flatMap((line, index) => (index === 0 || !/^\\s/u.test(line) ? [index] : []))\n\tconst reported = heads.map((head, position) => {\n\t\tconst line = lines[head] ?? ''\n\t\tconst located = DISTRIBUTION_DIAGNOSTIC_PATTERN.exec(line)?.[1]\n\t\tif (located === undefined) {\n\t\t\tthrow new Error(`The consumer compiler reported ${line}, which names no location`)\n\t\t}\n\t\tif (resolve(stage.consumer, located) === project) {\n\t\t\tthrow new Error(`The scratch project is itself at fault: ${line}`)\n\t\t}\n\t\treturn [\n\t\t\tline,\n\t\t\t...lines.slice(head + 1, heads[position + 1] ?? lines.length).map((detail) => detail.trim()),\n\t\t].join(' ')\n\t})\n\tif (reported.length === 0 && result.status !== 0) {\n\t\tthrow new Error(`The consumer compiler refused the project: ${readDistributionOutput(result)}`)\n\t}\n\treturn reported\n}\n\n// One installed entry's published names checked against its own declarations by\n// the compiler this workspace installs, in the direction each divergence surfaces\n// under. The runtime's key list is written into the consumer as a literal, so the\n// published side comes from a real process and the declared side from the\n// declarations that process's package ships, and the two can disagree. A name the\n// declarations carry and the runtime does not lands on `declared`. A name the\n// runtime carries and the declarations do not, and a name the declarations publish\n// as a type alone, land on `surfaced`: a variable widens into the type\n// `declared` annotates, and only `surfaced` reads the literal's own keys back.\n// Each names the member it is about, so the failure says which export moved.\n/**\n * Checks runtime export names against their installed declarations.\n *\n * @param stage - The installed consumer.\n * @param surface - The publication and declaration pair.\n * @returns The diagnostics labelled by compiler resolution.\n */\nexport function checkDistributionSurface(\n\tstage: DistributionStage,\n\tsurface: DistributionSurface,\n): readonly string[] {\n\tconst slug = surface.entry.subpath.replaceAll(/[^\\w]+/gu, '-')\n\tconst name = `surface.${surface.driver.label}${slug}.${surface.extension}`\n\tconst module = `${name}`\n\tconst keys = surface.published.map((key) => `${JSON.stringify(key)}: true`).join(', ')\n\twriteDistributionFile(\n\t\tjoin(stage.consumer, module),\n\t\t`import * as entry from ${JSON.stringify(surface.entry.specifier)}\nexport const published = {${keys.length === 0 ? '' : ` ${keys} `}} as const\nexport const declared: Record<keyof typeof entry, true> = published\nexport const surfaced: Record<keyof typeof published, true> = declared\n`,\n\t)\n\tconst project = writeDistributionProject(stage, name, surface.driver, [`./${module}`])\n\treturn checkDistributionProject(stage, project).map((line) => `${surface.driver.label}: ${line}`)\n}\n\n// One consumer module importing every installed entry, written where its own\n// resolution finds the installed package.\n/**\n * Writes a consumer importing the requested public specifiers.\n *\n * @param stage - The installed consumer.\n * @param path - The consumer-relative source path.\n * @param specifiers - The public imports to resolve.\n */\nexport function writeDistributionConsumerProbe(\n\tstage: DistributionStage,\n\tpath: string,\n\tspecifiers: readonly string[],\n): void {\n\tconst modules = specifiers.map((specifier, index) => ({\n\t\tbinding: `entry${String(index)}`,\n\t\tspecifier,\n\t}))\n\tconst bindings = modules.map(\n\t\t({ binding, specifier }) => `import * as ${binding} from ${JSON.stringify(specifier)}`,\n\t)\n\tconst names = modules.map(({ binding }) => binding)\n\tconst source = `${bindings.join('\\n')}\\nexport const surface = [${names.join(', ')}]\\n`\n\twriteDistributionFile(join(stage.consumer, path), source)\n}\n\n// The runtime key set a real process reads off one installed entry under one\n// condition. The driver is a file rather than an `--eval` string, so the specifier\n// travels as an argument and nothing needs escaping.\n/**\n * Reads the names a real Node process loads from an installed entry.\n *\n * @param stage - The installed consumer.\n * @param specifier - The public package specifier.\n * @param driver - The consumer driver filename.\n * @returns The exported names. Throws when loading or decoding fails.\n */\nexport function driveDistributionRuntime(\n\tstage: DistributionStage,\n\tspecifier: string,\n\tdriver: string,\n): readonly string[] {\n\tconst result = runDistributionNode([join(stage.consumer, driver), specifier], stage.consumer)\n\tif (result.status !== 0) {\n\t\tthrow new Error(\n\t\t\t`Loading ${specifier} from the consumer failed: ${readDistributionOutput(result)}`,\n\t\t)\n\t}\n\tconst published: unknown = JSON.parse(result.stdout)\n\tif (!isDistributionNames(published))\n\t\tthrow new Error(`The driver printed no name list for ${specifier}`)\n\treturn published\n}\n{{helpers}}\n// Pack this workspace, install the archive into an isolated consumer, and read the\n// published surface back off the installed tree. Every later claim reads this\n// result, so a failure here is raised where it happens rather than once per entry.\n/**\n * Packs the workspace and installs its archive into an isolated consumer.\n *\n * @param scratch - The owned scratch root.\n * @returns The installed consumer and classified exports.\n * @throws Thrown when packing or installation fails.\n */\nexport function buildDistributionStage(scratch: string): DistributionStage {\n\tconst packed = join(scratch, 'packed')\n\tconst consumer = join(scratch, 'consumer')\n\tmkdirSync(packed, { recursive: true })\n\tconst pack = runDistributionNpm(\n\t\t['pack', '--ignore-scripts', '--pack-destination', packed],\n\t\tDISTRIBUTION_ROOT,\n\t\tscratch,\n\t)\n\tif (pack.status !== 0)\n\t\tthrow new Error(`npm pack refused this workspace: ${readDistributionOutput(pack)}`)\n\tconst archives = readdirSync(packed).filter((name) => name.endsWith('.tgz'))\n\tconst archive = archives[0]\n\tif (archives.length !== 1 || archive === undefined) {\n\t\tthrow new Error(`npm pack wrote no single archive: ${archives.join(', ')}`)\n\t}\n\twriteDistributionFile(join(consumer, 'package.json'), DISTRIBUTION_CONSUMER_MANIFEST)\n\twriteDistributionFile(join(consumer, DISTRIBUTION_ESM_DRIVER), DISTRIBUTION_ESM_DRIVER_SOURCE)\n\twriteDistributionFile(join(consumer, DISTRIBUTION_CJS_DRIVER), DISTRIBUTION_CJS_DRIVER_SOURCE)\n\tconst install = runDistributionNpm(\n\t\t['install', '--ignore-scripts', '--no-audit', '--no-fund', join(packed, archive)],\n\t\tconsumer,\n\t\tscratch,\n\t)\n\tif (install.status !== 0) {\n\t\tthrow new Error(`Installing the packed archive failed: ${readDistributionOutput(install)}`)\n\t}\n\tconst name = readDistributionManifestName(join(DISTRIBUTION_ROOT, 'package.json'))\n\tconst installed = join(consumer, 'node_modules', ...name.split('/'))\n\tconst manifest = readDistributionJSON(join(installed, 'package.json'))\n\tif (!isDistributionRecord(manifest) || !isDistributionRecord(manifest.exports)) {\n\t\tthrow new Error('The installed manifest publishes no exports map')\n\t}\n\treturn { consumer, installed, archives, ...classifyDistributionStage(manifest, installed, name) }\n}\n\n// One file's run: the scratch directory and the staged consumer, which is absent when the\n// registry could not be reached.\n/** Binds an owned scratch directory to its optional installed consumer. */\nexport interface DistributionRun {\n\treadonly scratch: string\n\treadonly stage: DistributionStage | undefined\n}\n\n// The run the start hook binds once for this file and the stop hook releases.\n/** Owns the staged consumer shared by one distribution proof. */\nexport class DistributionSuite implements DistributionSuiteInterface {\n\t#run: DistributionRun | undefined\n\n\tget scratch(): string {\n\t\tif (this.#run === undefined) {\n\t\t\tthrow new Error('The distribution setup has not allocated its scratch directory')\n\t\t}\n\t\treturn this.#run.scratch\n\t}\n\n\tread(context: TestContext): DistributionStage {\n\t\tconst stage = this.#run?.stage\n\t\tif (stage === undefined) {\n\t\t\treturn context.skip('`npm ping` did not answer, so nothing was packed or installed')\n\t\t}\n\t\treturn stage\n\t}\n\n\tstart(): void {\n\t\tif (this.#run !== undefined) {\n\t\t\tthrow new Error('The distribution setup has already allocated its scratch directory')\n\t\t}\n\t\tconst scratch = mkdtempSync(join(tmpdir(), 'distribution-'))\n\t\tthis.#run = { scratch, stage: openDistributionStage(scratch) }\n\t}\n\n\tdestroy(): void {\n\t\tif (this.#run !== undefined) {\n\t\t\trmSync(this.#run.scratch, { force: true, recursive: true, maxRetries: 3, retryDelay: 100 })\n\t\t}\n\t\tthis.#run = undefined\n\t}\n}\n\n// Installing the packed archive resolves its own runtime dependencies, so an\n// unreachable registry leaves nothing to measure. Under release that is the gate\n// failing; anywhere else the suite skips and names the mechanism it wanted.\n/**\n * Opens an installed consumer after checking registry readiness.\n *\n * @param scratch - The owned scratch root.\n * @returns The installed consumer, or undefined when an ordinary run cannot reach the registry.\n * @throws Thrown in release mode or when staging fails, after removing scratch.\n */\nexport function openDistributionStage(scratch: string): DistributionStage | undefined {\n\ttry {\n\t\tmkdirSync(join(scratch, 'cache'), { recursive: true })\n\t\tif (runDistributionNpm(DISTRIBUTION_PING, DISTRIBUTION_ROOT, scratch).status !== 0) {\n\t\t\tif (!DISTRIBUTION_RELEASE) return undefined\n\t\t\tthrow new Error(\n\t\t\t\t'The release gate requires a reachable npm registry, and npm ping did not answer',\n\t\t\t)\n\t\t}\n\t\treturn buildDistributionStage(scratch)\n\t} catch (error) {\n\t\trmSync(scratch, {\n\t\t\tforce: true,\n\t\t\trecursive: true,\n\t\t\tmaxRetries: 3,\n\t\t\tretryDelay: 100,\n\t\t})\n\t\tthrow error\n\t}\n}\n\n/**\n * Partitions an installed exports map into driven, undeclared, and excluded subpaths.\n *\n * @param manifest - The installed package manifest.\n * @param installed - The installed package root.\n * @param name - The published package name.\n * @returns The classified entries and complete target population.\n * @throws Thrown when the exports map is absent.\n */\nexport function classifyDistributionStage(\n\tmanifest: Readonly<Record<string, unknown>>,\n\tinstalled: string,\n\tname: string,\n): DistributionClassification {\n\tif (!isDistributionRecord(manifest.exports))\n\t\tthrow new Error('The installed manifest publishes no exports map')\n\tconst readings = Object.entries(manifest.exports).map(([subpath, mapping]) => {\n\t\tconst files = collectDistributionTargets(mapping)\n\t\tconst declaration = readDistributionDeclaration(mapping, installed)\n\t\t// A subpath resolving no declaration is partitioned rather than dropped. It is a\n\t\t// defect when a runtime loads one of its targets for names, because a consumer\n\t\t// importing it compiles against nothing under `node16`. It is an excluded\n\t\t// publication otherwise: the `\"./package.json\"` manifest pointer and a stylesheet\n\t\t// are published for a reader rather than an importer.\n\t\tif (\n\t\t\tdeclaration.module === undefined &&\n\t\t\tdeclaration.commonjs === undefined &&\n\t\t\tdeclaration.browser === undefined\n\t\t) {\n\t\t\treturn { subpath, files, entry: undefined }\n\t\t}\n\t\tconst importTarget = resolveDistributionTarget(mapping, DISTRIBUTION_RUNTIME_CONDITIONS.module)\n\t\tconst requireTarget = resolveDistributionTarget(\n\t\t\tmapping,\n\t\t\tDISTRIBUTION_RUNTIME_CONDITIONS.commonjs,\n\t\t)\n\t\tconst browserTarget = resolveDistributionTarget(\n\t\t\tmapping,\n\t\t\tDISTRIBUTION_RUNTIME_CONDITIONS.browser,\n\t\t)\n\t\tconst browsable = resolvesDistributionBrowser(mapping)\n\t\tconst shadowed = browsable && requireTarget === browserTarget\n\t\tconst requirable = requireTarget !== undefined && !shadowed\n\t\tconst loadable = requirable && resolvesDistributionCommonJS(mapping, installed)\n\t\tconst entry: DistributionEntry = {\n\t\t\tsubpath,\n\t\t\tspecifier: subpath === '.' ? name : `${name}${subpath.slice(1)}`,\n\t\t\tmapping,\n\t\t\tdeclaration: {\n\t\t\t\timportable: declaration.module !== undefined,\n\t\t\t\trequirable: declaration.commonjs !== undefined,\n\t\t\t\tbrowsable: declaration.browser !== undefined,\n\t\t\t},\n\t\t\tbrowsable,\n\t\t\timportable: importTarget !== undefined && !(browsable && importTarget === browserTarget),\n\t\t\trequirable,\n\t\t\tloadable,\n\t\t}\n\t\treturn { subpath, files, entry }\n\t})\n\tconst entries = readings.flatMap(({ entry }) => (entry === undefined ? [] : [entry]))\n\tconst targets = readings.flatMap(({ files }) => files)\n\tconst subpaths = readings.map(({ subpath }) => subpath)\n\tconst undeclared = readings\n\t\t.filter(({ entry, files }) => entry === undefined && files.some(matchesDistributionModule))\n\t\t.map(({ subpath }) => subpath)\n\tconst excluded = readings\n\t\t.filter(({ entry, files }) => entry === undefined && !files.some(matchesDistributionModule))\n\t\t.map(({ subpath }) => subpath)\n\treturn { entries, subpaths, undeclared, excluded, targets }\n}\n\n/**\n * Creates the lifecycle boundary used by generated distribution proofs.\n * @returns The suite interface backed by an owned run.\n */\nexport function createDistributionSuite(): DistributionSuiteInterface {\n\treturn new DistributionSuite()\n}\n\n/**\n * Collects physical files beneath an installed output directory.\n * @param directory - The output directory to walk.\n * @returns The installed files, or an empty list when the directory is absent.\n */\nexport function collectDistributionFiles(directory: string): readonly string[] {\n\tif (!existsSync(directory)) return []\n\treturn readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {\n\t\tconst path = join(directory, entry.name)\n\t\treturn entry.isDirectory() ? collectDistributionFiles(path) : entry.isFile() ? [path] : []\n\t})\n}\n\n/**\n * Reads the source environment owning an installed output path.\n * @param installed - The installed package root.\n * @param path - The output file.\n * @returns The source environment, or undefined outside a JavaScript face.\n */\nexport function readDistributionFace(installed: string, path: string): string | undefined {\n\tconst [output, axis, face] = relativePath(installed, path).split(sep)\n\treturn output === 'dist'\n\t\t? axis === 'src'\n\t\t\t? face\n\t\t\t: axis === 'bin'\n\t\t\t\t? 'bin'\n\t\t\t\t: undefined\n\t\t: undefined\n}\n\n/**\n * Scans installed JavaScript maps for sources copied from another environment.\n * @param installed - The installed package root.\n * @returns The copied sources and unreadable maps.\n * @throws Thrown when a code-bearing output has no readable map of its own.\n */\nexport function scanDistributionSourceMaps(installed: string): readonly string[] {\n\tconst files = collectDistributionFiles(join(installed, 'dist')).filter(\n\t\t(path) => readDistributionFace(installed, path) !== undefined,\n\t)\n\tconst outputs = files\n\t\t.filter((path) => /\\.(?:js|cjs|mjs)$/u.test(path))\n\t\t.map((path) => {\n\t\t\tconst parsed = parseSync(path, readFileSync(path, 'utf8'))\n\t\t\tconst code = parsed.program.body.some(\n\t\t\t\t(statement) =>\n\t\t\t\t\tstatement.type !== 'EmptyStatement' &&\n\t\t\t\t\t!(\n\t\t\t\t\t\tstatement.type === 'ExportNamedDeclaration' &&\n\t\t\t\t\t\tstatement.declaration === null &&\n\t\t\t\t\t\tstatement.specifiers.length === 0 &&\n\t\t\t\t\t\tstatement.source === null\n\t\t\t\t\t),\n\t\t\t)\n\t\t\tconst reference = parsed.comments\n\t\t\t\t.flatMap((comment) => {\n\t\t\t\t\tconst match = /^[@#]\\s*sourceMappingURL=(\\S+)\\s*$/u.exec(comment.value)\n\t\t\t\t\treturn match?.[1] === undefined ? [] : [match[1]]\n\t\t\t\t})\n\t\t\t\t.at(-1)\n\t\t\ttry {\n\t\t\t\tconst inline = reference?.startsWith('data:') === true\n\t\t\t\tconst target = inline\n\t\t\t\t\t? path\n\t\t\t\t\t: reference === undefined\n\t\t\t\t\t\t? `${path}.map`\n\t\t\t\t\t\t: fileURLToPath(new URL(reference.replaceAll('\\\\', '/'), pathToFileURL(path)))\n\t\t\t\treturn {\n\t\t\t\t\tpath: target,\n\t\t\t\t\tface: readDistributionFace(installed, path),\n\t\t\t\t\tcode,\n\t\t\t\t\treference: inline ? reference : undefined,\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\tthrow new Error(`Unreadable source maps for ${path}`)\n\t\t\t}\n\t\t})\n\tconst maps = [\n\t\t...outputs.filter(\n\t\t\t({ path, code, reference }) => code || reference !== undefined || existsSync(path),\n\t\t),\n\t\t...files\n\t\t\t.filter(\n\t\t\t\t(path) =>\n\t\t\t\t\t/\\.(?:js|cjs|mjs)\\.map$/u.test(path) && !outputs.some((output) => output.path === path),\n\t\t\t)\n\t\t\t.map((path) => ({\n\t\t\t\tpath,\n\t\t\t\tface: readDistributionFace(installed, path),\n\t\t\t\tcode: false,\n\t\t\t\treference: undefined,\n\t\t\t})),\n\t]\n\tif (maps.length === 0)\n\t\tconsole.info('No built JavaScript face holds code, so no source map is required')\n\treturn maps.flatMap(({ path, face, code, reference }) => {\n\t\tconst label = relativePath(installed, path).split(sep).join('/')\n\t\ttry {\n\t\t\tconst payload =\n\t\t\t\treference === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: /^data:application\\/json(?:;charset=[^;,]+)?(;base64)?,(.*)$/iu.exec(reference)\n\t\t\tconst map: unknown =\n\t\t\t\treference === undefined\n\t\t\t\t\t? readDistributionJSON(path)\n\t\t\t\t\t: payload?.[2] === undefined\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: JSON.parse(\n\t\t\t\t\t\t\t\tpayload[1] === undefined\n\t\t\t\t\t\t\t\t\t? decodeURIComponent(payload[2])\n\t\t\t\t\t\t\t\t\t: Buffer.from(payload[2], 'base64').toString('utf8'),\n\t\t\t\t\t\t\t)\n\t\t\tif (\n\t\t\t\t!isDistributionRecord(map) ||\n\t\t\t\t!isDistributionNames(map.sources) ||\n\t\t\t\t(map.sourceRoot !== undefined && typeof map.sourceRoot !== 'string')\n\t\t\t) {\n\t\t\t\tthrow new Error('Unreadable source map')\n\t\t\t}\n\t\t\tconst root = typeof map.sourceRoot === 'string' ? map.sourceRoot : ''\n\t\t\tconst directory = root.startsWith('file:')\n\t\t\t\t? fileURLToPath(new URL(root))\n\t\t\t\t: resolve(dirname(path), root.replaceAll('\\\\', '/'))\n\t\t\tconst sources = map.sources.map((source) =>\n\t\t\t\trelativePath(\n\t\t\t\t\tresolve(installed),\n\t\t\t\t\tsource.startsWith('file:')\n\t\t\t\t\t\t? fileURLToPath(new URL(source))\n\t\t\t\t\t\t: resolve(directory, source.replaceAll('\\\\', '/')),\n\t\t\t\t)\n\t\t\t\t\t.split(sep)\n\t\t\t\t\t.join('/'),\n\t\t\t)\n\t\t\tconst copied = sources.filter(\n\t\t\t\t(source) => source.startsWith('src/') && !source.startsWith(`src/${face}/`),\n\t\t\t)\n\t\t\treturn [\n\t\t\t\t...copied.map((source) => `${label}: ${source}`),\n\t\t\t\t...(sources.some((source) => source.startsWith(`src/${face}/`))\n\t\t\t\t\t? []\n\t\t\t\t\t: [`${label}: unreadable source map (no src/${face}/ source)`]),\n\t\t\t]\n\t\t} catch {\n\t\t\tif (code) throw new Error(`Unreadable source maps for ${path}`)\n\t\t\treturn [`${label}: unreadable source map`]\n\t\t}\n\t})\n}\n\n/**\n * Reads top-level names declared by a roll-up, including unexported declarations.\n * @param path - The installed declaration file.\n * @returns The declared names. Refuses syntax errors and unreadable binding patterns.\n */\nexport function readDistributionNames(path: string): readonly string[] {\n\tconst source = parseSync(path, readFileSync(path, 'utf8'))\n\tif (source.errors.length > 0) throw new Error(`Unreadable declarations at ${path}`)\n\treturn source.program.body.flatMap((statement) => {\n\t\tconst declaration =\n\t\t\tstatement.type === 'ExportNamedDeclaration' || statement.type === 'ExportDefaultDeclaration'\n\t\t\t\t? statement.declaration\n\t\t\t\t: statement\n\t\tif (declaration === null) return []\n\t\tif (declaration.type === 'VariableDeclaration') {\n\t\t\treturn declaration.declarations.map((binding) => {\n\t\t\t\tif (binding.id.type !== 'Identifier')\n\t\t\t\t\tthrow new Error(`Unreadable declaration binding at ${path}`)\n\t\t\t\treturn binding.id.name\n\t\t\t})\n\t\t}\n\t\tif (\n\t\t\tdeclaration.type === 'ClassDeclaration' ||\n\t\t\tdeclaration.type === 'FunctionDeclaration' ||\n\t\t\tdeclaration.type === 'TSDeclareFunction' ||\n\t\t\tdeclaration.type === 'TSInterfaceDeclaration' ||\n\t\t\tdeclaration.type === 'TSTypeAliasDeclaration' ||\n\t\t\tdeclaration.type === 'TSEnumDeclaration' ||\n\t\t\tdeclaration.type === 'TSModuleDeclaration'\n\t\t) {\n\t\t\treturn declaration.id?.type === 'Identifier' ? [declaration.id.name] : []\n\t\t}\n\t\treturn []\n\t})\n}\n\n/**\n * Checks whether a source entry exports names, following local star exports.\n * @param path - The source entry to inspect.\n * @param ancestors - The entries already visited on this export path.\n * @returns True if the entry exports a name; false otherwise.\n */\nexport function matchesDistributionSourceExports(\n\tpath: string,\n\tancestors: readonly string[] = [],\n): boolean {\n\tif (ancestors.includes(path)) return false\n\tconst source = parseSync(path, readFileSync(path, 'utf8'))\n\tif (source.errors.length > 0) throw new Error(`Unreadable source exports at ${path}`)\n\treturn source.program.body.some((statement) => {\n\t\tif (statement.type === 'ExportDefaultDeclaration') return ancestors.length === 0\n\t\tif (statement.type === 'ExportNamedDeclaration')\n\t\t\treturn (\n\t\t\t\tstatement.declaration !== null ||\n\t\t\t\tstatement.specifiers.some((specifier) => {\n\t\t\t\t\tconst name =\n\t\t\t\t\t\tspecifier.exported.type === 'Identifier'\n\t\t\t\t\t\t\t? specifier.exported.name\n\t\t\t\t\t\t\t: specifier.exported.value\n\t\t\t\t\treturn ancestors.length === 0 || name !== 'default'\n\t\t\t\t})\n\t\t\t)\n\t\tif (statement.type !== 'ExportAllDeclaration') return false\n\t\tif (statement.exported !== null || !statement.source.value.startsWith('.')) return true\n\t\tconst target = resolve(dirname(path), statement.source.value.replace(/\\.js$/u, '.ts'))\n\t\treturn matchesDistributionSourceExports(target, [...ancestors, path])\n\t})\n}\n\n/**\n * Scans installed declaration faces for names declared by multiple environments.\n * @param installed - The installed package root.\n * @param source - The workspace holding the source entries being published.\n * @returns The repeated names with their declaring faces.\n * @throws Thrown when a source entry exports names but its roll-up declares none.\n */\nexport function scanDistributionDeclarations(\n\tinstalled: string,\n\tsource: string = DISTRIBUTION_ROOT,\n): readonly string[] {\n\tconst declarations = collectDistributionFiles(join(installed, 'dist'))\n\t\t.filter(matchesDistributionDeclaration)\n\t\t.map((path) => ({\n\t\t\tpath,\n\t\t\tface: readDistributionFace(installed, path),\n\t\t\tnames: readDistributionNames(path),\n\t\t}))\n\tconst entries = collectDistributionFiles(join(source, 'src')).filter((path) => {\n\t\tconst parts = relativePath(source, path).split(sep)\n\t\treturn parts.length === 3 && parts[2] === 'index.ts'\n\t})\n\tconst published = entries.filter((path) => matchesDistributionSourceExports(path))\n\tfor (const path of published) {\n\t\tconst face = relativePath(source, path).split(sep)[1]\n\t\tif (!declarations.some((entry) => entry.face === face && entry.names.length > 0))\n\t\t\tthrow new Error(\n\t\t\t\t`The ${face} source entry exports names but its declaration roll-up declares none`,\n\t\t\t)\n\t}\n\tif (published.length === 0)\n\t\tconsole.info('No source entry exports names, so no declaration names are required')\n\tconst names = [...new Set(declarations.flatMap((entry) => entry.names))].sort()\n\treturn names.flatMap((name) => {\n\t\tconst faces = [\n\t\t\t...new Set(\n\t\t\t\tdeclarations\n\t\t\t\t\t.filter((entry) => entry.names.includes(name))\n\t\t\t\t\t.map((entry) => entry.face)\n\t\t\t\t\t.filter((face) => face !== undefined),\n\t\t\t),\n\t\t].sort()\n\t\treturn faces.length > 1 ? [`${name}: ${faces.join(', ')}`] : []\n\t})\n}\n\n/**\n * Checks the installed manifest against npm's normalization in an owned scratch copy.\n * @param installed - The installed package root, read only.\n * @param scratch - The suite's owned scratch root and npm cache parent.\n * @returns The top-level keys changed by npm. Refuses an unsuccessful npm command.\n */\nexport function checkDistributionManifest(installed: string, scratch: string): readonly string[] {\n\tconst directory = mkdtempSync(join(scratch, 'manifest-'))\n\ttry {\n\t\tconst path = join(directory, 'package.json')\n\t\twriteFileSync(path, readFileSync(join(installed, 'package.json')))\n\t\tconst before = readDistributionJSON(path)\n\t\tconst result = runDistributionNpm(['pkg', 'fix'], directory, scratch)\n\t\tif (result.status !== 0)\n\t\t\tthrow new Error(`npm pkg fix failed: ${readDistributionOutput(result)}`)\n\t\tconst after = readDistributionJSON(path)\n\t\tif (!isDistributionRecord(before) || !isDistributionRecord(after))\n\t\t\tthrow new Error('Unreadable manifest')\n\t\treturn [...new Set([...Object.keys(before), ...Object.keys(after)])]\n\t\t\t.filter((key) => !isDeepStrictEqual(before[key], after[key]))\n\t\t\t.sort()\n\t} finally {\n\t\trmSync(directory, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 })\n\t}\n}\n\n/**\n * Builds independently registered observations over the suite's installed consumer.\n * @param suite - The lifecycle shared by the proof's hooks and observations.\n * @returns The case rows whose observations each require one assertion.\n */\nexport function buildDistributionCases(\n\tsuite: DistributionSuiteInterface,\n): readonly DistributionCase[] {\n\treturn [\n\t\t{\n\t\t\tlabel: 'classifies synthetic export mappings without a registry stage',\n\t\t\tobserve: () => {\n\t\t\t\tconst root = join(suite.scratch, 'classifiers')\n\t\t\t\twriteDistributionFile(\n\t\t\t\t\tjoin(root, 'package.json'),\n\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\ttype: 'commonjs',\n\t\t\t\t\t\texports: {\n\t\t\t\t\t\t\tcondition: { browser: './b.js', default: './n.js' },\n\t\t\t\t\t\t\tconvention: { default: './dist/src/browser/index.js' },\n\t\t\t\t\t\t\tuniversal: { default: './shared.js' },\n\t\t\t\t\t\t\t'import-shared': {\n\t\t\t\t\t\t\t\tbrowser: './shared.mjs',\n\t\t\t\t\t\t\t\timport: './shared.mjs',\n\t\t\t\t\t\t\t\tdefault: './node.js',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t'require-shared': {\n\t\t\t\t\t\t\t\tbrowser: './shared.cjs',\n\t\t\t\t\t\t\t\trequire: './shared.cjs',\n\t\t\t\t\t\t\t\tdefault: './node.js',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tnode: { node: './node.js', default: './node.js' },\n\t\t\t\t\t\t\tsilent: { 'module-sync': './x.cjs', import: './x.mjs' },\n\t\t\t\t\t\t\tmodule: { require: './x.mjs' },\n\t\t\t\t\t\t\t'nested-module': { require: './module/x.js' },\n\t\t\t\t\t\t\t'nested-commonjs': { require: './commonjs/x.js' },\n\t\t\t\t\t\t\tesm: { import: './x.mjs' },\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\twriteDistributionFile(join(root, 'module/package.json'), '{ \"type\": \"module\" }\\n')\n\t\t\t\twriteDistributionFile(join(root, 'commonjs/package.json'), '{ \"type\": \"commonjs\" }\\n')\n\t\t\t\tconst manifest = readDistributionJSON(join(root, 'package.json'))\n\t\t\t\tif (!isDistributionRecord(manifest) || !isDistributionRecord(manifest.exports)) {\n\t\t\t\t\tthrow new Error('The classifier fixture declares no exports map')\n\t\t\t\t}\n\t\t\t\tconst mappings = manifest.exports\n\n\t\t\t\treturn {\n\t\t\t\t\tactual: {\n\t\t\t\t\t\tbrowser: {\n\t\t\t\t\t\t\tcondition: resolvesDistributionBrowser(mappings.condition),\n\t\t\t\t\t\t\tconvention: resolvesDistributionBrowser(mappings.convention),\n\t\t\t\t\t\t\tuniversal: resolvesDistributionBrowser(mappings.universal),\n\t\t\t\t\t\t\timport: resolvesDistributionBrowser(mappings['import-shared']),\n\t\t\t\t\t\t\trequire: resolvesDistributionBrowser(mappings['require-shared']),\n\t\t\t\t\t\t\tnode: resolvesDistributionBrowser(mappings.node),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcommonjs: {\n\t\t\t\t\t\t\tsilent: resolvesDistributionCommonJS(mappings.silent, root),\n\t\t\t\t\t\t\tmodule: resolvesDistributionCommonJS(mappings.module, root),\n\t\t\t\t\t\t\tnestedModule: resolvesDistributionCommonJS(mappings['nested-module'], root),\n\t\t\t\t\t\t\tnestedCommonJS: resolvesDistributionCommonJS(mappings['nested-commonjs'], root),\n\t\t\t\t\t\t\tesm: resolvesDistributionCommonJS(mappings.esm, root),\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\texpected: {\n\t\t\t\t\t\tbrowser: {\n\t\t\t\t\t\t\tcondition: true,\n\t\t\t\t\t\t\tconvention: true,\n\t\t\t\t\t\t\tuniversal: false,\n\t\t\t\t\t\t\timport: false,\n\t\t\t\t\t\t\trequire: false,\n\t\t\t\t\t\t\tnode: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcommonjs: {\n\t\t\t\t\t\t\tsilent: true,\n\t\t\t\t\t\t\tmodule: false,\n\t\t\t\t\t\t\tnestedModule: false,\n\t\t\t\t\t\t\tnestedCommonJS: true,\n\t\t\t\t\t\t\tesm: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tlabel: 'keeps installed JavaScript sources in their own environment [requires the registry]',\n\t\t\tobserve: (context) => {\n\t\t\t\tconst stage = suite.read(context)\n\t\t\t\treturn { actual: scanDistributionSourceMaps(stage.installed), expected: [] }\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tlabel: 'declares each installed name in one environment [requires the registry]',\n\t\t\tobserve: (context) => {\n\t\t\t\tconst stage = suite.read(context)\n\t\t\t\tconst faces = new Set(\n\t\t\t\t\tcollectDistributionFiles(join(stage.installed, 'dist'))\n\t\t\t\t\t\t.filter(matchesDistributionDeclaration)\n\t\t\t\t\t\t.map((path) => readDistributionFace(stage.installed, path))\n\t\t\t\t\t\t.filter((face) => face !== undefined),\n\t\t\t\t)\n\t\t\t\tconst findings = scanDistributionDeclarations(stage.installed)\n\t\t\t\tif (faces.size <= 1)\n\t\t\t\t\tconsole.info(\n\t\t\t\t\t\t'Fewer than two declaration faces are installed, so no cross-face copy exists',\n\t\t\t\t\t)\n\t\t\t\treturn { actual: findings, expected: [] }\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tlabel: 'keeps the installed manifest fixed under npm pkg fix [requires the registry]',\n\t\t\tobserve: (context) => ({\n\t\t\t\tactual: checkDistributionManifest(suite.read(context).installed, suite.scratch),\n\t\t\t\texpected: [],\n\t\t\t}),\n\t\t},\n\t\t{\n\t\t\tlabel: 'packs one archive and installs it in isolation [requires the registry]',\n\t\t\tobserve: (context) => {\n\t\t\t\tconst stage = suite.read(context)\n\t\t\t\treturn {\n\t\t\t\t\tactual: {\n\t\t\t\t\t\tarchives: stage.archives.length,\n\t\t\t\t\t\tinstalled: existsSync(join(stage.installed, 'package.json')),\n\t\t\t\t\t\tentries: stage.entries.length > 0,\n\t\t\t\t\t},\n\t\t\t\t\texpected: { archives: 1, installed: true, entries: true },\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tlabel: 'ships every relative target its exports map names [requires the registry]',\n\t\t\tobserve: (context) => {\n\t\t\t\tconst stage = suite.read(context)\n\t\t\t\tconst relative = stage.targets.filter((target) => target.startsWith('./'))\n\t\t\t\treturn {\n\t\t\t\t\tactual: {\n\t\t\t\t\t\tpopulated: relative.length > 0,\n\t\t\t\t\t\tmissing: relative.filter((target) => !existsSync(join(stage.installed, target))),\n\t\t\t\t\t},\n\t\t\t\t\texpected: { populated: true, missing: [] },\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tlabel: 'declares types for every module it publishes [requires the registry]',\n\t\t\tobserve: (context) => {\n\t\t\t\tconst stage = suite.read(context)\n\t\t\t\tconst partitioned = [\n\t\t\t\t\t...stage.entries.map((entry) => entry.subpath),\n\t\t\t\t\t...stage.undeclared,\n\t\t\t\t\t...stage.excluded,\n\t\t\t\t]\n\t\t\t\treturn {\n\t\t\t\t\tactual: {\n\t\t\t\t\t\tundeclared: stage.undeclared,\n\t\t\t\t\t\tpartitioned: partitioned.sort(),\n\t\t\t\t\t\tunreachable: stage.entries\n\t\t\t\t\t\t\t.filter((entry) => !entry.importable && !entry.requirable && !entry.browsable)\n\t\t\t\t\t\t\t.map((entry) => entry.subpath),\n\t\t\t\t\t\tuntypable: filterDistributionUntypable(stage.entries, stage.installed).map(\n\t\t\t\t\t\t\t(entry) => entry.subpath,\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texpected: {\n\t\t\t\t\t\tundeclared: [],\n\t\t\t\t\t\tpartitioned: [...stage.subpaths].sort(),\n\t\t\t\t\t\tunreachable: [],\n\t\t\t\t\t\tuntypable: [],\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tlabel: 'refuses a subpath its exports map does not name [requires the registry]',\n\t\t\tobserve: (context) => {\n\t\t\t\tconst stage = suite.read(context)\n\t\t\t\tconst name = readDistributionManifestName(join(stage.installed, 'package.json'))\n\t\t\t\tconst result = runDistributionNode(\n\t\t\t\t\t[join(stage.consumer, DISTRIBUTION_ESM_DRIVER), `${name}${DISTRIBUTION_ABSENT_SUBPATH}`],\n\t\t\t\t\tstage.consumer,\n\t\t\t\t)\n\t\t\t\treturn {\n\t\t\t\t\tactual: {\n\t\t\t\t\t\trefused: result.status !== 0,\n\t\t\t\t\t\tcoded: readDistributionOutput(result).includes('ERR_PACKAGE_PATH_NOT_EXPORTED'),\n\t\t\t\t\t},\n\t\t\t\t\texpected: { refused: true, coded: true },\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tlabel: 'compiles a consumer under every module resolution [requires the registry]',\n\t\t\tobserve: (context) => {\n\t\t\t\tconst stage = suite.read(context)\n\t\t\t\tconst name = readDistributionManifestName(join(stage.installed, 'package.json'))\n\t\t\t\tconst readings = DISTRIBUTION_RESOLUTIONS.flatMap((driver) =>\n\t\t\t\t\tDISTRIBUTION_FORMATS.flatMap(([extension, format]) => {\n\t\t\t\t\t\tconst written = filterDistributionEntries(stage.entries, driver.conditions[format])\n\t\t\t\t\t\tif (written.length === 0) return []\n\t\t\t\t\t\tconst label = `${driver.label}.${extension}`\n\t\t\t\t\t\tconst probe = `probe.${label}`\n\t\t\t\t\t\tconst specifiers = written.map((entry) => entry.specifier)\n\t\t\t\t\t\twriteDistributionConsumerProbe(stage, probe, specifiers)\n\t\t\t\t\t\tconst project = writeDistributionProject(stage, probe, driver, [`./${probe}`])\n\t\t\t\t\t\tconst messages = checkDistributionProject(stage, project).map(\n\t\t\t\t\t\t\t(message) => `${label}: ${message}`,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tconst control = `control.${label}`\n\t\t\t\t\t\twriteDistributionConsumerProbe(stage, control, [\n\t\t\t\t\t\t\t`${name}${DISTRIBUTION_ABSENT_SUBPATH}`,\n\t\t\t\t\t\t])\n\t\t\t\t\t\tconst refused = writeDistributionProject(stage, control, driver, [`./${control}`])\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmessages,\n\t\t\t\t\t\t\t\tsilent: checkDistributionProject(stage, refused).length === 0 ? [label] : [],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t]\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\treturn {\n\t\t\t\t\tactual: {\n\t\t\t\t\t\tmessages: readings.flatMap(({ messages }) => messages),\n\t\t\t\t\t\tsilent: readings.flatMap(({ silent }) => silent),\n\t\t\t\t\t},\n\t\t\t\t\texpected: { messages: [], silent: [] },\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tlabel: 'publishes what it declares to a Node import, and no more',\n\t\t\tobserve: (context) => {\n\t\t\t\tconst stage = suite.read(context)\n\t\t\t\tconst entries = stage.entries.filter((entry) => entry.importable)\n\t\t\t\tif (entries.length === 0) return context.skip('No installed entry supports Node import')\n\t\t\t\tconst readings = entries.map((entry) => {\n\t\t\t\t\tif (!entry.declaration.importable)\n\t\t\t\t\t\tthrow new Error(`${entry.subpath} publishes no import declaration`)\n\t\t\t\t\tconst published = driveDistributionRuntime(\n\t\t\t\t\t\tstage,\n\t\t\t\t\t\tentry.specifier,\n\t\t\t\t\t\tDISTRIBUTION_ESM_DRIVER,\n\t\t\t\t\t)\n\t\t\t\t\tconst drivers = filterDistributionResolutions(entry, 'module')\n\t\t\t\t\treturn {\n\t\t\t\t\t\tentry: entry.subpath,\n\t\t\t\t\t\tdriven: drivers.length > 0,\n\t\t\t\t\t\treported: drivers.flatMap((driver) =>\n\t\t\t\t\t\t\tcheckDistributionSurface(stage, { entry, extension: 'ts', published, driver }),\n\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\treturn {\n\t\t\t\t\tactual: readings,\n\t\t\t\t\texpected: entries.map((entry) => ({ entry: entry.subpath, driven: true, reported: [] })),\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tlabel: 'publishes what it declares to a Node require, and no more',\n\t\t\tobserve: (context) => {\n\t\t\t\tconst stage = suite.read(context)\n\t\t\t\tconst entries = stage.entries.filter((entry) => entry.requirable)\n\t\t\t\tif (entries.length === 0) return context.skip('No installed entry supports Node require')\n\t\t\t\tconst readings = entries.map((entry) => {\n\t\t\t\t\tif (!entry.declaration.requirable)\n\t\t\t\t\t\tthrow new Error(`${entry.subpath} publishes no require declaration`)\n\t\t\t\t\tconst published = driveDistributionRuntime(\n\t\t\t\t\t\tstage,\n\t\t\t\t\t\tentry.specifier,\n\t\t\t\t\t\tDISTRIBUTION_CJS_DRIVER,\n\t\t\t\t\t)\n\t\t\t\t\tconst drivers = filterDistributionResolutions(entry, 'commonjs')\n\t\t\t\t\treturn {\n\t\t\t\t\t\tentry: entry.subpath,\n\t\t\t\t\t\tdriven: drivers.length > 0,\n\t\t\t\t\t\treported: drivers.flatMap((driver) =>\n\t\t\t\t\t\t\tcheckDistributionSurface(stage, { entry, extension: 'cts', published, driver }),\n\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\treturn {\n\t\t\t\t\tactual: readings,\n\t\t\t\t\texpected: entries.map((entry) => ({ entry: entry.subpath, driven: true, reported: [] })),\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t]\n}\n";
|
|
136
|
+
proof: "import {\n\t// These exports remain available to proofs emitted by earlier scaffold releases.\n\tbuildDistributionCases,\n\t{{import}}createDistributionSuite,\n} from './setupDistribution.js'\nimport { afterAll, beforeAll, describe, expect, it } from 'vitest'\n\nconst DISTRIBUTION_SUITE = createDistributionSuite()\n\nbeforeAll(() => DISTRIBUTION_SUITE.start())\n\nafterAll(() => DISTRIBUTION_SUITE.destroy())\n\ndescribe('installed package consumer', () => {\n\tfor (const row of buildDistributionCases(DISTRIBUTION_SUITE)) {\n\t\tit(`${row.label}`, async (context) => {\n\t\t\tconst observation = await row.observe(context)\n\t\t\texpect(observation.actual).toStrictEqual(observation.expected)\n\t\t})\n\t}\n{{guard}}{{drive}}})\n";
|
|
136
137
|
transport: "import { createServer } from 'node:http'\n";
|
|
137
138
|
types: "import type { PlaywrightProviderOptions } from '@vitest/browser-playwright'\nimport type { Browser } from 'playwright'\n";
|
|
138
139
|
launcher: "import { chromium } from 'playwright'\nimport { build } from 'vite'\nimport { resolveBrowser, resolvePinnedBrowser } from '../configs/browsers.js'\n";
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
import: "checkDistributionBrowser,\n\t";
|
|
141
|
+
helpers: "/** Defines the page that loads a bundled browser consumer. */\nexport const DISTRIBUTION_BROWSER_PAGE = `<!doctype html>\n<html lang=\"en\">\n\t<head>\n\t\t<meta charset=\"UTF-8\" />\n\t\t<title>Distribution</title>\n\t</head>\n\t<body>\n\t\t<script type=\"module\" src=\"./main.js\"></script>\n\t</body>\n</html>\n`\n\n/**\n * Infers the response media type from a bundle filename.\n *\n * @param path - The requested bundle path.\n * @returns The media type, defaulting to application/octet-stream.\n */\nexport function inferDistributionContentType(path: string): string {\n\tif (path.endsWith('.html')) return 'text/html'\n\tif (path.endsWith('.js')) return 'text/javascript'\n\tif (path.endsWith('.css')) return 'text/css'\n\tif (path.endsWith('.json') || path.endsWith('.map')) return 'application/json'\n\treturn 'application/octet-stream'\n}\n\n// `resolveBrowser` answers with provider options and never reports absence: its\n// last resort is a channel nothing verified. So the launch is attempted and its\n// rejection classified, rather than probed for and ruled on.\n/**\n * Renders the browser endpoint selected by provider options.\n *\n * @param options - The browser provider options.\n * @returns The endpoint, executable, channel, or bundled-browser description.\n */\nexport function renderDistributionBrowser(options: PlaywrightProviderOptions): string {\n\tconst endpoint = options.connectOptions?.wsEndpoint\n\tif (endpoint !== undefined) return `the browser server at ${endpoint}`\n\tconst executable = options.launchOptions?.executablePath\n\tif (executable !== undefined) return `the executable at ${executable}`\n\tconst channel = options.launchOptions?.channel\n\tif (channel !== undefined) return `the ${channel} channel`\n\treturn 'the Chromium Playwright installed for itself'\n}\n\n/**\n * Launches or connects to the selected Chromium browser.\n *\n * @param options - The browser provider options.\n * @returns The real browser. Rejects when the selected browser is unavailable.\n */\nexport async function launchDistributionBrowser(\n\toptions: PlaywrightProviderOptions,\n): Promise<Browser> {\n\tconst endpoint = options.connectOptions?.wsEndpoint\n\tif (endpoint !== undefined) return chromium.connect(endpoint)\n\treturn chromium.launch({ ...options.launchOptions, headless: true })\n}\n\n// A consumer of one installed browser entry, bundled by the Vite toolchain this\n// workspace already declares. Nothing is stubbed: the bundle resolves the installed\n// package and its whole transitive graph as an application consuming it would.\n/**\n * Bundles a browser consumer against an installed public entry.\n *\n * @param stage - The installed consumer.\n * @param entry - The browser publication.\n * @returns The bundle directory. Rejects when Vite cannot build the consumer.\n */\nexport async function bundleDistributionEntry(\n\tstage: DistributionStage,\n\tentry: DistributionEntry,\n): Promise<string> {\n\tconst page = join(stage.consumer, 'pages', entry.subpath.replaceAll(/[^\\w]+/gu, '-'))\n\tconst specifier = JSON.stringify(entry.specifier)\n\twriteDistributionFile(join(page, 'index.html'), DISTRIBUTION_BROWSER_PAGE)\n\twriteDistributionFile(\n\t\tjoin(page, 'main.js'),\n\t\t`import * as entry from ${specifier}\\nglobalThis.subject = Object.keys(entry).sort()\\n`,\n\t)\n\tawait build({\n\t\tbase: './',\n\t\tbuild: { emptyOutDir: true, outDir: 'bundle' },\n\t\tconfigFile: false,\n\t\tlogLevel: 'error',\n\t\troot: page,\n\t})\n\treturn join(page, 'bundle')\n}\n\n// The key set the bundled module publishes in a real browser, read off the page\n// once it has loaded over a loopback server. A module that never evaluated\n// publishes nothing, and a page error is raised rather than compared away.\n/**\n * Reads the names a real browser publishes from a served bundle.\n *\n * @param browser - The browser to drive.\n * @param bundle - The built consumer directory.\n * @returns The exported names. Rejects on a page error or an invalid name list.\n */\nexport async function readDistributionBrowserExports(\n\tbrowser: Browser,\n\tbundle: string,\n): Promise<readonly string[]> {\n\tconst server = createServer((request, response) => {\n\t\tconst asked = request.url === undefined || request.url === '/' ? '/index.html' : request.url\n\t\tconst path = join(bundle, decodeURIComponent(asked))\n\t\tif (!path.startsWith(bundle) || !existsSync(path)) {\n\t\t\tresponse.writeHead(404)\n\t\t\tresponse.end()\n\t\t\treturn\n\t\t}\n\t\tresponse.writeHead(200, { 'content-type': inferDistributionContentType(path) })\n\t\tresponse.end(readFileSync(path))\n\t})\n\ttry {\n\t\tawait new Promise<void>((settle) => {\n\t\t\tserver.listen(0, '127.0.0.1', settle)\n\t\t})\n\t\tconst address = server.address()\n\t\tif (address === null || typeof address === 'string') {\n\t\t\tthrow new Error('The bundle server bound no port')\n\t\t}\n\t\tconst page = await browser.newPage()\n\t\tconst failures: string[] = []\n\t\tpage.on('pageerror', (error) => failures.push(String(error)))\n\t\tawait page.goto(`http://127.0.0.1:${String(address.port)}/`, { waitUntil: 'load' })\n\t\tconst published: unknown = await page.evaluate('globalThis.subject')\n\t\tif (failures.length > 0) throw new Error(`The bundle raised ${failures.join(' | ')}`)\n\t\tif (!isDistributionNames(published))\n\t\t\tthrow new Error('The bundled module published no name list')\n\t\treturn published\n\t} finally {\n\t\tserver.close()\n\t}\n}\n/**\n * Checks each browser publication against its installed declarations in a real browser.\n * @param stage - The installed consumer to drive.\n * @param context - The proof context that reports unavailable browser prerequisites.\n * @returns The compiler diagnostics each browser publication reports.\n */\nexport async function checkDistributionBrowser(\n\tstage: DistributionStage,\n\tcontext: TestContext,\n): Promise<readonly string[]> {\n\tconst driver = DISTRIBUTION_BROWSER_RESOLUTION\n\tif (driver === undefined) throw new Error(\"DISTRIBUTION_RESOLUTIONS carries no 'bundler' row\")\n\tconst entries = stage.entries.filter((entry) => entry.browsable)\n\tif (entries.length === 0) return context.skip('No installed entry supports a browser')\n\tconst readings: Array<readonly string[]> = []\n\tfor (const entry of entries) {\n\t\tif (!entry.declaration.browsable) {\n\t\t\tthrow new Error(`${entry.subpath} publishes no browser declaration`)\n\t\t}\n\t\tconst options = resolveBrowser(resolvePinnedBrowser(), process.platform, process.env)\n\t\tconst browser = await launchDistributionBrowser(options).catch((error: unknown) => {\n\t\t\tconst cause = `${renderDistributionBrowser(options)} was rejected: ${String(error)}`\n\t\t\tif (DISTRIBUTION_RELEASE) throw new Error(`The release gate requires a browser, and ${cause}`)\n\t\t\treturn context.skip(`No browser launched. ${cause}`)\n\t\t})\n\t\ttry {\n\t\t\tconst bundle = await bundleDistributionEntry(stage, entry)\n\t\t\tconst published = await readDistributionBrowserExports(browser, bundle)\n\t\t\t// A browser consumer reads the installed declarations through a bundler, so\n\t\t\t// that is the one driver this face answers under.\n\t\t\tconst reported = checkDistributionSurface(stage, {\n\t\t\t\tentry,\n\t\t\t\textension: 'ts',\n\t\t\t\tpublished,\n\t\t\t\tdriver,\n\t\t\t})\n\t\t\treadings.push(reported)\n\t\t} finally {\n\t\t\tawait browser.close()\n\t\t}\n\t}\n\treturn readings.flat()\n}\n";
|
|
142
|
+
drive: "\tit('publishes what it declares to a real browser [requires a browser]', async (context) => {\n\t\texpect(await checkDistributionBrowser(DISTRIBUTION_SUITE.read(context), context)).toStrictEqual(\n\t\t\t[],\n\t\t)\n\t})\n";
|
|
143
|
+
guard: "\tit('publishes no browser face this proof cannot drive [requires the registry]', (context) => {\n\t\tconst faces = DISTRIBUTION_SUITE.read(context).entries.filter((entry) => entry.browsable)\n\t\texpect(faces.map((entry) => entry.subpath)).toStrictEqual([])\n\t})\n";
|
|
142
144
|
}>;
|
|
143
145
|
integration: "{{imports}}import { describe, expect, it } from 'vitest'\n\ndescribe('workspace integration', () => {\n\tit('loads every selected public barrel together as a composition seed', () => {\n\t\t// Replace this empty-barrel seed with one observable flow that passes one\n\t\t// environment's public result into another.\n\t\t{{actual}}{{expected}})\n\t})\n})\n";
|
|
144
146
|
}>;
|
|
@@ -279,6 +281,9 @@ export declare const BIN_CONFIGS: readonly string[];
|
|
|
279
281
|
/** Names the executable entry whose presence makes a workspace `bin`. */
|
|
280
282
|
export declare const BIN_ENTRY_PATH = "src/bin/main.ts";
|
|
281
283
|
|
|
284
|
+
/** Names the built executable a bin workspace's manifest command runs. */
|
|
285
|
+
export declare const BIN_OUTPUT_PATH = "dist/bin/main.js";
|
|
286
|
+
|
|
282
287
|
/**
|
|
283
288
|
* Represents the closed, JSON-serializable workspace specification.
|
|
284
289
|
*
|
|
@@ -289,11 +294,13 @@ export declare const BIN_ENTRY_PATH = "src/bin/main.ts";
|
|
|
289
294
|
* are runtime `@orkestrel/*` packages. A peer in the `@orkestrel` scope is a
|
|
290
295
|
* fleet pin; every other peer is a floor. `extras` are package-specific
|
|
291
296
|
* development dependencies and may carry any valid npm name.
|
|
292
|
-
* `bin`, `setup`, `guides`, `integration`, `conformance`, `service`,
|
|
297
|
+
* `bin`, `setup`, `guides`, `integration`, `conformance`, `tree`, `service`,
|
|
293
298
|
* `vendors`, `studies`, `global`, `showcase`, `journey`, `styles`, `themes`, and `skills` are structural facts: each is
|
|
294
299
|
* set only when the workspace physically ships the directory or exact-case file
|
|
295
300
|
* that defines it, never because of the workspace's name and never because a
|
|
296
301
|
* sibling fact is set.
|
|
302
|
+
* `tree` registers the Node proof over the package's real tree at the exact-case
|
|
303
|
+
* `tests/tree.test.ts` path, with `tests/setup.ts` and `tests/setupServer.ts`.
|
|
297
304
|
* `setup` lists the runtimes required by root setup proofs: `node` for generic
|
|
298
305
|
* and server proofs, and `browser` for `tests/setupBrowser.test.ts` and `tests/setupStyles.test.ts`.
|
|
299
306
|
* `journey` selects the birth-owned variant wrapper for a browser application.
|
|
@@ -340,6 +347,7 @@ export declare interface Blueprint {
|
|
|
340
347
|
readonly guides: boolean;
|
|
341
348
|
readonly integration: boolean;
|
|
342
349
|
readonly conformance: boolean;
|
|
350
|
+
readonly tree: boolean;
|
|
343
351
|
readonly service: boolean;
|
|
344
352
|
readonly vendors: readonly string[];
|
|
345
353
|
readonly studies: boolean;
|
|
@@ -874,12 +882,12 @@ export declare function blueprintToSourceArtifacts(blueprint: Blueprint): readon
|
|
|
874
882
|
* path. `studies` emits nothing: the root configuration names no study harness,
|
|
875
883
|
* so `tests/setupStudy.ts` is the package's own module.
|
|
876
884
|
*
|
|
877
|
-
* The distribution
|
|
878
|
-
*
|
|
879
|
-
* knows
|
|
880
|
-
* nothing has to be named.
|
|
881
|
-
*
|
|
882
|
-
*
|
|
885
|
+
* The content-owned distribution harness `tests/setupDistribution.ts` and the presence-owned
|
|
886
|
+
* proof `tests/distribution.test.ts` are emitted because the proof measures the packed tarball
|
|
887
|
+
* rather than anything only the package knows. Every assertion derives from the installed tree
|
|
888
|
+
* at run time, so nothing has to be named. The proof follows the published source it packs and
|
|
889
|
+
* alone is claimed by presence: a target lacking the proof reports as drift, and a package that
|
|
890
|
+
* replaced the proof with a better one keeps that proof.
|
|
883
891
|
*
|
|
884
892
|
* @example
|
|
885
893
|
* ```ts
|
|
@@ -1493,7 +1501,7 @@ export declare class Compiler implements CompilerInterface {
|
|
|
1493
1501
|
vite: "{{journey}}import type { PluginOption, UserConfig } from 'vite'\nimport { mergeConfig } from 'vite'\n{{imports}}import { defineConfig } from 'vitest/config'\nimport manifest from './package.json' with { type: 'json' }\nimport tsconfig from './tsconfig.json' with { type: 'json' }\n{{helpers}}{{browsers}}import { fileURLToPath, URL } from 'node:url'\n\n{{options}}export function resolveWorkspacePath(relativePath: string): string {\n\treturn fileURLToPath(new URL(relativePath, import.meta.url))\n}\n\nconst peerDependencies = 'peerDependencies' in manifest ? manifest.peerDependencies : undefined\nif (\n\tpeerDependencies !== undefined &&\n\t(typeof peerDependencies !== 'object' ||\n\t\tpeerDependencies === null ||\n\t\tArray.isArray(peerDependencies))\n) {\n\tthrow new Error('package peerDependencies must be an object')\n}\nexport const peers: readonly string[] =\n\tpeerDependencies === undefined ? [] : Object.keys(peerDependencies)\n\nconst resolve = {\n\talias: Object.fromEntries(\n\t\tObject.entries(tsconfig.compilerOptions.paths).map(([key, values]) => {\n\t\t\tconst [path] = values\n\t\t\tif (path === undefined) throw new Error('tsconfig path alias ' + key + ' has no target')\n\t\t\treturn [key, resolveWorkspacePath(path)]\n\t\t}),\n\t),\n}\n\n// Merges a caller's override onto the configuration a factory declares, so a\n// package's own configuration reaches the factory through its parameter instead of\n// wrapping the call from outside.\n//\n// Vitest calls every registered project factory with its own invocation record —\n// `command`, `mode`, `isSsrBuild`, `isPreview` — so a factory that also takes an\n// override receives that record in the same position. A `UserConfig` declares `mode`\n// but not `command`, and the invocation record always carries both, so a value\n// carrying the pair is that record rather than an override. The merge returns the\n// base in the record's `mode` and carries none of the record's other fields. Vitest\n// runs a project that declares no `mode` in its own run mode, `test`, rather than in\n// the `--mode` value it was invoked with, so a distribution proof run with\n// `--mode release` would read `test` and skip where it must fail. A record whose\n// `mode` is not a string throws. The `tests/config.test.ts` file drives every\n// registered factory through it.\n//\n// `mergeConfig` concatenates arrays, so an override carrying `plugins` would otherwise\n// add a second copy of a plugin the base already declares. Only named top-level\n// objects replace a base plugin of the same name, in the base's position, and one\n// override entry is taken at most once. An entry no base position took appends in its\n// written order; the caller's own entries never merge with each other. Nested arrays,\n// promises, falsy entries, and anonymous objects pass through unchanged. An override\n// cannot remove a base plugin. Every key other than `plugins` merges as `mergeConfig`\n// merges it, so an override's arrays elsewhere concatenate with the base's rather than\n// replacing them.\nexport function mergeOverride(base: UserConfig, override?: UserConfig): UserConfig {\n\tif (\n\t\toverride !== undefined &&\n\t\t'command' in override &&\n\t\t'mode' in override &&\n\t\ttypeof override.mode !== 'string'\n\t) {\n\t\tthrow new Error('The project invocation carries no string mode')\n\t}\n\tconst effective: UserConfig | undefined =\n\t\toverride !== undefined && 'command' in override && typeof override.mode === 'string'\n\t\t\t? { mode: override.mode }\n\t\t\t: override\n\tconst merged: UserConfig = effective === undefined ? { ...base } : mergeConfig(base, effective)\n\tconst name = merged.test?.name\n\tconst label = typeof name === 'string' ? name : name?.label\n\tconst browser = merged.test?.browser\n\tconst named: UserConfig =\n\t\tlabel !== undefined && browser?.instances !== undefined\n\t\t\t? {\n\t\t\t\t\t...merged,\n\t\t\t\t\ttest: {\n\t\t\t\t\t\t...merged.test,\n\t\t\t\t\t\tbrowser: {\n\t\t\t\t\t\t\t...browser,\n\t\t\t\t\t\t\tinstances: browser.instances.map((instance) => ({\n\t\t\t\t\t\t\t\t...instance,\n\t\t\t\t\t\t\t\tname: instance.name ?? `${label} (${instance.browser})`,\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: merged\n\tif (named.plugins === undefined || effective === undefined) return named\n\tconst candidates = [...(effective.plugins ?? [])]\n\tconst bases = [...(base.plugins ?? [])]\n\t// A base plugin takes the first candidate of its own name that no earlier base plugin took, and\n\t// candidates of other names never compete for it, so its pick is the candidate whose rank among\n\t// its name equals the number of earlier base plugins sharing that name.\n\tconst chosen = bases.map((plugin, position) =>\n\t\tisNamedPlugin(plugin)\n\t\t\t? candidates\n\t\t\t\t\t.flatMap((candidate, index) =>\n\t\t\t\t\t\tisNamedPlugin(candidate) && candidate.name === plugin.name ? [index] : [],\n\t\t\t\t\t)\n\t\t\t\t\t.at(\n\t\t\t\t\t\tbases\n\t\t\t\t\t\t\t.slice(0, position)\n\t\t\t\t\t\t\t.filter((earlier) => isNamedPlugin(earlier) && earlier.name === plugin.name).length,\n\t\t\t\t\t)\n\t\t\t: undefined,\n\t)\n\treturn {\n\t\t...named,\n\t\tplugins: [\n\t\t\t...bases.map((plugin, position) => {\n\t\t\t\tconst index = chosen[position]\n\t\t\t\treturn index === undefined ? plugin : (candidates[index] ?? plugin)\n\t\t\t}),\n\t\t\t...candidates.filter((_, index) => !chosen.includes(index)),\n\t\t],\n\t}\n}\n\nfunction isNamedPlugin(plugin: PluginOption): plugin is { name: string } {\n\treturn (\n\t\ttypeof plugin === 'object' &&\n\t\tplugin !== null &&\n\t\t!Array.isArray(plugin) &&\n\t\t!('then' in plugin && typeof plugin.then === 'function') &&\n\t\t'name' in plugin &&\n\t\ttypeof plugin.name === 'string'\n\t)\n}\n\n{{factories}}export default defineConfig({\n\tresolve,\n\ttest: {\n{{projects}}\n\t},\n})\n";
|
|
1494
1502
|
}>;
|
|
1495
1503
|
factories: Readonly<{
|
|
1496
|
-
sheet: "export function sheetProject(name: string, override?: UserConfig): UserConfig {\n\tconst project: UserConfig = {\n\t\tresolve,\n\t\toptimizeDeps,\n\t\tpublicDir: false,\n\t\ttest: {\n\t\t\tname: { label: name, color: 'magenta' },\n\t\t\troot: resolveWorkspacePath('.'),\n\t\t\tisolate: false,\n\t\t\tsetupFiles: ['./tests/setup.ts'
|
|
1504
|
+
sheet: "export function sheetProject(name: string, override?: UserConfig): UserConfig {\n\tconst project: UserConfig = {\n\t\tresolve,\n\t\toptimizeDeps,\n\t\tpublicDir: false,\n\t\ttest: {\n\t\t\tname: { label: name, color: 'magenta' },\n\t\t\troot: resolveWorkspacePath('.'),\n\t\t\tisolate: false,\n\t\t\tsetupFiles: [\n\t\t\t\t'./tests/setup.ts',\n\t\t\t\t'./tests/setupBrowser.ts',\n\t\t\t\t...(existsSync(resolveWorkspacePath('tests/setupStyles.ts'))\n\t\t\t\t\t? ['./tests/setupStyles.ts']\n\t\t\t\t\t: []),\n\t\t\t],\n\t\t\tbrowser: {\n\t\t\t\tenabled: true,\n\t\t\t\tprovider: playwright(browserOptions),\n\t\t\t\tcommands,\n\t\t\t\tinstances: [{ browser: 'chromium', headless: true }],\n\t\t\t},\n\t\t\tfileParallelism: false,\n\t\t\tsequence: { groupOrder: 1 },\n\t\t},\n\t}\n\treturn mergeOverride(project, override)\n}\n";
|
|
1497
1505
|
src: Readonly<{
|
|
1498
1506
|
core: "export function srcCore(override?: UserConfig): UserConfig {\n\tconst project: UserConfig = {\n\t\tresolve,\n\t\tpublicDir: false,\n\t\tbuild: {\n\t\t\temptyOutDir: true,\n\t\t\tsourcemap: true,\n\t\t\tminify: false,\n\t\t\trolldownOptions: { onLog: enforceBuildLog },\n\t\t},\n\t\ttest: {\n\t\t\tname: { label: 'src:core', color: 'magenta' },\n\t\t\tinclude: ['tests/src/core/**/*.test.ts'],\n\t\t\tsetupFiles: ['./tests/setup.ts'],\n\t\t\tenvironment: 'node',\n\t\t\tbrowser: { enabled: false },\n\t\t},\n\t}\n\treturn mergeOverride(project, override)\n}\n";
|
|
1499
1507
|
vue: "function resolveVueFilename(): string {\n\treturn 'index.js'\n}\n\nexport function srcVue(override?: UserConfig): UserConfig {\n\tconst project: UserConfig = {\n\t\tresolve,\n\t\toptimizeDeps: { include: [...optimizeDeps.include, 'vue'] },\n\t\tpublicDir: false,\n\t\tplugins: [outputBoundary('dist/src/vue'), environmentBoundary('src/vue'), vue()],\n\t\tbuild: {\n\t\t\temptyOutDir: true,\n\t\t\tsourcemap: true,\n\t\t\tminify: false,\n\t\t\tlib: {\n\t\t\t\tentry: resolveWorkspacePath('src/vue/index.ts'),\n\t\t\t\tformats: ['es'],\n\t\t\t\tfileName: resolveVueFilename,\n\t\t\t},\n\t\t\toutDir: 'dist/src/vue',\n\t\t\trolldownOptions: { onLog: enforceBuildLog },\n\t\t},\n\t\ttest: {\n\t\t\tname: { label: 'src:vue', color: 'green' },\n\t\t\tinclude: ['tests/src/vue/**/*.test.ts'],\n\t\t\tsetupFiles: ['./tests/setup.ts', './tests/setupBrowser.ts'],\n\t\t\tbrowser: {\n\t\t\t\tenabled: true,\n\t\t\t\tprovider: playwright(browserOptions),\n\t\t\t\tcommands,\n\t\t\t\tinstances: [{ browser: 'chromium', headless: true }],\n\t\t\t},\n\t\t\tfileParallelism: false,\n\t\t\tsequence: { groupOrder: 1 },\n\t\t},\n\t}\n\treturn mergeOverride(project, override)\n}\n";
|
|
@@ -1515,6 +1523,7 @@ export declare class Compiler implements CompilerInterface {
|
|
|
1515
1523
|
browser: "export function setupBrowser(override?: UserConfig): UserConfig {\n\tconst project: UserConfig = {\n\t\tresolve,\n\t\t{{optimization}},\n{{plugins}}\t\ttest: {\n\t\t\tname: { label: 'setup:browser', color: 'blue' },\n\t\t\tinclude: ['tests/setupBrowser.test.ts', 'tests/setupStyles.test.ts'],\n\t\t\tsetupFiles: ['./tests/setup.ts', './tests/setupBrowser.ts'],\n{{global}}\t\t\tbrowser: {\n\t\t\t\tenabled: true,\n\t\t\t\tprovider: playwright(browserOptions),\n\t\t\t\tcommands,\n\t\t\t\tinstances: [{ browser: 'chromium', headless: true }],\n\t\t\t},\n\t\t},\n\t}\n\treturn mergeOverride(project, override)\n}\n";
|
|
1516
1524
|
guides: "export function guides(override?: UserConfig): UserConfig {\n\tconst project: UserConfig = {\n\t\tresolve,\n\t\ttest: {\n\t\t\tname: { label: 'guides', color: 'green' },\n\t\t\tinclude: ['tests/guides.test.ts'],\n\t\t\texclude: ['tests/src/**/*.test.ts', 'tests/app/**/*.test.ts', 'tests/setup.test.ts'],\n\t\t\tsetupFiles: ['./tests/setup.ts'],\n\t\t\tenvironment: 'node',\n\t\t\tbrowser: { enabled: false },\n\t\t},\n\t}\n\treturn mergeOverride(project, override)\n}\n";
|
|
1517
1525
|
skills: "// The skill scripts this package ships as canon, each driven as a child process against a\n// scratch fixture from its mirrored proof under `tests/agents/skills/<skill>/scripts/`. The\n// `configs/agents/tsconfig.skills.json` wrapper selects the project.\nexport function skills(override?: UserConfig): UserConfig {\n\tconst project: UserConfig = {\n\t\tresolve,\n\t\ttest: {\n\t\t\tname: { label: 'skills', color: 'blue' },\n\t\t\tinclude: ['tests/agents/**/*.test.ts'],\n\t\t\tsetupFiles: ['./tests/setup.ts'],\n\t\t\tenvironment: 'node',\n\t\t\tbrowser: { enabled: false },\n\t\t\t// Each case spawns node on a script; a census case runs `vitest list` over this checkout.\n\t\t\ttestTimeout: 60_000,\n\t\t},\n\t}\n\treturn mergeOverride(project, override)\n}\n";
|
|
1526
|
+
tree: "// The laws this package states about its own real tree.\n// Standalone Node proof; reads the tree without a build, install, or service.\nexport function tree(override?: UserConfig): UserConfig {\n\tconst project: UserConfig = {\n\t\tresolve,\n\t\ttest: {\n\t\t\tname: { label: 'tree', color: 'magenta' },\n\t\t\tinclude: ['tests/tree.test.ts'],\n\t\t\tsetupFiles: ['./tests/setup.ts', './tests/setupServer.ts'],\n\t\t\tpool: 'threads',\n\t\t\tisolate: false,\n\t\t\tenvironment: 'node',\n\t\t\tbrowser: { enabled: false },\n\t\t},\n\t}\n\treturn mergeOverride(project, override)\n}\n";
|
|
1518
1527
|
conformance: "// Where this package drifts from the official tooling it stays compatible with.\n// The subject is this package, so the proof is hermetic and stays in `npm test`.\nexport function conformance(override?: UserConfig): UserConfig {\n\tconst project: UserConfig = {\n\t\tresolve,\n\t\ttest: {\n\t\t\tname: { label: 'conformance', color: 'magenta' },\n\t\t\tinclude: ['tests/conformance.test.ts'],\n\t\t\tsetupFiles: ['./tests/setup.ts', './tests/setupServer.ts'],\n\t\t\tpool: 'threads',\n\t\t\tisolate: false,\n\t\t\tenvironment: 'node',\n\t\t\tbrowser: { enabled: false },\n\t\t},\n\t}\n\treturn mergeOverride(project, override)\n}\n";
|
|
1519
1528
|
service: "// The caller prepares the live external services before this project.\n// `tests/setupService.ts` verifies readiness, and the project stays out of `npm test`\n// because a real service answers it.\nexport function service(override?: UserConfig): UserConfig {\n\tconst project: UserConfig = {\n\t\tresolve,\n\t\ttest: {\n\t\t\tname: { label: 'service', color: 'red' },\n\t\t\tinclude: ['tests/service/**/*.test.ts'],\n\t\t\tsetupFiles: ['./tests/setup.ts', './tests/setupService.ts'],\n\t\t\tenvironment: 'node',\n\t\t\tbrowser: { enabled: false },\n\t\t\ttestTimeout: 120_000,\n\t\t\thookTimeout: 120_000,\n\t\t\tfileParallelism: false,\n\t\t\tsequence: { groupOrder: 1 },\n\t\t},\n\t}\n\treturn mergeOverride(project, override)\n}\n";
|
|
1520
1529
|
studies: "// Authored study proofs run installed packages through bounded subprocesses and protocol fixtures,\n// so this project is isolated in its own gate script, test:studies.\nexport function studies(override?: UserConfig): UserConfig {\n\tconst project: UserConfig = {\n\t\tresolve,\n\t\ttest: {\n\t\t\tname: { label: 'studies', color: 'red' },\n\t\t\tinclude: ['tests/studies/**/*.test.ts'],\n\t\t\tsetupFiles: ['./tests/setup.ts'],\n\t\t\tenvironment: 'node',\n\t\t\tbrowser: { enabled: false },\n\t\t\ttestTimeout: 120_000,\n\t\t\thookTimeout: 120_000,\n\t\t\tfileParallelism: false,\n\t\t\tsequence: { groupOrder: 1 },\n\t\t},\n\t}\n\treturn mergeOverride(project, override)\n}\n";
|
|
@@ -1561,7 +1570,7 @@ export declare class Compiler implements CompilerInterface {
|
|
|
1561
1570
|
journey: "import type { JourneyVariant } from '@orkestrel/test'\nimport { defineConfig } from 'vitest/config'\nimport { appJourney } from '../../vite.config.ts'\n\n// Rename and extend these viewports for the application. Apply themes through its interface.\nconst VARIANTS: readonly JourneyVariant[] = Object.freeze([\n\t{ name: 'desktop', width: 1280, height: 800 },\n\t{ name: 'compact', width: 390, height: 844 },\n])\n\nexport default defineConfig(({ mode }) => ({\n\ttest: {\n\t\tprojects: VARIANTS.map((variant) => () => appJourney(variant, VARIANTS, mode)),\n\t},\n}))\n";
|
|
1562
1571
|
}>;
|
|
1563
1572
|
}>;
|
|
1564
|
-
browsers: "// A generated browser workspace resolves its own Chromium here rather than in\n// `configs/helpers.ts`, because that leaf is vendored byte-identical to every\n// workspace and most of them declare no `playwright` to import.\n\nimport type { PlaywrightProviderOptions } from '@vitest/browser-playwright'\nimport { chromium } from 'playwright'\nimport { accessSync, constants as FS_CONSTANTS, globSync, readdirSync, statSync } from 'node:fs'\nimport { basename, dirname, join, resolve as resolvePath } from 'node:path'\n\n/**\n * Lists the Chromium executable layouts inside a `chromium-<revision>` browsers-directory\n * entry, per platform.\n *\n * @remarks\n * The current Playwright build ships Chrome for Testing on macOS. The trailing `Chromium.app`\n * layouts are what earlier builds shipped, so the list spans Playwright versions instead of\n * pinning to the installed one.\n */\nexport const CHROMIUM_LAYOUTS = Object.freeze([\n\t'chrome-linux/chrome',\n\t'chrome-linux64/chrome',\n\t'chrome-win/chrome.exe',\n\t'chrome-win64/chrome.exe',\n\t'chrome-mac-x64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing',\n\t'chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing',\n\t'chrome-mac/Chromium.app/Contents/MacOS/Chromium',\n\t'chrome-mac-arm64/Chromium.app/Contents/MacOS/Chromium',\n])\n\n/** Matches the `chromium-<revision>` entry name Playwright installs one managed build into. */\nexport const CHROMIUM_ENTRY_PATTERN = /^chromium-\\d+$/\n\n/** Matches the revision number carried by any path containing a `chromium-<revision>` segment. */\nexport const CHROMIUM_REVISION_PATTERN = /chromium-(\\d+)/\n\n/** Names the directory a managed Linux container installs its bundled Playwright browsers into. */\nexport const BUNDLED_BROWSERS_ROOT = '/opt/pw-browsers'\n\n/**\n * Lists the bundled Chromium layouts under the managed-container browsers root, as glob patterns.\n *\n * @remarks\n * The revision directory and its inner layout both drift across Playwright builds, and the\n * container also carries a top-level `chromium` alias, so every known shape is globbed.\n */\nexport const BUNDLED_CHROMIUM_LAYOUTS = Object.freeze([\n\t'chromium',\n\t'chromium-*/chrome-linux64/chrome',\n\t'chromium-*/chrome-linux/chrome',\n])\n\n/** Lists the stable Playwright Chromium channels and their standard executable layouts. */\nexport const SYSTEM_BROWSER_CHANNELS = Object.freeze([\n\tObject.freeze({\n\t\tchannel: 'chrome',\n\t\tlayouts: Object.freeze({\n\t\t\tlinux: '/opt/google/chrome/chrome',\n\t\t\tdarwin: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',\n\t\t\twin32: Object.freeze(['Google', 'Chrome', 'Application', 'chrome.exe']),\n\t\t}),\n\t}),\n\tObject.freeze({\n\t\tchannel: 'msedge',\n\t\tlayouts: Object.freeze({\n\t\t\tlinux: '/opt/microsoft/msedge/msedge',\n\t\t\tdarwin: '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',\n\t\t\twin32: Object.freeze(['Microsoft', 'Edge', 'Application', 'msedge.exe']),\n\t\t}),\n\t}),\n])\n\n/**\n * Determines whether a path identifies an executable regular file.\n *\n * @param path - The filesystem path to inspect.\n * @returns True if the path is a regular file with execute access; false otherwise.\n *\n * @example\n * ```ts\n * isBrowserExecutable('/opt/google/chrome/chrome')\n * ```\n */\nexport function isBrowserExecutable(path: string): boolean {\n\ttry {\n\t\tif (!statSync(path).isFile()) return false\n\t\taccessSync(path, FS_CONSTANTS.X_OK)\n\t\treturn true\n\t} catch {\n\t\treturn false\n\t}\n}\n\n/**\n * Orders two Chromium paths so the highest revision sorts first.\n *\n * @param left - The first path or directory entry to compare.\n * @param right - The second path or directory entry to compare.\n * @returns A negative number when `left` sorts first, positive when `right` does.\n *\n * @remarks\n * Revisions are numbers, so `chromium-1200` outranks `chromium-999` despite sorting below it\n * lexically. A path carrying no revision falls back to descending name order.\n *\n * @example\n * ```ts\n * ['chromium-999', 'chromium-1200'].sort(compareRevisions)\n * ```\n */\nexport function compareRevisions(left: string, right: string): number {\n\tconst leftRevision = CHROMIUM_REVISION_PATTERN.exec(left)?.[1]\n\tconst rightRevision = CHROMIUM_REVISION_PATTERN.exec(right)?.[1]\n\tif (leftRevision === undefined || rightRevision === undefined) return right.localeCompare(left)\n\treturn Number(rightRevision) - Number(leftRevision)\n}\n\n/**\n * Reads the executable path of Playwright's pinned Chromium revision.\n *\n * @returns The pinned executable path, or `undefined` when this platform has none.\n *\n * @remarks\n * Playwright throws rather than returning a path when the current platform carries no initialized\n * executable, and an unguarded call would fail configuration evaluation for every project.\n *\n * @example\n * ```ts\n * resolvePinnedBrowser()\n * ```\n */\nexport function resolvePinnedBrowser(): string | undefined {\n\ttry {\n\t\tconst pinned = chromium.executablePath()\n\t\treturn pinned.length === 0 ? undefined : pinned\n\t} catch {\n\t\treturn undefined\n\t}\n}\n\n/**\n * Resolves a launchable Playwright-managed Chromium executable: the pinned revision when installed,\n * otherwise a `chromium` / `chromium.exe` alias or any other `chromium-*` revision under the same\n * Playwright browsers directory. A pinned-revision miss is not Chromium absence — managed\n * containers ship one usable build, often behind a revision-agnostic alias, for many Playwright\n * versions.\n *\n * @param pinned - The executable path for Playwright's pinned Chromium revision.\n * @returns The managed executable path, or `undefined` when none is executable.\n *\n * @example\n * ```ts\n * resolveManagedBrowser('/root/.cache/ms-playwright/chromium-1234/chrome-linux64/chrome')\n * ```\n */\nexport function resolveManagedBrowser(pinned: string): string | undefined {\n\tif (isBrowserExecutable(pinned)) return pinned\n\t// One `dirname` per path segment reaches the root from any path, and the nearest\n\t// ancestor named `chromium-<revision>` is the revision directory this build sits in.\n\tconst directory = dirname(pinned)\n\tconst ancestors = directory\n\t\t.split(/[\\\\/]/u)\n\t\t.reduce<string[]>((chain) => [...chain, dirname(chain.at(-1) ?? directory)], [directory])\n\tconst revisionRoot = ancestors.find((ancestor) => CHROMIUM_ENTRY_PATTERN.test(basename(ancestor)))\n\tif (revisionRoot === undefined) return undefined\n\tconst browsersRoot = dirname(revisionRoot)\n\tfor (const alias of ['chromium', 'chromium.exe']) {\n\t\tconst candidate = resolvePath(browsersRoot, alias)\n\t\tif (isBrowserExecutable(candidate)) return candidate\n\t}\n\ttry {\n\t\tconst revisions = readdirSync(browsersRoot)\n\t\t\t.filter((entry) => CHROMIUM_ENTRY_PATTERN.test(entry))\n\t\t\t.sort(compareRevisions)\n\t\tfor (const revision of revisions) {\n\t\t\tfor (const layout of CHROMIUM_LAYOUTS) {\n\t\t\t\tconst candidate = resolvePath(browsersRoot, revision, layout)\n\t\t\t\tif (isBrowserExecutable(candidate)) return candidate\n\t\t\t}\n\t\t}\n\t\treturn undefined\n\t} catch {\n\t\treturn undefined\n\t}\n}\n\n/**\n * Resolves the Chromium a managed Linux container bundles outside the Playwright cache.\n *\n * @param platform - The Node platform the container runs on.\n * @param root - The bundled browsers directory to search.\n * @returns The highest matching executable path, or `undefined` when none is executable.\n *\n * @example\n * ```ts\n * resolveBundledBrowser('linux', BUNDLED_BROWSERS_ROOT)\n * ```\n */\nexport function resolveBundledBrowser(platform: NodeJS.Platform, root: string): string | undefined {\n\tif (platform !== 'linux') return undefined\n\tfor (const layout of BUNDLED_CHROMIUM_LAYOUTS) {\n\t\ttry {\n\t\t\tfor (const match of globSync(layout, { cwd: root }).sort(compareRevisions)) {\n\t\t\t\tconst candidate = resolvePath(root, match)\n\t\t\t\tif (isBrowserExecutable(candidate)) return candidate\n\t\t\t}\n\t\t} catch {\n\t\t\treturn undefined\n\t\t}\n\t}\n\treturn undefined\n}\n\n/**\n * Resolves the first installed stable system Chromium channel.\n *\n * @param platform - The Node platform whose standard layouts this call probes.\n * @param environment - The process environment supplying Windows installation roots.\n * @returns `chrome`, then `msedge`, or `undefined` when neither is executable.\n *\n * @example\n * ```ts\n * resolveSystemBrowser(process.platform, process.env)\n * ```\n */\nexport function resolveSystemBrowser(\n\tplatform: NodeJS.Platform,\n\tenvironment: NodeJS.ProcessEnv,\n): string | undefined {\n\tif (platform !== 'linux' && platform !== 'darwin' && platform !== 'win32') return undefined\n\tconst roots = new Set(\n\t\tplatform === 'win32'\n\t\t\t? [\n\t\t\t\t\t...[\n\t\t\t\t\t\tenvironment.LOCALAPPDATA,\n\t\t\t\t\t\tenvironment.PROGRAMFILES,\n\t\t\t\t\t\tenvironment['PROGRAMFILES(X86)'],\n\t\t\t\t\t].flatMap((root) => (root !== undefined && root.length > 0 ? [root] : [])),\n\t\t\t\t\t...[environment.HOMEDRIVE].flatMap((homeDrive) =>\n\t\t\t\t\t\thomeDrive !== undefined && homeDrive.length > 0\n\t\t\t\t\t\t\t? [join(homeDrive, 'Program Files'), join(homeDrive, 'Program Files (x86)')]\n\t\t\t\t\t\t\t: [],\n\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t: [],\n\t)\n\tfor (const browser of SYSTEM_BROWSER_CHANNELS) {\n\t\tif (platform === 'win32') {\n\t\t\tfor (const root of roots) {\n\t\t\t\tif (isBrowserExecutable(join(root, ...browser.layouts.win32))) return browser.channel\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tif (isBrowserExecutable(browser.layouts[platform])) return browser.channel\n\t}\n\treturn undefined\n}\n\n/**\n * Resolves Playwright provider options for Chromium on this host.\n *\n * @param pinned - The executable path for Playwright's pinned Chromium revision, when it has one.\n * @param platform - The Node platform whose standard layouts this call probes.\n * @param environment - The process environment supplying operator overrides and Windows roots.\n * @param root - The managed-container bundled browsers directory to search.\n * @returns Provider options naming an executable, a WebSocket endpoint, or a channel.\n *\n * @remarks\n * Precedence, most important first: `PLAYWRIGHT_EXECUTABLE_PATH`, `PLAYWRIGHT_WS_ENDPOINT`,\n * `PLAYWRIGHT_CHANNEL`, the managed Playwright Chromium, the container's bundled Chromium, a\n * verified system channel, then the platform default channel. An operator override outranks\n * discovery and is returned exactly as given: none of those environment values is checked\n * against the filesystem, because verifying an override would defeat the override. The pinned\n * managed revision outranks anything found on the host because it is deterministic. The installed\n * pinned revision returns empty options unless `PLAYWRIGHT_SCROLLBARS=classic` is set. Only a\n * discovered system channel is verified before it is named. The platform default is unverified\n * as well and exists only as a last resort: Windows takes `msedge`, which ships with the OS and\n * never collides with a foreground Chrome.\n *\n * Set `PLAYWRIGHT_SCROLLBARS=classic` only for runs that measure scrollbar compensation, never\n * for a standing gate. Every Chromium launch in that run omits Playwright's `--hide-scrollbars`\n * default argument so classic scrollbars can take layout space in every case. An empty or unset\n * value preserves the launch defaults; any other value throws an `Error`. Pairing `classic`\n * with `PLAYWRIGHT_WS_ENDPOINT` throws an `Error`, even with an executable override, because the\n * server owns the launch.\n *\n * The resolver and the gate cover Chromium alone. Reopen engine selection when another\n * Playwright engine is installed and launches on the host with a `captureFrame` reading\n * back at its declared size, or when a journey or style divergence is recorded.\n *\n * @example\n * ```ts\n * resolveBrowser(resolvePinnedBrowser(), process.platform, process.env)\n * ```\n */\nexport function resolveBrowser(\n\tpinned: string | undefined,\n\tplatform: NodeJS.Platform,\n\tenvironment: NodeJS.ProcessEnv,\n\troot: string = BUNDLED_BROWSERS_ROOT,\n): PlaywrightProviderOptions {\n\tconst scrollbars = environment.PLAYWRIGHT_SCROLLBARS\n\tif (scrollbars !== undefined && scrollbars.length > 0 && scrollbars !== 'classic') {\n\t\tthrow new Error('PLAYWRIGHT_SCROLLBARS must be classic or empty')\n\t}\n\tconst endpoint = environment.PLAYWRIGHT_WS_ENDPOINT\n\tif (scrollbars === 'classic' && endpoint !== undefined && endpoint.length > 0) {\n\t\tthrow new Error('PLAYWRIGHT_SCROLLBARS=classic cannot be used with PLAYWRIGHT_WS_ENDPOINT')\n\t}\n\tconst launch: PlaywrightProviderOptions['launchOptions'] =\n\t\tscrollbars === 'classic' ? { ignoreDefaultArgs: ['--hide-scrollbars'] } : {}\n\tconst executable = environment.PLAYWRIGHT_EXECUTABLE_PATH\n\tif (executable !== undefined && executable.length > 0) {\n\t\treturn { launchOptions: { executablePath: executable, ...launch } }\n\t}\n\tif (endpoint !== undefined && endpoint.length > 0) {\n\t\treturn { connectOptions: { wsEndpoint: endpoint } }\n\t}\n\tconst requested = environment.PLAYWRIGHT_CHANNEL\n\tif (requested !== undefined && requested.length > 0) {\n\t\treturn { launchOptions: { channel: requested, ...launch } }\n\t}\n\tconst managed = pinned === undefined ? undefined : resolveManagedBrowser(pinned)\n\tif (managed !== undefined) {\n\t\tif (managed === pinned) return scrollbars === 'classic' ? { launchOptions: launch } : {}\n\t\treturn { launchOptions: { executablePath: managed, ...launch } }\n\t}\n\tconst bundled = resolveBundledBrowser(platform, root)\n\tif (bundled !== undefined) return { launchOptions: { executablePath: bundled, ...launch } }\n\tconst fallback = platform === 'win32' ? 'msedge' : 'chrome'\n\treturn {\n\t\tlaunchOptions: { channel: resolveSystemBrowser(platform, environment) ?? fallback, ...launch },\n\t}\n}\n";
|
|
1573
|
+
browsers: "// A generated browser workspace resolves its own Chromium here rather than in\n// `configs/helpers.ts`, because that leaf is vendored byte-identical to every\n// workspace and most of them declare no `playwright` to import.\n\nimport type { PlaywrightProviderOptions } from '@vitest/browser-playwright'\nimport { chromium } from 'playwright'\nimport { accessSync, constants as FS_CONSTANTS, globSync, readdirSync, statSync } from 'node:fs'\nimport { basename, dirname, join, resolve as resolvePath } from 'node:path'\n\n/**\n * Lists the Chromium executable layouts inside a `chromium-<revision>` browsers-directory\n * entry, per platform.\n *\n * @remarks\n * The current Playwright build ships Chrome for Testing on macOS. The trailing `Chromium.app`\n * layouts are what earlier builds shipped, so the list spans Playwright versions instead of\n * pinning to the installed one.\n */\nexport const CHROMIUM_LAYOUTS = Object.freeze([\n\t'chrome-linux/chrome',\n\t'chrome-linux64/chrome',\n\t'chrome-win/chrome.exe',\n\t'chrome-win64/chrome.exe',\n\t'chrome-mac-x64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing',\n\t'chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing',\n\t'chrome-mac/Chromium.app/Contents/MacOS/Chromium',\n\t'chrome-mac-arm64/Chromium.app/Contents/MacOS/Chromium',\n])\n\n/** Matches the `chromium-<revision>` entry name Playwright installs one managed build into. */\nexport const CHROMIUM_ENTRY_PATTERN = /^chromium-\\d+$/\n\n/** Matches the revision number carried by any path containing a `chromium-<revision>` segment. */\nexport const CHROMIUM_REVISION_PATTERN = /chromium-(\\d+)/\n\n/** Names the directory a managed Linux container installs its bundled Playwright browsers into. */\nexport const BUNDLED_BROWSERS_ROOT = '/opt/pw-browsers'\n\n/**\n * Lists the bundled Chromium layouts under the managed-container browsers root, as glob patterns.\n *\n * @remarks\n * The revision directory and its inner layout both drift across Playwright builds, and the\n * container also carries a top-level `chromium` alias, so every known shape is globbed.\n */\nexport const BUNDLED_CHROMIUM_LAYOUTS = Object.freeze([\n\t'chromium',\n\t'chromium-*/chrome-linux64/chrome',\n\t'chromium-*/chrome-linux/chrome',\n])\n\n/** Lists the stable Playwright Chromium channels and their standard executable layouts. */\nexport const SYSTEM_BROWSER_CHANNELS = Object.freeze([\n\tObject.freeze({\n\t\tchannel: 'chrome',\n\t\tlayouts: Object.freeze({\n\t\t\tlinux: '/opt/google/chrome/chrome',\n\t\t\tdarwin: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',\n\t\t\twin32: Object.freeze(['Google', 'Chrome', 'Application', 'chrome.exe']),\n\t\t}),\n\t}),\n\tObject.freeze({\n\t\tchannel: 'msedge',\n\t\tlayouts: Object.freeze({\n\t\t\tlinux: '/opt/microsoft/msedge/msedge',\n\t\t\tdarwin: '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',\n\t\t\twin32: Object.freeze(['Microsoft', 'Edge', 'Application', 'msedge.exe']),\n\t\t}),\n\t}),\n])\n\n/**\n * Determines whether a path identifies an executable regular file.\n *\n * @param path - The filesystem path to inspect.\n * @returns True if the path is a regular file with execute access; false otherwise.\n *\n * @example\n * ```ts\n * isBrowserExecutable('/opt/google/chrome/chrome')\n * ```\n */\nexport function isBrowserExecutable(path: string): boolean {\n\ttry {\n\t\tif (!statSync(path).isFile()) return false\n\t\taccessSync(path, FS_CONSTANTS.X_OK)\n\t\treturn true\n\t} catch {\n\t\treturn false\n\t}\n}\n\n/**\n * Orders two Chromium paths so the highest revision sorts first.\n *\n * @param left - The first path or directory entry to compare.\n * @param right - The second path or directory entry to compare.\n * @returns A negative number when `left` sorts first, positive when `right` does.\n *\n * @remarks\n * Revisions are numbers, so `chromium-1200` outranks `chromium-999` despite sorting below it\n * lexically. A path carrying no revision falls back to descending name order.\n *\n * @example\n * ```ts\n * ['chromium-999', 'chromium-1200'].sort(compareRevisions)\n * ```\n */\nexport function compareRevisions(left: string, right: string): number {\n\tconst leftRevision = CHROMIUM_REVISION_PATTERN.exec(left)?.[1]\n\tconst rightRevision = CHROMIUM_REVISION_PATTERN.exec(right)?.[1]\n\tif (leftRevision === undefined || rightRevision === undefined) return right.localeCompare(left)\n\treturn Number(rightRevision) - Number(leftRevision)\n}\n\n/**\n * Reads the executable path of Playwright's pinned Chromium revision.\n *\n * @returns The pinned executable path, or `undefined` when this platform has none.\n *\n * @remarks\n * Playwright throws rather than returning a path when the current platform carries no initialized\n * executable, and an unguarded call would fail configuration evaluation for every project.\n *\n * @example\n * ```ts\n * resolvePinnedBrowser()\n * ```\n */\nexport function resolvePinnedBrowser(): string | undefined {\n\ttry {\n\t\tconst pinned = chromium.executablePath()\n\t\treturn pinned.length === 0 ? undefined : pinned\n\t} catch {\n\t\treturn undefined\n\t}\n}\n\n/**\n * Resolves a launchable Playwright-managed Chromium executable: the pinned revision when installed,\n * otherwise a `chromium` / `chromium.exe` alias or any other `chromium-*` revision under the same\n * Playwright browsers directory. A pinned-revision miss is not Chromium absence — managed\n * containers ship one usable build, often behind a revision-agnostic alias, for many Playwright\n * versions.\n *\n * @param pinned - The executable path for Playwright's pinned Chromium revision.\n * @returns The managed executable path, or `undefined` when none is executable.\n *\n * @example\n * ```ts\n * resolveManagedBrowser('/root/.cache/ms-playwright/chromium-1234/chrome-linux64/chrome')\n * ```\n */\nexport function resolveManagedBrowser(pinned: string): string | undefined {\n\tif (isBrowserExecutable(pinned)) return pinned\n\t// One `dirname` per path segment reaches the root from any path, and the nearest\n\t// ancestor named `chromium-<revision>` is the revision directory this build sits in.\n\tconst directory = dirname(pinned)\n\tconst ancestors = directory\n\t\t.split(/[\\\\/]/u)\n\t\t.reduce<string[]>((chain) => [...chain, dirname(chain.at(-1) ?? directory)], [directory])\n\tconst revisionRoot = ancestors.find((ancestor) => CHROMIUM_ENTRY_PATTERN.test(basename(ancestor)))\n\tif (revisionRoot === undefined) return undefined\n\tconst browsersRoot = dirname(revisionRoot)\n\tfor (const alias of ['chromium', 'chromium.exe']) {\n\t\tconst candidate = resolvePath(browsersRoot, alias)\n\t\tif (isBrowserExecutable(candidate)) return candidate\n\t}\n\ttry {\n\t\tconst revisions = readdirSync(browsersRoot)\n\t\t\t.filter((entry) => CHROMIUM_ENTRY_PATTERN.test(entry))\n\t\t\t.sort(compareRevisions)\n\t\tfor (const revision of revisions) {\n\t\t\tfor (const layout of CHROMIUM_LAYOUTS) {\n\t\t\t\tconst candidate = resolvePath(browsersRoot, revision, layout)\n\t\t\t\tif (isBrowserExecutable(candidate)) return candidate\n\t\t\t}\n\t\t}\n\t\treturn undefined\n\t} catch {\n\t\treturn undefined\n\t}\n}\n\n/**\n * Resolves the Chromium a managed Linux container bundles outside the Playwright cache.\n *\n * @param platform - The Node platform the container runs on.\n * @param root - The bundled browsers directory to search.\n * @returns The highest matching executable path, or `undefined` when none is executable.\n *\n * @example\n * ```ts\n * resolveBundledBrowser('linux', BUNDLED_BROWSERS_ROOT)\n * ```\n */\nexport function resolveBundledBrowser(platform: NodeJS.Platform, root: string): string | undefined {\n\tif (platform !== 'linux') return undefined\n\tfor (const layout of BUNDLED_CHROMIUM_LAYOUTS) {\n\t\ttry {\n\t\t\tfor (const match of globSync(layout, { cwd: root }).sort(compareRevisions)) {\n\t\t\t\tconst candidate = resolvePath(root, match)\n\t\t\t\tif (isBrowserExecutable(candidate)) return candidate\n\t\t\t}\n\t\t} catch {\n\t\t\treturn undefined\n\t\t}\n\t}\n\treturn undefined\n}\n\n/**\n * Resolves the first installed stable system Chromium channel.\n *\n * @param platform - The Node platform whose standard layouts this call probes.\n * @param environment - The process environment supplying Windows installation roots.\n * @returns `chrome`, then `msedge`, or `undefined` when neither is executable.\n *\n * @example\n * ```ts\n * resolveSystemBrowser(process.platform, process.env)\n * ```\n */\nexport function resolveSystemBrowser(\n\tplatform: NodeJS.Platform,\n\tenvironment: NodeJS.ProcessEnv,\n): string | undefined {\n\tif (platform !== 'linux' && platform !== 'darwin' && platform !== 'win32') return undefined\n\tconst roots = new Set(\n\t\tplatform === 'win32'\n\t\t\t? [\n\t\t\t\t\t...[\n\t\t\t\t\t\tenvironment.LOCALAPPDATA,\n\t\t\t\t\t\tenvironment.PROGRAMFILES,\n\t\t\t\t\t\tenvironment['PROGRAMFILES(X86)'],\n\t\t\t\t\t].flatMap((root) => (root !== undefined && root.length > 0 ? [root] : [])),\n\t\t\t\t\t...[environment.HOMEDRIVE].flatMap((homeDrive) =>\n\t\t\t\t\t\thomeDrive !== undefined && homeDrive.length > 0\n\t\t\t\t\t\t\t? [join(homeDrive, 'Program Files'), join(homeDrive, 'Program Files (x86)')]\n\t\t\t\t\t\t\t: [],\n\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t: [],\n\t)\n\tfor (const browser of SYSTEM_BROWSER_CHANNELS) {\n\t\tif (platform === 'win32') {\n\t\t\tfor (const root of roots) {\n\t\t\t\tif (isBrowserExecutable(join(root, ...browser.layouts.win32))) return browser.channel\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tif (isBrowserExecutable(browser.layouts[platform])) return browser.channel\n\t}\n\treturn undefined\n}\n\n/**\n * Resolves Playwright provider options for Chromium on this host.\n *\n * @param pinned - The executable path for Playwright's pinned Chromium revision, when it has one.\n * @param platform - The Node platform whose standard layouts this call probes.\n * @param environment - The process environment supplying operator overrides and Windows roots.\n * @param root - The managed-container bundled browsers directory to search.\n * @returns Provider options naming an executable, a WebSocket endpoint, or a channel.\n *\n * @remarks\n * Precedence, most important first: `PLAYWRIGHT_EXECUTABLE_PATH`, `PLAYWRIGHT_WS_ENDPOINT`,\n * `PLAYWRIGHT_CHANNEL`, the managed Playwright Chromium, the container's bundled Chromium, a\n * verified system channel, then the platform default channel. An operator override outranks\n * discovery and is returned exactly as given: none of those environment values is checked\n * against the filesystem, because verifying an override would defeat the override. The pinned\n * managed revision outranks anything found on the host because it is deterministic. Every resolved\n * managed path names the full Chromium executable so headless launches retain browser permissions.\n * Only a discovered system channel is verified before it is named. The platform default is\n * unverified as well and exists only as a last resort: Windows takes `msedge`, which ships with the\n * OS and never collides with a foreground Chrome.\n *\n * Set `PLAYWRIGHT_SCROLLBARS=classic` only for runs that measure scrollbar compensation, never\n * for a standing gate. Every Chromium launch in that run omits Playwright's `--hide-scrollbars`\n * default argument so classic scrollbars can take layout space in every case. An empty or unset\n * value preserves the launch defaults; any other value throws an `Error`. Pairing `classic`\n * with `PLAYWRIGHT_WS_ENDPOINT` throws an `Error`, even with an executable override, because the\n * server owns the launch.\n *\n * The resolver and the gate cover Chromium alone. Reopen engine selection when another\n * Playwright engine is installed and launches on the host with a `captureFrame` reading\n * back at its declared size, or when a journey or style divergence is recorded.\n *\n * @example\n * ```ts\n * resolveBrowser(resolvePinnedBrowser(), process.platform, process.env)\n * ```\n */\nexport function resolveBrowser(\n\tpinned: string | undefined,\n\tplatform: NodeJS.Platform,\n\tenvironment: NodeJS.ProcessEnv,\n\troot: string = BUNDLED_BROWSERS_ROOT,\n): PlaywrightProviderOptions {\n\tconst scrollbars = environment.PLAYWRIGHT_SCROLLBARS\n\tif (scrollbars !== undefined && scrollbars.length > 0 && scrollbars !== 'classic') {\n\t\tthrow new Error('PLAYWRIGHT_SCROLLBARS must be classic or empty')\n\t}\n\tconst endpoint = environment.PLAYWRIGHT_WS_ENDPOINT\n\tif (scrollbars === 'classic' && endpoint !== undefined && endpoint.length > 0) {\n\t\tthrow new Error('PLAYWRIGHT_SCROLLBARS=classic cannot be used with PLAYWRIGHT_WS_ENDPOINT')\n\t}\n\tconst launch: PlaywrightProviderOptions['launchOptions'] =\n\t\tscrollbars === 'classic' ? { ignoreDefaultArgs: ['--hide-scrollbars'] } : {}\n\tconst executable = environment.PLAYWRIGHT_EXECUTABLE_PATH\n\tif (executable !== undefined && executable.length > 0) {\n\t\treturn { launchOptions: { executablePath: executable, ...launch } }\n\t}\n\tif (endpoint !== undefined && endpoint.length > 0) {\n\t\treturn { connectOptions: { wsEndpoint: endpoint } }\n\t}\n\tconst requested = environment.PLAYWRIGHT_CHANNEL\n\tif (requested !== undefined && requested.length > 0) {\n\t\treturn { launchOptions: { channel: requested, ...launch } }\n\t}\n\tconst managed = pinned === undefined ? undefined : resolveManagedBrowser(pinned)\n\tif (managed !== undefined) {\n\t\treturn { launchOptions: { executablePath: managed, ...launch } }\n\t}\n\tconst bundled = resolveBundledBrowser(platform, root)\n\tif (bundled !== undefined) return { launchOptions: { executablePath: bundled, ...launch } }\n\tconst fallback = platform === 'win32' ? 'msedge' : 'chrome'\n\treturn {\n\t\tlaunchOptions: { channel: resolveSystemBrowser(platform, environment) ?? fallback, ...launch },\n\t}\n}\n";
|
|
1565
1574
|
commands: "import type { BrowserConfigOptions } from 'vitest/node'\n\nexport const commands: Readonly<NonNullable<BrowserConfigOptions['commands']>> = Object.freeze({})\n";
|
|
1566
1575
|
}>;
|
|
1567
1576
|
|
|
@@ -1718,8 +1727,8 @@ export declare class Compiler implements CompilerInterface {
|
|
|
1718
1727
|
* @remarks
|
|
1719
1728
|
* A dependency name reaches a path, because a workspace's guide mirror is
|
|
1720
1729
|
* derived from it. Fixing the scope and forbidding everything but the bare name
|
|
1721
|
-
* after it is what stops a hand-built name from
|
|
1722
|
-
* mirror belongs in.
|
|
1730
|
+
* after it is what stops a hand-built name from resolving outside the directory
|
|
1731
|
+
* the mirror belongs in.
|
|
1723
1732
|
*/
|
|
1724
1733
|
export declare const DEPENDENCY_NAME_PATTERN: RegExp;
|
|
1725
1734
|
|
|
@@ -1729,6 +1738,9 @@ export declare class Compiler implements CompilerInterface {
|
|
|
1729
1738
|
readonly development: readonly Dependency[];
|
|
1730
1739
|
}
|
|
1731
1740
|
|
|
1741
|
+
/** Names the content-owned harness imported by the generated distribution proof. */
|
|
1742
|
+
export declare const DISTRIBUTION_SETUP_PATH = "tests/setupDistribution.ts";
|
|
1743
|
+
|
|
1732
1744
|
/** Names the generated packed-package proof every publishing workspace is planned at. */
|
|
1733
1745
|
export declare const DISTRIBUTION_TEST_PATH = "tests/distribution.test.ts";
|
|
1734
1746
|
|
|
@@ -2289,7 +2301,7 @@ export declare class Compiler implements CompilerInterface {
|
|
|
2289
2301
|
*
|
|
2290
2302
|
* @remarks
|
|
2291
2303
|
* Compose this ahead of an element guard so the item count is settled before
|
|
2292
|
-
* anything walks the items. A
|
|
2304
|
+
* anything walks the items. A throwing `length` accessor answers `false` here
|
|
2293
2305
|
* rather than escaping as a thrown error.
|
|
2294
2306
|
*
|
|
2295
2307
|
* @example
|
|
@@ -2655,7 +2667,7 @@ export declare class Compiler implements CompilerInterface {
|
|
|
2655
2667
|
* whose every value is exact lowercase hexadecimal bytes; false otherwise.
|
|
2656
2668
|
*
|
|
2657
2669
|
* @remarks
|
|
2658
|
-
* Read through the shared total key lens, so
|
|
2670
|
+
* Read through the shared total key lens, so an `ownKeys` trap that throws and a
|
|
2659
2671
|
* throwing accessor both answer `false` rather than escaping. There is no
|
|
2660
2672
|
* dictionary combinator upstream to compose this from: the key law and the
|
|
2661
2673
|
* value law are both this package's own.
|
|
@@ -4065,6 +4077,9 @@ export declare class Compiler implements CompilerInterface {
|
|
|
4065
4077
|
/** Names the themes build entry marker. */
|
|
4066
4078
|
export declare const THEMES_ENTRY_PATH = "src/styles/themes/sheet.ts";
|
|
4067
4079
|
|
|
4080
|
+
/** Names the real-tree proof whose presence makes a workspace `tree`. */
|
|
4081
|
+
export declare const TREE_TEST_PATH = "tests/tree.test.ts";
|
|
4082
|
+
|
|
4068
4083
|
/** Matches the exact `major.minor.patch` version syntax a blueprint declares. */
|
|
4069
4084
|
export declare const VERSION_PATTERN: RegExp;
|
|
4070
4085
|
|