ptech-preset 1.1.9 → 1.2.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/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,9 +170,7 @@ 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",
@@ -173,8 +179,7 @@ function pluginMFAuto(opts) {
173
179
  const { pluginModuleFederation } = await import("@module-federation/rsbuild-plugin");
174
180
  const getExposes = async () => {
175
181
  if (exposesMode === "jsdoc") return collectAutoExposes({ baseDir, globs });
176
- if (exposesMode === "wrapper")
177
- return collectAutoExposesWithWrapper({ baseDir, globs });
182
+ if (exposesMode === "wrapper") return collectAutoExposesWithWrapper({ baseDir, globs });
178
183
  const a = await collectAutoExposes({ baseDir, globs });
179
184
  const b = await collectAutoExposesWithWrapper({ baseDir, globs });
180
185
  return { ...a, ...b };
@@ -207,6 +212,9 @@ function pluginMFAuto(opts) {
207
212
  if (!mfMerged.name) {
208
213
  mfMerged.name = getPackageName(root) || path3.basename(root).replace(/\W+/g, "");
209
214
  }
215
+ if (typeof mfMerged.shared === "undefined") {
216
+ mfMerged.shared = DEFAULT_SHARED;
217
+ }
210
218
  if (cssInjection !== "none") {
211
219
  const cssAbs = path3.resolve(root, cssEntry);
212
220
  const hasCss = fs3.existsSync(cssAbs);
@@ -214,20 +222,12 @@ function pluginMFAuto(opts) {
214
222
  fs3.mkdirSync(tempDir, { recursive: true });
215
223
  if (cssInjection === "wrapper" && mfMerged.exposes) {
216
224
  const wrapped = {};
217
- for (const [key, rel] of Object.entries(
218
- mfMerged.exposes
219
- )) {
225
+ for (const [key, rel] of Object.entries(mfMerged.exposes)) {
220
226
  const targetAbs = path3.resolve(root, String(rel).replace(/^\.\//, ""));
221
- const proxyFile = path3.join(
222
- tempDir,
223
- `expose_${key.replace(/[./]/g, "_")}.ts`
224
- );
227
+ const proxyFile = path3.join(tempDir, `expose_${key.replace(/[./]/g, "_")}.ts`);
225
228
  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
- }
229
+ if (hasCss) lines.push(`import ${JSON.stringify(cssAbs.replace(/\\/g, "/"))};`);
230
+ else lines.push(`/* no css: ${cssEntry} not found */`);
231
231
  const target = JSON.stringify(targetAbs.replace(/\\/g, "/"));
232
232
  lines.push(`export * from ${target};`);
233
233
  lines.push(`export { default } from ${target};`);
@@ -247,20 +247,23 @@ function pluginMFAuto(opts) {
247
247
  "utf8"
248
248
  );
249
249
  const relFromRoot = path3.relative(root, stylesFile).replace(/\\/g, "/");
250
- mfMerged.exposes = {
251
- ...mfMerged.exposes ?? {},
252
- [stylesExposeKey]: `./${relFromRoot}`
253
- };
250
+ mfMerged.exposes = { ...mfMerged.exposes ?? {}, [stylesExposeKey]: `./${relFromRoot}` };
254
251
  }
255
252
  }
256
253
  if (typeof mfMerged.dts === "undefined") mfMerged.dts = true;
257
254
  const mfPlugin = pluginModuleFederation(mfMerged);
258
255
  await mfPlugin.setup?.(api);
256
+ const pkgSafe = getPackageName(root) || mfMerged.name || path3.basename(root).replace(/\W+/g, "");
257
+ const cdnUrl = `${CDN_BASE}${pkgSafe}/`;
258
+ const isProd = process.env.NODE_ENV === "production";
259
+ api.modifyRsbuildConfig((config) => {
260
+ config.output ??= {};
261
+ if (isProd && !config.output.assetPrefix) config.output.assetPrefix = cdnUrl;
262
+ return config;
263
+ });
259
264
  if (separateExposes && mfMerged.exposes) {
260
265
  const force = {};
261
- for (const [key, rel] of Object.entries(
262
- mfMerged.exposes
263
- )) {
266
+ for (const [key, rel] of Object.entries(mfMerged.exposes)) {
264
267
  const abs = path3.resolve(root, String(rel).replace(/^\.\//, "")).replace(/\\/g, "/");
265
268
  const safe = separateExposeChunkPrefix + key.replace(/[^a-zA-Z0-9_]/g, "_");
266
269
  force[safe] = new RegExp(`${escapeRegExp(abs)}$`);
@@ -275,8 +278,8 @@ function pluginMFAuto(opts) {
275
278
  }
276
279
  };
277
280
  }
278
- var index_default = pluginMFAuto;
281
+ var index_default = pluginCore;
279
282
  export {
280
283
  index_default as default,
281
- pluginMFAuto
284
+ pluginCore
282
285
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ptech-preset",
3
- "version": "1.1.9",
3
+ "version": "1.2.1",
4
4
  "description": "Auto Module.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",