@yao-pkg/pkg 6.10.1 → 6.11.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/README.md +23 -10
- package/package.json +3 -2
- package/prelude/bootstrap.js +10 -2
package/README.md
CHANGED
|
@@ -302,21 +302,25 @@ The startup time of the application might be reduced slightly.
|
|
|
302
302
|
|
|
303
303
|
All pkg-cache [environment vars](https://github.com/yao-pkg/pkg-fetch#environment), plus:
|
|
304
304
|
|
|
305
|
-
| Var
|
|
306
|
-
|
|
|
307
|
-
| `CHDIR`
|
|
308
|
-
| `
|
|
309
|
-
| `
|
|
305
|
+
| Var | Description |
|
|
306
|
+
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
307
|
+
| `CHDIR` | Override process `chdir` |
|
|
308
|
+
| `PKG_NATIVE_CACHE_PATH` | Override the base directory for caching extracted native addons at runtime (default: `~/.cache`) |
|
|
309
|
+
| `PKG_STRICT_VER` | Turn on some assertion in the walker code to assert that each file content/state that we appending to the virtual file system applies to a real file, not a symlink. |
|
|
310
|
+
| `PKG_EXECPATH` | Used internally by `pkg`, do not override |
|
|
310
311
|
|
|
311
312
|
Examples
|
|
312
313
|
|
|
313
314
|
```bash
|
|
314
|
-
# 1 -
|
|
315
|
+
# 1 - Set cache path at build time (for pkg-fetch to cache Node.js binaries)
|
|
315
316
|
export PKG_CACHE_PATH=/my/cache
|
|
316
317
|
pkg app.js
|
|
317
318
|
|
|
318
|
-
# 2 -
|
|
319
|
-
|
|
319
|
+
# 2 - Set cache path at runtime (for packaged app to cache extracted native addons)
|
|
320
|
+
PKG_NATIVE_CACHE_PATH=/opt/myapp/cache ./myapp
|
|
321
|
+
|
|
322
|
+
# 3 - Both can be used together
|
|
323
|
+
PKG_CACHE_PATH=/build/cache PKG_NATIVE_CACHE_PATH=/runtime/cache pkg app.js
|
|
320
324
|
```
|
|
321
325
|
|
|
322
326
|
## Usage of packaged app
|
|
@@ -384,8 +388,17 @@ add the `.node` file directly in the `assets` field in `package.json`.
|
|
|
384
388
|
The way Node.js requires native addon is different from a classic JS
|
|
385
389
|
file. It needs to have a file on disk to load it, but `pkg` only generates
|
|
386
390
|
one file. To circumvent this, `pkg` will extract native addon files to
|
|
387
|
-
`$HOME/.cache/pkg
|
|
388
|
-
exited and will be used again on the next process launch.
|
|
391
|
+
`$HOME/.cache/pkg/` by default. These files will stay on the disk after the
|
|
392
|
+
process has exited and will be used again on the next process launch.
|
|
393
|
+
|
|
394
|
+
You can customize the cache directory by setting the `PKG_NATIVE_CACHE_PATH`
|
|
395
|
+
environment variable. This is useful in enterprise environments where specific
|
|
396
|
+
directories may be restricted or monitored:
|
|
397
|
+
|
|
398
|
+
```bash
|
|
399
|
+
# Set custom cache path for native addons
|
|
400
|
+
PKG_NATIVE_CACHE_PATH=/opt/myapp/cache ./myapp
|
|
401
|
+
```
|
|
389
402
|
|
|
390
403
|
When a package, that contains a native module, is being installed,
|
|
391
404
|
the native module is compiled against current system-wide Node.js
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yao-pkg/pkg",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.11.0",
|
|
4
4
|
"description": "Package your Node.js project into an executable",
|
|
5
5
|
"main": "lib-es5/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@babel/generator": "^7.23.0",
|
|
26
26
|
"@babel/parser": "^7.23.0",
|
|
27
27
|
"@babel/types": "^7.23.0",
|
|
28
|
-
"@yao-pkg/pkg-fetch": "3.5.
|
|
28
|
+
"@yao-pkg/pkg-fetch": "3.5.31",
|
|
29
29
|
"into-stream": "^6.0.0",
|
|
30
30
|
"minimist": "^1.2.6",
|
|
31
31
|
"multistream": "^4.1.0",
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
"test:20": "node test/test.js node20 no-npm",
|
|
82
82
|
"test:18": "node test/test.js node18 no-npm",
|
|
83
83
|
"test:host": "node test/test.js host only-npm",
|
|
84
|
+
"bump:fetch": "yarn add @yao-pkg/pkg-fetch --exact",
|
|
84
85
|
"release": "read -p 'GITHUB_TOKEN: ' GITHUB_TOKEN && export GITHUB_TOKEN=$GITHUB_TOKEN && release-it"
|
|
85
86
|
},
|
|
86
87
|
"simple-git-hooks": {
|
package/prelude/bootstrap.js
CHANGED
|
@@ -2187,6 +2187,15 @@ function payloadFileSync(pointer) {
|
|
|
2187
2187
|
dlopen: process.dlopen,
|
|
2188
2188
|
};
|
|
2189
2189
|
|
|
2190
|
+
// Allow users to override the cache base directory via PKG_NATIVE_CACHE_PATH environment variable
|
|
2191
|
+
// Default: path.join(homedir(), '.cache')
|
|
2192
|
+
// - Linux/macOS: /home/john/.cache or /Users/john/.cache
|
|
2193
|
+
// - Windows: C:\Users\John\.cache
|
|
2194
|
+
// Custom example: /opt/myapp/cache or C:\myapp\cache
|
|
2195
|
+
// Native addons will be extracted to: <PKG_NATIVE_CACHE_BASE>/pkg/<hash>
|
|
2196
|
+
const PKG_NATIVE_CACHE_BASE =
|
|
2197
|
+
process.env.PKG_NATIVE_CACHE_PATH || path.join(homedir(), '.cache');
|
|
2198
|
+
|
|
2190
2199
|
function revertMakingLong(f) {
|
|
2191
2200
|
if (/^\\\\\?\\/.test(f)) return f.slice(4);
|
|
2192
2201
|
return f;
|
|
@@ -2206,8 +2215,7 @@ function payloadFileSync(pointer) {
|
|
|
2206
2215
|
// the hash is needed to be sure we reload the module in case it changes
|
|
2207
2216
|
const hash = createHash('sha256').update(moduleContent).digest('hex');
|
|
2208
2217
|
|
|
2209
|
-
|
|
2210
|
-
const tmpFolder = path.join(homedir(), '.cache/pkg', hash);
|
|
2218
|
+
const tmpFolder = path.join(PKG_NATIVE_CACHE_BASE, 'pkg', hash);
|
|
2211
2219
|
|
|
2212
2220
|
fs.mkdirSync(tmpFolder, { recursive: true });
|
|
2213
2221
|
|