@stacksjs/desktop-build 0.75.693 → 0.75.694

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/index.d.ts CHANGED
@@ -285,6 +285,7 @@ export declare interface InfoPlistOptions {
285
285
  appName: string
286
286
  bundleId: string
287
287
  version: string
288
+ buildNumber?: string
288
289
  executable: string
289
290
  iconFile?: string
290
291
  ownsLauncher: boolean
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ ${kept.map(([key,value])=>` <key>${xmlEscape(key)}</key>${plistValue(value," "
28
28
  <key>CFBundleName</key><string>${name}</string>
29
29
  <key>CFBundleDisplayName</key><string>${name}</string>
30
30
  <key>CFBundleIdentifier</key><string>${xmlEscape(options.bundleId)}</string>
31
- <key>CFBundleVersion</key><string>${version}</string>
31
+ <key>CFBundleVersion</key><string>${options.buildNumber?xmlEscape(options.buildNumber):version}</string>
32
32
  <key>CFBundleShortVersionString</key><string>${version}</string>
33
33
  <key>CFBundleExecutable</key><string>${xmlEscape(options.executable)}</string>
34
34
  <key>CFBundlePackageType</key><string>APPL</string>
@@ -4,7 +4,7 @@ import type { WebviewAppManifest } from './webview-launcher';
4
4
  /** Whether the project declares a web view desktop app. */
5
5
  export declare function hasWebviewDesktop(root: string): Promise<boolean>;
6
6
  export declare function loadWebviewDesktop(root: string, packageVersion?: string): Promise<ResolvedWebviewDesktop | null>;
7
- export declare function resolveWebviewDesktop(config: WebviewDesktopConfig, packageVersion?: string): ResolvedWebviewDesktop;
7
+ export declare function resolveWebviewDesktop(config: WebviewDesktopConfig, packageVersion?: string, env?: Record<string, string | undefined>): ResolvedWebviewDesktop;
8
8
  /** Why a config cannot build, as a list; empty when it can. */
9
9
  export declare function validateWebviewDesktop(config: ResolvedWebviewDesktop): string[];
10
10
  export declare function hostDesktopTarget(): DesktopTargetName;
@@ -128,6 +128,7 @@ export declare const WEBVIEW_DEFAULTS: {
128
128
  export declare const BUN_HARDENED_ENTITLEMENTS: Readonly<Record<string, boolean>>;
129
129
  export declare interface ResolvedWebviewDesktop extends WebviewDesktopConfig {
130
130
  version: string
131
+ buildNumber: string
131
132
  window: Required<Pick<NonNullable<WebviewDesktopConfig['window']>, 'title' | 'width' | 'height'>> & NonNullable<WebviewDesktopConfig['window']>
132
133
  agent: NonNullable<WebviewDesktopConfig['agent']> & { views: string }
133
134
  output: string
@@ -1,9 +1,9 @@
1
- import{chmodSync,copyFileSync,existsSync,mkdirSync,readdirSync,readFileSync,rmSync,statSync,writeFileSync}from"node:fs";import{basename,dirname,isAbsolute,join,relative,resolve,sep}from"node:path";import process from"node:process";import{codesignArgs,desktopLauncherCompileArgs,plistValue,renderInfoPlist}from"./index";import{loadDesktopConfig}from"./macos-app";import{makeIcns,runBundleCommand}from"./macos-bundle";import{desktopUpdatesProblems}from"./update-signing";import{webviewComponentDirs}from"./webview-agent";import{OPTIONAL_CRAFT_FLAGS,WEBVIEW_RUNTIME_NAME}from"./webview-launcher";export const DESKTOP_TARGETS=["darwin-arm64","darwin-x64","linux-x64","linux-arm64","win32-x64","win32-arm64"];export const WEBVIEW_DEFAULTS={views:"resources/desktop",output:"storage/framework/desktop/webview",width:1280,height:800,minimumSystemVersion:"13.0",category:"public.app-category.developer-tools"};export async function hasWebviewDesktop(root){return Boolean((await loadDesktopConfig(root))?.webview)}export async function loadWebviewDesktop(root,packageVersion="0.0.0"){const config=await loadDesktopConfig(root);return config?.webview?resolveWebviewDesktop(config.webview,packageVersion):null}export function resolveWebviewDesktop(config,packageVersion="0.0.0"){return{...config,version:config.version??packageVersion,window:{...config.window,title:config.window?.title??config.appName,width:config.window?.width??WEBVIEW_DEFAULTS.width,height:config.window?.height??WEBVIEW_DEFAULTS.height},agent:{...config.agent,views:config.agent?.views??WEBVIEW_DEFAULTS.views},output:config.output??WEBVIEW_DEFAULTS.output,executable:config.appName.replace(/[^\w .-]+/g,"").trim()||"App",slug:config.appName.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"app"}}export function validateWebviewDesktop(config){const errors=[];if(!config.appName?.trim())errors.push("webview.appName is required");if(!/^[a-z0-9-]+(\.[a-z0-9-]+)+$/i.test(config.appId??""))errors.push(`webview.appId must be reverse-DNS, like org.example.app (got ${JSON.stringify(config.appId)})`);if(!/^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/.test(config.version))errors.push(`webview.version must be a semantic version (got ${JSON.stringify(config.version)})`);for(const scheme of config.urlSchemes??[]){if(!/^[a-z][a-z0-9+.-]*$/i.test(scheme))errors.push(`webview.urlSchemes: ${JSON.stringify(scheme)} is not a URL scheme`)}if(config.updates)errors.push(...desktopUpdatesProblems(config.updates,"webview.updates"));return errors}export function hostDesktopTarget(){return`${process.platform}-${process.arch}`}export function parseDesktopTargets(input,host=hostDesktopTarget()){if(!input?.trim())return[host];if(input.trim()==="all")return[...DESKTOP_TARGETS];const targets=input.split(",").map((part)=>part.trim()).filter(Boolean).map((part)=>{const name=part.replace(/^macos-/,"darwin-").replace(/^windows-/,"win32-");if(!DESKTOP_TARGETS.includes(name))throw new Error(`Unknown desktop target ${JSON.stringify(part)}. Targets: ${DESKTOP_TARGETS.join(", ")}, or all.`);return name});return[...new Set(targets)]}export function splitDesktopTarget(target){const[platform,architecture]=target.split("-");return{platform,architecture}}export function bunCompileTarget(target){const{platform,architecture}=splitDesktopTarget(target);return`bun-${platform==="win32"?"windows":platform}-${architecture}`}export function webviewCompileArgs(options){const cross=options.target!==(options.host??hostDesktopTarget());const[command,...args]=desktopLauncherCompileArgs(options);return[command,...cross?[`--target=${bunCompileTarget(options.target)}`]:[],...options.target.startsWith("win32-")?["--windows-hide-console"]:[],...args]}export function webviewRuntimeFor(config,target,options){const configured=configuredWebviewRuntime(config,target,options);if(configured)return configured;throw new Error(`No Craft runtime for ${target}. Unpack that platform's Craft release and name its binary in desktop.webview.runtime['${target}'] or CRAFT_BIN_${target.replace("-","_").toUpperCase()}.`)}export function isWrapperScript(file){return readFileSync(file).subarray(0,2).toString()==="#!"}export function nativeHostRuntime(hostRuntime){const found=hostRuntime();if(isWrapperScript(found))throw new Error(`The Craft on this machine is a wrapper script, not a native binary: ${found}. Name the native binary in CRAFT_BIN, or let the build fetch the published runtime.`);return found}export function configuredWebviewRuntime(config,target,options){const env=options.env??process.env;const variable=`CRAFT_BIN_${target.replace("-","_").toUpperCase()}`;const named=config.runtime?.[target]??env[variable];if(named){const file=isAbsolute(named)?named:resolve(options.root,named);if(!existsSync(file))throw new Error(`The Craft runtime for ${target} does not exist: ${file}`);return file}if(target===(options.host??hostDesktopTarget())&&options.hostRuntime)return options.hostRuntime();return null}export function probeCraftFlags(runtime,flags=OPTIONAL_CRAFT_FLAGS){const binary=readFileSync(runtime);return flags.filter((flag)=>binary.includes(flag))}export function webviewManifest(config,options){return{appName:config.appName,appId:config.appId,version:config.version,runtime:options.runtime,window:{title:config.window.title,width:config.window.width,height:config.window.height,...config.window.darkMode!==undefined?{darkMode:config.window.darkMode}:{},...options.development||config.window.devtools?{devtools:true}:{},...config.window.titlebarHidden?{titlebarHidden:true}:{},...config.window.arguments?.length?{arguments:config.window.arguments}:{}},...config.agent.port?{port:config.agent.port}:{},...config.agent.startPath?{startPath:config.agent.startPath}:{},...config.agent.publicPaths?.length?{publicPaths:config.agent.publicPaths}:{},...config.urlSchemes?.length?{urlSchemes:config.urlSchemes}:{},...config.updates&&!options.development?{updates:{feedUrl:config.updates.feedUrl,publicKeys:config.updates.publicKeys,...config.updates.channel?{channel:config.updates.channel}:{},...config.updates.checkEveryHours!==undefined?{checkEveryHours:config.updates.checkEveryHours}:{}}}:{},...options.runtimeFlags?.length?{runtimeFlags:options.runtimeFlags}:{},...options.sourceRevision?{sourceRevision:options.sourceRevision}:{}}}export function collectViewFiles(directory){const files={};const walk=(current)=>{for(const entry of readdirSync(current).sort()){if(entry===".DS_Store")continue;const file=join(current,entry);if(statSync(file).isDirectory())walk(file);else files[`/${relative(directory,file).split(sep).join("/")}`]=file}};if(existsSync(directory))walk(directory);return files}export const BUN_HARDENED_ENTITLEMENTS={"com.apple.security.cs.allow-jit":true,"com.apple.security.cs.allow-unsigned-executable-memory":true,"com.apple.security.cs.disable-library-validation":true};export function renderWebviewEntitlements(config){return`<?xml version="1.0" encoding="UTF-8"?>
1
+ import{chmodSync,copyFileSync,existsSync,mkdirSync,readdirSync,readFileSync,rmSync,statSync,writeFileSync}from"node:fs";import{basename,dirname,isAbsolute,join,relative,resolve,sep}from"node:path";import process from"node:process";import{codesignArgs,desktopLauncherCompileArgs,plistValue,renderInfoPlist}from"./index";import{loadDesktopConfig}from"./macos-app";import{makeIcns,runBundleCommand}from"./macos-bundle";import{desktopUpdatesProblems}from"./update-signing";import{webviewComponentDirs}from"./webview-agent";import{OPTIONAL_CRAFT_FLAGS,WEBVIEW_RUNTIME_NAME}from"./webview-launcher";export const DESKTOP_TARGETS=["darwin-arm64","darwin-x64","linux-x64","linux-arm64","win32-x64","win32-arm64"];export const WEBVIEW_DEFAULTS={views:"resources/desktop",output:"storage/framework/desktop/webview",width:1280,height:800,minimumSystemVersion:"13.0",category:"public.app-category.developer-tools"};export async function hasWebviewDesktop(root){return Boolean((await loadDesktopConfig(root))?.webview)}export async function loadWebviewDesktop(root,packageVersion="0.0.0"){const config=await loadDesktopConfig(root);return config?.webview?resolveWebviewDesktop(config.webview,packageVersion):null}export function resolveWebviewDesktop(config,packageVersion="0.0.0",env=process.env){const version=config.version??packageVersion;return{...config,version,buildNumber:String(config.buildNumber??env.DESKTOP_BUILD_NUMBER??"").trim()||version.replace(/-.*$/,""),window:{...config.window,title:config.window?.title??config.appName,width:config.window?.width??WEBVIEW_DEFAULTS.width,height:config.window?.height??WEBVIEW_DEFAULTS.height},agent:{...config.agent,views:config.agent?.views??WEBVIEW_DEFAULTS.views},output:config.output??WEBVIEW_DEFAULTS.output,executable:config.appName.replace(/[^\w .-]+/g,"").trim()||"App",slug:config.appName.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"app"}}export function validateWebviewDesktop(config){const errors=[];if(!config.appName?.trim())errors.push("webview.appName is required");if(!/^[a-z0-9-]+(\.[a-z0-9-]+)+$/i.test(config.appId??""))errors.push(`webview.appId must be reverse-DNS, like org.example.app (got ${JSON.stringify(config.appId)})`);const versionValid=/^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/.test(config.version);if(!versionValid)errors.push(`webview.version must be a semantic version (got ${JSON.stringify(config.version)})`);if((versionValid||config.buildNumber!==config.version)&&!/^\d+(\.\d+){0,2}$/.test(config.buildNumber))errors.push(`webview.buildNumber must be one to three dot-separated integers, as CFBundleVersion is (got ${JSON.stringify(config.buildNumber)})`);for(const scheme of config.urlSchemes??[]){if(!/^[a-z][a-z0-9+.-]*$/i.test(scheme))errors.push(`webview.urlSchemes: ${JSON.stringify(scheme)} is not a URL scheme`)}if(config.updates)errors.push(...desktopUpdatesProblems(config.updates,"webview.updates"));return errors}export function hostDesktopTarget(){return`${process.platform}-${process.arch}`}export function parseDesktopTargets(input,host=hostDesktopTarget()){if(!input?.trim())return[host];if(input.trim()==="all")return[...DESKTOP_TARGETS];const targets=input.split(",").map((part)=>part.trim()).filter(Boolean).map((part)=>{const name=part.replace(/^macos-/,"darwin-").replace(/^windows-/,"win32-");if(!DESKTOP_TARGETS.includes(name))throw new Error(`Unknown desktop target ${JSON.stringify(part)}. Targets: ${DESKTOP_TARGETS.join(", ")}, or all.`);return name});return[...new Set(targets)]}export function splitDesktopTarget(target){const[platform,architecture]=target.split("-");return{platform,architecture}}export function bunCompileTarget(target){const{platform,architecture}=splitDesktopTarget(target);return`bun-${platform==="win32"?"windows":platform}-${architecture}`}export function webviewCompileArgs(options){const cross=options.target!==(options.host??hostDesktopTarget());const[command,...args]=desktopLauncherCompileArgs(options);return[command,...cross?[`--target=${bunCompileTarget(options.target)}`]:[],...options.target.startsWith("win32-")?["--windows-hide-console"]:[],...args]}export function webviewRuntimeFor(config,target,options){const configured=configuredWebviewRuntime(config,target,options);if(configured)return configured;throw new Error(`No Craft runtime for ${target}. Unpack that platform's Craft release and name its binary in desktop.webview.runtime['${target}'] or CRAFT_BIN_${target.replace("-","_").toUpperCase()}.`)}export function isWrapperScript(file){return readFileSync(file).subarray(0,2).toString()==="#!"}export function nativeHostRuntime(hostRuntime){const found=hostRuntime();if(isWrapperScript(found))throw new Error(`The Craft on this machine is a wrapper script, not a native binary: ${found}. Name the native binary in CRAFT_BIN, or let the build fetch the published runtime.`);return found}export function configuredWebviewRuntime(config,target,options){const env=options.env??process.env;const variable=`CRAFT_BIN_${target.replace("-","_").toUpperCase()}`;const named=config.runtime?.[target]??env[variable];if(named){const file=isAbsolute(named)?named:resolve(options.root,named);if(!existsSync(file))throw new Error(`The Craft runtime for ${target} does not exist: ${file}`);return file}if(target===(options.host??hostDesktopTarget())&&options.hostRuntime)return options.hostRuntime();return null}export function probeCraftFlags(runtime,flags=OPTIONAL_CRAFT_FLAGS){const binary=readFileSync(runtime);return flags.filter((flag)=>binary.includes(flag))}export function webviewManifest(config,options){return{appName:config.appName,appId:config.appId,version:config.version,runtime:options.runtime,window:{title:config.window.title,width:config.window.width,height:config.window.height,...config.window.darkMode!==undefined?{darkMode:config.window.darkMode}:{},...options.development||config.window.devtools?{devtools:true}:{},...config.window.titlebarHidden?{titlebarHidden:true}:{},...config.window.arguments?.length?{arguments:config.window.arguments}:{}},...config.agent.port?{port:config.agent.port}:{},...config.agent.startPath?{startPath:config.agent.startPath}:{},...config.agent.publicPaths?.length?{publicPaths:config.agent.publicPaths}:{},...config.urlSchemes?.length?{urlSchemes:config.urlSchemes}:{},...config.updates&&!options.development?{updates:{feedUrl:config.updates.feedUrl,publicKeys:config.updates.publicKeys,...config.updates.channel?{channel:config.updates.channel}:{},...config.updates.checkEveryHours!==undefined?{checkEveryHours:config.updates.checkEveryHours}:{}}}:{},...options.runtimeFlags?.length?{runtimeFlags:options.runtimeFlags}:{},...options.sourceRevision?{sourceRevision:options.sourceRevision}:{}}}export function collectViewFiles(directory){const files={};const walk=(current)=>{for(const entry of readdirSync(current).sort()){if(entry===".DS_Store")continue;const file=join(current,entry);if(statSync(file).isDirectory())walk(file);else files[`/${relative(directory,file).split(sep).join("/")}`]=file}};if(existsSync(directory))walk(directory);return files}export const BUN_HARDENED_ENTITLEMENTS={"com.apple.security.cs.allow-jit":true,"com.apple.security.cs.allow-unsigned-executable-memory":true,"com.apple.security.cs.disable-library-validation":true};export function renderWebviewEntitlements(config){return`<?xml version="1.0" encoding="UTF-8"?>
2
2
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
3
  <plist version="1.0">
4
4
  ${plistValue({...BUN_HARDENED_ENTITLEMENTS,...config.macos?.entitlements})}
5
5
  </plist>
6
- `}export function renderWebviewInfoPlist(config,options={}){const schemes=config.urlSchemes??[];return renderInfoPlist({appName:config.appName,bundleId:config.macos?.bundleId??config.appId,version:config.version,executable:config.executable,iconFile:options.iconFile,ownsLauncher:true,declared:{LSMinimumSystemVersion:config.macos?.minimumSystemVersion??WEBVIEW_DEFAULTS.minimumSystemVersion,LSApplicationCategoryType:config.macos?.category??WEBVIEW_DEFAULTS.category,...schemes.length?{CFBundleURLTypes:[{CFBundleURLName:config.appId,CFBundleURLSchemes:schemes}]}:{},...config.macos?.usageDescriptions,...config.macos?.infoPlist}})}export function assembleWebviewMacosApp(options){const{config}=options;const run=options.run??runBundleCommand;const identity=options.signingIdentity??"-";const appPath=join(options.output,`${config.appName}.app`);const macos=join(appPath,"Contents","MacOS");const resources=join(appPath,"Contents","Resources");rmSync(appPath,{recursive:true,force:true});mkdirSync(macos,{recursive:true});mkdirSync(resources,{recursive:true});const executable=join(macos,config.executable);const runtime=join(macos,WEBVIEW_RUNTIME_NAME);copyFileSync(options.agent,executable);copyFileSync(options.runtime,runtime);chmodSync(executable,493);chmodSync(runtime,493);let iconFile;if(config.icon){const icon=resolve(options.root,config.icon);if(!existsSync(icon))throw new Error(`webview.icon does not exist: ${icon}`);if(icon.endsWith(".icns"))copyFileSync(icon,join(resources,"AppIcon.icns"));else makeIcns(icon,join(resources,"AppIcon.icns"),options.output,run);iconFile="AppIcon"}const plist=renderWebviewInfoPlist(config,{iconFile});writeFileSync(join(appPath,"Contents","Info.plist"),plist.xml);const entitlementsPath=join(options.output,`${config.appName}.entitlements`);writeFileSync(entitlementsPath,renderWebviewEntitlements(config));run(codesignArgs({identity,target:runtime}));run(codesignArgs({identity,target:appPath,entitlements:entitlementsPath}));return{appPath,entitlementsPath,ignoredPlistKeys:plist.ignored}}export function webviewPackageConfig(config,target,staged){const{platform,architecture}=splitDesktopTarget(target);const base={name:config.appName,version:config.version,...config.description?{description:config.description}:{},...config.publisher?{author:config.publisher}:{},...config.homepage?{homepage:config.homepage}:{},bundleId:config.appId,binaryPath:staged.binary,...staged.icon?{iconPath:staged.icon}:{},outDir:staged.outDir};if(platform==="win32"){return{...base,platforms:["windows"],windows:{msi:true,zip:true,architecture,...staged.additionalFiles?.length?{additionalFiles:staged.additionalFiles}:{},...config.urlSchemes?.length?{urlSchemes:config.urlSchemes}:{},...config.windows?.certificatePath?{certificatePath:config.windows.certificatePath,...staged.certificatePassword?{certificatePassword:staged.certificatePassword}:{}}:{}}}}return{...base,platforms:["linux"],linux:{appImage:true,deb:true,rpm:true,categories:config.linux?.categories??["Development"],...config.urlSchemes?.length?{urlSchemes:config.urlSchemes}:{},...config.linux?.debDependencies?{debDependencies:config.linux.debDependencies}:{},...config.linux?.rpmDependencies?{rpmDependencies:config.linux.rpmDependencies}:{}}}}export function nativeBuildSteps(target){const{platform}=splitDesktopTarget(target);if(platform==="darwin")return"The .app is assembled and signed with codesign, notarized with notarytool and imaged with hdiutil: macOS only.";if(platform==="win32")return"The MSI is built with WiX (candle, light) and signed with signtool: Windows only.";return"The AppImage (appimagetool), deb (dpkg-deb) and rpm (rpmbuild) are built with Linux tools: Linux only."}export function signtoolArgs(options){return["signtool.exe","sign","/f",options.certificatePath,...options.certificatePassword?["/p",options.certificatePassword]:[],"/fd","SHA256","/tr",options.timestampUrl??"http://timestamp.digicert.com","/td","SHA256",options.file]}export function releaseArtifactNames(config,target){const{platform,architecture}=splitDesktopTarget(target);const base=`${config.appName.replace(/[^\w.-]+/g,"-")}-${config.version}-${architecture}`;if(platform==="darwin")return{update:`${base}.zip`,downloads:[`${base}.dmg`]};if(platform==="win32")return{update:`${base}.msi`,downloads:[`${base}.msi`]};return{update:`${base}.AppImage`,downloads:[`${base}.AppImage`,`${base}.deb`,`${base}.rpm`]}}export function releaseArtifactFormat(name){return name.slice(name.lastIndexOf(".")+1).toLowerCase()}export function signingIdentityNote(identity,chosen){if(chosen)return;const fix="Set DESKTOP_SIGNING_IDENTITY (or pass --identity) to a Developer ID Application certificate to build what a release can notarize; `buddy release:desktop --identity` signs it again otherwise.";if(identity==="-")return`Signed ad hoc: it runs on this Mac only. ${fix}`;return`Signed with the Apple Development certificate found on this Mac: it runs here, and cannot be notarized. ${fix}`}export function resignWebviewMacosApp(options){const run=options.run??runBundleCommand;const runtime=join(options.appPath,"Contents","MacOS",WEBVIEW_RUNTIME_NAME);if(!existsSync(runtime))throw new Error(`${options.appPath} has no ${WEBVIEW_RUNTIME_NAME}: it is not a web view app this build made.`);let entitlements=options.entitlementsPath;if(!entitlements||!existsSync(entitlements)){entitlements=join(dirname(options.appPath),`${basename(options.appPath,".app")}.entitlements`);writeFileSync(entitlements,renderWebviewEntitlements(options.config))}run(codesignArgs({identity:options.signingIdentity,target:runtime}));run(codesignArgs({identity:options.signingIdentity,target:options.appPath,entitlements}))}export function releaseVersionProblem(version,published,compare){if(!published)return;const order=compare(version,published);if(order===0)return`${version} is already published. Bump the version; a published build is never replaced under the same number.`;if(order<0)return`${published} is already published, which is newer than ${version}.`;return}export function resolveWebviewComponents(root,components){return(components??[]).map((directory)=>resolve(root,directory))}export function renderViewsBuildScript(options){const pages=relative(options.root,options.viewsDir);const site={name:options.appName,url:"http://127.0.0.1",pagesDir:pages,outDir:options.outDir,publicDir:join(pages,"public"),...webviewComponentDirs(resolveWebviewComponents(options.root,options.components)),sitemap:false,robots:false};return`// Written by buddy build:desktop. Do not edit.
6
+ `}export function renderWebviewInfoPlist(config,options={}){const schemes=config.urlSchemes??[];return renderInfoPlist({appName:config.appName,bundleId:config.macos?.bundleId??config.appId,version:config.version,buildNumber:config.buildNumber,executable:config.executable,iconFile:options.iconFile,ownsLauncher:true,declared:{LSMinimumSystemVersion:config.macos?.minimumSystemVersion??WEBVIEW_DEFAULTS.minimumSystemVersion,LSApplicationCategoryType:config.macos?.category??WEBVIEW_DEFAULTS.category,...schemes.length?{CFBundleURLTypes:[{CFBundleURLName:config.appId,CFBundleURLSchemes:schemes}]}:{},...config.macos?.usageDescriptions,...config.macos?.infoPlist}})}export function assembleWebviewMacosApp(options){const{config}=options;const run=options.run??runBundleCommand;const identity=options.signingIdentity??"-";const appPath=join(options.output,`${config.appName}.app`);const macos=join(appPath,"Contents","MacOS");const resources=join(appPath,"Contents","Resources");rmSync(appPath,{recursive:true,force:true});mkdirSync(macos,{recursive:true});mkdirSync(resources,{recursive:true});const executable=join(macos,config.executable);const runtime=join(macos,WEBVIEW_RUNTIME_NAME);copyFileSync(options.agent,executable);copyFileSync(options.runtime,runtime);chmodSync(executable,493);chmodSync(runtime,493);let iconFile;if(config.icon){const icon=resolve(options.root,config.icon);if(!existsSync(icon))throw new Error(`webview.icon does not exist: ${icon}`);if(icon.endsWith(".icns"))copyFileSync(icon,join(resources,"AppIcon.icns"));else makeIcns(icon,join(resources,"AppIcon.icns"),options.output,run);iconFile="AppIcon"}const plist=renderWebviewInfoPlist(config,{iconFile});writeFileSync(join(appPath,"Contents","Info.plist"),plist.xml);const entitlementsPath=join(options.output,`${config.appName}.entitlements`);writeFileSync(entitlementsPath,renderWebviewEntitlements(config));run(codesignArgs({identity,target:runtime}));run(codesignArgs({identity,target:appPath,entitlements:entitlementsPath}));return{appPath,entitlementsPath,ignoredPlistKeys:plist.ignored}}export function webviewPackageConfig(config,target,staged){const{platform,architecture}=splitDesktopTarget(target);const base={name:config.appName,version:config.version,...config.description?{description:config.description}:{},...config.publisher?{author:config.publisher}:{},...config.homepage?{homepage:config.homepage}:{},bundleId:config.appId,binaryPath:staged.binary,...staged.icon?{iconPath:staged.icon}:{},outDir:staged.outDir};if(platform==="win32"){return{...base,platforms:["windows"],windows:{msi:true,zip:true,architecture,...staged.additionalFiles?.length?{additionalFiles:staged.additionalFiles}:{},...config.urlSchemes?.length?{urlSchemes:config.urlSchemes}:{},...config.windows?.certificatePath?{certificatePath:config.windows.certificatePath,...staged.certificatePassword?{certificatePassword:staged.certificatePassword}:{}}:{}}}}return{...base,platforms:["linux"],linux:{appImage:true,deb:true,rpm:true,categories:config.linux?.categories??["Development"],...config.urlSchemes?.length?{urlSchemes:config.urlSchemes}:{},...config.linux?.debDependencies?{debDependencies:config.linux.debDependencies}:{},...config.linux?.rpmDependencies?{rpmDependencies:config.linux.rpmDependencies}:{}}}}export function nativeBuildSteps(target){const{platform}=splitDesktopTarget(target);if(platform==="darwin")return"The .app is assembled and signed with codesign, notarized with notarytool and imaged with hdiutil: macOS only.";if(platform==="win32")return"The MSI is built with WiX (candle, light) and signed with signtool: Windows only.";return"The AppImage (appimagetool), deb (dpkg-deb) and rpm (rpmbuild) are built with Linux tools: Linux only."}export function signtoolArgs(options){return["signtool.exe","sign","/f",options.certificatePath,...options.certificatePassword?["/p",options.certificatePassword]:[],"/fd","SHA256","/tr",options.timestampUrl??"http://timestamp.digicert.com","/td","SHA256",options.file]}export function releaseArtifactNames(config,target){const{platform,architecture}=splitDesktopTarget(target);const base=`${config.appName.replace(/[^\w.-]+/g,"-")}-${config.version}-${architecture}`;if(platform==="darwin")return{update:`${base}.zip`,downloads:[`${base}.dmg`]};if(platform==="win32")return{update:`${base}.msi`,downloads:[`${base}.msi`]};return{update:`${base}.AppImage`,downloads:[`${base}.AppImage`,`${base}.deb`,`${base}.rpm`]}}export function releaseArtifactFormat(name){return name.slice(name.lastIndexOf(".")+1).toLowerCase()}export function signingIdentityNote(identity,chosen){if(chosen)return;const fix="Set DESKTOP_SIGNING_IDENTITY (or pass --identity) to a Developer ID Application certificate to build what a release can notarize; `buddy release:desktop --identity` signs it again otherwise.";if(identity==="-")return`Signed ad hoc: it runs on this Mac only. ${fix}`;return`Signed with the Apple Development certificate found on this Mac: it runs here, and cannot be notarized. ${fix}`}export function resignWebviewMacosApp(options){const run=options.run??runBundleCommand;const runtime=join(options.appPath,"Contents","MacOS",WEBVIEW_RUNTIME_NAME);if(!existsSync(runtime))throw new Error(`${options.appPath} has no ${WEBVIEW_RUNTIME_NAME}: it is not a web view app this build made.`);let entitlements=options.entitlementsPath;if(!entitlements||!existsSync(entitlements)){entitlements=join(dirname(options.appPath),`${basename(options.appPath,".app")}.entitlements`);writeFileSync(entitlements,renderWebviewEntitlements(options.config))}run(codesignArgs({identity:options.signingIdentity,target:runtime}));run(codesignArgs({identity:options.signingIdentity,target:options.appPath,entitlements}))}export function releaseVersionProblem(version,published,compare){if(!published)return;const order=compare(version,published);if(order===0)return`${version} is already published. Bump the version; a published build is never replaced under the same number.`;if(order<0)return`${published} is already published, which is newer than ${version}.`;return}export function resolveWebviewComponents(root,components){return(components??[]).map((directory)=>resolve(root,directory))}export function renderViewsBuildScript(options){const pages=relative(options.root,options.viewsDir);const site={name:options.appName,url:"http://127.0.0.1",pagesDir:pages,outDir:options.outDir,publicDir:join(pages,"public"),...webviewComponentDirs(resolveWebviewComponents(options.root,options.components)),sitemap:false,robots:false};return`// Written by buddy build:desktop. Do not edit.
7
7
  import { buildStaticSite } from '@stacksjs/stx'
8
8
 
9
9
  await buildStaticSite(${JSON.stringify(site,null,2)})
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/desktop-build",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.693",
5
+ "version": "0.75.694",
6
6
  "description": "Build and launch Craft desktop applications for Stacks",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -73,17 +73,17 @@
73
73
  "prepublishOnly": "bun run build"
74
74
  },
75
75
  "dependencies": {
76
- "@stacksjs/config": "0.75.693",
77
- "@stacksjs/router": "0.75.693",
78
- "@stacksjs/server": "0.75.693",
79
- "@stacksjs/storage": "0.75.693",
76
+ "@stacksjs/config": "0.75.694",
77
+ "@stacksjs/router": "0.75.694",
78
+ "@stacksjs/server": "0.75.694",
79
+ "@stacksjs/storage": "0.75.694",
80
80
  "craft-native": ">=0.0.505"
81
81
  },
82
82
  "peerDependencies": {
83
- "@stacksjs/config": "0.75.693",
84
- "@stacksjs/router": "0.75.693",
85
- "@stacksjs/server": "0.75.693",
86
- "@stacksjs/storage": "0.75.693"
83
+ "@stacksjs/config": "0.75.694",
84
+ "@stacksjs/router": "0.75.694",
85
+ "@stacksjs/server": "0.75.694",
86
+ "@stacksjs/storage": "0.75.694"
87
87
  },
88
88
  "peerDependenciesMeta": {
89
89
  "@stacksjs/config": {
@@ -100,7 +100,7 @@
100
100
  }
101
101
  },
102
102
  "devDependencies": {
103
- "@stacksjs/build": "0.75.693",
103
+ "@stacksjs/build": "0.75.694",
104
104
  "better-dx": "^0.2.39"
105
105
  }
106
106
  }