@babelize/engine 0.0.0-stage → 0.1.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 (270) 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/detection/stack.d.ts +42 -0
  11. package/dist/detection/stack.js +277 -0
  12. package/dist/django/catalog.d.ts +92 -0
  13. package/dist/django/catalog.js +677 -0
  14. package/dist/django/extract.d.ts +20 -0
  15. package/dist/django/extract.js +79 -0
  16. package/dist/django/inject-file.d.ts +6 -0
  17. package/dist/django/inject-file.js +52 -0
  18. package/dist/django/inject.d.ts +11 -0
  19. package/dist/django/inject.js +205 -0
  20. package/dist/django/keys.d.ts +21 -0
  21. package/dist/django/keys.js +63 -0
  22. package/dist/django/locale-names.d.ts +13 -0
  23. package/dist/django/locale-names.js +60 -0
  24. package/dist/django/mo-file.d.ts +6 -0
  25. package/dist/django/mo-file.js +60 -0
  26. package/dist/django/plural-forms.d.ts +34 -0
  27. package/dist/django/plural-forms.js +216 -0
  28. package/dist/django/po-file.d.ts +38 -0
  29. package/dist/django/po-file.js +273 -0
  30. package/dist/django/python-extract.d.ts +34 -0
  31. package/dist/django/python-extract.js +619 -0
  32. package/dist/django/python-lexer.d.ts +65 -0
  33. package/dist/django/python-lexer.js +398 -0
  34. package/dist/django/template-extract.d.ts +32 -0
  35. package/dist/django/template-extract.js +680 -0
  36. package/dist/django/types.d.ts +49 -0
  37. package/dist/django/types.js +15 -0
  38. package/dist/index.d.ts +59 -0
  39. package/dist/index.js +140 -0
  40. package/dist/injection/InjectionStrategy.d.ts +62 -0
  41. package/dist/injection/InjectionStrategy.js +2 -0
  42. package/dist/injection/StrategyFactory.d.ts +4 -0
  43. package/dist/injection/StrategyFactory.js +29 -0
  44. package/dist/injection/html/html-injector.d.ts +11 -0
  45. package/dist/injection/html/html-injector.js +173 -0
  46. package/dist/injection/strategies/NextIntlStrategy.d.ts +25 -0
  47. package/dist/injection/strategies/NextIntlStrategy.js +141 -0
  48. package/dist/injection/strategies/ReactI18nextStrategy.d.ts +19 -0
  49. package/dist/injection/strategies/ReactI18nextStrategy.js +116 -0
  50. package/dist/injection/strategies/VanillaStrategy.d.ts +11 -0
  51. package/dist/injection/strategies/VanillaStrategy.js +73 -0
  52. package/dist/injection/strategies/VueI18nStrategy.d.ts +11 -0
  53. package/dist/injection/strategies/VueI18nStrategy.js +84 -0
  54. package/dist/local/formatter.d.ts +26 -0
  55. package/dist/local/formatter.js +105 -0
  56. package/dist/local/git.d.ts +23 -0
  57. package/dist/local/git.js +136 -0
  58. package/dist/local/hosted-provider.d.ts +68 -0
  59. package/dist/local/hosted-provider.js +215 -0
  60. package/dist/local/index.d.ts +23 -0
  61. package/dist/local/index.js +75 -0
  62. package/dist/local/provider.d.ts +56 -0
  63. package/dist/local/provider.js +119 -0
  64. package/dist/local/pseudo-provider.d.ts +18 -0
  65. package/dist/local/pseudo-provider.js +208 -0
  66. package/dist/local/report.d.ts +177 -0
  67. package/dist/local/report.js +186 -0
  68. package/dist/local/translate-core.d.ts +218 -0
  69. package/dist/local/translate-core.js +499 -0
  70. package/dist/local/translate-messages.d.ts +49 -0
  71. package/dist/local/translate-messages.js +89 -0
  72. package/dist/local/workspace-copy.d.ts +91 -0
  73. package/dist/local/workspace-copy.js +355 -0
  74. package/dist/modules/extractor/extract.d.ts +20 -0
  75. package/dist/modules/extractor/extract.js +709 -0
  76. package/dist/modules/extractor/index.d.ts +2 -0
  77. package/dist/modules/extractor/index.js +63 -0
  78. package/dist/modules/finalization/django-finalize.d.ts +28 -0
  79. package/dist/modules/finalization/django-finalize.js +412 -0
  80. package/dist/modules/finalization/finalize.d.ts +38 -0
  81. package/dist/modules/finalization/finalize.js +745 -0
  82. package/dist/modules/finalization/index.d.ts +1 -0
  83. package/dist/modules/finalization/index.js +5 -0
  84. package/dist/modules/finalization/nextjs-finalize.d.ts +40 -0
  85. package/dist/modules/finalization/nextjs-finalize.js +328 -0
  86. package/dist/modules/finalization/static-runtime.d.ts +9 -0
  87. package/dist/modules/finalization/static-runtime.js +261 -0
  88. package/dist/modules/finalization/writes.d.ts +29 -0
  89. package/dist/modules/finalization/writes.js +78 -0
  90. package/dist/modules/format-injection/index.d.ts +19 -0
  91. package/dist/modules/format-injection/index.js +273 -0
  92. package/dist/modules/format-injection/inject-formats.d.ts +31 -0
  93. package/dist/modules/format-injection/inject-formats.js +208 -0
  94. package/dist/modules/glossary/index.d.ts +2 -0
  95. package/dist/modules/glossary/index.js +16 -0
  96. package/dist/modules/glossary/rules.d.ts +81 -0
  97. package/dist/modules/glossary/rules.js +244 -0
  98. package/dist/modules/glossary/types.d.ts +22 -0
  99. package/dist/modules/glossary/types.js +2 -0
  100. package/dist/modules/injection/index.d.ts +1 -0
  101. package/dist/modules/injection/index.js +6 -0
  102. package/dist/modules/injection/inject.d.ts +29 -0
  103. package/dist/modules/injection/inject.js +1050 -0
  104. package/dist/modules/keygen/index.d.ts +1 -0
  105. package/dist/modules/keygen/index.js +11 -0
  106. package/dist/modules/keygen/keygen.d.ts +4 -0
  107. package/dist/modules/keygen/keygen.js +123 -0
  108. package/dist/modules/keygen/locale-data.d.ts +7 -0
  109. package/dist/modules/keygen/locale-data.js +73 -0
  110. package/dist/modules/keygen/public.d.ts +2 -0
  111. package/dist/modules/keygen/public.js +12 -0
  112. package/dist/modules/locale-builder/index.d.ts +1 -0
  113. package/dist/modules/locale-builder/index.js +7 -0
  114. package/dist/modules/locale-builder/locales.d.ts +13 -0
  115. package/dist/modules/locale-builder/locales.js +130 -0
  116. package/dist/modules/lockfile/hasher.d.ts +7 -0
  117. package/dist/modules/lockfile/hasher.js +13 -0
  118. package/dist/modules/lockfile/index.d.ts +3 -0
  119. package/dist/modules/lockfile/index.js +22 -0
  120. package/dist/modules/lockfile/lockfile-manager.d.ts +99 -0
  121. package/dist/modules/lockfile/lockfile-manager.js +497 -0
  122. package/dist/modules/lockfile/schema.d.ts +196 -0
  123. package/dist/modules/lockfile/schema.js +56 -0
  124. package/dist/modules/parser/index.d.ts +2 -0
  125. package/dist/modules/parser/index.js +9 -0
  126. package/dist/modules/summary/index.d.ts +1 -0
  127. package/dist/modules/summary/index.js +7 -0
  128. package/dist/modules/summary/summary.d.ts +9 -0
  129. package/dist/modules/summary/summary.js +195 -0
  130. package/dist/modules/sync-detector/index.d.ts +2 -0
  131. package/dist/modules/sync-detector/index.js +7 -0
  132. package/dist/modules/sync-detector/reporter.d.ts +3 -0
  133. package/dist/modules/sync-detector/reporter.js +16 -0
  134. package/dist/modules/sync-detector/sync-detector.d.ts +39 -0
  135. package/dist/modules/sync-detector/sync-detector.js +374 -0
  136. package/dist/modules/translator/batch-optimizer.d.ts +12 -0
  137. package/dist/modules/translator/batch-optimizer.js +30 -0
  138. package/dist/modules/translator/client/byok.provider.d.ts +64 -0
  139. package/dist/modules/translator/client/byok.provider.js +319 -0
  140. package/dist/modules/translator/client/direct-translator.client.d.ts +12 -0
  141. package/dist/modules/translator/client/direct-translator.client.js +71 -0
  142. package/dist/modules/translator/client/gemini.provider.d.ts +1 -0
  143. package/dist/modules/translator/client/gemini.provider.js +110 -0
  144. package/dist/modules/translator/client/groq.provider.d.ts +1 -0
  145. package/dist/modules/translator/client/groq.provider.js +111 -0
  146. package/dist/modules/translator/client/request.types.d.ts +1 -0
  147. package/dist/modules/translator/client/request.types.js +2 -0
  148. package/dist/modules/translator/client/retry.d.ts +29 -0
  149. package/dist/modules/translator/client/retry.js +94 -0
  150. package/dist/modules/translator/client/test-utils/mock.client.d.ts +31 -0
  151. package/dist/modules/translator/client/test-utils/mock.client.js +59 -0
  152. package/dist/modules/translator/client/translator.interface.d.ts +1 -0
  153. package/dist/modules/translator/client/translator.interface.js +2 -0
  154. package/dist/modules/translator/icu-branches.d.ts +138 -0
  155. package/dist/modules/translator/icu-branches.js +393 -0
  156. package/dist/modules/translator/language-codes/errors.d.ts +10 -0
  157. package/dist/modules/translator/language-codes/errors.js +18 -0
  158. package/dist/modules/translator/language-codes/flores-map.d.ts +1 -0
  159. package/dist/modules/translator/language-codes/flores-map.js +107 -0
  160. package/dist/modules/translator/language-codes/index.d.ts +11 -0
  161. package/dist/modules/translator/language-codes/index.js +24 -0
  162. package/dist/modules/translator/language-codes/language-mapper.d.ts +25 -0
  163. package/dist/modules/translator/language-codes/language-mapper.js +132 -0
  164. package/dist/modules/translator/language-codes/rtl-languages.d.ts +2 -0
  165. package/dist/modules/translator/language-codes/rtl-languages.js +9 -0
  166. package/dist/modules/translator/memory/memory-matcher.d.ts +8 -0
  167. package/dist/modules/translator/memory/memory-matcher.js +218 -0
  168. package/dist/modules/translator/memory/types.d.ts +22 -0
  169. package/dist/modules/translator/memory/types.js +2 -0
  170. package/dist/modules/translator/translate.d.ts +74 -0
  171. package/dist/modules/translator/translate.js +1047 -0
  172. package/dist/modules/vue/migrate.d.ts +13 -0
  173. package/dist/modules/vue/migrate.js +40 -0
  174. package/dist/modules/vue/script-inject.d.ts +16 -0
  175. package/dist/modules/vue/script-inject.js +115 -0
  176. package/dist/modules/vue/sfc.d.ts +11 -0
  177. package/dist/modules/vue/sfc.js +51 -0
  178. package/dist/modules/vue/template-rewrite.d.ts +25 -0
  179. package/dist/modules/vue/template-rewrite.js +76 -0
  180. package/dist/modules/vue/template-scan.d.ts +29 -0
  181. package/dist/modules/vue/template-scan.js +264 -0
  182. package/dist/modules/workspace/index.d.ts +1 -0
  183. package/dist/modules/workspace/index.js +5 -0
  184. package/dist/modules/workspace/validate.d.ts +13 -0
  185. package/dist/modules/workspace/validate.js +333 -0
  186. package/dist/orchestrator.d.ts +13 -0
  187. package/dist/orchestrator.js +727 -0
  188. package/dist/providers/default-translation-provider.d.ts +20 -0
  189. package/dist/providers/default-translation-provider.js +30 -0
  190. package/dist/providers/index.d.ts +2 -0
  191. package/dist/providers/index.js +21 -0
  192. package/dist/providers/types.d.ts +153 -0
  193. package/dist/providers/types.js +2 -0
  194. package/dist/qa/check-project.d.ts +50 -0
  195. package/dist/qa/check-project.js +193 -0
  196. package/dist/qa/gettext-files.d.ts +15 -0
  197. package/dist/qa/gettext-files.js +115 -0
  198. package/dist/qa/locale-files.d.ts +44 -0
  199. package/dist/qa/locale-files.js +159 -0
  200. package/dist/qa/locale-qa.d.ts +61 -0
  201. package/dist/qa/locale-qa.js +342 -0
  202. package/dist/qa/review.d.ts +43 -0
  203. package/dist/qa/review.js +175 -0
  204. package/dist/runtime/config.d.ts +8 -0
  205. package/dist/runtime/config.js +37 -0
  206. package/dist/runtime/index.d.ts +3 -0
  207. package/dist/runtime/index.js +8 -0
  208. package/dist/runtime/types.d.ts +427 -0
  209. package/dist/runtime/types.js +38 -0
  210. package/dist/types.d.ts +134 -0
  211. package/dist/types.js +12 -0
  212. package/dist/utils/ast-helpers.d.ts +57 -0
  213. package/dist/utils/ast-helpers.js +608 -0
  214. package/dist/utils/cache-keys.d.ts +8 -0
  215. package/dist/utils/cache-keys.js +18 -0
  216. package/dist/utils/circuit-breaker.d.ts +43 -0
  217. package/dist/utils/circuit-breaker.js +119 -0
  218. package/dist/utils/concurrent-map.d.ts +4 -0
  219. package/dist/utils/concurrent-map.js +21 -0
  220. package/dist/utils/detect-format.d.ts +5 -0
  221. package/dist/utils/detect-format.js +125 -0
  222. package/dist/utils/extraction-options.d.ts +29 -0
  223. package/dist/utils/extraction-options.js +33 -0
  224. package/dist/utils/file-utils.d.ts +33 -0
  225. package/dist/utils/file-utils.js +267 -0
  226. package/dist/utils/glossary-match.d.ts +9 -0
  227. package/dist/utils/glossary-match.js +25 -0
  228. package/dist/utils/html-extractor.d.ts +8 -0
  229. package/dist/utils/html-extractor.js +317 -0
  230. package/dist/utils/i18next-icu.d.ts +38 -0
  231. package/dist/utils/i18next-icu.js +159 -0
  232. package/dist/utils/icu-message.d.ts +65 -0
  233. package/dist/utils/icu-message.js +346 -0
  234. package/dist/utils/icu-spans.d.ts +10 -0
  235. package/dist/utils/icu-spans.js +126 -0
  236. package/dist/utils/jsx-message.d.ts +93 -0
  237. package/dist/utils/jsx-message.js +628 -0
  238. package/dist/utils/key-usage.d.ts +35 -0
  239. package/dist/utils/key-usage.js +247 -0
  240. package/dist/utils/logger.d.ts +24 -0
  241. package/dist/utils/logger.js +33 -0
  242. package/dist/utils/metadata.d.ts +82 -0
  243. package/dist/utils/metadata.js +261 -0
  244. package/dist/utils/module-constants.d.ts +30 -0
  245. package/dist/utils/module-constants.js +265 -0
  246. package/dist/utils/not-injected.d.ts +6 -0
  247. package/dist/utils/not-injected.js +38 -0
  248. package/dist/utils/placeholder-protection.d.ts +74 -0
  249. package/dist/utils/placeholder-protection.js +181 -0
  250. package/dist/utils/pseudo-markers.d.ts +9 -0
  251. package/dist/utils/pseudo-markers.js +16 -0
  252. package/dist/utils/string-utils.d.ts +52 -0
  253. package/dist/utils/string-utils.js +270 -0
  254. package/dist/utils/translation-quality.d.ts +34 -0
  255. package/dist/utils/translation-quality.js +156 -0
  256. package/dist/utils/translation-sanitizer.d.ts +11 -0
  257. package/dist/utils/translation-sanitizer.js +71 -0
  258. package/dist/utils/translator-caller.d.ts +32 -0
  259. package/dist/utils/translator-caller.js +217 -0
  260. package/dist/utils/translator-load-balancer.d.ts +73 -0
  261. package/dist/utils/translator-load-balancer.js +297 -0
  262. package/dist/utils/ui-copy.d.ts +32 -0
  263. package/dist/utils/ui-copy.js +126 -0
  264. package/dist/utils/untranslated.d.ts +15 -0
  265. package/dist/utils/untranslated.js +34 -0
  266. package/dist/utils/workspace.d.ts +14 -0
  267. package/dist/utils/workspace.js +89 -0
  268. package/package.json +64 -4
  269. package/schemas/translate-report.schema.json +297 -0
  270. package/README.md +0 -3
@@ -0,0 +1,333 @@
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
+ const stack_1 = require("../../detection/stack");
47
+ const django_finalize_1 = require("../finalization/django-finalize");
48
+ const locale_names_1 = require("../../django/locale-names");
49
+ const PY_IGNORE = ['**/node_modules/**', '**/.venv/**', '**/venv/**', '**/site-packages/**', '**/.git/**'];
50
+ /**
51
+ * The Django project root (directory of the shallowest manage.py), relative
52
+ * to the workspace, or null when this isn't a Django project. A root-level
53
+ * package.json with a supported JS framework wins over a nested manage.py.
54
+ */
55
+ async function detectDjangoRoot(workspacePath, rootJsFramework) {
56
+ if (await (0, file_utils_1.pathExists)(path.join(workspacePath, 'manage.py')))
57
+ return '.';
58
+ if (rootJsFramework !== 'unknown')
59
+ return null;
60
+ const manage = await (0, fast_glob_1.default)('**/manage.py', { cwd: workspacePath, onlyFiles: true, deep: 4, ignore: PY_IGNORE });
61
+ if (manage.length > 0) {
62
+ const shallowest = manage.sort((a, b) => a.split('/').length - b.split('/').length || a.localeCompare(b))[0];
63
+ return path.posix.dirname(shallowest) || '.';
64
+ }
65
+ const depFiles = ['pyproject.toml', 'requirements.txt', 'Pipfile', 'setup.py', 'setup.cfg'];
66
+ for (const file of depFiles) {
67
+ const content = await (0, file_utils_1.readFile)(path.join(workspacePath, file)).catch(() => '');
68
+ if (content && (0, stack_1.mentionsPythonPackage)(content, 'django'))
69
+ return '.';
70
+ }
71
+ return null;
72
+ }
73
+ const SUPPORTED_LIST = 'React, Next.js, Vue, Django and plain HTML/CSS/JS';
74
+ /** The clearest "not supported" message for a workspace we couldn't classify. */
75
+ async function unsupportedMessage(workspacePath, fallback) {
76
+ try {
77
+ const stack = await (0, stack_1.detectStack)(await (0, stack_1.localRepoFiles)(workspacePath));
78
+ if (stack.unsupported)
79
+ return stack.message;
80
+ }
81
+ catch {
82
+ // fall through
83
+ }
84
+ return fallback;
85
+ }
86
+ async function validateWorkspace(config) {
87
+ const { workspacePath } = config;
88
+ if (!(await (0, file_utils_1.pathExists)(workspacePath))) {
89
+ throw new Error(`Workspace path does not exist: ${workspacePath}`);
90
+ }
91
+ if (!(await (0, file_utils_1.isDirectory)(workspacePath))) {
92
+ throw new Error(`Workspace path is not a directory: ${workspacePath}`);
93
+ }
94
+ const packageJsonPath = path.join(workspacePath, 'package.json');
95
+ let packageJson = await (0, file_utils_1.readJsonFile)(packageJsonPath);
96
+ let framework = 'unknown';
97
+ let isStatic = false;
98
+ if (config.framework && types_1.SUPPORTED_FRAMEWORKS.includes(config.framework)) {
99
+ framework = config.framework;
100
+ logger_1.engineLogger.info('Using explicit framework override', { framework });
101
+ }
102
+ let djangoRoot = null;
103
+ if (!framework || framework === 'unknown' || framework === 'django') {
104
+ djangoRoot = await detectDjangoRoot(workspacePath, packageJson ? detectFramework(packageJson) : 'unknown');
105
+ if (djangoRoot !== null) {
106
+ framework = 'django';
107
+ logger_1.engineLogger.info('Detected Django project', { djangoRoot });
108
+ }
109
+ else if (framework === 'django') {
110
+ throw new Error('This project was set up as Django, but no manage.py or Django dependency was found.');
111
+ }
112
+ }
113
+ if (!packageJson && framework !== 'django') {
114
+ const htmlFiles = await (0, fast_glob_1.default)('**/*.html', { cwd: workspacePath, onlyFiles: true, deep: 6 });
115
+ if (htmlFiles.length > 0) {
116
+ // Check for server-template markers
117
+ let hasServerTemplates = false;
118
+ for (const file of htmlFiles.slice(0, 10)) {
119
+ const content = await (0, file_utils_1.readFile)(path.join(workspacePath, file)).catch(() => '');
120
+ if (/\{%|<\?php|<%=/.test(content)) {
121
+ hasServerTemplates = true;
122
+ logger_1.engineLogger.warn('Found server-template markers, refusing static classification', { file });
123
+ break;
124
+ }
125
+ }
126
+ if (!hasServerTemplates && framework === 'unknown') {
127
+ framework = 'static';
128
+ packageJson = {};
129
+ isStatic = true;
130
+ logger_1.engineLogger.info('Detected static HTML/CSS/JS project');
131
+ }
132
+ }
133
+ else if (framework === 'unknown') {
134
+ throw new Error(await unsupportedMessage(workspacePath, `Babelize supports ${SUPPORTED_LIST} projects. No package.json, manage.py or HTML files were found.`));
135
+ }
136
+ }
137
+ else if (framework === 'unknown' && packageJson) {
138
+ framework = detectFramework(packageJson);
139
+ }
140
+ if (framework === 'unknown' && !isStatic) {
141
+ const workspacePatterns = getWorkspacePatterns(packageJson);
142
+ if (workspacePatterns.length > 0) {
143
+ const matchedDirs = await (0, fast_glob_1.default)(workspacePatterns, { cwd: workspacePath, onlyDirectories: true, deep: 3, absolute: true });
144
+ for (const dir of matchedDirs) {
145
+ const subPkgPath = path.join(dir, 'package.json');
146
+ const subPkg = await (0, file_utils_1.readJsonFile)(subPkgPath);
147
+ if (subPkg) {
148
+ const subFramework = detectFramework(subPkg);
149
+ if (subFramework !== 'unknown') {
150
+ framework = subFramework;
151
+ packageJson = subPkg;
152
+ logger_1.engineLogger.info('Framework detected in workspace', { workspaceDir: path.relative(workspacePath, dir), framework });
153
+ break;
154
+ }
155
+ }
156
+ }
157
+ }
158
+ if (framework === 'unknown' && !isStatic) {
159
+ const entries = await (0, file_utils_1.readDir)(workspacePath);
160
+ for (const entry of entries) {
161
+ if (entry.startsWith('.'))
162
+ continue;
163
+ const subDirPath = path.join(workspacePath, entry);
164
+ if (await (0, file_utils_1.isDirectory)(subDirPath)) {
165
+ const subPkgPath = path.join(subDirPath, 'package.json');
166
+ const subPkg = await (0, file_utils_1.readJsonFile)(subPkgPath);
167
+ if (subPkg) {
168
+ const subFramework = detectFramework(subPkg);
169
+ if (subFramework !== 'unknown') {
170
+ framework = subFramework;
171
+ packageJson = subPkg;
172
+ logger_1.engineLogger.info('Framework detected in subdirectory', { subDir: entry, framework });
173
+ break;
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+ if (!types_1.SUPPORTED_FRAMEWORKS.includes(framework)) {
181
+ throw new Error(await unsupportedMessage(workspacePath, `Babelize supports ${SUPPORTED_LIST} projects. This project's framework isn't supported yet.`));
182
+ }
183
+ if (framework === 'static') {
184
+ // A stray HTML file in a Rails/Laravel/Flutter repo doesn't make it a static site.
185
+ const stack = await (0, stack_1.detectStack)(await (0, stack_1.localRepoFiles)(workspacePath)).catch(() => null);
186
+ if (stack?.unsupported)
187
+ throw new Error(stack.message);
188
+ }
189
+ // Django: the whole project is scanned (templates/ and apps live anywhere).
190
+ const sourceDirs = framework === 'django' ? ['.'] : await findSourceDirectories(workspacePath);
191
+ if (sourceDirs.length === 0) {
192
+ logger_1.engineLogger.info('No standard source directories found, defaulting to root');
193
+ sourceDirs.push('.');
194
+ }
195
+ const frameworkConfig = types_1.FRAMEWORK_CONFIGS[framework] || types_1.FRAMEWORK_CONFIGS['unknown'];
196
+ const localeFormat = frameworkConfig.localeFormat;
197
+ const existingLocales = [];
198
+ let hasLocalesDir = false;
199
+ let localeDirRel = '';
200
+ if (localeFormat === 'po') {
201
+ // Django: <LOCALE_PATHS[0]>/<lang>/LC_MESSAGES/django.po (default <BASE_DIR>/locale)
202
+ localeDirRel = await (0, django_finalize_1.resolveDjangoLocaleDir)(workspacePath, djangoRoot ?? '.');
203
+ const djangoLocaleDir = path.join(workspacePath, localeDirRel);
204
+ hasLocalesDir = await (0, file_utils_1.isDirectory)(djangoLocaleDir);
205
+ if (hasLocalesDir) {
206
+ const langDirs = await (0, file_utils_1.readDir)(djangoLocaleDir);
207
+ for (const langDir of langDirs) {
208
+ const poFile = path.join(djangoLocaleDir, langDir, 'LC_MESSAGES', 'django.po');
209
+ if (await (0, file_utils_1.pathExists)(poFile)) {
210
+ existingLocales.push((0, locale_names_1.localeFromDjangoName)(langDir));
211
+ }
212
+ }
213
+ }
214
+ }
215
+ else {
216
+ const localesDir = path.join(workspacePath, 'locales');
217
+ hasLocalesDir = await (0, file_utils_1.isDirectory)(localesDir);
218
+ const localeExt = (0, file_utils_1.localeExtension)(localeFormat);
219
+ if (hasLocalesDir) {
220
+ const localeFiles = await (0, file_utils_1.readDir)(localesDir);
221
+ for (const file of localeFiles) {
222
+ if (file.endsWith(localeExt))
223
+ existingLocales.push(file.replace(localeExt, ''));
224
+ }
225
+ }
226
+ }
227
+ let publicDir = 'public';
228
+ if (sourceDirs.length > 0 && sourceDirs[0] !== '.') {
229
+ const firstSourceDir = sourceDirs[0];
230
+ const parts = firstSourceDir.split(/[\\/]/);
231
+ if (parts.length > 1) {
232
+ parts.pop();
233
+ publicDir = path.join(...parts, 'public');
234
+ }
235
+ }
236
+ if (framework === 'static') {
237
+ sourceDirs.length = 0;
238
+ sourceDirs.push('.');
239
+ publicDir = '.';
240
+ }
241
+ if (localeFormat === 'po') {
242
+ // For gettext projects publicDir is the locale directory.
243
+ publicDir = localeDirRel;
244
+ }
245
+ const babelizeDir = path.join(workspacePath, '.babelize');
246
+ await (0, file_utils_1.ensureDir)(babelizeDir);
247
+ const workspace = {
248
+ path: workspacePath,
249
+ framework,
250
+ localeFormat,
251
+ sourceDirs,
252
+ hasLocalesDir,
253
+ existingLocales,
254
+ publicDir,
255
+ packageJson: (packageJson ?? {}),
256
+ formatConfig: config.formatConfig,
257
+ ...(framework === 'django' ? { djangoRoot: djangoRoot ?? '.' } : {}),
258
+ };
259
+ return { workspace };
260
+ }
261
+ function getWorkspacePatterns(packageJson) {
262
+ const ws = packageJson?.workspaces;
263
+ if (Array.isArray(ws))
264
+ return ws;
265
+ if (ws && typeof ws === 'object' && Array.isArray(ws.packages))
266
+ return ws.packages;
267
+ return [];
268
+ }
269
+ function detectFramework(packageJson) {
270
+ const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
271
+ if (deps['next'])
272
+ return 'nextjs';
273
+ if (deps['nuxt'])
274
+ return 'vue';
275
+ if (deps['vue'])
276
+ return 'vue';
277
+ const reactBasedFrameworks = ['gatsby', '@remix-run/react', 'astro'];
278
+ for (const dep of reactBasedFrameworks) {
279
+ if (deps[dep])
280
+ return 'react';
281
+ }
282
+ if (deps['react'])
283
+ return 'react';
284
+ const reactIndicators = [
285
+ 'react-dom',
286
+ 'react-icons',
287
+ 'react-router-dom',
288
+ 'react-router',
289
+ 'react-scripts',
290
+ '@vitejs/plugin-react',
291
+ 'react-modal',
292
+ 'react-toastify',
293
+ 'react-i18next',
294
+ ];
295
+ if (reactIndicators.some((pkg) => deps[pkg]))
296
+ return 'react';
297
+ return 'unknown';
298
+ }
299
+ async function findSourceDirectories(workspacePath) {
300
+ const possibleDirs = ['src', 'app', 'pages', 'components', 'features', 'modules', 'lib'];
301
+ const foundDirs = [];
302
+ for (const dir of possibleDirs) {
303
+ const fullPath = path.join(workspacePath, dir);
304
+ if (await (0, file_utils_1.isDirectory)(fullPath))
305
+ foundDirs.push(dir);
306
+ }
307
+ return foundDirs;
308
+ }
309
+ async function checkI18nDependencies(packageJson, framework) {
310
+ const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
311
+ const hasReactI18next = !!deps['react-i18next'];
312
+ const hasI18next = !!deps['i18next'];
313
+ let recommendation = null;
314
+ if (framework === 'static') {
315
+ recommendation = null; // Static HTML projects do not require npm packages
316
+ }
317
+ else if (framework === 'nextjs') {
318
+ if (!deps['next-intl'])
319
+ recommendation = 'Run: bun install next-intl';
320
+ }
321
+ else if (framework === 'vue') {
322
+ if (!deps['vue-i18n'])
323
+ recommendation = 'Run: bun install vue-i18n';
324
+ }
325
+ else {
326
+ // React / vanilla / unknown
327
+ if (!hasI18next)
328
+ recommendation = 'Run: bun install i18next react-i18next';
329
+ else if (!hasReactI18next)
330
+ recommendation = 'Run: bun install react-i18next';
331
+ }
332
+ return { hasReactI18next, hasI18next, recommendation };
333
+ }
@@ -0,0 +1,13 @@
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
+ /** Thrown at a progress checkpoint once the run's AbortSignal has fired. */
9
+ export declare class RunAbortedError extends Error {
10
+ readonly reason: string;
11
+ constructor(reason: string);
12
+ }
13
+ export declare function runEngineV2(config: EngineConfigV2): Promise<EngineResultV2>;