bun-plugin-stx 0.2.6 → 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-j0k3wkwg.js → chunk-a3qganyh.js} +13 -1
- package/dist/chunk-fj6fej0j.js +12771 -0
- package/dist/client.js +1 -1
- package/dist/index.js +2 -2
- package/dist/preload.js +2 -2
- package/dist/serve.d.ts +3 -0
- package/dist/serve.js +57 -18
- package/package.json +7 -2
- /package/dist/{chunk-eecw9x2f.js → chunk-2mx7fq49.js} +0 -0
package/dist/client.js
CHANGED
package/dist/index.js
CHANGED
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
|
+
quiet?: boolean
|
|
13
|
+
routes?: Record<string, (req: Request) => Response | Promise<Response>>
|
|
14
|
+
onRequest?: (req: Request) => Response | Promise<Response> | null | undefined
|
|
12
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;
|
|
@@ -5145,9 +5145,8 @@ After installing: bun add bun-plugin-stx`);
|
|
|
5145
5145
|
return crosswindModule;
|
|
5146
5146
|
crosswindLoadAttempted = true;
|
|
5147
5147
|
try {
|
|
5148
|
-
const mod = await import("
|
|
5148
|
+
const mod = await import("./chunk-fj6fej0j.js");
|
|
5149
5149
|
crosswindModule = { CSSGenerator: mod.CSSGenerator, config: mod.config };
|
|
5150
|
-
console.log("\u2705 Crosswind CSS engine loaded");
|
|
5151
5150
|
return crosswindModule;
|
|
5152
5151
|
} catch {
|
|
5153
5152
|
try {
|
|
@@ -5155,10 +5154,8 @@ After installing: bun add bun-plugin-stx`);
|
|
|
5155
5154
|
const localPath = nodePath.join(process13.env.HOME || "", "Code/Tools/crosswind/packages/crosswind/src/index.ts");
|
|
5156
5155
|
const mod = await import(localPath);
|
|
5157
5156
|
crosswindModule = { CSSGenerator: mod.CSSGenerator, config: mod.config };
|
|
5158
|
-
console.log("\u2705 Crosswind CSS engine loaded from local path");
|
|
5159
5157
|
return crosswindModule;
|
|
5160
5158
|
} catch {
|
|
5161
|
-
console.warn("\u26A0\uFE0F Crosswind CSS engine not available");
|
|
5162
5159
|
return null;
|
|
5163
5160
|
}
|
|
5164
5161
|
}
|
|
@@ -5193,15 +5190,30 @@ After installing: bun add bun-plugin-stx`);
|
|
|
5193
5190
|
async function processTemplate(filePath) {
|
|
5194
5191
|
const path = await import("path");
|
|
5195
5192
|
const content = await Bun.file(filePath).text();
|
|
5196
|
-
const
|
|
5197
|
-
const
|
|
5198
|
-
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, "");
|
|
5199
5209
|
const context = {
|
|
5200
5210
|
__filename: filePath,
|
|
5201
5211
|
__dirname: path.dirname(filePath)
|
|
5202
5212
|
};
|
|
5203
|
-
const { processDirectives, extractVariables, defaultConfig: defaultConfig3, generateSpaShell } = await import("@stacksjs/stx");
|
|
5204
|
-
|
|
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
|
+
}
|
|
5205
5217
|
const config3 = {
|
|
5206
5218
|
...defaultConfig3,
|
|
5207
5219
|
...componentsDir && { componentsDir },
|
|
@@ -5218,6 +5230,7 @@ After installing: bun add bun-plugin-stx`);
|
|
|
5218
5230
|
let output = templateContent;
|
|
5219
5231
|
const dependencies = new Set;
|
|
5220
5232
|
output = await processDirectives(output, context, filePath, config3, dependencies);
|
|
5233
|
+
output = injectRouterScript(output);
|
|
5221
5234
|
const hasDirectiveTemplates = /<template\s[^>]*(?:@for|:for|@if|:if)/.test(output);
|
|
5222
5235
|
if (hasDirectiveTemplates) {
|
|
5223
5236
|
output = output.replace(/<template(?:\s[^>]*)?>|<\/template>/gi, (match) => {
|
|
@@ -5346,9 +5359,22 @@ ${crosswindCSS}</style>`;
|
|
|
5346
5359
|
async function processTemplateDynamic(filePath, paramNames, paramValues, routePath) {
|
|
5347
5360
|
const path = await import("path");
|
|
5348
5361
|
const content = await Bun.file(filePath).text();
|
|
5349
|
-
const
|
|
5350
|
-
const
|
|
5351
|
-
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, "");
|
|
5352
5378
|
const context = {
|
|
5353
5379
|
__filename: filePath,
|
|
5354
5380
|
__dirname: path.dirname(filePath),
|
|
@@ -5357,8 +5383,10 @@ ${crosswindCSS}</style>`;
|
|
|
5357
5383
|
for (let i = 0;i < paramNames.length; i++) {
|
|
5358
5384
|
context[paramNames[i]] = paramValues[i];
|
|
5359
5385
|
}
|
|
5360
|
-
const { processDirectives, extractVariables, defaultConfig: defaultConfig3 } = await import("@stacksjs/stx");
|
|
5361
|
-
|
|
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
|
+
}
|
|
5362
5390
|
const config3 = {
|
|
5363
5391
|
...defaultConfig3,
|
|
5364
5392
|
...componentsDir && { componentsDir },
|
|
@@ -5368,6 +5396,7 @@ ${crosswindCSS}</style>`;
|
|
|
5368
5396
|
let output = templateContent;
|
|
5369
5397
|
const dependencies = new Set;
|
|
5370
5398
|
output = await processDirectives(output, context, filePath, config3, dependencies);
|
|
5399
|
+
output = injectRouter(output);
|
|
5371
5400
|
output = output.replace(/<template[^>]*>/gi, "").replace(/<\/template>/gi, "");
|
|
5372
5401
|
const crosswindCSS = await generateCrosswindCSS(output);
|
|
5373
5402
|
if (crosswindCSS) {
|
|
@@ -5385,9 +5414,8 @@ ${crosswindCSS}</style>`;
|
|
|
5385
5414
|
}
|
|
5386
5415
|
return output;
|
|
5387
5416
|
}
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
`);
|
|
5417
|
+
if (!options.quiet)
|
|
5418
|
+
console.log(` \u2713 Frontend running at http://localhost:${port}`);
|
|
5391
5419
|
const corsHeaders = {
|
|
5392
5420
|
"Access-Control-Allow-Origin": "*",
|
|
5393
5421
|
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
|
|
@@ -5401,6 +5429,17 @@ ${crosswindCSS}</style>`;
|
|
|
5401
5429
|
if (req.method === "OPTIONS") {
|
|
5402
5430
|
return new Response(null, { headers: corsHeaders });
|
|
5403
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
|
+
}
|
|
5404
5443
|
if (path.startsWith("/api/data/") && req.method === "POST") {
|
|
5405
5444
|
try {
|
|
5406
5445
|
const tableName = path.replace("/api/data/", "").split("/")[0];
|
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
|