@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.
- package/CHANGELOG.md +15 -0
- package/README.md +66 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -2
- package/dist/internal/browser-router/link.d.ts +1 -1
- package/dist/internal/browser-router/link.js +1 -1
- package/dist/internal/browser-router/router.d.ts +2 -165
- package/dist/internal/browser-router/router.js +3 -99
- package/dist/internal/browser-router/shared.d.ts +169 -0
- package/dist/internal/browser-router/shared.js +71 -0
- package/dist/internal/browser-router/use-router.d.ts +1 -1
- package/dist/internal/codegen/environments.js +5 -4
- package/dist/internal/env/rsc.d.ts +2 -2
- package/dist/internal/env/rsc.js +82 -22
- package/dist/internal/http-router/create-http-router.d.ts +1 -1
- package/dist/internal/http-router/create-http-router.js +4 -2
- package/dist/internal/http-router/router.d.ts +4 -14
- package/dist/internal/http-router/router.js +32 -59
- package/dist/internal/navigation/http-exception.d.ts +4 -4
- package/dist/internal/navigation/http-exception.js +4 -5
- package/dist/internal/postbuild.d.ts +1 -0
- package/dist/{cli/build.js → internal/postbuild.js} +13 -48
- package/dist/internal/prerender.d.ts +4 -19
- package/dist/internal/prerender.js +8 -98
- package/dist/internal/public-files.d.ts +18 -0
- package/dist/internal/public-files.js +63 -0
- package/dist/internal/resolver.d.ts +23 -23
- package/dist/internal/server/actions.d.ts +2 -5
- package/dist/internal/server/actions.js +4 -35
- package/dist/internal/server/csrf.d.ts +14 -0
- package/dist/internal/server/csrf.js +98 -0
- package/dist/router.d.ts +1 -0
- package/dist/router.js +1 -0
- package/dist/solas.d.ts +12 -1
- package/dist/solas.js +116 -1
- package/dist/types.d.ts +8 -3
- package/dist/utils/base-path.d.ts +14 -0
- package/dist/utils/base-path.js +85 -0
- package/package.json +3 -6
- package/dist/cli/build.d.ts +0 -7
- package/dist/cli/dev.d.ts +0 -4
- package/dist/cli/dev.js +0 -13
- package/dist/cli/preview.d.ts +0 -1
- package/dist/cli/preview.js +0 -47
- package/dist/cli.d.ts +0 -2
- 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.
|
|
4
|
-
"description": "A
|
|
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
|
|
74
|
+
"build": "rm -rf dist && tsgo",
|
|
78
75
|
"lint": "bunx oxlint .",
|
|
79
76
|
"lint:fix": "bunx oxlint --fix .",
|
|
80
77
|
"format": "bunx oxfmt --write .",
|
package/dist/cli/build.d.ts
DELETED
|
@@ -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
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
|
-
}
|
package/dist/cli/preview.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function preview(): Promise<void>;
|
package/dist/cli/preview.js
DELETED
|
@@ -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
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
|
-
}
|