@bitefoundry/obsidian 0.0.0-stage → 0.1.0
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.md +141 -2
- package/bin/obs.js +4 -0
- package/bin/obsidian.js +75 -0
- package/docs/NPM.md +29 -0
- package/package.json +50 -4
- package/scripts/postinstall.mjs +259 -0
package/README.md
CHANGED
|
@@ -1,3 +1,142 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# `@bitefoundry/obsidian`
|
|
4
|
+
|
|
5
|
+
**Obsidian-native terminal workspace, interactive knowledge graph & AI agent toolkit — Zero-Auth Local Vaults, Backlinks, Braille Graph View, CLI · TUI · HTTP API · MCP.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@bitefoundry/obsidian)
|
|
8
|
+
[](docs/NPM.md)
|
|
9
|
+
[](Cargo.toml)
|
|
10
|
+
[](package.json)
|
|
11
|
+
|
|
12
|
+
<br />
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Highlights
|
|
21
|
+
|
|
22
|
+
| Pillar | Capabilities |
|
|
23
|
+
| :--- | :--- |
|
|
24
|
+
| **Zero-Auth Native Vault Discovery** | Automatically discovers every local Obsidian vault from `%APPDATA%\obsidian\obsidian.json` (Windows), `~/Library/Application Support/obsidian/obsidian.json` (macOS), or `~/.config/obsidian/obsidian.json` (Linux) — 100% local-first Markdown files on disk, zero API keys or cloud auth required. |
|
|
25
|
+
| **Obsidian-Native 3-Pane TUI** | Signature Obsidian purple (`#a78bfa` / `#7c3aed`) Minimal-Chrome workspace (`obsidian` / `obs`): collapsible **5-Tab Left Sidebar (`[`)** (`1 Files · 2 Tags · 3 Bookmarks · 4 Outline · 5 Tasks`), **Live Note Canvas** with YAML Frontmatter pills, `#tag` chips, semantic Callout cards, interactive `- [ ]` checkboxes (`Space`/`x` updates the `.md` file atomically), clickable `[[wikilinks]]`, inline HD `![[image.png]]` previews (`v`), **Right Backlinks & Outgoing Inspector (`B`)**, **Quick Switcher (`Ctrl+O`)**, **Daily Notes (`D`)**, and **5 curated palettes** (`Obsidian Dark`, `Catppuccin Mocha`, `Tokyo Night`, `Nord`, `Warm Paper`). |
|
|
26
|
+
| **Interactive Knowledge Graph (`G`)** | Force-directed & radial **Braille Canvas Knowledge Graph** rendered right inside the terminal: purple focal edges, 1-hop / 2-hop / unresolved ghost nodes, Local vs Global scope (`l`), hop depth (`+/-`), node cycling (`j`/`k`/`Tab`), and `Enter` jump-to-note. |
|
|
27
|
+
| **SQLite WAL + FTS5 + 4-in-1 Agent Interface** | Incremental `mtime_ms` + `size_bytes` filesystem scanner powering SQLite WAL + FTS5 search (with automatic `<3`-char Korean/CJK `LIKE` fallback), background watcher IPC daemon (`obsidian daemon`), scriptable `--json` CLI, local **HTTP JSON API** (`obsidian serve`, `:8792`), and **stdio MCP server** (`obsidian mcp`, **18 typed tools** with `confirm: true` `.trash/` safety guard). |
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# 1. Install globally (links `obsidian` and `obs` native Rust binaries)
|
|
35
|
+
npm i -g @bitefoundry/obsidian
|
|
36
|
+
|
|
37
|
+
# 2. Launch directly — auto-discovers your existing local Obsidian vaults!
|
|
38
|
+
obsidian # alias: obs
|
|
39
|
+
|
|
40
|
+
# Or scaffold a starter local vault anywhere:
|
|
41
|
+
obsidian init ~/Documents/SecondBrain
|
|
42
|
+
obsidian vaults list
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Keybindings Cheat Sheet
|
|
48
|
+
|
|
49
|
+
| Key | Action | Context |
|
|
50
|
+
| :--- | :--- | :--- |
|
|
51
|
+
| `Ctrl+O` / `Ctrl+K` / `Ctrl+P` | **Quick Switcher** & Command Palette (fuzzy notes + `>commands`) | Global |
|
|
52
|
+
| `G` | Toggle **Interactive Knowledge Graph View** (Braille force-directed canvas) | Global |
|
|
53
|
+
| `l` / `+` `-` / `j` `k` / `Enter` | Toggle Local/Global scope · Depth · Cycle nodes · Open node | Graph View |
|
|
54
|
+
| `D` | Open or create **Today's Daily Note** (reads `.obsidian/daily-notes.json`) | Global |
|
|
55
|
+
| `[` / `Ctrl+B` | Toggle collapsible Left Sidebar | Global |
|
|
56
|
+
| `1` `2` `3` `4` `5` | Switch Sidebar tabs: **Files · Tags · Bookmarks · Outline · Tasks** | Global |
|
|
57
|
+
| `B` | Toggle Right Inspector (**Linked Mentions / Backlinks** & Outgoing Links) | Global |
|
|
58
|
+
| `Space` / `x` | Toggle live `- [ ]` / `- [x]` checkbox surgically in the `.md` file | Canvas / Tasks |
|
|
59
|
+
| `Enter` / `Backspace` / `Alt+←` | Follow `[[wikilink]]` / Navigate back in note history stack | Canvas |
|
|
60
|
+
| `a` / `n` / `e` / `b` | Quick Append · New Note · Open in `$EDITOR` (auto-reindexes) · Bookmark | Global |
|
|
61
|
+
| `u` / `h` / `v` / `y` | Link Extractor · Toggle Inline Hrefs · HD Image Preview · Copy Code/Note | Global |
|
|
62
|
+
| `Ctrl+V` / `Ctrl+F` | Paste clipboard PNG into `Attachments/` · File Picker (`z` zoxide jump) | Global |
|
|
63
|
+
| `Ctrl+S` / `Ctrl+,` / `.` / `?` | Vault Switcher · Settings (5 Palettes) · Context Menu · Keybinding Help | Global |
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## CLI, HTTP API & MCP
|
|
68
|
+
|
|
69
|
+
### CLI (`--json` & `--vault` ready)
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Discover, register, scaffold & reindex local vaults
|
|
73
|
+
obsidian vaults list --json
|
|
74
|
+
obsidian vaults add ~/Vaults/Work --name work
|
|
75
|
+
obsidian vaults use work
|
|
76
|
+
obsidian init ~/Vaults/Starter
|
|
77
|
+
obsidian reindex
|
|
78
|
+
|
|
79
|
+
# Search, read, author, daily notes & surgical checkbox toggles
|
|
80
|
+
obsidian search "Architecture" --json
|
|
81
|
+
obsidian notes list --folder Projects --json
|
|
82
|
+
obsidian notes read "Q4 Architecture RFC"
|
|
83
|
+
obsidian notes create "Sprint Retro" --folder Notes --tags "retro,q4"
|
|
84
|
+
obsidian notes append "Q4 Architecture RFC" "- [ ] Ship v0.1.0"
|
|
85
|
+
obsidian daily --append "- [ ] Review PRs"
|
|
86
|
+
obsidian tasks --open --json
|
|
87
|
+
obsidian toggle-task "Q4 Architecture RFC" 14
|
|
88
|
+
|
|
89
|
+
# Knowledge Graph & Link Intelligence
|
|
90
|
+
obsidian backlinks "Q4 Architecture RFC" --json
|
|
91
|
+
obsidian links "Q4 Architecture RFC" --json
|
|
92
|
+
obsidian graph "Q4 Architecture RFC" --depth 2 --json
|
|
93
|
+
obsidian orphans --json
|
|
94
|
+
obsidian tags architecture --json
|
|
95
|
+
|
|
96
|
+
# Background watcher daemon & diagnostics
|
|
97
|
+
obsidian daemon start
|
|
98
|
+
obsidian doctor --json
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Local HTTP JSON API (`obsidian serve`)
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
obsidian serve --bind 127.0.0.1 --port 8792 --token "$API_TOKEN"
|
|
105
|
+
curl -H "Authorization: Bearer $API_TOKEN" "http://127.0.0.1:8792/api/v1/search?q=Architecture"
|
|
106
|
+
curl -H "Authorization: Bearer $API_TOKEN" "http://127.0.0.1:8792/api/v1/graph?note=Q4%20Architecture%20RFC&depth=2"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Full endpoint catalog and OpenAPI schema: **[docs/API.md](docs/API.md)** · **[docs/openapi.yaml](docs/openapi.yaml)**.
|
|
110
|
+
|
|
111
|
+
### MCP Server (`obsidian mcp` — 18 Tools)
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"mcpServers": {
|
|
116
|
+
"obsidian": {
|
|
117
|
+
"command": "obsidian",
|
|
118
|
+
"args": ["mcp"]
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Full tool catalog and argument schemas: **[docs/MCP.md](docs/MCP.md)** · npm packaging details: **[docs/NPM.md](docs/NPM.md)**.
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## `@bitefoundry` Enterprise Terminal Suite
|
|
129
|
+
|
|
130
|
+
| Package | Commands | Workspace | Interfaces |
|
|
131
|
+
| :--- | :--- | :--- | :--- |
|
|
132
|
+
| [`@bitefoundry/teams`](https://www.npmjs.com/package/@bitefoundry/teams) | `teams` | Microsoft Teams (Chats, Channels, Meetings & Threads) | TUI · CLI · HTTP · MCP |
|
|
133
|
+
| [`@bitefoundry/outlook`](https://www.npmjs.com/package/@bitefoundry/outlook) | `outlook`, `ol` | Microsoft Outlook (Mail, Calendar & Contacts) | TUI · CLI · HTTP · MCP |
|
|
134
|
+
| [`@bitefoundry/onenote`](https://www.npmjs.com/package/@bitefoundry/onenote) | `onenote`, `on` | Microsoft OneNote (Notebooks, Sections & Pages) | TUI · CLI · HTTP · MCP |
|
|
135
|
+
| [`@bitefoundry/sharepoint`](https://www.npmjs.com/package/@bitefoundry/sharepoint) | `sharepoint`, `sp` | Microsoft SharePoint & OneDrive (Sites, Libraries & Lists) | TUI · CLI · HTTP · MCP |
|
|
136
|
+
| [`@bitefoundry/atlassian`](https://www.npmjs.com/package/@bitefoundry/atlassian) | `atlassian`, `jira`, `confluence`, `conf` | Atlassian Jira (Kanban, Sprints, JQL) & Confluence Wiki | TUI · CLI · HTTP · MCP |
|
|
137
|
+
| [`@bitefoundry/notion`](https://www.npmjs.com/package/@bitefoundry/notion) | `notion`, `nt` | Notion (Editorial Pages, Interactive Blocks & Databases) | TUI · CLI · HTTP · MCP |
|
|
138
|
+
| **`@bitefoundry/obsidian`** | `obsidian`, `obs` | Obsidian (Local Vaults, Backlinks & Interactive Knowledge Graph) | TUI · CLI · HTTP · MCP |
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
> **Disclaimer:** Unofficial terminal client for Obsidian vaults. Not affiliated with, endorsed by, or sponsored by Dynalist Inc. (Obsidian).
|
package/bin/obs.js
ADDED
package/bin/obsidian.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
const PLATFORM_KEY = `${process.platform}-${process.arch}`;
|
|
9
|
+
const PACKAGE_NAME = `@bitefoundry/obsidian-${PLATFORM_KEY}`;
|
|
10
|
+
const BINARY_NAME = process.platform === 'win32' ? 'obsidian.exe' : 'obsidian';
|
|
11
|
+
|
|
12
|
+
function resolveBinary() {
|
|
13
|
+
if (process.env.OBSIDIAN_BIN_PATH && fs.existsSync(process.env.OBSIDIAN_BIN_PATH)) {
|
|
14
|
+
return process.env.OBSIDIAN_BIN_PATH;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const requireFromHere = createRequire(import.meta.url);
|
|
18
|
+
try {
|
|
19
|
+
const pkgJsonPath = requireFromHere.resolve(`${PACKAGE_NAME}/package.json`);
|
|
20
|
+
const candidate = path.join(path.dirname(pkgJsonPath), 'bin', BINARY_NAME);
|
|
21
|
+
if (fs.existsSync(candidate)) {
|
|
22
|
+
return candidate;
|
|
23
|
+
}
|
|
24
|
+
} catch {
|
|
25
|
+
// Fall through to local repository fallback.
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
29
|
+
const localCandidates = [
|
|
30
|
+
path.join(repoRoot, 'npm', `obsidian-${PLATFORM_KEY}`, 'bin', BINARY_NAME),
|
|
31
|
+
path.join(repoRoot, 'target', 'release', BINARY_NAME),
|
|
32
|
+
path.join(repoRoot, 'target', 'debug', BINARY_NAME),
|
|
33
|
+
];
|
|
34
|
+
for (const candidate of localCandidates) {
|
|
35
|
+
if (fs.existsSync(candidate)) {
|
|
36
|
+
return candidate;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
console.error(
|
|
41
|
+
`[@bitefoundry/obsidian] Unable to locate native binary for ${PLATFORM_KEY} (${PACKAGE_NAME}).\n` +
|
|
42
|
+
`Try reinstalling with optional dependencies enabled:\n` +
|
|
43
|
+
` npm install -g @bitefoundry/obsidian`,
|
|
44
|
+
);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function runObsidianCli(argv = process.argv.slice(2)) {
|
|
49
|
+
const binary = resolveBinary();
|
|
50
|
+
if (process.platform !== 'win32') {
|
|
51
|
+
try {
|
|
52
|
+
fs.chmodSync(binary, 0o755);
|
|
53
|
+
} catch {
|
|
54
|
+
// Ignore chmod failures on read-only package stores.
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const result = spawnSync(binary, argv, {
|
|
59
|
+
stdio: 'inherit',
|
|
60
|
+
windowsHide: false,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
if (result.error) {
|
|
64
|
+
console.error(`[@bitefoundry/obsidian] Failed to launch ${binary}: ${result.error.message}`);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
if (result.signal) {
|
|
68
|
+
process.kill(process.pid, result.signal);
|
|
69
|
+
}
|
|
70
|
+
process.exit(result.status ?? 0);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
74
|
+
runObsidianCli();
|
|
75
|
+
}
|
package/docs/NPM.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# npm Cross-Platform Packaging (`@bitefoundry/obsidian`)
|
|
2
|
+
|
|
3
|
+
`@bitefoundry/obsidian` distributes prebuilt native Rust binaries across 6 OS/CPU targets via npm `optionalDependencies` and a zero-Node-process `postinstall` linker.
|
|
4
|
+
|
|
5
|
+
## Published Packages
|
|
6
|
+
|
|
7
|
+
| Package | OS | Arch | Rust Target |
|
|
8
|
+
| :--- | :--- | :--- | :--- |
|
|
9
|
+
| `@bitefoundry/obsidian` | All | All | Root CLI wrapper (`obsidian`, `obs`) |
|
|
10
|
+
| `@bitefoundry/obsidian-win32-x64` | Windows | x64 | `x86_64-pc-windows-msvc` |
|
|
11
|
+
| `@bitefoundry/obsidian-win32-arm64` | Windows | arm64 | `aarch64-pc-windows-msvc` |
|
|
12
|
+
| `@bitefoundry/obsidian-darwin-x64` | macOS (`>= 11.0`) | x64 | `x86_64-apple-darwin` |
|
|
13
|
+
| `@bitefoundry/obsidian-darwin-arm64` | macOS (`>= 11.0`) | arm64 | `aarch64-apple-darwin` |
|
|
14
|
+
| `@bitefoundry/obsidian-linux-x64` | Linux (`GLIBC >= 2.28`) | x64 | `x86_64-unknown-linux-gnu` |
|
|
15
|
+
| `@bitefoundry/obsidian-linux-arm64` | Linux (`GLIBC >= 2.28`) | arm64 | `aarch64-unknown-linux-gnu` |
|
|
16
|
+
|
|
17
|
+
## Compatibility Guarantees
|
|
18
|
+
|
|
19
|
+
- **Linux**: Built with `cargo-zigbuild` targeting `GLIBC 2.28` and verified in CI via `node scripts/verify-glibc.mjs --max 2.28` + AlmaLinux 8 container smoke test.
|
|
20
|
+
- **macOS**: Built with `MACOSX_DEPLOYMENT_TARGET=11.0` (Big Sur and newer).
|
|
21
|
+
- **Zero-Auth, Zero-Native-Keyring**: 100% pure Rust + bundled SQLite — no `libsecret` or system DBus runtime dependencies.
|
|
22
|
+
|
|
23
|
+
## Maintenance Scripts
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
node scripts/sync-version.mjs --check # Verify Cargo.toml + all 7 package.json versions match
|
|
27
|
+
node scripts/verify-glibc.mjs --self-test # Run ELF GLIBC parser self-tests
|
|
28
|
+
node scripts/build-npm.mjs --all # Stage release binaries into npm/obsidian-*/bin
|
|
29
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitefoundry/obsidian",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Obsidian-native terminal workspace, interactive knowledge graph & AI agent toolkit — Local Vaults, Backlinks, Graph View, CLI, TUI, HTTP API & MCP",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/BiteFoundry/obsidian.git"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"bin": {
|
|
11
|
+
"obsidian": "bin/obsidian.js",
|
|
12
|
+
"obs": "bin/obs.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"bin/obsidian.js",
|
|
16
|
+
"bin/obs.js",
|
|
17
|
+
"scripts/postinstall.mjs",
|
|
18
|
+
"docs/NPM.md",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=18"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"obsidian",
|
|
26
|
+
"obsidian-cli",
|
|
27
|
+
"obsidian-tui",
|
|
28
|
+
"obs",
|
|
29
|
+
"knowledge-graph",
|
|
30
|
+
"second-brain",
|
|
31
|
+
"pkm",
|
|
32
|
+
"markdown",
|
|
33
|
+
"wikilinks",
|
|
34
|
+
"backlinks",
|
|
35
|
+
"cli",
|
|
36
|
+
"tui",
|
|
37
|
+
"mcp"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"postinstall": "node scripts/postinstall.mjs",
|
|
41
|
+
"sync-version": "node scripts/sync-version.mjs",
|
|
42
|
+
"build:npm": "node scripts/build-npm.mjs"
|
|
43
|
+
},
|
|
44
|
+
"optionalDependencies": {
|
|
45
|
+
"@bitefoundry/obsidian-win32-x64": "0.1.0",
|
|
46
|
+
"@bitefoundry/obsidian-win32-arm64": "0.1.0",
|
|
47
|
+
"@bitefoundry/obsidian-darwin-x64": "0.1.0",
|
|
48
|
+
"@bitefoundry/obsidian-darwin-arm64": "0.1.0",
|
|
49
|
+
"@bitefoundry/obsidian-linux-x64": "0.1.0",
|
|
50
|
+
"@bitefoundry/obsidian-linux-arm64": "0.1.0"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Zero-Node-Process npm native binary linker.
|
|
3
|
+
//
|
|
4
|
+
// On Unix (linux/darwin): replaces installed `bin/obsidian.js` and `bin/obs.js` with
|
|
5
|
+
// hardlinks/symlinks directly to `@bitefoundry/obsidian-<platform>-<arch>/bin/obsidian` so npm's
|
|
6
|
+
// bin symlink execve's the native Rust binary directly (0ms Node startup, 0MB Node RSS).
|
|
7
|
+
//
|
|
8
|
+
// On Windows (win32): creates NTFS hardlinks (fallback copy) `bin/obsidian.exe` & `bin/obs.exe`
|
|
9
|
+
// and rewrites npm's `.bin/{obsidian,obs}[.cmd|.ps1]` shims when present to invoke
|
|
10
|
+
// the native executable directly without spawning `node.exe`.
|
|
11
|
+
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import { createRequire } from 'node:module';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
|
|
17
|
+
const BIN_NAMES = ['obsidian', 'obs'];
|
|
18
|
+
const PKG_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
19
|
+
|
|
20
|
+
function linkOrCopyFile(source, destination) {
|
|
21
|
+
const tmp = `${destination}.tmp-${process.pid}`;
|
|
22
|
+
try {
|
|
23
|
+
fs.rmSync(tmp, { force: true });
|
|
24
|
+
} catch {
|
|
25
|
+
// Ignore cleanup errors on nonexistent temp paths.
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
fs.linkSync(source, tmp);
|
|
29
|
+
} catch {
|
|
30
|
+
fs.copyFileSync(source, tmp);
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
fs.renameSync(tmp, destination);
|
|
34
|
+
} catch {
|
|
35
|
+
try {
|
|
36
|
+
fs.rmSync(destination, { force: true });
|
|
37
|
+
} catch {
|
|
38
|
+
// Ignore; renameSync below will surface or fail safely.
|
|
39
|
+
}
|
|
40
|
+
fs.renameSync(tmp, destination);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function replaceJsWithNativeLinkUnix(binaryPath, destinationJs) {
|
|
45
|
+
const tmp = `${destinationJs}.tmp-${process.pid}`;
|
|
46
|
+
try {
|
|
47
|
+
fs.rmSync(tmp, { force: true });
|
|
48
|
+
} catch {
|
|
49
|
+
// Ignore cleanup errors.
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
fs.linkSync(binaryPath, tmp);
|
|
53
|
+
} catch {
|
|
54
|
+
try {
|
|
55
|
+
fs.rmSync(tmp, { force: true });
|
|
56
|
+
} catch {
|
|
57
|
+
// Ignore cleanup errors.
|
|
58
|
+
}
|
|
59
|
+
fs.symlinkSync(binaryPath, tmp);
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
fs.renameSync(tmp, destinationJs);
|
|
63
|
+
} catch (err) {
|
|
64
|
+
try {
|
|
65
|
+
fs.rmSync(tmp, { force: true });
|
|
66
|
+
} catch {
|
|
67
|
+
// Ignore cleanup errors.
|
|
68
|
+
}
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function collectWindowsShimDirs(pkgRoot, env = process.env) {
|
|
74
|
+
const dirs = [];
|
|
75
|
+
const parentScope = path.dirname(pkgRoot);
|
|
76
|
+
const nodeModulesDir = path.dirname(parentScope);
|
|
77
|
+
if (
|
|
78
|
+
path.basename(parentScope) === '@bitefoundry' &&
|
|
79
|
+
path.basename(nodeModulesDir) === 'node_modules'
|
|
80
|
+
) {
|
|
81
|
+
dirs.push(path.join(nodeModulesDir, '.bin'));
|
|
82
|
+
dirs.push(path.dirname(nodeModulesDir));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (env.npm_config_global === 'true' && env.npm_config_prefix) {
|
|
86
|
+
const prefix = path.resolve(env.npm_config_prefix);
|
|
87
|
+
dirs.push(prefix);
|
|
88
|
+
dirs.push(path.join(prefix, 'bin'));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return [...new Set(dirs)];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function shimReferencesLauncher(content, name) {
|
|
95
|
+
const normalized = content.replace(/\\/g, '/').toLowerCase();
|
|
96
|
+
return (
|
|
97
|
+
normalized.includes('@bitefoundry/obsidian') &&
|
|
98
|
+
normalized.includes(`bin/${name}.js`)
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function rewriteWindowsShims(shimDir, pkgRoot) {
|
|
103
|
+
if (!fs.existsSync(shimDir)) return 0;
|
|
104
|
+
let rewritten = 0;
|
|
105
|
+
|
|
106
|
+
for (const name of BIN_NAMES) {
|
|
107
|
+
const exePath = path.join(pkgRoot, 'bin', `${name}.exe`);
|
|
108
|
+
if (!fs.existsSync(exePath)) continue;
|
|
109
|
+
|
|
110
|
+
const relWin = path.relative(shimDir, exePath).replace(/\//g, '\\');
|
|
111
|
+
const relPosix = path.relative(shimDir, exePath).replace(/\\/g, '/');
|
|
112
|
+
|
|
113
|
+
const cmdPath = path.join(shimDir, `${name}.cmd`);
|
|
114
|
+
try {
|
|
115
|
+
if (fs.existsSync(cmdPath)) {
|
|
116
|
+
const content = fs.readFileSync(cmdPath, 'utf8');
|
|
117
|
+
if (shimReferencesLauncher(content, name)) {
|
|
118
|
+
fs.writeFileSync(cmdPath, `@ECHO off\r\n"%~dp0${relWin}" %*\r\n`, 'utf8');
|
|
119
|
+
rewritten += 1;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
} catch {
|
|
123
|
+
// Fall back cleanly.
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const ps1Path = path.join(shimDir, `${name}.ps1`);
|
|
127
|
+
try {
|
|
128
|
+
if (fs.existsSync(ps1Path)) {
|
|
129
|
+
const content = fs.readFileSync(ps1Path, 'utf8');
|
|
130
|
+
if (shimReferencesLauncher(content, name)) {
|
|
131
|
+
const ps1Body = [
|
|
132
|
+
'#!/usr/bin/env pwsh',
|
|
133
|
+
'$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent',
|
|
134
|
+
`$exePath = Join-Path $basedir '${relWin.replace(/'/g, "''")}'`,
|
|
135
|
+
'if ($MyInvocation.ExpectingInput) {',
|
|
136
|
+
' $input | & $exePath @args',
|
|
137
|
+
'} else {',
|
|
138
|
+
' & $exePath @args',
|
|
139
|
+
'}',
|
|
140
|
+
'exit $LASTEXITCODE',
|
|
141
|
+
'',
|
|
142
|
+
].join('\n');
|
|
143
|
+
fs.writeFileSync(ps1Path, ps1Body, 'utf8');
|
|
144
|
+
rewritten += 1;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
} catch {
|
|
148
|
+
// Fall back cleanly.
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const shPath = path.join(shimDir, name);
|
|
152
|
+
try {
|
|
153
|
+
if (fs.existsSync(shPath)) {
|
|
154
|
+
const content = fs.readFileSync(shPath, 'utf8');
|
|
155
|
+
if (shimReferencesLauncher(content, name)) {
|
|
156
|
+
const shBody = [
|
|
157
|
+
'#!/bin/sh',
|
|
158
|
+
'basedir=$(dirname "$(echo "$0" | sed -e \'s,\\\\,/,g\')")',
|
|
159
|
+
`exec "$basedir/${relPosix}" "$@"`,
|
|
160
|
+
'',
|
|
161
|
+
].join('\n');
|
|
162
|
+
fs.writeFileSync(shPath, shBody, 'utf8');
|
|
163
|
+
rewritten += 1;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
} catch {
|
|
167
|
+
// Fall back cleanly.
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return rewritten;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function runPostinstall(options = {}) {
|
|
175
|
+
const pkgRoot = path.resolve(options.pkgRoot || PKG_ROOT);
|
|
176
|
+
const platform = options.platform || process.platform;
|
|
177
|
+
const arch = options.arch || process.arch;
|
|
178
|
+
const env = options.env || process.env;
|
|
179
|
+
|
|
180
|
+
if (
|
|
181
|
+
fs.existsSync(path.join(pkgRoot, 'Cargo.toml')) ||
|
|
182
|
+
fs.existsSync(path.join(pkgRoot, '.git'))
|
|
183
|
+
) {
|
|
184
|
+
return { skipped: true, reason: 'dev_repo' };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const platformKey = `${platform}-${arch}`;
|
|
188
|
+
const packageName = `@bitefoundry/obsidian-${platformKey}`;
|
|
189
|
+
const binaryName = platform === 'win32' ? 'obsidian.exe' : 'obsidian';
|
|
190
|
+
|
|
191
|
+
let packageDir = null;
|
|
192
|
+
try {
|
|
193
|
+
const requireFromPkg = createRequire(path.join(pkgRoot, 'package.json'));
|
|
194
|
+
packageDir = path.dirname(requireFromPkg.resolve(`${packageName}/package.json`));
|
|
195
|
+
} catch {
|
|
196
|
+
packageDir = null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const binaryPath = packageDir ? path.join(packageDir, 'bin', binaryName) : null;
|
|
200
|
+
if (!binaryPath || !fs.existsSync(binaryPath)) {
|
|
201
|
+
return { skipped: true, reason: 'missing_platform_binary' };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const binDir = path.join(pkgRoot, 'bin');
|
|
205
|
+
if (!fs.existsSync(binDir)) {
|
|
206
|
+
return { skipped: true, reason: 'missing_bin_dir' };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (platform === 'win32') {
|
|
210
|
+
let linked = 0;
|
|
211
|
+
for (const name of BIN_NAMES) {
|
|
212
|
+
const destExe = path.join(binDir, `${name}.exe`);
|
|
213
|
+
try {
|
|
214
|
+
linkOrCopyFile(binaryPath, destExe);
|
|
215
|
+
linked += 1;
|
|
216
|
+
} catch {
|
|
217
|
+
// Leave fallback JS launcher untouched.
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
let shimsRewritten = 0;
|
|
222
|
+
for (const shimDir of collectWindowsShimDirs(pkgRoot, env)) {
|
|
223
|
+
try {
|
|
224
|
+
shimsRewritten += rewriteWindowsShims(shimDir, pkgRoot);
|
|
225
|
+
} catch {
|
|
226
|
+
// Never fail npm install on read-only or custom shims.
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return { skipped: false, platform, linked, shimsRewritten };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
try {
|
|
233
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
234
|
+
} catch {
|
|
235
|
+
// Ignore on read-only stores.
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
let linked = 0;
|
|
239
|
+
for (const name of BIN_NAMES) {
|
|
240
|
+
const destJs = path.join(binDir, `${name}.js`);
|
|
241
|
+
try {
|
|
242
|
+
replaceJsWithNativeLinkUnix(binaryPath, destJs);
|
|
243
|
+
linked += 1;
|
|
244
|
+
} catch {
|
|
245
|
+
// Leave fallback JS launcher intact.
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return { skipped: false, platform, linked };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
253
|
+
try {
|
|
254
|
+
runPostinstall();
|
|
255
|
+
} catch {
|
|
256
|
+
// Postinstall optimization must never fail npm install.
|
|
257
|
+
}
|
|
258
|
+
process.exit(0);
|
|
259
|
+
}
|