@shellui/cli 0.0.10 → 0.0.13

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.10",
3
+ "version": "0.0.13",
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.10"
33
+ "@shellui/core": "0.0.13"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public"
package/src/cli.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { cac } from 'cac';
2
2
  import { startCommand, buildCommand } from './commands/index.js';
3
+ import pkg from '../package.json' with { type: 'json' };
3
4
 
4
5
  const cli = cac('shellui');
5
6
 
@@ -10,5 +11,5 @@ cli.command('build [root]', 'Build the shellui application').action(buildCommand
10
11
 
11
12
  // Setup CLI metadata
12
13
  cli.help();
13
- cli.version('0.0.1');
14
+ cli.version(pkg.version);
14
15
  cli.parse();
@@ -11,7 +11,6 @@ import {
11
11
  createPostCSSConfig,
12
12
  createViteDefine,
13
13
  resolvePackagePath,
14
- inlineLazyImportsPlugin,
15
14
  } from '../utils/index.js';
16
15
 
17
16
  /**
@@ -84,7 +83,7 @@ export async function buildCommand(root = '.') {
84
83
  // Build main app
85
84
  await build({
86
85
  root: coreSrcPath,
87
- plugins: [react(), inlineLazyImportsPlugin()],
86
+ plugins: [react()],
88
87
  define: createViteDefine(config),
89
88
  resolve: {
90
89
  alias: resolveAlias,
@@ -10,7 +10,6 @@ import {
10
10
  createPostCSSConfig,
11
11
  createViteDefine,
12
12
  resolvePackagePath,
13
- inlineLazyImportsPlugin,
14
13
  } from '../utils/index.js';
15
14
  import { serviceWorkerDevPlugin } from '../utils/service-worker-plugin.js';
16
15
 
@@ -40,7 +39,7 @@ async function startServer(root, cwd, shouldOpen = false) {
40
39
 
41
40
  const server = await createServer({
42
41
  root: coreSrcPath,
43
- plugins: [react(), inlineLazyImportsPlugin(), serviceWorkerDevPlugin(corePackagePath, coreSrcPath)],
42
+ plugins: [react(), serviceWorkerDevPlugin(corePackagePath, coreSrcPath)],
44
43
  define: createViteDefine(config),
45
44
  resolve: {
46
45
  alias: createResolveAlias(),
@@ -54,12 +53,6 @@ async function startServer(root, cwd, shouldOpen = false) {
54
53
  esbuild: {
55
54
  sourcemap: false,
56
55
  },
57
- // Prevent Vite from pre-bundling @shellui/core when it's in node_modules
58
- // We want our transform plugin to handle lazy imports, not esbuild's pre-bundler
59
- // This ensures consistent behavior between workspace and npm-installed packages
60
- optimizeDeps: {
61
- exclude: ['@shellui/core'],
62
- },
63
56
  server: {
64
57
  port: config.port || 3000,
65
58
  open: shouldOpen,
@@ -13,4 +13,3 @@ export {
13
13
  createPostCSSConfig,
14
14
  createViteDefine,
15
15
  } from './vite.js';
16
- export { inlineLazyImportsPlugin } from './inline-lazy-imports-plugin.js';
@@ -8,19 +8,17 @@ const require = createRequire(import.meta.url);
8
8
 
9
9
  /**
10
10
  * Resolve the path to a package in the monorepo or node_modules
11
+ * Works in both workspace mode (monorepo) and npm-installed mode
11
12
  * @param {string} packageName - The name of the package
12
13
  * @returns {string} The absolute path to the package
13
14
  */
14
15
  export function resolvePackagePath(packageName) {
15
16
  try {
16
17
  // Try to resolve the package using require.resolve
18
+ // This works for both workspace packages (via pnpm workspace) and npm-installed packages
17
19
  const packageJsonPath = require.resolve(`${packageName}/package.json`);
18
- return path.dirname(packageJsonPath);
19
- } catch (e) {
20
- // Fallback: assume workspace structure or pnpm symlinked node_modules
21
- // Go up from cli/src/utils/package-path.js -> cli/src/utils -> cli/src -> cli -> packages -> packageName
22
- const packagesDir = path.resolve(__dirname, '../../../');
23
- const resolved = path.join(packagesDir, packageName.replace('@shellui/', ''));
20
+ const resolved = path.dirname(packageJsonPath);
21
+
24
22
  // Resolve symlinks to get the canonical path — pnpm uses symlinks that
25
23
  // point to different .pnpm/ directories; Vite resolves real paths so we
26
24
  // need to be consistent to avoid mismatched root vs input paths.
@@ -29,6 +27,27 @@ export function resolvePackagePath(packageName) {
29
27
  } catch {
30
28
  return resolved;
31
29
  }
30
+ } catch (e) {
31
+ // Fallback: assume workspace structure (for development in monorepo)
32
+ // Go up from cli/src/utils/package-path.js -> cli/src/utils -> cli/src -> cli -> packages -> packageName
33
+ const packagesDir = path.resolve(__dirname, '../../../');
34
+ const resolved = path.join(packagesDir, packageName.replace('@shellui/', ''));
35
+
36
+ // Only use this fallback if the path exists (workspace mode)
37
+ if (fs.existsSync(resolved)) {
38
+ try {
39
+ return fs.realpathSync(resolved);
40
+ } catch {
41
+ return resolved;
42
+ }
43
+ }
44
+
45
+ // If we get here, the package wasn't found
46
+ throw new Error(
47
+ `Package "${packageName}" not found. ` +
48
+ `Make sure it's installed (npm/pnpm install) or available in the workspace. ` +
49
+ `Original error: ${e.message}`
50
+ );
32
51
  }
33
52
  }
34
53
 
package/src/utils/vite.js CHANGED
@@ -1,15 +1,36 @@
1
1
  import path from 'path';
2
+ import fs from 'fs';
2
3
  import tailwindcssPlugin from '@tailwindcss/postcss';
3
4
  import autoprefixerPlugin from 'autoprefixer';
4
5
  import { resolvePackagePath, resolveSdkEntry } from './index.js';
5
6
 
6
7
  /**
7
8
  * Get the path to the core package source directory
9
+ * Works in both workspace mode (monorepo) and npm-installed mode
8
10
  * @returns {string} Absolute path to core package src directory
9
11
  */
10
12
  export function getCoreSrcPath() {
11
13
  const corePackagePath = resolvePackagePath('@shellui/core');
12
- return path.join(corePackagePath, 'src');
14
+ const srcPath = path.join(corePackagePath, 'src');
15
+
16
+ // Verify src directory exists (should always exist since it's in package.json files)
17
+ if (!fs.existsSync(srcPath)) {
18
+ throw new Error(
19
+ `Core package src directory not found at ${srcPath}. ` +
20
+ `Make sure @shellui/core is properly installed and includes the src directory.`
21
+ );
22
+ }
23
+
24
+ // Verify index.html exists (required for dev server)
25
+ const indexHtmlPath = path.join(srcPath, 'index.html');
26
+ if (!fs.existsSync(indexHtmlPath)) {
27
+ throw new Error(
28
+ `Core package index.html not found at ${indexHtmlPath}. ` +
29
+ `Make sure @shellui/core is properly installed.`
30
+ );
31
+ }
32
+
33
+ return srcPath;
13
34
  }
14
35
 
15
36
  /**
@@ -1,66 +0,0 @@
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
- }