@marko/run 0.4.4 → 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 +183 -142
- package/dist/adapter/index.d.ts +1 -1
- package/dist/adapter/index.js +186 -143
- package/dist/adapter/middleware.cjs +16 -10
- package/dist/adapter/middleware.d.ts +0 -1
- package/dist/adapter/middleware.js +16 -10
- package/dist/adapter/polyfill.d.ts +0 -1
- package/dist/adapter/utils.d.ts +16 -0
- package/dist/cli/index.mjs +227 -220
- 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 +226 -219
- package/dist/vite/index.js +227 -220
- package/dist/vite/utils/ast.d.ts +1 -0
- package/dist/vite/utils/server.d.ts +0 -3
- package/package.json +30 -30
- package/dist/components/src-attributes-transformer.cjs +0 -122
package/dist/cli/index.mjs
CHANGED
|
@@ -1,28 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
-
return value;
|
|
7
|
-
};
|
|
8
|
-
var __accessCheck = (obj, member, msg) => {
|
|
9
|
-
if (!member.has(obj))
|
|
10
|
-
throw TypeError("Cannot " + msg);
|
|
11
|
-
};
|
|
12
|
-
var __privateGet = (obj, member, getter) => {
|
|
13
|
-
__accessCheck(obj, member, "read from private field");
|
|
14
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
15
|
-
};
|
|
16
|
-
var __privateAdd = (obj, member, value) => {
|
|
17
|
-
if (member.has(obj))
|
|
18
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
19
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
20
|
-
};
|
|
21
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
22
|
-
__accessCheck(obj, member, "write to private field");
|
|
23
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
24
|
-
return value;
|
|
3
|
+
var __typeError = (msg) => {
|
|
4
|
+
throw TypeError(msg);
|
|
25
5
|
};
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
9
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
10
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
11
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
26
12
|
|
|
27
13
|
// src/cli/index.ts
|
|
28
14
|
import sade from "sade";
|
|
@@ -89,7 +75,7 @@ import { glob } from "glob";
|
|
|
89
75
|
import { fileURLToPath } from "url";
|
|
90
76
|
import browserslist from "browserslist";
|
|
91
77
|
import { resolveToEsbuildTarget } from "esbuild-plugin-browserslist";
|
|
92
|
-
import { mergeConfig } from "vite";
|
|
78
|
+
import { buildErrorMessage, mergeConfig } from "vite";
|
|
93
79
|
import markoVitePlugin from "@marko/vite";
|
|
94
80
|
|
|
95
81
|
// src/vite/constants.ts
|
|
@@ -111,8 +97,8 @@ var RoutableFileTypes = {
|
|
|
111
97
|
var _dirs, _pathlessDirs;
|
|
112
98
|
var _VDir = class _VDir {
|
|
113
99
|
constructor(parent, segment, source) {
|
|
114
|
-
__privateAdd(this, _dirs
|
|
115
|
-
__privateAdd(this, _pathlessDirs
|
|
100
|
+
__privateAdd(this, _dirs);
|
|
101
|
+
__privateAdd(this, _pathlessDirs);
|
|
116
102
|
__publicField(this, "parent");
|
|
117
103
|
__publicField(this, "source");
|
|
118
104
|
__publicField(this, "path");
|
|
@@ -252,8 +238,7 @@ var VDir = _VDir;
|
|
|
252
238
|
|
|
253
239
|
// src/vite/routes/parse.ts
|
|
254
240
|
function parseFlatRoute(pattern) {
|
|
255
|
-
if (!pattern)
|
|
256
|
-
throw new Error("Empty pattern");
|
|
241
|
+
if (!pattern) throw new Error("Empty pattern");
|
|
257
242
|
const len = pattern.length;
|
|
258
243
|
let i = 0;
|
|
259
244
|
return parse2([
|
|
@@ -959,45 +944,6 @@ function writeRouteEntryHandler(writer, route, verb) {
|
|
|
959
944
|
continuations.join();
|
|
960
945
|
writer.writeBlockEnd("}");
|
|
961
946
|
}
|
|
962
|
-
function renderErrorRouter(error, options = {
|
|
963
|
-
trailingSlashes: "RedirectWithout"
|
|
964
|
-
}) {
|
|
965
|
-
const writer = createStringWriter();
|
|
966
|
-
writer.write(`
|
|
967
|
-
// @marko/run/router
|
|
968
|
-
import { createContext } from '${virtualFilePrefix}/runtime/internal';
|
|
969
|
-
import errorPage from '${virtualFilePrefix}/${markoRunFilePrefix}error.marko${serverEntryQuery}';
|
|
970
|
-
|
|
971
|
-
const error = new Error(\`${error.message}\`);
|
|
972
|
-
error.name = '${error.name}';`);
|
|
973
|
-
if (error.stack) {
|
|
974
|
-
writer.write(`
|
|
975
|
-
error.stack = \`${error.stack}\`;`);
|
|
976
|
-
}
|
|
977
|
-
writer.write(`
|
|
978
|
-
|
|
979
|
-
globalThis.__marko_run__ = { match, fetch, invoke };
|
|
980
|
-
|
|
981
|
-
export function match() {
|
|
982
|
-
return { handler: errorPage, params: {}, meta: {}, path: '/*' }; // /$$
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
export async function invoke(route, request, platform, url) {
|
|
986
|
-
const [context, buildInput] = createContext(route, request, platform, url);
|
|
987
|
-
if (context.request.headers.get('Accept')?.includes('text/html')) {
|
|
988
|
-
return new Response(errorPage.stream(buildInput({ error })), {
|
|
989
|
-
status: 500,
|
|
990
|
-
headers: { "content-type": "text/html;charset=UTF-8" },
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
return new Response(error, {
|
|
994
|
-
status: 500,
|
|
995
|
-
});
|
|
996
|
-
}
|
|
997
|
-
`);
|
|
998
|
-
renderFetch(writer, options);
|
|
999
|
-
return writer.end();
|
|
1000
|
-
}
|
|
1001
947
|
function renderRouter(routes, options = {
|
|
1002
948
|
trailingSlashes: "RedirectWithout"
|
|
1003
949
|
}) {
|
|
@@ -1130,15 +1076,7 @@ export async function fetch(request, platform) {
|
|
|
1130
1076
|
return await invoke(route, request, platform, url);
|
|
1131
1077
|
} catch (error) {
|
|
1132
1078
|
if (import.meta.env.DEV) {
|
|
1133
|
-
|
|
1134
|
-
if (error.cause) {
|
|
1135
|
-
body = error.cause.stack || error.cause.message || error.cause;
|
|
1136
|
-
} else {
|
|
1137
|
-
body = error.stack || error.message || "Internal Server Error";
|
|
1138
|
-
}
|
|
1139
|
-
return new Response(body, {
|
|
1140
|
-
status: 500
|
|
1141
|
-
});
|
|
1079
|
+
throw error;
|
|
1142
1080
|
}
|
|
1143
1081
|
return new Response(null, {
|
|
1144
1082
|
status: 500
|
|
@@ -1578,6 +1516,29 @@ function getExportIdentifiers(astProgramNode) {
|
|
|
1578
1516
|
}
|
|
1579
1517
|
return result;
|
|
1580
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
|
+
}
|
|
1581
1542
|
|
|
1582
1543
|
// src/vite/utils/log.ts
|
|
1583
1544
|
import zlib from "node:zlib";
|
|
@@ -1698,12 +1659,9 @@ function prettySize([bytes, compBytes]) {
|
|
|
1698
1659
|
const [size, prefix] = format(bytes, { decimals: 1 }).split(/\s+/);
|
|
1699
1660
|
const compSize = format(compBytes, { decimals: 1, prefix, unit: "B" });
|
|
1700
1661
|
let str = kleur.white(size) + kleur.gray("/");
|
|
1701
|
-
if (compBytes < 20 * 1e3)
|
|
1702
|
-
|
|
1703
|
-
else
|
|
1704
|
-
str += kleur.yellow(compSize);
|
|
1705
|
-
else
|
|
1706
|
-
str += kleur.bold(kleur.red(compSize));
|
|
1662
|
+
if (compBytes < 20 * 1e3) str += kleur.green(compSize);
|
|
1663
|
+
else if (compBytes < 50 * 1e3) str += kleur.yellow(compSize);
|
|
1664
|
+
else str += kleur.bold(kleur.red(compSize));
|
|
1707
1665
|
return str;
|
|
1708
1666
|
}
|
|
1709
1667
|
function prettyPath(path5) {
|
|
@@ -1759,6 +1717,31 @@ process.once("beforeExit", (code) => {
|
|
|
1759
1717
|
}
|
|
1760
1718
|
});
|
|
1761
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
|
+
|
|
1762
1745
|
// src/vite/plugin.ts
|
|
1763
1746
|
var debug = createDebug("@marko/run");
|
|
1764
1747
|
var __dirname = path3.dirname(fileURLToPath(import.meta.url));
|
|
@@ -1782,11 +1765,10 @@ function markoRun(opts = {}) {
|
|
|
1782
1765
|
let devServer;
|
|
1783
1766
|
let routes;
|
|
1784
1767
|
let routeData;
|
|
1785
|
-
let
|
|
1768
|
+
let getExportsFromFile;
|
|
1786
1769
|
let resolvedConfig;
|
|
1787
1770
|
let typesFile;
|
|
1788
|
-
let
|
|
1789
|
-
let isRendered = false;
|
|
1771
|
+
let seenErrors = /* @__PURE__ */ new Set();
|
|
1790
1772
|
const virtualFiles = /* @__PURE__ */ new Map();
|
|
1791
1773
|
let times = {
|
|
1792
1774
|
routesBuild: 0,
|
|
@@ -1809,97 +1791,134 @@ function markoRun(opts = {}) {
|
|
|
1809
1791
|
}
|
|
1810
1792
|
}
|
|
1811
1793
|
}
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
};
|
|
1817
|
-
try {
|
|
1818
|
-
if (isStale) {
|
|
1794
|
+
let buildVirtualFilesResult;
|
|
1795
|
+
function buildVirtualFiles() {
|
|
1796
|
+
return buildVirtualFilesResult ?? (buildVirtualFilesResult = new Promise(async (resolve, reject) => {
|
|
1797
|
+
try {
|
|
1819
1798
|
virtualFiles.clear();
|
|
1820
|
-
isRendered = false;
|
|
1821
|
-
const buildStartTime = performance.now();
|
|
1822
1799
|
routes = await buildRoutes({
|
|
1823
1800
|
walker: createFSWalker(resolvedRoutesDir),
|
|
1824
1801
|
importPrefix: routesDir
|
|
1825
1802
|
});
|
|
1826
|
-
times.routesBuild = performance.now() - buildStartTime;
|
|
1827
1803
|
if (!routes.list.length) {
|
|
1828
1804
|
throw new Error("No routes generated");
|
|
1829
1805
|
}
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
if (!route.handler.verbs.length) {
|
|
1836
|
-
throw new Error(
|
|
1837
|
-
`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
|
+
""
|
|
1838
1811
|
);
|
|
1839
1812
|
}
|
|
1813
|
+
virtualFiles.set(path3.posix.join(root, `${route.entryName}.js`), "");
|
|
1840
1814
|
}
|
|
1841
|
-
|
|
1815
|
+
for (const route of Object.values(routes.special)) {
|
|
1842
1816
|
virtualFiles.set(
|
|
1843
1817
|
path3.posix.join(root, `${route.entryName}.marko`),
|
|
1844
|
-
|
|
1818
|
+
""
|
|
1845
1819
|
);
|
|
1846
1820
|
}
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
virtualFiles.set(
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
);
|
|
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);
|
|
1857
1831
|
}
|
|
1858
|
-
|
|
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
|
+
}
|
|
1859
1892
|
virtualFiles.set(
|
|
1860
|
-
|
|
1861
|
-
|
|
1893
|
+
"@marko/run/router",
|
|
1894
|
+
renderRouter(routes2, routerOptions)
|
|
1862
1895
|
);
|
|
1863
|
-
|
|
1864
|
-
virtualFiles.set(
|
|
1865
|
-
"@marko/run/router",
|
|
1866
|
-
render ? renderRouter(routes, routerOptions) : ""
|
|
1867
|
-
);
|
|
1868
|
-
times.routesRender = performance.now() - renderStartTime;
|
|
1869
|
-
if (render) {
|
|
1870
|
-
await writeTypesFile(routes);
|
|
1896
|
+
await writeTypesFile(routes2);
|
|
1871
1897
|
if (adapter == null ? void 0 : adapter.routesGenerated) {
|
|
1872
1898
|
await adapter.routesGenerated(
|
|
1873
|
-
|
|
1899
|
+
routes2,
|
|
1874
1900
|
new Map(virtualFiles.entries()),
|
|
1875
1901
|
{
|
|
1876
1902
|
buildTime: times.routesBuild,
|
|
1877
1903
|
renderTime: times.routesRender
|
|
1878
1904
|
}
|
|
1879
1905
|
);
|
|
1906
|
+
if (!isBuild) {
|
|
1907
|
+
await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes2.list));
|
|
1908
|
+
}
|
|
1880
1909
|
}
|
|
1881
|
-
|
|
1882
|
-
|
|
1910
|
+
} catch (err) {
|
|
1911
|
+
if (isBuild) {
|
|
1912
|
+
throw err;
|
|
1883
1913
|
}
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
throw err;
|
|
1914
|
+
virtualFiles.set(
|
|
1915
|
+
"@marko/run/router",
|
|
1916
|
+
`throw ${JSON.stringify(prepareError(err))}`
|
|
1917
|
+
);
|
|
1889
1918
|
}
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
renderEntryTemplate(`${markoRunFilePrefix}error`, ["<dev-error-page>"])
|
|
1894
|
-
);
|
|
1895
|
-
virtualFiles.set(
|
|
1896
|
-
"@marko/run/router",
|
|
1897
|
-
renderErrorRouter(err, routerOptions)
|
|
1898
|
-
);
|
|
1899
|
-
isRendered = true;
|
|
1900
|
-
}
|
|
1901
|
-
isStale = false;
|
|
1902
|
-
});
|
|
1919
|
+
resolve();
|
|
1920
|
+
}));
|
|
1921
|
+
}
|
|
1903
1922
|
return [
|
|
1904
1923
|
{
|
|
1905
1924
|
name: `${PLUGIN_NAME_PREFIX}:pre`,
|
|
@@ -1935,12 +1954,6 @@ function markoRun(opts = {}) {
|
|
|
1935
1954
|
template: normalizePath(
|
|
1936
1955
|
path3.resolve(__dirname, "../components/dev-error-page.marko")
|
|
1937
1956
|
)
|
|
1938
|
-
},
|
|
1939
|
-
"<*>": {
|
|
1940
|
-
transform: path3.resolve(
|
|
1941
|
-
__dirname,
|
|
1942
|
-
"../components/src-attributes-transformer.cjs"
|
|
1943
|
-
)
|
|
1944
1957
|
}
|
|
1945
1958
|
});
|
|
1946
1959
|
routesDir = opts.routesDir || "src/routes";
|
|
@@ -2025,7 +2038,12 @@ function markoRun(opts = {}) {
|
|
|
2025
2038
|
] : void 0
|
|
2026
2039
|
},
|
|
2027
2040
|
resolve: isBuild ? {
|
|
2028
|
-
mainFields: (isSSRBuild ? [] : ["browser"]).concat([
|
|
2041
|
+
mainFields: (isSSRBuild ? [] : ["browser"]).concat([
|
|
2042
|
+
"module",
|
|
2043
|
+
"jsnext:main",
|
|
2044
|
+
"jsnext",
|
|
2045
|
+
"main"
|
|
2046
|
+
]),
|
|
2029
2047
|
conditions: [
|
|
2030
2048
|
isSSRBuild ? "node" : "browser",
|
|
2031
2049
|
"import",
|
|
@@ -2060,29 +2078,44 @@ function markoRun(opts = {}) {
|
|
|
2060
2078
|
} else {
|
|
2061
2079
|
ssrEntryFiles = [];
|
|
2062
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
|
+
};
|
|
2063
2091
|
},
|
|
2064
2092
|
configureServer(_server) {
|
|
2065
2093
|
devServer = _server;
|
|
2066
2094
|
devServer.watcher.on("all", async (type, filename) => {
|
|
2067
|
-
|
|
2095
|
+
seenErrors.clear();
|
|
2096
|
+
const routableFileType = matchRoutableFile(
|
|
2097
|
+
path3.parse(filename).base
|
|
2098
|
+
);
|
|
2068
2099
|
if (filename.startsWith(resolvedRoutesDir) && routableFileType) {
|
|
2069
|
-
if (type === "add") {
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
if (
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
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
|
+
}
|
|
2082
2115
|
}
|
|
2083
2116
|
}
|
|
2084
2117
|
}
|
|
2085
|
-
});
|
|
2118
|
+
}).unwatch(typesDir + "/*");
|
|
2086
2119
|
},
|
|
2087
2120
|
async buildStart(_options) {
|
|
2088
2121
|
if (isBuild && !isSSRBuild) {
|
|
@@ -2098,10 +2131,10 @@ function markoRun(opts = {}) {
|
|
|
2098
2131
|
for (const { key, code } of routeData.files) {
|
|
2099
2132
|
virtualFiles.set(key, code);
|
|
2100
2133
|
}
|
|
2101
|
-
|
|
2102
|
-
|
|
2134
|
+
buildVirtualFilesResult = Promise.resolve(routes);
|
|
2135
|
+
renderVirtualFilesResult = Promise.resolve();
|
|
2103
2136
|
} else {
|
|
2104
|
-
|
|
2137
|
+
getExportsFromFile = isBuild ? getExportsFromFileBuild : getExportsFromFileDev.bind(null, devServer);
|
|
2105
2138
|
}
|
|
2106
2139
|
},
|
|
2107
2140
|
async resolveId(importee, importer) {
|
|
@@ -2114,8 +2147,8 @@ function markoRun(opts = {}) {
|
|
|
2114
2147
|
importee = path3.resolve(root, "." + importee);
|
|
2115
2148
|
}
|
|
2116
2149
|
importee = normalizePath(importee);
|
|
2117
|
-
if (
|
|
2118
|
-
await buildVirtualFiles(
|
|
2150
|
+
if (!buildVirtualFilesResult) {
|
|
2151
|
+
await buildVirtualFiles();
|
|
2119
2152
|
}
|
|
2120
2153
|
if (virtualFiles.has(importee)) {
|
|
2121
2154
|
resolved = importee;
|
|
@@ -2132,11 +2165,13 @@ function markoRun(opts = {}) {
|
|
|
2132
2165
|
if (id.endsWith(serverEntryQuery)) {
|
|
2133
2166
|
id = id.slice(0, -serverEntryQuery.length);
|
|
2134
2167
|
}
|
|
2168
|
+
if (!renderVirtualFilesResult) {
|
|
2169
|
+
await renderVirtualFiles(this);
|
|
2170
|
+
}
|
|
2135
2171
|
if (virtualFiles.has(id)) {
|
|
2136
|
-
if (isStale || !isRendered) {
|
|
2137
|
-
await buildVirtualFiles(true);
|
|
2138
|
-
}
|
|
2139
2172
|
return virtualFiles.get(id);
|
|
2173
|
+
} else if (path3.basename(id).startsWith(markoRunFilePrefix) && /^\.(js|marko)$/.test(path3.extname(id))) {
|
|
2174
|
+
return "";
|
|
2140
2175
|
}
|
|
2141
2176
|
}
|
|
2142
2177
|
},
|
|
@@ -2194,57 +2229,20 @@ function markoRun(opts = {}) {
|
|
|
2194
2229
|
}
|
|
2195
2230
|
];
|
|
2196
2231
|
}
|
|
2197
|
-
async function
|
|
2198
|
-
const verbs = [];
|
|
2232
|
+
async function getExportsFromFileBuild(context, filePath) {
|
|
2199
2233
|
const result = await context.load({
|
|
2200
2234
|
id: filePath,
|
|
2201
2235
|
resolveDependencies: false
|
|
2202
2236
|
});
|
|
2203
|
-
|
|
2204
|
-
const exportIds = getExportIdentifiers(result.ast);
|
|
2205
|
-
for (const id of exportIds) {
|
|
2206
|
-
const verb = id.toLowerCase();
|
|
2207
|
-
if (id === verb.toUpperCase() && httpVerbs.includes(verb)) {
|
|
2208
|
-
verbs.push(verb);
|
|
2209
|
-
}
|
|
2210
|
-
}
|
|
2211
|
-
}
|
|
2212
|
-
return verbs;
|
|
2237
|
+
return result ? getExportIdentifiers(result.ast) : [];
|
|
2213
2238
|
}
|
|
2214
|
-
async function
|
|
2215
|
-
const verbs = [];
|
|
2239
|
+
async function getExportsFromFileDev(devServer, context, filePath) {
|
|
2216
2240
|
const result = await devServer.transformRequest(filePath, { ssr: true });
|
|
2217
|
-
if (result
|
|
2218
|
-
const
|
|
2219
|
-
|
|
2220
|
-
while (match) {
|
|
2221
|
-
const id = match[1];
|
|
2222
|
-
const verb = id.toLowerCase();
|
|
2223
|
-
if (httpVerbs.includes(verb)) {
|
|
2224
|
-
if (id === verb.toUpperCase()) {
|
|
2225
|
-
verbs.push(verb);
|
|
2226
|
-
} else {
|
|
2227
|
-
console.warn(
|
|
2228
|
-
`Found export '${id}' in handler ${filePath} which is close to '${verb.toUpperCase()}'. Exported handlers need to be uppercase: GET, POST, PUT or DELETE.`
|
|
2229
|
-
);
|
|
2230
|
-
}
|
|
2231
|
-
}
|
|
2232
|
-
match = verbMatchReg.exec(result.code);
|
|
2233
|
-
}
|
|
2241
|
+
if (result) {
|
|
2242
|
+
const ast = context.parse(result.code);
|
|
2243
|
+
return getViteSSRExportIdentifiers(ast);
|
|
2234
2244
|
}
|
|
2235
|
-
return
|
|
2236
|
-
}
|
|
2237
|
-
function single(fn) {
|
|
2238
|
-
let promise;
|
|
2239
|
-
return async (...args) => {
|
|
2240
|
-
if (promise) {
|
|
2241
|
-
return promise;
|
|
2242
|
-
}
|
|
2243
|
-
promise = fn(...args);
|
|
2244
|
-
const result = await promise;
|
|
2245
|
-
promise = void 0;
|
|
2246
|
-
return result;
|
|
2247
|
-
};
|
|
2245
|
+
return [];
|
|
2248
2246
|
}
|
|
2249
2247
|
async function globFileExists(root, pattern) {
|
|
2250
2248
|
return (await glob(pattern, { root })).length > 0;
|
|
@@ -2302,6 +2300,15 @@ function isPluginIncluded(config2) {
|
|
|
2302
2300
|
return plugin.name.startsWith(PLUGIN_NAME_PREFIX);
|
|
2303
2301
|
});
|
|
2304
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
|
+
}
|
|
2305
2312
|
|
|
2306
2313
|
// src/cli/commands.ts
|
|
2307
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
|
};
|