@jk2908/solas 0.3.8 → 0.4.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +66 -6
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.js +16 -2
  5. package/dist/internal/browser-router/link.d.ts +1 -1
  6. package/dist/internal/browser-router/link.js +1 -1
  7. package/dist/internal/browser-router/router.d.ts +2 -165
  8. package/dist/internal/browser-router/router.js +3 -99
  9. package/dist/internal/browser-router/shared.d.ts +169 -0
  10. package/dist/internal/browser-router/shared.js +71 -0
  11. package/dist/internal/browser-router/use-router.d.ts +1 -1
  12. package/dist/internal/codegen/environments.js +5 -4
  13. package/dist/internal/env/rsc.d.ts +2 -2
  14. package/dist/internal/env/rsc.js +82 -22
  15. package/dist/internal/http-router/create-http-router.d.ts +1 -1
  16. package/dist/internal/http-router/create-http-router.js +4 -2
  17. package/dist/internal/http-router/router.d.ts +4 -14
  18. package/dist/internal/http-router/router.js +32 -59
  19. package/dist/internal/navigation/http-exception.d.ts +4 -4
  20. package/dist/internal/navigation/http-exception.js +4 -5
  21. package/dist/internal/postbuild.d.ts +1 -0
  22. package/dist/{cli/build.js → internal/postbuild.js} +13 -48
  23. package/dist/internal/prerender.d.ts +4 -19
  24. package/dist/internal/prerender.js +8 -98
  25. package/dist/internal/public-files.d.ts +18 -0
  26. package/dist/internal/public-files.js +63 -0
  27. package/dist/internal/resolver.d.ts +23 -23
  28. package/dist/internal/server/actions.d.ts +2 -5
  29. package/dist/internal/server/actions.js +4 -35
  30. package/dist/internal/server/csrf.d.ts +14 -0
  31. package/dist/internal/server/csrf.js +98 -0
  32. package/dist/router.d.ts +1 -0
  33. package/dist/router.js +1 -0
  34. package/dist/solas.d.ts +12 -1
  35. package/dist/solas.js +116 -1
  36. package/dist/types.d.ts +8 -3
  37. package/dist/utils/base-path.d.ts +14 -0
  38. package/dist/utils/base-path.js +85 -0
  39. package/package.json +3 -6
  40. package/dist/cli/build.d.ts +0 -7
  41. package/dist/cli/dev.d.ts +0 -4
  42. package/dist/cli/dev.js +0 -13
  43. package/dist/cli/preview.d.ts +0 -1
  44. package/dist/cli/preview.js +0 -47
  45. package/dist/cli.d.ts +0 -2
  46. package/dist/cli.js +0 -28
@@ -0,0 +1,85 @@
1
+ export { BasePath };
2
+ var BasePath;
3
+ (function (BasePath) {
4
+ /**
5
+ * Normalise a base path so every check uses the same shape
6
+ */
7
+ function normalise(value) {
8
+ // no base means the app lives at the site root
9
+ if (!value)
10
+ return '/';
11
+ if (value === '/' || value === '.' || value === './')
12
+ return '/';
13
+ let pathname = value.trim();
14
+ if (!pathname)
15
+ return '/';
16
+ // plain path bases are the common case, so keep them cheap
17
+ if (!pathname.startsWith('http://') && !pathname.startsWith('https://')) {
18
+ const hashIndex = pathname.indexOf('#');
19
+ const searchIndex = pathname.indexOf('?');
20
+ const end = hashIndex === -1
21
+ ? searchIndex
22
+ : searchIndex === -1
23
+ ? hashIndex
24
+ : Math.min(hashIndex, searchIndex);
25
+ if (end >= 0)
26
+ pathname = pathname.slice(0, end);
27
+ }
28
+ else {
29
+ try {
30
+ // full urls can still show up here, but we only need the path part
31
+ pathname = new URL(pathname).pathname;
32
+ }
33
+ catch {
34
+ // if parsing fails, fall back to the raw value below
35
+ }
36
+ }
37
+ if (!pathname || pathname === '.' || pathname === './')
38
+ return '/';
39
+ // keep one stable shape: leading slash, trailing slash
40
+ if (!pathname.startsWith('/'))
41
+ pathname = `/${pathname}`;
42
+ return pathname.endsWith('/') ? pathname : `${pathname}/`;
43
+ }
44
+ BasePath.normalise = normalise;
45
+ /**
46
+ * Strip the base path from a request path
47
+ */
48
+ function strip(pathname, base) {
49
+ const normalisedBase = normalise(base);
50
+ // root base means there is nothing to strip
51
+ if (normalisedBase === '/')
52
+ return pathname || '/';
53
+ const basePath = normalisedBase.slice(0, -1);
54
+ // treat both '/docs' and '/docs/' as the app root
55
+ if (pathname === basePath || pathname === normalisedBase)
56
+ return '/';
57
+ // paths outside the base do not belong to this app
58
+ if (!pathname.startsWith(`${basePath}/`))
59
+ return null;
60
+ // return the path as the app should see it
61
+ return pathname.slice(basePath.length) || '/';
62
+ }
63
+ BasePath.strip = strip;
64
+ /**
65
+ * Add the base path to a path when needed
66
+ */
67
+ function apply(pathname, base) {
68
+ const normalisedBase = normalise(base);
69
+ // always work with a path-like value
70
+ const target = pathname.startsWith('/') ? pathname : `/${pathname}`;
71
+ // root base means the path can pass through unchanged
72
+ if (normalisedBase === '/')
73
+ return target;
74
+ const basePath = normalisedBase.slice(0, -1);
75
+ // leave it alone if the base is already there
76
+ if (target === basePath || target.startsWith(`${basePath}/`))
77
+ return target;
78
+ // the app root maps to the base path itself
79
+ if (target === '/')
80
+ return normalisedBase;
81
+ // everything else sits underneath the base path
82
+ return `${basePath}${target}`;
83
+ }
84
+ BasePath.apply = apply;
85
+ })(BasePath || (BasePath = {}));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jk2908/solas",
3
- "version": "0.3.8",
4
- "description": "A React Server Components meta-framework powered by Vite",
3
+ "version": "0.4.0",
4
+ "description": "A Vite + React meta-framework exploring streaming, Server Components, and partial prerendering. Designed for simplicity and lightness",
5
5
  "keywords": [
6
6
  "framework",
7
7
  "ppr",
@@ -19,9 +19,6 @@
19
19
  "type": "git",
20
20
  "url": "https://github.com/jk2908/solas.git"
21
21
  },
22
- "bin": {
23
- "solas": "./dist/cli.js"
24
- },
25
22
  "files": [
26
23
  "dist",
27
24
  "CHANGELOG.md",
@@ -74,7 +71,7 @@
74
71
  }
75
72
  },
76
73
  "scripts": {
77
- "build": "rm -rf dist && tsgo && chmod +x dist/cli.js",
74
+ "build": "rm -rf dist && tsgo",
78
75
  "lint": "bunx oxlint .",
79
76
  "lint:fix": "bunx oxlint --fix .",
80
77
  "format": "bunx oxfmt --write .",
@@ -1,7 +0,0 @@
1
- /**
2
- * The build command does more than just run vite build - it also handles prerendering and
3
- * precompressing assets. This is because prerendering needs to run against the built
4
- * server entry to ensure the same code paths as preview, and precompressing needs
5
- * to include the prerendered html and json files
6
- */
7
- export declare function build(): Promise<void>;
package/dist/cli/dev.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * Start the vite development server
3
- */
4
- export declare function dev(): Promise<void>;
package/dist/cli/dev.js DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * Start the vite development server
3
- */
4
- export async function dev() {
5
- const proc = Bun.spawn(['bunx', '--bun', 'vite', 'dev'], {
6
- cwd: process.cwd(),
7
- stdout: 'inherit',
8
- stderr: 'inherit',
9
- stdin: 'inherit',
10
- env: { ...process.env, NODE_ENV: 'development' },
11
- });
12
- await proc.exited;
13
- }
@@ -1 +0,0 @@
1
- export declare function preview(): Promise<void>;
@@ -1,47 +0,0 @@
1
- import fs from 'node:fs/promises';
2
- import path from 'node:path';
3
- import { Logger } from '../utils/logger.js';
4
- import { Solas } from '../solas.js';
5
- const logger = new Logger();
6
- const DEFAULT_PREVIEW_PORT = 4173;
7
- const [, , , ...args] = process.argv;
8
- export async function preview() {
9
- // preview should behave like production, not like vite dev
10
- process.env.NODE_ENV = 'production';
11
- const cwd = process.cwd();
12
- const outDir = path.resolve(cwd, Solas.Config.OUT_DIR);
13
- const rscDir = path.join(outDir, 'rsc');
14
- const rscEntry = path.join(rscDir, 'index.js');
15
- const portFlagIndex = args.findIndex(arg => arg === '--port' || arg === '-p');
16
- const parsedPort = portFlagIndex >= 0 && args[portFlagIndex + 1]
17
- ? Number(args[portFlagIndex + 1])
18
- : DEFAULT_PREVIEW_PORT;
19
- // fail fast if the port is invalid
20
- if (!Number.isInteger(parsedPort) || parsedPort <= 0 || parsedPort > 65535) {
21
- logger.error(`[preview] invalid port: ${args[portFlagIndex + 1] ?? 'undefined'}`);
22
- process.exit(1);
23
- }
24
- // the built server entry handles routing, prerendered html, and ssr here
25
- try {
26
- await fs.access(rscEntry);
27
- }
28
- catch (err) {
29
- logger.error(`[preview] missing ${path.relative(cwd, rscEntry)} - run \`${Solas.Config.SLUG} build\` from this project directory first`, err);
30
- process.exit(1);
31
- }
32
- const { default: app } = await import(/* @vite-ignore */ rscEntry);
33
- try {
34
- // keep the preview server thin and let the app handle requests
35
- Bun.serve({
36
- port: parsedPort,
37
- fetch: app.fetch,
38
- });
39
- }
40
- catch (err) {
41
- logger.error(`[preview] failed to start on port ${parsedPort}: ${err}`);
42
- process.exit(1);
43
- }
44
- logger.info('[preview]', `server running at http://localhost:${parsedPort}`);
45
- // keep the process running after the server starts
46
- await new Promise(() => { });
47
- }
package/dist/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env bun
2
- export {};
package/dist/cli.js DELETED
@@ -1,28 +0,0 @@
1
- #!/usr/bin/env bun
2
- import { build } from './cli/build.js';
3
- import { dev } from './cli/dev.js';
4
- import { preview } from './cli/preview.js';
5
- import { Solas } from './solas.js';
6
- // read the subcommand once and dispatch below
7
- const [, , command] = process.argv;
8
- switch (command) {
9
- case 'build':
10
- await build();
11
- break;
12
- case 'dev':
13
- await dev();
14
- break;
15
- case 'preview':
16
- await preview();
17
- break;
18
- default:
19
- console.log(`
20
- ${Solas.Config.NAME} - cli
21
-
22
- Commands:
23
- build Build for production (vite build + prerender + compress)
24
- dev Start development server
25
- preview Preview production build (serves prerendered HTML with SSR fallback)
26
- `);
27
- process.exit(command ? 1 : 0);
28
- }