@codemoreira/esad 1.4.6-2 → 1.4.6-21

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,96 +1,96 @@
1
- const { runProcess } = require('./process');
2
- const fs = require('fs-extra');
3
- const path = require('path');
4
-
5
- /**
6
- * Clones a template repository and cleans up the .git folder
7
- */
8
- async function cloneTemplate(url, dest) {
9
- console.log(`\nšŸ“„ Cloning template: ${url}...`);
10
- await runProcess('git', ['clone', url, dest]);
11
-
12
- const gitDir = path.join(dest, '.git');
13
- if (fs.existsSync(gitDir)) {
14
- await fs.remove(gitDir);
15
- console.log(`āœ… Detached from template repository.`);
16
- }
17
- }
18
-
19
- /**
20
- * Renames the project in package.json and app.json
21
- */
22
- async function renameProject(targetDir, newName) {
23
- const pkgPath = path.join(targetDir, 'package.json');
24
- const appJsonPath = path.join(targetDir, 'app.json');
25
-
26
- if (fs.existsSync(pkgPath)) {
27
- const pkg = await fs.readJson(pkgPath);
28
- pkg.name = newName;
29
- await fs.writeJson(pkgPath, pkg, { spaces: 2 });
30
- console.log(`āœ… Updated package.json name: ${newName}`);
31
- }
32
-
33
- if (fs.existsSync(appJsonPath)) {
34
- const appJson = await fs.readJson(appJsonPath);
35
- if (appJson.expo) {
36
- appJson.expo.name = newName;
37
- appJson.expo.slug = newName;
38
- if (appJson.expo.android) {
39
- appJson.expo.android.package = `com.anonymous.${newName.replace(/[^a-zA-Z0-9]/g, '')}`;
40
- }
41
- } else {
42
- appJson.name = newName;
43
- appJson.slug = newName;
44
- }
45
- await fs.writeJson(appJsonPath, appJson, { spaces: 2 });
46
- console.log(`āœ… Updated app.json name/slug/package.`);
47
- }
48
-
49
- // 3. Update Rspack Config if exists
50
- const rspackPath = path.join(targetDir, 'rspack.config.mjs');
51
- if (fs.existsSync(rspackPath)) {
52
- let content = await fs.readFile(rspackPath, 'utf8');
53
- const regex = /id:\s*['"][^'"]+['"]/;
54
- if (regex.test(content)) {
55
- content = content.replace(regex, `id: '${newName}'`);
56
- await fs.writeFile(rspackPath, content);
57
- console.log(`āœ… Updated rspack.config.mjs id: ${newName}`);
58
- }
59
- }
60
- }
61
-
62
- /**
63
- * Prepares the native folders and applies Re.Pack patches
64
- */
65
- async function prepareNative(cwd, platform = 'android') {
66
- if (!fs.existsSync(path.join(cwd, 'android')) && (platform === 'android' || platform === 'all')) {
67
- console.log(`šŸ“¦ Native folder not found. Running expo prebuild...`);
68
- await runProcess('npx', ['expo', 'prebuild', '--platform', 'android'], cwd);
69
- }
70
-
71
- // Apply Gradle Patch (Android)
72
- const buildGradlePath = path.join(cwd, 'android/app/build.gradle');
73
- if (fs.existsSync(buildGradlePath)) {
74
- let content = await fs.readFile(buildGradlePath, 'utf8');
75
- if (!content.includes('project.ext.react')) {
76
- const patch = `\nproject.ext.react = [\n bundleCommand: "repack-bundle",\n bundleConfig: "rspack.config.mjs"\n]\n\n`;
77
- content = content.replace(/react \{/, `${patch}react {`);
78
- await fs.writeFile(buildGradlePath, content);
79
- console.log(`āœ… Patched android/app/build.gradle for Re.Pack.`);
80
- }
81
- }
82
-
83
- // Create react-native.config.js if missing
84
- const rnConfigPath = path.join(cwd, 'react-native.config.js');
85
- if (!fs.existsSync(rnConfigPath)) {
86
- const content = `module.exports = {\n commands: require('@callstack/repack/commands/rspack'),\n};\n`;
87
- await fs.writeFile(rnConfigPath, content);
88
- console.log(`āœ… Generated react-native.config.js.`);
89
- }
90
- }
91
-
92
- module.exports = {
93
- cloneTemplate,
94
- renameProject,
95
- prepareNative
96
- };
1
+ const { runProcess } = require('./process');
2
+ const fs = require('fs-extra');
3
+ const path = require('path');
4
+
5
+ /**
6
+ * Clones a template repository and cleans up the .git folder
7
+ */
8
+ async function cloneTemplate(url, dest) {
9
+ console.log(`\nšŸ“„ Cloning template: ${url}...`);
10
+ await runProcess('git', ['clone', url, dest]);
11
+
12
+ const gitDir = path.join(dest, '.git');
13
+ if (fs.existsSync(gitDir)) {
14
+ await fs.remove(gitDir);
15
+ console.log(`āœ… Detached from template repository.`);
16
+ }
17
+ }
18
+
19
+ /**
20
+ * Renames the project in package.json and app.json
21
+ */
22
+ async function renameProject(targetDir, newName) {
23
+ const pkgPath = path.join(targetDir, 'package.json');
24
+ const appJsonPath = path.join(targetDir, 'app.json');
25
+
26
+ if (fs.existsSync(pkgPath)) {
27
+ const pkg = await fs.readJson(pkgPath);
28
+ pkg.name = newName;
29
+ await fs.writeJson(pkgPath, pkg, { spaces: 2 });
30
+ console.log(`āœ… Updated package.json name: ${newName}`);
31
+ }
32
+
33
+ if (fs.existsSync(appJsonPath)) {
34
+ const appJson = await fs.readJson(appJsonPath);
35
+ if (appJson.expo) {
36
+ appJson.expo.name = newName;
37
+ appJson.expo.slug = newName;
38
+ if (appJson.expo.android) {
39
+ appJson.expo.android.package = `com.anonymous.${newName.replace(/[^a-zA-Z0-9]/g, '')}`;
40
+ }
41
+ } else {
42
+ appJson.name = newName;
43
+ appJson.slug = newName;
44
+ }
45
+ await fs.writeJson(appJsonPath, appJson, { spaces: 2 });
46
+ console.log(`āœ… Updated app.json name/slug/package.`);
47
+ }
48
+
49
+ // 3. Update Rspack Config if exists
50
+ const rspackPath = path.join(targetDir, 'rspack.config.mjs');
51
+ if (fs.existsSync(rspackPath)) {
52
+ let content = await fs.readFile(rspackPath, 'utf8');
53
+ const regex = /id:\s*['"][^'"]+['"]/;
54
+ if (regex.test(content)) {
55
+ content = content.replace(regex, `id: '${newName}'`);
56
+ await fs.writeFile(rspackPath, content);
57
+ console.log(`āœ… Updated rspack.config.mjs id: ${newName}`);
58
+ }
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Prepares the native folders and applies Re.Pack patches
64
+ */
65
+ async function prepareNative(cwd, platform = 'android') {
66
+ if (!fs.existsSync(path.join(cwd, 'android')) && (platform === 'android' || platform === 'all')) {
67
+ console.log(`šŸ“¦ Native folder not found. Running expo prebuild...`);
68
+ await runProcess('npx', ['expo', 'prebuild', '--platform', 'android'], cwd);
69
+ }
70
+
71
+ // Apply Gradle Patch (Android)
72
+ const buildGradlePath = path.join(cwd, 'android/app/build.gradle');
73
+ if (fs.existsSync(buildGradlePath)) {
74
+ let content = await fs.readFile(buildGradlePath, 'utf8');
75
+ if (!content.includes('project.ext.react')) {
76
+ const patch = `\nproject.ext.react = [\n bundleCommand: "repack-bundle",\n bundleConfig: "rspack.config.mjs"\n]\n\n`;
77
+ content = content.replace(/react \{/, `${patch}react {`);
78
+ await fs.writeFile(buildGradlePath, content);
79
+ console.log(`āœ… Patched android/app/build.gradle for Re.Pack.`);
80
+ }
81
+ }
82
+
83
+ // Create react-native.config.js if missing
84
+ const rnConfigPath = path.join(cwd, 'react-native.config.js');
85
+ if (!fs.existsSync(rnConfigPath)) {
86
+ const content = `module.exports = {\n commands: require('@callstack/repack/commands/rspack'),\n};\n`;
87
+ await fs.writeFile(rnConfigPath, content);
88
+ console.log(`āœ… Generated react-native.config.js.`);
89
+ }
90
+ }
91
+
92
+ module.exports = {
93
+ cloneTemplate,
94
+ renameProject,
95
+ prepareNative
96
+ };
@@ -1,82 +1,69 @@
1
- import { useState, useEffect } from 'react';
2
-
3
- /**
4
- * ESAD Global Event Manager
5
- * This class runs as a true Singleton across the Host and all Federated Modules,
6
- * allowing instant variable sharing without tight coupling.
7
- */
8
- // Unique key to store the global state in the environment (shared across sessions)
9
- const GLOBAL_STORE_KEY = '__ESAD_GLOBAL_STATE__';
10
-
11
- // Initialize the global store if it doesn't already exist.
12
- // This ensures that even if different chunks/modules have their own copy
13
- // of this JS file, they all point to the same memory object in globalThis.
14
- if (!globalThis[GLOBAL_STORE_KEY]) {
15
- globalThis[GLOBAL_STORE_KEY] = {
16
- state: {},
17
- listeners: {}
18
- };
19
- }
20
-
21
- const GlobalStore = globalThis[GLOBAL_STORE_KEY];
22
-
23
- class ESADEventEmitter {
24
- set(key, value) {
25
- GlobalStore.state[key] = value;
26
- if (GlobalStore.listeners[key]) {
27
- GlobalStore.listeners[key].forEach(callback => callback(value));
28
- }
29
- }
30
-
31
- get(key) {
32
- return GlobalStore.state[key];
33
- }
34
-
35
- subscribe(key, callback) {
36
- if (!GlobalStore.listeners[key]) {
37
- GlobalStore.listeners[key] = [];
38
- }
39
- GlobalStore.listeners[key].push(callback);
40
-
41
- // Return unsubscribe function
42
- return () => {
43
- GlobalStore.listeners[key] = GlobalStore.listeners[key].filter(cb => cb !== callback);
44
- };
45
- }
46
- }
47
-
48
- // Global instance (acts as a proxy to the globalStore)
49
- const ESADState = new ESADEventEmitter();
50
-
51
- /**
52
- * React Hook for subscribing to Global State Changes
53
- * @param {string} key Unique identifier for the state slice (e.g. 'auth_token', 'theme')
54
- * @param {any} initialValue Optional initial state fallback
55
- */
56
- export function useESADState(key, initialValue) {
57
- const [val, setVal] = useState(() => {
58
- const existing = ESADState.get(key);
59
- if (existing !== undefined) return existing;
60
- if (initialValue !== undefined) {
61
- ESADState.set(key, initialValue);
62
- return initialValue;
63
- }
64
- return undefined;
65
- });
66
-
67
- useEffect(() => {
68
- // Whenever ESADState.set is called matching this key, this component will re-render
69
- const unsubscribe = ESADState.subscribe(key, (newVal) => {
70
- setVal(newVal);
71
- });
72
- return unsubscribe;
73
- }, [key]);
74
-
75
- const setter = (newVal) => {
76
- ESADState.set(key, newVal);
77
- };
78
-
79
- return [val, setter];
80
- }
81
-
82
- export { ESADState };
1
+ import { useState, useEffect } from 'react';
2
+
3
+ /**
4
+ * ESAD Global Event Manager
5
+ * This class runs as a true Singleton across the Host and all Federated Modules,
6
+ * allowing instant variable sharing without tight coupling.
7
+ */
8
+ class ESADEventEmitter {
9
+ constructor() {
10
+ this.state = {};
11
+ this.listeners = {};
12
+ }
13
+
14
+ set(key, value) {
15
+ this.state[key] = value;
16
+ if (this.listeners[key]) {
17
+ this.listeners[key].forEach(callback => callback(value));
18
+ }
19
+ }
20
+
21
+ get(key) {
22
+ return this.state[key];
23
+ }
24
+
25
+ subscribe(key, callback) {
26
+ if (!this.listeners[key]) this.listeners[key] = [];
27
+ this.listeners[key].push(callback);
28
+ return () => {
29
+ this.listeners[key] = this.listeners[key].filter(cb => cb !== callback);
30
+ };
31
+ }
32
+ }
33
+
34
+ // Because this package is marked as a ModuleFederation Singleton,
35
+ // this instance will be shared identically across all chunks!
36
+ const ESADState = new ESADEventEmitter();
37
+
38
+ /**
39
+ * React Hook for subscribing to Global State Changes
40
+ * @param {string} key Unique identifier for the state slice (e.g. 'auth_token', 'theme')
41
+ * @param {any} initialValue Optional initial state fallback
42
+ */
43
+ export function useESADState(key, initialValue) {
44
+ const [val, setVal] = useState(() => {
45
+ const existing = ESADState.get(key);
46
+ if (existing !== undefined) return existing;
47
+ if (initialValue !== undefined) {
48
+ ESADState.set(key, initialValue);
49
+ return initialValue;
50
+ }
51
+ return undefined;
52
+ });
53
+
54
+ useEffect(() => {
55
+ // Whenever ESADState.set is called matching this key, this component will re-render
56
+ const unsubscribe = ESADState.subscribe(key, (newVal) => {
57
+ setVal(newVal);
58
+ });
59
+ return unsubscribe;
60
+ }, [key]);
61
+
62
+ const setter = (newVal) => {
63
+ ESADState.set(key, newVal);
64
+ };
65
+
66
+ return [val, setter];
67
+ }
68
+
69
+ export { ESADState };
@@ -39,16 +39,15 @@ function withESAD(env, options) {
39
39
  },
40
40
  resolve: {
41
41
  ...Repack.getResolveOptions(),
42
- extensions: [
43
- '.expo.ts', '.expo.tsx', '.expo.js', '.expo.jsx',
44
- '.native.ts', '.native.tsx', '.native.js', '.native.jsx',
45
- ...Repack.getResolveOptions().extensions,
46
- ],
47
42
  alias: {
48
- '@': dirname,
49
- 'expo-router': path.resolve(dirname, 'node_modules/expo-router'),
50
- 'react-native': path.resolve(dirname, 'node_modules/react-native'),
43
+ '@': path.resolve(dirname, '.'),
44
+ // Internal MFv2 & Re.Pack Aliases (Magic)
45
+ '@module-federation/runtime/helpers': path.resolve(dirname, 'node_modules/@module-federation/runtime/dist/helpers.js'),
46
+ '@module-federation/error-codes/browser': path.resolve(dirname, 'node_modules/@module-federation/error-codes/dist/browser.cjs'),
47
+ '@module-federation/sdk': path.resolve(dirname, 'node_modules/@module-federation/sdk'),
48
+
51
49
  ...Repack.getResolveOptions().alias,
50
+ ...(options.alias || {}),
52
51
  }
53
52
  },
54
53
  module: {
@@ -56,21 +55,19 @@ function withESAD(env, options) {
56
55
  {
57
56
  oneOf: [
58
57
  {
59
- test: /\.[jt]sx?$/,
58
+ test: /\.[cm]?[jt]sx?$/,
60
59
  include: [
61
- path.resolve(dirname, 'app'),
62
- path.resolve(dirname, 'index.js'),
63
- /[\\/]node_modules[\\/](expo-router|react-native|@react-native|expo-modules-core)[\\/]/
60
+ /node_modules[\\/]react-native[\\/]/,
61
+ /node_modules[\\/]@react-native[\\/]/,
64
62
  ],
63
+ type: 'javascript/auto',
65
64
  use: {
66
65
  loader: 'babel-loader',
67
66
  options: {
68
67
  presets: ['babel-preset-expo'],
69
- babelrc: false,
70
- configFile: false,
68
+ caller: { name: 'repack' },
71
69
  },
72
70
  },
73
- type: 'javascript/auto',
74
71
  },
75
72
  ...Repack.getJsTransformRules(),
76
73
  ]
@@ -100,12 +97,10 @@ function withESAD(env, options) {
100
97
  'react/jsx-runtime': { singleton: true, eager: true, requiredVersion: pkg.dependencies.react },
101
98
  'react-native': { singleton: true, eager: true, requiredVersion: pkg.dependencies['react-native'] },
102
99
  'react-native-safe-area-context': { singleton: true, eager: true, requiredVersion: pkg.dependencies['react-native-safe-area-context'] },
103
- 'expo-router': { singleton: true, eager: true, requiredVersion: pkg.dependencies['expo-router'] },
104
- 'react-native-screens': { singleton: true, eager: true, requiredVersion: pkg.dependencies['react-native-screens'] },
105
- '@codemoreira/esad/client': {
106
- singleton: true,
100
+ '@codemoreira/esad/client': {
101
+ singleton: true,
107
102
  eager: options.type === 'host', // Only eager in host to ensure it's available
108
- import: clientPath
103
+ import: clientPath
109
104
  },
110
105
  ...(options.shared || {})
111
106
  }