forked from coder/nbin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nbin.d.ts
121 lines (102 loc) · 2.72 KB
/
nbin.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
declare module 'nbin' {
/**
* Returns the stat for a path.
*/
export interface Stat {
readonly isDirectory: boolean;
readonly isFile: boolean;
readonly size: number;
}
export interface Disposable {
dispose(): void;
}
/**
* Checks if a file exists within the binary.
*/
export const existsSync: (path: string) => boolean;
/**
* Performs a stat on paths within the binary.
*/
export const statSync: (path: string) => Stat;
/**
* Reads a directory within the binary.
*/
export const readdirSync: (path: string) => ReadonlyArray<string>;
/**
* Reads a file asynchronously from the binary.
*/
function readFile(path: string, encoding?: "buffer", offset?: number, length?: number): Promise<Buffer>;
function readFile(path: string, encoding?: "utf8", offset?: number, length?: number): Promise<Buffer>;
/**
* Reads a file synchronously from the binary.
*/
function readFileSync(path: string, encoding?: "buffer", offset?: number, length?: number): Buffer;
function readFileSync(path: string, encoding?: "utf8", offset?: number, length?: number): Buffer;
/**
* Uniquely generated ID for the packaged binary.
*/
export const id: string;
/**
* Returns the entrypoint of the application.
*/
export const mainFile: string;
/**
* Shims the native `fs` module for the path
*/
export const shimNativeFs: (path: string) => void;
}
declare module '@coder/nbin' {
export interface BinaryOptions {
/**
* Path of the node binary to bundle.
* *Must* be a patched binary.
*/
readonly nodePath?: string;
/**
* Suppresses log output.
*/
readonly suppressOutput?: boolean;
/**
* Main file for your application.
* Will be called as the entrypoint.
*/
readonly mainFile: string;
/**
* OS target
*/
readonly target?: "darwin" | "alpine" | "linux";
}
/**
* Create a new binary.
*/
export class Binary {
public constructor(
options: BinaryOptions,
);
/**
* Write a file to the bundle at a path.
*/
public writeFile(pathName: string, content: Buffer): void;
/**
* Writes files from an FS glob.
* Calls back as files are written.
* @example
* writeFiles(path.join(__dirname, "dog/**"));
* @returns number of files written
*/
public writeFiles(glob: string, callback?: (fileWritten: string) => void): number;
/**
* Will bundle a module based on path and name.
* Allows you to do `writeModule("/test/bananas/node_modules/frog")` and
* embed the `frog` module within the binary.
*
* All modules by default will be placed in `/node_modules`
*/
public writeModule(modulePath: string): void;
/**
* Bundles the binary.
* @returns the content of the executable file.
*/
public build(): Promise<Buffer>;
}
}