@marko/vite 3.1.5 → 4.0.0

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 (46) hide show
  1. package/README.md +0 -20
  2. package/dist/index.d.ts +3 -4
  3. package/dist/index.mjs +674 -103
  4. package/dist/manifest-generator.d.ts +1 -1
  5. package/dist/read-once-persisted-store.d.ts +6 -0
  6. package/dist/render-assets-runtime.d.ts +6 -0
  7. package/dist/serializer.d.ts +1 -1
  8. package/dist/server-entry-template.d.ts +1 -1
  9. package/package.json +20 -30
  10. package/dist/babel-plugin-cjs-interop.js +0 -117
  11. package/dist/babel-plugin-cjs-interop.mjs +0 -7
  12. package/dist/chunk-2E5QX7AF.mjs +0 -83
  13. package/dist/chunk-4NVOXZG5.mjs +0 -93
  14. package/dist/chunk-6IJ5UJ3N.mjs +0 -29
  15. package/dist/chunk-DCBMHGK4.mjs +0 -20
  16. package/dist/chunk-FCWFM7VD.mjs +0 -63
  17. package/dist/chunk-HR4PYNIR.mjs +0 -85
  18. package/dist/chunk-KIYHBIE6.mjs +0 -0
  19. package/dist/chunk-NTHVNXFC.mjs +0 -104
  20. package/dist/chunk-XYEU3RSG.mjs +0 -61
  21. package/dist/components/vite.marko +0 -74
  22. package/dist/esbuild-plugin.js +0 -113
  23. package/dist/esbuild-plugin.mjs +0 -6
  24. package/dist/index.js +0 -687
  25. package/dist/manifest-generator.js +0 -113
  26. package/dist/manifest-generator.mjs +0 -9
  27. package/dist/render-assets-transform.js +0 -41
  28. package/dist/render-assets-transform.mjs +0 -22
  29. package/dist/resolve.js +0 -94
  30. package/dist/resolve.mjs +0 -8
  31. package/dist/serializer.js +0 -127
  32. package/dist/serializer.mjs +0 -6
  33. package/dist/server-entry-template.js +0 -57
  34. package/dist/server-entry-template.mjs +0 -6
  35. package/dist/store/file-store.d.ts +0 -11
  36. package/dist/store/file-store.js +0 -91
  37. package/dist/store/file-store.mjs +0 -6
  38. package/dist/store/index.d.ts +0 -3
  39. package/dist/store/index.js +0 -41
  40. package/dist/store/index.mjs +0 -11
  41. package/dist/store/memory-store.d.ts +0 -8
  42. package/dist/store/memory-store.js +0 -38
  43. package/dist/store/memory-store.mjs +0 -6
  44. package/dist/store/types.d.ts +0 -5
  45. package/dist/store/types.js +0 -16
  46. package/dist/store/types.mjs +0 -0
@@ -1,104 +0,0 @@
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(basePath, nodes, entries, 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
- let urlAttr;
30
- curString += `<${name}`;
31
- switch (tag.tagName) {
32
- case "script":
33
- parts.push(curString, 0 /* AssetAttrs */);
34
- urlAttr = "src";
35
- curString = "";
36
- break;
37
- case "style":
38
- parts.push(curString, 0 /* AssetAttrs */);
39
- curString = "";
40
- break;
41
- case "link":
42
- urlAttr = "href";
43
- if (tag.attribs.rel === "stylesheet" || tag.attribs.rel === "modulepreload" || tag.attribs.as === "style" || tag.attribs.as === "script") {
44
- parts.push(curString, 0 /* AssetAttrs */);
45
- curString = "";
46
- }
47
- break;
48
- }
49
- for (const attr of tag.attributes) {
50
- if (attr.value === "") {
51
- curString += ` ${attr.name}`;
52
- } else if (attr.name === urlAttr) {
53
- const id = stripBasePath(basePath, attr.value).replace(/^\.\//, "");
54
- if (tag.name === "script") {
55
- entries.push(id);
56
- }
57
- curString += ` ${attr.name}="`;
58
- parts.push(
59
- curString,
60
- 1 /* PublicPath */,
61
- id.replace(/"/g, "&#39;") + '"'
62
- );
63
- curString = "";
64
- } else {
65
- curString += ` ${attr.name}="${attr.value.replace(/"/g, "&#39;")}"`;
66
- }
67
- }
68
- curString += ">";
69
- if (tag.children.length) {
70
- parts.push(curString);
71
- serialize(basePath, tag.children, entries, parts);
72
- curString = parts.pop();
73
- }
74
- if (!voidElements.has(name)) {
75
- curString += `</${name}>`;
76
- }
77
- break;
78
- }
79
- case ElementType.Text: {
80
- const text = node.data;
81
- if (!/^\s*$/.test(text)) {
82
- curString += text;
83
- }
84
- break;
85
- }
86
- case ElementType.Comment:
87
- curString += `<!--${node.data}-->`;
88
- break;
89
- }
90
- }
91
- if (curString) {
92
- parts.push(curString);
93
- }
94
- return parts;
95
- }
96
- function stripBasePath(basePath, path) {
97
- if (path.startsWith(basePath))
98
- return path.slice(basePath.length);
99
- return path;
100
- }
101
-
102
- export {
103
- serialize
104
- };
@@ -1,61 +0,0 @@
1
- // src/resolve.ts
2
- import { exports } from "resolve.exports";
3
- import * as Resolve from "resolve";
4
- import path from "path";
5
- import fs from "fs";
6
- var exportsMainFile = `__package_exports__`;
7
- var modulePathReg = /^.*[/\\]node_modules[/\\](?:@[^/\\]+[/\\])?[^/\\]+[/\\]/;
8
- var cjsModuleLookup = /* @__PURE__ */ new Map();
9
- function isCJSModule(id) {
10
- var _a;
11
- const modulePath = (_a = modulePathReg.exec(id)) == null ? void 0 : _a[0];
12
- if (modulePath) {
13
- const pkgPath = modulePath + "package.json";
14
- let isCJS = cjsModuleLookup.get(pkgPath);
15
- if (isCJS === void 0) {
16
- try {
17
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
18
- isCJS = pkg.type !== "module" && !pkg.exports;
19
- } catch {
20
- isCJS = false;
21
- }
22
- cjsModuleLookup.set(pkgPath, isCJS);
23
- }
24
- return isCJS;
25
- }
26
- return false;
27
- }
28
- function resolve(id, from, extensions, conditions) {
29
- return Resolve.sync(id, {
30
- basedir: path.dirname(from),
31
- filename: from,
32
- pathFilter,
33
- packageFilter,
34
- extensions
35
- });
36
- function pathFilter(pkg, pkgFile, relativePath) {
37
- var _a;
38
- cjsModuleLookup.set(pkgFile, pkg.type !== "module" && !pkg.exports);
39
- if (pkg.exports) {
40
- return (_a = exports(
41
- pkg,
42
- relativePath === exportsMainFile ? "." : relativePath,
43
- {
44
- conditions
45
- }
46
- )) == null ? void 0 : _a[0];
47
- }
48
- return relativePath;
49
- }
50
- }
51
- function packageFilter(pkg) {
52
- if (pkg.exports) {
53
- pkg.main = exportsMainFile;
54
- }
55
- return pkg;
56
- }
57
-
58
- export {
59
- isCJSModule,
60
- resolve
61
- };
@@ -1,74 +0,0 @@
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
- if(this.___viteBasePath && !this.___flushedMBP && slot !== "head-prepend") {
11
- this.___flushedMBP = true;
12
-
13
- html += `<script${this.___viteInjectAttrs}>${
14
- this.___viteBaseVar
15
- }=${JSON.stringify(this.___viteBasePath)}</script>`
16
- }
17
-
18
- for (let i = lastWrittenEntry; i < writtenEntries; i++) {
19
- let entry = entries[i];
20
-
21
- if (typeof __MARKO_MANIFEST__ === "object") {
22
- entry = __MARKO_MANIFEST__[entry] || {};
23
- } else if (slot === "head") {
24
- // In dev mode we have is a list entries of the top level modules that need to be imported.
25
- // To avoid FOUC we will hide the page until all of these modules are loaded.
26
- const { entries } = entry;
27
- if (entries) {
28
- let sep = "";
29
- html += `<script${this.___viteInjectAttrs}>((root=document.documentElement)=>{`;
30
- html += "root.style.visibility='hidden';";
31
- html += "document.currentScript.remove();";
32
- html += "Promise.allSettled([";
33
-
34
- for (const id of entries) {
35
- html += `${sep}import(${JSON.stringify(this.___viteBasePath + id)})`;
36
- sep = ",";
37
- }
38
-
39
- html += "]).then(()=>{";
40
- html += "root.style.visibility='';";
41
- html +=
42
- "if(root.getAttribute('style')==='')root.removeAttribute('style')";
43
- html += "})})()</script>";
44
- }
45
- }
46
-
47
- const parts = entry[slot];
48
-
49
- if (parts) {
50
- for (const part of parts) {
51
- html +=
52
- part === 0 /** InjectType.AssetAttrs */
53
- ? this.___viteInjectAttrs
54
- : part === 1 /** InjectType.PublicPath */
55
- ? this.___viteBasePath
56
- : part;
57
- }
58
- }
59
- }
60
- }
61
-
62
- return html;
63
- }
64
- $ if (!out.global.___viteRenderAssets) {
65
- out.global.___viteInjectAttrs = out.global.cspNonce
66
- ? ` nonce="${out.global.cspNonce.replace(/"/g, "&#39;")}"`
67
- : "";
68
- out.global.___viteRenderAssets = renderAssets;
69
- out.global.___viteBasePath = input.base || import.meta.env.BASE_URL;
70
- }
71
-
72
- <__flush_here_and_after__>
73
- $!{out.global.___viteRenderAssets(input.slot)}
74
- </__flush_here_and_after__>
@@ -1,113 +0,0 @@
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(
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
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var esbuild_plugin_exports = {};
30
- __export(esbuild_plugin_exports, {
31
- default: () => esbuildPlugin
32
- });
33
- module.exports = __toCommonJS(esbuild_plugin_exports);
34
- var import_fs = __toESM(require("fs"));
35
- var import_path = __toESM(require("path"));
36
- const markoErrorRegExp = /^(.+?)(?:\((\d+)(?:\s*,\s*(\d+))?\))?: (.*)$/gm;
37
- function esbuildPlugin(compiler, config) {
38
- return {
39
- name: "marko",
40
- async setup(build) {
41
- var _a;
42
- const { platform = "browser" } = build.initialOptions;
43
- const isScan = (_a = build.initialOptions.plugins) == null ? void 0 : _a.some(
44
- (v) => v.name === "vite:dep-scan"
45
- );
46
- const virtualFiles = /* @__PURE__ */ new Map();
47
- const finalConfig = {
48
- ...config,
49
- output: isScan ? "hydrate" : platform === "browser" ? "dom" : "html",
50
- resolveVirtualDependency(from, dep) {
51
- virtualFiles.set(import_path.default.join(from, "..", dep.virtualPath), dep);
52
- return dep.virtualPath;
53
- }
54
- };
55
- build.onResolve({ filter: /\.marko\./ }, (args) => {
56
- return {
57
- namespace: "marko:virtual",
58
- path: import_path.default.resolve(args.resolveDir, args.path)
59
- };
60
- });
61
- build.onLoad(
62
- { filter: /\.marko\./, namespace: "marko:virtual" },
63
- (args) => ({
64
- contents: virtualFiles.get(args.path).code,
65
- loader: import_path.default.extname(args.path).slice(1),
66
- external: isScan
67
- })
68
- );
69
- build.onLoad({ filter: /\.marko$/ }, async (args) => {
70
- try {
71
- const { code, meta } = await compiler.compileFile(
72
- args.path,
73
- finalConfig
74
- );
75
- return {
76
- loader: "js",
77
- contents: code,
78
- watchFiles: meta.watchFiles,
79
- resolveDir: import_path.default.dirname(args.path)
80
- };
81
- } catch (e) {
82
- const text = e.message;
83
- const errors = [];
84
- let match;
85
- let lines;
86
- while (match = markoErrorRegExp.exec(text)) {
87
- const [, file, rawLine, rawCol, text2] = match;
88
- const line = parseInt(rawLine, 10) || 1;
89
- const column = parseInt(rawCol, 10) || 1;
90
- lines || (lines = (await import_fs.default.promises.readFile(args.path, "utf-8")).split(
91
- /\n/g
92
- ));
93
- errors.push({
94
- text: text2,
95
- location: {
96
- file,
97
- line,
98
- column,
99
- lineText: ` ${lines[line - 1]}`
100
- }
101
- });
102
- }
103
- if (!errors.length) {
104
- errors.push({ text });
105
- }
106
- return {
107
- errors
108
- };
109
- }
110
- });
111
- }
112
- };
113
- }
@@ -1,6 +0,0 @@
1
- import {
2
- esbuildPlugin
3
- } from "./chunk-HR4PYNIR.mjs";
4
- export {
5
- esbuildPlugin as default
6
- };