@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/cli/index.mjs
CHANGED
|
@@ -79,7 +79,6 @@ var httpVerbs = [
|
|
|
79
79
|
"patch",
|
|
80
80
|
"options"
|
|
81
81
|
];
|
|
82
|
-
var serverEntryQuery = "?marko-server-entry";
|
|
83
82
|
var RoutableFileTypes = {
|
|
84
83
|
Page: "page",
|
|
85
84
|
Layout: "layout",
|
|
@@ -115,6 +114,11 @@ function getVerbs(route, noAutoHead) {
|
|
|
115
114
|
}
|
|
116
115
|
return [...verbs].sort((a, b) => httpVerbOrder[a] - httpVerbOrder[b]);
|
|
117
116
|
}
|
|
117
|
+
function getUniqueSortedVerbs(verbs) {
|
|
118
|
+
return [...new Set(verbs)].sort(
|
|
119
|
+
(a, b) => httpVerbOrder[a] - httpVerbOrder[b]
|
|
120
|
+
);
|
|
121
|
+
}
|
|
118
122
|
function hasVerb(route, verb) {
|
|
119
123
|
var _a, _b;
|
|
120
124
|
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");
|
|
@@ -366,7 +370,7 @@ function renderRouteEntry(route, rootDir) {
|
|
|
366
370
|
}
|
|
367
371
|
if (page) {
|
|
368
372
|
imports.writeLines(
|
|
369
|
-
`import page from "${normalizedRelativePath(rootDir, route.templateFilePath || page.filePath)}
|
|
373
|
+
`import page from "${normalizedRelativePath(rootDir, route.templateFilePath || page.filePath)}";`
|
|
370
374
|
);
|
|
371
375
|
}
|
|
372
376
|
if (meta) {
|
|
@@ -499,7 +503,7 @@ function renderRouter(routes, rootDir, runtimeInclude, options = {
|
|
|
499
503
|
}
|
|
500
504
|
for (const route of Object.values(routes.special)) {
|
|
501
505
|
imports.writeLines(
|
|
502
|
-
`import page${route.key} from "${normalizedRelativePath(rootDir, route.templateFilePath || route.page.filePath)}
|
|
506
|
+
`import page${route.key} from "${normalizedRelativePath(rootDir, route.templateFilePath || route.page.filePath)}";`
|
|
503
507
|
);
|
|
504
508
|
}
|
|
505
509
|
writer.writeLines(
|
|
@@ -1631,7 +1635,7 @@ var HttpVerbColors = {
|
|
|
1631
1635
|
function verbColor(verb) {
|
|
1632
1636
|
return verb in HttpVerbColors ? HttpVerbColors[verb] : kleur2.gray;
|
|
1633
1637
|
}
|
|
1634
|
-
function logRoutesTable(routes, bundle) {
|
|
1638
|
+
function logRoutesTable(routes, externalRoutes, bundle) {
|
|
1635
1639
|
const hasMiddleware = routes.list.some((route) => route.middleware.length);
|
|
1636
1640
|
const hasMeta = routes.list.some((route) => route.meta);
|
|
1637
1641
|
const headings = ["Method", "Path", "Entry"];
|
|
@@ -1665,7 +1669,7 @@ function logRoutesTable(routes, bundle) {
|
|
|
1665
1669
|
if (route.page && (verb === "get" || verb === "head")) {
|
|
1666
1670
|
entryType.push(kleur2.yellow("page"));
|
|
1667
1671
|
if (verb === "get") {
|
|
1668
|
-
size = prettySize(computeRouteSize(route, bundle));
|
|
1672
|
+
size = prettySize(computeRouteSize(route.templateFilePath, bundle));
|
|
1669
1673
|
}
|
|
1670
1674
|
}
|
|
1671
1675
|
const row = [verbCell];
|
|
@@ -1687,9 +1691,35 @@ function logRoutesTable(routes, bundle) {
|
|
|
1687
1691
|
const row = [kleur2.bold(kleur2.white("*")), key, kleur2.yellow("page")];
|
|
1688
1692
|
hasMiddleware && row.push("");
|
|
1689
1693
|
hasMeta && row.push("");
|
|
1690
|
-
row.push(prettySize(computeRouteSize(route, bundle)));
|
|
1694
|
+
row.push(prettySize(computeRouteSize(route.templateFilePath, bundle)));
|
|
1691
1695
|
table.push(row);
|
|
1692
1696
|
}
|
|
1697
|
+
for (const external of externalRoutes) {
|
|
1698
|
+
for (const route of external.routes) {
|
|
1699
|
+
const verbs = getUniqueSortedVerbs(route.verbs);
|
|
1700
|
+
let firstRow = true;
|
|
1701
|
+
for (const verb of verbs) {
|
|
1702
|
+
let size = "";
|
|
1703
|
+
const verbCell = verbColor(verb)(verb.toUpperCase());
|
|
1704
|
+
if (verb === "get") {
|
|
1705
|
+
size = prettySize(computeRouteSize(route.entryFile, bundle));
|
|
1706
|
+
}
|
|
1707
|
+
const row = [verbCell];
|
|
1708
|
+
if (verbs.length === 1 || firstRow) {
|
|
1709
|
+
row.push({
|
|
1710
|
+
rowSpan: verbs.length,
|
|
1711
|
+
content: prettyPath(route.path)
|
|
1712
|
+
});
|
|
1713
|
+
firstRow = false;
|
|
1714
|
+
}
|
|
1715
|
+
row.push(kleur2.magenta(external.name));
|
|
1716
|
+
hasMiddleware && row.push("");
|
|
1717
|
+
hasMeta && row.push("");
|
|
1718
|
+
row.push(size || "");
|
|
1719
|
+
table.push(row);
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1693
1723
|
if (!table.length) {
|
|
1694
1724
|
table.push([
|
|
1695
1725
|
{
|
|
@@ -1701,11 +1731,10 @@ function logRoutesTable(routes, bundle) {
|
|
|
1701
1731
|
}
|
|
1702
1732
|
console.log(table.toString());
|
|
1703
1733
|
}
|
|
1704
|
-
function computeRouteSize(
|
|
1705
|
-
|
|
1706
|
-
if (facadeModuleId) {
|
|
1734
|
+
function computeRouteSize(filePath, bundle) {
|
|
1735
|
+
if (filePath) {
|
|
1707
1736
|
for (const chunk of Object.values(bundle)) {
|
|
1708
|
-
if (chunk.type === "chunk" && chunk.isEntry && chunk.facadeModuleId ===
|
|
1737
|
+
if (chunk.type === "chunk" && chunk.isEntry && chunk.facadeModuleId === `${filePath}.html`) {
|
|
1709
1738
|
return computeChunkSize(chunk, bundle);
|
|
1710
1739
|
}
|
|
1711
1740
|
}
|
|
@@ -1828,9 +1857,12 @@ function markoRun(opts = {}) {
|
|
|
1828
1857
|
let devEntryFilePosix;
|
|
1829
1858
|
let devServer;
|
|
1830
1859
|
let routes;
|
|
1860
|
+
let entryTemplates;
|
|
1861
|
+
let entryTemplateImporters;
|
|
1831
1862
|
let routeData;
|
|
1832
1863
|
let resolvedConfig;
|
|
1833
1864
|
let typesFile;
|
|
1865
|
+
const externalRoutes = /* @__PURE__ */ new Set();
|
|
1834
1866
|
const seenErrors = /* @__PURE__ */ new Set();
|
|
1835
1867
|
const virtualFiles = /* @__PURE__ */ new Map();
|
|
1836
1868
|
let times = {
|
|
@@ -1864,6 +1896,7 @@ function markoRun(opts = {}) {
|
|
|
1864
1896
|
let buildVirtualFilesResult;
|
|
1865
1897
|
function buildVirtualFiles() {
|
|
1866
1898
|
return buildVirtualFilesResult ?? (buildVirtualFilesResult = (async () => {
|
|
1899
|
+
var _a, _b;
|
|
1867
1900
|
virtualFiles.clear();
|
|
1868
1901
|
if (fs3.existsSync(resolvedRoutesDir)) {
|
|
1869
1902
|
routes = await buildRoutes(
|
|
@@ -1885,16 +1918,43 @@ function markoRun(opts = {}) {
|
|
|
1885
1918
|
console.warn(`Routes directory ${resolvedRoutesDir} does not exist`);
|
|
1886
1919
|
}
|
|
1887
1920
|
}
|
|
1921
|
+
entryTemplates = /* @__PURE__ */ new Set();
|
|
1922
|
+
entryTemplateImporters = /* @__PURE__ */ new Set();
|
|
1888
1923
|
for (const route of routes.list) {
|
|
1924
|
+
const routeEntryPath = route.templateFilePath || ((_a = route.page) == null ? void 0 : _a.filePath);
|
|
1925
|
+
if (routeEntryPath) {
|
|
1926
|
+
entryTemplates.add(normalizePath(routeEntryPath));
|
|
1927
|
+
}
|
|
1928
|
+
for (const middleware of route.middleware) {
|
|
1929
|
+
entryTemplateImporters.add(normalizePath(middleware.filePath));
|
|
1930
|
+
}
|
|
1931
|
+
if (route.handler) {
|
|
1932
|
+
entryTemplateImporters.add(normalizePath(route.handler.filePath));
|
|
1933
|
+
}
|
|
1889
1934
|
virtualFiles.set(
|
|
1890
1935
|
path6.posix.join(root, getRouteVirtualFileName(route)),
|
|
1891
1936
|
""
|
|
1892
1937
|
);
|
|
1893
1938
|
}
|
|
1939
|
+
for (const route of Object.values(routes.special)) {
|
|
1940
|
+
const routeEntryPath = route.templateFilePath || ((_b = route.page) == null ? void 0 : _b.filePath);
|
|
1941
|
+
if (routeEntryPath) {
|
|
1942
|
+
entryTemplates.add(normalizePath(routeEntryPath));
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1894
1945
|
if (routes.middleware.length) {
|
|
1895
1946
|
virtualFiles.set(path6.posix.join(root, MIDDLEWARE_FILENAME), "");
|
|
1896
1947
|
}
|
|
1897
1948
|
virtualFiles.set(path6.posix.join(root, ROUTER_FILENAME), "");
|
|
1949
|
+
for (const externalRoute of externalRoutes) {
|
|
1950
|
+
for (const { entryFile } of externalRoute.routes) {
|
|
1951
|
+
if (/\.marko(\?.*)?$/i.test(entryFile)) {
|
|
1952
|
+
entryTemplates.add(normalizePath(entryFile));
|
|
1953
|
+
} else {
|
|
1954
|
+
entryTemplateImporters.add(normalizePath(entryFile));
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1898
1958
|
return routes;
|
|
1899
1959
|
})());
|
|
1900
1960
|
}
|
|
@@ -2001,6 +2061,14 @@ function markoRun(opts = {}) {
|
|
|
2001
2061
|
{
|
|
2002
2062
|
name: `${PLUGIN_NAME_PREFIX}:pre`,
|
|
2003
2063
|
enforce: "pre",
|
|
2064
|
+
api: {
|
|
2065
|
+
addExternalRoutes(routes2) {
|
|
2066
|
+
externalRoutes.add(routes2);
|
|
2067
|
+
return () => {
|
|
2068
|
+
externalRoutes.delete(routes2);
|
|
2069
|
+
};
|
|
2070
|
+
}
|
|
2071
|
+
},
|
|
2004
2072
|
async config(config2, env) {
|
|
2005
2073
|
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;
|
|
2006
2074
|
const externalPluginOptions = getExternalPluginOptions(config2);
|
|
@@ -2033,6 +2101,9 @@ function markoRun(opts = {}) {
|
|
|
2033
2101
|
);
|
|
2034
2102
|
markoVitePluginOptions.runtimeId = opts.runtimeId;
|
|
2035
2103
|
markoVitePluginOptions.basePathVar = opts.basePathVar;
|
|
2104
|
+
markoVitePluginOptions.isEntry = (importee, importer) => {
|
|
2105
|
+
return entryTemplates.has(importee) || entryTemplateImporters.has(importer);
|
|
2106
|
+
};
|
|
2036
2107
|
resolvedRoutesDir = path6.resolve(root, routesDir);
|
|
2037
2108
|
outputDir = path6.join(root, ((_d = config2.build) == null ? void 0 : _d.outDir) || "dist");
|
|
2038
2109
|
entryFilesDir = path6.join(outputDir, ".marko-run");
|
|
@@ -2221,16 +2292,14 @@ function markoRun(opts = {}) {
|
|
|
2221
2292
|
}
|
|
2222
2293
|
},
|
|
2223
2294
|
async resolveId(importee, importer) {
|
|
2295
|
+
let virtualFilePath;
|
|
2224
2296
|
if (importee === "@marko/run/router") {
|
|
2225
2297
|
return normalizePath(path6.resolve(root, ROUTER_FILENAME));
|
|
2226
2298
|
} else if (importee.endsWith(".marko") && importee.includes(relativeEntryFilesDirPosix)) {
|
|
2227
2299
|
if (!importee.startsWith(root)) {
|
|
2228
2300
|
importee = path6.resolve(root, "." + importee);
|
|
2229
2301
|
}
|
|
2230
|
-
|
|
2231
|
-
}
|
|
2232
|
-
let virtualFilePath;
|
|
2233
|
-
if (importee.startsWith(virtualFilePrefix)) {
|
|
2302
|
+
} else if (importee.startsWith(virtualFilePrefix)) {
|
|
2234
2303
|
virtualFilePath = importee.slice(virtualFilePrefix.length + 1);
|
|
2235
2304
|
importee = path6.resolve(root, virtualFilePath);
|
|
2236
2305
|
} else if (!isBuild && importer && (importer === devEntryFile || normalizePath(importer) === devEntryFilePosix) && importee.startsWith(`/${markoRunFilePrefix}`)) {
|
|
@@ -2250,9 +2319,6 @@ function markoRun(opts = {}) {
|
|
|
2250
2319
|
}
|
|
2251
2320
|
},
|
|
2252
2321
|
async load(id) {
|
|
2253
|
-
if (id.endsWith(serverEntryQuery)) {
|
|
2254
|
-
id = id.slice(0, -serverEntryQuery.length);
|
|
2255
|
-
}
|
|
2256
2322
|
if (!renderVirtualFilesResult) {
|
|
2257
2323
|
await renderVirtualFiles(this);
|
|
2258
2324
|
}
|
|
@@ -2302,7 +2368,7 @@ function markoRun(opts = {}) {
|
|
|
2302
2368
|
store.write(routeData);
|
|
2303
2369
|
await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes.list));
|
|
2304
2370
|
} else if (process.env.MR_EXPLORER !== "true") {
|
|
2305
|
-
logRoutesTable(routes, bundle);
|
|
2371
|
+
logRoutesTable(routes, [...externalRoutes], bundle);
|
|
2306
2372
|
}
|
|
2307
2373
|
},
|
|
2308
2374
|
async closeBundle() {
|
|
@@ -2380,10 +2446,13 @@ function getEntryFileName(file) {
|
|
|
2380
2446
|
const match = file && markoEntryFileRegex.exec(file);
|
|
2381
2447
|
return match ? match[2] || "index" : void 0;
|
|
2382
2448
|
}
|
|
2449
|
+
function getPlugin(config2) {
|
|
2450
|
+
return config2.plugins.find(
|
|
2451
|
+
(plugin) => plugin.name === `${PLUGIN_NAME_PREFIX}:pre`
|
|
2452
|
+
);
|
|
2453
|
+
}
|
|
2383
2454
|
function isPluginIncluded(config2) {
|
|
2384
|
-
return config2
|
|
2385
|
-
return plugin.name === `${PLUGIN_NAME_PREFIX}:pre`;
|
|
2386
|
-
});
|
|
2455
|
+
return !!getPlugin(config2);
|
|
2387
2456
|
}
|
|
2388
2457
|
function getImporters(module, fileName, seen = /* @__PURE__ */ new Set()) {
|
|
2389
2458
|
for (const importer of module.importers) {
|
package/dist/vite/constants.d.ts
CHANGED
|
@@ -2,8 +2,6 @@ type ValuesOf<T> = T[keyof T];
|
|
|
2
2
|
export declare const markoRunFilePrefix = "__marko-run__";
|
|
3
3
|
export declare const virtualFilePrefix = "virtual:marko-run";
|
|
4
4
|
export declare const httpVerbs: readonly ["get", "head", "post", "put", "delete", "patch", "options"];
|
|
5
|
-
export declare const serverEntryQuery = "?marko-server-entry";
|
|
6
|
-
export declare const browserEntryQuery = "?marko-browser-entry";
|
|
7
5
|
export declare const RoutableFileTypes: {
|
|
8
6
|
readonly Page: "page";
|
|
9
7
|
readonly Layout: "layout";
|
package/dist/vite/index.cjs
CHANGED
|
@@ -41,6 +41,7 @@ var vite_exports = {};
|
|
|
41
41
|
__export(vite_exports, {
|
|
42
42
|
default: () => markoRun,
|
|
43
43
|
defaultConfigPlugin: () => defaultConfigPlugin,
|
|
44
|
+
getApi: () => getApi,
|
|
44
45
|
getAvailablePort: () => getAvailablePort,
|
|
45
46
|
getPackageData: () => getPackageData,
|
|
46
47
|
isPortInUse: () => isPortInUse,
|
|
@@ -106,7 +107,6 @@ var httpVerbs = [
|
|
|
106
107
|
"patch",
|
|
107
108
|
"options"
|
|
108
109
|
];
|
|
109
|
-
var serverEntryQuery = "?marko-server-entry";
|
|
110
110
|
var RoutableFileTypes = {
|
|
111
111
|
Page: "page",
|
|
112
112
|
Layout: "layout",
|
|
@@ -142,6 +142,11 @@ function getVerbs(route, noAutoHead) {
|
|
|
142
142
|
}
|
|
143
143
|
return [...verbs].sort((a, b) => httpVerbOrder[a] - httpVerbOrder[b]);
|
|
144
144
|
}
|
|
145
|
+
function getUniqueSortedVerbs(verbs) {
|
|
146
|
+
return [...new Set(verbs)].sort(
|
|
147
|
+
(a, b) => httpVerbOrder[a] - httpVerbOrder[b]
|
|
148
|
+
);
|
|
149
|
+
}
|
|
145
150
|
function hasVerb(route, verb) {
|
|
146
151
|
var _a, _b;
|
|
147
152
|
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");
|
|
@@ -393,7 +398,7 @@ function renderRouteEntry(route, rootDir) {
|
|
|
393
398
|
}
|
|
394
399
|
if (page) {
|
|
395
400
|
imports.writeLines(
|
|
396
|
-
`import page from "${normalizedRelativePath(rootDir, route.templateFilePath || page.filePath)}
|
|
401
|
+
`import page from "${normalizedRelativePath(rootDir, route.templateFilePath || page.filePath)}";`
|
|
397
402
|
);
|
|
398
403
|
}
|
|
399
404
|
if (meta) {
|
|
@@ -526,7 +531,7 @@ function renderRouter(routes, rootDir, runtimeInclude, options = {
|
|
|
526
531
|
}
|
|
527
532
|
for (const route of Object.values(routes.special)) {
|
|
528
533
|
imports.writeLines(
|
|
529
|
-
`import page${route.key} from "${normalizedRelativePath(rootDir, route.templateFilePath || route.page.filePath)}
|
|
534
|
+
`import page${route.key} from "${normalizedRelativePath(rootDir, route.templateFilePath || route.page.filePath)}";`
|
|
530
535
|
);
|
|
531
536
|
}
|
|
532
537
|
writer.writeLines(
|
|
@@ -1657,7 +1662,7 @@ var HttpVerbColors = {
|
|
|
1657
1662
|
function verbColor(verb) {
|
|
1658
1663
|
return verb in HttpVerbColors ? HttpVerbColors[verb] : import_kleur2.default.gray;
|
|
1659
1664
|
}
|
|
1660
|
-
function logRoutesTable(routes, bundle) {
|
|
1665
|
+
function logRoutesTable(routes, externalRoutes, bundle) {
|
|
1661
1666
|
const hasMiddleware = routes.list.some((route) => route.middleware.length);
|
|
1662
1667
|
const hasMeta = routes.list.some((route) => route.meta);
|
|
1663
1668
|
const headings = ["Method", "Path", "Entry"];
|
|
@@ -1691,7 +1696,7 @@ function logRoutesTable(routes, bundle) {
|
|
|
1691
1696
|
if (route.page && (verb === "get" || verb === "head")) {
|
|
1692
1697
|
entryType.push(import_kleur2.default.yellow("page"));
|
|
1693
1698
|
if (verb === "get") {
|
|
1694
|
-
size = prettySize(computeRouteSize(route, bundle));
|
|
1699
|
+
size = prettySize(computeRouteSize(route.templateFilePath, bundle));
|
|
1695
1700
|
}
|
|
1696
1701
|
}
|
|
1697
1702
|
const row = [verbCell];
|
|
@@ -1713,9 +1718,35 @@ function logRoutesTable(routes, bundle) {
|
|
|
1713
1718
|
const row = [import_kleur2.default.bold(import_kleur2.default.white("*")), key, import_kleur2.default.yellow("page")];
|
|
1714
1719
|
hasMiddleware && row.push("");
|
|
1715
1720
|
hasMeta && row.push("");
|
|
1716
|
-
row.push(prettySize(computeRouteSize(route, bundle)));
|
|
1721
|
+
row.push(prettySize(computeRouteSize(route.templateFilePath, bundle)));
|
|
1717
1722
|
table.push(row);
|
|
1718
1723
|
}
|
|
1724
|
+
for (const external of externalRoutes) {
|
|
1725
|
+
for (const route of external.routes) {
|
|
1726
|
+
const verbs = getUniqueSortedVerbs(route.verbs);
|
|
1727
|
+
let firstRow = true;
|
|
1728
|
+
for (const verb of verbs) {
|
|
1729
|
+
let size = "";
|
|
1730
|
+
const verbCell = verbColor(verb)(verb.toUpperCase());
|
|
1731
|
+
if (verb === "get") {
|
|
1732
|
+
size = prettySize(computeRouteSize(route.entryFile, bundle));
|
|
1733
|
+
}
|
|
1734
|
+
const row = [verbCell];
|
|
1735
|
+
if (verbs.length === 1 || firstRow) {
|
|
1736
|
+
row.push({
|
|
1737
|
+
rowSpan: verbs.length,
|
|
1738
|
+
content: prettyPath(route.path)
|
|
1739
|
+
});
|
|
1740
|
+
firstRow = false;
|
|
1741
|
+
}
|
|
1742
|
+
row.push(import_kleur2.default.magenta(external.name));
|
|
1743
|
+
hasMiddleware && row.push("");
|
|
1744
|
+
hasMeta && row.push("");
|
|
1745
|
+
row.push(size || "");
|
|
1746
|
+
table.push(row);
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1719
1750
|
if (!table.length) {
|
|
1720
1751
|
table.push([
|
|
1721
1752
|
{
|
|
@@ -1727,11 +1758,10 @@ function logRoutesTable(routes, bundle) {
|
|
|
1727
1758
|
}
|
|
1728
1759
|
console.log(table.toString());
|
|
1729
1760
|
}
|
|
1730
|
-
function computeRouteSize(
|
|
1731
|
-
|
|
1732
|
-
if (facadeModuleId) {
|
|
1761
|
+
function computeRouteSize(filePath, bundle) {
|
|
1762
|
+
if (filePath) {
|
|
1733
1763
|
for (const chunk of Object.values(bundle)) {
|
|
1734
|
-
if (chunk.type === "chunk" && chunk.isEntry && chunk.facadeModuleId ===
|
|
1764
|
+
if (chunk.type === "chunk" && chunk.isEntry && chunk.facadeModuleId === `${filePath}.html`) {
|
|
1735
1765
|
return computeChunkSize(chunk, bundle);
|
|
1736
1766
|
}
|
|
1737
1767
|
}
|
|
@@ -1854,9 +1884,12 @@ function markoRun(opts = {}) {
|
|
|
1854
1884
|
let devEntryFilePosix;
|
|
1855
1885
|
let devServer;
|
|
1856
1886
|
let routes;
|
|
1887
|
+
let entryTemplates;
|
|
1888
|
+
let entryTemplateImporters;
|
|
1857
1889
|
let routeData;
|
|
1858
1890
|
let resolvedConfig;
|
|
1859
1891
|
let typesFile;
|
|
1892
|
+
const externalRoutes = /* @__PURE__ */ new Set();
|
|
1860
1893
|
const seenErrors = /* @__PURE__ */ new Set();
|
|
1861
1894
|
const virtualFiles = /* @__PURE__ */ new Map();
|
|
1862
1895
|
let times = {
|
|
@@ -1890,6 +1923,7 @@ function markoRun(opts = {}) {
|
|
|
1890
1923
|
let buildVirtualFilesResult;
|
|
1891
1924
|
function buildVirtualFiles() {
|
|
1892
1925
|
return buildVirtualFilesResult ?? (buildVirtualFilesResult = (async () => {
|
|
1926
|
+
var _a, _b;
|
|
1893
1927
|
virtualFiles.clear();
|
|
1894
1928
|
if (import_fs4.default.existsSync(resolvedRoutesDir)) {
|
|
1895
1929
|
routes = await buildRoutes(
|
|
@@ -1911,16 +1945,43 @@ function markoRun(opts = {}) {
|
|
|
1911
1945
|
console.warn(`Routes directory ${resolvedRoutesDir} does not exist`);
|
|
1912
1946
|
}
|
|
1913
1947
|
}
|
|
1948
|
+
entryTemplates = /* @__PURE__ */ new Set();
|
|
1949
|
+
entryTemplateImporters = /* @__PURE__ */ new Set();
|
|
1914
1950
|
for (const route of routes.list) {
|
|
1951
|
+
const routeEntryPath = route.templateFilePath || ((_a = route.page) == null ? void 0 : _a.filePath);
|
|
1952
|
+
if (routeEntryPath) {
|
|
1953
|
+
entryTemplates.add(normalizePath(routeEntryPath));
|
|
1954
|
+
}
|
|
1955
|
+
for (const middleware of route.middleware) {
|
|
1956
|
+
entryTemplateImporters.add(normalizePath(middleware.filePath));
|
|
1957
|
+
}
|
|
1958
|
+
if (route.handler) {
|
|
1959
|
+
entryTemplateImporters.add(normalizePath(route.handler.filePath));
|
|
1960
|
+
}
|
|
1915
1961
|
virtualFiles.set(
|
|
1916
1962
|
import_path6.default.posix.join(root, getRouteVirtualFileName(route)),
|
|
1917
1963
|
""
|
|
1918
1964
|
);
|
|
1919
1965
|
}
|
|
1966
|
+
for (const route of Object.values(routes.special)) {
|
|
1967
|
+
const routeEntryPath = route.templateFilePath || ((_b = route.page) == null ? void 0 : _b.filePath);
|
|
1968
|
+
if (routeEntryPath) {
|
|
1969
|
+
entryTemplates.add(normalizePath(routeEntryPath));
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1920
1972
|
if (routes.middleware.length) {
|
|
1921
1973
|
virtualFiles.set(import_path6.default.posix.join(root, MIDDLEWARE_FILENAME), "");
|
|
1922
1974
|
}
|
|
1923
1975
|
virtualFiles.set(import_path6.default.posix.join(root, ROUTER_FILENAME), "");
|
|
1976
|
+
for (const externalRoute of externalRoutes) {
|
|
1977
|
+
for (const { entryFile } of externalRoute.routes) {
|
|
1978
|
+
if (/\.marko(\?.*)?$/i.test(entryFile)) {
|
|
1979
|
+
entryTemplates.add(normalizePath(entryFile));
|
|
1980
|
+
} else {
|
|
1981
|
+
entryTemplateImporters.add(normalizePath(entryFile));
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1924
1985
|
return routes;
|
|
1925
1986
|
})());
|
|
1926
1987
|
}
|
|
@@ -2027,6 +2088,14 @@ function markoRun(opts = {}) {
|
|
|
2027
2088
|
{
|
|
2028
2089
|
name: `${PLUGIN_NAME_PREFIX}:pre`,
|
|
2029
2090
|
enforce: "pre",
|
|
2091
|
+
api: {
|
|
2092
|
+
addExternalRoutes(routes2) {
|
|
2093
|
+
externalRoutes.add(routes2);
|
|
2094
|
+
return () => {
|
|
2095
|
+
externalRoutes.delete(routes2);
|
|
2096
|
+
};
|
|
2097
|
+
}
|
|
2098
|
+
},
|
|
2030
2099
|
async config(config2, env) {
|
|
2031
2100
|
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;
|
|
2032
2101
|
const externalPluginOptions = getExternalPluginOptions(config2);
|
|
@@ -2059,6 +2128,9 @@ function markoRun(opts = {}) {
|
|
|
2059
2128
|
);
|
|
2060
2129
|
markoVitePluginOptions.runtimeId = opts.runtimeId;
|
|
2061
2130
|
markoVitePluginOptions.basePathVar = opts.basePathVar;
|
|
2131
|
+
markoVitePluginOptions.isEntry = (importee, importer) => {
|
|
2132
|
+
return entryTemplates.has(importee) || entryTemplateImporters.has(importer);
|
|
2133
|
+
};
|
|
2062
2134
|
resolvedRoutesDir = import_path6.default.resolve(root, routesDir);
|
|
2063
2135
|
outputDir = import_path6.default.join(root, ((_d = config2.build) == null ? void 0 : _d.outDir) || "dist");
|
|
2064
2136
|
entryFilesDir = import_path6.default.join(outputDir, ".marko-run");
|
|
@@ -2247,16 +2319,14 @@ function markoRun(opts = {}) {
|
|
|
2247
2319
|
}
|
|
2248
2320
|
},
|
|
2249
2321
|
async resolveId(importee, importer) {
|
|
2322
|
+
let virtualFilePath;
|
|
2250
2323
|
if (importee === "@marko/run/router") {
|
|
2251
2324
|
return normalizePath(import_path6.default.resolve(root, ROUTER_FILENAME));
|
|
2252
2325
|
} else if (importee.endsWith(".marko") && importee.includes(relativeEntryFilesDirPosix)) {
|
|
2253
2326
|
if (!importee.startsWith(root)) {
|
|
2254
2327
|
importee = import_path6.default.resolve(root, "." + importee);
|
|
2255
2328
|
}
|
|
2256
|
-
|
|
2257
|
-
}
|
|
2258
|
-
let virtualFilePath;
|
|
2259
|
-
if (importee.startsWith(virtualFilePrefix)) {
|
|
2329
|
+
} else if (importee.startsWith(virtualFilePrefix)) {
|
|
2260
2330
|
virtualFilePath = importee.slice(virtualFilePrefix.length + 1);
|
|
2261
2331
|
importee = import_path6.default.resolve(root, virtualFilePath);
|
|
2262
2332
|
} else if (!isBuild && importer && (importer === devEntryFile || normalizePath(importer) === devEntryFilePosix) && importee.startsWith(`/${markoRunFilePrefix}`)) {
|
|
@@ -2276,9 +2346,6 @@ function markoRun(opts = {}) {
|
|
|
2276
2346
|
}
|
|
2277
2347
|
},
|
|
2278
2348
|
async load(id) {
|
|
2279
|
-
if (id.endsWith(serverEntryQuery)) {
|
|
2280
|
-
id = id.slice(0, -serverEntryQuery.length);
|
|
2281
|
-
}
|
|
2282
2349
|
if (!renderVirtualFilesResult) {
|
|
2283
2350
|
await renderVirtualFiles(this);
|
|
2284
2351
|
}
|
|
@@ -2328,7 +2395,7 @@ function markoRun(opts = {}) {
|
|
|
2328
2395
|
store.write(routeData);
|
|
2329
2396
|
await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes.list));
|
|
2330
2397
|
} else if (process.env.MR_EXPLORER !== "true") {
|
|
2331
|
-
logRoutesTable(routes, bundle);
|
|
2398
|
+
logRoutesTable(routes, [...externalRoutes], bundle);
|
|
2332
2399
|
}
|
|
2333
2400
|
},
|
|
2334
2401
|
async closeBundle() {
|
|
@@ -2406,6 +2473,18 @@ function getEntryFileName(file) {
|
|
|
2406
2473
|
const match = file && markoEntryFileRegex.exec(file);
|
|
2407
2474
|
return match ? match[2] || "index" : void 0;
|
|
2408
2475
|
}
|
|
2476
|
+
function getPlugin(config2) {
|
|
2477
|
+
return config2.plugins.find(
|
|
2478
|
+
(plugin) => plugin.name === `${PLUGIN_NAME_PREFIX}:pre`
|
|
2479
|
+
);
|
|
2480
|
+
}
|
|
2481
|
+
function getApi(config2) {
|
|
2482
|
+
const plugin = getPlugin(config2);
|
|
2483
|
+
if (!plugin) {
|
|
2484
|
+
throw new Error("Marko Run vite plugin not found");
|
|
2485
|
+
}
|
|
2486
|
+
return plugin.api;
|
|
2487
|
+
}
|
|
2409
2488
|
function getImporters(module2, fileName, seen = /* @__PURE__ */ new Set()) {
|
|
2410
2489
|
for (const importer of module2.importers) {
|
|
2411
2490
|
if (importer.id && !seen.has(importer.id)) {
|
|
@@ -2567,6 +2646,7 @@ function sleep(ms) {
|
|
|
2567
2646
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2568
2647
|
0 && (module.exports = {
|
|
2569
2648
|
defaultConfigPlugin,
|
|
2649
|
+
getApi,
|
|
2570
2650
|
getAvailablePort,
|
|
2571
2651
|
getPackageData,
|
|
2572
2652
|
isPortInUse,
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { default, defaultConfigPlugin, getPackageData } from "./plugin";
|
|
2
|
-
export type { Adapter, AdapterConfig, BuiltRoutes, ExplorerData, HttpVerb, Options, PackageData, PathInfo, RoutableFile, RoutableFileType, Route, RouteGenerationData, } from "./types";
|
|
1
|
+
export { default, defaultConfigPlugin, getApi, getPackageData } from "./plugin";
|
|
2
|
+
export type { Adapter, AdapterConfig, BuiltRoutes, ExplorerData, ExternalRoutes, HttpVerb, Options, PackageData, PathInfo, RoutableFile, RoutableFileType, Route, RouteGenerationData, } from "./types";
|
|
3
3
|
export type { SpawnedServer } from "./utils/server";
|
|
4
4
|
export { getAvailablePort, isPortInUse, loadEnv, parseEnv, spawnServer, spawnServerWorker, } from "./utils/server";
|