@orkestrel/guide 0.0.25 → 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/core/index.cjs +696 -705
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +39 -4
- package/dist/src/core/index.d.ts +39 -4
- package/dist/src/core/index.js +696 -705
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +5 -10
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.js +4 -8
- package/dist/src/server/index.js.map +1 -1
- package/package.json +14 -14
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
// \0rolldown/runtime.js
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -20,7 +20,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
20
20
|
value: mod,
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
23
|
-
//#endregion
|
|
24
23
|
let _orkestrel_contract = require("@orkestrel/contract");
|
|
25
24
|
let node_path = require("node:path");
|
|
26
25
|
let node_url = require("node:url");
|
|
@@ -28,7 +27,7 @@ let node_fs = require("node:fs");
|
|
|
28
27
|
let node_process = require("node:process");
|
|
29
28
|
node_process = __toESM(node_process, 1);
|
|
30
29
|
let _src_core = require("../core/index.cjs");
|
|
31
|
-
|
|
30
|
+
// src/server/constants.ts
|
|
32
31
|
/** Names the workspace-relative guide concept index. */
|
|
33
32
|
var GUIDE_INDEX = "guides/README.md";
|
|
34
33
|
/** Names the package manifest read for native pitch selection. */
|
|
@@ -37,8 +36,7 @@ var GUIDE_MANIFEST = "package.json";
|
|
|
37
36
|
var GUIDE_README = "README.md";
|
|
38
37
|
/** Holds the native command usage text written for unsupported arguments. */
|
|
39
38
|
var GUIDE_USAGE = "usage: npm run test:guides [-- --to guide|--to source]";
|
|
40
|
-
|
|
41
|
-
//#region src/server/helpers.ts
|
|
39
|
+
// src/server/helpers.ts
|
|
42
40
|
/**
|
|
43
41
|
* Formats one finding with its guide prefix when needed.
|
|
44
42
|
*
|
|
@@ -111,8 +109,7 @@ function selectGuidePitch(entries, name) {
|
|
|
111
109
|
const spec = `guides/${name}.md`;
|
|
112
110
|
return entries.some((entry) => entry.spec === spec) ? spec : void 0;
|
|
113
111
|
}
|
|
114
|
-
|
|
115
|
-
//#region src/server/parsers.ts
|
|
112
|
+
// src/server/parsers.ts
|
|
116
113
|
/**
|
|
117
114
|
* Maps the supported `--to guide` and `--to source` arguments to an explicit rewrite destination.
|
|
118
115
|
*
|
|
@@ -146,8 +143,7 @@ function parsePackageName(manifest) {
|
|
|
146
143
|
if (!(0, _orkestrel_contract.isNonEmptyString)(name)) return void 0;
|
|
147
144
|
return name.slice(name.lastIndexOf("/") + 1);
|
|
148
145
|
}
|
|
149
|
-
|
|
150
|
-
//#region src/server/GuideCommand.ts
|
|
146
|
+
// src/server/GuideCommand.ts
|
|
151
147
|
/**
|
|
152
148
|
* Drives native checking and explicit rewrites or registers package assertions in the guides
|
|
153
149
|
* worker.
|
|
@@ -328,7 +324,6 @@ var GuideCommand = class {
|
|
|
328
324
|
if (!(0, _orkestrel_contract.isFiniteNumber)(numeric) || numeric < code) node_process.default.exitCode = code;
|
|
329
325
|
}
|
|
330
326
|
};
|
|
331
|
-
//#endregion
|
|
332
327
|
exports.GUIDE_INDEX = GUIDE_INDEX;
|
|
333
328
|
exports.GUIDE_MANIFEST = GUIDE_MANIFEST;
|
|
334
329
|
exports.GUIDE_README = GUIDE_README;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["isObject","isArray","isFunction","resolve","isInstance","fileURLToPath","parseEnum","parseJSONAs","isRecord","isNonEmptyString","process","isError","parseManifest","Parity","resolve","globSync","isObject","isFunction","isString","isFiniteNumber"],"sources":["../../../src/server/constants.ts","../../../src/server/helpers.ts","../../../src/server/parsers.ts","../../../src/server/GuideCommand.ts"],"sourcesContent":["/** Names the workspace-relative guide concept index. */\nexport const GUIDE_INDEX = 'guides/README.md'\n\n/** Names the package manifest read for native pitch selection. */\nexport const GUIDE_MANIFEST = 'package.json'\n\n/** Names the package README paired with its indexed guide pitch. */\nexport const GUIDE_README = 'README.md'\n\n/** Holds the native command usage text written for unsupported arguments. */\nexport const GUIDE_USAGE = 'usage: npm run test:guides [-- --to guide|--to source]'\n","import type { ManifestEntry, ParityFinding } from '@src/core'\nimport { isArray, isFunction, isInstance, isObject } from '@orkestrel/contract'\nimport { resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\n/**\n * Formats one finding with its guide prefix when needed.\n *\n * @param finding - The finding to format\n * @returns The finding text with its spec prefix when the text does not already carry it\n *\n * @example\n * ```ts\n * formatGuideFinding({ spec: 'guides/widget.md', text: 'missing export' })\n * ```\n */\nexport function formatGuideFinding(finding: ParityFinding): string {\n\tconst spec = finding.spec\n\tconst prefix = spec === undefined || finding.text.startsWith(spec) ? '' : `${spec} `\n\treturn `${prefix}${finding.text}`\n}\n\n/**\n * Reads an owned foreign result view and accepts passed modules without unhandled errors.\n *\n * @param result - The unknown external runner result to inspect\n * @returns True if a module is present, every module passed, and no unhandled error exists; false otherwise\n *\n * @example\n * ```ts\n * matchesGuideResult({ testModules: [{ state: () => 'passed' }], unhandledErrors: [] })\n * ```\n */\nexport function matchesGuideResult(result: unknown): boolean {\n\tif (!isObject(result)) return false\n\tconst testModules = Reflect.get(result, 'testModules')\n\tconst unhandledErrors = Reflect.get(result, 'unhandledErrors')\n\tif (!isArray(testModules) || !isArray(unhandledErrors)) return false\n\tconst modules = [...testModules]\n\tconst errors = [...unhandledErrors]\n\tif (modules.length === 0 || errors.length > 0) return false\n\tfor (const module of modules) {\n\t\tif (!isObject(module)) return false\n\t\tconst state = Reflect.get(module, 'state')\n\t\tif (!isFunction(state) || Reflect.apply(state, module, []) !== 'passed') return false\n\t}\n\treturn true\n}\n\n/**\n * Resolves a command root to a native absolute path.\n *\n * @param root - The workspace root as a file URL or native path\n * @returns The native absolute workspace path\n *\n * @example\n * ```ts\n * resolveGuideRoot('/workspace')\n * ```\n */\nexport function resolveGuideRoot(root: URL | string): string {\n\treturn resolve(isInstance(root, URL) ? fileURLToPath(root) : root)\n}\n\n/**\n * Selects the indexed guide matching a package's bare name.\n *\n * @param entries - The concept-index entries to search\n * @param name - The package's bare name, or `undefined` when none was parsed\n * @returns The indexed own-guide path, or `undefined` when the index carries none\n *\n * @example\n * ```ts\n * selectGuidePitch([{ concept: 'Widget', spec: 'guides/widget.md', source: 'src', tests: 'tests' }], 'widget')\n * ```\n */\nexport function selectGuidePitch(\n\tentries: readonly ManifestEntry[],\n\tname: string | undefined,\n): string | undefined {\n\tif (name === undefined) return undefined\n\tconst spec = `guides/${name}.md`\n\treturn entries.some((entry) => entry.spec === spec) ? spec : undefined\n}\n","import type { ParityDirection } from '@src/core'\nimport { isNonEmptyString, isRecord, parseEnum, parseJSONAs } from '@orkestrel/contract'\n\n/**\n * Maps the supported `--to guide` and `--to source` arguments to an explicit rewrite destination.\n *\n * @param args - The arguments after the native command entry\n * @returns The requested destination, or `undefined` when the shape is unsupported\n *\n * @example\n * ```ts\n * parseGuideDirection(['--to', 'guide'])\n * ```\n */\nexport function parseGuideDirection(args: readonly string[]): ParityDirection | undefined {\n\tif (args.length !== 2 || args[0] !== '--to') return undefined\n\treturn parseEnum(args[1], ['guide', 'source'])\n}\n\n/**\n * Reads the bare package name from package manifest JSON.\n *\n * @param manifest - The package manifest JSON text\n * @returns The name after its final scope separator, or `undefined` when no name is declared\n *\n * @example\n * ```ts\n * parsePackageName('{\"name\":\"@scope/widget\"}')\n * ```\n */\nexport function parsePackageName(manifest: string): string | undefined {\n\tconst parsed = parseJSONAs(manifest, isRecord)\n\tif (parsed === undefined) return undefined\n\tconst name = parsed.name\n\tif (!isNonEmptyString(name)) return undefined\n\treturn name.slice(name.lastIndexOf('/') + 1)\n}\n","import type {\n\tGuideCommandContext,\n\tGuideCommandHandler,\n\tGuideCommandInterface,\n\tGuideCommandOptions,\n\tGuideReadFunction,\n\tGuideRunnerFunction,\n} from './types.js'\nimport type { GuideModule, ParityFinding, ParityOptions } from '@src/core'\nimport { isError, isFiniteNumber, isFunction, isObject, isString } from '@orkestrel/contract'\nimport { globSync, writeFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport process from 'node:process'\nimport { Parity, parseManifest } from '@src/core'\nimport { GUIDE_INDEX, GUIDE_MANIFEST, GUIDE_README, GUIDE_USAGE } from './constants.js'\nimport {\n\tformatGuideFinding,\n\tmatchesGuideResult,\n\tresolveGuideRoot,\n\tselectGuidePitch,\n} from './helpers.js'\nimport { parseGuideDirection, parsePackageName } from './parsers.js'\n\n/**\n * Drives native checking and explicit rewrites or registers package assertions in the guides\n * worker.\n *\n * @param options - The workspace policy and direct host ports\n *\n * @example\n * ```ts\n * import { GuideCommand } from '@orkestrel/guide/server'\n * import { readInventory } from '@orkestrel/test/server'\n * import { createVitest } from 'vitest/node'\n *\n * await new GuideCommand({\n * \troot: new URL('../', import.meta.url),\n * \tpatterns: ['src/**\\/*.ts', 'tests/**\\/*.ts', 'guides/*.md', '*.md'],\n * \tmodules: { '@scope/widget': 'src/core' },\n * \tlanguages: ['ts'],\n * \tlanguage: 'ts',\n * \treader: readInventory,\n * \trunner: createVitest,\n * }).execute(async ({ files, report, root, rows }) => {\n * \tconst { expect, it } = await import('vitest')\n * \tit('checks the documented inventory', () => {\n * \t\texpect(root.length).toBeGreaterThan(0)\n * \t\texpect(Object.keys(files).length).toBeGreaterThan(0)\n * \t\texpect(rows.length).toBeGreaterThan(0)\n * \t\texpect(report.input).toEqual([])\n * \t})\n * })\n * ```\n */\nexport class GuideCommand implements GuideCommandInterface {\n\treadonly #root: string\n\treadonly #patterns: readonly string[]\n\treadonly #modules: Readonly<Record<string, GuideModule>>\n\treadonly #languages: readonly string[]\n\treadonly #language: string\n\treadonly #reader: GuideReadFunction\n\treadonly #runner: GuideRunnerFunction\n\n\tconstructor(options: GuideCommandOptions) {\n\t\tthis.#root = resolveGuideRoot(options.root)\n\t\tthis.#patterns = Object.freeze([...options.patterns])\n\t\tthis.#modules = Object.freeze({ ...options.modules })\n\t\tthis.#languages = Object.freeze([...options.languages])\n\t\tthis.#language = options.language\n\t\tthis.#reader = options.reader\n\t\tthis.#runner = options.runner\n\t}\n\n\t/**\n\t * Runs the native command or registers package assertions with fresh worker inventory and parity.\n\t *\n\t * @param register - The package-owned assertion registration callback\n\t * @returns A promise that resolves after the selected command path finishes\n\t * @throws When worker inventory reading or package assertion registration fails. Native failures\n\t * are reported through stderr and process exit status before this promise resolves.\n\t */\n\tasync execute(register: GuideCommandHandler): Promise<void> {\n\t\tif (process.env.VITEST === 'true') {\n\t\t\tawait this.#register(register)\n\t\t\treturn\n\t\t}\n\t\ttry {\n\t\t\tawait this.#executeNative()\n\t\t} catch (error) {\n\t\t\tprocess.stderr.write(`${isError(error) ? error.message : String(error)}\\n`)\n\t\t\tthis.#raise(1)\n\t\t}\n\t}\n\n\t#createOptions(): ParityOptions | undefined {\n\t\tconst files = this.#readInventory()\n\t\tconst manifest = files[GUIDE_INDEX]\n\t\tif (manifest === undefined) return undefined\n\t\tconst entries = Object.freeze([...parseManifest(manifest, 'guides')])\n\t\tconst packageFiles = Object.freeze({ ...this.#reader(this.#root, [GUIDE_MANIFEST]) })\n\t\tconst packageManifest = packageFiles[GUIDE_MANIFEST]\n\t\tconst pitch = selectGuidePitch(\n\t\t\tentries,\n\t\t\tpackageManifest === undefined ? undefined : parsePackageName(packageManifest),\n\t\t)\n\t\treturn {\n\t\t\tfiles,\n\t\t\tentries,\n\t\t\tmodules: this.#modules,\n\t\t\tlanguages: this.#languages,\n\t\t\tlanguage: this.#language,\n\t\t\t...(pitch === undefined\n\t\t\t\t? {}\n\t\t\t\t: { pitch: Object.freeze({ readme: GUIDE_README, spec: pitch }) }),\n\t\t}\n\t}\n\n\tasync #executeNative(): Promise<void> {\n\t\tconst args = process.argv.slice(2)\n\t\tconst direction = parseGuideDirection(args)\n\t\tif (direction === undefined && args.length > 0) {\n\t\t\tprocess.stdout.write(`${GUIDE_USAGE}\\n`)\n\t\t\tthis.#raise(2)\n\t\t\treturn\n\t\t}\n\t\tif (direction === undefined) {\n\t\t\tif (!(await this.#executeRunner())) this.#raise(1)\n\t\t\treturn\n\t\t}\n\n\t\tconst options = this.#createOptions()\n\t\tif (options === undefined) {\n\t\t\tthis.#reportMissing()\n\t\t\treturn\n\t\t}\n\t\tconst parity = new Parity(options)\n\t\tif (this.#report(parity.inspect().input)) {\n\t\t\tthis.#raise(2)\n\t\t\treturn\n\t\t}\n\t\tconst rewritten = direction === 'guide' ? parity.document() : parity.annotate()\n\t\tfor (const change of rewritten.changes) {\n\t\t\twriteFileSync(resolve(this.#root, change.path), change.content)\n\t\t\tprocess.stdout.write(`wrote ${change.path}\\n`)\n\t\t}\n\n\t\tconst freshOptions = this.#createOptions()\n\t\tif (freshOptions === undefined) {\n\t\t\tthis.#reportMissing()\n\t\t\treturn\n\t\t}\n\t\tconst freshParity = new Parity(freshOptions)\n\t\tconst freshReport = freshParity.inspect()\n\t\tif (this.#report(freshReport.input)) {\n\t\t\tthis.#raise(2)\n\t\t\treturn\n\t\t}\n\t\tconst remaining =\n\t\t\tdirection === 'guide' ? freshParity.document().findings : freshParity.annotate().findings\n\t\tif (this.#report(remaining)) this.#raise(1)\n\t\tif (this.#report(freshReport.pitch)) this.#raise(1)\n\t\tif (rewritten.changes.length > 0) process.stdout.write('next: npm run format\\n')\n\t\tif (!(await this.#executeRunner())) this.#raise(1)\n\t}\n\n\t#readInventory(): Readonly<Record<string, string>> {\n\t\tconst targets = globSync([...this.#patterns], { cwd: this.#root }).map((path) =>\n\t\t\tpath.replaceAll('\\\\', '/'),\n\t\t)\n\t\treturn Object.freeze({ ...this.#reader(this.#root, targets) })\n\t}\n\n\tasync #register(register: GuideCommandHandler): Promise<void> {\n\t\tconst options = this.#createOptions()\n\t\tif (options === undefined) {\n\t\t\tthrow new Error('The inventory carries no guides/README.md to index from')\n\t\t}\n\t\tconst parity = new Parity(options)\n\t\tconst context: GuideCommandContext = Object.freeze({\n\t\t\troot: this.#root,\n\t\t\tfiles: options.files,\n\t\t\trows: parity.rows(),\n\t\t\treport: parity.inspect(),\n\t\t})\n\t\tawait register(context)\n\t}\n\n\t#report(findings: readonly ParityFinding[]): boolean {\n\t\tfor (const finding of findings) {\n\t\t\tprocess.stdout.write(`${formatGuideFinding(finding)}\\n`)\n\t\t}\n\t\treturn findings.length > 0\n\t}\n\n\t#reportMissing(): void {\n\t\tprocess.stdout.write(`${GUIDE_INDEX}: the workspace carries no concept index to read\\n`)\n\t\tthis.#raise(2)\n\t}\n\n\tasync #executeRunner(): Promise<boolean> {\n\t\tconst runner = await this.#runner('test', {\n\t\t\troot: this.#root,\n\t\t\tconfig: resolve(this.#root, 'vite.config.ts'),\n\t\t\tproject: 'guides',\n\t\t\treporters: 'dot',\n\t\t\tcache: false,\n\t\t\twatch: false,\n\t\t})\n\t\tif (!isObject(runner)) throw new Error('The guides runner is not an object')\n\t\tconst close = Reflect.get(runner, 'close')\n\t\tif (!isFunction(close)) throw new Error('The guides runner has no callable close member')\n\t\ttry {\n\t\t\tconst start = Reflect.get(runner, 'start')\n\t\t\tif (!isFunction(start)) throw new Error('The guides runner has no callable start member')\n\t\t\treturn matchesGuideResult(await Reflect.apply(start, runner, []))\n\t\t} finally {\n\t\t\tawait Reflect.apply(close, runner, [])\n\t\t}\n\t}\n\n\t#raise(code: number): void {\n\t\tconst current = process.exitCode\n\t\tconst numeric = isString(current) ? Number.parseInt(current, 10) : current\n\t\tif (!isFiniteNumber(numeric) || numeric < code) {\n\t\t\tprocess.exitCode = code\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAC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AUP,aAAAA,QAAQ;EACxB,MAAM,WAAA,GAAUQ,oBAAAA,SAAAA,CAAS,OAAO,IAAI,OAAO,SAAS,SAAS,EAAE,IAAI;EACnE,IAAI,EAAA,GAACC,oBAAAA,eAAAA,CAAe,OAAO,KAAK,UAAU,MACzC,aAAA,QAAA,WAAmB;CAErB;AACD"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["isObject","isArray","isFunction","resolve","isInstance","fileURLToPath","parseEnum","parseJSONAs","isRecord","isNonEmptyString","process","isError","parseManifest","Parity","resolve","globSync","isObject","isFunction","isString","isFiniteNumber"],"sources":["../../../src/server/constants.ts","../../../src/server/helpers.ts","../../../src/server/parsers.ts","../../../src/server/GuideCommand.ts"],"sourcesContent":["/** Names the workspace-relative guide concept index. */\nexport const GUIDE_INDEX = 'guides/README.md'\n\n/** Names the package manifest read for native pitch selection. */\nexport const GUIDE_MANIFEST = 'package.json'\n\n/** Names the package README paired with its indexed guide pitch. */\nexport const GUIDE_README = 'README.md'\n\n/** Holds the native command usage text written for unsupported arguments. */\nexport const GUIDE_USAGE = 'usage: npm run test:guides [-- --to guide|--to source]'\n","import type { ManifestEntry, ParityFinding } from '@src/core'\nimport { isArray, isFunction, isInstance, isObject } from '@orkestrel/contract'\nimport { resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\n/**\n * Formats one finding with its guide prefix when needed.\n *\n * @param finding - The finding to format\n * @returns The finding text with its spec prefix when the text does not already carry it\n *\n * @example\n * ```ts\n * formatGuideFinding({ spec: 'guides/widget.md', text: 'missing export' })\n * ```\n */\nexport function formatGuideFinding(finding: ParityFinding): string {\n\tconst spec = finding.spec\n\tconst prefix = spec === undefined || finding.text.startsWith(spec) ? '' : `${spec} `\n\treturn `${prefix}${finding.text}`\n}\n\n/**\n * Reads an owned foreign result view and accepts passed modules without unhandled errors.\n *\n * @param result - The unknown external runner result to inspect\n * @returns True if a module is present, every module passed, and no unhandled error exists; false otherwise\n *\n * @example\n * ```ts\n * matchesGuideResult({ testModules: [{ state: () => 'passed' }], unhandledErrors: [] })\n * ```\n */\nexport function matchesGuideResult(result: unknown): boolean {\n\tif (!isObject(result)) return false\n\tconst testModules = Reflect.get(result, 'testModules')\n\tconst unhandledErrors = Reflect.get(result, 'unhandledErrors')\n\tif (!isArray(testModules) || !isArray(unhandledErrors)) return false\n\tconst modules = [...testModules]\n\tconst errors = [...unhandledErrors]\n\tif (modules.length === 0 || errors.length > 0) return false\n\tfor (const module of modules) {\n\t\tif (!isObject(module)) return false\n\t\tconst state = Reflect.get(module, 'state')\n\t\tif (!isFunction(state) || Reflect.apply(state, module, []) !== 'passed') return false\n\t}\n\treturn true\n}\n\n/**\n * Resolves a command root to a native absolute path.\n *\n * @param root - The workspace root as a file URL or native path\n * @returns The native absolute workspace path\n *\n * @example\n * ```ts\n * resolveGuideRoot('/workspace')\n * ```\n */\nexport function resolveGuideRoot(root: URL | string): string {\n\treturn resolve(isInstance(root, URL) ? fileURLToPath(root) : root)\n}\n\n/**\n * Selects the indexed guide matching a package's bare name.\n *\n * @param entries - The concept-index entries to search\n * @param name - The package's bare name, or `undefined` when none was parsed\n * @returns The indexed own-guide path, or `undefined` when the index carries none\n *\n * @example\n * ```ts\n * selectGuidePitch([{ concept: 'Widget', spec: 'guides/widget.md', source: 'src', tests: 'tests' }], 'widget')\n * ```\n */\nexport function selectGuidePitch(\n\tentries: readonly ManifestEntry[],\n\tname: string | undefined,\n): string | undefined {\n\tif (name === undefined) return undefined\n\tconst spec = `guides/${name}.md`\n\treturn entries.some((entry) => entry.spec === spec) ? spec : undefined\n}\n","import type { ParityDirection } from '@src/core'\nimport { isNonEmptyString, isRecord, parseEnum, parseJSONAs } from '@orkestrel/contract'\n\n/**\n * Maps the supported `--to guide` and `--to source` arguments to an explicit rewrite destination.\n *\n * @param args - The arguments after the native command entry\n * @returns The requested destination, or `undefined` when the shape is unsupported\n *\n * @example\n * ```ts\n * parseGuideDirection(['--to', 'guide'])\n * ```\n */\nexport function parseGuideDirection(args: readonly string[]): ParityDirection | undefined {\n\tif (args.length !== 2 || args[0] !== '--to') return undefined\n\treturn parseEnum(args[1], ['guide', 'source'])\n}\n\n/**\n * Reads the bare package name from package manifest JSON.\n *\n * @param manifest - The package manifest JSON text\n * @returns The name after its final scope separator, or `undefined` when no name is declared\n *\n * @example\n * ```ts\n * parsePackageName('{\"name\":\"@scope/widget\"}')\n * ```\n */\nexport function parsePackageName(manifest: string): string | undefined {\n\tconst parsed = parseJSONAs(manifest, isRecord)\n\tif (parsed === undefined) return undefined\n\tconst name = parsed.name\n\tif (!isNonEmptyString(name)) return undefined\n\treturn name.slice(name.lastIndexOf('/') + 1)\n}\n","import type {\n\tGuideCommandContext,\n\tGuideCommandHandler,\n\tGuideCommandInterface,\n\tGuideCommandOptions,\n\tGuideReadFunction,\n\tGuideRunnerFunction,\n} from './types.js'\nimport type { GuideModule, ParityFinding, ParityOptions } from '@src/core'\nimport { isError, isFiniteNumber, isFunction, isObject, isString } from '@orkestrel/contract'\nimport { globSync, writeFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport process from 'node:process'\nimport { Parity, parseManifest } from '@src/core'\nimport { GUIDE_INDEX, GUIDE_MANIFEST, GUIDE_README, GUIDE_USAGE } from './constants.js'\nimport {\n\tformatGuideFinding,\n\tmatchesGuideResult,\n\tresolveGuideRoot,\n\tselectGuidePitch,\n} from './helpers.js'\nimport { parseGuideDirection, parsePackageName } from './parsers.js'\n\n/**\n * Drives native checking and explicit rewrites or registers package assertions in the guides\n * worker.\n *\n * @param options - The workspace policy and direct host ports\n *\n * @example\n * ```ts\n * import { GuideCommand } from '@orkestrel/guide/server'\n * import { readInventory } from '@orkestrel/test/server'\n * import { createVitest } from 'vitest/node'\n *\n * await new GuideCommand({\n * \troot: new URL('../', import.meta.url),\n * \tpatterns: ['src/**\\/*.ts', 'tests/**\\/*.ts', 'guides/*.md', '*.md'],\n * \tmodules: { '@scope/widget': 'src/core' },\n * \tlanguages: ['ts'],\n * \tlanguage: 'ts',\n * \treader: readInventory,\n * \trunner: createVitest,\n * }).execute(async ({ files, report, root, rows }) => {\n * \tconst { expect, it } = await import('vitest')\n * \tit('checks the documented inventory', () => {\n * \t\texpect(root.length).toBeGreaterThan(0)\n * \t\texpect(Object.keys(files).length).toBeGreaterThan(0)\n * \t\texpect(rows.length).toBeGreaterThan(0)\n * \t\texpect(report.input).toEqual([])\n * \t})\n * })\n * ```\n */\nexport class GuideCommand implements GuideCommandInterface {\n\treadonly #root: string\n\treadonly #patterns: readonly string[]\n\treadonly #modules: Readonly<Record<string, GuideModule>>\n\treadonly #languages: readonly string[]\n\treadonly #language: string\n\treadonly #reader: GuideReadFunction\n\treadonly #runner: GuideRunnerFunction\n\n\tconstructor(options: GuideCommandOptions) {\n\t\tthis.#root = resolveGuideRoot(options.root)\n\t\tthis.#patterns = Object.freeze([...options.patterns])\n\t\tthis.#modules = Object.freeze({ ...options.modules })\n\t\tthis.#languages = Object.freeze([...options.languages])\n\t\tthis.#language = options.language\n\t\tthis.#reader = options.reader\n\t\tthis.#runner = options.runner\n\t}\n\n\t/**\n\t * Runs the native command or registers package assertions with fresh worker inventory and parity.\n\t *\n\t * @param register - The package-owned assertion registration callback\n\t * @returns A promise that resolves after the selected command path finishes\n\t * @throws When worker inventory reading or package assertion registration fails. Native failures\n\t * are reported through stderr and process exit status before this promise resolves.\n\t */\n\tasync execute(register: GuideCommandHandler): Promise<void> {\n\t\tif (process.env.VITEST === 'true') {\n\t\t\tawait this.#register(register)\n\t\t\treturn\n\t\t}\n\t\ttry {\n\t\t\tawait this.#executeNative()\n\t\t} catch (error) {\n\t\t\tprocess.stderr.write(`${isError(error) ? error.message : String(error)}\\n`)\n\t\t\tthis.#raise(1)\n\t\t}\n\t}\n\n\t#createOptions(): ParityOptions | undefined {\n\t\tconst files = this.#readInventory()\n\t\tconst manifest = files[GUIDE_INDEX]\n\t\tif (manifest === undefined) return undefined\n\t\tconst entries = Object.freeze([...parseManifest(manifest, 'guides')])\n\t\tconst packageFiles = Object.freeze({ ...this.#reader(this.#root, [GUIDE_MANIFEST]) })\n\t\tconst packageManifest = packageFiles[GUIDE_MANIFEST]\n\t\tconst pitch = selectGuidePitch(\n\t\t\tentries,\n\t\t\tpackageManifest === undefined ? undefined : parsePackageName(packageManifest),\n\t\t)\n\t\treturn {\n\t\t\tfiles,\n\t\t\tentries,\n\t\t\tmodules: this.#modules,\n\t\t\tlanguages: this.#languages,\n\t\t\tlanguage: this.#language,\n\t\t\t...(pitch === undefined\n\t\t\t\t? {}\n\t\t\t\t: { pitch: Object.freeze({ readme: GUIDE_README, spec: pitch }) }),\n\t\t}\n\t}\n\n\tasync #executeNative(): Promise<void> {\n\t\tconst args = process.argv.slice(2)\n\t\tconst direction = parseGuideDirection(args)\n\t\tif (direction === undefined && args.length > 0) {\n\t\t\tprocess.stdout.write(`${GUIDE_USAGE}\\n`)\n\t\t\tthis.#raise(2)\n\t\t\treturn\n\t\t}\n\t\tif (direction === undefined) {\n\t\t\tif (!(await this.#executeRunner())) this.#raise(1)\n\t\t\treturn\n\t\t}\n\n\t\tconst options = this.#createOptions()\n\t\tif (options === undefined) {\n\t\t\tthis.#reportMissing()\n\t\t\treturn\n\t\t}\n\t\tconst parity = new Parity(options)\n\t\tif (this.#report(parity.inspect().input)) {\n\t\t\tthis.#raise(2)\n\t\t\treturn\n\t\t}\n\t\tconst rewritten = direction === 'guide' ? parity.document() : parity.annotate()\n\t\tfor (const change of rewritten.changes) {\n\t\t\twriteFileSync(resolve(this.#root, change.path), change.content)\n\t\t\tprocess.stdout.write(`wrote ${change.path}\\n`)\n\t\t}\n\n\t\tconst freshOptions = this.#createOptions()\n\t\tif (freshOptions === undefined) {\n\t\t\tthis.#reportMissing()\n\t\t\treturn\n\t\t}\n\t\tconst freshParity = new Parity(freshOptions)\n\t\tconst freshReport = freshParity.inspect()\n\t\tif (this.#report(freshReport.input)) {\n\t\t\tthis.#raise(2)\n\t\t\treturn\n\t\t}\n\t\tconst remaining =\n\t\t\tdirection === 'guide' ? freshParity.document().findings : freshParity.annotate().findings\n\t\tif (this.#report(remaining)) this.#raise(1)\n\t\tif (this.#report(freshReport.pitch)) this.#raise(1)\n\t\tif (rewritten.changes.length > 0) process.stdout.write('next: npm run format\\n')\n\t\tif (!(await this.#executeRunner())) this.#raise(1)\n\t}\n\n\t#readInventory(): Readonly<Record<string, string>> {\n\t\tconst targets = globSync([...this.#patterns], { cwd: this.#root }).map((path) =>\n\t\t\tpath.replaceAll('\\\\', '/'),\n\t\t)\n\t\treturn Object.freeze({ ...this.#reader(this.#root, targets) })\n\t}\n\n\tasync #register(register: GuideCommandHandler): Promise<void> {\n\t\tconst options = this.#createOptions()\n\t\tif (options === undefined) {\n\t\t\tthrow new Error('The inventory carries no guides/README.md to index from')\n\t\t}\n\t\tconst parity = new Parity(options)\n\t\tconst context: GuideCommandContext = Object.freeze({\n\t\t\troot: this.#root,\n\t\t\tfiles: options.files,\n\t\t\trows: parity.rows(),\n\t\t\treport: parity.inspect(),\n\t\t})\n\t\tawait register(context)\n\t}\n\n\t#report(findings: readonly ParityFinding[]): boolean {\n\t\tfor (const finding of findings) {\n\t\t\tprocess.stdout.write(`${formatGuideFinding(finding)}\\n`)\n\t\t}\n\t\treturn findings.length > 0\n\t}\n\n\t#reportMissing(): void {\n\t\tprocess.stdout.write(`${GUIDE_INDEX}: the workspace carries no concept index to read\\n`)\n\t\tthis.#raise(2)\n\t}\n\n\tasync #executeRunner(): Promise<boolean> {\n\t\tconst runner = await this.#runner('test', {\n\t\t\troot: this.#root,\n\t\t\tconfig: resolve(this.#root, 'vite.config.ts'),\n\t\t\tproject: 'guides',\n\t\t\treporters: 'dot',\n\t\t\tcache: false,\n\t\t\twatch: false,\n\t\t})\n\t\tif (!isObject(runner)) throw new Error('The guides runner is not an object')\n\t\tconst close = Reflect.get(runner, 'close')\n\t\tif (!isFunction(close)) throw new Error('The guides runner has no callable close member')\n\t\ttry {\n\t\t\tconst start = Reflect.get(runner, 'start')\n\t\t\tif (!isFunction(start)) throw new Error('The guides runner has no callable start member')\n\t\t\treturn matchesGuideResult(await Reflect.apply(start, runner, []))\n\t\t} finally {\n\t\t\tawait Reflect.apply(close, runner, [])\n\t\t}\n\t}\n\n\t#raise(code: number): void {\n\t\tconst current = process.exitCode\n\t\tconst numeric = isString(current) ? Number.parseInt(current, 10) : current\n\t\tif (!isFiniteNumber(numeric) || numeric < code) {\n\t\t\tprocess.exitCode = code\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAa,cAAc;;AAG3B,IAAa,iBAAiB;;AAG9B,IAAa,eAAe;;AAG5B,IAAa,cAAc;;;;;;;;;;;;;ACM3B,SAAgB,mBAAmB,SAAgC;CAClE,MAAM,OAAO,QAAQ;CAErB,OAAO,GADQ,SAAS,KAAA,KAAa,QAAQ,KAAK,WAAW,IAAI,IAAI,KAAK,GAAG,KAAK,KAC/D,QAAQ;AAC5B;;;;;;;;;;;;AAaA,SAAgB,mBAAmB,QAA0B;CAC5D,IAAI,EAAA,GAACA,oBAAAA,SAAAA,CAAS,MAAM,GAAG,OAAO;CAC9B,MAAM,cAAc,QAAQ,IAAI,QAAQ,aAAa;CACrD,MAAM,kBAAkB,QAAQ,IAAI,QAAQ,iBAAiB;CAC7D,IAAI,EAAA,GAACC,oBAAAA,QAAAA,CAAQ,WAAW,KAAK,EAAA,GAACA,oBAAAA,QAAAA,CAAQ,eAAe,GAAG,OAAO;CAC/D,MAAM,UAAU,CAAC,GAAG,WAAW;CAC/B,MAAM,SAAS,CAAC,GAAG,eAAe;CAClC,IAAI,QAAQ,WAAW,KAAK,OAAO,SAAS,GAAG,OAAO;CACtD,KAAK,MAAM,UAAU,SAAS;EAC7B,IAAI,EAAA,GAACD,oBAAAA,SAAAA,CAAS,MAAM,GAAG,OAAO;EAC9B,MAAM,QAAQ,QAAQ,IAAI,QAAQ,OAAO;EACzC,IAAI,EAAA,GAACE,oBAAAA,WAAAA,CAAW,KAAK,KAAK,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,gDAAgD;EACxF,IAAI;GACH,MAAM,QAAQ,QAAQ,IAAI,QAAQ,OAAO;GACzC,IAAI,EAAA,GAACA,oBAAAA,WAAAA,CAAW,KAAK,GAAG,MAAM,IAAI,MAAM,gDAAgD;GACxF,OAAO,mBAAmB,MAAM,QAAQ,MAAM,OAAO,QAAQ,CAAC,CAAC,CAAC;EACjE,UAAU;GACT,MAAM,QAAQ,MAAM,OAAO,QAAQ,CAAC,CAAC;EACtC;CACD;CAEA,OAAO,MAAoB;EAC1B,MAAM,UAAUP,aAAAA,QAAQ;EACxB,MAAM,WAAA,GAAUQ,oBAAAA,SAAAA,CAAS,OAAO,IAAI,OAAO,SAAS,SAAS,EAAE,IAAI;EACnE,IAAI,EAAA,GAACC,oBAAAA,eAAAA,CAAe,OAAO,KAAK,UAAU,MACzC,aAAA,QAAA,WAAmB;CAErB;AACD"}
|
package/dist/src/server/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url";
|
|
|
4
4
|
import { globSync, writeFileSync } from "node:fs";
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
import { Parity, parseManifest } from "../core/index.js";
|
|
7
|
-
|
|
7
|
+
// src/server/constants.ts
|
|
8
8
|
/** Names the workspace-relative guide concept index. */
|
|
9
9
|
var GUIDE_INDEX = "guides/README.md";
|
|
10
10
|
/** Names the package manifest read for native pitch selection. */
|
|
@@ -13,8 +13,7 @@ var GUIDE_MANIFEST = "package.json";
|
|
|
13
13
|
var GUIDE_README = "README.md";
|
|
14
14
|
/** Holds the native command usage text written for unsupported arguments. */
|
|
15
15
|
var GUIDE_USAGE = "usage: npm run test:guides [-- --to guide|--to source]";
|
|
16
|
-
|
|
17
|
-
//#region src/server/helpers.ts
|
|
16
|
+
// src/server/helpers.ts
|
|
18
17
|
/**
|
|
19
18
|
* Formats one finding with its guide prefix when needed.
|
|
20
19
|
*
|
|
@@ -87,8 +86,7 @@ function selectGuidePitch(entries, name) {
|
|
|
87
86
|
const spec = `guides/${name}.md`;
|
|
88
87
|
return entries.some((entry) => entry.spec === spec) ? spec : void 0;
|
|
89
88
|
}
|
|
90
|
-
|
|
91
|
-
//#region src/server/parsers.ts
|
|
89
|
+
// src/server/parsers.ts
|
|
92
90
|
/**
|
|
93
91
|
* Maps the supported `--to guide` and `--to source` arguments to an explicit rewrite destination.
|
|
94
92
|
*
|
|
@@ -122,8 +120,7 @@ function parsePackageName(manifest) {
|
|
|
122
120
|
if (!isNonEmptyString(name)) return void 0;
|
|
123
121
|
return name.slice(name.lastIndexOf("/") + 1);
|
|
124
122
|
}
|
|
125
|
-
|
|
126
|
-
//#region src/server/GuideCommand.ts
|
|
123
|
+
// src/server/GuideCommand.ts
|
|
127
124
|
/**
|
|
128
125
|
* Drives native checking and explicit rewrites or registers package assertions in the guides
|
|
129
126
|
* worker.
|
|
@@ -304,7 +301,6 @@ var GuideCommand = class {
|
|
|
304
301
|
if (!isFiniteNumber(numeric) || numeric < code) process.exitCode = code;
|
|
305
302
|
}
|
|
306
303
|
};
|
|
307
|
-
//#endregion
|
|
308
304
|
export { GUIDE_INDEX, GUIDE_MANIFEST, GUIDE_README, GUIDE_USAGE, GuideCommand, formatGuideFinding, matchesGuideResult, parseGuideDirection, parsePackageName, resolveGuideRoot, selectGuidePitch };
|
|
309
305
|
|
|
310
306
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/server/constants.ts","../../../src/server/helpers.ts","../../../src/server/parsers.ts","../../../src/server/GuideCommand.ts"],"sourcesContent":["/** Names the workspace-relative guide concept index. */\nexport const GUIDE_INDEX = 'guides/README.md'\n\n/** Names the package manifest read for native pitch selection. */\nexport const GUIDE_MANIFEST = 'package.json'\n\n/** Names the package README paired with its indexed guide pitch. */\nexport const GUIDE_README = 'README.md'\n\n/** Holds the native command usage text written for unsupported arguments. */\nexport const GUIDE_USAGE = 'usage: npm run test:guides [-- --to guide|--to source]'\n","import type { ManifestEntry, ParityFinding } from '@src/core'\nimport { isArray, isFunction, isInstance, isObject } from '@orkestrel/contract'\nimport { resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\n/**\n * Formats one finding with its guide prefix when needed.\n *\n * @param finding - The finding to format\n * @returns The finding text with its spec prefix when the text does not already carry it\n *\n * @example\n * ```ts\n * formatGuideFinding({ spec: 'guides/widget.md', text: 'missing export' })\n * ```\n */\nexport function formatGuideFinding(finding: ParityFinding): string {\n\tconst spec = finding.spec\n\tconst prefix = spec === undefined || finding.text.startsWith(spec) ? '' : `${spec} `\n\treturn `${prefix}${finding.text}`\n}\n\n/**\n * Reads an owned foreign result view and accepts passed modules without unhandled errors.\n *\n * @param result - The unknown external runner result to inspect\n * @returns True if a module is present, every module passed, and no unhandled error exists; false otherwise\n *\n * @example\n * ```ts\n * matchesGuideResult({ testModules: [{ state: () => 'passed' }], unhandledErrors: [] })\n * ```\n */\nexport function matchesGuideResult(result: unknown): boolean {\n\tif (!isObject(result)) return false\n\tconst testModules = Reflect.get(result, 'testModules')\n\tconst unhandledErrors = Reflect.get(result, 'unhandledErrors')\n\tif (!isArray(testModules) || !isArray(unhandledErrors)) return false\n\tconst modules = [...testModules]\n\tconst errors = [...unhandledErrors]\n\tif (modules.length === 0 || errors.length > 0) return false\n\tfor (const module of modules) {\n\t\tif (!isObject(module)) return false\n\t\tconst state = Reflect.get(module, 'state')\n\t\tif (!isFunction(state) || Reflect.apply(state, module, []) !== 'passed') return false\n\t}\n\treturn true\n}\n\n/**\n * Resolves a command root to a native absolute path.\n *\n * @param root - The workspace root as a file URL or native path\n * @returns The native absolute workspace path\n *\n * @example\n * ```ts\n * resolveGuideRoot('/workspace')\n * ```\n */\nexport function resolveGuideRoot(root: URL | string): string {\n\treturn resolve(isInstance(root, URL) ? fileURLToPath(root) : root)\n}\n\n/**\n * Selects the indexed guide matching a package's bare name.\n *\n * @param entries - The concept-index entries to search\n * @param name - The package's bare name, or `undefined` when none was parsed\n * @returns The indexed own-guide path, or `undefined` when the index carries none\n *\n * @example\n * ```ts\n * selectGuidePitch([{ concept: 'Widget', spec: 'guides/widget.md', source: 'src', tests: 'tests' }], 'widget')\n * ```\n */\nexport function selectGuidePitch(\n\tentries: readonly ManifestEntry[],\n\tname: string | undefined,\n): string | undefined {\n\tif (name === undefined) return undefined\n\tconst spec = `guides/${name}.md`\n\treturn entries.some((entry) => entry.spec === spec) ? spec : undefined\n}\n","import type { ParityDirection } from '@src/core'\nimport { isNonEmptyString, isRecord, parseEnum, parseJSONAs } from '@orkestrel/contract'\n\n/**\n * Maps the supported `--to guide` and `--to source` arguments to an explicit rewrite destination.\n *\n * @param args - The arguments after the native command entry\n * @returns The requested destination, or `undefined` when the shape is unsupported\n *\n * @example\n * ```ts\n * parseGuideDirection(['--to', 'guide'])\n * ```\n */\nexport function parseGuideDirection(args: readonly string[]): ParityDirection | undefined {\n\tif (args.length !== 2 || args[0] !== '--to') return undefined\n\treturn parseEnum(args[1], ['guide', 'source'])\n}\n\n/**\n * Reads the bare package name from package manifest JSON.\n *\n * @param manifest - The package manifest JSON text\n * @returns The name after its final scope separator, or `undefined` when no name is declared\n *\n * @example\n * ```ts\n * parsePackageName('{\"name\":\"@scope/widget\"}')\n * ```\n */\nexport function parsePackageName(manifest: string): string | undefined {\n\tconst parsed = parseJSONAs(manifest, isRecord)\n\tif (parsed === undefined) return undefined\n\tconst name = parsed.name\n\tif (!isNonEmptyString(name)) return undefined\n\treturn name.slice(name.lastIndexOf('/') + 1)\n}\n","import type {\n\tGuideCommandContext,\n\tGuideCommandHandler,\n\tGuideCommandInterface,\n\tGuideCommandOptions,\n\tGuideReadFunction,\n\tGuideRunnerFunction,\n} from './types.js'\nimport type { GuideModule, ParityFinding, ParityOptions } from '@src/core'\nimport { isError, isFiniteNumber, isFunction, isObject, isString } from '@orkestrel/contract'\nimport { globSync, writeFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport process from 'node:process'\nimport { Parity, parseManifest } from '@src/core'\nimport { GUIDE_INDEX, GUIDE_MANIFEST, GUIDE_README, GUIDE_USAGE } from './constants.js'\nimport {\n\tformatGuideFinding,\n\tmatchesGuideResult,\n\tresolveGuideRoot,\n\tselectGuidePitch,\n} from './helpers.js'\nimport { parseGuideDirection, parsePackageName } from './parsers.js'\n\n/**\n * Drives native checking and explicit rewrites or registers package assertions in the guides\n * worker.\n *\n * @param options - The workspace policy and direct host ports\n *\n * @example\n * ```ts\n * import { GuideCommand } from '@orkestrel/guide/server'\n * import { readInventory } from '@orkestrel/test/server'\n * import { createVitest } from 'vitest/node'\n *\n * await new GuideCommand({\n * \troot: new URL('../', import.meta.url),\n * \tpatterns: ['src/**\\/*.ts', 'tests/**\\/*.ts', 'guides/*.md', '*.md'],\n * \tmodules: { '@scope/widget': 'src/core' },\n * \tlanguages: ['ts'],\n * \tlanguage: 'ts',\n * \treader: readInventory,\n * \trunner: createVitest,\n * }).execute(async ({ files, report, root, rows }) => {\n * \tconst { expect, it } = await import('vitest')\n * \tit('checks the documented inventory', () => {\n * \t\texpect(root.length).toBeGreaterThan(0)\n * \t\texpect(Object.keys(files).length).toBeGreaterThan(0)\n * \t\texpect(rows.length).toBeGreaterThan(0)\n * \t\texpect(report.input).toEqual([])\n * \t})\n * })\n * ```\n */\nexport class GuideCommand implements GuideCommandInterface {\n\treadonly #root: string\n\treadonly #patterns: readonly string[]\n\treadonly #modules: Readonly<Record<string, GuideModule>>\n\treadonly #languages: readonly string[]\n\treadonly #language: string\n\treadonly #reader: GuideReadFunction\n\treadonly #runner: GuideRunnerFunction\n\n\tconstructor(options: GuideCommandOptions) {\n\t\tthis.#root = resolveGuideRoot(options.root)\n\t\tthis.#patterns = Object.freeze([...options.patterns])\n\t\tthis.#modules = Object.freeze({ ...options.modules })\n\t\tthis.#languages = Object.freeze([...options.languages])\n\t\tthis.#language = options.language\n\t\tthis.#reader = options.reader\n\t\tthis.#runner = options.runner\n\t}\n\n\t/**\n\t * Runs the native command or registers package assertions with fresh worker inventory and parity.\n\t *\n\t * @param register - The package-owned assertion registration callback\n\t * @returns A promise that resolves after the selected command path finishes\n\t * @throws When worker inventory reading or package assertion registration fails. Native failures\n\t * are reported through stderr and process exit status before this promise resolves.\n\t */\n\tasync execute(register: GuideCommandHandler): Promise<void> {\n\t\tif (process.env.VITEST === 'true') {\n\t\t\tawait this.#register(register)\n\t\t\treturn\n\t\t}\n\t\ttry {\n\t\t\tawait this.#executeNative()\n\t\t} catch (error) {\n\t\t\tprocess.stderr.write(`${isError(error) ? error.message : String(error)}\\n`)\n\t\t\tthis.#raise(1)\n\t\t}\n\t}\n\n\t#createOptions(): ParityOptions | undefined {\n\t\tconst files = this.#readInventory()\n\t\tconst manifest = files[GUIDE_INDEX]\n\t\tif (manifest === undefined) return undefined\n\t\tconst entries = Object.freeze([...parseManifest(manifest, 'guides')])\n\t\tconst packageFiles = Object.freeze({ ...this.#reader(this.#root, [GUIDE_MANIFEST]) })\n\t\tconst packageManifest = packageFiles[GUIDE_MANIFEST]\n\t\tconst pitch = selectGuidePitch(\n\t\t\tentries,\n\t\t\tpackageManifest === undefined ? undefined : parsePackageName(packageManifest),\n\t\t)\n\t\treturn {\n\t\t\tfiles,\n\t\t\tentries,\n\t\t\tmodules: this.#modules,\n\t\t\tlanguages: this.#languages,\n\t\t\tlanguage: this.#language,\n\t\t\t...(pitch === undefined\n\t\t\t\t? {}\n\t\t\t\t: { pitch: Object.freeze({ readme: GUIDE_README, spec: pitch }) }),\n\t\t}\n\t}\n\n\tasync #executeNative(): Promise<void> {\n\t\tconst args = process.argv.slice(2)\n\t\tconst direction = parseGuideDirection(args)\n\t\tif (direction === undefined && args.length > 0) {\n\t\t\tprocess.stdout.write(`${GUIDE_USAGE}\\n`)\n\t\t\tthis.#raise(2)\n\t\t\treturn\n\t\t}\n\t\tif (direction === undefined) {\n\t\t\tif (!(await this.#executeRunner())) this.#raise(1)\n\t\t\treturn\n\t\t}\n\n\t\tconst options = this.#createOptions()\n\t\tif (options === undefined) {\n\t\t\tthis.#reportMissing()\n\t\t\treturn\n\t\t}\n\t\tconst parity = new Parity(options)\n\t\tif (this.#report(parity.inspect().input)) {\n\t\t\tthis.#raise(2)\n\t\t\treturn\n\t\t}\n\t\tconst rewritten = direction === 'guide' ? parity.document() : parity.annotate()\n\t\tfor (const change of rewritten.changes) {\n\t\t\twriteFileSync(resolve(this.#root, change.path), change.content)\n\t\t\tprocess.stdout.write(`wrote ${change.path}\\n`)\n\t\t}\n\n\t\tconst freshOptions = this.#createOptions()\n\t\tif (freshOptions === undefined) {\n\t\t\tthis.#reportMissing()\n\t\t\treturn\n\t\t}\n\t\tconst freshParity = new Parity(freshOptions)\n\t\tconst freshReport = freshParity.inspect()\n\t\tif (this.#report(freshReport.input)) {\n\t\t\tthis.#raise(2)\n\t\t\treturn\n\t\t}\n\t\tconst remaining =\n\t\t\tdirection === 'guide' ? freshParity.document().findings : freshParity.annotate().findings\n\t\tif (this.#report(remaining)) this.#raise(1)\n\t\tif (this.#report(freshReport.pitch)) this.#raise(1)\n\t\tif (rewritten.changes.length > 0) process.stdout.write('next: npm run format\\n')\n\t\tif (!(await this.#executeRunner())) this.#raise(1)\n\t}\n\n\t#readInventory(): Readonly<Record<string, string>> {\n\t\tconst targets = globSync([...this.#patterns], { cwd: this.#root }).map((path) =>\n\t\t\tpath.replaceAll('\\\\', '/'),\n\t\t)\n\t\treturn Object.freeze({ ...this.#reader(this.#root, targets) })\n\t}\n\n\tasync #register(register: GuideCommandHandler): Promise<void> {\n\t\tconst options = this.#createOptions()\n\t\tif (options === undefined) {\n\t\t\tthrow new Error('The inventory carries no guides/README.md to index from')\n\t\t}\n\t\tconst parity = new Parity(options)\n\t\tconst context: GuideCommandContext = Object.freeze({\n\t\t\troot: this.#root,\n\t\t\tfiles: options.files,\n\t\t\trows: parity.rows(),\n\t\t\treport: parity.inspect(),\n\t\t})\n\t\tawait register(context)\n\t}\n\n\t#report(findings: readonly ParityFinding[]): boolean {\n\t\tfor (const finding of findings) {\n\t\t\tprocess.stdout.write(`${formatGuideFinding(finding)}\\n`)\n\t\t}\n\t\treturn findings.length > 0\n\t}\n\n\t#reportMissing(): void {\n\t\tprocess.stdout.write(`${GUIDE_INDEX}: the workspace carries no concept index to read\\n`)\n\t\tthis.#raise(2)\n\t}\n\n\tasync #executeRunner(): Promise<boolean> {\n\t\tconst runner = await this.#runner('test', {\n\t\t\troot: this.#root,\n\t\t\tconfig: resolve(this.#root, 'vite.config.ts'),\n\t\t\tproject: 'guides',\n\t\t\treporters: 'dot',\n\t\t\tcache: false,\n\t\t\twatch: false,\n\t\t})\n\t\tif (!isObject(runner)) throw new Error('The guides runner is not an object')\n\t\tconst close = Reflect.get(runner, 'close')\n\t\tif (!isFunction(close)) throw new Error('The guides runner has no callable close member')\n\t\ttry {\n\t\t\tconst start = Reflect.get(runner, 'start')\n\t\t\tif (!isFunction(start)) throw new Error('The guides runner has no callable start member')\n\t\t\treturn matchesGuideResult(await Reflect.apply(start, runner, []))\n\t\t} finally {\n\t\t\tawait Reflect.apply(close, runner, [])\n\t\t}\n\t}\n\n\t#raise(code: number): void {\n\t\tconst current = process.exitCode\n\t\tconst numeric = isString(current) ? Number.parseInt(current, 10) : current\n\t\tif (!isFiniteNumber(numeric) || numeric < code) {\n\t\t\tprocess.exitCode = code\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;AACA,IAAa,cAAc;;AAG3B,IAAa,iBAAiB;;AAG9B,IAAa,eAAe;;AAG5B,IAAa,cAAc;;;;;;;;;;;;;;ACM3B,SAAgB,mBAAmB,SAAgC;CAClE,MAAM,OAAO,QAAQ;CAErB,OAAO,GADQ,SAAS,KAAA,KAAa,QAAQ,KAAK,WAAW,IAAI,IAAI,KAAK,GAAG,KAAK,KAC/D,QAAQ;AAC5B;;;;;;;;;;;;AAaA,SAAgB,mBAAmB,QAA0B;CAC5D,IAAI,CAAC,SAAS,MAAM,GAAG,OAAO;CAC9B,MAAM,cAAc,QAAQ,IAAI,QAAQ,aAAa;CACrD,MAAM,kBAAkB,Q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;EACxF,IAAI;GACH,MAAM,QAAQ,QAAQ,IAAI,QAAQ,OAAO;GACzC,IAAI,CAAC,WAAW,KAAK,GAAG,MAAM,IAAI,MAAM,gDAAgD;GACxF,OAAO,mBAAmB,MAAM,QAAQ,MAAM,OAAO,QAAQ,CAAC,CAAC,CAAC;EACjE,UAAU;GACT,MAAM,QAAQ,MAAM,OAAO,QAAQ,CAAC,CAAC;EACtC;CACD;CAEA,OAAO,MAAoB;EAC1B,MAAM,UAAU,QAAQ;EACxB,MAAM,UAAU,SAAS,OAAO,IAAI,OAAO,SAAS,SAAS,EAAE,IAAI;EACnE,IAAI,CAAC,eAAe,OAAO,KAAK,UAAU,MACzC,QAAQ,WAAW;CAErB;AACD"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/server/constants.ts","../../../src/server/helpers.ts","../../../src/server/parsers.ts","../../../src/server/GuideCommand.ts"],"sourcesContent":["/** Names the workspace-relative guide concept index. */\nexport const GUIDE_INDEX = 'guides/README.md'\n\n/** Names the package manifest read for native pitch selection. */\nexport const GUIDE_MANIFEST = 'package.json'\n\n/** Names the package README paired with its indexed guide pitch. */\nexport const GUIDE_README = 'README.md'\n\n/** Holds the native command usage text written for unsupported arguments. */\nexport const GUIDE_USAGE = 'usage: npm run test:guides [-- --to guide|--to source]'\n","import type { ManifestEntry, ParityFinding } from '@src/core'\nimport { isArray, isFunction, isInstance, isObject } from '@orkestrel/contract'\nimport { resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\n/**\n * Formats one finding with its guide prefix when needed.\n *\n * @param finding - The finding to format\n * @returns The finding text with its spec prefix when the text does not already carry it\n *\n * @example\n * ```ts\n * formatGuideFinding({ spec: 'guides/widget.md', text: 'missing export' })\n * ```\n */\nexport function formatGuideFinding(finding: ParityFinding): string {\n\tconst spec = finding.spec\n\tconst prefix = spec === undefined || finding.text.startsWith(spec) ? '' : `${spec} `\n\treturn `${prefix}${finding.text}`\n}\n\n/**\n * Reads an owned foreign result view and accepts passed modules without unhandled errors.\n *\n * @param result - The unknown external runner result to inspect\n * @returns True if a module is present, every module passed, and no unhandled error exists; false otherwise\n *\n * @example\n * ```ts\n * matchesGuideResult({ testModules: [{ state: () => 'passed' }], unhandledErrors: [] })\n * ```\n */\nexport function matchesGuideResult(result: unknown): boolean {\n\tif (!isObject(result)) return false\n\tconst testModules = Reflect.get(result, 'testModules')\n\tconst unhandledErrors = Reflect.get(result, 'unhandledErrors')\n\tif (!isArray(testModules) || !isArray(unhandledErrors)) return false\n\tconst modules = [...testModules]\n\tconst errors = [...unhandledErrors]\n\tif (modules.length === 0 || errors.length > 0) return false\n\tfor (const module of modules) {\n\t\tif (!isObject(module)) return false\n\t\tconst state = Reflect.get(module, 'state')\n\t\tif (!isFunction(state) || Reflect.apply(state, module, []) !== 'passed') return false\n\t}\n\treturn true\n}\n\n/**\n * Resolves a command root to a native absolute path.\n *\n * @param root - The workspace root as a file URL or native path\n * @returns The native absolute workspace path\n *\n * @example\n * ```ts\n * resolveGuideRoot('/workspace')\n * ```\n */\nexport function resolveGuideRoot(root: URL | string): string {\n\treturn resolve(isInstance(root, URL) ? fileURLToPath(root) : root)\n}\n\n/**\n * Selects the indexed guide matching a package's bare name.\n *\n * @param entries - The concept-index entries to search\n * @param name - The package's bare name, or `undefined` when none was parsed\n * @returns The indexed own-guide path, or `undefined` when the index carries none\n *\n * @example\n * ```ts\n * selectGuidePitch([{ concept: 'Widget', spec: 'guides/widget.md', source: 'src', tests: 'tests' }], 'widget')\n * ```\n */\nexport function selectGuidePitch(\n\tentries: readonly ManifestEntry[],\n\tname: string | undefined,\n): string | undefined {\n\tif (name === undefined) return undefined\n\tconst spec = `guides/${name}.md`\n\treturn entries.some((entry) => entry.spec === spec) ? spec : undefined\n}\n","import type { ParityDirection } from '@src/core'\nimport { isNonEmptyString, isRecord, parseEnum, parseJSONAs } from '@orkestrel/contract'\n\n/**\n * Maps the supported `--to guide` and `--to source` arguments to an explicit rewrite destination.\n *\n * @param args - The arguments after the native command entry\n * @returns The requested destination, or `undefined` when the shape is unsupported\n *\n * @example\n * ```ts\n * parseGuideDirection(['--to', 'guide'])\n * ```\n */\nexport function parseGuideDirection(args: readonly string[]): ParityDirection | undefined {\n\tif (args.length !== 2 || args[0] !== '--to') return undefined\n\treturn parseEnum(args[1], ['guide', 'source'])\n}\n\n/**\n * Reads the bare package name from package manifest JSON.\n *\n * @param manifest - The package manifest JSON text\n * @returns The name after its final scope separator, or `undefined` when no name is declared\n *\n * @example\n * ```ts\n * parsePackageName('{\"name\":\"@scope/widget\"}')\n * ```\n */\nexport function parsePackageName(manifest: string): string | undefined {\n\tconst parsed = parseJSONAs(manifest, isRecord)\n\tif (parsed === undefined) return undefined\n\tconst name = parsed.name\n\tif (!isNonEmptyString(name)) return undefined\n\treturn name.slice(name.lastIndexOf('/') + 1)\n}\n","import type {\n\tGuideCommandContext,\n\tGuideCommandHandler,\n\tGuideCommandInterface,\n\tGuideCommandOptions,\n\tGuideReadFunction,\n\tGuideRunnerFunction,\n} from './types.js'\nimport type { GuideModule, ParityFinding, ParityOptions } from '@src/core'\nimport { isError, isFiniteNumber, isFunction, isObject, isString } from '@orkestrel/contract'\nimport { globSync, writeFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport process from 'node:process'\nimport { Parity, parseManifest } from '@src/core'\nimport { GUIDE_INDEX, GUIDE_MANIFEST, GUIDE_README, GUIDE_USAGE } from './constants.js'\nimport {\n\tformatGuideFinding,\n\tmatchesGuideResult,\n\tresolveGuideRoot,\n\tselectGuidePitch,\n} from './helpers.js'\nimport { parseGuideDirection, parsePackageName } from './parsers.js'\n\n/**\n * Drives native checking and explicit rewrites or registers package assertions in the guides\n * worker.\n *\n * @param options - The workspace policy and direct host ports\n *\n * @example\n * ```ts\n * import { GuideCommand } from '@orkestrel/guide/server'\n * import { readInventory } from '@orkestrel/test/server'\n * import { createVitest } from 'vitest/node'\n *\n * await new GuideCommand({\n * \troot: new URL('../', import.meta.url),\n * \tpatterns: ['src/**\\/*.ts', 'tests/**\\/*.ts', 'guides/*.md', '*.md'],\n * \tmodules: { '@scope/widget': 'src/core' },\n * \tlanguages: ['ts'],\n * \tlanguage: 'ts',\n * \treader: readInventory,\n * \trunner: createVitest,\n * }).execute(async ({ files, report, root, rows }) => {\n * \tconst { expect, it } = await import('vitest')\n * \tit('checks the documented inventory', () => {\n * \t\texpect(root.length).toBeGreaterThan(0)\n * \t\texpect(Object.keys(files).length).toBeGreaterThan(0)\n * \t\texpect(rows.length).toBeGreaterThan(0)\n * \t\texpect(report.input).toEqual([])\n * \t})\n * })\n * ```\n */\nexport class GuideCommand implements GuideCommandInterface {\n\treadonly #root: string\n\treadonly #patterns: readonly string[]\n\treadonly #modules: Readonly<Record<string, GuideModule>>\n\treadonly #languages: readonly string[]\n\treadonly #language: string\n\treadonly #reader: GuideReadFunction\n\treadonly #runner: GuideRunnerFunction\n\n\tconstructor(options: GuideCommandOptions) {\n\t\tthis.#root = resolveGuideRoot(options.root)\n\t\tthis.#patterns = Object.freeze([...options.patterns])\n\t\tthis.#modules = Object.freeze({ ...options.modules })\n\t\tthis.#languages = Object.freeze([...options.languages])\n\t\tthis.#language = options.language\n\t\tthis.#reader = options.reader\n\t\tthis.#runner = options.runner\n\t}\n\n\t/**\n\t * Runs the native command or registers package assertions with fresh worker inventory and parity.\n\t *\n\t * @param register - The package-owned assertion registration callback\n\t * @returns A promise that resolves after the selected command path finishes\n\t * @throws When worker inventory reading or package assertion registration fails. Native failures\n\t * are reported through stderr and process exit status before this promise resolves.\n\t */\n\tasync execute(register: GuideCommandHandler): Promise<void> {\n\t\tif (process.env.VITEST === 'true') {\n\t\t\tawait this.#register(register)\n\t\t\treturn\n\t\t}\n\t\ttry {\n\t\t\tawait this.#executeNative()\n\t\t} catch (error) {\n\t\t\tprocess.stderr.write(`${isError(error) ? error.message : String(error)}\\n`)\n\t\t\tthis.#raise(1)\n\t\t}\n\t}\n\n\t#createOptions(): ParityOptions | undefined {\n\t\tconst files = this.#readInventory()\n\t\tconst manifest = files[GUIDE_INDEX]\n\t\tif (manifest === undefined) return undefined\n\t\tconst entries = Object.freeze([...parseManifest(manifest, 'guides')])\n\t\tconst packageFiles = Object.freeze({ ...this.#reader(this.#root, [GUIDE_MANIFEST]) })\n\t\tconst packageManifest = packageFiles[GUIDE_MANIFEST]\n\t\tconst pitch = selectGuidePitch(\n\t\t\tentries,\n\t\t\tpackageManifest === undefined ? undefined : parsePackageName(packageManifest),\n\t\t)\n\t\treturn {\n\t\t\tfiles,\n\t\t\tentries,\n\t\t\tmodules: this.#modules,\n\t\t\tlanguages: this.#languages,\n\t\t\tlanguage: this.#language,\n\t\t\t...(pitch === undefined\n\t\t\t\t? {}\n\t\t\t\t: { pitch: Object.freeze({ readme: GUIDE_README, spec: pitch }) }),\n\t\t}\n\t}\n\n\tasync #executeNative(): Promise<void> {\n\t\tconst args = process.argv.slice(2)\n\t\tconst direction = parseGuideDirection(args)\n\t\tif (direction === undefined && args.length > 0) {\n\t\t\tprocess.stdout.write(`${GUIDE_USAGE}\\n`)\n\t\t\tthis.#raise(2)\n\t\t\treturn\n\t\t}\n\t\tif (direction === undefined) {\n\t\t\tif (!(await this.#executeRunner())) this.#raise(1)\n\t\t\treturn\n\t\t}\n\n\t\tconst options = this.#createOptions()\n\t\tif (options === undefined) {\n\t\t\tthis.#reportMissing()\n\t\t\treturn\n\t\t}\n\t\tconst parity = new Parity(options)\n\t\tif (this.#report(parity.inspect().input)) {\n\t\t\tthis.#raise(2)\n\t\t\treturn\n\t\t}\n\t\tconst rewritten = direction === 'guide' ? parity.document() : parity.annotate()\n\t\tfor (const change of rewritten.changes) {\n\t\t\twriteFileSync(resolve(this.#root, change.path), change.content)\n\t\t\tprocess.stdout.write(`wrote ${change.path}\\n`)\n\t\t}\n\n\t\tconst freshOptions = this.#createOptions()\n\t\tif (freshOptions === undefined) {\n\t\t\tthis.#reportMissing()\n\t\t\treturn\n\t\t}\n\t\tconst freshParity = new Parity(freshOptions)\n\t\tconst freshReport = freshParity.inspect()\n\t\tif (this.#report(freshReport.input)) {\n\t\t\tthis.#raise(2)\n\t\t\treturn\n\t\t}\n\t\tconst remaining =\n\t\t\tdirection === 'guide' ? freshParity.document().findings : freshParity.annotate().findings\n\t\tif (this.#report(remaining)) this.#raise(1)\n\t\tif (this.#report(freshReport.pitch)) this.#raise(1)\n\t\tif (rewritten.changes.length > 0) process.stdout.write('next: npm run format\\n')\n\t\tif (!(await this.#executeRunner())) this.#raise(1)\n\t}\n\n\t#readInventory(): Readonly<Record<string, string>> {\n\t\tconst targets = globSync([...this.#patterns], { cwd: this.#root }).map((path) =>\n\t\t\tpath.replaceAll('\\\\', '/'),\n\t\t)\n\t\treturn Object.freeze({ ...this.#reader(this.#root, targets) })\n\t}\n\n\tasync #register(register: GuideCommandHandler): Promise<void> {\n\t\tconst options = this.#createOptions()\n\t\tif (options === undefined) {\n\t\t\tthrow new Error('The inventory carries no guides/README.md to index from')\n\t\t}\n\t\tconst parity = new Parity(options)\n\t\tconst context: GuideCommandContext = Object.freeze({\n\t\t\troot: this.#root,\n\t\t\tfiles: options.files,\n\t\t\trows: parity.rows(),\n\t\t\treport: parity.inspect(),\n\t\t})\n\t\tawait register(context)\n\t}\n\n\t#report(findings: readonly ParityFinding[]): boolean {\n\t\tfor (const finding of findings) {\n\t\t\tprocess.stdout.write(`${formatGuideFinding(finding)}\\n`)\n\t\t}\n\t\treturn findings.length > 0\n\t}\n\n\t#reportMissing(): void {\n\t\tprocess.stdout.write(`${GUIDE_INDEX}: the workspace carries no concept index to read\\n`)\n\t\tthis.#raise(2)\n\t}\n\n\tasync #executeRunner(): Promise<boolean> {\n\t\tconst runner = await this.#runner('test', {\n\t\t\troot: this.#root,\n\t\t\tconfig: resolve(this.#root, 'vite.config.ts'),\n\t\t\tproject: 'guides',\n\t\t\treporters: 'dot',\n\t\t\tcache: false,\n\t\t\twatch: false,\n\t\t})\n\t\tif (!isObject(runner)) throw new Error('The guides runner is not an object')\n\t\tconst close = Reflect.get(runner, 'close')\n\t\tif (!isFunction(close)) throw new Error('The guides runner has no callable close member')\n\t\ttry {\n\t\t\tconst start = Reflect.get(runner, 'start')\n\t\t\tif (!isFunction(start)) throw new Error('The guides runner has no callable start member')\n\t\t\treturn matchesGuideResult(await Reflect.apply(start, runner, []))\n\t\t} finally {\n\t\t\tawait Reflect.apply(close, runner, [])\n\t\t}\n\t}\n\n\t#raise(code: number): void {\n\t\tconst current = process.exitCode\n\t\tconst numeric = isString(current) ? Number.parseInt(current, 10) : current\n\t\tif (!isFiniteNumber(numeric) || numeric < code) {\n\t\t\tprocess.exitCode = code\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;AACA,IAAa,cAAc;;AAG3B,IAAa,iBAAiB;;AAG9B,IAAa,eAAe;;AAG5B,IAAa,cAAc;;;;;;;;;;;;;ACM3B,SAAgB,mBAAmB,SAAgC;CAClE,MAAM,OAAO,QAAQ;CAErB,OAAO,GADQ,SAAS,KAAA,KAAa,QAAQ,KAAK,WAAW,IAAI,IAAI,KAAK,GAAG,KAAK,KAC/D,QAAQ;AAC5B;;;;;;;;;;;;AAaA,SAAgB,mBAAmB,QAA0B;CAC5D,IAAI,CAAC,SAAS,MAAM,GAAG,OAAO;CAC9B,MAAM,cAAc,QAAQ,IAAI,QAAQ,aAAa;CACrD,MAAM,kBAAkB,QAAQ,IAAI,QAAQ,iBAAiB;CAC7D,IAAI,CAAC,QAAQ,WAAW,KAAK,CAAC,QAAQ,eAAe,GAAG,OAAO;CAC/D,MAAM,UAAU,CAAC,GAAG,WAAW;CAC/B,MAAM,SAAS,CAAC,GAAG,eAAe;CAClC,IAAI,QAAQ,WAAW,KAAK,OAAO,SAAS,GAAG,OAAO;CACtD,KAAK,MAAM,UAAU,SAAS;EAC7B,IAAI,CAAC,SAAS,MAAM,GAAG,OAAO;EAC9B,MAAM,QAAQ,QAAQ,IAAI,QAAQ,OAAO;EACzC,IAAI,CAAC,WAAW,KAAK,KAAK,QAAQ,MAAM,OAAO,QAA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K,UAAU,MACzC,QAAQ,WAAW;CAErB;AACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orkestrel/guide",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26",
|
|
4
4
|
"description": "Guides-parity test helpers — prove a package's guides are in bijection with the code they document: surface and methods bijection, link integrity, and non-vacuous extraction, built on @orkestrel/markdown. Part of the @orkestrel line.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bijection",
|
|
@@ -80,25 +80,25 @@
|
|
|
80
80
|
"prepublishOnly": "npm run format:check && npm run lint:check && npm run check && npm run build && npm test && npm run test:distribution -- --mode release",
|
|
81
81
|
"test:distribution": "vitest run --config vite.config.ts --no-cache --reporter=dot --project distribution",
|
|
82
82
|
"test:probe": "vitest run --config vite.config.ts --no-cache --reporter=verbose --project probe",
|
|
83
|
-
"test:bench": "vitest bench --config vite.config.ts --no-cache --project probe",
|
|
83
|
+
"test:bench": "vitest bench --config vite.config.ts --no-cache --project \"probe (bench)\" --mode benchmark",
|
|
84
84
|
"prepack": "npm run build",
|
|
85
85
|
"test:setup": "vitest run --config vite.config.ts --no-cache --reporter=dot --project setup"
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@orkestrel/contract": "^0.0.
|
|
89
|
-
"@orkestrel/markdown": "^0.0.
|
|
88
|
+
"@orkestrel/contract": "^0.0.20",
|
|
89
|
+
"@orkestrel/markdown": "^0.0.18"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
|
-
"@microsoft/api-extractor": "^7.
|
|
93
|
-
"@orkestrel/probe": "^0.0.
|
|
94
|
-
"@orkestrel/scaffold": "^0.0.
|
|
95
|
-
"@orkestrel/test": "^0.0.
|
|
96
|
-
"@types/node": "^26.6.
|
|
97
|
-
"oxfmt": "^0.
|
|
98
|
-
"oxlint": "^1.
|
|
99
|
-
"typescript": "^
|
|
100
|
-
"vite": "^8.3.
|
|
101
|
-
"vitest": "^
|
|
92
|
+
"@microsoft/api-extractor": "^7.60.0",
|
|
93
|
+
"@orkestrel/probe": "^0.0.25",
|
|
94
|
+
"@orkestrel/scaffold": "^0.0.113",
|
|
95
|
+
"@orkestrel/test": "^0.0.31",
|
|
96
|
+
"@types/node": "^26.6.6",
|
|
97
|
+
"oxfmt": "^0.75.0",
|
|
98
|
+
"oxlint": "^1.90.0",
|
|
99
|
+
"typescript": "^7.0.2",
|
|
100
|
+
"vite": "^8.3.5",
|
|
101
|
+
"vitest": "^5.0.5"
|
|
102
102
|
},
|
|
103
103
|
"engines": {
|
|
104
104
|
"node": ">=22.18.0"
|