@codemoreira/esad 1.2.5 → 1.2.7

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/bin/esad.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  const { program } = require('commander');
4
4
  const pkg = require('../package.json');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemoreira/esad",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
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",
@@ -1,41 +1,129 @@
1
+ const path = require('node:path');
2
+ const fs = require('node:fs');
1
3
  const Repack = require('@callstack/repack');
4
+ const { ExpoModulesPlugin } = require('@callstack/repack-plugin-expo-modules');
5
+ const { ProvidePlugin, DefinePlugin } = require('@rspack/core');
2
6
 
3
7
  /**
4
8
  * ESAD Re.Pack Plugin Wrapper
5
- * Abstracts away the boilerplate of Module Federation for SuperApps.
9
+ * Abstracts away the boilerplate of Module Federation and SDK integration for SuperApps.
6
10
  *
11
+ * @param {Object} env Rspack environment
7
12
  * @param {Object} options
8
13
  * @param {string} options.type 'host' | 'module'
9
14
  * @param {string} options.id Unique module or host ID
15
+ * @param {string} options.dirname Base directory (__dirname)
16
+ * @param {Object} [options.shared] Additional shared dependencies
17
+ * @param {Object} [options.exposes] Modules to expose (for modules)
18
+ * @param {Object} [options.remotes] Remote modules (for host)
10
19
  */
11
- function withESAD(options) {
12
- return (env) => {
13
- // In a real scenario, we merge heavily with Repack.getTemplateConfig here
14
- console.log(`[ESAD Plugin] Applying Zero-Config Re.Pack profile for ${options.type.toUpperCase()}: ${options.id}`);
15
-
16
- // Ensure the esad state library is ALWAYS shared
17
- const sharedConfig = {
18
- react: { singleton: true, eager: options.type === 'host' },
19
- 'react-native': { singleton: true, eager: options.type === 'host' },
20
- 'esad/client': { singleton: true, eager: true } // Crucial for Global State
21
- };
20
+ function withESAD(env, options) {
21
+ const isDev = env.dev !== false;
22
+ const dirname = options.dirname;
23
+ const pkgPath = path.resolve(dirname, 'package.json');
24
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
25
+ const id = options.id.replace(/-/g, '_');
22
26
 
23
- return {
24
- // Configuration abstraction
25
- plugins: [
26
- new Repack.plugins.ModuleFederationPlugin({
27
- name: options.id.replace(/-/g, '_'),
28
- shared: sharedConfig,
29
- // If type is module, also configure exposes
30
- ...(options.type === 'module' && {
31
- exposes: {
32
- './App': './src/App'
33
- }
34
- })
35
- })
36
- ]
37
- };
27
+ console.log(`[ESAD] Applying Mega-Zero-Config profile for ${options.type.toUpperCase()}: ${id}`);
28
+
29
+ const config = {
30
+ context: dirname,
31
+ entry: options.entry || './index.js',
32
+ output: {
33
+ ...Repack.getOutputOptions(env),
34
+ },
35
+ resolve: {
36
+ ...Repack.getResolveOptions(),
37
+ alias: {
38
+ '@': path.resolve(dirname, '.'),
39
+ // Internal MFv2 & Re.Pack Aliases (Magic)
40
+ '@module-federation/runtime/helpers': path.resolve(dirname, 'node_modules/@module-federation/runtime/dist/helpers.js'),
41
+ '@module-federation/error-codes/browser': path.resolve(dirname, 'node_modules/@module-federation/error-codes/dist/browser.cjs'),
42
+ '@module-federation/sdk': path.resolve(dirname, 'node_modules/@module-federation/sdk'),
43
+
44
+ // ESAD SDK Aliases (Zero-Config)
45
+ '@codemoreira/esad/client': path.resolve(dirname, 'node_modules/@codemoreira/esad/src/client/index.js'),
46
+
47
+ ...Repack.getResolveOptions().alias,
48
+ ...options.alias,
49
+ }
50
+ },
51
+ module: {
52
+ rules: [
53
+ {
54
+ oneOf: [
55
+ {
56
+ test: /\.[cm]?[jt]sx?$/,
57
+ include: [
58
+ /node_modules[\\/]react-native/,
59
+ /node_modules[\\/]@react-native/,
60
+ ],
61
+ type: 'javascript/auto',
62
+ use: {
63
+ loader: '@callstack/repack/babel-swc-loader',
64
+ options: {
65
+ sourceMaps: true,
66
+ parallel: true,
67
+ },
68
+ },
69
+ },
70
+ ...Repack.getJsTransformRules(),
71
+ ]
72
+ },
73
+ ...Repack.getAssetTransformRules(),
74
+ ],
75
+ },
76
+ plugins: [
77
+ new ProvidePlugin({
78
+ process: 'process/browser',
79
+ }),
80
+ new DefinePlugin({
81
+ 'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production'),
82
+ '__DEV__': JSON.stringify(isDev),
83
+ }),
84
+ new ExpoModulesPlugin(),
85
+ new Repack.RepackPlugin(),
86
+ new Repack.plugins.ModuleFederationPluginV2({
87
+ name: id,
88
+ filename: `${id}.container.js.bundle`,
89
+ remotes: options.remotes || {},
90
+ exposes: options.exposes || {},
91
+ dts: false,
92
+ dev: isDev,
93
+ shared: {
94
+ 'react': { singleton: true, eager: true, requiredVersion: pkg.dependencies.react },
95
+ 'react/jsx-runtime': { singleton: true, eager: true, requiredVersion: pkg.dependencies.react },
96
+ 'react-native': { singleton: true, eager: true, requiredVersion: pkg.dependencies['react-native'] },
97
+ 'react-native-safe-area-context': { singleton: true, eager: true, requiredVersion: pkg.dependencies['react-native-safe-area-context'] },
98
+ '@codemoreira/esad': { singleton: true, eager: true },
99
+ ...options.shared
100
+ }
101
+ })
102
+ ],
38
103
  };
104
+
105
+ // Add Host-specific DevServer magic for Expo
106
+ if (options.type === 'host') {
107
+ config.devServer = {
108
+ setupMiddlewares: (middlewares) => {
109
+ middlewares.unshift((req, res, next) => {
110
+ if (req.url.startsWith('/.expo/.virtual-metro-entry.bundle')) {
111
+ const query = req.url.split('?')[1];
112
+ const isMap = req.url.includes('.map');
113
+ const target = isMap ? '/index.bundle.map' : '/index.bundle';
114
+ const location = query ? `${target}?${query}` : target;
115
+ res.writeHead(302, { Location: location });
116
+ res.end();
117
+ return;
118
+ }
119
+ next();
120
+ });
121
+ return middlewares;
122
+ },
123
+ };
124
+ }
125
+
126
+ return config;
39
127
  }
40
128
 
41
129
  module.exports = { withESAD };