@codemoreira/esad 1.2.5 → 1.2.6
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 +1 -1
- package/package.json +1 -1
- package/src/plugin/index.js +112 -27
package/bin/esad.js
CHANGED
package/package.json
CHANGED
package/src/plugin/index.js
CHANGED
|
@@ -1,41 +1,126 @@
|
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
resolve: {
|
|
33
|
+
...Repack.getResolveOptions(),
|
|
34
|
+
alias: {
|
|
35
|
+
'@': path.resolve(dirname, '.'),
|
|
36
|
+
// Internal MFv2 & Re.Pack Aliases (Magic)
|
|
37
|
+
'@module-federation/runtime/helpers': path.resolve(dirname, 'node_modules/@module-federation/runtime/dist/helpers.js'),
|
|
38
|
+
'@module-federation/error-codes/browser': path.resolve(dirname, 'node_modules/@module-federation/error-codes/dist/browser.cjs'),
|
|
39
|
+
'@module-federation/sdk': path.resolve(dirname, 'node_modules/@module-federation/sdk'),
|
|
40
|
+
|
|
41
|
+
// ESAD SDK Aliases (Zero-Config)
|
|
42
|
+
'@codemoreira/esad/client': path.resolve(dirname, 'node_modules/@codemoreira/esad/src/client/index.js'),
|
|
43
|
+
|
|
44
|
+
...Repack.getResolveOptions().alias,
|
|
45
|
+
...options.alias,
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
module: {
|
|
49
|
+
rules: [
|
|
50
|
+
{
|
|
51
|
+
oneOf: [
|
|
52
|
+
{
|
|
53
|
+
test: /\.[cm]?[jt]sx?$/,
|
|
54
|
+
include: [
|
|
55
|
+
/node_modules[\\/]react-native/,
|
|
56
|
+
/node_modules[\\/]@react-native/,
|
|
57
|
+
],
|
|
58
|
+
type: 'javascript/auto',
|
|
59
|
+
use: {
|
|
60
|
+
loader: '@callstack/repack/babel-swc-loader',
|
|
61
|
+
options: {
|
|
62
|
+
sourceMaps: true,
|
|
63
|
+
parallel: true,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
...Repack.getJsTransformRules(),
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
...Repack.getAssetTransformRules(),
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
plugins: [
|
|
74
|
+
new ProvidePlugin({
|
|
75
|
+
process: 'process/browser',
|
|
76
|
+
}),
|
|
77
|
+
new DefinePlugin({
|
|
78
|
+
'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production'),
|
|
79
|
+
'__DEV__': JSON.stringify(isDev),
|
|
80
|
+
}),
|
|
81
|
+
new ExpoModulesPlugin(),
|
|
82
|
+
new Repack.RepackPlugin(),
|
|
83
|
+
new Repack.plugins.ModuleFederationPluginV2({
|
|
84
|
+
name: id,
|
|
85
|
+
filename: `${id}.container.js.bundle`,
|
|
86
|
+
remotes: options.remotes || {},
|
|
87
|
+
exposes: options.exposes || {},
|
|
88
|
+
dts: false,
|
|
89
|
+
dev: isDev,
|
|
90
|
+
shared: {
|
|
91
|
+
'react': { singleton: true, eager: true, requiredVersion: pkg.dependencies.react },
|
|
92
|
+
'react/jsx-runtime': { singleton: true, eager: true, requiredVersion: pkg.dependencies.react },
|
|
93
|
+
'react-native': { singleton: true, eager: true, requiredVersion: pkg.dependencies['react-native'] },
|
|
94
|
+
'react-native-safe-area-context': { singleton: true, eager: true, requiredVersion: pkg.dependencies['react-native-safe-area-context'] },
|
|
95
|
+
'@codemoreira/esad': { singleton: true, eager: true },
|
|
96
|
+
...options.shared
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
],
|
|
38
100
|
};
|
|
101
|
+
|
|
102
|
+
// Add Host-specific DevServer magic for Expo
|
|
103
|
+
if (options.type === 'host') {
|
|
104
|
+
config.devServer = {
|
|
105
|
+
setupMiddlewares: (middlewares) => {
|
|
106
|
+
middlewares.unshift((req, res, next) => {
|
|
107
|
+
if (req.url.startsWith('/.expo/.virtual-metro-entry.bundle')) {
|
|
108
|
+
const query = req.url.split('?')[1];
|
|
109
|
+
const isMap = req.url.includes('.map');
|
|
110
|
+
const target = isMap ? '/index.bundle.map' : '/index.bundle';
|
|
111
|
+
const location = query ? `${target}?${query}` : target;
|
|
112
|
+
res.writeHead(302, { Location: location });
|
|
113
|
+
res.end();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
next();
|
|
117
|
+
});
|
|
118
|
+
return middlewares;
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return config;
|
|
39
124
|
}
|
|
40
125
|
|
|
41
126
|
module.exports = { withESAD };
|