@bitefoundry/sharepoint 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 +132 -2
- package/bin/od.js +4 -0
- package/bin/onedrive.js +4 -0
- package/bin/sharepoint.js +121 -0
- package/bin/sp.js +4 -0
- package/docs/NPM.md +15 -0
- package/package.json +51 -4
- package/scripts/postinstall.mjs +264 -0
package/README.md
CHANGED
|
@@ -1,3 +1,133 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# `@bitefoundry/sharepoint`
|
|
4
|
+
|
|
5
|
+
**Unified Microsoft SharePoint & OneDrive terminal client, CLI, HTTP API, and MCP server — powered by Rust, Ratatui, and local SQLite FTS5.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@bitefoundry/sharepoint)
|
|
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
|
+
| Capability | Details |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| **Minimal-Chrome 3-Pane TUI** | Dual-persona explorer (`sharepoint`/`sp` & `onedrive`/`od`) with collapsible Sites, Document Libraries & OneDrive sidebar, sorted file list, live Inspector (metadata, version history, Markdown/YAML/JSON/code preview), Link Extractor (`u`), File Picker with `zoxide` (`Ctrl+F`), Context Menu (`.`), and 6 themes. |
|
|
25
|
+
| **High-Res Terminal Images** | Inline Inspector thumbnails & fullscreen HD previews (`v` / `Alt+v`) with 80ms protocol probing for **Kitty**, **iTerm2**, **Sixel** (Floyd-Steinberg dithering), and **24-bit Unicode Half-Blocks** + `Ctrl+V` instant clipboard PNG upload. |
|
|
26
|
+
| **Local SQLite FTS5 + IPC Daemon** | WAL-mode SQLite cache with 4-reader pool, hybrid local FTS5 + remote Graph search (`/`), streaming chunked uploads (`> 4 MiB`), and a shared background sync daemon (`sharepoint daemon start`). |
|
|
27
|
+
| **4-in-1 Agent Interface** | Interactive **TUI**, scriptable `--json` **CLI**, local **HTTP JSON API** (`sharepoint serve`, port `8790`), and stdio **MCP Server** (`sharepoint mcp`, 16 tools). |
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
# 1. Install globally via npm (precompiled native binary for win32 / darwin / linux)
|
|
35
|
+
npm i -g @bitefoundry/sharepoint
|
|
36
|
+
|
|
37
|
+
# 2. Authenticate with Microsoft 365 (PKCE loopback, --device-code, or shared M365 token)
|
|
38
|
+
sharepoint login
|
|
39
|
+
|
|
40
|
+
# 3. Launch the interactive 3-pane TUI in either persona
|
|
41
|
+
sharepoint # SharePoint Sites & Document Libraries (alias: sp)
|
|
42
|
+
onedrive # Personal OneDrive: My Files, Recent, Shared (alias: od)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
> Required Microsoft Graph delegated scopes: `Files.ReadWrite.All`, `Sites.ReadWrite.All`, `User.Read`, `offline_access`.
|
|
46
|
+
> Prefer building from source? Run `cargo build --release` and see [docs/NPM.md](docs/NPM.md) for external token brokers & environment variables.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Keybindings Cheat Sheet
|
|
51
|
+
|
|
52
|
+
| Key | Action |
|
|
53
|
+
| --- | --- |
|
|
54
|
+
| `Tab` / `Shift+Tab` | Cycle focus (Sidebar → File List → Inspector) |
|
|
55
|
+
| `j` / `k` · `↑` / `↓` | Move selection / scroll Inspector preview |
|
|
56
|
+
| `Enter` / `Backspace` | Open folder or site / navigate to parent folder |
|
|
57
|
+
| `S` | Cycle sort order (Name / Modified / Size / Type) |
|
|
58
|
+
| `Ctrl+F` | Upload file via interactive File Picker (`z` for `zoxide` jump) |
|
|
59
|
+
| `Ctrl+V` | Encode clipboard image as PNG & upload to current folder |
|
|
60
|
+
| `d` / `n` / `r` / `x` | Download file / new folder / rename / delete (with confirm) |
|
|
61
|
+
| `s` / `o` / `p` | Create & copy share link / open in browser / pin target |
|
|
62
|
+
| `v` / `u` / `h` | HD image preview / Link Extractor / toggle inline `href` URLs |
|
|
63
|
+
| `/` | Hybrid local FTS5 + Microsoft Graph file search |
|
|
64
|
+
| `Ctrl+P` / `Ctrl+K` | Unified Command Palette & Library Omni-Switcher |
|
|
65
|
+
| `.` / Right-click | Context Menu |
|
|
66
|
+
| `Ctrl+,` / `Ctrl+B` / `?` | Settings / Toggle sidebar / Keyboard shortcuts help |
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## CLI, HTTP API & MCP
|
|
71
|
+
|
|
72
|
+
### CLI (`--json` on every command)
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
sharepoint sites --json
|
|
76
|
+
sharepoint drives --site "Acme Engineering" --json
|
|
77
|
+
onedrive ls /Projects/Platform-v4 --json
|
|
78
|
+
onedrive cat /Projects/Platform-v4/deploy-pipeline.yaml
|
|
79
|
+
sharepoint upload ./q4-architecture-deck.pdf /RFCs --site "Acme Engineering" --json
|
|
80
|
+
sharepoint share /api-gateway-rfc.md --site "Acme Engineering" --type view --scope organization --json
|
|
81
|
+
sharepoint search "gateway" --remote --json
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Local HTTP API (`sharepoint serve`)
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
# Start local Axum JSON server (default 127.0.0.1:8790)
|
|
88
|
+
sharepoint serve --port 8790 --api-key dev-secret
|
|
89
|
+
|
|
90
|
+
# Search files across OneDrive & SharePoint from scripts or agents
|
|
91
|
+
curl -H "Authorization: Bearer dev-secret" \
|
|
92
|
+
"http://127.0.0.1:8790/v1/search?q=gateway&remote=true&limit=10"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Full route reference & OpenAPI 3.1 spec: [docs/API.md](docs/API.md) · [docs/openapi.yaml](docs/openapi.yaml).
|
|
96
|
+
|
|
97
|
+
### Model Context Protocol (`sharepoint mcp`)
|
|
98
|
+
|
|
99
|
+
Add to Claude Desktop, Claude Code, Cursor, or Codex (`16` tools over stdio JSON-RPC 2.0):
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"mcpServers": {
|
|
104
|
+
"sharepoint": {
|
|
105
|
+
"command": "sharepoint",
|
|
106
|
+
"args": ["mcp"]
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Full tool catalog & schemas: [docs/MCP.md](docs/MCP.md).
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## `@bitefoundry` Enterprise Terminal Suite
|
|
117
|
+
|
|
118
|
+
| Package | Commands | Workspace Coverage |
|
|
119
|
+
| --- | --- | --- |
|
|
120
|
+
| [`@bitefoundry/teams`](https://www.npmjs.com/package/@bitefoundry/teams) | `teams`, `tm` | Microsoft Teams chats, channels, threads & meetings |
|
|
121
|
+
| [`@bitefoundry/outlook`](https://www.npmjs.com/package/@bitefoundry/outlook) | `outlook`, `mail`, `cal` | Microsoft Outlook mail, calendar & contacts |
|
|
122
|
+
| [`@bitefoundry/onenote`](https://www.npmjs.com/package/@bitefoundry/onenote) | `onenote`, `note` | Microsoft OneNote notebooks, sections, pages & XHTML/Markdown |
|
|
123
|
+
| **`@bitefoundry/sharepoint`** | `sharepoint`, `sp`, `onedrive`, `od` | Microsoft SharePoint sites, document libraries & OneDrive files |
|
|
124
|
+
| [`@bitefoundry/atlassian`](https://www.npmjs.com/package/@bitefoundry/atlassian) | `atlassian`, `jira`, `confluence` | Atlassian Jira issues, boards, sprints & Confluence pages |
|
|
125
|
+
| [`@bitefoundry/notion`](https://www.npmjs.com/package/@bitefoundry/notion) | `notion`, `nt` | Notion pages, databases, blocks & Markdown sync |
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## License & Disclaimer
|
|
130
|
+
|
|
131
|
+
Licensed under the **MIT License**.
|
|
132
|
+
|
|
133
|
+
> Unofficial terminal client for Microsoft SharePoint & OneDrive. Not affiliated with, endorsed by, or sponsored by Microsoft Corporation.
|
package/bin/od.js
ADDED
package/bin/onedrive.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const { spawn } = require('node:child_process');
|
|
8
|
+
|
|
9
|
+
const SUPPORTED = [
|
|
10
|
+
'win32-x64',
|
|
11
|
+
'win32-arm64',
|
|
12
|
+
'darwin-x64',
|
|
13
|
+
'darwin-arm64',
|
|
14
|
+
'linux-x64',
|
|
15
|
+
'linux-arm64',
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
function launch(
|
|
19
|
+
commandName = 'sharepoint',
|
|
20
|
+
persona = process.env.SHAREPOINT_PERSONA || 'sharepoint',
|
|
21
|
+
) {
|
|
22
|
+
function fail(message) {
|
|
23
|
+
process.stderr.write(`${commandName}: ${message}\n`);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const platform = process.platform;
|
|
28
|
+
const arch = process.arch;
|
|
29
|
+
const platformKey = `${platform}-${arch}`;
|
|
30
|
+
const packageName = `@bitefoundry/sharepoint-${platformKey}`;
|
|
31
|
+
const binaryName = platform === 'win32' ? 'sharepoint.exe' : 'sharepoint';
|
|
32
|
+
|
|
33
|
+
let packageDir = null;
|
|
34
|
+
try {
|
|
35
|
+
packageDir = path.dirname(require.resolve(`${packageName}/package.json`));
|
|
36
|
+
} catch {
|
|
37
|
+
packageDir = null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const binaryPath = packageDir ? path.join(packageDir, 'bin', binaryName) : null;
|
|
41
|
+
|
|
42
|
+
if (!binaryPath || !fs.existsSync(binaryPath)) {
|
|
43
|
+
const fallbackNpx =
|
|
44
|
+
commandName === 'sharepoint'
|
|
45
|
+
? ' npx --yes @bitefoundry/sharepoint'
|
|
46
|
+
: ` npx --yes -p @bitefoundry/sharepoint ${commandName}`;
|
|
47
|
+
const lines = [
|
|
48
|
+
`no prebuilt binary found for ${platformKey}.`,
|
|
49
|
+
'',
|
|
50
|
+
`Expected the optional dependency "${packageName}" to provide:`,
|
|
51
|
+
` ${binaryPath || `node_modules/${packageName}/bin/${binaryName}`}`,
|
|
52
|
+
'',
|
|
53
|
+
`Supported platforms: ${SUPPORTED.join(', ')}`,
|
|
54
|
+
'',
|
|
55
|
+
'Try one of:',
|
|
56
|
+
' npm install -g @bitefoundry/sharepoint --include=optional',
|
|
57
|
+
' npm install @bitefoundry/sharepoint --include=optional',
|
|
58
|
+
fallbackNpx,
|
|
59
|
+
'',
|
|
60
|
+
'If you are on an unsupported platform (for example Alpine/musl Linux),',
|
|
61
|
+
'build from source with Cargo:',
|
|
62
|
+
' cargo build --release',
|
|
63
|
+
];
|
|
64
|
+
fail(lines.join('\n'));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// npm does not guarantee the executable bit survives packaging, so make sure
|
|
68
|
+
// the binary is runnable before spawning it.
|
|
69
|
+
if (platform !== 'win32') {
|
|
70
|
+
try {
|
|
71
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
72
|
+
} catch {
|
|
73
|
+
// Read-only install; spawn will report EACCES if the bit is missing.
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
78
|
+
stdio: 'inherit',
|
|
79
|
+
windowsHide: false,
|
|
80
|
+
env: {
|
|
81
|
+
...process.env,
|
|
82
|
+
SHAREPOINT_PERSONA: persona,
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
child.on('error', (err) => {
|
|
87
|
+
fail(`failed to launch ${binaryPath}: ${err.message}`);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Forward termination signals to the child process.
|
|
91
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
92
|
+
const handler = () => {
|
|
93
|
+
if (!child.killed) {
|
|
94
|
+
try {
|
|
95
|
+
child.kill(signal);
|
|
96
|
+
} catch {
|
|
97
|
+
// Child already exited.
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
try {
|
|
102
|
+
process.on(signal, handler);
|
|
103
|
+
} catch {
|
|
104
|
+
// Signal not supported on this platform.
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
child.on('exit', (code, signal) => {
|
|
109
|
+
if (signal) {
|
|
110
|
+
const number = os.constants.signals[signal] || 1;
|
|
111
|
+
process.exit(128 + number);
|
|
112
|
+
}
|
|
113
|
+
process.exit(code === null ? 1 : code);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
module.exports = { launch };
|
|
118
|
+
|
|
119
|
+
if (require.main === module) {
|
|
120
|
+
launch('sharepoint', process.env.SHAREPOINT_PERSONA || 'sharepoint');
|
|
121
|
+
}
|
package/bin/sp.js
ADDED
package/docs/NPM.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# `@bitefoundry/sharepoint` npm Packaging
|
|
2
|
+
|
|
3
|
+
`@bitefoundry/sharepoint` ships a single prebuilt native Rust binary across 6 optional platform packages (`win32-x64`, `win32-arm64`, `darwin-x64`, `darwin-arm64`, `linux-x64`, `linux-arm64`) with 4 launchers:
|
|
4
|
+
|
|
5
|
+
- `sharepoint` / `sp`: SharePoint Sites & Document Libraries persona
|
|
6
|
+
- `onedrive` / `od`: Personal OneDrive persona (`SHAREPOINT_PERSONA=onedrive` + `argv[0]` detection)
|
|
7
|
+
|
|
8
|
+
## Zero-Node-Process Linking
|
|
9
|
+
`scripts/postinstall.mjs` hardlinks the platform binary directly to `bin/{sharepoint,sp,onedrive,od}` so invocations run with 0ms Node.js overhead while preserving persona detection via `argv[0]`.
|
|
10
|
+
|
|
11
|
+
## Release Verification
|
|
12
|
+
```bash
|
|
13
|
+
node scripts/sync-version.mjs --check
|
|
14
|
+
node scripts/verify-glibc.mjs --self-test
|
|
15
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitefoundry/sharepoint",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Unified Microsoft SharePoint & OneDrive terminal client & AI agent toolkit — Sites, Document Libraries & Personal Files (CLI, TUI, HTTP API, MCP)",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/BiteFoundry/sharepoint.git"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"bin": {
|
|
11
|
+
"sharepoint": "bin/sharepoint.js",
|
|
12
|
+
"sp": "bin/sp.js",
|
|
13
|
+
"onedrive": "bin/onedrive.js",
|
|
14
|
+
"od": "bin/od.js"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"bin/sharepoint.js",
|
|
18
|
+
"bin/sp.js",
|
|
19
|
+
"bin/onedrive.js",
|
|
20
|
+
"bin/od.js",
|
|
21
|
+
"scripts/postinstall.mjs",
|
|
22
|
+
"docs/NPM.md",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"microsoft-sharepoint",
|
|
30
|
+
"sharepoint",
|
|
31
|
+
"onedrive",
|
|
32
|
+
"microsoft-365",
|
|
33
|
+
"microsoft-graph",
|
|
34
|
+
"document-library",
|
|
35
|
+
"cloud-storage",
|
|
36
|
+
"cli",
|
|
37
|
+
"tui",
|
|
38
|
+
"mcp"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"postinstall": "node scripts/postinstall.mjs",
|
|
42
|
+
"sync-version": "node scripts/sync-version.mjs",
|
|
43
|
+
"build:npm": "node scripts/build-npm.mjs"
|
|
44
|
+
},
|
|
45
|
+
"optionalDependencies": {
|
|
46
|
+
"@bitefoundry/sharepoint-win32-x64": "0.1.0",
|
|
47
|
+
"@bitefoundry/sharepoint-win32-arm64": "0.1.0",
|
|
48
|
+
"@bitefoundry/sharepoint-darwin-x64": "0.1.0",
|
|
49
|
+
"@bitefoundry/sharepoint-darwin-arm64": "0.1.0",
|
|
50
|
+
"@bitefoundry/sharepoint-linux-x64": "0.1.0",
|
|
51
|
+
"@bitefoundry/sharepoint-linux-arm64": "0.1.0"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Zero-Node-Process npm native binary linker.
|
|
3
|
+
//
|
|
4
|
+
// On Unix (linux/darwin): replaces installed `bin/{sharepoint,sp,onedrive,od}.js` with
|
|
5
|
+
// hardlinks/symlinks directly to `@bitefoundry/sharepoint-<platform>-<arch>/bin/sharepoint` so npm's
|
|
6
|
+
// bin symlink execve's the native Rust binary directly (0ms Node startup, 0MB Node RSS),
|
|
7
|
+
// with persona inferred cleanly from `argv[0]` (`onedrive`/`od` vs `sharepoint`/`sp`).
|
|
8
|
+
//
|
|
9
|
+
// On Windows (win32): creates NTFS hardlinks (fallback copy) `bin/{sharepoint,sp,onedrive,od}.exe`
|
|
10
|
+
// and rewrites npm's `.bin/<name>[.cmd|.ps1]` shims when present to invoke `<name>.exe`
|
|
11
|
+
// directly without spawning `node.exe`.
|
|
12
|
+
|
|
13
|
+
import fs from 'node:fs';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
import { createRequire } from 'node:module';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
|
|
18
|
+
const BIN_NAMES = ['sharepoint', 'sp', 'onedrive', 'od'];
|
|
19
|
+
const PKG_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
20
|
+
|
|
21
|
+
function linkOrCopyFile(source, destination) {
|
|
22
|
+
const tmp = `${destination}.tmp-${process.pid}`;
|
|
23
|
+
try {
|
|
24
|
+
fs.rmSync(tmp, { force: true });
|
|
25
|
+
} catch {
|
|
26
|
+
// Ignore cleanup errors on nonexistent temp paths.
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
fs.linkSync(source, tmp);
|
|
30
|
+
} catch {
|
|
31
|
+
fs.copyFileSync(source, tmp);
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
fs.renameSync(tmp, destination);
|
|
35
|
+
} catch {
|
|
36
|
+
try {
|
|
37
|
+
fs.rmSync(destination, { force: true });
|
|
38
|
+
} catch {
|
|
39
|
+
// Ignore; renameSync below will surface or fail safely.
|
|
40
|
+
}
|
|
41
|
+
fs.renameSync(tmp, destination);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function replaceJsWithNativeLinkUnix(binaryPath, destinationJs) {
|
|
46
|
+
const tmp = `${destinationJs}.tmp-${process.pid}`;
|
|
47
|
+
try {
|
|
48
|
+
fs.rmSync(tmp, { force: true });
|
|
49
|
+
} catch {
|
|
50
|
+
// Ignore cleanup errors.
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
fs.linkSync(binaryPath, tmp);
|
|
54
|
+
} catch {
|
|
55
|
+
try {
|
|
56
|
+
fs.rmSync(tmp, { force: true });
|
|
57
|
+
} catch {
|
|
58
|
+
// Ignore cleanup errors.
|
|
59
|
+
}
|
|
60
|
+
fs.symlinkSync(binaryPath, tmp);
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
fs.renameSync(tmp, destinationJs);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
try {
|
|
66
|
+
fs.rmSync(tmp, { force: true });
|
|
67
|
+
} catch {
|
|
68
|
+
// Ignore cleanup errors.
|
|
69
|
+
}
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function collectWindowsShimDirs(pkgRoot, env = process.env) {
|
|
75
|
+
const dirs = [];
|
|
76
|
+
const parentScope = path.dirname(pkgRoot);
|
|
77
|
+
const nodeModulesDir = path.dirname(parentScope);
|
|
78
|
+
if (
|
|
79
|
+
path.basename(parentScope) === '@bitefoundry' &&
|
|
80
|
+
path.basename(nodeModulesDir) === 'node_modules'
|
|
81
|
+
) {
|
|
82
|
+
dirs.push(path.join(nodeModulesDir, '.bin'));
|
|
83
|
+
dirs.push(path.dirname(nodeModulesDir));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (env.npm_config_global === 'true' && env.npm_config_prefix) {
|
|
87
|
+
const prefix = path.resolve(env.npm_config_prefix);
|
|
88
|
+
dirs.push(prefix);
|
|
89
|
+
dirs.push(path.join(prefix, 'bin'));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return [...new Set(dirs)];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function shimReferencesLauncher(content, name) {
|
|
96
|
+
const normalized = content.replace(/\\/g, '/').toLowerCase();
|
|
97
|
+
return (
|
|
98
|
+
normalized.includes('@bitefoundry/sharepoint') &&
|
|
99
|
+
normalized.includes(`bin/${name}.js`)
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function rewriteWindowsShims(shimDir, pkgRoot) {
|
|
104
|
+
if (!fs.existsSync(shimDir)) return 0;
|
|
105
|
+
let rewritten = 0;
|
|
106
|
+
|
|
107
|
+
for (const name of BIN_NAMES) {
|
|
108
|
+
const exePath = path.join(pkgRoot, 'bin', `${name}.exe`);
|
|
109
|
+
if (!fs.existsSync(exePath)) continue;
|
|
110
|
+
|
|
111
|
+
const relWin = path.relative(shimDir, exePath).replace(/\//g, '\\');
|
|
112
|
+
const relPosix = path.relative(shimDir, exePath).replace(/\\/g, '/');
|
|
113
|
+
|
|
114
|
+
// 1. `<name>.cmd`
|
|
115
|
+
const cmdPath = path.join(shimDir, `${name}.cmd`);
|
|
116
|
+
try {
|
|
117
|
+
if (fs.existsSync(cmdPath)) {
|
|
118
|
+
const content = fs.readFileSync(cmdPath, 'utf8');
|
|
119
|
+
if (shimReferencesLauncher(content, name)) {
|
|
120
|
+
fs.writeFileSync(cmdPath, `@ECHO off\r\n"%~dp0${relWin}" %*\r\n`, 'utf8');
|
|
121
|
+
rewritten += 1;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
} catch {
|
|
125
|
+
// Fall back cleanly to bin/<name>.js if shim is read-only or locked.
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 2. `<name>.ps1`
|
|
129
|
+
const ps1Path = path.join(shimDir, `${name}.ps1`);
|
|
130
|
+
try {
|
|
131
|
+
if (fs.existsSync(ps1Path)) {
|
|
132
|
+
const content = fs.readFileSync(ps1Path, 'utf8');
|
|
133
|
+
if (shimReferencesLauncher(content, name)) {
|
|
134
|
+
const ps1Body = [
|
|
135
|
+
'#!/usr/bin/env pwsh',
|
|
136
|
+
'$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent',
|
|
137
|
+
`$exePath = Join-Path $basedir '${relWin.replace(/'/g, "''")}'`,
|
|
138
|
+
'if ($MyInvocation.ExpectingInput) {',
|
|
139
|
+
' $input | & $exePath @args',
|
|
140
|
+
'} else {',
|
|
141
|
+
' & $exePath @args',
|
|
142
|
+
'}',
|
|
143
|
+
'exit $LASTEXITCODE',
|
|
144
|
+
'',
|
|
145
|
+
].join('\n');
|
|
146
|
+
fs.writeFileSync(ps1Path, ps1Body, 'utf8');
|
|
147
|
+
rewritten += 1;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
} catch {
|
|
151
|
+
// Fall back cleanly.
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// 3. `<name>` (Git Bash / MSYS2 POSIX shell shim)
|
|
155
|
+
const shPath = path.join(shimDir, name);
|
|
156
|
+
try {
|
|
157
|
+
if (fs.existsSync(shPath)) {
|
|
158
|
+
const content = fs.readFileSync(shPath, 'utf8');
|
|
159
|
+
if (shimReferencesLauncher(content, name)) {
|
|
160
|
+
const shBody = [
|
|
161
|
+
'#!/bin/sh',
|
|
162
|
+
'basedir=$(dirname "$(echo "$0" | sed -e \'s,\\\\,/,g\')")',
|
|
163
|
+
`exec "$basedir/${relPosix}" "$@"`,
|
|
164
|
+
'',
|
|
165
|
+
].join('\n');
|
|
166
|
+
fs.writeFileSync(shPath, shBody, 'utf8');
|
|
167
|
+
rewritten += 1;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
} catch {
|
|
171
|
+
// Fall back cleanly.
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return rewritten;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function runPostinstall(options = {}) {
|
|
179
|
+
const pkgRoot = path.resolve(options.pkgRoot || PKG_ROOT);
|
|
180
|
+
const platform = options.platform || process.platform;
|
|
181
|
+
const arch = options.arch || process.arch;
|
|
182
|
+
const env = options.env || process.env;
|
|
183
|
+
|
|
184
|
+
// CRITICAL SAFETY GUARD: Never mutate files inside the git development repository.
|
|
185
|
+
if (
|
|
186
|
+
fs.existsSync(path.join(pkgRoot, 'Cargo.toml')) ||
|
|
187
|
+
fs.existsSync(path.join(pkgRoot, '.git'))
|
|
188
|
+
) {
|
|
189
|
+
return { skipped: true, reason: 'dev_repo' };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const platformKey = `${platform}-${arch}`;
|
|
193
|
+
const packageName = `@bitefoundry/sharepoint-${platformKey}`;
|
|
194
|
+
const binaryName = platform === 'win32' ? 'sharepoint.exe' : 'sharepoint';
|
|
195
|
+
|
|
196
|
+
let packageDir = null;
|
|
197
|
+
try {
|
|
198
|
+
const requireFromPkg = createRequire(path.join(pkgRoot, 'package.json'));
|
|
199
|
+
packageDir = path.dirname(requireFromPkg.resolve(`${packageName}/package.json`));
|
|
200
|
+
} catch {
|
|
201
|
+
packageDir = null;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const binaryPath = packageDir ? path.join(packageDir, 'bin', binaryName) : null;
|
|
205
|
+
if (!binaryPath || !fs.existsSync(binaryPath)) {
|
|
206
|
+
return { skipped: true, reason: 'missing_platform_binary' };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const binDir = path.join(pkgRoot, 'bin');
|
|
210
|
+
if (!fs.existsSync(binDir)) {
|
|
211
|
+
return { skipped: true, reason: 'missing_bin_dir' };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (platform === 'win32') {
|
|
215
|
+
let linked = 0;
|
|
216
|
+
for (const name of BIN_NAMES) {
|
|
217
|
+
const destExe = path.join(binDir, `${name}.exe`);
|
|
218
|
+
try {
|
|
219
|
+
linkOrCopyFile(binaryPath, destExe);
|
|
220
|
+
linked += 1;
|
|
221
|
+
} catch {
|
|
222
|
+
// Leave fallback JS launcher untouched.
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
let shimsRewritten = 0;
|
|
227
|
+
for (const shimDir of collectWindowsShimDirs(pkgRoot, env)) {
|
|
228
|
+
try {
|
|
229
|
+
shimsRewritten += rewriteWindowsShims(shimDir, pkgRoot);
|
|
230
|
+
} catch {
|
|
231
|
+
// Never fail npm install on read-only or custom shims.
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return { skipped: false, platform, linked, shimsRewritten };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
try {
|
|
238
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
239
|
+
} catch {
|
|
240
|
+
// Ignore on read-only stores.
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
let linked = 0;
|
|
244
|
+
for (const name of BIN_NAMES) {
|
|
245
|
+
const destJs = path.join(binDir, `${name}.js`);
|
|
246
|
+
try {
|
|
247
|
+
replaceJsWithNativeLinkUnix(binaryPath, destJs);
|
|
248
|
+
linked += 1;
|
|
249
|
+
} catch {
|
|
250
|
+
// Leave fallback JS launcher intact.
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return { skipped: false, platform, linked };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
258
|
+
try {
|
|
259
|
+
runPostinstall();
|
|
260
|
+
} catch {
|
|
261
|
+
// Postinstall optimization must never fail npm install.
|
|
262
|
+
}
|
|
263
|
+
process.exit(0);
|
|
264
|
+
}
|