ptech-preset 1.3.4 → 1.3.6
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.js +112 -39
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -133,10 +133,18 @@ var esmRequire = createRequire(import.meta.url);
|
|
|
133
133
|
var HERE = typeof __dirname !== "undefined" ? __dirname : path3.dirname(fileURLToPath(import.meta.url));
|
|
134
134
|
var DEFAULT_SHARED = {
|
|
135
135
|
react: { singleton: true, eager: true, requiredVersion: false },
|
|
136
|
-
"react-dom": {
|
|
136
|
+
"react-dom": {
|
|
137
|
+
singleton: true,
|
|
138
|
+
eager: true,
|
|
139
|
+
requiredVersion: false
|
|
140
|
+
},
|
|
137
141
|
"react-router": { singleton: true, eager: true, requiredVersion: false },
|
|
138
142
|
"@azure/msal-react": { singleton: true, eager: true, requiredVersion: false },
|
|
139
|
-
"@azure/msal-browser": {
|
|
143
|
+
"@azure/msal-browser": {
|
|
144
|
+
singleton: true,
|
|
145
|
+
eager: true,
|
|
146
|
+
requiredVersion: false
|
|
147
|
+
}
|
|
140
148
|
};
|
|
141
149
|
var CDN_BASE = "https://oneportal.blob.core.windows.net/external/ts/";
|
|
142
150
|
function getPackageName(root) {
|
|
@@ -199,7 +207,9 @@ async function devFetchRemoteTypesOnce(params) {
|
|
|
199
207
|
try {
|
|
200
208
|
const res = await fetch(spec.api);
|
|
201
209
|
if (!res.ok) {
|
|
202
|
-
console.warn(
|
|
210
|
+
console.warn(
|
|
211
|
+
`[mf-auto] fetch types failed for ${scope}: ${res.status} ${res.statusText}`
|
|
212
|
+
);
|
|
203
213
|
continue;
|
|
204
214
|
}
|
|
205
215
|
const txt = await res.text();
|
|
@@ -211,7 +221,11 @@ async function devFetchRemoteTypesOnce(params) {
|
|
|
211
221
|
const refs = Object.keys(urls).map((s) => `/// <reference path="./__remotes/${s}.d.ts" />`).join(os.EOL);
|
|
212
222
|
const banner = `// generated by plugin-mf-auto (dev once)
|
|
213
223
|
`;
|
|
214
|
-
fs3.writeFileSync(
|
|
224
|
+
fs3.writeFileSync(
|
|
225
|
+
path3.join(typesRootAbs, "index.d.ts"),
|
|
226
|
+
banner + refs + os.EOL,
|
|
227
|
+
"utf8"
|
|
228
|
+
);
|
|
215
229
|
const shimDir = path3.join(root, baseDir, ".mf-auto");
|
|
216
230
|
fs3.mkdirSync(shimDir, { recursive: true });
|
|
217
231
|
const relToIndex = path3.relative(shimDir, path3.join(typesRootAbs, "index.d.ts")).replace(/\\/g, "/");
|
|
@@ -258,7 +272,10 @@ function readBaseTsConfigJSONC(baseAbs, root) {
|
|
|
258
272
|
const raw = fs3.readFileSync(baseAbs, "utf8").replace(/^\uFEFF/, "").replace(/(^|[\s{[,])\/\/.*$/gm, "$1").replace(/\/\*[\s\S]*?\*\//g, "").replace(/,(?=\s*[\]}])/g, "");
|
|
259
273
|
return JSON.parse(raw);
|
|
260
274
|
} catch (e) {
|
|
261
|
-
console.warn(
|
|
275
|
+
console.warn(
|
|
276
|
+
"[plugin-mf-auto] Cannot parse tsconfig (fallback) -> using minimal:",
|
|
277
|
+
e
|
|
278
|
+
);
|
|
262
279
|
return {};
|
|
263
280
|
}
|
|
264
281
|
}
|
|
@@ -274,7 +291,9 @@ function writePatchedTsconfig(opts) {
|
|
|
274
291
|
fs3.mkdirSync(outDirAbs, { recursive: true });
|
|
275
292
|
const baseAbs = path3.resolve(root, baseTsconfigPath);
|
|
276
293
|
const base = readBaseTsConfigJSONC(baseAbs, root);
|
|
277
|
-
const compilerOptions = {
|
|
294
|
+
const compilerOptions = {
|
|
295
|
+
...base.compilerOptions ?? {}
|
|
296
|
+
};
|
|
278
297
|
const rootAbs = path3.resolve(root).replace(/\\/g, "/");
|
|
279
298
|
const baseUrlAbs = (compilerOptions.baseUrl ? path3.resolve(root, compilerOptions.baseUrl) : rootAbs).replace(/\\/g, "/");
|
|
280
299
|
const srcAbs = path3.resolve(root, baseDir).replace(/\\/g, "/");
|
|
@@ -300,11 +319,16 @@ function writePatchedTsconfig(opts) {
|
|
|
300
319
|
paths[key] = arr;
|
|
301
320
|
}
|
|
302
321
|
compilerOptions.paths = paths;
|
|
303
|
-
const tr = new Set(
|
|
304
|
-
|
|
322
|
+
const tr = new Set(
|
|
323
|
+
Array.isArray(compilerOptions.typeRoots) ? compilerOptions.typeRoots : []
|
|
324
|
+
);
|
|
325
|
+
if (![...tr].some((s) => /node_modules\/@types$/.test(s)))
|
|
326
|
+
tr.add(`${rootAbs}/node_modules/@types`);
|
|
305
327
|
compilerOptions.typeRoots = Array.from(tr);
|
|
306
328
|
base.compilerOptions = compilerOptions;
|
|
307
|
-
const include = new Set(
|
|
329
|
+
const include = new Set(
|
|
330
|
+
Array.isArray(base.include) ? base.include : []
|
|
331
|
+
);
|
|
308
332
|
include.add(`${srcAbs}/**/*`);
|
|
309
333
|
include.add(`${typesAbs}/**/*`);
|
|
310
334
|
include.add(`${outDirAbs.replace(/\\/g, "/")}/**/*`);
|
|
@@ -333,15 +357,18 @@ function pluginCore(opts) {
|
|
|
333
357
|
mf
|
|
334
358
|
} = opts;
|
|
335
359
|
if (!mf || typeof mf !== "object") {
|
|
336
|
-
throw new Error(
|
|
360
|
+
throw new Error(
|
|
361
|
+
'[plugin-mf-auto] "mf" options is required and must be an object.'
|
|
362
|
+
);
|
|
337
363
|
}
|
|
338
364
|
return {
|
|
339
365
|
name: "plugin-mf-auto",
|
|
340
366
|
async setup(api) {
|
|
341
|
-
const { pluginModuleFederation } = await import("@module-federation/rsbuild-plugin");
|
|
342
367
|
const getExposes = async () => {
|
|
343
|
-
if (exposesMode === "jsdoc")
|
|
344
|
-
|
|
368
|
+
if (exposesMode === "jsdoc")
|
|
369
|
+
return collectAutoExposes({ baseDir, globs });
|
|
370
|
+
if (exposesMode === "wrapper")
|
|
371
|
+
return collectAutoExposesWithWrapper({ baseDir, globs });
|
|
345
372
|
const a = await collectAutoExposes({ baseDir, globs });
|
|
346
373
|
const b = await collectAutoExposesWithWrapper({ baseDir, globs });
|
|
347
374
|
return { ...a, ...b };
|
|
@@ -377,6 +404,17 @@ function pluginCore(opts) {
|
|
|
377
404
|
if (typeof mfMerged.shared === "undefined") {
|
|
378
405
|
mfMerged.shared = DEFAULT_SHARED;
|
|
379
406
|
}
|
|
407
|
+
const command = api?.context?.command;
|
|
408
|
+
const isBuild = command === "build";
|
|
409
|
+
const isDev = !isBuild;
|
|
410
|
+
if (isDev && mfMerged.shared && typeof mfMerged.shared === "object") {
|
|
411
|
+
for (const key of Object.keys(mfMerged.shared)) {
|
|
412
|
+
const conf = mfMerged.shared[key];
|
|
413
|
+
if (!conf || typeof conf !== "object") continue;
|
|
414
|
+
if (/^react(-dom)?$/.test(key)) continue;
|
|
415
|
+
if ("eager" in conf) conf.eager = false;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
380
418
|
if (cssInjection !== "none") {
|
|
381
419
|
const cssAbs = path3.resolve(root, cssEntry);
|
|
382
420
|
const hasCss = fs3.existsSync(cssAbs);
|
|
@@ -384,15 +422,30 @@ function pluginCore(opts) {
|
|
|
384
422
|
fs3.mkdirSync(tempDir, { recursive: true });
|
|
385
423
|
if (cssInjection === "wrapper" && mfMerged.exposes) {
|
|
386
424
|
const wrapped = {};
|
|
387
|
-
for (const [key, rel] of Object.entries(
|
|
388
|
-
|
|
389
|
-
|
|
425
|
+
for (const [key, rel] of Object.entries(
|
|
426
|
+
mfMerged.exposes
|
|
427
|
+
)) {
|
|
428
|
+
const targetAbs = path3.resolve(root, String(rel).replace(/^\.\//, "")).replace(/\\/g, "/");
|
|
429
|
+
const proxyFile = path3.join(
|
|
430
|
+
tempDir,
|
|
431
|
+
`expose_${key.replace(/[./]/g, "_")}.ts`
|
|
432
|
+
);
|
|
390
433
|
const lines = [];
|
|
391
|
-
if (hasCss)
|
|
392
|
-
|
|
393
|
-
|
|
434
|
+
if (hasCss) {
|
|
435
|
+
const cssRel = path3.relative(path3.dirname(proxyFile), cssAbs).replace(/\\/g, "/");
|
|
436
|
+
const cssImport = cssRel.startsWith(".") ? cssRel : `./${cssRel}`;
|
|
437
|
+
lines.push(`import ${JSON.stringify(cssImport)};`);
|
|
438
|
+
} else {
|
|
439
|
+
lines.push(`/* no css: ${cssEntry} not found */`);
|
|
440
|
+
}
|
|
441
|
+
const targetRel = path3.relative(path3.dirname(proxyFile), targetAbs).replace(/\\/g, "/");
|
|
442
|
+
const targetImport = targetRel.startsWith(".") ? targetRel : `./${targetRel}`;
|
|
443
|
+
const target = JSON.stringify(targetImport);
|
|
394
444
|
lines.push(`export * from ${target};`);
|
|
395
445
|
lines.push(`export { default } from ${target};`);
|
|
446
|
+
lines.push(
|
|
447
|
+
`if (import.meta && (import.meta as any).webpackHot) {(import.meta as any).webpackHot.accept();}`
|
|
448
|
+
);
|
|
396
449
|
lines.push(`// generated by plugin-mf-auto`);
|
|
397
450
|
fs3.writeFileSync(proxyFile, lines.join(os.EOL), "utf8");
|
|
398
451
|
const relFromRoot = path3.relative(root, proxyFile).replace(/\\/g, "/");
|
|
@@ -402,19 +455,22 @@ function pluginCore(opts) {
|
|
|
402
455
|
}
|
|
403
456
|
if (cssInjection === "styles-expose" && hasCss) {
|
|
404
457
|
const stylesFile = path3.join(tempDir, `styles_expose.ts`);
|
|
458
|
+
const cssRel = path3.relative(path3.dirname(stylesFile), cssAbs).replace(/\\/g, "/");
|
|
459
|
+
const cssImport = cssRel.startsWith(".") ? cssRel : `./${cssRel}`;
|
|
405
460
|
fs3.writeFileSync(
|
|
406
461
|
stylesFile,
|
|
407
|
-
`import ${JSON.stringify(
|
|
462
|
+
`import ${JSON.stringify(cssImport)};
|
|
463
|
+
if (import.meta && (import.meta as any).webpackHot) {(import.meta as any).webpackHot.accept();}
|
|
408
464
|
// generated by plugin-mf-auto`,
|
|
409
465
|
"utf8"
|
|
410
466
|
);
|
|
411
467
|
const relFromRoot = path3.relative(root, stylesFile).replace(/\\/g, "/");
|
|
412
|
-
mfMerged.exposes = {
|
|
468
|
+
mfMerged.exposes = {
|
|
469
|
+
...mfMerged.exposes ?? {},
|
|
470
|
+
[stylesExposeKey]: `./${relFromRoot}`
|
|
471
|
+
};
|
|
413
472
|
}
|
|
414
473
|
}
|
|
415
|
-
const command = api?.context?.command;
|
|
416
|
-
const isProdLike = command === "build" || process.env.NODE_ENV === "production";
|
|
417
|
-
const isDev = !isProdLike;
|
|
418
474
|
const autoTypeUrls = buildRemoteTypeUrls(mfMerged.remotes || {});
|
|
419
475
|
const remoteAliases = Object.keys(autoTypeUrls);
|
|
420
476
|
const tsconfigForDtsAbs = writePatchedTsconfig({
|
|
@@ -433,23 +489,38 @@ function pluginCore(opts) {
|
|
|
433
489
|
const refresh = process.env[devTypesRefreshEnvVar] === "1";
|
|
434
490
|
const typesRootAbs = path3.resolve(root, typesFolder);
|
|
435
491
|
const indexFile = path3.join(typesRootAbs, "index.d.ts");
|
|
436
|
-
const needFetch = refresh || !fs3.existsSync(indexFile) || remoteAliases.some(
|
|
492
|
+
const needFetch = refresh || !fs3.existsSync(indexFile) || remoteAliases.some(
|
|
493
|
+
(s) => !fs3.existsSync(path3.join(typesRootAbs, "__remotes", `${s}.d.ts`))
|
|
494
|
+
);
|
|
437
495
|
if (remoteAliases.length > 0 && needFetch) {
|
|
438
|
-
await devFetchRemoteTypesOnce({
|
|
496
|
+
await devFetchRemoteTypesOnce({
|
|
497
|
+
root,
|
|
498
|
+
baseDir,
|
|
499
|
+
typesFolderRel: typesFolder,
|
|
500
|
+
urls: autoTypeUrls
|
|
501
|
+
});
|
|
439
502
|
}
|
|
440
503
|
}
|
|
441
|
-
const
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
typesFolder: existingConsume.typesFolder ?? typesFolder,
|
|
448
|
-
maxRetries: existingConsume.maxRetries ?? 3,
|
|
449
|
-
remoteTypeUrls: { ...autoTypeUrls, ...existingRt }
|
|
504
|
+
const dtsGenMaybe = ensureDtsObject(mfMerged.dts);
|
|
505
|
+
if (dtsGenMaybe !== false) {
|
|
506
|
+
const dtsGen = dtsGenMaybe;
|
|
507
|
+
dtsGen.generateTypes = {
|
|
508
|
+
...dtsGen.generateTypes ?? {},
|
|
509
|
+
tsConfigPath: tsconfigForDtsToUse
|
|
450
510
|
};
|
|
511
|
+
if (isBuild && remoteAliases.length > 0) {
|
|
512
|
+
const existingConsume = dtsGen.consumeTypes ?? {};
|
|
513
|
+
const existingRt = existingConsume.remoteTypeUrls ?? {};
|
|
514
|
+
dtsGen.consumeTypes = {
|
|
515
|
+
typesFolder: existingConsume.typesFolder ?? typesFolder,
|
|
516
|
+
maxRetries: existingConsume.maxRetries ?? 3,
|
|
517
|
+
remoteTypeUrls: { ...autoTypeUrls, ...existingRt }
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
mfMerged.dts = dtsGen;
|
|
521
|
+
} else {
|
|
522
|
+
mfMerged.dts = false;
|
|
451
523
|
}
|
|
452
|
-
mfMerged.dts = dtsGen;
|
|
453
524
|
const { pluginModuleFederation: mfPluginFactory } = await import("@module-federation/rsbuild-plugin");
|
|
454
525
|
const mfPlugin = mfPluginFactory(mfMerged);
|
|
455
526
|
await mfPlugin.setup?.(api);
|
|
@@ -460,17 +531,19 @@ function pluginCore(opts) {
|
|
|
460
531
|
const fromEnv = process.env.CDN_URL || process.env.ASSET_PREFIX;
|
|
461
532
|
const fallbackCdn = `${CDN_BASE}${pkgSafe}/`;
|
|
462
533
|
const target = fromEnv ?? fallbackCdn;
|
|
463
|
-
if (
|
|
534
|
+
if (isBuild && (!current || current === "/" || current === "./")) {
|
|
464
535
|
config.output.assetPrefix = target;
|
|
465
536
|
}
|
|
466
537
|
return config;
|
|
467
538
|
});
|
|
468
539
|
if (separateExposes && mfMerged.exposes) {
|
|
469
540
|
const force = {};
|
|
470
|
-
for (const [key, rel] of Object.entries(
|
|
541
|
+
for (const [key, rel] of Object.entries(
|
|
542
|
+
mfMerged.exposes
|
|
543
|
+
)) {
|
|
471
544
|
const abs = path3.resolve(root, String(rel).replace(/^\.\//, "")).replace(/\\/g, "/");
|
|
472
545
|
const safe = separateExposeChunkPrefix + key.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
473
|
-
force[safe] = new RegExp(`${escapeRegExp(abs)}
|
|
546
|
+
force[safe] = new RegExp(`${escapeRegExp(abs)}(\\?.*)?$`);
|
|
474
547
|
}
|
|
475
548
|
api.modifyRsbuildConfig((config) => {
|
|
476
549
|
(config.performance ??= {}).chunkSplit ??= {};
|