@codemoreira/esad 2.0.1-2 → 2.0.1-3

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": "@codemoreira/esad",
3
- "version": "2.0.1-2",
3
+ "version": "2.0.1-3",
4
4
  "description": "Easy Super App Development - Zero-Config CLI and DevTools for React Native Module Federation",
5
5
  "main": "src/plugin/index.js",
6
6
  "types": "./src/plugin/index.d.ts",
@@ -63,13 +63,23 @@ export default {
63
63
  await renameProject(hostDir, hostName);
64
64
 
65
65
  // Inject local context mock immediately to avoid crashes on fresh boot
66
- fs.writeJsonSync(path.join(hostDir, '.esad.context.json'), { projectName, devMode: {} }, { spaces: 2 });
66
+ const context = { projectName, devMode: {} };
67
+ fs.writeJsonSync(path.join(hostDir, '.esad.context.json'), context, { spaces: 2 });
67
68
 
68
- console.log(`\nšŸ“¦ Installing dependencies into host...`);
69
+ // Stabilize filesystem before heavy operations
70
+ await new Promise(res => setTimeout(res, 500));
71
+
72
+ console.log(`\nšŸ“¦ Installing dependencies into host (this may take a minute)...`);
69
73
  await runProcess('npm', ['install'], { cwd: hostDir });
70
- console.log(`\nšŸŽ‰ ESAD Workspace Initialized!`);
71
- console.log(`-> cd ${projectName}/${hostName}\n-> esad host dev (to start Host)`);
74
+
75
+ console.log(chalk.green(`\nšŸŽ‰ ESAD Workspace Initialized successfully!`));
76
+ console.log(chalk.cyan(`\nšŸ‘‰ Next steps:`));
77
+ console.log(` 1. cd ${projectName}/${hostName}`);
78
+ console.log(` 2. esad host dev (to start Host)`);
79
+ console.log(` 3. esad dev (in a module folder to federate)\n`);
72
80
  } catch (err) {
73
- console.error(`āŒ Failed to init Host:`, err.message);
81
+ console.error(chalk.red(`\nāŒ Failed to initialize workspace:`));
82
+ console.error(chalk.yellow(` ${err.message}`));
83
+ console.log(chalk.dim(`\n Check npm logs if it was an installation error.`));
74
84
  }
75
85
  };
@@ -3,7 +3,8 @@ const nativeSpawn = require('child_process').spawn;
3
3
  const path = require('path');
4
4
  const fs = require('fs-extra');
5
5
 
6
- const runProcess = (cmd, args, cwd = process.cwd()) => {
6
+ const runProcess = (cmd, args, options = process.cwd()) => {
7
+ const cwd = typeof options === 'string' ? options : (options.cwd || process.cwd());
7
8
  let childRef;
8
9
  const promise = new Promise((resolve, reject) => {
9
10
  let finished = false;
@@ -10,20 +10,19 @@ const updateDevMode = (configPath, moduleId, url) => {
10
10
 
11
11
  // 1. Ensure devMode object exists
12
12
  if (!content.includes('devMode:')) {
13
- // Inject devMode before the last closing brace (naive but effective for clean configs)
14
- content = content.replace(/}([^}]*)$/, ` devMode: {},\n}$1`);
13
+ // Inject devMode after the opening brace of export default
14
+ content = content.replace(/(export default\s*\{)/, `$1\n devMode: {},\n`);
15
15
  }
16
16
 
17
17
  // 2. Add or update the module entry
18
18
  const entryRegex = new RegExp(`(['"]${moduleId}['"]|${moduleId}):\\s*['"]([^'"]*)['"]`, 'g');
19
19
 
20
20
  if (entryRegex.test(content)) {
21
- // Update existing
22
- content = content.replace(entryRegex, `$1: '${url}'`);
21
+ // Update existing entry
22
+ content = content.replace(entryRegex, `'${moduleId}': '${url}'`);
23
23
  } else {
24
- // Insert new entry into devMode object
25
- const devModeRegex = /(devMode:\s*{)/;
26
- content = content.replace(devModeRegex, `$1\n '${moduleId}': '${url}',`);
24
+ // Insert new entry right after devMode: {
25
+ content = content.replace(/(devMode:\s*\{)/, `$1\n '${moduleId}': '${url}',`);
27
26
  }
28
27
 
29
28
  fs.writeFileSync(configPath, content);
@@ -44,9 +43,9 @@ const clearAllDevMode = (configPath) => {
44
43
  if (!fs.existsSync(configPath)) return;
45
44
  let content = fs.readFileSync(configPath, 'utf8');
46
45
 
47
- // Remove the entire devMode block
48
- const devModeBlockRegex = /\s*devMode:\s*{[\s\S]*?},?/g;
49
- content = content.replace(devModeBlockRegex, '');
46
+ // Simply reset devMode to empty object
47
+ const devModeBlockRegex = /devMode:\s*{[\s\S]*?}/;
48
+ content = content.replace(devModeBlockRegex, 'devMode: {}');
50
49
 
51
50
  fs.writeFileSync(configPath, content);
52
51
  };