@stacksjs/actions 0.70.294 → 0.70.297

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.
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Resolve the framework's default resources root — the fallback views, layouts
3
+ * and components a server renders under an app's own.
4
+ *
5
+ * A vendored checkout keeps them at `storage/framework/defaults/resources` and
6
+ * wins, so a full framework checkout behaves exactly as before. An app that
7
+ * consumes the framework from node_modules has no vendored copy — that directory
8
+ * is generated and gitignored, so `git ls-files storage/framework` is empty on a
9
+ * fresh clone — and must resolve the published `@stacksjs/defaults` package
10
+ * instead. Without this fallback the dev server pointed every default at a path
11
+ * that does not exist until `buddy setup` has run (stacksjs/stacks#2240).
12
+ *
13
+ * The production server (core/buddy's production-server.ts) already resolved it
14
+ * this way; the dev server still had the bare path. This is the shared shape —
15
+ * import it from both rather than keep two copies that can drift.
16
+ *
17
+ * Returns the vendored path if neither resolves, letting the caller (stx serve)
18
+ * surface a clear missing-directory error rather than a silent empty glob.
19
+ */
20
+ export declare function resolveDefaultsResources(): string;
@@ -0,0 +1 @@
1
+ import{existsSync}from"node:fs";import{dirname,join}from"node:path";export function resolveDefaultsResources(){const vendored="storage/framework/defaults/resources";if(existsSync(vendored))return vendored;try{const pkgJson=Bun.resolveSync("@stacksjs/defaults/package.json",process.cwd());return join(dirname(pkgJson),"resources")}catch{return vendored}}
package/dist/dev/views.js CHANGED
@@ -1 +1 @@
1
- import{AsyncLocalStorage}from"node:async_hooks";import{existsSync}from"node:fs";import{config,overridesReady}from"@stacksjs/config";import{projectPath}from"@stacksjs/path";import{seedCsrfPageResponse}from"./csrf";import{exitWithParent}from"./exit-with-parent";const requestStore=new AsyncLocalStorage;function currentRequestContext(){return requestStore.getStore()??globalThis.__stxServeContext}globalThis.requestContext={cookie(name){return currentRequestContext()?.cookies?.[name]??null},url(){return currentRequestContext()?.url??""},search(){const url=currentRequestContext()?.url;if(!url)return"";const mark=url.indexOf("?");return mark===-1?"":url.slice(mark)},locale(){return currentRequestContext()?.locale??"en"}};exitWithParent();const projectServe=projectPath("serve.ts");try{if(await Bun.file(projectServe).exists())await import(projectServe);else await startDefaultServer()}catch{await startDefaultServer()}function parseCookies(req){const out={},header=req.headers.get("cookie")||"";if(!header)return out;for(const part of header.split(";")){const trimmed=part.trim(),eq=trimmed.indexOf("=");if(eq===-1)continue;const k=trimmed.slice(0,eq).trim(),v=trimmed.slice(eq+1).trim();if(!k)continue;try{out[k]=decodeURIComponent(v)}catch{out[k]=v}}return out}async function startDefaultServer(){await overridesReady;const{injectGlobalAutoImports,isApiBoundRequest,proxyToBackend}=await import("@stacksjs/server"),{applyRequestLocale}=await import("@stacksjs/i18n");await injectGlobalAutoImports();const{serve}=await import("bun-plugin-stx/serve"),{site:siteConfig,i18n:i18nConfig}=await loadStxSiteConfig(),userViewsPath="resources/views",defaultViewsPath="storage/framework/defaults/resources/views",userLayoutsPath=await firstExistingPath(["resources/views/layouts","resources/layouts"])??"resources/views/layouts",defaultLayoutsPath="storage/framework/defaults/resources/layouts",userPartialsPath=await firstExistingPath(["resources/partials","resources/views/partials","partials","resources/components"]),preferredPort=Number(process.env.PORT)||3000,apiPort=Number(process.env.PORT_API)||3008,docsPort=Number(process.env.PORT_DOCS)||config.ports?.docs||3006,apiBase=`http://127.0.0.1:${apiPort}`,docsBase=`http://127.0.0.1:${docsPort}`,hasUserDocsView=["docs.stx","docs/index.stx"].some((rel)=>existsSync(projectPath(`${userViewsPath}/${rel}`))),hasDocsSite=existsSync(projectPath("docs")),docsProxyEnabled=!hasUserDocsView&&hasDocsSite,authCookie=config?.auth?.defaultTokenName??"auth-token";await serve({patterns:[userViewsPath,defaultViewsPath],port:preferredPort,componentsDir:"storage/framework/defaults/resources/components",layoutsDir:userLayoutsPath,...userPartialsPath&&{partialsDir:userPartialsPath},fallbackLayoutsDir:defaultLayoutsPath,fallbackPartialsDir:defaultViewsPath,quiet:!0,openPath:process.env.STACKS_DEV_ENTRY_PATH||"/",...i18nConfig&&{i18n:i18nConfig},...siteConfig?.url&&{site:siteConfig},auth:{cookieName:authCookie,redirectTo:"/login"},onRequest:async(req)=>{const url=new URL(req.url),{maintenanceGate}=await import("@stacksjs/server"),gated=await maintenanceGate(req);if(gated)return gated;if(existsSync(projectPath("resources/views/blog.stx"))){const{renderBlogFeed}=await import("../blog"),feed=await renderBlogFeed(req);if(feed)return feed}else{const{renderBlog}=await import("../blog"),blogResponse=await renderBlog(req);if(blogResponse)return blogResponse}if(docsProxyEnabled&&(url.pathname==="/docs"||url.pathname.startsWith("/docs/")))return proxyToBackend(req,docsBase,"/docs");if(isApiBoundRequest(req,url.pathname))return proxyToBackend(req,apiBase);if(i18nConfig&&req.method==="GET"){const localeSwitch=url.pathname.match(/^\/locale\/([a-z]{2}(?:-[a-z]{2})?)\/?$/i);if(localeSwitch){const{createLocaleSwitchResponse}=await import("@stacksjs/i18n");return createLocaleSwitchResponse(req,localeSwitch[1],i18nConfig)}}const locale=await applyRequestLocale(req),ctx={cookies:parseCookies(req),url:req.url,locale};globalThis.__stxServeSearch=url.search;globalThis.__stxServeContext=ctx;requestStore.enterWith(ctx);return null},onResponse:seedCsrfPageResponse})}async function firstExistingPath(candidates){const existing=candidates.filter((candidate)=>existsSync(projectPath(candidate)));if(existing.length===0)return null;for(const candidate of existing)if(containsTemplates(projectPath(candidate)))return candidate;return existing[0]}function containsTemplates(dir){try{return[...new Bun.Glob("**/*.stx").scanSync({cwd:dir,onlyFiles:!0})].length>0}catch{return!1}}function fallbackI18nFromSite(site){const locales=site.i18n.locales,defaultLocale=site.i18n.defaultLocale??locales[0];return{locales,defaultLocale,labels:site.i18n.labels??Object.fromEntries(locales.map((c)=>[c,c.toUpperCase()])),translations:{},pickerSelector:site.i18n.pickerSelector??"#lang-picker"}}async function resolveSiteI18n(site){try{const{resolveI18n}=await import("@stacksjs/stx");if(typeof resolveI18n==="function"){const i18n=resolveI18n(site,projectPath());if(i18n)return i18n}}catch{}return fallbackI18nFromSite(site)}async function loadStxSiteConfig(){const sitePath=projectPath("site.config.ts");if(!existsSync(sitePath))return{};try{const site=(await import(sitePath)).default;if(!site)return{};if(!site.i18n)return{site};const i18n=await resolveSiteI18n(site);return{site,i18n}}catch{}return{}}
1
+ import{AsyncLocalStorage}from"node:async_hooks";import{existsSync}from"node:fs";import{join}from"node:path";import{config,installRequestContext,overridesReady,parseCookieHeader,resolveViewPatterns}from"@stacksjs/config";import{log}from"@stacksjs/logging";import{projectPath}from"@stacksjs/path";import{seedCsrfPageResponse}from"./csrf";import{resolveDefaultsResources}from"./defaults-resources";import{exitWithParent}from"./exit-with-parent";const requestStore=new AsyncLocalStorage;function currentRequestContext(){return requestStore.getStore()??globalThis.__stxServeContext}installRequestContext(currentRequestContext);exitWithParent();const projectServe=projectPath("serve.ts");try{if(await Bun.file(projectServe).exists())await import(projectServe);else await startDefaultServer()}catch{await startDefaultServer()}function parseCookies(req){return parseCookieHeader(req.headers.get("cookie"))}async function startDefaultServer(){await overridesReady;const{describeApiProxyRules,injectGlobalAutoImports,isApiBoundRequest,proxyToBackend,resolveApiProxyRules}=await import("@stacksjs/server"),{applyRequestLocale}=await import("@stacksjs/i18n");await injectGlobalAutoImports();const{serve}=await import("bun-plugin-stx/serve"),{site:siteConfig,i18n:i18nConfig}=await loadStxSiteConfig(),defaultsResources=resolveDefaultsResources(),userViewsPath="resources/views",defaultViewsPath=join(defaultsResources,"views"),userLayoutsPath=await firstExistingPath(["resources/views/layouts","resources/layouts"])??"resources/views/layouts",defaultLayoutsPath=join(defaultsResources,"layouts"),userPartialsPath=await firstExistingPath(["resources/partials","resources/views/partials","partials","resources/components"]),preferredPort=Number(process.env.PORT)||3000,apiPort=Number(process.env.PORT_API)||3008,docsPort=Number(process.env.PORT_DOCS)||config.ports?.docs||3006,apiBase=`http://127.0.0.1:${apiPort}`,docsBase=`http://127.0.0.1:${docsPort}`,apiProxyRules=resolveApiProxyRules(config.server?.proxy);if(apiProxyRules.paths.length>0||apiProxyRules.prefixes.length>1)console.log(` API proxy: ${describeApiProxyRules(apiProxyRules)}`);const hasUserDocsView=["docs.stx","docs/index.stx"].some((rel)=>existsSync(projectPath(`${userViewsPath}/${rel}`))),hasDocsSite=existsSync(projectPath("docs")),docsProxyEnabled=!hasUserDocsView&&hasDocsSite,{authCookieName,stxPageAuthMiddleware}=await import("@stacksjs/auth"),authCookie=authCookieName(),viewPatterns=resolveViewPatterns(userViewsPath,defaultViewsPath,config?.ui?.defaultViews,(path)=>existsSync(projectPath(path)));for(const name of viewPatterns.missing)log.warn(`ui.defaultViews lists "${name}", which does not exist under ${defaultViewsPath} \u2014 ignoring.`);await serve({patterns:viewPatterns.patterns,port:preferredPort,componentsDir:join(defaultsResources,"components"),layoutsDir:userLayoutsPath,...userPartialsPath&&{partialsDir:userPartialsPath},fallbackLayoutsDir:defaultLayoutsPath,fallbackPartialsDir:defaultViewsPath,quiet:!0,openPath:process.env.STACKS_DEV_ENTRY_PATH||"/",...i18nConfig&&{i18n:i18nConfig},...siteConfig?.url&&{site:siteConfig},auth:{cookieName:authCookie,redirectTo:"/login"},middleware:stxPageAuthMiddleware({cookieName:authCookie,redirectTo:"/login"}),onRequest:async(req)=>{const url=new URL(req.url),{maintenanceGate}=await import("@stacksjs/server"),gated=await maintenanceGate(req);if(gated)return gated;if(existsSync(projectPath("resources/views/blog.stx"))){const{renderBlogFeed}=await import("../blog"),feed=await renderBlogFeed(req);if(feed)return feed}else{const{renderBlog}=await import("../blog"),blogResponse=await renderBlog(req);if(blogResponse)return blogResponse}if(docsProxyEnabled&&(url.pathname==="/docs"||url.pathname.startsWith("/docs/")))return proxyToBackend(req,docsBase,"/docs");if(isApiBoundRequest(req,url.pathname,apiProxyRules))return proxyToBackend(req,apiBase);if(i18nConfig&&req.method==="GET"){const localeSwitch=url.pathname.match(/^\/locale\/([a-z]{2}(?:-[a-z]{2})?)\/?$/i);if(localeSwitch){const{createLocaleSwitchResponse}=await import("@stacksjs/i18n");return createLocaleSwitchResponse(req,localeSwitch[1],i18nConfig)}}const locale=await applyRequestLocale(req),ctx={cookies:parseCookies(req),url:req.url,path:url.pathname,search:url.search,host:url.host,locale};globalThis.__stxServeSearch=url.search;globalThis.__stxServeContext=ctx;requestStore.enterWith(ctx);return null},onResponse:seedCsrfPageResponse})}async function firstExistingPath(candidates){const existing=candidates.filter((candidate)=>existsSync(projectPath(candidate)));if(existing.length===0)return null;for(const candidate of existing)if(containsTemplates(projectPath(candidate)))return candidate;return existing[0]}function containsTemplates(dir){try{return[...new Bun.Glob("**/*.stx").scanSync({cwd:dir,onlyFiles:!0})].length>0}catch{return!1}}function fallbackI18nFromSite(site){const locales=site.i18n.locales,defaultLocale=site.i18n.defaultLocale??locales[0];return{locales,defaultLocale,labels:site.i18n.labels??Object.fromEntries(locales.map((c)=>[c,c.toUpperCase()])),translations:{},pickerSelector:site.i18n.pickerSelector??"#lang-picker"}}async function resolveSiteI18n(site){try{const{resolveI18n}=await import("@stacksjs/stx");if(typeof resolveI18n==="function"){const i18n=resolveI18n(site,projectPath());if(i18n)return i18n}}catch{}return fallbackI18nFromSite(site)}async function loadStxSiteConfig(){const sitePath=projectPath("site.config.ts");if(!existsSync(sitePath))return{};try{const site=(await import(sitePath)).default;if(!site)return{};if(!site.i18n)return{site};const i18n=await resolveSiteI18n(site);return{site,i18n}}catch{}return{}}
@@ -1 +1 @@
1
- import process from"node:process";import{log}from"@stacksjs/logging";import{startProcessor,stopProcessor}from"@stacksjs/queue";process.on("unhandledRejection",(reason)=>{log.error(`Unhandled Rejection in queue worker: ${reason}`)});process.on("uncaughtException",(error)=>{log.error(`Uncaught Exception in queue worker: ${error.message}`)});const SHUTDOWN_GRACE_MS=Number(process.env.STACKS_QUEUE_SHUTDOWN_GRACE_MS)||1e4;let shuttingDown=!1;async function gracefulShutdown(signal){if(shuttingDown)return;shuttingDown=!0;log.info(`[queue] Worker received ${signal}, draining in-flight jobs (max ${SHUTDOWN_GRACE_MS/1000}s)\u2026`);setTimeout(()=>{log.warn("[queue] Drain window exceeded \u2014 forcing worker exit.");process.exit(1)},SHUTDOWN_GRACE_MS+2000).unref();try{await stopProcessor({graceMs:SHUTDOWN_GRACE_MS})}catch(error){log.error("[queue] Error while draining worker on shutdown:",error)}process.exit(0)}process.on("SIGTERM",()=>{gracefulShutdown("SIGTERM")});process.on("SIGINT",()=>{gracefulShutdown("SIGINT")});const options=parseArgs(),queue=options.queue,concurrency=Number(options.concurrency)||1;log.info(`Starting queue worker with ${concurrency} concurrent worker(s)...`);const result=await startProcessor(queue,{concurrency});if(result.isErr){log.error("Failed to start queue worker:",result.error);process.exit(1)}log.success("Queue worker started successfully!");await new Promise(()=>{});function parseArgs(){const args={};process.argv.forEach((arg)=>{if(arg.startsWith("--")){const[key,value]=arg.slice(2).split("=");if(key&&value)args[key]=value;else if(key)args[key]="true"}});return args}
1
+ import process from"node:process";import{log}from"@stacksjs/logging";import{startProcessor,stopProcessor}from"@stacksjs/queue";process.on("unhandledRejection",(reason)=>{log.error(`Unhandled Rejection in queue worker: ${reason}`)});process.on("uncaughtException",(error)=>{log.error(`Uncaught Exception in queue worker: ${error.message}`)});const SHUTDOWN_GRACE_MS=Number(process.env.STACKS_QUEUE_SHUTDOWN_GRACE_MS)||1e4;let shuttingDown=!1;async function gracefulShutdown(signal){if(shuttingDown)return;shuttingDown=!0;log.info(`[queue] Worker received ${signal}, draining in-flight jobs (max ${SHUTDOWN_GRACE_MS/1000}s)\u2026`);setTimeout(()=>{log.warn("[queue] Drain window exceeded \u2014 forcing worker exit.");process.exit(1)},SHUTDOWN_GRACE_MS+2000).unref();try{await stopProcessor({graceMs:SHUTDOWN_GRACE_MS})}catch(error){log.error("[queue] Error while draining worker on shutdown:",error)}process.exit(0)}process.on("SIGTERM",()=>{gracefulShutdown("SIGTERM")});process.on("SIGINT",()=>{gracefulShutdown("SIGINT")});const options=parseArgs(),queue=options.queue,concurrency=Number(options.concurrency)||1;log.info(`Starting queue worker with ${concurrency} concurrent worker(s)...`);const result=await startProcessor(queue,{concurrency});if(result.isErr){log.error("Failed to start queue worker:",result.error);process.exit(1)}log.success("Queue worker started successfully!");await new Promise(()=>{});function parseArgs(){const args={},argv=process.argv;for(let index=0;index<argv.length;index++){const arg=argv[index];if(!arg?.startsWith("--"))continue;const[key,inline]=arg.slice(2).split("=");if(!key)continue;if(inline!==void 0){args[key]=inline;continue}const next=argv[index+1];if(next!==void 0&&!next.startsWith("-")){args[key]=next;index++;continue}args[key]="true"}return args}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/actions",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.70.294",
5
+ "version": "0.70.297",
6
6
  "description": "The Stacks actions.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -59,33 +59,33 @@
59
59
  "prepublishOnly": "bun run build"
60
60
  },
61
61
  "dependencies": {
62
- "@stacksjs/config": "0.70.294",
62
+ "@stacksjs/config": "0.70.297",
63
63
  "@stacksjs/bumpx": "^0.2.6",
64
64
  "@stacksjs/bunpress": "^0.1.18",
65
65
  "@stacksjs/logsmith": "^0.2.3",
66
- "@stacksjs/registry": "0.70.294",
66
+ "@stacksjs/registry": "0.70.297",
67
67
  "@stacksjs/stx": "^0.2.148",
68
68
  "@stacksjs/ts-cloud": "^0.7.103",
69
69
  "@stacksjs/ts-md": "^0.1.1"
70
70
  },
71
71
  "devDependencies": {
72
- "@stacksjs/api": "0.70.294",
73
- "@stacksjs/cli": "0.70.294",
74
- "@stacksjs/database": "0.70.294",
72
+ "@stacksjs/api": "0.70.297",
73
+ "@stacksjs/cli": "0.70.297",
74
+ "@stacksjs/database": "0.70.297",
75
75
  "@stacksjs/tlsx": "^0.13.2",
76
76
  "better-dx": "^0.2.17",
77
- "@stacksjs/dns": "0.70.294",
78
- "@stacksjs/enums": "0.70.294",
79
- "@stacksjs/env": "0.70.294",
80
- "@stacksjs/error-handling": "0.70.294",
81
- "@stacksjs/image": "0.70.294",
82
- "@stacksjs/logging": "0.70.294",
83
- "@stacksjs/path": "0.70.294",
84
- "@stacksjs/security": "0.70.294",
85
- "@stacksjs/storage": "0.70.294",
86
- "@stacksjs/strings": "0.70.294",
87
- "@stacksjs/utils": "0.70.294",
88
- "@stacksjs/validation": "0.70.294"
77
+ "@stacksjs/dns": "0.70.297",
78
+ "@stacksjs/enums": "0.70.297",
79
+ "@stacksjs/env": "0.70.297",
80
+ "@stacksjs/error-handling": "0.70.297",
81
+ "@stacksjs/image": "0.70.297",
82
+ "@stacksjs/logging": "0.70.297",
83
+ "@stacksjs/path": "0.70.297",
84
+ "@stacksjs/security": "0.70.297",
85
+ "@stacksjs/storage": "0.70.297",
86
+ "@stacksjs/strings": "0.70.297",
87
+ "@stacksjs/utils": "0.70.297",
88
+ "@stacksjs/validation": "0.70.297"
89
89
  },
90
90
  "peerDependencies": {
91
91
  "pickier": "^0.1.35"