Skip to content

Commit

Permalink
Prevent use of /tmp for Node.js on Windows (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Nov 10, 2024
1 parent 7fa9bf2 commit a50ff5e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions src/vips-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@ 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 }}};

// We cannot safely spawn dedicated workers on the web. Therefore, to avoid any potential deadlocks, we reduce
// 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');
Expand Down
8 changes: 1 addition & 7 deletions test/bench/perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
5 changes: 0 additions & 5 deletions test/unit/node-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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

import { tmpdir } from 'node:os';
import { expect } from 'chai';

globalThis.expect = expect;
Expand All @@ -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);
Expand Down

0 comments on commit a50ff5e

Please sign in to comment.