@marko/run 0.2.18 → 0.3.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/dist/.tsbuildinfo +1 -1
- package/dist/adapter/index.cjs +1 -1
- package/dist/adapter/index.js +1 -1
- package/dist/cli/index.mjs +190 -144
- package/dist/vite/index.cjs +154 -109
- package/dist/vite/index.js +155 -110
- package/dist/vite/types.d.ts +2 -2
- package/dist/vite/utils/read-once-persisted-store.d.ts +6 -0
- package/package.json +10 -10
package/dist/vite/index.cjs
CHANGED
|
@@ -68,9 +68,8 @@ var import_url = require("url");
|
|
|
68
68
|
var __importMetaURL = (0, import_url.pathToFileURL)(__filename);
|
|
69
69
|
|
|
70
70
|
// src/vite/plugin.ts
|
|
71
|
-
var
|
|
72
|
-
var
|
|
73
|
-
var import_fs2 = __toESM(require("fs"), 1);
|
|
71
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
72
|
+
var import_fs3 = __toESM(require("fs"), 1);
|
|
74
73
|
var import_glob = require("glob");
|
|
75
74
|
var import_url2 = require("url");
|
|
76
75
|
var import_browserslist = __toESM(require("browserslist"), 1);
|
|
@@ -157,10 +156,10 @@ var _VDir = class _VDir {
|
|
|
157
156
|
});
|
|
158
157
|
return value;
|
|
159
158
|
}
|
|
160
|
-
addDir(
|
|
159
|
+
addDir(path4, segment) {
|
|
161
160
|
const map = segment.type === "_" ? __privateGet(this, _pathlessDirs) ?? __privateSet(this, _pathlessDirs, /* @__PURE__ */ new Map()) : __privateGet(this, _dirs) ?? __privateSet(this, _dirs, /* @__PURE__ */ new Map());
|
|
162
161
|
if (!map.has(segment.name)) {
|
|
163
|
-
const dir = new _VDir(this, segment,
|
|
162
|
+
const dir = new _VDir(this, segment, path4);
|
|
164
163
|
map.set(segment.name, dir);
|
|
165
164
|
return dir;
|
|
166
165
|
}
|
|
@@ -206,10 +205,10 @@ var _VDir = class _VDir {
|
|
|
206
205
|
const dirs = [];
|
|
207
206
|
const unique = /* @__PURE__ */ new Set();
|
|
208
207
|
for (const root of roots) {
|
|
209
|
-
for (const
|
|
208
|
+
for (const path4 of paths) {
|
|
210
209
|
let dir = root;
|
|
211
|
-
for (const segment of
|
|
212
|
-
dir = dir.addDir(
|
|
210
|
+
for (const segment of path4.segments) {
|
|
211
|
+
dir = dir.addDir(path4, segment);
|
|
213
212
|
}
|
|
214
213
|
if (unique.has(dir.path)) {
|
|
215
214
|
const sources = /* @__PURE__ */ new Set();
|
|
@@ -221,7 +220,7 @@ var _VDir = class _VDir {
|
|
|
221
220
|
}
|
|
222
221
|
}
|
|
223
222
|
throw new Error(
|
|
224
|
-
`Ambiguous directory structure: '${sourcePath}${
|
|
223
|
+
`Ambiguous directory structure: '${sourcePath}${path4.source}' defines '${dir.path}' multiple times.`
|
|
225
224
|
);
|
|
226
225
|
} else {
|
|
227
226
|
unique.add(dir.path);
|
|
@@ -263,9 +262,9 @@ function parseFlatRoute(pattern) {
|
|
|
263
262
|
} else if (charCode === 44) {
|
|
264
263
|
if (!current) {
|
|
265
264
|
segmentEnd(
|
|
266
|
-
basePaths.map((
|
|
267
|
-
...
|
|
268
|
-
segments:
|
|
265
|
+
basePaths.map((path4) => ({
|
|
266
|
+
...path4,
|
|
267
|
+
segments: path4.segments.slice()
|
|
269
268
|
})),
|
|
270
269
|
"",
|
|
271
270
|
"_",
|
|
@@ -295,9 +294,9 @@ function parseFlatRoute(pattern) {
|
|
|
295
294
|
} else if (charCode === 36) {
|
|
296
295
|
type = pattern.charCodeAt(i + 1) === 36 ? "$$" : "$";
|
|
297
296
|
}
|
|
298
|
-
current ?? (current = basePaths.map((
|
|
299
|
-
...
|
|
300
|
-
segments:
|
|
297
|
+
current ?? (current = basePaths.map((path4) => ({
|
|
298
|
+
...path4,
|
|
299
|
+
segments: path4.segments.slice()
|
|
301
300
|
})));
|
|
302
301
|
i = len;
|
|
303
302
|
for (const char of delimiters) {
|
|
@@ -317,9 +316,9 @@ function parseFlatRoute(pattern) {
|
|
|
317
316
|
}
|
|
318
317
|
if (!current) {
|
|
319
318
|
segmentEnd(
|
|
320
|
-
basePaths.map((
|
|
321
|
-
...
|
|
322
|
-
segments:
|
|
319
|
+
basePaths.map((path4) => ({
|
|
320
|
+
...path4,
|
|
321
|
+
segments: path4.segments.slice()
|
|
323
322
|
})),
|
|
324
323
|
"",
|
|
325
324
|
"_",
|
|
@@ -343,9 +342,9 @@ function parseFlatRoute(pattern) {
|
|
|
343
342
|
segment.param = raw.slice(type.length);
|
|
344
343
|
}
|
|
345
344
|
}
|
|
346
|
-
for (const
|
|
345
|
+
for (const path4 of paths) {
|
|
347
346
|
if (segment) {
|
|
348
|
-
if (
|
|
347
|
+
if (path4.isCatchall) {
|
|
349
348
|
throw new Error(
|
|
350
349
|
`Invalid route pattern: nested segments are not allowed after a catch-all parameter. Found '.' following '${pattern.slice(
|
|
351
350
|
0,
|
|
@@ -353,22 +352,22 @@ function parseFlatRoute(pattern) {
|
|
|
353
352
|
)}' in '${pattern}'.`
|
|
354
353
|
);
|
|
355
354
|
}
|
|
356
|
-
|
|
357
|
-
|
|
355
|
+
path4.segments.push(segment);
|
|
356
|
+
path4.id += path4.id === "/" ? segment.name : `/${segment.name}`;
|
|
358
357
|
if (type === "$$") {
|
|
359
|
-
|
|
358
|
+
path4.isCatchall = true;
|
|
360
359
|
}
|
|
361
360
|
}
|
|
362
361
|
if (map) {
|
|
363
|
-
if (map.has(
|
|
364
|
-
const existing = map.get(
|
|
362
|
+
if (map.has(path4.id)) {
|
|
363
|
+
const existing = map.get(path4.id);
|
|
365
364
|
const existingExpansion = existing.segments.map((s) => s.raw).join(".");
|
|
366
|
-
const currentExpansion =
|
|
365
|
+
const currentExpansion = path4.segments.map((s) => s.raw).join(".");
|
|
367
366
|
throw new Error(
|
|
368
|
-
`Invalid route pattern: route '${
|
|
367
|
+
`Invalid route pattern: route '${path4.id}' is ambiguous. Expansion '${currentExpansion}' collides with '${existingExpansion}' in '${pattern}'.`
|
|
369
368
|
);
|
|
370
369
|
}
|
|
371
|
-
map.set(
|
|
370
|
+
map.set(path4.id, path4);
|
|
372
371
|
}
|
|
373
372
|
}
|
|
374
373
|
}
|
|
@@ -424,7 +423,7 @@ async function buildRoutes(sources) {
|
|
|
424
423
|
dirStack.length = prevDirStackLength;
|
|
425
424
|
};
|
|
426
425
|
},
|
|
427
|
-
onFile({ name, path:
|
|
426
|
+
onFile({ name, path: path4 }) {
|
|
428
427
|
const match = name.match(routeableFileRegex);
|
|
429
428
|
if (!match) {
|
|
430
429
|
return;
|
|
@@ -432,7 +431,7 @@ async function buildRoutes(sources) {
|
|
|
432
431
|
const type = (match[1] || match[3]).toLowerCase();
|
|
433
432
|
if (dirStack.length && isSpecialType(type)) {
|
|
434
433
|
console.warn(
|
|
435
|
-
`Special pages '${RoutableFileTypes.NotFound}' and '${RoutableFileTypes.Error}' are only considered in the root directory - ignoring ${
|
|
434
|
+
`Special pages '${RoutableFileTypes.NotFound}' and '${RoutableFileTypes.Error}' are only considered in the root directory - ignoring ${path4}`
|
|
436
435
|
);
|
|
437
436
|
return;
|
|
438
437
|
}
|
|
@@ -447,7 +446,7 @@ async function buildRoutes(sources) {
|
|
|
447
446
|
id: String(nextFileId++),
|
|
448
447
|
name,
|
|
449
448
|
type,
|
|
450
|
-
filePath:
|
|
449
|
+
filePath: path4,
|
|
451
450
|
relativePath,
|
|
452
451
|
importPath: `${importPrefix}/${relativePath}`,
|
|
453
452
|
verbs: type === RoutableFileTypes.Page ? ["get"] : void 0
|
|
@@ -499,23 +498,23 @@ async function buildRoutes(sources) {
|
|
|
499
498
|
}
|
|
500
499
|
}
|
|
501
500
|
if (page || handler) {
|
|
502
|
-
const
|
|
503
|
-
if (uniqueRoutes.has(
|
|
504
|
-
const existing = uniqueRoutes.get(
|
|
501
|
+
const path4 = dir.pathInfo;
|
|
502
|
+
if (uniqueRoutes.has(path4.id)) {
|
|
503
|
+
const existing = uniqueRoutes.get(path4.id);
|
|
505
504
|
const route = routes[existing.index];
|
|
506
505
|
const existingFiles = [route.handler, route.page].filter(Boolean).map((f) => f.filePath);
|
|
507
506
|
const currentFiles = [handler, page].filter(Boolean).map((f) => f.filePath);
|
|
508
|
-
throw new Error(`Duplicate routes for path '${
|
|
507
|
+
throw new Error(`Duplicate routes for path '${path4.path}' were defined. A route established by:
|
|
509
508
|
${existingFiles.join(" and ")} via '${existing.dir.path}'
|
|
510
509
|
collides with
|
|
511
510
|
${currentFiles.join(" and ")} via '${dir.path}'
|
|
512
511
|
`);
|
|
513
512
|
}
|
|
514
|
-
uniqueRoutes.set(
|
|
513
|
+
uniqueRoutes.set(path4.id, { dir, index: routes.length });
|
|
515
514
|
routes.push({
|
|
516
515
|
index: nextRouteIndex++,
|
|
517
516
|
key: dir.fullPath,
|
|
518
|
-
paths: [
|
|
517
|
+
paths: [path4],
|
|
519
518
|
middleware: [...currentMiddleware],
|
|
520
519
|
layouts: page ? [...currentLayouts] : [],
|
|
521
520
|
meta: dir.files.get(RoutableFileTypes.Meta),
|
|
@@ -1178,7 +1177,7 @@ function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
|
|
|
1178
1177
|
if (useSwitch) {
|
|
1179
1178
|
writer.writeBlockStart(`switch (${value}) {`);
|
|
1180
1179
|
}
|
|
1181
|
-
for (const { key, path:
|
|
1180
|
+
for (const { key, path: path4, route: route2 } of terminal) {
|
|
1182
1181
|
const decodedKey = decodeURIComponent(key);
|
|
1183
1182
|
if (useSwitch) {
|
|
1184
1183
|
writer.write(`case '${decodedKey}': `, true);
|
|
@@ -1186,7 +1185,7 @@ function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
|
|
|
1186
1185
|
writer.write(`if (${value} === '${decodedKey}') `, true);
|
|
1187
1186
|
}
|
|
1188
1187
|
writer.write(
|
|
1189
|
-
`return ${renderMatch(verb, route2,
|
|
1188
|
+
`return ${renderMatch(verb, route2, path4)}; // ${path4.path}
|
|
1190
1189
|
`
|
|
1191
1190
|
);
|
|
1192
1191
|
}
|
|
@@ -1291,11 +1290,11 @@ function renderParams(params, pathIndex) {
|
|
|
1291
1290
|
}
|
|
1292
1291
|
return result ? result + " }" : "{}";
|
|
1293
1292
|
}
|
|
1294
|
-
function renderMatch(verb, route,
|
|
1293
|
+
function renderMatch(verb, route, path4, pathIndex) {
|
|
1295
1294
|
const handler = `${verb}${route.index}`;
|
|
1296
|
-
const params =
|
|
1295
|
+
const params = path4.params ? renderParams(path4.params, pathIndex) : "{}";
|
|
1297
1296
|
const meta = route.meta ? `meta${route.index}` : "{}";
|
|
1298
|
-
const pathPattern = pathToURLPatternString(
|
|
1297
|
+
const pathPattern = pathToURLPatternString(path4.path);
|
|
1299
1298
|
return `{ handler: ${handler}, params: ${params}, meta: ${meta}, path: '${pathPattern}' }`;
|
|
1300
1299
|
}
|
|
1301
1300
|
function renderMiddleware(middleware) {
|
|
@@ -1316,15 +1315,15 @@ function renderMiddleware(middleware) {
|
|
|
1316
1315
|
imports.join();
|
|
1317
1316
|
return writer.end();
|
|
1318
1317
|
}
|
|
1319
|
-
function stripTsExtension(
|
|
1320
|
-
const index =
|
|
1318
|
+
function stripTsExtension(path4) {
|
|
1319
|
+
const index = path4.lastIndexOf(".");
|
|
1321
1320
|
if (index !== -1) {
|
|
1322
|
-
const ext =
|
|
1321
|
+
const ext = path4.slice(index + 1);
|
|
1323
1322
|
if (ext.toLowerCase() === "ts") {
|
|
1324
|
-
return
|
|
1323
|
+
return path4.slice(0, index);
|
|
1325
1324
|
}
|
|
1326
1325
|
}
|
|
1327
|
-
return
|
|
1326
|
+
return path4;
|
|
1328
1327
|
}
|
|
1329
1328
|
async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
|
|
1330
1329
|
var _a, _b;
|
|
@@ -1356,8 +1355,8 @@ async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
|
|
|
1356
1355
|
const routeTypes = /* @__PURE__ */ new Map();
|
|
1357
1356
|
for (const route of routes.list) {
|
|
1358
1357
|
let routeType = "";
|
|
1359
|
-
for (const
|
|
1360
|
-
const pathType = `"${pathToURLPatternString(
|
|
1358
|
+
for (const path4 of route.paths) {
|
|
1359
|
+
const pathType = `"${pathToURLPatternString(path4.path)}"`;
|
|
1361
1360
|
routeType += routeType ? " | " + pathType : pathType;
|
|
1362
1361
|
routesWriter.writeLines(`${pathType}: Routes["${route.key}"];`);
|
|
1363
1362
|
}
|
|
@@ -1393,22 +1392,22 @@ async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
|
|
|
1393
1392
|
const pageWriter = writer.branch("page");
|
|
1394
1393
|
const layoutWriter = writer.branch("layout");
|
|
1395
1394
|
for (const [file, types] of routeTypes) {
|
|
1396
|
-
const
|
|
1395
|
+
const path4 = `${pathPrefix}/${file.relativePath}`;
|
|
1397
1396
|
const routeType = `Run.Routes[${types.join(" | ")}]`;
|
|
1398
1397
|
switch (file.type) {
|
|
1399
1398
|
case RoutableFileTypes.Handler:
|
|
1400
|
-
writeModuleDeclaration(handlerWriter,
|
|
1399
|
+
writeModuleDeclaration(handlerWriter, path4, routeType);
|
|
1401
1400
|
break;
|
|
1402
1401
|
case RoutableFileTypes.Middleware:
|
|
1403
|
-
writeModuleDeclaration(middlewareWriter,
|
|
1402
|
+
writeModuleDeclaration(middlewareWriter, path4, routeType);
|
|
1404
1403
|
break;
|
|
1405
1404
|
case RoutableFileTypes.Page:
|
|
1406
|
-
writeModuleDeclaration(pageWriter,
|
|
1405
|
+
writeModuleDeclaration(pageWriter, path4, routeType);
|
|
1407
1406
|
break;
|
|
1408
1407
|
case RoutableFileTypes.Layout:
|
|
1409
1408
|
writeModuleDeclaration(
|
|
1410
1409
|
layoutWriter,
|
|
1411
|
-
|
|
1410
|
+
path4,
|
|
1412
1411
|
routeType,
|
|
1413
1412
|
`
|
|
1414
1413
|
export interface Input {
|
|
@@ -1419,7 +1418,7 @@ async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
|
|
|
1419
1418
|
case RoutableFileTypes.Error:
|
|
1420
1419
|
writeModuleDeclaration(
|
|
1421
1420
|
writer,
|
|
1422
|
-
|
|
1421
|
+
path4,
|
|
1423
1422
|
"globalThis.MarkoRun.Route",
|
|
1424
1423
|
`
|
|
1425
1424
|
export interface Input {
|
|
@@ -1428,7 +1427,7 @@ async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
|
|
|
1428
1427
|
);
|
|
1429
1428
|
break;
|
|
1430
1429
|
case RoutableFileTypes.NotFound:
|
|
1431
|
-
writeModuleDeclaration(writer,
|
|
1430
|
+
writeModuleDeclaration(writer, path4, "Run.Route");
|
|
1432
1431
|
break;
|
|
1433
1432
|
}
|
|
1434
1433
|
}
|
|
@@ -1463,13 +1462,13 @@ type Routes = {`);
|
|
|
1463
1462
|
writer.writeBlockEnd("}");
|
|
1464
1463
|
return writer.end();
|
|
1465
1464
|
}
|
|
1466
|
-
function writeModuleDeclaration(writer,
|
|
1467
|
-
writer.writeLines("").write(`declare module "${stripTsExtension(
|
|
1465
|
+
function writeModuleDeclaration(writer, path4, routeType, moduleTypes) {
|
|
1466
|
+
writer.writeLines("").write(`declare module "${stripTsExtension(path4)}" {`);
|
|
1468
1467
|
if (moduleTypes) {
|
|
1469
1468
|
writer.write(moduleTypes);
|
|
1470
1469
|
}
|
|
1471
1470
|
if (routeType) {
|
|
1472
|
-
const isMarko =
|
|
1471
|
+
const isMarko = path4.endsWith(".marko");
|
|
1473
1472
|
writer.write(`
|
|
1474
1473
|
namespace MarkoRun {
|
|
1475
1474
|
export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform };
|
|
@@ -1482,8 +1481,8 @@ function writeModuleDeclaration(writer, path3, routeType, moduleTypes) {
|
|
|
1482
1481
|
writer.writeLines(`
|
|
1483
1482
|
}`);
|
|
1484
1483
|
}
|
|
1485
|
-
function pathToURLPatternString(
|
|
1486
|
-
return
|
|
1484
|
+
function pathToURLPatternString(path4) {
|
|
1485
|
+
return path4.replace(/\/\$(\$?)([^\/]*)/g, (_, catchAll, name) => {
|
|
1487
1486
|
name = decodeURIComponent(name);
|
|
1488
1487
|
return catchAll ? `/:${name || "rest"}*` : `/:${name}`;
|
|
1489
1488
|
});
|
|
@@ -1492,11 +1491,11 @@ function createRouteTrie(routes) {
|
|
|
1492
1491
|
const root = {
|
|
1493
1492
|
key: ""
|
|
1494
1493
|
};
|
|
1495
|
-
function insert(
|
|
1494
|
+
function insert(path4, route) {
|
|
1496
1495
|
let node = root;
|
|
1497
|
-
for (const segment of
|
|
1496
|
+
for (const segment of path4.segments) {
|
|
1498
1497
|
if (segment === "$$") {
|
|
1499
|
-
node.catchAll ?? (node.catchAll = { route, path:
|
|
1498
|
+
node.catchAll ?? (node.catchAll = { route, path: path4 });
|
|
1500
1499
|
return;
|
|
1501
1500
|
} else if (segment === "$") {
|
|
1502
1501
|
node = node.dynamic ?? (node.dynamic = {
|
|
@@ -1514,12 +1513,12 @@ function createRouteTrie(routes) {
|
|
|
1514
1513
|
node = next;
|
|
1515
1514
|
}
|
|
1516
1515
|
}
|
|
1517
|
-
node.path ?? (node.path =
|
|
1516
|
+
node.path ?? (node.path = path4);
|
|
1518
1517
|
node.route ?? (node.route = route);
|
|
1519
1518
|
}
|
|
1520
1519
|
for (const route of routes) {
|
|
1521
|
-
for (const
|
|
1522
|
-
insert(
|
|
1520
|
+
for (const path4 of route.paths) {
|
|
1521
|
+
insert(path4, route);
|
|
1523
1522
|
}
|
|
1524
1523
|
}
|
|
1525
1524
|
return root;
|
|
@@ -1609,7 +1608,7 @@ function logRoutesTable(routes, bundle, options) {
|
|
|
1609
1608
|
style: { compact: true }
|
|
1610
1609
|
});
|
|
1611
1610
|
for (const route of routes.list) {
|
|
1612
|
-
for (const
|
|
1611
|
+
for (const path4 of route.paths) {
|
|
1613
1612
|
const verbs = getVerbs(route).sort(
|
|
1614
1613
|
(a, b) => HttpVerbOrder[a] - HttpVerbOrder[b]
|
|
1615
1614
|
);
|
|
@@ -1628,7 +1627,7 @@ function logRoutesTable(routes, bundle, options) {
|
|
|
1628
1627
|
import_kleur.default.bold(HttpVerbColors[verb](verb.toUpperCase()))
|
|
1629
1628
|
];
|
|
1630
1629
|
if (verbs.length === 1 || firstRow) {
|
|
1631
|
-
row.push({ rowSpan: verbs.length, content: prettyPath(
|
|
1630
|
+
row.push({ rowSpan: verbs.length, content: prettyPath(path4.path) });
|
|
1632
1631
|
firstRow = false;
|
|
1633
1632
|
}
|
|
1634
1633
|
row.push(entryType.join(" -> "));
|
|
@@ -1692,8 +1691,8 @@ function prettySize([bytes, compBytes]) {
|
|
|
1692
1691
|
str += import_kleur.default.bold(import_kleur.default.red(compSize));
|
|
1693
1692
|
return str;
|
|
1694
1693
|
}
|
|
1695
|
-
function prettyPath(
|
|
1696
|
-
return
|
|
1694
|
+
function prettyPath(path4) {
|
|
1695
|
+
return path4.replace(/\/\$\$(.*)$/, (_, p) => "/" + import_kleur.default.bold(import_kleur.default.dim(`*${p}`))).replace(/\/\$([^/]+)/g, (_, p) => "/" + import_kleur.default.bold(import_kleur.default.dim(`:${p}`)));
|
|
1697
1696
|
}
|
|
1698
1697
|
|
|
1699
1698
|
// src/vite/utils/config.ts
|
|
@@ -1712,12 +1711,60 @@ var getExternalAdapterOptions = (viteConfig) => getConfig(viteConfig, AdapterCon
|
|
|
1712
1711
|
|
|
1713
1712
|
// src/vite/plugin.ts
|
|
1714
1713
|
var import_debug = __toESM(require("debug"), 1);
|
|
1714
|
+
|
|
1715
|
+
// src/vite/utils/read-once-persisted-store.ts
|
|
1716
|
+
var import_os = __toESM(require("os"), 1);
|
|
1717
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
1718
|
+
var import_fs2 = require("fs");
|
|
1719
|
+
var noop = () => {
|
|
1720
|
+
};
|
|
1721
|
+
var tmpFile = import_path2.default.join(import_os.default.tmpdir(), "marko-run-storage.json");
|
|
1722
|
+
var values = /* @__PURE__ */ new Map();
|
|
1723
|
+
var loadedFromDisk;
|
|
1724
|
+
var ReadOncePersistedStore = class {
|
|
1725
|
+
constructor(uid) {
|
|
1726
|
+
this.uid = uid;
|
|
1727
|
+
}
|
|
1728
|
+
write(value) {
|
|
1729
|
+
values.set(this.uid, value);
|
|
1730
|
+
}
|
|
1731
|
+
async read() {
|
|
1732
|
+
const { uid } = this;
|
|
1733
|
+
if (values.has(uid)) {
|
|
1734
|
+
const value = values.get(uid);
|
|
1735
|
+
values.delete(uid);
|
|
1736
|
+
return value;
|
|
1737
|
+
}
|
|
1738
|
+
if (loadedFromDisk === true) {
|
|
1739
|
+
throw new Error(`Value for ${uid} could not be loaded.`);
|
|
1740
|
+
}
|
|
1741
|
+
await (loadedFromDisk || (loadedFromDisk = import_fs2.promises.readFile(tmpFile, "utf-8").then(syncDataFromDisk).catch(finishLoadFromDisk)));
|
|
1742
|
+
return this.read();
|
|
1743
|
+
}
|
|
1744
|
+
};
|
|
1745
|
+
function syncDataFromDisk(data) {
|
|
1746
|
+
finishLoadFromDisk();
|
|
1747
|
+
import_fs2.promises.unlink(tmpFile).catch(noop);
|
|
1748
|
+
for (const [k, v] of JSON.parse(data)) {
|
|
1749
|
+
values.set(k, v);
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
function finishLoadFromDisk() {
|
|
1753
|
+
loadedFromDisk = true;
|
|
1754
|
+
}
|
|
1755
|
+
process.once("beforeExit", (code) => {
|
|
1756
|
+
if (code === 0 && values.size) {
|
|
1757
|
+
import_fs2.promises.writeFile(tmpFile, JSON.stringify([...values])).catch(noop);
|
|
1758
|
+
}
|
|
1759
|
+
});
|
|
1760
|
+
|
|
1761
|
+
// src/vite/plugin.ts
|
|
1715
1762
|
var debug = (0, import_debug.default)("@marko/run");
|
|
1716
|
-
var __dirname =
|
|
1763
|
+
var __dirname = import_path3.default.dirname((0, import_url2.fileURLToPath)(__importMetaURL));
|
|
1717
1764
|
var PLUGIN_NAME_PREFIX = "marko-run-vite";
|
|
1718
1765
|
var POSIX_SEP = "/";
|
|
1719
1766
|
var WINDOWS_SEP = "\\";
|
|
1720
|
-
var normalizePath =
|
|
1767
|
+
var normalizePath = import_path3.default.sep === WINDOWS_SEP ? (id) => id.replace(/\\/g, POSIX_SEP) : (id) => id;
|
|
1721
1768
|
function markoRun(opts = {}) {
|
|
1722
1769
|
let { routesDir, adapter, ...markoVitePluginOptions } = opts;
|
|
1723
1770
|
let compiler;
|
|
@@ -1734,7 +1781,6 @@ function markoRun(opts = {}) {
|
|
|
1734
1781
|
let devServer;
|
|
1735
1782
|
let routes;
|
|
1736
1783
|
let routeData;
|
|
1737
|
-
let routeDataFilename = "routes.json";
|
|
1738
1784
|
let extractVerbs;
|
|
1739
1785
|
let resolvedConfig;
|
|
1740
1786
|
let typesFile;
|
|
@@ -1750,15 +1796,15 @@ function markoRun(opts = {}) {
|
|
|
1750
1796
|
root,
|
|
1751
1797
|
"{.tsconfig*,tsconfig*.json}"
|
|
1752
1798
|
)))) {
|
|
1753
|
-
const filepath =
|
|
1799
|
+
const filepath = import_path3.default.join(typesDir, "routes.d.ts");
|
|
1754
1800
|
const data = await renderRouteTypeInfo(
|
|
1755
1801
|
routes2,
|
|
1756
|
-
normalizePath(
|
|
1802
|
+
normalizePath(import_path3.default.relative(typesDir, resolvedRoutesDir)),
|
|
1757
1803
|
adapter
|
|
1758
1804
|
);
|
|
1759
|
-
if (data !== typesFile || !
|
|
1805
|
+
if (data !== typesFile || !import_fs3.default.existsSync(filepath)) {
|
|
1760
1806
|
await ensureDir(typesDir);
|
|
1761
|
-
await
|
|
1807
|
+
await import_fs3.default.promises.writeFile(filepath, typesFile = data);
|
|
1762
1808
|
}
|
|
1763
1809
|
}
|
|
1764
1810
|
}
|
|
@@ -1793,24 +1839,24 @@ function markoRun(opts = {}) {
|
|
|
1793
1839
|
}
|
|
1794
1840
|
if (route.page) {
|
|
1795
1841
|
virtualFiles.set(
|
|
1796
|
-
|
|
1842
|
+
import_path3.default.posix.join(root, `${route.entryName}.marko`),
|
|
1797
1843
|
render ? renderRouteTemplate(route) : ""
|
|
1798
1844
|
);
|
|
1799
1845
|
}
|
|
1800
1846
|
virtualFiles.set(
|
|
1801
|
-
|
|
1847
|
+
import_path3.default.posix.join(root, `${route.entryName}.js`),
|
|
1802
1848
|
render ? renderRouteEntry(route) : ""
|
|
1803
1849
|
);
|
|
1804
1850
|
}
|
|
1805
1851
|
for (const route of Object.values(routes.special)) {
|
|
1806
1852
|
virtualFiles.set(
|
|
1807
|
-
|
|
1853
|
+
import_path3.default.posix.join(root, `${route.entryName}.marko`),
|
|
1808
1854
|
render ? renderRouteTemplate(route) : ""
|
|
1809
1855
|
);
|
|
1810
1856
|
}
|
|
1811
1857
|
if (routes.middleware.length) {
|
|
1812
1858
|
virtualFiles.set(
|
|
1813
|
-
|
|
1859
|
+
import_path3.default.posix.join(root, `${markoRunFilePrefix}middleware.js`),
|
|
1814
1860
|
render ? renderMiddleware(routes.middleware) : ""
|
|
1815
1861
|
);
|
|
1816
1862
|
}
|
|
@@ -1842,7 +1888,7 @@ function markoRun(opts = {}) {
|
|
|
1842
1888
|
}
|
|
1843
1889
|
console.error(err);
|
|
1844
1890
|
virtualFiles.set(
|
|
1845
|
-
|
|
1891
|
+
import_path3.default.posix.join(root, `${markoRunFilePrefix}error.marko`),
|
|
1846
1892
|
renderEntryTemplate(`${markoRunFilePrefix}error`, ["<dev-error-page>"])
|
|
1847
1893
|
);
|
|
1848
1894
|
virtualFiles.set(
|
|
@@ -1886,25 +1932,25 @@ function markoRun(opts = {}) {
|
|
|
1886
1932
|
compiler.taglib.register("@marko/run", {
|
|
1887
1933
|
"<dev-error-page>": {
|
|
1888
1934
|
template: normalizePath(
|
|
1889
|
-
|
|
1935
|
+
import_path3.default.resolve(__dirname, "../components/dev-error-page.marko")
|
|
1890
1936
|
)
|
|
1891
1937
|
},
|
|
1892
1938
|
"<*>": {
|
|
1893
|
-
transform:
|
|
1939
|
+
transform: import_path3.default.resolve(
|
|
1894
1940
|
__dirname,
|
|
1895
1941
|
"../components/src-attributes-transformer.cjs"
|
|
1896
1942
|
)
|
|
1897
1943
|
}
|
|
1898
1944
|
});
|
|
1899
1945
|
routesDir = opts.routesDir || "src/routes";
|
|
1900
|
-
|
|
1901
|
-
`marko-
|
|
1946
|
+
store = new ReadOncePersistedStore(
|
|
1947
|
+
`vite-marko-run${opts.runtimeId ? `-${opts.runtimeId}` : ""}`
|
|
1902
1948
|
);
|
|
1903
1949
|
markoVitePluginOptions.runtimeId = opts.runtimeId;
|
|
1904
1950
|
markoVitePluginOptions.basePathVar = opts.basePathVar;
|
|
1905
|
-
resolvedRoutesDir =
|
|
1906
|
-
typesDir =
|
|
1907
|
-
devEntryFile =
|
|
1951
|
+
resolvedRoutesDir = import_path3.default.resolve(root, routesDir);
|
|
1952
|
+
typesDir = import_path3.default.join(root, ".marko-run");
|
|
1953
|
+
devEntryFile = import_path3.default.join(root, "index.html");
|
|
1908
1954
|
devEntryFilePosix = normalizePath(devEntryFile);
|
|
1909
1955
|
const assetsDir = ((_d = config2.build) == null ? void 0 : _d.assetsDir) || "assets";
|
|
1910
1956
|
let rollupOutputOptions = (_f = (_e = config2.build) == null ? void 0 : _e.rollupOptions) == null ? void 0 : _f.output;
|
|
@@ -1963,7 +2009,8 @@ function markoRun(opts = {}) {
|
|
|
1963
2009
|
// Avoid server & client deleting files from each other.
|
|
1964
2010
|
rollupOptions: {
|
|
1965
2011
|
output: rollupOutputOptions
|
|
1966
|
-
}
|
|
2012
|
+
},
|
|
2013
|
+
modulePreload: { polyfill: false }
|
|
1967
2014
|
},
|
|
1968
2015
|
optimizeDeps: {
|
|
1969
2016
|
entries: !((_h = config2.optimizeDeps) == null ? void 0 : _h.entries) ? [
|
|
@@ -2013,7 +2060,7 @@ function markoRun(opts = {}) {
|
|
|
2013
2060
|
configureServer(_server) {
|
|
2014
2061
|
devServer = _server;
|
|
2015
2062
|
devServer.watcher.on("all", async (type, filename) => {
|
|
2016
|
-
const routableFileType = matchRoutableFile(
|
|
2063
|
+
const routableFileType = matchRoutableFile(import_path3.default.parse(filename).base);
|
|
2017
2064
|
if (filename.startsWith(resolvedRoutesDir) && routableFileType) {
|
|
2018
2065
|
if (type === "add") {
|
|
2019
2066
|
isStale = true;
|
|
@@ -2036,9 +2083,7 @@ function markoRun(opts = {}) {
|
|
|
2036
2083
|
async buildStart(_options) {
|
|
2037
2084
|
if (isBuild && !isSSRBuild) {
|
|
2038
2085
|
try {
|
|
2039
|
-
routeData =
|
|
2040
|
-
await store.get(routeDataFilename)
|
|
2041
|
-
);
|
|
2086
|
+
routeData = await store.read();
|
|
2042
2087
|
} catch {
|
|
2043
2088
|
this.error(
|
|
2044
2089
|
`You must run the "ssr" build before the "browser" build.`
|
|
@@ -2060,9 +2105,9 @@ function markoRun(opts = {}) {
|
|
|
2060
2105
|
let virtualFilePath;
|
|
2061
2106
|
if (importee.startsWith(virtualFilePrefix)) {
|
|
2062
2107
|
virtualFilePath = importee.slice(virtualFilePrefix.length + 1);
|
|
2063
|
-
importee =
|
|
2108
|
+
importee = import_path3.default.resolve(root, virtualFilePath);
|
|
2064
2109
|
} else if (!isBuild && importer && (importer === devEntryFile || normalizePath(importer) === devEntryFilePosix) && importee.startsWith(`/${markoRunFilePrefix}`)) {
|
|
2065
|
-
importee =
|
|
2110
|
+
importee = import_path3.default.resolve(root, "." + importee);
|
|
2066
2111
|
}
|
|
2067
2112
|
importee = normalizePath(importee);
|
|
2068
2113
|
if (isStale) {
|
|
@@ -2071,7 +2116,7 @@ function markoRun(opts = {}) {
|
|
|
2071
2116
|
if (virtualFiles.has(importee)) {
|
|
2072
2117
|
resolved = importee;
|
|
2073
2118
|
} else if (virtualFilePath) {
|
|
2074
|
-
const filePath =
|
|
2119
|
+
const filePath = import_path3.default.resolve(__dirname, "..", virtualFilePath);
|
|
2075
2120
|
const resolution = await this.resolve(filePath, importer, {
|
|
2076
2121
|
skipSelf: true
|
|
2077
2122
|
});
|
|
@@ -2110,7 +2155,7 @@ function markoRun(opts = {}) {
|
|
|
2110
2155
|
const builtEntries = Object.values(bundle).reduce(
|
|
2111
2156
|
(acc, item) => {
|
|
2112
2157
|
if (item.type === "chunk" && item.isEntry) {
|
|
2113
|
-
acc.push(
|
|
2158
|
+
acc.push(import_path3.default.join(options.dir, item.fileName));
|
|
2114
2159
|
}
|
|
2115
2160
|
return acc;
|
|
2116
2161
|
},
|
|
@@ -2126,7 +2171,7 @@ function markoRun(opts = {}) {
|
|
|
2126
2171
|
for (const [key, code] of virtualFiles) {
|
|
2127
2172
|
routeData.files.push({ key, code });
|
|
2128
2173
|
}
|
|
2129
|
-
|
|
2174
|
+
store.write(routeData);
|
|
2130
2175
|
await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes.list));
|
|
2131
2176
|
} else if (process.env.MR_EXPLORER !== "true") {
|
|
2132
2177
|
logRoutesTable(routes, bundle, options);
|
|
@@ -2201,17 +2246,17 @@ async function globFileExists(root, pattern) {
|
|
|
2201
2246
|
return (await (0, import_glob.glob)(pattern, { root })).length > 0;
|
|
2202
2247
|
}
|
|
2203
2248
|
async function ensureDir(dir) {
|
|
2204
|
-
if (!
|
|
2205
|
-
await
|
|
2249
|
+
if (!import_fs3.default.existsSync(dir)) {
|
|
2250
|
+
await import_fs3.default.promises.mkdir(dir, { recursive: true });
|
|
2206
2251
|
}
|
|
2207
2252
|
}
|
|
2208
2253
|
async function getPackageData(dir) {
|
|
2209
2254
|
do {
|
|
2210
|
-
const pkgPath =
|
|
2211
|
-
if (
|
|
2212
|
-
return JSON.parse(await
|
|
2255
|
+
const pkgPath = import_path3.default.join(dir, "package.json");
|
|
2256
|
+
if (import_fs3.default.existsSync(pkgPath)) {
|
|
2257
|
+
return JSON.parse(await import_fs3.default.promises.readFile(pkgPath, "utf-8"));
|
|
2213
2258
|
}
|
|
2214
|
-
} while (dir !== (dir =
|
|
2259
|
+
} while (dir !== (dir = import_path3.default.dirname(dir)));
|
|
2215
2260
|
return null;
|
|
2216
2261
|
}
|
|
2217
2262
|
async function resolveAdapter(root, options, log) {
|
|
@@ -2253,11 +2298,11 @@ function getEntryFileName(file) {
|
|
|
2253
2298
|
var import_net = __toESM(require("net"), 1);
|
|
2254
2299
|
var import_child_process = __toESM(require("child_process"), 1);
|
|
2255
2300
|
var import_dotenv = require("dotenv");
|
|
2256
|
-
var
|
|
2301
|
+
var import_fs4 = __toESM(require("fs"), 1);
|
|
2257
2302
|
var import_cluster = __toESM(require("cluster"), 1);
|
|
2258
2303
|
async function parseEnv(envFile) {
|
|
2259
|
-
if (
|
|
2260
|
-
const content = await
|
|
2304
|
+
if (import_fs4.default.existsSync(envFile)) {
|
|
2305
|
+
const content = await import_fs4.default.promises.readFile(envFile, "utf8");
|
|
2261
2306
|
return (0, import_dotenv.parse)(content);
|
|
2262
2307
|
}
|
|
2263
2308
|
}
|