@stacksjs/actions 0.75.420 → 0.75.422

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.
@@ -1,4 +1,4 @@
1
1
  import{createHash}from"node:crypto";import{existsSync,mkdirSync,readdirSync,readFileSync,writeFileSync}from"node:fs";import{dirname,join,resolve}from"node:path";import process from"node:process";import{pathToFileURL}from"node:url";import{log}from"@stacksjs/cli";import{AGENT_MANIFEST,agentHostArguments,desktopLauncherCompileArgs,macosOutputDirectory,macosScreens,renderAgentEntry,validateMacosDesktop}from"@stacksjs/desktop-build";import{projectPath,storagePath}from"@stacksjs/path";import{craftBuilderVersion}from"./craft-entry";function entryFile(entry,root){try{return entry.startsWith("file:")?new URL(entry).pathname:Bun.resolveSync(entry,root)}catch{return null}}export function craftSupportsWebkit(source){return/\.webkit\b|[{,]\s*webkit\s*[,}=]/.test(source)}function craftMacosEntry(root){if(process.env.CRAFT_MACOS_SRC)return pathToFileURL(process.env.CRAFT_MACOS_SRC).href;try{const desktop=Bun.resolveSync("@stacksjs/desktop-build/package.json",root);return pathToFileURL(Bun.resolveSync("craft-native/macos",dirname(desktop))).href}catch{return"craft-native/macos"}}function hostKey(entry,root,webkit=!1){const hash=createHash("sha256");if(webkit)hash.update("webkit");const path=entry.startsWith("file:")?new URL(entry).pathname:entry,version=craftBuilderVersion(entry,root)?.version;hash.update(version??"unversioned");if(process.env.CRAFT_MACOS_SRC||!version){const templates=join(dirname(path),"../templates");if(existsSync(templates))for(const file of readdirSync(templates).sort())hash.update(readFileSync(join(templates,file)))}return hash.digest("hex").slice(0,16)}export async function prepareMacosNative(config,options={}){const root=options.root??projectPath(),errors=validateMacosDesktop(config);if(errors.length)throw Error(`config/desktop.ts macos is not buildable:
2
2
  ${errors.map((error)=>` - ${error}`).join(`
3
- `)}`);if(process.platform!=="darwin")throw Error("The native macOS app builds on macOS");const output=macosOutputDirectory(root,config),work=join(output,".build");mkdirSync(work,{recursive:!0});const screens=Object.fromEntries(Object.entries(macosScreens(config)).map(([name,file])=>[name,join(root,file)]));for(const[name,file]of Object.entries(screens))if(!existsSync(file))throw Error(`macos.nativeScreens: screen "${name}" is ${file}, which does not exist`);const{compileNativeBundle}=await(process.env.STX_NATIVE_SRC?import(pathToFileURL(process.env.STX_NATIVE_SRC).href):import("@stacksjs/stx/native")),app=config.nativeApp?join(root,config.nativeApp):void 0,compiled=await compileNativeBundle({screens,initialScreen:config.initialScreen,minify:!0,outFile:join(work,"native-screen.js"),root,...app?{app}:{},...config.shareStorage&&Object.keys(config.shareStorage).length?{shareStorage:{...config.shareStorage}}:{}}),problems=(compiled.diagnostics??[]).filter((item)=>item.message!=="dropped-subtree: script");for(const item of problems)await log.warn(`${item.file?`${item.file}: `:""}${item.message}`);if(problems.some((item)=>item.level==="error"))throw Error("The native screens did not compile");const nativeBundle=compiled.outFile??join(work,"native-screen.js"),entry=craftMacosEntry(root),webkit=config.webkit===!0;if(webkit){const file=entryFile(entry,root);if(!file||!existsSync(file)||!craftSupportsWebkit(readFileSync(file,"utf8")))throw Error(`macos.webkit needs a Craft whose buildMacOSNative links WebKit, and ${file??entry} does not. Upgrade craft-native, or point CRAFT_MACOS_SRC at a Craft checkout that has it.`)}const key=hostKey(entry,root,webkit),hostDirectory=storagePath(`framework/desktop/host/${key}`),host=join(hostDirectory,"craft-native-macos");if(!existsSync(host)){await log.info(`Building the AppKit host${webkit?" with WebKit":""} (first build for this Craft; the toolchain installs through Pantry)`);const builder=await import(entry);mkdirSync(hostDirectory,{recursive:!0});await builder.buildMacOSNative({outdir:hostDirectory,nativeBundle,...webkit?{webkit:!0}:{}})}return{root,output,nativeBundle,host,hostKey:key}}export function macosAgentEntry(root,config){if(!config.agent)return;if(config.agent.entry){const entry=resolve(root,config.agent.entry);if(!existsSync(entry))throw Error(`macos.agent.entry does not exist: ${entry}`);return entry}const conventional=join(root,"app/Desktop/Agent.ts");return existsSync(conventional)?conventional:void 0}export function macosAgentDevManifest(config,prepared){return{appName:config.appName,bundleId:config.bundleId,version:config.version,host:prepared.host,nativeBundle:prepared.nativeBundle,hostArguments:agentHostArguments(config),...config.agent?.port?{port:config.agent.port}:{},...config.agent?.staticDir?{staticDir:resolve(prepared.root,config.agent.staticDir)}:{},projectRoot:prepared.root,appRoutes:config.agent?.appRoutes!==!1}}export async function macosAgentRouteFiles(root){const manifest=join(root,"app/Routes.ts"),loaded=existsSync(manifest)?(await import(pathToFileURL(manifest).href)).default:void 0,registry=loaded&&typeof loaded==="object"&&Object.keys(loaded).length?loaded:{api:"api"},files=[];for(const[key,definition]of Object.entries(registry)){const config=typeof definition==="string"?{path:definition}:definition,file=[".ts",".js"].map((extension)=>join(root,"routes",`${config.path}${extension}`)).find((candidate)=>existsSync(candidate));if(!file)continue;const prefix=config.prefix!==void 0?config.prefix?config.prefix.startsWith("/")?config.prefix:`/${config.prefix}`:void 0:key==="web"?void 0:`/${key}`,middleware=config.middleware===void 0?[]:Array.isArray(config.middleware)?config.middleware:[config.middleware];files.push({file,...prefix?{prefix}:{},...middleware.length?{middleware}:{}})}return files}export function macosAgentActionFiles(root,sources){const actions={};for(const source of sources){if(!existsSync(source))continue;for(const match of readFileSync(source,"utf8").matchAll(/['"`](Actions\/[\w/-]+?)(?:\.ts)?['"`]/g)){const name=match[1];if(actions[name])continue;const file=[join(root,"app",`${name}.ts`),join(root,"storage/framework/defaults/app",`${name}.ts`)].find((candidate)=>existsSync(candidate));if(file)actions[name]=file}}return actions}export async function prepareMacosAgent(config,prepared,_distribution){if(!config.agent)throw Error("config/desktop.ts has no macos.agent");const work=join(prepared.output,".build"),entry=join(work,"agent-entry.ts"),routes=config.agent.appRoutes===!1?[]:await macosAgentRouteFiles(prepared.root),agentEntry=macosAgentEntry(prepared.root,config),actions=macosAgentActionFiles(prepared.root,[...routes.map((route)=>route.file),...agentEntry?[agentEntry]:[]]);writeFileSync(entry,renderAgentEntry({agentEntry,routes,actions}));const launcher=join(work,`${config.executable}-agent`),compile=Bun.spawnSync(["bun",...desktopLauncherCompileArgs({entry,outfile:launcher})],{cwd:prepared.root,stdout:"pipe",stderr:"pipe"});if(compile.exitCode!==0)throw Error(`Compiling the agent launcher failed:
4
- ${compile.stderr.toString().trim()||compile.stdout.toString().trim()}`);return{launcher,manifest:{appName:config.appName,bundleId:config.bundleId,version:config.version,hostArguments:agentHostArguments(config),...config.agent.port?{port:config.agent.port}:{},...config.agent.staticDir?{staticDir:resolve(prepared.root,config.agent.staticDir)}:{},appRoutes:!1}}}export function macosAgentDevFiles(prepared){const work=join(prepared.output,".build");return{entry:join(work,"agent-entry.ts"),manifest:join(work,AGENT_MANIFEST)}}
3
+ `)}`);if(process.platform!=="darwin")throw Error("The native macOS app builds on macOS");const output=macosOutputDirectory(root,config),work=join(output,".build");mkdirSync(work,{recursive:!0});const screens=Object.fromEntries(Object.entries(macosScreens(config)).map(([name,file])=>[name,join(root,file)]));for(const[name,file]of Object.entries(screens))if(!existsSync(file))throw Error(`macos.nativeScreens: screen "${name}" is ${file}, which does not exist`);const{compileNativeBundle}=await(process.env.STX_NATIVE_SRC?import(pathToFileURL(process.env.STX_NATIVE_SRC).href):import("@stacksjs/stx/native")),app=config.nativeApp?join(root,config.nativeApp):void 0,compiled=await compileNativeBundle({screens,initialScreen:config.initialScreen,minify:!0,outFile:join(work,"native-screen.js"),root,...app?{app}:{},...config.shareStorage&&Object.keys(config.shareStorage).length?{shareStorage:{...config.shareStorage}}:{}}),problems=(compiled.diagnostics??[]).filter((item)=>item.message!=="dropped-subtree: script");for(const item of problems)await log.warn(`${item.file?`${item.file}: `:""}${item.message}`);if(problems.some((item)=>item.level==="error"))throw Error("The native screens did not compile");const nativeBundle=compiled.outFile??join(work,"native-screen.js"),entry=craftMacosEntry(root),webkit=config.webkit===!0;if(webkit){const file=entryFile(entry,root);if(!file||!existsSync(file)||!craftSupportsWebkit(readFileSync(file,"utf8")))throw Error(`macos.webkit needs a Craft whose buildMacOSNative links WebKit, and ${file??entry} does not. Upgrade craft-native, or point CRAFT_MACOS_SRC at a Craft checkout that has it.`)}const key=hostKey(entry,root,webkit),hostDirectory=storagePath(`framework/desktop/host/${key}`),host=join(hostDirectory,"craft-native-macos");if(!existsSync(host)){await log.info(`Building the AppKit host${webkit?" with WebKit":""} (first build for this Craft; the toolchain installs through Pantry)`);const builder=await import(entry);mkdirSync(hostDirectory,{recursive:!0});await builder.buildMacOSNative({outdir:hostDirectory,nativeBundle,...webkit?{webkit:!0}:{}})}return{root,output,nativeBundle,host,hostKey:key}}export function macosAgentEntry(root,config){if(!config.agent)return;if(config.agent.entry){const entry=resolve(root,config.agent.entry);if(!existsSync(entry))throw Error(`macos.agent.entry does not exist: ${entry}`);return entry}const conventional=join(root,"app/Desktop/Agent.ts");return existsSync(conventional)?conventional:void 0}function agentResources(config,root){const resources=config.agent?.resources;return resources&&Object.keys(resources).length?{resources:Object.fromEntries(Object.entries(resources).map(([name,path])=>[name,resolve(root,path)]))}:{}}export function macosAgentDevManifest(config,prepared){return{appName:config.appName,bundleId:config.bundleId,version:config.version,host:prepared.host,nativeBundle:prepared.nativeBundle,hostArguments:agentHostArguments(config),...config.agent?.port?{port:config.agent.port}:{},...config.agent?.staticDir?{staticDir:resolve(prepared.root,config.agent.staticDir)}:{},...agentResources(config,prepared.root),projectRoot:prepared.root,appRoutes:config.agent?.appRoutes!==!1}}export async function macosAgentRouteFiles(root){const manifest=join(root,"app/Routes.ts"),loaded=existsSync(manifest)?(await import(pathToFileURL(manifest).href)).default:void 0,registry=loaded&&typeof loaded==="object"&&Object.keys(loaded).length?loaded:{api:"api"},files=[];for(const[key,definition]of Object.entries(registry)){const config=typeof definition==="string"?{path:definition}:definition,file=[".ts",".js"].map((extension)=>join(root,"routes",`${config.path}${extension}`)).find((candidate)=>existsSync(candidate));if(!file)continue;const prefix=config.prefix!==void 0?config.prefix?config.prefix.startsWith("/")?config.prefix:`/${config.prefix}`:void 0:key==="web"?void 0:`/${key}`,middleware=config.middleware===void 0?[]:Array.isArray(config.middleware)?config.middleware:[config.middleware];files.push({file,...prefix?{prefix}:{},...middleware.length?{middleware}:{}})}return files}export function macosAgentActionFiles(root,sources){const actions={};for(const source of sources){if(!existsSync(source))continue;for(const match of readFileSync(source,"utf8").matchAll(/['"`](Actions\/[\w/-]+?)(?:\.ts)?['"`]/g)){const name=match[1];if(actions[name])continue;const file=[join(root,"app",`${name}.ts`),join(root,"storage/framework/defaults/app",`${name}.ts`)].find((candidate)=>existsSync(candidate));if(file)actions[name]=file}}return actions}export async function prepareMacosAgent(config,prepared,_distribution){if(!config.agent)throw Error("config/desktop.ts has no macos.agent");const work=join(prepared.output,".build"),entry=join(work,"agent-entry.ts"),routes=config.agent.appRoutes===!1?[]:await macosAgentRouteFiles(prepared.root),agentEntry=macosAgentEntry(prepared.root,config),actions=macosAgentActionFiles(prepared.root,[...routes.map((route)=>route.file),...agentEntry?[agentEntry]:[]]);writeFileSync(entry,renderAgentEntry({agentEntry,routes,actions}));const launcher=join(work,`${config.executable}-agent`),compile=Bun.spawnSync(["bun",...desktopLauncherCompileArgs({entry,outfile:launcher})],{cwd:prepared.root,stdout:"pipe",stderr:"pipe"});if(compile.exitCode!==0)throw Error(`Compiling the agent launcher failed:
4
+ ${compile.stderr.toString().trim()||compile.stdout.toString().trim()}`);return{launcher,manifest:{appName:config.appName,bundleId:config.bundleId,version:config.version,hostArguments:agentHostArguments(config),...config.agent.port?{port:config.agent.port}:{},...config.agent.staticDir?{staticDir:resolve(prepared.root,config.agent.staticDir)}:{},...agentResources(config,prepared.root),appRoutes:!1}}}export function macosAgentDevFiles(prepared){const work=join(prepared.output,".build");return{entry:join(work,"agent-entry.ts"),manifest:join(work,AGENT_MANIFEST)}}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/actions",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.420",
5
+ "version": "0.75.422",
6
6
  "description": "The Stacks actions.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -66,55 +66,55 @@
66
66
  "prepublishOnly": "bun run build"
67
67
  },
68
68
  "dependencies": {
69
- "@stacksjs/action-runner": "0.75.420",
70
- "@stacksjs/ai": "0.75.420",
71
- "@stacksjs/analytics": "0.75.420",
72
- "@stacksjs/api": "0.75.420",
73
- "@stacksjs/auth": "0.75.420",
74
- "@stacksjs/build": "0.75.420",
69
+ "@stacksjs/action-runner": "0.75.422",
70
+ "@stacksjs/ai": "0.75.422",
71
+ "@stacksjs/analytics": "0.75.422",
72
+ "@stacksjs/api": "0.75.422",
73
+ "@stacksjs/auth": "0.75.422",
74
+ "@stacksjs/build": "0.75.422",
75
75
  "@stacksjs/bumpx": "^0.2.26",
76
76
  "@stacksjs/bunpress": "^0.2.15",
77
- "@stacksjs/cli": "0.75.420",
78
- "@stacksjs/cloud": "0.75.420",
79
- "@stacksjs/cms": "0.75.420",
80
- "@stacksjs/components": "0.2.782",
81
- "@stacksjs/config": "0.75.420",
82
- "@stacksjs/database": "0.75.420",
83
- "@stacksjs/desktop-build": "0.75.420",
84
- "@stacksjs/dns": "0.75.420",
85
- "@stacksjs/enums": "0.75.420",
86
- "@stacksjs/env": "0.75.420",
87
- "@stacksjs/error-handling": "0.75.420",
88
- "@stacksjs/github": "0.75.420",
77
+ "@stacksjs/cli": "0.75.422",
78
+ "@stacksjs/cloud": "0.75.422",
79
+ "@stacksjs/cms": "0.75.422",
80
+ "@stacksjs/components": "0.2.784",
81
+ "@stacksjs/config": "0.75.422",
82
+ "@stacksjs/database": "0.75.422",
83
+ "@stacksjs/desktop-build": "0.75.422",
84
+ "@stacksjs/dns": "0.75.422",
85
+ "@stacksjs/enums": "0.75.422",
86
+ "@stacksjs/env": "0.75.422",
87
+ "@stacksjs/error-handling": "0.75.422",
88
+ "@stacksjs/github": "0.75.422",
89
89
  "@stacksjs/gitit": "^0.2.5",
90
- "@stacksjs/i18n": "0.75.420",
91
- "@stacksjs/image": "0.75.420",
92
- "@stacksjs/logging": "0.75.420",
90
+ "@stacksjs/i18n": "0.75.422",
91
+ "@stacksjs/image": "0.75.422",
92
+ "@stacksjs/logging": "0.75.422",
93
93
  "@stacksjs/logsmith": "^0.2.11",
94
- "@stacksjs/mobile": "0.75.420",
95
- "@stacksjs/orm": "0.75.420",
96
- "@stacksjs/path": "0.75.420",
97
- "@stacksjs/payments": "0.75.420",
98
- "@stacksjs/queue": "0.75.420",
99
- "@stacksjs/registry": "0.75.420",
100
- "@stacksjs/router": "0.75.420",
94
+ "@stacksjs/mobile": "0.75.422",
95
+ "@stacksjs/orm": "0.75.422",
96
+ "@stacksjs/path": "0.75.422",
97
+ "@stacksjs/payments": "0.75.422",
98
+ "@stacksjs/queue": "0.75.422",
99
+ "@stacksjs/registry": "0.75.422",
100
+ "@stacksjs/router": "0.75.422",
101
101
  "@stacksjs/rpx": "^0.11.54",
102
- "@stacksjs/scheduler": "0.75.420",
103
- "@stacksjs/search-engine": "0.75.420",
104
- "@stacksjs/security": "0.75.420",
105
- "@stacksjs/server": "0.75.420",
106
- "@stacksjs/sites": "0.75.420",
107
- "@stacksjs/storage": "0.75.420",
108
- "@stacksjs/strings": "0.75.420",
109
- "@stacksjs/stx": "0.2.782",
102
+ "@stacksjs/scheduler": "0.75.422",
103
+ "@stacksjs/search-engine": "0.75.422",
104
+ "@stacksjs/security": "0.75.422",
105
+ "@stacksjs/server": "0.75.422",
106
+ "@stacksjs/sites": "0.75.422",
107
+ "@stacksjs/storage": "0.75.422",
108
+ "@stacksjs/strings": "0.75.422",
109
+ "@stacksjs/stx": "0.2.784",
110
110
  "@stacksjs/tlsx": "^0.13.19",
111
111
  "@stacksjs/ts-cloud": "^0.16.91",
112
112
  "@stacksjs/ts-md": "^0.1.1",
113
- "@stacksjs/tunnel": "0.75.420",
114
- "@stacksjs/types": "0.75.420",
115
- "@stacksjs/utils": "0.75.420",
116
- "@stacksjs/whois": "0.75.420",
117
- "bun-plugin-stx": "0.2.782"
113
+ "@stacksjs/tunnel": "0.75.422",
114
+ "@stacksjs/types": "0.75.422",
115
+ "@stacksjs/utils": "0.75.422",
116
+ "@stacksjs/whois": "0.75.422",
117
+ "bun-plugin-stx": "0.2.784"
118
118
  },
119
119
  "peerDependencies": {
120
120
  "craft-native": ">=0.0.420",
@@ -129,7 +129,7 @@
129
129
  }
130
130
  },
131
131
  "devDependencies": {
132
- "@stacksjs/validation": "0.75.420",
132
+ "@stacksjs/validation": "0.75.422",
133
133
  "better-dx": "^0.2.24"
134
134
  }
135
135
  }