ptech-preset 1.2.8 → 1.2.9
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 +69 -20
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -150,10 +150,18 @@ function normalizeExposePath(root, maybeRel) {
|
|
|
150
150
|
var escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
151
151
|
var DEFAULT_SHARED = {
|
|
152
152
|
react: { singleton: true, eager: true, requiredVersion: false },
|
|
153
|
-
"react-dom": {
|
|
153
|
+
"react-dom": {
|
|
154
|
+
singleton: true,
|
|
155
|
+
eager: true,
|
|
156
|
+
requiredVersion: false
|
|
157
|
+
},
|
|
154
158
|
"react-router": { singleton: true, eager: true, requiredVersion: false },
|
|
155
159
|
"@azure/msal-react": { singleton: true, eager: true, requiredVersion: false },
|
|
156
|
-
"@azure/msal-browser": {
|
|
160
|
+
"@azure/msal-browser": {
|
|
161
|
+
singleton: true,
|
|
162
|
+
eager: true,
|
|
163
|
+
requiredVersion: false
|
|
164
|
+
}
|
|
157
165
|
};
|
|
158
166
|
var CDN_BASE = "https://oneportal.blob.core.windows.net/external/ts/";
|
|
159
167
|
function parseRemoteSpec(key, val) {
|
|
@@ -201,7 +209,9 @@ async function devFetchRemoteTypesOnce(params) {
|
|
|
201
209
|
try {
|
|
202
210
|
const res = await fetch(spec.api);
|
|
203
211
|
if (!res.ok) {
|
|
204
|
-
console.warn(
|
|
212
|
+
console.warn(
|
|
213
|
+
`[mf-auto] fetch types failed for ${scope}: ${res.status} ${res.statusText}`
|
|
214
|
+
);
|
|
205
215
|
continue;
|
|
206
216
|
}
|
|
207
217
|
const txt = await res.text();
|
|
@@ -213,7 +223,11 @@ async function devFetchRemoteTypesOnce(params) {
|
|
|
213
223
|
const refs = Object.keys(urls).map((s) => `/// <reference path="./__remotes/${s}.d.ts" />`).join(os.EOL);
|
|
214
224
|
const banner = `// generated by plugin-mf-auto (dev once)
|
|
215
225
|
`;
|
|
216
|
-
fs3.writeFileSync(
|
|
226
|
+
fs3.writeFileSync(
|
|
227
|
+
path3.join(typesRootAbs, "index.d.ts"),
|
|
228
|
+
banner + refs + os.EOL,
|
|
229
|
+
"utf8"
|
|
230
|
+
);
|
|
217
231
|
const shimDir = path3.join(root, baseDir, ".mf-auto");
|
|
218
232
|
fs3.mkdirSync(shimDir, { recursive: true });
|
|
219
233
|
const relToIndex = path3.relative(shimDir, path3.join(typesRootAbs, "index.d.ts")).replace(/\\/g, "/");
|
|
@@ -229,17 +243,23 @@ function stripJsonComments(json) {
|
|
|
229
243
|
return json.replace(/^\uFEFF/, "").replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
230
244
|
}
|
|
231
245
|
function writePatchedTsconfig(opts) {
|
|
232
|
-
const { root, baseTsconfigPath, typesFolder, remoteAliases } = opts;
|
|
246
|
+
const { root, baseTsconfigPath, typesFolder, remoteAliases, baseDir } = opts;
|
|
233
247
|
const baseAbs = path3.resolve(root, baseTsconfigPath);
|
|
234
248
|
let base = {};
|
|
235
249
|
try {
|
|
236
250
|
const raw = fs3.readFileSync(baseAbs, "utf8");
|
|
237
251
|
base = JSON.parse(stripJsonComments(raw));
|
|
238
252
|
} catch (e) {
|
|
239
|
-
console.warn(
|
|
253
|
+
console.warn(
|
|
254
|
+
"[plugin-mf-auto] Cannot read base tsconfig, using minimal:",
|
|
255
|
+
e
|
|
256
|
+
);
|
|
240
257
|
base = {};
|
|
241
258
|
}
|
|
242
259
|
const compilerOptions = { ...base.compilerOptions ?? {} };
|
|
260
|
+
const rootDirFromEnv = process.env.MF_DTS_ROOTDIR;
|
|
261
|
+
compilerOptions.rootDir = compilerOptions.rootDir ?? rootDirFromEnv ?? ".";
|
|
262
|
+
compilerOptions.baseUrl = compilerOptions.baseUrl ?? ".";
|
|
243
263
|
const paths = { ...compilerOptions.paths ?? {} };
|
|
244
264
|
for (const scope of remoteAliases) {
|
|
245
265
|
const key = `${scope}/*`;
|
|
@@ -249,11 +269,17 @@ function writePatchedTsconfig(opts) {
|
|
|
249
269
|
paths[key] = arr;
|
|
250
270
|
}
|
|
251
271
|
compilerOptions.paths = paths;
|
|
252
|
-
const tr = new Set(
|
|
253
|
-
|
|
272
|
+
const tr = new Set(
|
|
273
|
+
Array.isArray(compilerOptions.typeRoots) ? compilerOptions.typeRoots : []
|
|
274
|
+
);
|
|
275
|
+
if (![...tr].some((s) => /node_modules\/@types$/.test(s)))
|
|
276
|
+
tr.add("./node_modules/@types");
|
|
254
277
|
compilerOptions.typeRoots = Array.from(tr);
|
|
255
278
|
base.compilerOptions = compilerOptions;
|
|
256
|
-
const include = new Set(
|
|
279
|
+
const include = new Set(
|
|
280
|
+
Array.isArray(base.include) ? base.include : []
|
|
281
|
+
);
|
|
282
|
+
include.add(`./${baseDir}/**/*`);
|
|
257
283
|
include.add(`./${typesFolder}/**/*`);
|
|
258
284
|
base.include = Array.from(include);
|
|
259
285
|
const outDir = path3.resolve(root, ".mf-auto");
|
|
@@ -280,15 +306,19 @@ function pluginCore(opts) {
|
|
|
280
306
|
mf
|
|
281
307
|
} = opts;
|
|
282
308
|
if (!mf || typeof mf !== "object") {
|
|
283
|
-
throw new Error(
|
|
309
|
+
throw new Error(
|
|
310
|
+
'[plugin-mf-auto] "mf" options is required and must be an object.'
|
|
311
|
+
);
|
|
284
312
|
}
|
|
285
313
|
return {
|
|
286
314
|
name: "plugin-mf-auto",
|
|
287
315
|
async setup(api) {
|
|
288
316
|
const { pluginModuleFederation } = await import("@module-federation/rsbuild-plugin");
|
|
289
317
|
const getExposes = async () => {
|
|
290
|
-
if (exposesMode === "jsdoc")
|
|
291
|
-
|
|
318
|
+
if (exposesMode === "jsdoc")
|
|
319
|
+
return collectAutoExposes({ baseDir, globs });
|
|
320
|
+
if (exposesMode === "wrapper")
|
|
321
|
+
return collectAutoExposesWithWrapper({ baseDir, globs });
|
|
292
322
|
const a = await collectAutoExposes({ baseDir, globs });
|
|
293
323
|
const b = await collectAutoExposesWithWrapper({ baseDir, globs });
|
|
294
324
|
return { ...a, ...b };
|
|
@@ -331,11 +361,22 @@ function pluginCore(opts) {
|
|
|
331
361
|
fs3.mkdirSync(tempDir, { recursive: true });
|
|
332
362
|
if (cssInjection === "wrapper" && mfMerged.exposes) {
|
|
333
363
|
const wrapped = {};
|
|
334
|
-
for (const [key, rel] of Object.entries(
|
|
335
|
-
|
|
336
|
-
|
|
364
|
+
for (const [key, rel] of Object.entries(
|
|
365
|
+
mfMerged.exposes
|
|
366
|
+
)) {
|
|
367
|
+
const targetAbs = path3.resolve(
|
|
368
|
+
root,
|
|
369
|
+
String(rel).replace(/^\.\//, "")
|
|
370
|
+
);
|
|
371
|
+
const proxyFile = path3.join(
|
|
372
|
+
tempDir,
|
|
373
|
+
`expose_${key.replace(/[./]/g, "_")}.ts`
|
|
374
|
+
);
|
|
337
375
|
const lines = [];
|
|
338
|
-
if (hasCss)
|
|
376
|
+
if (hasCss)
|
|
377
|
+
lines.push(
|
|
378
|
+
`import ${JSON.stringify(cssAbs.replace(/\\/g, "/"))};`
|
|
379
|
+
);
|
|
339
380
|
else lines.push(`/* no css: ${cssEntry} not found */`);
|
|
340
381
|
const target = JSON.stringify(targetAbs.replace(/\\/g, "/"));
|
|
341
382
|
lines.push(`export * from ${target};`);
|
|
@@ -351,12 +392,17 @@ function pluginCore(opts) {
|
|
|
351
392
|
const stylesFile = path3.join(tempDir, `styles_expose.ts`);
|
|
352
393
|
fs3.writeFileSync(
|
|
353
394
|
stylesFile,
|
|
354
|
-
`import ${JSON.stringify(
|
|
395
|
+
`import ${JSON.stringify(
|
|
396
|
+
cssAbs.replace(/\\/g, "/")
|
|
397
|
+
)};
|
|
355
398
|
// generated by plugin-mf-auto`,
|
|
356
399
|
"utf8"
|
|
357
400
|
);
|
|
358
401
|
const relFromRoot = path3.relative(root, stylesFile).replace(/\\/g, "/");
|
|
359
|
-
mfMerged.exposes = {
|
|
402
|
+
mfMerged.exposes = {
|
|
403
|
+
...mfMerged.exposes ?? {},
|
|
404
|
+
[stylesExposeKey]: `./${relFromRoot}`
|
|
405
|
+
};
|
|
360
406
|
}
|
|
361
407
|
}
|
|
362
408
|
const command = api?.context?.command;
|
|
@@ -369,7 +415,8 @@ function pluginCore(opts) {
|
|
|
369
415
|
root,
|
|
370
416
|
baseTsconfigPath,
|
|
371
417
|
typesFolder,
|
|
372
|
-
remoteAliases
|
|
418
|
+
remoteAliases,
|
|
419
|
+
baseDir
|
|
373
420
|
});
|
|
374
421
|
const overrideTsCfg = process.env.MF_DTS_TSCONFIG;
|
|
375
422
|
const tsconfigForDtsRel = (overrideTsCfg ? overrideTsCfg : path3.relative(root, tsconfigForDtsAbs)).replace(/\\/g, "/");
|
|
@@ -431,7 +478,9 @@ function pluginCore(opts) {
|
|
|
431
478
|
});
|
|
432
479
|
if (separateExposes && mfMerged.exposes) {
|
|
433
480
|
const force = {};
|
|
434
|
-
for (const [key, rel] of Object.entries(
|
|
481
|
+
for (const [key, rel] of Object.entries(
|
|
482
|
+
mfMerged.exposes
|
|
483
|
+
)) {
|
|
435
484
|
const abs = path3.resolve(root, String(rel).replace(/^\.\//, "")).replace(/\\/g, "/");
|
|
436
485
|
const safe = separateExposeChunkPrefix + key.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
437
486
|
force[safe] = new RegExp(`${escapeRegExp(abs)}$`);
|