@chikx/compiler 0.1.0 → 0.1.1

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.
Files changed (85) hide show
  1. package/README.md +5 -5
  2. package/package.json +3 -3
  3. package/src/emitter/index.ts +658 -0
  4. package/src/formatter/index.ts +544 -0
  5. package/src/host/node.ts +85 -0
  6. package/src/index.ts +1021 -0
  7. package/src/ir/factories.ts +85 -0
  8. package/src/ir/index.ts +28 -0
  9. package/src/ir/types.ts +145 -0
  10. package/src/lexer/at-keywords.ts +35 -0
  11. package/src/lexer/characters.ts +82 -0
  12. package/src/lexer/comments.ts +27 -0
  13. package/src/lexer/diagnostics.ts +42 -0
  14. package/src/lexer/dollar-refs.ts +23 -0
  15. package/src/lexer/index.ts +37 -0
  16. package/src/lexer/names.ts +49 -0
  17. package/src/lexer/numbers.ts +59 -0
  18. package/src/lexer/scanner.ts +199 -0
  19. package/src/lexer/strings.ts +52 -0
  20. package/src/lexer/urls.ts +63 -0
  21. package/src/lowering/expand-groups.ts +206 -0
  22. package/src/lowering/group.ts +119 -0
  23. package/src/lowering/index.ts +43 -0
  24. package/src/lowering/lower.ts +441 -0
  25. package/src/lowering/media.ts +314 -0
  26. package/src/lowering/merge.ts +163 -0
  27. package/src/lowering/property-families.ts +194 -0
  28. package/src/lowering/spans.ts +118 -0
  29. package/src/naming/index.ts +44 -0
  30. package/src/naming/mapgen.ts +252 -0
  31. package/src/naming/merge.ts +114 -0
  32. package/src/naming/rewrite.ts +333 -0
  33. package/src/naming/scan.ts +267 -0
  34. package/src/naming/table.ts +153 -0
  35. package/src/naming/types.ts +100 -0
  36. package/src/output/import-path.ts +30 -0
  37. package/src/output/index.ts +213 -0
  38. package/src/output/manifest.ts +28 -0
  39. package/src/output/paths.ts +200 -0
  40. package/src/output/resolve.ts +401 -0
  41. package/src/output/validate.ts +251 -0
  42. package/src/parser/cursor.ts +138 -0
  43. package/src/parser/declaration.ts +247 -0
  44. package/src/parser/diagnostics.ts +75 -0
  45. package/src/parser/group.ts +303 -0
  46. package/src/parser/index.ts +50 -0
  47. package/src/parser/modifier.ts +60 -0
  48. package/src/parser/recovery.ts +88 -0
  49. package/src/parser/rule.ts +370 -0
  50. package/src/parser/statement.ts +47 -0
  51. package/src/parser/statements.ts +667 -0
  52. package/src/parser/value.ts +265 -0
  53. package/src/resolver/graph.ts +467 -0
  54. package/src/resolver/groups.ts +177 -0
  55. package/src/resolver/index.ts +68 -0
  56. package/src/resolver/keyframes.ts +131 -0
  57. package/src/resolver/paths.ts +142 -0
  58. package/src/resolver/rules.ts +54 -0
  59. package/src/resolver/scopes.ts +342 -0
  60. package/src/resolver/types.ts +259 -0
  61. package/src/selectors/flatten.ts +448 -0
  62. package/src/selectors/index.ts +14 -0
  63. package/src/selectors/scan.ts +227 -0
  64. package/src/selectors/specificity.ts +319 -0
  65. package/src/setup-list.ts +172 -0
  66. package/src/sourcemaps/index.ts +25 -0
  67. package/src/sourcemaps/mappings.ts +190 -0
  68. package/src/sourcemaps/vlq.ts +29 -0
  69. package/src/types/ast.ts +318 -0
  70. package/src/types/diagnostics.ts +124 -0
  71. package/src/types/options.ts +286 -0
  72. package/src/types/result.ts +121 -0
  73. package/src/types/span.ts +18 -0
  74. package/src/types/token.ts +77 -0
  75. package/src/variables/ast.ts +182 -0
  76. package/src/variables/expand.ts +319 -0
  77. package/src/variables/index.ts +38 -0
  78. package/src/variables/naming.ts +46 -0
  79. package/src/variables/runtime.ts +336 -0
  80. package/src/variables/substitute.ts +148 -0
  81. package/src/variables/walk.ts +147 -0
  82. package/dist/output/importPath.d.ts +0 -27
  83. package/dist/output/importPath.d.ts.map +0 -1
  84. package/dist/output/importPath.js +0 -84
  85. package/dist/output/importPath.js.map +0 -1
@@ -0,0 +1,153 @@
1
+ /**
2
+ * CSS class-identifier primitives shared by the selector scanner and the naming
3
+ * table (SPECIFICATION.md §7.2 "Validate CSS identifier compatibility").
4
+ *
5
+ * Everything here is pure and lossless: identifiers are decoded exactly once so
6
+ * that the class map is keyed by the logical class name (`.foo\.bar` →
7
+ * `foo.bar`), while the authored selector bytes stay available for unprefixed
8
+ * output.
9
+ */
10
+
11
+ /** A decoded CSS identifier plus the exclusive end offset in the source text. */
12
+ export interface CssIdentifier {
13
+ /** Exclusive end offset of the identifier in the scanned text. */
14
+ readonly end: number;
15
+ /** Decoded identifier text, with CSS escapes resolved. */
16
+ readonly name: string;
17
+ }
18
+
19
+ /** A decoded escape plus the exclusive end offset in the source text. */
20
+ export interface CssEscape {
21
+ /** Decoded character (a replacement character for invalid code points). */
22
+ readonly character: string;
23
+ /** Exclusive end offset after the escape, including any terminating whitespace. */
24
+ readonly end: number;
25
+ }
26
+
27
+ /**
28
+ * True when `name` is a valid, unescaped CSS identifier.
29
+ *
30
+ * This is the strict MVP check of §7.2: it accepts ASCII letters, digits after
31
+ * the start, `_`, `-` and non-ASCII code points, with the CSS start rule
32
+ * (`--`, `-<start>` or `<start>`). Escapes are deliberately not accepted here:
33
+ * a renamed class is emitted verbatim as a bare identifier, so a result that
34
+ * would need escaping is rejected rather than silently rewritten into an
35
+ * equivalent-looking but different map key.
36
+ */
37
+ export function isValidCssIdentifier(name: string): boolean {
38
+ return /^(?:--|-?[A-Za-z_\u0080-\uFFFF])[A-Za-z0-9_\-\u0080-\uFFFF]*$/.test(name);
39
+ }
40
+
41
+ /**
42
+ * Decode one CSS escape starting at `index` (which must be a backslash).
43
+ *
44
+ * Handles 1–6 hex digits with the optional single terminating whitespace and a
45
+ * non-hex escaped character. Returns `null` for a trailing backslash or an
46
+ * escaped newline, which cannot start an identifier; callers then stop scanning
47
+ * instead of inventing a name.
48
+ */
49
+ export function decodeCssEscape(text: string, index: number): CssEscape | null {
50
+ if (text.charAt(index) !== "\\") return null;
51
+ const next = index + 1;
52
+ if (next >= text.length) return null;
53
+
54
+ const hex = /[0-9A-Fa-f]/.test(text.charAt(next));
55
+ if (hex) {
56
+ let cursor = next;
57
+ let digits = "";
58
+ while (cursor < text.length && digits.length < 6 && /[0-9A-Fa-f]/.test(text.charAt(cursor))) {
59
+ digits += text.charAt(cursor);
60
+ cursor += 1;
61
+ }
62
+ if (text.charAt(cursor) === "\r" && text.charAt(cursor + 1) === "\n") {
63
+ cursor += 2;
64
+ } else if (/[ \t\n\r\f]/.test(text.charAt(cursor))) {
65
+ cursor += 1;
66
+ }
67
+ const codePoint = Number.parseInt(digits, 16);
68
+ if (codePoint === 0 || codePoint > 0x10ffff || (codePoint >= 0xd800 && codePoint <= 0xdfff)) {
69
+ return { character: "\uFFFD", end: cursor };
70
+ }
71
+ return { character: String.fromCodePoint(codePoint), end: cursor };
72
+ }
73
+
74
+ const character = text.charAt(next);
75
+ if (character === "\n" || character === "\r" || character === "\f") return null;
76
+ return { character, end: next + 1 };
77
+ }
78
+
79
+ /**
80
+ * Read a CSS identifier starting at `start`, decoding escapes.
81
+ *
82
+ * The caller supplies the position **after** a class dot. A digit-first name is
83
+ * rejected (invalid CSS unless escaped), and a lone `-` is rejected. The end
84
+ * offset is exclusive, so callers can splice the identifier out precisely.
85
+ */
86
+ export function readCssIdentifier(text: string, start: number): CssIdentifier | null {
87
+ let index = start;
88
+ let name = "";
89
+ let started = false;
90
+
91
+ while (index < text.length) {
92
+ const character = text.charAt(index);
93
+ if (character === "\\") {
94
+ const escaped = decodeCssEscape(text, index);
95
+ if (escaped === null) break;
96
+ name += escaped.character;
97
+ index = escaped.end;
98
+ started = true;
99
+ continue;
100
+ }
101
+ if (!started) {
102
+ if (/[A-Za-z_\u0080-\uFFFF]/.test(character)) {
103
+ name += character;
104
+ index += 1;
105
+ started = true;
106
+ continue;
107
+ }
108
+ if (character === "-") {
109
+ name += character;
110
+ index += 1;
111
+ started = true;
112
+ continue;
113
+ }
114
+ return null;
115
+ }
116
+ if (/[A-Za-z0-9_\-\u0080-\uFFFF]/.test(character)) {
117
+ name += character;
118
+ index += 1;
119
+ continue;
120
+ }
121
+ break;
122
+ }
123
+
124
+ if (!started || name === "-") return null;
125
+ return { end: index, name };
126
+ }
127
+
128
+ /**
129
+ * Apply the MVP naming table to one decoded class name (ADR-0010).
130
+ *
131
+ * - `prefix` with a non-empty, valid prefix → `"<prefix>-<name>"`, but only
132
+ * when the result is itself a valid bare CSS identifier.
133
+ * - `none`, an empty prefix, an invalid prefix or an invalid result → the name
134
+ * is unchanged, and the caller reports CHIKX4001 for the invalid configuration
135
+ * or result (the documented fallback: the class stays unprefixed).
136
+ *
137
+ * Pure and deterministic; it never escapes names, which is why the result check
138
+ * is strict.
139
+ */
140
+ export function renameClassName(
141
+ name: string,
142
+ prefix: string,
143
+ strategy: "none" | "prefix",
144
+ ): { readonly emitted: string; readonly renamed: boolean } {
145
+ if (strategy === "none" || prefix === "" || !isValidCssIdentifier(prefix)) {
146
+ return { emitted: name, renamed: false };
147
+ }
148
+ const candidate = `${prefix}-${name}`;
149
+ if (!isValidCssIdentifier(candidate)) {
150
+ return { emitted: name, renamed: false };
151
+ }
152
+ return { emitted: candidate, renamed: true };
153
+ }
@@ -0,0 +1,100 @@
1
+ import type { StylesheetIr } from "../ir/types.js";
2
+ import type { Diagnostic } from "../types/diagnostics.js";
3
+ import type { NamingStrategy } from "../types/options.js";
4
+ import type { Span } from "../types/span.js";
5
+
6
+ /**
7
+ * Public shapes of the class-naming stage (SPECIFICATION.md §7.2, §8).
8
+ *
9
+ * The stage is two pure passes: {@link renameClasses} rewrites selectors and
10
+ * builds a {@link ClassTable}; `generateClassMap` turns that table into an ESM
11
+ * module of camelCase `export const` bindings plus opt-in `.d.ts` declarations.
12
+ * The table is the single source of truth for both, so the CSS class text, the
13
+ * exported bindings and the declaration file can never disagree (ADR-0010).
14
+ */
15
+
16
+ /**
17
+ * Class-naming configuration accepted by {@link renameClasses}.
18
+ *
19
+ * Structurally compatible with the frozen `NamingOptions` but with an optional
20
+ * strategy, so callers may pass either resolved options or a projection.
21
+ */
22
+ export interface ClassNamingOptions {
23
+ /** `none` keeps authored names; `prefix` prepends the effective prefix. */
24
+ readonly strategy?: NamingStrategy;
25
+ /** Prefix for the `prefix` strategy; empty leaves names unchanged. */
26
+ readonly prefix?: string;
27
+ }
28
+
29
+ /** Options for {@link renameClasses}. */
30
+ export interface RenameOptions {
31
+ /**
32
+ * Effective file prefix. Overridden by {@link RenameOptions.naming}. Omitted
33
+ * or empty means names are unchanged (`SPECIFICATION.md` §7.2).
34
+ */
35
+ readonly prefix?: string;
36
+ /** Strategy and prefix; `naming.prefix` wins over {@link RenameOptions.prefix}. */
37
+ readonly naming?: ClassNamingOptions;
38
+ }
39
+
40
+ /**
41
+ * One class name discovered in the lowered stylesheet.
42
+ *
43
+ * `name` is the decoded CSS class name: `.\31 23` yields `"123"` and
44
+ * `.status\:active` yields `"status:active"`, because a class identity is its
45
+ * decoded text, not its source spelling. `emitted` is the decoded name after
46
+ * the naming table is applied. A renamed entry has no CSS escapes (the result
47
+ * is validated as a bare CSS identifier); an unprefixed entry keeps its
48
+ * authored selector bytes even when they contain escapes.
49
+ */
50
+ export interface ClassEntry {
51
+ /** Decoded authored class name; the source of the map's camelCase binding. */
52
+ readonly name: string;
53
+ /** Decoded emitted class name; what `className` must use in applications. */
54
+ readonly emitted: string;
55
+ /** `true` when this name came only from a `:global(...)` escape. */
56
+ readonly global: boolean;
57
+ /** `true` when `emitted` differs from `name` because the prefix applied. */
58
+ readonly renamed: boolean;
59
+ /** First occurrence of the name, used for diagnostics. */
60
+ readonly span: Span;
61
+ }
62
+
63
+ /**
64
+ * First-appearance-ordered class table for one stylesheet.
65
+ *
66
+ * Entries include global classes so diagnostics and the rewrite can reason about
67
+ * them, but globals are excluded from map generation by `generateClassMap`
68
+ * (§3.6 "Global classes are not exported"). Names are unique; the first
69
+ * occurrence fixes the position, and a later local occurrence upgrades a
70
+ * previously global-only entry in place.
71
+ */
72
+ export interface ClassTable {
73
+ /** Unique entries in first-appearance order across the IR walk. */
74
+ readonly entries: readonly ClassEntry[];
75
+ }
76
+
77
+ /** Result of {@link renameClasses}. */
78
+ export interface RenameResult {
79
+ /** Rewritten, re-frozen IR (the input instance when nothing changed). */
80
+ readonly ir: StylesheetIr;
81
+ /** Naming table covering every local and global class token. */
82
+ readonly classes: ClassTable;
83
+ /** CHIKX4001 diagnostics for invalid prefixes or invalid prefixed results. */
84
+ readonly diagnostics: Diagnostic[];
85
+ }
86
+
87
+ /**
88
+ * Result of `generateClassMap`.
89
+ *
90
+ * The generated map has no CSS side-effect import: style loading belongs to the
91
+ * page (`<link>`) or the bundler (`import "./x.css"`).
92
+ */
93
+ export interface ClassMapResult {
94
+ /** ESM JavaScript class map: one `export const` binding per class. */
95
+ readonly js: string;
96
+ /** Opt-in TypeScript declarations mirroring {@link ClassMapResult.js} exactly. */
97
+ readonly types: string;
98
+ /** CHIKX4001 warnings for adjusted export identifiers. */
99
+ readonly diagnostics: Diagnostic[];
100
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Import specifier for the opt-in CSS side-effect import in the class map
3
+ * (ADR-0021).
4
+ *
5
+ * The specifier is computed from the two planned artifacts, never from authored
6
+ * settings, so it always names the stylesheet that is actually written:
7
+ *
8
+ * - relative to the directory of the emitted `map.js`;
9
+ * - POSIX separators only;
10
+ * - always `./`-prefixed when the stylesheet is in or below the map directory,
11
+ * and left as authored `..` segments when it is above it.
12
+ *
13
+ * The planner guarantees both artifacts stay inside the workspace; a
14
+ * non-relative result would therefore mean the plan was rejected, and callers
15
+ * omit the import instead of emitting a dangling specifier.
16
+ */
17
+
18
+ import { dirnamePath, isAbsolutePath, relativePath } from "./paths.js";
19
+
20
+ /**
21
+ * Return the ESM specifier a generated map uses to import its stylesheet.
22
+ *
23
+ * @param mapFile Absolute POSIX path of the generated JS map.
24
+ * @param stylesheetFile Absolute POSIX path of the emitted stylesheet.
25
+ */
26
+ export function stylesheetImportSpecifier(mapFile: string, stylesheetFile: string): string {
27
+ const relative = relativePath(dirnamePath(mapFile), stylesheetFile);
28
+ if (relative === "." || relative.startsWith("../") || isAbsolutePath(relative)) return relative;
29
+ return `./${relative}`;
30
+ }
@@ -0,0 +1,213 @@
1
+ /**
2
+ * Pure output planner for Chikx (SPECIFICATION.md §9).
3
+ *
4
+ * `planOutputs` resolves every CSS, JS map, declaration and CSS source-map
5
+ * destination from the frozen `ResolvedSetup`/`ProjectConfig`/CLI inputs,
6
+ * validates the complete plan, and returns it with a matching manifest. It is
7
+ * synchronous, deterministic and never writes. Expected planning failures are
8
+ * returned as CHIKX5001 diagnostics instead of exceptions.
9
+ *
10
+ * The frozen `PlanOutputsInput` does not carry a host or trusted-output policy.
11
+ * This module therefore exposes an optional second context argument:
12
+ * `host` supplies `canonicalize` for symlink containment, and
13
+ * `occupiedTargets` lets a project build pass targets already planned by other
14
+ * entries so cross-source collisions are rejected. Without them the planner
15
+ * uses lexical identity canonicalization and validates one entry at a time.
16
+ * External output is always rejected; no trusted policy escape exists in the
17
+ * frozen contracts.
18
+ */
19
+
20
+ import type { Diagnostic } from "../types/diagnostics.js";
21
+ import { error } from "../types/diagnostics.js";
22
+ import type {
23
+ OutputKind,
24
+ OutputPlan,
25
+ PlanOutputsInput,
26
+ PlanOutputsResult,
27
+ PlannedOutput,
28
+ } from "../types/result.js";
29
+ import type { Span } from "../types/span.js";
30
+ import { buildManifest } from "./manifest.js";
31
+ import { isAbsolutePath, joinPath, normalizePath, relativePath } from "./paths.js";
32
+ import {
33
+ declarationNameFor,
34
+ resolveOutputSettings,
35
+ resolveSource,
36
+ sourceMapNameFor,
37
+ } from "./resolve.js";
38
+ import type { OutputCandidate, OutputPlannerHost } from "./validate.js";
39
+ import {
40
+ findDuplicateTargets,
41
+ suppressedTypesWarning,
42
+ validateCandidate,
43
+ validateName,
44
+ workspacePathFor,
45
+ } from "./validate.js";
46
+
47
+ export type { OutputPlannerHost } from "./validate.js";
48
+
49
+ /** Optional planning context that the frozen input shape has no room for. */
50
+ export interface OutputPlannerContext {
51
+ /** Canonicalization host used to detect symlink escapes. */
52
+ readonly host?: OutputPlannerHost;
53
+ /** Absolute or workspace-relative targets already planned by other entries. */
54
+ readonly occupiedTargets?: readonly string[];
55
+ }
56
+
57
+ /**
58
+ * Validate and return the complete output plan for one entry before anything is
59
+ * written.
60
+ *
61
+ * @param input Frozen planner input: source, effective setup, optional project
62
+ * configuration and CLI overrides, and the absolute workspace root.
63
+ * @param context Optional host and cross-entry occupied targets.
64
+ * @returns The valid plan plus diagnostics. Any error leaves an empty plan so a
65
+ * caller cannot accidentally write a partial or unsafe artifact set.
66
+ */
67
+ export function planOutputs(
68
+ input: PlanOutputsInput,
69
+ context: OutputPlannerContext = {},
70
+ ): PlanOutputsResult {
71
+ const workspaceRoot = normalizePath(input.workspaceRoot);
72
+ const resolvedSource = resolveSource(input);
73
+ const sourceRelative = relativePath(workspaceRoot, resolvedSource.absolute);
74
+ const source = Object.freeze({ ...resolvedSource, relative: sourceRelative });
75
+ const span: Span = Object.freeze({ start: 0, end: 0, file: sourceRelative });
76
+ const emptyPlan: OutputPlan = Object.freeze({
77
+ outputs: Object.freeze([]),
78
+ manifest: Object.freeze([]),
79
+ });
80
+ const diagnostics: Diagnostic[] = [];
81
+
82
+ if (!isAbsolutePath(workspaceRoot)) {
83
+ diagnostics.push(
84
+ error(
85
+ "CHIKX5001",
86
+ `Workspace root "${input.workspaceRoot}" must be an absolute POSIX or drive-letter path.`,
87
+ span,
88
+ ),
89
+ );
90
+ return freezeResult(emptyPlan, diagnostics);
91
+ }
92
+
93
+ if (
94
+ isAbsolutePath(sourceRelative) ||
95
+ sourceRelative === ".." ||
96
+ sourceRelative.startsWith("../")
97
+ ) {
98
+ diagnostics.push(
99
+ error(
100
+ "CHIKX5001",
101
+ `Source "${sourceRelative}" is outside the workspace root "${workspaceRoot}".`,
102
+ span,
103
+ ),
104
+ );
105
+ return freezeResult(emptyPlan, diagnostics);
106
+ }
107
+
108
+ const settings = resolveOutputSettings(input, source, workspaceRoot);
109
+
110
+ let emitTypes = settings.emitTypes;
111
+ if (!settings.emitMap && settings.emitTypes) {
112
+ diagnostics.push(suppressedTypesWarning(span));
113
+ emitTypes = false;
114
+ }
115
+
116
+ const cssNameDiagnostic = settings.emitCss
117
+ ? validateName(settings.cssName, "css", span)
118
+ : undefined;
119
+ if (cssNameDiagnostic !== undefined) diagnostics.push(cssNameDiagnostic);
120
+ const mapNameDiagnostic = settings.emitMap
121
+ ? validateName(settings.mapName, "js", span)
122
+ : undefined;
123
+ if (mapNameDiagnostic !== undefined) diagnostics.push(mapNameDiagnostic);
124
+
125
+ if (hasError(diagnostics)) {
126
+ return freezeResult(emptyPlan, diagnostics);
127
+ }
128
+
129
+ const candidates: OutputCandidate[] = [];
130
+ const mapAbsolute = joinPath(settings.mapDir, settings.mapName);
131
+
132
+ if (settings.emitCss) {
133
+ for (const directory of settings.cssDirs) {
134
+ const cssAbsolute = joinPath(directory, settings.cssName);
135
+ candidates.push(toCandidate("css", cssAbsolute, source.relative, workspaceRoot));
136
+ }
137
+ }
138
+ if (settings.emitMap) {
139
+ candidates.push(toCandidate("js", mapAbsolute, source.relative, workspaceRoot));
140
+ if (emitTypes) {
141
+ const declarationsAbsolute = joinPath(settings.mapDir, declarationNameFor(settings.mapName));
142
+ candidates.push(toCandidate("types", declarationsAbsolute, source.relative, workspaceRoot));
143
+ }
144
+ }
145
+ if (settings.emitCss && settings.sourceMap) {
146
+ for (const directory of settings.cssDirs) {
147
+ const mapFileAbsolute = joinPath(directory, sourceMapNameFor(settings.cssName));
148
+ candidates.push(toCandidate("cssSourceMap", mapFileAbsolute, source.relative, workspaceRoot));
149
+ }
150
+ }
151
+
152
+ for (const candidate of candidates) {
153
+ diagnostics.push(
154
+ ...validateCandidate(candidate, {
155
+ workspaceRoot,
156
+ source: { relative: source.relative, absolute: source.absolute },
157
+ span,
158
+ ...(context.host === undefined ? {} : { host: context.host }),
159
+ ...(context.occupiedTargets === undefined
160
+ ? {}
161
+ : { occupiedTargets: context.occupiedTargets }),
162
+ }),
163
+ );
164
+ }
165
+ diagnostics.push(...findDuplicateTargets(candidates, span));
166
+
167
+ if (hasError(diagnostics)) {
168
+ return freezeResult(emptyPlan, diagnostics);
169
+ }
170
+
171
+ const outputs: readonly PlannedOutput[] = Object.freeze(
172
+ candidates.map((candidate) =>
173
+ Object.freeze({
174
+ kind: candidate.kind,
175
+ absolutePath: candidate.absolutePath,
176
+ workspacePath: candidate.workspacePath,
177
+ sourceFile: candidate.sourceFile,
178
+ }),
179
+ ),
180
+ );
181
+ return freezeResult(
182
+ Object.freeze({
183
+ outputs,
184
+ manifest: buildManifest(outputs),
185
+ }),
186
+ diagnostics,
187
+ );
188
+ }
189
+
190
+ function toCandidate(
191
+ kind: OutputKind,
192
+ absolutePath: string,
193
+ sourceFile: string,
194
+ workspaceRoot: string,
195
+ ): OutputCandidate {
196
+ return Object.freeze({
197
+ kind,
198
+ absolutePath: normalizePath(absolutePath),
199
+ workspacePath: workspacePathFor(workspaceRoot, absolutePath),
200
+ sourceFile,
201
+ });
202
+ }
203
+
204
+ function hasError(diagnostics: readonly Diagnostic[]): boolean {
205
+ return diagnostics.some((diagnostic) => diagnostic.severity === "error");
206
+ }
207
+
208
+ function freezeResult(plan: OutputPlan, diagnostics: Diagnostic[]): PlanOutputsResult {
209
+ return Object.freeze({
210
+ plan,
211
+ diagnostics: Object.freeze([...diagnostics]),
212
+ });
213
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Manifest construction for planned artifacts.
3
+ *
4
+ * A manifest records every compiler-owned artifact so `chikx clean` and watch
5
+ * invalidation can remove or refresh only files the compiler created. Entries
6
+ * never carry timestamps and follow the same order as the plan. Content hashes
7
+ * are added only after a successful write, so the planner omits them.
8
+ */
9
+
10
+ import type { ManifestEntry, PlannedOutput } from "../types/result.js";
11
+
12
+ /**
13
+ * Build one manifest entry per planned artifact, in plan order.
14
+ *
15
+ * @param outputs Deterministically ordered planned artifacts.
16
+ * @returns Frozen manifest entries with kind, workspace path and source file.
17
+ */
18
+ export function buildManifest(outputs: readonly PlannedOutput[]): readonly ManifestEntry[] {
19
+ return Object.freeze(
20
+ outputs.map((output) =>
21
+ Object.freeze({
22
+ kind: output.kind,
23
+ workspacePath: output.workspacePath,
24
+ sourceFile: output.sourceFile,
25
+ }),
26
+ ),
27
+ );
28
+ }