Skip to content

Commit

Permalink
fix: use cache directory in users home instead of system-wide tmp dir (
Browse files Browse the repository at this point in the history
  • Loading branch information
kayahr authored Apr 15, 2024
1 parent 42fd35e commit a217727
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,14 @@ This way you may even avoid creating `pkg` config for your project.
Native addons (`.node` files) use is supported. When `pkg` encounters
a `.node` file in a `require` call, it will package this like an asset.
In some cases (like with the `bindings` package), the module path is generated
dynamicaly and `pkg` won't be able to detect it. In this case, you should
dynamically and `pkg` won't be able to detect it. In this case, you should
add the `.node` file directly in the `assets` field in `package.json`.

The way Node.js requires native addon is different from a classic JS
file. It needs to have a file on disk to load it, but `pkg` only generates
one file. To circumvent this, `pkg` will create a temporary file on the
disk. These files will stay on the disk after the process has exited
and will be used again on the next process launch.
one file. To circumvent this, `pkg` will extract native addon files to
`$HOME/.cache/pkg/`. These files will stay on the disk after the process has
exited and will be used again on the next process launch.

When a package, that contains a native module, is being installed,
the native module is compiled against current system-wide Node.js
Expand Down
6 changes: 3 additions & 3 deletions prelude/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Module = require('module');
const path = require('path');
const { promisify, _extend } = require('util');
const { Script } = require('vm');
const { tmpdir } = require('os');
const { homedir } = require('os');
const util = require('util');
const {
brotliDecompress,
Expand Down Expand Up @@ -2210,8 +2210,8 @@ function payloadFileSync(pointer) {
// the hash is needed to be sure we reload the module in case it changes
const hash = createHash('sha256').update(moduleContent).digest('hex');

// Example: /tmp/pkg/<hash>
const tmpFolder = path.join(tmpdir(), 'pkg', hash);
// Example: /home/john/.cache/pkg/<hash>
const tmpFolder = path.join(homedir(), '.cache/pkg', hash);

createDirRecursively(tmpFolder);

Expand Down

0 comments on commit a217727

Please sign in to comment.