@babelize/engine 0.0.0-stage → 0.1.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.
Files changed (246) hide show
  1. package/LICENSE +202 -0
  2. package/dist/BabelizeEngine.d.ts +12 -0
  3. package/dist/BabelizeEngine.js +47 -0
  4. package/dist/analysis/analyze.d.ts +106 -0
  5. package/dist/analysis/analyze.js +323 -0
  6. package/dist/config/env.d.ts +9 -0
  7. package/dist/config/env.js +16 -0
  8. package/dist/config.d.ts +74 -0
  9. package/dist/config.js +47 -0
  10. package/dist/index.d.ts +54 -0
  11. package/dist/index.js +126 -0
  12. package/dist/injection/InjectionStrategy.d.ts +62 -0
  13. package/dist/injection/InjectionStrategy.js +2 -0
  14. package/dist/injection/StrategyFactory.d.ts +4 -0
  15. package/dist/injection/StrategyFactory.js +29 -0
  16. package/dist/injection/django/django-template-injector.d.ts +29 -0
  17. package/dist/injection/django/django-template-injector.js +216 -0
  18. package/dist/injection/html/html-injector.d.ts +11 -0
  19. package/dist/injection/html/html-injector.js +173 -0
  20. package/dist/injection/strategies/NextIntlStrategy.d.ts +25 -0
  21. package/dist/injection/strategies/NextIntlStrategy.js +141 -0
  22. package/dist/injection/strategies/ReactI18nextStrategy.d.ts +19 -0
  23. package/dist/injection/strategies/ReactI18nextStrategy.js +116 -0
  24. package/dist/injection/strategies/VanillaStrategy.d.ts +11 -0
  25. package/dist/injection/strategies/VanillaStrategy.js +73 -0
  26. package/dist/injection/strategies/VueI18nStrategy.d.ts +11 -0
  27. package/dist/injection/strategies/VueI18nStrategy.js +84 -0
  28. package/dist/local/formatter.d.ts +26 -0
  29. package/dist/local/formatter.js +105 -0
  30. package/dist/local/git.d.ts +23 -0
  31. package/dist/local/git.js +136 -0
  32. package/dist/local/hosted-provider.d.ts +68 -0
  33. package/dist/local/hosted-provider.js +215 -0
  34. package/dist/local/index.d.ts +23 -0
  35. package/dist/local/index.js +75 -0
  36. package/dist/local/provider.d.ts +56 -0
  37. package/dist/local/provider.js +119 -0
  38. package/dist/local/pseudo-provider.d.ts +18 -0
  39. package/dist/local/pseudo-provider.js +207 -0
  40. package/dist/local/report.d.ts +177 -0
  41. package/dist/local/report.js +186 -0
  42. package/dist/local/translate-core.d.ts +215 -0
  43. package/dist/local/translate-core.js +461 -0
  44. package/dist/local/translate-messages.d.ts +49 -0
  45. package/dist/local/translate-messages.js +91 -0
  46. package/dist/local/workspace-copy.d.ts +91 -0
  47. package/dist/local/workspace-copy.js +355 -0
  48. package/dist/modules/extractor/extract.d.ts +20 -0
  49. package/dist/modules/extractor/extract.js +701 -0
  50. package/dist/modules/extractor/index.d.ts +2 -0
  51. package/dist/modules/extractor/index.js +63 -0
  52. package/dist/modules/finalization/django-finalize.d.ts +13 -0
  53. package/dist/modules/finalization/django-finalize.js +275 -0
  54. package/dist/modules/finalization/finalize.d.ts +36 -0
  55. package/dist/modules/finalization/finalize.js +717 -0
  56. package/dist/modules/finalization/index.d.ts +1 -0
  57. package/dist/modules/finalization/index.js +5 -0
  58. package/dist/modules/finalization/nextjs-finalize.d.ts +37 -0
  59. package/dist/modules/finalization/nextjs-finalize.js +329 -0
  60. package/dist/modules/finalization/static-runtime.d.ts +9 -0
  61. package/dist/modules/finalization/static-runtime.js +261 -0
  62. package/dist/modules/format-injection/index.d.ts +19 -0
  63. package/dist/modules/format-injection/index.js +272 -0
  64. package/dist/modules/format-injection/inject-formats.d.ts +31 -0
  65. package/dist/modules/format-injection/inject-formats.js +208 -0
  66. package/dist/modules/glossary/glossary.d.ts +9 -0
  67. package/dist/modules/glossary/glossary.js +27 -0
  68. package/dist/modules/glossary/index.d.ts +3 -0
  69. package/dist/modules/glossary/index.js +8 -0
  70. package/dist/modules/glossary/masker.d.ts +23 -0
  71. package/dist/modules/glossary/masker.js +56 -0
  72. package/dist/modules/glossary/types.d.ts +22 -0
  73. package/dist/modules/glossary/types.js +2 -0
  74. package/dist/modules/injection/index.d.ts +1 -0
  75. package/dist/modules/injection/index.js +6 -0
  76. package/dist/modules/injection/inject.d.ts +29 -0
  77. package/dist/modules/injection/inject.js +1066 -0
  78. package/dist/modules/keygen/index.d.ts +1 -0
  79. package/dist/modules/keygen/index.js +11 -0
  80. package/dist/modules/keygen/keygen.d.ts +4 -0
  81. package/dist/modules/keygen/keygen.js +116 -0
  82. package/dist/modules/keygen/locale-data.d.ts +7 -0
  83. package/dist/modules/keygen/locale-data.js +73 -0
  84. package/dist/modules/keygen/public.d.ts +2 -0
  85. package/dist/modules/keygen/public.js +12 -0
  86. package/dist/modules/locale-builder/index.d.ts +1 -0
  87. package/dist/modules/locale-builder/index.js +7 -0
  88. package/dist/modules/locale-builder/locales.d.ts +13 -0
  89. package/dist/modules/locale-builder/locales.js +107 -0
  90. package/dist/modules/locale-builder/po.d.ts +33 -0
  91. package/dist/modules/locale-builder/po.js +131 -0
  92. package/dist/modules/lockfile/hasher.d.ts +7 -0
  93. package/dist/modules/lockfile/hasher.js +13 -0
  94. package/dist/modules/lockfile/index.d.ts +3 -0
  95. package/dist/modules/lockfile/index.js +21 -0
  96. package/dist/modules/lockfile/lockfile-manager.d.ts +90 -0
  97. package/dist/modules/lockfile/lockfile-manager.js +482 -0
  98. package/dist/modules/lockfile/schema.d.ts +154 -0
  99. package/dist/modules/lockfile/schema.js +45 -0
  100. package/dist/modules/parser/index.d.ts +2 -0
  101. package/dist/modules/parser/index.js +9 -0
  102. package/dist/modules/summary/index.d.ts +1 -0
  103. package/dist/modules/summary/index.js +7 -0
  104. package/dist/modules/summary/summary.d.ts +9 -0
  105. package/dist/modules/summary/summary.js +195 -0
  106. package/dist/modules/sync-detector/index.d.ts +2 -0
  107. package/dist/modules/sync-detector/index.js +7 -0
  108. package/dist/modules/sync-detector/reporter.d.ts +3 -0
  109. package/dist/modules/sync-detector/reporter.js +16 -0
  110. package/dist/modules/sync-detector/sync-detector.d.ts +39 -0
  111. package/dist/modules/sync-detector/sync-detector.js +374 -0
  112. package/dist/modules/translator/batch-optimizer.d.ts +12 -0
  113. package/dist/modules/translator/batch-optimizer.js +30 -0
  114. package/dist/modules/translator/client/byok.provider.d.ts +64 -0
  115. package/dist/modules/translator/client/byok.provider.js +319 -0
  116. package/dist/modules/translator/client/direct-translator.client.d.ts +12 -0
  117. package/dist/modules/translator/client/direct-translator.client.js +71 -0
  118. package/dist/modules/translator/client/gemini.provider.d.ts +1 -0
  119. package/dist/modules/translator/client/gemini.provider.js +110 -0
  120. package/dist/modules/translator/client/groq.provider.d.ts +1 -0
  121. package/dist/modules/translator/client/groq.provider.js +111 -0
  122. package/dist/modules/translator/client/request.types.d.ts +1 -0
  123. package/dist/modules/translator/client/request.types.js +2 -0
  124. package/dist/modules/translator/client/retry.d.ts +29 -0
  125. package/dist/modules/translator/client/retry.js +94 -0
  126. package/dist/modules/translator/client/test-utils/mock.client.d.ts +31 -0
  127. package/dist/modules/translator/client/test-utils/mock.client.js +59 -0
  128. package/dist/modules/translator/client/translator.interface.d.ts +1 -0
  129. package/dist/modules/translator/client/translator.interface.js +2 -0
  130. package/dist/modules/translator/language-codes/errors.d.ts +10 -0
  131. package/dist/modules/translator/language-codes/errors.js +18 -0
  132. package/dist/modules/translator/language-codes/flores-map.d.ts +1 -0
  133. package/dist/modules/translator/language-codes/flores-map.js +107 -0
  134. package/dist/modules/translator/language-codes/index.d.ts +11 -0
  135. package/dist/modules/translator/language-codes/index.js +24 -0
  136. package/dist/modules/translator/language-codes/language-mapper.d.ts +25 -0
  137. package/dist/modules/translator/language-codes/language-mapper.js +132 -0
  138. package/dist/modules/translator/language-codes/rtl-languages.d.ts +2 -0
  139. package/dist/modules/translator/language-codes/rtl-languages.js +9 -0
  140. package/dist/modules/translator/memory/memory-matcher.d.ts +8 -0
  141. package/dist/modules/translator/memory/memory-matcher.js +218 -0
  142. package/dist/modules/translator/memory/types.d.ts +22 -0
  143. package/dist/modules/translator/memory/types.js +2 -0
  144. package/dist/modules/translator/translate.d.ts +38 -0
  145. package/dist/modules/translator/translate.js +932 -0
  146. package/dist/modules/translator/translator.d.ts +5 -0
  147. package/dist/modules/translator/translator.js +46 -0
  148. package/dist/modules/vue/migrate.d.ts +13 -0
  149. package/dist/modules/vue/migrate.js +40 -0
  150. package/dist/modules/vue/script-inject.d.ts +16 -0
  151. package/dist/modules/vue/script-inject.js +115 -0
  152. package/dist/modules/vue/sfc.d.ts +11 -0
  153. package/dist/modules/vue/sfc.js +51 -0
  154. package/dist/modules/vue/template-rewrite.d.ts +25 -0
  155. package/dist/modules/vue/template-rewrite.js +76 -0
  156. package/dist/modules/vue/template-scan.d.ts +29 -0
  157. package/dist/modules/vue/template-scan.js +264 -0
  158. package/dist/modules/workspace/index.d.ts +1 -0
  159. package/dist/modules/workspace/index.js +5 -0
  160. package/dist/modules/workspace/validate.d.ts +13 -0
  161. package/dist/modules/workspace/validate.js +298 -0
  162. package/dist/orchestrator.d.ts +8 -0
  163. package/dist/orchestrator.js +616 -0
  164. package/dist/providers/default-translation-provider.d.ts +20 -0
  165. package/dist/providers/default-translation-provider.js +30 -0
  166. package/dist/providers/index.d.ts +2 -0
  167. package/dist/providers/index.js +21 -0
  168. package/dist/providers/types.d.ts +145 -0
  169. package/dist/providers/types.js +2 -0
  170. package/dist/qa/check-project.d.ts +49 -0
  171. package/dist/qa/check-project.js +150 -0
  172. package/dist/qa/locale-files.d.ts +44 -0
  173. package/dist/qa/locale-files.js +159 -0
  174. package/dist/qa/locale-qa.d.ts +61 -0
  175. package/dist/qa/locale-qa.js +325 -0
  176. package/dist/qa/review.d.ts +43 -0
  177. package/dist/qa/review.js +175 -0
  178. package/dist/runtime/config.d.ts +8 -0
  179. package/dist/runtime/config.js +36 -0
  180. package/dist/runtime/index.d.ts +3 -0
  181. package/dist/runtime/index.js +8 -0
  182. package/dist/runtime/types.d.ts +363 -0
  183. package/dist/runtime/types.js +38 -0
  184. package/dist/types.d.ts +134 -0
  185. package/dist/types.js +12 -0
  186. package/dist/utils/ast-helpers.d.ts +57 -0
  187. package/dist/utils/ast-helpers.js +608 -0
  188. package/dist/utils/cache-keys.d.ts +8 -0
  189. package/dist/utils/cache-keys.js +18 -0
  190. package/dist/utils/circuit-breaker.d.ts +43 -0
  191. package/dist/utils/circuit-breaker.js +119 -0
  192. package/dist/utils/concurrent-map.d.ts +4 -0
  193. package/dist/utils/concurrent-map.js +21 -0
  194. package/dist/utils/detect-format.d.ts +5 -0
  195. package/dist/utils/detect-format.js +125 -0
  196. package/dist/utils/dtl-mask.d.ts +25 -0
  197. package/dist/utils/dtl-mask.js +58 -0
  198. package/dist/utils/extraction-options.d.ts +23 -0
  199. package/dist/utils/extraction-options.js +23 -0
  200. package/dist/utils/file-utils.d.ts +33 -0
  201. package/dist/utils/file-utils.js +262 -0
  202. package/dist/utils/glossary-match.d.ts +9 -0
  203. package/dist/utils/glossary-match.js +25 -0
  204. package/dist/utils/html-extractor.d.ts +8 -0
  205. package/dist/utils/html-extractor.js +317 -0
  206. package/dist/utils/i18next-icu.d.ts +38 -0
  207. package/dist/utils/i18next-icu.js +159 -0
  208. package/dist/utils/icu-message.d.ts +65 -0
  209. package/dist/utils/icu-message.js +346 -0
  210. package/dist/utils/icu-spans.d.ts +10 -0
  211. package/dist/utils/icu-spans.js +126 -0
  212. package/dist/utils/jsx-message.d.ts +93 -0
  213. package/dist/utils/jsx-message.js +621 -0
  214. package/dist/utils/key-usage.d.ts +35 -0
  215. package/dist/utils/key-usage.js +247 -0
  216. package/dist/utils/logger.d.ts +24 -0
  217. package/dist/utils/logger.js +33 -0
  218. package/dist/utils/metadata.d.ts +80 -0
  219. package/dist/utils/metadata.js +255 -0
  220. package/dist/utils/module-constants.d.ts +30 -0
  221. package/dist/utils/module-constants.js +265 -0
  222. package/dist/utils/not-injected.d.ts +6 -0
  223. package/dist/utils/not-injected.js +36 -0
  224. package/dist/utils/placeholder-protection.d.ts +57 -0
  225. package/dist/utils/placeholder-protection.js +136 -0
  226. package/dist/utils/pseudo-markers.d.ts +9 -0
  227. package/dist/utils/pseudo-markers.js +16 -0
  228. package/dist/utils/py-extractor.d.ts +14 -0
  229. package/dist/utils/py-extractor.js +285 -0
  230. package/dist/utils/string-utils.d.ts +52 -0
  231. package/dist/utils/string-utils.js +270 -0
  232. package/dist/utils/translation-quality.d.ts +34 -0
  233. package/dist/utils/translation-quality.js +156 -0
  234. package/dist/utils/translation-sanitizer.d.ts +10 -0
  235. package/dist/utils/translation-sanitizer.js +57 -0
  236. package/dist/utils/translator-caller.d.ts +32 -0
  237. package/dist/utils/translator-caller.js +217 -0
  238. package/dist/utils/translator-load-balancer.d.ts +73 -0
  239. package/dist/utils/translator-load-balancer.js +293 -0
  240. package/dist/utils/ui-copy.d.ts +32 -0
  241. package/dist/utils/ui-copy.js +126 -0
  242. package/dist/utils/workspace.d.ts +14 -0
  243. package/dist/utils/workspace.js +89 -0
  244. package/package.json +64 -4
  245. package/schemas/translate-report.schema.json +297 -0
  246. package/README.md +0 -3
@@ -0,0 +1,264 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scanTemplate = scanTemplate;
4
+ const compiler_dom_1 = require("@vue/compiler-dom");
5
+ const TRANSLATABLE_ATTRS = new Set([
6
+ 'alt',
7
+ 'title',
8
+ 'placeholder',
9
+ 'aria-label',
10
+ 'aria-description',
11
+ 'label',
12
+ 'text',
13
+ ]);
14
+ const ATTR_DENY_LIST = new Set([
15
+ 'class',
16
+ 'style',
17
+ 'id',
18
+ 'key',
19
+ 'ref',
20
+ 'src',
21
+ 'href',
22
+ 'to',
23
+ 'target',
24
+ 'rel',
25
+ 'type',
26
+ 'width',
27
+ 'height',
28
+ 'rows',
29
+ 'cols',
30
+ 'data-testid',
31
+ 'role',
32
+ 'as',
33
+ 'name',
34
+ 'value',
35
+ 'disabled',
36
+ 'required',
37
+ 'checked',
38
+ 'multiple',
39
+ 'hidden',
40
+ 'tabindex',
41
+ 'autofocus',
42
+ 'accesskey',
43
+ 'contenteditable',
44
+ 'draggable',
45
+ 'translate',
46
+ 'dir',
47
+ 'lang',
48
+ 'slot',
49
+ 'is',
50
+ ]);
51
+ function hasVPre(node) {
52
+ return node.props.some((p) => p.type === compiler_dom_1.NodeTypes.ATTRIBUTE && p.name === 'v-pre');
53
+ }
54
+ function hasVHtml(node) {
55
+ return node.props.some((p) => p.type === compiler_dom_1.NodeTypes.DIRECTIVE && p.name === 'html');
56
+ }
57
+ function isInsideI18nT(node, ancestors) {
58
+ return ancestors.some((a) => a.tag === 'i18n-t' && a.tagType === compiler_dom_1.ElementTypes.ELEMENT);
59
+ }
60
+ function hasDollarTBinding(node) {
61
+ return node.props.some((p) => p.type === compiler_dom_1.NodeTypes.ATTRIBUTE &&
62
+ p.value?.content.includes('$t('));
63
+ }
64
+ function locToOffset(loc, templateOffset) {
65
+ return templateOffset + loc.start.offset;
66
+ }
67
+ function locToLine(loc) {
68
+ return loc.start.line;
69
+ }
70
+ function isTranslatableAttr(name) {
71
+ if (ATTR_DENY_LIST.has(name))
72
+ return false;
73
+ if (TRANSLATABLE_ATTRS.has(name))
74
+ return true;
75
+ if (/^(aria-|data-)/.test(name))
76
+ return false;
77
+ return true;
78
+ }
79
+ function extractBoundLiteralString(dir) {
80
+ const exp = dir.exp;
81
+ if (!exp)
82
+ return null;
83
+ if (exp.type !== compiler_dom_1.NodeTypes.SIMPLE_EXPRESSION)
84
+ return null;
85
+ const raw = exp.content.trim();
86
+ // Matches: 'string' or "string"
87
+ const match = raw.match(/^['"](.*)['"]$/);
88
+ if (match)
89
+ return match[1];
90
+ return null;
91
+ }
92
+ function extractTextContent(node) {
93
+ if (node.type === compiler_dom_1.NodeTypes.TEXT) {
94
+ return node.content;
95
+ }
96
+ return null;
97
+ }
98
+ function isStaticAttribute(prop) {
99
+ return prop.type === compiler_dom_1.NodeTypes.ATTRIBUTE;
100
+ }
101
+ function processElement(node, templateContent, templateOffset, filePath, hashFn, ancestors, skippedElements) {
102
+ const units = [];
103
+ if (hasVPre(node)) {
104
+ skippedElements.push(`${node.tag}:v-pre`);
105
+ return units;
106
+ }
107
+ if (hasVHtml(node)) {
108
+ skippedElements.push(`${node.tag}:v-html`);
109
+ return units;
110
+ }
111
+ if (isInsideI18nT(node, ancestors)) {
112
+ skippedElements.push(`${node.tag}:inside-i18n-t`);
113
+ return units;
114
+ }
115
+ if (hasDollarTBinding(node)) {
116
+ skippedElements.push(`${node.tag}:already-translated`);
117
+ return units;
118
+ }
119
+ // Process text children — merge adjacent text nodes and interpolations
120
+ const textRuns = buildTextRuns(node);
121
+ for (const run of textRuns) {
122
+ const runText = run.map((n) => extractTextContent(n)).join('');
123
+ if (!runText.trim())
124
+ continue;
125
+ const firstNode = run[0];
126
+ const lastNode = run[run.length - 1];
127
+ const offset = locToOffset(firstNode.loc, templateOffset);
128
+ const length = locToOffset(lastNode.loc, templateOffset) +
129
+ lastNode.loc.source.length -
130
+ offset;
131
+ const line = locToLine(firstNode.loc);
132
+ const id = `${filePath}:${line}:${hashFn(runText)}`;
133
+ units.push({
134
+ type: 'text',
135
+ text: runText,
136
+ line,
137
+ offset,
138
+ end: offset + length,
139
+ length,
140
+ id,
141
+ confidence: 1.0,
142
+ });
143
+ }
144
+ // Process attributes
145
+ for (const prop of node.props) {
146
+ if (isStaticAttribute(prop)) {
147
+ const name = prop.name.toLowerCase();
148
+ if (!isTranslatableAttr(name))
149
+ continue;
150
+ if (!prop.value)
151
+ continue;
152
+ const text = prop.value.content;
153
+ if (!text.trim())
154
+ continue;
155
+ const offset = locToOffset(prop.value.loc, templateOffset);
156
+ const length = prop.value.loc.source.length;
157
+ const line = locToLine(prop.value.loc);
158
+ const id = `${filePath}:${line}:${hashFn(text)}`;
159
+ units.push({
160
+ type: 'attr',
161
+ text,
162
+ line,
163
+ offset,
164
+ end: offset + length,
165
+ length,
166
+ id,
167
+ confidence: 1.0,
168
+ attrName: prop.name,
169
+ tagName: node.tag,
170
+ attrBoundLiteral: false,
171
+ });
172
+ }
173
+ else if (prop.type === compiler_dom_1.NodeTypes.DIRECTIVE &&
174
+ prop.name === 'bind' &&
175
+ prop.arg &&
176
+ prop.arg.type === compiler_dom_1.NodeTypes.SIMPLE_EXPRESSION &&
177
+ prop.arg.isStatic &&
178
+ !prop.modifiers.length) {
179
+ const attrName = prop.arg.content;
180
+ if (!isTranslatableAttr(attrName))
181
+ continue;
182
+ const literal = extractBoundLiteralString(prop);
183
+ if (literal === null)
184
+ continue;
185
+ const offset = locToOffset(prop.loc, templateOffset);
186
+ const length = prop.loc.source.length;
187
+ const line = locToLine(prop.loc);
188
+ const id = `${filePath}:${line}:${hashFn(literal)}`;
189
+ units.push({
190
+ type: 'attr',
191
+ text: literal,
192
+ line,
193
+ offset,
194
+ end: offset + length,
195
+ length,
196
+ id,
197
+ confidence: 1.0,
198
+ attrName,
199
+ tagName: node.tag,
200
+ attrBoundLiteral: true,
201
+ });
202
+ }
203
+ else if (prop.type === compiler_dom_1.NodeTypes.DIRECTIVE &&
204
+ prop.name === 'text') {
205
+ // v-text is dynamic — skip
206
+ skippedElements.push(`${node.tag}:v-text`);
207
+ }
208
+ }
209
+ return units;
210
+ }
211
+ function buildTextRuns(node) {
212
+ const runs = [];
213
+ let currentRun = [];
214
+ for (const child of node.children) {
215
+ if (child.type === compiler_dom_1.NodeTypes.TEXT ||
216
+ child.type === compiler_dom_1.NodeTypes.INTERPOLATION ||
217
+ child.type === compiler_dom_1.NodeTypes.COMPOUND_EXPRESSION) {
218
+ currentRun.push(child);
219
+ }
220
+ else {
221
+ if (currentRun.length > 0) {
222
+ runs.push(currentRun);
223
+ currentRun = [];
224
+ }
225
+ }
226
+ }
227
+ if (currentRun.length > 0) {
228
+ runs.push(currentRun);
229
+ }
230
+ return runs;
231
+ }
232
+ function walkNode(node, templateContent, templateOffset, filePath, hashFn, units, skippedElements, ancestors) {
233
+ if (node.type === compiler_dom_1.NodeTypes.ELEMENT) {
234
+ const element = node;
235
+ ancestors.push(element);
236
+ const elementUnits = processElement(element, templateContent, templateOffset, filePath, hashFn, ancestors, skippedElements);
237
+ units.push(...elementUnits);
238
+ for (const child of element.children) {
239
+ walkNode(child, templateContent, templateOffset, filePath, hashFn, units, skippedElements, ancestors);
240
+ }
241
+ ancestors.pop();
242
+ }
243
+ else if (node.type === compiler_dom_1.NodeTypes.IF) {
244
+ for (const branch of node.branches) {
245
+ for (const child of branch.children) {
246
+ walkNode(child, templateContent, templateOffset, filePath, hashFn, units, skippedElements, ancestors);
247
+ }
248
+ }
249
+ }
250
+ else if (node.type === compiler_dom_1.NodeTypes.FOR) {
251
+ for (const child of node.children) {
252
+ walkNode(child, templateContent, templateOffset, filePath, hashFn, units, skippedElements, ancestors);
253
+ }
254
+ }
255
+ }
256
+ function scanTemplate(templateContent, filePath, templateOffset, hashFn) {
257
+ const units = [];
258
+ const skippedElements = [];
259
+ const root = (0, compiler_dom_1.parse)(templateContent);
260
+ for (const child of root.children) {
261
+ walkNode(child, templateContent, templateOffset, filePath, hashFn, units, skippedElements, []);
262
+ }
263
+ return { units, skippedElements };
264
+ }
@@ -0,0 +1 @@
1
+ export { validateWorkspace } from './validate';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateWorkspace = void 0;
4
+ var validate_1 = require("./validate");
5
+ Object.defineProperty(exports, "validateWorkspace", { enumerable: true, get: function () { return validate_1.validateWorkspace; } });
@@ -0,0 +1,13 @@
1
+ import type { EngineConfigV2, Phase0Result } from '../../runtime/types';
2
+ interface PackageJson {
3
+ dependencies?: Record<string, string>;
4
+ devDependencies?: Record<string, string>;
5
+ [key: string]: unknown;
6
+ }
7
+ export declare function validateWorkspace(config: EngineConfigV2): Promise<Phase0Result>;
8
+ export declare function checkI18nDependencies(packageJson: PackageJson, framework?: string): Promise<{
9
+ hasReactI18next: boolean;
10
+ hasI18next: boolean;
11
+ recommendation: string | null;
12
+ }>;
13
+ export {};
@@ -0,0 +1,298 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.validateWorkspace = validateWorkspace;
40
+ exports.checkI18nDependencies = checkI18nDependencies;
41
+ const path = __importStar(require("path"));
42
+ const fast_glob_1 = __importDefault(require("fast-glob"));
43
+ const types_1 = require("@babelize/types");
44
+ const logger_1 = require("../../utils/logger");
45
+ const file_utils_1 = require("../../utils/file-utils");
46
+ // Python/Django detection — runs BEFORE the static fallback
47
+ async function detectPythonFramework(workspacePath) {
48
+ // Check for manage.py (Django)
49
+ if (await (0, file_utils_1.pathExists)(path.join(workspacePath, 'manage.py'))) {
50
+ return 'django';
51
+ }
52
+ // Check for Django in requirements/pyproject
53
+ const configFiles = ['pyproject.toml', 'requirements.txt', 'Pipfile'];
54
+ for (const file of configFiles) {
55
+ const content = await (0, file_utils_1.readFile)(path.join(workspacePath, file)).catch(() => '');
56
+ if (content && /django/i.test(content)) {
57
+ return 'django';
58
+ }
59
+ }
60
+ // Check for settings.py
61
+ const settingsFiles = await (0, fast_glob_1.default)('**/settings.py', { cwd: workspacePath, onlyFiles: true, deep: 4 });
62
+ if (settingsFiles.length > 0) {
63
+ return 'django';
64
+ }
65
+ return null;
66
+ }
67
+ async function validateWorkspace(config) {
68
+ const { workspacePath } = config;
69
+ if (!(await (0, file_utils_1.pathExists)(workspacePath))) {
70
+ throw new Error(`Workspace path does not exist: ${workspacePath}`);
71
+ }
72
+ if (!(await (0, file_utils_1.isDirectory)(workspacePath))) {
73
+ throw new Error(`Workspace path is not a directory: ${workspacePath}`);
74
+ }
75
+ const packageJsonPath = path.join(workspacePath, 'package.json');
76
+ let packageJson = await (0, file_utils_1.readJsonFile)(packageJsonPath);
77
+ let framework = 'unknown';
78
+ let isStatic = false;
79
+ if (config.framework && types_1.SUPPORTED_FRAMEWORKS.includes(config.framework)) {
80
+ framework = config.framework;
81
+ logger_1.engineLogger.info('Using explicit framework override', { framework });
82
+ }
83
+ if (!framework || framework === 'unknown') {
84
+ const pythonFramework = await detectPythonFramework(workspacePath);
85
+ if (pythonFramework) {
86
+ framework = pythonFramework;
87
+ logger_1.engineLogger.info('Detected Python framework', { framework });
88
+ }
89
+ }
90
+ if (!packageJson) {
91
+ const htmlFiles = await (0, fast_glob_1.default)('**/*.html', { cwd: workspacePath, onlyFiles: true, deep: 6 });
92
+ if (htmlFiles.length > 0) {
93
+ // Check for server-template markers
94
+ let hasServerTemplates = false;
95
+ for (const file of htmlFiles.slice(0, 10)) {
96
+ const content = await (0, file_utils_1.readFile)(path.join(workspacePath, file)).catch(() => '');
97
+ if (/\{%|<\?php|<%=/.test(content)) {
98
+ hasServerTemplates = true;
99
+ logger_1.engineLogger.warn('Found server-template markers, refusing static classification', { file });
100
+ break;
101
+ }
102
+ }
103
+ if (!hasServerTemplates && framework === 'unknown') {
104
+ framework = 'static';
105
+ packageJson = {};
106
+ isStatic = true;
107
+ logger_1.engineLogger.info('Detected static HTML/CSS/JS project');
108
+ }
109
+ }
110
+ else if (framework === 'unknown') {
111
+ throw new Error('Babelize currently supports only React, Next.js, Vue, and plain HTML/CSS/JS projects. ' +
112
+ 'No package.json or HTML files found.');
113
+ }
114
+ }
115
+ else if (framework === 'unknown') {
116
+ framework = detectFramework(packageJson);
117
+ }
118
+ if (framework === 'unknown' && !isStatic) {
119
+ const workspacePatterns = getWorkspacePatterns(packageJson);
120
+ if (workspacePatterns.length > 0) {
121
+ const matchedDirs = await (0, fast_glob_1.default)(workspacePatterns, { cwd: workspacePath, onlyDirectories: true, deep: 3, absolute: true });
122
+ for (const dir of matchedDirs) {
123
+ const subPkgPath = path.join(dir, 'package.json');
124
+ const subPkg = await (0, file_utils_1.readJsonFile)(subPkgPath);
125
+ if (subPkg) {
126
+ const subFramework = detectFramework(subPkg);
127
+ if (subFramework !== 'unknown') {
128
+ framework = subFramework;
129
+ packageJson = subPkg;
130
+ logger_1.engineLogger.info('Framework detected in workspace', { workspaceDir: path.relative(workspacePath, dir), framework });
131
+ break;
132
+ }
133
+ }
134
+ }
135
+ }
136
+ if (framework === 'unknown' && !isStatic) {
137
+ const entries = await (0, file_utils_1.readDir)(workspacePath);
138
+ for (const entry of entries) {
139
+ if (entry.startsWith('.'))
140
+ continue;
141
+ const subDirPath = path.join(workspacePath, entry);
142
+ if (await (0, file_utils_1.isDirectory)(subDirPath)) {
143
+ const subPkgPath = path.join(subDirPath, 'package.json');
144
+ const subPkg = await (0, file_utils_1.readJsonFile)(subPkgPath);
145
+ if (subPkg) {
146
+ const subFramework = detectFramework(subPkg);
147
+ if (subFramework !== 'unknown') {
148
+ framework = subFramework;
149
+ packageJson = subPkg;
150
+ logger_1.engineLogger.info('Framework detected in subdirectory', { subDir: entry, framework });
151
+ break;
152
+ }
153
+ }
154
+ }
155
+ }
156
+ }
157
+ }
158
+ if (!types_1.SUPPORTED_FRAMEWORKS.includes(framework)) {
159
+ throw new Error('Babelize currently supports only React, Next.js, Vue, and plain HTML/CSS/JS projects. ' +
160
+ 'Other frameworks are not supported yet.');
161
+ }
162
+ const sourceDirs = await findSourceDirectories(workspacePath);
163
+ if (sourceDirs.length === 0) {
164
+ logger_1.engineLogger.info('No standard source directories found, defaulting to root');
165
+ sourceDirs.push('.');
166
+ }
167
+ const frameworkConfig = types_1.FRAMEWORK_CONFIGS[framework] || types_1.FRAMEWORK_CONFIGS['unknown'];
168
+ const localeFormat = frameworkConfig.localeFormat;
169
+ const existingLocales = [];
170
+ let hasLocalesDir = false;
171
+ if (localeFormat === 'po') {
172
+ // Django: check locale/<lang>/LC_MESSAGES/django.po structure
173
+ const djangoLocaleDir = path.join(workspacePath, 'locale');
174
+ hasLocalesDir = await (0, file_utils_1.isDirectory)(djangoLocaleDir);
175
+ if (hasLocalesDir) {
176
+ const langDirs = await (0, file_utils_1.readDir)(djangoLocaleDir);
177
+ for (const langDir of langDirs) {
178
+ const poFile = path.join(djangoLocaleDir, langDir, 'LC_MESSAGES', 'django.po');
179
+ if (await (0, file_utils_1.pathExists)(poFile)) {
180
+ existingLocales.push(langDir);
181
+ }
182
+ }
183
+ }
184
+ }
185
+ else {
186
+ const localesDir = path.join(workspacePath, 'locales');
187
+ hasLocalesDir = await (0, file_utils_1.isDirectory)(localesDir);
188
+ const localeExt = (0, file_utils_1.localeExtension)(localeFormat);
189
+ if (hasLocalesDir) {
190
+ const localeFiles = await (0, file_utils_1.readDir)(localesDir);
191
+ for (const file of localeFiles) {
192
+ if (file.endsWith(localeExt))
193
+ existingLocales.push(file.replace(localeExt, ''));
194
+ }
195
+ }
196
+ }
197
+ let publicDir = 'public';
198
+ if (sourceDirs.length > 0 && sourceDirs[0] !== '.') {
199
+ const firstSourceDir = sourceDirs[0];
200
+ const parts = firstSourceDir.split(/[\\/]/);
201
+ if (parts.length > 1) {
202
+ parts.pop();
203
+ publicDir = path.join(...parts, 'public');
204
+ }
205
+ }
206
+ if (framework === 'static') {
207
+ sourceDirs.length = 0;
208
+ sourceDirs.push('.');
209
+ publicDir = '.';
210
+ }
211
+ const babelizeDir = path.join(workspacePath, '.babelize');
212
+ await (0, file_utils_1.ensureDir)(babelizeDir);
213
+ const workspace = {
214
+ path: workspacePath,
215
+ framework,
216
+ localeFormat,
217
+ sourceDirs,
218
+ hasLocalesDir,
219
+ existingLocales,
220
+ publicDir,
221
+ packageJson: packageJson,
222
+ formatConfig: config.formatConfig,
223
+ };
224
+ return { workspace };
225
+ }
226
+ function getWorkspacePatterns(packageJson) {
227
+ const ws = packageJson?.workspaces;
228
+ if (Array.isArray(ws))
229
+ return ws;
230
+ if (ws && typeof ws === 'object' && Array.isArray(ws.packages))
231
+ return ws.packages;
232
+ return [];
233
+ }
234
+ function detectFramework(packageJson) {
235
+ const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
236
+ if (deps['next'])
237
+ return 'nextjs';
238
+ if (deps['nuxt'])
239
+ return 'vue';
240
+ if (deps['vue'])
241
+ return 'vue';
242
+ const reactBasedFrameworks = ['gatsby', '@remix-run/react', 'astro'];
243
+ for (const dep of reactBasedFrameworks) {
244
+ if (deps[dep])
245
+ return 'react';
246
+ }
247
+ if (deps['react'])
248
+ return 'react';
249
+ const reactIndicators = [
250
+ 'react-dom',
251
+ 'react-icons',
252
+ 'react-router-dom',
253
+ 'react-router',
254
+ 'react-scripts',
255
+ '@vitejs/plugin-react',
256
+ 'react-modal',
257
+ 'react-toastify',
258
+ 'react-i18next',
259
+ ];
260
+ if (reactIndicators.some((pkg) => deps[pkg]))
261
+ return 'react';
262
+ return 'unknown';
263
+ }
264
+ async function findSourceDirectories(workspacePath) {
265
+ const possibleDirs = ['src', 'app', 'pages', 'components', 'features', 'modules', 'lib'];
266
+ const foundDirs = [];
267
+ for (const dir of possibleDirs) {
268
+ const fullPath = path.join(workspacePath, dir);
269
+ if (await (0, file_utils_1.isDirectory)(fullPath))
270
+ foundDirs.push(dir);
271
+ }
272
+ return foundDirs;
273
+ }
274
+ async function checkI18nDependencies(packageJson, framework) {
275
+ const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
276
+ const hasReactI18next = !!deps['react-i18next'];
277
+ const hasI18next = !!deps['i18next'];
278
+ let recommendation = null;
279
+ if (framework === 'static') {
280
+ recommendation = null; // Static HTML projects do not require npm packages
281
+ }
282
+ else if (framework === 'nextjs') {
283
+ if (!deps['next-intl'])
284
+ recommendation = 'Run: bun install next-intl';
285
+ }
286
+ else if (framework === 'vue') {
287
+ if (!deps['vue-i18n'])
288
+ recommendation = 'Run: bun install vue-i18n';
289
+ }
290
+ else {
291
+ // React / vanilla / unknown
292
+ if (!hasI18next)
293
+ recommendation = 'Run: bun install i18next react-i18next';
294
+ else if (!hasReactI18next)
295
+ recommendation = 'Run: bun install react-i18next';
296
+ }
297
+ return { hasReactI18next, hasI18next, recommendation };
298
+ }
@@ -0,0 +1,8 @@
1
+ import type { EngineConfigV2, EngineResultV2 } from './runtime/types';
2
+ /**
3
+ * Engine v2 Orchestrator (backend runtime)
4
+ *
5
+ * This is the single, clean wiring layer for the pipeline.
6
+ * Workers/controllers call `runEngineV2()`.
7
+ */
8
+ export declare function runEngineV2(config: EngineConfigV2): Promise<EngineResultV2>;