@granite-js/plugin-micro-frontend 0.1.30 → 0.1.32

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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # @granite-js/plugin-micro-frontend
2
2
 
3
+ ## 0.1.32
4
+
5
+ ### Patch Changes
6
+
7
+ - 7572713: bump version up babel
8
+ - Updated dependencies [7572713]
9
+ - @granite-js/plugin-core@0.1.32
10
+ - @granite-js/utils@0.1.32
11
+
12
+ ## 0.1.31
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [9bf8b50]
17
+ - Updated dependencies [e957833]
18
+ - @granite-js/plugin-core@0.1.31
19
+ - @granite-js/utils@0.1.31
20
+
3
21
  ## 0.1.30
4
22
 
5
23
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -21,16 +21,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  }) : target, mod));
22
22
 
23
23
  //#endregion
24
- const fs = __toESM(require("fs"));
25
- const path = __toESM(require("path"));
26
- const __granite_js_utils = __toESM(require("@granite-js/utils"));
27
- const picocolors = __toESM(require("picocolors"));
24
+ let fs = require("fs");
25
+ fs = __toESM(fs);
26
+ let path = require("path");
27
+ path = __toESM(path);
28
+ let __granite_js_utils = require("@granite-js/utils");
29
+ let picocolors = require("picocolors");
30
+ picocolors = __toESM(picocolors);
28
31
 
29
32
  //#region src/prelude.ts
30
33
  function getPreludeConfig(options) {
31
- const sharedEntries = Object.entries(options.shared ?? {});
32
- const eagerEntries = sharedEntries.filter(([_, config]) => config.eager === true);
33
- const registerStatements = eagerEntries.map(([libName], index) => {
34
+ const registerStatements = Object.entries(options.shared ?? {}).filter(([_, config]) => config.eager === true).map(([libName], index) => {
34
35
  const identifier = `__mod${index}`;
35
36
  return `
36
37
  // ${libName}
@@ -40,21 +41,11 @@ function getPreludeConfig(options) {
40
41
  });
41
42
  const exposeStatements = Object.entries(options.exposes ?? {}).map(([exposeName, modulePath], index) => {
42
43
  const identifier = `__expose${index}`;
43
- const resolvedModulePath = path.default.resolve(modulePath);
44
44
  return `
45
- import * as ${identifier} from '${resolvedModulePath}';
45
+ import * as ${identifier} from '${path.default.resolve(modulePath)}';
46
46
  exposeModule(__container, '${exposeName}', ${identifier});
47
47
  `;
48
48
  });
49
- const preludeScript = [
50
- `import { registerShared, createContainer, exposeModule } from '@granite-js/plugin-micro-frontend/runtime';`,
51
- `const __container = createContainer('${options.name}', ${JSON.stringify({
52
- remote: options.remote,
53
- shared: options.shared
54
- })});`,
55
- ...registerStatements,
56
- ...exposeStatements
57
- ].join("\n");
58
49
  return {
59
50
  banner: `
60
51
  if (global.__MICRO_FRONTEND__ == null) {
@@ -64,7 +55,15 @@ function getPreludeConfig(options) {
64
55
  };
65
56
  }
66
57
  `,
67
- preludeScript
58
+ preludeScript: [
59
+ `import { registerShared, createContainer, exposeModule } from '@granite-js/plugin-micro-frontend/runtime';`,
60
+ `const __container = createContainer('${options.name}', ${JSON.stringify({
61
+ remote: options.remote,
62
+ shared: options.shared
63
+ })});`,
64
+ ...registerStatements,
65
+ ...exposeStatements
66
+ ].join("\n")
68
67
  };
69
68
  }
70
69
 
@@ -96,9 +95,7 @@ async function fetchRemoteBundle(remote) {
96
95
  }
97
96
  }
98
97
  async function fetchBundle(remote, platform) {
99
- const response = await fetch(`http://${remote.host}:${remote.port}/index.bundle?dev=true&platform=${platform}`);
100
- const bundle = await response.text();
101
- return bundle;
98
+ return await (await fetch(`http://${remote.host}:${remote.port}/index.bundle?dev=true&platform=${platform}`)).text();
102
99
  }
103
100
 
104
101
  //#endregion
@@ -112,21 +109,18 @@ function resolveReactNativeBasePath() {
112
109
  const VIRTUAL_INITIALIZE_CORE_PROTOCOL = "virtual-initialize-core";
113
110
  const VIRTUAL_SHARED_PROTOCOL = "virtual-shared";
114
111
  function virtualInitializeCoreConfig(reactNativeBasePath = resolveReactNativeBasePath()) {
115
- const initializeCorePath = path.join(reactNativeBasePath, "Libraries/Core/InitializeCore.js");
116
- const alias = [{
117
- from: `prelude:${initializeCorePath}`,
118
- to: `${VIRTUAL_INITIALIZE_CORE_PROTOCOL}:noop`,
119
- exact: false
120
- }];
121
- const protocols = { [VIRTUAL_INITIALIZE_CORE_PROTOCOL]: { load: function virtualInitializeCoreProtocolLoader() {
122
- return {
123
- loader: "js",
124
- contents: `// noop`
125
- };
126
- } } };
127
112
  return {
128
- alias,
129
- protocols
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
+ } } }
130
124
  };
131
125
  }
132
126
  function virtualSharedConfig(moduleEntries) {
@@ -168,8 +162,7 @@ function intoShared(shared) {
168
162
  //#endregion
169
163
  //#region src/microFrontendPlugin.ts
170
164
  const microFrontendPlugin = async (options) => {
171
- const sharedEntries = Object.entries(intoShared(options.shared) ?? {});
172
- const nonEagerEntries = sharedEntries.filter(([_, config]) => config.eager !== true);
165
+ const nonEagerEntries = Object.entries(intoShared(options.shared) ?? {}).filter(([_, config]) => config.eager !== true);
173
166
  const rootDir = process.cwd();
174
167
  const preludeConfig = getPreludeConfig(options);
175
168
  const localDir = (0, __granite_js_utils.prepareLocalDirectory)(rootDir);
@@ -179,12 +172,7 @@ const microFrontendPlugin = async (options) => {
179
172
  * @TODO `MPACK_DEV_SERVER` flag should be removed after next version of bundle loader is released and load bundle dynamically at JS runtime.
180
173
  */
181
174
  if (process.env.MPACK_DEV_SERVER === "true" && options.remote) await fetchRemoteBundle(options.remote);
182
- /**
183
- * If importing `react-native` from the shared registry,
184
- * `InitializeCore.js` must be excluded from the bundle to ensure the core is loaded only once per runtime.
185
- */
186
- const shouldExcludeReactNativeInitializeCore = Boolean(nonEagerEntries.find(([libName]) => libName === "react-native"));
187
- const virtualInitializeCore = shouldExcludeReactNativeInitializeCore ? virtualInitializeCoreConfig(options.reactNativeBasePath) : void 0;
175
+ const virtualInitializeCore = Boolean(nonEagerEntries.find(([libName]) => libName === "react-native")) ? virtualInitializeCoreConfig(options.reactNativeBasePath) : void 0;
188
176
  const virtualShared = virtualSharedConfig(nonEagerEntries);
189
177
  return {
190
178
  name: "micro-frontend-plugin",
package/dist/index.d.cts CHANGED
@@ -49,9 +49,9 @@ interface SharedConfig {
49
49
  }
50
50
  interface ExposeConfig {
51
51
  [exposePath: string]: string;
52
- } //#endregion
52
+ }
53
+ //#endregion
53
54
  //#region src/microFrontendPlugin.d.ts
54
55
  declare const microFrontendPlugin: (options: MicroFrontendPluginOptions) => Promise<GranitePluginCore>;
55
-
56
56
  //#endregion
57
- export { MicroFrontendPluginOptions, microFrontendPlugin as microFrontend };
57
+ export { type MicroFrontendPluginOptions, microFrontendPlugin as microFrontend };
package/dist/index.d.ts CHANGED
@@ -49,9 +49,9 @@ interface SharedConfig {
49
49
  }
50
50
  interface ExposeConfig {
51
51
  [exposePath: string]: string;
52
- } //#endregion
52
+ }
53
+ //#endregion
53
54
  //#region src/microFrontendPlugin.d.ts
54
55
  declare const microFrontendPlugin: (options: MicroFrontendPluginOptions) => Promise<GranitePluginCore>;
55
-
56
56
  //#endregion
57
- export { MicroFrontendPluginOptions, microFrontendPlugin as microFrontend };
57
+ export { type MicroFrontendPluginOptions, microFrontendPlugin as microFrontend };
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
2
  import * as fs from "fs";
3
- import * as path$2 from "path";
4
3
  import * as path$1 from "path";
5
4
  import path from "path";
6
5
  import { getPackageRoot, prepareLocalDirectory } from "@granite-js/utils";
@@ -12,9 +11,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
12
11
  //#endregion
13
12
  //#region src/prelude.ts
14
13
  function getPreludeConfig(options) {
15
- const sharedEntries = Object.entries(options.shared ?? {});
16
- const eagerEntries = sharedEntries.filter(([_, config]) => config.eager === true);
17
- const registerStatements = eagerEntries.map(([libName], index) => {
14
+ const registerStatements = Object.entries(options.shared ?? {}).filter(([_, config]) => config.eager === true).map(([libName], index) => {
18
15
  const identifier = `__mod${index}`;
19
16
  return `
20
17
  // ${libName}
@@ -24,21 +21,11 @@ function getPreludeConfig(options) {
24
21
  });
25
22
  const exposeStatements = Object.entries(options.exposes ?? {}).map(([exposeName, modulePath], index) => {
26
23
  const identifier = `__expose${index}`;
27
- const resolvedModulePath = path.resolve(modulePath);
28
24
  return `
29
- import * as ${identifier} from '${resolvedModulePath}';
25
+ import * as ${identifier} from '${path.resolve(modulePath)}';
30
26
  exposeModule(__container, '${exposeName}', ${identifier});
31
27
  `;
32
28
  });
33
- const preludeScript = [
34
- `import { registerShared, createContainer, exposeModule } from '@granite-js/plugin-micro-frontend/runtime';`,
35
- `const __container = createContainer('${options.name}', ${JSON.stringify({
36
- remote: options.remote,
37
- shared: options.shared
38
- })});`,
39
- ...registerStatements,
40
- ...exposeStatements
41
- ].join("\n");
42
29
  return {
43
30
  banner: `
44
31
  if (global.__MICRO_FRONTEND__ == null) {
@@ -48,7 +35,15 @@ function getPreludeConfig(options) {
48
35
  };
49
36
  }
50
37
  `,
51
- preludeScript
38
+ preludeScript: [
39
+ `import { registerShared, createContainer, exposeModule } from '@granite-js/plugin-micro-frontend/runtime';`,
40
+ `const __container = createContainer('${options.name}', ${JSON.stringify({
41
+ remote: options.remote,
42
+ shared: options.shared
43
+ })});`,
44
+ ...registerStatements,
45
+ ...exposeStatements
46
+ ].join("\n")
52
47
  };
53
48
  }
54
49
 
@@ -80,9 +75,7 @@ async function fetchRemoteBundle(remote) {
80
75
  }
81
76
  }
82
77
  async function fetchBundle(remote, platform) {
83
- const response = await fetch(`http://${remote.host}:${remote.port}/index.bundle?dev=true&platform=${platform}`);
84
- const bundle = await response.text();
85
- return bundle;
78
+ return await (await fetch(`http://${remote.host}:${remote.port}/index.bundle?dev=true&platform=${platform}`)).text();
86
79
  }
87
80
 
88
81
  //#endregion
@@ -96,21 +89,18 @@ function resolveReactNativeBasePath() {
96
89
  const VIRTUAL_INITIALIZE_CORE_PROTOCOL = "virtual-initialize-core";
97
90
  const VIRTUAL_SHARED_PROTOCOL = "virtual-shared";
98
91
  function virtualInitializeCoreConfig(reactNativeBasePath = resolveReactNativeBasePath()) {
99
- const initializeCorePath = path$2.join(reactNativeBasePath, "Libraries/Core/InitializeCore.js");
100
- const alias = [{
101
- from: `prelude:${initializeCorePath}`,
102
- to: `${VIRTUAL_INITIALIZE_CORE_PROTOCOL}:noop`,
103
- exact: false
104
- }];
105
- const protocols = { [VIRTUAL_INITIALIZE_CORE_PROTOCOL]: { load: function virtualInitializeCoreProtocolLoader() {
106
- return {
107
- loader: "js",
108
- contents: `// noop`
109
- };
110
- } } };
111
92
  return {
112
- alias,
113
- protocols
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
+ } } }
114
104
  };
115
105
  }
116
106
  function virtualSharedConfig(moduleEntries) {
@@ -152,8 +142,7 @@ function intoShared(shared) {
152
142
  //#endregion
153
143
  //#region src/microFrontendPlugin.ts
154
144
  const microFrontendPlugin = async (options) => {
155
- const sharedEntries = Object.entries(intoShared(options.shared) ?? {});
156
- const nonEagerEntries = sharedEntries.filter(([_, config]) => config.eager !== true);
145
+ const nonEagerEntries = Object.entries(intoShared(options.shared) ?? {}).filter(([_, config]) => config.eager !== true);
157
146
  const rootDir = process.cwd();
158
147
  const preludeConfig = getPreludeConfig(options);
159
148
  const localDir = prepareLocalDirectory(rootDir);
@@ -163,12 +152,7 @@ const microFrontendPlugin = async (options) => {
163
152
  * @TODO `MPACK_DEV_SERVER` flag should be removed after next version of bundle loader is released and load bundle dynamically at JS runtime.
164
153
  */
165
154
  if (process.env.MPACK_DEV_SERVER === "true" && options.remote) await fetchRemoteBundle(options.remote);
166
- /**
167
- * If importing `react-native` from the shared registry,
168
- * `InitializeCore.js` must be excluded from the bundle to ensure the core is loaded only once per runtime.
169
- */
170
- const shouldExcludeReactNativeInitializeCore = Boolean(nonEagerEntries.find(([libName]) => libName === "react-native"));
171
- const virtualInitializeCore = shouldExcludeReactNativeInitializeCore ? virtualInitializeCoreConfig(options.reactNativeBasePath) : void 0;
155
+ const virtualInitializeCore = Boolean(nonEagerEntries.find(([libName]) => libName === "react-native")) ? virtualInitializeCoreConfig(options.reactNativeBasePath) : void 0;
172
156
  const virtualShared = virtualSharedConfig(nonEagerEntries);
173
157
  return {
174
158
  name: "micro-frontend-plugin",
@@ -22,7 +22,8 @@ interface SharedConfig {
22
22
  }
23
23
  interface ExposeConfig {
24
24
  [exposePath: string]: string;
25
- } //#endregion
25
+ }
26
+ //#endregion
26
27
  //#region src/runtime/types.d.ts
27
28
  declare global {
28
29
  var __MICRO_FRONTEND__: RuntimeContext;
@@ -46,7 +47,6 @@ interface SharedModuleRegistry {
46
47
  };
47
48
  }
48
49
  type Module = any;
49
-
50
50
  //#endregion
51
51
  //#region src/runtime/createContainer.d.ts
52
52
  declare function createContainer(name: string, config: {
@@ -54,15 +54,12 @@ declare function createContainer(name: string, config: {
54
54
  shared?: SharedConfig;
55
55
  exposes?: ExposeConfig;
56
56
  }): Container;
57
-
58
57
  //#endregion
59
58
  //#region src/runtime/registerShared.d.ts
60
59
  declare function registerShared(libName: string, module: Module): void;
61
-
62
60
  //#endregion
63
61
  //#region src/runtime/exposeModule.d.ts
64
62
  declare function exposeModule(container: Container, exposeName: string, module: Module): void;
65
-
66
63
  //#endregion
67
64
  //#region src/runtime/utils.d.ts
68
65
  declare function getContainer(instanceName: string): Container | null;
@@ -72,6 +69,5 @@ declare function parseRemotePath(remotePath: string): {
72
69
  fullRequest: string;
73
70
  };
74
71
  declare function importRemoteModule(remoteRequestPath: string): any;
75
-
76
72
  //#endregion
77
- export { Container, Module, RuntimeContext, SharedModuleRegistry, createContainer, exposeModule, getContainer, importRemoteModule, parseRemotePath, registerShared };
73
+ export { type Container, type Module, type RuntimeContext, type SharedModuleRegistry, createContainer, exposeModule, getContainer, importRemoteModule, parseRemotePath, registerShared };
@@ -22,7 +22,8 @@ interface SharedConfig {
22
22
  }
23
23
  interface ExposeConfig {
24
24
  [exposePath: string]: string;
25
- } //#endregion
25
+ }
26
+ //#endregion
26
27
  //#region src/runtime/types.d.ts
27
28
  declare global {
28
29
  var __MICRO_FRONTEND__: RuntimeContext;
@@ -46,7 +47,6 @@ interface SharedModuleRegistry {
46
47
  };
47
48
  }
48
49
  type Module = any;
49
-
50
50
  //#endregion
51
51
  //#region src/runtime/createContainer.d.ts
52
52
  declare function createContainer(name: string, config: {
@@ -54,15 +54,12 @@ declare function createContainer(name: string, config: {
54
54
  shared?: SharedConfig;
55
55
  exposes?: ExposeConfig;
56
56
  }): Container;
57
-
58
57
  //#endregion
59
58
  //#region src/runtime/registerShared.d.ts
60
59
  declare function registerShared(libName: string, module: Module): void;
61
-
62
60
  //#endregion
63
61
  //#region src/runtime/exposeModule.d.ts
64
62
  declare function exposeModule(container: Container, exposeName: string, module: Module): void;
65
-
66
63
  //#endregion
67
64
  //#region src/runtime/utils.d.ts
68
65
  declare function getContainer(instanceName: string): Container | null;
@@ -72,6 +69,5 @@ declare function parseRemotePath(remotePath: string): {
72
69
  fullRequest: string;
73
70
  };
74
71
  declare function importRemoteModule(remoteRequestPath: string): any;
75
-
76
72
  //#endregion
77
- export { Container, Module, RuntimeContext, SharedModuleRegistry, createContainer, exposeModule, getContainer, importRemoteModule, parseRemotePath, registerShared };
73
+ export { type Container, type Module, type RuntimeContext, type SharedModuleRegistry, createContainer, exposeModule, getContainer, importRemoteModule, parseRemotePath, registerShared };
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.30",
4
+ "version": "0.1.32",
5
5
  "description": "Plugin for micro frontend",
6
6
  "scripts": {
7
7
  "prepack": "yarn build",
@@ -45,13 +45,14 @@
45
45
  "*.d.ts"
46
46
  ],
47
47
  "devDependencies": {
48
- "tsdown": "^0.11.11",
48
+ "@vitest/coverage-v8": "^4.0.12",
49
+ "tsdown": "^0.16.5",
49
50
  "typescript": "^5.8.3",
50
- "vitest": "^3.2.4"
51
+ "vitest": "^4.0.12"
51
52
  },
52
53
  "dependencies": {
53
- "@granite-js/plugin-core": "0.1.30",
54
- "@granite-js/utils": "0.1.30",
54
+ "@granite-js/plugin-core": "0.1.32",
55
+ "@granite-js/utils": "0.1.32",
55
56
  "es-toolkit": "^1.39.8",
56
57
  "picocolors": "^1.1.1"
57
58
  },