@marko/run 0.9.5 → 0.9.7
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 +69 -14
- package/dist/.tsbuildinfo +1 -1
- package/dist/adapter/dev-server.d.ts +1 -1
- package/dist/adapter/index.cjs +10 -9
- package/dist/adapter/index.js +16 -15
- package/dist/cli/index.mjs +61 -23
- package/dist/runtime/index.d.ts +13 -3
- package/dist/runtime/internal.cjs +49 -3
- package/dist/runtime/internal.d.ts +2 -1
- package/dist/runtime/internal.js +47 -2
- package/dist/runtime/namespace.d.ts +1 -1
- package/dist/runtime/types.d.ts +24 -18
- package/dist/vite/index.cjs +85 -20
- package/dist/vite/index.d.ts +2 -2
- package/dist/vite/index.js +85 -21
- package/dist/vite/utils/meta-data.d.ts +3 -0
- package/package.json +1 -1
package/dist/vite/index.cjs
CHANGED
|
@@ -43,6 +43,7 @@ __export(vite_exports, {
|
|
|
43
43
|
defaultConfigPlugin: () => defaultConfigPlugin,
|
|
44
44
|
getApi: () => getApi,
|
|
45
45
|
getAvailablePort: () => getAvailablePort,
|
|
46
|
+
getMetaDataForVerb: () => getMetaDataForVerb,
|
|
46
47
|
getPackageData: () => getPackageData,
|
|
47
48
|
isPortInUse: () => isPortInUse,
|
|
48
49
|
loadEnv: () => loadEnv,
|
|
@@ -72,6 +73,7 @@ var import_kleur = __toESM(require("kleur"), 1);
|
|
|
72
73
|
var import_supports_color = __toESM(require("supports-color"), 1);
|
|
73
74
|
function stripAnsi(string) {
|
|
74
75
|
return string.replace(
|
|
76
|
+
/* cspell:disable-next-line */
|
|
75
77
|
/([\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><])/g,
|
|
76
78
|
""
|
|
77
79
|
);
|
|
@@ -354,7 +356,10 @@ function renderRouteEntry(route, rootDir) {
|
|
|
354
356
|
const imports = writer.branch("imports");
|
|
355
357
|
const runtimeImports = [];
|
|
356
358
|
if (handler) {
|
|
357
|
-
runtimeImports.push("
|
|
359
|
+
runtimeImports.push("normalizeHandler");
|
|
360
|
+
}
|
|
361
|
+
if (meta) {
|
|
362
|
+
runtimeImports.push("normalizeMeta");
|
|
358
363
|
}
|
|
359
364
|
if (handler || middleware.length) {
|
|
360
365
|
runtimeImports.push("call");
|
|
@@ -386,7 +391,9 @@ function renderRouteEntry(route, rootDir) {
|
|
|
386
391
|
for (const verb of handler.verbs) {
|
|
387
392
|
const importName = verb.toUpperCase();
|
|
388
393
|
names.push(importName);
|
|
389
|
-
writer.writeLines(
|
|
394
|
+
writer.writeLines(
|
|
395
|
+
`const ${verb}Handler = normalizeHandler(${importName});`
|
|
396
|
+
);
|
|
390
397
|
}
|
|
391
398
|
imports.writeLines(
|
|
392
399
|
`import { ${names.join(", ")} } from "${normalizedRelativePath(rootDir, handler.filePath)}";`
|
|
@@ -398,8 +405,18 @@ function renderRouteEntry(route, rootDir) {
|
|
|
398
405
|
);
|
|
399
406
|
}
|
|
400
407
|
if (meta) {
|
|
408
|
+
const metaName = `meta${index}`;
|
|
409
|
+
const metaVerbsExports = verbs.map((verb) => {
|
|
410
|
+
var _a2;
|
|
411
|
+
const name = verb === "head" && !((_a2 = handler == null ? void 0 : handler.verbs) == null ? void 0 : _a2.includes(verb)) ? "GET" : verb.toUpperCase();
|
|
412
|
+
return `${name}: ${verb}${index}_meta`;
|
|
413
|
+
}).join(", ");
|
|
414
|
+
writer.writeLines("");
|
|
401
415
|
imports.writeLines(
|
|
402
|
-
`
|
|
416
|
+
`import ${metaName} from "${normalizedRelativePath(rootDir, meta.filePath)}";`
|
|
417
|
+
);
|
|
418
|
+
writer.writeLines(
|
|
419
|
+
`export const { ${metaVerbsExports} } = normalizeMeta(${metaName});`
|
|
403
420
|
);
|
|
404
421
|
}
|
|
405
422
|
for (const verb of verbs) {
|
|
@@ -518,10 +535,16 @@ function renderRouter(routes, rootDir, runtimeInclude, options = {
|
|
|
518
535
|
);
|
|
519
536
|
for (const route of routes.list) {
|
|
520
537
|
const verbs = getVerbs(route);
|
|
521
|
-
const
|
|
522
|
-
|
|
538
|
+
const routeImports = [];
|
|
539
|
+
for (const verb of verbs) {
|
|
540
|
+
const verbName = `${verb}${route.index}`;
|
|
541
|
+
routeImports.push(verbName);
|
|
542
|
+
if (route.meta) {
|
|
543
|
+
routeImports.push(`${verbName}_meta`);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
523
546
|
imports.writeLines(
|
|
524
|
-
`import { ${
|
|
547
|
+
`import { ${routeImports.join(", ")} } from "${virtualFilePrefix}/${getRouteVirtualFileName(route)}";`
|
|
525
548
|
);
|
|
526
549
|
}
|
|
527
550
|
for (const route of Object.values(routes.special)) {
|
|
@@ -813,14 +836,14 @@ function renderParams(params, pathIndex) {
|
|
|
813
836
|
function renderMatch(verb, route, path7, pathIndex) {
|
|
814
837
|
const handler = `${verb}${route.index}`;
|
|
815
838
|
const params = path7.params ? renderParams(path7.params, pathIndex) : "{}";
|
|
816
|
-
const meta = route.meta ?
|
|
839
|
+
const meta = route.meta ? `${verb}${route.index}_meta` : "{}";
|
|
817
840
|
return `{ handler: ${handler}, params: ${params}, meta: ${meta}, path: '${path7.path}' }`;
|
|
818
841
|
}
|
|
819
842
|
function renderMiddleware(middleware, rootDir) {
|
|
820
843
|
const writer = createStringWriter();
|
|
821
844
|
const imports = writer.branch("imports");
|
|
822
845
|
imports.writeLines(
|
|
823
|
-
`import {
|
|
846
|
+
`import { normalizeHandler } from "${virtualFilePrefix}/runtime/internal";`
|
|
824
847
|
);
|
|
825
848
|
writer.writeLines("");
|
|
826
849
|
for (const { id, filePath } of middleware) {
|
|
@@ -828,7 +851,9 @@ function renderMiddleware(middleware, rootDir) {
|
|
|
828
851
|
imports.writeLines(
|
|
829
852
|
`import ${importName} from "${normalizedRelativePath(rootDir, filePath)}";`
|
|
830
853
|
);
|
|
831
|
-
writer.writeLines(
|
|
854
|
+
writer.writeLines(
|
|
855
|
+
`export const mware${id} = normalizeHandler(${importName});`
|
|
856
|
+
);
|
|
832
857
|
}
|
|
833
858
|
imports.join();
|
|
834
859
|
return writer.end();
|
|
@@ -987,7 +1012,12 @@ function writeModuleDeclaration(writer, name, routeType, moduleTypes) {
|
|
|
987
1012
|
export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform };
|
|
988
1013
|
export type Route = ${routeType};
|
|
989
1014
|
export type Context = Run.MultiRouteContext<Route>${isMarko ? " & Marko.Global" : ""};
|
|
990
|
-
export type Handler = Run.HandlerLike<Route
|
|
1015
|
+
export type Handler = Run.HandlerLike<Route>;`);
|
|
1016
|
+
for (const verb of httpVerbs) {
|
|
1017
|
+
writer.write(`
|
|
1018
|
+
export type ${verb.toUpperCase()} = Run.HandlerLike<Route, "${verb.toUpperCase()}">;`);
|
|
1019
|
+
}
|
|
1020
|
+
writer.write(`
|
|
991
1021
|
/** @deprecated use \`((context, next) => { ... }) satisfies MarkoRun.Handler\` instead */
|
|
992
1022
|
export const route: Run.HandlerTypeFn<Route>;
|
|
993
1023
|
}`);
|
|
@@ -1352,12 +1382,12 @@ var VDir = _VDir;
|
|
|
1352
1382
|
// src/vite/routes/builder.ts
|
|
1353
1383
|
var markoFiles = `(${RoutableFileTypes.Layout}|${RoutableFileTypes.Page}|${RoutableFileTypes.NotFound}|${RoutableFileTypes.Error})\\.(?:.*\\.)?(marko)`;
|
|
1354
1384
|
var nonMarkoFiles = `(${RoutableFileTypes.Middleware}|${RoutableFileTypes.Handler}|${RoutableFileTypes.Meta})\\.(?:.*\\.)?(.+)`;
|
|
1355
|
-
var
|
|
1385
|
+
var RoutableFileRegex = new RegExp(
|
|
1356
1386
|
`[+](?:${markoFiles}|${nonMarkoFiles})$`,
|
|
1357
1387
|
"i"
|
|
1358
1388
|
);
|
|
1359
1389
|
function matchRoutableFile(filename) {
|
|
1360
|
-
const match = filename.match(
|
|
1390
|
+
const match = filename.match(RoutableFileRegex);
|
|
1361
1391
|
return match && (match[1] || match[3]).toLowerCase();
|
|
1362
1392
|
}
|
|
1363
1393
|
async function buildRoutes(sources, outDir) {
|
|
@@ -1399,7 +1429,7 @@ async function buildRoutes(sources, outDir) {
|
|
|
1399
1429
|
},
|
|
1400
1430
|
onFile(file) {
|
|
1401
1431
|
const { name } = file;
|
|
1402
|
-
const match = name.match(
|
|
1432
|
+
const match = name.match(RoutableFileRegex);
|
|
1403
1433
|
if (!match) {
|
|
1404
1434
|
return;
|
|
1405
1435
|
}
|
|
@@ -2173,9 +2203,15 @@ function markoRun(opts = {}) {
|
|
|
2173
2203
|
}
|
|
2174
2204
|
rollupOutputOptions = mergeOutputOptions(
|
|
2175
2205
|
{
|
|
2176
|
-
assetFileNames
|
|
2206
|
+
assetFileNames(info) {
|
|
2207
|
+
var _a2;
|
|
2208
|
+
const name = ((_a2 = info.names) == null ? void 0 : _a2[0]) && cleanFileName(info.names[0]);
|
|
2209
|
+
return name ? `${assetsDir}/${name}-[hash].[ext]` : `${assetsDir}/_[hash].[ext]`;
|
|
2210
|
+
},
|
|
2177
2211
|
entryFileNames(info) {
|
|
2178
|
-
|
|
2212
|
+
const raw = getEntryFileName(info.name) || info.name;
|
|
2213
|
+
const name = raw && cleanFileName(raw);
|
|
2214
|
+
return name ? `${assetsDir}/${name}-[hash].js` : `${assetsDir}/_[hash].js`;
|
|
2179
2215
|
},
|
|
2180
2216
|
chunkFileNames: isSSRBuild ? `_[hash].js` : `${assetsDir}/_[hash].js`
|
|
2181
2217
|
},
|
|
@@ -2457,11 +2493,11 @@ async function resolveAdapter(root, options, log) {
|
|
|
2457
2493
|
}
|
|
2458
2494
|
const pkg = await getPackageData(root);
|
|
2459
2495
|
if (pkg) {
|
|
2460
|
-
let
|
|
2496
|
+
let dependencies = pkg.dependencies ? Object.keys(pkg.dependencies) : [];
|
|
2461
2497
|
if (pkg.devDependencies) {
|
|
2462
|
-
|
|
2498
|
+
dependencies = dependencies.concat(Object.keys(pkg.devDependencies));
|
|
2463
2499
|
}
|
|
2464
|
-
for (const name of
|
|
2500
|
+
for (const name of dependencies) {
|
|
2465
2501
|
if (name.startsWith("@marko/run-adapter") || name.indexOf("marko-run-adapter") !== -1) {
|
|
2466
2502
|
try {
|
|
2467
2503
|
const module3 = await import(
|
|
@@ -2469,7 +2505,7 @@ async function resolveAdapter(root, options, log) {
|
|
|
2469
2505
|
name
|
|
2470
2506
|
);
|
|
2471
2507
|
log && debug(
|
|
2472
|
-
`Using adapter ${name} listed in your package.json
|
|
2508
|
+
`Using adapter ${name} listed in your package.json dependencies`
|
|
2473
2509
|
);
|
|
2474
2510
|
return module3.default();
|
|
2475
2511
|
} catch (err) {
|
|
@@ -2491,6 +2527,9 @@ function getEntryFileName(file) {
|
|
|
2491
2527
|
const match = file && markoEntryFileRegex.exec(file);
|
|
2492
2528
|
return match ? match[1] : void 0;
|
|
2493
2529
|
}
|
|
2530
|
+
function cleanFileName(name) {
|
|
2531
|
+
return name.replace(/\.[^/.]+$/, "").replace(/[^a-zA-Z0-9._[\]-]+/g, "-").replace(/-{2,}/g, "-").replace(/^-|-$/g, "");
|
|
2532
|
+
}
|
|
2494
2533
|
function getPlugin(config2) {
|
|
2495
2534
|
return config2.plugins.find(
|
|
2496
2535
|
(plugin) => plugin.name === `${PLUGIN_NAME_PREFIX}:pre`
|
|
@@ -2528,6 +2567,31 @@ var defaultConfigPlugin = {
|
|
|
2528
2567
|
}
|
|
2529
2568
|
};
|
|
2530
2569
|
|
|
2570
|
+
// src/vite/utils/meta-data.ts
|
|
2571
|
+
var verbKeys = new Set(httpVerbs.map((v) => v.toUpperCase()));
|
|
2572
|
+
function isObject(obj) {
|
|
2573
|
+
return obj && typeof obj === "object" && !Array.isArray(obj);
|
|
2574
|
+
}
|
|
2575
|
+
function getMetaDataForVerb(data, verb) {
|
|
2576
|
+
if (!httpVerbs.includes(verb.toLowerCase())) {
|
|
2577
|
+
throw new Error(
|
|
2578
|
+
`Invalid argument 'verb': expected one of ${[...verbKeys].join(", ")} but received ${verb}`
|
|
2579
|
+
);
|
|
2580
|
+
}
|
|
2581
|
+
if (isObject(data)) {
|
|
2582
|
+
return Object.keys(data).reduce(
|
|
2583
|
+
(result, key) => {
|
|
2584
|
+
if (!(key in result || verbKeys.has(key))) {
|
|
2585
|
+
result[key] = data[key];
|
|
2586
|
+
}
|
|
2587
|
+
return result;
|
|
2588
|
+
},
|
|
2589
|
+
isObject(data[verb]) ? { ...data[verb] } : {}
|
|
2590
|
+
);
|
|
2591
|
+
}
|
|
2592
|
+
return data;
|
|
2593
|
+
}
|
|
2594
|
+
|
|
2531
2595
|
// src/vite/utils/server.ts
|
|
2532
2596
|
var import_child_process = __toESM(require("child_process"), 1);
|
|
2533
2597
|
var import_cluster = __toESM(require("cluster"), 1);
|
|
@@ -2640,7 +2704,7 @@ async function waitForServer(port, wait = 0) {
|
|
|
2640
2704
|
await sleep(100);
|
|
2641
2705
|
} else {
|
|
2642
2706
|
throw new Error(
|
|
2643
|
-
`Timeout while
|
|
2707
|
+
`Timeout while waiting for server to start on port "${port}".`
|
|
2644
2708
|
);
|
|
2645
2709
|
}
|
|
2646
2710
|
}
|
|
@@ -2678,6 +2742,7 @@ function sleep(ms) {
|
|
|
2678
2742
|
defaultConfigPlugin,
|
|
2679
2743
|
getApi,
|
|
2680
2744
|
getAvailablePort,
|
|
2745
|
+
getMetaDataForVerb,
|
|
2681
2746
|
getPackageData,
|
|
2682
2747
|
isPortInUse,
|
|
2683
2748
|
loadEnv,
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default, defaultConfigPlugin, getApi, getPackageData } from "./plugin";
|
|
2
2
|
export type { Adapter, AdapterConfig, BuiltRoutes, ExplorerData, ExternalRoutes, HttpVerb, Options, PackageData, PathInfo, RoutableFile, RoutableFileType, Route, RouteGenerationData, } from "./types";
|
|
3
|
-
export
|
|
4
|
-
export { getAvailablePort, isPortInUse, loadEnv, parseEnv, spawnServer, spawnServerWorker, } from "./utils/server";
|
|
3
|
+
export { getMetaDataForVerb } from "./utils/meta-data";
|
|
4
|
+
export { getAvailablePort, isPortInUse, loadEnv, parseEnv, type SpawnedServer, spawnServer, spawnServerWorker, } from "./utils/server";
|
package/dist/vite/index.js
CHANGED
|
@@ -25,9 +25,10 @@ import {
|
|
|
25
25
|
|
|
26
26
|
// src/adapter/utils.ts
|
|
27
27
|
import kleur from "kleur";
|
|
28
|
-
import
|
|
28
|
+
import supportsColor from "supports-color";
|
|
29
29
|
function stripAnsi(string) {
|
|
30
30
|
return string.replace(
|
|
31
|
+
/* cspell:disable-next-line */
|
|
31
32
|
/([\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><])/g,
|
|
32
33
|
""
|
|
33
34
|
);
|
|
@@ -310,7 +311,10 @@ function renderRouteEntry(route, rootDir) {
|
|
|
310
311
|
const imports = writer.branch("imports");
|
|
311
312
|
const runtimeImports = [];
|
|
312
313
|
if (handler) {
|
|
313
|
-
runtimeImports.push("
|
|
314
|
+
runtimeImports.push("normalizeHandler");
|
|
315
|
+
}
|
|
316
|
+
if (meta) {
|
|
317
|
+
runtimeImports.push("normalizeMeta");
|
|
314
318
|
}
|
|
315
319
|
if (handler || middleware.length) {
|
|
316
320
|
runtimeImports.push("call");
|
|
@@ -342,7 +346,9 @@ function renderRouteEntry(route, rootDir) {
|
|
|
342
346
|
for (const verb of handler.verbs) {
|
|
343
347
|
const importName = verb.toUpperCase();
|
|
344
348
|
names.push(importName);
|
|
345
|
-
writer.writeLines(
|
|
349
|
+
writer.writeLines(
|
|
350
|
+
`const ${verb}Handler = normalizeHandler(${importName});`
|
|
351
|
+
);
|
|
346
352
|
}
|
|
347
353
|
imports.writeLines(
|
|
348
354
|
`import { ${names.join(", ")} } from "${normalizedRelativePath(rootDir, handler.filePath)}";`
|
|
@@ -354,8 +360,18 @@ function renderRouteEntry(route, rootDir) {
|
|
|
354
360
|
);
|
|
355
361
|
}
|
|
356
362
|
if (meta) {
|
|
363
|
+
const metaName = `meta${index}`;
|
|
364
|
+
const metaVerbsExports = verbs.map((verb) => {
|
|
365
|
+
var _a2;
|
|
366
|
+
const name = verb === "head" && !((_a2 = handler == null ? void 0 : handler.verbs) == null ? void 0 : _a2.includes(verb)) ? "GET" : verb.toUpperCase();
|
|
367
|
+
return `${name}: ${verb}${index}_meta`;
|
|
368
|
+
}).join(", ");
|
|
369
|
+
writer.writeLines("");
|
|
357
370
|
imports.writeLines(
|
|
358
|
-
`
|
|
371
|
+
`import ${metaName} from "${normalizedRelativePath(rootDir, meta.filePath)}";`
|
|
372
|
+
);
|
|
373
|
+
writer.writeLines(
|
|
374
|
+
`export const { ${metaVerbsExports} } = normalizeMeta(${metaName});`
|
|
359
375
|
);
|
|
360
376
|
}
|
|
361
377
|
for (const verb of verbs) {
|
|
@@ -474,10 +490,16 @@ function renderRouter(routes, rootDir, runtimeInclude, options = {
|
|
|
474
490
|
);
|
|
475
491
|
for (const route of routes.list) {
|
|
476
492
|
const verbs = getVerbs(route);
|
|
477
|
-
const
|
|
478
|
-
|
|
493
|
+
const routeImports = [];
|
|
494
|
+
for (const verb of verbs) {
|
|
495
|
+
const verbName = `${verb}${route.index}`;
|
|
496
|
+
routeImports.push(verbName);
|
|
497
|
+
if (route.meta) {
|
|
498
|
+
routeImports.push(`${verbName}_meta`);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
479
501
|
imports.writeLines(
|
|
480
|
-
`import { ${
|
|
502
|
+
`import { ${routeImports.join(", ")} } from "${virtualFilePrefix}/${getRouteVirtualFileName(route)}";`
|
|
481
503
|
);
|
|
482
504
|
}
|
|
483
505
|
for (const route of Object.values(routes.special)) {
|
|
@@ -769,14 +791,14 @@ function renderParams(params, pathIndex) {
|
|
|
769
791
|
function renderMatch(verb, route, path7, pathIndex) {
|
|
770
792
|
const handler = `${verb}${route.index}`;
|
|
771
793
|
const params = path7.params ? renderParams(path7.params, pathIndex) : "{}";
|
|
772
|
-
const meta = route.meta ?
|
|
794
|
+
const meta = route.meta ? `${verb}${route.index}_meta` : "{}";
|
|
773
795
|
return `{ handler: ${handler}, params: ${params}, meta: ${meta}, path: '${path7.path}' }`;
|
|
774
796
|
}
|
|
775
797
|
function renderMiddleware(middleware, rootDir) {
|
|
776
798
|
const writer = createStringWriter();
|
|
777
799
|
const imports = writer.branch("imports");
|
|
778
800
|
imports.writeLines(
|
|
779
|
-
`import {
|
|
801
|
+
`import { normalizeHandler } from "${virtualFilePrefix}/runtime/internal";`
|
|
780
802
|
);
|
|
781
803
|
writer.writeLines("");
|
|
782
804
|
for (const { id, filePath } of middleware) {
|
|
@@ -784,7 +806,9 @@ function renderMiddleware(middleware, rootDir) {
|
|
|
784
806
|
imports.writeLines(
|
|
785
807
|
`import ${importName} from "${normalizedRelativePath(rootDir, filePath)}";`
|
|
786
808
|
);
|
|
787
|
-
writer.writeLines(
|
|
809
|
+
writer.writeLines(
|
|
810
|
+
`export const mware${id} = normalizeHandler(${importName});`
|
|
811
|
+
);
|
|
788
812
|
}
|
|
789
813
|
imports.join();
|
|
790
814
|
return writer.end();
|
|
@@ -943,7 +967,12 @@ function writeModuleDeclaration(writer, name, routeType, moduleTypes) {
|
|
|
943
967
|
export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform };
|
|
944
968
|
export type Route = ${routeType};
|
|
945
969
|
export type Context = Run.MultiRouteContext<Route>${isMarko ? " & Marko.Global" : ""};
|
|
946
|
-
export type Handler = Run.HandlerLike<Route
|
|
970
|
+
export type Handler = Run.HandlerLike<Route>;`);
|
|
971
|
+
for (const verb of httpVerbs) {
|
|
972
|
+
writer.write(`
|
|
973
|
+
export type ${verb.toUpperCase()} = Run.HandlerLike<Route, "${verb.toUpperCase()}">;`);
|
|
974
|
+
}
|
|
975
|
+
writer.write(`
|
|
947
976
|
/** @deprecated use \`((context, next) => { ... }) satisfies MarkoRun.Handler\` instead */
|
|
948
977
|
export const route: Run.HandlerTypeFn<Route>;
|
|
949
978
|
}`);
|
|
@@ -1308,12 +1337,12 @@ var VDir = _VDir;
|
|
|
1308
1337
|
// src/vite/routes/builder.ts
|
|
1309
1338
|
var markoFiles = `(${RoutableFileTypes.Layout}|${RoutableFileTypes.Page}|${RoutableFileTypes.NotFound}|${RoutableFileTypes.Error})\\.(?:.*\\.)?(marko)`;
|
|
1310
1339
|
var nonMarkoFiles = `(${RoutableFileTypes.Middleware}|${RoutableFileTypes.Handler}|${RoutableFileTypes.Meta})\\.(?:.*\\.)?(.+)`;
|
|
1311
|
-
var
|
|
1340
|
+
var RoutableFileRegex = new RegExp(
|
|
1312
1341
|
`[+](?:${markoFiles}|${nonMarkoFiles})$`,
|
|
1313
1342
|
"i"
|
|
1314
1343
|
);
|
|
1315
1344
|
function matchRoutableFile(filename) {
|
|
1316
|
-
const match = filename.match(
|
|
1345
|
+
const match = filename.match(RoutableFileRegex);
|
|
1317
1346
|
return match && (match[1] || match[3]).toLowerCase();
|
|
1318
1347
|
}
|
|
1319
1348
|
async function buildRoutes(sources, outDir) {
|
|
@@ -1355,7 +1384,7 @@ async function buildRoutes(sources, outDir) {
|
|
|
1355
1384
|
},
|
|
1356
1385
|
onFile(file) {
|
|
1357
1386
|
const { name } = file;
|
|
1358
|
-
const match = name.match(
|
|
1387
|
+
const match = name.match(RoutableFileRegex);
|
|
1359
1388
|
if (!match) {
|
|
1360
1389
|
return;
|
|
1361
1390
|
}
|
|
@@ -2129,9 +2158,15 @@ function markoRun(opts = {}) {
|
|
|
2129
2158
|
}
|
|
2130
2159
|
rollupOutputOptions = mergeOutputOptions(
|
|
2131
2160
|
{
|
|
2132
|
-
assetFileNames
|
|
2161
|
+
assetFileNames(info) {
|
|
2162
|
+
var _a2;
|
|
2163
|
+
const name = ((_a2 = info.names) == null ? void 0 : _a2[0]) && cleanFileName(info.names[0]);
|
|
2164
|
+
return name ? `${assetsDir}/${name}-[hash].[ext]` : `${assetsDir}/_[hash].[ext]`;
|
|
2165
|
+
},
|
|
2133
2166
|
entryFileNames(info) {
|
|
2134
|
-
|
|
2167
|
+
const raw = getEntryFileName(info.name) || info.name;
|
|
2168
|
+
const name = raw && cleanFileName(raw);
|
|
2169
|
+
return name ? `${assetsDir}/${name}-[hash].js` : `${assetsDir}/_[hash].js`;
|
|
2135
2170
|
},
|
|
2136
2171
|
chunkFileNames: isSSRBuild ? `_[hash].js` : `${assetsDir}/_[hash].js`
|
|
2137
2172
|
},
|
|
@@ -2413,11 +2448,11 @@ async function resolveAdapter(root, options, log) {
|
|
|
2413
2448
|
}
|
|
2414
2449
|
const pkg = await getPackageData(root);
|
|
2415
2450
|
if (pkg) {
|
|
2416
|
-
let
|
|
2451
|
+
let dependencies = pkg.dependencies ? Object.keys(pkg.dependencies) : [];
|
|
2417
2452
|
if (pkg.devDependencies) {
|
|
2418
|
-
|
|
2453
|
+
dependencies = dependencies.concat(Object.keys(pkg.devDependencies));
|
|
2419
2454
|
}
|
|
2420
|
-
for (const name of
|
|
2455
|
+
for (const name of dependencies) {
|
|
2421
2456
|
if (name.startsWith("@marko/run-adapter") || name.indexOf("marko-run-adapter") !== -1) {
|
|
2422
2457
|
try {
|
|
2423
2458
|
const module2 = await import(
|
|
@@ -2425,7 +2460,7 @@ async function resolveAdapter(root, options, log) {
|
|
|
2425
2460
|
name
|
|
2426
2461
|
);
|
|
2427
2462
|
log && debug(
|
|
2428
|
-
`Using adapter ${name} listed in your package.json
|
|
2463
|
+
`Using adapter ${name} listed in your package.json dependencies`
|
|
2429
2464
|
);
|
|
2430
2465
|
return module2.default();
|
|
2431
2466
|
} catch (err) {
|
|
@@ -2447,6 +2482,9 @@ function getEntryFileName(file) {
|
|
|
2447
2482
|
const match = file && markoEntryFileRegex.exec(file);
|
|
2448
2483
|
return match ? match[1] : void 0;
|
|
2449
2484
|
}
|
|
2485
|
+
function cleanFileName(name) {
|
|
2486
|
+
return name.replace(/\.[^/.]+$/, "").replace(/[^a-zA-Z0-9._[\]-]+/g, "-").replace(/-{2,}/g, "-").replace(/^-|-$/g, "");
|
|
2487
|
+
}
|
|
2450
2488
|
function getPlugin(config2) {
|
|
2451
2489
|
return config2.plugins.find(
|
|
2452
2490
|
(plugin) => plugin.name === `${PLUGIN_NAME_PREFIX}:pre`
|
|
@@ -2484,6 +2522,31 @@ var defaultConfigPlugin = {
|
|
|
2484
2522
|
}
|
|
2485
2523
|
};
|
|
2486
2524
|
|
|
2525
|
+
// src/vite/utils/meta-data.ts
|
|
2526
|
+
var verbKeys = new Set(httpVerbs.map((v) => v.toUpperCase()));
|
|
2527
|
+
function isObject(obj) {
|
|
2528
|
+
return obj && typeof obj === "object" && !Array.isArray(obj);
|
|
2529
|
+
}
|
|
2530
|
+
function getMetaDataForVerb(data, verb) {
|
|
2531
|
+
if (!httpVerbs.includes(verb.toLowerCase())) {
|
|
2532
|
+
throw new Error(
|
|
2533
|
+
`Invalid argument 'verb': expected one of ${[...verbKeys].join(", ")} but received ${verb}`
|
|
2534
|
+
);
|
|
2535
|
+
}
|
|
2536
|
+
if (isObject(data)) {
|
|
2537
|
+
return Object.keys(data).reduce(
|
|
2538
|
+
(result, key) => {
|
|
2539
|
+
if (!(key in result || verbKeys.has(key))) {
|
|
2540
|
+
result[key] = data[key];
|
|
2541
|
+
}
|
|
2542
|
+
return result;
|
|
2543
|
+
},
|
|
2544
|
+
isObject(data[verb]) ? { ...data[verb] } : {}
|
|
2545
|
+
);
|
|
2546
|
+
}
|
|
2547
|
+
return data;
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2487
2550
|
// src/vite/utils/server.ts
|
|
2488
2551
|
import cp from "child_process";
|
|
2489
2552
|
import cluster from "cluster";
|
|
@@ -2596,7 +2659,7 @@ async function waitForServer(port, wait = 0) {
|
|
|
2596
2659
|
await sleep(100);
|
|
2597
2660
|
} else {
|
|
2598
2661
|
throw new Error(
|
|
2599
|
-
`Timeout while
|
|
2662
|
+
`Timeout while waiting for server to start on port "${port}".`
|
|
2600
2663
|
);
|
|
2601
2664
|
}
|
|
2602
2665
|
}
|
|
@@ -2634,6 +2697,7 @@ export {
|
|
|
2634
2697
|
defaultConfigPlugin,
|
|
2635
2698
|
getApi,
|
|
2636
2699
|
getAvailablePort,
|
|
2700
|
+
getMetaDataForVerb,
|
|
2637
2701
|
getPackageData,
|
|
2638
2702
|
isPortInUse,
|
|
2639
2703
|
loadEnv,
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { NormalizedMeta, NormalizedMetaLookup, Verb } from "../../runtime/types";
|
|
2
|
+
export declare function getMetaDataForVerb<T, TVerb extends Verb>(data: T, verb: TVerb): NormalizedMeta<T, TVerb>;
|
|
3
|
+
export declare function getMetaDataLookup<T>(data: T): NormalizedMetaLookup<T>;
|