prettier 1.5.4 → 1.5.5

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.
@@ -1,57 +0,0 @@
1
- const { spawnSync } = require("child_process");
2
- const os = require("os");
3
-
4
- // Checks to see if an executable is available.
5
- function hasCommand(name) {
6
- let result;
7
-
8
- if (os.type() === "Windows_NT") {
9
- result = spawnSync("where", [name]);
10
- } else {
11
- result = spawnSync("command", ["-v", name]);
12
- }
13
-
14
- return result.status === 0;
15
- }
16
-
17
- // Finds an netcat-like adapter to use for sending data to a socket. We order
18
- // these by likelihood of being found so we can avoid some shell-outs.
19
- function getCommandAndArgs() {
20
- if (hasCommand("nc")) {
21
- return ["nc", ["-U"]];
22
- }
23
-
24
- if (hasCommand("telnet")) {
25
- return ["telnet", ["-u"]];
26
- }
27
-
28
- if (hasCommand("ncat")) {
29
- return ["ncat", ["-U"]];
30
- }
31
-
32
- if (hasCommand("socat")) {
33
- return ["socat", ["-"]];
34
- }
35
-
36
- return ["node", [require.resolve("./netcat.js")]];
37
- }
38
-
39
- let command;
40
- let args;
41
-
42
- function getNetcat(opts) {
43
- if (!command) {
44
- if (opts.rubyNetcatCommand) {
45
- const splits = opts.rubyNetcatCommand.split(" ");
46
-
47
- command = splits[0];
48
- args = splits.slice(1);
49
- } else {
50
- [command, args] = getCommandAndArgs();
51
- }
52
- }
53
-
54
- return { command, args };
55
- }
56
-
57
- module.exports = getNetcat;
@@ -1,74 +0,0 @@
1
- const { spawn, spawnSync, execSync } = require("child_process");
2
- const path = require("path");
3
- const { existsSync, mkdtempSync } = require("fs");
4
- const process = require("process");
5
- const os = require("os");
6
-
7
- const getNetcat = require("./getNetcat");
8
- const getLang = require("./getLang");
9
-
10
- let sockfile = process.env.PRETTIER_RUBY_HOST;
11
-
12
- // Spawn the parser.rb subprocess. We do this since booting Ruby is slow, and we
13
- // can re-use the parser process multiple times since it is statelesss.
14
- function spawnParseServer() {
15
- const server = spawn(
16
- "ruby",
17
- [path.join(__dirname, "./server.rb"), sockfile],
18
- {
19
- env: Object.assign({}, process.env, { LANG: getLang() }),
20
- detached: true,
21
- stdio: "inherit"
22
- }
23
- );
24
-
25
- process.on("exit", () => {
26
- try {
27
- process.kill(-server.pid);
28
- } catch (e) {
29
- // ignore
30
- }
31
- });
32
-
33
- server.unref();
34
- const now = new Date();
35
-
36
- // Wait for server to go live.
37
- while (!existsSync(sockfile) && new Date() - now < 3000) {
38
- execSync("sleep 0.1");
39
- }
40
- }
41
-
42
- // Ensures that a parser server is currently running by checking against the
43
- // sockfile variable. If it is not, create a temporary directory to house the
44
- // sockfile and spawn the ruby process.
45
- function ensureParseServer() {
46
- if (sockfile) {
47
- return;
48
- }
49
-
50
- const tmpDir = mkdtempSync(path.join(os.tmpdir(), "prettier-ruby"));
51
- sockfile = path.join(tmpDir, `${process.pid}.sock`);
52
-
53
- spawnParseServer();
54
- }
55
-
56
- // Sends a request to the parse server to parse the given content.
57
- function requestParse(parser, source, opts) {
58
- ensureParseServer();
59
-
60
- const { command, args } = getNetcat(opts);
61
- const { stdout, stderr, status } = spawnSync(command, args.concat(sockfile), {
62
- input: `${parser}|${source}`,
63
- maxBuffer: 15 * 1024 * 1024
64
- });
65
-
66
- return {
67
- command,
68
- stdout: stdout.toString(),
69
- stderr: stderr.toString(),
70
- status
71
- };
72
- }
73
-
74
- module.exports = requestParse;