@shellui/cli 0.0.7 → 0.0.9
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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shellui/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "ShellUI CLI - Command-line tool for ShellUI",
|
|
5
5
|
"main": "src/cli.js",
|
|
6
6
|
"type": "module",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"tsx": "^4.21.0",
|
|
31
31
|
"vite": "7.3.1",
|
|
32
32
|
"workbox-build": "^7.1.0",
|
|
33
|
-
"@shellui/core": "0.0.
|
|
33
|
+
"@shellui/core": "0.0.9"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
package/src/commands/build.js
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
createPostCSSConfig,
|
|
12
12
|
createViteDefine,
|
|
13
13
|
resolvePackagePath,
|
|
14
|
+
inlineLazyImportsPlugin,
|
|
14
15
|
} from '../utils/index.js';
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -83,7 +84,7 @@ export async function buildCommand(root = '.') {
|
|
|
83
84
|
// Build main app
|
|
84
85
|
await build({
|
|
85
86
|
root: coreSrcPath,
|
|
86
|
-
plugins: [react()],
|
|
87
|
+
plugins: [react(), inlineLazyImportsPlugin()],
|
|
87
88
|
define: createViteDefine(config),
|
|
88
89
|
resolve: {
|
|
89
90
|
alias: resolveAlias,
|
package/src/commands/start.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
createPostCSSConfig,
|
|
11
11
|
createViteDefine,
|
|
12
12
|
resolvePackagePath,
|
|
13
|
+
inlineLazyImportsPlugin,
|
|
13
14
|
} from '../utils/index.js';
|
|
14
15
|
import { serviceWorkerDevPlugin } from '../utils/service-worker-plugin.js';
|
|
15
16
|
|
|
@@ -39,7 +40,7 @@ async function startServer(root, cwd, shouldOpen = false) {
|
|
|
39
40
|
|
|
40
41
|
const server = await createServer({
|
|
41
42
|
root: coreSrcPath,
|
|
42
|
-
plugins: [react(), serviceWorkerDevPlugin(corePackagePath, coreSrcPath)],
|
|
43
|
+
plugins: [react(), inlineLazyImportsPlugin(), serviceWorkerDevPlugin(corePackagePath, coreSrcPath)],
|
|
43
44
|
define: createViteDefine(config),
|
|
44
45
|
resolve: {
|
|
45
46
|
alias: createResolveAlias(),
|
package/src/utils/index.js
CHANGED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin that converts lazy(() => import(...)) to direct imports.
|
|
3
|
+
* This prevents Rollup/Vite from creating code-split chunks, ensuring all rendering
|
|
4
|
+
* goes through App.tsx where ConfigProvider wraps everything.
|
|
5
|
+
*
|
|
6
|
+
* This is critical: when the library is consumed via npm, Vite processes the source files.
|
|
7
|
+
* If there are dynamic imports, it creates separate chunks that load separately, causing
|
|
8
|
+
* duplicate module instances and breaking React context (ConfigContext, SettingsContext, etc.).
|
|
9
|
+
*
|
|
10
|
+
* @returns {import('vite').Plugin} Vite plugin
|
|
11
|
+
*/
|
|
12
|
+
export function inlineLazyImportsPlugin() {
|
|
13
|
+
return {
|
|
14
|
+
name: 'inline-lazy-imports',
|
|
15
|
+
// Apply to both dev and build modes
|
|
16
|
+
transform(code, id) {
|
|
17
|
+
// Only transform source files, not node_modules (except our own src)
|
|
18
|
+
// Match paths that contain /src/ but exclude node_modules that aren't @shellui/core/src
|
|
19
|
+
if (!id.includes('/src/') || (id.includes('node_modules') && !id.includes('@shellui/core/src'))) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Check if code contains lazy() calls - if not, skip
|
|
24
|
+
if (!code.includes('lazy(') || !code.includes('import(')) return null;
|
|
25
|
+
|
|
26
|
+
const imports = [];
|
|
27
|
+
let transformed = code;
|
|
28
|
+
let hasChanges = false;
|
|
29
|
+
|
|
30
|
+
// Match the exact pattern: const Name = lazy(() => import('path').then((m) => ({ default: m.Name })),);
|
|
31
|
+
// Handles both single-line and multiline patterns
|
|
32
|
+
// The regex captures: const declaration, lazy call, import path, component name, and trailing punctuation
|
|
33
|
+
const lazyPattern = /const\s+(\w+)\s*=\s*lazy\s*\(\s*\(\)\s*=>\s*[\s\n]*import\s*\((['"])([^'"]+)\2\)\s*\.then\s*\([\s\S]*?\(?\s*m\s*\)?\s*=>\s*\([\s\S]*?\{\s*default:\s*m\.(\w+)\s*\}[\s\S]*?\)[\s\S]*?\)[\s\n]*\)[\s\n]*,?[\s\n]*;?/g;
|
|
34
|
+
|
|
35
|
+
transformed = transformed.replace(lazyPattern, (fullMatch, varName, quote, importPath, componentName) => {
|
|
36
|
+
hasChanges = true;
|
|
37
|
+
// Import with the same name as the variable (they match in the source code)
|
|
38
|
+
const importStatement = `import { ${componentName} as ${varName} } from ${quote}${importPath}${quote};`;
|
|
39
|
+
if (!imports.some(imp => imp.includes(`${varName}`))) {
|
|
40
|
+
imports.push(importStatement);
|
|
41
|
+
}
|
|
42
|
+
// Remove the entire const declaration - the import statement replaces it
|
|
43
|
+
return '';
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
if (!hasChanges || imports.length === 0) return null;
|
|
47
|
+
|
|
48
|
+
// Prepend all imports at the top of the file (after any existing imports)
|
|
49
|
+
// Find the last import statement
|
|
50
|
+
const lastImportMatch = transformed.match(/^import\s+.*$/gm);
|
|
51
|
+
if (lastImportMatch) {
|
|
52
|
+
const lastImportIndex = transformed.lastIndexOf(lastImportMatch[lastImportMatch.length - 1]);
|
|
53
|
+
const insertIndex = transformed.indexOf('\n', lastImportIndex) + 1;
|
|
54
|
+
transformed = transformed.slice(0, insertIndex) + imports.join('\n') + '\n' + transformed.slice(insertIndex);
|
|
55
|
+
} else {
|
|
56
|
+
// No imports found, add at the top
|
|
57
|
+
transformed = imports.join('\n') + '\n' + transformed;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
code: transformed,
|
|
62
|
+
map: null,
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|