@motiadev/workbench 0.13.0-beta.162-846200 → 0.13.0-beta.162-813224

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 (237) hide show
  1. package/LICENSE +93 -21
  2. package/dist/index.d.ts +10 -189
  3. package/dist/index.html +1 -1
  4. package/dist/index.js +7 -1065
  5. package/dist/middleware.d.ts +8 -66
  6. package/dist/middleware.js +86 -684
  7. package/dist/motia-plugin/__tests__/generator.test.d.ts +1 -0
  8. package/dist/motia-plugin/__tests__/generator.test.js +97 -0
  9. package/dist/motia-plugin/__tests__/resolver.test.d.ts +1 -0
  10. package/dist/motia-plugin/__tests__/resolver.test.js +64 -0
  11. package/dist/motia-plugin/__tests__/validator.test.d.ts +1 -0
  12. package/dist/motia-plugin/__tests__/validator.test.js +59 -0
  13. package/dist/motia-plugin/generator.d.ts +78 -0
  14. package/dist/motia-plugin/{generator.ts → generator.js} +35 -37
  15. package/dist/motia-plugin/hmr.d.ts +22 -0
  16. package/dist/motia-plugin/hmr.js +100 -0
  17. package/dist/motia-plugin/index.d.ts +3 -0
  18. package/dist/motia-plugin/index.js +153 -0
  19. package/dist/motia-plugin/{resolver.ts → resolver.d.ts} +5 -38
  20. package/dist/motia-plugin/resolver.js +92 -0
  21. package/dist/motia-plugin/types.d.ts +169 -0
  22. package/dist/motia-plugin/types.js +36 -0
  23. package/dist/motia-plugin/{utils.ts → utils.d.ts} +4 -17
  24. package/dist/motia-plugin/utils.js +75 -0
  25. package/dist/motia-plugin/validator.d.ts +19 -0
  26. package/dist/motia-plugin/validator.js +163 -0
  27. package/dist/src/App.d.ts +2 -0
  28. package/dist/src/App.js +35 -0
  29. package/dist/src/components/NotFoundPage.d.ts +1 -0
  30. package/dist/src/components/NotFoundPage.js +3 -0
  31. package/dist/src/components/bottom-panel.d.ts +1 -0
  32. package/dist/src/components/bottom-panel.js +15 -0
  33. package/dist/src/components/flow/base-edge.d.ts +3 -0
  34. package/dist/src/components/flow/base-edge.js +39 -0
  35. package/dist/src/components/flow/flow-loader.d.ts +1 -0
  36. package/dist/src/components/flow/flow-loader.js +4 -0
  37. package/dist/src/components/flow/flow-page.d.ts +1 -0
  38. package/dist/src/components/flow/flow-page.js +25 -0
  39. package/dist/src/components/flow/flow-tab-menu-item.d.ts +1 -0
  40. package/dist/src/components/flow/flow-tab-menu-item.js +18 -0
  41. package/dist/src/components/flow/flow-view.d.ts +12 -0
  42. package/dist/src/components/flow/flow-view.js +22 -0
  43. package/dist/src/components/flow/hooks/use-get-flow-state.d.ts +10 -0
  44. package/dist/src/components/flow/hooks/use-get-flow-state.js +133 -0
  45. package/dist/src/components/flow/hooks/use-save-workflow-config.d.ts +2 -0
  46. package/dist/src/components/flow/hooks/use-save-workflow-config.js +22 -0
  47. package/dist/src/components/flow/node-organizer.d.ts +10 -0
  48. package/dist/src/components/flow/node-organizer.js +82 -0
  49. package/dist/src/components/flow/nodes/api-flow-node.d.ts +2 -0
  50. package/dist/src/components/flow/nodes/api-flow-node.js +5 -0
  51. package/dist/src/components/flow/nodes/cron-flow-node.d.ts +2 -0
  52. package/dist/src/components/flow/nodes/cron-flow-node.js +5 -0
  53. package/dist/src/components/flow/nodes/event-flow-node.d.ts +2 -0
  54. package/dist/src/components/flow/nodes/event-flow-node.js +5 -0
  55. package/dist/src/components/flow/nodes/noop-flow-node.d.ts +2 -0
  56. package/dist/src/components/flow/nodes/noop-flow-node.js +5 -0
  57. package/dist/src/components/header/deploy-button.d.ts +1 -0
  58. package/dist/src/components/header/deploy-button.js +28 -0
  59. package/dist/src/components/header/header.d.ts +2 -0
  60. package/dist/src/components/header/header.js +23 -0
  61. package/dist/src/components/root-motia.d.ts +2 -0
  62. package/dist/src/components/root-motia.js +7 -0
  63. package/dist/src/components/top-panel.d.ts +1 -0
  64. package/dist/src/components/top-panel.js +15 -0
  65. package/dist/src/components/tutorial/engine/tutorial-engine.d.ts +12 -0
  66. package/dist/src/components/tutorial/engine/tutorial-engine.js +36 -0
  67. package/dist/src/components/tutorial/engine/tutorial-types.d.ts +22 -0
  68. package/dist/src/components/tutorial/engine/tutorial-types.js +1 -0
  69. package/dist/src/components/tutorial/engine/workbench-xpath.d.ts +45 -0
  70. package/dist/src/components/tutorial/engine/workbench-xpath.js +45 -0
  71. package/dist/src/components/tutorial/hooks/tutorial-utils.d.ts +1 -0
  72. package/dist/src/components/tutorial/hooks/tutorial-utils.js +17 -0
  73. package/dist/src/components/tutorial/hooks/use-tutorial-engine.d.ts +15 -0
  74. package/dist/src/components/tutorial/hooks/use-tutorial-engine.js +183 -0
  75. package/dist/src/components/tutorial/hooks/use-tutorial.d.ts +5 -0
  76. package/dist/src/components/tutorial/hooks/use-tutorial.js +10 -0
  77. package/dist/src/components/tutorial/tutorial-button.d.ts +2 -0
  78. package/dist/src/components/tutorial/tutorial-button.js +21 -0
  79. package/dist/src/components/tutorial/tutorial-step.d.ts +14 -0
  80. package/dist/src/components/tutorial/tutorial-step.js +19 -0
  81. package/dist/src/components/tutorial/tutorial.css +2 -2
  82. package/dist/src/components/tutorial/tutorial.d.ts +2 -0
  83. package/dist/src/components/tutorial/tutorial.js +32 -0
  84. package/dist/src/components/ui/json-editor.d.ts +12 -0
  85. package/dist/src/components/ui/json-editor.js +35 -0
  86. package/dist/src/components/ui/table.d.ts +10 -0
  87. package/dist/src/components/ui/table.js +20 -0
  88. package/dist/src/components/ui/theme-toggle.d.ts +2 -0
  89. package/dist/src/components/ui/theme-toggle.js +19 -0
  90. package/dist/src/components/ui/tooltip.d.ts +6 -0
  91. package/dist/src/components/ui/tooltip.js +3 -0
  92. package/dist/src/hooks/use-debounced.d.ts +1 -0
  93. package/dist/src/hooks/use-debounced.js +18 -0
  94. package/dist/src/hooks/use-fetch-flows.d.ts +1 -0
  95. package/dist/src/hooks/use-fetch-flows.js +26 -0
  96. package/dist/src/hooks/use-mobile.d.ts +1 -0
  97. package/dist/src/hooks/use-mobile.js +15 -0
  98. package/dist/src/hooks/use-update-handle-positions.d.ts +10 -0
  99. package/dist/src/hooks/use-update-handle-positions.js +35 -0
  100. package/dist/src/index.css +5 -5
  101. package/dist/src/lib/__tests__/utils.test.d.ts +1 -0
  102. package/dist/src/lib/__tests__/utils.test.js +94 -0
  103. package/dist/src/lib/motia-analytics.d.ts +38 -0
  104. package/dist/src/lib/motia-analytics.js +132 -0
  105. package/dist/src/lib/plugins.d.ts +2 -0
  106. package/dist/src/lib/plugins.js +105 -0
  107. package/dist/src/lib/utils.d.ts +7 -0
  108. package/dist/src/lib/utils.js +34 -0
  109. package/dist/src/main.d.ts +2 -0
  110. package/dist/src/main.js +17 -0
  111. package/dist/src/project-view-mode.d.ts +1 -0
  112. package/dist/src/project-view-mode.js +20 -0
  113. package/dist/src/publicComponents/api-node.d.ts +5 -0
  114. package/dist/src/publicComponents/api-node.js +5 -0
  115. package/dist/src/publicComponents/base-node/base-handle.d.ts +9 -0
  116. package/dist/src/publicComponents/base-node/base-handle.js +8 -0
  117. package/dist/src/publicComponents/base-node/base-node.d.ts +15 -0
  118. package/dist/src/publicComponents/base-node/base-node.js +30 -0
  119. package/dist/src/publicComponents/base-node/code-display.d.ts +9 -0
  120. package/dist/src/publicComponents/base-node/code-display.js +64 -0
  121. package/dist/src/publicComponents/base-node/emits.d.ts +5 -0
  122. package/dist/src/publicComponents/base-node/emits.js +5 -0
  123. package/dist/src/publicComponents/base-node/feature-card.d.ts +10 -0
  124. package/dist/src/publicComponents/base-node/feature-card.js +5 -0
  125. package/dist/src/publicComponents/base-node/language-indicator.d.ts +10 -0
  126. package/dist/src/publicComponents/base-node/language-indicator.js +29 -0
  127. package/dist/src/publicComponents/base-node/node-header.d.ts +13 -0
  128. package/dist/src/publicComponents/base-node/node-header.js +30 -0
  129. package/dist/src/publicComponents/base-node/node-sidebar.d.ts +14 -0
  130. package/dist/src/publicComponents/base-node/node-sidebar.js +9 -0
  131. package/dist/src/publicComponents/base-node/subscribe.d.ts +4 -0
  132. package/dist/src/publicComponents/base-node/subscribe.js +4 -0
  133. package/dist/src/publicComponents/cron-node.d.ts +4 -0
  134. package/dist/src/publicComponents/cron-node.js +6 -0
  135. package/dist/src/publicComponents/event-node.d.ts +4 -0
  136. package/dist/src/publicComponents/event-node.js +5 -0
  137. package/dist/src/publicComponents/node-props.d.ts +21 -0
  138. package/dist/src/publicComponents/node-props.js +1 -0
  139. package/dist/src/publicComponents/noop-node.d.ts +4 -0
  140. package/dist/src/publicComponents/noop-node.js +5 -0
  141. package/dist/src/setupTests.d.ts +1 -0
  142. package/dist/src/setupTests.js +1 -0
  143. package/dist/src/stores/use-app-tabs-store.d.ts +16 -0
  144. package/dist/src/stores/use-app-tabs-store.js +31 -0
  145. package/dist/src/stores/use-flow-store.d.ts +21 -0
  146. package/dist/src/stores/use-flow-store.js +16 -0
  147. package/dist/src/stores/use-global-store.d.ts +18 -0
  148. package/dist/src/stores/use-global-store.js +12 -0
  149. package/dist/src/stores/use-motia-config-store.d.ts +12 -0
  150. package/dist/src/stores/use-motia-config-store.js +24 -0
  151. package/dist/src/stores/use-tabs-store.d.ts +19 -0
  152. package/dist/src/stores/use-tabs-store.js +22 -0
  153. package/dist/src/system-view-mode.d.ts +1 -0
  154. package/dist/src/system-view-mode.js +10 -0
  155. package/dist/src/types/endpoint.d.ts +14 -0
  156. package/dist/src/types/endpoint.js +1 -0
  157. package/dist/src/types/file.d.ts +7 -0
  158. package/dist/src/types/file.js +1 -0
  159. package/dist/src/types/flow.d.ts +115 -0
  160. package/dist/src/types/flow.js +1 -0
  161. package/dist/tsconfig.app.tsbuildinfo +1 -0
  162. package/dist/tsconfig.node.tsbuildinfo +1 -0
  163. package/package.json +51 -55
  164. package/dist/motia-plugin/__tests__/generator.test.ts +0 -129
  165. package/dist/motia-plugin/__tests__/resolver.test.ts +0 -82
  166. package/dist/motia-plugin/__tests__/validator.test.ts +0 -71
  167. package/dist/motia-plugin/hmr.ts +0 -123
  168. package/dist/motia-plugin/index.ts +0 -183
  169. package/dist/motia-plugin/types.ts +0 -198
  170. package/dist/motia-plugin/validator.ts +0 -197
  171. package/dist/src/App.tsx +0 -41
  172. package/dist/src/components/NotFoundPage.tsx +0 -11
  173. package/dist/src/components/bottom-panel.tsx +0 -39
  174. package/dist/src/components/flow/base-edge.tsx +0 -61
  175. package/dist/src/components/flow/flow-loader.tsx +0 -3
  176. package/dist/src/components/flow/flow-page.tsx +0 -75
  177. package/dist/src/components/flow/flow-tab-menu-item.tsx +0 -50
  178. package/dist/src/components/flow/flow-view.tsx +0 -66
  179. package/dist/src/components/flow/hooks/use-get-flow-state.tsx +0 -171
  180. package/dist/src/components/flow/hooks/use-save-workflow-config.ts +0 -25
  181. package/dist/src/components/flow/node-organizer.tsx +0 -103
  182. package/dist/src/components/flow/nodes/api-flow-node.tsx +0 -6
  183. package/dist/src/components/flow/nodes/cron-flow-node.tsx +0 -6
  184. package/dist/src/components/flow/nodes/event-flow-node.tsx +0 -6
  185. package/dist/src/components/flow/nodes/noop-flow-node.tsx +0 -6
  186. package/dist/src/components/header/deploy-button.tsx +0 -110
  187. package/dist/src/components/header/header.tsx +0 -39
  188. package/dist/src/components/root-motia.tsx +0 -10
  189. package/dist/src/components/top-panel.tsx +0 -40
  190. package/dist/src/components/tutorial/engine/tutorial-engine.ts +0 -26
  191. package/dist/src/components/tutorial/engine/tutorial-types.ts +0 -26
  192. package/dist/src/components/tutorial/engine/workbench-xpath.ts +0 -53
  193. package/dist/src/components/tutorial/hooks/tutorial-utils.ts +0 -26
  194. package/dist/src/components/tutorial/hooks/use-tutorial-engine.ts +0 -213
  195. package/dist/src/components/tutorial/hooks/use-tutorial.ts +0 -14
  196. package/dist/src/components/tutorial/tutorial-button.tsx +0 -46
  197. package/dist/src/components/tutorial/tutorial-step.tsx +0 -82
  198. package/dist/src/components/tutorial/tutorial.tsx +0 -59
  199. package/dist/src/components/ui/json-editor.tsx +0 -68
  200. package/dist/src/components/ui/table.tsx +0 -75
  201. package/dist/src/components/ui/theme-toggle.tsx +0 -54
  202. package/dist/src/components/ui/tooltip.tsx +0 -26
  203. package/dist/src/hooks/use-debounced.ts +0 -22
  204. package/dist/src/hooks/use-fetch-flows.ts +0 -33
  205. package/dist/src/hooks/use-mobile.ts +0 -19
  206. package/dist/src/hooks/use-update-handle-positions.ts +0 -42
  207. package/dist/src/lib/__tests__/utils.test.ts +0 -110
  208. package/dist/src/lib/motia-analytics.ts +0 -140
  209. package/dist/src/lib/plugins.tsx +0 -132
  210. package/dist/src/lib/utils.ts +0 -37
  211. package/dist/src/main.tsx +0 -30
  212. package/dist/src/project-view-mode.tsx +0 -32
  213. package/dist/src/publicComponents/api-node.tsx +0 -26
  214. package/dist/src/publicComponents/base-node/base-handle.tsx +0 -50
  215. package/dist/src/publicComponents/base-node/base-node.tsx +0 -114
  216. package/dist/src/publicComponents/base-node/code-display.tsx +0 -119
  217. package/dist/src/publicComponents/base-node/emits.tsx +0 -17
  218. package/dist/src/publicComponents/base-node/feature-card.tsx +0 -32
  219. package/dist/src/publicComponents/base-node/language-indicator.tsx +0 -131
  220. package/dist/src/publicComponents/base-node/node-header.tsx +0 -49
  221. package/dist/src/publicComponents/base-node/node-sidebar.tsx +0 -41
  222. package/dist/src/publicComponents/base-node/subscribe.tsx +0 -13
  223. package/dist/src/publicComponents/cron-node.tsx +0 -24
  224. package/dist/src/publicComponents/event-node.tsx +0 -20
  225. package/dist/src/publicComponents/node-props.tsx +0 -15
  226. package/dist/src/publicComponents/noop-node.tsx +0 -19
  227. package/dist/src/setupTests.ts +0 -1
  228. package/dist/src/stores/use-app-tabs-store.ts +0 -49
  229. package/dist/src/stores/use-flow-store.ts +0 -31
  230. package/dist/src/stores/use-global-store.ts +0 -24
  231. package/dist/src/stores/use-motia-config-store.ts +0 -36
  232. package/dist/src/stores/use-tabs-store.ts +0 -34
  233. package/dist/src/system-view-mode.tsx +0 -28
  234. package/dist/src/types/endpoint.ts +0 -12
  235. package/dist/src/types/file.ts +0 -7
  236. package/dist/src/types/flow.ts +0 -103
  237. package/eslint.config.cjs +0 -22
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const generator_1 = require("../generator");
4
+ describe('Generator', () => {
5
+ describe('generateImports', () => {
6
+ it('should generate import statements', () => {
7
+ const packages = ['@test/plugin-1', '@test/plugin-2'];
8
+ const imports = (0, generator_1.generateImports)(packages);
9
+ expect(imports).toContain("import * as plugin_0 from '@test/plugin-1'");
10
+ expect(imports).toContain("import * as plugin_1 from '@test/plugin-2'");
11
+ });
12
+ it('should handle empty package array', () => {
13
+ const imports = (0, generator_1.generateImports)([]);
14
+ expect(imports).toBe('');
15
+ });
16
+ });
17
+ describe('generatePackageMap', () => {
18
+ it('should generate package map', () => {
19
+ const packages = ['@test/plugin-1', '@test/plugin-2'];
20
+ const map = (0, generator_1.generatePackageMap)(packages);
21
+ expect(map).toContain('const packageMap');
22
+ expect(map).toContain("'@test/plugin-1': plugin_0");
23
+ expect(map).toContain("'@test/plugin-2': plugin_1");
24
+ });
25
+ });
26
+ describe('generatePluginLogic', () => {
27
+ it('should generate plugin processing logic', () => {
28
+ const plugins = [{ packageName: '@test/plugin', label: 'Test' }];
29
+ const logic = (0, generator_1.generatePluginLogic)(plugins);
30
+ expect(logic).toContain('const motiaPlugins');
31
+ expect(logic).toContain('export const plugins');
32
+ expect(logic).toContain('packageMap[plugin.packageName]');
33
+ });
34
+ });
35
+ describe('generatePluginCode', () => {
36
+ it('should generate complete module code', () => {
37
+ const plugins = [{ packageName: '@test/plugin', label: 'Test' }];
38
+ const code = (0, generator_1.generatePluginCode)(plugins);
39
+ expect(code).toContain('import * as plugin_0');
40
+ expect(code).toContain('const packageMap');
41
+ expect(code).toContain('export const plugins');
42
+ });
43
+ it('should handle empty plugins array', () => {
44
+ const code = (0, generator_1.generatePluginCode)([]);
45
+ expect(code).toBe('export const plugins = []');
46
+ });
47
+ it('should handle multiple plugins', () => {
48
+ const plugins = [{ packageName: '@test/plugin-1' }, { packageName: '@test/plugin-2' }];
49
+ const code = (0, generator_1.generatePluginCode)(plugins);
50
+ expect(code).toContain("'@test/plugin-1'");
51
+ expect(code).toContain("'@test/plugin-2'");
52
+ });
53
+ });
54
+ describe('generateCssImports', () => {
55
+ it('should generate CSS import statements', () => {
56
+ const plugins = [{ packageName: '@test/plugin', cssImports: ['styles.css', 'theme.css'] }];
57
+ const css = (0, generator_1.generateCssImports)(plugins);
58
+ expect(css).toContain("@import 'styles.css';");
59
+ expect(css).toContain("@import 'theme.css';");
60
+ });
61
+ it('should filter empty CSS imports', () => {
62
+ const plugins = [{ packageName: '@test/plugin', cssImports: ['styles.css', '', ' '] }];
63
+ const css = (0, generator_1.generateCssImports)(plugins);
64
+ expect(css).toContain("@import 'styles.css';");
65
+ expect(css).not.toContain("@import '';");
66
+ });
67
+ it('should return empty string for plugins without CSS imports', () => {
68
+ const plugins = [{ packageName: '@test/plugin' }];
69
+ const css = (0, generator_1.generateCssImports)(plugins);
70
+ expect(css).toBe('');
71
+ });
72
+ it('should flatten CSS imports from multiple plugins', () => {
73
+ const plugins = [
74
+ { packageName: '@test/plugin-1', cssImports: ['a.css'] },
75
+ { packageName: '@test/plugin-2', cssImports: ['b.css'] },
76
+ ];
77
+ const css = (0, generator_1.generateCssImports)(plugins);
78
+ expect(css).toContain("@import 'a.css';");
79
+ expect(css).toContain("@import 'b.css';");
80
+ });
81
+ });
82
+ describe('isValidCode', () => {
83
+ it('should return true for valid code', () => {
84
+ expect((0, generator_1.isValidCode)('export const plugins = []')).toBe(true);
85
+ });
86
+ it('should return false for empty string', () => {
87
+ expect((0, generator_1.isValidCode)('')).toBe(false);
88
+ });
89
+ it('should return false for whitespace only', () => {
90
+ expect((0, generator_1.isValidCode)(' \n\t ')).toBe(false);
91
+ });
92
+ it('should return false for non-string', () => {
93
+ expect((0, generator_1.isValidCode)(null)).toBe(false);
94
+ expect((0, generator_1.isValidCode)(undefined)).toBe(false);
95
+ });
96
+ });
97
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const resolver_1 = require("../resolver");
4
+ describe('Resolver', () => {
5
+ describe('resolvePluginPackage', () => {
6
+ it('should resolve local plugin', () => {
7
+ const plugin = { packageName: '~/plugins/local' };
8
+ const resolved = (0, resolver_1.resolvePluginPackage)(plugin);
9
+ expect(resolved.packageName).toBe('~/plugins/local');
10
+ expect(resolved.isLocal).toBe(true);
11
+ expect(resolved.resolvedPath).toContain('plugins/local');
12
+ expect(resolved.alias).toBe('~/plugins/local');
13
+ });
14
+ it('should resolve npm package', () => {
15
+ const plugin = { packageName: '@test/plugin' };
16
+ const resolved = (0, resolver_1.resolvePluginPackage)(plugin);
17
+ expect(resolved.packageName).toBe('@test/plugin');
18
+ expect(resolved.isLocal).toBe(false);
19
+ expect(resolved.resolvedPath).toContain('node_modules');
20
+ expect(resolved.resolvedPath).toContain('@test/plugin');
21
+ expect(resolved.alias).toBe('@test/plugin');
22
+ });
23
+ it('should normalize paths', () => {
24
+ const plugin = { packageName: 'simple-plugin' };
25
+ const resolved = (0, resolver_1.resolvePluginPackage)(plugin);
26
+ expect(resolved.resolvedPath).not.toContain('\\');
27
+ });
28
+ });
29
+ describe('createAliasConfig', () => {
30
+ it('should create aliases for all plugins', () => {
31
+ const plugins = [{ packageName: '~/plugins/local' }, { packageName: '@test/npm' }];
32
+ const aliases = (0, resolver_1.createAliasConfig)(plugins);
33
+ expect(aliases['~/plugins/local']).toBeDefined();
34
+ expect(aliases['@test/npm']).toBeDefined();
35
+ });
36
+ it('should handle duplicate package names', () => {
37
+ const plugins = [{ packageName: '@test/plugin' }, { packageName: '@test/plugin' }];
38
+ const aliases = (0, resolver_1.createAliasConfig)(plugins);
39
+ expect(Object.keys(aliases)).toHaveLength(1);
40
+ expect(aliases['@test/plugin']).toBeDefined();
41
+ });
42
+ it('should return empty object for empty plugins array', () => {
43
+ const aliases = (0, resolver_1.createAliasConfig)([]);
44
+ expect(aliases).toEqual({});
45
+ });
46
+ });
47
+ describe('getUniquePackageNames', () => {
48
+ it('should return unique package names', () => {
49
+ const plugins = [
50
+ { packageName: '@test/a' },
51
+ { packageName: '@test/b' },
52
+ { packageName: '@test/a' },
53
+ ];
54
+ const unique = (0, resolver_1.getUniquePackageNames)(plugins);
55
+ expect(unique).toHaveLength(2);
56
+ expect(unique).toContain('@test/a');
57
+ expect(unique).toContain('@test/b');
58
+ });
59
+ it('should return empty array for no plugins', () => {
60
+ const unique = (0, resolver_1.getUniquePackageNames)([]);
61
+ expect(unique).toEqual([]);
62
+ });
63
+ });
64
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const validator_1 = require("../validator");
4
+ describe('Validator', () => {
5
+ describe('validatePlugins', () => {
6
+ it('should validate array of valid plugins', () => {
7
+ const plugins = [
8
+ { packageName: '@test/plugin-1', label: 'Plugin 1' },
9
+ { packageName: '@test/plugin-2', label: 'Plugin 2' },
10
+ ];
11
+ const result = (0, validator_1.validatePlugins)(plugins);
12
+ expect(result.valid).toBe(true);
13
+ expect(result.errors).toHaveLength(0);
14
+ });
15
+ it('should reject non-array input', () => {
16
+ const result = (0, validator_1.validatePlugins)('not-an-array');
17
+ expect(result.valid).toBe(false);
18
+ expect(result.errors.some((err) => err.includes('array'))).toBe(true);
19
+ });
20
+ it('should handle empty array', () => {
21
+ const result = (0, validator_1.validatePlugins)([]);
22
+ expect(result.valid).toBe(true);
23
+ expect(result.warnings.some((w) => w.includes('No plugins'))).toBe(true);
24
+ });
25
+ it('should collect all errors from multiple plugins', () => {
26
+ const plugins = [{ packageName: '' }, { packageName: '' }, { packageName: 'valid' }];
27
+ const result = (0, validator_1.validatePlugins)(plugins);
28
+ expect(result.valid).toBe(false);
29
+ expect(result.errors.length).toBeGreaterThanOrEqual(2);
30
+ });
31
+ it('should warn about duplicate package names', () => {
32
+ const plugins = [
33
+ { packageName: '@test/plugin', label: 'Plugin 1' },
34
+ { packageName: '@test/plugin', label: 'Plugin 2' },
35
+ ];
36
+ const result = (0, validator_1.validatePlugins)(plugins);
37
+ expect(result.valid).toBe(true);
38
+ expect(result.warnings.some((w) => w.includes('Duplicate'))).toBe(true);
39
+ });
40
+ it('should support failFast option', () => {
41
+ const plugins = [{ packageName: '' }, { packageName: '' }];
42
+ const result = (0, validator_1.validatePlugins)(plugins, { failFast: true });
43
+ expect(result.valid).toBe(false);
44
+ // With failFast, should stop after first plugin validation fails
45
+ // Each plugin with empty packageName generates 2 errors (min length + invalid format)
46
+ // So failFast should result in only the first plugin's errors
47
+ expect(result.errors.length).toBeLessThanOrEqual(2);
48
+ // Verify it didn't process second plugin by checking error messages don't mention index 1
49
+ const hasIndex1Error = result.errors.some((err) => err.includes('index 1'));
50
+ expect(hasIndex1Error).toBe(false);
51
+ });
52
+ it('should handle mixed valid and invalid plugins', () => {
53
+ const plugins = [{ packageName: '@test/valid' }, { packageName: '' }, { packageName: '@test/another-valid' }];
54
+ const result = (0, validator_1.validatePlugins)(plugins);
55
+ expect(result.valid).toBe(false);
56
+ expect(result.errors.length).toBeGreaterThan(0);
57
+ });
58
+ });
59
+ });
@@ -0,0 +1,78 @@
1
+ import type { WorkbenchPlugin } from './types';
2
+ /**
3
+ * Generates import statements for all unique plugin packages.
4
+ *
5
+ * @param packages - Array of unique package names
6
+ * @returns JavaScript code string with import statements
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * generateImports(['@org/plugin-1', '~/plugins/local'])
11
+ * // Returns:
12
+ * // import * as plugin_0 from '@org/plugin-1'
13
+ * // import * as plugin_1 from '~/plugins/local'
14
+ * ```
15
+ */
16
+ export declare function generateImports(packages: string[]): string;
17
+ /**
18
+ * Generates the package map that links package names to their imported modules.
19
+ *
20
+ * @param packages - Array of unique package names
21
+ * @returns JavaScript code string defining the package map
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * generatePackageMap(['@org/plugin-1', '~/plugins/local'])
26
+ * // Returns: const packageMap = {'@org/plugin-1': plugin_0,'~/plugins/local': plugin_1}
27
+ * ```
28
+ */
29
+ export declare function generatePackageMap(packages: string[]): string;
30
+ /**
31
+ * Generates the plugin transformation logic that processes plugin configurations.
32
+ *
33
+ * @param plugins - Array of plugin configurations
34
+ * @returns JavaScript code string with plugin processing logic
35
+ */
36
+ export declare function generatePluginLogic(plugins: WorkbenchPlugin[]): string;
37
+ /**
38
+ * Generates the complete virtual module code for all plugins.
39
+ * This is the main code generation function that combines all parts.
40
+ *
41
+ * @param plugins - Array of plugin configurations
42
+ * @returns Complete JavaScript code string for the virtual module
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const plugins = [
47
+ * { packageName: '@test/plugin', label: 'Test' }
48
+ * ]
49
+ * const code = generatePluginCode(plugins)
50
+ * // Returns complete module code with imports, map, and logic
51
+ * ```
52
+ */
53
+ export declare function generatePluginCode(plugins: WorkbenchPlugin[]): string;
54
+ /**
55
+ * Generates CSS imports for plugins that specify cssImports.
56
+ *
57
+ * @param plugins - Array of plugin configurations
58
+ * @returns CSS import statements as a string
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const plugins = [
63
+ * { packageName: '@test/plugin', cssImports: ['styles.css', 'theme.css'] }
64
+ * ]
65
+ * generateCssImports(plugins)
66
+ * // Returns:
67
+ * // @import 'styles.css';
68
+ * // @import 'theme.css';
69
+ * ```
70
+ */
71
+ export declare function generateCssImports(plugins: WorkbenchPlugin[]): string;
72
+ /**
73
+ * Checks if the generated code is valid (non-empty and has content).
74
+ *
75
+ * @param code - The generated code to check
76
+ * @returns True if code is valid
77
+ */
78
+ export declare function isValidCode(code: string): boolean;
@@ -1,6 +1,12 @@
1
- import { getUniquePackageNames } from './resolver'
2
- import type { WorkbenchPlugin } from './types'
3
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateImports = generateImports;
4
+ exports.generatePackageMap = generatePackageMap;
5
+ exports.generatePluginLogic = generatePluginLogic;
6
+ exports.generatePluginCode = generatePluginCode;
7
+ exports.generateCssImports = generateCssImports;
8
+ exports.isValidCode = isValidCode;
9
+ const resolver_1 = require("./resolver");
4
10
  /**
5
11
  * Generates import statements for all unique plugin packages.
6
12
  *
@@ -15,10 +21,9 @@ import type { WorkbenchPlugin } from './types'
15
21
  * // import * as plugin_1 from '~/plugins/local'
16
22
  * ```
17
23
  */
18
- export function generateImports(packages: string[]): string {
19
- return packages.map((packageName, index) => `import * as plugin_${index} from '${packageName}'`).join('\n')
24
+ function generateImports(packages) {
25
+ return packages.map((packageName, index) => `import * as plugin_${index} from '${packageName}'`).join('\n');
20
26
  }
21
-
22
27
  /**
23
28
  * Generates the package map that links package names to their imported modules.
24
29
  *
@@ -31,19 +36,18 @@ export function generateImports(packages: string[]): string {
31
36
  * // Returns: const packageMap = {'@org/plugin-1': plugin_0,'~/plugins/local': plugin_1}
32
37
  * ```
33
38
  */
34
- export function generatePackageMap(packages: string[]): string {
35
- const entries = packages.map((packageName, index) => `'${packageName}': plugin_${index}`)
36
- return `const packageMap = {${entries.join(',')}}`
39
+ function generatePackageMap(packages) {
40
+ const entries = packages.map((packageName, index) => `'${packageName}': plugin_${index}`);
41
+ return `const packageMap = {${entries.join(',')}}`;
37
42
  }
38
-
39
43
  /**
40
44
  * Generates the plugin transformation logic that processes plugin configurations.
41
45
  *
42
46
  * @param plugins - Array of plugin configurations
43
47
  * @returns JavaScript code string with plugin processing logic
44
48
  */
45
- export function generatePluginLogic(plugins: WorkbenchPlugin[]): string {
46
- return `
49
+ function generatePluginLogic(plugins) {
50
+ return `
47
51
  const motiaPlugins = ${JSON.stringify(plugins)}
48
52
 
49
53
  export const plugins = motiaPlugins.map((plugin) => {
@@ -59,9 +63,8 @@ export function generatePluginLogic(plugins: WorkbenchPlugin[]): string {
59
63
  component: componentName ? component[componentName] : component.default,
60
64
  }
61
65
  })
62
- `
66
+ `;
63
67
  }
64
-
65
68
  /**
66
69
  * Generates the complete virtual module code for all plugins.
67
70
  * This is the main code generation function that combines all parts.
@@ -78,21 +81,18 @@ export function generatePluginLogic(plugins: WorkbenchPlugin[]): string {
78
81
  * // Returns complete module code with imports, map, and logic
79
82
  * ```
80
83
  */
81
- export function generatePluginCode(plugins: WorkbenchPlugin[]): string {
82
- if (!plugins || plugins.length === 0) {
83
- return 'export const plugins = []'
84
- }
85
-
86
- const packages = getUniquePackageNames(plugins)
87
- const imports = generateImports(packages)
88
- const packageMap = generatePackageMap(packages)
89
- const logic = generatePluginLogic(plugins)
90
-
91
- return `${imports}
84
+ function generatePluginCode(plugins) {
85
+ if (!plugins || plugins.length === 0) {
86
+ return 'export const plugins = []';
87
+ }
88
+ const packages = (0, resolver_1.getUniquePackageNames)(plugins);
89
+ const imports = generateImports(packages);
90
+ const packageMap = generatePackageMap(packages);
91
+ const logic = generatePluginLogic(plugins);
92
+ return `${imports}
92
93
  ${packageMap}
93
- ${logic}`
94
+ ${logic}`;
94
95
  }
95
-
96
96
  /**
97
97
  * Generates CSS imports for plugins that specify cssImports.
98
98
  *
@@ -110,21 +110,19 @@ ${logic}`
110
110
  * // @import 'theme.css';
111
111
  * ```
112
112
  */
113
- export function generateCssImports(plugins: WorkbenchPlugin[]): string {
114
- const cssImports = plugins
115
- .flatMap((plugin) => plugin.cssImports || [])
116
- .filter((cssImport) => cssImport && cssImport.trim() !== '')
117
- .map((cssImport) => `@import '${cssImport}';`)
118
-
119
- return cssImports.join('\n')
113
+ function generateCssImports(plugins) {
114
+ const cssImports = plugins
115
+ .flatMap((plugin) => plugin.cssImports || [])
116
+ .filter((cssImport) => cssImport && cssImport.trim() !== '')
117
+ .map((cssImport) => `@import '${cssImport}';`);
118
+ return cssImports.join('\n');
120
119
  }
121
-
122
120
  /**
123
121
  * Checks if the generated code is valid (non-empty and has content).
124
122
  *
125
123
  * @param code - The generated code to check
126
124
  * @returns True if code is valid
127
125
  */
128
- export function isValidCode(code: string): boolean {
129
- return typeof code === 'string' && code.trim().length > 0
126
+ function isValidCode(code) {
127
+ return typeof code === 'string' && code.trim().length > 0;
130
128
  }
@@ -0,0 +1,22 @@
1
+ import type { Printer } from '@motiadev/core';
2
+ import type { HmrContext, ModuleNode } from 'vite';
3
+ import type { WorkbenchPlugin } from './types';
4
+ export declare function isConfigFile(file: string): boolean;
5
+ /**
6
+ * Checks if a file change should trigger HMR for plugins.
7
+ *
8
+ * @param file - The file path that changed
9
+ * @param plugins - Current plugin configurations
10
+ * @returns True if the change affects plugins
11
+ */
12
+ export declare function shouldInvalidatePlugins(file: string, plugins: WorkbenchPlugin[]): boolean;
13
+ /**
14
+ * Handles hot updates for the plugin system.
15
+ * This function is called by Vite's handleHotUpdate hook.
16
+ *
17
+ * @param ctx - Vite's HMR context
18
+ * @param plugins - Current plugin configurations
19
+ * @param printer - Printer instance for logging
20
+ * @returns Array of modules to update, or undefined to continue with default behavior
21
+ */
22
+ export declare function handlePluginHotUpdate(ctx: HmrContext, plugins: WorkbenchPlugin[], printer: Printer): ModuleNode[] | undefined;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isConfigFile = isConfigFile;
7
+ exports.shouldInvalidatePlugins = shouldInvalidatePlugins;
8
+ exports.handlePluginHotUpdate = handlePluginHotUpdate;
9
+ const path_1 = __importDefault(require("path"));
10
+ const resolver_1 = require("./resolver");
11
+ const types_1 = require("./types");
12
+ const utils_1 = require("./utils");
13
+ const WATCHED_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.css', '.scss', '.less'];
14
+ function isConfigFile(file) {
15
+ const normalizedFile = (0, utils_1.normalizePath)(file);
16
+ return normalizedFile.endsWith('motia.config.ts') || normalizedFile.endsWith('motia.config.js');
17
+ }
18
+ /**
19
+ * Checks if a file change should trigger HMR for plugins.
20
+ *
21
+ * @param file - The file path that changed
22
+ * @param plugins - Current plugin configurations
23
+ * @returns True if the change affects plugins
24
+ */
25
+ function shouldInvalidatePlugins(file, plugins) {
26
+ const normalizedFile = (0, utils_1.normalizePath)(file);
27
+ const absoluteFile = path_1.default.isAbsolute(normalizedFile) ? normalizedFile : path_1.default.resolve(process.cwd(), normalizedFile);
28
+ if (isConfigFile(file)) {
29
+ return true;
30
+ }
31
+ const hasWatchedExtension = WATCHED_EXTENSIONS.some((ext) => absoluteFile.endsWith(ext));
32
+ if (!hasWatchedExtension) {
33
+ return false;
34
+ }
35
+ for (const plugin of plugins) {
36
+ if ((0, utils_1.isLocalPlugin)(plugin.packageName)) {
37
+ const resolved = (0, resolver_1.resolvePluginPackage)(plugin);
38
+ const pluginAbsolutePath = path_1.default.isAbsolute(resolved.resolvedPath)
39
+ ? resolved.resolvedPath
40
+ : path_1.default.resolve(process.cwd(), resolved.resolvedPath);
41
+ const normalizedPluginPath = pluginAbsolutePath.endsWith(path_1.default.sep)
42
+ ? pluginAbsolutePath
43
+ : `${pluginAbsolutePath}${path_1.default.sep}`;
44
+ if (absoluteFile.startsWith(normalizedPluginPath) || absoluteFile === pluginAbsolutePath) {
45
+ return true;
46
+ }
47
+ }
48
+ }
49
+ return false;
50
+ }
51
+ /**
52
+ * Handles hot updates for the plugin system.
53
+ * This function is called by Vite's handleHotUpdate hook.
54
+ *
55
+ * @param ctx - Vite's HMR context
56
+ * @param plugins - Current plugin configurations
57
+ * @param printer - Printer instance for logging
58
+ * @returns Array of modules to update, or undefined to continue with default behavior
59
+ */
60
+ function handlePluginHotUpdate(ctx, plugins, printer) {
61
+ const { file, server, timestamp } = ctx;
62
+ printer.printPluginLog(`HMR: File changed: ${(0, utils_1.normalizePath)(file)}`);
63
+ if (isConfigFile(file)) {
64
+ printer.printPluginLog('HMR: Config file changed, triggering full page reload');
65
+ printer.printPluginWarn('Configuration changes require a server restart for full effect. Please restart the dev server to apply all changes.');
66
+ server.ws.send({
67
+ type: 'full-reload',
68
+ path: '*',
69
+ });
70
+ return;
71
+ }
72
+ if (!shouldInvalidatePlugins(file, plugins)) {
73
+ printer.printPluginLog('HMR: Change outside plugin scope, delegating to Vite default handling');
74
+ return;
75
+ }
76
+ printer.printPluginLog('HMR: Plugin change detected, invalidating virtual module');
77
+ const virtualModule = server.moduleGraph.getModuleById(types_1.CONSTANTS.RESOLVED_VIRTUAL_MODULE_ID);
78
+ if (!virtualModule) {
79
+ printer.printPluginWarn('HMR: Virtual module not found, triggering full reload as fallback');
80
+ server.ws.send({
81
+ type: 'full-reload',
82
+ path: '*',
83
+ });
84
+ return;
85
+ }
86
+ server.moduleGraph.invalidateModule(virtualModule, new Set(), timestamp);
87
+ printer.printPluginLog('HMR: Virtual module invalidated');
88
+ const modulesToUpdateSet = new Set([virtualModule]);
89
+ const processedModules = new Set([virtualModule]);
90
+ for (const importer of virtualModule.importers) {
91
+ if (!processedModules.has(importer)) {
92
+ processedModules.add(importer);
93
+ modulesToUpdateSet.add(importer);
94
+ server.moduleGraph.invalidateModule(importer, new Set(), timestamp);
95
+ }
96
+ }
97
+ const modulesToUpdate = Array.from(modulesToUpdateSet);
98
+ printer.printPluginLog(`HMR: Updated ${modulesToUpdate.length} module(s)`);
99
+ return modulesToUpdate;
100
+ }
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vite';
2
+ import type { WorkbenchPlugin } from './types';
3
+ export default function motiaPluginsPlugin(plugins: WorkbenchPlugin[]): Plugin;