Skip to content

Commit

Permalink
Make relative paths work for gem
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Oct 18, 2022
1 parent c64944d commit 44ab439
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 7 additions & 5 deletions lib/prettier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
require "open3"

module Prettier
PLUGIN = -File.expand_path("..", __dir__)
BINARY = -File.join(PLUGIN, "node_modules", "prettier", "bin-prettier.js")
VERSION = -JSON.parse(File.read(File.join(PLUGIN, "package.json")))["version"]
directory = -File.expand_path("..", __dir__)
package = File.read(File.join(directory, "package.json"))

PLUGIN = -File.join(directory, "src/plugin.js")
BINARY = -File.join(directory, "node_modules/prettier/bin/prettier.cjs")
VERSION = -JSON.parse(package)["version"]

def self.run(args)
quoted = args.map { |arg| arg.start_with?("-") ? arg : "\"#{arg}\"" }
command = "node #{BINARY} --plugin \"#{PLUGIN}\" #{quoted.join(" ")}"
opts = STDIN.tty? ? {} : { stdin_data: STDIN }

stdout, stderr, status =
Open3.capture3({ "RBPRETTIER" => "1" }, command, opts)
stdout, stderr, status = Open3.capture3({}, command, opts)
STDOUT.puts(stdout)

# If we completed successfully, then just exit out.
Expand Down
4 changes: 1 addition & 3 deletions prettier.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ Gem::Specification.new do |spec|
spec.files =
Dir.chdir(__dir__) do
%w[LICENSE package.json rubocop.yml] + Dir["{{exe,lib,src}/**/*,*.md}"] +
Dir[
"node_modules/prettier/{package.json,index.js,cli.js,doc.js,bin-prettier.js,third-party.js,parser-*.js}"
]
Dir["node_modules/prettier/**/*"]
end

spec.required_ruby_version = ">= 2.7.0"
Expand Down

0 comments on commit 44ab439

Please sign in to comment.