ptech-preset 1.3.5 → 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 +70 -22
- 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,14 +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
367
|
const getExposes = async () => {
|
|
342
|
-
if (exposesMode === "jsdoc")
|
|
343
|
-
|
|
368
|
+
if (exposesMode === "jsdoc")
|
|
369
|
+
return collectAutoExposes({ baseDir, globs });
|
|
370
|
+
if (exposesMode === "wrapper")
|
|
371
|
+
return collectAutoExposesWithWrapper({ baseDir, globs });
|
|
344
372
|
const a = await collectAutoExposes({ baseDir, globs });
|
|
345
373
|
const b = await collectAutoExposesWithWrapper({ baseDir, globs });
|
|
346
374
|
return { ...a, ...b };
|
|
@@ -382,9 +410,9 @@ function pluginCore(opts) {
|
|
|
382
410
|
if (isDev && mfMerged.shared && typeof mfMerged.shared === "object") {
|
|
383
411
|
for (const key of Object.keys(mfMerged.shared)) {
|
|
384
412
|
const conf = mfMerged.shared[key];
|
|
385
|
-
if (conf
|
|
386
|
-
|
|
387
|
-
|
|
413
|
+
if (!conf || typeof conf !== "object") continue;
|
|
414
|
+
if (/^react(-dom)?$/.test(key)) continue;
|
|
415
|
+
if ("eager" in conf) conf.eager = false;
|
|
388
416
|
}
|
|
389
417
|
}
|
|
390
418
|
if (cssInjection !== "none") {
|
|
@@ -394,9 +422,14 @@ function pluginCore(opts) {
|
|
|
394
422
|
fs3.mkdirSync(tempDir, { recursive: true });
|
|
395
423
|
if (cssInjection === "wrapper" && mfMerged.exposes) {
|
|
396
424
|
const wrapped = {};
|
|
397
|
-
for (const [key, rel] of Object.entries(
|
|
425
|
+
for (const [key, rel] of Object.entries(
|
|
426
|
+
mfMerged.exposes
|
|
427
|
+
)) {
|
|
398
428
|
const targetAbs = path3.resolve(root, String(rel).replace(/^\.\//, "")).replace(/\\/g, "/");
|
|
399
|
-
const proxyFile = path3.join(
|
|
429
|
+
const proxyFile = path3.join(
|
|
430
|
+
tempDir,
|
|
431
|
+
`expose_${key.replace(/[./]/g, "_")}.ts`
|
|
432
|
+
);
|
|
400
433
|
const lines = [];
|
|
401
434
|
if (hasCss) {
|
|
402
435
|
const cssRel = path3.relative(path3.dirname(proxyFile), cssAbs).replace(/\\/g, "/");
|
|
@@ -432,7 +465,10 @@ if (import.meta && (import.meta as any).webpackHot) {(import.meta as any).webpac
|
|
|
432
465
|
"utf8"
|
|
433
466
|
);
|
|
434
467
|
const relFromRoot = path3.relative(root, stylesFile).replace(/\\/g, "/");
|
|
435
|
-
mfMerged.exposes = {
|
|
468
|
+
mfMerged.exposes = {
|
|
469
|
+
...mfMerged.exposes ?? {},
|
|
470
|
+
[stylesExposeKey]: `./${relFromRoot}`
|
|
471
|
+
};
|
|
436
472
|
}
|
|
437
473
|
}
|
|
438
474
|
const autoTypeUrls = buildRemoteTypeUrls(mfMerged.remotes || {});
|
|
@@ -453,15 +489,25 @@ if (import.meta && (import.meta as any).webpackHot) {(import.meta as any).webpac
|
|
|
453
489
|
const refresh = process.env[devTypesRefreshEnvVar] === "1";
|
|
454
490
|
const typesRootAbs = path3.resolve(root, typesFolder);
|
|
455
491
|
const indexFile = path3.join(typesRootAbs, "index.d.ts");
|
|
456
|
-
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
|
+
);
|
|
457
495
|
if (remoteAliases.length > 0 && needFetch) {
|
|
458
|
-
await devFetchRemoteTypesOnce({
|
|
496
|
+
await devFetchRemoteTypesOnce({
|
|
497
|
+
root,
|
|
498
|
+
baseDir,
|
|
499
|
+
typesFolderRel: typesFolder,
|
|
500
|
+
urls: autoTypeUrls
|
|
501
|
+
});
|
|
459
502
|
}
|
|
460
503
|
}
|
|
461
504
|
const dtsGenMaybe = ensureDtsObject(mfMerged.dts);
|
|
462
505
|
if (dtsGenMaybe !== false) {
|
|
463
506
|
const dtsGen = dtsGenMaybe;
|
|
464
|
-
dtsGen.generateTypes = {
|
|
507
|
+
dtsGen.generateTypes = {
|
|
508
|
+
...dtsGen.generateTypes ?? {},
|
|
509
|
+
tsConfigPath: tsconfigForDtsToUse
|
|
510
|
+
};
|
|
465
511
|
if (isBuild && remoteAliases.length > 0) {
|
|
466
512
|
const existingConsume = dtsGen.consumeTypes ?? {};
|
|
467
513
|
const existingRt = existingConsume.remoteTypeUrls ?? {};
|
|
@@ -492,7 +538,9 @@ if (import.meta && (import.meta as any).webpackHot) {(import.meta as any).webpac
|
|
|
492
538
|
});
|
|
493
539
|
if (separateExposes && mfMerged.exposes) {
|
|
494
540
|
const force = {};
|
|
495
|
-
for (const [key, rel] of Object.entries(
|
|
541
|
+
for (const [key, rel] of Object.entries(
|
|
542
|
+
mfMerged.exposes
|
|
543
|
+
)) {
|
|
496
544
|
const abs = path3.resolve(root, String(rel).replace(/^\.\//, "")).replace(/\\/g, "/");
|
|
497
545
|
const safe = separateExposeChunkPrefix + key.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
498
546
|
force[safe] = new RegExp(`${escapeRegExp(abs)}(\\?.*)?$`);
|