@marko/vite 2.3.9 → 2.3.11
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.
- package/README.md +20 -0
- package/dist/chunk-DCBMHGK4.mjs +20 -0
- package/dist/{chunk-MPTD6LHF.mjs → chunk-DSFBTWOA.mjs} +35 -19
- package/dist/chunk-FCWFM7VD.mjs +63 -0
- package/dist/chunk-KIYHBIE6.mjs +0 -0
- package/dist/{chunk-Z64RCGRQ.mjs → chunk-KRSZ5IRT.mjs} +14 -6
- package/dist/esbuild-plugin.js +22 -7
- package/dist/esbuild-plugin.mjs +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +103 -51
- package/dist/index.mjs +103 -52
- package/dist/manifest-generator.d.ts +1 -1
- package/dist/manifest-generator.js +43 -20
- package/dist/manifest-generator.mjs +1 -1
- package/dist/render-assets-transform.js +10 -1
- package/dist/render-assets-transform.mjs +10 -1
- package/dist/server-entry-template.js +8 -1
- package/dist/store/file-store.d.ts +11 -0
- package/dist/store/file-store.js +93 -0
- package/dist/store/file-store.mjs +6 -0
- package/dist/store/index.d.ts +3 -0
- package/dist/store/index.js +41 -0
- package/dist/store/index.mjs +11 -0
- package/dist/store/memory-store.d.ts +8 -0
- package/dist/store/memory-store.js +40 -0
- package/dist/store/memory-store.mjs +6 -0
- package/dist/store/types.d.ts +5 -0
- package/dist/store/types.js +16 -0
- package/dist/store/types.mjs +0 -0
- package/package.json +26 -26
package/README.md
CHANGED
|
@@ -118,6 +118,26 @@ marko({ runtimeId: "MY_MARKO_RUNTIME_ID" });
|
|
|
118
118
|
|
|
119
119
|
Set this to `false` to opt out of [linked mode](#linked-mode). When this is false, the plugin will only handle resolving and transforming `.marko` files.
|
|
120
120
|
|
|
121
|
+
### options.store
|
|
122
|
+
|
|
123
|
+
Storage mechanism to preserve data between SSR and client builds when building in linked mode. Two implementations are available:
|
|
124
|
+
|
|
125
|
+
- FileStore _(default)_
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
import { FileStore } from "@marko/vite";
|
|
129
|
+
const store = new FileStore();
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Reads/writes data to the file system. Use this when running the SSR and client builds in seperate processes such as when using Vite from the command line or npm scripts.
|
|
133
|
+
|
|
134
|
+
- MemoryStore
|
|
135
|
+
```js
|
|
136
|
+
import { MemoryStore } from "@marko/vite";
|
|
137
|
+
const store = new MemoryStore();
|
|
138
|
+
```
|
|
139
|
+
Reads/writes data to memory. This option can be used when building with Vite programatically.
|
|
140
|
+
|
|
121
141
|
## Code of Conduct
|
|
122
142
|
|
|
123
143
|
This project adheres to the [eBay Code of Conduct](./.github/CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/store/memory-store.ts
|
|
2
|
+
var MemoryStore = class {
|
|
3
|
+
_store;
|
|
4
|
+
constructor() {
|
|
5
|
+
this._store = /* @__PURE__ */ new Map();
|
|
6
|
+
}
|
|
7
|
+
async has(key) {
|
|
8
|
+
return Promise.resolve(this._store.has(key));
|
|
9
|
+
}
|
|
10
|
+
async get(key) {
|
|
11
|
+
return Promise.resolve(this._store.get(key));
|
|
12
|
+
}
|
|
13
|
+
async set(key, value) {
|
|
14
|
+
this._store.set(key, value);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
MemoryStore
|
|
20
|
+
};
|
|
@@ -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(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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(
|
|
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);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/store/file-store.ts
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import os from "os";
|
|
5
|
+
var FileStore = class {
|
|
6
|
+
_id;
|
|
7
|
+
_temp;
|
|
8
|
+
_cache;
|
|
9
|
+
constructor(id) {
|
|
10
|
+
this._id = id;
|
|
11
|
+
this._cache = /* @__PURE__ */ new Map();
|
|
12
|
+
}
|
|
13
|
+
async _getKeyPath(key) {
|
|
14
|
+
this._temp ?? (this._temp = getTempDir(this._id));
|
|
15
|
+
return path.join(await this._temp, key);
|
|
16
|
+
}
|
|
17
|
+
async has(key) {
|
|
18
|
+
if (!this._cache.has(key)) {
|
|
19
|
+
const path2 = await this._getKeyPath(key);
|
|
20
|
+
try {
|
|
21
|
+
await fs.promises.access(path2);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
async get(key) {
|
|
29
|
+
let value = this._cache.get(key);
|
|
30
|
+
if (value === void 0) {
|
|
31
|
+
const path2 = await this._getKeyPath(key);
|
|
32
|
+
try {
|
|
33
|
+
value = await fs.promises.readFile(path2, "utf-8");
|
|
34
|
+
} catch (e) {
|
|
35
|
+
return void 0;
|
|
36
|
+
}
|
|
37
|
+
this._cache.set(key, value);
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
async set(key, value) {
|
|
42
|
+
this._cache.set(key, value);
|
|
43
|
+
const path2 = await this._getKeyPath(key);
|
|
44
|
+
await fs.promises.writeFile(path2, value, "utf-8");
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
async function getTempDir(id) {
|
|
48
|
+
const dir = path.join(os.tmpdir(), id);
|
|
49
|
+
try {
|
|
50
|
+
const stat = await fs.promises.stat(dir);
|
|
51
|
+
if (stat.isDirectory()) {
|
|
52
|
+
return dir;
|
|
53
|
+
}
|
|
54
|
+
} catch {
|
|
55
|
+
await fs.promises.mkdir(dir);
|
|
56
|
+
return dir;
|
|
57
|
+
}
|
|
58
|
+
throw new Error("Unable to create temp directory");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
FileStore
|
|
63
|
+
};
|
|
File without changes
|
|
@@ -23,14 +23,20 @@ function esbuildPlugin(compiler, config) {
|
|
|
23
23
|
path: path.resolve(args.resolveDir, args.path)
|
|
24
24
|
};
|
|
25
25
|
});
|
|
26
|
-
build.onLoad(
|
|
27
|
-
|
|
28
|
-
|
|
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(
|
|
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(
|
|
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: {
|
package/dist/esbuild-plugin.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(
|
|
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(
|
|
52
|
-
|
|
53
|
-
|
|
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(
|
|
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(
|
|
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: {
|
package/dist/esbuild-plugin.mjs
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type * as vite from "vite";
|
|
2
2
|
import type * as Compiler from "@marko/compiler";
|
|
3
|
+
import { BuildStore } from "./store";
|
|
4
|
+
export * from "./store";
|
|
5
|
+
export type { BuildStore } from "./store";
|
|
3
6
|
export interface Options {
|
|
4
7
|
linked?: boolean;
|
|
5
8
|
compiler?: string;
|
|
6
9
|
runtimeId?: string;
|
|
7
10
|
translator?: string;
|
|
8
11
|
babelConfig?: Compiler.Config["babelConfig"];
|
|
12
|
+
store?: BuildStore;
|
|
9
13
|
}
|
|
10
14
|
export default function markoPlugin(opts?: Options): vite.Plugin[];
|
package/dist/index.js
CHANGED
|
@@ -17,14 +17,21 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
21
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
30
|
var src_exports = {};
|
|
23
31
|
__export(src_exports, {
|
|
24
32
|
default: () => markoPlugin
|
|
25
33
|
});
|
|
26
34
|
module.exports = __toCommonJS(src_exports);
|
|
27
|
-
var import_os = __toESM(require("os"));
|
|
28
35
|
var import_fs = __toESM(require("fs"));
|
|
29
36
|
var import_path = __toESM(require("path"));
|
|
30
37
|
var import_crypto = __toESM(require("crypto"));
|
|
@@ -34,6 +41,8 @@ var import_relative_import_path = require("relative-import-path");
|
|
|
34
41
|
var import_server_entry_template = __toESM(require("./server-entry-template"));
|
|
35
42
|
var import_manifest_generator = require("./manifest-generator");
|
|
36
43
|
var import_esbuild_plugin = __toESM(require("./esbuild-plugin"));
|
|
44
|
+
var import_store = require("./store");
|
|
45
|
+
__reExport(src_exports, require("./store"), module.exports);
|
|
37
46
|
const import_meta = {};
|
|
38
47
|
const normalizePath = import_path.default.sep === "\\" ? (id) => id.replace(/\\/g, "/") : (id) => id;
|
|
39
48
|
const virtualFiles = /* @__PURE__ */ new Map();
|
|
@@ -41,12 +50,12 @@ const queryReg = /\?marko-.+$/;
|
|
|
41
50
|
const browserEntryQuery = "?marko-browser-entry";
|
|
42
51
|
const serverEntryQuery = "?marko-server-entry";
|
|
43
52
|
const virtualFileQuery = "?marko-virtual";
|
|
53
|
+
const manifestFileName = "manifest.json";
|
|
44
54
|
const markoExt = ".marko";
|
|
45
55
|
const htmlExt = ".html";
|
|
46
56
|
const resolveOpts = { skipSelf: true };
|
|
47
57
|
const cache = /* @__PURE__ */ new Map();
|
|
48
58
|
const thisFile = typeof __filename === "string" ? __filename : (0, import_url.fileURLToPath)(import_meta.url);
|
|
49
|
-
let tempDir;
|
|
50
59
|
function markoPlugin(opts = {}) {
|
|
51
60
|
var _a;
|
|
52
61
|
let compiler;
|
|
@@ -74,7 +83,9 @@ function markoPlugin(opts = {}) {
|
|
|
74
83
|
if (devServer) {
|
|
75
84
|
const prev = virtualFiles.get(id);
|
|
76
85
|
if (prev && prev.code !== dep.code) {
|
|
77
|
-
devServer.moduleGraph.invalidateModule(
|
|
86
|
+
devServer.moduleGraph.invalidateModule(
|
|
87
|
+
devServer.moduleGraph.getModuleById(id)
|
|
88
|
+
);
|
|
78
89
|
}
|
|
79
90
|
}
|
|
80
91
|
virtualFiles.set(id, dep);
|
|
@@ -102,6 +113,7 @@ function markoPlugin(opts = {}) {
|
|
|
102
113
|
let devServer;
|
|
103
114
|
let registeredTag = false;
|
|
104
115
|
let serverManifest;
|
|
116
|
+
let store;
|
|
105
117
|
const entrySources = /* @__PURE__ */ new Map();
|
|
106
118
|
const transformWatchFiles = /* @__PURE__ */ new Map();
|
|
107
119
|
const transformOptionalFiles = /* @__PURE__ */ new Map();
|
|
@@ -109,15 +121,24 @@ function markoPlugin(opts = {}) {
|
|
|
109
121
|
{
|
|
110
122
|
name: "marko-vite:pre",
|
|
111
123
|
enforce: "pre",
|
|
124
|
+
// Must be pre to allow us to resolve assets before vite.
|
|
112
125
|
async config(config, env) {
|
|
113
126
|
compiler ?? (compiler = await import(opts.compiler || "@marko/compiler"));
|
|
114
127
|
root = normalizePath(config.root || process.cwd());
|
|
115
128
|
devEntryFile = import_path.default.join(root, "index.html");
|
|
116
129
|
isBuild = env.command === "build";
|
|
117
130
|
isSSRBuild = isBuild && linked && Boolean(config.build.ssr);
|
|
131
|
+
store = opts.store || new import_store.FileStore(
|
|
132
|
+
`marko-vite-${import_crypto.default.createHash("SHA1").update(root).digest("hex")}`
|
|
133
|
+
);
|
|
118
134
|
if (linked && !registeredTag) {
|
|
119
|
-
const transformer = import_path.default.resolve(
|
|
120
|
-
|
|
135
|
+
const transformer = import_path.default.resolve(
|
|
136
|
+
thisFile,
|
|
137
|
+
"../render-assets-transform"
|
|
138
|
+
);
|
|
139
|
+
registeredTag = normalizePath(
|
|
140
|
+
import_path.default.resolve(thisFile, "../components", "vite.marko")
|
|
141
|
+
);
|
|
121
142
|
compiler.taglib.register("@marko/vite", {
|
|
122
143
|
"<_vite>": { template: registeredTag },
|
|
123
144
|
"<head>": { transformer },
|
|
@@ -139,12 +160,14 @@ function markoPlugin(opts = {}) {
|
|
|
139
160
|
}
|
|
140
161
|
}
|
|
141
162
|
const optimizeDeps = config.optimizeDeps ?? (config.optimizeDeps = {});
|
|
142
|
-
optimizeDeps.include = Array.from(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
163
|
+
optimizeDeps.include = Array.from(
|
|
164
|
+
/* @__PURE__ */ new Set([
|
|
165
|
+
...optimizeDeps.include || [],
|
|
166
|
+
...compiler.getRuntimeEntryFiles("dom", opts.translator),
|
|
167
|
+
...compiler.getRuntimeEntryFiles("html", opts.translator),
|
|
168
|
+
...taglibDeps
|
|
169
|
+
])
|
|
170
|
+
);
|
|
148
171
|
const optimizeExtensions = optimizeDeps.extensions ?? (optimizeDeps.extensions = []);
|
|
149
172
|
optimizeExtensions.push(".marko");
|
|
150
173
|
const esbuildOptions = optimizeDeps.esbuildOptions ?? (optimizeDeps.esbuildOptions = {});
|
|
@@ -152,7 +175,11 @@ function markoPlugin(opts = {}) {
|
|
|
152
175
|
esbuildPlugins.push((0, import_esbuild_plugin.default)(compiler, baseConfig));
|
|
153
176
|
const ssr = config.ssr ?? (config.ssr = {});
|
|
154
177
|
if (ssr.noExternal !== true) {
|
|
155
|
-
ssr.noExternal = Array.from(
|
|
178
|
+
ssr.noExternal = Array.from(
|
|
179
|
+
new Set(
|
|
180
|
+
taglibDeps.concat(ssr.noExternal || [])
|
|
181
|
+
)
|
|
182
|
+
);
|
|
156
183
|
}
|
|
157
184
|
},
|
|
158
185
|
configureServer(_server) {
|
|
@@ -183,16 +210,21 @@ function markoPlugin(opts = {}) {
|
|
|
183
210
|
},
|
|
184
211
|
async buildStart(inputOptions) {
|
|
185
212
|
if (isBuild && linked && !isSSRBuild) {
|
|
186
|
-
const serverMetaFile = await getServerManifestFile(root);
|
|
187
|
-
this.addWatchFile(serverMetaFile);
|
|
188
213
|
try {
|
|
189
|
-
serverManifest = JSON.parse(
|
|
214
|
+
serverManifest = JSON.parse(
|
|
215
|
+
await store.get(manifestFileName)
|
|
216
|
+
);
|
|
190
217
|
inputOptions.input = toHTMLEntries(root, serverManifest.entries);
|
|
191
218
|
for (const entry in serverManifest.entrySources) {
|
|
192
|
-
entrySources.set(
|
|
219
|
+
entrySources.set(
|
|
220
|
+
import_path.default.resolve(root, entry),
|
|
221
|
+
serverManifest.entrySources[entry]
|
|
222
|
+
);
|
|
193
223
|
}
|
|
194
224
|
} catch (err) {
|
|
195
|
-
this.error(
|
|
225
|
+
this.error(
|
|
226
|
+
`You must run the "ssr" build before the "browser" build.`
|
|
227
|
+
);
|
|
196
228
|
}
|
|
197
229
|
if (isEmpty(inputOptions.input)) {
|
|
198
230
|
this.error("No Marko files were found when compiling the server.");
|
|
@@ -207,14 +239,17 @@ function markoPlugin(opts = {}) {
|
|
|
207
239
|
let importeeQuery = getMarkoQuery(importee);
|
|
208
240
|
if (importeeQuery) {
|
|
209
241
|
importee = importee.slice(0, -importeeQuery.length);
|
|
210
|
-
} else if (ssr && linked && importer && importer !== devEntryFile &&
|
|
242
|
+
} else if (ssr && linked && importer && importer !== devEntryFile && // Vite tries to resolve against an `index.html` in some cases, we ignore it here.
|
|
243
|
+
isMarkoFile(importee) && !isMarkoFile(importer.replace(queryReg, ""))) {
|
|
211
244
|
importeeQuery = serverEntryQuery;
|
|
212
245
|
} else if (!ssr && isBuild && importer && isMarkoFile(importee) && ((_a2 = this.getModuleInfo(importer)) == null ? void 0 : _a2.isEntry)) {
|
|
213
246
|
importeeQuery = browserEntryQuery;
|
|
214
247
|
}
|
|
215
248
|
if (importeeQuery) {
|
|
216
249
|
const resolved = importee[0] === "." ? {
|
|
217
|
-
id: normalizePath(
|
|
250
|
+
id: normalizePath(
|
|
251
|
+
importer ? import_path.default.resolve(importer, "..", importee) : import_path.default.resolve(root, importee)
|
|
252
|
+
)
|
|
218
253
|
} : await this.resolve(importee, importer, resolveOpts);
|
|
219
254
|
if (resolved) {
|
|
220
255
|
resolved.id += importeeQuery;
|
|
@@ -252,7 +287,14 @@ function markoPlugin(opts = {}) {
|
|
|
252
287
|
serverManifest.entries[entryId] = relativeFileName;
|
|
253
288
|
entryData = JSON.stringify(entryId);
|
|
254
289
|
} else {
|
|
255
|
-
entryData = JSON.stringify(
|
|
290
|
+
entryData = JSON.stringify(
|
|
291
|
+
await (0, import_manifest_generator.generateDocManifest)(
|
|
292
|
+
await devServer.transformIndexHtml(
|
|
293
|
+
"/",
|
|
294
|
+
(0, import_manifest_generator.generateInputDoc)(fileNameToURL(fileName, root))
|
|
295
|
+
)
|
|
296
|
+
)
|
|
297
|
+
);
|
|
256
298
|
}
|
|
257
299
|
return (0, import_server_entry_template.default)({
|
|
258
300
|
fileName,
|
|
@@ -270,7 +312,10 @@ function markoPlugin(opts = {}) {
|
|
|
270
312
|
if (isBuild) {
|
|
271
313
|
return html;
|
|
272
314
|
}
|
|
273
|
-
return html.replace(
|
|
315
|
+
return html.replace(
|
|
316
|
+
/(src\s*=\s*(['"])(?:(?!\2).)*\.marko)(?:\?((?:(?!\2).)*))?\2/gim,
|
|
317
|
+
(_, prefix, quote, query) => prefix + browserEntryQuery + (query ? "&" + query : "") + quote
|
|
318
|
+
);
|
|
274
319
|
},
|
|
275
320
|
async transform(source, id, ssr) {
|
|
276
321
|
const query = getMarkoQuery(id);
|
|
@@ -289,7 +334,11 @@ function markoPlugin(opts = {}) {
|
|
|
289
334
|
serverManifest.entrySources[import_path.default.relative(root, id)] = source;
|
|
290
335
|
}
|
|
291
336
|
}
|
|
292
|
-
const compiled = await compiler.compile(
|
|
337
|
+
const compiled = await compiler.compile(
|
|
338
|
+
source,
|
|
339
|
+
id,
|
|
340
|
+
(typeof ssr === "object" ? ssr.ssr : ssr) ? ssrConfig : query === browserEntryQuery ? hydrateConfig : domConfig
|
|
341
|
+
);
|
|
293
342
|
const { map, meta } = compiled;
|
|
294
343
|
let { code } = compiled;
|
|
295
344
|
if (query !== browserEntryQuery && devServer) {
|
|
@@ -317,15 +366,20 @@ if (import.meta.hot) import.meta.hot.accept();`;
|
|
|
317
366
|
name: "marko-vite:post",
|
|
318
367
|
apply: "build",
|
|
319
368
|
enforce: "post",
|
|
369
|
+
// We use a "post" plugin to allow us to read the final generated `.html` from vite.
|
|
320
370
|
async generateBundle(outputOptions, bundle, isWrite) {
|
|
321
371
|
if (!linked) {
|
|
322
372
|
return;
|
|
323
373
|
}
|
|
324
374
|
if (!isWrite) {
|
|
325
|
-
this.error(
|
|
375
|
+
this.error(
|
|
376
|
+
`Linked builds are currently only supported when in "write" mode.`
|
|
377
|
+
);
|
|
326
378
|
}
|
|
327
379
|
if (!serverManifest) {
|
|
328
|
-
this.error(
|
|
380
|
+
this.error(
|
|
381
|
+
"No Marko files were found when bundling the server in linked mode."
|
|
382
|
+
);
|
|
329
383
|
}
|
|
330
384
|
if (isSSRBuild) {
|
|
331
385
|
const dir = outputOptions.dir ? import_path.default.resolve(outputOptions.dir) : import_path.default.resolve(outputOptions.file, "..");
|
|
@@ -334,13 +388,15 @@ if (import.meta.hot) import.meta.hot.accept();`;
|
|
|
334
388
|
if (chunk.type === "chunk") {
|
|
335
389
|
for (const id in chunk.modules) {
|
|
336
390
|
if (id === registeredTag) {
|
|
337
|
-
serverManifest.chunksNeedingAssets.push(
|
|
391
|
+
serverManifest.chunksNeedingAssets.push(
|
|
392
|
+
import_path.default.resolve(dir, fileName)
|
|
393
|
+
);
|
|
338
394
|
break;
|
|
339
395
|
}
|
|
340
396
|
}
|
|
341
397
|
}
|
|
342
398
|
}
|
|
343
|
-
await
|
|
399
|
+
await store.set(manifestFileName, JSON.stringify(serverManifest));
|
|
344
400
|
} else {
|
|
345
401
|
const browserManifest = {};
|
|
346
402
|
for (const entryId in serverManifest.entries) {
|
|
@@ -352,13 +408,19 @@ if (import.meta.hot) import.meta.hot.accept();`;
|
|
|
352
408
|
chunk = bundle[chunkId];
|
|
353
409
|
}
|
|
354
410
|
if ((chunk == null ? void 0 : chunk.type) === "asset") {
|
|
355
|
-
browserManifest[entryId] = await (0, import_manifest_generator.generateDocManifest)(
|
|
411
|
+
browserManifest[entryId] = await (0, import_manifest_generator.generateDocManifest)(
|
|
412
|
+
chunk.source.toString()
|
|
413
|
+
);
|
|
356
414
|
delete bundle[chunkId];
|
|
357
415
|
} else {
|
|
358
|
-
this.error(
|
|
416
|
+
this.error(
|
|
417
|
+
`Marko template had unexpected output from vite, ${fileName}`
|
|
418
|
+
);
|
|
359
419
|
}
|
|
360
420
|
}
|
|
361
|
-
const manifestStr = `;var __MARKO_MANIFEST__=${JSON.stringify(
|
|
421
|
+
const manifestStr = `;var __MARKO_MANIFEST__=${JSON.stringify(
|
|
422
|
+
browserManifest
|
|
423
|
+
)};
|
|
362
424
|
`;
|
|
363
425
|
for (const fileName of serverManifest.chunksNeedingAssets) {
|
|
364
426
|
await import_fs.default.promises.appendFile(fileName, manifestStr);
|
|
@@ -387,36 +449,26 @@ function toHTMLEntries(root, serverEntries) {
|
|
|
387
449
|
}
|
|
388
450
|
return result;
|
|
389
451
|
}
|
|
390
|
-
async function getServerManifestFile(root) {
|
|
391
|
-
return import_path.default.join(await getTempDir(root), "manifest.json");
|
|
392
|
-
}
|
|
393
|
-
function getTempDir(root) {
|
|
394
|
-
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")}`);
|
|
396
|
-
try {
|
|
397
|
-
const stat = await import_fs.default.promises.stat(dir);
|
|
398
|
-
if (stat.isDirectory()) {
|
|
399
|
-
return dir;
|
|
400
|
-
}
|
|
401
|
-
} catch {
|
|
402
|
-
await import_fs.default.promises.mkdir(dir);
|
|
403
|
-
return dir;
|
|
404
|
-
}
|
|
405
|
-
throw new Error("Unable to create temp directory");
|
|
406
|
-
})());
|
|
407
|
-
}
|
|
408
452
|
function toEntryId(id) {
|
|
409
453
|
const lastSepIndex = id.lastIndexOf(import_path.default.sep);
|
|
410
454
|
let name = id.slice(lastSepIndex + 1, id.indexOf(".", lastSepIndex));
|
|
411
455
|
if (name === "index" || name === "template") {
|
|
412
|
-
name = id.slice(
|
|
456
|
+
name = id.slice(
|
|
457
|
+
id.lastIndexOf(import_path.default.sep, lastSepIndex - 1) + 1,
|
|
458
|
+
lastSepIndex
|
|
459
|
+
);
|
|
413
460
|
}
|
|
414
461
|
return `${name}_${import_crypto.default.createHash("SHA1").update(id).digest("base64").replace(/[/+]/g, "-").slice(0, 4)}`;
|
|
415
462
|
}
|
|
416
463
|
function fileNameToURL(fileName, root) {
|
|
417
|
-
const relativeURL = import_path.default.posix.relative(
|
|
464
|
+
const relativeURL = import_path.default.posix.relative(
|
|
465
|
+
(0, import_url.pathToFileURL)(root).pathname,
|
|
466
|
+
(0, import_url.pathToFileURL)(fileName).pathname
|
|
467
|
+
);
|
|
418
468
|
if (relativeURL[0] === ".") {
|
|
419
|
-
throw new Error(
|
|
469
|
+
throw new Error(
|
|
470
|
+
"@marko/vite: Entry templates must exist under the current root directory."
|
|
471
|
+
);
|
|
420
472
|
}
|
|
421
473
|
return `/${relativeURL}`;
|
|
422
474
|
}
|