vitral 0.10.0 → 0.10.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/{chunk-5OM6KOCP.js → chunk-SOENZNXO.js} +52 -9
- package/dist/next-config.d.ts +2 -0
- package/dist/next-config.js +6 -3
- package/dist/next-host.js +13 -1
- package/dist/next.d.ts +1 -1
- package/dist/vite.js +1 -1
- package/dist/vue.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/vite/dedupe.ts
|
|
2
|
+
import { execFileSync } from "child_process";
|
|
2
3
|
import { existsSync, readFileSync, realpathSync } from "fs";
|
|
3
4
|
import { dirname, join, resolve } from "path";
|
|
4
5
|
import { pathToFileURL } from "url";
|
|
@@ -143,6 +144,7 @@ async function groups(list, root, entry, resolveId) {
|
|
|
143
144
|
byName.set(g, [.../* @__PURE__ */ new Set([...byName.get(g) ?? [], ...g === "react" ? REACT : [spec.endsWith("/*") ? g : spec]])]);
|
|
144
145
|
}
|
|
145
146
|
const out = [];
|
|
147
|
+
const files = [];
|
|
146
148
|
for (const [name, list2] of byName) {
|
|
147
149
|
const group = { name, range: "", version: "", keys: [], names: {}, pkgs: name === "react" ? ["react", "react-dom", "scheduler"] : [name] };
|
|
148
150
|
let specs = list2;
|
|
@@ -162,19 +164,55 @@ async function groups(list, root, entry, resolveId) {
|
|
|
162
164
|
specs = [.../* @__PURE__ */ new Set([...specs, ...subpaths(name, pkg.data)])];
|
|
163
165
|
}
|
|
164
166
|
}
|
|
165
|
-
|
|
166
|
-
const mod = await import(pathToFileURL(found.id.split("?")[0]).href);
|
|
167
|
-
const extra = mod.default && (typeof mod.default === "object" || typeof mod.default === "function") ? Object.keys(mod.default) : [];
|
|
168
|
-
group.names[spec] = [.../* @__PURE__ */ new Set([...Object.keys(mod), ...extra])].filter((n) => n !== "default" && ident.test(n));
|
|
169
|
-
} catch {
|
|
170
|
-
}
|
|
167
|
+
files.push([group, spec, found.id.split("?")[0]]);
|
|
171
168
|
group.keys.push(spec);
|
|
172
169
|
}
|
|
173
170
|
group.range = name === "svelte" || name.startsWith("@angular/") ? group.version : `^${group.version}`;
|
|
174
171
|
out.push(group);
|
|
175
172
|
}
|
|
173
|
+
const names = exportNames(files.map(([, , f]) => f));
|
|
174
|
+
files.forEach(([g, spec], i) => names[i] && (g.names[spec] = names[i]));
|
|
176
175
|
return out;
|
|
177
176
|
}
|
|
177
|
+
var MARK = "@@vitral-names@@";
|
|
178
|
+
function isCommonJs(file) {
|
|
179
|
+
if (/\.cjs$/.test(file)) return true;
|
|
180
|
+
if (!/\.js$/.test(file)) return false;
|
|
181
|
+
for (let dir = dirname(file); dir !== dirname(dir); dir = dirname(dir)) {
|
|
182
|
+
const json = join(dir, "package.json");
|
|
183
|
+
if (existsSync(json)) {
|
|
184
|
+
try {
|
|
185
|
+
return JSON.parse(readFileSync(json, "utf8")).type !== "module";
|
|
186
|
+
} catch {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
function exportNames(files) {
|
|
194
|
+
if (!files.length) return [];
|
|
195
|
+
const code = `const out = []
|
|
196
|
+
for (const [f, cjs] of JSON.parse(process.argv[1])) {
|
|
197
|
+
try {
|
|
198
|
+
const mod = await import(f)
|
|
199
|
+
// CommonJS: os nomes ficam no module.exports, que pode ser uma fun\xE7\xE3o (o axios \xE9).
|
|
200
|
+
const obj = mod.default && (typeof mod.default === "object" || typeof mod.default === "function") ? mod.default : undefined
|
|
201
|
+
const all = cjs ? Object.keys(obj ?? {}) : [...new Set([...Object.keys(mod), ...Object.keys(obj ?? {})])]
|
|
202
|
+
out.push(all.filter((n) => n !== "default" && ${ident}.test(n)))
|
|
203
|
+
} catch {
|
|
204
|
+
out.push(null)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
process.stdout.write("\\n${MARK}" + JSON.stringify(out))`;
|
|
208
|
+
const env = { ...process.env, NODE_ENV: process.env.NODE_ENV === "development" ? "development" : "production" };
|
|
209
|
+
try {
|
|
210
|
+
const out = execFileSync(process.execPath, ["--input-type=module", "-e", code, JSON.stringify(files.map((f) => [pathToFileURL(f).href, isCommonJs(f)]))], { env, encoding: "utf8", maxBuffer: 64 << 20, stdio: ["ignore", "pipe", "ignore"] });
|
|
211
|
+
return JSON.parse(out.slice(out.lastIndexOf(MARK) + MARK.length));
|
|
212
|
+
} catch {
|
|
213
|
+
return files.map(() => null);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
178
216
|
var escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\0/g, "\\x00");
|
|
179
217
|
function dedupeIds(list) {
|
|
180
218
|
const specs = new Set(list.flatMap((s) => groupOf(s) === "react" ? REACT : [s.replace(/\/\*$/, "")]));
|
|
@@ -311,9 +349,14 @@ async function need(name, range, version, keys, load) {
|
|
|
311
349
|
let m = shared && (await p.dedupe(name, range, { version, load }))
|
|
312
350
|
// A oferta pode ter s\xF3 os nomes que o remote usa (host Next): confere cada um.
|
|
313
351
|
const has = (o, n) => n === "default" || (o != null && (n in o || (o.default != null && n in Object(o.default))))
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
352
|
+
const lacks = m ? keys.filter((k) => !(k in m)) : []
|
|
353
|
+
const names = m ? keys.flatMap((k) => (k in m ? (uses[name]?.[k] || []).filter((n) => !has(m[k], n)).map((n) => k + " " + n) : [])) : []
|
|
354
|
+
// React e React DOM nunca t\xEAm duas c\xF3pias na p\xE1gina (hooks e contexto
|
|
355
|
+
// quebram): um nome que falta s\xF3 gera aviso, e o remote fica com a oferta.
|
|
356
|
+
const keep = name === "react" && !lacks.length
|
|
357
|
+
if (lacks.length || names.length)
|
|
358
|
+
console.warn("[vitral] dedupe: a oferta de " + name + " n\xE3o tem " + [...lacks, ...names].join(", ") + (keep ? "; o remote usa a oferta do host mesmo assim" : "; o remote usa a c\xF3pia pr\xF3pria inteira"))
|
|
359
|
+
if (!m || ((lacks.length || names.length) && !keep)) m = await load()
|
|
317
360
|
Object.assign(deps, m)
|
|
318
361
|
}
|
|
319
362
|
await Promise.all([${calls.join(", ")}])
|
package/dist/next-config.d.ts
CHANGED
|
@@ -104,6 +104,8 @@ interface HtmlHints {
|
|
|
104
104
|
manifest: string;
|
|
105
105
|
css: [string, string?][];
|
|
106
106
|
js: [string, string?][];
|
|
107
|
+
/** Grupos de `share` que o remote vai pedir: o host começa o download deles antes da hidratação. */
|
|
108
|
+
offers?: string[];
|
|
107
109
|
}
|
|
108
110
|
/**
|
|
109
111
|
* Lê o `vitral.json` no build e lista o que a primeira tela do remote baixa: o
|
package/dist/next-config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
subpaths
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SOENZNXO.js";
|
|
4
4
|
import {
|
|
5
5
|
satisfies
|
|
6
6
|
} from "./chunk-4E33RZMM.js";
|
|
@@ -81,11 +81,14 @@ function htmlHints(dir, r, offered) {
|
|
|
81
81
|
return u.origin === "http://host.invalid" ? u.pathname + u.search : u.href;
|
|
82
82
|
};
|
|
83
83
|
const hint = (f) => r.integrity !== false && m.files?.[f] ? [at(f), m.files[f]] : [at(f)];
|
|
84
|
-
const
|
|
84
|
+
const served = (d) => !!offered[d.name] && satisfies(offered[d.name], d.range);
|
|
85
|
+
const own = (m.dedupe ?? []).filter((d) => !served(d)).flatMap((d) => [...d.chunks ?? [], d.file]);
|
|
86
|
+
const offers = m.split ? (m.dedupe ?? []).filter((d) => d.name !== "react" && served(d)).map((d) => d.name) : [];
|
|
85
87
|
return {
|
|
86
88
|
manifest: at(r.url),
|
|
87
89
|
css: (m.css ?? []).map(hint),
|
|
88
|
-
js: (m.split ? [...own, ...m.split.chunks ?? [], m.split.entry] : [m.entry]).map(hint)
|
|
90
|
+
js: (m.split ? [...own, ...m.split.chunks ?? [], m.split.entry] : [m.entry]).map(hint),
|
|
91
|
+
...offers.length && { offers }
|
|
89
92
|
};
|
|
90
93
|
}
|
|
91
94
|
function readManifest(dir, r) {
|
package/dist/next-host.js
CHANGED
|
@@ -36,6 +36,18 @@ var under = (path, prefix) => path === prefix || path.startsWith(prefix + "/");
|
|
|
36
36
|
function remoteFor(path) {
|
|
37
37
|
for (const [name, r] of Object.entries(remotes)) if (under(path, r.basePath) || r.routes?.some((x) => under(path, x.public))) return name;
|
|
38
38
|
}
|
|
39
|
+
var offers = Object.fromEntries(
|
|
40
|
+
Object.entries(shared).map(([k, g]) => {
|
|
41
|
+
let p;
|
|
42
|
+
return [k, typeof g.modules === "function" ? { ...g, modules: () => p ??= g.modules().catch((e) => (p = void 0, Promise.reject(e))) } : g];
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
function warmOffers(path) {
|
|
46
|
+
const name = remoteFor(path);
|
|
47
|
+
for (const g of name && remotes[name].hints?.offers || []) offers[g]?.modules().catch(() => {
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (typeof window !== "undefined") warmOffers(location.pathname);
|
|
39
51
|
var configured = false;
|
|
40
52
|
function setup() {
|
|
41
53
|
if (configured || typeof window === "undefined") return;
|
|
@@ -44,7 +56,7 @@ function setup() {
|
|
|
44
56
|
bundled.dedupe = dedupe_exports;
|
|
45
57
|
configure({
|
|
46
58
|
remotes: Object.fromEntries(Object.entries(remotes).map(([name, r]) => [name, { url: r.url, ...r.integrity === false && { integrity: false } }])),
|
|
47
|
-
dedupe:
|
|
59
|
+
dedupe: offers
|
|
48
60
|
});
|
|
49
61
|
}
|
|
50
62
|
function interceptNavigation() {
|
package/dist/next.d.ts
CHANGED
|
@@ -118,7 +118,7 @@ type ImageProps = Omit<ImgHTMLAttributes<HTMLImageElement>, 'src' | 'width' | 'h
|
|
|
118
118
|
}) => string;
|
|
119
119
|
onLoadingComplete?: (img: HTMLImageElement) => void;
|
|
120
120
|
};
|
|
121
|
-
declare const Image: react.ForwardRefExoticComponent<Omit<ImgHTMLAttributes<HTMLImageElement>, "
|
|
121
|
+
declare const Image: react.ForwardRefExoticComponent<Omit<ImgHTMLAttributes<HTMLImageElement>, "loading" | "src" | "width" | "height"> & {
|
|
122
122
|
src: string | StaticImage;
|
|
123
123
|
alt: string;
|
|
124
124
|
width?: number | string;
|
package/dist/vite.js
CHANGED
package/dist/vue.d.ts
CHANGED
|
@@ -127,8 +127,8 @@ declare const VitralRemote: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
127
127
|
onError?: ((...args: any[]) => any) | undefined;
|
|
128
128
|
onReady?: ((...args: any[]) => any) | undefined;
|
|
129
129
|
}>, {
|
|
130
|
-
name: string;
|
|
131
130
|
isolate: Isolation;
|
|
131
|
+
name: string;
|
|
132
132
|
priority: RequestPriority;
|
|
133
133
|
loading: Loading;
|
|
134
134
|
src: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitral",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Micro-frontends de qualquer framework numa página só, sem configuração de build no host. React, Next, Vue, Nuxt, Angular, Svelte, Solid, Preact, Lit e JS puro.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"micro-frontend",
|