@marko/vite 2.4.3 → 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
@@ -59,27 +59,14 @@ const resolveOpts = { skipSelf: true };
59
59
  const cache = /* @__PURE__ */ new Map();
60
60
  const thisFile = typeof __filename === "string" ? __filename : (0, import_url.fileURLToPath)(import_meta.url);
61
61
  function markoPlugin(opts = {}) {
62
- var _a;
63
62
  let compiler;
64
63
  let { linked = true } = opts;
65
- const { runtimeId, basePathVar } = opts;
66
- const baseConfig = {
67
- cache,
68
- runtimeId,
69
- sourceMaps: true,
70
- writeVersionComment: false,
71
- babelConfig: {
72
- ...opts.babelConfig,
73
- caller: {
74
- name: "@marko/vite",
75
- supportsStaticESM: true,
76
- supportsDynamicImport: true,
77
- supportsTopLevelAwait: true,
78
- supportsExportNamespaceFrom: true,
79
- ...(_a = opts.babelConfig) == null ? void 0 : _a.caller
80
- }
81
- }
82
- };
64
+ let runtimeId;
65
+ let basePathVar;
66
+ let baseConfig;
67
+ let ssrConfig;
68
+ let domConfig;
69
+ let hydrateConfig;
83
70
  const resolveViteVirtualDep = (from, dep) => {
84
71
  const query = `${virtualFileQuery}&id=${encodeURIComponent(
85
72
  normalizePath(dep.virtualPath)
@@ -95,21 +82,6 @@ function markoPlugin(opts = {}) {
95
82
  virtualFiles.set(id, dep);
96
83
  return `./${import_path.default.posix.basename(normalizedFrom) + query}`;
97
84
  };
98
- const ssrConfig = {
99
- ...baseConfig,
100
- resolveVirtualDependency: resolveViteVirtualDep,
101
- output: "html"
102
- };
103
- const domConfig = {
104
- ...baseConfig,
105
- resolveVirtualDependency: resolveViteVirtualDep,
106
- output: "dom"
107
- };
108
- const hydrateConfig = {
109
- ...baseConfig,
110
- resolveVirtualDependency: resolveViteVirtualDep,
111
- output: "hydrate"
112
- };
113
85
  let root;
114
86
  let devEntryFile;
115
87
  let devEntryFilePosix;
@@ -131,7 +103,42 @@ function markoPlugin(opts = {}) {
131
103
  enforce: "pre",
132
104
  // Must be pre to allow us to resolve assets before vite.
133
105
  async config(config, env) {
106
+ var _a;
134
107
  compiler ?? (compiler = await import(opts.compiler || "@marko/compiler"));
108
+ runtimeId = opts.runtimeId;
109
+ basePathVar = opts.basePathVar;
110
+ baseConfig = {
111
+ cache,
112
+ runtimeId,
113
+ sourceMaps: true,
114
+ writeVersionComment: false,
115
+ babelConfig: {
116
+ ...opts.babelConfig,
117
+ caller: {
118
+ name: "@marko/vite",
119
+ supportsStaticESM: true,
120
+ supportsDynamicImport: true,
121
+ supportsTopLevelAwait: true,
122
+ supportsExportNamespaceFrom: true,
123
+ ...(_a = opts.babelConfig) == null ? void 0 : _a.caller
124
+ }
125
+ }
126
+ };
127
+ ssrConfig = {
128
+ ...baseConfig,
129
+ resolveVirtualDependency: resolveViteVirtualDep,
130
+ output: "html"
131
+ };
132
+ domConfig = {
133
+ ...baseConfig,
134
+ resolveVirtualDependency: resolveViteVirtualDep,
135
+ output: "dom"
136
+ };
137
+ hydrateConfig = {
138
+ ...baseConfig,
139
+ resolveVirtualDependency: resolveViteVirtualDep,
140
+ output: "hydrate"
141
+ };
135
142
  compiler.configure(baseConfig);
136
143
  root = normalizePath(config.root || process.cwd());
137
144
  devEntryFile = import_path.default.join(root, "index.html");
@@ -283,7 +290,7 @@ function markoPlugin(opts = {}) {
283
290
  }
284
291
  },
285
292
  async resolveId(importee, importer, importOpts, ssr = importOpts.ssr) {
286
- var _a2;
293
+ var _a;
287
294
  if (virtualFiles.has(importee)) {
288
295
  return importee;
289
296
  }
@@ -293,7 +300,7 @@ function markoPlugin(opts = {}) {
293
300
  } else if (ssr && linked && importer && (importer !== devEntryFile || normalizePath(importer) !== devEntryFilePosix) && // Vite tries to resolve against an `index.html` in some cases, we ignore it here.
294
301
  isMarkoFile(importee) && !isMarkoFile(importer.replace(queryReg, ""))) {
295
302
  importeeQuery = serverEntryQuery;
296
- } else if (!ssr && isBuild && importer && isMarkoFile(importee) && ((_a2 = this.getModuleInfo(importer)) == null ? void 0 : _a2.isEntry)) {
303
+ } else if (!ssr && isBuild && importer && isMarkoFile(importee) && ((_a = this.getModuleInfo(importer)) == null ? void 0 : _a.isEntry)) {
297
304
  importeeQuery = browserEntryQuery;
298
305
  }
299
306
  if (importeeQuery) {
@@ -354,7 +361,7 @@ function markoPlugin(opts = {}) {
354
361
  fileName,
355
362
  entryData,
356
363
  runtimeId,
357
- basePathVar
364
+ basePathVar: isBuild ? basePathVar : void 0
358
365
  });
359
366
  }
360
367
  case browserEntryQuery: {
@@ -478,10 +485,14 @@ if (import.meta.hot) import.meta.hot.accept(() => {});`;
478
485
  chunk = bundle[chunkId];
479
486
  }
480
487
  if ((chunk == null ? void 0 : chunk.type) === "asset") {
481
- browserManifest[entryId] = await (0, import_manifest_generator.generateDocManifest)(
482
- basePath,
483
- chunk.source.toString()
484
- );
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
+ };
485
496
  delete bundle[chunkId];
486
497
  } else {
487
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";
@@ -39,27 +39,14 @@ var resolveOpts = { skipSelf: true };
39
39
  var cache = /* @__PURE__ */ new Map();
40
40
  var thisFile = typeof __filename === "string" ? __filename : fileURLToPath(import.meta.url);
41
41
  function markoPlugin(opts = {}) {
42
- var _a;
43
42
  let compiler;
44
43
  let { linked = true } = opts;
45
- const { runtimeId, basePathVar } = opts;
46
- const baseConfig = {
47
- cache,
48
- runtimeId,
49
- sourceMaps: true,
50
- writeVersionComment: false,
51
- babelConfig: {
52
- ...opts.babelConfig,
53
- caller: {
54
- name: "@marko/vite",
55
- supportsStaticESM: true,
56
- supportsDynamicImport: true,
57
- supportsTopLevelAwait: true,
58
- supportsExportNamespaceFrom: true,
59
- ...(_a = opts.babelConfig) == null ? void 0 : _a.caller
60
- }
61
- }
62
- };
44
+ let runtimeId;
45
+ let basePathVar;
46
+ let baseConfig;
47
+ let ssrConfig;
48
+ let domConfig;
49
+ let hydrateConfig;
63
50
  const resolveViteVirtualDep = (from, dep) => {
64
51
  const query = `${virtualFileQuery}&id=${encodeURIComponent(
65
52
  normalizePath(dep.virtualPath)
@@ -75,21 +62,6 @@ function markoPlugin(opts = {}) {
75
62
  virtualFiles.set(id, dep);
76
63
  return `./${path.posix.basename(normalizedFrom) + query}`;
77
64
  };
78
- const ssrConfig = {
79
- ...baseConfig,
80
- resolveVirtualDependency: resolveViteVirtualDep,
81
- output: "html"
82
- };
83
- const domConfig = {
84
- ...baseConfig,
85
- resolveVirtualDependency: resolveViteVirtualDep,
86
- output: "dom"
87
- };
88
- const hydrateConfig = {
89
- ...baseConfig,
90
- resolveVirtualDependency: resolveViteVirtualDep,
91
- output: "hydrate"
92
- };
93
65
  let root;
94
66
  let devEntryFile;
95
67
  let devEntryFilePosix;
@@ -111,7 +83,42 @@ function markoPlugin(opts = {}) {
111
83
  enforce: "pre",
112
84
  // Must be pre to allow us to resolve assets before vite.
113
85
  async config(config, env) {
86
+ var _a;
114
87
  compiler ?? (compiler = await import(opts.compiler || "@marko/compiler"));
88
+ runtimeId = opts.runtimeId;
89
+ basePathVar = opts.basePathVar;
90
+ baseConfig = {
91
+ cache,
92
+ runtimeId,
93
+ sourceMaps: true,
94
+ writeVersionComment: false,
95
+ babelConfig: {
96
+ ...opts.babelConfig,
97
+ caller: {
98
+ name: "@marko/vite",
99
+ supportsStaticESM: true,
100
+ supportsDynamicImport: true,
101
+ supportsTopLevelAwait: true,
102
+ supportsExportNamespaceFrom: true,
103
+ ...(_a = opts.babelConfig) == null ? void 0 : _a.caller
104
+ }
105
+ }
106
+ };
107
+ ssrConfig = {
108
+ ...baseConfig,
109
+ resolveVirtualDependency: resolveViteVirtualDep,
110
+ output: "html"
111
+ };
112
+ domConfig = {
113
+ ...baseConfig,
114
+ resolveVirtualDependency: resolveViteVirtualDep,
115
+ output: "dom"
116
+ };
117
+ hydrateConfig = {
118
+ ...baseConfig,
119
+ resolveVirtualDependency: resolveViteVirtualDep,
120
+ output: "hydrate"
121
+ };
115
122
  compiler.configure(baseConfig);
116
123
  root = normalizePath(config.root || process.cwd());
117
124
  devEntryFile = path.join(root, "index.html");
@@ -263,7 +270,7 @@ function markoPlugin(opts = {}) {
263
270
  }
264
271
  },
265
272
  async resolveId(importee, importer, importOpts, ssr = importOpts.ssr) {
266
- var _a2;
273
+ var _a;
267
274
  if (virtualFiles.has(importee)) {
268
275
  return importee;
269
276
  }
@@ -273,7 +280,7 @@ function markoPlugin(opts = {}) {
273
280
  } else if (ssr && linked && importer && (importer !== devEntryFile || normalizePath(importer) !== devEntryFilePosix) && // Vite tries to resolve against an `index.html` in some cases, we ignore it here.
274
281
  isMarkoFile(importee) && !isMarkoFile(importer.replace(queryReg, ""))) {
275
282
  importeeQuery = serverEntryQuery;
276
- } else if (!ssr && isBuild && importer && isMarkoFile(importee) && ((_a2 = this.getModuleInfo(importer)) == null ? void 0 : _a2.isEntry)) {
283
+ } else if (!ssr && isBuild && importer && isMarkoFile(importee) && ((_a = this.getModuleInfo(importer)) == null ? void 0 : _a.isEntry)) {
277
284
  importeeQuery = browserEntryQuery;
278
285
  }
279
286
  if (importeeQuery) {
@@ -334,7 +341,7 @@ function markoPlugin(opts = {}) {
334
341
  fileName,
335
342
  entryData,
336
343
  runtimeId,
337
- basePathVar
344
+ basePathVar: isBuild ? basePathVar : void 0
338
345
  });
339
346
  }
340
347
  case browserEntryQuery: {
@@ -458,10 +465,14 @@ if (import.meta.hot) import.meta.hot.accept(() => {});`;
458
465
  chunk = bundle[chunkId];
459
466
  }
460
467
  if ((chunk == null ? void 0 : chunk.type) === "asset") {
461
- browserManifest[entryId] = await generateDocManifest(
462
- basePath,
463
- chunk.source.toString()
464
- );
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
+ };
465
476
  delete bundle[chunkId];
466
477
  } else {
467
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.3",
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": {