Skip to content

Commit a50ff5e

Browse files
committed
Prevent use of /tmp for Node.js on Windows (#84)
1 parent 7fa9bf2 commit a50ff5e

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
Uses libvips v8.16.0, compiled with Emscripten v3.1.71.
1010

11+
### Fixed
12+
13+
- Prevent use of the `/tmp` directory for Node.js on Windows.
14+
[#84](https://github.com/kleisauke/wasm-vips/issues/84)
15+
1116
## [v0.0.11] - 2024-10-31
1217

1318
Uses libvips v8.16.0, compiled with Emscripten v3.1.70.

src/vips-library.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,23 @@ var LibraryVips = {
1010
$VIPS__postset: 'VIPS.init();',
1111
$VIPS: {
1212
init() {
13-
#if ENVIRONMENT_MAY_BE_WEB
1413
addOnPreRun(() => {
14+
#if ENVIRONMENT_MAY_BE_WEB
1515
// Enforce a fixed thread pool by default on web
1616
ENV['VIPS_MAX_THREADS'] = {{{ PTHREAD_POOL_SIZE }}};
1717

1818
// We cannot safely spawn dedicated workers on the web. Therefore, to avoid any potential deadlocks, we reduce
1919
// the concurrency to 1. For more details, see:
2020
// https://emscripten.org/docs/porting/pthreads.html#blocking-on-the-main-browser-thread
2121
ENV['VIPS_CONCURRENCY'] = 1;
22-
});
2322
#endif
23+
#if ENVIRONMENT_MAY_BE_NODE
24+
// libvips stores temporary files by default in `/tmp`;
25+
// set the TMPDIR env variable to override this directory
26+
ENV['TMPDIR'] = require('os').tmpdir();
27+
#endif
28+
});
29+
2430
addOnInit(() => {
2531
// SourceCustom.onRead marshaller
2632
const sourceCustom = Object.getOwnPropertyDescriptor(Module['SourceCustom'].prototype, 'onRead');

test/bench/perf.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import Benchmark from 'benchmark';
44

55
import Vips from '../../lib/vips-node.mjs';
6-
import { tmpdir } from 'node:os';
76
import { inputJpg, inputPng, inputWebP, getPath } from './images.js';
87

98
const width = 720;
@@ -19,12 +18,7 @@ const webpOut = getPath('output.webp');
1918

2019
const vips = await Vips({
2120
// Disable dynamic modules
22-
dynamicLibraries: [],
23-
preRun: (module) => {
24-
// libvips stores temporary files by default in `/tmp`;
25-
// set the TMPDIR env variable to override this directory
26-
module.ENV.TMPDIR = tmpdir();
27-
}
21+
dynamicLibraries: []
2822
});
2923

3024
// Disable libvips cache to ensure tests are as fair as they can be

test/unit/node-helper.js

-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import Vips from '../../lib/vips-node.mjs';
44

5-
import { tmpdir } from 'node:os';
65
import { expect } from 'chai';
76

87
globalThis.expect = expect;
@@ -26,10 +25,6 @@ export async function mochaGlobalSetup () {
2625

2726
// Hide warning messages
2827
module.ENV.VIPS_WARNING = 0;
29-
30-
// libvips stores temporary files by default in `/tmp`;
31-
// set the TMPDIR env variable to override this directory
32-
module.ENV.TMPDIR = tmpdir();
3328
}
3429
};
3530
globalThis.vips = await Vips(options);

0 commit comments

Comments
 (0)