@marko/run 0.5.0 → 0.5.2
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 +1 -1
- package/dist/adapter/index.js +1 -1
- package/dist/cli/index.mjs +77 -51
- package/dist/vite/codegen/index.d.ts +4 -4
- package/dist/vite/index.cjs +77 -51
- package/dist/vite/index.js +77 -51
- package/package.json +4 -3
package/dist/vite/index.js
CHANGED
|
@@ -705,16 +705,19 @@ function hasVerb(route, verb) {
|
|
|
705
705
|
}
|
|
706
706
|
|
|
707
707
|
// src/vite/codegen/index.ts
|
|
708
|
-
function renderRouteTemplate(route) {
|
|
708
|
+
function renderRouteTemplate(route, getRelativePath) {
|
|
709
709
|
if (!route.page) {
|
|
710
710
|
throw new Error(`Route ${route.key} has no page to render`);
|
|
711
711
|
}
|
|
712
712
|
return renderEntryTemplate(
|
|
713
713
|
route.entryName,
|
|
714
|
-
[...route.layouts, route.page].map(
|
|
714
|
+
[...route.layouts, route.page].map(
|
|
715
|
+
(file) => getRelativePath(file.importPath)
|
|
716
|
+
),
|
|
717
|
+
route.key === RoutableFileTypes.Error ? ["error"] : []
|
|
715
718
|
);
|
|
716
719
|
}
|
|
717
|
-
function renderEntryTemplate(name, files) {
|
|
720
|
+
function renderEntryTemplate(name, files, pageInputs = []) {
|
|
718
721
|
if (!name) {
|
|
719
722
|
throw new Error(`Invalid argument - 'name' cannot be empty`);
|
|
720
723
|
}
|
|
@@ -722,27 +725,28 @@ function renderEntryTemplate(name, files) {
|
|
|
722
725
|
throw new Error(`Invalid argument - 'files' cannot be empty`);
|
|
723
726
|
}
|
|
724
727
|
const writer = createStringWriter();
|
|
725
|
-
writer.writeLines(`// ${
|
|
728
|
+
writer.writeLines(`// ${name}.marko`);
|
|
726
729
|
writer.branch("imports");
|
|
727
730
|
writer.writeLines("");
|
|
728
|
-
writeEntryTemplateTag(writer, files);
|
|
731
|
+
writeEntryTemplateTag(writer, files, pageInputs);
|
|
729
732
|
return writer.end();
|
|
730
733
|
}
|
|
731
|
-
function writeEntryTemplateTag(writer, [file, ...rest], index = 1) {
|
|
734
|
+
function writeEntryTemplateTag(writer, [file, ...rest], pageInputs, index = 1) {
|
|
732
735
|
if (file) {
|
|
733
736
|
const isLast = !rest.length;
|
|
734
737
|
const tag = isLast ? "Page" : `Layout${index}`;
|
|
735
738
|
writer.branch("imports").writeLines(`import ${tag} from '${file}';`);
|
|
736
739
|
if (isLast) {
|
|
737
|
-
|
|
740
|
+
const attributes = pageInputs.length ? " " + pageInputs.map((name) => `${name}=input.${name}`).join(" ") : "";
|
|
741
|
+
writer.writeLines(`<${tag}${attributes}/>`);
|
|
738
742
|
} else {
|
|
739
|
-
writer.writeBlockStart(`<${tag}
|
|
740
|
-
writeEntryTemplateTag(writer, rest, index + 1);
|
|
743
|
+
writer.writeBlockStart(`<${tag}>`);
|
|
744
|
+
writeEntryTemplateTag(writer, rest, pageInputs, index + 1);
|
|
741
745
|
writer.writeBlockEnd(`</>`);
|
|
742
746
|
}
|
|
743
747
|
}
|
|
744
748
|
}
|
|
745
|
-
function renderRouteEntry(route) {
|
|
749
|
+
function renderRouteEntry(route, entriesDir) {
|
|
746
750
|
var _a;
|
|
747
751
|
const { key, index, handler, page, middleware, meta, entryName } = route;
|
|
748
752
|
const verbs = getVerbs(route);
|
|
@@ -795,9 +799,8 @@ function renderRouteEntry(route) {
|
|
|
795
799
|
);
|
|
796
800
|
}
|
|
797
801
|
if (page) {
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
);
|
|
802
|
+
const importPath = route.layouts.length ? `./${entriesDir}/${entryName}.marko` : `./${page.importPath}`;
|
|
803
|
+
imports.writeLines(`import page from '${importPath}${serverEntryQuery}';`);
|
|
801
804
|
}
|
|
802
805
|
if (meta) {
|
|
803
806
|
imports.writeLines(
|
|
@@ -885,7 +888,7 @@ function writeRouteEntryHandler(writer, route, verb) {
|
|
|
885
888
|
continuations.join();
|
|
886
889
|
writer.writeBlockEnd("}");
|
|
887
890
|
}
|
|
888
|
-
function renderRouter(routes, options = {
|
|
891
|
+
function renderRouter(routes, entriesDir, options = {
|
|
889
892
|
trailingSlashes: "RedirectWithout"
|
|
890
893
|
}) {
|
|
891
894
|
const writer = createStringWriter();
|
|
@@ -902,9 +905,10 @@ function renderRouter(routes, options = {
|
|
|
902
905
|
`import { ${names.join(", ")} } from '${virtualFilePrefix}/${route.entryName}.js';`
|
|
903
906
|
);
|
|
904
907
|
}
|
|
905
|
-
for (const
|
|
908
|
+
for (const page of Object.values(routes.special)) {
|
|
909
|
+
const importPath = page.layouts.length ? `./${entriesDir}/${page.entryName}.marko` : `./${page.importPath}`;
|
|
906
910
|
imports.writeLines(
|
|
907
|
-
`import page${key} from '${
|
|
911
|
+
`import page${page.key} from '${importPath}${serverEntryQuery}';`
|
|
908
912
|
);
|
|
909
913
|
}
|
|
910
914
|
writer.writeLines(
|
|
@@ -1692,18 +1696,23 @@ function prepareError(err) {
|
|
|
1692
1696
|
}
|
|
1693
1697
|
|
|
1694
1698
|
// src/vite/plugin.ts
|
|
1699
|
+
import { createHash } from "crypto";
|
|
1695
1700
|
var debug = createDebug("@marko/run");
|
|
1696
1701
|
var __dirname = path3.dirname(fileURLToPath(import.meta.url));
|
|
1697
1702
|
var PLUGIN_NAME_PREFIX = "marko-run-vite";
|
|
1698
1703
|
var POSIX_SEP = "/";
|
|
1699
1704
|
var WINDOWS_SEP = "\\";
|
|
1700
1705
|
var CLIENT_OUT_DIR = "public";
|
|
1706
|
+
var MIDDLEWARE_FILENAME = `${markoRunFilePrefix}middleware.js`;
|
|
1707
|
+
var ROUTER_FILENAME = `${markoRunFilePrefix}router.js`;
|
|
1701
1708
|
var normalizePath = path3.sep === WINDOWS_SEP ? (id) => id.replace(/\\/g, POSIX_SEP) : (id) => id;
|
|
1702
1709
|
function markoRun(opts = {}) {
|
|
1703
1710
|
let { routesDir, adapter, ...markoVitePluginOptions } = opts;
|
|
1704
1711
|
let store;
|
|
1705
1712
|
let root;
|
|
1706
1713
|
let resolvedRoutesDir;
|
|
1714
|
+
let entryFilesDir;
|
|
1715
|
+
let relativeEntryFilesDir;
|
|
1707
1716
|
let typesDir;
|
|
1708
1717
|
let isBuild = false;
|
|
1709
1718
|
let isSSRBuild = false;
|
|
@@ -1723,6 +1732,9 @@ function markoRun(opts = {}) {
|
|
|
1723
1732
|
routesBuild: 0,
|
|
1724
1733
|
routesRender: 0
|
|
1725
1734
|
};
|
|
1735
|
+
function getEntryFileRelativePath(to) {
|
|
1736
|
+
return path3.relative(entryFilesDir, to);
|
|
1737
|
+
}
|
|
1726
1738
|
async function writeTypesFile(routes2) {
|
|
1727
1739
|
if (routes2 && (tsConfigExists ?? (tsConfigExists = await globFileExists(
|
|
1728
1740
|
root,
|
|
@@ -1753,27 +1765,12 @@ function markoRun(opts = {}) {
|
|
|
1753
1765
|
throw new Error("No routes generated");
|
|
1754
1766
|
}
|
|
1755
1767
|
for (const route of routes.list) {
|
|
1756
|
-
if (route.page) {
|
|
1757
|
-
virtualFiles.set(
|
|
1758
|
-
path3.posix.join(root, `${route.entryName}.marko`),
|
|
1759
|
-
""
|
|
1760
|
-
);
|
|
1761
|
-
}
|
|
1762
1768
|
virtualFiles.set(path3.posix.join(root, `${route.entryName}.js`), "");
|
|
1763
1769
|
}
|
|
1764
|
-
for (const route of Object.values(routes.special)) {
|
|
1765
|
-
virtualFiles.set(
|
|
1766
|
-
path3.posix.join(root, `${route.entryName}.marko`),
|
|
1767
|
-
""
|
|
1768
|
-
);
|
|
1769
|
-
}
|
|
1770
1770
|
if (routes.middleware.length) {
|
|
1771
|
-
virtualFiles.set(
|
|
1772
|
-
path3.posix.join(root, `${markoRunFilePrefix}middleware.js`),
|
|
1773
|
-
""
|
|
1774
|
-
);
|
|
1771
|
+
virtualFiles.set(path3.posix.join(root, MIDDLEWARE_FILENAME), "");
|
|
1775
1772
|
}
|
|
1776
|
-
virtualFiles.set(
|
|
1773
|
+
virtualFiles.set(path3.posix.join(root, ROUTER_FILENAME), "");
|
|
1777
1774
|
resolve(routes);
|
|
1778
1775
|
} catch (err) {
|
|
1779
1776
|
reject(err);
|
|
@@ -1784,11 +1781,12 @@ function markoRun(opts = {}) {
|
|
|
1784
1781
|
function renderVirtualFiles(context) {
|
|
1785
1782
|
return renderVirtualFilesResult ?? (renderVirtualFilesResult = new Promise(async (resolve) => {
|
|
1786
1783
|
var _a;
|
|
1787
|
-
const routerOptions = {
|
|
1788
|
-
trailingSlashes: opts.trailingSlashes || "RedirectWithout"
|
|
1789
|
-
};
|
|
1790
1784
|
try {
|
|
1791
1785
|
const routes2 = await buildVirtualFiles();
|
|
1786
|
+
let entryFilesDirExists = false;
|
|
1787
|
+
if (fs3.existsSync(entryFilesDir)) {
|
|
1788
|
+
fs3.rmSync(entryFilesDir, { recursive: true });
|
|
1789
|
+
}
|
|
1792
1790
|
for (const route of routes2.list) {
|
|
1793
1791
|
if (route.handler) {
|
|
1794
1792
|
const exports = await getExportsFromFile(
|
|
@@ -1808,22 +1806,30 @@ function markoRun(opts = {}) {
|
|
|
1808
1806
|
);
|
|
1809
1807
|
}
|
|
1810
1808
|
}
|
|
1811
|
-
if (route.page) {
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1809
|
+
if (route.page && route.layouts.length) {
|
|
1810
|
+
entryFilesDirExists || (entryFilesDirExists = !!fs3.mkdirSync(entryFilesDir, {
|
|
1811
|
+
recursive: true
|
|
1812
|
+
}));
|
|
1813
|
+
fs3.writeFileSync(
|
|
1814
|
+
path3.posix.join(entryFilesDir, `${route.entryName}.marko`),
|
|
1815
|
+
renderRouteTemplate(route, getEntryFileRelativePath)
|
|
1815
1816
|
);
|
|
1816
1817
|
}
|
|
1817
1818
|
virtualFiles.set(
|
|
1818
1819
|
path3.posix.join(root, `${route.entryName}.js`),
|
|
1819
|
-
renderRouteEntry(route)
|
|
1820
|
+
renderRouteEntry(route, relativeEntryFilesDir)
|
|
1820
1821
|
);
|
|
1821
1822
|
}
|
|
1822
1823
|
for (const route of Object.values(routes2.special)) {
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1824
|
+
if (route.layouts.length) {
|
|
1825
|
+
entryFilesDirExists || (entryFilesDirExists = !!fs3.mkdirSync(entryFilesDir, {
|
|
1826
|
+
recursive: true
|
|
1827
|
+
}));
|
|
1828
|
+
fs3.writeFileSync(
|
|
1829
|
+
path3.posix.join(entryFilesDir, `${route.entryName}.marko`),
|
|
1830
|
+
renderRouteTemplate(route, getEntryFileRelativePath)
|
|
1831
|
+
);
|
|
1832
|
+
}
|
|
1827
1833
|
}
|
|
1828
1834
|
if (routes2.middleware.length) {
|
|
1829
1835
|
for (const middleware of routes2.middleware) {
|
|
@@ -1834,13 +1840,15 @@ function markoRun(opts = {}) {
|
|
|
1834
1840
|
}
|
|
1835
1841
|
}
|
|
1836
1842
|
virtualFiles.set(
|
|
1837
|
-
path3.posix.join(root,
|
|
1843
|
+
path3.posix.join(root, MIDDLEWARE_FILENAME),
|
|
1838
1844
|
renderMiddleware(routes2.middleware)
|
|
1839
1845
|
);
|
|
1840
1846
|
}
|
|
1841
1847
|
virtualFiles.set(
|
|
1842
|
-
|
|
1843
|
-
renderRouter(routes2,
|
|
1848
|
+
path3.posix.join(root, ROUTER_FILENAME),
|
|
1849
|
+
renderRouter(routes2, relativeEntryFilesDir, {
|
|
1850
|
+
trailingSlashes: opts.trailingSlashes || "RedirectWithout"
|
|
1851
|
+
})
|
|
1844
1852
|
);
|
|
1845
1853
|
await writeTypesFile(routes2);
|
|
1846
1854
|
if (adapter == null ? void 0 : adapter.routesGenerated) {
|
|
@@ -1861,7 +1869,7 @@ function markoRun(opts = {}) {
|
|
|
1861
1869
|
throw err;
|
|
1862
1870
|
}
|
|
1863
1871
|
virtualFiles.set(
|
|
1864
|
-
|
|
1872
|
+
path3.posix.join(root, ROUTER_FILENAME),
|
|
1865
1873
|
`throw ${JSON.stringify(prepareError(err))}`
|
|
1866
1874
|
);
|
|
1867
1875
|
}
|
|
@@ -1904,6 +1912,13 @@ function markoRun(opts = {}) {
|
|
|
1904
1912
|
markoVitePluginOptions.runtimeId = opts.runtimeId;
|
|
1905
1913
|
markoVitePluginOptions.basePathVar = opts.basePathVar;
|
|
1906
1914
|
resolvedRoutesDir = path3.resolve(root, routesDir);
|
|
1915
|
+
const modulesDir = getModulesDir(root);
|
|
1916
|
+
entryFilesDir = path3.join(
|
|
1917
|
+
modulesDir,
|
|
1918
|
+
".marko",
|
|
1919
|
+
createHash("shake256", { outputLength: 4 }).update(root).digest("hex")
|
|
1920
|
+
);
|
|
1921
|
+
relativeEntryFilesDir = path3.relative(root, entryFilesDir);
|
|
1907
1922
|
typesDir = path3.join(root, ".marko-run");
|
|
1908
1923
|
devEntryFile = path3.join(root, "index.html");
|
|
1909
1924
|
devEntryFilePosix = normalizePath(devEntryFile);
|
|
@@ -2089,7 +2104,9 @@ function markoRun(opts = {}) {
|
|
|
2089
2104
|
async resolveId(importee, importer) {
|
|
2090
2105
|
let resolved;
|
|
2091
2106
|
let virtualFilePath;
|
|
2092
|
-
if (importee
|
|
2107
|
+
if (importee === "@marko/run/router") {
|
|
2108
|
+
importee = path3.resolve(root, ROUTER_FILENAME);
|
|
2109
|
+
} else if (importee.startsWith(virtualFilePrefix)) {
|
|
2093
2110
|
virtualFilePath = importee.slice(virtualFilePrefix.length + 1);
|
|
2094
2111
|
importee = path3.resolve(root, virtualFilePath);
|
|
2095
2112
|
} else if (!isBuild && importer && (importer === devEntryFile || normalizePath(importer) === devEntryFilePosix) && importee.startsWith(`/${markoRunFilePrefix}`)) {
|
|
@@ -2119,7 +2136,7 @@ function markoRun(opts = {}) {
|
|
|
2119
2136
|
}
|
|
2120
2137
|
if (virtualFiles.has(id)) {
|
|
2121
2138
|
return virtualFiles.get(id);
|
|
2122
|
-
} else if (/[/\\]__marko-run__[^?/\\]+\.(js|marko)$/.exec(id)) {
|
|
2139
|
+
} else if (!id.startsWith(entryFilesDir) && /[/\\]__marko-run__[^?/\\]+\.(js|marko)$/.exec(id)) {
|
|
2123
2140
|
return "";
|
|
2124
2141
|
}
|
|
2125
2142
|
}
|
|
@@ -2253,6 +2270,15 @@ function getImporters(module, fileName, seen = /* @__PURE__ */ new Set()) {
|
|
|
2253
2270
|
}
|
|
2254
2271
|
return seen;
|
|
2255
2272
|
}
|
|
2273
|
+
function getModulesDir(root, dir = __dirname) {
|
|
2274
|
+
if (dir.startsWith(root)) {
|
|
2275
|
+
const index = dir.indexOf("node_modules");
|
|
2276
|
+
if (index >= 0) {
|
|
2277
|
+
return dir.slice(0, index + 12);
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
return path3.join(root, "node_modules");
|
|
2281
|
+
}
|
|
2256
2282
|
|
|
2257
2283
|
// src/vite/utils/server.ts
|
|
2258
2284
|
import net from "net";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marko/run",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "The Marko application framework.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/marko-js/run/tree/main/packages/run",
|
|
@@ -98,6 +98,7 @@
|
|
|
98
98
|
"acorn": "^8.14.0",
|
|
99
99
|
"body-parser": "^1.20.3",
|
|
100
100
|
"cross-env": "^7.0.3",
|
|
101
|
+
"diff": "^7.0.0",
|
|
101
102
|
"esbuild": "^0.24.0",
|
|
102
103
|
"express": "^4.21.1",
|
|
103
104
|
"jsdom": "^25.0.1",
|
|
@@ -109,11 +110,11 @@
|
|
|
109
110
|
"ts-node": "^10.9.2",
|
|
110
111
|
"tslib": "^2.8.1",
|
|
111
112
|
"tsx": "^4.19.2",
|
|
112
|
-
"typescript": "^5.
|
|
113
|
+
"typescript": "^5.7.2"
|
|
113
114
|
},
|
|
114
115
|
"dependencies": {
|
|
115
116
|
"@marko/run-explorer": "^0.1.2",
|
|
116
|
-
"@marko/vite": "^5.0.
|
|
117
|
+
"@marko/vite": "^5.0.5",
|
|
117
118
|
"browserslist": "^4.24.2",
|
|
118
119
|
"cli-table3": "^0.6.5",
|
|
119
120
|
"compression": "^1.7.5",
|