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 +4 -5
- package/dist/index.js +29 -55
- package/package.json +1 -1
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
|
-
|
|
9
|
+
autoWhenEmpty?: boolean;
|
|
10
|
+
mf: Record<string, any>;
|
|
12
11
|
};
|
|
13
|
-
declare function
|
|
12
|
+
declare function pluginMFAuto(opts: MfAutoOptions): RsbuildPlugin;
|
|
14
13
|
|
|
15
|
-
export { type MfAutoOptions,
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
132
|
-
return collectAutoRemotes({ envPrefix, manifestPathOrUrl });
|
|
133
|
-
}
|
|
134
|
+
};
|
|
135
|
+
const getRemotes = async () => collectAutoRemotes({ envPrefix, manifestPathOrUrl });
|
|
134
136
|
api.modifyRsbuildConfig(async (config) => {
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
}
|
|
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 =
|
|
160
|
+
var index_default = pluginMFAuto;
|
|
187
161
|
export {
|
|
188
162
|
index_default as default,
|
|
189
|
-
|
|
163
|
+
pluginMFAuto
|
|
190
164
|
};
|