docbrain 1.6.0 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/run.js +31 -1
package/package.json
CHANGED
package/run.js
CHANGED
|
@@ -7,6 +7,29 @@ const path = require("path");
|
|
|
7
7
|
|
|
8
8
|
const binary = path.join(__dirname, "bin", "docbrain");
|
|
9
9
|
|
|
10
|
+
// Node acts on these options itself, even after this script's path and even where they read as
|
|
11
|
+
// another flag's value: it reads the named file (and runs NODE_OPTIONS from it) or a config file
|
|
12
|
+
// before any line here runs. Versions differ: run here, Node 20.20 and 22.23 act on the env-file
|
|
13
|
+
// options before a "--", 22.23 and 26 also on the config-file options even after "--" (and 22.23
|
|
14
|
+
// on --experimental-default-config-file by prefix), and Node 16 on none; Node's source shows
|
|
15
|
+
// 20.6-22.6 matching --env-file by prefix without stopping at "--". So any argument that starts
|
|
16
|
+
// with one of them is refused, wherever it is (--env-file-if-exists starts with --env-file). This wrapper cannot undo what Node did, but it
|
|
17
|
+
// never starts DocBrain with one of them (#603): the file DocBrain reads is named with
|
|
18
|
+
// --docbrain-env, which Node ignores. Nothing typed is echoed: a value may be a key.
|
|
19
|
+
const NODE_READS = ["--env-file", "--experimental-config-file", "--experimental-default-config-file"];
|
|
20
|
+
|
|
21
|
+
function nodeReads(args) {
|
|
22
|
+
return args.some((arg) => NODE_READS.some((flag) => arg.startsWith(flag)));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (nodeReads(process.argv.slice(2))) {
|
|
26
|
+
console.error(
|
|
27
|
+
"docbrain: refusing to start: Node reads --env-file and its config-file options itself. " +
|
|
28
|
+
"Name DocBrain's file with --docbrain-env instead."
|
|
29
|
+
);
|
|
30
|
+
process.exit(2);
|
|
31
|
+
}
|
|
32
|
+
|
|
10
33
|
// npm 12 turned lifecycle scripts off by default, so the postinstall hook that
|
|
11
34
|
// fetches this binary may simply never have run — `npm install -g docbrain`
|
|
12
35
|
// reports success and leaves nothing behind. Fetching on first use covers that,
|
|
@@ -49,6 +72,13 @@ try {
|
|
|
49
72
|
if (err.status !== null && err.status !== undefined) {
|
|
50
73
|
process.exit(err.status);
|
|
51
74
|
}
|
|
52
|
-
|
|
75
|
+
// Never print err.message: for a CLI ended by a signal it is "Command failed:"
|
|
76
|
+
// followed by the whole command line, a key or a path included (#603).
|
|
77
|
+
if (err.signal) {
|
|
78
|
+
console.error(`DocBrain CLI stopped by ${err.signal}.`);
|
|
79
|
+
process.kill(process.pid, err.signal);
|
|
80
|
+
} else {
|
|
81
|
+
console.error(`Failed to run DocBrain CLI: ${err.code || "it could not be started"}`);
|
|
82
|
+
}
|
|
53
83
|
process.exit(1);
|
|
54
84
|
}
|