/// /// import type { log } from './log'; import { CompressType } from './compress_type'; export interface FileRecord { file: string; body?: Buffer | string; wasTransformed?: boolean; [key: number]: any; } export type FileRecords = Record; type License = string | { type: string; }; export type Patches = Record; export type ConfigDictionary = Record; }; dependencies?: Record; }>; export type PkgCompressType = Exclude; /** * Build hook called once before the walker collects files. Use for setup * work like pre-bundling with esbuild/webpack, codegen, or fetching assets. * * Function form takes no arguments; throw or return a rejected promise to * abort the build. */ export type PreBuildHook = () => void | Promise; /** * Build hook called once per produced binary, after it has been written * (and codesigned/chmodded on macOS/Linux). Use for smoke tests, signing, * notarization, upload, etc. * * Function form receives the absolute output path. Shell form receives it * via the `PKG_OUTPUT` env var. Throw / non-zero exit to fail the build. */ export type PostBuildHook = (output: string) => void | Promise; /** * Per-file transform applied after the walker collects files and after * refinement, but before bytecode compilation and compression. Use for * minification, obfuscation, or any other content rewrite. * * Receives the absolute on-disk file path and the current contents (a * Buffer when loaded from disk, a string when an earlier step rewrote it). * Return the replacement bytes/string to apply, or `undefined`/`void` to * leave the file unchanged. */ export type TransformHook = (filePath: string, contents: Buffer | string) => string | Buffer | void | undefined | Promise; /** * Build-shaping fields shared verbatim between the config-file shape * (`PkgOptions`) and the programmatic API shape (`PkgExecOptions`): the * boolean toggles, `compress`, `outputPath`, and the build hooks. * * Listy fields with deliberate typing differences (`targets`, * `publicPackages`, `noDictionary` are lenient `string | string[]` in the * config and strict `string[]` in the API) and per-shape-only fields * (e.g. `options` vs `bakeOptions`) stay on the leaf interfaces — pulling * them up here would require generic gymnastics for no net win. */ export interface PkgBaseOptions { /** Directory to save the output executable(s). */ outputPath?: string; /** VFS compression algorithm. Default `'None'`. */ compress?: PkgCompressType; /** Use Node.js Single Executable Application mode. */ sea?: boolean; /** Verbose packaging logs. */ debug?: boolean; /** Compile bytecode. Default `true`. Set to `false` to ship plain JS. */ bytecode?: boolean; /** Build native addons. Default `true`. */ nativeBuild?: boolean; /** If bytecode compilation fails for a file, ship it as plain source. */ fallbackToSource?: boolean; /** Treat the top-level project as public (faster, discloses sources). */ public?: boolean; /** Sign macOS binaries when applicable. Default `true`. */ signature?: boolean; /** * Shell command (string) or JS function run once before the walker * collects files. Throw or reject to abort the build. * * Function form is reachable from the Node.js API and from * `pkg.config.{js,cjs,mjs}`; JSON config files can only carry the shell * form. */ preBuild?: string | PreBuildHook; /** * Shell command (string) or JS function run once per produced binary, * after it has been written. Function form receives the output path; * shell form receives it via `PKG_OUTPUT`. */ postBuild?: string | PostBuildHook; /** * Per-file content transform applied after walking and refinement, before * bytecode and compression. Function-only — shell-string transforms are * not supported because piping every file through a child process would * be prohibitively slow. Receives `(filePath, contents)` and returns the * replacement (or void to keep). */ transform?: TransformHook; } export interface PkgOptions extends PkgBaseOptions { scripts?: string[]; log?: (logger: typeof log, context: Record) => void; assets?: string[]; ignore?: string[]; /** * Files that must be shipped next to the executable instead of bundled. * Each entry is a tuple `[from, to]` or `[from, to, 'directory']` where * `from` is the source path (relative to the package) and `to` is the * destination path relative to the output binary. */ deployFiles?: Array<[string, string] | [string, string, 'directory']>; patches?: Patches; dictionary?: ConfigDictionary; targets?: string | string[]; publicPackages?: string | string[]; options?: string | string[]; noDictionary?: string | string[]; } export interface PackageJson { name?: string; private?: boolean; licenses?: License; license?: License; main?: string; dependencies?: Record; files?: string[]; pkg?: PkgOptions; } export declare const platform: { macos: string; win: string; linux: string; }; /** * Canonical Node.js version string as produced by nodejs.org/dist and * `process.version`: `v..`. Always v-prefixed — * downstream consumers rely on the prefix to build archive filenames * (`node-v22.22.2-linux-x64.tar.gz`) and to compare against * `process.version`. */ export type NodeVersion = `v${number}.${number}.${number}`; /** * pkg's `nodeRange` format: `node` (e.g. `node22`, * `node22.22.2`). Matches `NodeTarget.nodeRange` by convention. */ export type NodeRange = `node${string}`; /** OS segment used in nodejs.org archive filenames. */ export declare const NODE_OSES: readonly ["darwin", "linux", "win"]; export type NodeOs = (typeof NODE_OSES)[number]; /** Arch segment used in nodejs.org archive filenames. */ export declare const NODE_ARCHS: readonly ["x64", "arm64", "armv7l", "ppc64", "s390x", "riscv64", "loong64"]; export type NodeArch = (typeof NODE_ARCHS)[number]; export interface NodeTarget { nodeRange: string; arch: string; platform: keyof typeof platform; forceBuild?: boolean; } export interface Target extends NodeTarget { binaryPath: string; output: string; fabricator: Target; } export interface Marker { hasDictionary?: boolean; activated?: boolean; toplevel?: boolean; public?: boolean; hasDeployFiles?: boolean; config?: PackageJson; configPath: string; base: string; } export interface WalkerParams { publicToplevel?: boolean; publicPackages?: string[]; noDictionary?: string[]; seaMode?: boolean; } export interface SeaEnhancedOptions { seaConfig?: { disableExperimentalSEAWarning?: boolean; useSnapshot?: boolean; useCodeCache?: boolean; }; signature?: boolean; targets: (NodeTarget & Partial)[]; useLocalNode?: boolean; nodePath?: string; marker: Marker; params: WalkerParams; addition?: string; doCompress?: CompressType; } export type SymLinks = Record; export interface PkgExecOptions extends PkgBaseOptions { /** Entry file or directory (required). */ input: string; /** Target specs, e.g. `['node22-linux-x64']` or `['host']`. */ targets?: string[]; /** Path to a `package.json` or standalone config JSON. */ config?: string; /** Output file name or template for multiple targets. */ output?: string; /** Bake Node/V8 CLI options into the executable (e.g. `['expose-gc']`). */ bakeOptions?: string | string[]; /** Build base binaries from source instead of downloading prebuilt ones. */ build?: boolean; /** Package names to treat as public. `['*']` for all packages. */ publicPackages?: string[]; /** Package names to ignore dictionaries for. `['*']` to disable all. */ noDictionary?: string[]; } export {}; //# sourceMappingURL=types.d.ts.map