ptech-preset 1.1.9 → 1.2.2

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
@@ -7,18 +7,14 @@ type MfAutoOptions = {
7
7
  exposesMode?: "jsdoc" | "wrapper" | "both";
8
8
  envPrefix?: string;
9
9
  manifestPathOrUrl?: string;
10
- /** true: chỉ auto khi exposes/remotes trống; false: luôn auto rồi merge */
11
10
  autoWhenEmpty?: boolean;
12
- /** Tiêm CSS vào exposes */
13
11
  cssInjection?: CssInjectionMode;
14
12
  cssEntry?: string;
15
13
  stylesExposeKey?: string;
16
- /** Ép tách chunk cho từng expose */
17
14
  separateExposes?: boolean;
18
15
  separateExposeChunkPrefix?: string;
19
- /** options chuyển nguyên vẹn sang @module-federation/rsbuild-plugin */
20
16
  mf: Record<string, any>;
21
17
  };
22
- declare function pluginMFAuto(opts: MfAutoOptions): RsbuildPlugin;
18
+ declare function pluginCore(opts: MfAutoOptions): RsbuildPlugin;
23
19
 
24
- export { type MfAutoOptions, pluginMFAuto as default, pluginMFAuto };
20
+ export { type MfAutoOptions, pluginCore as default, pluginCore };
package/dist/index.js CHANGED
@@ -146,7 +146,15 @@ function normalizeExposePath(root, maybeRel) {
146
146
  return `./${relFromRoot}`;
147
147
  }
148
148
  var escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
149
- function pluginMFAuto(opts) {
149
+ var DEFAULT_SHARED = {
150
+ react: { singleton: true, eager: true, requiredVersion: false },
151
+ "react-dom": { singleton: true, eager: true, requiredVersion: false },
152
+ "react-router": { singleton: true, eager: true, requiredVersion: false },
153
+ "@azure/msal-react": { singleton: true, eager: true, requiredVersion: false },
154
+ "@azure/msal-browser": { singleton: true, eager: true, requiredVersion: false }
155
+ };
156
+ var CDN_BASE = "https://oneportal.blob.core.windows.net/external/ts/";
157
+ function pluginCore(opts) {
150
158
  const {
151
159
  baseDir = "src",
152
160
  globs = ["src/components/**/*.{ts,tsx}"],
@@ -162,19 +170,15 @@ function pluginMFAuto(opts) {
162
170
  mf
163
171
  } = opts;
164
172
  if (!mf || typeof mf !== "object") {
165
- throw new Error(
166
- '[plugin-mf-auto] "mf" options is required and must be an object.'
167
- );
173
+ throw new Error('[plugin-mf-auto] "mf" options is required and must be an object.');
168
174
  }
169
175
  return {
170
176
  name: "plugin-mf-auto",
171
- apply: "build",
172
177
  async setup(api) {
173
178
  const { pluginModuleFederation } = await import("@module-federation/rsbuild-plugin");
174
179
  const getExposes = async () => {
175
180
  if (exposesMode === "jsdoc") return collectAutoExposes({ baseDir, globs });
176
- if (exposesMode === "wrapper")
177
- return collectAutoExposesWithWrapper({ baseDir, globs });
181
+ if (exposesMode === "wrapper") return collectAutoExposesWithWrapper({ baseDir, globs });
178
182
  const a = await collectAutoExposes({ baseDir, globs });
179
183
  const b = await collectAutoExposesWithWrapper({ baseDir, globs });
180
184
  return { ...a, ...b };
@@ -207,6 +211,9 @@ function pluginMFAuto(opts) {
207
211
  if (!mfMerged.name) {
208
212
  mfMerged.name = getPackageName(root) || path3.basename(root).replace(/\W+/g, "");
209
213
  }
214
+ if (typeof mfMerged.shared === "undefined") {
215
+ mfMerged.shared = DEFAULT_SHARED;
216
+ }
210
217
  if (cssInjection !== "none") {
211
218
  const cssAbs = path3.resolve(root, cssEntry);
212
219
  const hasCss = fs3.existsSync(cssAbs);
@@ -214,20 +221,12 @@ function pluginMFAuto(opts) {
214
221
  fs3.mkdirSync(tempDir, { recursive: true });
215
222
  if (cssInjection === "wrapper" && mfMerged.exposes) {
216
223
  const wrapped = {};
217
- for (const [key, rel] of Object.entries(
218
- mfMerged.exposes
219
- )) {
224
+ for (const [key, rel] of Object.entries(mfMerged.exposes)) {
220
225
  const targetAbs = path3.resolve(root, String(rel).replace(/^\.\//, ""));
221
- const proxyFile = path3.join(
222
- tempDir,
223
- `expose_${key.replace(/[./]/g, "_")}.ts`
224
- );
226
+ const proxyFile = path3.join(tempDir, `expose_${key.replace(/[./]/g, "_")}.ts`);
225
227
  const lines = [];
226
- if (hasCss) {
227
- lines.push(`import ${JSON.stringify(cssAbs.replace(/\\/g, "/"))};`);
228
- } else {
229
- lines.push(`/* no css: ${cssEntry} not found */`);
230
- }
228
+ if (hasCss) lines.push(`import ${JSON.stringify(cssAbs.replace(/\\/g, "/"))};`);
229
+ else lines.push(`/* no css: ${cssEntry} not found */`);
231
230
  const target = JSON.stringify(targetAbs.replace(/\\/g, "/"));
232
231
  lines.push(`export * from ${target};`);
233
232
  lines.push(`export { default } from ${target};`);
@@ -247,20 +246,23 @@ function pluginMFAuto(opts) {
247
246
  "utf8"
248
247
  );
249
248
  const relFromRoot = path3.relative(root, stylesFile).replace(/\\/g, "/");
250
- mfMerged.exposes = {
251
- ...mfMerged.exposes ?? {},
252
- [stylesExposeKey]: `./${relFromRoot}`
253
- };
249
+ mfMerged.exposes = { ...mfMerged.exposes ?? {}, [stylesExposeKey]: `./${relFromRoot}` };
254
250
  }
255
251
  }
256
252
  if (typeof mfMerged.dts === "undefined") mfMerged.dts = true;
257
253
  const mfPlugin = pluginModuleFederation(mfMerged);
258
254
  await mfPlugin.setup?.(api);
255
+ const pkgSafe = getPackageName(root) || mfMerged.name || path3.basename(root).replace(/\W+/g, "");
256
+ const cdnUrl = `${CDN_BASE}${pkgSafe}/`;
257
+ const isProd = process.env.NODE_ENV === "production";
258
+ api.modifyRsbuildConfig((config) => {
259
+ config.output ??= {};
260
+ if (isProd && !config.output.assetPrefix) config.output.assetPrefix = cdnUrl;
261
+ return config;
262
+ });
259
263
  if (separateExposes && mfMerged.exposes) {
260
264
  const force = {};
261
- for (const [key, rel] of Object.entries(
262
- mfMerged.exposes
263
- )) {
265
+ for (const [key, rel] of Object.entries(mfMerged.exposes)) {
264
266
  const abs = path3.resolve(root, String(rel).replace(/^\.\//, "")).replace(/\\/g, "/");
265
267
  const safe = separateExposeChunkPrefix + key.replace(/[^a-zA-Z0-9_]/g, "_");
266
268
  force[safe] = new RegExp(`${escapeRegExp(abs)}$`);
@@ -275,8 +277,8 @@ function pluginMFAuto(opts) {
275
277
  }
276
278
  };
277
279
  }
278
- var index_default = pluginMFAuto;
280
+ var index_default = pluginCore;
279
281
  export {
280
282
  index_default as default,
281
- pluginMFAuto
283
+ pluginCore
282
284
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ptech-preset",
3
- "version": "1.1.9",
3
+ "version": "1.2.2",
4
4
  "description": "Auto Module.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",