vite-plugin-zephyr 1.4.0 → 1.4.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.
@@ -4,15 +4,38 @@ function getGlobalManifestCache() {
4
4
  if (!_global[globalCacheKey]) _global[globalCacheKey] = new Map();
5
5
  return _global[globalCacheKey];
6
6
  }
7
- function getScriptBaseUrl() {
8
- if ("u" > typeof document && document.currentScript) try {
9
- const src = document.currentScript.src;
10
- if (src) {
11
- const url = new URL(src);
12
- return `${url.protocol}//${url.host}`;
13
- }
14
- } catch {}
15
- return '';
7
+ const manifestFileName = 'zephyr-manifest.json';
8
+ function toHttpUrl(value) {
9
+ if (!value) return;
10
+ try {
11
+ const url = new URL(value);
12
+ return 'http:' === url.protocol || 'https:' === url.protocol ? url : void 0;
13
+ } catch {
14
+ return;
15
+ }
16
+ }
17
+ function getModuleUrl() {
18
+ try {
19
+ return import.meta.url;
20
+ } catch {
21
+ return;
22
+ }
23
+ }
24
+ function getDocumentBaseUrl() {
25
+ if ("u" < typeof document || 'function' != typeof document.querySelector) return;
26
+ if (!document.querySelector('base[href]')) return;
27
+ try {
28
+ return toHttpUrl(new URL('.', document.baseURI).href);
29
+ } catch {
30
+ return;
31
+ }
32
+ }
33
+ export function resolveManifestUrl(moduleUrl) {
34
+ const script = toHttpUrl(moduleUrl);
35
+ const documentBase = getDocumentBaseUrl();
36
+ if (documentBase && (!script || script.origin === documentBase.origin)) return `${documentBase.href}${manifestFileName}`;
37
+ if (script) return `${script.origin}/${manifestFileName}`;
38
+ return `/${manifestFileName}`;
16
39
  }
17
40
  function getRemotes(args) {
18
41
  if (Array.isArray(args?.options?.remotes)) return args.options.remotes;
@@ -20,7 +43,7 @@ function getRemotes(args) {
20
43
  return [];
21
44
  }
22
45
  export default function createZephyrRuntimePlugin(options = {}) {
23
- const defaultManifestUrl = `${getScriptBaseUrl()}/zephyr-manifest.json`;
46
+ const defaultManifestUrl = resolveManifestUrl(getModuleUrl());
24
47
  const { manifestUrl = defaultManifestUrl } = options;
25
48
  let processedRemotes;
26
49
  async function fetchManifest(url) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/vitejs/vite-plugin-registry/refs/heads/main/data/schema/extended-package-json.schema.json",
3
3
  "name": "vite-plugin-zephyr",
4
- "version": "1.4.0",
4
+ "version": "1.4.1",
5
5
  "description": "Vite plugin for Zephyr",
6
6
  "keywords": [
7
7
  "deploy",
@@ -51,7 +51,7 @@
51
51
  "acorn": "^8.18.0",
52
52
  "acorn-walk": "^8.3.5",
53
53
  "magic-string": "1.2.3",
54
- "zephyr-agent": "1.4.0"
54
+ "zephyr-agent": "1.4.1"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@module-federation/vite": "1.21.2",