@mekuru/platform 0.0.0-stage → 0.1.3

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/README.jp.md ADDED
@@ -0,0 +1,3 @@
1
+ # @mekuru/platform
2
+
3
+ `configDir()` はMekuruの設定ディレクトリを解決します。`openBrowser(url)` はWSLを含むOS別のブラウザ起動を担当します。サービス固有の認証は投稿パッケージに置きます。
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
- # Temporary Holding Version
1
+ # @mekuru/platform
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Shared operating system integration.
4
+
5
+ `configDir()` resolves the Mekuru settings directory. `openBrowser(url)` starts the operating system browser, including WSL. Service-specific authentication belongs to the upload packages.
package/package.json CHANGED
@@ -1,6 +1,16 @@
1
1
  {
2
2
  "name": "@mekuru/platform",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.3",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./src/index.ts"
7
+ },
8
+ "files": [
9
+ "src"
10
+ ],
11
+ "sideEffects": false,
12
+ "dependencies": {},
13
+ "engines": {
14
+ "bun": ">=1.4"
15
+ }
16
+ }
package/src/index.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { existsSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ export const configDir = (): string => {
5
+ if (process.env.MEKURU_CONFIG_DIR) return process.env.MEKURU_CONFIG_DIR;
6
+ if (process.platform === "win32") return join(process.env.APPDATA ?? join(homedir(), "AppData", "Roaming"), "mekuru");
7
+ return join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "mekuru");
8
+ };
9
+
10
+ export const openBrowser = (url: string): void => {
11
+ const wsl = process.platform === "linux" && (!!process.env.WSL_INTEROP || existsSync("/proc/sys/fs/binfmt_misc/WSLInterop"));
12
+ const tries: string[][] = wsl
13
+ ? [["wslview"], ["cmd.exe", "/c", "start", ""]]
14
+ : process.platform === "darwin"
15
+ ? [["open"]]
16
+ : process.platform === "win32"
17
+ ? [["cmd", "/c", "start", ""]]
18
+ : [["xdg-open"]];
19
+ for (const [cmd, ...args] of tries) {
20
+ const target = cmd.startsWith("cmd") ? url.replaceAll("&", "^&") : url;
21
+ try {
22
+ Bun.spawn([cmd, ...args, target], { stdin: "ignore", stdout: "ignore", stderr: "ignore", cwd: wsl ? "/mnt/c" : undefined }).unref();
23
+ break;
24
+ } catch {}
25
+ }
26
+ };