@lakutata/builder 3.0.0-beta.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/LICENSE +23 -0
- package/README.md +27 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/lib/Archive.js +21 -0
- package/dist/esm/lib/Bundle.js +162 -0
- package/dist/esm/lib/Executable.js +221 -0
- package/dist/esm/lib/Icons.js +372 -0
- package/dist/esm/lib/Installer.js +158 -0
- package/dist/esm/lib/Native.js +533 -0
- package/dist/esm/lib/NativeRuntime.js +177 -0
- package/dist/esm/lib/Platform.js +9 -0
- package/dist/esm/lib/Processes.js +42 -0
- package/dist/esm/lib/Scripts.js +161 -0
- package/dist/esm/lib/Tools.js +109 -0
- package/dist/esm/lib/electron/Electron.js +366 -0
- package/dist/esm/lib/linux/Linux.js +361 -0
- package/dist/esm/lib/mac/Mac.js +270 -0
- package/dist/esm/lib/win/Windows.js +525 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/lib/Archive.d.ts +14 -0
- package/dist/types/lib/Bundle.d.ts +96 -0
- package/dist/types/lib/Executable.d.ts +50 -0
- package/dist/types/lib/Icons.d.ts +70 -0
- package/dist/types/lib/Installer.d.ts +242 -0
- package/dist/types/lib/Native.d.ts +196 -0
- package/dist/types/lib/NativeRuntime.d.ts +75 -0
- package/dist/types/lib/Platform.d.ts +4 -0
- package/dist/types/lib/Processes.d.ts +21 -0
- package/dist/types/lib/Scripts.d.ts +77 -0
- package/dist/types/lib/Tools.d.ts +32 -0
- package/dist/types/lib/electron/Electron.d.ts +13 -0
- package/dist/types/lib/linux/Linux.d.ts +29 -0
- package/dist/types/lib/mac/Mac.d.ts +19 -0
- package/dist/types/lib/win/Windows.d.ts +20 -0
- package/package.json +51 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type BundleOptions } from './Bundle.js';
|
|
2
|
+
export type ExecutableOptions = Omit<BundleOptions, 'outfile' | 'native' | 'directories'> & {
|
|
3
|
+
/**
|
|
4
|
+
* The directory of the executable, dist by default
|
|
5
|
+
*/
|
|
6
|
+
outdir?: string;
|
|
7
|
+
/**
|
|
8
|
+
* One file, its native tree and its resources embedded, extracted at its first run (by default); or a directory, the
|
|
9
|
+
* executable and its native tree (native) and its resources (resources) next to it, loaded from there (the
|
|
10
|
+
* installers, the images)
|
|
11
|
+
*/
|
|
12
|
+
layout?: 'file' | 'directory';
|
|
13
|
+
};
|
|
14
|
+
export type ExecutableResult = {
|
|
15
|
+
name: string;
|
|
16
|
+
/**
|
|
17
|
+
* The executable, and its platform ("darwin-arm64")
|
|
18
|
+
*/
|
|
19
|
+
file: string;
|
|
20
|
+
platform: string;
|
|
21
|
+
size: number;
|
|
22
|
+
/**
|
|
23
|
+
* The packages of native addons embedded, extracted at the first run, or next to the executable
|
|
24
|
+
*/
|
|
25
|
+
native: string[];
|
|
26
|
+
/**
|
|
27
|
+
* The resources of the application (their paths in the resources)
|
|
28
|
+
*/
|
|
29
|
+
resources: string[];
|
|
30
|
+
/**
|
|
31
|
+
* The directory of the executable, its native tree and its resources (the layout directory)
|
|
32
|
+
*/
|
|
33
|
+
directory?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The runtime embedded in the executable, and its version ("Node.js v24.11.1", "Bun 1.4.2")
|
|
36
|
+
*/
|
|
37
|
+
runtime: string;
|
|
38
|
+
/**
|
|
39
|
+
* What to do before distributing the executable (sign it)
|
|
40
|
+
*/
|
|
41
|
+
warnings: string[];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Make the executable of the application for the platform it is made on, which runs without Node.js installed: its bundle
|
|
45
|
+
* embedded in the Node.js binary running the tool (the single executable applications of Node.js), or compiled by Bun.
|
|
46
|
+
* The executables of the other platforms are made on them (their native addons are built there), as the applications are
|
|
47
|
+
* built there
|
|
48
|
+
* @param options
|
|
49
|
+
*/
|
|
50
|
+
export declare function buildExecutable(options: ExecutableOptions): Promise<ExecutableResult>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An image: its pixels, red, green, blue and alpha (8 bits each), by rows
|
|
3
|
+
*/
|
|
4
|
+
export type Image = {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
pixels: Buffer;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Decode a PNG file (not interlaced): its pixels in RGBA, whatever its colors (gray, RGB, palette, with alpha) and its
|
|
11
|
+
* depth (1 to 16 bits)
|
|
12
|
+
* @param data
|
|
13
|
+
* @param file its name, in the errors
|
|
14
|
+
*/
|
|
15
|
+
export declare function decodePng(data: Buffer, file?: string): Image;
|
|
16
|
+
/**
|
|
17
|
+
* Encode an image into a PNG file (RGBA, 8 bits)
|
|
18
|
+
* @param image
|
|
19
|
+
*/
|
|
20
|
+
export declare function encodePng(image: Image): Buffer;
|
|
21
|
+
/**
|
|
22
|
+
* Resize an image (a square into a square): each pixel the average of the ones it covers, weighted by their alpha
|
|
23
|
+
* (premultiplied, the transparent edges keep their colors)
|
|
24
|
+
* @param image
|
|
25
|
+
* @param size
|
|
26
|
+
*/
|
|
27
|
+
export declare function resize(image: Image, size: number): Image;
|
|
28
|
+
/**
|
|
29
|
+
* The sizes of the icons of Windows (ico)
|
|
30
|
+
*/
|
|
31
|
+
export declare const ICO_SIZES: number[];
|
|
32
|
+
/**
|
|
33
|
+
* The icon of Windows (ico) of an image, in its sizes: the bitmaps of the ones smaller than 256 (the format every tool
|
|
34
|
+
* reads: the resources of the executables, NSIS, Windows Installer), the PNG of 256
|
|
35
|
+
* @param image
|
|
36
|
+
*/
|
|
37
|
+
export declare function icoFile(image: Image): Buffer;
|
|
38
|
+
/**
|
|
39
|
+
* The icon of macOS (icns) of an image: its PNG in the sizes of macOS, but the ones larger than it
|
|
40
|
+
* @param image
|
|
41
|
+
*/
|
|
42
|
+
export declare function icnsFile(image: Image): Buffer;
|
|
43
|
+
/**
|
|
44
|
+
* The sizes of the icons of Linux (the hicolor theme)
|
|
45
|
+
*/
|
|
46
|
+
export declare const LINUX_SIZES: number[];
|
|
47
|
+
/**
|
|
48
|
+
* Write the icons of Linux of an image into a directory: its PNG in the sizes of the hicolor theme (<size>x<size>.png),
|
|
49
|
+
* but the ones larger than it
|
|
50
|
+
* @param image
|
|
51
|
+
* @param directory
|
|
52
|
+
*/
|
|
53
|
+
export declare function writeLinuxIcons(image: Image, directory: string): Promise<string[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Give an executable of Windows the icon (ico), as its icon groups (the one of node.exe), its signature removed (it does
|
|
56
|
+
* not match it anymore)
|
|
57
|
+
* @param file
|
|
58
|
+
* @param ico
|
|
59
|
+
*/
|
|
60
|
+
export declare function setExecutableIcon(file: string, ico: Buffer): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* The icon of the application (lakutata.icon of its package.json): a square PNG image, 256 pixels at least (1024 for
|
|
63
|
+
* the Retina screens of macOS), undefined without icon
|
|
64
|
+
* @param project
|
|
65
|
+
* @param manifest
|
|
66
|
+
*/
|
|
67
|
+
export declare function applicationIcon(project: string, manifest: Record<string, any>): {
|
|
68
|
+
file: string;
|
|
69
|
+
image: Image;
|
|
70
|
+
} | undefined;
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { type ExecutableResult } from './Executable.js';
|
|
2
|
+
import { type InstallerScripts, type NativeScripts, type TargetScripts } from './Scripts.js';
|
|
3
|
+
import { type LinuxTarget } from './linux/Linux.js';
|
|
4
|
+
import { type MacTarget } from './mac/Mac.js';
|
|
5
|
+
import { type WindowsTarget } from './win/Windows.js';
|
|
6
|
+
/**
|
|
7
|
+
* The service an installer registers (systemd, OpenRC): the application runs at the start of the system
|
|
8
|
+
*/
|
|
9
|
+
export type ServiceOptions = {
|
|
10
|
+
/**
|
|
11
|
+
* The name of the service, the one of the package by default
|
|
12
|
+
*/
|
|
13
|
+
name?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The arguments of the application
|
|
17
|
+
*/
|
|
18
|
+
args?: string[];
|
|
19
|
+
/**
|
|
20
|
+
* Its environment, written to the environment file of the service (/etc/<name>/<name>.env), which the
|
|
21
|
+
* administrators change: MODE=production by default
|
|
22
|
+
*/
|
|
23
|
+
env?: Record<string, string>;
|
|
24
|
+
/**
|
|
25
|
+
* The user running it: a system user named after the package by default (created by the installer), or root; on
|
|
26
|
+
* Windows, its virtual account by default (NT SERVICE\<service>), LocalService, NetworkService or LocalSystem
|
|
27
|
+
*/
|
|
28
|
+
user?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Whether it is started again when it exits: on-failure (by default), always or no
|
|
31
|
+
*/
|
|
32
|
+
restart?: 'on-failure' | 'always' | 'no';
|
|
33
|
+
/**
|
|
34
|
+
* Whether it is enabled and started by the installation (by default), or by the administrators
|
|
35
|
+
*/
|
|
36
|
+
autoStart?: boolean;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The installers of an application, declared by the "lakutata.installer" of its package.json (as the configuration of
|
|
40
|
+
* electron-builder)
|
|
41
|
+
*/
|
|
42
|
+
export type InstallerConfig = {
|
|
43
|
+
/**
|
|
44
|
+
* The name of the package (lower case), the one of the program by default
|
|
45
|
+
*/
|
|
46
|
+
name?: string;
|
|
47
|
+
/**
|
|
48
|
+
* The identifier of the application (reverse DNS: com.acme.app), its name by default: the identifier of the package
|
|
49
|
+
* of macOS and the label of its service (launchd), the key of its uninstaller and of its upgrades on Windows
|
|
50
|
+
*/
|
|
51
|
+
appId?: string;
|
|
52
|
+
/**
|
|
53
|
+
* The name of the application shown to the users (the installers, the programs of Windows), its name by default
|
|
54
|
+
*/
|
|
55
|
+
productName?: string;
|
|
56
|
+
/**
|
|
57
|
+
* The description, the maintainer, the home page and the license: the ones of the package.json by default
|
|
58
|
+
*/
|
|
59
|
+
description?: string;
|
|
60
|
+
maintainer?: string;
|
|
61
|
+
homepage?: string;
|
|
62
|
+
license?: string;
|
|
63
|
+
vendor?: string;
|
|
64
|
+
/**
|
|
65
|
+
* The runtime of the executable: node (by default) or bun; electron for the Electron applications, whose installers
|
|
66
|
+
* are made by electron-builder
|
|
67
|
+
*/
|
|
68
|
+
runtime?: 'node' | 'bun' | 'electron';
|
|
69
|
+
/**
|
|
70
|
+
* The configuration of electron-builder of an Electron application, merged over the one made from lakutata.installer
|
|
71
|
+
*/
|
|
72
|
+
electron?: Record<string, unknown>;
|
|
73
|
+
/**
|
|
74
|
+
* Whether the program is in the PATH of the system (/usr/bin/<program>), by default
|
|
75
|
+
*/
|
|
76
|
+
addToPath?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* The service of the application, none by default
|
|
79
|
+
*/
|
|
80
|
+
service?: boolean | ServiceOptions;
|
|
81
|
+
linux?: {
|
|
82
|
+
/**
|
|
83
|
+
* The packages: deb, rpm and tar.gz on the systems of the glibc, apk and tar.gz on the ones of musl (Alpine) by
|
|
84
|
+
* default
|
|
85
|
+
*/
|
|
86
|
+
targets?: LinuxTarget[];
|
|
87
|
+
/**
|
|
88
|
+
* The packages of the system it needs
|
|
89
|
+
*/
|
|
90
|
+
depends?: string[];
|
|
91
|
+
recommends?: string[];
|
|
92
|
+
section?: string;
|
|
93
|
+
priority?: string;
|
|
94
|
+
/**
|
|
95
|
+
* The scripts the packages run (sh), given install, upgrade or remove
|
|
96
|
+
*/
|
|
97
|
+
scripts?: InstallerScripts;
|
|
98
|
+
/**
|
|
99
|
+
* The ones of each package, replacing them; its native scripts, run as nFPM gives them to the package (with its
|
|
100
|
+
* own arguments)
|
|
101
|
+
*/
|
|
102
|
+
deb?: {
|
|
103
|
+
scripts?: InstallerScripts;
|
|
104
|
+
nativeScripts?: NativeScripts;
|
|
105
|
+
};
|
|
106
|
+
rpm?: {
|
|
107
|
+
scripts?: InstallerScripts;
|
|
108
|
+
nativeScripts?: NativeScripts;
|
|
109
|
+
};
|
|
110
|
+
apk?: {
|
|
111
|
+
scripts?: InstallerScripts;
|
|
112
|
+
nativeScripts?: NativeScripts;
|
|
113
|
+
};
|
|
114
|
+
archlinux?: {
|
|
115
|
+
scripts?: InstallerScripts;
|
|
116
|
+
nativeScripts?: NativeScripts;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
mac?: {
|
|
120
|
+
/**
|
|
121
|
+
* The installers: pkg and tar.gz by default
|
|
122
|
+
*/
|
|
123
|
+
targets?: MacTarget[];
|
|
124
|
+
/**
|
|
125
|
+
* The scripts the package runs (sh), given install, upgrade or remove (the removal is the one of its uninstall
|
|
126
|
+
* script)
|
|
127
|
+
*/
|
|
128
|
+
scripts?: InstallerScripts;
|
|
129
|
+
pkg?: {
|
|
130
|
+
scripts?: InstallerScripts;
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
win?: {
|
|
134
|
+
/**
|
|
135
|
+
* The installers: nsis, msi and zip by default
|
|
136
|
+
*/
|
|
137
|
+
targets?: WindowsTarget[];
|
|
138
|
+
/**
|
|
139
|
+
* The scripts the installers run (PowerShell, .ps1), given install, upgrade or remove
|
|
140
|
+
*/
|
|
141
|
+
scripts?: InstallerScripts;
|
|
142
|
+
/**
|
|
143
|
+
* The ones of the installer of NSIS, replacing them; the file of NSIS it includes (.nsh), its macros inserted
|
|
144
|
+
* (customHeader, customInit, customInstall, customUnInit, customUnInstall)
|
|
145
|
+
*/
|
|
146
|
+
nsis?: {
|
|
147
|
+
scripts?: InstallerScripts;
|
|
148
|
+
include?: string;
|
|
149
|
+
};
|
|
150
|
+
msi?: {
|
|
151
|
+
scripts?: InstallerScripts;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
export type InstallerOptions = {
|
|
156
|
+
/**
|
|
157
|
+
* The directory of the project (its package.json)
|
|
158
|
+
*/
|
|
159
|
+
project: string;
|
|
160
|
+
entry?: string;
|
|
161
|
+
minify?: boolean;
|
|
162
|
+
external?: string[];
|
|
163
|
+
/**
|
|
164
|
+
* The packages made, the ones of the configuration by default
|
|
165
|
+
*/
|
|
166
|
+
targets?: string[];
|
|
167
|
+
/**
|
|
168
|
+
* The directory of the packages, dist/installer by default
|
|
169
|
+
*/
|
|
170
|
+
outdir?: string;
|
|
171
|
+
};
|
|
172
|
+
export type InstallerResult = {
|
|
173
|
+
name: string;
|
|
174
|
+
version: string;
|
|
175
|
+
/**
|
|
176
|
+
* The packages made
|
|
177
|
+
*/
|
|
178
|
+
files: {
|
|
179
|
+
target: string;
|
|
180
|
+
file: string;
|
|
181
|
+
size: number;
|
|
182
|
+
}[];
|
|
183
|
+
/**
|
|
184
|
+
* The executable they install
|
|
185
|
+
*/
|
|
186
|
+
executable: ExecutableResult;
|
|
187
|
+
warnings: string[];
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* What an installer installs, resolved from the configuration
|
|
191
|
+
*/
|
|
192
|
+
export type InstallerPlan = {
|
|
193
|
+
/**
|
|
194
|
+
* The name of the package, its identifier, the name of the program, the version
|
|
195
|
+
*/
|
|
196
|
+
name: string;
|
|
197
|
+
appId: string;
|
|
198
|
+
productName: string;
|
|
199
|
+
program: string;
|
|
200
|
+
version: string;
|
|
201
|
+
description: string;
|
|
202
|
+
maintainer: string;
|
|
203
|
+
homepage?: string;
|
|
204
|
+
license?: string;
|
|
205
|
+
vendor?: string;
|
|
206
|
+
addToPath: boolean;
|
|
207
|
+
service?: Required<Omit<ServiceOptions, 'description'>> & {
|
|
208
|
+
description: string;
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* The packages of the system it needs and recommends, its section and its priority (deb)
|
|
212
|
+
*/
|
|
213
|
+
depends: string[];
|
|
214
|
+
recommends: string[];
|
|
215
|
+
section?: string;
|
|
216
|
+
priority?: string;
|
|
217
|
+
/**
|
|
218
|
+
* The directory of the executable, its native addons and its resources
|
|
219
|
+
*/
|
|
220
|
+
directory: string;
|
|
221
|
+
/**
|
|
222
|
+
* Where it is installed (/opt/<name> on Linux, /usr/local/lib/<name> on macOS)
|
|
223
|
+
*/
|
|
224
|
+
prefix: string;
|
|
225
|
+
/**
|
|
226
|
+
* The scripts of the application each installer runs
|
|
227
|
+
*/
|
|
228
|
+
scripts: Record<string, TargetScripts>;
|
|
229
|
+
/**
|
|
230
|
+
* The icon of the installers of Windows and of their application (ico), made from the icon of the application
|
|
231
|
+
* (lakutata.icon), none without it
|
|
232
|
+
*/
|
|
233
|
+
icon?: string;
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Make the installers of the application for the platform it is made on (the installers of the other platforms are
|
|
237
|
+
* made on them, as its executables): its executable in a directory, with its native addons and its resources, installed
|
|
238
|
+
* in /opt/<name> (Linux) or /usr/local/lib/<name> (macOS), its program in the PATH, its service registered (systemd,
|
|
239
|
+
* OpenRC, launchd)
|
|
240
|
+
* @param options
|
|
241
|
+
*/
|
|
242
|
+
export declare function buildInstaller(options: InstallerOptions): Promise<InstallerResult>;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import type { Plugin, PluginBuild } from 'esbuild';
|
|
2
|
+
/**
|
|
3
|
+
* A file of the native tree: its path in the tree ("/" separated) and where it is read
|
|
4
|
+
*/
|
|
5
|
+
export type NativeFile = {
|
|
6
|
+
path: string;
|
|
7
|
+
source: string;
|
|
8
|
+
mode: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A link of the native tree to a directory of the tree, as the links of the node_modules (pnpm, the workspaces)
|
|
12
|
+
*/
|
|
13
|
+
export type NativeLink = {
|
|
14
|
+
path: string;
|
|
15
|
+
target: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The native addons of an application and what they need at run time, which cannot be bundled: their packages (and
|
|
19
|
+
* the packages they load), laid out as node lays them out, loaded from the disk.
|
|
20
|
+
* The tree is the layout of the packages from the directory of their node_modules (the project, the workspace): node
|
|
21
|
+
* finds them there as it finds them in the project; the links of the tree are the ones of the project (the packages of
|
|
22
|
+
* the workspace, pnpm) and the packages the application loads which are not in its node_modules. The addons loaded by the
|
|
23
|
+
* application itself are in .lakutata/addons
|
|
24
|
+
*/
|
|
25
|
+
export type NativeTree = {
|
|
26
|
+
/**
|
|
27
|
+
* The packages the application loads from the tree
|
|
28
|
+
*/
|
|
29
|
+
modules: string[];
|
|
30
|
+
files: NativeFile[];
|
|
31
|
+
links: NativeLink[];
|
|
32
|
+
/**
|
|
33
|
+
* The hash of the tree, which names the directory it is extracted into
|
|
34
|
+
*/
|
|
35
|
+
hash: string;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The index of a packed native tree
|
|
39
|
+
*/
|
|
40
|
+
export type NativeIndex = {
|
|
41
|
+
hash: string;
|
|
42
|
+
files: {
|
|
43
|
+
path: string;
|
|
44
|
+
offset: number;
|
|
45
|
+
size: number;
|
|
46
|
+
mode: number;
|
|
47
|
+
}[];
|
|
48
|
+
links: NativeLink[];
|
|
49
|
+
};
|
|
50
|
+
type PackageInfo = {
|
|
51
|
+
root: string;
|
|
52
|
+
name: string;
|
|
53
|
+
manifest: Record<string, any>;
|
|
54
|
+
addons: boolean;
|
|
55
|
+
libraries: boolean;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* The name of the package of a module specifier ("@scope/name/sub/path" → "@scope/name"), undefined for a path
|
|
59
|
+
* @param specifier
|
|
60
|
+
*/
|
|
61
|
+
export declare function specifierPackage(specifier: string): string | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Find the native addons of an application while it is bundled: the packages holding addons (and the packages loading
|
|
64
|
+
* them with computed paths, such as sharp) are left out of the bundle and gathered, with the packages they load, into
|
|
65
|
+
* a native tree; the addons of the application itself are loaded from the tree
|
|
66
|
+
*/
|
|
67
|
+
export declare class NativeCollector {
|
|
68
|
+
protected readonly project: string;
|
|
69
|
+
protected readonly runtime: 'node' | 'bun';
|
|
70
|
+
protected readonly packages: Map<string, PackageInfo | undefined>;
|
|
71
|
+
protected readonly roots: Map<string, string | undefined>;
|
|
72
|
+
/**
|
|
73
|
+
* The packages left out of the bundle, by the name the application loads them with, and the files it loads
|
|
74
|
+
*/
|
|
75
|
+
protected readonly externals: Map<string, {
|
|
76
|
+
root: string;
|
|
77
|
+
entries: Set<string>;
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* The addons of the application itself, by their key in the tree
|
|
81
|
+
*/
|
|
82
|
+
protected readonly addons: Map<string, string>;
|
|
83
|
+
/**
|
|
84
|
+
* The files of the packages of the tree which are loaded, by package (traced)
|
|
85
|
+
*/
|
|
86
|
+
protected readonly loaded: Map<string, Set<string>>;
|
|
87
|
+
/**
|
|
88
|
+
* The packages of the tree kept as a whole: the ones which are not traced, the ones loading their files by paths
|
|
89
|
+
* esbuild cannot follow
|
|
90
|
+
*/
|
|
91
|
+
protected readonly whole: Set<string>;
|
|
92
|
+
/**
|
|
93
|
+
* The packages each package of the tree requires, by their names (traced)
|
|
94
|
+
*/
|
|
95
|
+
protected readonly required: Map<string, Map<string, string>>;
|
|
96
|
+
/**
|
|
97
|
+
* @param project the directory of the project, whose files are bundled
|
|
98
|
+
* @param runtime the runtime loading the tree: Bun resolves the packages with its condition (bun) first
|
|
99
|
+
*/
|
|
100
|
+
constructor(project: string, runtime?: 'node' | 'bun');
|
|
101
|
+
/**
|
|
102
|
+
* The directory of the package a file belongs to: the nearest directory with a named package.json
|
|
103
|
+
* @param file
|
|
104
|
+
*/
|
|
105
|
+
protected packageRoot(file: string): string | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* A package: its manifest and whether it holds addons or shared libraries
|
|
108
|
+
* @param root
|
|
109
|
+
*/
|
|
110
|
+
protected package(root: string): PackageInfo | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* The dependencies of a package, as node finds them from it: the path looked up (a link with pnpm) and the package
|
|
113
|
+
* @param root
|
|
114
|
+
*/
|
|
115
|
+
protected dependencies(root: string): {
|
|
116
|
+
name: string;
|
|
117
|
+
lookup: string;
|
|
118
|
+
root: string;
|
|
119
|
+
}[];
|
|
120
|
+
/**
|
|
121
|
+
* Whether a package is left out of the bundle: it holds addons, or one of its dependencies does (it loads them,
|
|
122
|
+
* with computed paths often), and it is not the project
|
|
123
|
+
* @param root
|
|
124
|
+
*/
|
|
125
|
+
protected isNative(root: string | undefined): root is string;
|
|
126
|
+
/**
|
|
127
|
+
* Resolve an import as esbuild does
|
|
128
|
+
* @param build
|
|
129
|
+
* @param args
|
|
130
|
+
*/
|
|
131
|
+
protected resolve(build: PluginBuild, args: {
|
|
132
|
+
path: string;
|
|
133
|
+
kind: any;
|
|
134
|
+
resolveDir: string;
|
|
135
|
+
importer: string;
|
|
136
|
+
}): Promise<string | undefined>;
|
|
137
|
+
/**
|
|
138
|
+
* The plugin of the bundle: the native packages are external, the addons of the application are loaded from the tree
|
|
139
|
+
*/
|
|
140
|
+
plugin(): Plugin;
|
|
141
|
+
/**
|
|
142
|
+
* The packages a native package loads at run time: the JavaScript it requires (followed by esbuild), the packages of
|
|
143
|
+
* shared libraries it depends on (the libraries linked with its addons), and the native packages it loads
|
|
144
|
+
* @param build the build function of esbuild
|
|
145
|
+
* @param root
|
|
146
|
+
* @param entries the files of the package which are loaded
|
|
147
|
+
* @param included the packages of the tree
|
|
148
|
+
*/
|
|
149
|
+
protected trace(build: typeof import('esbuild').build, root: string, entries: Set<string>, included: Set<string>): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* The packages a package requires, by their names
|
|
152
|
+
* @param root
|
|
153
|
+
*/
|
|
154
|
+
protected requires(root: string): Map<string, string>;
|
|
155
|
+
/**
|
|
156
|
+
* The layout of the packages of the tree, without links (as npm installs them, the tree is moved, copied, archived
|
|
157
|
+
* and installed as it is): the packages the application loads in node_modules, the packages each package requires
|
|
158
|
+
* (traced) or declares where node finds them from it: shared when node finds the same package, at the top when its
|
|
159
|
+
* name is free there, else in the node_modules of the package
|
|
160
|
+
* @param included the packages of the tree
|
|
161
|
+
* @return the packages by their directories in the tree
|
|
162
|
+
*/
|
|
163
|
+
protected layout(included: Set<string>): Map<string, string>;
|
|
164
|
+
/**
|
|
165
|
+
* The files of a package of the tree which are loaded at run time, without the ones node never loads (UNUSED): the
|
|
166
|
+
* packages of shared libraries (which find their addons by computed paths), and the ones kept as a whole, have all
|
|
167
|
+
* their files; the others have the JavaScript files they load (traced) and all their other files (the data they read)
|
|
168
|
+
* @param root
|
|
169
|
+
*/
|
|
170
|
+
protected packageFiles(root: string): string[];
|
|
171
|
+
/**
|
|
172
|
+
* The native tree of the application, once it is bundled; undefined when it has no native addon
|
|
173
|
+
*/
|
|
174
|
+
collect(): Promise<NativeTree | undefined>;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The hash of a native tree, which names the directory it is extracted into: its files and their content, its links
|
|
178
|
+
* @param files
|
|
179
|
+
* @param links
|
|
180
|
+
*/
|
|
181
|
+
export declare function hashNativeTree(files: NativeFile[], links: NativeLink[]): string;
|
|
182
|
+
/**
|
|
183
|
+
* Write a native tree into a directory (next to a bundle)
|
|
184
|
+
* @param tree
|
|
185
|
+
* @param directory
|
|
186
|
+
*/
|
|
187
|
+
export declare function writeNativeTree(tree: NativeTree, directory: string): Promise<void>;
|
|
188
|
+
/**
|
|
189
|
+
* Pack a native tree into the assets of an executable: its gzipped files and their index
|
|
190
|
+
* @param tree
|
|
191
|
+
*/
|
|
192
|
+
export declare function packNativeTree(tree: NativeTree): {
|
|
193
|
+
index: NativeIndex;
|
|
194
|
+
data: Buffer;
|
|
195
|
+
};
|
|
196
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the require of a bundle knows of its native tree
|
|
3
|
+
*/
|
|
4
|
+
export type NativeRuntimeConfig = {
|
|
5
|
+
/**
|
|
6
|
+
* The name of the program, which names its cache directory
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* The hash of the tree, which names the directory it is extracted into
|
|
11
|
+
*/
|
|
12
|
+
hash: string;
|
|
13
|
+
/**
|
|
14
|
+
* The directory of the tree next to the bundle (the bundles run by node), or in the resources of a packaged Electron
|
|
15
|
+
* application
|
|
16
|
+
*/
|
|
17
|
+
directory: string;
|
|
18
|
+
/**
|
|
19
|
+
* The packages loaded from the tree
|
|
20
|
+
*/
|
|
21
|
+
modules: string[];
|
|
22
|
+
/**
|
|
23
|
+
* Whether the tree is embedded in an executable, extracted at its first run (with the resources of the application,
|
|
24
|
+
* in its .lakutata/resources), or a directory next to the bundle
|
|
25
|
+
*/
|
|
26
|
+
embedded: boolean;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The global symbol of the packed applications giving the directory of their resources (resourcesPath of lakutata)
|
|
30
|
+
*/
|
|
31
|
+
export declare const PACKAGED: string;
|
|
32
|
+
/**
|
|
33
|
+
* The directory of the resources of the embedded trees
|
|
34
|
+
*/
|
|
35
|
+
export declare const EMBEDDED_RESOURCES: string;
|
|
36
|
+
/**
|
|
37
|
+
* The asset of the executables holding the files of the native tree (gzipped), and the one of its index
|
|
38
|
+
*/
|
|
39
|
+
export declare const NATIVE_DATA_ASSET: string;
|
|
40
|
+
export declare const NATIVE_INDEX_ASSET: string;
|
|
41
|
+
/**
|
|
42
|
+
* The global symbol of the executables of Bun giving the files of the native tree they embed: {data, index}, their paths
|
|
43
|
+
* in the executable
|
|
44
|
+
*/
|
|
45
|
+
export declare const BUN_NATIVE_ASSETS: string;
|
|
46
|
+
/**
|
|
47
|
+
* The require of a bundle having native addons, which loads the native packages from the native tree: next to the bundle,
|
|
48
|
+
* or, in an executable, extracted from its assets once into the cache directory of the program (a directory named after
|
|
49
|
+
* the hash of the tree: the versions of the program do not share it). The assets are the ones of a single executable
|
|
50
|
+
* application of Node.js, or the files embedded in an executable of Bun. The other modules are loaded by the require of node.
|
|
51
|
+
* Its source is written at the top of the bundle: it uses nothing but its arguments and the modules of node
|
|
52
|
+
* @param nodeRequire
|
|
53
|
+
* @param config
|
|
54
|
+
*/
|
|
55
|
+
export declare function lakutataNativeRequire(nodeRequire: NodeJS.Require, config: NativeRuntimeConfig): NodeJS.Require;
|
|
56
|
+
/**
|
|
57
|
+
* Load the environment file of the application into its environment, before it starts: the file given by
|
|
58
|
+
* LAKUTATA_ENV_FILE (the services of Windows, whose wrapper has none), its lines NAME=value or NAME="value" (the
|
|
59
|
+
* quoted values with their \\ escapes, as the installers write them), its comments (#). Its source is written at the top
|
|
60
|
+
* of the bundle: it uses nothing but its argument and the modules of node
|
|
61
|
+
* @param nodeRequire
|
|
62
|
+
*/
|
|
63
|
+
export declare function lakutataEnvironmentFile(nodeRequire: NodeJS.Require): void;
|
|
64
|
+
/**
|
|
65
|
+
* The source given to the top of every bundle: it is packed (isPackaged of lakutata), its resources are in a directory
|
|
66
|
+
* next to it, or in the resources of a packaged Electron application (outside of its archive); its environment file is
|
|
67
|
+
* loaded (LAKUTATA_ENV_FILE)
|
|
68
|
+
* @param directory the directory of the resources, relative to the bundle
|
|
69
|
+
*/
|
|
70
|
+
export declare function packagedBanner(directory: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* The source given to the top of a bundle: its require loads the native packages from the tree
|
|
73
|
+
* @param config
|
|
74
|
+
*/
|
|
75
|
+
export declare function nativeBanner(config: NativeRuntimeConfig): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ChildProcess, type SpawnOptions } from 'node:child_process';
|
|
2
|
+
/**
|
|
3
|
+
* Spawn a command: on Windows, the commands found in the PATH by their names (the package managers, the commands of npm:
|
|
4
|
+
* npm.cmd, bun.cmd) are scripts, run by cmd.exe with their arguments quoted; the executables given by their paths (the
|
|
5
|
+
* ones of spaces: C:\Program Files\nodejs\node.exe) are run as they are
|
|
6
|
+
* @param command
|
|
7
|
+
* @param args
|
|
8
|
+
* @param options
|
|
9
|
+
*/
|
|
10
|
+
export declare function spawnCommand(command: string, args: string[], options: SpawnOptions): ChildProcess;
|
|
11
|
+
/**
|
|
12
|
+
* Run a command, its output is given back
|
|
13
|
+
* @param command
|
|
14
|
+
* @param args
|
|
15
|
+
* @param cwd
|
|
16
|
+
* @return the exit code and the output
|
|
17
|
+
*/
|
|
18
|
+
export declare function runCommand(command: string, args: string[], cwd: string): Promise<{
|
|
19
|
+
code: number;
|
|
20
|
+
output: string;
|
|
21
|
+
}>;
|