@stacksjs/actions 0.70.294 → 0.70.296
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}
|
|
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{}}
|
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.
|
|
5
|
+
"version": "0.70.296",
|
|
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.
|
|
62
|
+
"@stacksjs/config": "0.70.296",
|
|
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.
|
|
66
|
+
"@stacksjs/registry": "0.70.296",
|
|
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.
|
|
73
|
-
"@stacksjs/cli": "0.70.
|
|
74
|
-
"@stacksjs/database": "0.70.
|
|
72
|
+
"@stacksjs/api": "0.70.296",
|
|
73
|
+
"@stacksjs/cli": "0.70.296",
|
|
74
|
+
"@stacksjs/database": "0.70.296",
|
|
75
75
|
"@stacksjs/tlsx": "^0.13.2",
|
|
76
76
|
"better-dx": "^0.2.17",
|
|
77
|
-
"@stacksjs/dns": "0.70.
|
|
78
|
-
"@stacksjs/enums": "0.70.
|
|
79
|
-
"@stacksjs/env": "0.70.
|
|
80
|
-
"@stacksjs/error-handling": "0.70.
|
|
81
|
-
"@stacksjs/image": "0.70.
|
|
82
|
-
"@stacksjs/logging": "0.70.
|
|
83
|
-
"@stacksjs/path": "0.70.
|
|
84
|
-
"@stacksjs/security": "0.70.
|
|
85
|
-
"@stacksjs/storage": "0.70.
|
|
86
|
-
"@stacksjs/strings": "0.70.
|
|
87
|
-
"@stacksjs/utils": "0.70.
|
|
88
|
-
"@stacksjs/validation": "0.70.
|
|
77
|
+
"@stacksjs/dns": "0.70.296",
|
|
78
|
+
"@stacksjs/enums": "0.70.296",
|
|
79
|
+
"@stacksjs/env": "0.70.296",
|
|
80
|
+
"@stacksjs/error-handling": "0.70.296",
|
|
81
|
+
"@stacksjs/image": "0.70.296",
|
|
82
|
+
"@stacksjs/logging": "0.70.296",
|
|
83
|
+
"@stacksjs/path": "0.70.296",
|
|
84
|
+
"@stacksjs/security": "0.70.296",
|
|
85
|
+
"@stacksjs/storage": "0.70.296",
|
|
86
|
+
"@stacksjs/strings": "0.70.296",
|
|
87
|
+
"@stacksjs/utils": "0.70.296",
|
|
88
|
+
"@stacksjs/validation": "0.70.296"
|
|
89
89
|
},
|
|
90
90
|
"peerDependencies": {
|
|
91
91
|
"pickier": "^0.1.35"
|