vitral 0.7.2 → 0.8.0

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.
Files changed (59) hide show
  1. package/README.md +2 -0
  2. package/dist/angular.d.ts +2 -2
  3. package/dist/angular.js +8 -6
  4. package/dist/auto.js +5 -4
  5. package/dist/chunk-4IWZIFAL.js +165 -0
  6. package/dist/chunk-6AFVJCQG.js +311 -0
  7. package/dist/{chunk-72H4FXMD.js → chunk-6T25WKNK.js} +44 -13
  8. package/dist/chunk-EQZOJU3B.js +48 -0
  9. package/dist/{chunk-O7DV3EVB.js → chunk-NTXMEZIZ.js} +9 -46
  10. package/dist/{chunk-4NSPG6NK.js → chunk-PQXS2UDM.js} +1 -1
  11. package/dist/{chunk-TXSHK3SK.js → chunk-ZJ4IM2PZ.js} +2 -2
  12. package/dist/{chunk-V24ZNHUF.js → chunk-ZRAGLT3I.js} +4 -4
  13. package/dist/cli.js +1 -1
  14. package/dist/{contract-46EZFQPQ.js → contract-OMHCH6LI.js} +1 -1
  15. package/dist/{dedupe-S7BHQMOZ.js → dedupe-PZCSKL3L.js} +1 -1
  16. package/dist/edge.d.ts +1 -1
  17. package/dist/element.d.ts +2 -2
  18. package/dist/element.js +5 -4
  19. package/dist/embed.js +2 -2
  20. package/dist/{events-DLdbFqBM.d.ts → events-Cieg_far.d.ts} +1 -1
  21. package/dist/{expose-ZLYQZUP2.js → expose-V5ASGX4E.js} +2 -2
  22. package/dist/federation.d.ts +1 -1
  23. package/dist/{hydrate-NFZZMYWT.js → hydrate-6NE4MYOD.js} +7 -5
  24. package/dist/iframe.js +9 -7
  25. package/dist/index.d.ts +6 -19
  26. package/dist/index.js +6 -4
  27. package/dist/loader-BIXjuvvp.d.ts +25 -0
  28. package/dist/next-config.d.ts +95 -0
  29. package/dist/next-config.js +149 -0
  30. package/dist/next-host.d.ts +26 -0
  31. package/dist/next-host.js +92 -0
  32. package/dist/next.d.ts +190 -0
  33. package/dist/next.js +287 -0
  34. package/dist/preact.d.ts +4 -4
  35. package/dist/preact.js +7 -5
  36. package/dist/prefetch.js +2 -2
  37. package/dist/react-server.d.ts +1 -1
  38. package/dist/react.d.ts +11 -4
  39. package/dist/react.js +17 -144
  40. package/dist/{reframe-7K5S6JC6.js → reframe-3ZN5CHEG.js} +4 -4
  41. package/dist/routes.d.ts +2 -2
  42. package/dist/routes.js +6 -4
  43. package/dist/single-spa.d.ts +1 -1
  44. package/dist/{slot-Ddzp7AgL.d.ts → slot-Dhczjs1E.d.ts} +1 -1
  45. package/dist/solid.d.ts +3 -3
  46. package/dist/solid.js +7 -5
  47. package/dist/{sri-576GTDIA.js → sri-TBZ6PYYY.js} +39 -24
  48. package/dist/svelte.d.ts +4 -4
  49. package/dist/svelte.js +6 -4
  50. package/dist/sw.d.ts +8 -0
  51. package/dist/sw.js +21 -0
  52. package/dist/testing.d.ts +1 -1
  53. package/dist/testing.js +3 -2
  54. package/dist/{types-EOz1rOHs.d.ts → types-wsKR1gfx.d.ts} +19 -3
  55. package/dist/vite.d.ts +33 -1
  56. package/dist/vite.js +353 -158
  57. package/dist/vue.d.ts +3 -3
  58. package/dist/vue.js +6 -4
  59. package/package.json +28 -12
@@ -45,14 +45,14 @@ var mapped = /* @__PURE__ */ new Set();
45
45
  var probing;
46
46
  var preloads;
47
47
  var KEY = "vitral:sri-map";
48
- async function useMap(sri) {
48
+ async function useMap(sri, own) {
49
49
  if (probing) return await probing && addMap(sri, false);
50
50
  let seen = false;
51
51
  try {
52
52
  seen = localStorage[KEY] === navigator.userAgent;
53
53
  } catch {
54
54
  }
55
- const ok = await (probing = addMap(sri, !seen));
55
+ const ok = await (probing = addMap(sri, !seen, own));
56
56
  if (ok && !seen)
57
57
  try {
58
58
  localStorage[KEY] = navigator.userAgent;
@@ -72,7 +72,7 @@ async function verified(build, run) {
72
72
  const p = globalThis[/* @__PURE__ */ Symbol.for("vitral")];
73
73
  const share = async (pre) => {
74
74
  if (!run || !dedupe.length) return;
75
- const { shared } = await import("./dedupe-S7BHQMOZ.js");
75
+ const { shared } = await import("./dedupe-PZCSKL3L.js");
76
76
  for (const d of dedupe)
77
77
  shared(p)(d.name, d.range, {
78
78
  version: d.version,
@@ -83,47 +83,60 @@ async function verified(build, run) {
83
83
  }
84
84
  });
85
85
  };
86
- if (maps !== false && (maps = await useMap(sri))) {
86
+ const probes = build.probe?.every((u) => u.startsWith("data:") || new URL(u, location.href).origin === location.origin) ? build.probe : void 0;
87
+ if (maps !== false && (maps = await useMap(sri, probes))) {
87
88
  await share();
88
89
  for (const u of chunks) fetch(u, { priority }).catch(() => {
89
90
  });
90
91
  return entry;
91
92
  }
92
- if (await (preloads ??= checkPreloads())) {
93
+ if (await (preloads ??= checkPreloads(probes))) {
93
94
  p.sri = { ...p.sri, ...sri };
94
95
  await share(true);
95
96
  await Promise.all([...chunks, entry].map((u) => preload(u, sri[u], priority)));
96
97
  return entry;
97
98
  }
98
99
  }
99
- async function addMap(sri, probe) {
100
+ async function addMap(sri, probe, own) {
100
101
  if (!HTMLScriptElement.supports?.("importmap")) return false;
101
102
  const integrity = {};
102
103
  for (const u in sri) if (!/\.css([?#]|$)/.test(u) && !mapped.has(u)) mapped.add(u), integrity[u] = sri[u];
103
104
  const urls = probe ? ["export{}", "export{}//"].map((c) => URL.createObjectURL(new Blob([c], { type: "text/javascript" }))) : [];
104
105
  for (const u of urls) integrity[u] = PROBE_SRI;
105
106
  let ok = true;
107
+ const fail = () => ok = false;
108
+ const load = (u) => import(
109
+ /* @vite-ignore */
110
+ /* webpackIgnore: true */
111
+ u
112
+ );
106
113
  try {
107
- const s = document.createElement("script");
108
- s.type = "importmap";
109
- s.nonce = document.querySelector("script[nonce]")?.nonce ?? "";
110
- s.onerror = () => ok = false;
111
- s.addEventListener("securitypolicyviolation", () => ok = false);
112
- s.textContent = JSON.stringify({ integrity });
113
- document.head.append(s);
114
- await tick();
115
- await tick();
116
- if (ok && probe) ok = await check((u) => import(
117
- /* @vite-ignore */
118
- /* webpackIgnore: true */
119
- u
120
- ), urls[0], urls[1]);
114
+ await map(integrity, fail);
115
+ if (ok && probe) {
116
+ let r = await check(load, urls[0], urls[1]);
117
+ if (r === void 0 && own) {
118
+ await map({ [own[0]]: PROBE_SRI, [own[1]]: PROBE_SRI }, fail);
119
+ r = ok && await check(load, own[0], own[1]);
120
+ }
121
+ ok = !!r;
122
+ }
121
123
  } catch {
122
124
  ok = false;
123
125
  }
124
126
  for (const u of urls) URL.revokeObjectURL(u);
125
127
  return ok;
126
128
  }
129
+ async function map(integrity, fail) {
130
+ const s = document.createElement("script");
131
+ s.type = "importmap";
132
+ s.nonce = document.querySelector("script[nonce]")?.nonce ?? "";
133
+ s.onerror = fail;
134
+ s.addEventListener("securitypolicyviolation", fail);
135
+ s.textContent = JSON.stringify({ integrity });
136
+ document.head.append(s);
137
+ await tick();
138
+ await tick();
139
+ }
127
140
  function preload(href, integrity, fetchPriority = "auto") {
128
141
  return new Promise((resolve, reject) => {
129
142
  const link = addLink("modulepreload", href, { integrity, fetchPriority });
@@ -131,13 +144,15 @@ function preload(href, integrity, fetchPriority = "auto") {
131
144
  link.onerror = reject;
132
145
  });
133
146
  }
134
- function checkPreloads() {
135
- if (!document.createElement("link").relList.supports("modulepreload")) return Promise.resolve(false);
136
- return check((href) => preload(href, PROBE_SRI), PROBE, PROBE + "//");
147
+ async function checkPreloads(own) {
148
+ if (!document.createElement("link").relList.supports("modulepreload")) return false;
149
+ const load = (href) => preload(href, PROBE_SRI);
150
+ const r = await check(load, PROBE, PROBE + "//");
151
+ return !!(r === void 0 && own ? await check(load, ...own.map((u) => u + (u.includes("?") ? "&" : "?") + "preload")) : r);
137
152
  }
138
153
  function check(load, good, bad) {
139
154
  return Promise.race([
140
- Promise.all([load(good).then(() => true, () => false), load(bad).then(() => false, () => true)]).then(([a, b]) => a && b),
155
+ Promise.all([load(good).then(() => true, () => false), load(bad).then(() => false, () => true)]).then(([a, b]) => a ? b : void 0),
141
156
  new Promise((resolve) => setTimeout(resolve, 3e3, false))
142
157
  ]);
143
158
  }
package/dist/svelte.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Component } from 'svelte';
2
- import { P as Props, I as Isolation, a as RemoteModule } from './types-EOz1rOHs.js';
3
- export { R as RemoteContext } from './types-EOz1rOHs.js';
2
+ import { P as Props, I as Isolation, a as RemoteModule } from './types-wsKR1gfx.js';
3
+ export { R as RemoteContext } from './types-wsKR1gfx.js';
4
4
  import { R as RemoteError } from './errors-kjBv6IH_.js';
5
- import { S as SlotStatus } from './slot-Ddzp7AgL.js';
6
- export { e as events } from './events-DLdbFqBM.js';
5
+ import { S as SlotStatus } from './slot-Dhczjs1E.js';
6
+ export { e as events } from './events-Cieg_far.js';
7
7
  export { n as navigate } from './navigate-BRG1WJUM.js';
8
8
  import { L as Loading, P as Prefetch } from './host-slot-Cz6EiGsB.js';
9
9
 
package/dist/svelte.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import {
2
2
  hostSlot
3
- } from "./chunk-TXSHK3SK.js";
3
+ } from "./chunk-ZJ4IM2PZ.js";
4
+ import {
5
+ defineRemote
6
+ } from "./chunk-NTXMEZIZ.js";
4
7
  import {
5
- defineRemote,
6
8
  events,
7
9
  navigate
8
- } from "./chunk-O7DV3EVB.js";
9
- import "./chunk-72H4FXMD.js";
10
+ } from "./chunk-EQZOJU3B.js";
11
+ import "./chunk-6T25WKNK.js";
10
12
  import "./chunk-KU6HF2EW.js";
11
13
  import "./chunk-TW7KYJQ6.js";
12
14
  import "./chunk-463H6B56.js";
package/dist/sw.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * URLs absolutas do manifesto e de tudo que ele lista: arquivo único, CSS,
3
+ * build dividido (inclusive os `import()` das rotas), cópias de `dedupe` e os
4
+ * módulos de teste do SRI.
5
+ */
6
+ declare function remoteFiles(manifestUrl: string, init?: RequestInit): Promise<string[]>;
7
+
8
+ export { remoteFiles };
package/dist/sw.js ADDED
@@ -0,0 +1,21 @@
1
+ // src/sw.ts
2
+ async function remoteFiles(manifestUrl, init) {
3
+ const base = new URL(manifestUrl, globalThis.location?.href);
4
+ const res = await fetch(base, { cache: "no-cache", ...init });
5
+ if (!res.ok) throw new Error(`vitral: ${base.href} respondeu ${res.status}`);
6
+ const m = await res.json();
7
+ const files = [
8
+ m.entry,
9
+ ...m.css ?? [],
10
+ ...m.shadow?.css ?? [],
11
+ ...m.shadow?.global ?? [],
12
+ ...Object.keys(m.files ?? {}),
13
+ ...m.split ? [m.split.entry, ...m.split.chunks ?? []] : [],
14
+ ...(m.dedupe ?? []).flatMap((d) => [d.file, ...d.chunks ?? []]),
15
+ ...m.probe ?? []
16
+ ];
17
+ return [base.href, ...new Set(files.filter(Boolean).map((f) => new URL(f, base).href))];
18
+ }
19
+ export {
20
+ remoteFiles
21
+ };
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { P as Props, R as RemoteContext, a as RemoteModule } from './types-EOz1rOHs.js';
1
+ import { P as Props, R as RemoteContext, a as RemoteModule } from './types-wsKR1gfx.js';
2
2
  export { r as resetVitral } from './state-BDdCwc21.js';
3
3
  import './errors-kjBv6IH_.js';
4
4
 
package/dist/testing.js CHANGED
@@ -4,10 +4,11 @@ import {
4
4
  harness,
5
5
  verify
6
6
  } from "./chunk-DAESKNQ6.js";
7
- import "./chunk-O7DV3EVB.js";
7
+ import "./chunk-NTXMEZIZ.js";
8
+ import "./chunk-EQZOJU3B.js";
8
9
  import {
9
10
  register
10
- } from "./chunk-72H4FXMD.js";
11
+ } from "./chunk-6T25WKNK.js";
11
12
  import "./chunk-KU6HF2EW.js";
12
13
  import "./chunk-TW7KYJQ6.js";
13
14
  import "./chunk-463H6B56.js";
@@ -177,8 +177,13 @@ interface RemoteEntry {
177
177
  module?: RemoteModule<any> | (() => Promise<RemoteModule<any> | {
178
178
  default: RemoteModule<any>;
179
179
  }>);
180
- /** Hash SRI (`sha256-…`, `sha384-…`, `sha512-…`) do JS. Verificado antes de executar. */
181
- integrity?: string;
180
+ /**
181
+ * Hash SRI (`sha256-…`, `sha384-…`, `sha512-…`) do JS. Verificado antes de
182
+ * executar. Sem ele, vale o do manifesto. `false` não confere hash nenhum:
183
+ * para um remote da mesma origem numa página cuja CSP não aceita `data:`
184
+ * nem `blob:` em `script-src`, onde a conferência não tem como rodar.
185
+ */
186
+ integrity?: string | false;
182
187
  /** CSS extra para carregar junto. */
183
188
  css?: string[];
184
189
  /** Isolamento padrão para este remote. */
@@ -328,10 +333,13 @@ interface VitralConfig {
328
333
  * Dependências que o host oferece aos remotes com `dedupe`, por grupo:
329
334
  * `{ vue: { version: Vue.version, modules: { vue: Vue } } }`. O remote usa
330
335
  * a do host se a versão estiver na faixa dele; senão, a própria cópia.
336
+ * `modules` pode ser uma função que carrega os módulos só quando algum
337
+ * remote pede (`() => import('vue').then((vue) => ({ vue }))`): o host não
338
+ * paga por eles no bundle inicial.
331
339
  */
332
340
  dedupe?: Record<string, {
333
341
  version: string;
334
- modules: SharedModules;
342
+ modules: SharedModules | (() => Promise<SharedModules>);
335
343
  }>;
336
344
  /**
337
345
  * Faixa de versão do contrato que o host aceita dos remotes (ex.: `'^2'`).
@@ -394,7 +402,15 @@ interface RemoteManifest {
394
402
  split?: {
395
403
  entry: string;
396
404
  chunks?: string[];
405
+ lazy?: string[];
397
406
  };
407
+ /**
408
+ * Dois módulos de teste do build dividido (`export{}` e um com hash errado),
409
+ * servidos junto com o remote. O runtime testa com eles se o navegador
410
+ * confere o hash, no lugar de `data:` e `blob:`, que uma CSP sem esses
411
+ * esquemas bloqueia.
412
+ */
413
+ probe?: [string, string];
398
414
  /**
399
415
  * Dependências de `dedupe` do build dividido: faixa aceita, versão da
400
416
  * cópia própria e o arquivo dela, para o loader baixar junto com a entrada.
package/dist/vite.d.ts CHANGED
@@ -23,6 +23,20 @@ interface CssBuildOptions {
23
23
 
24
24
  type AdapterName = 'react' | 'vue' | 'svelte' | 'solid' | 'preact' | 'angular' | 'element';
25
25
 
26
+ /**
27
+ * `vitral({ next: true })`: os imports `next/*` de um código escrito para
28
+ * Next.js viram módulos virtuais que reexportam `vitral/next`, e as variáveis
29
+ * `NEXT_PUBLIC_*` do `.env` entram em `process.env`, como no `next build`.
30
+ */
31
+ interface NextOptions {
32
+ /** `basePath` do `next.config`: `router.push('/x')` vai para `<basePath>/x`. */
33
+ basePath?: string;
34
+ /** Resolve os `paths` do tsconfig mais próximo de cada arquivo. Padrão: true. */
35
+ tsconfigPaths?: boolean;
36
+ /** `.svg` importado vira componente React, como com `@svgr/webpack`. Padrão: true (se o SVGR estiver instalado). */
37
+ svgr?: boolean;
38
+ }
39
+
26
40
  interface VitralViteOptions extends CssBuildOptions {
27
41
  /**
28
42
  * Arquivo cujo `export default` é o remote: um componente do framework ou
@@ -105,7 +119,25 @@ interface VitralViteOptions extends CssBuildOptions {
105
119
  * carregamento). Os outros navegadores ignoram. Padrão: false.
106
120
  */
107
121
  compileHints?: boolean;
122
+ /**
123
+ * Pacotes tratados como sem efeitos colaterais, menos o CSS deles: o
124
+ * tree-shaking tira o que o remote não usa. Útil para pacote publicado como
125
+ * código-fonte sem `sideEffects` no package.json. Ex.: `['@empresa/ui']`.
126
+ */
127
+ sideEffectFree?: string[];
128
+ /**
129
+ * Builda com o Vite um código escrito para Next.js: `next/link`,
130
+ * `next/image`, `next/head`, `next/dynamic`, `next/router` e
131
+ * `next/navigation` vêm de `vitral/next`, e as `NEXT_PUBLIC_*` do `.env`
132
+ * entram em `process.env`. `basePath` é o do `next.config`. Também lê os
133
+ * `paths` do tsconfig de cada arquivo, importa `.svg` como componente (com
134
+ * o SVGR do projeto) e builda com `NODE_ENV=production` mesmo com
135
+ * `NODE_ENV=development` no `.env`. Padrão: false.
136
+ */
137
+ next?: boolean | NextOptions;
108
138
  }
109
139
  declare function vitral(options?: VitralViteOptions): Plugin;
140
+ /** `moduleSideEffects` com os pacotes de `sideEffectFree` sem efeitos, menos o CSS deles. */
141
+ declare function pureExcept(pkgs: string[]): (id: string) => boolean;
110
142
 
111
- export { type VitralViteOptions, vitral as default, vitral };
143
+ export { type NextOptions, type VitralViteOptions, vitral as default, pureExcept, vitral };