Skip to content

Commit a217727

Browse files
authored
fix: use cache directory in users home instead of system-wide tmp dir (#55)
1 parent 42fd35e commit a217727

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,14 @@ This way you may even avoid creating `pkg` config for your project.
353353
Native addons (`.node` files) use is supported. When `pkg` encounters
354354
a `.node` file in a `require` call, it will package this like an asset.
355355
In some cases (like with the `bindings` package), the module path is generated
356-
dynamicaly and `pkg` won't be able to detect it. In this case, you should
356+
dynamically and `pkg` won't be able to detect it. In this case, you should
357357
add the `.node` file directly in the `assets` field in `package.json`.
358358

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

365365
When a package, that contains a native module, is being installed,
366366
the native module is compiled against current system-wide Node.js

prelude/bootstrap.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const Module = require('module');
2424
const path = require('path');
2525
const { promisify, _extend } = require('util');
2626
const { Script } = require('vm');
27-
const { tmpdir } = require('os');
27+
const { homedir } = require('os');
2828
const util = require('util');
2929
const {
3030
brotliDecompress,
@@ -2210,8 +2210,8 @@ function payloadFileSync(pointer) {
22102210
// the hash is needed to be sure we reload the module in case it changes
22112211
const hash = createHash('sha256').update(moduleContent).digest('hex');
22122212

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

22162216
createDirRecursively(tmpFolder);
22172217

0 commit comments

Comments
 (0)