@marko/vite 3.1.6 → 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.
- package/README.md +0 -20
- package/dist/index.d.ts +3 -4
- package/dist/index.mjs +674 -103
- package/dist/manifest-generator.d.ts +1 -1
- package/dist/read-once-persisted-store.d.ts +6 -0
- package/dist/render-assets-runtime.d.ts +6 -0
- package/dist/serializer.d.ts +1 -1
- package/dist/server-entry-template.d.ts +1 -1
- package/package.json +20 -30
- package/dist/babel-plugin-cjs-interop.js +0 -117
- package/dist/babel-plugin-cjs-interop.mjs +0 -7
- package/dist/chunk-2E5QX7AF.mjs +0 -83
- package/dist/chunk-6IJ5UJ3N.mjs +0 -29
- package/dist/chunk-AEF7OQDP.mjs +0 -93
- package/dist/chunk-DCBMHGK4.mjs +0 -20
- package/dist/chunk-FCWFM7VD.mjs +0 -63
- package/dist/chunk-J6VIHWF4.mjs +0 -85
- package/dist/chunk-KIYHBIE6.mjs +0 -0
- package/dist/chunk-NTHVNXFC.mjs +0 -104
- package/dist/chunk-Y3E2OP42.mjs +0 -61
- package/dist/components/vite.marko +0 -74
- package/dist/esbuild-plugin.js +0 -113
- package/dist/esbuild-plugin.mjs +0 -6
- package/dist/index.js +0 -687
- package/dist/manifest-generator.js +0 -113
- package/dist/manifest-generator.mjs +0 -9
- package/dist/render-assets-transform.js +0 -41
- package/dist/render-assets-transform.mjs +0 -22
- package/dist/resolve.js +0 -94
- package/dist/resolve.mjs +0 -8
- package/dist/serializer.js +0 -127
- package/dist/serializer.mjs +0 -6
- package/dist/server-entry-template.js +0 -57
- package/dist/server-entry-template.mjs +0 -6
- package/dist/store/file-store.d.ts +0 -11
- package/dist/store/file-store.js +0 -91
- package/dist/store/file-store.mjs +0 -6
- package/dist/store/index.d.ts +0 -3
- package/dist/store/index.js +0 -41
- package/dist/store/index.mjs +0 -11
- package/dist/store/memory-store.d.ts +0 -8
- package/dist/store/memory-store.js +0 -38
- package/dist/store/memory-store.mjs +0 -6
- package/dist/store/types.d.ts +0 -5
- package/dist/store/types.js +0 -16
- package/dist/store/types.mjs +0 -0
package/dist/index.js
DELETED
|
@@ -1,687 +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 __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
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
var src_exports = {};
|
|
31
|
-
__export(src_exports, {
|
|
32
|
-
default: () => markoPlugin
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(src_exports);
|
|
35
|
-
var import_fs = __toESM(require("fs"));
|
|
36
|
-
var import_path = __toESM(require("path"));
|
|
37
|
-
var import_crypto = __toESM(require("crypto"));
|
|
38
|
-
var import_anymatch = __toESM(require("anymatch"));
|
|
39
|
-
var import_url = require("url");
|
|
40
|
-
var import_server_entry_template = __toESM(require("./server-entry-template"));
|
|
41
|
-
var import_manifest_generator = require("./manifest-generator");
|
|
42
|
-
var import_esbuild_plugin = __toESM(require("./esbuild-plugin"));
|
|
43
|
-
var import_store = require("./store");
|
|
44
|
-
var import_babel_plugin_cjs_interop = __toESM(require("./babel-plugin-cjs-interop"));
|
|
45
|
-
var import_resolve = require("./resolve");
|
|
46
|
-
__reExport(src_exports, require("./store"), module.exports);
|
|
47
|
-
const import_meta = {};
|
|
48
|
-
const POSIX_SEP = "/";
|
|
49
|
-
const WINDOWS_SEP = "\\";
|
|
50
|
-
const normalizePath = import_path.default.sep === WINDOWS_SEP ? (id) => id.replace(/\\/g, POSIX_SEP) : (id) => id;
|
|
51
|
-
const virtualFiles = /* @__PURE__ */ new Map();
|
|
52
|
-
const queryReg = /\?marko-[^?]+$/;
|
|
53
|
-
const browserEntryQuery = "?marko-browser-entry";
|
|
54
|
-
const serverEntryQuery = "?marko-server-entry";
|
|
55
|
-
const virtualFileQuery = "?marko-virtual";
|
|
56
|
-
const browserQuery = "?marko-browser";
|
|
57
|
-
const manifestFileName = "manifest.json";
|
|
58
|
-
const markoExt = ".marko";
|
|
59
|
-
const htmlExt = ".html";
|
|
60
|
-
const resolveOpts = { skipSelf: true };
|
|
61
|
-
const cache = /* @__PURE__ */ new Map();
|
|
62
|
-
const thisFile = typeof __filename === "string" ? __filename : (0, import_url.fileURLToPath)(import_meta.url);
|
|
63
|
-
const babelCaller = {
|
|
64
|
-
name: "@marko/vite",
|
|
65
|
-
supportsStaticESM: true,
|
|
66
|
-
supportsDynamicImport: true,
|
|
67
|
-
supportsTopLevelAwait: true,
|
|
68
|
-
supportsExportNamespaceFrom: true
|
|
69
|
-
};
|
|
70
|
-
let registeredTag = false;
|
|
71
|
-
function markoPlugin(opts = {}) {
|
|
72
|
-
let compiler;
|
|
73
|
-
let { linked = true } = opts;
|
|
74
|
-
let runtimeId;
|
|
75
|
-
let basePathVar;
|
|
76
|
-
let baseConfig;
|
|
77
|
-
let ssrConfig;
|
|
78
|
-
let ssrCjsConfig;
|
|
79
|
-
let domConfig;
|
|
80
|
-
let hydrateConfig;
|
|
81
|
-
const resolveVirtualDependency = (from, dep) => {
|
|
82
|
-
const normalizedFrom = normalizePath(from);
|
|
83
|
-
const query = `${virtualFileQuery}&id=${Buffer.from(dep.virtualPath).toString("base64url") + import_path.default.extname(dep.virtualPath)}`;
|
|
84
|
-
const id = normalizePath(normalizedFrom) + query;
|
|
85
|
-
if (devServer) {
|
|
86
|
-
const prev = virtualFiles.get(id);
|
|
87
|
-
if (isDeferredPromise(prev)) {
|
|
88
|
-
prev.resolve(dep);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
virtualFiles.set(id, dep);
|
|
92
|
-
return `./${import_path.default.posix.basename(normalizedFrom) + query}`;
|
|
93
|
-
};
|
|
94
|
-
let root;
|
|
95
|
-
let devEntryFile;
|
|
96
|
-
let devEntryFilePosix;
|
|
97
|
-
let isTest = false;
|
|
98
|
-
let isBuild = false;
|
|
99
|
-
let isSSRBuild = false;
|
|
100
|
-
let devServer;
|
|
101
|
-
let serverManifest;
|
|
102
|
-
let store;
|
|
103
|
-
let basePath = "/";
|
|
104
|
-
const entryIds = /* @__PURE__ */ new Set();
|
|
105
|
-
const cachedSources = /* @__PURE__ */ new Map();
|
|
106
|
-
const transformWatchFiles = /* @__PURE__ */ new Map();
|
|
107
|
-
const transformOptionalFiles = /* @__PURE__ */ new Map();
|
|
108
|
-
return [
|
|
109
|
-
{
|
|
110
|
-
name: "marko-vite:pre",
|
|
111
|
-
enforce: "pre",
|
|
112
|
-
// Must be pre to allow us to resolve assets before vite.
|
|
113
|
-
async config(config, env) {
|
|
114
|
-
var _a, _b, _c, _d, _e;
|
|
115
|
-
compiler ?? (compiler = await import(opts.compiler || "@marko/compiler"));
|
|
116
|
-
runtimeId = opts.runtimeId;
|
|
117
|
-
basePathVar = opts.basePathVar;
|
|
118
|
-
baseConfig = {
|
|
119
|
-
cache,
|
|
120
|
-
runtimeId,
|
|
121
|
-
sourceMaps: true,
|
|
122
|
-
writeVersionComment: false,
|
|
123
|
-
babelConfig: opts.babelConfig ? {
|
|
124
|
-
...opts.babelConfig,
|
|
125
|
-
caller: opts.babelConfig.caller ? {
|
|
126
|
-
name: "@marko/vite",
|
|
127
|
-
supportsStaticESM: true,
|
|
128
|
-
supportsDynamicImport: true,
|
|
129
|
-
supportsTopLevelAwait: true,
|
|
130
|
-
supportsExportNamespaceFrom: true,
|
|
131
|
-
...opts.babelConfig.caller
|
|
132
|
-
} : babelCaller
|
|
133
|
-
} : {
|
|
134
|
-
babelrc: false,
|
|
135
|
-
configFile: false,
|
|
136
|
-
browserslistConfigFile: false,
|
|
137
|
-
caller: babelCaller
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
ssrConfig = {
|
|
141
|
-
...baseConfig,
|
|
142
|
-
resolveVirtualDependency,
|
|
143
|
-
output: "html"
|
|
144
|
-
};
|
|
145
|
-
domConfig = {
|
|
146
|
-
...baseConfig,
|
|
147
|
-
resolveVirtualDependency,
|
|
148
|
-
output: "dom"
|
|
149
|
-
};
|
|
150
|
-
hydrateConfig = {
|
|
151
|
-
...baseConfig,
|
|
152
|
-
resolveVirtualDependency,
|
|
153
|
-
output: "hydrate"
|
|
154
|
-
};
|
|
155
|
-
compiler.configure(baseConfig);
|
|
156
|
-
root = normalizePath(config.root || process.cwd());
|
|
157
|
-
devEntryFile = import_path.default.join(root, "index.html");
|
|
158
|
-
devEntryFilePosix = normalizePath(devEntryFile);
|
|
159
|
-
isTest = env.mode === "test";
|
|
160
|
-
isBuild = env.command === "build";
|
|
161
|
-
isSSRBuild = isBuild && linked && Boolean(config.build.ssr);
|
|
162
|
-
store = opts.store || new import_store.FileStore(
|
|
163
|
-
`marko-vite-${import_crypto.default.createHash("SHA1").update(root).digest("hex")}`
|
|
164
|
-
);
|
|
165
|
-
if (isTest) {
|
|
166
|
-
linked = false;
|
|
167
|
-
if ((_b = (_a = config.test) == null ? void 0 : _a.environment) == null ? void 0 : _b.includes(
|
|
168
|
-
"dom"
|
|
169
|
-
)) {
|
|
170
|
-
config.resolve ?? (config.resolve = {});
|
|
171
|
-
(_c = config.resolve).conditions ?? (_c.conditions = []);
|
|
172
|
-
config.resolve.conditions.push("browser");
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (!registeredTag) {
|
|
176
|
-
const transformer = import_path.default.resolve(
|
|
177
|
-
thisFile,
|
|
178
|
-
"../render-assets-transform"
|
|
179
|
-
);
|
|
180
|
-
registeredTag = normalizePath(
|
|
181
|
-
import_path.default.resolve(thisFile, "../components", "vite.marko")
|
|
182
|
-
);
|
|
183
|
-
compiler.taglib.register("@marko/vite", {
|
|
184
|
-
"<_vite>": { template: registeredTag },
|
|
185
|
-
"<head>": { transformer },
|
|
186
|
-
"<body>": { transformer }
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
const optimizeDeps = config.optimizeDeps ?? (config.optimizeDeps = {});
|
|
190
|
-
optimizeDeps.entries ?? (optimizeDeps.entries = [
|
|
191
|
-
"**/*.marko",
|
|
192
|
-
"!**/__snapshots__/**",
|
|
193
|
-
`!**/__tests__/**`,
|
|
194
|
-
`!**/coverage/**`
|
|
195
|
-
]);
|
|
196
|
-
const domDeps = compiler.getRuntimeEntryFiles("dom", opts.translator);
|
|
197
|
-
optimizeDeps.include = optimizeDeps.include ? [...optimizeDeps.include, ...domDeps] : domDeps;
|
|
198
|
-
const optimizeExtensions = optimizeDeps.extensions ?? (optimizeDeps.extensions = []);
|
|
199
|
-
optimizeExtensions.push(".marko");
|
|
200
|
-
const esbuildOptions = optimizeDeps.esbuildOptions ?? (optimizeDeps.esbuildOptions = {});
|
|
201
|
-
const esbuildPlugins = esbuildOptions.plugins ?? (esbuildOptions.plugins = []);
|
|
202
|
-
esbuildPlugins.push((0, import_esbuild_plugin.default)(compiler, baseConfig));
|
|
203
|
-
const ssr = config.ssr ?? (config.ssr = {});
|
|
204
|
-
let { noExternal } = ssr;
|
|
205
|
-
if (noExternal !== true) {
|
|
206
|
-
const noExternalReg = /\.marko$/;
|
|
207
|
-
if (noExternal) {
|
|
208
|
-
if (Array.isArray(noExternal)) {
|
|
209
|
-
noExternal.push(noExternalReg);
|
|
210
|
-
} else {
|
|
211
|
-
noExternal = [noExternal, noExternalReg];
|
|
212
|
-
}
|
|
213
|
-
} else {
|
|
214
|
-
noExternal = noExternalReg;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
if (basePathVar) {
|
|
218
|
-
config.experimental ?? (config.experimental = {});
|
|
219
|
-
if (config.experimental.renderBuiltUrl) {
|
|
220
|
-
throw new Error(
|
|
221
|
-
"Cannot use @marko/vite `basePathVar` with Vite's `renderBuiltUrl` option."
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
const assetsDir = ((_e = (_d = config.build) == null ? void 0 : _d.assetsDir) == null ? void 0 : _e.replace(/[/\\]$/, "")) ?? "assets";
|
|
225
|
-
const assetsDirLen = assetsDir.length;
|
|
226
|
-
const assetsDirEnd = assetsDirLen + 1;
|
|
227
|
-
const trimAssertsDir = (fileName) => {
|
|
228
|
-
if (fileName.startsWith(assetsDir)) {
|
|
229
|
-
switch (fileName[assetsDirLen]) {
|
|
230
|
-
case POSIX_SEP:
|
|
231
|
-
case WINDOWS_SEP:
|
|
232
|
-
return fileName.slice(assetsDirEnd);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return fileName;
|
|
236
|
-
};
|
|
237
|
-
config.experimental.renderBuiltUrl = (fileName, { hostType, ssr: ssr2 }) => {
|
|
238
|
-
switch (hostType) {
|
|
239
|
-
case "html":
|
|
240
|
-
return trimAssertsDir(fileName);
|
|
241
|
-
case "js":
|
|
242
|
-
return {
|
|
243
|
-
runtime: `${ssr2 ? basePathVar : `$mbp${runtimeId ? `_${runtimeId}` : ""}`}+${JSON.stringify(trimAssertsDir(fileName))}`
|
|
244
|
-
};
|
|
245
|
-
default:
|
|
246
|
-
return { relative: true };
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
},
|
|
251
|
-
configResolved(config) {
|
|
252
|
-
basePath = config.base;
|
|
253
|
-
ssrCjsConfig = {
|
|
254
|
-
...ssrConfig,
|
|
255
|
-
//modules: 'cjs'
|
|
256
|
-
babelConfig: {
|
|
257
|
-
...ssrConfig.babelConfig,
|
|
258
|
-
plugins: (ssrConfig.babelConfig.plugins || []).concat(
|
|
259
|
-
(0, import_babel_plugin_cjs_interop.default)({
|
|
260
|
-
extensions: config.resolve.extensions,
|
|
261
|
-
conditions: config.resolve.conditions
|
|
262
|
-
})
|
|
263
|
-
)
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
},
|
|
267
|
-
configureServer(_server) {
|
|
268
|
-
ssrConfig.hot = domConfig.hot = true;
|
|
269
|
-
devServer = _server;
|
|
270
|
-
devServer.watcher.on("all", (type, filename) => {
|
|
271
|
-
cachedSources.delete(filename);
|
|
272
|
-
if (type === "unlink") {
|
|
273
|
-
entryIds.delete(filename);
|
|
274
|
-
transformWatchFiles.delete(filename);
|
|
275
|
-
transformOptionalFiles.delete(filename);
|
|
276
|
-
}
|
|
277
|
-
for (const [id, files] of transformWatchFiles) {
|
|
278
|
-
if ((0, import_anymatch.default)(files, filename)) {
|
|
279
|
-
devServer.watcher.emit("change", id);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
if (type === "add" || type === "unlink") {
|
|
283
|
-
for (const [id, files] of transformOptionalFiles) {
|
|
284
|
-
if ((0, import_anymatch.default)(files, filename)) {
|
|
285
|
-
devServer.watcher.emit("change", id);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
},
|
|
291
|
-
handleHotUpdate(ctx) {
|
|
292
|
-
compiler.taglib.clearCaches();
|
|
293
|
-
baseConfig.cache.clear();
|
|
294
|
-
for (const mod of ctx.modules) {
|
|
295
|
-
if (mod.id && virtualFiles.has(mod.id)) {
|
|
296
|
-
virtualFiles.set(mod.id, createDeferredPromise());
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
},
|
|
300
|
-
async buildStart(inputOptions) {
|
|
301
|
-
if (isBuild && linked && !isSSRBuild) {
|
|
302
|
-
try {
|
|
303
|
-
serverManifest = JSON.parse(
|
|
304
|
-
await store.get(manifestFileName)
|
|
305
|
-
);
|
|
306
|
-
inputOptions.input = toHTMLEntries(root, serverManifest.entries);
|
|
307
|
-
for (const entry in serverManifest.entrySources) {
|
|
308
|
-
const id = normalizePath(import_path.default.resolve(root, entry));
|
|
309
|
-
entryIds.add(id);
|
|
310
|
-
cachedSources.set(id, serverManifest.entrySources[entry]);
|
|
311
|
-
}
|
|
312
|
-
} catch (err) {
|
|
313
|
-
this.error(
|
|
314
|
-
`You must run the "ssr" build before the "browser" build.`
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
if (isEmpty(inputOptions.input)) {
|
|
318
|
-
this.error("No Marko files were found when compiling the server.");
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
},
|
|
322
|
-
async resolveId(importee, importer, importOpts, ssr = importOpts.ssr) {
|
|
323
|
-
var _a;
|
|
324
|
-
if (virtualFiles.has(importee)) {
|
|
325
|
-
return importee;
|
|
326
|
-
}
|
|
327
|
-
let importeeQuery = getMarkoQuery(importee);
|
|
328
|
-
if (importeeQuery) {
|
|
329
|
-
importee = importee.slice(0, -importeeQuery.length);
|
|
330
|
-
} else if (!importOpts.scan) {
|
|
331
|
-
if (ssr && linked && importer && (importer !== devEntryFile || normalizePath(importer) !== devEntryFilePosix) && // Vite tries to resolve against an `index.html` in some cases, we ignore it here.
|
|
332
|
-
isMarkoFile(importee) && !isMarkoFile(importer.replace(queryReg, ""))) {
|
|
333
|
-
importeeQuery = serverEntryQuery;
|
|
334
|
-
} else if (!ssr && isBuild && importer && isMarkoFile(importee) && ((_a = this.getModuleInfo(importer)) == null ? void 0 : _a.isEntry)) {
|
|
335
|
-
importeeQuery = browserEntryQuery;
|
|
336
|
-
} else if (linked && !ssr && !importeeQuery && isMarkoFile(importee)) {
|
|
337
|
-
importeeQuery = browserQuery;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
if (importeeQuery) {
|
|
341
|
-
const resolved = importee[0] === "." ? {
|
|
342
|
-
id: normalizePath(
|
|
343
|
-
importer ? import_path.default.resolve(importer, "..", importee) : import_path.default.resolve(root, importee)
|
|
344
|
-
)
|
|
345
|
-
} : await this.resolve(importee, importer, resolveOpts);
|
|
346
|
-
if (resolved) {
|
|
347
|
-
resolved.id += importeeQuery;
|
|
348
|
-
}
|
|
349
|
-
return resolved;
|
|
350
|
-
}
|
|
351
|
-
if (importer) {
|
|
352
|
-
const importerQuery = getMarkoQuery(importer);
|
|
353
|
-
if (importerQuery) {
|
|
354
|
-
importer = importer.slice(0, -importerQuery.length);
|
|
355
|
-
if (importee[0] === ".") {
|
|
356
|
-
const resolved = normalizePath(
|
|
357
|
-
import_path.default.resolve(importer, "..", importee)
|
|
358
|
-
);
|
|
359
|
-
if (resolved === normalizePath(importer))
|
|
360
|
-
return resolved;
|
|
361
|
-
}
|
|
362
|
-
return this.resolve(importee, importer, resolveOpts);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
return null;
|
|
366
|
-
},
|
|
367
|
-
async load(rawId) {
|
|
368
|
-
const id = stripVersionAndTimeStamp(rawId);
|
|
369
|
-
const query = getMarkoQuery(id);
|
|
370
|
-
switch (query) {
|
|
371
|
-
case serverEntryQuery: {
|
|
372
|
-
entryIds.add(id.slice(0, -query.length));
|
|
373
|
-
return null;
|
|
374
|
-
}
|
|
375
|
-
case browserEntryQuery:
|
|
376
|
-
case browserQuery: {
|
|
377
|
-
return cachedSources.get(id.slice(0, -query.length)) || null;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
return virtualFiles.get(id) || null;
|
|
381
|
-
},
|
|
382
|
-
async transform(source, rawId, ssr) {
|
|
383
|
-
let id = stripVersionAndTimeStamp(rawId);
|
|
384
|
-
const isSSR = typeof ssr === "object" ? ssr.ssr : ssr;
|
|
385
|
-
const query = getMarkoQuery(id);
|
|
386
|
-
if (query && !query.startsWith(virtualFileQuery)) {
|
|
387
|
-
id = id.slice(0, -query.length);
|
|
388
|
-
if (query === serverEntryQuery) {
|
|
389
|
-
const fileName = id;
|
|
390
|
-
let entryData;
|
|
391
|
-
id = `${id.slice(0, -markoExt.length)}.entry.marko`;
|
|
392
|
-
cachedSources.set(fileName, source);
|
|
393
|
-
if (isBuild) {
|
|
394
|
-
const relativeFileName = import_path.default.posix.relative(root, fileName);
|
|
395
|
-
const entryId = toEntryId(relativeFileName);
|
|
396
|
-
serverManifest ?? (serverManifest = {
|
|
397
|
-
entries: {},
|
|
398
|
-
entrySources: {},
|
|
399
|
-
chunksNeedingAssets: []
|
|
400
|
-
});
|
|
401
|
-
serverManifest.entries[entryId] = relativeFileName;
|
|
402
|
-
serverManifest.entrySources[relativeFileName] = source;
|
|
403
|
-
entryData = JSON.stringify(entryId);
|
|
404
|
-
} else {
|
|
405
|
-
entryData = JSON.stringify(
|
|
406
|
-
await (0, import_manifest_generator.generateDocManifest)(
|
|
407
|
-
basePath,
|
|
408
|
-
await devServer.transformIndexHtml(
|
|
409
|
-
"/",
|
|
410
|
-
(0, import_manifest_generator.generateInputDoc)(
|
|
411
|
-
posixFileNameToURL(fileName, root) + browserEntryQuery
|
|
412
|
-
)
|
|
413
|
-
)
|
|
414
|
-
)
|
|
415
|
-
);
|
|
416
|
-
}
|
|
417
|
-
source = await (0, import_server_entry_template.default)({
|
|
418
|
-
fileName,
|
|
419
|
-
entryData,
|
|
420
|
-
runtimeId,
|
|
421
|
-
basePathVar: isBuild ? basePathVar : void 0
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
if (!isMarkoFile(id)) {
|
|
426
|
-
return null;
|
|
427
|
-
}
|
|
428
|
-
if (isSSR) {
|
|
429
|
-
if (linked) {
|
|
430
|
-
cachedSources.set(id, source);
|
|
431
|
-
}
|
|
432
|
-
if (!query && (0, import_resolve.isCJSModule)(id)) {
|
|
433
|
-
if (isBuild) {
|
|
434
|
-
const { code: code2, map: map2 } = await compiler.compile(
|
|
435
|
-
source,
|
|
436
|
-
id,
|
|
437
|
-
ssrCjsConfig
|
|
438
|
-
);
|
|
439
|
-
return { code: code2, map: map2, meta: { source } };
|
|
440
|
-
} else {
|
|
441
|
-
const { ast } = await compiler.compile(source, id, {
|
|
442
|
-
cache,
|
|
443
|
-
ast: true,
|
|
444
|
-
code: false,
|
|
445
|
-
output: "source",
|
|
446
|
-
sourceMaps: false
|
|
447
|
-
});
|
|
448
|
-
let namedExports = "";
|
|
449
|
-
let code2 = `import { createRequire } from "module";
|
|
450
|
-
`;
|
|
451
|
-
code2 += `import "@marko/compiler/register.js";
|
|
452
|
-
`;
|
|
453
|
-
code2 += `const mod = createRequire(import.meta.url)(${JSON.stringify(
|
|
454
|
-
id
|
|
455
|
-
)});
|
|
456
|
-
`;
|
|
457
|
-
for (const child of ast.program.body) {
|
|
458
|
-
switch (child.type) {
|
|
459
|
-
case "ExportAllDeclaration":
|
|
460
|
-
code2 += `export * from ${JSON.stringify(
|
|
461
|
-
child.source.value
|
|
462
|
-
)};
|
|
463
|
-
`;
|
|
464
|
-
break;
|
|
465
|
-
case "ExportNamedDeclaration":
|
|
466
|
-
if (child.specifiers) {
|
|
467
|
-
for (const specifier of child.specifiers) {
|
|
468
|
-
if (specifier.exported.type === "Identifier") {
|
|
469
|
-
namedExports += `${specifier.exported.name},`;
|
|
470
|
-
} else {
|
|
471
|
-
namedExports += `mod[${JSON.stringify(
|
|
472
|
-
specifier.exported.value
|
|
473
|
-
)}] as ${specifier.exported.value},`;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
if (child.declaration) {
|
|
478
|
-
if ("id" in child.declaration && child.declaration.id) {
|
|
479
|
-
if (child.declaration.id.type === "Identifier") {
|
|
480
|
-
namedExports += `${child.declaration.id.name},`;
|
|
481
|
-
} else {
|
|
482
|
-
namedExports += `mod[${JSON.stringify(
|
|
483
|
-
child.declaration.id.value
|
|
484
|
-
)}] as ${child.declaration.id.value},`;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
if ("declarations" in child.declaration) {
|
|
488
|
-
for (const declaration of child.declaration.declarations) {
|
|
489
|
-
if (declaration.id.type === "Identifier") {
|
|
490
|
-
namedExports += `${declaration.id.name},`;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
break;
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
code2 += `export const { ${namedExports} } = mod;
|
|
499
|
-
`;
|
|
500
|
-
code2 += `export default mod.default;
|
|
501
|
-
`;
|
|
502
|
-
return code2;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
const compiled = await compiler.compile(
|
|
507
|
-
source,
|
|
508
|
-
id,
|
|
509
|
-
isSSR ? ssrConfig : query === browserEntryQuery ? hydrateConfig : domConfig
|
|
510
|
-
);
|
|
511
|
-
const { map, meta } = compiled;
|
|
512
|
-
let { code } = compiled;
|
|
513
|
-
if (query !== browserEntryQuery && devServer) {
|
|
514
|
-
code += `
|
|
515
|
-
if (import.meta.hot) import.meta.hot.accept(() => {});`;
|
|
516
|
-
}
|
|
517
|
-
if (devServer) {
|
|
518
|
-
const templateName = getPosixBasenameWithoutExt(id);
|
|
519
|
-
const optionalFilePrefix = import_path.default.dirname(id) + import_path.default.sep + (templateName === "index" ? "" : `${templateName}.`);
|
|
520
|
-
for (const file of meta.watchFiles) {
|
|
521
|
-
this.addWatchFile(file);
|
|
522
|
-
}
|
|
523
|
-
transformOptionalFiles.set(id, [
|
|
524
|
-
`${optionalFilePrefix}style.*`,
|
|
525
|
-
`${optionalFilePrefix}component.*`,
|
|
526
|
-
`${optionalFilePrefix}component-browser.*`,
|
|
527
|
-
`${optionalFilePrefix}marko-tag.json`
|
|
528
|
-
]);
|
|
529
|
-
transformWatchFiles.set(id, meta.watchFiles);
|
|
530
|
-
}
|
|
531
|
-
return { code, map, meta: isBuild ? { source } : void 0 };
|
|
532
|
-
}
|
|
533
|
-
},
|
|
534
|
-
{
|
|
535
|
-
name: "marko-vite:post",
|
|
536
|
-
apply: "build",
|
|
537
|
-
enforce: "post",
|
|
538
|
-
// We use a "post" plugin to allow us to read the final generated `.html` from vite.
|
|
539
|
-
async generateBundle(outputOptions, bundle, isWrite) {
|
|
540
|
-
if (!linked) {
|
|
541
|
-
return;
|
|
542
|
-
}
|
|
543
|
-
if (!isWrite) {
|
|
544
|
-
this.error(
|
|
545
|
-
`Linked builds are currently only supported when in "write" mode.`
|
|
546
|
-
);
|
|
547
|
-
}
|
|
548
|
-
if (!serverManifest) {
|
|
549
|
-
this.error(
|
|
550
|
-
"No Marko files were found when bundling the server in linked mode."
|
|
551
|
-
);
|
|
552
|
-
}
|
|
553
|
-
if (isSSRBuild) {
|
|
554
|
-
const dir = outputOptions.dir ? import_path.default.resolve(outputOptions.dir) : import_path.default.resolve(outputOptions.file, "..");
|
|
555
|
-
for (const fileName in bundle) {
|
|
556
|
-
const chunk = bundle[fileName];
|
|
557
|
-
if (chunk.type === "chunk") {
|
|
558
|
-
for (const id in chunk.modules) {
|
|
559
|
-
if (id === registeredTag) {
|
|
560
|
-
serverManifest.chunksNeedingAssets.push(
|
|
561
|
-
import_path.default.resolve(dir, fileName)
|
|
562
|
-
);
|
|
563
|
-
break;
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
await store.set(manifestFileName, JSON.stringify(serverManifest));
|
|
569
|
-
} else {
|
|
570
|
-
const browserManifest = {};
|
|
571
|
-
for (const entryId in serverManifest.entries) {
|
|
572
|
-
const fileName = serverManifest.entries[entryId];
|
|
573
|
-
let chunkId = fileName + htmlExt;
|
|
574
|
-
let chunk = bundle[chunkId];
|
|
575
|
-
if (!chunk) {
|
|
576
|
-
chunkId = chunkId.replace(/\//g, "\\");
|
|
577
|
-
chunk = bundle[chunkId];
|
|
578
|
-
}
|
|
579
|
-
if ((chunk == null ? void 0 : chunk.type) === "asset") {
|
|
580
|
-
browserManifest[entryId] = {
|
|
581
|
-
...await (0, import_manifest_generator.generateDocManifest)(
|
|
582
|
-
basePath,
|
|
583
|
-
chunk.source.toString()
|
|
584
|
-
),
|
|
585
|
-
entries: void 0
|
|
586
|
-
// clear out entries for prod builds.
|
|
587
|
-
};
|
|
588
|
-
delete bundle[chunkId];
|
|
589
|
-
} else {
|
|
590
|
-
this.error(
|
|
591
|
-
`Marko template had unexpected output from vite, ${fileName}`
|
|
592
|
-
);
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
const manifestStr = `;var __MARKO_MANIFEST__=${JSON.stringify(
|
|
596
|
-
browserManifest
|
|
597
|
-
)};
|
|
598
|
-
`;
|
|
599
|
-
for (const fileName of serverManifest.chunksNeedingAssets) {
|
|
600
|
-
await import_fs.default.promises.appendFile(fileName, manifestStr);
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
];
|
|
606
|
-
}
|
|
607
|
-
function getMarkoQuery(id) {
|
|
608
|
-
var _a;
|
|
609
|
-
return ((_a = queryReg.exec(id)) == null ? void 0 : _a[0]) || "";
|
|
610
|
-
}
|
|
611
|
-
function isMarkoFile(id) {
|
|
612
|
-
return id.endsWith(markoExt);
|
|
613
|
-
}
|
|
614
|
-
function toHTMLEntries(root, serverEntries) {
|
|
615
|
-
const result = [];
|
|
616
|
-
for (const id in serverEntries) {
|
|
617
|
-
const markoFile = import_path.default.posix.join(root, serverEntries[id]);
|
|
618
|
-
const htmlFile = markoFile + htmlExt;
|
|
619
|
-
virtualFiles.set(htmlFile, {
|
|
620
|
-
code: (0, import_manifest_generator.generateInputDoc)(markoFile + browserEntryQuery)
|
|
621
|
-
});
|
|
622
|
-
result.push(htmlFile);
|
|
623
|
-
}
|
|
624
|
-
return result;
|
|
625
|
-
}
|
|
626
|
-
function toEntryId(id) {
|
|
627
|
-
const lastSepIndex = id.lastIndexOf(POSIX_SEP);
|
|
628
|
-
let name = id.slice(lastSepIndex + 1, id.indexOf(".", lastSepIndex));
|
|
629
|
-
if (name === "index" || name === "template") {
|
|
630
|
-
name = id.slice(
|
|
631
|
-
id.lastIndexOf(POSIX_SEP, lastSepIndex - 1) + 1,
|
|
632
|
-
lastSepIndex
|
|
633
|
-
);
|
|
634
|
-
}
|
|
635
|
-
return `${name}_${import_crypto.default.createHash("SHA1").update(id).digest("base64").replace(/[/+]/g, "-").slice(0, 4)}`;
|
|
636
|
-
}
|
|
637
|
-
function posixFileNameToURL(fileName, root) {
|
|
638
|
-
const relativeURL = import_path.default.posix.relative(
|
|
639
|
-
(0, import_url.pathToFileURL)(root).pathname,
|
|
640
|
-
(0, import_url.pathToFileURL)(fileName).pathname
|
|
641
|
-
);
|
|
642
|
-
if (relativeURL[0] === ".") {
|
|
643
|
-
throw new Error(
|
|
644
|
-
"@marko/vite: Entry templates must exist under the current root directory."
|
|
645
|
-
);
|
|
646
|
-
}
|
|
647
|
-
return `/${relativeURL}`;
|
|
648
|
-
}
|
|
649
|
-
function getPosixBasenameWithoutExt(file) {
|
|
650
|
-
const baseStart = file.lastIndexOf(POSIX_SEP) + 1;
|
|
651
|
-
const extStart = file.indexOf(".", baseStart + 1);
|
|
652
|
-
return file.slice(baseStart, extStart);
|
|
653
|
-
}
|
|
654
|
-
function createDeferredPromise() {
|
|
655
|
-
let resolve;
|
|
656
|
-
let reject;
|
|
657
|
-
const promise = new Promise((res, rej) => {
|
|
658
|
-
resolve = res;
|
|
659
|
-
reject = rej;
|
|
660
|
-
});
|
|
661
|
-
promise.resolve = resolve;
|
|
662
|
-
promise.reject = reject;
|
|
663
|
-
return promise;
|
|
664
|
-
}
|
|
665
|
-
function isDeferredPromise(obj) {
|
|
666
|
-
return typeof (obj == null ? void 0 : obj.then) === "function";
|
|
667
|
-
}
|
|
668
|
-
function isEmpty(obj) {
|
|
669
|
-
for (const _ in obj) {
|
|
670
|
-
return false;
|
|
671
|
-
}
|
|
672
|
-
return true;
|
|
673
|
-
}
|
|
674
|
-
function stripVersionAndTimeStamp(id) {
|
|
675
|
-
const queryStart = id.indexOf("?");
|
|
676
|
-
if (queryStart === -1)
|
|
677
|
-
return id;
|
|
678
|
-
const url = id.slice(0, queryStart);
|
|
679
|
-
const query = id.slice(queryStart + 1).replace(/(?:^|[&])[vt]=[^&]+/g, "");
|
|
680
|
-
if (query)
|
|
681
|
-
return `${url}?${query}`;
|
|
682
|
-
return url;
|
|
683
|
-
}
|
|
684
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
685
|
-
0 && (module.exports = {
|
|
686
|
-
...require("./store")
|
|
687
|
-
});
|