bun-plugin-stx 0.2.5 → 0.2.8
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/dist/{chunk-ymdk9x8z.js → chunk-a3qganyh.js} +21 -7
- package/dist/chunk-fj6fej0j.js +12771 -0
- package/dist/client.d.ts +2 -2
- package/dist/client.js +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +2 -2
- package/dist/preload.d.ts +1 -0
- package/dist/preload.js +2 -2
- package/dist/serve.d.ts +4 -1
- package/dist/serve.js +82 -23
- package/dist/watch.d.ts +1 -1
- package/package.json +7 -2
- /package/dist/{chunk-eecw9x2f.js → chunk-2mx7fq49.js} +0 -0
package/dist/client.d.ts
CHANGED
|
@@ -26,8 +26,8 @@ export declare interface HydrationConfig {
|
|
|
26
26
|
/**
|
|
27
27
|
* Island handler registry
|
|
28
28
|
*/
|
|
29
|
-
export type IslandHandlers = Record<string, () => Promise<any
|
|
29
|
+
export type IslandHandlers = Record<string, () => Promise<any>>;
|
|
30
30
|
/**
|
|
31
31
|
* Island hydration function type
|
|
32
32
|
*/
|
|
33
|
-
export type HydrationFunction = (
|
|
33
|
+
export type HydrationFunction = (_element: HTMLElement, _props: any) => void | Promise<void>;
|
package/dist/client.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,9 @@ export type { CustomDirective, CustomDirectiveHandler, ServeOptions, ServeResult
|
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
export declare function stxPlugin(userOptions?: StxOptions): BunPlugin;
|
|
32
|
+
// Export watch functionality
|
|
32
33
|
export { createWatcher, startWatchMode, watchAndBuild } from './watch';
|
|
34
|
+
// Re-export functions and types that consumers might need
|
|
35
|
+
// Note: serve is exported from ./serve.ts, not here (to avoid duplicate export names when bundled)
|
|
33
36
|
export { createMiddleware, createRoute, readMarkdownFile } from '@stacksjs/stx';
|
|
34
|
-
export default stxPlugin;
|
|
37
|
+
export default stxPlugin;
|
package/dist/index.js
CHANGED
package/dist/preload.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/preload.js
CHANGED
package/dist/serve.d.ts
CHANGED
|
@@ -9,4 +9,7 @@ export declare interface ServeOptions {
|
|
|
9
9
|
componentsDir?: string
|
|
10
10
|
layoutsDir?: string
|
|
11
11
|
partialsDir?: string
|
|
12
|
-
|
|
12
|
+
quiet?: boolean
|
|
13
|
+
routes?: Record<string, (req: Request) => Response | Promise<Response>>
|
|
14
|
+
onRequest?: (req: Request) => Response | Promise<Response> | null | undefined
|
|
15
|
+
}
|
package/dist/serve.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
import {
|
|
4
4
|
__require
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-2mx7fq49.js";
|
|
6
6
|
|
|
7
7
|
// src/serve.ts
|
|
8
8
|
var {serve: bunServe, Glob } = globalThis.Bun;
|
|
@@ -5063,7 +5063,9 @@ var defaultGeneratedDir3 = resolve7(process12.cwd(), "src/generated");
|
|
|
5063
5063
|
var defaultStxConfig = {
|
|
5064
5064
|
partialsDir: "partials",
|
|
5065
5065
|
componentsDir: "components",
|
|
5066
|
-
layoutsDir: "layouts"
|
|
5066
|
+
layoutsDir: "layouts",
|
|
5067
|
+
ssr: true,
|
|
5068
|
+
defaultTitle: "stx App"
|
|
5067
5069
|
};
|
|
5068
5070
|
async function serve(options) {
|
|
5069
5071
|
const stxConfig = await loadConfig5({
|
|
@@ -5143,9 +5145,8 @@ After installing: bun add bun-plugin-stx`);
|
|
|
5143
5145
|
return crosswindModule;
|
|
5144
5146
|
crosswindLoadAttempted = true;
|
|
5145
5147
|
try {
|
|
5146
|
-
const mod = await import("
|
|
5148
|
+
const mod = await import("./chunk-fj6fej0j.js");
|
|
5147
5149
|
crosswindModule = { CSSGenerator: mod.CSSGenerator, config: mod.config };
|
|
5148
|
-
console.log("\u2705 Crosswind CSS engine loaded");
|
|
5149
5150
|
return crosswindModule;
|
|
5150
5151
|
} catch {
|
|
5151
5152
|
try {
|
|
@@ -5153,10 +5154,8 @@ After installing: bun add bun-plugin-stx`);
|
|
|
5153
5154
|
const localPath = nodePath.join(process13.env.HOME || "", "Code/Tools/crosswind/packages/crosswind/src/index.ts");
|
|
5154
5155
|
const mod = await import(localPath);
|
|
5155
5156
|
crosswindModule = { CSSGenerator: mod.CSSGenerator, config: mod.config };
|
|
5156
|
-
console.log("\u2705 Crosswind CSS engine loaded from local path");
|
|
5157
5157
|
return crosswindModule;
|
|
5158
5158
|
} catch {
|
|
5159
|
-
console.warn("\u26A0\uFE0F Crosswind CSS engine not available");
|
|
5160
5159
|
return null;
|
|
5161
5160
|
}
|
|
5162
5161
|
}
|
|
@@ -5191,25 +5190,59 @@ After installing: bun add bun-plugin-stx`);
|
|
|
5191
5190
|
async function processTemplate(filePath) {
|
|
5192
5191
|
const path = await import("path");
|
|
5193
5192
|
const content = await Bun.file(filePath).text();
|
|
5194
|
-
const
|
|
5195
|
-
const
|
|
5196
|
-
const
|
|
5193
|
+
const scriptRegex = /<script\b([^>]*)>([\s\S]*?)<\/script>/gi;
|
|
5194
|
+
const clientScripts = [];
|
|
5195
|
+
const serverScripts = [];
|
|
5196
|
+
let scriptMatch;
|
|
5197
|
+
while ((scriptMatch = scriptRegex.exec(content)) !== null) {
|
|
5198
|
+
const attrs = scriptMatch[1];
|
|
5199
|
+
const scriptBody = scriptMatch[2];
|
|
5200
|
+
const fullScript = scriptMatch[0];
|
|
5201
|
+
const isClientScript = attrs.includes("client") || attrs.includes('type="module"') || attrs.includes("src=");
|
|
5202
|
+
if (isClientScript) {
|
|
5203
|
+
clientScripts.push(fullScript);
|
|
5204
|
+
} else {
|
|
5205
|
+
serverScripts.push(scriptBody);
|
|
5206
|
+
}
|
|
5207
|
+
}
|
|
5208
|
+
let templateContent = content.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "");
|
|
5197
5209
|
const context = {
|
|
5198
5210
|
__filename: filePath,
|
|
5199
5211
|
__dirname: path.dirname(filePath)
|
|
5200
5212
|
};
|
|
5201
|
-
const { processDirectives, extractVariables, defaultConfig: defaultConfig3 } = await import("@stacksjs/stx");
|
|
5202
|
-
|
|
5213
|
+
const { processDirectives, extractVariables, defaultConfig: defaultConfig3, generateSpaShell, injectRouterScript } = await import("@stacksjs/stx");
|
|
5214
|
+
for (const scriptBody of serverScripts) {
|
|
5215
|
+
await extractVariables(scriptBody, context, filePath);
|
|
5216
|
+
}
|
|
5203
5217
|
const config3 = {
|
|
5204
5218
|
...defaultConfig3,
|
|
5205
5219
|
...componentsDir && { componentsDir },
|
|
5206
5220
|
...layoutsDir && { layoutsDir },
|
|
5207
5221
|
...partialsDir && { partialsDir }
|
|
5208
5222
|
};
|
|
5223
|
+
if (config3.ssr === false || stxConfig.ssr === false) {
|
|
5224
|
+
return generateSpaShell({
|
|
5225
|
+
template: templateContent,
|
|
5226
|
+
context,
|
|
5227
|
+
title: stxConfig.defaultTitle ?? "stx App"
|
|
5228
|
+
});
|
|
5229
|
+
}
|
|
5209
5230
|
let output = templateContent;
|
|
5210
5231
|
const dependencies = new Set;
|
|
5211
5232
|
output = await processDirectives(output, context, filePath, config3, dependencies);
|
|
5212
|
-
output = output
|
|
5233
|
+
output = injectRouterScript(output);
|
|
5234
|
+
const hasDirectiveTemplates = /<template\s[^>]*(?:@for|:for|@if|:if)/.test(output);
|
|
5235
|
+
if (hasDirectiveTemplates) {
|
|
5236
|
+
output = output.replace(/<template(?:\s[^>]*)?>|<\/template>/gi, (match) => {
|
|
5237
|
+
if (/@for|:for|@if|:if/.test(match))
|
|
5238
|
+
return match;
|
|
5239
|
+
if (match === "</template>")
|
|
5240
|
+
return match;
|
|
5241
|
+
return "";
|
|
5242
|
+
});
|
|
5243
|
+
} else {
|
|
5244
|
+
output = output.replace(/<template[^>]*>/gi, "").replace(/<\/template>/gi, "");
|
|
5245
|
+
}
|
|
5213
5246
|
const crosswindCSS = await generateCrosswindCSS(output);
|
|
5214
5247
|
if (crosswindCSS) {
|
|
5215
5248
|
const styleTag = `<style>/* crosswind css */
|
|
@@ -5267,7 +5300,7 @@ ${crosswindCSS}</style>`;
|
|
|
5267
5300
|
let relativeFilePath = normalizedFilePath;
|
|
5268
5301
|
for (const pattern of patterns) {
|
|
5269
5302
|
const normalizedPattern = pattern.replace(/\\/g, "/").replace(/\/$/, "");
|
|
5270
|
-
if (normalizedFilePath.startsWith(normalizedPattern
|
|
5303
|
+
if (normalizedFilePath.startsWith(`${normalizedPattern}/`)) {
|
|
5271
5304
|
relativeFilePath = normalizedFilePath.slice(normalizedPattern.length + 1);
|
|
5272
5305
|
break;
|
|
5273
5306
|
}
|
|
@@ -5296,7 +5329,7 @@ ${crosswindCSS}</style>`;
|
|
|
5296
5329
|
let relativeFilePath = normalizedFilePath;
|
|
5297
5330
|
for (const pattern of patterns) {
|
|
5298
5331
|
const normalizedPattern = pattern.replace(/\\/g, "/").replace(/\/$/, "");
|
|
5299
|
-
if (normalizedFilePath.startsWith(normalizedPattern
|
|
5332
|
+
if (normalizedFilePath.startsWith(`${normalizedPattern}/`)) {
|
|
5300
5333
|
relativeFilePath = normalizedFilePath.slice(normalizedPattern.length + 1);
|
|
5301
5334
|
break;
|
|
5302
5335
|
}
|
|
@@ -5326,9 +5359,22 @@ ${crosswindCSS}</style>`;
|
|
|
5326
5359
|
async function processTemplateDynamic(filePath, paramNames, paramValues, routePath) {
|
|
5327
5360
|
const path = await import("path");
|
|
5328
5361
|
const content = await Bun.file(filePath).text();
|
|
5329
|
-
const
|
|
5330
|
-
const
|
|
5331
|
-
const
|
|
5362
|
+
const dynScriptRegex = /<script\b([^>]*)>([\s\S]*?)<\/script>/gi;
|
|
5363
|
+
const dynClientScripts = [];
|
|
5364
|
+
const dynServerScripts = [];
|
|
5365
|
+
let dynScriptMatch;
|
|
5366
|
+
while ((dynScriptMatch = dynScriptRegex.exec(content)) !== null) {
|
|
5367
|
+
const attrs = dynScriptMatch[1];
|
|
5368
|
+
const scriptBody = dynScriptMatch[2];
|
|
5369
|
+
const fullScript = dynScriptMatch[0];
|
|
5370
|
+
const isClientScript = attrs.includes("client") || attrs.includes('type="module"') || attrs.includes("src=");
|
|
5371
|
+
if (isClientScript) {
|
|
5372
|
+
dynClientScripts.push(fullScript);
|
|
5373
|
+
} else {
|
|
5374
|
+
dynServerScripts.push(scriptBody);
|
|
5375
|
+
}
|
|
5376
|
+
}
|
|
5377
|
+
const templateContent = content.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "");
|
|
5332
5378
|
const context = {
|
|
5333
5379
|
__filename: filePath,
|
|
5334
5380
|
__dirname: path.dirname(filePath),
|
|
@@ -5337,8 +5383,10 @@ ${crosswindCSS}</style>`;
|
|
|
5337
5383
|
for (let i = 0;i < paramNames.length; i++) {
|
|
5338
5384
|
context[paramNames[i]] = paramValues[i];
|
|
5339
5385
|
}
|
|
5340
|
-
const { processDirectives, extractVariables, defaultConfig: defaultConfig3 } = await import("@stacksjs/stx");
|
|
5341
|
-
|
|
5386
|
+
const { processDirectives, extractVariables, defaultConfig: defaultConfig3, injectRouterScript: injectRouter } = await import("@stacksjs/stx");
|
|
5387
|
+
for (const scriptBody of dynServerScripts) {
|
|
5388
|
+
await extractVariables(scriptBody, context, filePath);
|
|
5389
|
+
}
|
|
5342
5390
|
const config3 = {
|
|
5343
5391
|
...defaultConfig3,
|
|
5344
5392
|
...componentsDir && { componentsDir },
|
|
@@ -5348,6 +5396,7 @@ ${crosswindCSS}</style>`;
|
|
|
5348
5396
|
let output = templateContent;
|
|
5349
5397
|
const dependencies = new Set;
|
|
5350
5398
|
output = await processDirectives(output, context, filePath, config3, dependencies);
|
|
5399
|
+
output = injectRouter(output);
|
|
5351
5400
|
output = output.replace(/<template[^>]*>/gi, "").replace(/<\/template>/gi, "");
|
|
5352
5401
|
const crosswindCSS = await generateCrosswindCSS(output);
|
|
5353
5402
|
if (crosswindCSS) {
|
|
@@ -5365,9 +5414,8 @@ ${crosswindCSS}</style>`;
|
|
|
5365
5414
|
}
|
|
5366
5415
|
return output;
|
|
5367
5416
|
}
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
`);
|
|
5417
|
+
if (!options.quiet)
|
|
5418
|
+
console.log(` \u2713 Frontend running at http://localhost:${port}`);
|
|
5371
5419
|
const corsHeaders = {
|
|
5372
5420
|
"Access-Control-Allow-Origin": "*",
|
|
5373
5421
|
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
|
|
@@ -5381,6 +5429,17 @@ ${crosswindCSS}</style>`;
|
|
|
5381
5429
|
if (req.method === "OPTIONS") {
|
|
5382
5430
|
return new Response(null, { headers: corsHeaders });
|
|
5383
5431
|
}
|
|
5432
|
+
if (options.onRequest) {
|
|
5433
|
+
const customResponse = await options.onRequest(req);
|
|
5434
|
+
if (customResponse)
|
|
5435
|
+
return customResponse;
|
|
5436
|
+
}
|
|
5437
|
+
if (options.routes) {
|
|
5438
|
+
const routeHandler = options.routes[path];
|
|
5439
|
+
if (routeHandler) {
|
|
5440
|
+
return routeHandler(req);
|
|
5441
|
+
}
|
|
5442
|
+
}
|
|
5384
5443
|
if (path.startsWith("/api/data/") && req.method === "POST") {
|
|
5385
5444
|
try {
|
|
5386
5445
|
const tableName = path.replace("/api/data/", "").split("/")[0];
|
|
@@ -5581,7 +5640,7 @@ ${crosswindCSS}</style>`;
|
|
|
5581
5640
|
let normalizedPath = filePath.replace(/^\.\//, "").replace(/\\/g, "/");
|
|
5582
5641
|
for (const pattern of patterns) {
|
|
5583
5642
|
const normalizedPattern = pattern.replace(/\\/g, "/").replace(/\/$/, "");
|
|
5584
|
-
if (normalizedPath.startsWith(normalizedPattern
|
|
5643
|
+
if (normalizedPath.startsWith(`${normalizedPattern}/`)) {
|
|
5585
5644
|
normalizedPath = normalizedPath.slice(normalizedPattern.length + 1);
|
|
5586
5645
|
break;
|
|
5587
5646
|
}
|
package/dist/watch.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bun-plugin-stx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.8",
|
|
5
5
|
"description": "A Bun plugin that allows for using Laravel Blade-like syntax.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -25,20 +25,25 @@
|
|
|
25
25
|
],
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
28
|
+
"bun": "./src/index.ts",
|
|
28
29
|
"types": "./dist/index.d.ts",
|
|
29
30
|
"import": "./dist/index.js"
|
|
30
31
|
},
|
|
31
32
|
"./client": {
|
|
33
|
+
"bun": "./src/client.ts",
|
|
32
34
|
"types": "./dist/client.d.ts",
|
|
33
35
|
"import": "./dist/client.js"
|
|
34
36
|
},
|
|
35
37
|
"./preload": {
|
|
38
|
+
"bun": "./src/preload.ts",
|
|
36
39
|
"import": "./dist/preload.js"
|
|
37
40
|
},
|
|
38
41
|
"./serve": {
|
|
42
|
+
"bun": "./src/serve.ts",
|
|
39
43
|
"import": "./dist/serve.js"
|
|
40
44
|
},
|
|
41
45
|
"./*": {
|
|
46
|
+
"bun": "./src/*",
|
|
42
47
|
"import": "./dist/*"
|
|
43
48
|
}
|
|
44
49
|
},
|
|
@@ -67,6 +72,6 @@
|
|
|
67
72
|
"typecheck": "bun tsc --noEmit"
|
|
68
73
|
},
|
|
69
74
|
"dependencies": {
|
|
70
|
-
"@stacksjs/stx": "0.2.
|
|
75
|
+
"@stacksjs/stx": "0.2.8"
|
|
71
76
|
}
|
|
72
77
|
}
|
|
File without changes
|