prettier 3.2.2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -2
- data/README.md +23 -59
- data/lib/prettier.rb +7 -5
- data/node_modules/prettier/LICENSE +5205 -0
- data/node_modules/prettier/README.md +109 -0
- data/node_modules/prettier/{bin-prettier.js → bin/prettier.cjs} +10 -5
- data/node_modules/prettier/doc.d.ts +240 -0
- data/node_modules/prettier/doc.js +1257 -1309
- data/node_modules/prettier/doc.mjs +1312 -0
- data/node_modules/prettier/index.cjs +655 -0
- data/node_modules/prettier/index.d.ts +915 -0
- data/node_modules/prettier/index.mjs +21845 -0
- data/node_modules/prettier/internal/cli.mjs +6978 -0
- data/node_modules/prettier/internal/internal.mjs +6531 -0
- data/node_modules/prettier/package.json +179 -6
- data/node_modules/prettier/plugins/acorn.d.ts +6 -0
- data/node_modules/prettier/plugins/acorn.js +13 -0
- data/node_modules/prettier/plugins/acorn.mjs +13 -0
- data/node_modules/prettier/plugins/angular.d.ts +8 -0
- data/node_modules/prettier/plugins/angular.js +2 -0
- data/node_modules/prettier/plugins/angular.mjs +2 -0
- data/node_modules/prettier/plugins/babel.d.ts +17 -0
- data/node_modules/prettier/plugins/babel.js +16 -0
- data/node_modules/prettier/plugins/babel.mjs +16 -0
- data/node_modules/prettier/plugins/estree.d.ts +0 -0
- data/node_modules/prettier/plugins/estree.js +35 -0
- data/node_modules/prettier/plugins/estree.mjs +35 -0
- data/node_modules/prettier/plugins/flow.d.ts +5 -0
- data/node_modules/prettier/plugins/flow.js +21 -0
- data/node_modules/prettier/plugins/flow.mjs +21 -0
- data/node_modules/prettier/plugins/glimmer.d.ts +5 -0
- data/node_modules/prettier/plugins/glimmer.js +30 -0
- data/node_modules/prettier/plugins/glimmer.mjs +30 -0
- data/node_modules/prettier/plugins/graphql.d.ts +5 -0
- data/node_modules/prettier/plugins/graphql.js +29 -0
- data/node_modules/prettier/plugins/graphql.mjs +29 -0
- data/node_modules/prettier/plugins/html.d.ts +8 -0
- data/node_modules/prettier/plugins/html.js +19 -0
- data/node_modules/prettier/plugins/html.mjs +19 -0
- data/node_modules/prettier/plugins/markdown.d.ts +7 -0
- data/node_modules/prettier/plugins/markdown.js +59 -0
- data/node_modules/prettier/plugins/markdown.mjs +59 -0
- data/node_modules/prettier/plugins/meriyah.d.ts +5 -0
- data/node_modules/prettier/plugins/meriyah.js +5 -0
- data/node_modules/prettier/plugins/meriyah.mjs +5 -0
- data/node_modules/prettier/plugins/postcss.d.ts +7 -0
- data/node_modules/prettier/plugins/postcss.js +52 -0
- data/node_modules/prettier/plugins/postcss.mjs +52 -0
- data/node_modules/prettier/plugins/typescript.d.ts +5 -0
- data/node_modules/prettier/plugins/typescript.js +27 -0
- data/node_modules/prettier/plugins/typescript.mjs +27 -0
- data/node_modules/prettier/plugins/yaml.d.ts +5 -0
- data/node_modules/prettier/plugins/yaml.js +161 -0
- data/node_modules/prettier/plugins/yaml.mjs +161 -0
- data/node_modules/prettier/standalone.d.ts +33 -0
- data/node_modules/prettier/standalone.js +34 -0
- data/node_modules/prettier/standalone.mjs +34 -0
- data/package.json +15 -10
- data/src/plugin.js +210 -14
- data/src/server.rb +50 -87
- metadata +60 -28
- data/CONTRIBUTING.md +0 -185
- data/node_modules/prettier/cli.js +0 -15085
- data/node_modules/prettier/index.js +0 -37282
- data/node_modules/prettier/parser-angular.js +0 -2
- data/node_modules/prettier/parser-babel.js +0 -27
- data/node_modules/prettier/parser-espree.js +0 -26
- data/node_modules/prettier/parser-flow.js +0 -35
- data/node_modules/prettier/parser-glimmer.js +0 -27
- data/node_modules/prettier/parser-graphql.js +0 -15
- data/node_modules/prettier/parser-html.js +0 -36
- data/node_modules/prettier/parser-markdown.js +0 -76
- data/node_modules/prettier/parser-meriyah.js +0 -19
- data/node_modules/prettier/parser-postcss.js +0 -76
- data/node_modules/prettier/parser-typescript.js +0 -280
- data/node_modules/prettier/parser-yaml.js +0 -150
- data/node_modules/prettier/third-party.js +0 -8978
- data/src/getInfo.js +0 -23
- data/src/netcat.js +0 -13
- data/src/parseSync.js +0 -236
data/src/getInfo.js
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
const { existsSync, readFileSync } = require("fs");
|
2
|
-
|
3
|
-
// This is how long to wait for the parser to spin up. For the most part, 5
|
4
|
-
// seconds is plenty of time. But in some environments, it may be necessary to
|
5
|
-
// increase this value.
|
6
|
-
const timeoutMs = parseInt(process.env.PRETTIER_RUBY_TIMEOUT_MS || "5000", 10);
|
7
|
-
|
8
|
-
const filepath = process.argv[process.argv.length - 1];
|
9
|
-
|
10
|
-
const timeout = setTimeout(() => {
|
11
|
-
clearInterval(interval);
|
12
|
-
throw new Error(`Failed to get information from parse server in time. If this
|
13
|
-
happens repeatedly, try increasing the PRETTIER_RUBY_TIMEOUT_MS environment
|
14
|
-
variable beyond 5000.`);
|
15
|
-
}, timeoutMs);
|
16
|
-
|
17
|
-
const interval = setInterval(() => {
|
18
|
-
if (existsSync(filepath)) {
|
19
|
-
process.stdout.write(readFileSync(filepath).toString("utf8"));
|
20
|
-
clearTimeout(timeout);
|
21
|
-
clearInterval(interval);
|
22
|
-
}
|
23
|
-
}, 100);
|
data/src/netcat.js
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
// A simple fallback when no netcat-compatible adapter is found on the system.
|
2
|
-
// On average, this is 2-3x slower than netcat, but still much faster than
|
3
|
-
// spawning a new Ruby process.
|
4
|
-
|
5
|
-
const { createConnection } = require("net");
|
6
|
-
|
7
|
-
const sock = process.argv[process.argv.length - 1];
|
8
|
-
const client = createConnection(sock, () => process.stdin.pipe(client));
|
9
|
-
|
10
|
-
client.on("data", (data) => process.stdout.write(data));
|
11
|
-
client.on("error", (error) => {
|
12
|
-
console.error(error);
|
13
|
-
});
|
data/src/parseSync.js
DELETED
@@ -1,236 +0,0 @@
|
|
1
|
-
const { spawn, spawnSync } = require("child_process");
|
2
|
-
const {
|
3
|
-
existsSync,
|
4
|
-
unlinkSync,
|
5
|
-
mkdtempSync,
|
6
|
-
copyFileSync,
|
7
|
-
mkdirSync,
|
8
|
-
rmdirSync
|
9
|
-
} = require("fs");
|
10
|
-
const os = require("os");
|
11
|
-
const path = require("path");
|
12
|
-
const process = require("process");
|
13
|
-
|
14
|
-
let parserArgs;
|
15
|
-
|
16
|
-
if (process.env.PRETTIER_RUBY_HOST) {
|
17
|
-
const [cmd, ...args] = process.env.PRETTIER_RUBY_HOST.split(" ");
|
18
|
-
parserArgs = { cmd, args };
|
19
|
-
}
|
20
|
-
|
21
|
-
// In order to properly parse ruby code, we need to tell the ruby process to
|
22
|
-
// parse using UTF-8. Unfortunately, the way that you accomplish this looks
|
23
|
-
// differently depending on your platform.
|
24
|
-
/* istanbul ignore next */
|
25
|
-
function getLang() {
|
26
|
-
const { env, platform } = process;
|
27
|
-
const envValue = env.LC_ALL || env.LC_CTYPE || env.LANG;
|
28
|
-
|
29
|
-
// If an env var is set for the locale that already includes UTF-8 in the
|
30
|
-
// name, then assume we can go with that.
|
31
|
-
if (envValue && envValue.includes("UTF-8")) {
|
32
|
-
return envValue;
|
33
|
-
}
|
34
|
-
|
35
|
-
// Otherwise, we're going to guess which encoding to use based on the system.
|
36
|
-
// This is probably not the best approach in the world, as you could be on
|
37
|
-
// linux and not have C.UTF-8, but in that case you're probably passing an env
|
38
|
-
// var for it. This object below represents all of the possible values of
|
39
|
-
// process.platform per:
|
40
|
-
// https://nodejs.org/api/process.html#process_process_platform
|
41
|
-
return {
|
42
|
-
aix: "C.UTF-8",
|
43
|
-
android: "C.UTF-8",
|
44
|
-
cygwin: "C.UTF-8",
|
45
|
-
darwin: "en_US.UTF-8",
|
46
|
-
freebsd: "C.UTF-8",
|
47
|
-
haiku: "C.UTF-8",
|
48
|
-
linux: "C.UTF-8",
|
49
|
-
netbsd: "C.UTF-8",
|
50
|
-
openbsd: "C.UTF-8",
|
51
|
-
sunos: "C.UTF-8",
|
52
|
-
win32: ".UTF-8"
|
53
|
-
}[platform];
|
54
|
-
}
|
55
|
-
|
56
|
-
// Generate the filepath that should be used to communicate the connection
|
57
|
-
// information between this process and the parser server.
|
58
|
-
function getInfoFilepath() {
|
59
|
-
return path.join(os.tmpdir(), `prettier-ruby-parser-${process.pid}.info`);
|
60
|
-
}
|
61
|
-
|
62
|
-
// Return the list of plugins that should be passed to the server process.
|
63
|
-
function getPlugins(opts) {
|
64
|
-
const plugins = new Set();
|
65
|
-
|
66
|
-
const rubyPlugins = opts.rubyPlugins.trim();
|
67
|
-
if (rubyPlugins.length > 0) {
|
68
|
-
rubyPlugins.split(",").forEach((plugin) => plugins.add(plugin.trim()));
|
69
|
-
}
|
70
|
-
|
71
|
-
if (opts.singleQuote) {
|
72
|
-
plugins.add("plugin/single_quotes");
|
73
|
-
}
|
74
|
-
|
75
|
-
if (opts.trailingComma !== "none") {
|
76
|
-
plugins.add("plugin/trailing_comma");
|
77
|
-
}
|
78
|
-
|
79
|
-
return Array.from(plugins);
|
80
|
-
}
|
81
|
-
|
82
|
-
// Create a file that will act as a communication mechanism, spawn a parser
|
83
|
-
// server with that filepath as an argument, then spawn another process that
|
84
|
-
// will read that information in order to enable us to connect to it in the
|
85
|
-
// spawnSync function.
|
86
|
-
function spawnServer(opts) {
|
87
|
-
const tempDir = mkdtempSync(path.join(os.tmpdir(), "prettier-plugin-ruby-"));
|
88
|
-
const filepath = getInfoFilepath();
|
89
|
-
|
90
|
-
let serverRbPath = path.join(__dirname, "./server.rb");
|
91
|
-
let getInfoJsPath = path.join(__dirname, "./getInfo.js");
|
92
|
-
let cleanupTempFiles;
|
93
|
-
|
94
|
-
if (runningInPnPZip()) {
|
95
|
-
// If we're running in a Yarn PnP environment inside a ZIP file, it's not possible to run
|
96
|
-
// the Ruby server or the getInfo.js script directly. Instead, we need to copy them and all
|
97
|
-
// the files they depend on to a temporary directory.
|
98
|
-
|
99
|
-
const sourceFiles = ["server.rb", "getInfo.js", "netcat.js"];
|
100
|
-
serverRbPath = path.join(tempDir, "server.rb");
|
101
|
-
getInfoJsPath = path.join(tempDir, "getInfo.js");
|
102
|
-
|
103
|
-
sourceFiles.forEach((rubyFile) => {
|
104
|
-
const destDir = path.join(tempDir, path.dirname(rubyFile));
|
105
|
-
if (!existsSync(destDir)) {
|
106
|
-
mkdirSync(destDir);
|
107
|
-
}
|
108
|
-
copyFileSync(
|
109
|
-
path.join(__dirname, "..", "src", rubyFile),
|
110
|
-
path.join(tempDir, rubyFile)
|
111
|
-
);
|
112
|
-
});
|
113
|
-
|
114
|
-
cleanupTempFiles = () => {
|
115
|
-
[
|
116
|
-
getInfoJsPath,
|
117
|
-
...sourceFiles.map((rubyFile) => path.join(tempDir, rubyFile))
|
118
|
-
].forEach((tmpFilePath) => {
|
119
|
-
if (existsSync(tmpFilePath)) {
|
120
|
-
unlinkSync(tmpFilePath);
|
121
|
-
}
|
122
|
-
});
|
123
|
-
|
124
|
-
sourceFiles.forEach((rubyFile) => {
|
125
|
-
const tempSubdir = path.join(tempDir, path.dirname(rubyFile));
|
126
|
-
if (existsSync(tempSubdir)) {
|
127
|
-
rmdirSync(tempSubdir);
|
128
|
-
}
|
129
|
-
});
|
130
|
-
|
131
|
-
if (existsSync(tempDir)) {
|
132
|
-
rmdirSync(tempDir);
|
133
|
-
}
|
134
|
-
};
|
135
|
-
}
|
136
|
-
|
137
|
-
const server = spawn(
|
138
|
-
"ruby",
|
139
|
-
[serverRbPath, `--plugins=${getPlugins(opts).join(",")}`, filepath],
|
140
|
-
{
|
141
|
-
env: Object.assign({}, process.env, { LANG: getLang() }),
|
142
|
-
detached: true,
|
143
|
-
stdio: "inherit"
|
144
|
-
}
|
145
|
-
);
|
146
|
-
|
147
|
-
server.unref();
|
148
|
-
process.on("exit", () => {
|
149
|
-
if (existsSync(filepath)) {
|
150
|
-
unlinkSync(filepath);
|
151
|
-
}
|
152
|
-
|
153
|
-
if (cleanupTempFiles != null) {
|
154
|
-
cleanupTempFiles();
|
155
|
-
}
|
156
|
-
|
157
|
-
try {
|
158
|
-
if (server.pid) {
|
159
|
-
// Kill the server process if it's still running. If we're on windows
|
160
|
-
// we're going to use the process ID number. If we're not, we're going
|
161
|
-
// to use the negative process ID to indicate the group.
|
162
|
-
const pid = process.platform === "win32" ? server.pid : -server.pid;
|
163
|
-
process.kill(pid);
|
164
|
-
}
|
165
|
-
} catch (e) {
|
166
|
-
if (process.env.PLUGIN_RUBY_CI) {
|
167
|
-
throw new Error(`Failed to kill the parser server: ${e}`);
|
168
|
-
}
|
169
|
-
}
|
170
|
-
});
|
171
|
-
|
172
|
-
const info = spawnSync("node", [getInfoJsPath, filepath]);
|
173
|
-
|
174
|
-
if (info.status !== 0) {
|
175
|
-
throw new Error(`
|
176
|
-
We failed to spawn our parser server. Please report this error on GitHub
|
177
|
-
at https://github.com/prettier/plugin-ruby. The error message was:
|
178
|
-
|
179
|
-
${info.stderr.toString()}.
|
180
|
-
`);
|
181
|
-
}
|
182
|
-
|
183
|
-
const [cmd, ...args] = info.stdout.toString().split(" ");
|
184
|
-
return { cmd, args };
|
185
|
-
}
|
186
|
-
|
187
|
-
// If we're in a yarn Plug'n'Play environment, then the relative paths being
|
188
|
-
// used by the parser server and the various scripts used to communicate
|
189
|
-
// therein are not going to work with its virtual file system.
|
190
|
-
function runningInPnPZip() {
|
191
|
-
return process.versions.pnp && __dirname.includes(".zip");
|
192
|
-
}
|
193
|
-
|
194
|
-
// Formats and sends a request to the parser server. We use netcat (or something
|
195
|
-
// like it) here since Prettier requires the results of `parse` to be
|
196
|
-
// synchronous and Node.js does not offer a mechanism for synchronous socket
|
197
|
-
// requests.
|
198
|
-
function parseSync(parser, source, opts) {
|
199
|
-
if (!parserArgs) {
|
200
|
-
parserArgs = spawnServer(opts);
|
201
|
-
}
|
202
|
-
|
203
|
-
const response = spawnSync(parserArgs.cmd, parserArgs.args, {
|
204
|
-
input: `${parser}|${opts.printWidth}|${opts.tabWidth}|${source}`,
|
205
|
-
maxBuffer: 15 * 1024 * 1024
|
206
|
-
});
|
207
|
-
|
208
|
-
const stdout = response.stdout.toString();
|
209
|
-
const stderr = response.stderr.toString();
|
210
|
-
const { status } = response;
|
211
|
-
|
212
|
-
// If we didn't receive anything over stdout or we have a bad exit status,
|
213
|
-
// then throw whatever we can.
|
214
|
-
if (stdout.length === 0 || (status !== null && status !== 0)) {
|
215
|
-
throw new Error(stderr || "An unknown error occurred");
|
216
|
-
}
|
217
|
-
|
218
|
-
const parsed = JSON.parse(stdout);
|
219
|
-
|
220
|
-
if (parsed.error) {
|
221
|
-
const error = new Error(parsed.error);
|
222
|
-
if (parsed.loc) {
|
223
|
-
error.loc = parsed.loc;
|
224
|
-
}
|
225
|
-
|
226
|
-
throw error;
|
227
|
-
}
|
228
|
-
|
229
|
-
return parsed;
|
230
|
-
}
|
231
|
-
|
232
|
-
module.exports = {
|
233
|
-
getLang,
|
234
|
-
getInfoFilepath,
|
235
|
-
parseSync
|
236
|
-
};
|