@marko/vite 2.3.9 → 2.3.10

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.
@@ -9,30 +9,46 @@ import { DomHandler } from "domhandler";
9
9
  var MARKER_COMMENT = "MARKO_VITE";
10
10
  function generateDocManifest(rawHtml) {
11
11
  return new Promise((resolve, reject) => {
12
- const parser = new Parser(new DomHandler(function(err, dom) {
13
- if (err) {
14
- return reject(err);
15
- }
16
- const htmlChildren = dom.find(isElement).childNodes;
17
- const headPrepend = [];
18
- const head = [];
19
- const bodyPrepend = [];
20
- const body = [];
21
- splitNodesByMarker(htmlChildren.find((node) => isElement(node) && node.tagName === "head").childNodes, headPrepend, head);
22
- splitNodesByMarker(htmlChildren.find((node) => isElement(node) && node.tagName === "body").childNodes, bodyPrepend, body);
23
- resolve({
24
- "head-prepend": serializeOrNull(headPrepend),
25
- head: serializeOrNull(head),
26
- "body-prepend": serializeOrNull(bodyPrepend),
27
- body: serializeOrNull(body)
28
- });
29
- }));
12
+ const parser = new Parser(
13
+ new DomHandler(function(err, dom) {
14
+ if (err) {
15
+ return reject(err);
16
+ }
17
+ const htmlChildren = dom.find(isElement).childNodes;
18
+ const headPrepend = [];
19
+ const head = [];
20
+ const bodyPrepend = [];
21
+ const body = [];
22
+ splitNodesByMarker(
23
+ htmlChildren.find(
24
+ (node) => isElement(node) && node.tagName === "head"
25
+ ).childNodes,
26
+ headPrepend,
27
+ head
28
+ );
29
+ splitNodesByMarker(
30
+ htmlChildren.find(
31
+ (node) => isElement(node) && node.tagName === "body"
32
+ ).childNodes,
33
+ bodyPrepend,
34
+ body
35
+ );
36
+ resolve({
37
+ "head-prepend": serializeOrNull(headPrepend),
38
+ head: serializeOrNull(head),
39
+ "body-prepend": serializeOrNull(bodyPrepend),
40
+ body: serializeOrNull(body)
41
+ });
42
+ })
43
+ );
30
44
  parser.write(rawHtml);
31
45
  parser.end();
32
46
  });
33
47
  }
34
48
  function generateInputDoc(entry) {
35
- return `<!DOCTYPE html><html><head><!--${MARKER_COMMENT}--></head><body><!--${MARKER_COMMENT}--><script async type="module" src=${JSON.stringify(entry)}><\/script></body></html>`;
49
+ return `<!DOCTYPE html><html><head><!--${MARKER_COMMENT}--></head><body><!--${MARKER_COMMENT}--><script async type="module" src=${JSON.stringify(
50
+ entry
51
+ )}></script></body></html>`;
36
52
  }
37
53
  function serializeOrNull(nodes) {
38
54
  const result = serialize(nodes);
@@ -23,14 +23,20 @@ function esbuildPlugin(compiler, config) {
23
23
  path: path.resolve(args.resolveDir, args.path)
24
24
  };
25
25
  });
26
- build.onLoad({ filter: /\.marko\./, namespace: "marko:virtual" }, (args) => ({
27
- contents: virtualFiles.get(args.path).code,
28
- loader: path.extname(args.path).slice(1)
29
- }));
26
+ build.onLoad(
27
+ { filter: /\.marko\./, namespace: "marko:virtual" },
28
+ (args) => ({
29
+ contents: virtualFiles.get(args.path).code,
30
+ loader: path.extname(args.path).slice(1)
31
+ })
32
+ );
30
33
  }
31
34
  build.onLoad({ filter: /\.marko$/ }, async (args) => {
32
35
  try {
33
- const { code, meta } = await compiler.compileFile(args.path, finalConfig);
36
+ const { code, meta } = await compiler.compileFile(
37
+ args.path,
38
+ finalConfig
39
+ );
34
40
  return {
35
41
  loader: "js",
36
42
  contents: code,
@@ -46,7 +52,9 @@ function esbuildPlugin(compiler, config) {
46
52
  const [, file, rawLine, rawCol, text2] = match;
47
53
  const line = parseInt(rawLine, 10) || 1;
48
54
  const column = parseInt(rawCol, 10) || 1;
49
- lines || (lines = (await fs.promises.readFile(args.path, "utf-8")).split(/\n/g));
55
+ lines || (lines = (await fs.promises.readFile(args.path, "utf-8")).split(
56
+ /\n/g
57
+ ));
50
58
  errors.push({
51
59
  text: text2,
52
60
  location: {
@@ -17,7 +17,14 @@ var __copyProps = (to, from, except, desc) => {
17
17
  }
18
18
  return to;
19
19
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
21
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
29
  var esbuild_plugin_exports = {};
23
30
  __export(esbuild_plugin_exports, {
@@ -48,14 +55,20 @@ function esbuildPlugin(compiler, config) {
48
55
  path: import_path.default.resolve(args.resolveDir, args.path)
49
56
  };
50
57
  });
51
- build.onLoad({ filter: /\.marko\./, namespace: "marko:virtual" }, (args) => ({
52
- contents: virtualFiles.get(args.path).code,
53
- loader: import_path.default.extname(args.path).slice(1)
54
- }));
58
+ build.onLoad(
59
+ { filter: /\.marko\./, namespace: "marko:virtual" },
60
+ (args) => ({
61
+ contents: virtualFiles.get(args.path).code,
62
+ loader: import_path.default.extname(args.path).slice(1)
63
+ })
64
+ );
55
65
  }
56
66
  build.onLoad({ filter: /\.marko$/ }, async (args) => {
57
67
  try {
58
- const { code, meta } = await compiler.compileFile(args.path, finalConfig);
68
+ const { code, meta } = await compiler.compileFile(
69
+ args.path,
70
+ finalConfig
71
+ );
59
72
  return {
60
73
  loader: "js",
61
74
  contents: code,
@@ -71,7 +84,9 @@ function esbuildPlugin(compiler, config) {
71
84
  const [, file, rawLine, rawCol, text2] = match;
72
85
  const line = parseInt(rawLine, 10) || 1;
73
86
  const column = parseInt(rawCol, 10) || 1;
74
- lines || (lines = (await import_fs.default.promises.readFile(args.path, "utf-8")).split(/\n/g));
87
+ lines || (lines = (await import_fs.default.promises.readFile(args.path, "utf-8")).split(
88
+ /\n/g
89
+ ));
75
90
  errors.push({
76
91
  text: text2,
77
92
  location: {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  esbuildPlugin
3
- } from "./chunk-Z64RCGRQ.mjs";
3
+ } from "./chunk-KRSZ5IRT.mjs";
4
4
  export {
5
5
  esbuildPlugin as default
6
6
  };
package/dist/index.js CHANGED
@@ -17,7 +17,14 @@ var __copyProps = (to, from, except, desc) => {
17
17
  }
18
18
  return to;
19
19
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
21
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
29
  var src_exports = {};
23
30
  __export(src_exports, {
@@ -74,7 +81,9 @@ function markoPlugin(opts = {}) {
74
81
  if (devServer) {
75
82
  const prev = virtualFiles.get(id);
76
83
  if (prev && prev.code !== dep.code) {
77
- devServer.moduleGraph.invalidateModule(devServer.moduleGraph.getModuleById(id));
84
+ devServer.moduleGraph.invalidateModule(
85
+ devServer.moduleGraph.getModuleById(id)
86
+ );
78
87
  }
79
88
  }
80
89
  virtualFiles.set(id, dep);
@@ -109,6 +118,7 @@ function markoPlugin(opts = {}) {
109
118
  {
110
119
  name: "marko-vite:pre",
111
120
  enforce: "pre",
121
+ // Must be pre to allow us to resolve assets before vite.
112
122
  async config(config, env) {
113
123
  compiler ?? (compiler = await import(opts.compiler || "@marko/compiler"));
114
124
  root = normalizePath(config.root || process.cwd());
@@ -116,8 +126,13 @@ function markoPlugin(opts = {}) {
116
126
  isBuild = env.command === "build";
117
127
  isSSRBuild = isBuild && linked && Boolean(config.build.ssr);
118
128
  if (linked && !registeredTag) {
119
- const transformer = import_path.default.resolve(thisFile, "../render-assets-transform");
120
- registeredTag = normalizePath(import_path.default.resolve(thisFile, "../components", "vite.marko"));
129
+ const transformer = import_path.default.resolve(
130
+ thisFile,
131
+ "../render-assets-transform"
132
+ );
133
+ registeredTag = normalizePath(
134
+ import_path.default.resolve(thisFile, "../components", "vite.marko")
135
+ );
121
136
  compiler.taglib.register("@marko/vite", {
122
137
  "<_vite>": { template: registeredTag },
123
138
  "<head>": { transformer },
@@ -139,12 +154,14 @@ function markoPlugin(opts = {}) {
139
154
  }
140
155
  }
141
156
  const optimizeDeps = config.optimizeDeps ?? (config.optimizeDeps = {});
142
- optimizeDeps.include = Array.from(/* @__PURE__ */ new Set([
143
- ...optimizeDeps.include || [],
144
- ...compiler.getRuntimeEntryFiles("dom", opts.translator),
145
- ...compiler.getRuntimeEntryFiles("html", opts.translator),
146
- ...taglibDeps
147
- ]));
157
+ optimizeDeps.include = Array.from(
158
+ /* @__PURE__ */ new Set([
159
+ ...optimizeDeps.include || [],
160
+ ...compiler.getRuntimeEntryFiles("dom", opts.translator),
161
+ ...compiler.getRuntimeEntryFiles("html", opts.translator),
162
+ ...taglibDeps
163
+ ])
164
+ );
148
165
  const optimizeExtensions = optimizeDeps.extensions ?? (optimizeDeps.extensions = []);
149
166
  optimizeExtensions.push(".marko");
150
167
  const esbuildOptions = optimizeDeps.esbuildOptions ?? (optimizeDeps.esbuildOptions = {});
@@ -152,7 +169,11 @@ function markoPlugin(opts = {}) {
152
169
  esbuildPlugins.push((0, import_esbuild_plugin.default)(compiler, baseConfig));
153
170
  const ssr = config.ssr ?? (config.ssr = {});
154
171
  if (ssr.noExternal !== true) {
155
- ssr.noExternal = Array.from(new Set(taglibDeps.concat(ssr.noExternal || [])));
172
+ ssr.noExternal = Array.from(
173
+ new Set(
174
+ taglibDeps.concat(ssr.noExternal || [])
175
+ )
176
+ );
156
177
  }
157
178
  },
158
179
  configureServer(_server) {
@@ -186,13 +207,20 @@ function markoPlugin(opts = {}) {
186
207
  const serverMetaFile = await getServerManifestFile(root);
187
208
  this.addWatchFile(serverMetaFile);
188
209
  try {
189
- serverManifest = JSON.parse(await import_fs.default.promises.readFile(serverMetaFile, "utf-8"));
210
+ serverManifest = JSON.parse(
211
+ await import_fs.default.promises.readFile(serverMetaFile, "utf-8")
212
+ );
190
213
  inputOptions.input = toHTMLEntries(root, serverManifest.entries);
191
214
  for (const entry in serverManifest.entrySources) {
192
- entrySources.set(import_path.default.resolve(root, entry), serverManifest.entrySources[entry]);
215
+ entrySources.set(
216
+ import_path.default.resolve(root, entry),
217
+ serverManifest.entrySources[entry]
218
+ );
193
219
  }
194
220
  } catch (err) {
195
- this.error(`You must run the "ssr" build before the "browser" build.`);
221
+ this.error(
222
+ `You must run the "ssr" build before the "browser" build.`
223
+ );
196
224
  }
197
225
  if (isEmpty(inputOptions.input)) {
198
226
  this.error("No Marko files were found when compiling the server.");
@@ -207,14 +235,17 @@ function markoPlugin(opts = {}) {
207
235
  let importeeQuery = getMarkoQuery(importee);
208
236
  if (importeeQuery) {
209
237
  importee = importee.slice(0, -importeeQuery.length);
210
- } else if (ssr && linked && importer && importer !== devEntryFile && isMarkoFile(importee) && !isMarkoFile(importer.replace(queryReg, ""))) {
238
+ } else if (ssr && linked && importer && importer !== devEntryFile && // Vite tries to resolve against an `index.html` in some cases, we ignore it here.
239
+ isMarkoFile(importee) && !isMarkoFile(importer.replace(queryReg, ""))) {
211
240
  importeeQuery = serverEntryQuery;
212
241
  } else if (!ssr && isBuild && importer && isMarkoFile(importee) && ((_a2 = this.getModuleInfo(importer)) == null ? void 0 : _a2.isEntry)) {
213
242
  importeeQuery = browserEntryQuery;
214
243
  }
215
244
  if (importeeQuery) {
216
245
  const resolved = importee[0] === "." ? {
217
- id: normalizePath(importer ? import_path.default.resolve(importer, "..", importee) : import_path.default.resolve(root, importee))
246
+ id: normalizePath(
247
+ importer ? import_path.default.resolve(importer, "..", importee) : import_path.default.resolve(root, importee)
248
+ )
218
249
  } : await this.resolve(importee, importer, resolveOpts);
219
250
  if (resolved) {
220
251
  resolved.id += importeeQuery;
@@ -252,7 +283,14 @@ function markoPlugin(opts = {}) {
252
283
  serverManifest.entries[entryId] = relativeFileName;
253
284
  entryData = JSON.stringify(entryId);
254
285
  } else {
255
- entryData = JSON.stringify(await (0, import_manifest_generator.generateDocManifest)(await devServer.transformIndexHtml("/", (0, import_manifest_generator.generateInputDoc)(fileNameToURL(fileName, root)))));
286
+ entryData = JSON.stringify(
287
+ await (0, import_manifest_generator.generateDocManifest)(
288
+ await devServer.transformIndexHtml(
289
+ "/",
290
+ (0, import_manifest_generator.generateInputDoc)(fileNameToURL(fileName, root))
291
+ )
292
+ )
293
+ );
256
294
  }
257
295
  return (0, import_server_entry_template.default)({
258
296
  fileName,
@@ -270,7 +308,10 @@ function markoPlugin(opts = {}) {
270
308
  if (isBuild) {
271
309
  return html;
272
310
  }
273
- return html.replace(/(src\s*=\s*(['"])(?:(?!\2).)*\.marko)(?:\?((?:(?!\2).)*))?\2/gim, (_, prefix, quote, query) => prefix + browserEntryQuery + (query ? "&" + query : "") + quote);
311
+ return html.replace(
312
+ /(src\s*=\s*(['"])(?:(?!\2).)*\.marko)(?:\?((?:(?!\2).)*))?\2/gim,
313
+ (_, prefix, quote, query) => prefix + browserEntryQuery + (query ? "&" + query : "") + quote
314
+ );
274
315
  },
275
316
  async transform(source, id, ssr) {
276
317
  const query = getMarkoQuery(id);
@@ -289,7 +330,11 @@ function markoPlugin(opts = {}) {
289
330
  serverManifest.entrySources[import_path.default.relative(root, id)] = source;
290
331
  }
291
332
  }
292
- const compiled = await compiler.compile(source, id, (typeof ssr === "object" ? ssr.ssr : ssr) ? ssrConfig : query === browserEntryQuery ? hydrateConfig : domConfig);
333
+ const compiled = await compiler.compile(
334
+ source,
335
+ id,
336
+ (typeof ssr === "object" ? ssr.ssr : ssr) ? ssrConfig : query === browserEntryQuery ? hydrateConfig : domConfig
337
+ );
293
338
  const { map, meta } = compiled;
294
339
  let { code } = compiled;
295
340
  if (query !== browserEntryQuery && devServer) {
@@ -317,15 +362,20 @@ if (import.meta.hot) import.meta.hot.accept();`;
317
362
  name: "marko-vite:post",
318
363
  apply: "build",
319
364
  enforce: "post",
365
+ // We use a "post" plugin to allow us to read the final generated `.html` from vite.
320
366
  async generateBundle(outputOptions, bundle, isWrite) {
321
367
  if (!linked) {
322
368
  return;
323
369
  }
324
370
  if (!isWrite) {
325
- this.error(`Linked builds are currently only supported when in "write" mode.`);
371
+ this.error(
372
+ `Linked builds are currently only supported when in "write" mode.`
373
+ );
326
374
  }
327
375
  if (!serverManifest) {
328
- this.error("No Marko files were found when bundling the server in linked mode.");
376
+ this.error(
377
+ "No Marko files were found when bundling the server in linked mode."
378
+ );
329
379
  }
330
380
  if (isSSRBuild) {
331
381
  const dir = outputOptions.dir ? import_path.default.resolve(outputOptions.dir) : import_path.default.resolve(outputOptions.file, "..");
@@ -334,13 +384,18 @@ if (import.meta.hot) import.meta.hot.accept();`;
334
384
  if (chunk.type === "chunk") {
335
385
  for (const id in chunk.modules) {
336
386
  if (id === registeredTag) {
337
- serverManifest.chunksNeedingAssets.push(import_path.default.resolve(dir, fileName));
387
+ serverManifest.chunksNeedingAssets.push(
388
+ import_path.default.resolve(dir, fileName)
389
+ );
338
390
  break;
339
391
  }
340
392
  }
341
393
  }
342
394
  }
343
- await import_fs.default.promises.writeFile(await getServerManifestFile(root), JSON.stringify(serverManifest));
395
+ await import_fs.default.promises.writeFile(
396
+ await getServerManifestFile(root),
397
+ JSON.stringify(serverManifest)
398
+ );
344
399
  } else {
345
400
  const browserManifest = {};
346
401
  for (const entryId in serverManifest.entries) {
@@ -352,13 +407,19 @@ if (import.meta.hot) import.meta.hot.accept();`;
352
407
  chunk = bundle[chunkId];
353
408
  }
354
409
  if ((chunk == null ? void 0 : chunk.type) === "asset") {
355
- browserManifest[entryId] = await (0, import_manifest_generator.generateDocManifest)(chunk.source.toString());
410
+ browserManifest[entryId] = await (0, import_manifest_generator.generateDocManifest)(
411
+ chunk.source.toString()
412
+ );
356
413
  delete bundle[chunkId];
357
414
  } else {
358
- this.error(`Marko template had unexpected output from vite, ${fileName}`);
415
+ this.error(
416
+ `Marko template had unexpected output from vite, ${fileName}`
417
+ );
359
418
  }
360
419
  }
361
- const manifestStr = `;var __MARKO_MANIFEST__=${JSON.stringify(browserManifest)};
420
+ const manifestStr = `;var __MARKO_MANIFEST__=${JSON.stringify(
421
+ browserManifest
422
+ )};
362
423
  `;
363
424
  for (const fileName of serverManifest.chunksNeedingAssets) {
364
425
  await import_fs.default.promises.appendFile(fileName, manifestStr);
@@ -392,7 +453,10 @@ async function getServerManifestFile(root) {
392
453
  }
393
454
  function getTempDir(root) {
394
455
  return tempDir || (tempDir = (async () => {
395
- const dir = import_path.default.join(import_os.default.tmpdir(), `marko-vite-${import_crypto.default.createHash("SHA1").update(root).digest("hex")}`);
456
+ const dir = import_path.default.join(
457
+ import_os.default.tmpdir(),
458
+ `marko-vite-${import_crypto.default.createHash("SHA1").update(root).digest("hex")}`
459
+ );
396
460
  try {
397
461
  const stat = await import_fs.default.promises.stat(dir);
398
462
  if (stat.isDirectory()) {
@@ -409,14 +473,22 @@ function toEntryId(id) {
409
473
  const lastSepIndex = id.lastIndexOf(import_path.default.sep);
410
474
  let name = id.slice(lastSepIndex + 1, id.indexOf(".", lastSepIndex));
411
475
  if (name === "index" || name === "template") {
412
- name = id.slice(id.lastIndexOf(import_path.default.sep, lastSepIndex - 1) + 1, lastSepIndex);
476
+ name = id.slice(
477
+ id.lastIndexOf(import_path.default.sep, lastSepIndex - 1) + 1,
478
+ lastSepIndex
479
+ );
413
480
  }
414
481
  return `${name}_${import_crypto.default.createHash("SHA1").update(id).digest("base64").replace(/[/+]/g, "-").slice(0, 4)}`;
415
482
  }
416
483
  function fileNameToURL(fileName, root) {
417
- const relativeURL = import_path.default.posix.relative((0, import_url.pathToFileURL)(root).pathname, (0, import_url.pathToFileURL)(fileName).pathname);
484
+ const relativeURL = import_path.default.posix.relative(
485
+ (0, import_url.pathToFileURL)(root).pathname,
486
+ (0, import_url.pathToFileURL)(fileName).pathname
487
+ );
418
488
  if (relativeURL[0] === ".") {
419
- throw new Error("@marko/vite: Entry templates must exist under the current root directory.");
489
+ throw new Error(
490
+ "@marko/vite: Entry templates must exist under the current root directory."
491
+ );
420
492
  }
421
493
  return `/${relativeURL}`;
422
494
  }
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  esbuildPlugin
3
- } from "./chunk-Z64RCGRQ.mjs";
3
+ } from "./chunk-KRSZ5IRT.mjs";
4
4
  import {
5
5
  generateDocManifest,
6
6
  generateInputDoc
7
- } from "./chunk-MPTD6LHF.mjs";
7
+ } from "./chunk-DSFBTWOA.mjs";
8
8
  import "./chunk-VL2HLMVE.mjs";
9
9
  import {
10
10
  server_entry_template_default
@@ -57,7 +57,9 @@ function markoPlugin(opts = {}) {
57
57
  if (devServer) {
58
58
  const prev = virtualFiles.get(id);
59
59
  if (prev && prev.code !== dep.code) {
60
- devServer.moduleGraph.invalidateModule(devServer.moduleGraph.getModuleById(id));
60
+ devServer.moduleGraph.invalidateModule(
61
+ devServer.moduleGraph.getModuleById(id)
62
+ );
61
63
  }
62
64
  }
63
65
  virtualFiles.set(id, dep);
@@ -92,6 +94,7 @@ function markoPlugin(opts = {}) {
92
94
  {
93
95
  name: "marko-vite:pre",
94
96
  enforce: "pre",
97
+ // Must be pre to allow us to resolve assets before vite.
95
98
  async config(config, env) {
96
99
  compiler ?? (compiler = await import(opts.compiler || "@marko/compiler"));
97
100
  root = normalizePath(config.root || process.cwd());
@@ -99,8 +102,13 @@ function markoPlugin(opts = {}) {
99
102
  isBuild = env.command === "build";
100
103
  isSSRBuild = isBuild && linked && Boolean(config.build.ssr);
101
104
  if (linked && !registeredTag) {
102
- const transformer = path.resolve(thisFile, "../render-assets-transform");
103
- registeredTag = normalizePath(path.resolve(thisFile, "../components", "vite.marko"));
105
+ const transformer = path.resolve(
106
+ thisFile,
107
+ "../render-assets-transform"
108
+ );
109
+ registeredTag = normalizePath(
110
+ path.resolve(thisFile, "../components", "vite.marko")
111
+ );
104
112
  compiler.taglib.register("@marko/vite", {
105
113
  "<_vite>": { template: registeredTag },
106
114
  "<head>": { transformer },
@@ -122,12 +130,14 @@ function markoPlugin(opts = {}) {
122
130
  }
123
131
  }
124
132
  const optimizeDeps = config.optimizeDeps ?? (config.optimizeDeps = {});
125
- optimizeDeps.include = Array.from(/* @__PURE__ */ new Set([
126
- ...optimizeDeps.include || [],
127
- ...compiler.getRuntimeEntryFiles("dom", opts.translator),
128
- ...compiler.getRuntimeEntryFiles("html", opts.translator),
129
- ...taglibDeps
130
- ]));
133
+ optimizeDeps.include = Array.from(
134
+ /* @__PURE__ */ new Set([
135
+ ...optimizeDeps.include || [],
136
+ ...compiler.getRuntimeEntryFiles("dom", opts.translator),
137
+ ...compiler.getRuntimeEntryFiles("html", opts.translator),
138
+ ...taglibDeps
139
+ ])
140
+ );
131
141
  const optimizeExtensions = optimizeDeps.extensions ?? (optimizeDeps.extensions = []);
132
142
  optimizeExtensions.push(".marko");
133
143
  const esbuildOptions = optimizeDeps.esbuildOptions ?? (optimizeDeps.esbuildOptions = {});
@@ -135,7 +145,11 @@ function markoPlugin(opts = {}) {
135
145
  esbuildPlugins.push(esbuildPlugin(compiler, baseConfig));
136
146
  const ssr = config.ssr ?? (config.ssr = {});
137
147
  if (ssr.noExternal !== true) {
138
- ssr.noExternal = Array.from(new Set(taglibDeps.concat(ssr.noExternal || [])));
148
+ ssr.noExternal = Array.from(
149
+ new Set(
150
+ taglibDeps.concat(ssr.noExternal || [])
151
+ )
152
+ );
139
153
  }
140
154
  },
141
155
  configureServer(_server) {
@@ -169,13 +183,20 @@ function markoPlugin(opts = {}) {
169
183
  const serverMetaFile = await getServerManifestFile(root);
170
184
  this.addWatchFile(serverMetaFile);
171
185
  try {
172
- serverManifest = JSON.parse(await fs.promises.readFile(serverMetaFile, "utf-8"));
186
+ serverManifest = JSON.parse(
187
+ await fs.promises.readFile(serverMetaFile, "utf-8")
188
+ );
173
189
  inputOptions.input = toHTMLEntries(root, serverManifest.entries);
174
190
  for (const entry in serverManifest.entrySources) {
175
- entrySources.set(path.resolve(root, entry), serverManifest.entrySources[entry]);
191
+ entrySources.set(
192
+ path.resolve(root, entry),
193
+ serverManifest.entrySources[entry]
194
+ );
176
195
  }
177
196
  } catch (err) {
178
- this.error(`You must run the "ssr" build before the "browser" build.`);
197
+ this.error(
198
+ `You must run the "ssr" build before the "browser" build.`
199
+ );
179
200
  }
180
201
  if (isEmpty(inputOptions.input)) {
181
202
  this.error("No Marko files were found when compiling the server.");
@@ -190,14 +211,17 @@ function markoPlugin(opts = {}) {
190
211
  let importeeQuery = getMarkoQuery(importee);
191
212
  if (importeeQuery) {
192
213
  importee = importee.slice(0, -importeeQuery.length);
193
- } else if (ssr && linked && importer && importer !== devEntryFile && isMarkoFile(importee) && !isMarkoFile(importer.replace(queryReg, ""))) {
214
+ } else if (ssr && linked && importer && importer !== devEntryFile && // Vite tries to resolve against an `index.html` in some cases, we ignore it here.
215
+ isMarkoFile(importee) && !isMarkoFile(importer.replace(queryReg, ""))) {
194
216
  importeeQuery = serverEntryQuery;
195
217
  } else if (!ssr && isBuild && importer && isMarkoFile(importee) && ((_a2 = this.getModuleInfo(importer)) == null ? void 0 : _a2.isEntry)) {
196
218
  importeeQuery = browserEntryQuery;
197
219
  }
198
220
  if (importeeQuery) {
199
221
  const resolved = importee[0] === "." ? {
200
- id: normalizePath(importer ? path.resolve(importer, "..", importee) : path.resolve(root, importee))
222
+ id: normalizePath(
223
+ importer ? path.resolve(importer, "..", importee) : path.resolve(root, importee)
224
+ )
201
225
  } : await this.resolve(importee, importer, resolveOpts);
202
226
  if (resolved) {
203
227
  resolved.id += importeeQuery;
@@ -235,7 +259,14 @@ function markoPlugin(opts = {}) {
235
259
  serverManifest.entries[entryId] = relativeFileName;
236
260
  entryData = JSON.stringify(entryId);
237
261
  } else {
238
- entryData = JSON.stringify(await generateDocManifest(await devServer.transformIndexHtml("/", generateInputDoc(fileNameToURL(fileName, root)))));
262
+ entryData = JSON.stringify(
263
+ await generateDocManifest(
264
+ await devServer.transformIndexHtml(
265
+ "/",
266
+ generateInputDoc(fileNameToURL(fileName, root))
267
+ )
268
+ )
269
+ );
239
270
  }
240
271
  return server_entry_template_default({
241
272
  fileName,
@@ -253,7 +284,10 @@ function markoPlugin(opts = {}) {
253
284
  if (isBuild) {
254
285
  return html;
255
286
  }
256
- return html.replace(/(src\s*=\s*(['"])(?:(?!\2).)*\.marko)(?:\?((?:(?!\2).)*))?\2/gim, (_, prefix, quote, query) => prefix + browserEntryQuery + (query ? "&" + query : "") + quote);
287
+ return html.replace(
288
+ /(src\s*=\s*(['"])(?:(?!\2).)*\.marko)(?:\?((?:(?!\2).)*))?\2/gim,
289
+ (_, prefix, quote, query) => prefix + browserEntryQuery + (query ? "&" + query : "") + quote
290
+ );
257
291
  },
258
292
  async transform(source, id, ssr) {
259
293
  const query = getMarkoQuery(id);
@@ -272,7 +306,11 @@ function markoPlugin(opts = {}) {
272
306
  serverManifest.entrySources[path.relative(root, id)] = source;
273
307
  }
274
308
  }
275
- const compiled = await compiler.compile(source, id, (typeof ssr === "object" ? ssr.ssr : ssr) ? ssrConfig : query === browserEntryQuery ? hydrateConfig : domConfig);
309
+ const compiled = await compiler.compile(
310
+ source,
311
+ id,
312
+ (typeof ssr === "object" ? ssr.ssr : ssr) ? ssrConfig : query === browserEntryQuery ? hydrateConfig : domConfig
313
+ );
276
314
  const { map, meta } = compiled;
277
315
  let { code } = compiled;
278
316
  if (query !== browserEntryQuery && devServer) {
@@ -300,15 +338,20 @@ if (import.meta.hot) import.meta.hot.accept();`;
300
338
  name: "marko-vite:post",
301
339
  apply: "build",
302
340
  enforce: "post",
341
+ // We use a "post" plugin to allow us to read the final generated `.html` from vite.
303
342
  async generateBundle(outputOptions, bundle, isWrite) {
304
343
  if (!linked) {
305
344
  return;
306
345
  }
307
346
  if (!isWrite) {
308
- this.error(`Linked builds are currently only supported when in "write" mode.`);
347
+ this.error(
348
+ `Linked builds are currently only supported when in "write" mode.`
349
+ );
309
350
  }
310
351
  if (!serverManifest) {
311
- this.error("No Marko files were found when bundling the server in linked mode.");
352
+ this.error(
353
+ "No Marko files were found when bundling the server in linked mode."
354
+ );
312
355
  }
313
356
  if (isSSRBuild) {
314
357
  const dir = outputOptions.dir ? path.resolve(outputOptions.dir) : path.resolve(outputOptions.file, "..");
@@ -317,13 +360,18 @@ if (import.meta.hot) import.meta.hot.accept();`;
317
360
  if (chunk.type === "chunk") {
318
361
  for (const id in chunk.modules) {
319
362
  if (id === registeredTag) {
320
- serverManifest.chunksNeedingAssets.push(path.resolve(dir, fileName));
363
+ serverManifest.chunksNeedingAssets.push(
364
+ path.resolve(dir, fileName)
365
+ );
321
366
  break;
322
367
  }
323
368
  }
324
369
  }
325
370
  }
326
- await fs.promises.writeFile(await getServerManifestFile(root), JSON.stringify(serverManifest));
371
+ await fs.promises.writeFile(
372
+ await getServerManifestFile(root),
373
+ JSON.stringify(serverManifest)
374
+ );
327
375
  } else {
328
376
  const browserManifest = {};
329
377
  for (const entryId in serverManifest.entries) {
@@ -335,13 +383,19 @@ if (import.meta.hot) import.meta.hot.accept();`;
335
383
  chunk = bundle[chunkId];
336
384
  }
337
385
  if ((chunk == null ? void 0 : chunk.type) === "asset") {
338
- browserManifest[entryId] = await generateDocManifest(chunk.source.toString());
386
+ browserManifest[entryId] = await generateDocManifest(
387
+ chunk.source.toString()
388
+ );
339
389
  delete bundle[chunkId];
340
390
  } else {
341
- this.error(`Marko template had unexpected output from vite, ${fileName}`);
391
+ this.error(
392
+ `Marko template had unexpected output from vite, ${fileName}`
393
+ );
342
394
  }
343
395
  }
344
- const manifestStr = `;var __MARKO_MANIFEST__=${JSON.stringify(browserManifest)};
396
+ const manifestStr = `;var __MARKO_MANIFEST__=${JSON.stringify(
397
+ browserManifest
398
+ )};
345
399
  `;
346
400
  for (const fileName of serverManifest.chunksNeedingAssets) {
347
401
  await fs.promises.appendFile(fileName, manifestStr);
@@ -375,7 +429,10 @@ async function getServerManifestFile(root) {
375
429
  }
376
430
  function getTempDir(root) {
377
431
  return tempDir || (tempDir = (async () => {
378
- const dir = path.join(os.tmpdir(), `marko-vite-${crypto.createHash("SHA1").update(root).digest("hex")}`);
432
+ const dir = path.join(
433
+ os.tmpdir(),
434
+ `marko-vite-${crypto.createHash("SHA1").update(root).digest("hex")}`
435
+ );
379
436
  try {
380
437
  const stat = await fs.promises.stat(dir);
381
438
  if (stat.isDirectory()) {
@@ -392,14 +449,22 @@ function toEntryId(id) {
392
449
  const lastSepIndex = id.lastIndexOf(path.sep);
393
450
  let name = id.slice(lastSepIndex + 1, id.indexOf(".", lastSepIndex));
394
451
  if (name === "index" || name === "template") {
395
- name = id.slice(id.lastIndexOf(path.sep, lastSepIndex - 1) + 1, lastSepIndex);
452
+ name = id.slice(
453
+ id.lastIndexOf(path.sep, lastSepIndex - 1) + 1,
454
+ lastSepIndex
455
+ );
396
456
  }
397
457
  return `${name}_${crypto.createHash("SHA1").update(id).digest("base64").replace(/[/+]/g, "-").slice(0, 4)}`;
398
458
  }
399
459
  function fileNameToURL(fileName, root) {
400
- const relativeURL = path.posix.relative(pathToFileURL(root).pathname, pathToFileURL(fileName).pathname);
460
+ const relativeURL = path.posix.relative(
461
+ pathToFileURL(root).pathname,
462
+ pathToFileURL(fileName).pathname
463
+ );
401
464
  if (relativeURL[0] === ".") {
402
- throw new Error("@marko/vite: Entry templates must exist under the current root directory.");
465
+ throw new Error(
466
+ "@marko/vite: Entry templates must exist under the current root directory."
467
+ );
403
468
  }
404
469
  return `/${relativeURL}`;
405
470
  }
@@ -1,5 +1,5 @@
1
1
  import serialize from "./serializer";
2
- declare type SerializedOrNull = null | ReturnType<typeof serialize>;
2
+ type SerializedOrNull = null | ReturnType<typeof serialize>;
3
3
  export interface DocManifest {
4
4
  "head-prepend": SerializedOrNull;
5
5
  head: SerializedOrNull;
@@ -17,7 +17,14 @@ var __copyProps = (to, from, except, desc) => {
17
17
  }
18
18
  return to;
19
19
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
21
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
29
  var manifest_generator_exports = {};
23
30
  __export(manifest_generator_exports, {
@@ -32,30 +39,46 @@ var import_serializer = __toESM(require("./serializer"));
32
39
  const MARKER_COMMENT = "MARKO_VITE";
33
40
  function generateDocManifest(rawHtml) {
34
41
  return new Promise((resolve, reject) => {
35
- const parser = new import_htmlparser2.Parser(new import_domhandler.DomHandler(function(err, dom) {
36
- if (err) {
37
- return reject(err);
38
- }
39
- const htmlChildren = dom.find(isElement).childNodes;
40
- const headPrepend = [];
41
- const head = [];
42
- const bodyPrepend = [];
43
- const body = [];
44
- splitNodesByMarker(htmlChildren.find((node) => isElement(node) && node.tagName === "head").childNodes, headPrepend, head);
45
- splitNodesByMarker(htmlChildren.find((node) => isElement(node) && node.tagName === "body").childNodes, bodyPrepend, body);
46
- resolve({
47
- "head-prepend": serializeOrNull(headPrepend),
48
- head: serializeOrNull(head),
49
- "body-prepend": serializeOrNull(bodyPrepend),
50
- body: serializeOrNull(body)
51
- });
52
- }));
42
+ const parser = new import_htmlparser2.Parser(
43
+ new import_domhandler.DomHandler(function(err, dom) {
44
+ if (err) {
45
+ return reject(err);
46
+ }
47
+ const htmlChildren = dom.find(isElement).childNodes;
48
+ const headPrepend = [];
49
+ const head = [];
50
+ const bodyPrepend = [];
51
+ const body = [];
52
+ splitNodesByMarker(
53
+ htmlChildren.find(
54
+ (node) => isElement(node) && node.tagName === "head"
55
+ ).childNodes,
56
+ headPrepend,
57
+ head
58
+ );
59
+ splitNodesByMarker(
60
+ htmlChildren.find(
61
+ (node) => isElement(node) && node.tagName === "body"
62
+ ).childNodes,
63
+ bodyPrepend,
64
+ body
65
+ );
66
+ resolve({
67
+ "head-prepend": serializeOrNull(headPrepend),
68
+ head: serializeOrNull(head),
69
+ "body-prepend": serializeOrNull(bodyPrepend),
70
+ body: serializeOrNull(body)
71
+ });
72
+ })
73
+ );
53
74
  parser.write(rawHtml);
54
75
  parser.end();
55
76
  });
56
77
  }
57
78
  function generateInputDoc(entry) {
58
- return `<!DOCTYPE html><html><head><!--${MARKER_COMMENT}--></head><body><!--${MARKER_COMMENT}--><script async type="module" src=${JSON.stringify(entry)}><\/script></body></html>`;
79
+ return `<!DOCTYPE html><html><head><!--${MARKER_COMMENT}--></head><body><!--${MARKER_COMMENT}--><script async type="module" src=${JSON.stringify(
80
+ entry
81
+ )}></script></body></html>`;
59
82
  }
60
83
  function serializeOrNull(nodes) {
61
84
  const result = (0, import_serializer.default)(nodes);
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  generateDocManifest,
3
3
  generateInputDoc
4
- } from "./chunk-MPTD6LHF.mjs";
4
+ } from "./chunk-DSFBTWOA.mjs";
5
5
  import "./chunk-VL2HLMVE.mjs";
6
6
  export {
7
7
  generateDocManifest,
@@ -28,7 +28,16 @@ var render_assets_transform_default = (tag, t) => {
28
28
  body.pushContainer("body", renderAssetsCall(t, tagName));
29
29
  };
30
30
  function renderAssetsCall(t, slot) {
31
- return t.markoPlaceholder(t.callExpression(t.memberExpression(t.memberExpression(t.identifier("out"), t.identifier("global")), t.identifier("___viteRenderAssets")), [t.stringLiteral(slot)]), false);
31
+ return t.markoPlaceholder(
32
+ t.callExpression(
33
+ t.memberExpression(
34
+ t.memberExpression(t.identifier("out"), t.identifier("global")),
35
+ t.identifier("___viteRenderAssets")
36
+ ),
37
+ [t.stringLiteral(slot)]
38
+ ),
39
+ false
40
+ );
32
41
  }
33
42
  // Annotate the CommonJS export names for ESM import in node:
34
43
  0 && (module.exports = {});
@@ -6,7 +6,16 @@ var render_assets_transform_default = (tag, t) => {
6
6
  body.pushContainer("body", renderAssetsCall(t, tagName));
7
7
  };
8
8
  function renderAssetsCall(t, slot) {
9
- return t.markoPlaceholder(t.callExpression(t.memberExpression(t.memberExpression(t.identifier("out"), t.identifier("global")), t.identifier("___viteRenderAssets")), [t.stringLiteral(slot)]), false);
9
+ return t.markoPlaceholder(
10
+ t.callExpression(
11
+ t.memberExpression(
12
+ t.memberExpression(t.identifier("out"), t.identifier("global")),
13
+ t.identifier("___viteRenderAssets")
14
+ ),
15
+ [t.stringLiteral(slot)]
16
+ ),
17
+ false
18
+ );
10
19
  }
11
20
  export {
12
21
  render_assets_transform_default as default
@@ -17,7 +17,14 @@ var __copyProps = (to, from, except, desc) => {
17
17
  }
18
18
  return to;
19
19
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
21
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
29
  var server_entry_template_exports = {};
23
30
  __export(server_entry_template_exports, {
package/package.json CHANGED
@@ -1,47 +1,47 @@
1
1
  {
2
2
  "name": "@marko/vite",
3
3
  "description": "A Marko plugin for Vite",
4
- "version": "2.3.9",
4
+ "version": "2.3.10",
5
5
  "author": "Dylan Piercey <dpiercey@ebay.com>",
6
6
  "bugs": "https://github.com/marko-js/vite/issues",
7
7
  "dependencies": {
8
- "anymatch": "^3.1.2",
8
+ "anymatch": "^3.1.3",
9
9
  "domelementtype": "^2.3.0",
10
10
  "domhandler": "^5.0.3",
11
11
  "htmlparser2": "^8.0.1",
12
12
  "relative-import-path": "^1.0.0"
13
13
  },
14
14
  "devDependencies": {
15
- "@changesets/changelog-github": "^0.4.5",
16
- "@changesets/cli": "^2.23.1",
17
- "@marko/compiler": "^5.21.6",
15
+ "@changesets/changelog-github": "^0.4.8",
16
+ "@changesets/cli": "^2.26.0",
17
+ "@marko/compiler": "^5.23.0",
18
18
  "@marko/fixture-snapshots": "^2.1.7",
19
19
  "@marko/testing-library": "^6.1.2",
20
- "@types/jsdom": "^16.2.14",
21
- "@types/mocha": "^9.1.1",
22
- "@types/node": "^18.0.3",
20
+ "@types/jsdom": "^20.0.1",
21
+ "@types/mocha": "^10.0.1",
22
+ "@types/node": "^18.11.18",
23
23
  "@types/serve-handler": "^6.1.1",
24
- "@typescript-eslint/eslint-plugin": "^5.30.6",
25
- "@typescript-eslint/parser": "^5.30.6",
24
+ "@typescript-eslint/eslint-plugin": "^5.48.0",
25
+ "@typescript-eslint/parser": "^5.48.0",
26
26
  "cross-env": "^7.0.3",
27
- "esbuild": "^0.14.49",
28
- "eslint": "^8.19.0",
29
- "eslint-config-prettier": "^8.5.0",
30
- "fast-glob": "^3.2.11",
27
+ "esbuild": "^0.16.14",
28
+ "eslint": "^8.31.0",
29
+ "eslint-config-prettier": "^8.6.0",
30
+ "fast-glob": "^3.2.12",
31
31
  "fixpack": "^4.0.0",
32
- "husky": "^8.0.1",
33
- "jsdom": "^19.0.0",
34
- "lint-staged": "^13.0.3",
35
- "marko": "^5.21.2",
36
- "mocha": "^10.0.0",
32
+ "husky": "^8.0.3",
33
+ "jsdom": "^20.0.3",
34
+ "lint-staged": "^13.1.0",
35
+ "marko": "^5.22.0",
36
+ "mocha": "^10.2.0",
37
37
  "mocha-snap": "^4.3.0",
38
38
  "nyc": "^15.1.0",
39
- "playwright": "^1.23.2",
40
- "prettier": "^2.7.1",
41
- "serve-handler": "^6.1.3",
42
- "tsx": "^3.7.1",
43
- "typescript": "^4.7.4",
44
- "vite": "3.0.0-beta.10"
39
+ "playwright": "^1.29.1",
40
+ "prettier": "^2.8.1",
41
+ "serve-handler": "^6.1.5",
42
+ "tsx": "^3.12.1",
43
+ "typescript": "^4.9.4",
44
+ "vite": "^4.0.4"
45
45
  },
46
46
  "exports": {
47
47
  ".": {
@@ -69,7 +69,7 @@
69
69
  "module": "./dist/index.mjs",
70
70
  "peerDependencies": {
71
71
  "@marko/compiler": "^5",
72
- "vite": "^2 || ^3"
72
+ "vite": "^2 || ^3 || ^4"
73
73
  },
74
74
  "repository": {
75
75
  "type": "git",