Skip to content

Commit bd99702

Browse files
committed
fix: add missing deps and fix preview template in create-markopack
1 parent 035318b commit bd99702

4 files changed

Lines changed: 28 additions & 7 deletions

File tree

.changeset/fix-missing-deps.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@markopack/rspack": patch
3+
"create-markopack": patch
4+
---
5+
6+
Add missing dependencies: `sirv` in `@markopack/rspack` (used by dev server) and `@marko/runtime-tags` in create-markopack templates (required by Marko 6 compiled output).
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-markopack": patch
3+
---
4+
5+
Fix static adapter preview template: serve from `dist/server/public` (not `dist/client`), remove TypeScript syntax from `.mjs` output, and serve `404.html` for unknown paths.

packages/create-markopack/src/templates.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const ext = (opts: TemplateOptions) => (opts.typescript ? ".ts" : ".js");
1111
export function packageJson(opts: TemplateOptions): string {
1212
const deps: Record<string, string> = {
1313
marko: "^6.0.0",
14+
"@marko/runtime-tags": "^6.0.0",
1415
};
1516
const devDeps: Record<string, string> = {
1617
"@markopack/rspack": "^0.1.0",
@@ -128,14 +129,14 @@ import path from "node:path";
128129
129130
const root = import.meta.dirname;
130131
const port = Number(process.env.PORT || 3000);
131-
const publicDir = path.join(root, "dist/client");
132+
const publicDir = path.join(root, "dist/server/public");
132133
133134
if (!fs.existsSync(publicDir)) {
134135
console.error("No build found. Run \`npm run build\` first.");
135136
process.exit(1);
136137
}
137138
138-
const mimeTypes: Record<string, string> = {
139+
const mimeTypes = {
139140
".html": "text/html",
140141
".js": "application/javascript",
141142
".css": "text/css",
@@ -146,11 +147,19 @@ const mimeTypes: Record<string, string> = {
146147
".ico": "image/x-icon",
147148
};
148149
150+
function resolveFile(urlPath) {
151+
if (urlPath === "/") return path.join(publicDir, "index.html");
152+
const base = path.join(publicDir, urlPath);
153+
if (fs.existsSync(base) && !fs.statSync(base).isDirectory()) return base;
154+
const withExt = base + ".html";
155+
if (fs.existsSync(withExt)) return withExt;
156+
const asIndex = path.join(base, "index.html");
157+
if (fs.existsSync(asIndex)) return asIndex;
158+
return null;
159+
}
160+
149161
const server = http.createServer((req, res) => {
150-
let filePath = path.join(publicDir, req.url === "/" ? "index.html" : req.url!);
151-
if (!fs.existsSync(filePath) || fs.statSync(filePath).isDirectory()) {
152-
filePath = path.join(publicDir, "index.html");
153-
}
162+
const filePath = resolveFile(req.url) || path.join(publicDir, "404.html");
154163
const ext = path.extname(filePath);
155164
res.setHeader("Content-Type", mimeTypes[ext] || "application/octet-stream");
156165
fs.createReadStream(filePath).pipe(res);

packages/rspack/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"dependencies": {
3636
"@markopack/core": "^0.1.4",
3737
"@markopack/compiler": "^0.1.4",
38-
"picocolors": "^1.1.1"
38+
"picocolors": "^1.1.1",
39+
"sirv": "^3.0.1"
3940
},
4041
"peerDependencies": {
4142
"@marko/run": "^0.9.0",

0 commit comments

Comments
 (0)