@pie-element/cli 0.1.1 → 0.1.2-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/README.md +48 -10
  2. package/dist/commands/dev/demo/index.d.ts +1 -1
  3. package/dist/commands/dev/demo/index.js +21 -0
  4. package/dist/commands/dev/demo/index.js.map +1 -1
  5. package/dist/commands/dev/test-bundler.d.ts +0 -1
  6. package/dist/commands/dev/test-bundler.js +2 -10
  7. package/dist/commands/dev/test-bundler.js.map +1 -1
  8. package/dist/commands/docs/generate.d.ts +16 -0
  9. package/dist/commands/docs/generate.js +150 -0
  10. package/dist/commands/docs/generate.js.map +1 -0
  11. package/dist/commands/docs/verify.d.ts +12 -0
  12. package/dist/commands/docs/verify.js +40 -0
  13. package/dist/commands/docs/verify.js.map +1 -0
  14. package/dist/commands/packages/create-controllers.d.ts +0 -1
  15. package/dist/commands/packages/create-controllers.js.map +1 -1
  16. package/dist/commands/packages/create-lib-react.d.ts +0 -1
  17. package/dist/commands/packages/create-lib-react.js +1 -3
  18. package/dist/commands/packages/create-lib-react.js.map +1 -1
  19. package/dist/commands/packages/create-react-elements.d.ts +0 -1
  20. package/dist/commands/packages/create-react-elements.js +2 -3
  21. package/dist/commands/packages/create-react-elements.js.map +1 -1
  22. package/dist/commands/packages/enable-publishing.d.ts +0 -1
  23. package/dist/commands/packages/enable-publishing.js +26 -23
  24. package/dist/commands/packages/enable-publishing.js.map +1 -1
  25. package/dist/commands/packages/init-synced-elements.d.ts +0 -1
  26. package/dist/commands/packages/init-synced-elements.js +1 -1
  27. package/dist/commands/packages/init-synced-elements.js.map +1 -1
  28. package/dist/commands/upstream/analyze-esm.d.ts +0 -1
  29. package/dist/commands/upstream/analyze-esm.js +5 -1
  30. package/dist/commands/upstream/analyze-esm.js.map +1 -1
  31. package/dist/commands/upstream/check.d.ts +0 -1
  32. package/dist/commands/upstream/check.js.map +1 -1
  33. package/dist/commands/upstream/deps.d.ts +0 -1
  34. package/dist/commands/upstream/deps.js.map +1 -1
  35. package/dist/commands/upstream/sync.d.ts +11 -2
  36. package/dist/commands/upstream/sync.js +364 -25
  37. package/dist/commands/upstream/sync.js.map +1 -1
  38. package/dist/commands/upstream/track.d.ts +0 -1
  39. package/dist/commands/upstream/track.js.map +1 -1
  40. package/dist/commands/upstream/update.d.ts +0 -1
  41. package/dist/commands/upstream/update.js +37 -7
  42. package/dist/commands/upstream/update.js.map +1 -1
  43. package/dist/commands/verify/controllers.d.ts +0 -1
  44. package/dist/commands/verify/controllers.js +213 -59
  45. package/dist/commands/verify/controllers.js.map +1 -1
  46. package/dist/commands/verify/dependency-integrity.d.ts +18 -0
  47. package/dist/commands/verify/dependency-integrity.js +147 -0
  48. package/dist/commands/verify/dependency-integrity.js.map +1 -0
  49. package/dist/commands/verify/react-build.d.ts +0 -1
  50. package/dist/commands/verify/react-build.js.map +1 -1
  51. package/dist/index.d.ts +0 -1
  52. package/dist/index.js.map +1 -1
  53. package/dist/lib/docs/contract-validator.d.ts +12 -0
  54. package/dist/lib/docs/contract-validator.js +38 -0
  55. package/dist/lib/docs/contract-validator.js.map +1 -0
  56. package/dist/lib/docs/contracts.d.ts +11 -0
  57. package/dist/lib/docs/contracts.js +241 -0
  58. package/dist/lib/docs/contracts.js.map +1 -0
  59. package/dist/lib/docs/discovery.d.ts +10 -0
  60. package/dist/lib/docs/discovery.js +91 -0
  61. package/dist/lib/docs/discovery.js.map +1 -0
  62. package/dist/lib/docs/generator.d.ts +14 -0
  63. package/dist/lib/docs/generator.js +450 -0
  64. package/dist/lib/docs/generator.js.map +1 -0
  65. package/dist/lib/docs/source-extractor.d.ts +2 -0
  66. package/dist/lib/docs/source-extractor.js +209 -0
  67. package/dist/lib/docs/source-extractor.js.map +1 -0
  68. package/dist/lib/docs/types.d.ts +77 -0
  69. package/dist/lib/docs/types.js +2 -0
  70. package/dist/lib/docs/types.js.map +1 -0
  71. package/dist/lib/upstream/repo-utils.d.ts +0 -1
  72. package/dist/lib/upstream/repo-utils.js.map +1 -1
  73. package/dist/lib/upstream/sync-compatibility.d.ts +0 -1
  74. package/dist/lib/upstream/sync-compatibility.js.map +1 -1
  75. package/dist/lib/upstream/sync-constants.d.ts +35 -7
  76. package/dist/lib/upstream/sync-constants.js +40 -11
  77. package/dist/lib/upstream/sync-constants.js.map +1 -1
  78. package/dist/lib/upstream/sync-controllers-strategy.d.ts +0 -1
  79. package/dist/lib/upstream/sync-controllers-strategy.js +14 -4
  80. package/dist/lib/upstream/sync-controllers-strategy.js.map +1 -1
  81. package/dist/lib/upstream/sync-demo-metadata.d.ts +0 -1
  82. package/dist/lib/upstream/sync-demo-metadata.js +1 -1
  83. package/dist/lib/upstream/sync-demo-metadata.js.map +1 -1
  84. package/dist/lib/upstream/sync-entry-discovery.d.ts +3 -0
  85. package/dist/lib/upstream/sync-entry-discovery.js +23 -0
  86. package/dist/lib/upstream/sync-entry-discovery.js.map +1 -0
  87. package/dist/lib/upstream/sync-externals.d.ts +7 -7
  88. package/dist/lib/upstream/sync-externals.js +51 -35
  89. package/dist/lib/upstream/sync-externals.js.map +1 -1
  90. package/dist/lib/upstream/sync-filesystem.d.ts +0 -1
  91. package/dist/lib/upstream/sync-filesystem.js.map +1 -1
  92. package/dist/lib/upstream/sync-imports.d.ts +82 -62
  93. package/dist/lib/upstream/sync-imports.js +658 -185
  94. package/dist/lib/upstream/sync-imports.js.map +1 -1
  95. package/dist/lib/upstream/sync-package-json.d.ts +0 -1
  96. package/dist/lib/upstream/sync-package-json.js +7 -0
  97. package/dist/lib/upstream/sync-package-json.js.map +1 -1
  98. package/dist/lib/upstream/sync-package-manager.d.ts +14 -4
  99. package/dist/lib/upstream/sync-package-manager.js +408 -72
  100. package/dist/lib/upstream/sync-package-manager.js.map +1 -1
  101. package/dist/lib/upstream/sync-pielib-strategy.d.ts +2 -1
  102. package/dist/lib/upstream/sync-pielib-strategy.js +228 -110
  103. package/dist/lib/upstream/sync-pielib-strategy.js.map +1 -1
  104. package/dist/lib/upstream/sync-presets.d.ts +53 -0
  105. package/dist/lib/upstream/sync-presets.js +203 -0
  106. package/dist/lib/upstream/sync-presets.js.map +1 -0
  107. package/dist/lib/upstream/sync-react-strategy.d.ts +6 -1
  108. package/dist/lib/upstream/sync-react-strategy.js +342 -134
  109. package/dist/lib/upstream/sync-react-strategy.js.map +1 -1
  110. package/dist/lib/upstream/sync-source-edit.d.ts +14 -0
  111. package/dist/lib/upstream/sync-source-edit.js +89 -0
  112. package/dist/lib/upstream/sync-source-edit.js.map +1 -0
  113. package/dist/lib/upstream/sync-source-tree.d.ts +22 -0
  114. package/dist/lib/upstream/sync-source-tree.js +99 -0
  115. package/dist/lib/upstream/sync-source-tree.js.map +1 -0
  116. package/dist/lib/upstream/sync-strategy.d.ts +1 -1
  117. package/dist/lib/upstream/sync-strategy.js.map +1 -1
  118. package/dist/lib/upstream/sync-summary.d.ts +0 -1
  119. package/dist/lib/upstream/sync-summary.js.map +1 -1
  120. package/dist/lib/upstream/sync-transforms.d.ts +13 -11
  121. package/dist/lib/upstream/sync-transforms.js +23 -17
  122. package/dist/lib/upstream/sync-transforms.js.map +1 -1
  123. package/dist/lib/upstream/sync-vite-config.d.ts +13 -1
  124. package/dist/lib/upstream/sync-vite-config.js +65 -46
  125. package/dist/lib/upstream/sync-vite-config.js.map +1 -1
  126. package/dist/utils/compatibility.d.ts +13 -1
  127. package/dist/utils/compatibility.js +143 -2
  128. package/dist/utils/compatibility.js.map +1 -1
  129. package/dist/utils/conversion.d.ts +0 -1
  130. package/dist/utils/conversion.js.map +1 -1
  131. package/dist/utils/dependency-integrity.d.ts +37 -0
  132. package/dist/utils/dependency-integrity.js +557 -0
  133. package/dist/utils/dependency-integrity.js.map +1 -0
  134. package/dist/utils/git.d.ts +0 -1
  135. package/dist/utils/git.js.map +1 -1
  136. package/dist/utils/logger.d.ts +0 -1
  137. package/dist/utils/logger.js.map +1 -1
  138. package/dist/utils/package-json.d.ts +0 -1
  139. package/dist/utils/package-json.js.map +1 -1
  140. package/package.json +24 -12
  141. package/.compatibility/report.json +0 -2491
  142. package/.turbo/turbo-build.log +0 -1
  143. package/CHANGELOG.md +0 -8
  144. package/REFACTORING.md +0 -131
  145. package/bin/dev.js +0 -5
  146. package/dist/commands/dev/demo/index.d.ts.map +0 -1
  147. package/dist/commands/dev/test-bundler.d.ts.map +0 -1
  148. package/dist/commands/mathquill/migrate.d.ts +0 -20
  149. package/dist/commands/mathquill/migrate.d.ts.map +0 -1
  150. package/dist/commands/mathquill/migrate.js +0 -240
  151. package/dist/commands/mathquill/migrate.js.map +0 -1
  152. package/dist/commands/mathquill/status.d.ts +0 -20
  153. package/dist/commands/mathquill/status.d.ts.map +0 -1
  154. package/dist/commands/mathquill/status.js +0 -231
  155. package/dist/commands/mathquill/status.js.map +0 -1
  156. package/dist/commands/packages/create-controllers.d.ts.map +0 -1
  157. package/dist/commands/packages/create-lib-react.d.ts.map +0 -1
  158. package/dist/commands/packages/create-react-elements.d.ts.map +0 -1
  159. package/dist/commands/packages/enable-publishing.d.ts.map +0 -1
  160. package/dist/commands/packages/init-synced-elements.d.ts.map +0 -1
  161. package/dist/commands/upstream/analyze-esm.d.ts.map +0 -1
  162. package/dist/commands/upstream/check.d.ts.map +0 -1
  163. package/dist/commands/upstream/deps.d.ts.map +0 -1
  164. package/dist/commands/upstream/sync-mathquill.d.ts +0 -12
  165. package/dist/commands/upstream/sync-mathquill.d.ts.map +0 -1
  166. package/dist/commands/upstream/sync-mathquill.js +0 -97
  167. package/dist/commands/upstream/sync-mathquill.js.map +0 -1
  168. package/dist/commands/upstream/sync.d.ts.map +0 -1
  169. package/dist/commands/upstream/track.d.ts.map +0 -1
  170. package/dist/commands/upstream/update.d.ts.map +0 -1
  171. package/dist/commands/verify/controllers.d.ts.map +0 -1
  172. package/dist/commands/verify/react-build.d.ts.map +0 -1
  173. package/dist/index.d.ts.map +0 -1
  174. package/dist/lib/mathquill/extension-generator.d.ts +0 -9
  175. package/dist/lib/mathquill/extension-generator.d.ts.map +0 -1
  176. package/dist/lib/mathquill/extension-generator.js +0 -107
  177. package/dist/lib/mathquill/extension-generator.js.map +0 -1
  178. package/dist/lib/mathquill/khan-extractor.d.ts +0 -16
  179. package/dist/lib/mathquill/khan-extractor.d.ts.map +0 -1
  180. package/dist/lib/mathquill/khan-extractor.js +0 -148
  181. package/dist/lib/mathquill/khan-extractor.js.map +0 -1
  182. package/dist/lib/mathquill/learnosity-extractor.d.ts +0 -15
  183. package/dist/lib/mathquill/learnosity-extractor.d.ts.map +0 -1
  184. package/dist/lib/mathquill/learnosity-extractor.js +0 -170
  185. package/dist/lib/mathquill/learnosity-extractor.js.map +0 -1
  186. package/dist/lib/mathquill/migration-orchestrator.d.ts +0 -77
  187. package/dist/lib/mathquill/migration-orchestrator.d.ts.map +0 -1
  188. package/dist/lib/mathquill/migration-orchestrator.js +0 -391
  189. package/dist/lib/mathquill/migration-orchestrator.js.map +0 -1
  190. package/dist/lib/mathquill/package-updater.d.ts +0 -9
  191. package/dist/lib/mathquill/package-updater.d.ts.map +0 -1
  192. package/dist/lib/mathquill/package-updater.js +0 -103
  193. package/dist/lib/mathquill/package-updater.js.map +0 -1
  194. package/dist/lib/mathquill/pie-extractor.d.ts +0 -14
  195. package/dist/lib/mathquill/pie-extractor.d.ts.map +0 -1
  196. package/dist/lib/mathquill/pie-extractor.js +0 -167
  197. package/dist/lib/mathquill/pie-extractor.js.map +0 -1
  198. package/dist/lib/upstream/repo-utils.d.ts.map +0 -1
  199. package/dist/lib/upstream/sync-compatibility.d.ts.map +0 -1
  200. package/dist/lib/upstream/sync-constants.d.ts.map +0 -1
  201. package/dist/lib/upstream/sync-controllers-strategy.d.ts.map +0 -1
  202. package/dist/lib/upstream/sync-demo-metadata.d.ts.map +0 -1
  203. package/dist/lib/upstream/sync-dev-exports.d.ts +0 -13
  204. package/dist/lib/upstream/sync-dev-exports.d.ts.map +0 -1
  205. package/dist/lib/upstream/sync-dev-exports.js +0 -115
  206. package/dist/lib/upstream/sync-dev-exports.js.map +0 -1
  207. package/dist/lib/upstream/sync-externals.d.ts.map +0 -1
  208. package/dist/lib/upstream/sync-filesystem.d.ts.map +0 -1
  209. package/dist/lib/upstream/sync-imports.d.ts.map +0 -1
  210. package/dist/lib/upstream/sync-mathquill.d.ts +0 -19
  211. package/dist/lib/upstream/sync-mathquill.d.ts.map +0 -1
  212. package/dist/lib/upstream/sync-mathquill.js +0 -160
  213. package/dist/lib/upstream/sync-mathquill.js.map +0 -1
  214. package/dist/lib/upstream/sync-package-json.d.ts.map +0 -1
  215. package/dist/lib/upstream/sync-package-manager.d.ts.map +0 -1
  216. package/dist/lib/upstream/sync-pielib-strategy.d.ts.map +0 -1
  217. package/dist/lib/upstream/sync-react-strategy.d.ts.map +0 -1
  218. package/dist/lib/upstream/sync-strategy.d.ts.map +0 -1
  219. package/dist/lib/upstream/sync-summary.d.ts.map +0 -1
  220. package/dist/lib/upstream/sync-transforms.d.ts.map +0 -1
  221. package/dist/lib/upstream/sync-vite-config.d.ts.map +0 -1
  222. package/dist/utils/compatibility.d.ts.map +0 -1
  223. package/dist/utils/conversion.d.ts.map +0 -1
  224. package/dist/utils/git.d.ts.map +0 -1
  225. package/dist/utils/logger.d.ts.map +0 -1
  226. package/dist/utils/package-json.d.ts.map +0 -1
  227. package/packages/cli/bin/dev.js +0 -5
  228. package/packages/cli/bin/run.js +0 -5
  229. package/src/commands/dev/demo/index.ts +0 -313
  230. package/src/commands/dev/test-bundler.ts +0 -345
  231. package/src/commands/mathquill/migrate.ts +0 -269
  232. package/src/commands/mathquill/status.ts +0 -267
  233. package/src/commands/packages/create-controllers.ts +0 -127
  234. package/src/commands/packages/create-lib-react.ts +0 -279
  235. package/src/commands/packages/create-react-elements.ts +0 -306
  236. package/src/commands/packages/enable-publishing.ts +0 -161
  237. package/src/commands/packages/init-synced-elements.ts +0 -259
  238. package/src/commands/upstream/README.md +0 -444
  239. package/src/commands/upstream/analyze-esm.ts +0 -1973
  240. package/src/commands/upstream/check.ts +0 -228
  241. package/src/commands/upstream/deps.ts +0 -222
  242. package/src/commands/upstream/sync-mathquill.ts +0 -108
  243. package/src/commands/upstream/sync.ts +0 -687
  244. package/src/commands/upstream/track.ts +0 -145
  245. package/src/commands/upstream/update.ts +0 -110
  246. package/src/commands/verify/controllers.ts +0 -166
  247. package/src/commands/verify/react-build.ts +0 -171
  248. package/src/index.ts +0 -1
  249. package/src/lib/mathquill/extension-generator.ts +0 -111
  250. package/src/lib/mathquill/khan-extractor.ts +0 -175
  251. package/src/lib/mathquill/learnosity-extractor.ts +0 -198
  252. package/src/lib/mathquill/migration-orchestrator.ts +0 -513
  253. package/src/lib/mathquill/package-updater.ts +0 -120
  254. package/src/lib/mathquill/pie-extractor.ts +0 -194
  255. package/src/lib/upstream/repo-utils.ts +0 -18
  256. package/src/lib/upstream/sync-compatibility.ts +0 -89
  257. package/src/lib/upstream/sync-constants.ts +0 -77
  258. package/src/lib/upstream/sync-controllers-strategy.ts +0 -291
  259. package/src/lib/upstream/sync-demo-metadata.ts +0 -199
  260. package/src/lib/upstream/sync-dev-exports.ts +0 -151
  261. package/src/lib/upstream/sync-externals.ts +0 -159
  262. package/src/lib/upstream/sync-filesystem.ts +0 -87
  263. package/src/lib/upstream/sync-imports.ts +0 -992
  264. package/src/lib/upstream/sync-mathquill.ts +0 -194
  265. package/src/lib/upstream/sync-package-json.ts +0 -86
  266. package/src/lib/upstream/sync-package-manager.ts +0 -694
  267. package/src/lib/upstream/sync-pielib-strategy.ts +0 -441
  268. package/src/lib/upstream/sync-react-strategy.ts +0 -945
  269. package/src/lib/upstream/sync-strategy.ts +0 -61
  270. package/src/lib/upstream/sync-summary.ts +0 -194
  271. package/src/lib/upstream/sync-transforms.ts +0 -154
  272. package/src/lib/upstream/sync-vite-config.ts +0 -243
  273. package/src/types/es-module-lexer.d.ts +0 -4
  274. package/src/utils/compatibility.ts +0 -182
  275. package/src/utils/conversion.ts +0 -153
  276. package/src/utils/git.ts +0 -63
  277. package/src/utils/logger.ts +0 -69
  278. package/src/utils/package-json.ts +0 -43
  279. package/tests/sync-package-manager.test.ts +0 -112
  280. package/tests/transform-assign-props.test.ts +0 -101
  281. package/tsconfig.json +0 -15
@@ -1,182 +0,0 @@
1
- import { readFile } from 'node:fs/promises';
2
- import { existsSync } from 'node:fs';
3
-
4
- /**
5
- * ESM package.json validation result
6
- */
7
- export interface EsmPackageValidation {
8
- hasTypeModule: boolean;
9
- hasExportsField: boolean;
10
- hasMainExport: boolean;
11
- hasControllerExport: boolean;
12
- sideEffectsFree: boolean;
13
- mainExportIsEsm: boolean;
14
- controllerExportIsEsm: boolean;
15
- }
16
-
17
- /**
18
- * ESM player validation result for an element
19
- */
20
- export interface EsmValidationResult {
21
- compatible: boolean;
22
- packageJson: EsmPackageValidation;
23
- blockers: string[];
24
- warnings: string[];
25
- }
26
-
27
- /**
28
- * Runtime-ish validation for ESM player readiness (CDN resolution / module parse).
29
- * Note: this is NOT a full browser execution test, but it provides production-like signal
30
- * by verifying CDN URLs resolve and the returned JS parses as an ES module.
31
- */
32
- export interface EsmRuntimeValidationResult {
33
- /**
34
- * Whether this element passed the runtime-ish probe.
35
- * When false, see `errors` for details.
36
- */
37
- compatible: boolean;
38
- /** The CDN base URL used for probing (e.g. https://esm.sh). */
39
- cdnBaseUrl: string;
40
- /** Version that was probed (usually the upstream package.json version). */
41
- version: string;
42
- /** Whether the package entrypoint URL resolved (HTTP 200). */
43
- entryOk: boolean;
44
- /** Whether the controller URL resolved (HTTP 200). */
45
- controllerOk: boolean;
46
- /** Whether the returned JS for the entry parsed as an ES module. */
47
- entryParseOk: boolean;
48
- /** Whether the returned JS for the controller parsed as an ES module. */
49
- controllerParseOk: boolean;
50
- /** Any errors/warnings collected during probe. */
51
- errors: string[];
52
-
53
- /**
54
- * Probe details (for deep/transitive validation)
55
- */
56
- probeMode?: 'shallow' | 'deep';
57
- maxDepth?: number;
58
- maxModules?: number;
59
- fetchedModules?: number;
60
- fetchedOk?: number;
61
- firstFailingUrl?: string;
62
- }
63
-
64
- /**
65
- * Compatibility report structure
66
- */
67
- export interface CompatibilityReport {
68
- elements: string[];
69
- pieLibPackages: string[];
70
- blockedElements: Record<string, string[]>;
71
- elementDetails: Record<string, ElementDetail>;
72
- pieLibDetails: Record<string, PieLibDetail>;
73
-
74
- // ESM player validation
75
- esmPlayerReady: string[];
76
- esmValidation: Record<string, EsmValidationResult>;
77
- /**
78
- * Whether ESM player validation (package.json structure / exports) was run as part of analysis.
79
- * Optional for backwards compatibility with older reports.
80
- */
81
- esmPlayerValidationEnabled?: boolean;
82
-
83
- // Runtime-ish validation (CDN probes)
84
- esmRuntimeValidationEnabled?: boolean;
85
- esmRuntimeCdnBaseUrl?: string;
86
- esmRuntimeValidation?: Record<string, EsmRuntimeValidationResult>;
87
-
88
- // Student UI only (elements where student UI is ESM-ready but authoring isn't)
89
- studentUIOnly?: string[];
90
-
91
- lastAnalyzed: string;
92
- summary: {
93
- totalElements: number;
94
- compatibleElements: number;
95
- blockedElements: number;
96
- studentUIOnlyElements?: number;
97
- esmPlayerReady: number;
98
- esmRuntimeReady?: number;
99
- totalPieLibPackages: number;
100
- compatiblePieLibPackages: number;
101
- };
102
- }
103
-
104
- export interface ElementDetail {
105
- compatible: boolean;
106
- directDeps: string[];
107
- pieLibDeps: string[];
108
- pieElementDeps: string[];
109
- blockers: string[];
110
-
111
- // Separate analysis for student UI vs authoring
112
- studentUI?: {
113
- compatible: boolean;
114
- blockers: string[];
115
- };
116
- configure?: {
117
- compatible: boolean;
118
- blockers: string[];
119
- };
120
- controller?: {
121
- compatible: boolean;
122
- blockers: string[];
123
- };
124
- }
125
-
126
- export interface PieLibDetail {
127
- compatible: boolean;
128
- usedBy: string[];
129
- blockers: string[];
130
- }
131
-
132
- export async function loadCompatibilityReport(path: string): Promise<CompatibilityReport> {
133
- if (!existsSync(path)) {
134
- throw new Error(`Compatibility report not found at: ${path}`);
135
- }
136
-
137
- const content = await readFile(path, 'utf-8');
138
- return JSON.parse(content) as CompatibilityReport;
139
- }
140
-
141
- export function isElementCompatible(element: string, report: CompatibilityReport): boolean {
142
- return report.elements.includes(element);
143
- }
144
-
145
- export function isPieLibPackageCompatible(pkg: string, report: CompatibilityReport): boolean {
146
- return report.pieLibPackages.includes(pkg);
147
- }
148
-
149
- export function getElementBlockers(element: string, report: CompatibilityReport): string[] {
150
- return report.blockedElements[element] || [];
151
- }
152
-
153
- /**
154
- * Check if an element is ESM player ready (no CommonJS deps + proper ESM package structure)
155
- */
156
- export function isElementEsmPlayerReady(element: string, report: CompatibilityReport): boolean {
157
- return report.esmPlayerReady.includes(element);
158
- }
159
-
160
- /**
161
- * Check if an element has student UI ready (even if configure/controller aren't)
162
- */
163
- export function isElementStudentUIReady(element: string, report: CompatibilityReport): boolean {
164
- const detail = report.elementDetails[element];
165
- if (!detail) return false;
166
-
167
- // If fully compatible, student UI is ready
168
- if (detail.compatible) return true;
169
-
170
- // Check if student UI is explicitly marked as compatible
171
- return detail.studentUI?.compatible === true;
172
- }
173
-
174
- /**
175
- * Get ESM validation details for an element
176
- */
177
- export function getEsmValidation(
178
- element: string,
179
- report: CompatibilityReport
180
- ): EsmValidationResult | null {
181
- return report.esmValidation[element] || null;
182
- }
@@ -1,153 +0,0 @@
1
- /**
2
- * JavaScript to TypeScript conversion utilities
3
- */
4
-
5
- export interface ConversionMetadata {
6
- sourcePath: string;
7
- commit: string;
8
- }
9
-
10
- export interface ConversionResult {
11
- code: string;
12
- hasDefaultObjectExport: boolean;
13
- }
14
-
15
- /**
16
- * Convert JavaScript to TypeScript
17
- */
18
- export function convertJsToTs(jsCode: string, metadata: ConversionMetadata): ConversionResult {
19
- // We intentionally do NOT transform the JavaScript syntax.
20
- // Goal: keep upstream source as-is, while letting the monorepo's TS/Vite pipeline build it.
21
- // TypeScript diagnostics are suppressed for synced files.
22
- let tsCode = jsCode;
23
- const hasDefaultObjectExport = false;
24
-
25
- // Convert CommonJS module.exports to ES modules
26
- tsCode = convertModuleExportsToEsm(tsCode);
27
-
28
- // Must be at the very top of the file to reliably suppress TypeScript diagnostics.
29
- // We keep synced files buildable even when upstream JS has type issues.
30
- const tsNoCheck = `// @ts-nocheck\n`;
31
-
32
- // Add sync metadata header
33
- const header = `/**
34
- * @synced-from ${metadata.sourcePath}
35
- * @auto-generated
36
- *
37
- * This file is automatically synced from pie-elements and converted to TypeScript.
38
- * Manual edits will be overwritten on next sync.
39
- * To make changes, edit the upstream JavaScript file and run sync again.
40
- */
41
-
42
- `;
43
- return { code: tsNoCheck + header + tsCode, hasDefaultObjectExport };
44
- }
45
-
46
- /**
47
- * Convert CommonJS module.exports to ES module exports
48
- */
49
- function convertModuleExportsToEsm(content: string): string {
50
- // Match: module.exports = { key: value, key2: value2, ... };
51
- const moduleExportsPattern = /module\.exports\s*=\s*\{([\s\S]*?)\};?/;
52
- const match = content.match(moduleExportsPattern);
53
-
54
- if (!match) {
55
- return content;
56
- }
57
-
58
- const [fullMatch, objectContent] = match;
59
-
60
- // Parse the object content into key-value pairs
61
- const exports: string[] = [];
62
- const lines = objectContent.split('\n');
63
-
64
- let currentKey: string | null = null;
65
- let currentValue: string[] = [];
66
-
67
- for (const line of lines) {
68
- const trimmed = line.trim();
69
- if (!trimmed || trimmed === '{' || trimmed === '}') continue;
70
-
71
- // Check if this line starts a new key
72
- const keyMatch = trimmed.match(/^(\w+):\s*(.*)/);
73
- if (keyMatch) {
74
- // Save previous export if any
75
- if (currentKey) {
76
- const value = currentValue.join('\n').replace(/,\s*$/, ''); // Remove trailing comma
77
- exports.push(`export const ${currentKey} =\n${value};`);
78
- }
79
-
80
- // Start new export
81
- currentKey = keyMatch[1];
82
- currentValue = [keyMatch[2]];
83
- } else {
84
- // Continuation of current value
85
- currentValue.push(line);
86
- }
87
- }
88
-
89
- // Save last export
90
- if (currentKey) {
91
- const value = currentValue.join('\n').replace(/,\s*$/, '');
92
- exports.push(`export const ${currentKey} =\n${value};`);
93
- }
94
-
95
- // Replace the module.exports block with ES module exports
96
- const esmExports = exports.join('\n\n');
97
- return content.replace(fullMatch, esmExports);
98
- }
99
-
100
- /**
101
- * Convert JSX to TSX
102
- */
103
- export function convertJsxToTsx(jsxCode: string, metadata: ConversionMetadata): ConversionResult {
104
- // We intentionally do NOT transform the JavaScript/JSX syntax.
105
- // Goal: keep upstream source as-is, while letting the monorepo's TS/Vite pipeline build it.
106
- // TypeScript diagnostics are suppressed for synced files.
107
- const tsxCode = jsxCode;
108
- const hasDefaultObjectExport = false;
109
-
110
- // Must be at the very top of the file to reliably suppress TypeScript diagnostics.
111
- // We keep synced files buildable even when upstream JSX has type issues.
112
- const tsNoCheck = `// @ts-nocheck\n`;
113
-
114
- // Add sync metadata header
115
- const header = `/**
116
- * @synced-from ${metadata.sourcePath}
117
- * @auto-generated
118
- *
119
- * This file is automatically synced from pie-elements and converted to TypeScript.
120
- * Manual edits will be overwritten on next sync.
121
- * To make changes, edit the upstream JavaScript file and run sync again.
122
- */
123
-
124
- `;
125
- return { code: tsNoCheck + header + tsxCode, hasDefaultObjectExport };
126
- }
127
-
128
- /**
129
- * Fix imports from default export files
130
- * Some files export default objects but are imported with named imports
131
- */
132
- export function fixImports(content: string, hasDefaultObjectExport: boolean): string {
133
- if (!hasDefaultObjectExport) {
134
- return content;
135
- }
136
-
137
- // Convert: import { something } from './file'
138
- // To: import * as file from './file'
139
- // This is needed when the imported file has export default {}
140
- return content.replace(
141
- /import\s+{\s*([^}]+)\s*}\s+from\s+(['"]\.\/[^'"]+['"])/g,
142
- (_match, _imports, path) => {
143
- // Extract filename from path
144
- const filename =
145
- path
146
- .replace(/['"]/g, '')
147
- .split('/')
148
- .pop()
149
- ?.replace(/\.\w+$/, '') || 'module';
150
- return `import * as ${filename} from ${path}`;
151
- }
152
- );
153
- }
package/src/utils/git.ts DELETED
@@ -1,63 +0,0 @@
1
- import { execSync } from 'node:child_process';
2
-
3
- export function getCurrentCommit(cwd: string): string {
4
- try {
5
- return execSync('git rev-parse HEAD', { cwd, encoding: 'utf8' }).trim();
6
- } catch (error) {
7
- throw new Error(`Failed to get current commit: ${error}`);
8
- }
9
- }
10
-
11
- export function getCurrentCommitShort(cwd: string): string {
12
- try {
13
- return execSync('git rev-parse --short HEAD', { cwd, encoding: 'utf8' }).trim();
14
- } catch (error) {
15
- throw new Error(`Failed to get short commit: ${error}`);
16
- }
17
- }
18
-
19
- export function getCommitsSince(since: string, cwd: string): string[] {
20
- try {
21
- const output = execSync(`git log ${since}..HEAD --oneline`, {
22
- cwd,
23
- encoding: 'utf8',
24
- }).trim();
25
-
26
- if (!output) return [];
27
- return output.split('\n');
28
- } catch (error) {
29
- throw new Error(`Failed to get commits since ${since}: ${error}`);
30
- }
31
- }
32
-
33
- export function getFileModifiedDate(filePath: string, cwd: string): Date {
34
- try {
35
- const timestamp = execSync(`git log -1 --format=%ct -- "${filePath}"`, {
36
- cwd,
37
- encoding: 'utf8',
38
- }).trim();
39
-
40
- return new Date(Number.parseInt(timestamp, 10) * 1000);
41
- } catch (error) {
42
- throw new Error(`Failed to get file modification date: ${error}`);
43
- }
44
- }
45
-
46
- export function getCommitDetails(commit: string, cwd: string): string {
47
- try {
48
- return execSync(`git show --stat ${commit}`, {
49
- cwd,
50
- encoding: 'utf8',
51
- });
52
- } catch (error) {
53
- throw new Error(`Failed to get commit details: ${error}`);
54
- }
55
- }
56
-
57
- export function getAuthorName(cwd: string): string {
58
- try {
59
- return execSync('git config user.name', { cwd, encoding: 'utf8' }).trim();
60
- } catch (_error) {
61
- return 'Unknown';
62
- }
63
- }
@@ -1,69 +0,0 @@
1
- export class Logger {
2
- constructor(private verbose: boolean = false) {}
3
-
4
- isVerbose(): boolean {
5
- return this.verbose;
6
- }
7
-
8
- info(message: string): void {
9
- console.log(message);
10
- }
11
-
12
- debug(message: string): void {
13
- if (this.verbose) {
14
- console.log(message);
15
- }
16
- }
17
-
18
- warn(message: string): void {
19
- console.warn(`⚠️ ${message}`);
20
- }
21
-
22
- error(message: string): void {
23
- console.error(`❌ ${message}`);
24
- }
25
-
26
- success(message: string): void {
27
- console.log(`✅ ${message}`);
28
- }
29
-
30
- section(title: string): void {
31
- console.log(`\n${title}`);
32
- console.log('='.repeat(title.length));
33
- }
34
-
35
- /**
36
- * Show a progress message (only in verbose mode)
37
- * In non-verbose mode, use progressStart/progressComplete instead
38
- */
39
- progress(message: string): void {
40
- if (this.verbose) {
41
- console.log(` ${message}`);
42
- }
43
- }
44
-
45
- /**
46
- * Show start of an operation (always shown)
47
- */
48
- progressStart(message: string): void {
49
- process.stdout.write(message);
50
- }
51
-
52
- /**
53
- * Complete a progress operation with success
54
- */
55
- progressComplete(details?: string): void {
56
- if (details) {
57
- console.log(` ✓ ${details}`);
58
- } else {
59
- console.log(' ✓');
60
- }
61
- }
62
-
63
- /**
64
- * Complete a progress operation with a count
65
- */
66
- progressCompleteWithCount(count: number, label: string): void {
67
- console.log(` ✓ (${count} ${label})`);
68
- }
69
- }
@@ -1,43 +0,0 @@
1
- import { readFile, writeFile } from 'node:fs/promises';
2
-
3
- export interface PackageJson {
4
- name: string;
5
- version: string;
6
- private?: boolean;
7
- dependencies?: Record<string, string>;
8
- devDependencies?: Record<string, string>;
9
- [key: string]: unknown;
10
- }
11
-
12
- export async function loadPackageJson(path: string): Promise<PackageJson> {
13
- const content = await readFile(path, 'utf-8');
14
- return JSON.parse(content) as PackageJson;
15
- }
16
-
17
- export async function writePackageJson(path: string, pkg: PackageJson): Promise<void> {
18
- const content = `${JSON.stringify(pkg, null, 2)}\n`;
19
- await writeFile(path, content, 'utf-8');
20
- }
21
-
22
- export function extractDependencies(content: string): string[] {
23
- const deps = new Set<string>();
24
-
25
- // Match import statements
26
- const importRegex = /import\s+.+\s+from\s+['"]([^'"]+)['"]/g;
27
- let match: RegExpExecArray | null = importRegex.exec(content);
28
-
29
- while (match !== null) {
30
- const dep = match[1];
31
- // Skip relative imports
32
- if (!dep.startsWith('.') && !dep.startsWith('/')) {
33
- // Extract package name (handle scoped packages)
34
- const pkgName = dep.startsWith('@')
35
- ? dep.split('/').slice(0, 2).join('/')
36
- : dep.split('/')[0];
37
- deps.add(pkgName);
38
- }
39
- match = importRegex.exec(content);
40
- }
41
-
42
- return Array.from(deps).sort();
43
- }
@@ -1,112 +0,0 @@
1
- import { mkdtemp, mkdir, readFile, writeFile } from 'node:fs/promises';
2
- import { join } from 'node:path';
3
- import { tmpdir } from 'node:os';
4
- import { describe, expect, it } from 'vitest';
5
- import { SCRIPTS } from '../src/lib/upstream/sync-constants.js';
6
- import {
7
- ensureElementPackageJson,
8
- ensurePieLibPackageJson,
9
- } from '../src/lib/upstream/sync-package-manager.js';
10
-
11
- const createConfig = (rootDir: string) =>
12
- ({
13
- pieElements: join(rootDir, 'upstream', 'pie-elements'),
14
- pieLib: join(rootDir, 'upstream', 'pie-lib'),
15
- pieElementsNg: rootDir,
16
- syncControllers: true,
17
- syncReactComponents: true,
18
- syncPieLib: true,
19
- skipDemos: true,
20
- upstreamCommit: 'test',
21
- }) as any;
22
-
23
- const createElementBase = async (elementDir: string) => {
24
- await mkdir(join(elementDir, 'src'), { recursive: true });
25
- await writeFile(
26
- join(elementDir, 'src', 'index.ts'),
27
- 'export default class TestElement {}\n',
28
- 'utf-8'
29
- );
30
- };
31
-
32
- const readBuildScript = async (elementDir: string): Promise<string> => {
33
- const pkgJson = JSON.parse(await readFile(join(elementDir, 'package.json'), 'utf-8'));
34
- return pkgJson.scripts.build;
35
- };
36
-
37
- describe('ensureElementPackageJson iife build script generation', () => {
38
- it('uses IIFE build script when vite.config.iife.ts exists', async () => {
39
- const rootDir = await mkdtemp(join(tmpdir(), 'pie-cli-sync-test-'));
40
- const elementDir = join(rootDir, 'packages', 'elements-react', 'test-element');
41
-
42
- await createElementBase(elementDir);
43
- await writeFile(join(elementDir, 'vite.config.iife.ts'), 'export default {};\n', 'utf-8');
44
-
45
- const changed = await ensureElementPackageJson(
46
- 'test-element',
47
- elementDir,
48
- createConfig(rootDir)
49
- );
50
- expect(changed).toBe(true);
51
-
52
- const buildScript = await readBuildScript(elementDir);
53
- expect(buildScript).toBe(SCRIPTS.BUILD_WITH_IIFE);
54
- });
55
-
56
- it('uses standard build script when no IIFE files exist', async () => {
57
- const rootDir = await mkdtemp(join(tmpdir(), 'pie-cli-sync-test-'));
58
- const elementDir = join(rootDir, 'packages', 'elements-react', 'test-element');
59
-
60
- await createElementBase(elementDir);
61
-
62
- const changed = await ensureElementPackageJson(
63
- 'test-element',
64
- elementDir,
65
- createConfig(rootDir)
66
- );
67
- expect(changed).toBe(true);
68
-
69
- const buildScript = await readBuildScript(elementDir);
70
- expect(buildScript).toBe(SCRIPTS.BUILD);
71
- });
72
- });
73
-
74
- describe('ensurePieLibPackageJson', () => {
75
- it('pins math-rendering to shared mathjax adapter workspace package', async () => {
76
- const rootDir = await mkdtemp(join(tmpdir(), 'pie-cli-sync-test-'));
77
- const libDir = join(rootDir, 'packages', 'lib-react', 'math-rendering');
78
-
79
- await mkdir(join(libDir, 'src'), { recursive: true });
80
- await writeFile(join(libDir, 'src', 'index.ts'), 'export {};\n', 'utf-8');
81
-
82
- const changed = await ensurePieLibPackageJson('math-rendering', libDir, createConfig(rootDir));
83
- expect(changed).toBe(true);
84
-
85
- const pkgJson = JSON.parse(await readFile(join(libDir, 'package.json'), 'utf-8'));
86
- expect(pkgJson.dependencies).toEqual({
87
- '@pie-element/shared-math-rendering-mathjax': 'workspace:*',
88
- });
89
- });
90
-
91
- it('adds workspace deps detected from pie-lib source imports', async () => {
92
- const rootDir = await mkdtemp(join(tmpdir(), 'pie-cli-sync-test-'));
93
- const libDir = join(rootDir, 'packages', 'lib-react', 'math-input');
94
- const renderUiDir = join(rootDir, 'packages', 'lib-react', 'render-ui');
95
-
96
- await mkdir(join(libDir, 'src'), { recursive: true });
97
- await mkdir(renderUiDir, { recursive: true });
98
- await writeFile(
99
- join(libDir, 'src', 'index.ts'),
100
- "import { color } from '@pie-lib/render-ui';\nexport { color };\n",
101
- 'utf-8'
102
- );
103
-
104
- const changed = await ensurePieLibPackageJson('math-input', libDir, createConfig(rootDir));
105
- expect(changed).toBe(true);
106
-
107
- const pkgJson = JSON.parse(await readFile(join(libDir, 'package.json'), 'utf-8'));
108
- expect(pkgJson.dependencies).toMatchObject({
109
- '@pie-lib/render-ui': 'workspace:*',
110
- });
111
- });
112
- });