@codemoreira/esad 2.0.1-25 → 2.0.1-26
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 +1 -1
- package/src/plugin/env-shim.js +16 -0
- package/src/plugin/index.js +8 -17
- package/src/plugin/runtime-env.js +0 -15
package/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ESAD Runtime Environment Shim
|
|
3
|
+
* Injected at the very beginning of the bundle to prevent "TypeError: right operand of 'in' is not an object"
|
|
4
|
+
*/
|
|
5
|
+
if (typeof process === 'undefined') {
|
|
6
|
+
// Use globalThis for modern JS environments (Hermes/V8)
|
|
7
|
+
const globalObj = typeof globalThis !== 'undefined' ? globalThis : (typeof global !== 'undefined' ? global : {});
|
|
8
|
+
globalObj.process = { env: {} };
|
|
9
|
+
} else if (!process.env) {
|
|
10
|
+
process.env = {};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// These placeholders are replaced by Rspack's DefinePlugin during build time
|
|
14
|
+
process.env.EXPO_OS = '__EXPO_OS__';
|
|
15
|
+
process.env.NODE_ENV = '__NODE_ENV__';
|
|
16
|
+
process.env.REPACK_PLATFORM = '__REPACK_PLATFORM__';
|
package/src/plugin/index.js
CHANGED
|
@@ -2,7 +2,7 @@ const path = require('node:path');
|
|
|
2
2
|
const fs = require('node:fs');
|
|
3
3
|
const Repack = require('@callstack/repack');
|
|
4
4
|
const { ExpoModulesPlugin } = require('@callstack/repack-plugin-expo-modules');
|
|
5
|
-
const { DefinePlugin
|
|
5
|
+
const { DefinePlugin } = require('@rspack/core');
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* ESAD Re.Pack Plugin Wrapper
|
|
@@ -38,7 +38,10 @@ function withESAD(env, options) {
|
|
|
38
38
|
const config = {
|
|
39
39
|
mode: isDev ? 'development' : 'production',
|
|
40
40
|
context: dirname,
|
|
41
|
-
entry:
|
|
41
|
+
entry: [
|
|
42
|
+
path.resolve(__dirname, 'env-shim.js'),
|
|
43
|
+
options.entry || './index.js'
|
|
44
|
+
],
|
|
42
45
|
output: {
|
|
43
46
|
path: path.resolve(dirname, 'build', platform),
|
|
44
47
|
filename: 'index.bundle',
|
|
@@ -106,26 +109,14 @@ function withESAD(env, options) {
|
|
|
106
109
|
},
|
|
107
110
|
plugins: [
|
|
108
111
|
new DefinePlugin({
|
|
112
|
+
'__EXPO_OS__': JSON.stringify(platform),
|
|
113
|
+
'__NODE_ENV__': JSON.stringify(isDev ? 'development' : 'production'),
|
|
114
|
+
'__REPACK_PLATFORM__': JSON.stringify(platform),
|
|
109
115
|
'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production'),
|
|
110
116
|
'process.env.EXPO_OS': JSON.stringify(platform),
|
|
111
117
|
'process.env.REPACK_PLATFORM': JSON.stringify(platform),
|
|
112
|
-
'process.env': JSON.stringify({
|
|
113
|
-
NODE_ENV: isDev ? 'development' : 'production',
|
|
114
|
-
EXPO_OS: platform,
|
|
115
|
-
REPACK_PLATFORM: platform,
|
|
116
|
-
}),
|
|
117
118
|
'__DEV__': JSON.stringify(isDev),
|
|
118
119
|
}),
|
|
119
|
-
new BannerPlugin({
|
|
120
|
-
raw: true,
|
|
121
|
-
entryOnly: true,
|
|
122
|
-
banner: `
|
|
123
|
-
if (typeof process === 'undefined') { var process = { env: {} }; }
|
|
124
|
-
if (typeof process.env === 'undefined') { process.env = {}; }
|
|
125
|
-
process.env.EXPO_OS = '${platform}';
|
|
126
|
-
process.env.NODE_ENV = '${isDev ? 'development' : 'production'}';
|
|
127
|
-
`,
|
|
128
|
-
}),
|
|
129
120
|
new ExpoModulesPlugin(),
|
|
130
121
|
new Repack.RepackPlugin(),
|
|
131
122
|
new Repack.plugins.ModuleFederationPluginV2({
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ESAD Runtime Environment Polyfill
|
|
3
|
-
* This file is injected at the very beginning of the bundle to ensure
|
|
4
|
-
* that Expo and React Navigation find the expected environment variables.
|
|
5
|
-
*/
|
|
6
|
-
if (typeof global !== 'undefined') {
|
|
7
|
-
global.process = global.process || {};
|
|
8
|
-
global.process.env = global.process.env || {};
|
|
9
|
-
|
|
10
|
-
// These values are placeholders that will be replaced by DefinePlugin
|
|
11
|
-
// or set via BannerPlugin, but here we provide a safe fallback object.
|
|
12
|
-
if (typeof global.process.env !== 'object' || global.process.env === null) {
|
|
13
|
-
global.process.env = {};
|
|
14
|
-
}
|
|
15
|
-
}
|