prettier 2.0.0.pre.rc3 → 2.0.0.pre.rc4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8aa6c76fdc06048c17f4ae26b2179b181e2e10f4210c6d840d8059c661becdb5
4
- data.tar.gz: 186e3d071167018e2eeb16d50818be1a1684710a0007226f2b3b3c403a190cd1
3
+ metadata.gz: 7001f9fc2c9aed2d630d5133b86baa047f44b1634690e0fcecc81c6186943c6d
4
+ data.tar.gz: 73cd58e7dec8253b2d1a9e9a4d18dd1cb968b147ddf71f069457ed2c1091a066
5
5
  SHA512:
6
- metadata.gz: 31b4ebe0dc6c6a382c858f1349f4de1161e311df22d122c2f8935d833417e2ed235e42f075ded605f5e6924d3d2a2fb545123b9a5f66bfb89615c4cde3216758
7
- data.tar.gz: 81a4467f636867133da2a93c5fc2f9a595e54dae597f9cde5ba45e98c0485cb3e2ab890151ce6e2da765881b753f1ce140b758bba70f25dcd1e64e950326a6ba
6
+ metadata.gz: 96f757bea8e85f036ba84dbd59a64e072264eedfcec6c901df5ef94bcb9f638a5fbb5c84a5b92c8f02cf26f75a8d1f8a5025a13eb3ec9a9bc3c2efc5f8790303
7
+ data.tar.gz: 13b2dd4e2d8e13f3bc01e5cca5d9abbaab975b668f164dd82e3c598344def9acd618082a0da7bb710e47886d85efaa7ca1d55bd33af24aee4ce2e41e0a7bbd89
data/CHANGELOG.md CHANGED
@@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [2.0.0-rc4]
10
+
11
+ ### Added
12
+
13
+ - [#993](https://github.com/prettier/plugin-ruby/pull/993) - kddnewton - Nicer error message if you don't have the necessary JavaScript files to run prettier.
14
+ - [#996](https://github.com/prettier/plugin-ruby/pull/996) - nbudin - Allow `@prettier/plugin-ruby` to run in yarn's plug'n'play mode.
15
+
16
+ ### Changed
17
+
18
+ - [#1000](https://github.com/prettier/plugin-ruby/pull/1000) - nbudin, kddnewton - Fix for rescuing single top-level exceptions in `rescue` clauses.
19
+
9
20
  ## [2.0.0-rc3]
10
21
 
11
22
  ### Changed
@@ -1169,7 +1180,8 @@ would previously result in `array[]`, but now prints properly.
1169
1180
 
1170
1181
  - Initial release 🎉
1171
1182
 
1172
- [unreleased]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc3...HEAD
1183
+ [unreleased]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc4...HEAD
1184
+ [2.0.0-rc4]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc3...v2.0.0-rc4
1173
1185
  [2.0.0-rc3]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc2...v2.0.0-rc3
1174
1186
  [2.0.0-rc2]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc1...v2.0.0-rc2
1175
1187
  [2.0.0-rc1]: https://github.com/prettier/plugin-ruby/compare/v1.6.1...v2.0.0-rc1
@@ -58,8 +58,53 @@ exports.getInfoFilepath = getInfoFilepath;
58
58
  // will read that information in order to enable us to connect to it in the
59
59
  // spawnSync function.
60
60
  function spawnServer() {
61
+ const tempDir = (0, fs_1.mkdtempSync)(path_1.default.join(os_1.default.tmpdir(), "prettier-plugin-ruby-"));
61
62
  const filepath = getInfoFilepath();
62
- const server = (0, child_process_1.spawn)("ruby", [path_1.default.join(__dirname, "./server.rb"), filepath], {
63
+ let serverRbPath = path_1.default.join(__dirname, "./server.rb");
64
+ let getInfoJsPath = path_1.default.join(__dirname, "./getInfo.js");
65
+ let cleanupTempFiles;
66
+ if (runningInPnPZip()) {
67
+ // If we're running in a Yarn PnP environment inside a ZIP file, it's not possible to run
68
+ // the Ruby server or the getInfo.js script directly. Instead, we need to copy them and all
69
+ // the files they depend on to a temporary directory.
70
+ const sourceFiles = [
71
+ "parser/server.rb",
72
+ "parser/getInfo.js",
73
+ "parser/netcat.js",
74
+ "ruby/parser.rb",
75
+ "rbs/parser.rb",
76
+ "haml/parser.rb"
77
+ ];
78
+ serverRbPath = path_1.default.join(tempDir, "parser", "server.rb");
79
+ getInfoJsPath = path_1.default.join(tempDir, "parser", "getInfo.js");
80
+ sourceFiles.forEach((rubyFile) => {
81
+ const destDir = path_1.default.join(tempDir, path_1.default.dirname(rubyFile));
82
+ if (!(0, fs_1.existsSync)(destDir)) {
83
+ (0, fs_1.mkdirSync)(destDir);
84
+ }
85
+ (0, fs_1.copyFileSync)(path_1.default.join(__dirname, "..", rubyFile), path_1.default.join(tempDir, rubyFile));
86
+ });
87
+ cleanupTempFiles = () => {
88
+ [
89
+ getInfoJsPath,
90
+ ...sourceFiles.map((rubyFile) => path_1.default.join(tempDir, rubyFile))
91
+ ].forEach((tmpFilePath) => {
92
+ if ((0, fs_1.existsSync)(tmpFilePath)) {
93
+ (0, fs_1.unlinkSync)(tmpFilePath);
94
+ }
95
+ });
96
+ sourceFiles.forEach((rubyFile) => {
97
+ const tempSubdir = path_1.default.join(tempDir, path_1.default.dirname(rubyFile));
98
+ if ((0, fs_1.existsSync)(tempSubdir)) {
99
+ (0, fs_1.rmdirSync)(tempSubdir);
100
+ }
101
+ });
102
+ if ((0, fs_1.existsSync)(tempDir)) {
103
+ (0, fs_1.rmdirSync)(tempDir);
104
+ }
105
+ };
106
+ }
107
+ const server = (0, child_process_1.spawn)("ruby", [serverRbPath, filepath], {
63
108
  env: Object.assign({}, process_1.default.env, { LANG: getLang() }),
64
109
  detached: true,
65
110
  stdio: "inherit"
@@ -69,6 +114,9 @@ function spawnServer() {
69
114
  if ((0, fs_1.existsSync)(filepath)) {
70
115
  (0, fs_1.unlinkSync)(filepath);
71
116
  }
117
+ if (cleanupTempFiles != null) {
118
+ cleanupTempFiles();
119
+ }
72
120
  try {
73
121
  if (server.pid) {
74
122
  process_1.default.kill(-server.pid);
@@ -80,10 +128,7 @@ function spawnServer() {
80
128
  }
81
129
  }
82
130
  });
83
- const info = (0, child_process_1.spawnSync)("node", [
84
- path_1.default.join(__dirname, "./getInfo.js"),
85
- filepath
86
- ]);
131
+ const info = (0, child_process_1.spawnSync)("node", [getInfoJsPath, filepath]);
87
132
  if (info.status !== 0) {
88
133
  throw new Error(`
89
134
  We failed to spawn our parser server. Please report this error on GitHub
@@ -97,16 +142,9 @@ function spawnServer() {
97
142
  }
98
143
  // If we're in a yarn Plug'n'Play environment, then the relative paths being
99
144
  // used by the parser server and the various scripts used to communicate
100
- // therein are not going to work with its virtual file system. Presumably
101
- // there's a way to fix this but I haven't figured out how yet.
102
- function checkPnP() {
103
- if (process_1.default.versions.pnp) {
104
- throw new Error(`
105
- @prettier/plugin-ruby does not current work within the yarn Plug'n'Play
106
- virtual file system. If you would like to help support the effort to fix
107
- this, please see https://github.com/prettier/plugin-ruby/issues/894.
108
- `);
109
- }
145
+ // therein are not going to work with its virtual file system.
146
+ function runningInPnPZip() {
147
+ return process_1.default.versions.pnp && __dirname.includes(".zip");
110
148
  }
111
149
  // Formats and sends a request to the parser server. We use netcat (or something
112
150
  // like it) here since Prettier requires the results of `parse` to be
@@ -114,7 +152,6 @@ function checkPnP() {
114
152
  // requests.
115
153
  function parseSync(parser, source) {
116
154
  if (!parserArgs) {
117
- checkPnP();
118
155
  parserArgs = spawnServer();
119
156
  }
120
157
  const response = (0, child_process_1.spawnSync)(parserArgs.cmd, parserArgs.args, {
@@ -52,10 +52,13 @@ const printRescueEx = (path, opts, print) => {
52
52
  const [exception, variable] = path.getValue().body;
53
53
  const parts = [];
54
54
  if (exception) {
55
+ // If there's just one exception being rescued, then it's just going to be a
56
+ // single doc node.
55
57
  let exceptionDoc = path.call(print, "body", 0);
56
- if (Array.isArray(exceptionDoc)) {
57
- const joiner = [",", line];
58
- exceptionDoc = group(join(joiner, exceptionDoc));
58
+ // If there are multiple exceptions being rescued, then we're going to have
59
+ // multiple doc nodes returned as an array that we need to join together.
60
+ if (["mrhs_add_star", "mrhs_new_from_args"].includes(exception.type)) {
61
+ exceptionDoc = group(join([",", line], exceptionDoc));
59
62
  }
60
63
  parts.push(" ", exceptionDoc);
61
64
  }
data/exe/rbprettier CHANGED
@@ -4,5 +4,4 @@
4
4
  $:.unshift(File.expand_path(File.join('..', 'lib'), __dir__))
5
5
  require 'prettier'
6
6
 
7
- Prettier.run(ARGV)
8
- exit($?.exitstatus) if $?.exited?
7
+ exit(Prettier.run(ARGV))
data/lib/prettier.rb CHANGED
@@ -1,18 +1,49 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json' unless defined?(JSON)
4
+ require 'open3'
4
5
 
5
6
  module Prettier
6
7
  PLUGIN = -File.expand_path('..', __dir__)
7
8
  BINARY = -File.join(PLUGIN, 'node_modules', 'prettier', 'bin-prettier.js')
8
9
  VERSION = -JSON.parse(File.read(File.join(PLUGIN, 'package.json')))['version']
9
10
 
10
- class << self
11
- def run(args)
12
- quoted = args.map { |arg| arg.start_with?('-') ? arg : "\"#{arg}\"" }
13
- command = "node #{BINARY} --plugin \"#{PLUGIN}\" #{quoted.join(' ')}"
11
+ def self.run(args)
12
+ quoted = args.map { |arg| arg.start_with?('-') ? arg : "\"#{arg}\"" }
13
+ command = "node #{BINARY} --plugin \"#{PLUGIN}\" #{quoted.join(' ')}"
14
14
 
15
- system({ 'RBPRETTIER' => '1' }, command)
15
+ stdout, stderr, status = Open3.capture3({ 'RBPRETTIER' => '1' }, command)
16
+ STDOUT.puts(stdout)
17
+
18
+ # If we completed successfully, then just exit out.
19
+ exitstatus = status.exitstatus
20
+ return exitstatus if exitstatus == 0
21
+
22
+ if stderr.match?(%r{Cannot find module '/.+?/bin-prettier.js'})
23
+ # If we're missing bin-prettier.js, then it's possible the user installed
24
+ # the gem through git, which wouldn't have installed the requisite
25
+ # JavaScript files.
26
+ STDERR.puts(<<~MSG)
27
+ Could not find the JavaScript files necessary to run prettier.
28
+
29
+ If you installed this dependency through git instead of from rubygems,
30
+ it does not install the necessary files by default. To fix this you can
31
+ either install them yourself by cd-ing into the directory where this gem
32
+ is located (#{File.expand_path('..', __dir__)}) and running:
33
+
34
+ `yarn && yarn prepublishOnly`
35
+ or
36
+ `npm install && npm run prepublishOnly`
37
+ or
38
+ you can change the source in your Gemfile to point directly to rubygems.
39
+ MSG
40
+ else
41
+ # Otherwise, just print out the same error that prettier emitted, as it's
42
+ # unknown to us.
43
+ STDERR.puts(stderr)
16
44
  end
45
+
46
+ # Make sure we still exit with the same status code the prettier emitted.
47
+ exitstatus
17
48
  end
18
49
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prettier/plugin-ruby",
3
- "version": "2.0.0-rc3",
3
+ "version": "2.0.0-rc4",
4
4
  "description": "prettier plugin for the Ruby programming language",
5
5
  "main": "dist/plugin.js",
6
6
  "scripts": {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prettier
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.rc3
4
+ version: 2.0.0.pre.rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Newton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-01 00:00:00.000000000 Z
11
+ date: 2021-10-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: