@marko/run 0.4.5 → 0.4.6
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/dev-server.d.ts +2 -2
- package/dist/adapter/index.cjs +179 -134
- package/dist/adapter/index.d.ts +1 -1
- package/dist/adapter/index.js +182 -135
- package/dist/adapter/middleware.cjs +13 -4
- package/dist/adapter/middleware.d.ts +0 -1
- package/dist/adapter/middleware.js +13 -4
- package/dist/adapter/polyfill.d.ts +0 -1
- package/dist/adapter/utils.d.ts +16 -0
- package/dist/cli/index.mjs +207 -181
- package/dist/runtime/internal.cjs +7 -5
- package/dist/runtime/internal.d.ts +1 -0
- package/dist/runtime/internal.js +5 -4
- package/dist/runtime/router.d.ts +2 -2
- package/dist/vite/index.cjs +206 -180
- package/dist/vite/index.js +207 -181
- package/dist/vite/utils/ast.d.ts +1 -0
- package/dist/vite/utils/server.d.ts +0 -3
- package/package.json +25 -25
package/dist/cli/index.mjs
CHANGED
|
@@ -75,7 +75,7 @@ import { glob } from "glob";
|
|
|
75
75
|
import { fileURLToPath } from "url";
|
|
76
76
|
import browserslist from "browserslist";
|
|
77
77
|
import { resolveToEsbuildTarget } from "esbuild-plugin-browserslist";
|
|
78
|
-
import { mergeConfig } from "vite";
|
|
78
|
+
import { buildErrorMessage, mergeConfig } from "vite";
|
|
79
79
|
import markoVitePlugin from "@marko/vite";
|
|
80
80
|
|
|
81
81
|
// src/vite/constants.ts
|
|
@@ -944,45 +944,6 @@ function writeRouteEntryHandler(writer, route, verb) {
|
|
|
944
944
|
continuations.join();
|
|
945
945
|
writer.writeBlockEnd("}");
|
|
946
946
|
}
|
|
947
|
-
function renderErrorRouter(error, options = {
|
|
948
|
-
trailingSlashes: "RedirectWithout"
|
|
949
|
-
}) {
|
|
950
|
-
const writer = createStringWriter();
|
|
951
|
-
writer.write(`
|
|
952
|
-
// @marko/run/router
|
|
953
|
-
import { createContext } from '${virtualFilePrefix}/runtime/internal';
|
|
954
|
-
import errorPage from '${virtualFilePrefix}/${markoRunFilePrefix}error.marko${serverEntryQuery}';
|
|
955
|
-
|
|
956
|
-
const error = new Error(\`${error.message}\`);
|
|
957
|
-
error.name = '${error.name}';`);
|
|
958
|
-
if (error.stack) {
|
|
959
|
-
writer.write(`
|
|
960
|
-
error.stack = \`${error.stack}\`;`);
|
|
961
|
-
}
|
|
962
|
-
writer.write(`
|
|
963
|
-
|
|
964
|
-
globalThis.__marko_run__ = { match, fetch, invoke };
|
|
965
|
-
|
|
966
|
-
export function match() {
|
|
967
|
-
return { handler: errorPage, params: {}, meta: {}, path: '/*' }; // /$$
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
export async function invoke(route, request, platform, url) {
|
|
971
|
-
const [context, buildInput] = createContext(route, request, platform, url);
|
|
972
|
-
if (context.request.headers.get('Accept')?.includes('text/html')) {
|
|
973
|
-
return new Response(errorPage.stream(buildInput({ error })), {
|
|
974
|
-
status: 500,
|
|
975
|
-
headers: { "content-type": "text/html;charset=UTF-8" },
|
|
976
|
-
});
|
|
977
|
-
}
|
|
978
|
-
return new Response(error, {
|
|
979
|
-
status: 500,
|
|
980
|
-
});
|
|
981
|
-
}
|
|
982
|
-
`);
|
|
983
|
-
renderFetch(writer, options);
|
|
984
|
-
return writer.end();
|
|
985
|
-
}
|
|
986
947
|
function renderRouter(routes, options = {
|
|
987
948
|
trailingSlashes: "RedirectWithout"
|
|
988
949
|
}) {
|
|
@@ -1115,15 +1076,7 @@ export async function fetch(request, platform) {
|
|
|
1115
1076
|
return await invoke(route, request, platform, url);
|
|
1116
1077
|
} catch (error) {
|
|
1117
1078
|
if (import.meta.env.DEV) {
|
|
1118
|
-
|
|
1119
|
-
if (error.cause) {
|
|
1120
|
-
body = error.cause.stack || error.cause.message || error.cause;
|
|
1121
|
-
} else {
|
|
1122
|
-
body = error.stack || error.message || "Internal Server Error";
|
|
1123
|
-
}
|
|
1124
|
-
return new Response(body, {
|
|
1125
|
-
status: 500
|
|
1126
|
-
});
|
|
1079
|
+
throw error;
|
|
1127
1080
|
}
|
|
1128
1081
|
return new Response(null, {
|
|
1129
1082
|
status: 500
|
|
@@ -1563,6 +1516,29 @@ function getExportIdentifiers(astProgramNode) {
|
|
|
1563
1516
|
}
|
|
1564
1517
|
return result;
|
|
1565
1518
|
}
|
|
1519
|
+
function getViteSSRExportIdentifiers(astProgramNode, exportObjectName = "__vite_ssr_exports__") {
|
|
1520
|
+
const result = [];
|
|
1521
|
+
if (t.isProgram(astProgramNode)) {
|
|
1522
|
+
for (const node of astProgramNode.body) {
|
|
1523
|
+
if (t.isExpressionStatement(node)) {
|
|
1524
|
+
if (t.isAssignmentExpression(node.expression) && t.isMemberExpression(node.expression.left)) {
|
|
1525
|
+
const { object, property } = node.expression.left;
|
|
1526
|
+
if (t.isIdentifier(object) && object.name === exportObjectName && t.isIdentifier(property)) {
|
|
1527
|
+
result.push(property.name);
|
|
1528
|
+
}
|
|
1529
|
+
} else if (t.isCallExpression(node.expression) && t.isMemberExpression(node.expression.callee)) {
|
|
1530
|
+
const {
|
|
1531
|
+
arguments: [arg0, arg1]
|
|
1532
|
+
} = node.expression;
|
|
1533
|
+
if (t.isIdentifier(arg0) && arg0.name === exportObjectName && (t.isStringLiteral(arg1) || "value" in arg1 && typeof arg1.value === "string")) {
|
|
1534
|
+
result.push(arg1.value);
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
return result;
|
|
1541
|
+
}
|
|
1566
1542
|
|
|
1567
1543
|
// src/vite/utils/log.ts
|
|
1568
1544
|
import zlib from "node:zlib";
|
|
@@ -1741,6 +1717,31 @@ process.once("beforeExit", (code) => {
|
|
|
1741
1717
|
}
|
|
1742
1718
|
});
|
|
1743
1719
|
|
|
1720
|
+
// src/adapter/utils.ts
|
|
1721
|
+
import supporsColor from "supports-color";
|
|
1722
|
+
import kleur2 from "kleur";
|
|
1723
|
+
function stripAnsi(string) {
|
|
1724
|
+
return string.replace(
|
|
1725
|
+
/([\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><])/g,
|
|
1726
|
+
""
|
|
1727
|
+
);
|
|
1728
|
+
}
|
|
1729
|
+
function cleanStack(stack) {
|
|
1730
|
+
return stack.split(/\n/).filter((l) => /^\s*at/.test(l)).join("\n");
|
|
1731
|
+
}
|
|
1732
|
+
function prepareError(err) {
|
|
1733
|
+
var _a;
|
|
1734
|
+
return {
|
|
1735
|
+
message: stripAnsi(err.message),
|
|
1736
|
+
stack: stripAnsi(cleanStack(err.stack || "")),
|
|
1737
|
+
id: err.id,
|
|
1738
|
+
frame: stripAnsi(err.frame || ""),
|
|
1739
|
+
plugin: err.plugin,
|
|
1740
|
+
pluginCode: (_a = err.pluginCode) == null ? void 0 : _a.toString(),
|
|
1741
|
+
loc: err.loc
|
|
1742
|
+
};
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1744
1745
|
// src/vite/plugin.ts
|
|
1745
1746
|
var debug = createDebug("@marko/run");
|
|
1746
1747
|
var __dirname = path3.dirname(fileURLToPath(import.meta.url));
|
|
@@ -1764,11 +1765,10 @@ function markoRun(opts = {}) {
|
|
|
1764
1765
|
let devServer;
|
|
1765
1766
|
let routes;
|
|
1766
1767
|
let routeData;
|
|
1767
|
-
let
|
|
1768
|
+
let getExportsFromFile;
|
|
1768
1769
|
let resolvedConfig;
|
|
1769
1770
|
let typesFile;
|
|
1770
|
-
let
|
|
1771
|
-
let isRendered = false;
|
|
1771
|
+
let seenErrors = /* @__PURE__ */ new Set();
|
|
1772
1772
|
const virtualFiles = /* @__PURE__ */ new Map();
|
|
1773
1773
|
let times = {
|
|
1774
1774
|
routesBuild: 0,
|
|
@@ -1791,97 +1791,134 @@ function markoRun(opts = {}) {
|
|
|
1791
1791
|
}
|
|
1792
1792
|
}
|
|
1793
1793
|
}
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
};
|
|
1799
|
-
try {
|
|
1800
|
-
if (isStale) {
|
|
1794
|
+
let buildVirtualFilesResult;
|
|
1795
|
+
function buildVirtualFiles() {
|
|
1796
|
+
return buildVirtualFilesResult ?? (buildVirtualFilesResult = new Promise(async (resolve, reject) => {
|
|
1797
|
+
try {
|
|
1801
1798
|
virtualFiles.clear();
|
|
1802
|
-
isRendered = false;
|
|
1803
|
-
const buildStartTime = performance.now();
|
|
1804
1799
|
routes = await buildRoutes({
|
|
1805
1800
|
walker: createFSWalker(resolvedRoutesDir),
|
|
1806
1801
|
importPrefix: routesDir
|
|
1807
1802
|
});
|
|
1808
|
-
times.routesBuild = performance.now() - buildStartTime;
|
|
1809
1803
|
if (!routes.list.length) {
|
|
1810
1804
|
throw new Error("No routes generated");
|
|
1811
1805
|
}
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
if (!route.handler.verbs.length) {
|
|
1818
|
-
throw new Error(
|
|
1819
|
-
`Did not find any valid exports in middleware entry file:'${route.handler.filePath}' - expected to find any of 'GET', 'POST', 'PUT' or 'DELETE'`
|
|
1806
|
+
for (const route of routes.list) {
|
|
1807
|
+
if (route.page) {
|
|
1808
|
+
virtualFiles.set(
|
|
1809
|
+
path3.posix.join(root, `${route.entryName}.marko`),
|
|
1810
|
+
""
|
|
1820
1811
|
);
|
|
1821
1812
|
}
|
|
1813
|
+
virtualFiles.set(path3.posix.join(root, `${route.entryName}.js`), "");
|
|
1822
1814
|
}
|
|
1823
|
-
|
|
1815
|
+
for (const route of Object.values(routes.special)) {
|
|
1824
1816
|
virtualFiles.set(
|
|
1825
1817
|
path3.posix.join(root, `${route.entryName}.marko`),
|
|
1826
|
-
|
|
1818
|
+
""
|
|
1827
1819
|
);
|
|
1828
1820
|
}
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
virtualFiles.set(
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
);
|
|
1821
|
+
if (routes.middleware.length) {
|
|
1822
|
+
virtualFiles.set(
|
|
1823
|
+
path3.posix.join(root, `${markoRunFilePrefix}middleware.js`),
|
|
1824
|
+
""
|
|
1825
|
+
);
|
|
1826
|
+
}
|
|
1827
|
+
virtualFiles.set("@marko/run/router", "");
|
|
1828
|
+
resolve(routes);
|
|
1829
|
+
} catch (err) {
|
|
1830
|
+
reject(err);
|
|
1839
1831
|
}
|
|
1840
|
-
|
|
1832
|
+
}));
|
|
1833
|
+
}
|
|
1834
|
+
let renderVirtualFilesResult;
|
|
1835
|
+
function renderVirtualFiles(context) {
|
|
1836
|
+
return renderVirtualFilesResult ?? (renderVirtualFilesResult = new Promise(async (resolve) => {
|
|
1837
|
+
var _a;
|
|
1838
|
+
const routerOptions = {
|
|
1839
|
+
trailingSlashes: opts.trailingSlashes || "RedirectWithout"
|
|
1840
|
+
};
|
|
1841
|
+
try {
|
|
1842
|
+
const routes2 = await buildVirtualFiles();
|
|
1843
|
+
for (const route of routes2.list) {
|
|
1844
|
+
if (route.handler) {
|
|
1845
|
+
const exports = await getExportsFromFile(
|
|
1846
|
+
context,
|
|
1847
|
+
route.handler.filePath
|
|
1848
|
+
);
|
|
1849
|
+
route.handler.verbs = [];
|
|
1850
|
+
for (const name of exports) {
|
|
1851
|
+
const verb = name.toLowerCase();
|
|
1852
|
+
if (name === verb.toUpperCase() && httpVerbs.includes(verb)) {
|
|
1853
|
+
route.handler.verbs.push(verb);
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
if (!route.handler.verbs.length) {
|
|
1857
|
+
context.warn(
|
|
1858
|
+
`Did not find any http verb exports in handler '${path3.relative(root, route.handler.filePath)}' - expected ${httpVerbs.map((v) => v.toUpperCase()).join(", ")}`
|
|
1859
|
+
);
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
if (route.page) {
|
|
1863
|
+
virtualFiles.set(
|
|
1864
|
+
path3.posix.join(root, `${route.entryName}.marko`),
|
|
1865
|
+
renderRouteTemplate(route)
|
|
1866
|
+
);
|
|
1867
|
+
}
|
|
1868
|
+
virtualFiles.set(
|
|
1869
|
+
path3.posix.join(root, `${route.entryName}.js`),
|
|
1870
|
+
renderRouteEntry(route)
|
|
1871
|
+
);
|
|
1872
|
+
}
|
|
1873
|
+
for (const route of Object.values(routes2.special)) {
|
|
1874
|
+
virtualFiles.set(
|
|
1875
|
+
path3.posix.join(root, `${route.entryName}.marko`),
|
|
1876
|
+
renderRouteTemplate(route)
|
|
1877
|
+
);
|
|
1878
|
+
}
|
|
1879
|
+
if (routes2.middleware.length) {
|
|
1880
|
+
for (const middleware of routes2.middleware) {
|
|
1881
|
+
if (!(await getExportsFromFile(context, middleware.filePath)).includes("default")) {
|
|
1882
|
+
context.warn(
|
|
1883
|
+
`Did not find a default export in middleware '${path3.relative(root, middleware.filePath)}'`
|
|
1884
|
+
);
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
virtualFiles.set(
|
|
1888
|
+
path3.posix.join(root, `${markoRunFilePrefix}middleware.js`),
|
|
1889
|
+
renderMiddleware(routes2.middleware)
|
|
1890
|
+
);
|
|
1891
|
+
}
|
|
1841
1892
|
virtualFiles.set(
|
|
1842
|
-
|
|
1843
|
-
|
|
1893
|
+
"@marko/run/router",
|
|
1894
|
+
renderRouter(routes2, routerOptions)
|
|
1844
1895
|
);
|
|
1845
|
-
|
|
1846
|
-
virtualFiles.set(
|
|
1847
|
-
"@marko/run/router",
|
|
1848
|
-
render ? renderRouter(routes, routerOptions) : ""
|
|
1849
|
-
);
|
|
1850
|
-
times.routesRender = performance.now() - renderStartTime;
|
|
1851
|
-
if (render) {
|
|
1852
|
-
await writeTypesFile(routes);
|
|
1896
|
+
await writeTypesFile(routes2);
|
|
1853
1897
|
if (adapter == null ? void 0 : adapter.routesGenerated) {
|
|
1854
1898
|
await adapter.routesGenerated(
|
|
1855
|
-
|
|
1899
|
+
routes2,
|
|
1856
1900
|
new Map(virtualFiles.entries()),
|
|
1857
1901
|
{
|
|
1858
1902
|
buildTime: times.routesBuild,
|
|
1859
1903
|
renderTime: times.routesRender
|
|
1860
1904
|
}
|
|
1861
1905
|
);
|
|
1906
|
+
if (!isBuild) {
|
|
1907
|
+
await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes2.list));
|
|
1908
|
+
}
|
|
1862
1909
|
}
|
|
1863
|
-
|
|
1864
|
-
|
|
1910
|
+
} catch (err) {
|
|
1911
|
+
if (isBuild) {
|
|
1912
|
+
throw err;
|
|
1865
1913
|
}
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
throw err;
|
|
1914
|
+
virtualFiles.set(
|
|
1915
|
+
"@marko/run/router",
|
|
1916
|
+
`throw ${JSON.stringify(prepareError(err))}`
|
|
1917
|
+
);
|
|
1871
1918
|
}
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
renderEntryTemplate(`${markoRunFilePrefix}error`, ["<dev-error-page>"])
|
|
1876
|
-
);
|
|
1877
|
-
virtualFiles.set(
|
|
1878
|
-
"@marko/run/router",
|
|
1879
|
-
renderErrorRouter(err, routerOptions)
|
|
1880
|
-
);
|
|
1881
|
-
isRendered = true;
|
|
1882
|
-
}
|
|
1883
|
-
isStale = false;
|
|
1884
|
-
});
|
|
1919
|
+
resolve();
|
|
1920
|
+
}));
|
|
1921
|
+
}
|
|
1885
1922
|
return [
|
|
1886
1923
|
{
|
|
1887
1924
|
name: `${PLUGIN_NAME_PREFIX}:pre`,
|
|
@@ -2041,29 +2078,44 @@ function markoRun(opts = {}) {
|
|
|
2041
2078
|
} else {
|
|
2042
2079
|
ssrEntryFiles = [];
|
|
2043
2080
|
}
|
|
2081
|
+
const baseError = config2.logger.error;
|
|
2082
|
+
config2.logger.error = function(msg, options) {
|
|
2083
|
+
var _a;
|
|
2084
|
+
if (!((_a = options == null ? void 0 : options.error) == null ? void 0 : _a.message)) {
|
|
2085
|
+
baseError.call(this, msg, options);
|
|
2086
|
+
} else if (!seenErrors.has(options.error.message)) {
|
|
2087
|
+
seenErrors.add(options.error.message);
|
|
2088
|
+
console.error(buildErrorMessage(options.error));
|
|
2089
|
+
}
|
|
2090
|
+
};
|
|
2044
2091
|
},
|
|
2045
2092
|
configureServer(_server) {
|
|
2046
2093
|
devServer = _server;
|
|
2047
2094
|
devServer.watcher.on("all", async (type, filename) => {
|
|
2048
|
-
|
|
2095
|
+
seenErrors.clear();
|
|
2096
|
+
const routableFileType = matchRoutableFile(
|
|
2097
|
+
path3.parse(filename).base
|
|
2098
|
+
);
|
|
2049
2099
|
if (filename.startsWith(resolvedRoutesDir) && routableFileType) {
|
|
2050
|
-
if (type === "add") {
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
if (
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2100
|
+
if (type === "add" || type === "unlink" || type === "change" && (routableFileType === RoutableFileTypes.Handler || routableFileType === RoutableFileTypes.Middleware)) {
|
|
2101
|
+
buildVirtualFilesResult = void 0;
|
|
2102
|
+
renderVirtualFilesResult = void 0;
|
|
2103
|
+
const module = devServer.moduleGraph.getModuleById(filename);
|
|
2104
|
+
const importers = module && getImporters(module, filename);
|
|
2105
|
+
if (importers == null ? void 0 : importers.size) {
|
|
2106
|
+
for (const file of importers) {
|
|
2107
|
+
devServer.watcher.emit("change", file);
|
|
2108
|
+
}
|
|
2109
|
+
} else {
|
|
2110
|
+
for (const file of virtualFiles.keys()) {
|
|
2111
|
+
if (!file.endsWith(".marko")) {
|
|
2112
|
+
devServer.watcher.emit("change", file);
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2063
2115
|
}
|
|
2064
2116
|
}
|
|
2065
2117
|
}
|
|
2066
|
-
});
|
|
2118
|
+
}).unwatch(typesDir + "/*");
|
|
2067
2119
|
},
|
|
2068
2120
|
async buildStart(_options) {
|
|
2069
2121
|
if (isBuild && !isSSRBuild) {
|
|
@@ -2079,10 +2131,10 @@ function markoRun(opts = {}) {
|
|
|
2079
2131
|
for (const { key, code } of routeData.files) {
|
|
2080
2132
|
virtualFiles.set(key, code);
|
|
2081
2133
|
}
|
|
2082
|
-
|
|
2083
|
-
|
|
2134
|
+
buildVirtualFilesResult = Promise.resolve(routes);
|
|
2135
|
+
renderVirtualFilesResult = Promise.resolve();
|
|
2084
2136
|
} else {
|
|
2085
|
-
|
|
2137
|
+
getExportsFromFile = isBuild ? getExportsFromFileBuild : getExportsFromFileDev.bind(null, devServer);
|
|
2086
2138
|
}
|
|
2087
2139
|
},
|
|
2088
2140
|
async resolveId(importee, importer) {
|
|
@@ -2095,8 +2147,8 @@ function markoRun(opts = {}) {
|
|
|
2095
2147
|
importee = path3.resolve(root, "." + importee);
|
|
2096
2148
|
}
|
|
2097
2149
|
importee = normalizePath(importee);
|
|
2098
|
-
if (
|
|
2099
|
-
await buildVirtualFiles(
|
|
2150
|
+
if (!buildVirtualFilesResult) {
|
|
2151
|
+
await buildVirtualFiles();
|
|
2100
2152
|
}
|
|
2101
2153
|
if (virtualFiles.has(importee)) {
|
|
2102
2154
|
resolved = importee;
|
|
@@ -2113,11 +2165,13 @@ function markoRun(opts = {}) {
|
|
|
2113
2165
|
if (id.endsWith(serverEntryQuery)) {
|
|
2114
2166
|
id = id.slice(0, -serverEntryQuery.length);
|
|
2115
2167
|
}
|
|
2168
|
+
if (!renderVirtualFilesResult) {
|
|
2169
|
+
await renderVirtualFiles(this);
|
|
2170
|
+
}
|
|
2116
2171
|
if (virtualFiles.has(id)) {
|
|
2117
|
-
if (isStale || !isRendered) {
|
|
2118
|
-
await buildVirtualFiles(true);
|
|
2119
|
-
}
|
|
2120
2172
|
return virtualFiles.get(id);
|
|
2173
|
+
} else if (path3.basename(id).startsWith(markoRunFilePrefix) && /^\.(js|marko)$/.test(path3.extname(id))) {
|
|
2174
|
+
return "";
|
|
2121
2175
|
}
|
|
2122
2176
|
}
|
|
2123
2177
|
},
|
|
@@ -2175,57 +2229,20 @@ function markoRun(opts = {}) {
|
|
|
2175
2229
|
}
|
|
2176
2230
|
];
|
|
2177
2231
|
}
|
|
2178
|
-
async function
|
|
2179
|
-
const verbs = [];
|
|
2232
|
+
async function getExportsFromFileBuild(context, filePath) {
|
|
2180
2233
|
const result = await context.load({
|
|
2181
2234
|
id: filePath,
|
|
2182
2235
|
resolveDependencies: false
|
|
2183
2236
|
});
|
|
2184
|
-
|
|
2185
|
-
const exportIds = getExportIdentifiers(result.ast);
|
|
2186
|
-
for (const id of exportIds) {
|
|
2187
|
-
const verb = id.toLowerCase();
|
|
2188
|
-
if (id === verb.toUpperCase() && httpVerbs.includes(verb)) {
|
|
2189
|
-
verbs.push(verb);
|
|
2190
|
-
}
|
|
2191
|
-
}
|
|
2192
|
-
}
|
|
2193
|
-
return verbs;
|
|
2237
|
+
return result ? getExportIdentifiers(result.ast) : [];
|
|
2194
2238
|
}
|
|
2195
|
-
async function
|
|
2196
|
-
const verbs = [];
|
|
2239
|
+
async function getExportsFromFileDev(devServer, context, filePath) {
|
|
2197
2240
|
const result = await devServer.transformRequest(filePath, { ssr: true });
|
|
2198
|
-
if (result
|
|
2199
|
-
const
|
|
2200
|
-
|
|
2201
|
-
while (match) {
|
|
2202
|
-
const id = match[1];
|
|
2203
|
-
const verb = id.toLowerCase();
|
|
2204
|
-
if (httpVerbs.includes(verb)) {
|
|
2205
|
-
if (id === verb.toUpperCase()) {
|
|
2206
|
-
verbs.push(verb);
|
|
2207
|
-
} else {
|
|
2208
|
-
console.warn(
|
|
2209
|
-
`Found export '${id}' in handler ${filePath} which is close to '${verb.toUpperCase()}'. Exported handlers need to be uppercase: GET, POST, PUT or DELETE.`
|
|
2210
|
-
);
|
|
2211
|
-
}
|
|
2212
|
-
}
|
|
2213
|
-
match = verbMatchReg.exec(result.code);
|
|
2214
|
-
}
|
|
2241
|
+
if (result) {
|
|
2242
|
+
const ast = context.parse(result.code);
|
|
2243
|
+
return getViteSSRExportIdentifiers(ast);
|
|
2215
2244
|
}
|
|
2216
|
-
return
|
|
2217
|
-
}
|
|
2218
|
-
function single(fn) {
|
|
2219
|
-
let promise;
|
|
2220
|
-
return async (...args) => {
|
|
2221
|
-
if (promise) {
|
|
2222
|
-
return promise;
|
|
2223
|
-
}
|
|
2224
|
-
promise = fn(...args);
|
|
2225
|
-
const result = await promise;
|
|
2226
|
-
promise = void 0;
|
|
2227
|
-
return result;
|
|
2228
|
-
};
|
|
2245
|
+
return [];
|
|
2229
2246
|
}
|
|
2230
2247
|
async function globFileExists(root, pattern) {
|
|
2231
2248
|
return (await glob(pattern, { root })).length > 0;
|
|
@@ -2283,6 +2300,15 @@ function isPluginIncluded(config2) {
|
|
|
2283
2300
|
return plugin.name.startsWith(PLUGIN_NAME_PREFIX);
|
|
2284
2301
|
});
|
|
2285
2302
|
}
|
|
2303
|
+
function getImporters(module, fileName, seen = /* @__PURE__ */ new Set()) {
|
|
2304
|
+
for (const importer of module.importers) {
|
|
2305
|
+
if (importer.id && !seen.has(importer.id)) {
|
|
2306
|
+
seen.add(importer.id);
|
|
2307
|
+
getImporters(importer, fileName, seen);
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2310
|
+
return seen;
|
|
2311
|
+
}
|
|
2286
2312
|
|
|
2287
2313
|
// src/cli/commands.ts
|
|
2288
2314
|
var __dirname2 = path4.dirname(fileURLToPath2(import.meta.url));
|
|
@@ -29,7 +29,8 @@ __export(internal_exports, {
|
|
|
29
29
|
normalize: () => normalize,
|
|
30
30
|
notHandled: () => notHandled,
|
|
31
31
|
notMatched: () => notMatched,
|
|
32
|
-
pageResponse: () => pageResponse
|
|
32
|
+
pageResponse: () => pageResponse,
|
|
33
|
+
passthrough: () => passthrough
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(internal_exports);
|
|
35
36
|
|
|
@@ -157,9 +158,9 @@ function normalize(obj) {
|
|
|
157
158
|
};
|
|
158
159
|
return (context, next) => fn(context, next);
|
|
159
160
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
return passthrough;
|
|
162
|
+
}
|
|
163
|
+
function passthrough() {
|
|
163
164
|
}
|
|
164
165
|
function noContent() {
|
|
165
166
|
return new Response(null, {
|
|
@@ -183,5 +184,6 @@ function notMatched() {
|
|
|
183
184
|
normalize,
|
|
184
185
|
notHandled,
|
|
185
186
|
notMatched,
|
|
186
|
-
pageResponse
|
|
187
|
+
pageResponse,
|
|
188
|
+
passthrough
|
|
187
189
|
});
|
|
@@ -6,6 +6,7 @@ export declare function createContext<TRoute extends AnyRoute>(route: TRoute | u
|
|
|
6
6
|
export declare function call<TRoute extends AnyRoute>(handler: RouteHandler<TRoute>, next: NextFunction, context: MultiRouteContext<TRoute>): Promise<Response>;
|
|
7
7
|
export declare function compose(handlers: RouteHandler[]): RouteHandler;
|
|
8
8
|
export declare function normalize(obj: RouteHandler | RouteHandler[] | Promise<RouteHandler | RouteHandler[]>): RouteHandler;
|
|
9
|
+
export declare function passthrough(): void;
|
|
9
10
|
export declare function noContent(): Response;
|
|
10
11
|
export declare function notHandled(): void;
|
|
11
12
|
export declare function notMatched(): null;
|
package/dist/runtime/internal.js
CHANGED
|
@@ -118,9 +118,9 @@ function normalize(obj) {
|
|
|
118
118
|
};
|
|
119
119
|
return (context, next) => fn(context, next);
|
|
120
120
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
return passthrough;
|
|
122
|
+
}
|
|
123
|
+
function passthrough() {
|
|
124
124
|
}
|
|
125
125
|
function noContent() {
|
|
126
126
|
return new Response(null, {
|
|
@@ -143,5 +143,6 @@ export {
|
|
|
143
143
|
normalize,
|
|
144
144
|
notHandled,
|
|
145
145
|
notMatched,
|
|
146
|
-
pageResponse
|
|
146
|
+
pageResponse,
|
|
147
|
+
passthrough
|
|
147
148
|
};
|
package/dist/runtime/router.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const fetch: <TPlatform extends import("./types").Platform = import("./types").Platform>(request: Request, platform: TPlatform) =>
|
|
1
|
+
export declare const fetch: <TPlatform extends import("./types").Platform = import("./types").Platform>(request: Request, platform: TPlatform) => ReturnType<import("./types").Fetch<TPlatform>>;
|
|
2
2
|
export declare const match: import("./types").Match;
|
|
3
|
-
export declare const invoke: <TPlatform extends import("./types").Platform = import("./types").Platform>(route: import("./types").RouteWithHandler<import("./types").ParamsObject, unknown, string> | null, request: Request, platform: TPlatform) =>
|
|
3
|
+
export declare const invoke: <TPlatform extends import("./types").Platform = import("./types").Platform>(route: import("./types").RouteWithHandler<import("./types").ParamsObject, unknown, string> | null, request: Request, platform: TPlatform) => ReturnType<import("./types").Invoke<TPlatform>>;
|