@marko/vite 2.4.4 → 2.4.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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  serialize
3
- } from "./chunk-BV667Z5U.mjs";
3
+ } from "./chunk-NTHVNXFC.mjs";
4
4
 
5
5
  // src/manifest-generator.ts
6
6
  import { Parser } from "htmlparser2";
@@ -15,6 +15,7 @@ function generateDocManifest(basePath, rawHtml) {
15
15
  return reject(err);
16
16
  }
17
17
  const htmlChildren = dom.find(isElement).childNodes;
18
+ const entries = [];
18
19
  const headPrepend = [];
19
20
  const head = [];
20
21
  const bodyPrepend = [];
@@ -34,10 +35,11 @@ function generateDocManifest(basePath, rawHtml) {
34
35
  body
35
36
  );
36
37
  resolve({
37
- "head-prepend": serializeOrNull(basePath, headPrepend),
38
- head: serializeOrNull(basePath, head),
39
- "body-prepend": serializeOrNull(basePath, bodyPrepend),
40
- body: serializeOrNull(basePath, body)
38
+ entries,
39
+ "head-prepend": serializeOrNull(basePath, headPrepend, entries),
40
+ head: serializeOrNull(basePath, head, entries),
41
+ "body-prepend": serializeOrNull(basePath, bodyPrepend, entries),
42
+ body: serializeOrNull(basePath, body, entries)
41
43
  });
42
44
  })
43
45
  );
@@ -50,8 +52,8 @@ function generateInputDoc(entry) {
50
52
  entry
51
53
  )}></script></body></html>`;
52
54
  }
53
- function serializeOrNull(basePath, nodes) {
54
- const result = serialize(basePath, nodes);
55
+ function serializeOrNull(basePath, nodes, entries) {
56
+ const result = serialize(basePath, nodes, entries);
55
57
  if (result.length) {
56
58
  return result;
57
59
  }
@@ -16,7 +16,7 @@ var voidElements = /* @__PURE__ */ new Set([
16
16
  "track",
17
17
  "wbr"
18
18
  ]);
19
- function serialize(basePath, nodes, parts) {
19
+ function serialize(basePath, nodes, entries, parts) {
20
20
  let curString = parts ? parts.pop() : "";
21
21
  parts ?? (parts = []);
22
22
  for (const node of nodes) {
@@ -50,11 +50,15 @@ function serialize(basePath, nodes, parts) {
50
50
  if (attr.value === "") {
51
51
  curString += ` ${attr.name}`;
52
52
  } else if (attr.name === urlAttr) {
53
+ const id = stripBasePath(basePath, attr.value).replace(/^\.\//, "");
54
+ if (tag.name === "script") {
55
+ entries.push(id);
56
+ }
53
57
  curString += ` ${attr.name}="`;
54
58
  parts.push(
55
59
  curString,
56
60
  1 /* PublicPath */,
57
- stripBasePath(basePath, attr.value).replace(/"/g, "&#39;").replace(/^\.\//, "") + '"'
61
+ id.replace(/"/g, "&#39;") + '"'
58
62
  );
59
63
  curString = "";
60
64
  } else {
@@ -64,7 +68,7 @@ function serialize(basePath, nodes, parts) {
64
68
  curString += ">";
65
69
  if (tag.children.length) {
66
70
  parts.push(curString);
67
- serialize(basePath, tag.children, parts);
71
+ serialize(basePath, tag.children, entries, parts);
68
72
  curString = parts.pop();
69
73
  }
70
74
  if (!voidElements.has(name)) {
@@ -8,11 +8,35 @@ static function renderAssets(slot) {
8
8
  const writtenEntries = (this[slotWrittenEntriesKey] = entries.length);
9
9
 
10
10
  for (let i = lastWrittenEntry; i < writtenEntries; i++) {
11
- const entry = entries[i];
12
- const parts =
13
- typeof __MARKO_MANIFEST__ === "object"
14
- ? __MARKO_MANIFEST__[entry]?.[slot]
15
- : entry[slot];
11
+ let entry = entries[i];
12
+
13
+ if (typeof __MARKO_MANIFEST__ === "object") {
14
+ entry = __MARKO_MANIFEST__[entry] || {};
15
+ } else if (slot === "head") {
16
+ // In dev mode we have is a list entries of the top level modules that need to be imported.
17
+ // To avoid FOUC we will hide the page until all of these modules are loaded.
18
+ const { entries } = entry;
19
+ if (entries) {
20
+ let sep = "";
21
+ html += `<script${this.___viteInjectAttrs}>((root=document.documentElement)=>{`;
22
+ html += "root.style.visibility='hidden';";
23
+ html += "document.currentScript.remove();";
24
+ html += "Promise.allSettled([";
25
+
26
+ for (const id of entries) {
27
+ html += `${sep}import(${JSON.stringify(this.___viteBasePath + id)})`;
28
+ sep = ",";
29
+ }
30
+
31
+ html += "]).then(()=>{";
32
+ html += "root.style.visibility='';";
33
+ html +=
34
+ "if(root.getAttribute('style')==='')root.removeAttribute('style')";
35
+ html += "})})()</script>";
36
+ }
37
+ }
38
+
39
+ const parts = entry[slot];
16
40
 
17
41
  if (parts) {
18
42
  for (const part of parts) {
@@ -40,7 +64,9 @@ $ if (!out.global.___viteRenderAssets) {
40
64
  <__flush_here_and_after__>
41
65
  <if(input.base && !out.global.___flushedMBP)>
42
66
  $ out.global.___flushedMBP = true;
43
- $!{`<script${out.global.___viteInjectAttrs}>${out.global.___viteBaseVar}=${JSON.stringify(input.base)}</script>`}
67
+ $!{`<script${out.global.___viteInjectAttrs}>${
68
+ out.global.___viteBaseVar
69
+ }=${JSON.stringify(input.base)}</script>`}
44
70
  </if>
45
71
  $!{out.global.___viteRenderAssets(input.slot)}
46
72
  </__flush_here_and_after__>
package/dist/index.js CHANGED
@@ -485,10 +485,14 @@ if (import.meta.hot) import.meta.hot.accept(() => {});`;
485
485
  chunk = bundle[chunkId];
486
486
  }
487
487
  if ((chunk == null ? void 0 : chunk.type) === "asset") {
488
- browserManifest[entryId] = await (0, import_manifest_generator.generateDocManifest)(
489
- basePath,
490
- chunk.source.toString()
491
- );
488
+ browserManifest[entryId] = {
489
+ ...await (0, import_manifest_generator.generateDocManifest)(
490
+ basePath,
491
+ chunk.source.toString()
492
+ ),
493
+ entries: void 0
494
+ // clear out entries for prod builds.
495
+ };
492
496
  delete bundle[chunkId];
493
497
  } else {
494
498
  this.error(
package/dist/index.mjs CHANGED
@@ -4,8 +4,8 @@ import {
4
4
  import {
5
5
  generateDocManifest,
6
6
  generateInputDoc
7
- } from "./chunk-ZCKVZIQN.mjs";
8
- import "./chunk-BV667Z5U.mjs";
7
+ } from "./chunk-2E5QX7AF.mjs";
8
+ import "./chunk-NTHVNXFC.mjs";
9
9
  import {
10
10
  server_entry_template_default
11
11
  } from "./chunk-6IJ5UJ3N.mjs";
@@ -465,10 +465,14 @@ if (import.meta.hot) import.meta.hot.accept(() => {});`;
465
465
  chunk = bundle[chunkId];
466
466
  }
467
467
  if ((chunk == null ? void 0 : chunk.type) === "asset") {
468
- browserManifest[entryId] = await generateDocManifest(
469
- basePath,
470
- chunk.source.toString()
471
- );
468
+ browserManifest[entryId] = {
469
+ ...await generateDocManifest(
470
+ basePath,
471
+ chunk.source.toString()
472
+ ),
473
+ entries: void 0
474
+ // clear out entries for prod builds.
475
+ };
472
476
  delete bundle[chunkId];
473
477
  } else {
474
478
  this.error(
@@ -1,6 +1,7 @@
1
1
  import serialize from "./serializer";
2
2
  type SerializedOrNull = null | ReturnType<typeof serialize>;
3
3
  export interface DocManifest {
4
+ entries: string[];
4
5
  "head-prepend": SerializedOrNull;
5
6
  head: SerializedOrNull;
6
7
  "body-prepend": SerializedOrNull;
@@ -45,6 +45,7 @@ function generateDocManifest(basePath, rawHtml) {
45
45
  return reject(err);
46
46
  }
47
47
  const htmlChildren = dom.find(isElement).childNodes;
48
+ const entries = [];
48
49
  const headPrepend = [];
49
50
  const head = [];
50
51
  const bodyPrepend = [];
@@ -64,10 +65,11 @@ function generateDocManifest(basePath, rawHtml) {
64
65
  body
65
66
  );
66
67
  resolve({
67
- "head-prepend": serializeOrNull(basePath, headPrepend),
68
- head: serializeOrNull(basePath, head),
69
- "body-prepend": serializeOrNull(basePath, bodyPrepend),
70
- body: serializeOrNull(basePath, body)
68
+ entries,
69
+ "head-prepend": serializeOrNull(basePath, headPrepend, entries),
70
+ head: serializeOrNull(basePath, head, entries),
71
+ "body-prepend": serializeOrNull(basePath, bodyPrepend, entries),
72
+ body: serializeOrNull(basePath, body, entries)
71
73
  });
72
74
  })
73
75
  );
@@ -80,8 +82,8 @@ function generateInputDoc(entry) {
80
82
  entry
81
83
  )}></script></body></html>`;
82
84
  }
83
- function serializeOrNull(basePath, nodes) {
84
- const result = (0, import_serializer.default)(basePath, nodes);
85
+ function serializeOrNull(basePath, nodes, entries) {
86
+ const result = (0, import_serializer.default)(basePath, nodes, entries);
85
87
  if (result.length) {
86
88
  return result;
87
89
  }
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  generateDocManifest,
3
3
  generateInputDoc
4
- } from "./chunk-ZCKVZIQN.mjs";
5
- import "./chunk-BV667Z5U.mjs";
4
+ } from "./chunk-2E5QX7AF.mjs";
5
+ import "./chunk-NTHVNXFC.mjs";
6
6
  export {
7
7
  generateDocManifest,
8
8
  generateInputDoc
@@ -3,5 +3,5 @@ declare enum InjectType {
3
3
  AssetAttrs = 0,
4
4
  PublicPath = 1
5
5
  }
6
- export default function serialize(basePath: string, nodes: Node[], parts?: (string | InjectType)[]): (string | InjectType)[];
6
+ export default function serialize(basePath: string, nodes: Node[], entries: string[], parts?: (string | InjectType)[]): (string | InjectType)[];
7
7
  export {};
@@ -43,7 +43,7 @@ const voidElements = /* @__PURE__ */ new Set([
43
43
  "track",
44
44
  "wbr"
45
45
  ]);
46
- function serialize(basePath, nodes, parts) {
46
+ function serialize(basePath, nodes, entries, parts) {
47
47
  let curString = parts ? parts.pop() : "";
48
48
  parts ?? (parts = []);
49
49
  for (const node of nodes) {
@@ -77,11 +77,15 @@ function serialize(basePath, nodes, parts) {
77
77
  if (attr.value === "") {
78
78
  curString += ` ${attr.name}`;
79
79
  } else if (attr.name === urlAttr) {
80
+ const id = stripBasePath(basePath, attr.value).replace(/^\.\//, "");
81
+ if (tag.name === "script") {
82
+ entries.push(id);
83
+ }
80
84
  curString += ` ${attr.name}="`;
81
85
  parts.push(
82
86
  curString,
83
87
  1 /* PublicPath */,
84
- stripBasePath(basePath, attr.value).replace(/"/g, "&#39;").replace(/^\.\//, "") + '"'
88
+ id.replace(/"/g, "&#39;") + '"'
85
89
  );
86
90
  curString = "";
87
91
  } else {
@@ -91,7 +95,7 @@ function serialize(basePath, nodes, parts) {
91
95
  curString += ">";
92
96
  if (tag.children.length) {
93
97
  parts.push(curString);
94
- serialize(basePath, tag.children, parts);
98
+ serialize(basePath, tag.children, entries, parts);
95
99
  curString = parts.pop();
96
100
  }
97
101
  if (!voidElements.has(name)) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  serialize
3
- } from "./chunk-BV667Z5U.mjs";
3
+ } from "./chunk-NTHVNXFC.mjs";
4
4
  export {
5
5
  serialize as default
6
6
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@marko/vite",
3
3
  "description": "A Marko plugin for Vite",
4
- "version": "2.4.4",
4
+ "version": "2.4.5",
5
5
  "author": "Dylan Piercey <dpiercey@ebay.com>",
6
6
  "bugs": "https://github.com/marko-js/vite/issues",
7
7
  "dependencies": {