@granite-js/plugin-micro-frontend 0.1.34 → 1.0.1
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/CHANGELOG.md +9 -211
- package/dist/index.cjs +59 -42
- package/dist/index.js +46 -39
- package/dist/runtime/index.cjs +13 -12
- package/dist/runtime/index.d.cts +0 -1
- package/dist/runtime/index.d.ts +0 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,222 +1,20 @@
|
|
|
1
1
|
# @granite-js/plugin-micro-frontend
|
|
2
2
|
|
|
3
|
-
## 0.1
|
|
3
|
+
## 1.0.1
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
- @granite-js/utils@0.1.34
|
|
7
|
+
- @granite-js/plugin-core@1.0.1
|
|
8
|
+
- @granite-js/utils@1.0.1
|
|
10
9
|
|
|
11
|
-
## 0.
|
|
10
|
+
## 1.0.0
|
|
12
11
|
|
|
13
|
-
###
|
|
14
|
-
|
|
15
|
-
- @granite-js/plugin-core@0.1.33
|
|
16
|
-
- @granite-js/utils@0.1.33
|
|
17
|
-
|
|
18
|
-
## 0.1.32
|
|
19
|
-
|
|
20
|
-
### Patch Changes
|
|
21
|
-
|
|
22
|
-
- 7572713: bump version up babel
|
|
23
|
-
- Updated dependencies [7572713]
|
|
24
|
-
- @granite-js/plugin-core@0.1.32
|
|
25
|
-
- @granite-js/utils@0.1.32
|
|
26
|
-
|
|
27
|
-
## 0.1.31
|
|
28
|
-
|
|
29
|
-
### Patch Changes
|
|
30
|
-
|
|
31
|
-
- Updated dependencies [9bf8b50]
|
|
32
|
-
- Updated dependencies [e957833]
|
|
33
|
-
- @granite-js/plugin-core@0.1.31
|
|
34
|
-
- @granite-js/utils@0.1.31
|
|
35
|
-
|
|
36
|
-
## 0.1.30
|
|
37
|
-
|
|
38
|
-
### Patch Changes
|
|
39
|
-
|
|
40
|
-
- @granite-js/plugin-core@0.1.30
|
|
41
|
-
- @granite-js/utils@0.1.30
|
|
42
|
-
|
|
43
|
-
## 0.1.29
|
|
44
|
-
|
|
45
|
-
### Patch Changes
|
|
46
|
-
|
|
47
|
-
- Updated dependencies [ed4cdbf]
|
|
48
|
-
- @granite-js/plugin-core@0.1.29
|
|
49
|
-
- @granite-js/utils@0.1.29
|
|
50
|
-
|
|
51
|
-
## 0.1.28
|
|
52
|
-
|
|
53
|
-
### Patch Changes
|
|
54
|
-
|
|
55
|
-
- 1d958cc: ci: provenance
|
|
56
|
-
- Updated dependencies [1d958cc]
|
|
57
|
-
- @granite-js/plugin-core@0.1.28
|
|
58
|
-
- @granite-js/utils@0.1.28
|
|
59
|
-
|
|
60
|
-
## 0.1.27
|
|
61
|
-
|
|
62
|
-
### Patch Changes
|
|
63
|
-
|
|
64
|
-
- e32b020: ci: oidc
|
|
65
|
-
- Updated dependencies [e32b020]
|
|
66
|
-
- @granite-js/plugin-core@0.1.27
|
|
67
|
-
- @granite-js/utils@0.1.27
|
|
68
|
-
|
|
69
|
-
## 0.1.26
|
|
70
|
-
|
|
71
|
-
### Patch Changes
|
|
72
|
-
|
|
73
|
-
- @granite-js/plugin-core@0.1.26
|
|
74
|
-
- @granite-js/utils@0.1.26
|
|
75
|
-
|
|
76
|
-
## 0.1.25
|
|
77
|
-
|
|
78
|
-
### Patch Changes
|
|
79
|
-
|
|
80
|
-
- @granite-js/plugin-core@0.1.25
|
|
81
|
-
- @granite-js/utils@0.1.25
|
|
82
|
-
|
|
83
|
-
## 0.1.24
|
|
84
|
-
|
|
85
|
-
### Patch Changes
|
|
86
|
-
|
|
87
|
-
- Updated dependencies [6e42c3d]
|
|
88
|
-
- @granite-js/plugin-core@0.1.24
|
|
89
|
-
- @granite-js/utils@0.1.24
|
|
90
|
-
|
|
91
|
-
## 0.1.23
|
|
92
|
-
|
|
93
|
-
### Patch Changes
|
|
94
|
-
|
|
95
|
-
- @granite-js/plugin-core@0.1.23
|
|
96
|
-
- @granite-js/utils@0.1.23
|
|
97
|
-
|
|
98
|
-
## 0.1.22
|
|
99
|
-
|
|
100
|
-
### Patch Changes
|
|
101
|
-
|
|
102
|
-
- @granite-js/plugin-core@0.1.22
|
|
103
|
-
- @granite-js/utils@0.1.22
|
|
104
|
-
|
|
105
|
-
## 0.1.21
|
|
106
|
-
|
|
107
|
-
### Patch Changes
|
|
108
|
-
|
|
109
|
-
- @granite-js/plugin-core@0.1.21
|
|
110
|
-
- @granite-js/utils@0.1.21
|
|
111
|
-
|
|
112
|
-
## 0.1.20
|
|
113
|
-
|
|
114
|
-
### Patch Changes
|
|
115
|
-
|
|
116
|
-
- 1df5883: update package.json meta to supports any moduleResolutions
|
|
117
|
-
- @granite-js/plugin-core@0.1.20
|
|
118
|
-
- @granite-js/utils@0.1.20
|
|
119
|
-
|
|
120
|
-
## 0.1.19
|
|
121
|
-
|
|
122
|
-
### Patch Changes
|
|
123
|
-
|
|
124
|
-
- Updated dependencies [e9a3daf]
|
|
125
|
-
- @granite-js/plugin-core@0.1.19
|
|
126
|
-
- @granite-js/utils@0.1.19
|
|
127
|
-
|
|
128
|
-
## 0.1.18
|
|
129
|
-
|
|
130
|
-
### Patch Changes
|
|
131
|
-
|
|
132
|
-
- 58e4df9: define \_\_esModule flag safety
|
|
133
|
-
- @granite-js/plugin-core@0.1.18
|
|
134
|
-
- @granite-js/utils@0.1.18
|
|
135
|
-
|
|
136
|
-
## 0.1.17
|
|
137
|
-
|
|
138
|
-
### Patch Changes
|
|
139
|
-
|
|
140
|
-
- Updated dependencies [9c415df]
|
|
141
|
-
- @granite-js/plugin-core@0.1.17
|
|
142
|
-
- @granite-js/utils@0.1.17
|
|
143
|
-
|
|
144
|
-
## 0.1.16
|
|
145
|
-
|
|
146
|
-
### Patch Changes
|
|
147
|
-
|
|
148
|
-
- 1678419: improve plugin options
|
|
149
|
-
- @granite-js/plugin-core@0.1.16
|
|
150
|
-
- @granite-js/utils@0.1.16
|
|
151
|
-
|
|
152
|
-
## 0.1.15
|
|
153
|
-
|
|
154
|
-
### Patch Changes
|
|
155
|
-
|
|
156
|
-
- d16ee87: Add useInitialProps, useInitialSearchParams hook.
|
|
157
|
-
- Updated dependencies [d16ee87]
|
|
158
|
-
- @granite-js/plugin-core@0.1.15
|
|
159
|
-
- @granite-js/utils@0.1.15
|
|
160
|
-
|
|
161
|
-
## 0.1.14
|
|
162
|
-
|
|
163
|
-
### Patch Changes
|
|
164
|
-
|
|
165
|
-
- @granite-js/plugin-core@0.1.14
|
|
166
|
-
- @granite-js/utils@0.1.14
|
|
167
|
-
|
|
168
|
-
## 0.1.13
|
|
169
|
-
|
|
170
|
-
### Patch Changes
|
|
171
|
-
|
|
172
|
-
- @granite-js/plugin-core@0.1.13
|
|
173
|
-
- @granite-js/utils@0.1.13
|
|
174
|
-
|
|
175
|
-
## 0.1.12
|
|
176
|
-
|
|
177
|
-
### Patch Changes
|
|
178
|
-
|
|
179
|
-
- d1e6585: fix module resolutions
|
|
180
|
-
- Updated dependencies [d1e6585]
|
|
181
|
-
- Updated dependencies [1e99fe1]
|
|
182
|
-
- @granite-js/plugin-core@0.1.12
|
|
183
|
-
- @granite-js/utils@0.1.12
|
|
184
|
-
|
|
185
|
-
## 0.1.11
|
|
186
|
-
|
|
187
|
-
### Patch Changes
|
|
188
|
-
|
|
189
|
-
- Updated dependencies [d3a2b58]
|
|
190
|
-
- @granite-js/plugin-core@0.1.11
|
|
191
|
-
- @granite-js/utils@0.1.11
|
|
192
|
-
|
|
193
|
-
## 0.1.10
|
|
194
|
-
|
|
195
|
-
### Patch Changes
|
|
196
|
-
|
|
197
|
-
- Updated dependencies [9438be5]
|
|
198
|
-
- @granite-js/plugin-core@0.1.10
|
|
199
|
-
- @granite-js/utils@0.1.10
|
|
200
|
-
|
|
201
|
-
## 0.1.9
|
|
202
|
-
|
|
203
|
-
### Patch Changes
|
|
204
|
-
|
|
205
|
-
- Updated dependencies [935bb36]
|
|
206
|
-
- @granite-js/plugin-core@0.1.9
|
|
207
|
-
- @granite-js/utils@0.1.9
|
|
208
|
-
|
|
209
|
-
## 0.1.8
|
|
210
|
-
|
|
211
|
-
### Patch Changes
|
|
212
|
-
|
|
213
|
-
- Updated dependencies [b69366c]
|
|
214
|
-
- @granite-js/plugin-core@0.1.8
|
|
215
|
-
- @granite-js/utils@0.1.8
|
|
12
|
+
### Major Changes
|
|
216
13
|
|
|
217
|
-
|
|
14
|
+
- 260daab: feat: introduce support react native 0.84
|
|
218
15
|
|
|
219
16
|
### Patch Changes
|
|
220
17
|
|
|
221
|
-
-
|
|
222
|
-
- @granite-js/plugin-core@0.
|
|
18
|
+
- Updated dependencies [260daab]
|
|
19
|
+
- @granite-js/plugin-core@1.0.0
|
|
20
|
+
- @granite-js/utils@1.0.0
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -6,12 +7,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
9
|
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
15
20
|
}
|
|
16
21
|
return to;
|
|
17
22
|
};
|
|
@@ -25,7 +30,7 @@ let fs = require("fs");
|
|
|
25
30
|
fs = __toESM(fs);
|
|
26
31
|
let path = require("path");
|
|
27
32
|
path = __toESM(path);
|
|
28
|
-
let
|
|
33
|
+
let _granite_js_utils = require("@granite-js/utils");
|
|
29
34
|
let picocolors = require("picocolors");
|
|
30
35
|
picocolors = __toESM(picocolors);
|
|
31
36
|
|
|
@@ -98,31 +103,9 @@ async function fetchBundle(remote, platform) {
|
|
|
98
103
|
return await (await fetch(`http://${remote.host}:${remote.port}/index.bundle?dev=true&platform=${platform}`)).text();
|
|
99
104
|
}
|
|
100
105
|
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region src/utils/resolveReactNativeBasePath.ts
|
|
103
|
-
function resolveReactNativeBasePath() {
|
|
104
|
-
return path.default.dirname(require.resolve("react-native/package.json", { paths: [(0, __granite_js_utils.getPackageRoot)()] }));
|
|
105
|
-
}
|
|
106
|
-
|
|
107
106
|
//#endregion
|
|
108
107
|
//#region src/resolver.ts
|
|
109
|
-
const VIRTUAL_INITIALIZE_CORE_PROTOCOL = "virtual-initialize-core";
|
|
110
108
|
const VIRTUAL_SHARED_PROTOCOL = "virtual-shared";
|
|
111
|
-
function virtualInitializeCoreConfig(reactNativeBasePath = resolveReactNativeBasePath()) {
|
|
112
|
-
return {
|
|
113
|
-
alias: [{
|
|
114
|
-
from: `prelude:${path.join(reactNativeBasePath, "Libraries/Core/InitializeCore.js")}`,
|
|
115
|
-
to: `${VIRTUAL_INITIALIZE_CORE_PROTOCOL}:noop`,
|
|
116
|
-
exact: false
|
|
117
|
-
}],
|
|
118
|
-
protocols: { [VIRTUAL_INITIALIZE_CORE_PROTOCOL]: { load: function virtualInitializeCoreProtocolLoader() {
|
|
119
|
-
return {
|
|
120
|
-
loader: "js",
|
|
121
|
-
contents: `// noop`
|
|
122
|
-
};
|
|
123
|
-
} } }
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
109
|
function virtualSharedConfig(moduleEntries) {
|
|
127
110
|
const alias = moduleEntries.map(([libName]) => ({
|
|
128
111
|
from: libName,
|
|
@@ -151,38 +134,72 @@ function virtualSharedConfig(moduleEntries) {
|
|
|
151
134
|
|
|
152
135
|
//#endregion
|
|
153
136
|
//#region src/utils/intoShared.ts
|
|
137
|
+
const SHARED_PRESETS = {
|
|
138
|
+
"react-native": [
|
|
139
|
+
"react-native/Libraries/BatchedBridge/BatchedBridge",
|
|
140
|
+
"react-native/Libraries/BatchedBridge/NativeModules",
|
|
141
|
+
"react-native/Libraries/BatchedBridge/MessageQueue",
|
|
142
|
+
"react-native/Libraries/NativeComponent/NativeComponentRegistry",
|
|
143
|
+
"react-native/Libraries/NativeComponent/NativeComponentRegistryUnstable",
|
|
144
|
+
"react-native/Libraries/NativeComponent/ViewConfigIgnore",
|
|
145
|
+
"react-native/Libraries/ReactNative/RendererProxy",
|
|
146
|
+
"react-native/Libraries/StyleSheet/PlatformColorValueTypes",
|
|
147
|
+
"react-native/Libraries/StyleSheet/normalizeColor",
|
|
148
|
+
"react-native/Libraries/StyleSheet/processColor",
|
|
149
|
+
"react-native/Libraries/TurboModule/TurboModuleRegistry",
|
|
150
|
+
"react-native/Libraries/Utilities/NativePlatformConstantsIOS",
|
|
151
|
+
"react-native/Libraries/Utilities/Platform",
|
|
152
|
+
"react-native/Libraries/Utilities/defineLazyObjectProperty"
|
|
153
|
+
],
|
|
154
|
+
react: ["react/jsx-runtime", "react/jsx-dev-runtime"]
|
|
155
|
+
};
|
|
154
156
|
function intoShared(shared) {
|
|
155
|
-
if (
|
|
157
|
+
if (shared == null) return;
|
|
158
|
+
const normalized = Array.isArray(shared) ? shared.reduce((acc, lib) => {
|
|
156
159
|
acc[lib] = {};
|
|
157
160
|
return acc;
|
|
158
|
-
}, {});
|
|
159
|
-
|
|
161
|
+
}, {}) : { ...shared };
|
|
162
|
+
for (const [lib, subpaths] of Object.entries(SHARED_PRESETS)) {
|
|
163
|
+
const libConfig = normalized[lib];
|
|
164
|
+
if (libConfig == null) continue;
|
|
165
|
+
for (const subpath of subpaths) if (normalized[subpath] == null) normalized[subpath] = { ...libConfig };
|
|
166
|
+
}
|
|
167
|
+
return normalized;
|
|
160
168
|
}
|
|
161
169
|
|
|
162
170
|
//#endregion
|
|
163
171
|
//#region src/microFrontendPlugin.ts
|
|
164
172
|
const microFrontendPlugin = async (options) => {
|
|
165
|
-
const
|
|
173
|
+
const sharedConfig = intoShared(options.shared);
|
|
174
|
+
const nonEagerEntries = Object.entries(sharedConfig ?? {}).filter(([_, config]) => config.eager !== true);
|
|
166
175
|
const rootDir = process.cwd();
|
|
167
|
-
const preludeConfig = getPreludeConfig(
|
|
168
|
-
|
|
176
|
+
const preludeConfig = getPreludeConfig({
|
|
177
|
+
...options,
|
|
178
|
+
shared: sharedConfig
|
|
179
|
+
});
|
|
180
|
+
const localDir = (0, _granite_js_utils.prepareLocalDirectory)(rootDir);
|
|
169
181
|
const preludePath = path.join(localDir, "micro-frontend-runtime.js");
|
|
170
182
|
fs.writeFileSync(preludePath, preludeConfig.preludeScript);
|
|
171
183
|
/**
|
|
172
184
|
* @TODO `MPACK_DEV_SERVER` flag should be removed after next version of bundle loader is released and load bundle dynamically at JS runtime.
|
|
173
185
|
*/
|
|
174
186
|
if (process.env.MPACK_DEV_SERVER === "true" && options.remote) await fetchRemoteBundle(options.remote);
|
|
175
|
-
|
|
187
|
+
/**
|
|
188
|
+
* If importing `react-native` from the shared registry, skip its prelude scripts
|
|
189
|
+
* to ensure the core is loaded only once per runtime by the host.
|
|
190
|
+
*/
|
|
191
|
+
const isReactNativeShared = Boolean(nonEagerEntries.find(([libName]) => libName === "react-native"));
|
|
176
192
|
const virtualShared = virtualSharedConfig(nonEagerEntries);
|
|
177
193
|
return {
|
|
178
194
|
name: "micro-frontend-plugin",
|
|
179
195
|
config: {
|
|
196
|
+
extra: isReactNativeShared ? {
|
|
197
|
+
skipReactNativePolyfills: true,
|
|
198
|
+
skipReactNativeInitializeCore: true
|
|
199
|
+
} : void 0,
|
|
180
200
|
resolver: {
|
|
181
|
-
alias:
|
|
182
|
-
protocols:
|
|
183
|
-
...virtualInitializeCore?.protocols,
|
|
184
|
-
...virtualShared.protocols
|
|
185
|
-
}
|
|
201
|
+
alias: virtualShared.alias,
|
|
202
|
+
protocols: virtualShared.protocols
|
|
186
203
|
},
|
|
187
204
|
esbuild: {
|
|
188
205
|
prelude: [preludePath],
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
1
|
import * as fs from "fs";
|
|
3
2
|
import * as path$1 from "path";
|
|
4
3
|
import path from "path";
|
|
5
|
-
import {
|
|
4
|
+
import { prepareLocalDirectory } from "@granite-js/utils";
|
|
6
5
|
import pc from "picocolors";
|
|
7
6
|
|
|
8
|
-
//#region rolldown:runtime
|
|
9
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
7
|
//#region src/prelude.ts
|
|
13
8
|
function getPreludeConfig(options) {
|
|
14
9
|
const registerStatements = Object.entries(options.shared ?? {}).filter(([_, config]) => config.eager === true).map(([libName], index) => {
|
|
@@ -78,31 +73,9 @@ async function fetchBundle(remote, platform) {
|
|
|
78
73
|
return await (await fetch(`http://${remote.host}:${remote.port}/index.bundle?dev=true&platform=${platform}`)).text();
|
|
79
74
|
}
|
|
80
75
|
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/utils/resolveReactNativeBasePath.ts
|
|
83
|
-
function resolveReactNativeBasePath() {
|
|
84
|
-
return path.dirname(__require.resolve("react-native/package.json", { paths: [getPackageRoot()] }));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
76
|
//#endregion
|
|
88
77
|
//#region src/resolver.ts
|
|
89
|
-
const VIRTUAL_INITIALIZE_CORE_PROTOCOL = "virtual-initialize-core";
|
|
90
78
|
const VIRTUAL_SHARED_PROTOCOL = "virtual-shared";
|
|
91
|
-
function virtualInitializeCoreConfig(reactNativeBasePath = resolveReactNativeBasePath()) {
|
|
92
|
-
return {
|
|
93
|
-
alias: [{
|
|
94
|
-
from: `prelude:${path$1.join(reactNativeBasePath, "Libraries/Core/InitializeCore.js")}`,
|
|
95
|
-
to: `${VIRTUAL_INITIALIZE_CORE_PROTOCOL}:noop`,
|
|
96
|
-
exact: false
|
|
97
|
-
}],
|
|
98
|
-
protocols: { [VIRTUAL_INITIALIZE_CORE_PROTOCOL]: { load: function virtualInitializeCoreProtocolLoader() {
|
|
99
|
-
return {
|
|
100
|
-
loader: "js",
|
|
101
|
-
contents: `// noop`
|
|
102
|
-
};
|
|
103
|
-
} } }
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
79
|
function virtualSharedConfig(moduleEntries) {
|
|
107
80
|
const alias = moduleEntries.map(([libName]) => ({
|
|
108
81
|
from: libName,
|
|
@@ -131,20 +104,49 @@ function virtualSharedConfig(moduleEntries) {
|
|
|
131
104
|
|
|
132
105
|
//#endregion
|
|
133
106
|
//#region src/utils/intoShared.ts
|
|
107
|
+
const SHARED_PRESETS = {
|
|
108
|
+
"react-native": [
|
|
109
|
+
"react-native/Libraries/BatchedBridge/BatchedBridge",
|
|
110
|
+
"react-native/Libraries/BatchedBridge/NativeModules",
|
|
111
|
+
"react-native/Libraries/BatchedBridge/MessageQueue",
|
|
112
|
+
"react-native/Libraries/NativeComponent/NativeComponentRegistry",
|
|
113
|
+
"react-native/Libraries/NativeComponent/NativeComponentRegistryUnstable",
|
|
114
|
+
"react-native/Libraries/NativeComponent/ViewConfigIgnore",
|
|
115
|
+
"react-native/Libraries/ReactNative/RendererProxy",
|
|
116
|
+
"react-native/Libraries/StyleSheet/PlatformColorValueTypes",
|
|
117
|
+
"react-native/Libraries/StyleSheet/normalizeColor",
|
|
118
|
+
"react-native/Libraries/StyleSheet/processColor",
|
|
119
|
+
"react-native/Libraries/TurboModule/TurboModuleRegistry",
|
|
120
|
+
"react-native/Libraries/Utilities/NativePlatformConstantsIOS",
|
|
121
|
+
"react-native/Libraries/Utilities/Platform",
|
|
122
|
+
"react-native/Libraries/Utilities/defineLazyObjectProperty"
|
|
123
|
+
],
|
|
124
|
+
react: ["react/jsx-runtime", "react/jsx-dev-runtime"]
|
|
125
|
+
};
|
|
134
126
|
function intoShared(shared) {
|
|
135
|
-
if (
|
|
127
|
+
if (shared == null) return;
|
|
128
|
+
const normalized = Array.isArray(shared) ? shared.reduce((acc, lib) => {
|
|
136
129
|
acc[lib] = {};
|
|
137
130
|
return acc;
|
|
138
|
-
}, {});
|
|
139
|
-
|
|
131
|
+
}, {}) : { ...shared };
|
|
132
|
+
for (const [lib, subpaths] of Object.entries(SHARED_PRESETS)) {
|
|
133
|
+
const libConfig = normalized[lib];
|
|
134
|
+
if (libConfig == null) continue;
|
|
135
|
+
for (const subpath of subpaths) if (normalized[subpath] == null) normalized[subpath] = { ...libConfig };
|
|
136
|
+
}
|
|
137
|
+
return normalized;
|
|
140
138
|
}
|
|
141
139
|
|
|
142
140
|
//#endregion
|
|
143
141
|
//#region src/microFrontendPlugin.ts
|
|
144
142
|
const microFrontendPlugin = async (options) => {
|
|
145
|
-
const
|
|
143
|
+
const sharedConfig = intoShared(options.shared);
|
|
144
|
+
const nonEagerEntries = Object.entries(sharedConfig ?? {}).filter(([_, config]) => config.eager !== true);
|
|
146
145
|
const rootDir = process.cwd();
|
|
147
|
-
const preludeConfig = getPreludeConfig(
|
|
146
|
+
const preludeConfig = getPreludeConfig({
|
|
147
|
+
...options,
|
|
148
|
+
shared: sharedConfig
|
|
149
|
+
});
|
|
148
150
|
const localDir = prepareLocalDirectory(rootDir);
|
|
149
151
|
const preludePath = path$1.join(localDir, "micro-frontend-runtime.js");
|
|
150
152
|
fs.writeFileSync(preludePath, preludeConfig.preludeScript);
|
|
@@ -152,17 +154,22 @@ const microFrontendPlugin = async (options) => {
|
|
|
152
154
|
* @TODO `MPACK_DEV_SERVER` flag should be removed after next version of bundle loader is released and load bundle dynamically at JS runtime.
|
|
153
155
|
*/
|
|
154
156
|
if (process.env.MPACK_DEV_SERVER === "true" && options.remote) await fetchRemoteBundle(options.remote);
|
|
155
|
-
|
|
157
|
+
/**
|
|
158
|
+
* If importing `react-native` from the shared registry, skip its prelude scripts
|
|
159
|
+
* to ensure the core is loaded only once per runtime by the host.
|
|
160
|
+
*/
|
|
161
|
+
const isReactNativeShared = Boolean(nonEagerEntries.find(([libName]) => libName === "react-native"));
|
|
156
162
|
const virtualShared = virtualSharedConfig(nonEagerEntries);
|
|
157
163
|
return {
|
|
158
164
|
name: "micro-frontend-plugin",
|
|
159
165
|
config: {
|
|
166
|
+
extra: isReactNativeShared ? {
|
|
167
|
+
skipReactNativePolyfills: true,
|
|
168
|
+
skipReactNativeInitializeCore: true
|
|
169
|
+
} : void 0,
|
|
160
170
|
resolver: {
|
|
161
|
-
alias:
|
|
162
|
-
protocols:
|
|
163
|
-
...virtualInitializeCore?.protocols,
|
|
164
|
-
...virtualShared.protocols
|
|
165
|
-
}
|
|
171
|
+
alias: virtualShared.alias,
|
|
172
|
+
protocols: virtualShared.protocols
|
|
166
173
|
},
|
|
167
174
|
esbuild: {
|
|
168
175
|
prelude: [preludePath],
|
package/dist/runtime/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
1
2
|
|
|
2
3
|
//#region src/runtime/createContainer.ts
|
|
3
4
|
function createContainer(name, config) {
|
|
@@ -40,16 +41,16 @@ function importRemoteModule(remoteRequestPath) {
|
|
|
40
41
|
const { remoteName, modulePath } = parseRemotePath(remoteRequestPath);
|
|
41
42
|
const container = getContainer(remoteName);
|
|
42
43
|
if (container == null) throw new Error(`${remoteName} container not found`);
|
|
43
|
-
const module
|
|
44
|
-
if (module
|
|
45
|
-
return module
|
|
44
|
+
const module = container.exposeMap[normalizePath(modulePath)];
|
|
45
|
+
if (module == null) throw new Error(`Could not resolve '${modulePath}' in ${remoteName} container`);
|
|
46
|
+
return module;
|
|
46
47
|
}
|
|
47
|
-
function toESM(module
|
|
48
|
-
if (module
|
|
49
|
-
return Object.defineProperties(module
|
|
48
|
+
function toESM(module) {
|
|
49
|
+
if (module.__esModule) return module;
|
|
50
|
+
return Object.defineProperties(module, {
|
|
50
51
|
__esModule: { value: true },
|
|
51
|
-
...module
|
|
52
|
-
value: module
|
|
52
|
+
...module.default == null ? { default: {
|
|
53
|
+
value: module,
|
|
53
54
|
enumerable: true
|
|
54
55
|
} } : null
|
|
55
56
|
});
|
|
@@ -57,21 +58,21 @@ function toESM(module$1) {
|
|
|
57
58
|
|
|
58
59
|
//#endregion
|
|
59
60
|
//#region src/runtime/registerShared.ts
|
|
60
|
-
function registerShared(libName, module
|
|
61
|
+
function registerShared(libName, module) {
|
|
61
62
|
if (global.__MICRO_FRONTEND__.__SHARED__[libName]) throw new Error(`'${libName}' already registered as a shared module`);
|
|
62
63
|
global.__MICRO_FRONTEND__.__SHARED__[libName] = {
|
|
63
|
-
get: () => toESM(module
|
|
64
|
+
get: () => toESM(module),
|
|
64
65
|
loaded: true
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
//#endregion
|
|
69
70
|
//#region src/runtime/exposeModule.ts
|
|
70
|
-
function exposeModule(container, exposeName, module
|
|
71
|
+
function exposeModule(container, exposeName, module) {
|
|
71
72
|
const normalizedExposeName = normalizePath(exposeName);
|
|
72
73
|
if (container.exposeMap[normalizedExposeName]) throw new Error(`'${exposeName}' is already exposed in ${container.name} container`);
|
|
73
74
|
Object.defineProperty(container.exposeMap, normalizedExposeName, {
|
|
74
|
-
get: () => toESM(module
|
|
75
|
+
get: () => toESM(module),
|
|
75
76
|
enumerable: true
|
|
76
77
|
});
|
|
77
78
|
}
|
package/dist/runtime/index.d.cts
CHANGED
package/dist/runtime/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@granite-js/plugin-micro-frontend",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"description": "Plugin for micro frontend",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"prepack": "yarn build",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
],
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@vitest/coverage-v8": "^4.0.12",
|
|
49
|
-
"tsdown": "
|
|
50
|
-
"typescript": "
|
|
49
|
+
"tsdown": "0.20.3",
|
|
50
|
+
"typescript": "5.9.3",
|
|
51
51
|
"vitest": "^4.0.12"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@granite-js/plugin-core": "0.1
|
|
55
|
-
"@granite-js/utils": "0.1
|
|
54
|
+
"@granite-js/plugin-core": "1.0.1",
|
|
55
|
+
"@granite-js/utils": "1.0.1",
|
|
56
56
|
"es-toolkit": "^1.39.8",
|
|
57
57
|
"picocolors": "^1.1.1"
|
|
58
58
|
},
|