Skip to content
This repository was archived by the owner on Dec 14, 2019. It is now read-only.

Commit ac4393a

Browse files
author
Nathan Sobo
committed
Add transformBinPath parameter to support weird packaging situations
1 parent 11fb0f5 commit ac4393a

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ By default, the an appropriate implementation of the watcher is selected for the
5050
const watcher = new Watcher({pollInterval: 1000});
5151
```
5252

53+
### Bin path transformation
54+
55+
If you have a weird packaging situation (for example, this library being archived in an Electron ASAR archive), you may need to modify the path to the subprocess executable. You can pass a `transformBinPath` function to the `Watcher` constructor as a parameter to do so.
56+
57+
```js
58+
const watcher = new Watcher({
59+
transformBinPath: p => p.replace(/\bapp\.asar\b/, "app.asar.unpacked")
60+
});
61+
```
62+
5363
## Project structure
5464

5565
This library spawns a subprocess that speaks a simple line-oriented JSON protocol over stdin and stdout. The Rust source for the subprocess is located in [`subprocess`](./subprocess).

lib/index.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { spawn } = require("child_process");
2+
const path = require("path");
23
const util = require("util");
34
const realpath = util.promisify(require("fs").realpath);
45

@@ -13,15 +14,22 @@ module.exports = class Watcher {
1314
this.onError = params.onError;
1415
}
1516

16-
const args = [];
17-
if (params.pollInterval) args.push("--poll-interval", params.pollInterval);
18-
this.childProcess = spawn(
19-
`${__dirname}/../bin/notify-subprocess-${process.platform}`,
20-
args,
21-
{
22-
stdio: ["pipe", "pipe", "pipe"]
23-
}
17+
let binPath = path.join(
18+
__dirname,
19+
"..",
20+
"bin",
21+
`notify-subprocess-${process.platform}`
2422
);
23+
if (params && typeof params.transformBinPath === "function") {
24+
binPath = params.transformBinPath(binPath);
25+
}
26+
27+
const args = [];
28+
if (params && params.pollInterval)
29+
args.push("--poll-interval", params.pollInterval);
30+
this.childProcess = spawn(binPath, args, {
31+
stdio: ["pipe", "pipe", "pipe"]
32+
});
2533
this.kill = this.kill.bind(this);
2634
process.on("exit", this.kill);
2735

0 commit comments

Comments
 (0)