@kayjs/kay 2.0.0-alpha.5 → 2.0.0-alpha.7
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/package.json +1 -1
- package/src/build/compile.ts +18 -11
- package/src/build/index.ts +454 -43
- package/src/cli/check.ts +165 -4
- package/src/cli/index.ts +7 -4
- package/src/cli/new.ts +1 -1
- package/src/compiler/dom.ts +151 -37
- package/src/compiler/ssr.ts +16 -1
- package/src/dev/index.ts +135 -22
- package/src/dom/extras.ts +67 -11
- package/src/dom/index.ts +3 -3
- package/src/dom/island.ts +97 -75
- package/src/plugins/index.ts +35 -2
- package/src/server/action.ts +47 -0
- package/src/server/compress.ts +241 -0
- package/src/server/cookies.ts +4 -0
- package/src/server/http.ts +44 -9
- package/src/server/index.ts +510 -193
- package/src/server/security.ts +81 -1
- package/src/ssr/context.ts +5 -2
- package/src/ssr/index.ts +30 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kayjs/kay",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.7",
|
|
4
4
|
"description": "Bun-native TSX web framework with zero-directive automatic islands, fine-grained signals, and single-binary deploys",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://kayjs.kaynooo.fr",
|
package/src/build/compile.ts
CHANGED
|
@@ -15,10 +15,11 @@ export interface CompileExecutableOptions {
|
|
|
15
15
|
outfile: string
|
|
16
16
|
kaySrcRoot: string
|
|
17
17
|
resolveKaySpecifier: (specifier: string) => string | undefined
|
|
18
|
+
bunPlugins?: BunPlugin[] | undefined
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export async function compileExecutable(opts: CompileExecutableOptions): Promise<void> {
|
|
21
|
-
const { root, outDir, clientDir, manifest, assetPrefix, outfile, kaySrcRoot, resolveKaySpecifier } = opts
|
|
22
|
+
const { root, outDir, clientDir, manifest, assetPrefix, outfile, kaySrcRoot, resolveKaySpecifier, bunPlugins = [] } = opts
|
|
22
23
|
const entryPath = join(outDir, '__compile_entry.ts')
|
|
23
24
|
const imports: string[] = []
|
|
24
25
|
const modEntries: string[] = []
|
|
@@ -67,18 +68,21 @@ export async function compileExecutable(opts: CompileExecutableOptions): Promise
|
|
|
67
68
|
embeddedPublic.push(`${JSON.stringify(rel)}: ${v}`)
|
|
68
69
|
embeddedPublicEtags.push(`${JSON.stringify(rel)}: ${JSON.stringify(etag)}`)
|
|
69
70
|
}
|
|
70
|
-
const
|
|
71
|
+
const embeddedPrerenderedFiles: string[] = []
|
|
72
|
+
let preIdx = 0
|
|
71
73
|
for (const r of manifest.routes) {
|
|
72
74
|
if (r.prerendered) {
|
|
73
75
|
for (const [, relHtml] of Object.entries(r.prerendered)) {
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
+
const abs = join(outDir, relHtml)
|
|
77
|
+
const v = `_r${preIdx++}`
|
|
78
|
+
imports.push(`import ${v} from ${JSON.stringify(abs)} with { type: "file" };`)
|
|
79
|
+
embeddedPrerenderedFiles.push(`${JSON.stringify(relHtml)}: ${v}`)
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
const cfgSpread = hasConfig
|
|
81
|
-
? `, plugins: _kayConfig?.plugins, lang: _kayConfig?.lang, security: _kayConfig?.security, trustedOrigins: _kayConfig?.trustedOrigins`
|
|
85
|
+
? `, plugins: _kayConfig?.plugins, lang: _kayConfig?.lang, security: _kayConfig?.security, trustedOrigins: _kayConfig?.trustedOrigins, compress: _kayConfig?.compress, onError: _kayConfig?.onError`
|
|
82
86
|
: ''
|
|
83
87
|
|
|
84
88
|
// Default NODE_ENV to 'production' in compiled binaries (dynamic key avoids Bun.build constant-folding).
|
|
@@ -91,11 +95,14 @@ export async function compileExecutable(opts: CompileExecutableOptions): Promise
|
|
|
91
95
|
`const assets = { ${embeddedAssets.join(', ')} };`,
|
|
92
96
|
`const publicAssets = { ${embeddedPublic.join(', ')} };`,
|
|
93
97
|
`const publicEtags = { ${embeddedPublicEtags.join(', ')} };`,
|
|
94
|
-
`const prerendered = {
|
|
95
|
-
`const
|
|
96
|
-
`const port = Number(process.env.PORT ?? 3000);`,
|
|
97
|
-
`const
|
|
98
|
-
`
|
|
98
|
+
`const prerendered = {};`,
|
|
99
|
+
`const prerenderedFiles = { ${embeddedPrerenderedFiles.join(', ')} };`,
|
|
100
|
+
`const port = Number(process.env.PORT ?? ${hasConfig ? '_kayConfig?.port ?? ' : ''}3000);`,
|
|
101
|
+
`const hostname = process.env.HOST || undefined;`,
|
|
102
|
+
`if (Bun.argv.includes('--health')) { const r = await fetch(\`http://\${hostname ?? '127.0.0.1'}:\${port}/\`).catch(() => null); process.exit(r && r.status < 500 ? 0 : 1); }`,
|
|
103
|
+
`const app = await createServerFromEmbedded({ manifest, modules, assets, publicAssets, publicEtags, prerendered, prerenderedFiles, assetPrefix: ${JSON.stringify(assetPrefix)}${cfgSpread} });`,
|
|
104
|
+
`const server = app.serve(port, hostname);`,
|
|
105
|
+
`console.log(\`kay server listening on http://\${hostname ?? 'localhost'}:\${server.port}\`);`,
|
|
99
106
|
].join('\n')
|
|
100
107
|
|
|
101
108
|
writeFileSync(entryPath, code)
|
|
@@ -113,7 +120,7 @@ export async function compileExecutable(opts: CompileExecutableOptions): Promise
|
|
|
113
120
|
entrypoints: [entryPath],
|
|
114
121
|
compile: { outfile },
|
|
115
122
|
minify: true,
|
|
116
|
-
plugins: [kayResolvePlugin],
|
|
123
|
+
plugins: [kayResolvePlugin, ...bunPlugins],
|
|
117
124
|
})
|
|
118
125
|
if (!res.success) {
|
|
119
126
|
const msgs = res.logs.map(l => l.message).join('\n')
|