@hominis/fireforge 0.39.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +25 -1
- package/dist/src/cli.js +7 -0
- package/dist/src/commands/export-flow.js +14 -6
- package/dist/src/commands/export-shared.js +14 -3
- package/dist/src/commands/lint-per-patch.js +83 -14
- package/dist/src/commands/lint-report.d.ts +21 -0
- package/dist/src/commands/lint-report.js +62 -0
- package/dist/src/commands/lint.js +22 -18
- package/dist/src/commands/manifest.js +2 -0
- package/dist/src/commands/patch/rename.js +1 -1
- package/dist/src/commands/patch/staged-dependency.js +102 -14
- package/dist/src/commands/re-export-adjacent.d.ts +34 -0
- package/dist/src/commands/re-export-adjacent.js +106 -0
- package/dist/src/commands/re-export-options.js +3 -0
- package/dist/src/commands/re-export.js +42 -53
- package/dist/src/commands/run.js +18 -2
- package/dist/src/commands/status-check.d.ts +35 -0
- package/dist/src/commands/status-check.js +88 -0
- package/dist/src/commands/status.js +16 -5
- package/dist/src/commands/test-run.js +18 -3
- package/dist/src/commands/token.js +4 -1
- package/dist/src/commands/tree.d.ts +16 -0
- package/dist/src/commands/tree.js +174 -0
- package/dist/src/core/config-validate.js +17 -0
- package/dist/src/core/lint-cache.d.ts +15 -5
- package/dist/src/core/lint-cache.js +17 -5
- package/dist/src/core/patch-export.d.ts +2 -2
- package/dist/src/core/patch-export.js +1 -1
- package/dist/src/core/patch-lint-checkjs.d.ts +19 -1
- package/dist/src/core/patch-lint-checkjs.js +56 -3
- package/dist/src/core/patch-lint-css.js +64 -16
- package/dist/src/core/patch-lint-diff.d.ts +8 -0
- package/dist/src/core/patch-lint-diff.js +31 -0
- package/dist/src/core/patch-lint-ownership.d.ts +21 -0
- package/dist/src/core/patch-lint-ownership.js +30 -0
- package/dist/src/core/patch-lint-reexports.d.ts +1 -1
- package/dist/src/core/patch-lint.d.ts +23 -0
- package/dist/src/core/patch-lint.js +30 -2
- package/dist/src/core/patch-manifest.d.ts +1 -1
- package/dist/src/core/smoke-patterns.d.ts +24 -8
- package/dist/src/core/smoke-patterns.js +23 -12
- package/dist/src/core/status-classify.d.ts +16 -0
- package/dist/src/core/status-classify.js +20 -6
- package/dist/src/core/token-category.d.ts +40 -0
- package/dist/src/core/token-category.js +264 -0
- package/dist/src/core/token-manager.d.ts +7 -0
- package/dist/src/core/token-manager.js +48 -196
- package/dist/src/core/tree-cow.d.ts +18 -0
- package/dist/src/core/tree-cow.js +71 -0
- package/dist/src/core/tree-guard.d.ts +35 -0
- package/dist/src/core/tree-guard.js +124 -0
- package/dist/src/core/tree-store.d.ts +53 -0
- package/dist/src/core/tree-store.js +214 -0
- package/dist/src/core/typecheck-shim.d.ts +14 -0
- package/dist/src/core/typecheck-shim.js +41 -2
- package/dist/src/core/xpcshell-profile-dir.d.ts +12 -0
- package/dist/src/core/xpcshell-profile-dir.js +45 -0
- package/dist/src/errors/git.d.ts +8 -0
- package/dist/src/errors/git.js +17 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +1 -0
- package/dist/src/types/commands/options.d.ts +33 -2
- package/dist/src/types/config.d.ts +19 -0
- package/dist/src/utils/validation.d.ts +10 -0
- package/dist/src/utils/validation.js +29 -0
- package/package.json +6 -6
|
@@ -47,7 +47,14 @@ export function getPrimaryStatusCode(status) {
|
|
|
47
47
|
}
|
|
48
48
|
return status;
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
/**
|
|
51
|
+
* True for the branding paths whose content FireForge generates itself
|
|
52
|
+
* (configure.sh, brand.properties/ftl, browser/moz.configure). Unlike the
|
|
53
|
+
* broader branding-root test, a brand-new unowned file under the branding
|
|
54
|
+
* directory is NOT generated — it is a patch candidate and must stay
|
|
55
|
+
* visible as unmanaged (the Assets.car precedent).
|
|
56
|
+
*/
|
|
57
|
+
export function isGeneratedBrandingPath(file, binaryName) {
|
|
51
58
|
const normalized = file.replace(/\\/g, '/');
|
|
52
59
|
const brandingRoot = `browser/branding/${binaryName}`;
|
|
53
60
|
return (normalized === 'browser/moz.configure' ||
|
|
@@ -64,13 +71,14 @@ function isGeneratedBrandingPath(file, binaryName) {
|
|
|
64
71
|
* deletion the patch does not expect, or a failed comparison) reports
|
|
65
72
|
* `patch-owned-drift`.
|
|
66
73
|
*/
|
|
67
|
-
async function classifySingleOwnerFile(entry, engineDir, patchesDir, matchClassification) {
|
|
74
|
+
async function classifySingleOwnerFile(entry, engineDir, patchesDir, matchClassification, owner) {
|
|
68
75
|
if (getPrimaryStatusCode(entry.status) === 'D') {
|
|
69
76
|
// Deleted file: content matches only if the patch expects deletion
|
|
70
77
|
const expected = await computePatchedContent(patchesDir, engineDir, entry.file);
|
|
71
78
|
return {
|
|
72
79
|
...entry,
|
|
73
80
|
classification: expected === null ? matchClassification : 'patch-owned-drift',
|
|
81
|
+
owner,
|
|
74
82
|
};
|
|
75
83
|
}
|
|
76
84
|
// File exists on disk — compare actual vs expected
|
|
@@ -82,11 +90,12 @@ async function classifySingleOwnerFile(entry, engineDir, patchesDir, matchClassi
|
|
|
82
90
|
return {
|
|
83
91
|
...entry,
|
|
84
92
|
classification: actual === expected ? matchClassification : 'patch-owned-drift',
|
|
93
|
+
owner,
|
|
85
94
|
};
|
|
86
95
|
}
|
|
87
96
|
catch (error) {
|
|
88
97
|
verbose(`Treating ${entry.file} as patch-owned drift because patch-backed classification failed: ${toError(error).message}`);
|
|
89
|
-
return { ...entry, classification: 'patch-owned-drift' };
|
|
98
|
+
return { ...entry, classification: 'patch-owned-drift', owner };
|
|
90
99
|
}
|
|
91
100
|
}
|
|
92
101
|
/**
|
|
@@ -146,8 +155,8 @@ export async function classifyFiles(files, engineDir, patchesDir, binaryName, fu
|
|
|
146
155
|
// `furnace`. Multi-owner and unowned furnace paths keep the
|
|
147
156
|
// short-circuit — the ownership table independently flags
|
|
148
157
|
// filesAffected conflicts.
|
|
149
|
-
if (owners && owners.length === 1) {
|
|
150
|
-
results.push(await classifySingleOwnerFile(entry, engineDir, patchesDir, 'furnace'));
|
|
158
|
+
if (owners && owners.length === 1 && owners[0] !== undefined) {
|
|
159
|
+
results.push(await classifySingleOwnerFile(entry, engineDir, patchesDir, 'furnace', owners[0]));
|
|
151
160
|
}
|
|
152
161
|
else {
|
|
153
162
|
results.push({ ...entry, classification: 'furnace' });
|
|
@@ -174,7 +183,12 @@ export async function classifyFiles(files, engineDir, patchesDir, binaryName, fu
|
|
|
174
183
|
continue;
|
|
175
184
|
}
|
|
176
185
|
// File is claimed by exactly one patch — compare content.
|
|
177
|
-
|
|
186
|
+
const owner = owners[0];
|
|
187
|
+
if (owner === undefined) {
|
|
188
|
+
results.push({ ...entry, classification: 'unmanaged' });
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
results.push(await classifySingleOwnerFile(entry, engineDir, patchesDir, 'patch-backed', owner));
|
|
178
192
|
}
|
|
179
193
|
return results;
|
|
180
194
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* True when `lines` contain a category header (single-line or multi-line
|
|
3
|
+
* banner shape) whose name EQUALS `category`. Shared by the pre-add
|
|
4
|
+
* assertion, the banner creation path, and the section finder so all
|
|
5
|
+
* agree on what "exists" means.
|
|
6
|
+
*/
|
|
7
|
+
export declare function categoryHeaderExists(lines: string[], category: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Asserts the category banner exists (or that creation was requested).
|
|
10
|
+
* Throws a GeneralError naming the available categories and the
|
|
11
|
+
* `--create-category` remedy otherwise.
|
|
12
|
+
*/
|
|
13
|
+
export declare function assertTokenCategoryExists(engineDir: string, tokensCssPath: string, category: string, createCategory?: boolean): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Splices a new single-line category banner ("= Name =" comment shape, the
|
|
16
|
+
* same format `discoverCategoryHeaders` recognises) just before the closing
|
|
17
|
+
* brace of the `:root` block, making the new category the last section.
|
|
18
|
+
* Mutates `lines` in place.
|
|
19
|
+
*/
|
|
20
|
+
export declare function declareCategoryBanner(lines: string[], category: string, tokensCssPath: string): void;
|
|
21
|
+
/** Locates and bounds the named category section. Throws when absent. */
|
|
22
|
+
export declare function findCategorySection(lines: string[], category: string, tokensCssPath: string): {
|
|
23
|
+
categoryLine: number;
|
|
24
|
+
sectionEnd: number;
|
|
25
|
+
};
|
|
26
|
+
/** Location of an existing base-`:root` token declaration. */
|
|
27
|
+
export interface TokenDeclarationLocation {
|
|
28
|
+
/** 1-based line number in the tokens CSS file. */
|
|
29
|
+
line: number;
|
|
30
|
+
/** Nearest enclosing category banner name, when one precedes the declaration. */
|
|
31
|
+
category?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Finds an existing declaration of `tokenName` inside the base `:root`
|
|
35
|
+
* block. Dark `@media` and `:root[variant]` companion blocks are
|
|
36
|
+
* deliberately excluded — they mirror the base declaration, they do not
|
|
37
|
+
* own the token. Comment content never matches, and the name match is
|
|
38
|
+
* exact (`--foo-bar` does not match `--x-foo-bar`).
|
|
39
|
+
*/
|
|
40
|
+
export declare function findTokenDeclarationInRoot(lines: string[], tokenName: string): TokenDeclarationLocation | undefined;
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
// SPDX-License-Identifier: EUPL-1.2
|
|
2
|
+
/**
|
|
3
|
+
* Category banner and token-declaration helpers for the tokens CSS file
|
|
4
|
+
* (FORGE G3). Split out of `token-manager.ts` to stay inside the per-file
|
|
5
|
+
* line budget.
|
|
6
|
+
*
|
|
7
|
+
* Banner matching is EXACT: the text between the `=` runs (single-line
|
|
8
|
+
* shape) or on the block line (multi-line shape) must equal the category
|
|
9
|
+
* after trimming. The pre-0.40.0 substring match let a TOC comment or a
|
|
10
|
+
* longer banner (`Colors — Canvas` for `Colors`) satisfy the lookup, so
|
|
11
|
+
* `token add` wrote into the wrong section — or no-oped for 19
|
|
12
|
+
* consecutive calls — with exit 0.
|
|
13
|
+
*/
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { GeneralError } from '../errors/base.js';
|
|
16
|
+
import { pathExists, readText } from '../utils/fs.js';
|
|
17
|
+
import { escapeRegex } from '../utils/regex.js';
|
|
18
|
+
function singleLineBannerPattern(category) {
|
|
19
|
+
return new RegExp(`\\/\\*\\s*=+\\s*${escapeRegex(category)}\\s*=+\\s*\\*\\/`);
|
|
20
|
+
}
|
|
21
|
+
function multiLineBlockNameMatches(blockLine, category) {
|
|
22
|
+
return blockLine.replace(/^\s*\*\s*/, '').trim() === category;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* True when `lines` contain a category header (single-line or multi-line
|
|
26
|
+
* banner shape) whose name EQUALS `category`. Shared by the pre-add
|
|
27
|
+
* assertion, the banner creation path, and the section finder so all
|
|
28
|
+
* agree on what "exists" means.
|
|
29
|
+
*/
|
|
30
|
+
export function categoryHeaderExists(lines, category) {
|
|
31
|
+
const singleLinePattern = singleLineBannerPattern(category);
|
|
32
|
+
for (let i = 0; i < lines.length; i++) {
|
|
33
|
+
const line = lines[i] ?? '';
|
|
34
|
+
if (singleLinePattern.test(line)) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (/^\s*\/\*\s*=+/.test(line) && !/\*\//.test(line)) {
|
|
38
|
+
for (let j = i + 1; j < Math.min(i + 6, lines.length); j++) {
|
|
39
|
+
const blockLine = lines[j] ?? '';
|
|
40
|
+
if (multiLineBlockNameMatches(blockLine, category)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (/\*\//.test(blockLine))
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Scans a tokens CSS file for category header comments and returns the
|
|
52
|
+
* category names in document order. Used to enrich the "category not
|
|
53
|
+
* found" error body with concrete alternatives the operator can copy.
|
|
54
|
+
*
|
|
55
|
+
* Mirrors the shapes `findCategorySection` recognises:
|
|
56
|
+
* - Single-line: `/* = Foo = *\/`
|
|
57
|
+
* - Multi-line: `/* =====` opening, `Foo` on any of the next ~5 lines,
|
|
58
|
+
* closing `*\/`.
|
|
59
|
+
*
|
|
60
|
+
* This helper exists as a pure inspector; it never throws on malformed
|
|
61
|
+
* headers and silently skips shapes it cannot parse.
|
|
62
|
+
*/
|
|
63
|
+
function discoverCategoryHeaders(lines) {
|
|
64
|
+
const categories = new Set();
|
|
65
|
+
const singleLinePattern = /\/\*\s*=+\s*(.+?)\s*=+\s*\*\//;
|
|
66
|
+
for (let i = 0; i < lines.length; i++) {
|
|
67
|
+
const line = lines[i] ?? '';
|
|
68
|
+
const singleMatch = singleLinePattern.exec(line);
|
|
69
|
+
if (singleMatch?.[1]) {
|
|
70
|
+
const extracted = singleMatch[1].trim();
|
|
71
|
+
if (extracted.length > 0)
|
|
72
|
+
categories.add(extracted);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (/^\s*\/\*\s*=+/.test(line) && !/\*\//.test(line)) {
|
|
76
|
+
for (let j = i + 1; j < Math.min(i + 6, lines.length); j++) {
|
|
77
|
+
const blockLine = lines[j] ?? '';
|
|
78
|
+
if (/\*\//.test(blockLine))
|
|
79
|
+
break;
|
|
80
|
+
const trimmed = blockLine.replace(/^\s*\*\s*/, '').trim();
|
|
81
|
+
if (trimmed.length === 0)
|
|
82
|
+
continue;
|
|
83
|
+
if (/^=+$/.test(trimmed))
|
|
84
|
+
continue;
|
|
85
|
+
categories.add(trimmed);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return [...categories];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Asserts the category banner exists (or that creation was requested).
|
|
94
|
+
* Throws a GeneralError naming the available categories and the
|
|
95
|
+
* `--create-category` remedy otherwise.
|
|
96
|
+
*/
|
|
97
|
+
export async function assertTokenCategoryExists(engineDir, tokensCssPath, category, createCategory = false) {
|
|
98
|
+
const filePath = join(engineDir, tokensCssPath);
|
|
99
|
+
if (!(await pathExists(filePath))) {
|
|
100
|
+
throw new GeneralError(`Token CSS file not found: ${tokensCssPath}`);
|
|
101
|
+
}
|
|
102
|
+
const content = await readText(filePath);
|
|
103
|
+
const lines = content.split('\n');
|
|
104
|
+
if (categoryHeaderExists(lines, category))
|
|
105
|
+
return;
|
|
106
|
+
// The write path declares the banner in the same edit as the token
|
|
107
|
+
// insertion, so a missing category is fine when creation was requested.
|
|
108
|
+
if (createCategory)
|
|
109
|
+
return;
|
|
110
|
+
const discoveredCategories = discoverCategoryHeaders(lines);
|
|
111
|
+
const available = discoveredCategories.length > 0
|
|
112
|
+
? `Available categories in the file: ${discoveredCategories.map((name) => `"${name}"`).join(', ')}.`
|
|
113
|
+
: 'The file currently has no category headers.';
|
|
114
|
+
throw new GeneralError(`Category "${category}" not found in ${tokensCssPath}.\n\n` +
|
|
115
|
+
`${available}\n\n` +
|
|
116
|
+
'Categories are declared by comment headers. Single-line shape: /* = My Category = */. ' +
|
|
117
|
+
'Multi-line shape: /* =============\\n * My Category\\n * ============= */.\n\n' +
|
|
118
|
+
'Re-run with --create-category to declare the banner and insert the token in one step.');
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Splices a new single-line category banner ("= Name =" comment shape, the
|
|
122
|
+
* same format `discoverCategoryHeaders` recognises) just before the closing
|
|
123
|
+
* brace of the `:root` block, making the new category the last section.
|
|
124
|
+
* Mutates `lines` in place.
|
|
125
|
+
*/
|
|
126
|
+
export function declareCategoryBanner(lines, category, tokensCssPath) {
|
|
127
|
+
const bounds = findBaseRootBounds(lines);
|
|
128
|
+
if (bounds === null) {
|
|
129
|
+
throw new GeneralError(`Cannot create category "${category}": no :root block found in ${tokensCssPath}. ` +
|
|
130
|
+
'Run "fireforge furnace init --force" to re-scaffold the tokens CSS file.');
|
|
131
|
+
}
|
|
132
|
+
if (bounds.close === -1) {
|
|
133
|
+
throw new GeneralError(`Cannot create category "${category}": the :root block in ${tokensCssPath} never closes.`);
|
|
134
|
+
}
|
|
135
|
+
lines.splice(bounds.close, 0, '', ` /* = ${category} = */`);
|
|
136
|
+
}
|
|
137
|
+
/** Locates and bounds the named category section. Throws when absent. */
|
|
138
|
+
export function findCategorySection(lines, category, tokensCssPath) {
|
|
139
|
+
const singleLinePattern = singleLineBannerPattern(category);
|
|
140
|
+
let categoryLine = -1;
|
|
141
|
+
for (let i = 0; i < lines.length; i++) {
|
|
142
|
+
const line = lines[i] ?? '';
|
|
143
|
+
// Check single-line format: /* = Category = */
|
|
144
|
+
if (singleLinePattern.test(line)) {
|
|
145
|
+
categoryLine = i;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
// Check multi-line format: line opens a block comment with === but does NOT close it
|
|
149
|
+
if (/^\s*\/\*\s*=+/.test(line) && !/\*\//.test(line)) {
|
|
150
|
+
for (let j = i + 1; j < Math.min(i + 6, lines.length); j++) {
|
|
151
|
+
const blockLine = lines[j] ?? '';
|
|
152
|
+
if (multiLineBlockNameMatches(blockLine, category)) {
|
|
153
|
+
categoryLine = i;
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
if (/\*\//.test(blockLine))
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
if (categoryLine !== -1)
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (categoryLine === -1) {
|
|
164
|
+
const discoveredCategories = discoverCategoryHeaders(lines);
|
|
165
|
+
const available = discoveredCategories.length > 0
|
|
166
|
+
? `Available categories in the file: ${discoveredCategories.map((name) => `"${name}"`).join(', ')}.`
|
|
167
|
+
: 'The file currently has no category headers.';
|
|
168
|
+
throw new GeneralError(`Category "${category}" not found in ${tokensCssPath}.\n\n` +
|
|
169
|
+
`${available}\n\n` +
|
|
170
|
+
'Add a header by hand inside the :root block (format: "/* = My Category = */") or re-run "fireforge furnace init --force" to re-seed the default categories.');
|
|
171
|
+
}
|
|
172
|
+
// Find the end of this category section (next section header or closing })
|
|
173
|
+
// Skip past the current header block first
|
|
174
|
+
let scanStart = categoryLine + 1;
|
|
175
|
+
for (let i = categoryLine + 1; i < lines.length; i++) {
|
|
176
|
+
const line = lines[i] ?? '';
|
|
177
|
+
if (/^\s*\/\*\s*=/.test(line) || /^\s*\*\s*=/.test(line) || /^\s*\*\//.test(line)) {
|
|
178
|
+
scanStart = i + 1;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
let sectionEnd = lines.length;
|
|
184
|
+
for (let i = scanStart; i < lines.length; i++) {
|
|
185
|
+
const line = lines[i] ?? '';
|
|
186
|
+
if (/\/\*\s*=.*=\s*\*\//.test(line) ||
|
|
187
|
+
(/^\s*\/\*\s*=+/.test(line) && !/\*\//.test(line)) ||
|
|
188
|
+
/^\s*\}/.test(line)) {
|
|
189
|
+
sectionEnd = i;
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return { categoryLine, sectionEnd };
|
|
194
|
+
}
|
|
195
|
+
/** 0-based open/close line indices of the base `:root {` block. */
|
|
196
|
+
function findBaseRootBounds(lines) {
|
|
197
|
+
let open = -1;
|
|
198
|
+
for (let i = 0; i < lines.length; i++) {
|
|
199
|
+
if (/:root\s*\{/.test(lines[i] ?? '')) {
|
|
200
|
+
open = i;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (open === -1)
|
|
205
|
+
return null;
|
|
206
|
+
for (let i = open + 1; i < lines.length; i++) {
|
|
207
|
+
if (/^\s*\}/.test(lines[i] ?? '')) {
|
|
208
|
+
return { open, close: i };
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return { open, close: -1 };
|
|
212
|
+
}
|
|
213
|
+
/** Masks block-comment content per line so declarations inside comments never match. */
|
|
214
|
+
function maskCommentLines(lines) {
|
|
215
|
+
const masked = lines.join('\n').replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, ' '));
|
|
216
|
+
return masked.split('\n');
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Finds an existing declaration of `tokenName` inside the base `:root`
|
|
220
|
+
* block. Dark `@media` and `:root[variant]` companion blocks are
|
|
221
|
+
* deliberately excluded — they mirror the base declaration, they do not
|
|
222
|
+
* own the token. Comment content never matches, and the name match is
|
|
223
|
+
* exact (`--foo-bar` does not match `--x-foo-bar`).
|
|
224
|
+
*/
|
|
225
|
+
export function findTokenDeclarationInRoot(lines, tokenName) {
|
|
226
|
+
const bounds = findBaseRootBounds(lines);
|
|
227
|
+
if (bounds === null || bounds.close === -1)
|
|
228
|
+
return undefined;
|
|
229
|
+
const masked = maskCommentLines(lines);
|
|
230
|
+
const declPattern = new RegExp(`^\\s*${escapeRegex(tokenName)}\\s*:`);
|
|
231
|
+
for (let i = bounds.open + 1; i < bounds.close; i++) {
|
|
232
|
+
if (!declPattern.test(masked[i] ?? ''))
|
|
233
|
+
continue;
|
|
234
|
+
const category = findSectionNameAbove(lines, i);
|
|
235
|
+
return category === undefined ? { line: i + 1 } : { line: i + 1, category };
|
|
236
|
+
}
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
/** Nearest category banner name above `lineIndex`, if any. */
|
|
240
|
+
function findSectionNameAbove(lines, lineIndex) {
|
|
241
|
+
const singleLinePattern = /\/\*\s*=+\s*(.+?)\s*=+\s*\*\//;
|
|
242
|
+
for (let i = lineIndex - 1; i >= 0; i--) {
|
|
243
|
+
const line = lines[i] ?? '';
|
|
244
|
+
const singleMatch = singleLinePattern.exec(line);
|
|
245
|
+
if (singleMatch?.[1]) {
|
|
246
|
+
const extracted = singleMatch[1].trim();
|
|
247
|
+
if (extracted.length > 0 && !/^=+$/.test(extracted))
|
|
248
|
+
return extracted;
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (/^\s*\/\*\s*=+/.test(line) && !/\*\//.test(line)) {
|
|
252
|
+
for (let j = i + 1; j < Math.min(i + 6, lines.length); j++) {
|
|
253
|
+
const blockLine = lines[j] ?? '';
|
|
254
|
+
if (/\*\//.test(blockLine))
|
|
255
|
+
break;
|
|
256
|
+
const trimmed = blockLine.replace(/^\s*\*\s*/, '').trim();
|
|
257
|
+
if (trimmed.length === 0 || /^=+$/.test(trimmed))
|
|
258
|
+
continue;
|
|
259
|
+
return trimmed;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return undefined;
|
|
264
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type TokenDeclarationLocation } from './token-category.js';
|
|
1
2
|
/**
|
|
2
3
|
* Dark mode behavior for a token.
|
|
3
4
|
*/
|
|
@@ -47,6 +48,12 @@ export interface AddTokenResult {
|
|
|
47
48
|
skipped: boolean;
|
|
48
49
|
/** Whether a new category banner was declared by this add. */
|
|
49
50
|
categoryCreated?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* When the add skipped because the token already lives in the TARGET
|
|
53
|
+
* category, names where the existing base-`:root` declaration sits so
|
|
54
|
+
* the skip message can point at it (FORGE G3).
|
|
55
|
+
*/
|
|
56
|
+
skippedExisting?: TokenDeclarationLocation;
|
|
50
57
|
}
|
|
51
58
|
/** Returns the token CSS path relative to engine root for a given binary name. */
|
|
52
59
|
export declare function getTokensCssPath(binaryName: string): string;
|