@motiadev/workbench 0.8.2-beta.140-364012 → 0.8.2-beta.140-709523

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.
@@ -1,7 +1,5 @@
1
- import type { Printer } from '@motiadev/core';
2
1
  import type { HmrContext, ModuleNode } from 'vite';
3
2
  import type { WorkbenchPlugin } from './types';
4
- export declare function isConfigFile(file: string): boolean;
5
3
  /**
6
4
  * Checks if a file change should trigger HMR for plugins.
7
5
  *
@@ -16,7 +14,6 @@ export declare function shouldInvalidatePlugins(file: string, plugins: Workbench
16
14
  *
17
15
  * @param ctx - Vite's HMR context
18
16
  * @param plugins - Current plugin configurations
19
- * @param printer - Printer instance for logging
20
17
  * @returns Array of modules to update, or undefined to continue with default behavior
21
18
  */
22
- export declare function handlePluginHotUpdate(ctx: HmrContext, plugins: WorkbenchPlugin[], printer: Printer): ModuleNode[] | undefined;
19
+ export declare function handlePluginHotUpdate(ctx: HmrContext, plugins: WorkbenchPlugin[]): ModuleNode[] | void;
@@ -1,20 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isConfigFile = isConfigFile;
7
3
  exports.shouldInvalidatePlugins = shouldInvalidatePlugins;
8
4
  exports.handlePluginHotUpdate = handlePluginHotUpdate;
9
- const path_1 = __importDefault(require("path"));
10
- const resolver_1 = require("./resolver");
11
5
  const types_1 = require("./types");
12
6
  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
7
  /**
19
8
  * Checks if a file change should trigger HMR for plugins.
20
9
  *
@@ -24,28 +13,19 @@ function isConfigFile(file) {
24
13
  */
25
14
  function shouldInvalidatePlugins(file, plugins) {
26
15
  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
- }
16
+ // Check if the changed file is a local plugin
35
17
  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) {
18
+ if (plugin.packageName.startsWith('~/')) {
19
+ const pluginPath = plugin.packageName.replace('~/', '');
20
+ if (normalizedFile.includes(pluginPath)) {
45
21
  return true;
46
22
  }
47
23
  }
48
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
+ }
49
29
  return false;
50
30
  }
51
31
  /**
@@ -54,63 +34,33 @@ function shouldInvalidatePlugins(file, plugins) {
54
34
  *
55
35
  * @param ctx - Vite's HMR context
56
36
  * @param plugins - Current plugin configurations
57
- * @param printer - Printer instance for logging
58
37
  * @returns Array of modules to update, or undefined to continue with default behavior
59
38
  */
60
- function handlePluginHotUpdate(ctx, plugins, printer) {
61
- const { file, server, timestamp } = ctx;
62
- printer.printPluginLog(`HMR: File changed: ${(0, utils_1.normalizePath)(file)}`);
39
+ function handlePluginHotUpdate(ctx, plugins) {
40
+ const { file, server } = ctx;
41
+ console.log('[motia-plugins] HMR: File changed:', file);
63
42
  // Check if this change affects plugins
64
43
  if (!shouldInvalidatePlugins(file, plugins)) {
65
44
  return; // Let Vite handle it normally
66
45
  }
67
- if (isConfigFile(file)) {
68
- printer.printPluginLog('HMR: Config file changed, triggering full page reload');
69
- printer.printPluginWarn('Configuration changes require a server restart for full effect. Please restart the dev server to apply all changes.');
70
- server.ws.send({
71
- type: 'full-reload',
72
- path: '*',
73
- });
74
- return;
75
- }
76
- printer.printPluginLog('HMR: Plugin change detected, invalidating virtual module');
46
+ console.log('[motia-plugins] HMR: Plugin configuration or local plugin changed, invalidating virtual module');
77
47
  // Find the virtual module
78
48
  const virtualModule = server.moduleGraph.getModuleById(types_1.CONSTANTS.RESOLVED_VIRTUAL_MODULE_ID);
79
- if (!virtualModule) {
80
- printer.printPluginWarn('HMR: Virtual module not found, triggering full reload');
81
- server.ws.send({
82
- type: 'full-reload',
83
- path: '*',
84
- });
85
- return;
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);
86
64
  }
87
- server.moduleGraph.invalidateModule(virtualModule, new Set(), timestamp);
88
- printer.printPluginLog('HMR: Virtual module invalidated');
89
- const modulesToUpdate = [virtualModule];
90
- const processedModules = new Set([virtualModule]);
91
- // Recursively add all importers
92
- const addImporters = (module) => {
93
- for (const importer of module.importers) {
94
- if (!processedModules.has(importer)) {
95
- processedModules.add(importer);
96
- modulesToUpdate.push(importer);
97
- server.moduleGraph.invalidateModule(importer, new Set(), timestamp);
98
- addImporters(importer);
99
- }
100
- }
101
- };
102
- addImporters(virtualModule);
103
- server.ws.send({
104
- type: 'update',
105
- updates: modulesToUpdate
106
- .filter((m) => m.url)
107
- .map((m) => ({
108
- type: m.type === 'css' ? 'css-update' : 'js-update',
109
- path: m.url,
110
- acceptedPath: m.url,
111
- timestamp,
112
- })),
113
- });
114
- printer.printPluginLog(`HMR: Updated ${modulesToUpdate.length} module(s)`);
115
65
  return modulesToUpdate;
116
66
  }
@@ -1,3 +1,27 @@
1
1
  import type { Plugin } from 'vite';
2
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
+ */
3
27
  export default function motiaPluginsPlugin(plugins: WorkbenchPlugin[]): Plugin;
@@ -1,11 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.default = motiaPluginsPlugin;
7
- const core_1 = require("@motiadev/core");
8
- const path_1 = __importDefault(require("path"));
9
4
  const generator_1 = require("./generator");
10
5
  const hmr_1 = require("./hmr");
11
6
  const resolver_1 = require("./resolver");
@@ -36,7 +31,6 @@ const validator_1 = require("./validator");
36
31
  * })
37
32
  * ```
38
33
  */
39
- const printer = new core_1.Printer(process.cwd());
40
34
  function motiaPluginsPlugin(plugins) {
41
35
  let devServer = null;
42
36
  try {
@@ -44,29 +38,25 @@ function motiaPluginsPlugin(plugins) {
44
38
  failFast: false,
45
39
  });
46
40
  if (!validationResult.valid) {
47
- printer.printPluginError('Plugin configuration validation failed:');
48
- for (const err of validationResult.errors) {
49
- printer.printPluginError(` ${err}`);
50
- }
41
+ console.error('[motia-plugins] Plugin configuration validation failed:');
42
+ validationResult.errors.forEach((err) => console.error(`[motia-plugins] ${err}`));
51
43
  throw new Error('Invalid plugin configuration. See errors above.');
52
44
  }
53
45
  if (validationResult.warnings.length > 0) {
54
- for (const warning of validationResult.warnings) {
55
- printer.printPluginWarn(warning);
56
- }
46
+ validationResult.warnings.forEach((warning) => console.warn('[motia-plugins]', warning));
57
47
  }
58
48
  }
59
49
  catch (error) {
60
- printer.printPluginError(`Failed to validate plugins: ${error}`);
50
+ console.error('[motia-plugins] Failed to validate plugins:', error);
61
51
  throw error;
62
52
  }
63
53
  const alias = (0, resolver_1.createAliasConfig)(plugins);
64
- printer.printPluginLog(`Initialized with ${plugins.length} plugin(s)`);
54
+ console.log(`[motia-plugins] Initialized with ${plugins.length} plugin(s)`);
65
55
  return {
66
56
  name: 'vite-plugin-motia-plugins',
67
57
  enforce: 'pre',
68
58
  buildStart() {
69
- printer.printPluginLog('Build started');
59
+ console.log('[motia-plugins] Build started');
70
60
  },
71
61
  config: () => ({
72
62
  resolve: {
@@ -75,30 +65,7 @@ function motiaPluginsPlugin(plugins) {
75
65
  }),
76
66
  configureServer(server) {
77
67
  devServer = server;
78
- printer.printPluginLog('Dev server configured, HMR enabled');
79
- const configPaths = [path_1.default.join(process.cwd(), 'motia.config.ts'), path_1.default.join(process.cwd(), 'motia.config.js')];
80
- for (const configPath of configPaths) {
81
- server.watcher.add(configPath);
82
- }
83
- printer.printPluginLog('Watching for config file changes');
84
- const localPlugins = plugins.filter((p) => (0, utils_1.isLocalPlugin)(p.packageName));
85
- if (localPlugins.length > 0) {
86
- printer.printPluginLog(`Watching ${localPlugins.length} local plugin(s)`);
87
- for (const plugin of localPlugins) {
88
- const resolved = (0, resolver_1.resolvePluginPackage)(plugin);
89
- const watchPath = resolved.resolvedPath;
90
- server.watcher.add(watchPath);
91
- printer.printPluginLog(`Watching: ${watchPath}`);
92
- }
93
- server.watcher.on('change', (file) => {
94
- const normalizedFile = (0, utils_1.normalizePath)(file);
95
- printer.printPluginLog(`File watcher detected change: ${normalizedFile}`);
96
- });
97
- server.watcher.on('add', (file) => {
98
- const normalizedFile = (0, utils_1.normalizePath)(file);
99
- printer.printPluginLog(`File watcher detected new file: ${normalizedFile}`);
100
- });
101
- }
68
+ console.log('[motia-plugins] Dev server configured, HMR enabled');
102
69
  },
103
70
  resolveId(id) {
104
71
  if (id === types_1.CONSTANTS.VIRTUAL_MODULE_ID) {
@@ -109,14 +76,14 @@ function motiaPluginsPlugin(plugins) {
109
76
  if (id !== types_1.CONSTANTS.RESOLVED_VIRTUAL_MODULE_ID) {
110
77
  return null;
111
78
  }
112
- printer.printPluginLog('Loading plugins virtual module');
113
- printer.printPluginLog('Generating plugin code...');
79
+ console.log('[motia-plugins] Loading plugins virtual module');
80
+ console.log('[motia-plugins] Generating plugin code...');
114
81
  const code = (0, generator_1.generatePluginCode)(plugins);
115
82
  if (!(0, generator_1.isValidCode)(code)) {
116
- printer.printPluginError('Generated code is invalid or empty');
83
+ console.error('[motia-plugins] Generated code is invalid or empty');
117
84
  return 'export const plugins = []';
118
85
  }
119
- printer.printPluginLog('Plugin code generated successfully');
86
+ console.log('[motia-plugins] Plugin code generated successfully');
120
87
  return code;
121
88
  },
122
89
  async transform(code, id) {
@@ -124,7 +91,7 @@ function motiaPluginsPlugin(plugins) {
124
91
  if (!normalizedId.endsWith('src/index.css')) {
125
92
  return null;
126
93
  }
127
- printer.printPluginLog('Injecting plugin CSS imports');
94
+ console.log('[motia-plugins] Injecting plugin CSS imports');
128
95
  const cssImports = (0, generator_1.generateCssImports)(plugins);
129
96
  if (!cssImports) {
130
97
  return null;
@@ -136,17 +103,16 @@ function motiaPluginsPlugin(plugins) {
136
103
  },
137
104
  handleHotUpdate(ctx) {
138
105
  if (!devServer) {
139
- printer.printPluginWarn('HMR: Dev server not available');
140
106
  return;
141
107
  }
142
- const modulesToUpdate = (0, hmr_1.handlePluginHotUpdate)(ctx, plugins, printer);
143
- if (modulesToUpdate && modulesToUpdate.length > 0) {
144
- printer.printPluginLog(`HMR: Successfully updated ${modulesToUpdate.length} module(s)`);
108
+ const modulesToUpdate = (0, hmr_1.handlePluginHotUpdate)(ctx, plugins);
109
+ if (modulesToUpdate) {
110
+ console.log('[motia-plugins] Hot reloaded plugins');
145
111
  return modulesToUpdate;
146
112
  }
147
113
  },
148
114
  buildEnd() {
149
- printer.printPluginLog('Build ended');
115
+ console.log('[motia-plugins] Build ended');
150
116
  },
151
117
  };
152
118
  }
package/dist/src/App.js CHANGED
@@ -1,36 +1,31 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useEffect, useMemo } from 'react';
2
+ import { useMemo } from 'react';
3
3
  import { FlowPage } from './components/flow/flow-page';
4
4
  import { FlowTabMenuItem } from './components/flow/flow-tab-menu-item';
5
5
  import { registerPluginTabs } from './lib/plugins';
6
6
  import { getViewModeFromURL } from './lib/utils';
7
7
  import { ProjectViewMode } from './project-view-mode';
8
- import { TabLocation, useAppTabsStore } from './stores/use-app-tabs-store';
8
+ import { setAppTabs, TabLocation } from './stores/use-app-tabs-store';
9
9
  import { SystemViewMode } from './system-view-mode';
10
10
  const TAB_IDS = {
11
11
  FLOW: 'flow',
12
12
  LOGS: 'logs',
13
13
  };
14
- const topTabs = [
15
- {
16
- id: TAB_IDS.FLOW,
17
- tabLabel: FlowTabMenuItem,
18
- content: FlowPage,
19
- },
20
- ];
14
+ const registerDefaultTabs = () => {
15
+ const topTabs = [
16
+ {
17
+ id: TAB_IDS.FLOW,
18
+ tabLabel: FlowTabMenuItem,
19
+ content: FlowPage,
20
+ },
21
+ ];
22
+ const bottomTabs = [];
23
+ setAppTabs(TabLocation.TOP, topTabs);
24
+ setAppTabs(TabLocation.BOTTOM, bottomTabs);
25
+ };
26
+ registerDefaultTabs();
27
+ registerPluginTabs();
21
28
  export const App = () => {
22
- const setTabs = useAppTabsStore((state) => state.setTabs);
23
- const addTab = useAppTabsStore((state) => state.addTab);
24
- useEffect(() => {
25
- const timeout = setTimeout(() => {
26
- console.log('registering default tabs');
27
- setTabs(TabLocation.TOP, topTabs);
28
- console.log('registering plugin tabs');
29
- registerPluginTabs(addTab);
30
- console.log('registered tabs');
31
- }, 10);
32
- return () => clearTimeout(timeout);
33
- }, [setTabs, addTab]);
34
29
  const viewMode = useMemo(getViewModeFromURL, []);
35
30
  const ViewComponent = viewMode === 'project' ? ProjectViewMode : SystemViewMode;
36
31
  return _jsx(ViewComponent, {});
@@ -1,2 +1 @@
1
- import { type AppTab, TabLocation } from '@/stores/use-app-tabs-store';
2
- export declare const registerPluginTabs: (addTab: (position: TabLocation, tab: AppTab) => void) => void;
1
+ export declare const registerPluginTabs: () => void;
@@ -2,14 +2,13 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
2
2
  import { plugins } from 'virtual:motia-plugins';
3
3
  import { DynamicIcon, dynamicIconImports } from 'lucide-react/dynamic';
4
4
  import { memo } from 'react';
5
- import { TabLocation } from '@/stores/use-app-tabs-store';
5
+ import { addAppTab, TabLocation } from '@/stores/use-app-tabs-store';
6
6
  import { isValidTabLocation } from './utils';
7
- export const registerPluginTabs = (addTab) => {
7
+ export const registerPluginTabs = () => {
8
8
  if (!Array.isArray(plugins)) {
9
9
  console.warn('[Motia] Invalid plugins configuration: expected array');
10
10
  return;
11
11
  }
12
- console.log('[Motia] Registering plugins:', plugins);
13
12
  plugins.forEach((plugin, index) => {
14
13
  try {
15
14
  if (!plugin.label) {
@@ -43,7 +42,7 @@ export const registerPluginTabs = (addTab) => {
43
42
  return _jsx(Component, { ...props });
44
43
  });
45
44
  PluginContent.displayName = `${plugin.label}Content`;
46
- addTab(tabLocation, {
45
+ addAppTab(tabLocation, {
47
46
  id: plugin.label.toLowerCase(),
48
47
  tabLabel: PluginTabLabel,
49
48
  content: PluginContent,
@@ -30,10 +30,8 @@ export const useAppTabsStore = create((set) => ({
30
30
  })),
31
31
  }));
32
32
  export const setAppTabs = (position, tabs) => {
33
- console.log('[Motia] Setting tabs:', position, tabs);
34
33
  useAppTabsStore.getState().setTabs(position, tabs);
35
34
  };
36
35
  export const addAppTab = (position, tab) => {
37
- console.log('[Motia] Adding tab:', position, tab);
38
36
  useAppTabsStore.getState().addTab(position, tab);
39
37
  };