ptech-preset 1.1.2 → 1.1.3

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/dist/index.d.ts CHANGED
@@ -1,15 +1,14 @@
1
1
  import { RsbuildPlugin } from '@rsbuild/core';
2
2
 
3
3
  type MfAutoOptions = {
4
- name?: string;
5
- filename?: string;
6
4
  baseDir?: string;
7
5
  globs?: string[];
8
6
  exposesMode?: "jsdoc" | "wrapper" | "both";
9
7
  envPrefix?: string;
10
8
  manifestPathOrUrl?: string;
11
- autoShareReact?: boolean;
9
+ autoWhenEmpty?: boolean;
10
+ mf: Record<string, any>;
12
11
  };
13
- declare function pluginCore(opts?: MfAutoOptions): RsbuildPlugin;
12
+ declare function pluginMFAuto(opts: MfAutoOptions): RsbuildPlugin;
14
13
 
15
- export { type MfAutoOptions, pluginCore as default, pluginCore };
14
+ export { type MfAutoOptions, pluginMFAuto as default, pluginMFAuto };
package/dist/index.js CHANGED
@@ -103,23 +103,27 @@ async function collectAutoRemotes(opts = {}) {
103
103
  }
104
104
 
105
105
  // src/index.ts
106
- function pluginCore(opts = {}) {
106
+ function pluginMFAuto(opts) {
107
107
  const {
108
- name,
109
- filename = "static/js/remoteEntry.js",
110
108
  baseDir = "src",
111
109
  globs = ["src/components/**/*.{ts,tsx}"],
112
110
  exposesMode = "both",
113
111
  envPrefix = "REMOTE_",
114
112
  manifestPathOrUrl,
115
- autoShareReact = true
113
+ autoWhenEmpty = true,
114
+ mf
116
115
  } = opts;
116
+ if (!mf || typeof mf !== "object") {
117
+ throw new Error(
118
+ '[plugin-mf-auto] "mf" options is required and must be an object.'
119
+ );
120
+ }
117
121
  return {
118
122
  name: "plugin-mf-auto",
119
123
  apply: "build",
120
124
  async setup(api) {
121
125
  const { pluginModuleFederation } = await import("@module-federation/rsbuild-plugin");
122
- async function getExposes() {
126
+ const getExposes = async () => {
123
127
  if (exposesMode === "jsdoc")
124
128
  return collectAutoExposes({ baseDir, globs });
125
129
  if (exposesMode === "wrapper")
@@ -127,64 +131,34 @@ function pluginCore(opts = {}) {
127
131
  const a = await collectAutoExposes({ baseDir, globs });
128
132
  const b = await collectAutoExposesWithWrapper({ baseDir, globs });
129
133
  return { ...a, ...b };
130
- }
131
- async function getRemotes() {
132
- return collectAutoRemotes({ envPrefix, manifestPathOrUrl });
133
- }
134
+ };
135
+ const getRemotes = async () => collectAutoRemotes({ envPrefix, manifestPathOrUrl });
134
136
  api.modifyRsbuildConfig(async (config) => {
135
- const [exposes, remotes] = await Promise.all([
136
- getExposes(),
137
- getRemotes()
138
- ]);
139
- const sharedDefaults = autoShareReact ? {
140
- react: {
141
- singleton: true,
142
- eager: true,
143
- requiredVersion: false
144
- },
145
- "react-dom": {
146
- singleton: true,
147
- eager: true,
148
- requiredVersion: false
149
- },
150
- "react-router": {
151
- singleton: true,
152
- eager: true,
153
- requiredVersion: false
154
- },
155
- "react-router-dom": {
156
- singleton: true,
157
- eager: true,
158
- requiredVersion: false
159
- },
160
- "@azure/msal-react": {
161
- singleton: true,
162
- eager: true,
163
- requiredVersion: false
164
- },
165
- "@azure/msal-browser": {
166
- singleton: true,
167
- eager: true,
168
- requiredVersion: false
137
+ const mfMerged = { ...mf };
138
+ if (!autoWhenEmpty || mfMerged.exposes == null || Object.keys(mfMerged.exposes).length === 0) {
139
+ const autoExposes = await getExposes();
140
+ if (Object.keys(autoExposes).length > 0) {
141
+ mfMerged.exposes = { ...mfMerged.exposes ?? {}, ...autoExposes };
169
142
  }
170
- } : void 0;
143
+ }
144
+ if (!autoWhenEmpty || mfMerged.remotes == null || Object.keys(mfMerged.remotes).length === 0) {
145
+ const autoRemotes = await getRemotes();
146
+ if (Object.keys(autoRemotes).length > 0) {
147
+ mfMerged.remotes = { ...mfMerged.remotes ?? {}, ...autoRemotes };
148
+ }
149
+ }
150
+ if (!mfMerged.name) {
151
+ mfMerged.name = path3.basename(api.context.rootPath).replace(/\W+/g, "");
152
+ }
171
153
  config.plugins ||= [];
172
- config.plugins.push(
173
- pluginModuleFederation({
174
- name: name ?? path3.basename(api.context.rootPath).replace(/\W+/g, ""),
175
- filename,
176
- exposes,
177
- remotes,
178
- shared: sharedDefaults
179
- })
180
- );
154
+ config.plugins.push(pluginModuleFederation(mfMerged));
181
155
  return config;
182
156
  });
183
157
  }
184
158
  };
185
159
  }
186
- var index_default = pluginCore;
160
+ var index_default = pluginMFAuto;
187
161
  export {
188
162
  index_default as default,
189
- pluginCore
163
+ pluginMFAuto
190
164
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ptech-preset",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Auto Module.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",