@marko/run 0.8.0 → 0.9.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 +2 -2
- package/dist/adapter/index.js +2 -2
- package/dist/adapter/middleware.cjs +1 -1
- package/dist/adapter/middleware.js +1 -1
- package/dist/cli/index.mjs +90 -21
- package/dist/vite/constants.d.ts +0 -2
- package/dist/vite/index.cjs +98 -18
- package/dist/vite/index.d.ts +2 -2
- package/dist/vite/index.js +97 -18
- package/dist/vite/plugin.d.ts +4 -1
- package/dist/vite/types.d.ts +8 -0
- package/dist/vite/utils/log.d.ts +2 -2
- package/dist/vite/utils/route.d.ts +1 -0
- package/package.json +2 -2
package/dist/vite/index.js
CHANGED
|
@@ -63,7 +63,6 @@ var httpVerbs = [
|
|
|
63
63
|
"patch",
|
|
64
64
|
"options"
|
|
65
65
|
];
|
|
66
|
-
var serverEntryQuery = "?marko-server-entry";
|
|
67
66
|
var RoutableFileTypes = {
|
|
68
67
|
Page: "page",
|
|
69
68
|
Layout: "layout",
|
|
@@ -99,6 +98,11 @@ function getVerbs(route, noAutoHead) {
|
|
|
99
98
|
}
|
|
100
99
|
return [...verbs].sort((a, b) => httpVerbOrder[a] - httpVerbOrder[b]);
|
|
101
100
|
}
|
|
101
|
+
function getUniqueSortedVerbs(verbs) {
|
|
102
|
+
return [...new Set(verbs)].sort(
|
|
103
|
+
(a, b) => httpVerbOrder[a] - httpVerbOrder[b]
|
|
104
|
+
);
|
|
105
|
+
}
|
|
102
106
|
function hasVerb(route, verb) {
|
|
103
107
|
var _a, _b;
|
|
104
108
|
return verb === "get" && !!route.page || ((_b = (_a = route.handler) == null ? void 0 : _a.verbs) == null ? void 0 : _b.includes(verb)) || verb === "head" && hasVerb(route, "get");
|
|
@@ -350,7 +354,7 @@ function renderRouteEntry(route, rootDir) {
|
|
|
350
354
|
}
|
|
351
355
|
if (page) {
|
|
352
356
|
imports.writeLines(
|
|
353
|
-
`import page from "${normalizedRelativePath(rootDir, route.templateFilePath || page.filePath)}
|
|
357
|
+
`import page from "${normalizedRelativePath(rootDir, route.templateFilePath || page.filePath)}";`
|
|
354
358
|
);
|
|
355
359
|
}
|
|
356
360
|
if (meta) {
|
|
@@ -483,7 +487,7 @@ function renderRouter(routes, rootDir, runtimeInclude, options = {
|
|
|
483
487
|
}
|
|
484
488
|
for (const route of Object.values(routes.special)) {
|
|
485
489
|
imports.writeLines(
|
|
486
|
-
`import page${route.key} from "${normalizedRelativePath(rootDir, route.templateFilePath || route.page.filePath)}
|
|
490
|
+
`import page${route.key} from "${normalizedRelativePath(rootDir, route.templateFilePath || route.page.filePath)}";`
|
|
487
491
|
);
|
|
488
492
|
}
|
|
489
493
|
writer.writeLines(
|
|
@@ -1614,7 +1618,7 @@ var HttpVerbColors = {
|
|
|
1614
1618
|
function verbColor(verb) {
|
|
1615
1619
|
return verb in HttpVerbColors ? HttpVerbColors[verb] : kleur2.gray;
|
|
1616
1620
|
}
|
|
1617
|
-
function logRoutesTable(routes, bundle) {
|
|
1621
|
+
function logRoutesTable(routes, externalRoutes, bundle) {
|
|
1618
1622
|
const hasMiddleware = routes.list.some((route) => route.middleware.length);
|
|
1619
1623
|
const hasMeta = routes.list.some((route) => route.meta);
|
|
1620
1624
|
const headings = ["Method", "Path", "Entry"];
|
|
@@ -1648,7 +1652,7 @@ function logRoutesTable(routes, bundle) {
|
|
|
1648
1652
|
if (route.page && (verb === "get" || verb === "head")) {
|
|
1649
1653
|
entryType.push(kleur2.yellow("page"));
|
|
1650
1654
|
if (verb === "get") {
|
|
1651
|
-
size = prettySize(computeRouteSize(route, bundle));
|
|
1655
|
+
size = prettySize(computeRouteSize(route.templateFilePath, bundle));
|
|
1652
1656
|
}
|
|
1653
1657
|
}
|
|
1654
1658
|
const row = [verbCell];
|
|
@@ -1670,9 +1674,35 @@ function logRoutesTable(routes, bundle) {
|
|
|
1670
1674
|
const row = [kleur2.bold(kleur2.white("*")), key, kleur2.yellow("page")];
|
|
1671
1675
|
hasMiddleware && row.push("");
|
|
1672
1676
|
hasMeta && row.push("");
|
|
1673
|
-
row.push(prettySize(computeRouteSize(route, bundle)));
|
|
1677
|
+
row.push(prettySize(computeRouteSize(route.templateFilePath, bundle)));
|
|
1674
1678
|
table.push(row);
|
|
1675
1679
|
}
|
|
1680
|
+
for (const external of externalRoutes) {
|
|
1681
|
+
for (const route of external.routes) {
|
|
1682
|
+
const verbs = getUniqueSortedVerbs(route.verbs);
|
|
1683
|
+
let firstRow = true;
|
|
1684
|
+
for (const verb of verbs) {
|
|
1685
|
+
let size = "";
|
|
1686
|
+
const verbCell = verbColor(verb)(verb.toUpperCase());
|
|
1687
|
+
if (verb === "get") {
|
|
1688
|
+
size = prettySize(computeRouteSize(route.entryFile, bundle));
|
|
1689
|
+
}
|
|
1690
|
+
const row = [verbCell];
|
|
1691
|
+
if (verbs.length === 1 || firstRow) {
|
|
1692
|
+
row.push({
|
|
1693
|
+
rowSpan: verbs.length,
|
|
1694
|
+
content: prettyPath(route.path)
|
|
1695
|
+
});
|
|
1696
|
+
firstRow = false;
|
|
1697
|
+
}
|
|
1698
|
+
row.push(kleur2.magenta(external.name));
|
|
1699
|
+
hasMiddleware && row.push("");
|
|
1700
|
+
hasMeta && row.push("");
|
|
1701
|
+
row.push(size || "");
|
|
1702
|
+
table.push(row);
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1676
1706
|
if (!table.length) {
|
|
1677
1707
|
table.push([
|
|
1678
1708
|
{
|
|
@@ -1684,11 +1714,10 @@ function logRoutesTable(routes, bundle) {
|
|
|
1684
1714
|
}
|
|
1685
1715
|
console.log(table.toString());
|
|
1686
1716
|
}
|
|
1687
|
-
function computeRouteSize(
|
|
1688
|
-
|
|
1689
|
-
if (facadeModuleId) {
|
|
1717
|
+
function computeRouteSize(filePath, bundle) {
|
|
1718
|
+
if (filePath) {
|
|
1690
1719
|
for (const chunk of Object.values(bundle)) {
|
|
1691
|
-
if (chunk.type === "chunk" && chunk.isEntry && chunk.facadeModuleId ===
|
|
1720
|
+
if (chunk.type === "chunk" && chunk.isEntry && chunk.facadeModuleId === `${filePath}.html`) {
|
|
1692
1721
|
return computeChunkSize(chunk, bundle);
|
|
1693
1722
|
}
|
|
1694
1723
|
}
|
|
@@ -1811,9 +1840,12 @@ function markoRun(opts = {}) {
|
|
|
1811
1840
|
let devEntryFilePosix;
|
|
1812
1841
|
let devServer;
|
|
1813
1842
|
let routes;
|
|
1843
|
+
let entryTemplates;
|
|
1844
|
+
let entryTemplateImporters;
|
|
1814
1845
|
let routeData;
|
|
1815
1846
|
let resolvedConfig;
|
|
1816
1847
|
let typesFile;
|
|
1848
|
+
const externalRoutes = /* @__PURE__ */ new Set();
|
|
1817
1849
|
const seenErrors = /* @__PURE__ */ new Set();
|
|
1818
1850
|
const virtualFiles = /* @__PURE__ */ new Map();
|
|
1819
1851
|
let times = {
|
|
@@ -1847,6 +1879,7 @@ function markoRun(opts = {}) {
|
|
|
1847
1879
|
let buildVirtualFilesResult;
|
|
1848
1880
|
function buildVirtualFiles() {
|
|
1849
1881
|
return buildVirtualFilesResult ?? (buildVirtualFilesResult = (async () => {
|
|
1882
|
+
var _a, _b;
|
|
1850
1883
|
virtualFiles.clear();
|
|
1851
1884
|
if (fs3.existsSync(resolvedRoutesDir)) {
|
|
1852
1885
|
routes = await buildRoutes(
|
|
@@ -1868,16 +1901,43 @@ function markoRun(opts = {}) {
|
|
|
1868
1901
|
console.warn(`Routes directory ${resolvedRoutesDir} does not exist`);
|
|
1869
1902
|
}
|
|
1870
1903
|
}
|
|
1904
|
+
entryTemplates = /* @__PURE__ */ new Set();
|
|
1905
|
+
entryTemplateImporters = /* @__PURE__ */ new Set();
|
|
1871
1906
|
for (const route of routes.list) {
|
|
1907
|
+
const routeEntryPath = route.templateFilePath || ((_a = route.page) == null ? void 0 : _a.filePath);
|
|
1908
|
+
if (routeEntryPath) {
|
|
1909
|
+
entryTemplates.add(normalizePath(routeEntryPath));
|
|
1910
|
+
}
|
|
1911
|
+
for (const middleware of route.middleware) {
|
|
1912
|
+
entryTemplateImporters.add(normalizePath(middleware.filePath));
|
|
1913
|
+
}
|
|
1914
|
+
if (route.handler) {
|
|
1915
|
+
entryTemplateImporters.add(normalizePath(route.handler.filePath));
|
|
1916
|
+
}
|
|
1872
1917
|
virtualFiles.set(
|
|
1873
1918
|
path6.posix.join(root, getRouteVirtualFileName(route)),
|
|
1874
1919
|
""
|
|
1875
1920
|
);
|
|
1876
1921
|
}
|
|
1922
|
+
for (const route of Object.values(routes.special)) {
|
|
1923
|
+
const routeEntryPath = route.templateFilePath || ((_b = route.page) == null ? void 0 : _b.filePath);
|
|
1924
|
+
if (routeEntryPath) {
|
|
1925
|
+
entryTemplates.add(normalizePath(routeEntryPath));
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1877
1928
|
if (routes.middleware.length) {
|
|
1878
1929
|
virtualFiles.set(path6.posix.join(root, MIDDLEWARE_FILENAME), "");
|
|
1879
1930
|
}
|
|
1880
1931
|
virtualFiles.set(path6.posix.join(root, ROUTER_FILENAME), "");
|
|
1932
|
+
for (const externalRoute of externalRoutes) {
|
|
1933
|
+
for (const { entryFile } of externalRoute.routes) {
|
|
1934
|
+
if (/\.marko(\?.*)?$/i.test(entryFile)) {
|
|
1935
|
+
entryTemplates.add(normalizePath(entryFile));
|
|
1936
|
+
} else {
|
|
1937
|
+
entryTemplateImporters.add(normalizePath(entryFile));
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1881
1941
|
return routes;
|
|
1882
1942
|
})());
|
|
1883
1943
|
}
|
|
@@ -1984,6 +2044,14 @@ function markoRun(opts = {}) {
|
|
|
1984
2044
|
{
|
|
1985
2045
|
name: `${PLUGIN_NAME_PREFIX}:pre`,
|
|
1986
2046
|
enforce: "pre",
|
|
2047
|
+
api: {
|
|
2048
|
+
addExternalRoutes(routes2) {
|
|
2049
|
+
externalRoutes.add(routes2);
|
|
2050
|
+
return () => {
|
|
2051
|
+
externalRoutes.delete(routes2);
|
|
2052
|
+
};
|
|
2053
|
+
}
|
|
2054
|
+
},
|
|
1987
2055
|
async config(config2, env) {
|
|
1988
2056
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
|
|
1989
2057
|
const externalPluginOptions = getExternalPluginOptions(config2);
|
|
@@ -2016,6 +2084,9 @@ function markoRun(opts = {}) {
|
|
|
2016
2084
|
);
|
|
2017
2085
|
markoVitePluginOptions.runtimeId = opts.runtimeId;
|
|
2018
2086
|
markoVitePluginOptions.basePathVar = opts.basePathVar;
|
|
2087
|
+
markoVitePluginOptions.isEntry = (importee, importer) => {
|
|
2088
|
+
return entryTemplates.has(importee) || entryTemplateImporters.has(importer);
|
|
2089
|
+
};
|
|
2019
2090
|
resolvedRoutesDir = path6.resolve(root, routesDir);
|
|
2020
2091
|
outputDir = path6.join(root, ((_d = config2.build) == null ? void 0 : _d.outDir) || "dist");
|
|
2021
2092
|
entryFilesDir = path6.join(outputDir, ".marko-run");
|
|
@@ -2204,16 +2275,14 @@ function markoRun(opts = {}) {
|
|
|
2204
2275
|
}
|
|
2205
2276
|
},
|
|
2206
2277
|
async resolveId(importee, importer) {
|
|
2278
|
+
let virtualFilePath;
|
|
2207
2279
|
if (importee === "@marko/run/router") {
|
|
2208
2280
|
return normalizePath(path6.resolve(root, ROUTER_FILENAME));
|
|
2209
2281
|
} else if (importee.endsWith(".marko") && importee.includes(relativeEntryFilesDirPosix)) {
|
|
2210
2282
|
if (!importee.startsWith(root)) {
|
|
2211
2283
|
importee = path6.resolve(root, "." + importee);
|
|
2212
2284
|
}
|
|
2213
|
-
|
|
2214
|
-
}
|
|
2215
|
-
let virtualFilePath;
|
|
2216
|
-
if (importee.startsWith(virtualFilePrefix)) {
|
|
2285
|
+
} else if (importee.startsWith(virtualFilePrefix)) {
|
|
2217
2286
|
virtualFilePath = importee.slice(virtualFilePrefix.length + 1);
|
|
2218
2287
|
importee = path6.resolve(root, virtualFilePath);
|
|
2219
2288
|
} else if (!isBuild && importer && (importer === devEntryFile || normalizePath(importer) === devEntryFilePosix) && importee.startsWith(`/${markoRunFilePrefix}`)) {
|
|
@@ -2233,9 +2302,6 @@ function markoRun(opts = {}) {
|
|
|
2233
2302
|
}
|
|
2234
2303
|
},
|
|
2235
2304
|
async load(id) {
|
|
2236
|
-
if (id.endsWith(serverEntryQuery)) {
|
|
2237
|
-
id = id.slice(0, -serverEntryQuery.length);
|
|
2238
|
-
}
|
|
2239
2305
|
if (!renderVirtualFilesResult) {
|
|
2240
2306
|
await renderVirtualFiles(this);
|
|
2241
2307
|
}
|
|
@@ -2285,7 +2351,7 @@ function markoRun(opts = {}) {
|
|
|
2285
2351
|
store.write(routeData);
|
|
2286
2352
|
await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes.list));
|
|
2287
2353
|
} else if (process.env.MR_EXPLORER !== "true") {
|
|
2288
|
-
logRoutesTable(routes, bundle);
|
|
2354
|
+
logRoutesTable(routes, [...externalRoutes], bundle);
|
|
2289
2355
|
}
|
|
2290
2356
|
},
|
|
2291
2357
|
async closeBundle() {
|
|
@@ -2363,6 +2429,18 @@ function getEntryFileName(file) {
|
|
|
2363
2429
|
const match = file && markoEntryFileRegex.exec(file);
|
|
2364
2430
|
return match ? match[2] || "index" : void 0;
|
|
2365
2431
|
}
|
|
2432
|
+
function getPlugin(config2) {
|
|
2433
|
+
return config2.plugins.find(
|
|
2434
|
+
(plugin) => plugin.name === `${PLUGIN_NAME_PREFIX}:pre`
|
|
2435
|
+
);
|
|
2436
|
+
}
|
|
2437
|
+
function getApi(config2) {
|
|
2438
|
+
const plugin = getPlugin(config2);
|
|
2439
|
+
if (!plugin) {
|
|
2440
|
+
throw new Error("Marko Run vite plugin not found");
|
|
2441
|
+
}
|
|
2442
|
+
return plugin.api;
|
|
2443
|
+
}
|
|
2366
2444
|
function getImporters(module, fileName, seen = /* @__PURE__ */ new Set()) {
|
|
2367
2445
|
for (const importer of module.importers) {
|
|
2368
2446
|
if (importer.id && !seen.has(importer.id)) {
|
|
@@ -2524,6 +2602,7 @@ function sleep(ms) {
|
|
|
2524
2602
|
export {
|
|
2525
2603
|
markoRun as default,
|
|
2526
2604
|
defaultConfigPlugin,
|
|
2605
|
+
getApi,
|
|
2527
2606
|
getAvailablePort,
|
|
2528
2607
|
getPackageData,
|
|
2529
2608
|
isPortInUse,
|
package/dist/vite/plugin.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Plugin, type ResolvedConfig } from "vite";
|
|
2
|
-
import type { Adapter, Options, PackageData } from "./types";
|
|
2
|
+
import type { Adapter, ExternalRoutes, Options, PackageData } from "./types";
|
|
3
3
|
export declare const defaultPort: number;
|
|
4
4
|
declare module "vite" {
|
|
5
5
|
interface TransformResult {
|
|
@@ -10,4 +10,7 @@ export default function markoRun(opts?: Options): Plugin[];
|
|
|
10
10
|
export declare function getPackageData(dir: string): Promise<PackageData | null>;
|
|
11
11
|
export declare function resolveAdapter(root: string, options?: Options, log?: boolean): Promise<Adapter | null>;
|
|
12
12
|
export declare function isPluginIncluded(config: ResolvedConfig): boolean;
|
|
13
|
+
export declare function getApi(config: ResolvedConfig): {
|
|
14
|
+
addExternalRoutes(routes: ExternalRoutes): () => void;
|
|
15
|
+
};
|
|
13
16
|
export declare const defaultConfigPlugin: Plugin;
|
package/dist/vite/types.d.ts
CHANGED
|
@@ -112,3 +112,11 @@ export interface ExplorerData {
|
|
|
112
112
|
routes: Record<string, Route>;
|
|
113
113
|
files: Record<string, string>;
|
|
114
114
|
}
|
|
115
|
+
export interface ExternalRoutes {
|
|
116
|
+
name: string;
|
|
117
|
+
routes: {
|
|
118
|
+
path: string;
|
|
119
|
+
entryFile: string;
|
|
120
|
+
verbs: HttpVerb[];
|
|
121
|
+
}[];
|
|
122
|
+
}
|
package/dist/vite/utils/log.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { OutputBundle } from "rollup";
|
|
2
|
-
import type { BuiltRoutes } from "../types";
|
|
3
|
-
export declare function logRoutesTable(routes: BuiltRoutes, bundle: OutputBundle): void;
|
|
2
|
+
import type { BuiltRoutes, ExternalRoutes } from "../types";
|
|
3
|
+
export declare function logRoutesTable(routes: BuiltRoutes, externalRoutes: ExternalRoutes[], bundle: OutputBundle): void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { HttpVerb, Route } from "../types";
|
|
2
2
|
export declare function getVerbs(route: Route, noAutoHead?: boolean): HttpVerb[];
|
|
3
|
+
export declare function getUniqueSortedVerbs(verbs: HttpVerb[]): HttpVerb[];
|
|
3
4
|
export declare function hasVerb(route: Route, verb: HttpVerb): boolean;
|
|
4
5
|
export declare function getRouteVirtualFileName(route: Route): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marko/run",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "The Marko application framework.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"marko"
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@marko/run-explorer": "^2.0.1",
|
|
58
|
-
"@marko/vite": "^5.
|
|
58
|
+
"@marko/vite": "^5.3.2",
|
|
59
59
|
"browserslist": "^4.24.4",
|
|
60
60
|
"cli-table3": "^0.6.5",
|
|
61
61
|
"compression": "^1.8.0",
|