@motiadev/workbench 0.8.2-beta.140-628177 → 0.8.2-beta.140-111855

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 (142) hide show
  1. package/dist/components.json +1 -1
  2. package/dist/index.d.ts +7 -7
  3. package/dist/index.js +5 -5
  4. package/dist/middleware.d.ts +1 -1
  5. package/dist/middleware.js +3 -3
  6. package/dist/motia-plugin/__tests__/generator.test.js +97 -0
  7. package/dist/motia-plugin/__tests__/resolver.test.d.ts +1 -0
  8. package/dist/motia-plugin/__tests__/resolver.test.js +64 -0
  9. package/dist/motia-plugin/__tests__/validator.test.d.ts +1 -0
  10. package/dist/motia-plugin/__tests__/validator.test.js +59 -0
  11. package/dist/motia-plugin/generator.d.ts +78 -0
  12. package/dist/motia-plugin/generator.js +128 -0
  13. package/dist/motia-plugin/hmr.d.ts +19 -0
  14. package/dist/motia-plugin/hmr.js +66 -0
  15. package/dist/motia-plugin/index.d.ts +27 -0
  16. package/dist/motia-plugin/index.js +118 -0
  17. package/dist/motia-plugin/resolver.d.ts +63 -0
  18. package/dist/motia-plugin/resolver.js +92 -0
  19. package/dist/motia-plugin/types.d.ts +169 -0
  20. package/dist/motia-plugin/types.js +36 -0
  21. package/dist/motia-plugin/utils.d.ts +57 -0
  22. package/dist/motia-plugin/utils.js +75 -0
  23. package/dist/motia-plugin/validator.d.ts +19 -0
  24. package/dist/motia-plugin/validator.js +163 -0
  25. package/dist/postcss.config.mjs +1 -1
  26. package/dist/src/App.d.ts +1 -1
  27. package/dist/src/App.js +1 -18
  28. package/dist/src/components/flow/base-edge.d.ts +2 -2
  29. package/dist/src/components/flow/base-edge.js +1 -1
  30. package/dist/src/components/flow/flow-page.js +2 -2
  31. package/dist/src/components/flow/flow-tab-menu-item.js +2 -2
  32. package/dist/src/components/flow/flow-view.d.ts +3 -3
  33. package/dist/src/components/flow/hooks/use-get-flow-state.d.ts +2 -2
  34. package/dist/src/components/flow/hooks/use-get-flow-state.js +0 -4
  35. package/dist/src/components/flow/hooks/use-save-workflow-config.d.ts +1 -1
  36. package/dist/src/components/flow/node-organizer.d.ts +3 -3
  37. package/dist/src/components/flow/nodes/api-flow-node.d.ts +1 -1
  38. package/dist/src/components/flow/nodes/cron-flow-node.d.ts +1 -1
  39. package/dist/src/components/flow/nodes/event-flow-node.d.ts +1 -1
  40. package/dist/src/components/flow/nodes/noop-flow-node.d.ts +1 -1
  41. package/dist/src/components/header/deploy-button.js +2 -2
  42. package/dist/src/components/header/header.d.ts +1 -1
  43. package/dist/src/components/header/header.js +2 -2
  44. package/dist/src/components/root-motia.d.ts +2 -1
  45. package/dist/src/components/tutorial/engine/tutorial-engine.d.ts +1 -1
  46. package/dist/src/components/tutorial/hooks/use-tutorial-engine.d.ts +1 -1
  47. package/dist/src/components/tutorial/hooks/use-tutorial.d.ts +1 -1
  48. package/dist/src/components/tutorial/tutorial-button.d.ts +1 -1
  49. package/dist/src/components/tutorial/tutorial-button.js +1 -1
  50. package/dist/src/components/tutorial/tutorial-step.d.ts +2 -2
  51. package/dist/src/components/tutorial/tutorial-step.js +1 -1
  52. package/dist/src/components/tutorial/tutorial.css +8 -8
  53. package/dist/src/components/ui/json-editor.d.ts +1 -1
  54. package/dist/src/components/ui/json-editor.js +1 -1
  55. package/dist/src/components/ui/table.js +1 -1
  56. package/dist/src/components/ui/theme-toggle.d.ts +1 -1
  57. package/dist/src/components/ui/tooltip.d.ts +1 -1
  58. package/dist/src/hooks/use-fetch-flows.js +1 -1
  59. package/dist/src/hooks/use-update-handle-positions.d.ts +1 -1
  60. package/dist/src/index.css +5 -5
  61. package/dist/src/lib/plugins.js +3 -3
  62. package/dist/src/main.js +2 -3
  63. package/dist/src/project-view-mode.js +1 -1
  64. package/dist/src/publicComponents/api-node.d.ts +2 -2
  65. package/dist/src/publicComponents/base-node/base-handle.d.ts +3 -2
  66. package/dist/src/publicComponents/base-node/base-node.d.ts +3 -2
  67. package/dist/src/publicComponents/base-node/base-node.js +1 -1
  68. package/dist/src/publicComponents/base-node/code-display.d.ts +2 -2
  69. package/dist/src/publicComponents/base-node/code-display.js +1 -1
  70. package/dist/src/publicComponents/base-node/emits.d.ts +2 -2
  71. package/dist/src/publicComponents/base-node/feature-card.d.ts +2 -2
  72. package/dist/src/publicComponents/base-node/language-indicator.d.ts +2 -2
  73. package/dist/src/publicComponents/base-node/node-header.d.ts +3 -2
  74. package/dist/src/publicComponents/base-node/node-sidebar.d.ts +2 -2
  75. package/dist/src/publicComponents/base-node/subscribe.d.ts +1 -1
  76. package/dist/src/publicComponents/cron-node.d.ts +3 -2
  77. package/dist/src/publicComponents/event-node.d.ts +3 -2
  78. package/dist/src/publicComponents/node-props.d.ts +1 -1
  79. package/dist/src/publicComponents/noop-node.d.ts +3 -2
  80. package/dist/src/stores/use-global-store.d.ts +0 -6
  81. package/dist/src/stores/use-global-store.js +0 -6
  82. package/dist/src/types/flow.d.ts +1 -1
  83. package/dist/tsconfig.app.tsbuildinfo +1 -1
  84. package/dist/tsconfig.node.tsbuildinfo +1 -1
  85. package/motia-plugin/__tests__/generator.test.ts +129 -0
  86. package/motia-plugin/__tests__/resolver.test.ts +82 -0
  87. package/motia-plugin/__tests__/validator.test.ts +71 -0
  88. package/motia-plugin/generator.ts +130 -0
  89. package/motia-plugin/hmr.ts +78 -0
  90. package/motia-plugin/index.ts +143 -0
  91. package/motia-plugin/resolver.ts +96 -0
  92. package/motia-plugin/types.ts +198 -0
  93. package/motia-plugin/utils.ts +70 -0
  94. package/motia-plugin/validator.ts +197 -0
  95. package/package.json +9 -9
  96. package/postcss.config.mjs +1 -1
  97. package/dist/src/components/observability/events/code/function-call.d.ts +0 -13
  98. package/dist/src/components/observability/events/code/function-call.js +0 -16
  99. package/dist/src/components/observability/events/event-icon.d.ts +0 -7
  100. package/dist/src/components/observability/events/event-icon.js +0 -16
  101. package/dist/src/components/observability/events/trace-emit-event.d.ts +0 -5
  102. package/dist/src/components/observability/events/trace-emit-event.js +0 -5
  103. package/dist/src/components/observability/events/trace-event.d.ts +0 -5
  104. package/dist/src/components/observability/events/trace-event.js +0 -20
  105. package/dist/src/components/observability/events/trace-log-event.d.ts +0 -5
  106. package/dist/src/components/observability/events/trace-log-event.js +0 -5
  107. package/dist/src/components/observability/events/trace-state-event.d.ts +0 -5
  108. package/dist/src/components/observability/events/trace-state-event.js +0 -5
  109. package/dist/src/components/observability/events/trace-stream-event.d.ts +0 -5
  110. package/dist/src/components/observability/events/trace-stream-event.js +0 -5
  111. package/dist/src/components/observability/hooks/use-get-endtime.d.ts +0 -2
  112. package/dist/src/components/observability/hooks/use-get-endtime.js +0 -15
  113. package/dist/src/components/observability/trace-item/trace-item-detail.d.ts +0 -8
  114. package/dist/src/components/observability/trace-item/trace-item-detail.js +0 -10
  115. package/dist/src/components/observability/trace-item/trace-item.d.ts +0 -10
  116. package/dist/src/components/observability/trace-item/trace-item.js +0 -14
  117. package/dist/src/components/observability/trace-status.d.ts +0 -8
  118. package/dist/src/components/observability/trace-status.js +0 -18
  119. package/dist/src/components/observability/trace-tab-label.d.ts +0 -1
  120. package/dist/src/components/observability/trace-tab-label.js +0 -5
  121. package/dist/src/components/observability/trace-timeline.d.ts +0 -6
  122. package/dist/src/components/observability/trace-timeline.js +0 -30
  123. package/dist/src/components/observability/traces-groups.d.ts +0 -9
  124. package/dist/src/components/observability/traces-groups.js +0 -9
  125. package/dist/src/components/observability/traces-page.d.ts +0 -1
  126. package/dist/src/components/observability/traces-page.js +0 -33
  127. package/dist/src/components/states/hooks/states-hooks.d.ts +0 -13
  128. package/dist/src/components/states/hooks/states-hooks.js +0 -26
  129. package/dist/src/components/states/state-details.d.ts +0 -7
  130. package/dist/src/components/states/state-details.js +0 -3
  131. package/dist/src/components/states/state-editor.d.ts +0 -7
  132. package/dist/src/components/states/state-editor.js +0 -71
  133. package/dist/src/components/states/state-sidebar.d.ts +0 -8
  134. package/dist/src/components/states/state-sidebar.js +0 -17
  135. package/dist/src/components/states/state-tab-label.d.ts +0 -1
  136. package/dist/src/components/states/state-tab-label.js +0 -5
  137. package/dist/src/components/states/states-page.d.ts +0 -1
  138. package/dist/src/components/states/states-page.js +0 -56
  139. package/dist/src/types/observability.d.ts +0 -78
  140. package/dist/vite-plugin-motia-plugins.d.ts +0 -9
  141. package/dist/vite-plugin-motia-plugins.js +0 -69
  142. /package/dist/{src/types/observability.js → motia-plugin/__tests__/generator.test.d.ts} +0 -0
@@ -18,4 +18,4 @@
18
18
  "hooks": "@/hooks"
19
19
  },
20
20
  "iconLibrary": "lucide"
21
- }
21
+ }
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- export { EventNode } from './src/publicComponents/event-node';
2
- export { ApiNode } from './src/publicComponents/api-node';
3
- export { NoopNode } from './src/publicComponents/noop-node';
4
- export { BaseNode } from './src/publicComponents/base-node/base-node';
5
- export { BaseHandle } from './src/publicComponents/base-node/base-handle';
6
1
  export { Position } from '@xyflow/react';
7
- export type { EventNodeData, ApiNodeData } from './src/types/flow';
8
- export type { ApiNodeProps, BaseNodeProps, CronNodeProps, EventNodeProps, NoopNodeProps, } from './src/publicComponents/node-props';
9
2
  export type { TutorialStep } from './src/components/tutorial/engine/tutorial-types';
10
3
  export { workbenchXPath } from './src/components/tutorial/engine/workbench-xpath';
4
+ export { ApiNode } from './src/publicComponents/api-node';
5
+ export { BaseHandle } from './src/publicComponents/base-node/base-handle';
6
+ export { BaseNode } from './src/publicComponents/base-node/base-node';
7
+ export { EventNode } from './src/publicComponents/event-node';
8
+ export type { ApiNodeProps, BaseNodeProps, CronNodeProps, EventNodeProps, NoopNodeProps, } from './src/publicComponents/node-props';
9
+ export { NoopNode } from './src/publicComponents/noop-node';
10
+ export type { ApiNodeData, EventNodeData } from './src/types/flow';
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- export { EventNode } from './src/publicComponents/event-node';
2
- export { ApiNode } from './src/publicComponents/api-node';
3
- export { NoopNode } from './src/publicComponents/noop-node';
4
- export { BaseNode } from './src/publicComponents/base-node/base-node';
5
- export { BaseHandle } from './src/publicComponents/base-node/base-handle';
6
1
  export { Position } from '@xyflow/react';
7
2
  export { workbenchXPath } from './src/components/tutorial/engine/workbench-xpath';
3
+ export { ApiNode } from './src/publicComponents/api-node';
4
+ export { BaseHandle } from './src/publicComponents/base-node/base-handle';
5
+ export { BaseNode } from './src/publicComponents/base-node/base-node';
6
+ export { EventNode } from './src/publicComponents/event-node';
7
+ export { NoopNode } from './src/publicComponents/noop-node';
@@ -1,5 +1,5 @@
1
1
  import type { Express } from 'express';
2
- import { type WorkbenchPlugin } from './vite-plugin-motia-plugins';
2
+ import type { WorkbenchPlugin } from './motia-plugin/types';
3
3
  export type ApplyMiddlewareParams = {
4
4
  app: Express;
5
5
  port: number;
@@ -8,7 +8,7 @@ const plugin_react_1 = __importDefault(require("@vitejs/plugin-react"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const path_1 = __importDefault(require("path"));
10
10
  const vite_1 = require("vite");
11
- const vite_plugin_motia_plugins_1 = __importDefault(require("./vite-plugin-motia-plugins"));
11
+ const motia_plugin_1 = __importDefault(require("./motia-plugin"));
12
12
  const workbenchBasePlugin = (workbenchBase) => {
13
13
  return {
14
14
  name: 'html-transform',
@@ -60,6 +60,7 @@ const applyMiddleware = async ({ app, port, workbenchBase, plugins }) => {
60
60
  path_1.default.join(process.cwd(), './steps'), // steps directory
61
61
  path_1.default.join(process.cwd(), './tutorial.tsx'), // tutorial file
62
62
  path_1.default.join(process.cwd(), './node_modules'), // node_modules directory
63
+ path_1.default.join(__dirname, './node_modules'), // node_modules directory
63
64
  ],
64
65
  },
65
66
  },
@@ -67,14 +68,13 @@ const applyMiddleware = async ({ app, port, workbenchBase, plugins }) => {
67
68
  alias: {
68
69
  '@': path_1.default.resolve(__dirname, './src'),
69
70
  '@/assets': path_1.default.resolve(__dirname, './src/assets'),
70
- // antd: path.join(process.cwd(), './node_modules/antd'),
71
71
  },
72
72
  },
73
73
  plugins: [
74
74
  (0, plugin_react_1.default)(),
75
75
  processCwdPlugin(),
76
76
  reoPlugin(),
77
- (0, vite_plugin_motia_plugins_1.default)(plugins),
77
+ (0, motia_plugin_1.default)(plugins),
78
78
  workbenchBasePlugin(workbenchBase),
79
79
  ],
80
80
  assetsInclude: ['**/*.png', '**/*.jpg', '**/*.jpeg', '**/*.gif', '**/*.svg', '**/*.ico', '**/*.webp', '**/*.avif'],
@@ -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;
@@ -0,0 +1,128 @@
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");
10
+ /**
11
+ * Generates import statements for all unique plugin packages.
12
+ *
13
+ * @param packages - Array of unique package names
14
+ * @returns JavaScript code string with import statements
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * generateImports(['@org/plugin-1', '~/plugins/local'])
19
+ * // Returns:
20
+ * // import * as plugin_0 from '@org/plugin-1'
21
+ * // import * as plugin_1 from '~/plugins/local'
22
+ * ```
23
+ */
24
+ function generateImports(packages) {
25
+ return packages.map((packageName, index) => `import * as plugin_${index} from '${packageName}'`).join('\n');
26
+ }
27
+ /**
28
+ * Generates the package map that links package names to their imported modules.
29
+ *
30
+ * @param packages - Array of unique package names
31
+ * @returns JavaScript code string defining the package map
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * generatePackageMap(['@org/plugin-1', '~/plugins/local'])
36
+ * // Returns: const packageMap = {'@org/plugin-1': plugin_0,'~/plugins/local': plugin_1}
37
+ * ```
38
+ */
39
+ function generatePackageMap(packages) {
40
+ const entries = packages.map((packageName, index) => `'${packageName}': plugin_${index}`);
41
+ return `const packageMap = {${entries.join(',')}}`;
42
+ }
43
+ /**
44
+ * Generates the plugin transformation logic that processes plugin configurations.
45
+ *
46
+ * @param plugins - Array of plugin configurations
47
+ * @returns JavaScript code string with plugin processing logic
48
+ */
49
+ function generatePluginLogic(plugins) {
50
+ return `
51
+ const motiaPlugins = ${JSON.stringify(plugins)}
52
+
53
+ export const plugins = motiaPlugins.map((plugin) => {
54
+ const component = packageMap[plugin.packageName]
55
+ const config = component.config || {}
56
+ const componentName = config.componentName || plugin.componentName
57
+
58
+ return {
59
+ label: plugin.label || config.label || 'Plugin label',
60
+ labelIcon: plugin.labelIcon || config.labelIcon || 'toy-brick',
61
+ position: plugin.position || config.position || 'top',
62
+ props: plugin.props || config.props || {},
63
+ component: componentName ? component[componentName] : component.default,
64
+ }
65
+ })
66
+ `;
67
+ }
68
+ /**
69
+ * Generates the complete virtual module code for all plugins.
70
+ * This is the main code generation function that combines all parts.
71
+ *
72
+ * @param plugins - Array of plugin configurations
73
+ * @returns Complete JavaScript code string for the virtual module
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * const plugins = [
78
+ * { packageName: '@test/plugin', label: 'Test' }
79
+ * ]
80
+ * const code = generatePluginCode(plugins)
81
+ * // Returns complete module code with imports, map, and logic
82
+ * ```
83
+ */
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}
93
+ ${packageMap}
94
+ ${logic}`;
95
+ }
96
+ /**
97
+ * Generates CSS imports for plugins that specify cssImports.
98
+ *
99
+ * @param plugins - Array of plugin configurations
100
+ * @returns CSS import statements as a string
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const plugins = [
105
+ * { packageName: '@test/plugin', cssImports: ['styles.css', 'theme.css'] }
106
+ * ]
107
+ * generateCssImports(plugins)
108
+ * // Returns:
109
+ * // @import 'styles.css';
110
+ * // @import 'theme.css';
111
+ * ```
112
+ */
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');
119
+ }
120
+ /**
121
+ * Checks if the generated code is valid (non-empty and has content).
122
+ *
123
+ * @param code - The generated code to check
124
+ * @returns True if code is valid
125
+ */
126
+ function isValidCode(code) {
127
+ return typeof code === 'string' && code.trim().length > 0;
128
+ }
@@ -0,0 +1,19 @@
1
+ import type { HmrContext, ModuleNode } from 'vite';
2
+ import type { WorkbenchPlugin } from './types';
3
+ /**
4
+ * Checks if a file change should trigger HMR for plugins.
5
+ *
6
+ * @param file - The file path that changed
7
+ * @param plugins - Current plugin configurations
8
+ * @returns True if the change affects plugins
9
+ */
10
+ export declare function shouldInvalidatePlugins(file: string, plugins: WorkbenchPlugin[]): boolean;
11
+ /**
12
+ * Handles hot updates for the plugin system.
13
+ * This function is called by Vite's handleHotUpdate hook.
14
+ *
15
+ * @param ctx - Vite's HMR context
16
+ * @param plugins - Current plugin configurations
17
+ * @returns Array of modules to update, or undefined to continue with default behavior
18
+ */
19
+ export declare function handlePluginHotUpdate(ctx: HmrContext, plugins: WorkbenchPlugin[]): ModuleNode[] | void;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shouldInvalidatePlugins = shouldInvalidatePlugins;
4
+ exports.handlePluginHotUpdate = handlePluginHotUpdate;
5
+ const types_1 = require("./types");
6
+ const utils_1 = require("./utils");
7
+ /**
8
+ * Checks if a file change should trigger HMR for plugins.
9
+ *
10
+ * @param file - The file path that changed
11
+ * @param plugins - Current plugin configurations
12
+ * @returns True if the change affects plugins
13
+ */
14
+ function shouldInvalidatePlugins(file, plugins) {
15
+ const normalizedFile = (0, utils_1.normalizePath)(file);
16
+ // Check if the changed file is a local plugin
17
+ for (const plugin of plugins) {
18
+ if (plugin.packageName.startsWith('~/')) {
19
+ const pluginPath = plugin.packageName.replace('~/', '');
20
+ if (normalizedFile.includes(pluginPath)) {
21
+ return true;
22
+ }
23
+ }
24
+ }
25
+ // Check if it's a plugin configuration file
26
+ if (normalizedFile.endsWith('motia.config.ts') || normalizedFile.endsWith('motia.config.js')) {
27
+ return true;
28
+ }
29
+ return false;
30
+ }
31
+ /**
32
+ * Handles hot updates for the plugin system.
33
+ * This function is called by Vite's handleHotUpdate hook.
34
+ *
35
+ * @param ctx - Vite's HMR context
36
+ * @param plugins - Current plugin configurations
37
+ * @returns Array of modules to update, or undefined to continue with default behavior
38
+ */
39
+ function handlePluginHotUpdate(ctx, plugins) {
40
+ const { file, server } = ctx;
41
+ console.log('[motia-plugins] HMR: File changed:', file);
42
+ // Check if this change affects plugins
43
+ if (!shouldInvalidatePlugins(file, plugins)) {
44
+ return; // Let Vite handle it normally
45
+ }
46
+ console.log('[motia-plugins] HMR: Plugin configuration or local plugin changed, invalidating virtual module');
47
+ // Find the virtual module
48
+ const virtualModule = server.moduleGraph.getModuleById(types_1.CONSTANTS.RESOLVED_VIRTUAL_MODULE_ID);
49
+ if (virtualModule) {
50
+ // Invalidate the virtual module to force regeneration
51
+ server.moduleGraph.invalidateModule(virtualModule);
52
+ console.log('[motia-plugins] HMR: Virtual module invalidated');
53
+ }
54
+ // Return modules to update (includes the virtual module and any dependent modules)
55
+ const modulesToUpdate = [];
56
+ if (virtualModule) {
57
+ modulesToUpdate.push(virtualModule);
58
+ }
59
+ // Add any modules that import the virtual module
60
+ const importers = virtualModule?.importers || new Set();
61
+ for (const importer of importers) {
62
+ modulesToUpdate.push(importer);
63
+ console.log('[motia-plugins] HMR: Invalidating importer:', importer.id);
64
+ }
65
+ return modulesToUpdate;
66
+ }
@@ -0,0 +1,27 @@
1
+ import type { Plugin } from 'vite';
2
+ import type { WorkbenchPlugin } from './types';
3
+ /**
4
+ * Vite plugin for loading and managing Motia workbench plugins.
5
+ *
6
+ * Features:
7
+ * - Hot Module Replacement (HMR) support
8
+ * - Runtime validation with detailed error messages
9
+ * - Verbose logging for debugging
10
+ * - CSS injection for plugin styles
11
+ *
12
+ * @param plugins - Array of plugin configurations
13
+ * @param options - Optional loader configuration
14
+ * @returns Vite plugin instance
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * export default defineConfig({
19
+ * plugins: [
20
+ * motiaPluginsPlugin([
21
+ * { packageName: '@my-org/plugin', label: 'My Plugin' }
22
+ * ])
23
+ * ]
24
+ * })
25
+ * ```
26
+ */
27
+ export default function motiaPluginsPlugin(plugins: WorkbenchPlugin[]): Plugin;