@collaborationlabs/rift 0.0.0 → 0.0.15
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/bin/rift.js +32 -0
- package/bun/index.js +73 -0
- package/index.d.ts +68 -0
- package/node/index.js +66 -0
- package/package.json +42 -1
- package/prebuilds/darwin-arm64/librift_ffi.dylib +0 -0
- package/prebuilds/darwin-arm64/rift +0 -0
- package/prebuilds/darwin-x64/librift_ffi.dylib +0 -0
- package/prebuilds/darwin-x64/rift +0 -0
- package/prebuilds/linux-x64/librift_ffi.so +0 -0
- package/prebuilds/linux-x64/rift +0 -0
- package/prebuilds/windows-x64/rift.exe +0 -0
- package/prebuilds/windows-x64/rift_ffi.dll +0 -0
package/bin/rift.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import childProcess from "node:child_process"
|
|
4
|
+
import fs from "node:fs"
|
|
5
|
+
import os from "node:os"
|
|
6
|
+
import path from "node:path"
|
|
7
|
+
import { fileURLToPath } from "node:url"
|
|
8
|
+
|
|
9
|
+
const platform = { darwin: "darwin", linux: "linux", win32: "windows" }[os.platform()]
|
|
10
|
+
const arch = { arm64: "arm64", x64: "x64" }[os.arch()]
|
|
11
|
+
|
|
12
|
+
if (!platform || !arch) {
|
|
13
|
+
console.error(`Unsupported Rift platform: ${os.platform()}-${os.arch()}`)
|
|
14
|
+
process.exit(1)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)))
|
|
18
|
+
const binary = path.join(root, "prebuilds", `${platform}-${arch}`, platform === "windows" ? "rift.exe" : "rift")
|
|
19
|
+
if (!fs.existsSync(binary)) {
|
|
20
|
+
console.error(`Unable to locate the Rift binary for ${platform}-${arch}. Reinstall @collaborationlabs/rift.`)
|
|
21
|
+
process.exit(1)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const result = childProcess.spawnSync(binary, process.argv.slice(2), {
|
|
25
|
+
stdio: "inherit",
|
|
26
|
+
windowsHide: true,
|
|
27
|
+
})
|
|
28
|
+
if (result.error) {
|
|
29
|
+
console.error(result.error.message)
|
|
30
|
+
process.exit(1)
|
|
31
|
+
}
|
|
32
|
+
process.exit(result.status ?? 1)
|
package/bun/index.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { CString, dlopen, ptr } from "bun:ffi"
|
|
2
|
+
import os from "node:os"
|
|
3
|
+
|
|
4
|
+
const platform = { darwin: "darwin", linux: "linux", win32: "windows" }[os.platform()]
|
|
5
|
+
const arch = { arm64: "arm64", x64: "x64" }[os.arch()]
|
|
6
|
+
if (!platform || !arch) throw new Error(`Unsupported Rift platform: ${os.platform()}-${os.arch()}`)
|
|
7
|
+
|
|
8
|
+
let libraryPath
|
|
9
|
+
if (platform === "linux" && arch === "x64") {
|
|
10
|
+
libraryPath = (await import("../prebuilds/linux-x64/librift_ffi.so", { with: { type: "file" } })).default
|
|
11
|
+
} else if (platform === "darwin" && arch === "x64") {
|
|
12
|
+
libraryPath = (await import("../prebuilds/darwin-x64/librift_ffi.dylib", { with: { type: "file" } })).default
|
|
13
|
+
} else if (platform === "darwin" && arch === "arm64") {
|
|
14
|
+
libraryPath = (await import("../prebuilds/darwin-arm64/librift_ffi.dylib", { with: { type: "file" } })).default
|
|
15
|
+
} else if (platform === "windows" && arch === "x64") {
|
|
16
|
+
libraryPath = (await import("../prebuilds/windows-x64/rift_ffi.dll", { with: { type: "file" } })).default
|
|
17
|
+
} else {
|
|
18
|
+
throw new Error(`Unsupported Rift platform: ${platform}-${arch}`)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const { symbols } = dlopen(libraryPath, {
|
|
22
|
+
rift_ffi_call: { args: ["ptr"], returns: "ptr" },
|
|
23
|
+
rift_ffi_free: { args: ["ptr"], returns: "void" },
|
|
24
|
+
})
|
|
25
|
+
const encoder = new TextEncoder()
|
|
26
|
+
|
|
27
|
+
function call(request) {
|
|
28
|
+
const input = encoder.encode(`${JSON.stringify(request)}\0`)
|
|
29
|
+
const output = symbols.rift_ffi_call(ptr(input))
|
|
30
|
+
if (!output) throw new Error("Rift native library returned no response")
|
|
31
|
+
let response
|
|
32
|
+
try {
|
|
33
|
+
response = JSON.parse(new CString(output).toString())
|
|
34
|
+
} finally {
|
|
35
|
+
symbols.rift_ffi_free(output)
|
|
36
|
+
}
|
|
37
|
+
if (response.status === "error") throw new RiftError(response.error)
|
|
38
|
+
return response.value
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class RiftError extends Error {
|
|
42
|
+
constructor({ code, message, path }) {
|
|
43
|
+
super(message)
|
|
44
|
+
this.name = "RiftError"
|
|
45
|
+
this.code = code
|
|
46
|
+
this.path = path
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function init({ at = process.cwd(), database } = {}) {
|
|
51
|
+
return call({ command: "init", at, database })
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function create({ from = process.cwd(), name, into, copyAll, hooks, exclude, include, git, defaultExcludes, database } = {}) {
|
|
55
|
+
return call({ command: "create", from, name, into, copyAll, hooks, exclude, include, git, defaultExcludes, database })
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function remove({ at = process.cwd(), all = false, hooks, database } = {}) {
|
|
59
|
+
const result = call({ command: "remove", at, all, hooks, database })
|
|
60
|
+
return all ? result : undefined
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function list({ of = process.cwd(), database } = {}) {
|
|
64
|
+
return call({ command: "list", of, database })
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function ancestors({ of = process.cwd(), database } = {}) {
|
|
68
|
+
return call({ command: "ancestors", of, database })
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function gc({ database } = {}) {
|
|
72
|
+
return call({ command: "gc", database })
|
|
73
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export interface Options {
|
|
2
|
+
database?: string
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface AtOptions extends Options {
|
|
6
|
+
at?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface CreateOptions extends Options {
|
|
10
|
+
from?: string
|
|
11
|
+
name?: string
|
|
12
|
+
into?: string
|
|
13
|
+
copyAll?: boolean
|
|
14
|
+
hooks?: boolean
|
|
15
|
+
exclude?: string[]
|
|
16
|
+
include?: string[]
|
|
17
|
+
git?: boolean
|
|
18
|
+
defaultExcludes?: boolean
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface RemoveOptions extends AtOptions {
|
|
22
|
+
all?: boolean
|
|
23
|
+
hooks?: boolean
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface OfOptions extends Options {
|
|
27
|
+
of?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type RiftErrorCode =
|
|
31
|
+
| "io"
|
|
32
|
+
| "database"
|
|
33
|
+
| "walk"
|
|
34
|
+
| "invalid_path"
|
|
35
|
+
| "cow_unavailable"
|
|
36
|
+
| "initialization_required"
|
|
37
|
+
| "workspace_not_initialized"
|
|
38
|
+
| "missing_marker"
|
|
39
|
+
| "unsupported_entry"
|
|
40
|
+
| "unsafe_git"
|
|
41
|
+
| "not_managed"
|
|
42
|
+
| "marker_mismatch"
|
|
43
|
+
| "unknown_marker"
|
|
44
|
+
| "already_exists"
|
|
45
|
+
| "missing_rift"
|
|
46
|
+
| "inside_source"
|
|
47
|
+
| "invalid_config"
|
|
48
|
+
| "invalid_filter"
|
|
49
|
+
| "invalid_options"
|
|
50
|
+
| "linked_worktree_requires_no_git"
|
|
51
|
+
| "hook_failed"
|
|
52
|
+
| "invalid_request"
|
|
53
|
+
| "panic"
|
|
54
|
+
| "serialization"
|
|
55
|
+
|
|
56
|
+
export class RiftError extends Error {
|
|
57
|
+
code: RiftErrorCode
|
|
58
|
+
path?: string
|
|
59
|
+
constructor(input: { code: RiftErrorCode; message: string; path?: string })
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function init(options?: AtOptions): null
|
|
63
|
+
export function create(options?: CreateOptions): string
|
|
64
|
+
export function remove(options?: RemoveOptions & { all: true }): string[]
|
|
65
|
+
export function remove(options?: RemoveOptions): void
|
|
66
|
+
export function list(options?: OfOptions): string[]
|
|
67
|
+
export function ancestors(options?: OfOptions): string[]
|
|
68
|
+
export function gc(options?: Options): string[]
|
package/node/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { dlopen, toString } from "node:ffi"
|
|
2
|
+
import fs from "node:fs"
|
|
3
|
+
import os from "node:os"
|
|
4
|
+
import path from "node:path"
|
|
5
|
+
import { fileURLToPath } from "node:url"
|
|
6
|
+
|
|
7
|
+
const platform = { darwin: "darwin", linux: "linux", win32: "windows" }[os.platform()]
|
|
8
|
+
const arch = { arm64: "arm64", x64: "x64" }[os.arch()]
|
|
9
|
+
if (!platform || !arch) throw new Error(`Unsupported Rift platform: ${os.platform()}-${os.arch()}`)
|
|
10
|
+
|
|
11
|
+
const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)))
|
|
12
|
+
const libraryName = platform === "windows" ? "rift_ffi.dll" : platform === "darwin" ? "librift_ffi.dylib" : "librift_ffi.so"
|
|
13
|
+
const libraryPath = path.join(root, "prebuilds", `${platform}-${arch}`, libraryName)
|
|
14
|
+
if (!fs.existsSync(libraryPath)) throw new Error(`Unable to locate the Rift Node library for ${platform}-${arch}. Reinstall @collaborationlabs/rift.`)
|
|
15
|
+
|
|
16
|
+
const { functions } = dlopen(libraryPath, {
|
|
17
|
+
rift_ffi_call: { arguments: ["string"], return: "pointer" },
|
|
18
|
+
rift_ffi_free: { arguments: ["pointer"], return: "void" },
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
function call(request) {
|
|
22
|
+
const output = functions.rift_ffi_call(JSON.stringify(request))
|
|
23
|
+
if (!output) throw new Error("Rift native library returned no response")
|
|
24
|
+
let response
|
|
25
|
+
try {
|
|
26
|
+
response = JSON.parse(toString(output))
|
|
27
|
+
} finally {
|
|
28
|
+
functions.rift_ffi_free(output)
|
|
29
|
+
}
|
|
30
|
+
if (response.status === "error") throw new RiftError(response.error)
|
|
31
|
+
return response.value
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class RiftError extends Error {
|
|
35
|
+
constructor({ code, message, path }) {
|
|
36
|
+
super(message)
|
|
37
|
+
this.name = "RiftError"
|
|
38
|
+
this.code = code
|
|
39
|
+
this.path = path
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function init({ at = process.cwd(), database } = {}) {
|
|
44
|
+
return call({ command: "init", at, database })
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function create({ from = process.cwd(), name, into, copyAll, hooks, exclude, include, git, defaultExcludes, database } = {}) {
|
|
48
|
+
return call({ command: "create", from, name, into, copyAll, hooks, exclude, include, git, defaultExcludes, database })
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function remove({ at = process.cwd(), all = false, hooks, database } = {}) {
|
|
52
|
+
const result = call({ command: "remove", at, all, hooks, database })
|
|
53
|
+
return all ? result : undefined
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function list({ of = process.cwd(), database } = {}) {
|
|
57
|
+
return call({ command: "list", of, database })
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function ancestors({ of = process.cwd(), database } = {}) {
|
|
61
|
+
return call({ command: "ancestors", of, database })
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function gc({ database } = {}) {
|
|
65
|
+
return call({ command: "gc", database })
|
|
66
|
+
}
|
package/package.json
CHANGED
|
@@ -1 +1,42 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@collaborationlabs/rift",
|
|
3
|
+
"version": "0.0.15",
|
|
4
|
+
"description": "Fast copy-on-write development workspaces",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/collaborationlabs/rift.git"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"bin": {
|
|
12
|
+
"rift": "bin/rift.js"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./index.d.ts",
|
|
17
|
+
"bun": "./bun/index.js",
|
|
18
|
+
"node": "./node/index.js",
|
|
19
|
+
"default": "./node/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"bin",
|
|
24
|
+
"bun",
|
|
25
|
+
"node",
|
|
26
|
+
"index.d.ts",
|
|
27
|
+
"prebuilds"
|
|
28
|
+
],
|
|
29
|
+
"os": [
|
|
30
|
+
"darwin",
|
|
31
|
+
"linux",
|
|
32
|
+
"win32"
|
|
33
|
+
],
|
|
34
|
+
"cpu": [
|
|
35
|
+
"arm64",
|
|
36
|
+
"x64"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"provenance": true,
|
|
40
|
+
"access": "public"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|