Skip to content

Commit

Permalink
feat!: add experimental sea support and drop nodejs 16 support (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Oct 22, 2024
1 parent f9f474b commit 0145a94
Show file tree
Hide file tree
Showing 10 changed files with 877 additions and 238 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false # prevent test to stop if one fails
matrix:
node-version: [16.x, 18.x]
node-version: [18.x, 20.x]
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -25,6 +25,7 @@ jobs:
key: ${{ matrix.os }}-${{ matrix.node-version }}

- run: yarn install

- if: matrix['node-version'] == '18.x' && matrix['os'] == 'ubuntu-latest'
run: yarn lint
- run: yarn build
Expand Down
32 changes: 15 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
**Disclaimer: `pkg` was created for use within containers and is not intended for use in serverless environments. For those using Vercel, this means that there is no requirement to use `pkg` in your projects as the benefits it provides are not applicable to the platform.**

![](https://res.cloudinary.com/zeit-inc/image/upload/v1509936789/repositories/pkg/pkg-repo-banner-new.png)

[![Build Status](https://github.com/yao-pkg/pkg/actions/workflows/ci.yml/badge.svg)](https://github.com/yao-pkg/pkg/actions/workflows/ci.yml)

This command line interface enables you to package your Node.js project into an executable that can be run even on devices without Node.js installed.
Expand All @@ -27,7 +23,7 @@ npm install -g @yao-pkg/pkg
After installing it, run `pkg --help` without arguments to see list of options:

```console
pkg [options] <input>
pkg [options] <input>

Options:

Expand All @@ -44,30 +40,32 @@ pkg [options] <input>
--public-packages force specified packages to be considered public
--no-bytecode skip bytecode generation and include source files as plain js
--no-native-build skip native addons build
--no-signature skip signature of the final executable on macos
--no-dict comma-separated list of packages names to ignore dictionaries. Use --no-dict * to disable all dictionaries
-C, --compress [default=None] compression algorithm = Brotli or GZip
--sea (Experimental) compile give file using node's SEA feature. Requires node v20.0.0 or higher and only single file is supported

Examples:

- Makes executables for Linux, macOS and Windows
Makes executables for Linux, macOS and Windows
$ pkg index.js
- Takes package.json from cwd and follows 'bin' entry
Takes package.json from cwd and follows 'bin' entry
$ pkg .
- Makes executable for particular target machine
$ pkg -t node16-win-arm64 index.js
- Makes executables for target machines of your choice
$ pkg -t node16-linux,node18-linux,node16-win index.js
- Bakes '--expose-gc' and '--max-heap-size=34' into executable
Makes executable for particular target machine
$ pkg -t node14-win-arm64 index.js
Makes executables for target machines of your choice
$ pkg -t node16-linux,node18-linux,node18-win index.js
Bakes '--expose-gc' and '--max-heap-size=34' into executable
$ pkg --options "expose-gc,max-heap-size=34" index.js
- Consider packageA and packageB to be public
Consider packageA and packageB to be public
$ pkg --public-packages "packageA,packageB" index.js
- Consider all packages to be public
Consider all packages to be public
$ pkg --public-packages "*" index.js
- Bakes '--expose-gc' into executable
Bakes '--expose-gc' into executable
$ pkg --options expose-gc index.js
- reduce size of the data packed inside the executable with GZip
reduce size of the data packed inside the executable with GZip
$ pkg --compress GZip index.js
– compile the file using node's SEA feature. Creates executables for Linux, macOS and Windows
$ pkg --sea index.js
```

The entrypoint of your project is a mandatory CLI argument. It may be:
Expand Down
3 changes: 3 additions & 0 deletions lib/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function help() {
--no-native-build skip native addons build
--no-dict comma-separated list of packages names to ignore dictionaries. Use --no-dict * to disable all dictionaries
-C, --compress [default=None] compression algorithm = Brotli or GZip
--sea (Experimental) compile give file using node's SEA feature. Requires node v20.0.0 or higher and only single file is supported
${pc.dim('Examples:')}
Expand All @@ -43,5 +44,7 @@ export default function help() {
${pc.cyan('$ pkg --options expose-gc index.js')}
${pc.gray('–')} reduce size of the data packed inside the executable with GZip
${pc.cyan('$ pkg --compress GZip index.js')}
${pc.gray('–')} compile the file using node's SEA feature. Creates executables for Linux, macOS and Windows
${pc.cyan('$ pkg --sea index.js')}
`);
}
7 changes: 7 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Target, NodeTarget, SymLinks } from './types';
import { CompressType } from './compress_type';
import { patchMachOExecutable, signMachOExecutable } from './mach-o';
import pkgOptions from './options';
import sea from './sea';

const { version } = JSON.parse(
readFileSync(path.join(__dirname, '../package.json'), 'utf-8'),
Expand Down Expand Up @@ -226,6 +227,7 @@ export async function exec(argv2: string[]) {
'v',
'version',
'signature',
'sea',
],
string: [
'_',
Expand Down Expand Up @@ -530,6 +532,11 @@ export async function exec(argv2: string[]) {
}
}

if (argv.sea) {
await sea(inputFin, { targets });
return;
}

// fetch targets

const { bytecode } = argv;
Expand Down
Loading

0 comments on commit 0145a94

Please sign in to comment.