@starci/eslint-canon-fe 9.5.23 → 9.6.2

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 (164) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/docs/button-intent.md +1 -1
  3. package/package.json +1 -1
  4. package/runtime/bundle.json +192 -0
  5. package/runtime/engine/by-code-unit.mjs +6 -6
  6. package/runtime/engine/model-config.mjs +98 -76
  7. package/runtime/engine/orca-config.mjs +22 -17
  8. package/runtime/engine/release-config.mjs +22 -18
  9. package/runtime/engine/removed-vocabulary.mjs +21 -20
  10. package/runtime/engine/resources-config.mjs +42 -35
  11. package/runtime/engine/runtime-root.mjs +11 -13
  12. package/runtime/engine/secrets.mjs +170 -102
  13. package/runtime/engine/sonar-config.mjs +16 -13
  14. package/runtime/engine/temp-root.mjs +3 -9
  15. package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
  16. package/runtime/knowledge/hfs/slots.yaml +2 -2
  17. package/runtime/knowledge/sonar-gate.yaml +1 -1
  18. package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
  19. package/runtime/scripts/api/git/cat-file.mjs +0 -1
  20. package/runtime/scripts/api/git/config-get.mjs +1 -2
  21. package/runtime/scripts/api/git/diff.mjs +0 -1
  22. package/runtime/scripts/api/git/lib.mjs +32 -32
  23. package/runtime/scripts/api/git/ls-files.mjs +0 -1
  24. package/runtime/scripts/api/git/ls-tree.mjs +0 -1
  25. package/runtime/scripts/api/git/merge-base.mjs +2 -3
  26. package/runtime/scripts/api/git/remote.mjs +0 -1
  27. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
  28. package/runtime/scripts/api/git/show.mjs +0 -1
  29. package/runtime/scripts/hfs/allows.mjs +37 -38
  30. package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
  31. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
  32. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
  33. package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
  34. package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
  35. package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
  36. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
  37. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
  38. package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
  39. package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
  40. package/runtime/scripts/hfs/architecture/config.mjs +302 -268
  41. package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
  42. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
  43. package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
  44. package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
  45. package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
  46. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
  47. package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
  48. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
  49. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
  50. package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
  51. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
  52. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
  53. package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
  54. package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
  55. package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
  56. package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
  57. package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
  58. package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
  59. package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
  60. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
  61. package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
  62. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
  63. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
  64. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
  65. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
  66. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
  67. package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
  68. package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
  69. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
  70. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
  71. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
  72. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
  73. package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
  74. package/runtime/scripts/hfs/architecture/index.mjs +272 -272
  75. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
  76. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
  77. package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
  78. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
  79. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
  80. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
  81. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
  82. package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
  83. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
  84. package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
  85. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
  86. package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
  87. package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
  88. package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
  89. package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
  90. package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
  91. package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
  92. package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
  93. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
  94. package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
  95. package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
  96. package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
  97. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
  98. package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
  99. package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
  100. package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
  101. package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
  102. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
  103. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
  104. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
  105. package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
  106. package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
  107. package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
  108. package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
  109. package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
  110. package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
  111. package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
  112. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
  113. package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
  114. package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
  115. package/runtime/scripts/hfs/edition-slots.mjs +43 -40
  116. package/runtime/scripts/hfs/linear-text.mjs +20 -20
  117. package/runtime/scripts/hfs/param-names.mjs +6 -11
  118. package/runtime/scripts/hfs/path-findings.mjs +120 -100
  119. package/runtime/scripts/hfs/repo-identity.mjs +55 -42
  120. package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
  121. package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
  122. package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
  123. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
  124. package/runtime/scripts/hfs/rules/read.mjs +19 -15
  125. package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
  126. package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
  127. package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
  128. package/runtime/scripts/hfs/slot-classify.mjs +42 -38
  129. package/runtime/scripts/hfs/slot-errors.mjs +8 -7
  130. package/runtime/scripts/hfs/slot-imports.mjs +70 -63
  131. package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
  132. package/runtime/scripts/hfs/slot-match.mjs +122 -111
  133. package/runtime/scripts/hfs/slot-path.mjs +0 -2
  134. package/runtime/scripts/hfs/slot-required.mjs +65 -59
  135. package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
  136. package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
  137. package/runtime/scripts/hfs/slots.mjs +175 -152
  138. package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
  139. package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
  140. package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
  141. package/runtime/scripts/hfs/view.mjs +38 -40
  142. package/runtime/scripts/lib/dockerfile.mjs +131 -114
  143. package/runtime/scripts/lib/env.mjs +3 -6
  144. package/runtime/scripts/lib/event-contract.mjs +73 -78
  145. package/runtime/scripts/lib/git.mjs +15 -16
  146. package/runtime/scripts/lib/glob.mjs +23 -14
  147. package/runtime/scripts/lib/grammar-lint.mjs +33 -37
  148. package/runtime/scripts/lib/i18n.mjs +32 -35
  149. package/runtime/scripts/lib/in-order.mjs +57 -38
  150. package/runtime/scripts/lib/json-clone.mjs +45 -36
  151. package/runtime/scripts/lib/json.mjs +26 -14
  152. package/runtime/scripts/lib/language.mjs +133 -129
  153. package/runtime/scripts/lib/list.mjs +9 -14
  154. package/runtime/scripts/lib/mutation-fence.mjs +10 -5
  155. package/runtime/scripts/lib/path-key.mjs +53 -38
  156. package/runtime/scripts/lib/read-text.mjs +30 -17
  157. package/runtime/scripts/lib/regex.mjs +1 -2
  158. package/runtime/scripts/lib/same-text.mjs +0 -1
  159. package/runtime/scripts/lib/sops-envelope.mjs +148 -120
  160. package/runtime/scripts/lib/stack-services.mjs +128 -129
  161. package/runtime/scripts/lib/ts-analysis.mjs +28 -26
  162. package/runtime/scripts/lib/ts-ast.mjs +36 -42
  163. package/runtime/scripts/lib/walk.mjs +33 -27
  164. package/runtime/scripts/lib/yaml-cached.mjs +4 -4
@@ -7,122 +7,125 @@
7
7
  // decomposed spelling (base letter + combining mark) is caught exactly like the precomposed one, and a loanword such as
8
8
  // `naive`, `facade` or `Muller` (no tone mark, no Vietnamese letter) is never a hit.
9
9
  import path from 'node:path';
10
-
11
10
  /** One Vietnamese letter, precomposed (NFC): the Vietnamese-specific base letters, tone-marked vowels and the Latin Extended Additional block. */
12
11
  export const SECOND_LANGUAGE_LETTER = /[À-ÃÈ-ÊÌÍÒ-ÕÙÚÝà-ãè-êìíò-õùúýĂăĐđĨĩŨũƠơƯưẠ-ỿ]/;
13
-
14
12
  /** Whether `text` holds a Vietnamese letter, in NFC or NFD spelling. */
15
13
  export const hasSecondLanguage = (text) => typeof text === 'string' && SECOND_LANGUAGE_LETTER.test(text.normalize('NFC'));
16
-
17
14
  /** Every line of `text` with a Vietnamese letter: `[{ line, column }]`, both 1-based. */
18
15
  function secondLanguageHits(text) {
19
- const hits = [];
20
- String(text).split(/\r?\n/).forEach((raw, index) => {
21
- const match = SECOND_LANGUAGE_LETTER.exec(raw.normalize('NFC'));
22
- if (match) hits.push({ line: index + 1, column: match.index + 1 });
23
- });
24
- return hits;
16
+ const hits = [];
17
+ String(text).split(/\r?\n/).forEach((raw, index) => {
18
+ const match = SECOND_LANGUAGE_LETTER.exec(raw.normalize('NFC'));
19
+ if (match)
20
+ hits.push({ line: index + 1, column: match.index + 1 });
21
+ });
22
+ return hits;
25
23
  }
26
-
27
24
  /** The named bindings of an import from the backend message catalog contract. */
28
25
  function messageCatalogBindings(ts, statement) {
29
- if (!ts.isImportDeclaration(statement) || statement.moduleSpecifier.text !== '@modules/platform/i18n') return null;
30
- return statement.importClause?.namedBindings ?? null;
26
+ if (!ts.isImportDeclaration(statement) || statement.moduleSpecifier.text !== '@modules/platform/i18n')
27
+ return null;
28
+ return statement.importClause?.namedBindings ?? null;
31
29
  }
32
-
33
30
  /** The local type names imported from the backend message catalog contract. */
34
31
  function messageBundleImports(ts, source) {
35
- const named = new Set();
36
- const namespaces = new Set();
37
- for (const statement of source.statements) {
38
- const bindings = messageCatalogBindings(ts, statement);
39
- if (!bindings) continue;
40
- if (ts.isNamespaceImport(bindings)) namespaces.add(bindings.name.text);
41
- for (const entry of ts.isNamedImports(bindings) ? bindings.elements : []) {
42
- if ((entry.propertyName ?? entry.name).text === 'MessageBundle') named.add(entry.name.text);
32
+ const named = new Set();
33
+ const namespaces = new Set();
34
+ for (const statement of source.statements) {
35
+ const bindings = messageCatalogBindings(ts, statement);
36
+ if (!bindings)
37
+ continue;
38
+ if (ts.isNamespaceImport(bindings))
39
+ namespaces.add(bindings.name.text);
40
+ for (const entry of ts.isNamedImports(bindings) ? bindings.elements : []) {
41
+ if ((entry.propertyName ?? entry.name).text === 'MessageBundle')
42
+ named.add(entry.name.text);
43
+ }
43
44
  }
44
- }
45
- return { named, namespaces };
45
+ return { named, namespaces };
46
46
  }
47
-
48
47
  /** A declaration that introduces a same-named local type or namespace. */
49
48
  function declaresTypeName(ts, statement, name) {
50
- if (statement.name?.text !== name) return false;
51
- return [ts.isTypeAliasDeclaration, ts.isInterfaceDeclaration, ts.isClassDeclaration, ts.isEnumDeclaration, ts.isModuleDeclaration]
52
- .some(predicate => predicate(statement));
49
+ if (statement.name?.text !== name)
50
+ return false;
51
+ return [ts.isTypeAliasDeclaration, ts.isInterfaceDeclaration, ts.isClassDeclaration, ts.isEnumDeclaration, ts.isModuleDeclaration]
52
+ .some(predicate => predicate(statement));
53
53
  }
54
-
55
54
  /** A type reference bound to the imported MessageBundle contract, including import aliases. */
56
55
  function isMessageBundleType(ts, type, imports) {
57
- if (!type || !ts.isTypeReferenceNode(type)) return false;
58
- const name = type.typeName;
59
- if (ts.isIdentifier(name)) return imports.named.has(name.text) && !shadowsImportedType(ts, type, name.text);
60
- return ts.isQualifiedName(name) && ts.isIdentifier(name.left)
61
- && imports.namespaces.has(name.left.text) && name.right.text === 'MessageBundle' && !shadowsImportedType(ts, type, name.left.text);
56
+ if (!type || !ts.isTypeReferenceNode(type))
57
+ return false;
58
+ const name = type.typeName;
59
+ if (ts.isIdentifier(name))
60
+ return imports.named.has(name.text) && !shadowsImportedType(ts, type, name.text);
61
+ return ts.isQualifiedName(name) && ts.isIdentifier(name.left)
62
+ && imports.namespaces.has(name.left.text) && name.right.text === 'MessageBundle' && !shadowsImportedType(ts, type, name.left.text);
62
63
  }
63
-
64
64
  /** A local declaration or generic type parameter takes precedence over a same-named import. */
65
65
  function shadowsImportedType(ts, node, name) {
66
- for (let scope = node.parent; scope; scope = scope.parent) {
67
- if (scope.typeParameters?.some(parameter => parameter.name.text === name)) return true;
68
- if (scope.statements?.some(statement => declaresTypeName(ts, statement, name))) return true;
69
- }
70
- return false;
66
+ for (let scope = node.parent; scope; scope = scope.parent) {
67
+ const scoped = scope;
68
+ if (scoped.typeParameters?.some(parameter => parameter.name.text === name))
69
+ return true;
70
+ if (scoped.statements?.some(statement => declaresTypeName(ts, statement, name)))
71
+ return true;
72
+ }
73
+ return false;
71
74
  }
72
-
73
75
  /** The literal object supplied by a variable typed with the imported MessageBundle contract. */
74
76
  function messageCatalogObject(ts, node, imports) {
75
- if (!ts.isVariableDeclaration(node) || !node.initializer) return null;
76
- let value = node.initializer;
77
- const type = ts.isSatisfiesExpression(value) ? value.type : node.type;
78
- if (ts.isSatisfiesExpression(value)) value = value.expression;
79
- return isMessageBundleType(ts, type, imports) && ts.isObjectLiteralExpression(value) ? value : null;
77
+ if (!ts.isVariableDeclaration(node) || !node.initializer)
78
+ return null;
79
+ let value = node.initializer;
80
+ const type = ts.isSatisfiesExpression(value) ? value.type : node.type;
81
+ if (ts.isSatisfiesExpression(value))
82
+ value = value.expression;
83
+ return isMessageBundleType(ts, type, imports) && ts.isObjectLiteralExpression(value) ? value : null;
80
84
  }
81
-
82
85
  /** Literal string values in the Vietnamese locale of one message catalog. */
83
86
  function vietnameseValueRanges(ts, catalog, source) {
84
- const ranges = [];
85
- for (const locale of catalog.properties) {
86
- if (!ts.isPropertyAssignment(locale) || locale.name.text !== 'vi' || !ts.isObjectLiteralExpression(locale.initializer)) continue;
87
- for (const message of locale.initializer.properties) {
88
- if (ts.isPropertyAssignment(message) && ts.isStringLiteralLike(message.initializer))
89
- ranges.push({ start: message.initializer.getStart(source), end: message.initializer.end });
87
+ const ranges = [];
88
+ for (const locale of catalog.properties) {
89
+ if (!ts.isPropertyAssignment(locale) || locale.name.text !== 'vi' || !ts.isObjectLiteralExpression(locale.initializer))
90
+ continue;
91
+ for (const message of locale.initializer.properties) {
92
+ if (ts.isPropertyAssignment(message) && ts.isStringLiteralLike(message.initializer))
93
+ ranges.push({ start: message.initializer.getStart(source), end: message.initializer.end });
94
+ }
90
95
  }
91
- }
92
- return ranges;
96
+ return ranges;
93
97
  }
94
-
95
98
  /** Literal Vietnamese message values of typed catalogs; keys, comments, English values and expressions remain source. */
96
99
  function messageBundleValueRanges(ts, source) {
97
- const imports = messageBundleImports(ts, source);
98
- const ranges = [];
99
- const visit = (node) => {
100
- const catalog = messageCatalogObject(ts, node, imports);
101
- if (catalog) ranges.push(...vietnameseValueRanges(ts, catalog, source));
102
- ts.forEachChild(node, visit);
103
- };
104
- visit(source);
105
- return ranges;
100
+ const imports = messageBundleImports(ts, source);
101
+ const ranges = [];
102
+ const visit = (node) => {
103
+ const catalog = messageCatalogObject(ts, node, imports);
104
+ if (catalog)
105
+ ranges.push(...vietnameseValueRanges(ts, catalog, source));
106
+ ts.forEachChild(node, visit);
107
+ };
108
+ visit(source);
109
+ return ranges;
106
110
  }
107
-
108
111
  /** Source-language hits, treating only literal vi values of typed backend MessageBundle objects as translated product data. */
109
112
  export function sourceLanguageHits(rel, text, ts) {
110
- if (!hasSecondLanguage(text)) return [];
111
- if (!ts || !/\.[cm]?tsx?$/.test(rel)) return secondLanguageHits(text);
112
- const source = ts.createSourceFile(rel, text, ts.ScriptTarget.Latest, true);
113
- let sourceText = text;
114
- for (const range of messageBundleValueRanges(ts, source).sort((left, right) => right.start - left.start)) {
115
- sourceText = sourceText.slice(0, range.start) + sourceText.slice(range.start, range.end).replace(/[^\r\n]/g, ' ') + sourceText.slice(range.end);
116
- }
117
- return secondLanguageHits(sourceText);
113
+ if (!hasSecondLanguage(text))
114
+ return [];
115
+ if (!ts || !/\.[cm]?tsx?$/.test(rel))
116
+ return secondLanguageHits(text);
117
+ const source = ts.createSourceFile(rel, text, ts.ScriptTarget.Latest, true);
118
+ let sourceText = text;
119
+ for (const range of messageBundleValueRanges(ts, source).sort((left, right) => right.start - left.start)) {
120
+ sourceText = sourceText.slice(0, range.start) + sourceText.slice(range.start, range.end).replace(/[^\r\n]/g, ' ') + sourceText.slice(range.end);
121
+ }
122
+ return secondLanguageHits(sourceText);
118
123
  }
119
-
120
124
  /**
121
125
  * The Vietnamese fields of one failure-code entry: the operator text the owner mandated for the failure-code catalog
122
126
  * (scripts/checks/check-failure-codes.mjs types the entry with exactly these). causes_vi is the list companion of the three scalar fields.
123
127
  */
124
128
  export const FAILURE_CODE_VIETNAMESE_FIELDS = Object.freeze(['title_vi', 'meaning_vi', 'nextStep_vi', 'causes_vi']);
125
-
126
129
  /**
127
130
  * The fields of a document that carry deliberate Vietnamese text, keyed by file: a declared field-level exception of that file's
128
131
  * typed content, never a path pattern over content. `fields` are block keys (the key's own value and its list items are exempt);
@@ -139,91 +142,92 @@ export const FAILURE_CODE_VIETNAMESE_FIELDS = Object.freeze(['title_vi', 'meanin
139
142
  * owner's reading of the same rule.
140
143
  */
141
144
  export const DECLARED_VIETNAMESE_FIELDS = Object.freeze({
142
- 'modules/kernel/failure-codes.yaml': Object.freeze({ fields: FAILURE_CODE_VIETNAMESE_FIELDS }),
143
- 'modules/ops/_labels.yaml': Object.freeze({ flowFields: Object.freeze(['vi']) }),
144
- 'modules/goal/archetypes.yaml': Object.freeze({
145
- fields: Object.freeze([
146
- 'buildIntent', 'canonIntent', 'e2eIntent', 'uatIntent', 'proofNegation', 'proofStateCue', 'integrationIntent', 'brandIntent',
147
- 'phrases', 'requires', 'excludes', 'backend', 'frontend', 'package',
148
- ]),
149
- }),
150
- 'modules/goal/source-phrases.yaml': Object.freeze({
151
- fields: Object.freeze([
152
- 'prefer', 'avoid', 'only', 'negation', 'refused', 'accept', 'golden',
153
- 'missingPaths', 'grantTooNarrow', 'toolTimeout', 'testGap', 'checkerUnavailable',
154
- 'supervisorVerbs', 'ownerWord', 'orWord', 'beyondAuthority', 'ownerOnly', 'workerDied', 'contractConflict', 'decision',
155
- 'product', 'grammar', 'knowledge', 'sourceLabel', 'internalVocabulary', 'actor', 'success',
156
- 'wizard', 'form', 'dashboard', 'gap', 'anatomy', 'otpLabel',
157
- ]),
158
- }),
145
+ 'modules/kernel/failure-codes.yaml': Object.freeze({ fields: FAILURE_CODE_VIETNAMESE_FIELDS }),
146
+ 'modules/ops/_labels.yaml': Object.freeze({ flowFields: Object.freeze(['vi']) }),
147
+ 'modules/goal/archetypes.yaml': Object.freeze({
148
+ fields: Object.freeze([
149
+ 'buildIntent', 'canonIntent', 'e2eIntent', 'uatIntent', 'proofNegation', 'proofStateCue', 'integrationIntent', 'brandIntent',
150
+ 'phrases', 'requires', 'excludes', 'backend', 'frontend', 'package',
151
+ ]),
152
+ }),
153
+ 'modules/goal/source-phrases.yaml': Object.freeze({
154
+ fields: Object.freeze([
155
+ 'prefer', 'avoid', 'only', 'negation', 'refused', 'accept', 'golden',
156
+ 'missingPaths', 'grantTooNarrow', 'toolTimeout', 'testGap', 'checkerUnavailable',
157
+ 'supervisorVerbs', 'ownerWord', 'orWord', 'beyondAuthority', 'ownerOnly', 'workerDied', 'contractConflict', 'decision',
158
+ 'product', 'grammar', 'knowledge', 'sourceLabel', 'internalVocabulary', 'actor', 'success',
159
+ 'wizard', 'form', 'dashboard', 'gap', 'anatomy', 'otpLabel',
160
+ ]),
161
+ }),
159
162
  });
160
-
161
163
  /**
162
164
  * The Vietnamese catalog of owner-visible messages (scripts/lib/i18n.mjs): modules/i18n/messages/<area>.yaml, a list of
163
165
  * `{en, vi}` entries keyed from the English source. The `vi` field (block or inline flow) is the declared Vietnamese.
164
166
  */
165
167
  const I18N_CATALOG_VIETNAMESE_FIELDS = Object.freeze({ fields: Object.freeze(['vi']), flowFields: Object.freeze(['vi']) });
166
168
  const I18N_CATALOG_DIR = 'modules/i18n/messages/';
167
-
168
169
  /** The `vi` field of an op manifest's text objects (modules/schemas/op.schema.yaml $defs text). */
169
170
  const OP_MANIFEST_VIETNAMESE_FIELDS = Object.freeze({ fields: Object.freeze(['vi']) });
170
171
  const OP_MANIFEST_DIR = 'modules/ops/ops/';
171
172
  /** The declared Vietnamese fields of `rel`: its own entry, or the op-manifest text field for a manifest of modules/ops/ops. */
172
173
  const declaredVietnameseFieldsOf = (rel) => DECLARED_VIETNAMESE_FIELDS[rel]
173
- ?? (rel.startsWith(I18N_CATALOG_DIR) && !rel.slice(I18N_CATALOG_DIR.length).includes('/') && /\.ya?ml$/.test(rel) ? I18N_CATALOG_VIETNAMESE_FIELDS : null)
174
- ?? (rel.startsWith(OP_MANIFEST_DIR) && !rel.slice(OP_MANIFEST_DIR.length).includes('/') && /\.ya?ml$/.test(rel) ? OP_MANIFEST_VIETNAMESE_FIELDS : null);
175
-
174
+ ?? (rel.startsWith(I18N_CATALOG_DIR) && !rel.slice(I18N_CATALOG_DIR.length).includes('/') && /\.ya?ml$/.test(rel) ? I18N_CATALOG_VIETNAMESE_FIELDS : null)
175
+ ?? (rel.startsWith(OP_MANIFEST_DIR) && !rel.slice(OP_MANIFEST_DIR.length).includes('/') && /\.ya?ml$/.test(rel) ? OP_MANIFEST_VIETNAMESE_FIELDS : null);
176
176
  /**
177
177
  * The slots whose files may carry another language, and why: a catalog is product copy in two languages, and an i18n
178
178
  * fixture reproduces a real localized string a parser or formatter must accept. Placement is the whole marker - there is no
179
179
  * comment pragma and no path pattern. The slots are declared in knowledge/hfs/slots.yaml.
180
180
  */
181
181
  const LOCALIZED_TEXT_SLOTS = Object.freeze([
182
- 'be.domain.messages', 'be.feature.messages', 'be.tests.fixtures.i18n',
183
- 'fe.modules.i18n', 'fe.package.i18n',
182
+ 'be.domain.messages', 'be.feature.messages', 'be.tests.fixtures.i18n',
183
+ 'fe.modules.i18n', 'fe.package.i18n',
184
184
  ]);
185
-
186
185
  /** Whether a document (Markdown or YAML) of `slot` is exempt: only catalogue and fixture DATA (YAML) is; Markdown is prose and never is. */
187
186
  export const isLocalizedDataFile = (rel, slot) => LOCALIZED_TEXT_SLOTS.includes(slot) && /\.ya?ml$/.test(rel);
188
-
189
187
  /**
190
188
  * The key each line of a YAML text belongs to: a `key:` line owns itself, and every deeper-indented line after it (a list item,
191
189
  * a folded block, a wrapped scalar) belongs to the same key. A line at or above the key's indent that is not a key belongs to none.
192
190
  */
193
191
  function yamlKeyOfEachLine(text) {
194
- let key = null;
195
- let keyIndent = -1;
196
- return String(text).split(/\r?\n/).map((raw) => {
197
- if (raw.trim() === '') return key;
198
- const indent = raw.length - raw.trimStart().length;
199
- const own = /^(\s*(?:-\s+)?)([A-Za-z_][\w-]*)\s*:(?:\s|$)/.exec(raw);
200
- if (own) { key = own[2]; keyIndent = own[1].length; return key; }
201
- // a list item may sit at the key's own indent (`key:` then `- item` at the same column)
202
- if (indent > keyIndent || (indent === keyIndent && /^\s*-\s/.test(raw))) return key;
203
- key = null;
204
- keyIndent = -1;
205
- return null;
206
- });
192
+ let key = null;
193
+ let keyIndent = -1;
194
+ return String(text).split(/\r?\n/).map((raw) => {
195
+ if (raw.trim() === '')
196
+ return key;
197
+ const indent = raw.length - raw.trimStart().length;
198
+ const own = /^(\s*(?:-\s+)?)([A-Za-z_][\w-]*)\s*:(?:\s|$)/.exec(raw);
199
+ if (own) {
200
+ key = own[2];
201
+ keyIndent = own[1].length;
202
+ return key;
203
+ }
204
+ // a list item may sit at the key's own indent (`key:` then `- item` at the same column)
205
+ if (indent > keyIndent || (indent === keyIndent && /^\s*-\s/.test(raw)))
206
+ return key;
207
+ key = null;
208
+ keyIndent = -1;
209
+ return null;
210
+ });
207
211
  }
208
-
209
212
  /** The Vietnamese hits of a document, minus the declared field-level exceptions of `rel` (a repository-relative POSIX path). */
210
213
  export function documentLanguageHits(rel, text) {
211
- const declared = declaredVietnameseFieldsOf(rel);
212
- const hits = secondLanguageHits(text);
213
- if (!declared) return hits;
214
- const keys = yamlKeyOfEachLine(text);
215
- const lines = String(text).split(/\r?\n/);
216
- return hits.filter((hit) => {
217
- if (declared.fields?.includes(keys[hit.line - 1])) return false;
218
- if (!declared.flowFields) return true;
219
- // an inline flow map: drop the declared fields' values and judge what is left of the line
220
- const rest = declared.flowFields.reduce((line, field) => line.replace(new RegExp(String.raw`\b${field}\s*:\s*(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|[^,}]*)`, 'g'), ''), lines[hit.line - 1]);
221
- return hasSecondLanguage(rest);
222
- });
214
+ const declared = declaredVietnameseFieldsOf(rel);
215
+ const hits = secondLanguageHits(text);
216
+ if (!declared)
217
+ return hits;
218
+ const keys = yamlKeyOfEachLine(text);
219
+ const lines = String(text).split(/\r?\n/);
220
+ return hits.filter((hit) => {
221
+ if (declared.fields?.includes(keys[hit.line - 1] ?? ''))
222
+ return false;
223
+ if (!declared.flowFields)
224
+ return true;
225
+ // an inline flow map: drop the declared fields' values and judge what is left of the line
226
+ const rest = declared.flowFields.reduce((line, field) => line.replace(new RegExp(String.raw `\b${field}\s*:\s*(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|[^,}]*)`, 'g'), ''), lines[hit.line - 1]);
227
+ return hasSecondLanguage(rest);
228
+ });
223
229
  }
224
-
225
230
  /** The file extensions of a prose document (Markdown and YAML). */
226
231
  const DOCUMENT_EXTENSIONS = Object.freeze(['.md', '.yaml', '.yml']);
227
-
228
232
  /** Whether `rel` is a document a language check reads. */
229
233
  export const isDocument = (rel) => DOCUMENT_EXTENSIONS.includes(path.posix.extname(rel));
@@ -2,30 +2,25 @@
2
2
  // `v` when it already is an array, else []. Scalars are NOT wrapped: a caller that wants
3
3
  // `[v]` for a lone value writes its own coercion (see contract-version's list).
4
4
  export const list = (v) => (Array.isArray(v) ? v : []);
5
-
6
5
  /** `v` as an array: itself when already one, [] for null/undefined, else [v]. */
7
6
  export const asList = (v) => {
8
- if (Array.isArray(v)) return v;
9
- if (v == null) return [];
10
- return [v];
7
+ if (Array.isArray(v))
8
+ return v;
9
+ if (v == null)
10
+ return [];
11
+ return [v];
11
12
  };
12
-
13
13
  /** The object entries of `v` (a non-array reads as []). */
14
14
  export const objectList = (v) => (Array.isArray(v) ? v : []).filter((item) => item && typeof item === 'object');
15
-
16
15
  /** Every entry of `v` a non-empty string (`blank: false` also rejects all-whitespace entries). */
17
- export const stringList = (v, { blank = true } = {}) =>
18
- Array.isArray(v) && v.every((s) => typeof s === 'string' && s.length > 0 && (blank || s.trim().length > 0));
19
-
16
+ export const stringList = (v, { blank = true } = {}) => Array.isArray(v) && v.every((s) => typeof s === 'string' && s.length > 0 && (blank || s.trim().length > 0));
20
17
  /** A non-empty list of distinct values, all accepted by the supplied predicate. */
21
18
  export const nonemptyUniqueList = (values, accepts) => Array.isArray(values) && values.length > 0
22
- && values.every((entry) => accepts(entry)) && new Set(values).size === values.length;
23
-
19
+ && values.every((entry) => accepts(entry)) && new Set(values).size === values.length;
24
20
  /** The items of a `sep`-separated list: trimmed, empties dropped; `dedupe` keeps first occurrences only. */
25
21
  export const splitList = (v, { sep = ',', dedupe = false } = {}) => {
26
- const items = String(v ?? '').split(sep).map((s) => s.trim()).filter(Boolean);
27
- return dedupe ? [...new Set(items)] : items;
22
+ const items = String(v ?? '').split(sep).map((s) => s.trim()).filter(Boolean);
23
+ return dedupe ? [...new Set(items)] : items;
28
24
  };
29
-
30
25
  // The comparator of a bare `sort()` (UTF-16 code-unit order) is owned by the engine, which cannot import scripts/lib.
31
26
  export { byCodeUnit } from '../../engine/by-code-unit.mjs';
@@ -1,15 +1,20 @@
1
1
  // mutation-fence.mjs — ephemeral admission carried through awaited work, never a state store.
2
2
  import { AsyncLocalStorage } from 'node:async_hooks';
3
3
  const scope = new AsyncLocalStorage();
4
-
5
4
  /** Run one admitted call; the checker is synchronous and reads its existing durable owners again. */
6
5
  export const withMutationFence = (check, authority, fn) => scope.run({ check, authority, checking: false }, fn);
7
6
  /** Recheck after the actual transaction lock or immediately before a native effect. */
8
7
  export function assertMutationFence(boundary) {
9
- const current = scope.getStore();
10
- if (!current || current.checking) return;
11
- current.checking = true;
12
- try { current.check(boundary); } finally { current.checking = false; }
8
+ const current = scope.getStore();
9
+ if (!current || current.checking)
10
+ return;
11
+ current.checking = true;
12
+ try {
13
+ current.check(boundary);
14
+ }
15
+ finally {
16
+ current.checking = false;
17
+ }
13
18
  }
14
19
  /** Identity stamped by existing write owners, never accepted from a command argument. */
15
20
  export const mutationAuthority = () => scope.getStore()?.authority ?? null;
@@ -1,21 +1,23 @@
1
1
  // path-key.mjs — spelling and comparing paths the way this host's filesystem does.
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
-
5
4
  const WIN = process.platform === 'win32';
6
-
7
5
  /** `p` with every backslash turned into a forward slash; null and undefined read as ''. */
8
6
  export const slash = (p) => String(p ?? '').replaceAll('\\', '/');
9
7
  /** `text` without its trailing '/' run (a loop: a trailing-run pattern backtracks super-linearly). */
10
8
  export const trimTrailingSlashes = (text) => {
11
- for (let end = text.length; ; end -= 1) if (end === 0 || text[end - 1] !== '/') return text.slice(0, end);
9
+ for (let end = text.length;; end -= 1)
10
+ if (end === 0 || text[end - 1] !== '/')
11
+ return text.slice(0, end);
12
12
  };
13
13
  // A trailing '*' run with the one '/' before it (the glob suffix of 'dir/**'); text without a trailing '*' is unchanged.
14
14
  const stripTrailingStars = (text) => {
15
- let end = text.length;
16
- while (end > 0 && text[end - 1] === '*') end -= 1;
17
- if (end === text.length) return text;
18
- return text.slice(0, end > 0 && text[end - 1] === '/' ? end - 1 : end);
15
+ let end = text.length;
16
+ while (end > 0 && text[end - 1] === '*')
17
+ end -= 1;
18
+ if (end === text.length)
19
+ return text;
20
+ return text.slice(0, end > 0 && text[end - 1] === '/' ? end - 1 : end);
19
21
  };
20
22
  /** A relative path in git's spelling: forward slashes, no leading './'. */
21
23
  export const posixPath = (p) => slash(p).replace(/^\.\//, '');
@@ -30,8 +32,8 @@ export const samePath = (a, b) => foldCase(a) === foldCase(b);
30
32
  * `fold: true` folds case on every platform (a comparison against a lowercase-stored root needs it).
31
33
  */
32
34
  export const pathKey = (p, { fold = WIN } = {}) => {
33
- const key = trimTrailingSlashes(slash(path.resolve(p)));
34
- return fold ? key.toLowerCase() : key;
35
+ const key = trimTrailingSlashes(slash(path.resolve(p)));
36
+ return fold ? key.toLowerCase() : key;
35
37
  };
36
38
  /** `a` is `b` or under it, or the reverse: two path spellings whose trees touch. */
37
39
  export const pathsOverlap = (a, b) => sameOrUnder(a, b) || sameOrUnder(b, a);
@@ -44,32 +46,45 @@ export const pathsOverlap = (a, b) => sameOrUnder(a, b) || sameOrUnder(b, a);
44
46
  * @param {{trim?: boolean, collapse?: boolean, dot?: boolean, glob?: string|null, fold?: boolean}} [options]
45
47
  */
46
48
  export const normPath = (p, { trim = false, collapse = false, dot = false, glob = null, fold = false } = {}) => {
47
- let s = p == null ? '' : String(p);
48
- if (trim) s = s.trim();
49
- s = slash(s);
50
- if (collapse) s = s.replace(/\/{2,}/g, '/');
51
- if (dot) s = s.replace(/^\.\//, '');
52
- if (glob === 'star') s = stripTrailingStars(s);
53
- else if (glob === 'double') s = s.replace(/\/\*\*$/, '');
54
- s = trimTrailingSlashes(s);
55
- return fold ? s.toLowerCase() : s;
49
+ let s = p == null ? '' : String(p);
50
+ if (trim)
51
+ s = s.trim();
52
+ s = slash(s);
53
+ if (collapse)
54
+ s = s.replace(/\/{2,}/g, '/');
55
+ if (dot)
56
+ s = s.replace(/^\.\//, '');
57
+ if (glob === 'star')
58
+ s = stripTrailingStars(s);
59
+ else if (glob === 'double')
60
+ s = s.replace(/\/\*\*$/, '');
61
+ s = trimTrailingSlashes(s);
62
+ return fold ? s.toLowerCase() : s;
56
63
  };
57
64
  /** A work-relative path in one spelling: forward slashes, no leading ./, no trailing slash. */
58
65
  export const normWork = (p) => trimTrailingSlashes(String(p ?? '').trim().replaceAll('\\', '/').replace(/^\.\/+/, ''));
59
-
60
66
  /** `p` resolved and dereferenced (realpath where the path exists) — the canonical spelling of a checkout dir. */
61
67
  export const realPath = (p) => {
62
- const resolved = path.resolve(p);
63
- try { return fs.realpathSync.native(resolved); } catch { return resolved; }
68
+ const resolved = path.resolve(p);
69
+ try {
70
+ return fs.realpathSync.native(resolved);
71
+ }
72
+ catch {
73
+ return resolved;
74
+ }
64
75
  };
65
76
  /** `p` with its nearest existing ancestor dereferenced and the not-yet-created rest appended: a root's canonical spelling before it exists. */
66
77
  export const canonicalPath = (p) => {
67
- const rest = [];
68
- for (let at = path.resolve(p); ; at = path.dirname(at)) {
69
- try { return path.join(fs.realpathSync.native(at), ...rest); } catch { /* not created yet */ }
70
- if (path.dirname(at) === at) return path.resolve(p);
71
- rest.unshift(path.basename(at));
72
- }
78
+ const rest = [];
79
+ for (let at = path.resolve(p);; at = path.dirname(at)) {
80
+ try {
81
+ return path.join(fs.realpathSync.native(at), ...rest);
82
+ }
83
+ catch { /* not created yet */ }
84
+ if (path.dirname(at) === at)
85
+ return path.resolve(p);
86
+ rest.unshift(path.basename(at));
87
+ }
73
88
  };
74
89
  /** `p` resolved and case-folded where the filesystem ignores case — the Map key of an absolute path. */
75
90
  export const resolvedKey = (p) => foldCase(path.resolve(p));
@@ -80,8 +95,8 @@ export const sameResolvedPath = (a, b) => pathKey(a, { fold: true }) === pathKey
80
95
  * both sides first (e.g. the registry's realpath-folded treeKey) when their spellings need it.
81
96
  */
82
97
  export const insidePath = (root, file, { key = (p) => p, includeSelf = false } = {}) => {
83
- const rel = path.relative(key(root), key(file));
84
- return (includeSelf || Boolean(rel)) && !rel.startsWith('..') && !path.isAbsolute(rel);
98
+ const rel = path.relative(key(root), key(file));
99
+ return (includeSelf || Boolean(rel)) && !rel.startsWith('..') && !path.isAbsolute(rel);
85
100
  };
86
101
  /**
87
102
  * `candidate` (absolute, or relative to `base`) resolved and dereferenced, required to sit under `base` (or be it):
@@ -90,20 +105,20 @@ export const insidePath = (root, file, { key = (p) => p, includeSelf = false } =
90
105
  * a PATH_OUTSIDE_BASE refusal (`label` names the argument in the message).
91
106
  */
92
107
  export const containedPath = (base, candidate, { label = 'path' } = {}) => {
93
- const root = canonicalPath(base);
94
- const resolved = canonicalPath(path.resolve(root, String(candidate ?? '')));
95
- const prefix = root.endsWith(path.sep) ? root : root + path.sep;
96
- if (!insidePath(root, resolved, { includeSelf: true }) || (resolved !== root && !resolved.startsWith(prefix))) throw Object.assign(new Error(`${label} ${String(candidate)} is outside ${root} [PATH_OUTSIDE_BASE]`), { code: 'PATH_OUTSIDE_BASE' });
97
- return resolved;
108
+ const root = canonicalPath(base);
109
+ const resolved = canonicalPath(path.resolve(root, String(candidate ?? '')));
110
+ const prefix = root.endsWith(path.sep) ? root : root + path.sep;
111
+ if (!insidePath(root, resolved, { includeSelf: true }) || (resolved !== root && !resolved.startsWith(prefix)))
112
+ throw Object.assign(new Error(`${label} ${String(candidate)} is outside ${root} [PATH_OUTSIDE_BASE]`), { code: 'PATH_OUTSIDE_BASE' });
113
+ return resolved;
98
114
  };
99
115
  /**
100
116
  * A path-ish value (a string or a {path} entry) in relative compare form: trimmed, forward slashes,
101
117
  * no trailing '/**' glob or slashes, no leading './'; `fold` lowercases for a case-insensitive key.
102
118
  */
103
119
  export const normRel = (p, { fold = false } = {}) => {
104
- const s = trimTrailingSlashes(String(typeof p === 'string' ? p : p?.path ?? '').trim().replaceAll('\\', '/').replace(/\/\*\*$/, '')).replace(/^\.\//, '');
105
- return fold ? s.toLowerCase() : s;
120
+ const s = trimTrailingSlashes(String(typeof p === 'string' ? p : p?.path ?? '').trim().replaceAll('\\', '/').replace(/\/\*\*$/, '')).replace(/^\.\//, '');
121
+ return fold ? s.toLowerCase() : s;
106
122
  };
107
123
  /** Whether `file` equals or sits under one of `prefixes` (posix spellings; `dot` counts a '.' prefix as covering all). */
108
- export const underAny = (file, prefixes, { dot = false } = {}) =>
109
- (prefixes ?? []).some((p) => (dot && p === '.') || sameOrUnder(file, p));
124
+ export const underAny = (file, prefixes, { dot = false } = {}) => (prefixes ?? []).some((p) => (dot && p === '.') || sameOrUnder(file, p));
@@ -2,33 +2,46 @@
2
2
  // never a throw (the JSON twin is ./json.mjs readJsonFile, the YAML twin ./read-yaml.mjs).
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
5
-
6
5
  /** The text of `rel` under `root` ('/'-separated rel), or null when it is missing or unreadable. */
7
6
  export const readTextFile = (root, rel) => {
8
- try { return fs.readFileSync(path.join(root, ...String(rel).split('/')), 'utf8'); } catch { return null; }
7
+ try {
8
+ return fs.readFileSync(path.join(root, ...String(rel).split('/')), 'utf8');
9
+ }
10
+ catch {
11
+ return null;
12
+ }
9
13
  };
10
-
11
14
  /** `file` read and parsed by `parse`, or `fallback` when it is missing, unreadable or malformed. */
12
15
  export const readParsedFile = (file, parse, fallback = null) => {
13
- try { return parse(fs.readFileSync(file, 'utf8')); } catch { return fallback; }
16
+ try {
17
+ return parse(fs.readFileSync(file, 'utf8'));
18
+ }
19
+ catch {
20
+ return fallback;
21
+ }
14
22
  };
15
-
16
23
  /**
17
24
  * Feed `file`'s lines to `onLine` reading in bounded chunks — a diff or a patch can exceed any single
18
25
  * string. `eol` is the line-ending pattern or literal (default CRLF-aware); a last unterminated line is fed too.
19
26
  */
20
27
  export function forEachFileLine(file, onLine, { chunkBytes = 8 * 1024 * 1024, eol = /\r?\n/ } = {}) {
21
- const fd = fs.openSync(file, 'r');
22
- try {
23
- const buf = Buffer.alloc(chunkBytes);
24
- let carry = '';
25
- for (;;) {
26
- const n = fs.readSync(fd, buf, 0, chunkBytes, null);
27
- if (n <= 0) break;
28
- const lines = (carry + buf.toString('utf8', 0, n)).split(eol);
29
- carry = lines.pop();
30
- for (const l of lines) onLine(l);
28
+ const fd = fs.openSync(file, 'r');
29
+ try {
30
+ const buf = Buffer.alloc(chunkBytes);
31
+ let carry = '';
32
+ for (;;) {
33
+ const n = fs.readSync(fd, buf, 0, chunkBytes, null);
34
+ if (n <= 0)
35
+ break;
36
+ const lines = (carry + buf.toString('utf8', 0, n)).split(eol);
37
+ carry = lines.pop();
38
+ for (const l of lines)
39
+ onLine(l);
40
+ }
41
+ if (carry)
42
+ onLine(carry);
43
+ }
44
+ finally {
45
+ fs.closeSync(fd);
31
46
  }
32
- if (carry) onLine(carry);
33
- } finally { fs.closeSync(fd); }
34
47
  }