@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,694 +0,0 @@
1
- /**
2
- * Centralized package.json management for upstream sync operations
3
- *
4
- * This module consolidates all package.json generation and management logic
5
- * to eliminate the massive duplication between controllers-strategy and react-strategy.
6
- */
7
-
8
- import { existsSync } from 'node:fs';
9
- import { readFile, writeFile } from 'node:fs/promises';
10
- import { dirname, join } from 'node:path';
11
- import { loadPackageJson, type PackageJson } from '../../utils/package-json.js';
12
- import type { SyncConfig } from './sync-strategy.js';
13
- import { existsAny } from './sync-filesystem.js';
14
- import { applyPackageJsonTransforms } from './sync-transforms.js';
15
- import { BUILD_TOOLS, REACT, PACKAGE_DEFAULTS, SCRIPTS, WORKSPACE } from './sync-constants.js';
16
-
17
- interface EntryPointMap {
18
- hasIndex: boolean;
19
- hasDelivery: boolean;
20
- hasAuthor: boolean;
21
- hasController: boolean;
22
- hasConfigure: boolean;
23
- hasPrint: boolean;
24
- hasTypes: boolean;
25
- }
26
-
27
- /**
28
- * Detect available entry points in an element package
29
- */
30
- export function detectEntryPoints(elementDir: string): EntryPointMap {
31
- return {
32
- hasIndex: existsAny([
33
- join(elementDir, 'src/index.ts'),
34
- join(elementDir, 'src/index.tsx'),
35
- join(elementDir, 'src/index.js'),
36
- join(elementDir, 'src/index.jsx'),
37
- ]),
38
- hasDelivery: existsAny([
39
- join(elementDir, 'src/delivery/index.ts'),
40
- join(elementDir, 'src/delivery/index.tsx'),
41
- join(elementDir, 'src/delivery/index.js'),
42
- join(elementDir, 'src/delivery/index.jsx'),
43
- ]),
44
- hasAuthor: existsAny([
45
- join(elementDir, 'src/author/index.ts'),
46
- join(elementDir, 'src/author/index.tsx'),
47
- join(elementDir, 'src/author/index.js'),
48
- join(elementDir, 'src/author/index.jsx'),
49
- ]),
50
- hasController: existsAny([
51
- join(elementDir, 'src/controller/index.ts'),
52
- join(elementDir, 'src/controller/index.tsx'),
53
- join(elementDir, 'src/controller/index.js'),
54
- join(elementDir, 'src/controller/index.jsx'),
55
- ]),
56
- hasConfigure: existsAny([
57
- join(elementDir, 'src/configure/index.ts'),
58
- join(elementDir, 'src/configure/index.tsx'),
59
- join(elementDir, 'src/configure/index.js'),
60
- join(elementDir, 'src/configure/index.jsx'),
61
- ]),
62
- hasPrint: existsAny([
63
- join(elementDir, 'src/print/index.ts'),
64
- join(elementDir, 'src/print/index.tsx'),
65
- join(elementDir, 'src/print/index.js'),
66
- join(elementDir, 'src/print/index.jsx'),
67
- ]),
68
- hasTypes: existsAny([
69
- join(elementDir, 'src/types/index.ts'),
70
- join(elementDir, 'src/types/index.tsx'),
71
- join(elementDir, 'src/types/index.js'),
72
- join(elementDir, 'src/types/index.jsx'),
73
- ]),
74
- };
75
- }
76
-
77
- /**
78
- * Generate exports object based on available entry points
79
- */
80
- export function generateExportsObject(entryPoints: EntryPointMap): Record<string, unknown> {
81
- const exports: Record<string, unknown> = {
82
- '.': {
83
- types: './dist/index.d.ts',
84
- default: './dist/index.js',
85
- },
86
- };
87
-
88
- if (entryPoints.hasDelivery) {
89
- exports['./delivery'] = {
90
- types: './dist/delivery/index.d.ts',
91
- default: './dist/delivery/index.js',
92
- };
93
- }
94
-
95
- if (entryPoints.hasAuthor) {
96
- exports['./author'] = {
97
- types: './dist/author/index.d.ts',
98
- default: './dist/author/index.js',
99
- };
100
- }
101
-
102
- if (entryPoints.hasController) {
103
- exports['./controller'] = {
104
- types: './dist/controller/index.d.ts',
105
- default: './dist/controller/index.js',
106
- };
107
- }
108
-
109
- if (entryPoints.hasConfigure) {
110
- exports['./configure'] = {
111
- types: './dist/configure/index.d.ts',
112
- default: './dist/configure/index.js',
113
- };
114
- }
115
-
116
- if (entryPoints.hasPrint) {
117
- exports['./print'] = {
118
- types: './dist/print/index.d.ts',
119
- default: './dist/print/index.js',
120
- };
121
- }
122
-
123
- if (entryPoints.hasTypes) {
124
- exports['./types'] = {
125
- types: './dist/types/index.d.ts',
126
- default: './dist/types/index.js',
127
- };
128
- }
129
-
130
- return exports;
131
- }
132
-
133
- /**
134
- * Extract imports from source files to determine runtime dependencies
135
- */
136
- export async function extractImportsFromSources(elementDir: string): Promise<Set<string>> {
137
- const imports = new Set<string>();
138
- const srcDir = join(elementDir, 'src');
139
-
140
- if (!existsSync(srcDir)) {
141
- return imports;
142
- }
143
-
144
- // Recursively find all .ts, .tsx, .js, .jsx files
145
- const { readdir: readdirRecursive } = await import('node:fs/promises');
146
-
147
- async function scanDirectory(dir: string): Promise<void> {
148
- try {
149
- const entries = await readdirRecursive(dir, { withFileTypes: true });
150
-
151
- for (const entry of entries) {
152
- const fullPath = join(dir, entry.name);
153
-
154
- if (entry.isDirectory()) {
155
- await scanDirectory(fullPath);
156
- } else if (entry.isFile() && /\.(ts|tsx|js|jsx)$/.test(entry.name)) {
157
- try {
158
- const content = await readFile(fullPath, 'utf-8');
159
- // Match import statements: import ... from 'package' or import('package')
160
- const importRegex = /import\s+(?:[\w{},\s*]+\s+from\s+)?['"]([^'"]+)['"]/g;
161
- const dynamicImportRegex = /import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
162
-
163
- let match: RegExpExecArray | null;
164
-
165
- match = importRegex.exec(content);
166
- while (match !== null) {
167
- const importPath = match[1];
168
- // Only track package imports (not relative imports)
169
- if (!importPath.startsWith('.') && !importPath.startsWith('/')) {
170
- imports.add(importPath);
171
- }
172
- match = importRegex.exec(content);
173
- }
174
-
175
- match = dynamicImportRegex.exec(content);
176
- while (match !== null) {
177
- const importPath = match[1];
178
- if (!importPath.startsWith('.') && !importPath.startsWith('/')) {
179
- imports.add(importPath);
180
- }
181
- match = dynamicImportRegex.exec(content);
182
- }
183
- } catch (err) {
184
- // Skip files that can't be read
185
- }
186
- }
187
- }
188
- } catch (err) {
189
- // Skip directories that can't be read
190
- }
191
- }
192
-
193
- await scanDirectory(srcDir);
194
- return imports;
195
- }
196
-
197
- async function findInstalledPackageJson(
198
- packageName: string,
199
- fromDir: string
200
- ): Promise<PackageJson | null> {
201
- try {
202
- const { createRequire } = await import('node:module');
203
- const req = createRequire(join(fromDir, 'package.json'));
204
- const resolvedEntry = req.resolve(packageName);
205
-
206
- let currentDir = dirname(resolvedEntry);
207
- while (true) {
208
- const candidate = join(currentDir, 'package.json');
209
- if (existsSync(candidate)) {
210
- const pkg = await loadPackageJson(candidate).catch(() => null);
211
- if (pkg && pkg.name === packageName) {
212
- return pkg;
213
- }
214
- }
215
-
216
- const parent = dirname(currentDir);
217
- if (parent === currentDir) {
218
- break;
219
- }
220
- currentDir = parent;
221
- }
222
- } catch {
223
- // Package not resolvable from this location.
224
- }
225
- return null;
226
- }
227
-
228
- async function addTransitivePeerDependencies(
229
- deps: Record<string, string>,
230
- fromDir: string
231
- ): Promise<void> {
232
- const depNames = Object.keys(deps);
233
-
234
- for (const depName of depNames) {
235
- if (
236
- depName.startsWith(WORKSPACE.PIE_LIB_PREFIX) ||
237
- depName.startsWith(WORKSPACE.PIE_ELEMENT_PREFIX) ||
238
- depName.startsWith(WORKSPACE.PIE_FRAMEWORK_PREFIX)
239
- ) {
240
- continue;
241
- }
242
-
243
- const installedPkg = await findInstalledPackageJson(depName, fromDir);
244
- const peerDeps = (installedPkg?.peerDependencies as Record<string, string> | undefined) ?? {};
245
-
246
- for (const [peerName, peerVersion] of Object.entries(peerDeps)) {
247
- if (deps[peerName]) {
248
- continue;
249
- }
250
-
251
- if (
252
- peerName.startsWith(WORKSPACE.PIE_LIB_PREFIX) ||
253
- peerName.startsWith(WORKSPACE.PIE_ELEMENT_PREFIX) ||
254
- peerName.startsWith(WORKSPACE.PIE_FRAMEWORK_PREFIX)
255
- ) {
256
- deps[peerName] = WORKSPACE.VERSION;
257
- } else {
258
- deps[peerName] = peerVersion;
259
- }
260
- }
261
- }
262
- }
263
-
264
- async function inferPeerVersionFromDeclaredDeps(
265
- targetDep: string,
266
- deps: Record<string, string>,
267
- fromDir: string
268
- ): Promise<string | null> {
269
- for (const depName of Object.keys(deps)) {
270
- if (
271
- depName.startsWith(WORKSPACE.PIE_LIB_PREFIX) ||
272
- depName.startsWith(WORKSPACE.PIE_ELEMENT_PREFIX) ||
273
- depName.startsWith(WORKSPACE.PIE_FRAMEWORK_PREFIX)
274
- ) {
275
- continue;
276
- }
277
-
278
- const installedPkg = await findInstalledPackageJson(depName, fromDir);
279
- const peerDeps = (installedPkg?.peerDependencies as Record<string, string> | undefined) ?? {};
280
- if (peerDeps[targetDep]) {
281
- return peerDeps[targetDep];
282
- }
283
- }
284
-
285
- return null;
286
- }
287
-
288
- /**
289
- * Extract and normalize dependencies from upstream package.json
290
- */
291
- export function extractUpstreamDependencies(
292
- upstreamPkg: PackageJson | null
293
- ): Record<string, string> {
294
- if (!upstreamPkg) return {};
295
-
296
- const upstreamDeps = (upstreamPkg.dependencies as Record<string, string> | undefined) ?? {};
297
- const expectedDeps: Record<string, string> = {};
298
-
299
- for (const [name, version] of Object.entries(upstreamDeps)) {
300
- if (name.startsWith(WORKSPACE.PIE_LIB_PREFIX)) {
301
- expectedDeps[name] = WORKSPACE.VERSION;
302
- } else if (name !== 'react' && name !== 'react-dom') {
303
- expectedDeps[name] = version;
304
- }
305
- }
306
-
307
- return expectedDeps;
308
- }
309
-
310
- /**
311
- * Ensure devDependencies include all required build tools
312
- */
313
- export function ensureBuildToolDependencies(pkg: PackageJson): void {
314
- if (!pkg.devDependencies || typeof pkg.devDependencies !== 'object') {
315
- pkg.devDependencies = {};
316
- }
317
-
318
- const devDeps = pkg.devDependencies as Record<string, string>;
319
-
320
- if (!devDeps.vite) devDeps.vite = BUILD_TOOLS.VITE;
321
- if (!devDeps.typescript) devDeps.typescript = BUILD_TOOLS.TYPESCRIPT;
322
- if (!devDeps['@vitejs/plugin-react'])
323
- devDeps['@vitejs/plugin-react'] = BUILD_TOOLS.VITE_REACT_PLUGIN;
324
- if (!devDeps['@types/react']) devDeps['@types/react'] = REACT.TYPES_VERSION;
325
- if (!devDeps['@types/react-dom']) devDeps['@types/react-dom'] = REACT.TYPES_VERSION;
326
- }
327
-
328
- /**
329
- * Check if a @pie-framework or @pie-element/shared- package exists in the workspace
330
- *
331
- * Supports both legacy @pie-framework naming and new @pie-element/shared- naming:
332
- * - @pie-framework/mathquill → packages/shared/mathquill (legacy, should migrate)
333
- * - @pie-element/shared-mathquill → packages/shared/mathquill (new convention)
334
- */
335
- function isPieFrameworkWorkspacePackage(packageName: string, config: SyncConfig): boolean {
336
- let pkgName: string;
337
-
338
- if (packageName.startsWith(WORKSPACE.PIE_FRAMEWORK_PREFIX)) {
339
- // Legacy @pie-framework/* packages
340
- pkgName = packageName.replace(WORKSPACE.PIE_FRAMEWORK_PREFIX, '');
341
- } else if (packageName.startsWith(WORKSPACE.PIE_ELEMENT_PREFIX + 'shared-')) {
342
- // New @pie-element/shared-* packages
343
- pkgName = packageName.replace(WORKSPACE.PIE_ELEMENT_PREFIX + 'shared-', '');
344
- } else {
345
- return false;
346
- }
347
-
348
- const sharedPackagePath = join(config.pieElementsNg, 'packages/shared', pkgName, 'package.json');
349
- return existsSync(sharedPackagePath);
350
- }
351
-
352
- /**
353
- * Generate or update element package.json
354
- *
355
- * This function consolidates the ~400 lines of duplicated package.json management
356
- * logic from controllers-strategy and react-strategy into a single, maintainable function.
357
- */
358
- export async function ensureElementPackageJson(
359
- elementName: string,
360
- elementDir: string,
361
- config: SyncConfig
362
- ): Promise<boolean> {
363
- if (!existsSync(elementDir)) {
364
- return false;
365
- }
366
-
367
- const pkgPath = join(elementDir, 'package.json');
368
- const upstreamPkgPath = join(config.pieElements, 'packages', elementName, 'package.json');
369
-
370
- // Load existing package.json
371
- let pkg: PackageJson | null = null;
372
- if (existsSync(pkgPath)) {
373
- pkg = await loadPackageJson(pkgPath).catch(() => null);
374
- }
375
-
376
- // Load upstream package.json for dependency info
377
- const upstreamPkg = existsSync(upstreamPkgPath)
378
- ? await loadPackageJson(upstreamPkgPath).catch(() => null)
379
- : null;
380
-
381
- // Extract and normalize upstream dependencies
382
- const expectedDeps = extractUpstreamDependencies(upstreamPkg);
383
-
384
- // Scan source files for actual imports to catch dependencies from skipped directories
385
- const importedPackages = await extractImportsFromSources(elementDir);
386
-
387
- // Add workspace dependencies found in imports
388
- const currentPackageName = `${WORKSPACE.PIE_ELEMENT_PREFIX}${elementName}`;
389
- for (const imported of importedPackages) {
390
- // Skip self-dependencies (package importing from itself)
391
- if (imported === currentPackageName) {
392
- continue;
393
- }
394
-
395
- if (imported.startsWith(WORKSPACE.PIE_LIB_PREFIX)) {
396
- expectedDeps[imported] = WORKSPACE.VERSION;
397
- } else if (imported.startsWith(WORKSPACE.PIE_ELEMENT_PREFIX)) {
398
- expectedDeps[imported] = WORKSPACE.VERSION;
399
- } else if (imported.startsWith(WORKSPACE.PIE_FRAMEWORK_PREFIX)) {
400
- // Only add as workspace dependency if it actually exists in packages/shared/
401
- if (isPieFrameworkWorkspacePackage(imported, config)) {
402
- expectedDeps[imported] = WORKSPACE.VERSION;
403
- } else {
404
- // External @pie-framework package - add with latest version if not already in deps
405
- if (!expectedDeps[imported]) {
406
- expectedDeps[imported] = '^1.0.0'; // Use latest 1.x version as default
407
- }
408
- }
409
- }
410
- }
411
- await addTransitivePeerDependencies(expectedDeps, elementDir);
412
-
413
- // Create minimal package.json if missing
414
- if (!pkg) {
415
- pkg = {
416
- name: `${WORKSPACE.PIE_ELEMENT_PREFIX}${elementName}`,
417
- private: true,
418
- version: '0.1.0',
419
- description:
420
- (upstreamPkg?.description as string | undefined) ??
421
- `React implementation of ${elementName} element synced from pie-elements`,
422
- dependencies: expectedDeps,
423
- peerDependencies: {
424
- react: REACT.VERSION,
425
- 'react-dom': REACT.VERSION,
426
- },
427
- };
428
- }
429
-
430
- // Update dependencies to match upstream
431
- if (Object.keys(expectedDeps).length > 0) {
432
- pkg.dependencies = expectedDeps;
433
- }
434
-
435
- // Preserve pie metadata (if present upstream or locally)
436
- const pieMetadata = ((upstreamPkg as PackageJson | null | undefined)?.pie ??
437
- (pkg as PackageJson | null | undefined)?.pie ??
438
- undefined) as { capabilities?: string[] } | undefined;
439
-
440
- // Apply all standard transformations
441
- pkg = applyPackageJsonTransforms(pkg);
442
-
443
- if (pieMetadata) {
444
- pkg.pie = pieMetadata;
445
- }
446
-
447
- // Detect available entry points
448
- const entryPoints = detectEntryPoints(elementDir);
449
-
450
- // Generate exports based on entry points
451
- pkg.exports = generateExportsObject(entryPoints);
452
-
453
- // Warn when metadata/structure disagree for core capabilities
454
- const metadataCapabilities = Array.isArray(pieMetadata?.capabilities)
455
- ? new Set(pieMetadata.capabilities)
456
- : null;
457
-
458
- if (!entryPoints.hasDelivery || !entryPoints.hasController) {
459
- console.warn(
460
- `[upstream:update] ${elementName} missing required entry points:` +
461
- `${entryPoints.hasDelivery ? '' : ' delivery'}` +
462
- `${entryPoints.hasController ? '' : ' controller'}`
463
- );
464
- }
465
-
466
- if (metadataCapabilities) {
467
- if (metadataCapabilities.has('author') && !entryPoints.hasAuthor) {
468
- console.warn(
469
- `[upstream:update] ${elementName} metadata includes author but no src/author entry`
470
- );
471
- }
472
- if (metadataCapabilities.has('print') && !entryPoints.hasPrint) {
473
- console.warn(
474
- `[upstream:update] ${elementName} metadata includes print but no src/print entry`
475
- );
476
- }
477
- } else {
478
- if (entryPoints.hasAuthor) {
479
- console.warn(
480
- `[upstream:update] ${elementName} has src/author but no pie.capabilities metadata`
481
- );
482
- }
483
- if (entryPoints.hasPrint) {
484
- console.warn(
485
- `[upstream:update] ${elementName} has src/print but no pie.capabilities metadata`
486
- );
487
- }
488
- }
489
-
490
- // Set core package.json fields
491
- pkg.name = `${WORKSPACE.PIE_ELEMENT_PREFIX}${elementName}`;
492
- pkg.type = PACKAGE_DEFAULTS.TYPE;
493
- pkg.main = './dist/index.js';
494
- pkg.types = './dist/index.d.ts';
495
-
496
- // Ensure files array
497
- const files = Array.isArray(pkg.files) ? (pkg.files as unknown[]) : [];
498
- const normalizedFiles = new Set<string>(files.filter((v): v is string => typeof v === 'string'));
499
- normalizedFiles.add('dist');
500
- normalizedFiles.add('src');
501
- pkg.files = Array.from(normalizedFiles).sort();
502
-
503
- // Set sideEffects
504
- if (typeof pkg.sideEffects === 'undefined') {
505
- pkg.sideEffects = PACKAGE_DEFAULTS.SIDE_EFFECTS;
506
- }
507
-
508
- // Ensure devDependencies
509
- ensureBuildToolDependencies(pkg);
510
-
511
- // Ensure build scripts
512
- if (!pkg.scripts || typeof pkg.scripts !== 'object') {
513
- pkg.scripts = {};
514
- }
515
-
516
- const scripts = pkg.scripts as Record<string, string>;
517
- const hasIifeEntry =
518
- existsSync(join(elementDir, 'src/index.iife.ts')) ||
519
- existsSync(join(elementDir, 'vite.config.iife.ts'));
520
-
521
- scripts.build = hasIifeEntry ? SCRIPTS.BUILD_WITH_IIFE : SCRIPTS.BUILD;
522
- scripts.dev = SCRIPTS.DEV;
523
- scripts.demo = SCRIPTS.DEMO;
524
- scripts.test = SCRIPTS.TEST;
525
-
526
- // Check if content changed
527
- const nextContent = `${JSON.stringify(pkg, null, 2)}\n`;
528
- const currentContent = existsSync(pkgPath)
529
- ? await readFile(pkgPath, 'utf-8').catch(() => null)
530
- : null;
531
-
532
- if (currentContent === nextContent) {
533
- return false;
534
- }
535
-
536
- // Write updated package.json
537
- await writeFile(pkgPath, nextContent, 'utf-8');
538
- return true;
539
- }
540
-
541
- /**
542
- * Generate or update pie-lib package.json
543
- */
544
- export async function ensurePieLibPackageJson(
545
- pkgName: string,
546
- pkgDir: string,
547
- config: SyncConfig
548
- ): Promise<boolean> {
549
- if (!existsSync(pkgDir)) {
550
- return false;
551
- }
552
-
553
- const pkgPath = join(pkgDir, 'package.json');
554
- const upstreamPkgPath = join(config.pieLib, 'packages', pkgName, 'package.json');
555
-
556
- let pkg: PackageJson | null = null;
557
- if (existsSync(pkgPath)) {
558
- pkg = await loadPackageJson(pkgPath).catch(() => null);
559
- }
560
-
561
- const upstreamPkg = existsSync(upstreamPkgPath)
562
- ? await loadPackageJson(upstreamPkgPath).catch(() => null)
563
- : null;
564
-
565
- // Extract upstream dependencies
566
- const upstreamDeps = (upstreamPkg?.dependencies as Record<string, string> | undefined) ?? {};
567
- const expectedDeps: Record<string, string> = {};
568
-
569
- for (const [name, version] of Object.entries(upstreamDeps)) {
570
- // Transform @pie-framework/mathquill to @pie-element/shared-mathquill
571
- if (name === '@pie-framework/mathquill') {
572
- expectedDeps['@pie-element/shared-mathquill'] = WORKSPACE.VERSION;
573
- } else if (name.startsWith(WORKSPACE.PIE_LIB_PREFIX)) {
574
- expectedDeps[name] = WORKSPACE.VERSION;
575
- } else {
576
- expectedDeps[name] = version;
577
- }
578
- }
579
-
580
- const importedPackages = await extractImportsFromSources(pkgDir);
581
- for (const importedPkg of importedPackages) {
582
- if (importedPkg === '@pie-framework/mathquill') {
583
- expectedDeps['@pie-element/shared-mathquill'] = WORKSPACE.VERSION;
584
- continue;
585
- }
586
- if (importedPkg.startsWith(WORKSPACE.PIE_LIB_PREFIX)) {
587
- expectedDeps[importedPkg] = WORKSPACE.VERSION;
588
- continue;
589
- }
590
- if (importedPkg.startsWith(WORKSPACE.PIE_ELEMENT_PREFIX)) {
591
- expectedDeps[importedPkg] = WORKSPACE.VERSION;
592
- continue;
593
- }
594
-
595
- // Keep pie-lib package.json aligned with actual runtime imports from src/.
596
- // Upstream package.json can miss some third-party dependencies.
597
- if (!expectedDeps[importedPkg]) {
598
- const installedPkg = await findInstalledPackageJson(importedPkg, pkgDir);
599
- if (installedPkg?.version) {
600
- expectedDeps[importedPkg] = `^${installedPkg.version}`;
601
- } else {
602
- const inferredPeerVersion = await inferPeerVersionFromDeclaredDeps(
603
- importedPkg,
604
- expectedDeps,
605
- pkgDir
606
- );
607
- if (inferredPeerVersion) {
608
- expectedDeps[importedPkg] = inferredPeerVersion;
609
- }
610
- }
611
- }
612
- }
613
-
614
- // graphing imports @dnd-kit/core directly in source but upstream metadata can omit it.
615
- if (pkgName === 'graphing' && !expectedDeps['@dnd-kit/core']) {
616
- expectedDeps['@dnd-kit/core'] = '^6.3.0';
617
- }
618
-
619
- // Create minimal package.json if missing
620
- if (!pkg) {
621
- pkg = {
622
- name: `${WORKSPACE.PIE_LIB_PREFIX}${pkgName}`,
623
- private: true,
624
- version: '0.1.0',
625
- description:
626
- (upstreamPkg?.description as string | undefined) ??
627
- `React implementation of @pie-lib/${pkgName} synced from pie-lib`,
628
- dependencies: expectedDeps,
629
- };
630
- }
631
-
632
- // Update dependencies
633
- if (Object.keys(expectedDeps).length > 0) {
634
- pkg.dependencies = expectedDeps;
635
- }
636
-
637
- // Special handling for math-rendering: reference MathJax adapter package
638
- if (pkgName === 'math-rendering') {
639
- pkg.dependencies = {
640
- [`${WORKSPACE.PIE_ELEMENT_PREFIX}shared-math-rendering-mathjax`]: WORKSPACE.VERSION,
641
- };
642
- }
643
-
644
- // Generate exports
645
- const exportsObj: Record<string, unknown> = {
646
- ...(typeof pkg.exports === 'object' && pkg.exports
647
- ? (pkg.exports as Record<string, unknown>)
648
- : {}),
649
- };
650
-
651
- exportsObj['.'] = {
652
- types: './dist/index.d.ts',
653
- default: './dist/index.js',
654
- };
655
-
656
- pkg.name = `${WORKSPACE.PIE_LIB_PREFIX}${pkgName}`;
657
- pkg.type = PACKAGE_DEFAULTS.TYPE;
658
- pkg.main = './dist/index.js';
659
- pkg.types = './dist/index.d.ts';
660
- pkg.exports = exportsObj;
661
-
662
- // Ensure files array
663
- const files = Array.isArray(pkg.files) ? (pkg.files as unknown[]) : [];
664
- const normalizedFiles = new Set<string>(files.filter((v): v is string => typeof v === 'string'));
665
- normalizedFiles.add('dist');
666
- normalizedFiles.add('src');
667
- pkg.files = Array.from(normalizedFiles).sort();
668
-
669
- if (typeof pkg.sideEffects === 'undefined') {
670
- pkg.sideEffects = PACKAGE_DEFAULTS.SIDE_EFFECTS;
671
- }
672
-
673
- // Ensure build scripts
674
- if (!pkg.scripts || typeof pkg.scripts !== 'object') {
675
- pkg.scripts = {};
676
- }
677
-
678
- const scripts = pkg.scripts as Record<string, string>;
679
- scripts.build = SCRIPTS.BUILD;
680
- scripts.dev = SCRIPTS.DEV;
681
- scripts.test = SCRIPTS.TEST;
682
-
683
- const nextContent = `${JSON.stringify(pkg, null, 2)}\n`;
684
- const currentContent = existsSync(pkgPath)
685
- ? await readFile(pkgPath, 'utf-8').catch(() => null)
686
- : null;
687
-
688
- if (currentContent === nextContent) {
689
- return false;
690
- }
691
-
692
- await writeFile(pkgPath, nextContent, 'utf-8');
693
- return true;
694
- }