From a50ff5e3f63eef9af9fa75210190f9836d8959b8 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sun, 10 Nov 2024 12:21:44 +0100 Subject: [PATCH] Prevent use of `/tmp` for Node.js on Windows (#84) --- CHANGELOG.md | 5 +++++ src/vips-library.js | 10 ++++++++-- test/bench/perf.js | 8 +------- test/unit/node-helper.js | 5 ----- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd0e64e31..750e62e3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Uses libvips v8.16.0, compiled with Emscripten v3.1.71. +### Fixed + +- Prevent use of the `/tmp` directory for Node.js on Windows. + [#84](https://github.com/kleisauke/wasm-vips/issues/84) + ## [v0.0.11] - 2024-10-31 Uses libvips v8.16.0, compiled with Emscripten v3.1.70. diff --git a/src/vips-library.js b/src/vips-library.js index b883cf23f..fa7abd5c6 100644 --- a/src/vips-library.js +++ b/src/vips-library.js @@ -10,8 +10,8 @@ var LibraryVips = { $VIPS__postset: 'VIPS.init();', $VIPS: { init() { -#if ENVIRONMENT_MAY_BE_WEB addOnPreRun(() => { +#if ENVIRONMENT_MAY_BE_WEB // Enforce a fixed thread pool by default on web ENV['VIPS_MAX_THREADS'] = {{{ PTHREAD_POOL_SIZE }}}; @@ -19,8 +19,14 @@ var LibraryVips = { // the concurrency to 1. For more details, see: // https://emscripten.org/docs/porting/pthreads.html#blocking-on-the-main-browser-thread ENV['VIPS_CONCURRENCY'] = 1; - }); #endif +#if ENVIRONMENT_MAY_BE_NODE + // libvips stores temporary files by default in `/tmp`; + // set the TMPDIR env variable to override this directory + ENV['TMPDIR'] = require('os').tmpdir(); +#endif + }); + addOnInit(() => { // SourceCustom.onRead marshaller const sourceCustom = Object.getOwnPropertyDescriptor(Module['SourceCustom'].prototype, 'onRead'); diff --git a/test/bench/perf.js b/test/bench/perf.js index 945bfbab4..a6b755865 100644 --- a/test/bench/perf.js +++ b/test/bench/perf.js @@ -3,7 +3,6 @@ import Benchmark from 'benchmark'; import Vips from '../../lib/vips-node.mjs'; -import { tmpdir } from 'node:os'; import { inputJpg, inputPng, inputWebP, getPath } from './images.js'; const width = 720; @@ -19,12 +18,7 @@ const webpOut = getPath('output.webp'); const vips = await Vips({ // Disable dynamic modules - dynamicLibraries: [], - preRun: (module) => { - // libvips stores temporary files by default in `/tmp`; - // set the TMPDIR env variable to override this directory - module.ENV.TMPDIR = tmpdir(); - } + dynamicLibraries: [] }); // Disable libvips cache to ensure tests are as fair as they can be diff --git a/test/unit/node-helper.js b/test/unit/node-helper.js index 75d34f185..49acad7cc 100644 --- a/test/unit/node-helper.js +++ b/test/unit/node-helper.js @@ -2,7 +2,6 @@ import Vips from '../../lib/vips-node.mjs'; -import { tmpdir } from 'node:os'; import { expect } from 'chai'; globalThis.expect = expect; @@ -26,10 +25,6 @@ export async function mochaGlobalSetup () { // Hide warning messages module.ENV.VIPS_WARNING = 0; - - // libvips stores temporary files by default in `/tmp`; - // set the TMPDIR env variable to override this directory - module.ENV.TMPDIR = tmpdir(); } }; globalThis.vips = await Vips(options);