@ebay/muse-boot-default 1.3.1 → 1.3.5

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.
@@ -0,0 +1,400 @@
1
+ # Plugin Integration Guide: @ebay/muse-boot-default
2
+
3
+ **Generated**: 2026-03-28
4
+ **Plugin Type**: boot
5
+
6
+ ---
7
+
8
+ ## 1. Plugin Purpose & Overview
9
+
10
+ ### Purpose
11
+
12
+ `@ebay/muse-boot-default` is the default bootstrap plugin for MUSE applications. It orchestrates the entire application startup sequence, loading plugins in the correct order and initializing the MUSE runtime environment.
13
+
14
+ ### Key Capabilities
15
+
16
+ **Bootstrap Orchestration**
17
+ - Loads and executes plugins in the correct order: boot → init → lib → normal
18
+ - Manages the plugin loading lifecycle with parallel loading for optimal performance
19
+ - Provides loading progress feedback to users
20
+ - Handles error states and recovery during bootstrap
21
+
22
+ **MUSE Global Environment Setup**
23
+ - Initializes `window.MUSE_GLOBAL` with core utilities and configuration
24
+ - Sets up the shared modules system (`__shared__`)
25
+ - Configures app variables, plugin variables, and configuration merging
26
+ - Provides message engine for parent-child communication (sub-app scenarios)
27
+
28
+ **Plugin Loading System**
29
+ - Supports multiple plugin sources: CDN, local development, linked plugins
30
+ - Implements parallel loading for lib and normal plugins
31
+ - Handles ES module and UMD plugin formats
32
+ - Supports `forcePlugins` query parameter for debugging/testing
33
+
34
+ **Service Worker Registration**
35
+ - Registers service workers for offline support
36
+ - Manages service worker lifecycle
37
+
38
+ **Error Handling & Loading UI**
39
+ - Displays loading progress during bootstrap
40
+ - Shows error messages when bootstrap fails
41
+ - Provides fallback UI for failed states
42
+
43
+ ### Integration Role
44
+
45
+ As a **boot plugin**, this plugin:
46
+ - **MUST be the first plugin loaded** in any MUSE application
47
+ - Does not use the js-plugin extension point system (it runs before plugins are loaded)
48
+ - Provides the foundational environment that allows other plugins to function
49
+ - Is typically referenced in `index.html` as the entry script
50
+
51
+ ---
52
+
53
+ ## 2. Extension Points Exposed
54
+
55
+ This plugin does not expose extension points. As a boot plugin, it runs before the js-plugin system is initialized and focuses solely on loading other plugins and setting up the runtime environment.
56
+
57
+ ---
58
+
59
+ ## 3. Extension Points Contributed
60
+
61
+ This plugin does not contribute to extension points from other plugins. As the first plugin to load, there are no other plugins available to extend when this plugin runs.
62
+
63
+ ### Bootstrap Integration Points
64
+
65
+ While this plugin doesn't use extension points, it provides several integration mechanisms through `window.MUSE_GLOBAL`:
66
+
67
+ #### `waitForLoaders`
68
+ **Type**: `Array<Promise | AsyncFunction>`
69
+ **File Reference**: `src/boot.js:23, 273-286`
70
+
71
+ Plugins can register async loaders that must complete before the app starts:
72
+
73
+ ```javascript
74
+ // In an init plugin
75
+ window.MUSE_GLOBAL.waitFor(async () => {
76
+ await performAuth();
77
+ return true; // Return false to prevent app from starting
78
+ });
79
+ ```
80
+
81
+ ---
82
+
83
+ #### `initEntries`
84
+ **Type**: `Array<{ func: Function, order?: number }>`
85
+ **File Reference**: `src/boot.js:44, 201-208`
86
+
87
+ Init plugins can register initialization functions executed after init plugins load:
88
+
89
+ ```javascript
90
+ // In an init plugin
91
+ window.MUSE_GLOBAL.initEntries.push({
92
+ order: 10,
93
+ func: async () => {
94
+ await initialize();
95
+ // Return false to prevent app from starting
96
+ }
97
+ });
98
+ ```
99
+
100
+ ---
101
+
102
+ #### `appEntries`
103
+ **Type**: `Array<{ name: string, func: Function }>`
104
+ **File Reference**: `src/boot.js:43, 289-314`
105
+
106
+ Lib plugins can register app entry points (typically from `@ebay/muse-lib-react`):
107
+
108
+ ```javascript
109
+ // In a lib plugin with isAppEntry: true
110
+ window.MUSE_GLOBAL.appEntries.push({
111
+ name: '@ebay/muse-lib-react',
112
+ func: renderApp
113
+ });
114
+ ```
115
+
116
+ ---
117
+
118
+ #### `pluginEntries`
119
+ **Type**: `Array<{ func: Function }>`
120
+ **File Reference**: `src/boot.js:45, 267-270`
121
+
122
+ Build system can register plugin initialization code:
123
+
124
+ ```javascript
125
+ window.MUSE_GLOBAL.pluginEntries.push({
126
+ func: () => {
127
+ // Plugin initialization
128
+ }
129
+ });
130
+ ```
131
+
132
+ ---
133
+
134
+ ## 4. Exported Functionality
135
+
136
+ This plugin sets up `window.MUSE_GLOBAL` with the following utilities and systems:
137
+
138
+ ### Global Utilities
139
+
140
+ #### `msgEngine`
141
+ **File Reference**: `src/boot.js:38`, `src/msgEngine.js`
142
+ **Purpose**: Message passing system for parent-child window communication
143
+
144
+ **Why it exists**: Enables MUSE apps embedded in iframes to communicate with their parent windows.
145
+
146
+ **Methods**:
147
+ - `sendToParent(message)` - Send message to parent window
148
+ - `addListener(key, handler)` - Listen for messages
149
+ - `removeListener(key)` - Remove message listener
150
+
151
+ ---
152
+
153
+ #### `loading`
154
+ **File Reference**: `src/boot.js:39`, `src/loading.js`
155
+ **Purpose**: Loading UI management
156
+
157
+ **Why it exists**: Provides user feedback during the bootstrap process.
158
+
159
+ **Methods**:
160
+ - `init()` - Initialize loading UI
161
+ - `showMessage(message)` - Display loading message
162
+ - `hide()` - Hide loading UI
163
+
164
+ ---
165
+
166
+ #### `error`
167
+ **File Reference**: `src/boot.js:40`, `src/error.js`
168
+ **Purpose**: Error UI management
169
+
170
+ **Why it exists**: Displays error messages when bootstrap fails.
171
+
172
+ **Methods**:
173
+ - `showMessage(message)` - Display error message
174
+
175
+ ---
176
+
177
+ #### `getPublicPath(pluginName, assetPath)`
178
+ **File Reference**: `src/boot.js:51-76`
179
+ **Purpose**: Resolve public asset paths for plugins
180
+
181
+ **Why it exists**: Allows plugins to reference their public assets (images, fonts, etc.) correctly regardless of deployment environment.
182
+
183
+ **Usage**:
184
+ ```javascript
185
+ const logoUrl = window.MUSE_GLOBAL.getPublicPath('@ebay/my-plugin', 'logo.png');
186
+ // Returns: /muse-assets/cdn/p/my-plugin/v1.0.0/dist/logo.png
187
+ ```
188
+
189
+ ---
190
+
191
+ #### `waitFor(asyncFuncOrPromise)`
192
+ **File Reference**: `src/boot.js:47-49`
193
+ **Purpose**: Register async operations that must complete before app starts
194
+
195
+ **Why it exists**: Allows init plugins to perform async initialization (auth, config loading) before the main app renders.
196
+
197
+ **Usage**:
198
+ ```javascript
199
+ // In init plugin
200
+ window.MUSE_GLOBAL.waitFor(async () => {
201
+ const user = await fetchUser();
202
+ window.MUSE_GLOBAL.currentUser = user;
203
+ });
204
+ ```
205
+
206
+ ---
207
+
208
+ #### `getUser()`
209
+ **File Reference**: `src/boot.js:42`
210
+ **Purpose**: Get current user (default returns null, overridden by init plugins)
211
+
212
+ **Why it exists**: Provides a standard way to access user information across plugins.
213
+
214
+ ---
215
+
216
+ ### Shared Modules System
217
+
218
+ #### `__shared__`
219
+ **File Reference**: `src/boot.js:78-83`
220
+ **Purpose**: Runtime module sharing container
221
+
222
+ **Why it exists**: Enables lib plugins to provide shared modules (React, Redux, etc.) that other plugins consume without bundling.
223
+
224
+ **Properties**:
225
+ - `modules` - Container for shared modules
226
+ - `register(id, module)` - Register a shared module
227
+ - `require(id)` - Require a shared module
228
+ - `parseMuseId(id)` - Parse MUSE module identifier
229
+
230
+ **Note**: This is managed by `@ebay/muse-modules` package.
231
+
232
+ ---
233
+
234
+ ### Configuration System
235
+
236
+ #### `appConfig`
237
+ **File Reference**: `src/boot.js:27-37`
238
+ **Purpose**: Merged app and environment configuration
239
+
240
+ **Why it exists**: Provides a single source of truth for app configuration, with env config overriding app config.
241
+
242
+ **Usage**:
243
+ ```javascript
244
+ const routerType = window.MUSE_GLOBAL.appConfig.routerType;
245
+ ```
246
+
247
+ ---
248
+
249
+ #### `appVariables`
250
+ **File Reference**: `src/boot.js:35`
251
+ **Purpose**: App-level runtime variables
252
+
253
+ ---
254
+
255
+ #### `pluginVariables`
256
+ **File Reference**: `src/boot.js:36`
257
+ **Purpose**: Plugin-level runtime variables
258
+
259
+ ---
260
+
261
+ ### Environment Flags
262
+
263
+ #### `isSubApp`
264
+ **File Reference**: `src/boot.js:41`
265
+ **Purpose**: Boolean indicating if app is running in an iframe
266
+
267
+ **Why it exists**: Allows plugins to adjust behavior when embedded as a sub-app.
268
+
269
+ ---
270
+
271
+ #### `isDev`
272
+ **File Reference**: `src/boot.js:86`
273
+ **Purpose**: Boolean indicating development mode
274
+
275
+ ---
276
+
277
+ #### `isLocal`
278
+ **File Reference**: From `MUSE_GLOBAL`
279
+ **Purpose**: Boolean indicating local development mode
280
+
281
+ ---
282
+
283
+ #### `isE2eTest`
284
+ **File Reference**: `src/boot.js:86`
285
+ **Purpose**: Boolean indicating E2E test mode
286
+
287
+ ---
288
+
289
+ ## 5. Integration Examples
290
+
291
+ **Note**: This boot plugin does not use the js-plugin extension point system. The examples below show how to integrate with the bootstrap environment it provides.
292
+
293
+ ### Example 1: Creating an Init Plugin
294
+
295
+ Init plugins run after boot and before lib/normal plugins. They're perfect for authentication, configuration loading, or permission checks.
296
+
297
+ ```javascript
298
+ // src/index.js in an init plugin
299
+ const initFunc = async () => {
300
+ // Perform authentication
301
+ const user = await fetch('/api/user').then(r => r.json());
302
+
303
+ // Make user available globally
304
+ window.MUSE_GLOBAL.getUser = () => user;
305
+
306
+ // If auth fails, return false to prevent app from starting
307
+ if (!user) {
308
+ window.MUSE_GLOBAL.error.showMessage('Authentication failed');
309
+ return false;
310
+ }
311
+
312
+ return true; // Continue startup
313
+ };
314
+
315
+ // Register init entry
316
+ window.MUSE_GLOBAL.initEntries.push({
317
+ order: 10, // Lower numbers run first
318
+ func: initFunc
319
+ });
320
+ ```
321
+
322
+ ---
323
+
324
+ ### Example 2: Using waitFor for Async Initialization
325
+
326
+ ```javascript
327
+ // In an init plugin
328
+ window.MUSE_GLOBAL.waitFor(async () => {
329
+ // Load configuration from API
330
+ const config = await fetch('/api/config').then(r => r.json());
331
+
332
+ // Store in MUSE_GLOBAL
333
+ window.MUSE_GLOBAL.appVariables.apiEndpoint = config.apiEndpoint;
334
+
335
+ // Return false to prevent app start if config fails
336
+ if (!config) return false;
337
+ });
338
+ ```
339
+
340
+ ---
341
+
342
+ ### Example 3: Registering an App Entry (Lib Plugin)
343
+
344
+ ```javascript
345
+ // In a lib plugin like @ebay/muse-lib-react
346
+ const renderApp = () => {
347
+ const root = createRoot(document.getElementById('root'));
348
+ root.render(<App />);
349
+ };
350
+
351
+ window.MUSE_GLOBAL.appEntries.push({
352
+ name: '@ebay/muse-lib-react',
353
+ func: renderApp
354
+ });
355
+ ```
356
+
357
+ ---
358
+
359
+ ### Example 4: Using getPublicPath for Assets
360
+
361
+ ```javascript
362
+ // In any plugin after bootstrap
363
+ import React from 'react';
364
+
365
+ const MyComponent = () => {
366
+ const logoPath = window.MUSE_GLOBAL.getPublicPath(
367
+ '@ebay/my-plugin',
368
+ 'images/logo.png'
369
+ );
370
+
371
+ return <img src={logoPath} alt="Logo" />;
372
+ };
373
+ ```
374
+
375
+ ---
376
+
377
+ ### Example 5: Force Loading Specific Plugin Versions
378
+
379
+ For debugging or testing, use the `forcePlugins` query parameter:
380
+
381
+ ```
382
+ https://myapp.com?forcePlugins=@ebay/my-plugin@1.2.3;other-plugin@2.0.0
383
+ ```
384
+
385
+ This overrides the deployed plugin versions with specific versions.
386
+
387
+ ---
388
+
389
+ ## Notes
390
+
391
+ - **This is a boot plugin** (`muse.type: "boot"`) - it MUST be loaded first via `index.html`
392
+ - Does not use js-plugin extension points (runs before plugin system is initialized)
393
+ - Provides the foundational environment for all other plugins
394
+ - Handles plugin loading order: boot → init → lib → normal
395
+ - Init plugins can use `initEntries` or `waitFor` to perform async initialization
396
+ - Lib plugins with `isAppEntry: true` register app entry functions
397
+ - The `forcePlugins` query parameter is useful for debugging specific plugin versions
398
+ - Service worker registration is automatic but can be customized
399
+ - All plugin loading happens in parallel for performance (within each type group)
400
+ - The loading UI provides user feedback during the bootstrap process
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ebay/muse-boot-default",
3
- "version": "1.3.1",
3
+ "version": "1.3.5",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "muse": {
@@ -54,6 +54,6 @@
54
54
  "build:dev": "muse-cra-patch && cross-env NODE_ENV=development FAST_REFRESH=false craco build",
55
55
  "test": "muse-cra-patch && craco test --ci --watchAll=false --passWithNoTests --coverage",
56
56
  "test:dev": "muse-cra-patch && craco test --coverage",
57
- "deploy": "pnpm build && muse release && muse deploy musemanager"
57
+ "postbuild": "cp MUSE_README.md ./build"
58
58
  }
59
59
  }