obsidian-launcher 0.3.1 → 0.4.1

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 @@
1
+ {"version":3,"sources":["/home/runner/work/wdio-obsidian-service/wdio-obsidian-service/packages/obsidian-launcher/dist/chunk-D3Z4H7XZ.cjs","../src/launcher.ts","../src/utils.ts","../src/apis.ts","../src/chromeLocalStorage.ts","../src/launcherUtils.ts"],"names":["path","_","fsAsync","fetch","manifestPath"],"mappings":"AAAA;ACAA,2FAAoB;AACpB,gEAAe;AACf,wEAAiB;AACjB,wEAAiB;AACjB,gFAAmB;AACnB,6FAAkB;AAClB,iGAAuB;AACvB,4CAAyB;AACzB,oCAAiC;AACjC,4GAA0B;AAC1B,gFAAmB;ADEnB;AACA;AEbA;AACA;AACA,gEAAe;AACf,wDAA4B;AAC5B,gFAAc;AAId,MAAA,SAAsB,UAAA,CAAWA,KAAAA,EAAc;AAC3C,EAAA,IAAI;AACA,IAAA,MAAM,kBAAA,CAAQ,MAAA,CAAOA,KAAI,CAAA;AACzB,IAAA,OAAO,IAAA;AAAA,EACX,EAAA,WAAQ;AACJ,IAAA,OAAO,KAAA;AAAA,EACX;AACJ;AAOA,MAAA,SAAsB,UAAA,CAAW,MAAA,EAAiB;AAC9C,EAAA,OAAO,kBAAA,CAAQ,OAAA,CAAQ,cAAA,CAAK,IAAA,CAAK,YAAA,CAAG,MAAA,CAAO,CAAA,mBAAG,MAAA,UAAU,QAAM,CAAC,CAAA;AACnE;AASA,MAAA,SAAsB,UAAA,CAAW,IAAA,EAAc,IAAA,EAA+D;AAC1G,EAAA,KAAA,EAAO,cAAA,CAAK,OAAA,CAAQ,IAAI,CAAA;AACxB,EAAA,MAAM,OAAA,EAAS,MAAM,kBAAA,CAAQ,OAAA,CAAQ,cAAA,CAAK,IAAA,CAAK,cAAA,CAAK,OAAA,CAAQ,IAAI,CAAA,EAAG,CAAA,CAAA,EAAI,cAAA,CAAK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AACmB,IAAA;AACf,MAAA;AAC3C,IAAA;AAEO,IAAA;AACX,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAO0D,EAAA;AACP,IAAA;AAE3C,IAAA;AACe,IAAA;AACwB,MAAA;AACpC,IAAA;AACsB,MAAA;AACmB,MAAA;AAChD,IAAA;AAEuD,IAAA;AAC3D,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOqD,EAAA;AACI,IAAA;AACE,IAAA;AAE/B,IAAA;AACoC,MAAA;AACA,MAAA;AACnB,MAAA;AAClC,IAAA;AACI,MAAA;AACX,IAAA;AACJ,EAAA;AACJ;ADiQ+D;AACA;AACA;AACA","file":"/home/runner/work/wdio-obsidian-service/wdio-obsidian-service/packages/obsidian-launcher/dist/chunk-D3Z4H7XZ.cjs","sourcesContent":[null,"import fsAsync from \"fs/promises\"\nimport fs from \"fs\"\nimport zlib from \"zlib\"\nimport path from \"path\"\nimport crypto from \"crypto\";\nimport fetch from \"node-fetch\"\nimport extractZip from \"extract-zip\"\nimport { pipeline } from \"stream/promises\";\nimport { downloadArtifact } from '@electron/get';\nimport child_process from \"child_process\"\nimport semver from \"semver\"\nimport { fileExists, makeTmpDir, withTmpDir, linkOrCp, maybe, pool, mergeKeepUndefined } from \"./utils.js\";\nimport {\n ObsidianVersionInfo, ObsidianCommunityPlugin, ObsidianCommunityTheme,\n PluginEntry, DownloadedPluginEntry, ThemeEntry, DownloadedThemeEntry,\n ObsidianVersionInfos,\n} from \"./types.js\";\nimport { fetchObsidianAPI, fetchGitHubAPIPaginated, fetchWithFileUrl } from \"./apis.js\";\nimport ChromeLocalStorage from \"./chromeLocalStorage.js\";\nimport {\n normalizeGitHubRepo, extractObsidianAppImage, extractObsidianExe, extractObsidianDmg,\n parseObsidianDesktopRelease, parseObsidianGithubRelease, correctObsidianVersionInfo,\n getElectronVersionInfo, normalizeObsidianVersionInfo,\n} from \"./launcherUtils.js\";\nimport _ from \"lodash\"\n\n\n/**\n * Helper class that handles downloading and installing Obsidian versions, plugins, and themes and launching Obsidian\n * with sandboxed configuration directories.\n */\nexport class ObsidianLauncher {\n readonly cacheDir: string\n\n readonly versionsUrl: string\n readonly communityPluginsUrl: string\n readonly communityThemesUrl: string\n readonly cacheDuration: number\n\n /** Cached metadata files and requests */\n private metadataCache: Record<string, any>\n\n /**\n * Construct an ObsidianLauncher.\n * @param options.cacheDir Path to the cache directory. Defaults to \"OBSIDIAN_CACHE\" env var or \".obsidian-cache\".\n * @param options.versionsUrl Custom `obsidian-versions.json` url. Can be a file URL.\n * @param options.communityPluginsUrl Custom `community-plugins.json` url. Can be a file URL.\n * @param options.communityThemesUrl Custom `community-css-themes.json` url. Can be a file URL.\n * @param options.cacheDuration If the cached version list is older than this (in ms), refetch it. Defaults to 30 minutes.\n */\n constructor(options: {\n cacheDir?: string,\n versionsUrl?: string,\n communityPluginsUrl?: string,\n communityThemesUrl?: string,\n cacheDuration?: number,\n } = {}) {\n this.cacheDir = path.resolve(options.cacheDir ?? process.env.OBSIDIAN_CACHE ?? \"./.obsidian-cache\");\n \n const defaultVersionsUrl = 'https://raw.githubusercontent.com/jesse-r-s-hines/wdio-obsidian-service/HEAD/obsidian-versions.json'\n this.versionsUrl = options.versionsUrl ?? defaultVersionsUrl;\n \n const defaultCommunityPluginsUrl = \"https://raw.githubusercontent.com/obsidianmd/obsidian-releases/HEAD/community-plugins.json\";\n this.communityPluginsUrl = options.communityPluginsUrl ?? defaultCommunityPluginsUrl;\n\n const defaultCommunityThemesUrl = \"https://raw.githubusercontent.com/obsidianmd/obsidian-releases/HEAD/community-css-themes.json\";\n this.communityThemesUrl = options.communityThemesUrl ?? defaultCommunityThemesUrl;\n\n this.cacheDuration = options.cacheDuration ?? (30 * 60 * 1000);\n\n this.metadataCache = {};\n }\n\n /**\n * Returns file content fetched from url as JSON. Caches content to dest and uses that cache if its more recent than\n * cacheDuration ms or if there are network errors.\n */\n private async cachedFetch(url: string, dest: string): Promise<any> {\n dest = path.resolve(dest);\n if (!(dest in this.metadataCache)) {\n let fileContent: string|undefined;\n const mtime = await fileExists(dest) ? (await fsAsync.stat(dest)).mtime : undefined;\n\n if (mtime && new Date().getTime() - mtime.getTime() < this.cacheDuration) { // read from cache if its recent\n fileContent = await fsAsync.readFile(dest, 'utf-8');\n } else { // otherwise try to fetch the url\n const request = await maybe(fetchWithFileUrl(url));\n if (request.success) {\n await fsAsync.mkdir(path.dirname(dest), { recursive: true });\n await withTmpDir(dest, async (tmpDir) => {\n await fsAsync.writeFile(path.join(tmpDir, 'download.json'), request.result);\n return path.join(tmpDir, 'download.json');\n })\n fileContent = request.result;\n } else if (await fileExists(dest)) { // use cache on network error\n console.warn(request.error)\n console.warn(`Unable to download ${dest}, using cached file.`);\n fileContent = await fsAsync.readFile(dest, 'utf-8');\n } else {\n throw request.error;\n }\n }\n\n this.metadataCache[dest] = JSON.parse(fileContent);\n }\n return this.metadataCache[dest];\n }\n\n /**\n * Get parsed content of the current project's manifest.json\n */\n private async getRootManifest(): Promise<any> {\n if (!('manifest.json' in this.metadataCache)) {\n const root = path.parse(process.cwd()).root;\n let dir = process.cwd();\n while (dir != root && !(await fileExists(path.join(dir, 'manifest.json')))) {\n dir = path.dirname(dir);\n }\n const manifestPath = path.join(dir, 'manifest.json');\n if (await fileExists(manifestPath)) {\n this.metadataCache['manifest.json'] = JSON.parse(await fsAsync.readFile(manifestPath, 'utf-8'));\n } else {\n this.metadataCache['manifest.json'] = null;\n }\n }\n return this.metadataCache['manifest.json'];\n }\n\n /**\n * Get information about all available Obsidian versions.\n */\n async getVersions(): Promise<ObsidianVersionInfo[]> {\n const dest = path.join(this.cacheDir, \"obsidian-versions.json\");\n return (await this.cachedFetch(this.versionsUrl, dest)).versions;\n }\n\n /**\n * Get information about all available community plugins.\n */\n async getCommunityPlugins(): Promise<ObsidianCommunityPlugin[]> {\n const dest = path.join(this.cacheDir, \"obsidian-community-plugins.json\");\n return await this.cachedFetch(this.communityPluginsUrl, dest);\n }\n\n /**\n * Get information about all available community themes.\n */\n async getCommunityThemes(): Promise<ObsidianCommunityTheme[]> {\n const dest = path.join(this.cacheDir, \"obsidian-community-css-themes.json\");\n return await this.cachedFetch(this.communityThemesUrl, dest);\n }\n\n /**\n * Resolves Obsidian app and installer version strings to absolute versions.\n * @param appVersion Obsidian version string or one of \n * - \"latest\": Get the current latest non-beta Obsidian version\n * - \"latest-beta\": Get the current latest beta Obsidian version (or latest is there is no current beta)\n * - \"earliest\": Get the `minAppVersion` set in set in your `manifest.json`\n * @param installerVersion Obsidian version string or one of \n * - \"latest\": Get the latest Obsidian installer\n * - \"earliest\": Get the oldest Obsidian installer compatible with the specified Obsidian app version\n * @returns [appVersion, installerVersion] with any \"latest\" etc. resolved to specific versions.\n */\n async resolveVersions(appVersion: string, installerVersion = \"latest\"): Promise<[string, string]> {\n const versions = await this.getVersions();\n const appVersionInfo = await this.getVersionInfo(appVersion);\n\n if (!appVersionInfo.minInstallerVersion || !appVersionInfo.maxInstallerVersion) {\n throw Error(`No compatible installers available for app version ${appVersion}`);\n }\n if (installerVersion == \"latest\") {\n installerVersion = appVersionInfo.maxInstallerVersion;\n } else if (installerVersion == \"earliest\") {\n installerVersion = appVersionInfo.minInstallerVersion;\n } else {\n installerVersion = semver.valid(installerVersion) ?? installerVersion;\n }\n const installerVersionInfo = versions.find(v => v.version == installerVersion);\n if (!installerVersionInfo || !installerVersionInfo.chromeVersion) {\n throw Error(`No Obsidian installer for version ${installerVersion} found`);\n }\n if (\n semver.lt(installerVersionInfo.version, appVersionInfo.minInstallerVersion) ||\n semver.gt(installerVersionInfo.version, appVersionInfo.maxInstallerVersion)\n ) {\n throw Error(\n `App and installer versions incompatible: app ${appVersionInfo.version} is compatible with installer ` +\n `>=${appVersionInfo.minInstallerVersion} <=${appVersionInfo.maxInstallerVersion} but ` +\n `${installerVersionInfo.version} specified`\n )\n }\n\n return [appVersionInfo.version, installerVersionInfo.version];\n }\n\n /**\n * Gets details about an Obsidian version.\n * @param appVersion Obsidian app version (see {@link resolveVersions} for format)\n */\n async getVersionInfo(appVersion: string): Promise<ObsidianVersionInfo> {\n const versions = await this.getVersions();\n if (appVersion == \"latest-beta\") {\n appVersion = versions.at(-1)!.version;\n } else if (appVersion == \"latest\") {\n appVersion = versions.filter(v => !v.isBeta).at(-1)!.version;\n } else if (appVersion == \"earliest\") {\n appVersion = (await this.getRootManifest())?.minAppVersion;\n if (!appVersion) {\n throw Error('Unable to resolve Obsidian app appVersion \"earliest\", no manifest.json or minAppVersion found.')\n }\n } else {\n // if invalid match won't be found and we'll throw error below\n appVersion = semver.valid(appVersion) ?? appVersion;\n }\n const versionInfo = versions.find(v => v.version == appVersion);\n if (!versionInfo) {\n throw Error(`No Obsidian app version ${appVersion} found`);\n }\n\n return versionInfo;\n }\n\n /**\n * Downloads the Obsidian installer for the given version and platform. Returns the file path.\n * @param installerVersion Obsidian installer version to download. (see {@link resolveVersions} for format)\n */\n async downloadInstaller(installerVersion: string): Promise<string> {\n const installerVersionInfo = await this.getVersionInfo(installerVersion);\n return await this.downloadInstallerFromVersionInfo(installerVersionInfo);\n }\n\n /**\n * Helper for downloadInstaller that doesn't require the obsidian-versions.json file so it can be used in\n * updateObsidianVersionInfos\n */\n private async downloadInstallerFromVersionInfo(versionInfo: ObsidianVersionInfo): Promise<string> {\n const installerVersion = versionInfo.version;\n const {platform, arch} = process;\n const cacheDir = path.join(this.cacheDir, `obsidian-installer/${platform}-${arch}/Obsidian-${installerVersion}`);\n \n let installerPath: string\n let downloader: ((tmpDir: string) => Promise<string>)|undefined\n \n if (platform == \"linux\") {\n installerPath = path.join(cacheDir, \"obsidian\");\n let installerUrl: string|undefined\n if (arch.startsWith(\"arm\")) {\n installerUrl = versionInfo.downloads.appImageArm;\n } else {\n installerUrl = versionInfo.downloads.appImage;\n }\n if (installerUrl) {\n downloader = async (tmpDir) => {\n const appImage = path.join(tmpDir, \"Obsidian.AppImage\");\n await fsAsync.writeFile(appImage, (await fetch(installerUrl)).body as any);\n const obsidianFolder = path.join(tmpDir, \"Obsidian\");\n await extractObsidianAppImage(appImage, obsidianFolder);\n return obsidianFolder;\n };\n }\n } else if (platform == \"win32\") {\n installerPath = path.join(cacheDir, \"Obsidian.exe\")\n const installerUrl = versionInfo.downloads.exe;\n let appArch: string|undefined\n if (arch == \"x64\") {\n appArch = \"app-64\"\n } else if (arch == \"ia32\") {\n appArch = \"app-32\"\n } else if (arch.startsWith(\"arm\")) {\n appArch = \"app-arm64\"\n }\n if (installerUrl && appArch) {\n downloader = async (tmpDir) => {\n const installerExecutable = path.join(tmpDir, \"Obsidian.exe\");\n await fsAsync.writeFile(installerExecutable, (await fetch(installerUrl)).body as any);\n const obsidianFolder = path.join(tmpDir, \"Obsidian\");\n await extractObsidianExe(installerExecutable, appArch, obsidianFolder);\n return obsidianFolder;\n };\n }\n } else if (platform == \"darwin\") {\n installerPath = path.join(cacheDir, \"Contents/MacOS/Obsidian\");\n const installerUrl = versionInfo.downloads.dmg;\n if (installerUrl) {\n downloader = async (tmpDir) => {\n const dmg = path.join(tmpDir, \"Obsidian.dmg\");\n await fsAsync.writeFile(dmg, (await fetch(installerUrl)).body as any);\n const obsidianFolder = path.join(tmpDir, \"Obsidian\");\n await extractObsidianDmg(dmg, obsidianFolder);\n return obsidianFolder;\n };\n }\n } else {\n throw Error(`Unsupported platform ${platform}`);\n }\n if (!downloader) {\n throw Error(`No Obsidian installer download available for v${installerVersion} ${platform} ${arch}`);\n }\n\n if (!(await fileExists(installerPath))) {\n console.log(`Downloading Obsidian installer v${installerVersion}...`)\n await fsAsync.mkdir(path.dirname(cacheDir), { recursive: true });\n await withTmpDir(cacheDir, downloader);\n }\n\n return installerPath;\n }\n\n /**\n * Downloads the Obsidian asar for the given version and platform. Returns the file path.\n * \n * To download beta versions you'll need to have an Obsidian account with Catalyst and set the `OBSIDIAN_USERNAME`\n * and `OBSIDIAN_PASSWORD` environment variables. 2FA needs to be disabled.\n * \n * @param appVersion Obsidian version to download (see {@link resolveVersions} for format)\n */\n async downloadApp(appVersion: string): Promise<string> {\n const appVersionInfo = await this.getVersionInfo(appVersion);\n const appUrl = appVersionInfo.downloads.asar;\n if (!appUrl) {\n throw Error(`No asar found for Obsidian version ${appVersion}`);\n }\n const appPath = path.join(this.cacheDir, 'obsidian-app', `obsidian-${appVersionInfo.version}.asar`);\n\n if (!(await fileExists(appPath))) {\n console.log(`Downloading Obsidian app v${appVersion} ...`)\n await fsAsync.mkdir(path.dirname(appPath), { recursive: true });\n\n await withTmpDir(appPath, async (tmpDir) => {\n const isInsidersBuild = new URL(appUrl).hostname.endsWith('.obsidian.md');\n const response = isInsidersBuild ? await fetchObsidianAPI(appUrl) : await fetch(appUrl);\n const archive = path.join(tmpDir, 'app.asar.gz');\n const asar = path.join(tmpDir, 'app.asar')\n await fsAsync.writeFile(archive, response.body as any);\n await pipeline(fs.createReadStream(archive), zlib.createGunzip(), fs.createWriteStream(asar));\n return asar;\n })\n }\n\n return appPath;\n }\n\n /**\n * Downloads chromedriver for the given Obsidian version.\n * \n * wdio will download chromedriver from the Chrome for Testing API automatically (see\n * https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints). However, Google has only put\n * chromedriver since v115.0.5763.0 in that API, so wdio can't automatically download older versions of chromedriver\n * for old Electron versions. Here we download chromedriver for older versions ourselves using the @electron/get\n * package which fetches chromedriver from https://github.com/electron/electron/releases.\n * \n * @param installerVersion Obsidian installer version (see {@link resolveVersions} for format)\n */\n async downloadChromedriver(installerVersion: string): Promise<string> {\n const versionInfo = await this.getVersionInfo(installerVersion);\n const electronVersion = versionInfo.electronVersion;\n if (!electronVersion) {\n throw Error(`${installerVersion} is not an Obsidian installer version.`)\n }\n\n const chromedriverZipPath = await downloadArtifact({\n version: electronVersion,\n artifactName: 'chromedriver',\n cacheRoot: path.join(this.cacheDir, \"chromedriver-legacy\"),\n unsafelyDisableChecksums: true, // the checksums are slow and run even on cache hit.\n });\n\n let chromedriverPath: string\n if (process.platform == \"win32\") {\n chromedriverPath = path.join(path.dirname(chromedriverZipPath), \"chromedriver.exe\");\n } else {\n chromedriverPath = path.join(path.dirname(chromedriverZipPath), \"chromedriver\");\n }\n\n if (!(await fileExists(chromedriverPath))) {\n console.log(`Downloading legacy chromedriver for electron ${electronVersion} ...`)\n await withTmpDir(chromedriverPath, async (tmpDir) => {\n await extractZip(chromedriverZipPath, { dir: tmpDir });\n return path.join(tmpDir, path.basename(chromedriverPath));\n })\n }\n\n return chromedriverPath;\n }\n\n /** Gets the latest version of a plugin. */\n private async getLatestPluginVersion(repo: string) {\n repo = normalizeGitHubRepo(repo)\n const manifestUrl = `https://raw.githubusercontent.com/${repo}/HEAD/manifest.json`;\n const cacheDest = path.join(this.cacheDir, \"obsidian-plugins\", repo, \"latest.json\");\n const manifest = await this.cachedFetch(manifestUrl, cacheDest);\n return manifest.version;\n }\n\n /**\n * Downloads a plugin from a GitHub repo to the cache.\n * @param repo Repo\n * @param version Version of the plugin to install or \"latest\"\n * @returns path to the downloaded plugin\n */\n private async downloadGitHubPlugin(repo: string, version = \"latest\"): Promise<string> {\n repo = normalizeGitHubRepo(repo)\n if (version == \"latest\") {\n version = await this.getLatestPluginVersion(repo);\n }\n if (!semver.valid(version)) {\n throw Error(`Invalid version \"${version}\"`);\n }\n version = semver.valid(version)!;\n\n const pluginDir = path.join(this.cacheDir, \"obsidian-plugins\", repo, version);\n if (!(await fileExists(pluginDir))) {\n await fsAsync.mkdir(path.dirname(pluginDir), { recursive: true });\n await withTmpDir(pluginDir, async (tmpDir) => {\n const assetsToDownload = {'manifest.json': true, 'main.js': true, 'styles.css': false};\n await Promise.all(\n Object.entries(assetsToDownload).map(async ([file, required]) => {\n const url = `https://github.com/${repo}/releases/download/${version}/${file}`;\n const response = await fetch(url);\n if (response.ok) {\n await fsAsync.writeFile(path.join(tmpDir, file), response.body as any);\n } else if (required) {\n throw Error(`No ${file} found for ${repo} version ${version}`)\n }\n })\n )\n return tmpDir;\n });\n }\n\n return pluginDir;\n }\n\n /**\n * Downloads a community plugin to the cache.\n * @param id Id of the plugin\n * @param version Version of the plugin to install, or \"latest\"\n * @returns path to the downloaded plugin\n */\n private async downloadCommunityPlugin(id: string, version = \"latest\"): Promise<string> {\n const communityPlugins = await this.getCommunityPlugins();\n const pluginInfo = communityPlugins.find(p => p.id == id);\n if (!pluginInfo) {\n throw Error(`No plugin with id ${id} found.`);\n }\n return await this.downloadGitHubPlugin(pluginInfo.repo, version);\n }\n\n /**\n * Downloads a list of plugins to the cache and returns a list of `DownloadedPluginEntry` with the downloaded paths.\n * Also adds the `id` property to the plugins based on the manifest.\n * \n * You can download plugins from GitHub using `{repo: \"org/repo\"}` and community plugins using `{id: 'plugin-id'}`.\n * Local plugins will just be passed through.\n * \n * @param plugins List of plugins to download.\n */\n async downloadPlugins(plugins: PluginEntry[]): Promise<DownloadedPluginEntry[]> {\n return await Promise.all(\n plugins.map(async (plugin) => {\n if (typeof plugin == \"object\" && \"originalType\" in plugin) {\n return {...plugin as DownloadedPluginEntry}\n }\n let pluginPath: string\n let originalType: \"local\"|\"github\"|\"community\"\n if (typeof plugin == \"string\") {\n pluginPath = path.resolve(plugin);\n originalType = \"local\";\n } else if (\"path\" in plugin) {;\n pluginPath = path.resolve(plugin.path);\n originalType = \"local\";\n } else if (\"repo\" in plugin) {\n pluginPath = await this.downloadGitHubPlugin(plugin.repo, plugin.version);\n originalType = \"github\";\n } else if (\"id\" in plugin) {\n pluginPath = await this.downloadCommunityPlugin(plugin.id, plugin.version);\n originalType = \"community\";\n } else {\n throw Error(\"You must specify one of plugin path, repo, or id\")\n }\n\n const manifestPath = path.join(pluginPath, \"manifest.json\");\n if (!(await fileExists(manifestPath))) {\n throw Error(`No plugin found at ${pluginPath}`)\n }\n let pluginId = (typeof plugin == \"object\" && (\"id\" in plugin)) ? plugin.id : undefined;\n if (!pluginId) {\n pluginId = JSON.parse(await fsAsync.readFile(manifestPath, 'utf8').catch(() => \"{}\")).id;\n if (!pluginId) {\n throw Error(`${pluginPath}/manifest.json malformed.`);\n }\n }\n\n let enabled: boolean\n if (typeof plugin == \"string\") {\n enabled = true\n } else {\n enabled = plugin.enabled ?? true;\n }\n return {path: pluginPath, id: pluginId, enabled, originalType}\n })\n );\n }\n\n /** Gets the latest version of a theme. */\n private async getLatestThemeVersion(repo: string) {\n repo = normalizeGitHubRepo(repo)\n const manifestUrl = `https://raw.githubusercontent.com/${repo}/HEAD/manifest.json`;\n const cacheDest = path.join(this.cacheDir, \"obsidian-themes\", repo, \"latest.json\");\n const manifest = await this.cachedFetch(manifestUrl, cacheDest);\n return manifest.version;\n }\n\n /**\n * Downloads a theme from a GitHub repo to the cache.\n * @param repo Repo\n * @returns path to the downloaded theme\n */\n private async downloadGitHubTheme(repo: string): Promise<string> {\n repo = normalizeGitHubRepo(repo)\n // Obsidian theme's are just pulled from the repo HEAD, not releases, so we can't really choose a specific \n // version of a theme.\n // We use the manifest.json version to check if the theme has changed.\n const version = await this.getLatestThemeVersion(repo);\n const themeDir = path.join(this.cacheDir, \"obsidian-themes\", repo, version);\n\n if (!(await fileExists(themeDir))) {\n await fsAsync.mkdir(path.dirname(themeDir), { recursive: true });\n await withTmpDir(themeDir, async (tmpDir) => {\n const assetsToDownload = ['manifest.json', 'theme.css'];\n await Promise.all(\n assetsToDownload.map(async (file) => {\n const url = `https://raw.githubusercontent.com/${repo}/HEAD/${file}`;\n const response = await fetch(url);\n if (response.ok) {\n await fsAsync.writeFile(path.join(tmpDir, file), response.body as any);\n } else {\n throw Error(`No ${file} found for ${repo}`);\n }\n })\n )\n return tmpDir;\n });\n }\n\n return themeDir;\n }\n\n /**\n * Downloads a community theme to the cache.\n * @param name name of the theme\n * @returns path to the downloaded theme\n */\n private async downloadCommunityTheme(name: string): Promise<string> {\n const communityThemes = await this.getCommunityThemes();\n const themeInfo = communityThemes.find(p => p.name == name);\n if (!themeInfo) {\n throw Error(`No theme with name ${name} found.`);\n }\n return await this.downloadGitHubTheme(themeInfo.repo);\n }\n\n /**\n * Downloads a list of themes to the cache and returns a list of `DownloadedThemeEntry` with the downloaded paths.\n * Also adds the `name` property to the plugins based on the manifest.\n * \n * You can download themes from GitHub using `{repo: \"org/repo\"}` and community themes using `{name: 'theme-name'}`.\n * Local themes will just be passed through.\n * \n * @param themes List of themes to download\n */\n async downloadThemes(themes: ThemeEntry[]): Promise<DownloadedThemeEntry[]> {\n return await Promise.all(\n themes.map(async (theme) => {\n if (typeof theme == \"object\" && \"originalType\" in theme) {\n return {...theme as DownloadedThemeEntry}\n }\n let themePath: string\n let originalType: \"local\"|\"github\"|\"community\"\n if (typeof theme == \"string\") {\n themePath = path.resolve(theme);\n originalType = \"local\";\n } else if (\"path\" in theme) {;\n themePath = path.resolve(theme.path);\n originalType = \"local\";\n } else if (\"repo\" in theme) {\n themePath = await this.downloadGitHubTheme(theme.repo);\n originalType = \"github\";\n } else if (\"name\" in theme) {\n themePath = await this.downloadCommunityTheme(theme.name);\n originalType = \"community\";\n } else {\n throw Error(\"You must specify one of theme path, repo, or name\")\n }\n\n const manifestPath = path.join(themePath, \"manifest.json\");\n if (!(await fileExists(manifestPath))) {\n throw Error(`No theme found at ${themePath}`)\n }\n let themeName = (typeof theme == \"object\" && (\"name\" in theme)) ? theme.name : undefined;\n if (!themeName) {\n const manifestPath = path.join(themePath, \"manifest.json\");\n themeName = JSON.parse(await fsAsync.readFile(manifestPath, 'utf8').catch(() => \"{}\")).name;\n if (!themeName) {\n throw Error(`${themePath}/manifest.json malformed.`);\n }\n }\n\n let enabled: boolean\n if (typeof theme == \"string\") {\n enabled = true\n } else {\n enabled = theme.enabled ?? true;\n }\n return {path: themePath, name: themeName, enabled: enabled, originalType};\n })\n );\n }\n\n /**\n * Installs plugins into an Obsidian vault\n * @param vault Path to the vault to install the plugins in\n * @param plugins List plugins to install\n */\n async installPlugins(vault: string, plugins: PluginEntry[]) {\n const downloadedPlugins = await this.downloadPlugins(plugins);\n\n const obsidianDir = path.join(vault, '.obsidian');\n await fsAsync.mkdir(obsidianDir, { recursive: true });\n\n const enabledPluginsPath = path.join(obsidianDir, 'community-plugins.json');\n let originalEnabledPlugins: string[] = [];\n if (await fileExists(enabledPluginsPath)) {\n originalEnabledPlugins = JSON.parse(await fsAsync.readFile(enabledPluginsPath, 'utf-8'));\n }\n let enabledPlugins = [...originalEnabledPlugins];\n\n for (const {path: pluginPath, enabled = true, originalType} of downloadedPlugins) {\n const manifestPath = path.join(pluginPath, 'manifest.json');\n const pluginId = JSON.parse(await fsAsync.readFile(manifestPath, 'utf8').catch(() => \"{}\")).id;\n if (!pluginId) {\n throw Error(`${manifestPath} missing or malformed.`);\n }\n\n const pluginDest = path.join(obsidianDir, 'plugins', pluginId);\n await fsAsync.mkdir(pluginDest, { recursive: true });\n\n const files: Record<string, [boolean, boolean]> = {\n \"manifest.json\": [true, true],\n \"main.js\": [true, true],\n \"styles.css\": [false, true],\n \"data.json\": [false, false],\n }\n for (const [file, [required, deleteIfMissing]] of Object.entries(files)) {\n if (await fileExists(path.join(pluginPath, file))) {\n await linkOrCp(path.join(pluginPath, file), path.join(pluginDest, file));\n } else if (required) {\n throw Error(`${pluginPath}/${file} missing.`);\n } else if (deleteIfMissing) {\n await fsAsync.rm(path.join(pluginDest, file), {force: true});\n }\n }\n\n const pluginAlreadyListed = enabledPlugins.includes(pluginId);\n if (enabled && !pluginAlreadyListed) {\n enabledPlugins.push(pluginId)\n } else if (!enabled && pluginAlreadyListed) {\n enabledPlugins = enabledPlugins.filter(p => p != pluginId);\n }\n\n if (originalType == \"local\") {\n // Add a .hotreload file for the https://github.com/pjeby/hot-reload plugin\n await fsAsync.writeFile(path.join(pluginDest, '.hotreload'), '');\n }\n }\n\n if (!_.isEqual(enabledPlugins, originalEnabledPlugins)) {\n await fsAsync.writeFile(enabledPluginsPath, JSON.stringify(enabledPlugins, undefined, 2));\n }\n }\n\n /** \n * Installs themes into an Obsidian vault\n * @param vault Path to the theme to install the themes in\n * @param themes List of themes to install\n */\n async installThemes(vault: string, themes: ThemeEntry[]) {\n const downloadedThemes = await this.downloadThemes(themes);\n\n const obsidianDir = path.join(vault, '.obsidian');\n await fsAsync.mkdir(obsidianDir, { recursive: true });\n\n let enabledTheme: string|undefined = undefined;\n\n for (const {path: themePath, enabled = true} of downloadedThemes) {\n const manifestPath = path.join(themePath, 'manifest.json');\n const cssPath = path.join(themePath, 'theme.css');\n\n const themeName = JSON.parse(await fsAsync.readFile(manifestPath, 'utf8').catch(() => \"{}\")).name;\n if (!themeName) {\n throw Error(`${manifestPath} missing or malformed.`);\n }\n if (!(await fileExists(cssPath))) {\n throw Error(`${cssPath} missing.`);\n }\n\n const themeDest = path.join(obsidianDir, 'themes', themeName);\n await fsAsync.mkdir(themeDest, { recursive: true });\n\n await linkOrCp(manifestPath, path.join(themeDest, \"manifest.json\"));\n await linkOrCp(cssPath, path.join(themeDest, \"theme.css\"));\n\n if (enabledTheme && enabled) {\n throw Error(\"You can only have one enabled theme.\")\n } else if (enabled) {\n enabledTheme = themeName;\n }\n }\n\n if (themes.length > 0) { // Only update appearance.json if we set the themes\n const appearancePath = path.join(obsidianDir, 'appearance.json');\n let appearance: any = {}\n if (await fileExists(appearancePath)) {\n appearance = JSON.parse(await fsAsync.readFile(appearancePath, 'utf-8'));\n }\n appearance.cssTheme = enabledTheme ?? \"\";\n await fsAsync.writeFile(appearancePath, JSON.stringify(appearance, undefined, 2));\n }\n }\n\n /**\n * Sets up the config dir to use for the `--user-data-dir` in obsidian. Returns the path to the created config dir.\n *\n * @param params.appVersion Obsidian app version (see {@link resolveVersions} for format)\n * @param params.installerVersion Obsidian version string.\n * @param params.appPath Path to the asar file to install. Will download if omitted.\n * @param params.vault Path to the vault to open in Obsidian.\n * @param params.dest Destination path for the config dir. If omitted it will create a temporary directory.\n */\n async setupConfigDir(params: {\n appVersion: string, installerVersion: string,\n appPath?: string,\n vault?: string,\n dest?: string,\n }): Promise<string> {\n const [appVersion, installerVersion] = await this.resolveVersions(params.appVersion, params.installerVersion);\n // configDir will be passed to --user-data-dir, so Obsidian is somewhat sandboxed. We set up \"obsidian.json\" so\n // that Obsidian opens the vault by default and doesn't check for updates.\n const configDir = params.dest ?? await makeTmpDir('obs-launcher-config-');\n \n let obsidianJson: any = {\n updateDisabled: true, // Prevents Obsidian trying to auto-update on boot.\n }\n let localStorageData: Record<string, string> = {\n \"most-recently-installed-version\": appVersion, // prevents the changelog page on boot\n }\n\n if (params.vault !== undefined) {\n if (!await fileExists(params.vault)) {\n throw Error(`Vault path ${params.vault} doesn't exist.`)\n }\n const vaultId = crypto.randomBytes(8).toString(\"hex\");\n obsidianJson = {\n ...obsidianJson,\n vaults: {\n [vaultId]: {\n path: path.resolve(params.vault),\n ts: new Date().getTime(),\n open: true,\n },\n },\n };\n localStorageData = {\n ...localStorageData,\n [`enable-plugin-${vaultId}`]: \"true\", // Disable \"safe mode\" and enable plugins\n }\n }\n\n await fsAsync.writeFile(path.join(configDir, 'obsidian.json'), JSON.stringify(obsidianJson));\n\n let appPath = params.appPath;\n if (!appPath) {\n appPath = await this.downloadApp(appVersion);\n }\n await linkOrCp(appPath, path.join(configDir, path.basename(appPath)));\n\n const localStorage = new ChromeLocalStorage(configDir);\n await localStorage.setItems(\"app://obsidian.md\", localStorageData)\n await localStorage.close();\n\n return configDir;\n }\n\n /**\n * Sets up a vault for Obsidian, installing plugins and themes and optionally copying the vault to a temporary\n * directory first.\n * @param params.vault Path to the vault to open in Obsidian\n * @param params.copy Whether to copy the vault to a tmpdir first. Default false\n * @param params.plugins List of plugins to install in the vault\n * @param params.themes List of themes to install in the vault\n * @returns Path to the copied vault (or just the path to the vault if copy is false)\n */\n async setupVault(params: {\n vault: string,\n copy?: boolean,\n plugins?: PluginEntry[], themes?: ThemeEntry[],\n }): Promise<string> {\n let vault = params.vault;\n if (params.copy) {\n const dest = await makeTmpDir('obs-launcher-vault-');\n await fsAsync.cp(vault, dest, { recursive: true, preserveTimestamps: true });\n vault = dest;\n }\n await this.installPlugins(vault, params.plugins ?? []);\n await this.installThemes(vault, params.themes ?? []);\n\n return vault;\n }\n\n /**\n * Downloads and launches Obsidian with a sandboxed config dir and a specifc vault open. Optionally install plugins\n * and themes first.\n * \n * This is just a shortcut for calling `downloadApp`, `downloadInstaller`, `setupVault` and `setupConfDir`.\n *\n * @param params.appVersion Obsidian app version (see {@link resolveVersions} for format). Default \"latest\"\n * @param params.installerVersion Obsidian installer version (see {@link resolveVersions} for format).\n * Default \"latest\"\n * @param params.vault Path to the vault to open in Obsidian\n * @param params.copy Whether to copy the vault to a tmpdir first. Default false\n * @param params.plugins List of plugins to install in the vault\n * @param params.themes List of themes to install in the vault\n * @param params.args CLI args to pass to Obsidian\n * @param params.spawnOptions Options to pass to `spawn`\n * @returns The launched child process and the created tmpdirs\n */\n async launch(params: {\n appVersion?: string, installerVersion?: string,\n copy?: boolean,\n vault?: string,\n plugins?: PluginEntry[], themes?: ThemeEntry[],\n args?: string[],\n spawnOptions?: child_process.SpawnOptions,\n }): Promise<{proc: child_process.ChildProcess, configDir: string, vault?: string}> {\n const [appVersion, installerVersion] = await this.resolveVersions(\n params.appVersion ?? \"latest\",\n params.installerVersion ?? \"latest\",\n );\n const appPath = await this.downloadApp(appVersion);\n const installerPath = await this.downloadInstaller(installerVersion);\n\n let vault = params.vault;\n if (vault) {\n vault = await this.setupVault({\n vault,\n copy: params.copy ?? false,\n plugins: params.plugins, themes: params.themes,\n })\n }\n\n const configDir = await this.setupConfigDir({ appVersion, installerVersion, appPath, vault });\n\n // Spawn child.\n const proc = child_process.spawn(installerPath, [\n `--user-data-dir=${configDir}`,\n ...(params.args ?? []),\n ], {\n ...params.spawnOptions,\n });\n\n return {proc, configDir, vault};\n }\n\n /** \n * Updates the info obsidian-versions.json. The obsidian-versions.json file is used in other launcher commands\n * and in wdio-obsidian-service to get metadata about Obsidian versions in one place such as minInstallerVersion and\n * the internal electron version.\n */\n async updateObsidianVersionInfos(\n original?: ObsidianVersionInfos, { maxInstances = 1 } = {},\n ): Promise<ObsidianVersionInfos> {\n const repo = 'obsidianmd/obsidian-releases';\n\n let commitHistory = await fetchGitHubAPIPaginated(`repos/${repo}/commits`, {\n path: \"desktop-releases.json\",\n since: original?.metadata.commit_date,\n });\n commitHistory.reverse();\n if (original) {\n commitHistory = _.takeRightWhile(commitHistory, c => c.sha != original.metadata.commit_sha);\n }\n \n const fileHistory: any[] = await pool(8, commitHistory, commit =>\n fetch(`https://raw.githubusercontent.com/${repo}/${commit.sha}/desktop-releases.json`).then(r => r.json())\n );\n \n const githubReleases = await fetchGitHubAPIPaginated(`repos/${repo}/releases`);\n \n const versionMap: _.Dictionary<Partial<ObsidianVersionInfo>> = _.keyBy(\n original?.versions ?? [],\n v => v.version,\n );\n \n for (const {beta, ...current} of fileHistory) {\n if (beta && (!versionMap[beta.latestVersion] || versionMap[beta.latestVersion].isBeta)) {\n versionMap[beta.latestVersion] = _.merge({}, versionMap[beta.latestVersion],\n parseObsidianDesktopRelease(beta, true),\n );\n }\n versionMap[current.latestVersion] = _.merge({}, versionMap[current.latestVersion],\n parseObsidianDesktopRelease(current, false),\n )\n }\n \n for (const release of githubReleases) {\n if (versionMap.hasOwnProperty(release.name)) {\n versionMap[release.name] = _.merge({}, versionMap[release.name], parseObsidianGithubRelease(release));\n }\n }\n \n const dependencyVersions = await pool(maxInstances,\n Object.values(versionMap).filter(v => v.downloads?.appImage && !v.chromeVersion),\n async (v) => {\n const binaryPath = await this.downloadInstallerFromVersionInfo(v as ObsidianVersionInfo);\n const electronVersionInfo = await getElectronVersionInfo(v.version!, binaryPath);\n return {...v, ...electronVersionInfo};\n },\n )\n for (const deps of dependencyVersions) {\n versionMap[deps.version!] = _.merge({}, versionMap[deps.version!], deps);\n }\n \n // populate minInstallerVersion and maxInstallerVersion and add corrections\n let minInstallerVersion: string|undefined = undefined;\n let maxInstallerVersion: string|undefined = undefined;\n for (const version of Object.keys(versionMap).sort(semver.compare)) {\n // older versions have 0.0.0 as there min version, which doesn't exist anywhere we can download.\n // we'll set those to the first available installer version.\n if (!minInstallerVersion && versionMap[version].chromeVersion) {\n minInstallerVersion = version;\n }\n if (versionMap[version].downloads!.appImage) {\n maxInstallerVersion = version;\n }\n versionMap[version] = mergeKeepUndefined({}, versionMap[version],\n {\n minInstallerVersion: versionMap[version].minInstallerVersion ?? minInstallerVersion,\n maxInstallerVersion: maxInstallerVersion,\n },\n correctObsidianVersionInfo(versionMap[version]),\n );\n }\n \n const result: ObsidianVersionInfos = {\n metadata: {\n commit_date: commitHistory.at(-1)?.commit.committer.date ?? original?.metadata.commit_date,\n commit_sha: commitHistory.at(-1)?.sha ?? original?.metadata.commit_sha,\n timestamp: original?.metadata.timestamp ?? \"\", // set down below\n },\n versions: Object.values(versionMap)\n .map(normalizeObsidianVersionInfo)\n .sort((a, b) => semver.compare(a.version, b.version)),\n }\n\n // Update timestamp if anything has changed. Also, GitHub will cancel scheduled workflows if the repository is\n // \"inactive\" for 60 days. So we'll update the timestamp every once in a while even if there are no Obsidian\n // updates to make sure there's commit activity in the repo.\n const dayMs = 24 * 60 * 60 * 1000;\n const timeSinceLastUpdate = new Date().getTime() - new Date(original?.metadata.timestamp ?? 0).getTime();\n if (!_.isEqual(original, result) || timeSinceLastUpdate > 29 * dayMs) {\n result.metadata.timestamp = new Date().toISOString();\n }\n\n return result;\n }\n\n /**\n * Returns true if the Obsidian version is already in the cache.\n * @param type on of \"app\" or \"installer\"\n * @param version Obsidian app/installer version (see {@link resolveVersions} for format)\n */\n async isInCache(type: \"app\"|\"installer\", version: string) {\n version = (await this.getVersionInfo(version)).version;\n\n let dest: string\n if (type == \"app\") {\n dest = `obsidian-app/obsidian-${version}.asar`;\n } else { // type == \"installer\"\n const {platform, arch} = process;\n dest =`obsidian-installer/${platform}-${arch}/Obsidian-${version}`;\n }\n\n return (await fileExists(path.join(this.cacheDir, dest)));\n }\n\n /**\n * Returns true if we either have the credentials to download the version or it's already in cache.\n * This is only relevant for Obsidian beta versions, as they require Obsidian insider credentials to download.\n * @param version Obsidian version (see {@link resolveVersions} for format)\n */\n async isAvailable(version: string): Promise<boolean> {\n const versionInfo = await this.getVersionInfo(version);\n const versionExists = !!(versionInfo.downloads.asar && versionInfo.minInstallerVersion)\n\n if (versionInfo.isBeta) {\n const hasCreds = !!(process.env['OBSIDIAN_USERNAME'] && process.env['OBSIDIAN_PASSWORD']);\n const inCache = await this.isInCache('app', versionInfo.version);\n return versionExists && (hasCreds || inCache);\n } else {\n return versionExists;\n }\n }\n}\n","import fsAsync from \"fs/promises\"\nimport path from \"path\"\nimport os from \"os\"\nimport { PromisePool } from '@supercharge/promise-pool'\nimport _ from \"lodash\"\n\n/// Files ///\n\nexport async function fileExists(path: string) {\n try {\n await fsAsync.access(path);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Create tmpdir under the system temporary directory.\n * @param prefix \n * @returns \n */\nexport async function makeTmpDir(prefix?: string) {\n return fsAsync.mkdtemp(path.join(os.tmpdir(), prefix ?? 'tmp-'));\n}\n\n/**\n * Handles creating a file \"atomically\" by creating a tmpDir, then downloading or otherwise creating the file under it,\n * then renaming it to the final location when done.\n * @param dest Path the file should end up at.\n * @param func Function takes path to a temporary directory it can use as scratch space. The path it returns will be\n * moved to `dest`. If no path is returned, it will move the whole tmpDir to dest.\n */\nexport async function withTmpDir(dest: string, func: (tmpDir: string) => Promise<string|void>): Promise<void> {\n dest = path.resolve(dest);\n const tmpDir = await fsAsync.mkdtemp(path.join(path.dirname(dest), `.${path.basename(dest)}.tmp.`));\n try {\n let result = await func(tmpDir) ?? tmpDir;\n if (!path.isAbsolute(result)) {\n result = path.join(tmpDir, result);\n } else if (!path.resolve(result).startsWith(tmpDir)) {\n throw new Error(`Returned path ${result} not under tmpDir`)\n }\n // rename will overwrite files but not directories\n if (await fileExists(dest) && (await fsAsync.stat(dest)).isDirectory()) {\n await fsAsync.rename(dest, tmpDir + \".old\")\n }\n \n await fsAsync.rename(result, dest);\n await fsAsync.rm(tmpDir + \".old\", { recursive: true, force: true });\n } finally {\n await fsAsync.rm(tmpDir, { recursive: true, force: true });\n }\n}\n\n/**\n * Tries to hardlink a file, falls back to copy if it fails\n */\nexport async function linkOrCp(src: string, dest: string) {\n try {\n await fsAsync.link(src, dest);\n } catch {\n await fsAsync.copyFile(src, dest);\n }\n}\n\n\n/// Promises ///\n\nexport async function sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n\n/**\n * Await a promise or reject if it takes longer than timeout.\n */\nexport async function withTimeout<T>(promise: Promise<T>, timeout: number): Promise<T> {\n let timer: NodeJS.Timeout;\n const result = Promise.race([\n promise,\n new Promise<T>((resolve, reject) => timer = setTimeout(() => reject(Error(\"Promise timed out\")), timeout))\n ])\n return result.finally(() => clearTimeout(timer));\n}\n\n/**\n * Wrapper around PromisePool that throws on any error.\n */\nexport async function pool<T, U>(size: number, items: T[], func: (item: T) => Promise<U>): Promise<U[]> {\n const { results } = await PromisePool\n .for(items)\n .withConcurrency(size)\n .handleError(async (error) => { throw error; })\n .useCorrespondingResults()\n .process(func);\n return results as U[];\n}\n\nexport type SuccessResult<T> = {success: true, result: T, error: undefined};\nexport type ErrorResult = {success: false, result: undefined, error: any};\nexport type Maybe<T> = SuccessResult<T>|ErrorResult;\n\n/**\n * Helper for handling asynchronous errors with less hassle.\n */\nexport async function maybe<T>(promise: Promise<T>): Promise<Maybe<T>> {\n return promise\n .then(r => ({success: true, result: r, error: undefined} as const))\n .catch(e => ({success: false, result: undefined, error: e} as const));\n}\n\n\n/**\n * Lodash _.merge but overwrites values with undefined if present, instead of ignoring undefined.\n */\nexport function mergeKeepUndefined(object: any, ...sources: any[]) {\n return _.mergeWith(object, ...sources,\n (objValue: any, srcValue: any, key: any, obj: any) => {\n if (_.isPlainObject(obj) && objValue !== srcValue && srcValue === undefined) {\n obj[key] = srcValue\n }\n }\n );\n}","import _ from \"lodash\"\nimport fetch from \"node-fetch\";\nimport fsAsync from \"fs/promises\";\nimport { fileURLToPath } from \"url\";\n\n\n/**\n * GitHub API stores pagination information in the \"Link\" header. The header looks like this:\n * ```\n * <https://api.github.com/repositories/1300192/issues?page=2>; rel=\"prev\", <https://api.github.com/repositories/1300192/issues?page=4>; rel=\"next\"\n * ```\n */\nexport function parseLinkHeader(linkHeader: string): Record<string, Record<string, string>> {\n function parseLinkData(linkData: string) {\n return Object.fromEntries(\n linkData.split(\";\").flatMap(x => {\n const partMatch = x.trim().match(/^([^=]+?)\\s*=\\s*\"?([^\"]+)\"?$/);\n return partMatch ? [[partMatch[1], partMatch[2]]] : [];\n })\n )\n }\n\n const linkDatas = linkHeader\n .split(/,\\s*(?=<)/)\n .flatMap(link => {\n const linkMatch = link.trim().match(/^<([^>]*)>(.*)$/);\n if (linkMatch) {\n return [{\n url: linkMatch[1],\n ...parseLinkData(linkMatch[2]),\n } as Record<string, string>];\n } else {\n return [];\n }\n })\n .filter(l => l.rel)\n return Object.fromEntries(linkDatas.map(l => [l.rel, l]));\n};\n\n\nfunction createURL(url: string, base: string, params: Record<string, any> = {}) {\n params =_.pickBy(params, x => x !== undefined);\n const urlObj = new URL(url, base);\n const searchParams = new URLSearchParams({...Object.fromEntries(urlObj.searchParams), ...params});\n if ([...searchParams].length > 0) {\n urlObj.search = '?' + searchParams;\n }\n return urlObj.toString();\n}\n\n\n/**\n * Fetch from the GitHub API. Uses GITHUB_TOKEN if available. You can access the API without a token, but will hit\n * the usage caps very quickly.\n */\nexport async function fetchGitHubAPI(url: string, params: Record<string, any> = {}) {\n url = createURL(url, \"https://api.github.com\", params)\n const token = process.env.GITHUB_TOKEN;\n const headers: Record<string, string> = token ? {Authorization: \"Bearer \" + token} : {};\n const response = await fetch(url, { headers });\n if (!response.ok) {\n throw new Error(`GitHub API error: ${await response.text()}`);\n }\n return await response;\n}\n\n\n/**\n * Fetch all data from a paginated GitHub API request.\n */\nexport async function fetchGitHubAPIPaginated(url: string, params: Record<string, any> = {}) {\n const results = [];\n let next: string|undefined = createURL(url, \"https://api.github.com\", { per_page: 100, ...params });\n while (next) {\n const response = await fetchGitHubAPI(next);\n results.push(...await response.json() as any);\n next = parseLinkHeader(response.headers.get('link') ?? '').next?.url;\n }\n return results;\n}\n\n/**\n * Fetch from the Obsidian API to download insider versions. Uses OBSIDIAN_USERNAME and\n * OBSIDIAN_PASSWORD environment variables.\n */\nexport async function fetchObsidianAPI(url: string) {\n url = createURL(url, \"https://releases.obsidian.md\");\n\n const username = process.env.OBSIDIAN_USERNAME;\n const password = process.env.OBSIDIAN_PASSWORD;\n if (!username || !password) {\n throw Error(\"OBSIDIAN_USERNAME or OBSIDIAN_PASSWORD environment variables are required to access the Obsidian API for beta versions.\")\n }\n\n const response = await fetch(url, {\n headers: {\n // For some reason you have to set the User-Agent or it won't let you download\n 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36',\n \"Origin\": \"app://obsidian.md\",\n 'Authorization': 'Basic ' + btoa(username + \":\" + password),\n },\n })\n return response;\n}\n\n\n/**\n * Fetches a URL returning its content as a string. Throws if response is not OK.\n * URL can be a file url.\n */\nexport async function fetchWithFileUrl(url: string) {\n if (url.startsWith(\"file:\")) {\n return await fsAsync.readFile(fileURLToPath(url), 'utf-8');\n } else {\n const response = await fetch(url);\n if (response.ok) {\n return response.text()\n } else {\n throw Error(`Request failed with ${response.status}: ${response.text()}`)\n }\n }\n}\n","import path from \"path\"\nimport { ClassicLevel } from \"classic-level\"\n\n\n/**\n * Class to directly manipulate chrome/electron local storage.\n *\n * Normally you'd just manipulate `localStorage` directly during the webdriver tests. However, there's not a built in\n * way to set up localStorage values *before* the app boots. We need to set `enable-plugins` and some other keys for\n * Obsidian to read during the boot process. This class lets us setup the local storage before launching Obsidian.\n */\nexport default class ChromeLocalStorage {\n private db: ClassicLevel;\n\n /** Pass the path to the user data dir for Chrome/Electron. If it doesn't exist it will be created. */\n constructor(public readonly userDataDir: string) {\n this.db = new ClassicLevel(path.join(userDataDir, 'Local Storage/leveldb/'));\n }\n\n private encodeKey = (domain: string, key: string) => `_${domain}\\u0000\\u0001${key}`;\n private decodeKey = (key: string) => key.slice(1).split(\"\\u0000\\u0001\") as [string, string];\n private encodeValue = (value: string) => `\\u0001${value}`;\n private decodeValue = (value: string) => value.slice(1);\n\n /**\n * Get a value from localStorage\n * @param domain Domain the value is under, e.g. \"https://example.com\" or \"app://obsidian.md\"\n * @param key Key to retreive\n */\n async getItem(domain: string, key: string): Promise<string|null> {\n const value = await this.db.get(this.encodeKey(domain, key));\n return (value === undefined) ? null : this.decodeValue(value);\n }\n\n /**\n * Set a value in localStorage\n * @param domain Domain the value is under, e.g. \"https://example.com\" or \"app://obsidian.md\"\n * @param key Key to set\n * @param value Value to set\n */\n async setItem(domain: string, key: string, value: string) {\n await this.db.put(this.encodeKey(domain, key), this.encodeValue(value))\n }\n\n /**\n * Removes a key from localStorage\n * @param domain Domain the values is under, e.g. \"https://example.com\" or \"app://obsidian.md\"\n * @param key key to remove.\n */\n async removeItem(domain: string, key: string) {\n await this.db.del(this.encodeKey(domain, key))\n }\n\n /** Get all items in localStorage as [domain, key, value] tuples */\n async getAllItems(): Promise<[string, string, string][]> {\n const result: [string, string, string][] = []\n for await (const pair of this.db.iterator()) {\n if (pair[0].startsWith(\"_\")) { // ignore the META values\n const [domain, key] = this.decodeKey(pair[0]);\n const value = this.decodeValue(pair[1]);\n result.push([domain, key, value]);\n }\n }\n return result;\n }\n\n /**\n * Write multiple values to localStorage in batch\n * @param domain Domain the values are under, e.g. \"https://example.com\" or \"app://obsidian.md\"\n * @param data key/value mapping to write\n */\n async setItems(domain: string, data: Record<string, string>) {\n await this.db.batch(\n Object.entries(data).map(([key, value]) => ({\n type: \"put\",\n key: this.encodeKey(domain, key),\n value: this.encodeValue(value),\n }))\n )\n }\n\n /**\n * Close the localStorage database.\n */\n async close() {\n await this.db.close();\n }\n}\n","import fsAsync from \"fs/promises\"\nimport path from \"path\"\nimport { promisify } from \"util\";\nimport child_process from \"child_process\"\nimport which from \"which\"\nimport semver from \"semver\"\nimport _ from \"lodash\"\nimport CDP from 'chrome-remote-interface'\nimport { makeTmpDir, withTmpDir, maybe, withTimeout, sleep } from \"./utils.js\";\nimport { ObsidianVersionInfo } from \"./types.js\";\nconst execFile = promisify(child_process.execFile);\n\n\nexport function normalizeGitHubRepo(repo: string) {\n return repo.replace(/^(https?:\\/\\/)?(github.com\\/)/, '')\n}\n\n/**\n * Running AppImage requires libfuse2, extracting the AppImage first avoids that.\n */\nexport async function extractObsidianAppImage(appImage: string, dest: string) {\n await withTmpDir(dest, async (tmpDir) => {\n await fsAsync.chmod(appImage, 0o755);\n await execFile(appImage, [\"--appimage-extract\"], {cwd: tmpDir});\n return path.join(tmpDir, 'squashfs-root');\n })\n}\n\n/**\n * Obsidian appears to use NSIS to bundle their Window's installers. We want to extract the executable\n * files directly without running the installer. 7zip can extract the raw files from the exe.\n */\nexport async function extractObsidianExe(exe: string, appArch: string, dest: string) {\n const path7z = await which(\"7z\", { nothrow: true });\n if (!path7z) {\n throw new Error(\n \"Downloading Obsidian for Windows requires 7zip to be installed and available on the PATH. \" +\n \"You install it from https://www.7-zip.org and then add the install location to the PATH.\"\n );\n }\n exe = path.resolve(exe);\n // The installer contains several `.7z` files with files for different architectures \n const subArchive = path.join('$PLUGINSDIR', appArch + \".7z\");\n dest = path.resolve(dest);\n\n await withTmpDir(dest, async (tmpDir) => {\n const extractedInstaller = path.join(tmpDir, \"installer\");\n await execFile(path7z, [\"x\", \"-o\" + extractedInstaller, exe, subArchive]);\n const extractedObsidian = path.join(tmpDir, \"obsidian\");\n await execFile(path7z, [\"x\", \"-o\" + extractedObsidian, path.join(extractedInstaller, subArchive)]);\n return extractedObsidian;\n })\n}\n\n/**\n * Extract the executable from the Obsidian dmg installer.\n */\nexport async function extractObsidianDmg(dmg: string, dest: string) {\n dest = path.resolve(dest);\n\n await withTmpDir(dest, async (tmpDir) => {\n const proc = await execFile('hdiutil', ['attach', '-nobrowse', '-readonly', dmg]);\n const volume = proc.stdout.match(/\\/Volumes\\/.*$/m)![0];\n const obsidianApp = path.join(volume, \"Obsidian.app\");\n try {\n await fsAsync.cp(obsidianApp, tmpDir, {recursive: true, verbatimSymlinks: true});\n } finally {\n await execFile('hdiutil', ['detach', volume]);\n }\n return tmpDir;\n })\n}\n\n\nexport function parseObsidianDesktopRelease(fileRelease: any, isBeta: boolean): Partial<ObsidianVersionInfo> {\n return {\n version: fileRelease.latestVersion,\n minInstallerVersion: fileRelease.minimumVersion != '0.0.0' ? fileRelease.minimumVersion : undefined,\n isBeta: isBeta,\n downloads: {\n asar: fileRelease.downloadUrl,\n },\n };\n}\n\nexport function parseObsidianGithubRelease(gitHubRelease: any): Partial<ObsidianVersionInfo> {\n const version = gitHubRelease.name;\n const assets: string[] = gitHubRelease.assets.map((a: any) => a.browser_download_url);\n const downloads = {\n appImage: assets.find(u => u.match(`${version}.AppImage$`)),\n appImageArm: assets.find(u => u.match(`${version}-arm64.AppImage$`)),\n apk: assets.find(u => u.match(`${version}.apk$`)),\n asar: assets.find(u => u.match(`${version}.asar.gz$`)),\n dmg: assets.find(u => u.match(`${version}(-universal)?.dmg$`)),\n exe: assets.find(u => u.match(`${version}.exe$`)),\n }\n\n return {\n version: version,\n gitHubRelease: gitHubRelease.html_url,\n downloads: downloads,\n }\n}\n\n/**\n * Extract electron and chrome versions for an Obsidian version.\n */\nexport async function getElectronVersionInfo(\n version:string, binaryPath: string,\n): Promise<Partial<ObsidianVersionInfo>> {\n console.log(`${version}: Retrieving electron & chrome versions...`);\n\n const configDir = await makeTmpDir('fetch-obsidian-versions-');\n\n const proc = child_process.spawn(binaryPath, [\n `--remote-debugging-port=0`, // 0 will make it choose a random available port\n '--test-type=webdriver',\n `--user-data-dir=${configDir}`,\n '--no-sandbox', // Workaround for SUID issue, see https://github.com/electron/electron/issues/42510\n ]);\n const procExit = new Promise<number>((resolve) => proc.on('exit', (code) => resolve(code ?? -1)));\n // proc.stdout.on('data', data => console.log(`stdout: ${data}`));\n // proc.stderr.on('data', data => console.log(`stderr: ${data}`));\n\n let dependencyVersions: any;\n try {\n // Wait for the logs showing that Obsidian is ready, and pull the chosen DevTool Protocol port from it\n const portPromise = new Promise<number>((resolve, reject) => {\n procExit.then(() => reject(\"Processed ended without opening a port\"))\n proc.stderr.on('data', data => {\n const port = data.toString().match(/ws:\\/\\/[\\w.]+?:(\\d+)/)?.[1];\n if (port) {\n resolve(Number(port));\n }\n });\n })\n\n const port = await maybe(withTimeout(portPromise, 10 * 1000));\n if (!port.success) {\n throw new Error(\"Timed out waiting for Chrome DevTools protocol port\");\n }\n const client = await CDP({port: port.result});\n const response = await client.Runtime.evaluate({ expression: \"JSON.stringify(process.versions)\" });\n dependencyVersions = JSON.parse(response.result.value);\n await client.close();\n } finally {\n proc.kill(\"SIGTERM\");\n const timeout = await maybe(withTimeout(procExit, 4 * 1000));\n if (!timeout.success) {\n console.log(`${version}: Stuck process ${proc.pid}, using SIGKILL`);\n proc.kill(\"SIGKILL\");\n }\n await procExit;\n await sleep(1000); // Need to wait a bit or sometimes the rm fails because something else is writing to it\n await fsAsync.rm(configDir, { recursive: true, force: true });\n }\n\n if (!dependencyVersions?.electron || !dependencyVersions?.chrome) {\n throw Error(`Failed to extract electron and chrome versions for ${version}`)\n }\n\n return {\n electronVersion: dependencyVersions.electron,\n chromeVersion: dependencyVersions.chrome,\n nodeVersion: dependencyVersions.node,\n };\n}\n\n/**\n * Add some corrections to the Obsidian version data.\n */\nexport function correctObsidianVersionInfo(versionInfo: Partial<ObsidianVersionInfo>): Partial<ObsidianVersionInfo> {\n const corrections: Partial<ObsidianVersionInfo>[] = [\n // These version's downloads are missing or broken.\n {version: '0.12.16', downloads: { asar: undefined }},\n {version: '1.4.7', downloads: { asar: undefined }},\n {version: '1.4.8', downloads: { asar: undefined }},\n \n // The minInstallerVersion here is incorrect\n {version: \"1.3.4\", minInstallerVersion: \"0.14.5\"},\n {version: \"1.3.3\", minInstallerVersion: \"0.14.5\"},\n {version: \"1.3.2\", minInstallerVersion: \"0.14.5\"},\n {version: \"1.3.1\", minInstallerVersion: \"0.14.5\"},\n {version: \"1.3.0\", minInstallerVersion: \"0.14.5\"},\n ]\n\n const result = corrections.find(v => v.version == versionInfo.version) ?? {};\n // minInstallerVersion is incorrect, running Obsidian with installer older than 1.1.9 won't boot with errors like\n // `(node:11592) electron: Failed to load URL: app://obsidian.md/starter.html with error: ERR_BLOCKED_BY_CLIENT`\n if (semver.gte(versionInfo.version!, \"1.5.3\") && semver.lt(versionInfo.minInstallerVersion!, \"1.1.9\")) {\n result.minInstallerVersion = \"1.1.9\"\n }\n\n return result;\n}\n\n/**\n * Normalize order and remove undefined values.\n */\nexport function normalizeObsidianVersionInfo(versionInfo: Partial<ObsidianVersionInfo>): ObsidianVersionInfo {\n versionInfo = {\n version: versionInfo.version,\n minInstallerVersion: versionInfo.minInstallerVersion,\n maxInstallerVersion: versionInfo.maxInstallerVersion,\n isBeta: versionInfo.isBeta,\n gitHubRelease: versionInfo.gitHubRelease,\n downloads: {\n asar: versionInfo.downloads?.asar,\n appImage: versionInfo.downloads?.appImage,\n appImageArm: versionInfo.downloads?.appImageArm,\n apk: versionInfo.downloads?.apk,\n dmg: versionInfo.downloads?.dmg,\n exe: versionInfo.downloads?.exe,\n },\n electronVersion: versionInfo.electronVersion,\n chromeVersion: versionInfo.chromeVersion,\n nodeVersion: versionInfo.nodeVersion,\n };\n versionInfo.downloads = _.omitBy(versionInfo.downloads, _.isUndefined);\n versionInfo = _.omitBy(versionInfo, _.isUndefined);\n return versionInfo as ObsidianVersionInfo;\n}\n"]}
@@ -423,10 +423,11 @@ import _4 from "lodash";
423
423
  var ObsidianLauncher = class {
424
424
  /**
425
425
  * Construct an ObsidianLauncher.
426
- * @param cacheDir Path to the cache directory. Defaults to "OBSIDIAN_CACHE" env var or ".obsidian-cache".
427
- * @param versionsUrl Custom `obsidian-versions.json` url. Can be a file URL.
428
- * @param communityPluginsUrl Custom `community-plugins.json` url. Can be a file URL.
429
- * @param communityThemes Custom `community-css-themes.json` url. Can be a file URL.
426
+ * @param options.cacheDir Path to the cache directory. Defaults to "OBSIDIAN_CACHE" env var or ".obsidian-cache".
427
+ * @param options.versionsUrl Custom `obsidian-versions.json` url. Can be a file URL.
428
+ * @param options.communityPluginsUrl Custom `community-plugins.json` url. Can be a file URL.
429
+ * @param options.communityThemesUrl Custom `community-css-themes.json` url. Can be a file URL.
430
+ * @param options.cacheDuration If the cached version list is older than this (in ms), refetch it. Defaults to 30 minutes.
430
431
  */
431
432
  constructor(options = {}) {
432
433
  this.cacheDir = path4.resolve(options.cacheDir ?? process.env.OBSIDIAN_CACHE ?? "./.obsidian-cache");
@@ -436,18 +437,19 @@ var ObsidianLauncher = class {
436
437
  this.communityPluginsUrl = options.communityPluginsUrl ?? defaultCommunityPluginsUrl;
437
438
  const defaultCommunityThemesUrl = "https://raw.githubusercontent.com/obsidianmd/obsidian-releases/HEAD/community-css-themes.json";
438
439
  this.communityThemesUrl = options.communityThemesUrl ?? defaultCommunityThemesUrl;
440
+ this.cacheDuration = options.cacheDuration ?? 30 * 60 * 1e3;
439
441
  this.metadataCache = {};
440
442
  }
441
443
  /**
442
444
  * Returns file content fetched from url as JSON. Caches content to dest and uses that cache if its more recent than
443
445
  * cacheDuration ms or if there are network errors.
444
446
  */
445
- async cachedFetch(url, dest, { cacheDuration = 30 * 60 * 1e3 } = {}) {
447
+ async cachedFetch(url, dest) {
446
448
  dest = path4.resolve(dest);
447
449
  if (!(dest in this.metadataCache)) {
448
450
  let fileContent;
449
451
  const mtime = await fileExists(dest) ? (await fsAsync4.stat(dest)).mtime : void 0;
450
- if (mtime && (/* @__PURE__ */ new Date()).getTime() - mtime.getTime() < cacheDuration) {
452
+ if (mtime && (/* @__PURE__ */ new Date()).getTime() - mtime.getTime() < this.cacheDuration) {
451
453
  fileContent = await fsAsync4.readFile(dest, "utf-8");
452
454
  } else {
453
455
  const request = await maybe(fetchWithFileUrl(url));
@@ -470,6 +472,9 @@ var ObsidianLauncher = class {
470
472
  }
471
473
  return this.metadataCache[dest];
472
474
  }
475
+ /**
476
+ * Get parsed content of the current project's manifest.json
477
+ */
473
478
  async getRootManifest() {
474
479
  if (!("manifest.json" in this.metadataCache)) {
475
480
  const root = path4.parse(process.cwd()).root;
@@ -486,27 +491,36 @@ var ObsidianLauncher = class {
486
491
  }
487
492
  return this.metadataCache["manifest.json"];
488
493
  }
489
- /** Get information about all available Obsidian versions. */
494
+ /**
495
+ * Get information about all available Obsidian versions.
496
+ */
490
497
  async getVersions() {
491
498
  const dest = path4.join(this.cacheDir, "obsidian-versions.json");
492
499
  return (await this.cachedFetch(this.versionsUrl, dest)).versions;
493
500
  }
494
- /** Get information about all available community plugins. */
501
+ /**
502
+ * Get information about all available community plugins.
503
+ */
495
504
  async getCommunityPlugins() {
496
505
  const dest = path4.join(this.cacheDir, "obsidian-community-plugins.json");
497
506
  return await this.cachedFetch(this.communityPluginsUrl, dest);
498
507
  }
499
- /** Get information about all available community themes. */
508
+ /**
509
+ * Get information about all available community themes.
510
+ */
500
511
  async getCommunityThemes() {
501
512
  const dest = path4.join(this.cacheDir, "obsidian-community-css-themes.json");
502
513
  return await this.cachedFetch(this.communityThemesUrl, dest);
503
514
  }
504
515
  /**
505
516
  * Resolves Obsidian app and installer version strings to absolute versions.
506
- * @param appVersion Obsidian version string or "latest", "latest-beta" or "earliest". "earliest" will use the
507
- * minAppVersion set in your manifest.json.
508
- * @param installerVersion Obsidian version string or "latest" or "earliest". "earliest" will use the minimum
509
- * installer version compatible with the appVersion.
517
+ * @param appVersion Obsidian version string or one of
518
+ * - "latest": Get the current latest non-beta Obsidian version
519
+ * - "latest-beta": Get the current latest beta Obsidian version (or latest is there is no current beta)
520
+ * - "earliest": Get the `minAppVersion` set in set in your `manifest.json`
521
+ * @param installerVersion Obsidian version string or one of
522
+ * - "latest": Get the latest Obsidian installer
523
+ * - "earliest": Get the oldest Obsidian installer compatible with the specified Obsidian app version
510
524
  * @returns [appVersion, installerVersion] with any "latest" etc. resolved to specific versions.
511
525
  */
512
526
  async resolveVersions(appVersion, installerVersion = "latest") {
@@ -535,32 +549,31 @@ var ObsidianLauncher = class {
535
549
  }
536
550
  /**
537
551
  * Gets details about an Obsidian version.
538
- * @param version Obsidian version string or "latest", "earliest", or "latest-beta". "earliest" will use the
539
- * minAppVersion set in your manifest.json.
552
+ * @param appVersion Obsidian app version (see {@link resolveVersions} for format)
540
553
  */
541
- async getVersionInfo(version) {
554
+ async getVersionInfo(appVersion) {
542
555
  const versions = await this.getVersions();
543
- if (version == "latest-beta") {
544
- version = versions.at(-1).version;
545
- } else if (version == "latest") {
546
- version = versions.filter((v) => !v.isBeta).at(-1).version;
547
- } else if (version == "earliest") {
548
- version = (await this.getRootManifest())?.minAppVersion;
549
- if (!version) {
550
- throw Error('Unable to resolve Obsidian app version "earliest", no manifest.json or minAppVersion found.');
556
+ if (appVersion == "latest-beta") {
557
+ appVersion = versions.at(-1).version;
558
+ } else if (appVersion == "latest") {
559
+ appVersion = versions.filter((v) => !v.isBeta).at(-1).version;
560
+ } else if (appVersion == "earliest") {
561
+ appVersion = (await this.getRootManifest())?.minAppVersion;
562
+ if (!appVersion) {
563
+ throw Error('Unable to resolve Obsidian app appVersion "earliest", no manifest.json or minAppVersion found.');
551
564
  }
552
565
  } else {
553
- version = semver2.valid(version) ?? version;
566
+ appVersion = semver2.valid(appVersion) ?? appVersion;
554
567
  }
555
- const versionInfo = versions.find((v) => v.version == version);
568
+ const versionInfo = versions.find((v) => v.version == appVersion);
556
569
  if (!versionInfo) {
557
- throw Error(`No Obsidian app version ${version} found`);
570
+ throw Error(`No Obsidian app version ${appVersion} found`);
558
571
  }
559
572
  return versionInfo;
560
573
  }
561
574
  /**
562
575
  * Downloads the Obsidian installer for the given version and platform. Returns the file path.
563
- * @param installerVersion Version to download.
576
+ * @param installerVersion Obsidian installer version to download. (see {@link resolveVersions} for format)
564
577
  */
565
578
  async downloadInstaller(installerVersion) {
566
579
  const installerVersionInfo = await this.getVersionInfo(installerVersion);
@@ -640,7 +653,11 @@ var ObsidianLauncher = class {
640
653
  }
641
654
  /**
642
655
  * Downloads the Obsidian asar for the given version and platform. Returns the file path.
643
- * @param appVersion Version to download.
656
+ *
657
+ * To download beta versions you'll need to have an Obsidian account with Catalyst and set the `OBSIDIAN_USERNAME`
658
+ * and `OBSIDIAN_PASSWORD` environment variables. 2FA needs to be disabled.
659
+ *
660
+ * @param appVersion Obsidian version to download (see {@link resolveVersions} for format)
644
661
  */
645
662
  async downloadApp(appVersion) {
646
663
  const appVersionInfo = await this.getVersionInfo(appVersion);
@@ -669,10 +686,11 @@ var ObsidianLauncher = class {
669
686
  *
670
687
  * wdio will download chromedriver from the Chrome for Testing API automatically (see
671
688
  * https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints). However, Google has only put
672
- * chromedriver since v115.0.5763.0 in that API, so wdio can't download older versions of chromedriver. As of
673
- * Obsidian v1.7.7, minInstallerVersion is v0.14.5 which runs on chromium v100.0.4896.75. Here we download
674
- * chromedriver for older versions ourselves using the @electron/get package which fetches it from
675
- * https://github.com/electron/electron/releases.
689
+ * chromedriver since v115.0.5763.0 in that API, so wdio can't automatically download older versions of chromedriver
690
+ * for old Electron versions. Here we download chromedriver for older versions ourselves using the @electron/get
691
+ * package which fetches chromedriver from https://github.com/electron/electron/releases.
692
+ *
693
+ * @param installerVersion Obsidian installer version (see {@link resolveVersions} for format)
676
694
  */
677
695
  async downloadChromedriver(installerVersion) {
678
696
  const versionInfo = await this.getVersionInfo(installerVersion);
@@ -761,11 +779,13 @@ var ObsidianLauncher = class {
761
779
  return await this.downloadGitHubPlugin(pluginInfo.repo, version);
762
780
  }
763
781
  /**
764
- * Downloads a list of plugins to the cache and returns a list of LocalPluginEntry with the downloaded paths.
782
+ * Downloads a list of plugins to the cache and returns a list of `DownloadedPluginEntry` with the downloaded paths.
765
783
  * Also adds the `id` property to the plugins based on the manifest.
766
784
  *
767
785
  * You can download plugins from GitHub using `{repo: "org/repo"}` and community plugins using `{id: 'plugin-id'}`.
768
786
  * Local plugins will just be passed through.
787
+ *
788
+ * @param plugins List of plugins to download.
769
789
  */
770
790
  async downloadPlugins(plugins) {
771
791
  return await Promise.all(
@@ -802,7 +822,12 @@ var ObsidianLauncher = class {
802
822
  throw Error(`${pluginPath}/manifest.json malformed.`);
803
823
  }
804
824
  }
805
- const enabled = typeof plugin == "string" ? true : plugin.enabled;
825
+ let enabled;
826
+ if (typeof plugin == "string") {
827
+ enabled = true;
828
+ } else {
829
+ enabled = plugin.enabled ?? true;
830
+ }
806
831
  return { path: pluginPath, id: pluginId, enabled, originalType };
807
832
  })
808
833
  );
@@ -858,11 +883,13 @@ var ObsidianLauncher = class {
858
883
  return await this.downloadGitHubTheme(themeInfo.repo);
859
884
  }
860
885
  /**
861
- * Downloads a list of themes to the cache and returns a list of LocalThemeEntry with the downloaded paths.
886
+ * Downloads a list of themes to the cache and returns a list of `DownloadedThemeEntry` with the downloaded paths.
862
887
  * Also adds the `name` property to the plugins based on the manifest.
863
888
  *
864
889
  * You can download themes from GitHub using `{repo: "org/repo"}` and community themes using `{name: 'theme-name'}`.
865
890
  * Local themes will just be passed through.
891
+ *
892
+ * @param themes List of themes to download
866
893
  */
867
894
  async downloadThemes(themes) {
868
895
  return await Promise.all(
@@ -900,15 +927,20 @@ var ObsidianLauncher = class {
900
927
  throw Error(`${themePath}/manifest.json malformed.`);
901
928
  }
902
929
  }
903
- const enabled = typeof theme == "string" ? true : theme.enabled;
930
+ let enabled;
931
+ if (typeof theme == "string") {
932
+ enabled = true;
933
+ } else {
934
+ enabled = theme.enabled ?? true;
935
+ }
904
936
  return { path: themePath, name: themeName, enabled, originalType };
905
937
  })
906
938
  );
907
939
  }
908
940
  /**
909
- * Installs plugins into an Obsidian vault.
910
- * @param vault Path to the vault to install the plugin in.
911
- * @param plugins List plugins paths to install.
941
+ * Installs plugins into an Obsidian vault
942
+ * @param vault Path to the vault to install the plugins in
943
+ * @param plugins List plugins to install
912
944
  */
913
945
  async installPlugins(vault, plugins) {
914
946
  const downloadedPlugins = await this.downloadPlugins(plugins);
@@ -958,9 +990,9 @@ var ObsidianLauncher = class {
958
990
  }
959
991
  }
960
992
  /**
961
- * Installs themes into an obsidian vault.
962
- * @param vault Path to the theme to install the plugin in.
963
- * @param themes: List of themes to install.
993
+ * Installs themes into an Obsidian vault
994
+ * @param vault Path to the theme to install the themes in
995
+ * @param themes List of themes to install
964
996
  */
965
997
  async installThemes(vault, themes) {
966
998
  const downloadedThemes = await this.downloadThemes(themes);
@@ -998,13 +1030,13 @@ var ObsidianLauncher = class {
998
1030
  }
999
1031
  }
1000
1032
  /**
1001
- * Sets up the config dir to use for the --user-data-dir in obsidian. Returns the path to the created config dir.
1033
+ * Sets up the config dir to use for the `--user-data-dir` in obsidian. Returns the path to the created config dir.
1002
1034
  *
1003
- * @param appVersion Obsidian version string.
1004
- * @param installerVersion Obsidian version string.
1005
- * @param appPath Path to the asar file to install. Will download if omitted.
1006
- * @param vault Path to the vault to open in Obsidian.
1007
- * @param dest Destination path for the config dir. If omitted it will create it under `/tmp`.
1035
+ * @param params.appVersion Obsidian app version (see {@link resolveVersions} for format)
1036
+ * @param params.installerVersion Obsidian version string.
1037
+ * @param params.appPath Path to the asar file to install. Will download if omitted.
1038
+ * @param params.vault Path to the vault to open in Obsidian.
1039
+ * @param params.dest Destination path for the config dir. If omitted it will create a temporary directory.
1008
1040
  */
1009
1041
  async setupConfigDir(params) {
1010
1042
  const [appVersion, installerVersion] = await this.resolveVersions(params.appVersion, params.installerVersion);
@@ -1018,6 +1050,9 @@ var ObsidianLauncher = class {
1018
1050
  // prevents the changelog page on boot
1019
1051
  };
1020
1052
  if (params.vault !== void 0) {
1053
+ if (!await fileExists(params.vault)) {
1054
+ throw Error(`Vault path ${params.vault} doesn't exist.`);
1055
+ }
1021
1056
  const vaultId = crypto.randomBytes(8).toString("hex");
1022
1057
  obsidianJson = {
1023
1058
  ...obsidianJson,
@@ -1049,17 +1084,17 @@ var ObsidianLauncher = class {
1049
1084
  /**
1050
1085
  * Sets up a vault for Obsidian, installing plugins and themes and optionally copying the vault to a temporary
1051
1086
  * directory first.
1052
- * @param vault Path to the vault to open in Obsidian.
1053
- * @param copy Whether to copy the vault to a tmpdir first. Default false.
1054
- * @param plugins List of plugins to install in the vault.
1055
- * @param themes List of themes to install in the vault.
1087
+ * @param params.vault Path to the vault to open in Obsidian
1088
+ * @param params.copy Whether to copy the vault to a tmpdir first. Default false
1089
+ * @param params.plugins List of plugins to install in the vault
1090
+ * @param params.themes List of themes to install in the vault
1056
1091
  * @returns Path to the copied vault (or just the path to the vault if copy is false)
1057
1092
  */
1058
1093
  async setupVault(params) {
1059
1094
  let vault = params.vault;
1060
1095
  if (params.copy) {
1061
1096
  const dest = await makeTmpDir("obs-launcher-vault-");
1062
- await fsAsync4.cp(vault, dest, { recursive: true });
1097
+ await fsAsync4.cp(vault, dest, { recursive: true, preserveTimestamps: true });
1063
1098
  vault = dest;
1064
1099
  }
1065
1100
  await this.installPlugins(vault, params.plugins ?? []);
@@ -1070,20 +1105,24 @@ var ObsidianLauncher = class {
1070
1105
  * Downloads and launches Obsidian with a sandboxed config dir and a specifc vault open. Optionally install plugins
1071
1106
  * and themes first.
1072
1107
  *
1073
- * This is just a shortcut for calling downloadApp, downloadInstaller, setupVault and setupConfDir.
1108
+ * This is just a shortcut for calling `downloadApp`, `downloadInstaller`, `setupVault` and `setupConfDir`.
1074
1109
  *
1075
- * @param appVersion Obsidian version string.
1076
- * @param installerVersion Obsidian version string.
1077
- * @param vault Path to the vault to open in Obsidian.
1078
- * @param copy Whether to copy the vault to a tmpdir first. Default false.
1079
- * @param plugins List of plugins to install in the vault.
1080
- * @param themes List of themes to install in the vault.
1081
- * @param args CLI args to pass to Obsidian
1082
- * @param spawnOptions Options to pass to `spawn`.
1083
- * @returns The launched child process and the created tmpdirs.
1110
+ * @param params.appVersion Obsidian app version (see {@link resolveVersions} for format). Default "latest"
1111
+ * @param params.installerVersion Obsidian installer version (see {@link resolveVersions} for format).
1112
+ * Default "latest"
1113
+ * @param params.vault Path to the vault to open in Obsidian
1114
+ * @param params.copy Whether to copy the vault to a tmpdir first. Default false
1115
+ * @param params.plugins List of plugins to install in the vault
1116
+ * @param params.themes List of themes to install in the vault
1117
+ * @param params.args CLI args to pass to Obsidian
1118
+ * @param params.spawnOptions Options to pass to `spawn`
1119
+ * @returns The launched child process and the created tmpdirs
1084
1120
  */
1085
1121
  async launch(params) {
1086
- const [appVersion, installerVersion] = await this.resolveVersions(params.appVersion, params.installerVersion);
1122
+ const [appVersion, installerVersion] = await this.resolveVersions(
1123
+ params.appVersion ?? "latest",
1124
+ params.installerVersion ?? "latest"
1125
+ );
1087
1126
  const appPath = await this.downloadApp(appVersion);
1088
1127
  const installerPath = await this.downloadInstaller(installerVersion);
1089
1128
  let vault = params.vault;
@@ -1197,6 +1236,8 @@ var ObsidianLauncher = class {
1197
1236
  }
1198
1237
  /**
1199
1238
  * Returns true if the Obsidian version is already in the cache.
1239
+ * @param type on of "app" or "installer"
1240
+ * @param version Obsidian app/installer version (see {@link resolveVersions} for format)
1200
1241
  */
1201
1242
  async isInCache(type, version) {
1202
1243
  version = (await this.getVersionInfo(version)).version;
@@ -1210,8 +1251,9 @@ var ObsidianLauncher = class {
1210
1251
  return await fileExists(path4.join(this.cacheDir, dest));
1211
1252
  }
1212
1253
  /**
1213
- * Returns true if we either have the credentails to download the version or it's already in cache.
1254
+ * Returns true if we either have the credentials to download the version or it's already in cache.
1214
1255
  * This is only relevant for Obsidian beta versions, as they require Obsidian insider credentials to download.
1256
+ * @param version Obsidian version (see {@link resolveVersions} for format)
1215
1257
  */
1216
1258
  async isAvailable(version) {
1217
1259
  const versionInfo = await this.getVersionInfo(version);
@@ -1229,4 +1271,4 @@ var ObsidianLauncher = class {
1229
1271
  export {
1230
1272
  ObsidianLauncher
1231
1273
  };
1232
- //# sourceMappingURL=chunk-D7KOZRZZ.js.map
1274
+ //# sourceMappingURL=chunk-K7DNIKI5.js.map