@orkestrel/scaffold 0.0.48 → 0.0.50
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/README.md +4 -2
- package/dist/bin/main.js +427 -97
- package/dist/bin/main.js.map +1 -1
- package/dist/host/agents/orchestration.md +35 -3
- package/dist/host/agents/skills/orkestrel-falsify/SKILL.md +4 -0
- package/dist/host/claude/agents/orkestrel.md +44 -44
- package/dist/host/claude/rules/quality.md +4 -1
- package/dist/host/claude/rules/tests.md +6 -2
- package/dist/host/guides/scaffold.md +478 -161
- package/dist/host/manifest.json +217 -109
- package/dist/host/scripts/codex.sh +0 -0
- package/dist/host/scripts/cursor.sh +0 -0
- package/dist/host/scripts/deps.sh +0 -0
- package/dist/host/scripts/ollama.sh +0 -0
- package/dist/host/tests/config.test.ts +129 -6
- package/dist/src/core/index.cjs +1315 -82
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +265 -44
- package/dist/src/core/index.d.ts +265 -44
- package/dist/src/core/index.js +1308 -83
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +816 -152
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +723 -391
- package/dist/src/server/index.d.ts +723 -391
- package/dist/src/server/index.js +812 -156
- package/dist/src/server/index.js.map +1 -1
- package/package.json +10 -9
package/dist/src/core/index.cjs
CHANGED
|
@@ -4,7 +4,7 @@ let _orkestrel_template = require("@orkestrel/template");
|
|
|
4
4
|
let _orkestrel_emitter = require("@orkestrel/emitter");
|
|
5
5
|
var package_default = {
|
|
6
6
|
name: "@orkestrel/scaffold",
|
|
7
|
-
version: "0.0.
|
|
7
|
+
version: "0.0.50",
|
|
8
8
|
description: "Scaffold workspaces with five commands: new, audit, repair, catalog, and overwrite.",
|
|
9
9
|
keywords: [
|
|
10
10
|
"audit",
|
|
@@ -84,23 +84,24 @@ var package_default = {
|
|
|
84
84
|
"build:src:server": "vite build --config configs/src/vite.server.config.ts && npm run copy dist/src/server/index.d.ts dist/src/server/index.d.cts",
|
|
85
85
|
"build:src:bin": "vite build --config configs/src/vite.bin.config.ts",
|
|
86
86
|
"build:host": "node -e \"import('./dist/src/server/index.js').then((m)=>{const n=m.stageHost(process.cwd(),'dist/host').length;console.log('build-host: staged '+n+' file(s) into dist/host')})\"",
|
|
87
|
+
"build:inventory": "node -e \"import('./dist/src/server/index.js').then((m)=>{const p=process.argv[1]??'host.json',n=m.stageInventory(process.cwd(),p).entries.length;console.log('build-inventory: staged '+n+' file(s) into '+p)})\"",
|
|
87
88
|
"prepack": "npm run build",
|
|
88
89
|
"prepublishOnly": "npm run format:check && npm run lint:check && npm run check && npm run build && npm test && npm run test:distribution -- --mode release"
|
|
89
90
|
},
|
|
90
91
|
dependencies: {
|
|
91
|
-
"@orkestrel/console": "^0.0.
|
|
92
|
+
"@orkestrel/console": "^0.0.10",
|
|
92
93
|
"@orkestrel/contract": "^0.0.13",
|
|
93
|
-
"@orkestrel/emitter": "^0.0.
|
|
94
|
-
"@orkestrel/markdown": "^0.0.
|
|
94
|
+
"@orkestrel/emitter": "^0.0.8",
|
|
95
|
+
"@orkestrel/markdown": "^0.0.10",
|
|
95
96
|
"@orkestrel/process": "^0.0.6",
|
|
96
|
-
"@orkestrel/template": "^0.0.
|
|
97
|
+
"@orkestrel/template": "^0.0.5"
|
|
97
98
|
},
|
|
98
99
|
devDependencies: {
|
|
99
100
|
"@microsoft/api-extractor": "^7.59.0",
|
|
100
|
-
"@orkestrel/guide": "^0.0.
|
|
101
|
-
"@orkestrel/html": "^0.0.
|
|
102
|
-
"@orkestrel/probe": "^0.0.
|
|
103
|
-
"@orkestrel/test": "^0.0.
|
|
101
|
+
"@orkestrel/guide": "^0.0.13",
|
|
102
|
+
"@orkestrel/html": "^0.0.5",
|
|
103
|
+
"@orkestrel/probe": "^0.0.3",
|
|
104
|
+
"@orkestrel/test": "^0.0.11",
|
|
104
105
|
"@types/node": "^26.2.0",
|
|
105
106
|
"@vitest/browser-playwright": "^4.1.11",
|
|
106
107
|
"oxfmt": "^0.64.0",
|
|
@@ -252,6 +253,8 @@ var HOST_PATHS = Object.freeze([
|
|
|
252
253
|
"guides/guide.md",
|
|
253
254
|
"guides/scaffold.md"
|
|
254
255
|
]);
|
|
256
|
+
/** The repository-relative path where the committed vendored-file inventory is served. */
|
|
257
|
+
var HOST_INVENTORY_PATH = "host.json";
|
|
255
258
|
/**
|
|
256
259
|
* The vendored paths whose present bytes belong to each workspace, frozen.
|
|
257
260
|
*
|
|
@@ -322,10 +325,21 @@ var SERVICE_SCRIPT_PATH = "scripts/service.sh";
|
|
|
322
325
|
var GLOBAL_SETUP_PATH = "tests/setupGlobal.ts";
|
|
323
326
|
/** The guide-parity proof whose presence selects the planned `guides` project. */
|
|
324
327
|
var GUIDES_TEST_PATH = "tests/guides.test.ts";
|
|
325
|
-
/** The packed-package proof
|
|
328
|
+
/** The generated packed-package proof every publishing workspace is planned at. */
|
|
326
329
|
var DISTRIBUTION_TEST_PATH = "tests/distribution.test.ts";
|
|
330
|
+
/**
|
|
331
|
+
* The `prepublishOnly` row that runs the packed-package proof against a real registry.
|
|
332
|
+
*
|
|
333
|
+
* @remarks
|
|
334
|
+
* The proof reads `import.meta.env.MODE`, so without `--mode release` it passes
|
|
335
|
+
* on an unreachable registry instead of failing. The row therefore has one home
|
|
336
|
+
* and both the script compiler and the manifest region writer read it from here.
|
|
337
|
+
*/
|
|
338
|
+
var RELEASE_PROOF_COMMAND = "npm run test:distribution -- --mode release";
|
|
327
339
|
/** The cross-environment composition proof whose presence makes a workspace `integration`. */
|
|
328
340
|
var INTEGRATION_TEST_PATH = "tests/integration.test.ts";
|
|
341
|
+
/** The manifest path every compiler plan emits with birth ownership. */
|
|
342
|
+
var MANIFEST_PATH = "package.json";
|
|
329
343
|
/** The official-tooling drift proof whose presence makes a workspace `conformance`. */
|
|
330
344
|
var CONFORMANCE_TEST_PATH = "tests/conformance.test.ts";
|
|
331
345
|
/** The live-service readiness module whose presence makes a workspace `service`. */
|
|
@@ -400,6 +414,8 @@ var MAX_NAME_LENGTH = 203;
|
|
|
400
414
|
var MAX_DEPENDENCY_NAME_LENGTH = 214;
|
|
401
415
|
/** Maximum length of one declared package range. */
|
|
402
416
|
var MAX_RANGE_LENGTH = 2048;
|
|
417
|
+
/** Maximum length of one manifest script name or command. */
|
|
418
|
+
var MAX_SCRIPT_LENGTH = 4096;
|
|
403
419
|
/** Maximum length of one path, matching the longest a supported filesystem accepts. */
|
|
404
420
|
var MAX_PATH_LENGTH = 32767;
|
|
405
421
|
/** Maximum items accepted in one public collection. */
|
|
@@ -769,8 +785,8 @@ const resolve = {
|
|
|
769
785
|
}
|
|
770
786
|
}
|
|
771
787
|
|
|
772
|
-
export function appBrowser(): UserConfig {
|
|
773
|
-
return applicationBrowser(false)
|
|
788
|
+
export function appBrowser(options?: UserConfig): UserConfig {
|
|
789
|
+
return mergeConfig(applicationBrowser(false), options ?? {})
|
|
774
790
|
}
|
|
775
791
|
{{showcaseFactory}}`,
|
|
776
792
|
server: `export const appServer = (options?: UserConfig): UserConfig =>
|
|
@@ -1588,6 +1604,865 @@ describe('bin entry', () => {
|
|
|
1588
1604
|
})
|
|
1589
1605
|
})
|
|
1590
1606
|
`,
|
|
1607
|
+
distribution: Object.freeze({
|
|
1608
|
+
proof: `// The artifact a consumer installs, measured rather than described. This workspace
|
|
1609
|
+
// is packed and installed into a throwaway consumer, and every following claim is read
|
|
1610
|
+
// off that installed tree: the exports map it publishes, the declarations it ships,
|
|
1611
|
+
// and the module objects a real runtime hands a consumer. Nothing here names this
|
|
1612
|
+
// package, one of its exports, or how many there are, so the proof stays true as
|
|
1613
|
+
// the published surface moves.
|
|
1614
|
+
{{types}}import type { SpawnSyncReturns } from 'node:child_process'
|
|
1615
|
+
import type { TestContext } from 'vitest'
|
|
1616
|
+
import { spawnSync } from 'node:child_process'
|
|
1617
|
+
import {
|
|
1618
|
+
existsSync,
|
|
1619
|
+
mkdirSync,
|
|
1620
|
+
mkdtempSync,
|
|
1621
|
+
readdirSync,
|
|
1622
|
+
readFileSync,
|
|
1623
|
+
rmSync,
|
|
1624
|
+
statSync,
|
|
1625
|
+
writeFileSync,
|
|
1626
|
+
} from 'node:fs'
|
|
1627
|
+
{{transport}}import { tmpdir } from 'node:os'
|
|
1628
|
+
import { dirname, join, resolve } from 'node:path'
|
|
1629
|
+
import { fileURLToPath } from 'node:url'
|
|
1630
|
+
{{launcher}}import ts from 'typescript'
|
|
1631
|
+
import { afterAll, describe, expect, it } from 'vitest'
|
|
1632
|
+
|
|
1633
|
+
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
1634
|
+
const NPM = process.platform === 'win32' ? 'npm.cmd' : 'npm'
|
|
1635
|
+
// Windows needs a shell to launch a \`.cmd\`: Node refuses one directly since the
|
|
1636
|
+
// batch-argument hardening, and \`spawnSync\` returns \`EINVAL\` with a null status
|
|
1637
|
+
// rather than an exit code a caller can read. Every following argument is a literal or
|
|
1638
|
+
// a path this file built, so the shell has nothing to escape.
|
|
1639
|
+
const SHELL = process.platform === 'win32'
|
|
1640
|
+
// \`prepublishOnly\` runs this proof as \`npm run test:distribution -- --mode release\`.
|
|
1641
|
+
// Release is the publish gate, so evidence it cannot obtain fails there and skips
|
|
1642
|
+
// everywhere else: a gate that passes on missing evidence proves nothing.
|
|
1643
|
+
const RELEASE = import.meta.env.MODE === 'release'
|
|
1644
|
+
// The built output directory a browser face is published from. Every selection here
|
|
1645
|
+
// reads this prefix off the export TARGET and never off the subpath name. A
|
|
1646
|
+
// workspace whose only published face is the browser one publishes that face at the
|
|
1647
|
+
// root subpath, so a rule keyed on the subpath name drives a browser bundle through
|
|
1648
|
+
// Node and the miss is silent.
|
|
1649
|
+
const BROWSER_OUTPUT = './dist/src/browser/'
|
|
1650
|
+
const ABSENT_SUBPATH = '/no-subpath-is-published-under-this-name'
|
|
1651
|
+
const PING = ['ping', '--fetch-retries=0', '--fetch-timeout=5000', '--loglevel=silent']
|
|
1652
|
+
const ESM_DRIVER = 'drive.mjs'
|
|
1653
|
+
const CJS_DRIVER = 'drive.cjs'
|
|
1654
|
+
const CONSUMER_MANIFEST = \`{ "name": "distribution-consumer", "private": true, "type": "module" }\\n\`
|
|
1655
|
+
const ESM_DRIVER_SOURCE = \`const entry = await import(process.argv[2])
|
|
1656
|
+
process.stdout.write(JSON.stringify(Object.keys(entry).sort()))
|
|
1657
|
+
\`
|
|
1658
|
+
const CJS_DRIVER_SOURCE = \`const entry = require(process.argv[2])
|
|
1659
|
+
process.stdout.write(JSON.stringify(Object.keys(entry).sort()))
|
|
1660
|
+
\`
|
|
1661
|
+
|
|
1662
|
+
// The extensions a JavaScript handler loads as modules. Node loads a native addon
|
|
1663
|
+
// through its addon handler instead, so that extension is named separately.
|
|
1664
|
+
const MODULE_EXTENSIONS = ['.js', '.mjs', '.cjs']
|
|
1665
|
+
const ADDON_EXTENSION = '.node'
|
|
1666
|
+
// The extensions a declaration file carries. A \`require\` condition declares
|
|
1667
|
+
// \`.d.cts\` and an ESM-only one \`.d.mts\`, so the \`.d.ts\` spelling alone does not
|
|
1668
|
+
// name them.
|
|
1669
|
+
const DECLARATION_EXTENSIONS = ['.d.ts', '.d.cts', '.d.mts']
|
|
1670
|
+
type Format = 'module' | 'commonjs'
|
|
1671
|
+
|
|
1672
|
+
// The Node import target is resolved with the conditions that driver supplies. The
|
|
1673
|
+
// CommonJS compile probe is selected from its declaration's format, and its runtime
|
|
1674
|
+
// drive loads the same subpath through Node's require resolver. Vite's production
|
|
1675
|
+
// client build enables its module and browser conditions.
|
|
1676
|
+
const RUNTIME_CONDITIONS = Object.freeze({
|
|
1677
|
+
module: Object.freeze(['node-addons', 'node', 'import', 'module-sync']),
|
|
1678
|
+
commonjs: Object.freeze(['node-addons', 'node', 'require', 'module-sync']),
|
|
1679
|
+
browser: Object.freeze(['module', 'browser', 'production', 'import']),
|
|
1680
|
+
})
|
|
1681
|
+
// TypeScript's Node resolutions add \`node\` to the format condition. Its bundler
|
|
1682
|
+
// resolution does not, so a browser drive compares against the declaration a bundler
|
|
1683
|
+
// consumer reads rather than borrowing the Node declaration.
|
|
1684
|
+
const BUNDLER_CONDITIONS = Object.freeze({
|
|
1685
|
+
module: ['types', 'import'],
|
|
1686
|
+
commonjs: ['types', 'require'],
|
|
1687
|
+
})
|
|
1688
|
+
const DECLARATION_CONDITIONS = Object.freeze({
|
|
1689
|
+
module: ['types', 'node', 'import'],
|
|
1690
|
+
commonjs: ['types', 'node', 'require'],
|
|
1691
|
+
browser: BUNDLER_CONDITIONS.module,
|
|
1692
|
+
})
|
|
1693
|
+
|
|
1694
|
+
interface Resolution {
|
|
1695
|
+
readonly label: string
|
|
1696
|
+
readonly resolution: ts.ModuleResolutionKind
|
|
1697
|
+
readonly module: ts.ModuleKind
|
|
1698
|
+
readonly conditions: Readonly<Record<Format, readonly string[]>>
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
interface TargetResolution {
|
|
1702
|
+
readonly target: string
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
// Each compile driver carries the conditions TypeScript applies for its resolution
|
|
1706
|
+
// and importing format. A \`require\`-only subpath therefore stays in each CommonJS
|
|
1707
|
+
// probe that can resolve it.
|
|
1708
|
+
const RESOLUTIONS: readonly Resolution[] = [
|
|
1709
|
+
{
|
|
1710
|
+
label: 'node16',
|
|
1711
|
+
resolution: ts.ModuleResolutionKind.Node16,
|
|
1712
|
+
module: ts.ModuleKind.Node16,
|
|
1713
|
+
conditions: DECLARATION_CONDITIONS,
|
|
1714
|
+
},
|
|
1715
|
+
{
|
|
1716
|
+
label: 'nodenext',
|
|
1717
|
+
resolution: ts.ModuleResolutionKind.NodeNext,
|
|
1718
|
+
module: ts.ModuleKind.NodeNext,
|
|
1719
|
+
conditions: DECLARATION_CONDITIONS,
|
|
1720
|
+
},
|
|
1721
|
+
{
|
|
1722
|
+
label: 'bundler',
|
|
1723
|
+
resolution: ts.ModuleResolutionKind.Bundler,
|
|
1724
|
+
module: ts.ModuleKind.ESNext,
|
|
1725
|
+
conditions: BUNDLER_CONDITIONS,
|
|
1726
|
+
},
|
|
1727
|
+
]
|
|
1728
|
+
|
|
1729
|
+
const FORMATS: ReadonlyArray<readonly [extension: string, format: Format]> = [
|
|
1730
|
+
['ts', 'module'],
|
|
1731
|
+
['cts', 'commonjs'],
|
|
1732
|
+
]
|
|
1733
|
+
|
|
1734
|
+
// One published subpath, resolved to what this proof can drive: the specifier a
|
|
1735
|
+
// consumer writes, the declarations its consumer formats name, whether its target
|
|
1736
|
+
// is a browser bundle, and whether it answers \`import\` and \`require\` at all.
|
|
1737
|
+
interface Entry {
|
|
1738
|
+
readonly subpath: string
|
|
1739
|
+
readonly specifier: string
|
|
1740
|
+
readonly mapping: unknown
|
|
1741
|
+
readonly declaration: {
|
|
1742
|
+
readonly module: string | undefined
|
|
1743
|
+
readonly commonjs: string | undefined
|
|
1744
|
+
readonly browser: string | undefined
|
|
1745
|
+
}
|
|
1746
|
+
readonly browser: boolean
|
|
1747
|
+
readonly module: boolean
|
|
1748
|
+
readonly commonjs: boolean
|
|
1749
|
+
readonly required: boolean
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
// The installed tree every claim is read from. Every subpath the exports map names
|
|
1753
|
+
// lands in exactly one of \`entries\`, \`undeclared\`, and \`excluded\`, so a subpath this
|
|
1754
|
+
// proof cannot drive is reported rather than dropped.
|
|
1755
|
+
interface Stage {
|
|
1756
|
+
readonly consumer: string
|
|
1757
|
+
readonly installed: string
|
|
1758
|
+
readonly archives: readonly string[]
|
|
1759
|
+
readonly entries: readonly Entry[]
|
|
1760
|
+
readonly subpaths: readonly string[]
|
|
1761
|
+
readonly undeclared: readonly string[]
|
|
1762
|
+
readonly excluded: readonly string[]
|
|
1763
|
+
readonly targets: readonly string[]
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
function isRecord(value: unknown): value is Readonly<Record<string, unknown>> {
|
|
1767
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
function isNames(value: unknown): value is readonly string[] {
|
|
1771
|
+
return Array.isArray(value) && value.every((name) => typeof name === 'string')
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1774
|
+
// A fallback list, which is what Node reads an array in an exports entry as. The
|
|
1775
|
+
// narrowing is what the following walkers need: \`Array.isArray\` widens an \`unknown\`
|
|
1776
|
+
// member to \`any\`, and an entry read that way is not read at all.
|
|
1777
|
+
function isList(value: unknown): value is readonly unknown[] {
|
|
1778
|
+
return Array.isArray(value)
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
// Whether a string is a valid package target. Node rejects a target outside the
|
|
1782
|
+
// package and a target containing a dot, parent, or node_modules segment during
|
|
1783
|
+
// package-target resolution. A later module-resolution failure is not the same
|
|
1784
|
+
// thing: an array falls through the former and keeps the latter.
|
|
1785
|
+
function isPackageTarget(target: string): boolean {
|
|
1786
|
+
if (!target.startsWith('./')) return false
|
|
1787
|
+
for (const segment of target.slice(2).split(/[\\\\/]/u)) {
|
|
1788
|
+
let decoded = segment
|
|
1789
|
+
try {
|
|
1790
|
+
decoded = decodeURIComponent(segment)
|
|
1791
|
+
} catch {}
|
|
1792
|
+
const normalized = decoded.toLowerCase()
|
|
1793
|
+
if (normalized === '.' || normalized === '..' || normalized === 'node_modules') return false
|
|
1794
|
+
}
|
|
1795
|
+
return true
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
function readJson(path: string): unknown {
|
|
1799
|
+
const parsed: unknown = JSON.parse(readFileSync(path, 'utf8'))
|
|
1800
|
+
return parsed
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
function readManifestName(path: string): string {
|
|
1804
|
+
const manifest = readJson(path)
|
|
1805
|
+
if (!isRecord(manifest) || typeof manifest.name !== 'string') {
|
|
1806
|
+
throw new Error(\`The manifest at \${path} declares no package name\`)
|
|
1807
|
+
}
|
|
1808
|
+
return manifest.name
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
function writeFile(path: string, content: string): void {
|
|
1812
|
+
mkdirSync(dirname(path), { recursive: true })
|
|
1813
|
+
writeFileSync(path, content)
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
function readOutput(result: SpawnSyncReturns<string>): string {
|
|
1817
|
+
return \`\${result.stdout ?? ''}\${result.stderr ?? ''}\`.trim()
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
function runNpm(args: readonly string[], cwd: string): SpawnSyncReturns<string> {
|
|
1821
|
+
return spawnSync(NPM, [...args], {
|
|
1822
|
+
cwd,
|
|
1823
|
+
encoding: 'utf8',
|
|
1824
|
+
env: { ...process.env, npm_config_cache: CACHE },
|
|
1825
|
+
shell: SHELL,
|
|
1826
|
+
windowsHide: true,
|
|
1827
|
+
})
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
function runNode(args: readonly string[], cwd: string): SpawnSyncReturns<string> {
|
|
1831
|
+
return spawnSync(process.execPath, [...args], { cwd, encoding: 'utf8', windowsHide: true })
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
// Node's own condition matching, read in declaration order.
|
|
1835
|
+
function resolvePackageTarget(
|
|
1836
|
+
entry: unknown,
|
|
1837
|
+
conditions: readonly string[],
|
|
1838
|
+
): TargetResolution | undefined {
|
|
1839
|
+
if (typeof entry === 'string') return { target: entry }
|
|
1840
|
+
if (isList(entry)) {
|
|
1841
|
+
for (const member of entry) {
|
|
1842
|
+
const resolved = resolvePackageTarget(member, conditions)
|
|
1843
|
+
if (resolved !== undefined && isPackageTarget(resolved.target)) return resolved
|
|
1844
|
+
}
|
|
1845
|
+
return undefined
|
|
1846
|
+
}
|
|
1847
|
+
if (!isRecord(entry)) return undefined
|
|
1848
|
+
for (const [condition, nested] of Object.entries(entry)) {
|
|
1849
|
+
if (condition !== 'default' && !conditions.includes(condition)) continue
|
|
1850
|
+
const resolved = resolvePackageTarget(nested, conditions)
|
|
1851
|
+
if (resolved !== undefined) return resolved
|
|
1852
|
+
}
|
|
1853
|
+
return undefined
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
// A flat entry, a condition-nested entry, and a fallback list all resolve through
|
|
1857
|
+
// one walker. An entry may declare \`types\` beside \`default\` at its top level
|
|
1858
|
+
// rather than inside \`import\`, so a fixed \`entry.import.types\` lookup is not
|
|
1859
|
+
// equivalent to condition resolution.
|
|
1860
|
+
function resolveTarget(entry: unknown, conditions: readonly string[]): string | undefined {
|
|
1861
|
+
return resolvePackageTarget(entry, conditions)?.target
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
// Whether a path is a physical file. TypeScript's file-existence check refuses a
|
|
1865
|
+
// directory at the same spelling and continues to the outer package scope.
|
|
1866
|
+
function matchesFile(path: string): boolean {
|
|
1867
|
+
try {
|
|
1868
|
+
return statSync(path).isFile()
|
|
1869
|
+
} catch {
|
|
1870
|
+
return false
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
// TypeScript resolves a declaration target by accepting an existing declaration
|
|
1875
|
+
// directly or by substituting beside a JavaScript target. A missing target leaves
|
|
1876
|
+
// the containing condition or fallback list unresolved, so the walk continues.
|
|
1877
|
+
function targetToDeclaration(target: string, installed: string): string | undefined {
|
|
1878
|
+
if (!isPackageTarget(target)) return undefined
|
|
1879
|
+
let declaration = target
|
|
1880
|
+
if (target.endsWith('.cjs')) declaration = \`\${target.slice(0, -4)}.d.cts\`
|
|
1881
|
+
else if (target.endsWith('.mjs')) declaration = \`\${target.slice(0, -4)}.d.mts\`
|
|
1882
|
+
else if (target.endsWith('.js')) declaration = \`\${target.slice(0, -3)}.d.ts\`
|
|
1883
|
+
else if (!isDeclaration(target)) return undefined
|
|
1884
|
+
return matchesFile(join(installed, declaration)) ? declaration : undefined
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
// The declaration TypeScript resolves through one importing format's conditions.
|
|
1888
|
+
// Condition objects keep manifest order, and arrays keep fallback order.
|
|
1889
|
+
function resolveDeclaration(
|
|
1890
|
+
entry: unknown,
|
|
1891
|
+
conditions: readonly string[],
|
|
1892
|
+
installed: string,
|
|
1893
|
+
): string | undefined {
|
|
1894
|
+
if (typeof entry === 'string') return targetToDeclaration(entry, installed)
|
|
1895
|
+
if (isList(entry)) {
|
|
1896
|
+
for (const member of entry) {
|
|
1897
|
+
const resolved = resolveDeclaration(member, conditions, installed)
|
|
1898
|
+
if (resolved !== undefined) return resolved
|
|
1899
|
+
}
|
|
1900
|
+
return undefined
|
|
1901
|
+
}
|
|
1902
|
+
if (!isRecord(entry)) return undefined
|
|
1903
|
+
for (const [condition, nested] of Object.entries(entry)) {
|
|
1904
|
+
if (condition !== 'default' && !conditions.includes(condition)) continue
|
|
1905
|
+
const resolved = resolveDeclaration(nested, conditions, installed)
|
|
1906
|
+
if (resolved !== undefined) return resolved
|
|
1907
|
+
}
|
|
1908
|
+
return undefined
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
// The nearest package scope that decides a \`.d.ts\` declaration's module format. A
|
|
1912
|
+
// physical nested manifest starts a scope even when it omits \`type\` or cannot be
|
|
1913
|
+
// parsed. A directory at that spelling is not a manifest, so the walk continues.
|
|
1914
|
+
function readPackageType(installed: string, target: string): unknown {
|
|
1915
|
+
let directory = dirname(join(installed, target))
|
|
1916
|
+
while (true) {
|
|
1917
|
+
const path = join(directory, 'package.json')
|
|
1918
|
+
if (matchesFile(path)) {
|
|
1919
|
+
try {
|
|
1920
|
+
const manifest = readJson(path)
|
|
1921
|
+
return isRecord(manifest) ? manifest.type : undefined
|
|
1922
|
+
} catch {
|
|
1923
|
+
return undefined
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
if (directory === installed) return undefined
|
|
1927
|
+
const parent = dirname(directory)
|
|
1928
|
+
if (parent === directory) return undefined
|
|
1929
|
+
directory = parent
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1933
|
+
// Whether the declaration selected by a typed CommonJS consumer admits that entry
|
|
1934
|
+
// to its compile probe. A \`.d.cts\` declaration admits and a \`.d.mts\`
|
|
1935
|
+
// declaration refuses. A \`.d.ts\` declaration takes its own nearest package scope.
|
|
1936
|
+
// Runtime target format remains the runtime drive's separate question.
|
|
1937
|
+
function resolvesCommonJS(entry: unknown, installed: string): boolean {
|
|
1938
|
+
const declaration = resolveDeclaration(entry, DECLARATION_CONDITIONS.commonjs, installed)
|
|
1939
|
+
if (declaration === undefined) return false
|
|
1940
|
+
if (declaration.endsWith('.d.cts')) return true
|
|
1941
|
+
if (declaration.endsWith('.d.mts')) return false
|
|
1942
|
+
return declaration.endsWith('.d.ts') && readPackageType(installed, declaration) !== 'module'
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
// Every target an entry names under any condition. A fallback list omits members
|
|
1946
|
+
// Node rejects during package-target validation, because no reader can take them.
|
|
1947
|
+
function collectTargets(entry: unknown): readonly string[] {
|
|
1948
|
+
if (typeof entry === 'string') return [entry]
|
|
1949
|
+
if (isList(entry)) return entry.flatMap(collectTargets).filter(isPackageTarget)
|
|
1950
|
+
if (!isRecord(entry)) return []
|
|
1951
|
+
return Object.values(entry).flatMap((nested) => collectTargets(nested))
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1954
|
+
// Whether a target is a file a runtime loads for its names, which is what a
|
|
1955
|
+
// declaration is owed for. The extension on the target's own file name decides it,
|
|
1956
|
+
// and a name carrying no extension is code: \`require\` reads such a file through its
|
|
1957
|
+
// JavaScript handler, so an extensionless target loads and publishes names. Node
|
|
1958
|
+
// loads \`.node\` through its native-addon handler. Every other extension is an asset
|
|
1959
|
+
// a consumer reads rather than imports — a stylesheet, a WebAssembly binary, the
|
|
1960
|
+
// \`"./package.json"\` manifest pointer, and a declaration alike.
|
|
1961
|
+
// The cost is an extensionless file published for a reader, such as a \`LICENSE\`:
|
|
1962
|
+
// that target reports undeclared until it is given an extension or a declaration.
|
|
1963
|
+
function isModule(target: string): boolean {
|
|
1964
|
+
const name = target.slice(target.lastIndexOf('/') + 1)
|
|
1965
|
+
const dot = name.lastIndexOf('.')
|
|
1966
|
+
if (name.endsWith(ADDON_EXTENSION)) return true
|
|
1967
|
+
return dot === -1 || MODULE_EXTENSIONS.includes(name.slice(dot))
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
// Whether a resolved target is a declaration rather than the JavaScript a
|
|
1971
|
+
// \`default\` branch answers with when the entry declares no \`types\` condition.
|
|
1972
|
+
function isDeclaration(target: string): boolean {
|
|
1973
|
+
return DECLARATION_EXTENSIONS.some((extension) => target.endsWith(extension))
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1976
|
+
// The declarations the Node module, Node CommonJS, and browser drives compare
|
|
1977
|
+
// against. Each field uses the conditions of the TypeScript consumer paired with
|
|
1978
|
+
// that runtime. A JavaScript target resolves through TypeScript's adjacent
|
|
1979
|
+
// declaration substitution rather than standing in for the declaration itself.
|
|
1980
|
+
function readDeclaration(entry: unknown, installed: string): Entry['declaration'] {
|
|
1981
|
+
return {
|
|
1982
|
+
module: resolveDeclaration(entry, DECLARATION_CONDITIONS.module, installed),
|
|
1983
|
+
commonjs: resolveDeclaration(entry, DECLARATION_CONDITIONS.commonjs, installed),
|
|
1984
|
+
browser: resolveDeclaration(entry, DECLARATION_CONDITIONS.browser, installed),
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
// The entries one compile driver can resolve under its own conditions.
|
|
1989
|
+
function selectEntries(entries: readonly Entry[], conditions: readonly string[]): readonly Entry[] {
|
|
1990
|
+
return entries.filter(
|
|
1991
|
+
(entry) =>
|
|
1992
|
+
resolveTarget(entry.mapping, conditions) !== undefined &&
|
|
1993
|
+
(!conditions.includes('require') || entry.commonjs),
|
|
1994
|
+
)
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
// Require-loadable entries that declare CommonJS support but a typed CommonJS
|
|
1998
|
+
// consumer cannot compile against. A default branch resolving under the require
|
|
1999
|
+
// condition set makes no CommonJS claim.
|
|
2000
|
+
function selectUntypable(entries: readonly Entry[]): readonly Entry[] {
|
|
2001
|
+
return entries.filter(
|
|
2002
|
+
(entry) =>
|
|
2003
|
+
entry.required &&
|
|
2004
|
+
isRecord(entry.mapping) &&
|
|
2005
|
+
Object.hasOwn(entry.mapping, 'require') &&
|
|
2006
|
+
!entry.commonjs,
|
|
2007
|
+
)
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
// The value exports a declaration publishes, read through the compiler's checker
|
|
2011
|
+
// over the module symbol rather than off the declaration text. An alias resolves to
|
|
2012
|
+
// what it names, so a re-export counts as the thing it re-exports, and a type-only
|
|
2013
|
+
// symbol is dropped because no runtime publishes one.
|
|
2014
|
+
function readDeclaredExports(declaration: string): readonly string[] {
|
|
2015
|
+
const program = ts.createProgram([declaration], {
|
|
2016
|
+
module: ts.ModuleKind.ESNext,
|
|
2017
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
2018
|
+
noEmit: true,
|
|
2019
|
+
skipLibCheck: true,
|
|
2020
|
+
target: ts.ScriptTarget.ESNext,
|
|
2021
|
+
})
|
|
2022
|
+
const source = program.getSourceFile(declaration)
|
|
2023
|
+
if (source === undefined) throw new Error(\`The declaration \${declaration} was not read\`)
|
|
2024
|
+
const checker = program.getTypeChecker()
|
|
2025
|
+
const symbol = checker.getSymbolAtLocation(source)
|
|
2026
|
+
if (symbol === undefined) throw new Error(\`\${declaration} declares no module symbol\`)
|
|
2027
|
+
const values: string[] = []
|
|
2028
|
+
for (const exported of checker.getExportsOfModule(symbol)) {
|
|
2029
|
+
const direct = (exported.flags & ts.SymbolFlags.Alias) === 0
|
|
2030
|
+
const resolved = direct ? exported : checker.getAliasedSymbol(exported)
|
|
2031
|
+
if ((resolved.flags & ts.SymbolFlags.Value) !== 0) values.push(exported.getName())
|
|
2032
|
+
}
|
|
2033
|
+
return [...values].sort()
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
// The diagnostics a consumer compiling against the installed declarations reports,
|
|
2037
|
+
// flattened to their messages so a failure names what the consumer could not do.
|
|
2038
|
+
function compileConsumer(
|
|
2039
|
+
entry: string,
|
|
2040
|
+
resolution: ts.ModuleResolutionKind,
|
|
2041
|
+
module: ts.ModuleKind,
|
|
2042
|
+
): readonly string[] {
|
|
2043
|
+
const program = ts.createProgram([entry], {
|
|
2044
|
+
module,
|
|
2045
|
+
moduleResolution: resolution,
|
|
2046
|
+
noEmit: true,
|
|
2047
|
+
skipLibCheck: true,
|
|
2048
|
+
strict: true,
|
|
2049
|
+
target: ts.ScriptTarget.ESNext,
|
|
2050
|
+
})
|
|
2051
|
+
return ts
|
|
2052
|
+
.getPreEmitDiagnostics(program)
|
|
2053
|
+
.map((diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, ' '))
|
|
2054
|
+
}
|
|
2055
|
+
|
|
2056
|
+
// One consumer module importing every installed entry, written where its own
|
|
2057
|
+
// resolution finds the installed package.
|
|
2058
|
+
function writeConsumerProbe(stage: Stage, path: string, specifiers: readonly string[]): string {
|
|
2059
|
+
const names: string[] = []
|
|
2060
|
+
const bindings: string[] = []
|
|
2061
|
+
for (const [index, specifier] of specifiers.entries()) {
|
|
2062
|
+
const binding = \`entry\${String(index)}\`
|
|
2063
|
+
names.push(binding)
|
|
2064
|
+
bindings.push(\`import * as \${binding} from \${JSON.stringify(specifier)}\`)
|
|
2065
|
+
}
|
|
2066
|
+
const target = join(stage.consumer, path)
|
|
2067
|
+
writeFile(target, \`\${bindings.join('\\n')}\\nexport const surface = [\${names.join(', ')}]\\n\`)
|
|
2068
|
+
return target
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
// The runtime key set a real process reads off one installed entry under one
|
|
2072
|
+
// condition. The driver is a file rather than an \`--eval\` string, so the specifier
|
|
2073
|
+
// travels as an argument and nothing needs escaping.
|
|
2074
|
+
function driveRuntime(stage: Stage, specifier: string, driver: string): readonly string[] {
|
|
2075
|
+
const result = runNode([join(stage.consumer, driver), specifier], stage.consumer)
|
|
2076
|
+
if (result.status !== 0) {
|
|
2077
|
+
throw new Error(\`Loading \${specifier} from the consumer failed: \${readOutput(result)}\`)
|
|
2078
|
+
}
|
|
2079
|
+
const published: unknown = JSON.parse(result.stdout)
|
|
2080
|
+
if (!isNames(published)) throw new Error(\`The driver printed no name list for \${specifier}\`)
|
|
2081
|
+
return published
|
|
2082
|
+
}
|
|
2083
|
+
{{helpers}}
|
|
2084
|
+
// Pack this workspace, install the archive into an isolated consumer, and read the
|
|
2085
|
+
// published surface back off the installed tree. Every later claim reads this
|
|
2086
|
+
// result, so a failure here is raised where it happens rather than once per entry.
|
|
2087
|
+
function buildStage(): Stage {
|
|
2088
|
+
const packed = join(SCRATCH, 'packed')
|
|
2089
|
+
const consumer = join(SCRATCH, 'consumer')
|
|
2090
|
+
mkdirSync(packed, { recursive: true })
|
|
2091
|
+
const pack = runNpm(['pack', '--ignore-scripts', '--pack-destination', packed], ROOT)
|
|
2092
|
+
if (pack.status !== 0) throw new Error(\`npm pack refused this workspace: \${readOutput(pack)}\`)
|
|
2093
|
+
const archives = readdirSync(packed).filter((name) => name.endsWith('.tgz'))
|
|
2094
|
+
const archive = archives[0]
|
|
2095
|
+
if (archives.length !== 1 || archive === undefined) {
|
|
2096
|
+
throw new Error(\`npm pack wrote no single archive: \${archives.join(', ')}\`)
|
|
2097
|
+
}
|
|
2098
|
+
writeFile(join(consumer, 'package.json'), CONSUMER_MANIFEST)
|
|
2099
|
+
writeFile(join(consumer, ESM_DRIVER), ESM_DRIVER_SOURCE)
|
|
2100
|
+
writeFile(join(consumer, CJS_DRIVER), CJS_DRIVER_SOURCE)
|
|
2101
|
+
const install = runNpm(
|
|
2102
|
+
['install', '--ignore-scripts', '--no-audit', '--no-fund', join(packed, archive)],
|
|
2103
|
+
consumer,
|
|
2104
|
+
)
|
|
2105
|
+
if (install.status !== 0) {
|
|
2106
|
+
throw new Error(\`Installing the packed archive failed: \${readOutput(install)}\`)
|
|
2107
|
+
}
|
|
2108
|
+
const name = readManifestName(join(ROOT, 'package.json'))
|
|
2109
|
+
const installed = join(consumer, 'node_modules', ...name.split('/'))
|
|
2110
|
+
const manifest = readJson(join(installed, 'package.json'))
|
|
2111
|
+
if (!isRecord(manifest) || !isRecord(manifest.exports)) {
|
|
2112
|
+
throw new Error('The installed manifest publishes no exports map')
|
|
2113
|
+
}
|
|
2114
|
+
const entries: Entry[] = []
|
|
2115
|
+
const targets: string[] = []
|
|
2116
|
+
const subpaths: string[] = []
|
|
2117
|
+
const undeclared: string[] = []
|
|
2118
|
+
const excluded: string[] = []
|
|
2119
|
+
for (const [subpath, entry] of Object.entries(manifest.exports)) {
|
|
2120
|
+
const files = collectTargets(entry)
|
|
2121
|
+
targets.push(...files)
|
|
2122
|
+
subpaths.push(subpath)
|
|
2123
|
+
const declaration = readDeclaration(entry, installed)
|
|
2124
|
+
// A subpath resolving no declaration is partitioned rather than dropped. It is a
|
|
2125
|
+
// defect when a runtime loads one of its targets for names, because a consumer
|
|
2126
|
+
// importing it compiles against nothing under \`node16\`. It is an excluded
|
|
2127
|
+
// publication otherwise: the \`"./package.json"\` manifest pointer and a stylesheet
|
|
2128
|
+
// are published for a reader rather than an importer.
|
|
2129
|
+
if (
|
|
2130
|
+
declaration.module === undefined &&
|
|
2131
|
+
declaration.commonjs === undefined &&
|
|
2132
|
+
declaration.browser === undefined
|
|
2133
|
+
) {
|
|
2134
|
+
if (files.some(isModule)) undeclared.push(subpath)
|
|
2135
|
+
else excluded.push(subpath)
|
|
2136
|
+
continue
|
|
2137
|
+
}
|
|
2138
|
+
const imported = resolveTarget(entry, RUNTIME_CONDITIONS.module)
|
|
2139
|
+
const commonjs = resolvesCommonJS(entry, installed)
|
|
2140
|
+
const required = resolveTarget(entry, RUNTIME_CONDITIONS.commonjs) !== undefined
|
|
2141
|
+
const module = resolveTarget(entry, RUNTIME_CONDITIONS.browser)
|
|
2142
|
+
entries.push({
|
|
2143
|
+
subpath,
|
|
2144
|
+
specifier: subpath === '.' ? name : \`\${name}\${subpath.slice(1)}\`,
|
|
2145
|
+
mapping: entry,
|
|
2146
|
+
declaration: {
|
|
2147
|
+
module: declaration.module === undefined ? undefined : join(installed, declaration.module),
|
|
2148
|
+
commonjs:
|
|
2149
|
+
declaration.commonjs === undefined ? undefined : join(installed, declaration.commonjs),
|
|
2150
|
+
browser:
|
|
2151
|
+
declaration.browser === undefined ? undefined : join(installed, declaration.browser),
|
|
2152
|
+
},
|
|
2153
|
+
browser: module !== undefined && module.startsWith(BROWSER_OUTPUT),
|
|
2154
|
+
module: imported !== undefined,
|
|
2155
|
+
commonjs,
|
|
2156
|
+
required,
|
|
2157
|
+
})
|
|
2158
|
+
}
|
|
2159
|
+
return { consumer, installed, archives, entries, subpaths, undeclared, excluded, targets }
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
const SCRATCH = mkdtempSync(join(tmpdir(), 'distribution-'))
|
|
2163
|
+
const CACHE = join(SCRATCH, 'cache')
|
|
2164
|
+
mkdirSync(CACHE, { recursive: true })
|
|
2165
|
+
// The scratch tree holds the npm cache, the packed archive, and the installed
|
|
2166
|
+
// consumer, so its removal is registered before the first thing that can throw.
|
|
2167
|
+
afterAll(() => {
|
|
2168
|
+
rmSync(SCRATCH, { force: true, recursive: true })
|
|
2169
|
+
})
|
|
2170
|
+
|
|
2171
|
+
// Installing the packed archive resolves its own runtime dependencies, so an
|
|
2172
|
+
// unreachable registry leaves nothing to measure. Under release that is the gate
|
|
2173
|
+
// failing; anywhere else the suite skips and names the mechanism it wanted.
|
|
2174
|
+
//
|
|
2175
|
+
// A module that throws while loading never reaches the \`afterAll\` it registered,
|
|
2176
|
+
// so every throw here removes the scratch tree on its way out.
|
|
2177
|
+
function openStage(): Stage | undefined {
|
|
2178
|
+
try {
|
|
2179
|
+
if (runNpm(PING, ROOT).status !== 0) {
|
|
2180
|
+
if (!RELEASE) return undefined
|
|
2181
|
+
throw new Error(
|
|
2182
|
+
'The release gate requires a reachable npm registry, and npm ping did not answer',
|
|
2183
|
+
)
|
|
2184
|
+
}
|
|
2185
|
+
return buildStage()
|
|
2186
|
+
} catch (error) {
|
|
2187
|
+
rmSync(SCRATCH, { force: true, recursive: true })
|
|
2188
|
+
throw error
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
const STAGE = openStage()
|
|
2193
|
+
const STAGED = STAGE !== undefined
|
|
2194
|
+
|
|
2195
|
+
// The staged consumer, or a skip naming what the run could not reach. \`it.skipIf\`
|
|
2196
|
+
// carries no reason, so the gate sits here where the test context can state one.
|
|
2197
|
+
function requireStage(context: TestContext): Stage {
|
|
2198
|
+
if (!STAGED) {
|
|
2199
|
+
return context.skip('\`npm ping\` did not answer, so nothing was packed or installed')
|
|
2200
|
+
}
|
|
2201
|
+
return STAGE
|
|
2202
|
+
}
|
|
2203
|
+
|
|
2204
|
+
describe('installed package consumer', () => {
|
|
2205
|
+
it('packs one archive and installs it in isolation [requires the registry]', (context) => {
|
|
2206
|
+
const stage = requireStage(context)
|
|
2207
|
+
expect(stage.archives).toHaveLength(1)
|
|
2208
|
+
expect(existsSync(join(stage.installed, 'package.json'))).toBe(true)
|
|
2209
|
+
expect(stage.entries.length).toBeGreaterThan(0)
|
|
2210
|
+
})
|
|
2211
|
+
|
|
2212
|
+
it('ships every relative target its exports map names [requires the registry]', (context) => {
|
|
2213
|
+
const stage = requireStage(context)
|
|
2214
|
+
const relative = stage.targets.filter((target) => target.startsWith('./'))
|
|
2215
|
+
expect(relative).not.toStrictEqual([])
|
|
2216
|
+
expect(relative.filter((target) => !existsSync(join(stage.installed, target)))).toStrictEqual(
|
|
2217
|
+
[],
|
|
2218
|
+
)
|
|
2219
|
+
})
|
|
2220
|
+
|
|
2221
|
+
// Every published subpath is driven, excluded by name, or reported here. A dropped
|
|
2222
|
+
// one leaves no trace: no runtime test, no declaration comparison, and no place in
|
|
2223
|
+
// the resolution compile, so the run reports success for a subpath it never
|
|
2224
|
+
// measured.
|
|
2225
|
+
it('declares types for every module it publishes [requires the registry]', (context) => {
|
|
2226
|
+
const stage = requireStage(context)
|
|
2227
|
+
const partitioned = [
|
|
2228
|
+
...stage.entries.map((entry) => entry.subpath),
|
|
2229
|
+
...stage.undeclared,
|
|
2230
|
+
...stage.excluded,
|
|
2231
|
+
]
|
|
2232
|
+
expect(stage.undeclared).toStrictEqual([])
|
|
2233
|
+
expect(partitioned.sort()).toStrictEqual([...stage.subpaths].sort())
|
|
2234
|
+
// A driven subpath answers a runtime condition. One resolving a declaration and
|
|
2235
|
+
// no Node or browser target compiles for a consumer and throws when that consumer
|
|
2236
|
+
// loads it. Each later drive retires itself for that entry, so this assertion names
|
|
2237
|
+
// the subpath rather than counting it as driven.
|
|
2238
|
+
const unreachable = stage.entries.filter(
|
|
2239
|
+
(entry) => !entry.module && !entry.required && !entry.browser,
|
|
2240
|
+
)
|
|
2241
|
+
expect(unreachable.map((entry) => entry.subpath)).toStrictEqual([])
|
|
2242
|
+
const untypable = selectUntypable(stage.entries)
|
|
2243
|
+
expect(untypable.map((entry) => entry.subpath)).toStrictEqual([])
|
|
2244
|
+
})
|
|
2245
|
+
|
|
2246
|
+
it('refuses a subpath its exports map does not name [requires the registry]', (context) => {
|
|
2247
|
+
const stage = requireStage(context)
|
|
2248
|
+
const name = readManifestName(join(stage.installed, 'package.json'))
|
|
2249
|
+
const driver = join(stage.consumer, ESM_DRIVER)
|
|
2250
|
+
const result = runNode([driver, \`\${name}\${ABSENT_SUBPATH}\`], stage.consumer)
|
|
2251
|
+
expect(result.status).not.toBe(0)
|
|
2252
|
+
expect(readOutput(result)).toContain('ERR_PACKAGE_PATH_NOT_EXPORTED')
|
|
2253
|
+
})
|
|
2254
|
+
|
|
2255
|
+
// The absent subpath is the firing control: a resolution that reports nothing
|
|
2256
|
+
// for every published entry has not been shown to resolve anything at all. Each
|
|
2257
|
+
// module format carries its own control, because a format that resolves nothing
|
|
2258
|
+
// is silent for the same reason a resolution that resolves nothing is.
|
|
2259
|
+
it('compiles a consumer under every module resolution [requires the registry]', (context) => {
|
|
2260
|
+
const stage = requireStage(context)
|
|
2261
|
+
const name = readManifestName(join(stage.installed, 'package.json'))
|
|
2262
|
+
const reported: string[] = []
|
|
2263
|
+
const silent: string[] = []
|
|
2264
|
+
for (const driver of RESOLUTIONS) {
|
|
2265
|
+
for (const [extension, format] of FORMATS) {
|
|
2266
|
+
const written = selectEntries(stage.entries, driver.conditions[format])
|
|
2267
|
+
if (written.length === 0) continue
|
|
2268
|
+
const specifiers = written.map((entry) => entry.specifier)
|
|
2269
|
+
const probe = writeConsumerProbe(stage, \`probe.\${driver.label}.\${extension}\`, specifiers)
|
|
2270
|
+
for (const message of compileConsumer(probe, driver.resolution, driver.module)) {
|
|
2271
|
+
reported.push(\`\${driver.label}.\${extension}: \${message}\`)
|
|
2272
|
+
}
|
|
2273
|
+
const absent = [\`\${name}\${ABSENT_SUBPATH}\`]
|
|
2274
|
+
const control = writeConsumerProbe(stage, \`control.\${driver.label}.\${extension}\`, absent)
|
|
2275
|
+
if (compileConsumer(control, driver.resolution, driver.module).length === 0) {
|
|
2276
|
+
silent.push(\`\${driver.label}.\${extension}\`)
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
expect(reported).toStrictEqual([])
|
|
2281
|
+
expect(silent).toStrictEqual([])
|
|
2282
|
+
})
|
|
2283
|
+
{{guard}}})
|
|
2284
|
+
|
|
2285
|
+
for (const entry of STAGE?.entries ?? []) {
|
|
2286
|
+
describe(\`installed entry \${entry.subpath}\`, () => {
|
|
2287
|
+
it.runIf(entry.module && !entry.browser)(
|
|
2288
|
+
'publishes what it declares to a Node import, and no more',
|
|
2289
|
+
(context) => {
|
|
2290
|
+
const declaration = entry.declaration.module
|
|
2291
|
+
if (declaration === undefined) {
|
|
2292
|
+
throw new Error(\`\${entry.subpath} publishes no import declaration\`)
|
|
2293
|
+
}
|
|
2294
|
+
const published = driveRuntime(requireStage(context), entry.specifier, ESM_DRIVER)
|
|
2295
|
+
expect(published).toStrictEqual(readDeclaredExports(declaration))
|
|
2296
|
+
},
|
|
2297
|
+
)
|
|
2298
|
+
|
|
2299
|
+
it.runIf(!entry.browser && entry.required)(
|
|
2300
|
+
'publishes what it declares to a Node require, and no more',
|
|
2301
|
+
(context) => {
|
|
2302
|
+
const declaration = entry.declaration.commonjs
|
|
2303
|
+
if (declaration === undefined) {
|
|
2304
|
+
throw new Error(\`\${entry.subpath} publishes no require declaration\`)
|
|
2305
|
+
}
|
|
2306
|
+
const published = driveRuntime(requireStage(context), entry.specifier, CJS_DRIVER)
|
|
2307
|
+
expect(published).toStrictEqual(readDeclaredExports(declaration))
|
|
2308
|
+
},
|
|
2309
|
+
)
|
|
2310
|
+
{{drive}} })
|
|
2311
|
+
}
|
|
2312
|
+
`,
|
|
2313
|
+
transport: `import { createServer } from 'node:http'
|
|
2314
|
+
`,
|
|
2315
|
+
types: `import type { PlaywrightProviderOptions } from '@vitest/browser-playwright'
|
|
2316
|
+
import type { Browser } from 'playwright'
|
|
2317
|
+
`,
|
|
2318
|
+
launcher: `import { chromium } from 'playwright'
|
|
2319
|
+
import { build } from 'vite'
|
|
2320
|
+
import { resolveBrowser, resolvePinnedBrowser } from '../configs/browsers.js'
|
|
2321
|
+
`,
|
|
2322
|
+
helpers: `
|
|
2323
|
+
const BROWSER_PAGE = \`<!doctype html>
|
|
2324
|
+
<html lang="en">
|
|
2325
|
+
<head>
|
|
2326
|
+
<meta charset="UTF-8" />
|
|
2327
|
+
<title>Distribution</title>
|
|
2328
|
+
</head>
|
|
2329
|
+
<body>
|
|
2330
|
+
<script type="module" src="./main.js"><\/script>
|
|
2331
|
+
</body>
|
|
2332
|
+
</html>
|
|
2333
|
+
\`
|
|
2334
|
+
|
|
2335
|
+
function readContentType(path: string): string {
|
|
2336
|
+
if (path.endsWith('.html')) return 'text/html'
|
|
2337
|
+
if (path.endsWith('.js')) return 'text/javascript'
|
|
2338
|
+
if (path.endsWith('.css')) return 'text/css'
|
|
2339
|
+
if (path.endsWith('.json') || path.endsWith('.map')) return 'application/json'
|
|
2340
|
+
return 'application/octet-stream'
|
|
2341
|
+
}
|
|
2342
|
+
|
|
2343
|
+
// \`resolveBrowser\` answers with provider options and never reports absence: its
|
|
2344
|
+
// last resort is a channel nothing verified. So the launch is attempted and its
|
|
2345
|
+
// rejection classified, rather than probed for and ruled on.
|
|
2346
|
+
function describeBrowser(options: PlaywrightProviderOptions): string {
|
|
2347
|
+
const endpoint = options.connectOptions?.wsEndpoint
|
|
2348
|
+
if (endpoint !== undefined) return \`the browser server at \${endpoint}\`
|
|
2349
|
+
const executable = options.launchOptions?.executablePath
|
|
2350
|
+
if (executable !== undefined) return \`the executable at \${executable}\`
|
|
2351
|
+
const channel = options.launchOptions?.channel
|
|
2352
|
+
if (channel !== undefined) return \`the \${channel} channel\`
|
|
2353
|
+
return 'the Chromium Playwright installed for itself'
|
|
2354
|
+
}
|
|
2355
|
+
|
|
2356
|
+
async function launchBrowser(options: PlaywrightProviderOptions): Promise<Browser> {
|
|
2357
|
+
const endpoint = options.connectOptions?.wsEndpoint
|
|
2358
|
+
if (endpoint !== undefined) return chromium.connect(endpoint)
|
|
2359
|
+
return chromium.launch({ ...options.launchOptions, headless: true })
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
// A consumer of one installed browser entry, bundled by the Vite toolchain this
|
|
2363
|
+
// workspace already declares. Nothing is stubbed: the bundle resolves the installed
|
|
2364
|
+
// package and its whole transitive graph as an application consuming it would.
|
|
2365
|
+
async function bundleEntry(stage: Stage, entry: Entry): Promise<string> {
|
|
2366
|
+
const page = join(stage.consumer, 'pages', entry.subpath.replaceAll(/[^\\w]+/gu, '-'))
|
|
2367
|
+
const specifier = JSON.stringify(entry.specifier)
|
|
2368
|
+
writeFile(join(page, 'index.html'), BROWSER_PAGE)
|
|
2369
|
+
writeFile(
|
|
2370
|
+
join(page, 'main.js'),
|
|
2371
|
+
\`import * as entry from \${specifier}\\nglobalThis.subject = Object.keys(entry).sort()\\n\`,
|
|
2372
|
+
)
|
|
2373
|
+
await build({
|
|
2374
|
+
base: './',
|
|
2375
|
+
build: { emptyOutDir: true, outDir: 'bundle' },
|
|
2376
|
+
configFile: false,
|
|
2377
|
+
logLevel: 'error',
|
|
2378
|
+
root: page,
|
|
2379
|
+
})
|
|
2380
|
+
return join(page, 'bundle')
|
|
2381
|
+
}
|
|
2382
|
+
|
|
2383
|
+
// The key set the bundled module publishes in a real browser, read off the page
|
|
2384
|
+
// once it has loaded over a loopback server. A module that never evaluated
|
|
2385
|
+
// publishes nothing, and a page error is raised rather than compared away.
|
|
2386
|
+
async function readBrowserExports(browser: Browser, bundle: string): Promise<readonly string[]> {
|
|
2387
|
+
const server = createServer((request, response) => {
|
|
2388
|
+
const asked = request.url === undefined || request.url === '/' ? '/index.html' : request.url
|
|
2389
|
+
const path = join(bundle, decodeURIComponent(asked))
|
|
2390
|
+
if (!path.startsWith(bundle) || !existsSync(path)) {
|
|
2391
|
+
response.writeHead(404)
|
|
2392
|
+
response.end()
|
|
2393
|
+
return
|
|
2394
|
+
}
|
|
2395
|
+
response.writeHead(200, { 'content-type': readContentType(path) })
|
|
2396
|
+
response.end(readFileSync(path))
|
|
2397
|
+
})
|
|
2398
|
+
try {
|
|
2399
|
+
await new Promise<void>((settle) => {
|
|
2400
|
+
server.listen(0, '127.0.0.1', settle)
|
|
2401
|
+
})
|
|
2402
|
+
const address = server.address()
|
|
2403
|
+
if (address === null || typeof address === 'string') {
|
|
2404
|
+
throw new Error('The bundle server bound no port')
|
|
2405
|
+
}
|
|
2406
|
+
const page = await browser.newPage()
|
|
2407
|
+
const failures: string[] = []
|
|
2408
|
+
page.on('pageerror', (error) => failures.push(String(error)))
|
|
2409
|
+
await page.goto(\`http://127.0.0.1:\${String(address.port)}/\`, { waitUntil: 'load' })
|
|
2410
|
+
const published: unknown = await page.evaluate('globalThis.subject')
|
|
2411
|
+
if (failures.length > 0) throw new Error(\`The bundle raised \${failures.join(' | ')}\`)
|
|
2412
|
+
if (!isNames(published)) throw new Error('The bundled module published no name list')
|
|
2413
|
+
return published
|
|
2414
|
+
} finally {
|
|
2415
|
+
server.close()
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
`,
|
|
2419
|
+
drive: `
|
|
2420
|
+
it.runIf(entry.browser)(
|
|
2421
|
+
'publishes what it declares to a real browser, and no more [requires a browser]',
|
|
2422
|
+
async (context) => {
|
|
2423
|
+
const stage = requireStage(context)
|
|
2424
|
+
const declaration = entry.declaration.browser
|
|
2425
|
+
if (declaration === undefined) {
|
|
2426
|
+
throw new Error(\`\${entry.subpath} publishes no browser declaration\`)
|
|
2427
|
+
}
|
|
2428
|
+
const options = resolveBrowser(resolvePinnedBrowser(), process.platform, process.env)
|
|
2429
|
+
const browser = await launchBrowser(options).catch((error: unknown) => {
|
|
2430
|
+
const cause = \`\${describeBrowser(options)} was rejected: \${String(error)}\`
|
|
2431
|
+
if (RELEASE) throw new Error(\`The release gate requires a browser, and \${cause}\`)
|
|
2432
|
+
return context.skip(\`No browser launched. \${cause}\`)
|
|
2433
|
+
})
|
|
2434
|
+
try {
|
|
2435
|
+
const bundle = await bundleEntry(stage, entry)
|
|
2436
|
+
expect(await readBrowserExports(browser, bundle)).toStrictEqual(
|
|
2437
|
+
readDeclaredExports(declaration),
|
|
2438
|
+
)
|
|
2439
|
+
} finally {
|
|
2440
|
+
await browser.close()
|
|
2441
|
+
}
|
|
2442
|
+
},
|
|
2443
|
+
)
|
|
2444
|
+
`,
|
|
2445
|
+
guard: `
|
|
2446
|
+
// This proof drives a Node import and a Node require and carries no browser
|
|
2447
|
+
// branch: the workspace published no browser face when it was written, and the
|
|
2448
|
+
// browser drive measures the packed artifact, so only a published face is owed
|
|
2449
|
+
// one. A private browser application does not select this branch. It declares the
|
|
2450
|
+
// browser launcher and its Vitest browser provider and gets the generated browser
|
|
2451
|
+
// configuration module beside it, but installed browser tooling does not stand for
|
|
2452
|
+
// a published browser face. \`vite\` selects nothing either, though the branch
|
|
2453
|
+
// imports it: scaffold puts \`vite\` in every workspace's base development
|
|
2454
|
+
// dependencies, whatever that workspace publishes. The later Node
|
|
2455
|
+
// \`it.runIf\` predicates retire each matching Node drive for a face published
|
|
2456
|
+
// later, which leaves nothing measuring it. So it reddens here and names the
|
|
2457
|
+
// subpath a browser branch is owed for. A workspace that gains one deletes this
|
|
2458
|
+
// file and runs the \`repair\` verb, which writes the variant carrying that branch.
|
|
2459
|
+
it('publishes no browser face this proof cannot drive [requires the registry]', (context) => {
|
|
2460
|
+
const stage = requireStage(context)
|
|
2461
|
+
const faces = stage.entries.filter((entry) => entry.browser)
|
|
2462
|
+
expect(faces.map((entry) => entry.subpath)).toStrictEqual([])
|
|
2463
|
+
})
|
|
2464
|
+
`
|
|
2465
|
+
}),
|
|
1591
2466
|
integration: `{{imports}}import { describe, expect, it } from 'vitest'
|
|
1592
2467
|
|
|
1593
2468
|
describe('workspace integration', () => {
|
|
@@ -1867,6 +2742,37 @@ var isDependency = (0, _orkestrel_contract.recordOf)({
|
|
|
1867
2742
|
optional: _orkestrel_contract.isBoolean
|
|
1868
2743
|
}, ["optional"]);
|
|
1869
2744
|
/**
|
|
2745
|
+
* Narrow a value to a {@link ManifestScript}.
|
|
2746
|
+
*
|
|
2747
|
+
* @remarks
|
|
2748
|
+
* Structural and bounded, exactly as {@link isDependency} is: a script name
|
|
2749
|
+
* and a script command are free text a manifest may carry, and which values a
|
|
2750
|
+
* region writer is willing to overwrite is the caller's decision rather than
|
|
2751
|
+
* this guard's.
|
|
2752
|
+
*
|
|
2753
|
+
* @example
|
|
2754
|
+
* ```ts
|
|
2755
|
+
* import { isManifestScript } from '@orkestrel/scaffold'
|
|
2756
|
+
*
|
|
2757
|
+
* isManifestScript({ name: 'test', command: 'vitest run', accepted: [] }) // true
|
|
2758
|
+
* isManifestScript({ name: 'test', command: 'vitest run' }) // false
|
|
2759
|
+
* ```
|
|
2760
|
+
*/
|
|
2761
|
+
var isManifestScript = (0, _orkestrel_contract.recordOf)({
|
|
2762
|
+
name: (0, _orkestrel_contract.stringOf)({
|
|
2763
|
+
min: 1,
|
|
2764
|
+
max: MAX_SCRIPT_LENGTH
|
|
2765
|
+
}),
|
|
2766
|
+
command: (0, _orkestrel_contract.stringOf)({
|
|
2767
|
+
min: 1,
|
|
2768
|
+
max: MAX_SCRIPT_LENGTH
|
|
2769
|
+
}),
|
|
2770
|
+
accepted: (0, _orkestrel_contract.andOf)(isCollection, (0, _orkestrel_contract.arrayOf)((0, _orkestrel_contract.stringOf)({
|
|
2771
|
+
min: 1,
|
|
2772
|
+
max: MAX_SCRIPT_LENGTH
|
|
2773
|
+
})))
|
|
2774
|
+
});
|
|
2775
|
+
/**
|
|
1870
2776
|
* Narrow a value to an {@link Override}.
|
|
1871
2777
|
*
|
|
1872
2778
|
* @remarks
|
|
@@ -1918,7 +2824,6 @@ var isBlueprint = (0, _orkestrel_contract.recordOf)({
|
|
|
1918
2824
|
bin: _orkestrel_contract.isBoolean,
|
|
1919
2825
|
setup: _orkestrel_contract.isBoolean,
|
|
1920
2826
|
guides: _orkestrel_contract.isBoolean,
|
|
1921
|
-
distribution: _orkestrel_contract.isBoolean,
|
|
1922
2827
|
integration: _orkestrel_contract.isBoolean,
|
|
1923
2828
|
conformance: _orkestrel_contract.isBoolean,
|
|
1924
2829
|
service: _orkestrel_contract.isBoolean,
|
|
@@ -1972,14 +2877,16 @@ var isArtifact = (0, _orkestrel_contract.unionOf)((0, _orkestrel_contract.record
|
|
|
1972
2877
|
* @remarks
|
|
1973
2878
|
* A plan reaches the writer, and the writer has no question channel, so this
|
|
1974
2879
|
* carries the whole law of the value: every artifact path, every claimed byte,
|
|
1975
|
-
* and the blueprint it was compiled from.
|
|
2880
|
+
* and the blueprint it was compiled from. An artifact at {@link MANIFEST_PATH}
|
|
2881
|
+
* must carry `birth` ownership. A plan claiming `content` or `presence` there
|
|
2882
|
+
* is refused because the compiler emits the manifest only as birth-owned.
|
|
1976
2883
|
*/
|
|
1977
|
-
var isPlan = (0, _orkestrel_contract.recordOf)({
|
|
2884
|
+
var isPlan = (0, _orkestrel_contract.andOf)((0, _orkestrel_contract.recordOf)({
|
|
1978
2885
|
blueprint: isBlueprint,
|
|
1979
2886
|
groups: isGroups,
|
|
1980
2887
|
artifacts: (0, _orkestrel_contract.andOf)(isCollection, (0, _orkestrel_contract.arrayOf)(isArtifact)),
|
|
1981
2888
|
hash: isHex
|
|
1982
|
-
}, ["hash"]);
|
|
2889
|
+
}, ["hash"]), (plan) => plan.artifacts.every((artifact) => artifact.path !== "package.json" || artifact.ownership === "birth"));
|
|
1983
2890
|
/**
|
|
1984
2891
|
* Narrow a value to a {@link Question}.
|
|
1985
2892
|
*
|
|
@@ -2062,7 +2969,7 @@ var isMirror = (0, _orkestrel_contract.unionOf)((0, _orkestrel_contract.recordOf
|
|
|
2062
2969
|
}, ["observed"]), (0, _orkestrel_contract.recordOf)({
|
|
2063
2970
|
name: isDependencyName,
|
|
2064
2971
|
path: isPath,
|
|
2065
|
-
lookup: (0, _orkestrel_contract.literalOf)("missing", "failed"),
|
|
2972
|
+
lookup: (0, _orkestrel_contract.literalOf)("missing", "unmatched", "failed"),
|
|
2066
2973
|
note: _orkestrel_contract.isString,
|
|
2067
2974
|
observed: isHex
|
|
2068
2975
|
}, ["observed"]));
|
|
@@ -2080,7 +2987,7 @@ var isCatalogEntry = (0, _orkestrel_contract.unionOf)((0, _orkestrel_contract.re
|
|
|
2080
2987
|
dependencies: (0, _orkestrel_contract.andOf)(isCollection, (0, _orkestrel_contract.arrayOf)(isDependency))
|
|
2081
2988
|
}), (0, _orkestrel_contract.recordOf)({
|
|
2082
2989
|
name: isDependencyName,
|
|
2083
|
-
lookup: (0, _orkestrel_contract.literalOf)("missing", "failed"),
|
|
2990
|
+
lookup: (0, _orkestrel_contract.literalOf)("missing", "unmatched", "failed"),
|
|
2084
2991
|
note: _orkestrel_contract.isString
|
|
2085
2992
|
}));
|
|
2086
2993
|
/**
|
|
@@ -2411,6 +3318,29 @@ function matchesOrchestrationPath(path) {
|
|
|
2411
3318
|
return ORCHESTRATION_PATH_PREFIXES.some((prefix) => path.startsWith(prefix));
|
|
2412
3319
|
}
|
|
2413
3320
|
/**
|
|
3321
|
+
* Checks whether another surface owns the vendored bytes at a path.
|
|
3322
|
+
*
|
|
3323
|
+
* @param path - The target-relative vendored path to test.
|
|
3324
|
+
* @returns `true` for the catalog agent file and for a Markdown guide mirror;
|
|
3325
|
+
* `false` otherwise.
|
|
3326
|
+
*
|
|
3327
|
+
* @remarks
|
|
3328
|
+
* The materializer keeps these paths presence-owned because the catalog or
|
|
3329
|
+
* mirror surface writes their bytes. A live host fill therefore keeps the
|
|
3330
|
+
* installed floor's bytes for them and requests only the host-owned paths.
|
|
3331
|
+
*
|
|
3332
|
+
* @example
|
|
3333
|
+
* ```ts
|
|
3334
|
+
* import { isDeferredPath } from '@orkestrel/scaffold'
|
|
3335
|
+
*
|
|
3336
|
+
* isDeferredPath('guides/router.md') // true
|
|
3337
|
+
* isDeferredPath('AGENTS.md') // false
|
|
3338
|
+
* ```
|
|
3339
|
+
*/
|
|
3340
|
+
function isDeferredPath(path) {
|
|
3341
|
+
return path === ".claude/agents/orkestrel.md" || path.startsWith("guides/") && path.endsWith(".md");
|
|
3342
|
+
}
|
|
3343
|
+
/**
|
|
2414
3344
|
* Infer the {@link Group} a path belongs to.
|
|
2415
3345
|
*
|
|
2416
3346
|
* @param path - The target-relative path to classify.
|
|
@@ -3000,19 +3930,17 @@ function manifestToName(manifest) {
|
|
|
3000
3930
|
return name;
|
|
3001
3931
|
}
|
|
3002
3932
|
/**
|
|
3003
|
-
* Project a package manifest's text to the `@orkestrel/*` packages
|
|
3933
|
+
* Project a package manifest's text to the `@orkestrel/*` packages each dependency section declares.
|
|
3004
3934
|
*
|
|
3005
3935
|
* @param manifest - The `package.json` text.
|
|
3006
|
-
* @returns
|
|
3007
|
-
* with the first declaration of a repeated name winning.
|
|
3936
|
+
* @returns The runtime, development, and peer declarations as separate lists.
|
|
3008
3937
|
*
|
|
3009
3938
|
* @remarks
|
|
3010
|
-
*
|
|
3011
|
-
*
|
|
3012
|
-
*
|
|
3013
|
-
* unrelated dependencies are not this package's to report on.
|
|
3939
|
+
* Every other name is skipped rather than refused: a workspace's unrelated
|
|
3940
|
+
* dependencies are not this package's to report on. Keeping the sections
|
|
3941
|
+
* separate prevents a caller from treating a peer as a writable floor.
|
|
3014
3942
|
*
|
|
3015
|
-
* Never throws, and every row it returns satisfies `isDependency` while
|
|
3943
|
+
* Never throws, and every row it returns satisfies `isDependency` while each
|
|
3016
3944
|
* list satisfies `isCollection`, so the result crosses the compiler's own
|
|
3017
3945
|
* boundary without a second cleaning.
|
|
3018
3946
|
*
|
|
@@ -3021,34 +3949,55 @@ function manifestToName(manifest) {
|
|
|
3021
3949
|
* import { manifestToDependencies } from '@orkestrel/scaffold'
|
|
3022
3950
|
*
|
|
3023
3951
|
* manifestToDependencies('{"dependencies":{"@orkestrel/emitter":"^0.0.5","vite":"~8.2.0"}}')
|
|
3024
|
-
* // [{ name: '@orkestrel/emitter', range: '^0.0.5' }]
|
|
3952
|
+
* // { runtime: [{ name: '@orkestrel/emitter', range: '^0.0.5' }], development: [], peer: [] }
|
|
3025
3953
|
* ```
|
|
3026
3954
|
*/
|
|
3027
3955
|
function manifestToDependencies(manifest) {
|
|
3028
|
-
if (computeBytes(manifest) > 1048576) return
|
|
3956
|
+
if (computeBytes(manifest) > 1048576) return {
|
|
3957
|
+
runtime: [],
|
|
3958
|
+
development: [],
|
|
3959
|
+
peer: []
|
|
3960
|
+
};
|
|
3029
3961
|
const parsed = (0, _orkestrel_contract.parseJSON)(manifest);
|
|
3030
|
-
if (!(0, _orkestrel_contract.isRecord)(parsed)) return
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
]
|
|
3038
|
-
|
|
3962
|
+
if (!(0, _orkestrel_contract.isRecord)(parsed)) return {
|
|
3963
|
+
runtime: [],
|
|
3964
|
+
development: [],
|
|
3965
|
+
peer: []
|
|
3966
|
+
};
|
|
3967
|
+
const runtime = [];
|
|
3968
|
+
const development = [];
|
|
3969
|
+
const peer = [];
|
|
3970
|
+
const sections = [
|
|
3971
|
+
{
|
|
3972
|
+
name: "dependencies",
|
|
3973
|
+
dependencies: runtime
|
|
3974
|
+
},
|
|
3975
|
+
{
|
|
3976
|
+
name: "devDependencies",
|
|
3977
|
+
dependencies: development
|
|
3978
|
+
},
|
|
3979
|
+
{
|
|
3980
|
+
name: "peerDependencies",
|
|
3981
|
+
dependencies: peer
|
|
3982
|
+
}
|
|
3983
|
+
];
|
|
3984
|
+
for (const section of sections) {
|
|
3985
|
+
const entries = parsed[section.name];
|
|
3039
3986
|
if (!(0, _orkestrel_contract.isRecord)(entries)) continue;
|
|
3040
3987
|
for (const [name, range] of Object.entries(entries)) {
|
|
3041
|
-
if (seen.has(name)) continue;
|
|
3042
3988
|
if (!DEPENDENCY_NAME_PATTERN.test(name) || name.length > 214) continue;
|
|
3043
3989
|
if (!(0, _orkestrel_contract.isString)(range) || range.length === 0 || range.length > 2048) continue;
|
|
3044
|
-
|
|
3045
|
-
dependencies.push({
|
|
3990
|
+
section.dependencies.push({
|
|
3046
3991
|
name,
|
|
3047
3992
|
range
|
|
3048
3993
|
});
|
|
3049
3994
|
}
|
|
3050
3995
|
}
|
|
3051
|
-
return
|
|
3996
|
+
return {
|
|
3997
|
+
runtime: (0, _orkestrel_contract.limitEntries)(runtime, MAX_COLLECTION_ITEMS),
|
|
3998
|
+
development: (0, _orkestrel_contract.limitEntries)(development, MAX_COLLECTION_ITEMS),
|
|
3999
|
+
peer: (0, _orkestrel_contract.limitEntries)(peer, MAX_COLLECTION_ITEMS)
|
|
4000
|
+
};
|
|
3052
4001
|
}
|
|
3053
4002
|
//#endregion
|
|
3054
4003
|
//#region src/core/compilers.ts
|
|
@@ -3254,13 +4203,15 @@ function blueprintToDevDependencies(blueprint) {
|
|
|
3254
4203
|
* proofs every workspace can pass before it has a public API, and one build per
|
|
3255
4204
|
* target that actually builds.
|
|
3256
4205
|
*
|
|
3257
|
-
* A publishing workspace isolates distribution and live-service proofs from
|
|
3258
|
-
* `test` and runs them from `prepublishOnly` instead.
|
|
3259
|
-
*
|
|
3260
|
-
*
|
|
3261
|
-
*
|
|
3262
|
-
*
|
|
3263
|
-
*
|
|
4206
|
+
* A publishing workspace isolates its distribution and live-service proofs from
|
|
4207
|
+
* `test` and runs them from `prepublishOnly` instead. Publishing is what selects
|
|
4208
|
+
* the distribution proof: what that proof measures is the packed tarball, so a
|
|
4209
|
+
* workspace that packs no published source has nothing for it to read. A private
|
|
4210
|
+
* workspace therefore omits it and runs a live-service proof from `test`.
|
|
4211
|
+
* Integration and conformance stay in `test` because they neither pack nor
|
|
4212
|
+
* install the workspace and drive no external service. A conformance run may
|
|
4213
|
+
* start a server, but it starts its own and reaches it over loopback, so the run
|
|
4214
|
+
* stays hermetic.
|
|
3264
4215
|
*
|
|
3265
4216
|
* The configuration paths interpolated here are the same ones `SRC_MATRIX` and
|
|
3266
4217
|
* `APP_MATRIX` list as each environment's configuration files, so a rename in
|
|
@@ -3277,7 +4228,6 @@ function blueprintToDevDependencies(blueprint) {
|
|
|
3277
4228
|
*/
|
|
3278
4229
|
function blueprintToScripts(blueprint) {
|
|
3279
4230
|
const publishes = blueprint.src.length > 0;
|
|
3280
|
-
const distributes = blueprint.distribution && publishes;
|
|
3281
4231
|
const integrates = blueprint.integration;
|
|
3282
4232
|
const compiles = publishes || blueprint.bin;
|
|
3283
4233
|
const runtime = blueprint.app.filter((environment) => environment !== "core");
|
|
@@ -3335,7 +4285,7 @@ function blueprintToScripts(blueprint) {
|
|
|
3335
4285
|
if (blueprint.conformance) scripts["test:conformance"] = `${vitest} --project conformance`;
|
|
3336
4286
|
scripts["test:probe"] = "vitest run --config vite.config.ts --no-cache --reporter=verbose --project probe";
|
|
3337
4287
|
scripts["test:bench"] = "vitest bench --config vite.config.ts --no-cache --project probe";
|
|
3338
|
-
if (
|
|
4288
|
+
if (publishes) scripts["test:distribution"] = `${vitest} --project distribution`;
|
|
3339
4289
|
if (integrates) scripts["test:integration"] = `${vitest} --project integration`;
|
|
3340
4290
|
if (blueprint.service) scripts["test:service"] = `${vitest} --project service`;
|
|
3341
4291
|
scripts.build = [
|
|
@@ -3371,13 +4321,55 @@ function blueprintToScripts(blueprint) {
|
|
|
3371
4321
|
scripts.prepack = scripts.build;
|
|
3372
4322
|
scripts.prepublishOnly = [
|
|
3373
4323
|
"npm run format:check && npm run lint:check && npm run check && npm run build && npm test",
|
|
3374
|
-
|
|
4324
|
+
RELEASE_PROOF_COMMAND,
|
|
3375
4325
|
...blueprint.service ? ["npm run test:service"] : []
|
|
3376
4326
|
].join(" && ");
|
|
3377
4327
|
}
|
|
3378
4328
|
return scripts;
|
|
3379
4329
|
}
|
|
3380
4330
|
/**
|
|
4331
|
+
* Project a blueprint into the manifest scripts a region write may replace.
|
|
4332
|
+
*
|
|
4333
|
+
* @param blueprint - The workspace specification.
|
|
4334
|
+
* @returns One entry per writable script, or none when the workspace publishes
|
|
4335
|
+
* nothing and therefore declares neither script.
|
|
4336
|
+
*
|
|
4337
|
+
* @remarks
|
|
4338
|
+
* Publishing is what selects these scripts, so a private workspace answers an
|
|
4339
|
+
* empty region and the write leaves its manifest alone.
|
|
4340
|
+
*
|
|
4341
|
+
* `accepted` carries the predecessor a target can hold before this package
|
|
4342
|
+
* generated the packed-package proof: the same gate chain without
|
|
4343
|
+
* {@link RELEASE_PROOF_COMMAND}. The value being written is always writable, so
|
|
4344
|
+
* it is not repeated there. Any other value is a chain the workspace author
|
|
4345
|
+
* customized, and {@link replaceManifestScripts} refuses the whole region
|
|
4346
|
+
* rather than taking it.
|
|
4347
|
+
*
|
|
4348
|
+
* @example
|
|
4349
|
+
* ```ts
|
|
4350
|
+
* import { blueprintToWritableScripts, createBlueprint } from '@orkestrel/scaffold'
|
|
4351
|
+
*
|
|
4352
|
+
* const blueprint = createBlueprint('router', { src: ['core'] })
|
|
4353
|
+
*
|
|
4354
|
+
* blueprintToWritableScripts(blueprint)[0]?.name // 'test:distribution'
|
|
4355
|
+
* ```
|
|
4356
|
+
*/
|
|
4357
|
+
function blueprintToWritableScripts(blueprint) {
|
|
4358
|
+
const scripts = blueprintToScripts(blueprint);
|
|
4359
|
+
const distribution = scripts["test:distribution"];
|
|
4360
|
+
const prepublish = scripts.prepublishOnly;
|
|
4361
|
+
if (distribution === void 0 || prepublish === void 0) return [];
|
|
4362
|
+
return [{
|
|
4363
|
+
name: "test:distribution",
|
|
4364
|
+
command: distribution,
|
|
4365
|
+
accepted: []
|
|
4366
|
+
}, {
|
|
4367
|
+
name: "prepublishOnly",
|
|
4368
|
+
command: prepublish,
|
|
4369
|
+
accepted: [prepublish.replace(` && ${RELEASE_PROOF_COMMAND}`, "")]
|
|
4370
|
+
}];
|
|
4371
|
+
}
|
|
4372
|
+
/**
|
|
3381
4373
|
* Compile a blueprint into its `package.json` content.
|
|
3382
4374
|
*
|
|
3383
4375
|
* @param blueprint - The workspace specification.
|
|
@@ -3544,7 +4536,6 @@ function blueprintToRootTsconfig(blueprint) {
|
|
|
3544
4536
|
function blueprintToRootVite(blueprint) {
|
|
3545
4537
|
const machinery = blueprintToMachinery(blueprint);
|
|
3546
4538
|
const publishes = blueprint.src.length > 0;
|
|
3547
|
-
const distributes = blueprint.distribution && publishes;
|
|
3548
4539
|
const imports = [];
|
|
3549
4540
|
if (machinery.browser) imports.push("import { playwright } from '@vitest/browser-playwright'");
|
|
3550
4541
|
if (machinery.vue) imports.push("import vue from '@vitejs/plugin-vue'");
|
|
@@ -3657,7 +4648,7 @@ export function appShowcase(): UserConfig {
|
|
|
3657
4648
|
showcaseBuild,
|
|
3658
4649
|
showcaseFactory
|
|
3659
4650
|
}));
|
|
3660
|
-
projects.push("appBrowser
|
|
4651
|
+
projects.push("appBrowser");
|
|
3661
4652
|
}
|
|
3662
4653
|
if (blueprint.app.includes("server")) {
|
|
3663
4654
|
factories.push(CONFIG_TEMPLATES.factories.app.server);
|
|
@@ -3683,7 +4674,7 @@ export function appShowcase(): UserConfig {
|
|
|
3683
4674
|
factories.push(CONFIG_TEMPLATES.factories.service);
|
|
3684
4675
|
projects.push("service");
|
|
3685
4676
|
}
|
|
3686
|
-
if (
|
|
4677
|
+
if (publishes) {
|
|
3687
4678
|
factories.push(CONFIG_TEMPLATES.factories.distribution);
|
|
3688
4679
|
projects.push("distribution");
|
|
3689
4680
|
}
|
|
@@ -3917,6 +4908,13 @@ function blueprintToSourceArtifacts(blueprint) {
|
|
|
3917
4908
|
* readiness setup alone, because the root configuration names that module by
|
|
3918
4909
|
* path.
|
|
3919
4910
|
*
|
|
4911
|
+
* The distribution proof is emitted, and the same test separates it from those
|
|
4912
|
+
* two: its subject is the packed tarball rather than anything only the package
|
|
4913
|
+
* knows, so every assertion derives from the installed tree at run time and
|
|
4914
|
+
* nothing has to be named. It follows the published source it packs, and it is
|
|
4915
|
+
* the one artifact here claimed by presence: a target lacking it reports as
|
|
4916
|
+
* drift, and a package that replaced it with a better proof keeps that proof.
|
|
4917
|
+
*
|
|
3920
4918
|
* @example
|
|
3921
4919
|
* ```ts
|
|
3922
4920
|
* import { blueprintToTestArtifacts, createBlueprint } from '@orkestrel/scaffold'
|
|
@@ -3998,6 +4996,24 @@ function blueprintToTestArtifacts(blueprint) {
|
|
|
3998
4996
|
label: serializeTypeScriptString(`app ${environment} entry`)
|
|
3999
4997
|
})
|
|
4000
4998
|
});
|
|
4999
|
+
if (blueprint.src.length > 0) {
|
|
5000
|
+
const browser = blueprint.src.includes("browser");
|
|
5001
|
+
const distribution = ARTIFACT_TEMPLATES.tests.distribution;
|
|
5002
|
+
artifacts.push({
|
|
5003
|
+
path: DISTRIBUTION_TEST_PATH,
|
|
5004
|
+
group: "tests",
|
|
5005
|
+
ownership: "presence",
|
|
5006
|
+
origin: "template",
|
|
5007
|
+
content: (0, _orkestrel_template.fillTemplate)(distribution.proof, {
|
|
5008
|
+
types: browser ? distribution.types : "",
|
|
5009
|
+
transport: browser ? distribution.transport : "",
|
|
5010
|
+
launcher: browser ? distribution.launcher : "",
|
|
5011
|
+
helpers: browser ? distribution.helpers : "",
|
|
5012
|
+
drive: browser ? distribution.drive : "",
|
|
5013
|
+
guard: browser ? "" : distribution.guard
|
|
5014
|
+
})
|
|
5015
|
+
});
|
|
5016
|
+
}
|
|
4001
5017
|
if (blueprint.integration) {
|
|
4002
5018
|
const imports = [];
|
|
4003
5019
|
const entries = [];
|
|
@@ -4184,34 +5200,33 @@ function applyOverrides(artifacts, overrides) {
|
|
|
4184
5200
|
* Replace declared dependency ranges in package manifest text.
|
|
4185
5201
|
*
|
|
4186
5202
|
* @param manifest - The manifest text to compile.
|
|
4187
|
-
* @param
|
|
4188
|
-
* @returns The manifest with every matching
|
|
4189
|
-
*
|
|
5203
|
+
* @param pins - The runtime and development names and replacement ranges.
|
|
5204
|
+
* @returns The manifest with every matching writable value replaced, or
|
|
5205
|
+
* `undefined` when a name has no quoted declaration in its named section.
|
|
4190
5206
|
*
|
|
4191
5207
|
* @remarks
|
|
4192
5208
|
* The compiler replaces values in place instead of serializing the manifest,
|
|
4193
5209
|
* so description, keywords, scripts, key order, indentation, and every byte
|
|
4194
|
-
* outside the named ranges survive.
|
|
4195
|
-
*
|
|
4196
|
-
*
|
|
4197
|
-
*
|
|
5210
|
+
* outside the named ranges survive. Runtime pins apply only to `dependencies`,
|
|
5211
|
+
* and development pins apply only to `devDependencies`. The compiler never
|
|
5212
|
+
* reads or writes `peerDependencies` or `peerDependenciesMeta`. An override or
|
|
5213
|
+
* resolution with the same name stays untouched.
|
|
4198
5214
|
*
|
|
4199
5215
|
* @example
|
|
4200
5216
|
* ```ts
|
|
4201
5217
|
* import { replaceManifestRanges } from '@orkestrel/scaffold'
|
|
4202
5218
|
*
|
|
4203
5219
|
* const manifest = '{"devDependencies":{"typescript":"^6"}}\n'
|
|
4204
|
-
* replaceManifestRanges(manifest,
|
|
5220
|
+
* replaceManifestRanges(manifest, {
|
|
5221
|
+
* runtime: [],
|
|
5222
|
+
* development: [{ name: 'typescript', range: '^7' }],
|
|
5223
|
+
* })
|
|
4205
5224
|
* // the manifest with the declared range replaced
|
|
4206
5225
|
* ```
|
|
4207
5226
|
*/
|
|
4208
|
-
function replaceManifestRanges(manifest,
|
|
4209
|
-
if (
|
|
4210
|
-
const sectionNames = /* @__PURE__ */ new Set([
|
|
4211
|
-
"dependencies",
|
|
4212
|
-
"devDependencies",
|
|
4213
|
-
"peerDependencies"
|
|
4214
|
-
]);
|
|
5227
|
+
function replaceManifestRanges(manifest, pins) {
|
|
5228
|
+
if (pins.runtime.length === 0 && pins.development.length === 0) return manifest;
|
|
5229
|
+
const sectionNames = /* @__PURE__ */ new Set(["dependencies", "devDependencies"]);
|
|
4215
5230
|
const sections = [];
|
|
4216
5231
|
let depth = 0;
|
|
4217
5232
|
let cursor = 0;
|
|
@@ -4271,6 +5286,7 @@ function replaceManifestRanges(manifest, dependencies) {
|
|
|
4271
5286
|
sectionDepth -= 1;
|
|
4272
5287
|
if (sectionDepth === 0) {
|
|
4273
5288
|
sections.push({
|
|
5289
|
+
name: key,
|
|
4274
5290
|
start: value,
|
|
4275
5291
|
end: sectionCursor + 1
|
|
4276
5292
|
});
|
|
@@ -4284,10 +5300,13 @@ function replaceManifestRanges(manifest, dependencies) {
|
|
|
4284
5300
|
}
|
|
4285
5301
|
cursor = end;
|
|
4286
5302
|
}
|
|
4287
|
-
const
|
|
4288
|
-
const
|
|
5303
|
+
const runtime = /* @__PURE__ */ new Set();
|
|
5304
|
+
const development = /* @__PURE__ */ new Set();
|
|
4289
5305
|
let compiled = manifest;
|
|
4290
5306
|
for (const bounds of sections.reverse()) {
|
|
5307
|
+
const dependencies = bounds.name === "dependencies" ? pins.runtime : pins.development;
|
|
5308
|
+
const replacements = new Map(dependencies.map(({ name, range }) => [name, range]));
|
|
5309
|
+
const declared = bounds.name === "dependencies" ? runtime : development;
|
|
4291
5310
|
let section = compiled.slice(bounds.start, bounds.end);
|
|
4292
5311
|
let sectionDepth = 0;
|
|
4293
5312
|
let sectionCursor = 0;
|
|
@@ -4354,13 +5373,225 @@ function replaceManifestRanges(manifest, dependencies) {
|
|
|
4354
5373
|
}
|
|
4355
5374
|
compiled = compiled.slice(0, bounds.start) + section + compiled.slice(bounds.end);
|
|
4356
5375
|
}
|
|
4357
|
-
|
|
5376
|
+
const declaredRuntime = pins.runtime.every(({ name }) => runtime.has(name));
|
|
5377
|
+
const declaredDevelopment = pins.development.every(({ name }) => development.has(name));
|
|
5378
|
+
return declaredRuntime && declaredDevelopment ? compiled : void 0;
|
|
5379
|
+
}
|
|
5380
|
+
/**
|
|
5381
|
+
* Replace named script values in package manifest text.
|
|
5382
|
+
*
|
|
5383
|
+
* @param manifest - The manifest text to compile.
|
|
5384
|
+
* @param scripts - The scripts to write, each with the predecessors it accepts.
|
|
5385
|
+
* @returns The manifest carrying every named script, or `undefined` when a
|
|
5386
|
+
* named script holds a value outside what it accepts, or when the text carries
|
|
5387
|
+
* no readable `scripts` object to write into.
|
|
5388
|
+
*
|
|
5389
|
+
* @remarks
|
|
5390
|
+
* The compiler replaces values in place instead of serializing the manifest, so
|
|
5391
|
+
* description, keywords, dependencies, key order, indentation, and every byte
|
|
5392
|
+
* outside the replaced ranges survive. A named script the manifest already
|
|
5393
|
+
* declares is overwritten only when its value is the one being written or one
|
|
5394
|
+
* of its {@link ManifestScript.accepted} predecessors; anything else is a chain
|
|
5395
|
+
* the workspace author customized, and the whole region is refused without a
|
|
5396
|
+
* byte moving. A named script the manifest does not declare is appended after
|
|
5397
|
+
* the last declared script, copying that section's indentation. A region
|
|
5398
|
+
* declaring nothing takes every named script as its first entries, indented
|
|
5399
|
+
* from the line its own opening brace sits on.
|
|
5400
|
+
*
|
|
5401
|
+
* The refusal is whole rather than per script, so a manifest never ends up
|
|
5402
|
+
* holding one written script beside one refused one.
|
|
5403
|
+
*
|
|
5404
|
+
* @example
|
|
5405
|
+
* ```ts
|
|
5406
|
+
* import { replaceManifestScripts } from '@orkestrel/scaffold'
|
|
5407
|
+
*
|
|
5408
|
+
* const manifest = '{\n\t"scripts": {\n\t\t"test": "vitest run"\n\t}\n}\n'
|
|
5409
|
+
* replaceManifestScripts(manifest, [
|
|
5410
|
+
* { name: 'test', command: 'vitest run --no-cache', accepted: ['vitest run'] },
|
|
5411
|
+
* ])
|
|
5412
|
+
* // the manifest with the declared script replaced
|
|
5413
|
+
* ```
|
|
5414
|
+
*/
|
|
5415
|
+
function replaceManifestScripts(manifest, scripts) {
|
|
5416
|
+
if (scripts.length === 0) return manifest;
|
|
5417
|
+
const parsed = (0, _orkestrel_contract.parseJSON)(manifest);
|
|
5418
|
+
if (!(0, _orkestrel_contract.isRecord)(parsed) || !(0, _orkestrel_contract.isRecord)(parsed.scripts)) return void 0;
|
|
5419
|
+
const declared = parsed.scripts;
|
|
5420
|
+
for (const script of scripts) {
|
|
5421
|
+
if (!Object.hasOwn(declared, script.name)) continue;
|
|
5422
|
+
const value = declared[script.name];
|
|
5423
|
+
if (!(0, _orkestrel_contract.isString)(value)) return void 0;
|
|
5424
|
+
if (value !== script.command && !script.accepted.includes(value)) return void 0;
|
|
5425
|
+
}
|
|
5426
|
+
let depth = 0;
|
|
5427
|
+
let cursor = 0;
|
|
5428
|
+
let start = -1;
|
|
5429
|
+
let end = -1;
|
|
5430
|
+
while (cursor < manifest.length && end < 0) {
|
|
5431
|
+
const character = manifest.charAt(cursor);
|
|
5432
|
+
if (character === "{") {
|
|
5433
|
+
depth += 1;
|
|
5434
|
+
cursor += 1;
|
|
5435
|
+
continue;
|
|
5436
|
+
}
|
|
5437
|
+
if (character === "}") {
|
|
5438
|
+
depth -= 1;
|
|
5439
|
+
cursor += 1;
|
|
5440
|
+
continue;
|
|
5441
|
+
}
|
|
5442
|
+
if (character !== "\"") {
|
|
5443
|
+
cursor += 1;
|
|
5444
|
+
continue;
|
|
5445
|
+
}
|
|
5446
|
+
const keyStart = cursor;
|
|
5447
|
+
cursor += 1;
|
|
5448
|
+
while (cursor < manifest.length) {
|
|
5449
|
+
if (manifest.charAt(cursor) === "\\") {
|
|
5450
|
+
cursor += 2;
|
|
5451
|
+
continue;
|
|
5452
|
+
}
|
|
5453
|
+
if (manifest.charAt(cursor) === "\"") break;
|
|
5454
|
+
cursor += 1;
|
|
5455
|
+
}
|
|
5456
|
+
if (cursor >= manifest.length) return void 0;
|
|
5457
|
+
const keyEnd = cursor + 1;
|
|
5458
|
+
cursor = keyEnd;
|
|
5459
|
+
if (depth !== 1) continue;
|
|
5460
|
+
if ((0, _orkestrel_contract.parseJSON)(manifest.slice(keyStart, keyEnd)) !== "scripts") continue;
|
|
5461
|
+
let opening = keyEnd;
|
|
5462
|
+
while (opening < manifest.length && /\s/u.test(manifest.charAt(opening))) opening += 1;
|
|
5463
|
+
if (manifest.charAt(opening) !== ":") continue;
|
|
5464
|
+
opening += 1;
|
|
5465
|
+
while (opening < manifest.length && /\s/u.test(manifest.charAt(opening))) opening += 1;
|
|
5466
|
+
if (manifest.charAt(opening) !== "{") continue;
|
|
5467
|
+
start = opening;
|
|
5468
|
+
let nested = 0;
|
|
5469
|
+
let scan = opening;
|
|
5470
|
+
while (scan < manifest.length) {
|
|
5471
|
+
const inner = manifest.charAt(scan);
|
|
5472
|
+
if (inner === "\"") {
|
|
5473
|
+
scan += 1;
|
|
5474
|
+
while (scan < manifest.length) {
|
|
5475
|
+
if (manifest.charAt(scan) === "\\") {
|
|
5476
|
+
scan += 2;
|
|
5477
|
+
continue;
|
|
5478
|
+
}
|
|
5479
|
+
if (manifest.charAt(scan) === "\"") break;
|
|
5480
|
+
scan += 1;
|
|
5481
|
+
}
|
|
5482
|
+
if (scan >= manifest.length) return void 0;
|
|
5483
|
+
} else if (inner === "{") nested += 1;
|
|
5484
|
+
else if (inner === "}") {
|
|
5485
|
+
nested -= 1;
|
|
5486
|
+
if (nested === 0) {
|
|
5487
|
+
end = scan + 1;
|
|
5488
|
+
break;
|
|
5489
|
+
}
|
|
5490
|
+
}
|
|
5491
|
+
scan += 1;
|
|
5492
|
+
}
|
|
5493
|
+
}
|
|
5494
|
+
if (start < 0 || end < 0) return void 0;
|
|
5495
|
+
const edits = [];
|
|
5496
|
+
const written = /* @__PURE__ */ new Set();
|
|
5497
|
+
let first = -1;
|
|
5498
|
+
let nested = 0;
|
|
5499
|
+
let scan = start;
|
|
5500
|
+
while (scan < end) {
|
|
5501
|
+
const character = manifest.charAt(scan);
|
|
5502
|
+
if (character === "{") {
|
|
5503
|
+
nested += 1;
|
|
5504
|
+
scan += 1;
|
|
5505
|
+
continue;
|
|
5506
|
+
}
|
|
5507
|
+
if (character === "}") {
|
|
5508
|
+
nested -= 1;
|
|
5509
|
+
scan += 1;
|
|
5510
|
+
continue;
|
|
5511
|
+
}
|
|
5512
|
+
if (character !== "\"") {
|
|
5513
|
+
scan += 1;
|
|
5514
|
+
continue;
|
|
5515
|
+
}
|
|
5516
|
+
const keyStart = scan;
|
|
5517
|
+
scan += 1;
|
|
5518
|
+
while (scan < end) {
|
|
5519
|
+
if (manifest.charAt(scan) === "\\") {
|
|
5520
|
+
scan += 2;
|
|
5521
|
+
continue;
|
|
5522
|
+
}
|
|
5523
|
+
if (manifest.charAt(scan) === "\"") break;
|
|
5524
|
+
scan += 1;
|
|
5525
|
+
}
|
|
5526
|
+
if (scan >= end) return void 0;
|
|
5527
|
+
const keyEnd = scan + 1;
|
|
5528
|
+
scan = keyEnd;
|
|
5529
|
+
if (nested !== 1) continue;
|
|
5530
|
+
let valueStart = keyEnd;
|
|
5531
|
+
while (valueStart < end && /\s/u.test(manifest.charAt(valueStart))) valueStart += 1;
|
|
5532
|
+
if (manifest.charAt(valueStart) !== ":") continue;
|
|
5533
|
+
valueStart += 1;
|
|
5534
|
+
while (valueStart < end && /\s/u.test(manifest.charAt(valueStart))) valueStart += 1;
|
|
5535
|
+
if (first < 0) first = keyStart;
|
|
5536
|
+
if (manifest.charAt(valueStart) !== "\"") continue;
|
|
5537
|
+
let valueEnd = valueStart + 1;
|
|
5538
|
+
while (valueEnd < end) {
|
|
5539
|
+
if (manifest.charAt(valueEnd) === "\\") {
|
|
5540
|
+
valueEnd += 2;
|
|
5541
|
+
continue;
|
|
5542
|
+
}
|
|
5543
|
+
if (manifest.charAt(valueEnd) === "\"") break;
|
|
5544
|
+
valueEnd += 1;
|
|
5545
|
+
}
|
|
5546
|
+
if (valueEnd >= end) return void 0;
|
|
5547
|
+
scan = valueEnd + 1;
|
|
5548
|
+
const key = (0, _orkestrel_contract.parseJSON)(manifest.slice(keyStart, keyEnd));
|
|
5549
|
+
const script = scripts.find((entry) => entry.name === key);
|
|
5550
|
+
if (script === void 0) continue;
|
|
5551
|
+
written.add(script.name);
|
|
5552
|
+
edits.push({
|
|
5553
|
+
start: valueStart,
|
|
5554
|
+
end: valueEnd + 1,
|
|
5555
|
+
text: JSON.stringify(script.command)
|
|
5556
|
+
});
|
|
5557
|
+
}
|
|
5558
|
+
const missing = scripts.filter((script) => !written.has(script.name));
|
|
5559
|
+
if (missing.length > 0) {
|
|
5560
|
+
if (first < 0) {
|
|
5561
|
+
const opening = manifest.lastIndexOf("\n", start);
|
|
5562
|
+
let column = opening + 1;
|
|
5563
|
+
while (column < start && /\s/u.test(manifest.charAt(column))) column += 1;
|
|
5564
|
+
const level = opening < 0 ? "" : manifest.slice(opening + 1, column);
|
|
5565
|
+
const separator = opening < 0 ? "" : `\n${level}${level}`;
|
|
5566
|
+
const closing = opening < 0 ? "" : `\n${level}`;
|
|
5567
|
+
const entries = missing.map((script) => `${separator}${JSON.stringify(script.name)}: ${JSON.stringify(script.command)}`);
|
|
5568
|
+
edits.push({
|
|
5569
|
+
start: start + 1,
|
|
5570
|
+
end: end - 1,
|
|
5571
|
+
text: `${entries.join(",")}${closing}`
|
|
5572
|
+
});
|
|
5573
|
+
} else {
|
|
5574
|
+
let anchor = end - 1;
|
|
5575
|
+
while (anchor > start && /\s/u.test(manifest.charAt(anchor - 1))) anchor -= 1;
|
|
5576
|
+
const newline = manifest.lastIndexOf("\n", first);
|
|
5577
|
+
const indent = newline < 0 ? "" : manifest.slice(newline + 1, first);
|
|
5578
|
+
const separator = newline < 0 || /\S/u.test(indent) ? "" : `\n${indent}`;
|
|
5579
|
+
edits.push({
|
|
5580
|
+
start: anchor,
|
|
5581
|
+
end: anchor,
|
|
5582
|
+
text: missing.map((script) => `,${separator}${JSON.stringify(script.name)}: ${JSON.stringify(script.command)}`).join("")
|
|
5583
|
+
});
|
|
5584
|
+
}
|
|
5585
|
+
}
|
|
5586
|
+
let compiled = manifest;
|
|
5587
|
+
for (const edit of edits.sort((left, right) => right.start - left.start)) compiled = compiled.slice(0, edit.start) + edit.text + compiled.slice(edit.end);
|
|
5588
|
+
return compiled;
|
|
4358
5589
|
}
|
|
4359
5590
|
/**
|
|
4360
5591
|
* Replace dependency ranges in a plan's manifest and recompute its identity.
|
|
4361
5592
|
*
|
|
4362
5593
|
* @param plan - The plan carrying the manifest artifact to compile.
|
|
4363
|
-
* @param
|
|
5594
|
+
* @param pins - The runtime and development names and replacement ranges.
|
|
4364
5595
|
* @returns A plan with replaced manifest ranges and a matching hash, or
|
|
4365
5596
|
* `undefined` when the manifest or its identity cannot be compiled.
|
|
4366
5597
|
*
|
|
@@ -4374,15 +5605,15 @@ function replaceManifestRanges(manifest, dependencies) {
|
|
|
4374
5605
|
* ```ts
|
|
4375
5606
|
* import { replacePlanRanges } from '@orkestrel/scaffold'
|
|
4376
5607
|
*
|
|
4377
|
-
* replacePlanRanges(plan,
|
|
5608
|
+
* replacePlanRanges(plan, pins) // the plan carrying the resolved writable ranges
|
|
4378
5609
|
* ```
|
|
4379
5610
|
*/
|
|
4380
|
-
function replacePlanRanges(plan,
|
|
5611
|
+
function replacePlanRanges(plan, pins) {
|
|
4381
5612
|
let replaced = false;
|
|
4382
5613
|
let refused = false;
|
|
4383
5614
|
const artifacts = plan.artifacts.map((artifact) => {
|
|
4384
5615
|
if (artifact.path !== "package.json" || artifact.origin === "host") return artifact;
|
|
4385
|
-
const content = replaceManifestRanges(artifact.content,
|
|
5616
|
+
const content = replaceManifestRanges(artifact.content, pins);
|
|
4386
5617
|
if (content === void 0) {
|
|
4387
5618
|
refused = true;
|
|
4388
5619
|
return artifact;
|
|
@@ -4709,11 +5940,6 @@ function blueprintToQuestions(blueprint) {
|
|
|
4709
5940
|
});
|
|
4710
5941
|
vendors.add(vendor);
|
|
4711
5942
|
}
|
|
4712
|
-
if (blueprint.distribution && blueprint.src.length === 0) questions.push({
|
|
4713
|
-
field: "distribution",
|
|
4714
|
-
message: "distribution packs the published source, and this workspace declares none, so it emits nothing.",
|
|
4715
|
-
blocking: false
|
|
4716
|
-
});
|
|
4717
5943
|
if (blueprint.showcase && !blueprint.app.includes("browser")) questions.push({
|
|
4718
5944
|
field: "showcase",
|
|
4719
5945
|
message: "showcase projects a browser app, and this workspace declares none, so it emits nothing.",
|
|
@@ -4922,7 +6148,6 @@ function createBlueprint(name, input) {
|
|
|
4922
6148
|
bin: input?.bin ?? false,
|
|
4923
6149
|
setup: input?.setup ?? false,
|
|
4924
6150
|
guides: input?.guides ?? false,
|
|
4925
|
-
distribution: input?.distribution ?? false,
|
|
4926
6151
|
integration: input?.integration ?? false,
|
|
4927
6152
|
conformance: input?.conformance ?? false,
|
|
4928
6153
|
service: input?.service ?? false,
|
|
@@ -5263,9 +6488,11 @@ exports.GLOBAL_SETUP_PATH = GLOBAL_SETUP_PATH;
|
|
|
5263
6488
|
exports.GROUPS = GROUPS;
|
|
5264
6489
|
exports.GUIDES_TEST_PATH = GUIDES_TEST_PATH;
|
|
5265
6490
|
exports.HEX_PATTERN = HEX_PATTERN;
|
|
6491
|
+
exports.HOST_INVENTORY_PATH = HOST_INVENTORY_PATH;
|
|
5266
6492
|
exports.HOST_PATHS = HOST_PATHS;
|
|
5267
6493
|
exports.INTEGRATION_TEST_PATH = INTEGRATION_TEST_PATH;
|
|
5268
6494
|
exports.INVALID_PATH_CHARACTER_PATTERN = INVALID_PATH_CHARACTER_PATTERN;
|
|
6495
|
+
exports.MANIFEST_PATH = MANIFEST_PATH;
|
|
5269
6496
|
exports.MAX_ARTIFACT_BYTES = MAX_ARTIFACT_BYTES;
|
|
5270
6497
|
exports.MAX_ARTIFACT_HEX_LENGTH = MAX_ARTIFACT_HEX_LENGTH;
|
|
5271
6498
|
exports.MAX_AUDIT_FINDINGS = MAX_AUDIT_FINDINGS;
|
|
@@ -5276,6 +6503,7 @@ exports.MAX_NAME_LENGTH = MAX_NAME_LENGTH;
|
|
|
5276
6503
|
exports.MAX_PATH_LENGTH = MAX_PATH_LENGTH;
|
|
5277
6504
|
exports.MAX_RANGE_LENGTH = MAX_RANGE_LENGTH;
|
|
5278
6505
|
exports.MAX_REGISTRY_BYTES = MAX_REGISTRY_BYTES;
|
|
6506
|
+
exports.MAX_SCRIPT_LENGTH = MAX_SCRIPT_LENGTH;
|
|
5279
6507
|
exports.MAX_TOTAL_ARTIFACT_BYTES = MAX_TOTAL_ARTIFACT_BYTES;
|
|
5280
6508
|
exports.MAX_TOTAL_REGISTRY_BYTES = MAX_TOTAL_REGISTRY_BYTES;
|
|
5281
6509
|
exports.MINIMUM_NODE_VERSION = MINIMUM_NODE_VERSION;
|
|
@@ -5284,6 +6512,7 @@ exports.ORCHESTRATION_PATH_NAMES = ORCHESTRATION_PATH_NAMES;
|
|
|
5284
6512
|
exports.ORCHESTRATION_PATH_PREFIXES = ORCHESTRATION_PATH_PREFIXES;
|
|
5285
6513
|
exports.ORKESTREL_RANGE_PATTERN = ORKESTREL_RANGE_PATTERN;
|
|
5286
6514
|
exports.PRINT_WIDTH = PRINT_WIDTH;
|
|
6515
|
+
exports.RELEASE_PROOF_COMMAND = RELEASE_PROOF_COMMAND;
|
|
5287
6516
|
exports.SERVICE_SCRIPT_PATH = SERVICE_SCRIPT_PATH;
|
|
5288
6517
|
exports.SERVICE_SETUP_PATH = SERVICE_SETUP_PATH;
|
|
5289
6518
|
exports.SERVICE_TEST_INCLUDE = SERVICE_TEST_INCLUDE;
|
|
@@ -5312,6 +6541,7 @@ exports.blueprintToRootVite = blueprintToRootVite;
|
|
|
5312
6541
|
exports.blueprintToScripts = blueprintToScripts;
|
|
5313
6542
|
exports.blueprintToSourceArtifacts = blueprintToSourceArtifacts;
|
|
5314
6543
|
exports.blueprintToTestArtifacts = blueprintToTestArtifacts;
|
|
6544
|
+
exports.blueprintToWritableScripts = blueprintToWritableScripts;
|
|
5315
6545
|
exports.bytesToHex = bytesToHex;
|
|
5316
6546
|
exports.catalogToLayers = catalogToLayers;
|
|
5317
6547
|
exports.cloneValue = cloneValue;
|
|
@@ -5333,6 +6563,7 @@ exports.isCollection = isCollection;
|
|
|
5333
6563
|
exports.isCompilerHooks = isCompilerHooks;
|
|
5334
6564
|
exports.isCompilerOptions = isCompilerOptions;
|
|
5335
6565
|
exports.isContent = isContent;
|
|
6566
|
+
exports.isDeferredPath = isDeferredPath;
|
|
5336
6567
|
exports.isDependency = isDependency;
|
|
5337
6568
|
exports.isDependencyName = isDependencyName;
|
|
5338
6569
|
exports.isEnvironment = isEnvironment;
|
|
@@ -5340,6 +6571,7 @@ exports.isFinding = isFinding;
|
|
|
5340
6571
|
exports.isGroup = isGroup;
|
|
5341
6572
|
exports.isGroups = isGroups;
|
|
5342
6573
|
exports.isHex = isHex;
|
|
6574
|
+
exports.isManifestScript = isManifestScript;
|
|
5343
6575
|
exports.isMirror = isMirror;
|
|
5344
6576
|
exports.isOverride = isOverride;
|
|
5345
6577
|
exports.isPath = isPath;
|
|
@@ -5367,6 +6599,7 @@ exports.planToFindings = planToFindings;
|
|
|
5367
6599
|
exports.planToHash = planToHash;
|
|
5368
6600
|
exports.planToSummary = planToSummary;
|
|
5369
6601
|
exports.replaceManifestRanges = replaceManifestRanges;
|
|
6602
|
+
exports.replaceManifestScripts = replaceManifestScripts;
|
|
5370
6603
|
exports.replacePlanRanges = replacePlanRanges;
|
|
5371
6604
|
exports.selectGroups = selectGroups;
|
|
5372
6605
|
exports.selectHostPaths = selectHostPaths;
|