@pracht/cli 0.0.0 → 1.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,54 @@
1
+ # @pracht/cli
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#58](https://github.com/JoviDeCroock/pracht/pull/58) [`6bf6738`](https://github.com/JoviDeCroock/pracht/commit/6bf6738469c8533db2890a89b4edcb92bbbb1011) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - Add framework-native `pracht generate route|shell|middleware|api` scaffolding commands, add `pracht doctor` with optional JSON output, and remove the Node-specific `pracht preview` command.
8
+
9
+ ### Minor Changes
10
+
11
+ - [#69](https://github.com/JoviDeCroock/pracht/pull/69) [`527e030`](https://github.com/JoviDeCroock/pracht/commit/527e030017f269b7cff51e96a0bcb98bbd1bff3d) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - Add a fast `pracht verify` command with optional `--changed` and `--json`
12
+ output for framework-aware manifest, pages-router, and API route validation.
13
+
14
+ ### Patch Changes
15
+
16
+ - [#63](https://github.com/JoviDeCroock/pracht/pull/63) [`cf71d67`](https://github.com/JoviDeCroock/pracht/commit/cf71d6781012cc5f79bf5e557658c9fb9112832e) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - Separate HTML and route-state cache variants across framework responses and build outputs.
17
+
18
+ Page responses now vary on `x-pracht-route-state-request`, framework-generated
19
+ route-state responses default to `Cache-Control: no-store`, and Node/preview
20
+ cached HTML paths no longer intercept route-state fetches. Vercel build output
21
+ now routes route-state requests to the edge function before static rewrites.
22
+
23
+ - [#62](https://github.com/JoviDeCroock/pracht/pull/62) [`4017a4a`](https://github.com/JoviDeCroock/pracht/commit/4017a4a59ef702de14a3eb835b0d7bf0967509f8) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - Serve static assets directly from the Node adapter with proper Cache-Control headers. Hashed assets under /assets/ get immutable caching; HTML gets must-revalidate. Preview server now mirrors production caching behavior.
24
+
25
+ - [#51](https://github.com/JoviDeCroock/pracht/pull/51) [`db5f6d0`](https://github.com/JoviDeCroock/pracht/commit/db5f6d0a6770cd36fbcdaea708d2f161d2be23d3) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - Apply default security headers to static asset responses across adapters
26
+
27
+ Cloudflare static assets now inherit the same permissions-policy, referrer-policy, x-content-type-options, and x-frame-options headers that dynamic responses already receive. Vercel build output config now emits a headers section so static files served by Vercel's CDN also get the baseline security headers.
28
+
29
+ - Updated dependencies [[`b34695f`](https://github.com/JoviDeCroock/pracht/commit/b34695f8e6cfaf2e00b77c451395351565ff3b7c), [`bb9480e`](https://github.com/JoviDeCroock/pracht/commit/bb9480ee6a22b3bbb744f174e9132fd8dda446b4), [`4c885be`](https://github.com/JoviDeCroock/pracht/commit/4c885be049049fe2f1b0bbcfe3a39aa63f7364c0), [`cf71d67`](https://github.com/JoviDeCroock/pracht/commit/cf71d6781012cc5f79bf5e557658c9fb9112832e), [`8b71a9f`](https://github.com/JoviDeCroock/pracht/commit/8b71a9f3a7d6fd8d43bea6767d59bfa2d5b28abb), [`4e9b705`](https://github.com/JoviDeCroock/pracht/commit/4e9b7053b5bedadedd39e6343e7a887864e094dd), [`9fc392f`](https://github.com/JoviDeCroock/pracht/commit/9fc392f132b5d34ee9da72f389c6ac15fe2f1161), [`12829ec`](https://github.com/JoviDeCroock/pracht/commit/12829ec075d269e2511387543c4ad592ae5d8c2a)]:
30
+ - @pracht/core@0.1.0
31
+
32
+ ## 0.0.1
33
+
34
+ ### Patch Changes
35
+
36
+ - [#21](https://github.com/JoviDeCroock/pracht/pull/21) [`1243610`](https://github.com/JoviDeCroock/pracht/commit/12436100f9ce4a6dd749190570bf3b0dd1170308) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - Add README files to all packages
37
+
38
+ - [`c95bb72`](https://github.com/JoviDeCroock/pracht/commit/c95bb72c53a2d9012fde847139c276808ba5a9c3) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - Fix SSG prerendered pages missing client JS script tag and framework context
39
+
40
+ Two issues caused prerendered (SSG) pages to ship without working hydration:
41
+
42
+ 1. **Vite 8 environment nesting**: The `@cloudflare/vite-plugin` outputs client assets
43
+ to `<outDir>/client/`, so `outDir: "dist/client"` produced `dist/client/client/`.
44
+ The CLI then couldn't find the Vite manifest, resulting in no `<script>` tag in
45
+ prerendered HTML. Fixed by setting `outDir: "dist"`.
46
+
47
+ 2. **Dual Preact context copies**: The CLI imported `prerenderApp` from its own
48
+ `@pracht/core`, while the server bundle had its own bundled copy. Different
49
+ `createContext` instances meant `useLocation()` returned `/` during prerendering,
50
+ breaking shell features like active link highlighting. Fixed by re-exporting
51
+ `prerenderApp` from the server module so the CLI uses the same bundled copy.
52
+
53
+ - Updated dependencies [[`1243610`](https://github.com/JoviDeCroock/pracht/commit/12436100f9ce4a6dd749190570bf3b0dd1170308), [`d64d7fc`](https://github.com/JoviDeCroock/pracht/commit/d64d7fc1e4a7b134259d1dfbb3d5a939599e42fc)]:
54
+ - @pracht/core@0.0.1
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # @pracht/cli
2
+
3
+ Command-line tool for developing, building, validating, and scaffolding pracht apps.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @pracht/cli
9
+ ```
10
+
11
+ ## Commands
12
+
13
+ ### `pracht dev`
14
+
15
+ Start the local development server with SSR and HMR.
16
+
17
+ ### `pracht build`
18
+
19
+ Create a production build with client/server output and SSG/ISG prerendering.
20
+
21
+ For Node.js targets, run the built server with:
22
+
23
+ ```bash
24
+ node dist/server/server.js
25
+ ```
26
+
27
+ ### `pracht verify`
28
+
29
+ Run fast framework-aware verification checks without paying for a full build or
30
+ test loop. Use `--changed` to focus on changed manifest-managed files and
31
+ `--json` for machine-readable output.
32
+
33
+ ```bash
34
+ pracht verify
35
+ pracht verify --changed
36
+ pracht verify --json
37
+ ```
38
+
39
+ ### `pracht generate route`
40
+
41
+ Create a new route module. In manifest apps this also updates `src/routes.ts`.
42
+
43
+ ```bash
44
+ pracht generate route --path /dashboard --render ssr --shell app --middleware auth
45
+ ```
46
+
47
+ ### `pracht generate shell`
48
+
49
+ Create a shell module and register it in the app manifest.
50
+
51
+ ```bash
52
+ pracht generate shell --name app
53
+ ```
54
+
55
+ ### `pracht generate middleware`
56
+
57
+ Create a middleware module and register it in the app manifest.
58
+
59
+ ```bash
60
+ pracht generate middleware --name auth
61
+ ```
62
+
63
+ ### `pracht generate api`
64
+
65
+ Create an API route under `src/api/`.
66
+
67
+ ```bash
68
+ pracht generate api --path /health --methods GET,POST
69
+ ```
70
+
71
+ ### `pracht doctor`
72
+
73
+ Validate the local app wiring across the whole project. Use `--json` for
74
+ machine-readable output.
75
+
76
+ ```bash
77
+ pracht doctor
78
+ pracht doctor --json
79
+ ```
package/bin/pracht.js CHANGED
@@ -1,29 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { createServer as createHttpServer } from "node:http";
4
- import { resolve, join, dirname, extname } from "node:path";
5
- import {
6
- existsSync,
7
- statSync,
8
- mkdirSync,
9
- writeFileSync,
10
- createReadStream,
11
- readFileSync,
12
- rmSync,
13
- cpSync,
14
- } from "node:fs";
15
- import { createServer, build as viteBuild } from "vite";
16
-
17
- const DEFAULT_SECURITY_HEADERS = {
18
- "permissions-policy":
19
- "accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=()",
20
- "referrer-policy": "strict-origin-when-cross-origin",
21
- "x-content-type-options": "nosniff",
22
- "x-frame-options": "SAMEORIGIN",
23
- };
24
-
25
- const VERSION = "0.0.0";
26
- const command = process.argv[2];
3
+ import { doctorCommand } from "../lib/commands/doctor.js";
4
+ import { buildCommand } from "../lib/commands/build.js";
5
+ import { devCommand } from "../lib/commands/dev.js";
6
+ import { generateCommand } from "../lib/commands/generate.js";
7
+ import { verifyCommand } from "../lib/commands/verify.js";
8
+ import { handleCliError, printHelp } from "../lib/cli.js";
9
+ import { VERSION } from "../lib/constants.js";
10
+
11
+ const argv = process.argv.slice(2);
12
+ const command = argv[0];
13
+ const jsonOutput = argv.includes("--json");
27
14
 
28
15
  if (!command || command === "help" || command === "--help" || command === "-h") {
29
16
  printHelp();
@@ -35,431 +22,18 @@ if (command === "--version" || command === "-v") {
35
22
  process.exit(0);
36
23
  }
37
24
 
38
- const handlers = { dev, build, preview };
25
+ const handlers = {
26
+ build: buildCommand,
27
+ dev: devCommand,
28
+ doctor: doctorCommand,
29
+ generate: generateCommand,
30
+ verify: verifyCommand,
31
+ };
39
32
 
40
33
  if (!(command in handlers)) {
41
- console.error(`Unknown pracht command: ${command}`);
42
- printHelp();
43
- process.exit(1);
34
+ handleCliError(new Error(`Unknown pracht command: ${command}`), { json: false });
44
35
  }
45
36
 
46
- handlers[command]().catch((err) => {
47
- console.error(err);
48
- process.exit(1);
37
+ handlers[command](argv.slice(1)).catch((error) => {
38
+ handleCliError(error, { json: jsonOutput });
49
39
  });
50
-
51
- // ---------------------------------------------------------------------------
52
- // Commands
53
- // ---------------------------------------------------------------------------
54
-
55
- async function dev() {
56
- const port = parseInt(process.env.PORT || process.argv[3] || "3000", 10);
57
-
58
- const server = await createServer({
59
- root: process.cwd(),
60
- server: { port },
61
- });
62
-
63
- await server.listen();
64
- server.printUrls();
65
- }
66
-
67
- async function build() {
68
- // 1. Client build
69
- console.log("\n Building client...\n");
70
- await viteBuild({
71
- root: process.cwd(),
72
- build: {
73
- outDir: "dist/client",
74
- manifest: true,
75
- rollupOptions: {
76
- input: "virtual:pracht/client",
77
- },
78
- },
79
- });
80
-
81
- // 2. SSR build
82
- console.log("\n Building server...\n");
83
- await viteBuild({
84
- root: process.cwd(),
85
- build: {
86
- ssr: "virtual:pracht/server",
87
- outDir: "dist/server",
88
- },
89
- });
90
-
91
- // 3. SSG prerendering
92
- const root = process.cwd();
93
- const serverEntry = resolve(root, "dist/server/server.js");
94
- const clientDir = resolve(root, "dist/client");
95
-
96
- if (existsSync(serverEntry)) {
97
- const serverMod = await import(serverEntry);
98
- const { prerenderApp } = await import("@pracht/core");
99
-
100
- // Read the Vite manifest for asset URLs
101
- const manifestPath = resolve(clientDir, ".vite/manifest.json");
102
- const viteManifest = existsSync(manifestPath)
103
- ? JSON.parse(readFileSync(manifestPath, "utf-8"))
104
- : {};
105
-
106
- const clientEntry = viteManifest["virtual:pracht/client"];
107
- const clientEntryUrl = clientEntry ? `/${clientEntry.file}` : undefined;
108
-
109
- // Build per-source-file CSS manifest by walking static imports transitively.
110
- // This ensures each page gets only the CSS it actually needs.
111
- function collectTransitiveCss(key) {
112
- const css = new Set();
113
- const visited = new Set();
114
- function collect(k) {
115
- if (visited.has(k)) return;
116
- visited.add(k);
117
- const entry = viteManifest[k];
118
- if (!entry) return;
119
- for (const c of entry.css ?? []) css.add(c);
120
- for (const imp of entry.imports ?? []) collect(imp);
121
- }
122
- collect(key);
123
- return [...css];
124
- }
125
-
126
- const cssManifest = {};
127
- for (const [key, entry] of Object.entries(viteManifest)) {
128
- if (!entry.src) continue;
129
- const css = collectTransitiveCss(key);
130
- if (css.length > 0) {
131
- cssManifest[key] = css.map((f) => `/${f}`);
132
- }
133
- }
134
-
135
- const { pages, isgManifest } = await prerenderApp({
136
- app: serverMod.resolvedApp,
137
- registry: serverMod.registry,
138
- clientEntryUrl,
139
- cssManifest,
140
- withISGManifest: true,
141
- });
142
-
143
- if (pages.length > 0) {
144
- console.log(`\n Prerendering ${pages.length} SSG/ISG route(s)...\n`);
145
- for (const page of pages) {
146
- const filePath =
147
- page.path === "/"
148
- ? join(clientDir, "index.html")
149
- : join(clientDir, page.path, "index.html");
150
-
151
- mkdirSync(dirname(filePath), { recursive: true });
152
- writeFileSync(filePath, page.html, "utf-8");
153
- console.log(` ${page.path} → ${filePath.replace(root + "/", "")}`);
154
- }
155
- }
156
-
157
- // Write ISG manifest for the preview/production server
158
- if (Object.keys(isgManifest).length > 0) {
159
- const isgManifestPath = resolve(root, "dist/server/isg-manifest.json");
160
- writeFileSync(isgManifestPath, JSON.stringify(isgManifest, null, 2), "utf-8");
161
- console.log(
162
- `\n ISG manifest → dist/server/isg-manifest.json (${Object.keys(isgManifest).length} route(s))\n`,
163
- );
164
- }
165
-
166
- if (serverMod.buildTarget === "cloudflare") {
167
- console.log(`\n Cloudflare worker → dist/server/server.js\n`);
168
- console.log(` Deploy with: wrangler deploy\n`);
169
- }
170
-
171
- if (serverMod.buildTarget === "vercel") {
172
- const outputPath = writeVercelBuildOutput({
173
- functionName: serverMod.vercelFunctionName,
174
- regions: serverMod.vercelRegions,
175
- root,
176
- staticRoutes: pages.map((page) => page.path).filter((path) => !(path in isgManifest)),
177
- isgRoutes: Object.keys(isgManifest),
178
- });
179
-
180
- console.log(`\n Vercel build output → ${outputPath}\n`);
181
- }
182
- }
183
-
184
- console.log("\n Build complete.\n");
185
- }
186
-
187
- async function preview() {
188
- const root = process.cwd();
189
- const clientDir = resolve(root, "dist/client");
190
- const serverEntry = resolve(root, "dist/server/server.js");
191
-
192
- if (!existsSync(serverEntry)) {
193
- console.error("Server build not found at dist/server/. Run `pracht build` first.");
194
- process.exit(1);
195
- }
196
-
197
- const serverMod = await import(serverEntry);
198
- const { handlePrachtRequest } = await import("@pracht/core");
199
-
200
- // Load ISG manifest if it exists
201
- const isgManifestPath = resolve(root, "dist/server/isg-manifest.json");
202
- const isgManifest = existsSync(isgManifestPath)
203
- ? JSON.parse(readFileSync(isgManifestPath, "utf-8"))
204
- : {};
205
-
206
- // Read the Vite manifest for asset URLs
207
- const manifestPath = resolve(clientDir, ".vite/manifest.json");
208
- const viteManifest = existsSync(manifestPath)
209
- ? JSON.parse(readFileSync(manifestPath, "utf-8"))
210
- : {};
211
-
212
- // Find the client entry asset from the manifest
213
- const clientEntry = viteManifest["virtual:pracht/client"];
214
- const clientEntryUrl = clientEntry ? `/${clientEntry.file}` : undefined;
215
- const cssUrls = (clientEntry?.css ?? []).map((f) => `/${f}`);
216
-
217
- const MIME_TYPES = {
218
- ".html": "text/html",
219
- ".js": "application/javascript",
220
- ".css": "text/css",
221
- ".json": "application/json",
222
- ".png": "image/png",
223
- ".jpg": "image/jpeg",
224
- ".svg": "image/svg+xml",
225
- ".woff": "font/woff",
226
- ".woff2": "font/woff2",
227
- };
228
-
229
- const port = parseInt(process.argv[3] || "3000", 10);
230
-
231
- const server = createHttpServer(async (req, res) => {
232
- const url = req.url ?? "/";
233
-
234
- const parsedUrl = new URL(url, "http://localhost");
235
-
236
- // ISG stale-while-revalidate check
237
- if (req.method === "GET" && parsedUrl.pathname in isgManifest) {
238
- const entry = isgManifest[parsedUrl.pathname];
239
- const htmlPath =
240
- parsedUrl.pathname === "/"
241
- ? join(clientDir, "index.html")
242
- : join(clientDir, parsedUrl.pathname, "index.html");
243
-
244
- if (existsSync(htmlPath) && statSync(htmlPath).isFile()) {
245
- const stat = statSync(htmlPath);
246
- const ageMs = Date.now() - stat.mtimeMs;
247
- const isStale = entry.revalidate.kind === "time" && ageMs > entry.revalidate.seconds * 1000;
248
-
249
- setDefaultSecurityHeaders(res, {
250
- "content-type": "text/html; charset=utf-8",
251
- "x-pracht-isg": isStale ? "stale" : "fresh",
252
- });
253
- createReadStream(htmlPath).pipe(res);
254
-
255
- if (isStale) {
256
- // Background regeneration
257
- const regenRequest = new Request(new URL(parsedUrl.pathname, "http://localhost"), {
258
- method: "GET",
259
- });
260
- handlePrachtRequest({
261
- app: serverMod.resolvedApp,
262
- registry: serverMod.registry,
263
- request: regenRequest,
264
- clientEntryUrl,
265
- cssUrls,
266
- })
267
- .then(async (response) => {
268
- if (response.status === 200) {
269
- const { mkdirSync, writeFileSync } = await import("node:fs");
270
- mkdirSync(dirname(htmlPath), { recursive: true });
271
- writeFileSync(htmlPath, await response.text(), "utf-8");
272
- }
273
- })
274
- .catch((err) => {
275
- console.error(`ISG regeneration failed for ${parsedUrl.pathname}:`, err);
276
- });
277
- }
278
- return;
279
- }
280
- }
281
-
282
- // Try static file first
283
- const filePath = resolve(clientDir, "." + url);
284
- if (!filePath.startsWith(clientDir + "/") && filePath !== clientDir) {
285
- res.statusCode = 403;
286
- res.end("Forbidden");
287
- return;
288
- }
289
- if (existsSync(filePath) && statSync(filePath).isFile()) {
290
- const ext = extname(filePath);
291
- const headers = {
292
- "content-type": MIME_TYPES[ext] || "application/octet-stream",
293
- };
294
- if (ext === ".html") {
295
- setDefaultSecurityHeaders(res, headers);
296
- } else {
297
- for (const [key, value] of Object.entries(headers)) {
298
- res.setHeader(key, value);
299
- }
300
- }
301
- createReadStream(filePath).pipe(res);
302
- return;
303
- }
304
-
305
- // SSR fallback
306
- try {
307
- const headers = new Headers();
308
- for (const [key, value] of Object.entries(req.headers)) {
309
- if (value === undefined) continue;
310
- if (Array.isArray(value)) {
311
- for (const v of value) headers.append(key, v);
312
- } else {
313
- headers.set(key, value);
314
- }
315
- }
316
-
317
- const protocol = req.headers["x-forwarded-proto"] || "http";
318
- const host = req.headers.host || "localhost";
319
- const webRequest = new Request(new URL(url, `${protocol}://${host}`), {
320
- method: req.method,
321
- headers,
322
- });
323
-
324
- const response = await handlePrachtRequest({
325
- app: serverMod.resolvedApp,
326
- registry: serverMod.registry,
327
- request: webRequest,
328
- clientEntryUrl,
329
- cssUrls,
330
- apiRoutes: serverMod.apiRoutes,
331
- });
332
-
333
- res.statusCode = response.status;
334
- response.headers.forEach((value, key) => {
335
- res.setHeader(key, value);
336
- });
337
-
338
- if (!response.body) {
339
- res.end();
340
- return;
341
- }
342
-
343
- const body = Buffer.from(await response.arrayBuffer());
344
- res.end(body);
345
- } catch (err) {
346
- console.error("SSR error:", err);
347
- res.statusCode = 500;
348
- res.end("Internal Server Error");
349
- }
350
- });
351
-
352
- server.listen(port, () => {
353
- console.log(`\n pracht preview server running at http://localhost:${port}\n`);
354
- });
355
- }
356
-
357
- function printHelp() {
358
- console.log(`pracht ${VERSION}
359
-
360
- Usage:
361
- pracht dev Start development server with HMR
362
- pracht build Production build (client + server)
363
- pracht preview Preview the production build
364
- `);
365
- }
366
-
367
- function setDefaultSecurityHeaders(res, headers = {}) {
368
- for (const [key, value] of Object.entries({
369
- ...DEFAULT_SECURITY_HEADERS,
370
- ...headers,
371
- })) {
372
- res.setHeader(key, value);
373
- }
374
- }
375
-
376
- function writeVercelBuildOutput({ functionName, regions, root, staticRoutes, isgRoutes }) {
377
- const outputDir = join(root, ".vercel/output");
378
- const staticDir = join(outputDir, "static");
379
- const functionDir = join(outputDir, "functions", `${functionName || "render"}.func`);
380
-
381
- rmSync(outputDir, { force: true, recursive: true });
382
- mkdirSync(outputDir, { recursive: true });
383
- cpSync(join(root, "dist/client"), staticDir, { recursive: true });
384
- cpSync(join(root, "dist/server"), functionDir, { recursive: true });
385
-
386
- writeFileSync(
387
- join(outputDir, "config.json"),
388
- `${JSON.stringify(createVercelOutputConfig({ functionName, staticRoutes, isgRoutes }), null, 2)}\n`,
389
- "utf-8",
390
- );
391
- writeFileSync(
392
- join(functionDir, ".vc-config.json"),
393
- `${JSON.stringify(createVercelFunctionConfig({ regions }), null, 2)}\n`,
394
- "utf-8",
395
- );
396
-
397
- return ".vercel/output";
398
- }
399
-
400
- function createVercelOutputConfig({ functionName, staticRoutes, isgRoutes }) {
401
- const target = `/${functionName || "render"}`;
402
- const routes = [];
403
-
404
- for (const route of sortStaticRoutes(staticRoutes)) {
405
- routes.push({
406
- src: routeToRouteExpression(route),
407
- dest: routeToStaticHtmlPath(route),
408
- });
409
- }
410
-
411
- for (const route of isgRoutes) {
412
- routes.push({
413
- src: routeToRouteExpression(route),
414
- dest: target,
415
- });
416
- }
417
-
418
- routes.push({ handle: "filesystem" });
419
- routes.push({ src: "/(.*)", dest: target });
420
-
421
- return {
422
- version: 3,
423
- routes,
424
- framework: {
425
- version: VERSION,
426
- },
427
- };
428
- }
429
-
430
- function createVercelFunctionConfig({ regions }) {
431
- const config = {
432
- runtime: "edge",
433
- entrypoint: "server.js",
434
- };
435
-
436
- if (regions) {
437
- config.regions = regions;
438
- }
439
-
440
- return config;
441
- }
442
-
443
- function sortStaticRoutes(routes) {
444
- return [...new Set(routes)].sort((left, right) => right.length - left.length);
445
- }
446
-
447
- function routeToRouteExpression(route) {
448
- if (route === "/") {
449
- return "^/$";
450
- }
451
-
452
- return `^${escapeRegex(route)}/?$`;
453
- }
454
-
455
- function routeToStaticHtmlPath(route) {
456
- if (route === "/") {
457
- return "/index.html";
458
- }
459
-
460
- return `${route}/index.html`;
461
- }
462
-
463
- function escapeRegex(value) {
464
- return value.replace(/[|\\{}()[\]^$+*?.-]/g, "\\$&");
465
- }