ptech-preset 1.2.4 → 1.2.5
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 +88 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -85,10 +85,12 @@ import path2 from "path";
|
|
|
85
85
|
async function collectAutoRemotes(opts = {}) {
|
|
86
86
|
const remotes = {};
|
|
87
87
|
const prefix = opts.envPrefix ?? "REMOTE_";
|
|
88
|
-
for (const [k,
|
|
89
|
-
if (!
|
|
88
|
+
for (const [k, vRaw] of Object.entries(process.env)) {
|
|
89
|
+
if (!vRaw) continue;
|
|
90
90
|
if (k.startsWith(prefix)) {
|
|
91
91
|
const scope = k.slice(prefix.length).toLowerCase();
|
|
92
|
+
const v = String(vRaw).trim();
|
|
93
|
+
if (!v) continue;
|
|
92
94
|
remotes[scope] = `${scope}@${v}`;
|
|
93
95
|
}
|
|
94
96
|
}
|
|
@@ -115,9 +117,13 @@ async function collectAutoRemotes(opts = {}) {
|
|
|
115
117
|
console.warn(`[mf-auto] read manifest error:`, e);
|
|
116
118
|
}
|
|
117
119
|
}
|
|
118
|
-
for (const [
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
for (const [scopeRaw, urlRaw] of Object.entries(obj)) {
|
|
121
|
+
const scope = String(scopeRaw).toLowerCase();
|
|
122
|
+
const url = String(urlRaw || "").trim();
|
|
123
|
+
if (url) {
|
|
124
|
+
if (!remotes[scope]) {
|
|
125
|
+
remotes[scope] = `${scope}@${url}`;
|
|
126
|
+
}
|
|
121
127
|
}
|
|
122
128
|
}
|
|
123
129
|
}
|
|
@@ -154,6 +160,54 @@ var DEFAULT_SHARED = {
|
|
|
154
160
|
"@azure/msal-browser": { singleton: true, eager: true, requiredVersion: false }
|
|
155
161
|
};
|
|
156
162
|
var CDN_BASE = "https://oneportal.blob.core.windows.net/external/ts/";
|
|
163
|
+
function parseRemoteSpec(key, val) {
|
|
164
|
+
if (typeof val !== "string") return null;
|
|
165
|
+
const m = val.match(/^([^@]+)@(.+)$/);
|
|
166
|
+
if (m) return { scope: m[1], url: m[2] };
|
|
167
|
+
return { scope: key, url: val };
|
|
168
|
+
}
|
|
169
|
+
function inferTypeUrls(remoteUrl) {
|
|
170
|
+
if (typeof remoteUrl !== "string") return null;
|
|
171
|
+
const base = remoteUrl.replace(/\/remoteEntry(\.[cm]?js)?(\?.*)?$/i, "");
|
|
172
|
+
if (!base || base === remoteUrl) {
|
|
173
|
+
const idx = remoteUrl.lastIndexOf("/");
|
|
174
|
+
const fallbackBase = idx > 7 ? remoteUrl.slice(0, idx) : remoteUrl;
|
|
175
|
+
return {
|
|
176
|
+
base: fallbackBase,
|
|
177
|
+
zip: `${fallbackBase}/@mf-types.zip`,
|
|
178
|
+
api: `${fallbackBase}/@mf-types.d.ts`
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
base,
|
|
183
|
+
zip: `${base}/@mf-types.zip`,
|
|
184
|
+
api: `${base}/@mf-types.d.ts`
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function buildRemoteTypeUrls(remotes) {
|
|
188
|
+
const out = {};
|
|
189
|
+
if (!remotes || typeof remotes !== "object") return out;
|
|
190
|
+
for (const [key, val] of Object.entries(remotes)) {
|
|
191
|
+
if (typeof val !== "string") continue;
|
|
192
|
+
const parsed = parseRemoteSpec(key, val);
|
|
193
|
+
if (!parsed) continue;
|
|
194
|
+
const t = inferTypeUrls(parsed.url);
|
|
195
|
+
if (!t) continue;
|
|
196
|
+
const scope = (parsed.scope || key).toString();
|
|
197
|
+
out[scope] = {
|
|
198
|
+
alias: scope,
|
|
199
|
+
zip: t.zip,
|
|
200
|
+
api: t.api
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
return out;
|
|
204
|
+
}
|
|
205
|
+
function ensureDtsObject(dts) {
|
|
206
|
+
if (dts === false) return false;
|
|
207
|
+
if (dts == null || dts === true) return {};
|
|
208
|
+
if (typeof dts === "object") return { ...dts };
|
|
209
|
+
return {};
|
|
210
|
+
}
|
|
157
211
|
function pluginCore(opts) {
|
|
158
212
|
const {
|
|
159
213
|
baseDir = "src",
|
|
@@ -249,9 +303,35 @@ function pluginCore(opts) {
|
|
|
249
303
|
mfMerged.exposes = { ...mfMerged.exposes ?? {}, [stylesExposeKey]: `./${relFromRoot}` };
|
|
250
304
|
}
|
|
251
305
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
306
|
+
if (mfMerged.remotes && Object.keys(mfMerged.remotes).length > 0) {
|
|
307
|
+
if (mfMerged.dts !== false) {
|
|
308
|
+
const dtsObj = ensureDtsObject(mfMerged.dts);
|
|
309
|
+
const autoTypeUrls = buildRemoteTypeUrls(mfMerged.remotes);
|
|
310
|
+
if (Object.keys(autoTypeUrls).length > 0) {
|
|
311
|
+
const existingConsume = dtsObj.consumeTypes ?? {};
|
|
312
|
+
const existingRt = existingConsume.remoteTypeUrls ?? {};
|
|
313
|
+
dtsObj.consumeTypes = {
|
|
314
|
+
typesFolder: existingConsume.typesFolder ?? "@mf-types",
|
|
315
|
+
maxRetries: existingConsume.maxRetries ?? 3,
|
|
316
|
+
remoteTypeUrls: { ...autoTypeUrls, ...existingRt }
|
|
317
|
+
// existing wins? or auto wins?
|
|
318
|
+
// Nếu muốn "khóa" theo existing ưu tiên, đảo thứ tự:
|
|
319
|
+
// remoteTypeUrls: { ...autoTypeUrls, ...existingRt },
|
|
320
|
+
};
|
|
321
|
+
dtsObj.generateTypes = dtsObj.generateTypes ?? { tsConfigPath: "./tsconfig.json" };
|
|
322
|
+
}
|
|
323
|
+
mfMerged.dts = dtsObj;
|
|
324
|
+
}
|
|
325
|
+
} else {
|
|
326
|
+
const isBuild = api?.context?.command === "build" || process.env.NODE_ENV === "production";
|
|
327
|
+
if (typeof mfMerged.dts === "undefined") {
|
|
328
|
+
mfMerged.dts = isBuild ? {} : {};
|
|
329
|
+
}
|
|
330
|
+
if (mfMerged.dts !== false) {
|
|
331
|
+
const dtsObj = ensureDtsObject(mfMerged.dts);
|
|
332
|
+
dtsObj.generateTypes = dtsObj.generateTypes ?? { tsConfigPath: "./tsconfig.json" };
|
|
333
|
+
mfMerged.dts = dtsObj;
|
|
334
|
+
}
|
|
255
335
|
}
|
|
256
336
|
const mfPlugin = pluginModuleFederation(mfMerged);
|
|
257
337
|
await mfPlugin.setup?.(api);
|