@marko/vite 2.3.11 → 2.3.13
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/dist/index.js +50 -25
- package/dist/index.mjs +50 -25
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -44,7 +44,9 @@ var import_esbuild_plugin = __toESM(require("./esbuild-plugin"));
|
|
|
44
44
|
var import_store = require("./store");
|
|
45
45
|
__reExport(src_exports, require("./store"), module.exports);
|
|
46
46
|
const import_meta = {};
|
|
47
|
-
const
|
|
47
|
+
const POSIX_SEP = "/";
|
|
48
|
+
const WINDOWS_SEP = "\\";
|
|
49
|
+
const normalizePath = import_path.default.sep === WINDOWS_SEP ? (id) => id.replace(/\\/g, POSIX_SEP) : (id) => id;
|
|
48
50
|
const virtualFiles = /* @__PURE__ */ new Map();
|
|
49
51
|
const queryReg = /\?marko-.+$/;
|
|
50
52
|
const browserEntryQuery = "?marko-browser-entry";
|
|
@@ -79,17 +81,16 @@ function markoPlugin(opts = {}) {
|
|
|
79
81
|
};
|
|
80
82
|
const resolveViteVirtualDep = (from, dep) => {
|
|
81
83
|
const query = `${virtualFileQuery}&id=${normalizePath(dep.virtualPath)}`;
|
|
82
|
-
const
|
|
84
|
+
const normalizedFrom = normalizePath(from);
|
|
85
|
+
const id = normalizePath(normalizedFrom) + query;
|
|
83
86
|
if (devServer) {
|
|
84
87
|
const prev = virtualFiles.get(id);
|
|
85
|
-
if (prev
|
|
86
|
-
|
|
87
|
-
devServer.moduleGraph.getModuleById(id)
|
|
88
|
-
);
|
|
88
|
+
if (isDeferredPromise(prev)) {
|
|
89
|
+
prev.resolve(dep);
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
virtualFiles.set(id, dep);
|
|
92
|
-
return `./${import_path.default.basename(
|
|
93
|
+
return `./${import_path.default.posix.basename(normalizedFrom) + query}`;
|
|
93
94
|
};
|
|
94
95
|
const ssrConfig = {
|
|
95
96
|
...baseConfig,
|
|
@@ -108,6 +109,7 @@ function markoPlugin(opts = {}) {
|
|
|
108
109
|
};
|
|
109
110
|
let root;
|
|
110
111
|
let devEntryFile;
|
|
112
|
+
let devEntryFilePosix;
|
|
111
113
|
let isBuild = false;
|
|
112
114
|
let isSSRBuild = false;
|
|
113
115
|
let devServer;
|
|
@@ -126,6 +128,7 @@ function markoPlugin(opts = {}) {
|
|
|
126
128
|
compiler ?? (compiler = await import(opts.compiler || "@marko/compiler"));
|
|
127
129
|
root = normalizePath(config.root || process.cwd());
|
|
128
130
|
devEntryFile = import_path.default.join(root, "index.html");
|
|
131
|
+
devEntryFilePosix = normalizePath(devEntryFile);
|
|
129
132
|
isBuild = env.command === "build";
|
|
130
133
|
isSSRBuild = isBuild && linked && Boolean(config.build.ssr);
|
|
131
134
|
store = opts.store || new import_store.FileStore(
|
|
@@ -188,6 +191,8 @@ function markoPlugin(opts = {}) {
|
|
|
188
191
|
devServer.watcher.on("all", (type, filename) => {
|
|
189
192
|
if (type === "unlink") {
|
|
190
193
|
entrySources.delete(filename);
|
|
194
|
+
transformWatchFiles.delete(filename);
|
|
195
|
+
transformOptionalFiles.delete(filename);
|
|
191
196
|
}
|
|
192
197
|
for (const [id, files] of transformWatchFiles) {
|
|
193
198
|
if ((0, import_anymatch.default)(files, filename)) {
|
|
@@ -195,19 +200,23 @@ function markoPlugin(opts = {}) {
|
|
|
195
200
|
}
|
|
196
201
|
}
|
|
197
202
|
if (type === "add" || type === "unlink") {
|
|
198
|
-
let clearedCache = false;
|
|
199
203
|
for (const [id, files] of transformOptionalFiles) {
|
|
200
204
|
if ((0, import_anymatch.default)(files, filename)) {
|
|
201
|
-
if (!clearedCache) {
|
|
202
|
-
baseConfig.cache.clear();
|
|
203
|
-
clearedCache = true;
|
|
204
|
-
}
|
|
205
205
|
devServer.watcher.emit("change", id);
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
});
|
|
210
210
|
},
|
|
211
|
+
handleHotUpdate(ctx) {
|
|
212
|
+
compiler.taglib.clearCaches();
|
|
213
|
+
baseConfig.cache.clear();
|
|
214
|
+
for (const mod of ctx.modules) {
|
|
215
|
+
if (mod.id && virtualFiles.has(mod.id)) {
|
|
216
|
+
virtualFiles.set(mod.id, createDeferredPromise());
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
},
|
|
211
220
|
async buildStart(inputOptions) {
|
|
212
221
|
if (isBuild && linked && !isSSRBuild) {
|
|
213
222
|
try {
|
|
@@ -217,7 +226,7 @@ function markoPlugin(opts = {}) {
|
|
|
217
226
|
inputOptions.input = toHTMLEntries(root, serverManifest.entries);
|
|
218
227
|
for (const entry in serverManifest.entrySources) {
|
|
219
228
|
entrySources.set(
|
|
220
|
-
import_path.default.resolve(root, entry),
|
|
229
|
+
normalizePath(import_path.default.resolve(root, entry)),
|
|
221
230
|
serverManifest.entrySources[entry]
|
|
222
231
|
);
|
|
223
232
|
}
|
|
@@ -239,7 +248,7 @@ function markoPlugin(opts = {}) {
|
|
|
239
248
|
let importeeQuery = getMarkoQuery(importee);
|
|
240
249
|
if (importeeQuery) {
|
|
241
250
|
importee = importee.slice(0, -importeeQuery.length);
|
|
242
|
-
} else if (ssr && linked && importer && importer !== devEntryFile && // Vite tries to resolve against an `index.html` in some cases, we ignore it here.
|
|
251
|
+
} else if (ssr && linked && importer && (importer !== devEntryFile || normalizePath(importer) !== devEntryFilePosix) && // Vite tries to resolve against an `index.html` in some cases, we ignore it here.
|
|
243
252
|
isMarkoFile(importee) && !isMarkoFile(importer.replace(queryReg, ""))) {
|
|
244
253
|
importeeQuery = serverEntryQuery;
|
|
245
254
|
} else if (!ssr && isBuild && importer && isMarkoFile(importee) && ((_a2 = this.getModuleInfo(importer)) == null ? void 0 : _a2.isEntry)) {
|
|
@@ -261,8 +270,10 @@ function markoPlugin(opts = {}) {
|
|
|
261
270
|
if (importerQuery) {
|
|
262
271
|
importer = importer.slice(0, -importerQuery.length);
|
|
263
272
|
if (importee[0] === ".") {
|
|
264
|
-
const resolved =
|
|
265
|
-
|
|
273
|
+
const resolved = normalizePath(
|
|
274
|
+
import_path.default.resolve(importer, "..", importee)
|
|
275
|
+
);
|
|
276
|
+
if (resolved === normalizePath(importer))
|
|
266
277
|
return resolved;
|
|
267
278
|
}
|
|
268
279
|
return this.resolve(importee, importer, resolveOpts);
|
|
@@ -291,7 +302,7 @@ function markoPlugin(opts = {}) {
|
|
|
291
302
|
await (0, import_manifest_generator.generateDocManifest)(
|
|
292
303
|
await devServer.transformIndexHtml(
|
|
293
304
|
"/",
|
|
294
|
-
(0, import_manifest_generator.generateInputDoc)(
|
|
305
|
+
(0, import_manifest_generator.generateInputDoc)(posixFileNameToURL(fileName, root))
|
|
295
306
|
)
|
|
296
307
|
)
|
|
297
308
|
);
|
|
@@ -331,7 +342,7 @@ function markoPlugin(opts = {}) {
|
|
|
331
342
|
if (ssr && entrySources.has(id)) {
|
|
332
343
|
entrySources.set(id, source);
|
|
333
344
|
if (serverManifest) {
|
|
334
|
-
serverManifest.entrySources[import_path.default.relative(root, id)] = source;
|
|
345
|
+
serverManifest.entrySources[import_path.default.posix.relative(root, id)] = source;
|
|
335
346
|
}
|
|
336
347
|
}
|
|
337
348
|
const compiled = await compiler.compile(
|
|
@@ -343,10 +354,10 @@ function markoPlugin(opts = {}) {
|
|
|
343
354
|
let { code } = compiled;
|
|
344
355
|
if (query !== browserEntryQuery && devServer) {
|
|
345
356
|
code += `
|
|
346
|
-
if (import.meta.hot) import.meta.hot.accept();`;
|
|
357
|
+
if (import.meta.hot) import.meta.hot.accept(() => {});`;
|
|
347
358
|
}
|
|
348
359
|
if (devServer) {
|
|
349
|
-
const templateName =
|
|
360
|
+
const templateName = getPosixBasenameWithoutExt(id);
|
|
350
361
|
const optionalFilePrefix = import_path.default.dirname(id) + import_path.default.sep + (templateName === "index" ? "" : `${templateName}.`);
|
|
351
362
|
for (const file of meta.watchFiles) {
|
|
352
363
|
this.addWatchFile(file);
|
|
@@ -450,17 +461,17 @@ function toHTMLEntries(root, serverEntries) {
|
|
|
450
461
|
return result;
|
|
451
462
|
}
|
|
452
463
|
function toEntryId(id) {
|
|
453
|
-
const lastSepIndex = id.lastIndexOf(
|
|
464
|
+
const lastSepIndex = id.lastIndexOf(POSIX_SEP);
|
|
454
465
|
let name = id.slice(lastSepIndex + 1, id.indexOf(".", lastSepIndex));
|
|
455
466
|
if (name === "index" || name === "template") {
|
|
456
467
|
name = id.slice(
|
|
457
|
-
id.lastIndexOf(
|
|
468
|
+
id.lastIndexOf(POSIX_SEP, lastSepIndex - 1) + 1,
|
|
458
469
|
lastSepIndex
|
|
459
470
|
);
|
|
460
471
|
}
|
|
461
472
|
return `${name}_${import_crypto.default.createHash("SHA1").update(id).digest("base64").replace(/[/+]/g, "-").slice(0, 4)}`;
|
|
462
473
|
}
|
|
463
|
-
function
|
|
474
|
+
function posixFileNameToURL(fileName, root) {
|
|
464
475
|
const relativeURL = import_path.default.posix.relative(
|
|
465
476
|
(0, import_url.pathToFileURL)(root).pathname,
|
|
466
477
|
(0, import_url.pathToFileURL)(fileName).pathname
|
|
@@ -472,11 +483,25 @@ function fileNameToURL(fileName, root) {
|
|
|
472
483
|
}
|
|
473
484
|
return `/${relativeURL}`;
|
|
474
485
|
}
|
|
475
|
-
function
|
|
476
|
-
const baseStart = file.lastIndexOf(
|
|
486
|
+
function getPosixBasenameWithoutExt(file) {
|
|
487
|
+
const baseStart = file.lastIndexOf(POSIX_SEP) + 1;
|
|
477
488
|
const extStart = file.indexOf(".", baseStart + 1);
|
|
478
489
|
return file.slice(baseStart, extStart);
|
|
479
490
|
}
|
|
491
|
+
function createDeferredPromise() {
|
|
492
|
+
let resolve;
|
|
493
|
+
let reject;
|
|
494
|
+
const promise = new Promise((res, rej) => {
|
|
495
|
+
resolve = res;
|
|
496
|
+
reject = rej;
|
|
497
|
+
});
|
|
498
|
+
promise.resolve = resolve;
|
|
499
|
+
promise.reject = reject;
|
|
500
|
+
return promise;
|
|
501
|
+
}
|
|
502
|
+
function isDeferredPromise(obj) {
|
|
503
|
+
return typeof (obj == null ? void 0 : obj.then) === "function";
|
|
504
|
+
}
|
|
480
505
|
function isEmpty(obj) {
|
|
481
506
|
for (const _ in obj) {
|
|
482
507
|
return false;
|
package/dist/index.mjs
CHANGED
|
@@ -24,7 +24,9 @@ import crypto from "crypto";
|
|
|
24
24
|
import anyMatch from "anymatch";
|
|
25
25
|
import { pathToFileURL, fileURLToPath } from "url";
|
|
26
26
|
import { relativeImportPath } from "relative-import-path";
|
|
27
|
-
var
|
|
27
|
+
var POSIX_SEP = "/";
|
|
28
|
+
var WINDOWS_SEP = "\\";
|
|
29
|
+
var normalizePath = path.sep === WINDOWS_SEP ? (id) => id.replace(/\\/g, POSIX_SEP) : (id) => id;
|
|
28
30
|
var virtualFiles = /* @__PURE__ */ new Map();
|
|
29
31
|
var queryReg = /\?marko-.+$/;
|
|
30
32
|
var browserEntryQuery = "?marko-browser-entry";
|
|
@@ -59,17 +61,16 @@ function markoPlugin(opts = {}) {
|
|
|
59
61
|
};
|
|
60
62
|
const resolveViteVirtualDep = (from, dep) => {
|
|
61
63
|
const query = `${virtualFileQuery}&id=${normalizePath(dep.virtualPath)}`;
|
|
62
|
-
const
|
|
64
|
+
const normalizedFrom = normalizePath(from);
|
|
65
|
+
const id = normalizePath(normalizedFrom) + query;
|
|
63
66
|
if (devServer) {
|
|
64
67
|
const prev = virtualFiles.get(id);
|
|
65
|
-
if (prev
|
|
66
|
-
|
|
67
|
-
devServer.moduleGraph.getModuleById(id)
|
|
68
|
-
);
|
|
68
|
+
if (isDeferredPromise(prev)) {
|
|
69
|
+
prev.resolve(dep);
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
virtualFiles.set(id, dep);
|
|
72
|
-
return `./${path.basename(
|
|
73
|
+
return `./${path.posix.basename(normalizedFrom) + query}`;
|
|
73
74
|
};
|
|
74
75
|
const ssrConfig = {
|
|
75
76
|
...baseConfig,
|
|
@@ -88,6 +89,7 @@ function markoPlugin(opts = {}) {
|
|
|
88
89
|
};
|
|
89
90
|
let root;
|
|
90
91
|
let devEntryFile;
|
|
92
|
+
let devEntryFilePosix;
|
|
91
93
|
let isBuild = false;
|
|
92
94
|
let isSSRBuild = false;
|
|
93
95
|
let devServer;
|
|
@@ -106,6 +108,7 @@ function markoPlugin(opts = {}) {
|
|
|
106
108
|
compiler ?? (compiler = await import(opts.compiler || "@marko/compiler"));
|
|
107
109
|
root = normalizePath(config.root || process.cwd());
|
|
108
110
|
devEntryFile = path.join(root, "index.html");
|
|
111
|
+
devEntryFilePosix = normalizePath(devEntryFile);
|
|
109
112
|
isBuild = env.command === "build";
|
|
110
113
|
isSSRBuild = isBuild && linked && Boolean(config.build.ssr);
|
|
111
114
|
store = opts.store || new FileStore(
|
|
@@ -168,6 +171,8 @@ function markoPlugin(opts = {}) {
|
|
|
168
171
|
devServer.watcher.on("all", (type, filename) => {
|
|
169
172
|
if (type === "unlink") {
|
|
170
173
|
entrySources.delete(filename);
|
|
174
|
+
transformWatchFiles.delete(filename);
|
|
175
|
+
transformOptionalFiles.delete(filename);
|
|
171
176
|
}
|
|
172
177
|
for (const [id, files] of transformWatchFiles) {
|
|
173
178
|
if (anyMatch(files, filename)) {
|
|
@@ -175,19 +180,23 @@ function markoPlugin(opts = {}) {
|
|
|
175
180
|
}
|
|
176
181
|
}
|
|
177
182
|
if (type === "add" || type === "unlink") {
|
|
178
|
-
let clearedCache = false;
|
|
179
183
|
for (const [id, files] of transformOptionalFiles) {
|
|
180
184
|
if (anyMatch(files, filename)) {
|
|
181
|
-
if (!clearedCache) {
|
|
182
|
-
baseConfig.cache.clear();
|
|
183
|
-
clearedCache = true;
|
|
184
|
-
}
|
|
185
185
|
devServer.watcher.emit("change", id);
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
});
|
|
190
190
|
},
|
|
191
|
+
handleHotUpdate(ctx) {
|
|
192
|
+
compiler.taglib.clearCaches();
|
|
193
|
+
baseConfig.cache.clear();
|
|
194
|
+
for (const mod of ctx.modules) {
|
|
195
|
+
if (mod.id && virtualFiles.has(mod.id)) {
|
|
196
|
+
virtualFiles.set(mod.id, createDeferredPromise());
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
},
|
|
191
200
|
async buildStart(inputOptions) {
|
|
192
201
|
if (isBuild && linked && !isSSRBuild) {
|
|
193
202
|
try {
|
|
@@ -197,7 +206,7 @@ function markoPlugin(opts = {}) {
|
|
|
197
206
|
inputOptions.input = toHTMLEntries(root, serverManifest.entries);
|
|
198
207
|
for (const entry in serverManifest.entrySources) {
|
|
199
208
|
entrySources.set(
|
|
200
|
-
path.resolve(root, entry),
|
|
209
|
+
normalizePath(path.resolve(root, entry)),
|
|
201
210
|
serverManifest.entrySources[entry]
|
|
202
211
|
);
|
|
203
212
|
}
|
|
@@ -219,7 +228,7 @@ function markoPlugin(opts = {}) {
|
|
|
219
228
|
let importeeQuery = getMarkoQuery(importee);
|
|
220
229
|
if (importeeQuery) {
|
|
221
230
|
importee = importee.slice(0, -importeeQuery.length);
|
|
222
|
-
} else if (ssr && linked && importer && importer !== devEntryFile && // Vite tries to resolve against an `index.html` in some cases, we ignore it here.
|
|
231
|
+
} else if (ssr && linked && importer && (importer !== devEntryFile || normalizePath(importer) !== devEntryFilePosix) && // Vite tries to resolve against an `index.html` in some cases, we ignore it here.
|
|
223
232
|
isMarkoFile(importee) && !isMarkoFile(importer.replace(queryReg, ""))) {
|
|
224
233
|
importeeQuery = serverEntryQuery;
|
|
225
234
|
} else if (!ssr && isBuild && importer && isMarkoFile(importee) && ((_a2 = this.getModuleInfo(importer)) == null ? void 0 : _a2.isEntry)) {
|
|
@@ -241,8 +250,10 @@ function markoPlugin(opts = {}) {
|
|
|
241
250
|
if (importerQuery) {
|
|
242
251
|
importer = importer.slice(0, -importerQuery.length);
|
|
243
252
|
if (importee[0] === ".") {
|
|
244
|
-
const resolved =
|
|
245
|
-
|
|
253
|
+
const resolved = normalizePath(
|
|
254
|
+
path.resolve(importer, "..", importee)
|
|
255
|
+
);
|
|
256
|
+
if (resolved === normalizePath(importer))
|
|
246
257
|
return resolved;
|
|
247
258
|
}
|
|
248
259
|
return this.resolve(importee, importer, resolveOpts);
|
|
@@ -271,7 +282,7 @@ function markoPlugin(opts = {}) {
|
|
|
271
282
|
await generateDocManifest(
|
|
272
283
|
await devServer.transformIndexHtml(
|
|
273
284
|
"/",
|
|
274
|
-
generateInputDoc(
|
|
285
|
+
generateInputDoc(posixFileNameToURL(fileName, root))
|
|
275
286
|
)
|
|
276
287
|
)
|
|
277
288
|
);
|
|
@@ -311,7 +322,7 @@ function markoPlugin(opts = {}) {
|
|
|
311
322
|
if (ssr && entrySources.has(id)) {
|
|
312
323
|
entrySources.set(id, source);
|
|
313
324
|
if (serverManifest) {
|
|
314
|
-
serverManifest.entrySources[path.relative(root, id)] = source;
|
|
325
|
+
serverManifest.entrySources[path.posix.relative(root, id)] = source;
|
|
315
326
|
}
|
|
316
327
|
}
|
|
317
328
|
const compiled = await compiler.compile(
|
|
@@ -323,10 +334,10 @@ function markoPlugin(opts = {}) {
|
|
|
323
334
|
let { code } = compiled;
|
|
324
335
|
if (query !== browserEntryQuery && devServer) {
|
|
325
336
|
code += `
|
|
326
|
-
if (import.meta.hot) import.meta.hot.accept();`;
|
|
337
|
+
if (import.meta.hot) import.meta.hot.accept(() => {});`;
|
|
327
338
|
}
|
|
328
339
|
if (devServer) {
|
|
329
|
-
const templateName =
|
|
340
|
+
const templateName = getPosixBasenameWithoutExt(id);
|
|
330
341
|
const optionalFilePrefix = path.dirname(id) + path.sep + (templateName === "index" ? "" : `${templateName}.`);
|
|
331
342
|
for (const file of meta.watchFiles) {
|
|
332
343
|
this.addWatchFile(file);
|
|
@@ -430,17 +441,17 @@ function toHTMLEntries(root, serverEntries) {
|
|
|
430
441
|
return result;
|
|
431
442
|
}
|
|
432
443
|
function toEntryId(id) {
|
|
433
|
-
const lastSepIndex = id.lastIndexOf(
|
|
444
|
+
const lastSepIndex = id.lastIndexOf(POSIX_SEP);
|
|
434
445
|
let name = id.slice(lastSepIndex + 1, id.indexOf(".", lastSepIndex));
|
|
435
446
|
if (name === "index" || name === "template") {
|
|
436
447
|
name = id.slice(
|
|
437
|
-
id.lastIndexOf(
|
|
448
|
+
id.lastIndexOf(POSIX_SEP, lastSepIndex - 1) + 1,
|
|
438
449
|
lastSepIndex
|
|
439
450
|
);
|
|
440
451
|
}
|
|
441
452
|
return `${name}_${crypto.createHash("SHA1").update(id).digest("base64").replace(/[/+]/g, "-").slice(0, 4)}`;
|
|
442
453
|
}
|
|
443
|
-
function
|
|
454
|
+
function posixFileNameToURL(fileName, root) {
|
|
444
455
|
const relativeURL = path.posix.relative(
|
|
445
456
|
pathToFileURL(root).pathname,
|
|
446
457
|
pathToFileURL(fileName).pathname
|
|
@@ -452,11 +463,25 @@ function fileNameToURL(fileName, root) {
|
|
|
452
463
|
}
|
|
453
464
|
return `/${relativeURL}`;
|
|
454
465
|
}
|
|
455
|
-
function
|
|
456
|
-
const baseStart = file.lastIndexOf(
|
|
466
|
+
function getPosixBasenameWithoutExt(file) {
|
|
467
|
+
const baseStart = file.lastIndexOf(POSIX_SEP) + 1;
|
|
457
468
|
const extStart = file.indexOf(".", baseStart + 1);
|
|
458
469
|
return file.slice(baseStart, extStart);
|
|
459
470
|
}
|
|
471
|
+
function createDeferredPromise() {
|
|
472
|
+
let resolve;
|
|
473
|
+
let reject;
|
|
474
|
+
const promise = new Promise((res, rej) => {
|
|
475
|
+
resolve = res;
|
|
476
|
+
reject = rej;
|
|
477
|
+
});
|
|
478
|
+
promise.resolve = resolve;
|
|
479
|
+
promise.reject = reject;
|
|
480
|
+
return promise;
|
|
481
|
+
}
|
|
482
|
+
function isDeferredPromise(obj) {
|
|
483
|
+
return typeof (obj == null ? void 0 : obj.then) === "function";
|
|
484
|
+
}
|
|
460
485
|
function isEmpty(obj) {
|
|
461
486
|
for (const _ in obj) {
|
|
462
487
|
return false;
|
package/package.json
CHANGED