@marko/vite 2.0.0 → 2.0.3

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/LICENSE +1 -1
  2. package/dist/chunk-HWRQJHCN.mjs +22 -0
  3. package/dist/chunk-MPTD6LHF.mjs +65 -0
  4. package/dist/chunk-VL2HLMVE.mjs +80 -0
  5. package/dist/chunk-Z64RCGRQ.mjs +74 -0
  6. package/dist/components/vite.marko +34 -0
  7. package/dist/esbuild-plugin.d.ts +3 -0
  8. package/dist/esbuild-plugin.js +97 -0
  9. package/dist/esbuild-plugin.mjs +6 -0
  10. package/dist/{cjs/index.d.ts → index.d.ts} +1 -1
  11. package/dist/index.js +416 -0
  12. package/dist/index.mjs +400 -0
  13. package/dist/{cjs/manifest-generator.d.ts → manifest-generator.d.ts} +0 -0
  14. package/dist/manifest-generator.js +88 -0
  15. package/dist/manifest-generator.mjs +9 -0
  16. package/dist/{cjs/render-assets-transform.d.ts → render-assets-transform.d.ts} +0 -0
  17. package/dist/render-assets-transform.js +34 -0
  18. package/dist/render-assets-transform.mjs +13 -0
  19. package/dist/{cjs/serializer.d.ts → serializer.d.ts} +0 -0
  20. package/dist/serializer.js +100 -0
  21. package/dist/serializer.mjs +6 -0
  22. package/dist/{cjs/server-entry-template.d.ts → server-entry-template.d.ts} +0 -0
  23. package/dist/server-entry-template.js +45 -0
  24. package/dist/server-entry-template.mjs +6 -0
  25. package/package.json +62 -45
  26. package/CHANGELOG.md +0 -72
  27. package/components/vite-watch.marko +0 -31
  28. package/components/vite.marko +0 -31
  29. package/dist/cjs/esbuild-plugin.d.ts +0 -0
  30. package/dist/cjs/esbuild-plugin.js +0 -2
  31. package/dist/cjs/esbuild-plugin.js.map +0 -1
  32. package/dist/cjs/index.js +0 -417
  33. package/dist/cjs/index.js.map +0 -1
  34. package/dist/cjs/manifest-generator.js +0 -63
  35. package/dist/cjs/manifest-generator.js.map +0 -1
  36. package/dist/cjs/render-assets-transform.js +0 -12
  37. package/dist/cjs/render-assets-transform.js.map +0 -1
  38. package/dist/cjs/serializer.js +0 -81
  39. package/dist/cjs/serializer.js.map +0 -1
  40. package/dist/cjs/server-entry-template.js +0 -22
  41. package/dist/cjs/server-entry-template.js.map +0 -1
  42. package/dist/esm/esbuild-plugin.d.ts +0 -0
  43. package/dist/esm/esbuild-plugin.js +0 -2
  44. package/dist/esm/esbuild-plugin.js.map +0 -1
  45. package/dist/esm/index.d.ts +0 -10
  46. package/dist/esm/index.js +0 -413
  47. package/dist/esm/index.js.map +0 -1
  48. package/dist/esm/manifest-generator.d.ts +0 -11
  49. package/dist/esm/manifest-generator.js +0 -57
  50. package/dist/esm/manifest-generator.js.map +0 -1
  51. package/dist/esm/render-assets-transform.d.ts +0 -3
  52. package/dist/esm/render-assets-transform.js +0 -10
  53. package/dist/esm/render-assets-transform.js.map +0 -1
  54. package/dist/esm/serializer.d.ts +0 -2
  55. package/dist/esm/serializer.js +0 -78
  56. package/dist/esm/serializer.js.map +0 -1
  57. package/dist/esm/server-entry-template.d.ts +0 -6
  58. package/dist/esm/server-entry-template.js +0 -19
  59. package/dist/esm/server-entry-template.js.map +0 -1
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 eBay Inc. and contributors
3
+ Copyright (c) 2022 eBay Inc. and contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,22 @@
1
+ // src/server-entry-template.ts
2
+ import path from "path";
3
+ var server_entry_template_default = async (opts) => {
4
+ const fileNameStr = JSON.stringify(`./${path.basename(opts.fileName)}`);
5
+ return `import template from ${fileNameStr};
6
+ export * from ${fileNameStr};
7
+ $ const $global = out.global;
8
+ ${opts.runtimeId ? `$ $global.runtimeId = ${JSON.stringify(opts.runtimeId)};
9
+ ` : ""}$ ($global.___viteEntries || ($global.___viteEntries = [])).push(${opts.entryData});
10
+ <_vite slot="head-prepend"/>
11
+ <_vite slot="head"/>
12
+ <_vite slot="body-prepend"/>
13
+ <\${template} ...input/>
14
+ <init-components/>
15
+ <await-reorderer/>
16
+ <_vite slot="body"/>
17
+ `;
18
+ };
19
+
20
+ export {
21
+ server_entry_template_default
22
+ };
@@ -0,0 +1,65 @@
1
+ import {
2
+ serialize
3
+ } from "./chunk-VL2HLMVE.mjs";
4
+
5
+ // src/manifest-generator.ts
6
+ import { Parser } from "htmlparser2";
7
+ import { ElementType } from "domelementtype";
8
+ import { DomHandler } from "domhandler";
9
+ var MARKER_COMMENT = "MARKO_VITE";
10
+ function generateDocManifest(rawHtml) {
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
+ }));
30
+ parser.write(rawHtml);
31
+ parser.end();
32
+ });
33
+ }
34
+ 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>`;
36
+ }
37
+ function serializeOrNull(nodes) {
38
+ const result = serialize(nodes);
39
+ if (result.length) {
40
+ return result;
41
+ }
42
+ return null;
43
+ }
44
+ function splitNodesByMarker(nodes, before, after) {
45
+ for (let i = 0; i < nodes.length; i++) {
46
+ let node = nodes[i];
47
+ if (node.data === MARKER_COMMENT) {
48
+ i++;
49
+ for (; i < nodes.length; i++) {
50
+ node = nodes[i];
51
+ after.push(node);
52
+ }
53
+ break;
54
+ }
55
+ before.push(node);
56
+ }
57
+ }
58
+ function isElement(node) {
59
+ return node.type === ElementType.Tag;
60
+ }
61
+
62
+ export {
63
+ generateDocManifest,
64
+ generateInputDoc
65
+ };
@@ -0,0 +1,80 @@
1
+ // src/serializer.ts
2
+ import { ElementType } from "domelementtype";
3
+ var voidElements = /* @__PURE__ */ new Set([
4
+ "area",
5
+ "base",
6
+ "br",
7
+ "col",
8
+ "embed",
9
+ "hr",
10
+ "img",
11
+ "input",
12
+ "link",
13
+ "meta",
14
+ "param",
15
+ "source",
16
+ "track",
17
+ "wbr"
18
+ ]);
19
+ function serialize(nodes, parts) {
20
+ let curString = parts ? parts.pop() : "";
21
+ parts ?? (parts = []);
22
+ for (const node of nodes) {
23
+ switch (node.type) {
24
+ case ElementType.Tag:
25
+ case ElementType.Style:
26
+ case ElementType.Script: {
27
+ const tag = node;
28
+ const { name } = tag;
29
+ curString += `<${name}`;
30
+ switch (tag.tagName) {
31
+ case "script":
32
+ parts.push(curString);
33
+ curString = "";
34
+ break;
35
+ case "style":
36
+ parts.push(curString);
37
+ curString = "";
38
+ break;
39
+ case "link":
40
+ if (tag.attribs.rel === "stylesheet") {
41
+ parts.push(curString);
42
+ curString = "";
43
+ }
44
+ break;
45
+ }
46
+ for (const attr of tag.attributes) {
47
+ curString += ` ${attr.value === "" ? attr.name : `${attr.name}="${attr.value.replace(/"/g, "&#39;")}"`}`;
48
+ }
49
+ curString += ">";
50
+ if (tag.children.length) {
51
+ parts.push(curString);
52
+ serialize(tag.children, parts);
53
+ curString = parts.pop();
54
+ }
55
+ if (!voidElements.has(name)) {
56
+ curString += `</${name}>`;
57
+ }
58
+ break;
59
+ }
60
+ case ElementType.Text: {
61
+ const text = node.data;
62
+ if (!/^\s*$/.test(text)) {
63
+ curString += text;
64
+ }
65
+ break;
66
+ }
67
+ case ElementType.Comment:
68
+ curString += `<!--${node.data}-->`;
69
+ break;
70
+ }
71
+ }
72
+ if (curString) {
73
+ parts.push(curString);
74
+ }
75
+ return parts;
76
+ }
77
+
78
+ export {
79
+ serialize
80
+ };
@@ -0,0 +1,74 @@
1
+ // src/esbuild-plugin.ts
2
+ import fs from "fs";
3
+ import path from "path";
4
+ var markoErrorRegExp = /^(.+?)(?:\((\d+)(?:\s*,\s*(\d+))?\))?: (.*)$/gm;
5
+ function esbuildPlugin(compiler, config) {
6
+ return {
7
+ name: "marko",
8
+ async setup(build) {
9
+ const { platform = "browser" } = build.initialOptions;
10
+ const virtualFiles = /* @__PURE__ */ new Map();
11
+ const finalConfig = {
12
+ ...config,
13
+ output: platform === "browser" ? "dom" : "html",
14
+ resolveVirtualDependency(from, dep) {
15
+ virtualFiles.set(path.join(from, "..", dep.virtualPath), dep);
16
+ return dep.virtualPath;
17
+ }
18
+ };
19
+ if (platform === "browser") {
20
+ build.onResolve({ filter: /\.marko\./ }, (args) => {
21
+ return {
22
+ namespace: "marko:virtual",
23
+ path: path.resolve(args.resolveDir, args.path)
24
+ };
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
+ }));
30
+ }
31
+ build.onLoad({ filter: /\.marko$/ }, async (args) => {
32
+ try {
33
+ const { code, meta } = await compiler.compileFile(args.path, finalConfig);
34
+ return {
35
+ loader: "js",
36
+ contents: code,
37
+ watchFiles: meta.watchFiles,
38
+ resolveDir: path.dirname(args.path)
39
+ };
40
+ } catch (e) {
41
+ const text = e.message;
42
+ const errors = [];
43
+ let match;
44
+ let lines;
45
+ while (match = markoErrorRegExp.exec(text)) {
46
+ const [, file, rawLine, rawCol, text2] = match;
47
+ const line = parseInt(rawLine, 10) || 1;
48
+ const column = parseInt(rawCol, 10) || 1;
49
+ lines || (lines = (await fs.promises.readFile(args.path, "utf-8")).split(/\n/g));
50
+ errors.push({
51
+ text: text2,
52
+ location: {
53
+ file,
54
+ line,
55
+ column,
56
+ lineText: ` ${lines[line - 1]}`
57
+ }
58
+ });
59
+ }
60
+ if (!errors.length) {
61
+ errors.push({ text });
62
+ }
63
+ return {
64
+ errors
65
+ };
66
+ }
67
+ });
68
+ }
69
+ };
70
+ }
71
+
72
+ export {
73
+ esbuildPlugin
74
+ };
@@ -0,0 +1,34 @@
1
+ static function renderAssets(slot) {
2
+ const entries = this.___viteEntries;
3
+ let html = "";
4
+
5
+ if (entries) {
6
+ const slotWrittenEntriesKey = `___viteWrittenEntries-${slot}`;
7
+ const lastWrittenEntry = this[slotWrittenEntriesKey] || 0;
8
+ const writtenEntries = (this[slotWrittenEntriesKey] = entries.length);
9
+
10
+ for (let i = lastWrittenEntry; i < writtenEntries; i++) {
11
+ const entry = entries[i];
12
+ const parts = typeof __MARKO_MANIFEST__ === "object"
13
+ ? __MARKO_MANIFEST__[entry]?.[slot]
14
+ : entry[slot];
15
+
16
+ if (parts) {
17
+ html += parts.join(this.___viteInjectAttrs);
18
+ }
19
+ }
20
+ }
21
+
22
+ return html;
23
+ }
24
+ $ const $global = out.global;
25
+ $ if (!$global.___viteRenderAssets) {
26
+ $global.___viteInjectAttrs = $global.cspNonce
27
+ ? ` nonce="${$global.cspNonce.replace(/"/g, "&#39;")}"`
28
+ : "";
29
+ $global.___viteRenderAssets = renderAssets;
30
+ }
31
+
32
+ <__flush_here_and_after__>
33
+ $!{$global.___viteRenderAssets(input.slot)}
34
+ </__flush_here_and_after__>
@@ -0,0 +1,3 @@
1
+ import type * as esbuild from "esbuild";
2
+ import type * as Compiler from "@marko/compiler";
3
+ export default function esbuildPlugin(compiler: typeof Compiler, config: Compiler.Config): esbuild.Plugin;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
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));
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var esbuild_plugin_exports = {};
23
+ __export(esbuild_plugin_exports, {
24
+ default: () => esbuildPlugin
25
+ });
26
+ module.exports = __toCommonJS(esbuild_plugin_exports);
27
+ var import_fs = __toESM(require("fs"));
28
+ var import_path = __toESM(require("path"));
29
+ const markoErrorRegExp = /^(.+?)(?:\((\d+)(?:\s*,\s*(\d+))?\))?: (.*)$/gm;
30
+ function esbuildPlugin(compiler, config) {
31
+ return {
32
+ name: "marko",
33
+ async setup(build) {
34
+ const { platform = "browser" } = build.initialOptions;
35
+ const virtualFiles = /* @__PURE__ */ new Map();
36
+ const finalConfig = {
37
+ ...config,
38
+ output: platform === "browser" ? "dom" : "html",
39
+ resolveVirtualDependency(from, dep) {
40
+ virtualFiles.set(import_path.default.join(from, "..", dep.virtualPath), dep);
41
+ return dep.virtualPath;
42
+ }
43
+ };
44
+ if (platform === "browser") {
45
+ build.onResolve({ filter: /\.marko\./ }, (args) => {
46
+ return {
47
+ namespace: "marko:virtual",
48
+ path: import_path.default.resolve(args.resolveDir, args.path)
49
+ };
50
+ });
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
+ }));
55
+ }
56
+ build.onLoad({ filter: /\.marko$/ }, async (args) => {
57
+ try {
58
+ const { code, meta } = await compiler.compileFile(args.path, finalConfig);
59
+ return {
60
+ loader: "js",
61
+ contents: code,
62
+ watchFiles: meta.watchFiles,
63
+ resolveDir: import_path.default.dirname(args.path)
64
+ };
65
+ } catch (e) {
66
+ const text = e.message;
67
+ const errors = [];
68
+ let match;
69
+ let lines;
70
+ while (match = markoErrorRegExp.exec(text)) {
71
+ const [, file, rawLine, rawCol, text2] = match;
72
+ const line = parseInt(rawLine, 10) || 1;
73
+ const column = parseInt(rawCol, 10) || 1;
74
+ lines || (lines = (await import_fs.default.promises.readFile(args.path, "utf-8")).split(/\n/g));
75
+ errors.push({
76
+ text: text2,
77
+ location: {
78
+ file,
79
+ line,
80
+ column,
81
+ lineText: ` ${lines[line - 1]}`
82
+ }
83
+ });
84
+ }
85
+ if (!errors.length) {
86
+ errors.push({ text });
87
+ }
88
+ return {
89
+ errors
90
+ };
91
+ }
92
+ });
93
+ }
94
+ };
95
+ }
96
+ // Annotate the CommonJS export names for ESM import in node:
97
+ 0 && (module.exports = {});
@@ -0,0 +1,6 @@
1
+ import {
2
+ esbuildPlugin
3
+ } from "./chunk-Z64RCGRQ.mjs";
4
+ export {
5
+ esbuildPlugin as default
6
+ };
@@ -1,4 +1,4 @@
1
- import * as vite from "vite";
1
+ import type * as vite from "vite";
2
2
  import type * as Compiler from "@marko/compiler";
3
3
  export interface Options {
4
4
  linked?: boolean;