@prettier/plugin-ruby
Advanced tools
Comparing version 2.0.0-rc3 to 2.0.0-rc4
@@ -9,2 +9,13 @@ # Changelog | ||
## [2.0.0-rc4] | ||
### Added | ||
- [#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. | ||
- [#996](https://github.com/prettier/plugin-ruby/pull/996) - nbudin - Allow `@prettier/plugin-ruby` to run in yarn's plug'n'play mode. | ||
### Changed | ||
- [#1000](https://github.com/prettier/plugin-ruby/pull/1000) - nbudin, kddnewton - Fix for rescuing single top-level exceptions in `rescue` clauses. | ||
## [2.0.0-rc3] | ||
@@ -1173,3 +1184,4 @@ | ||
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc3...HEAD | ||
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc4...HEAD | ||
[2.0.0-rc4]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc3...v2.0.0-rc4 | ||
[2.0.0-rc3]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc2...v2.0.0-rc3 | ||
@@ -1176,0 +1188,0 @@ [2.0.0-rc2]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc1...v2.0.0-rc2 |
@@ -61,4 +61,49 @@ "use strict"; | ||
function spawnServer() { | ||
const tempDir = (0, fs_1.mkdtempSync)(path_1.default.join(os_1.default.tmpdir(), "prettier-plugin-ruby-")); | ||
const filepath = getInfoFilepath(); | ||
const server = (0, child_process_1.spawn)("ruby", [path_1.default.join(__dirname, "./server.rb"), filepath], { | ||
let serverRbPath = path_1.default.join(__dirname, "./server.rb"); | ||
let getInfoJsPath = path_1.default.join(__dirname, "./getInfo.js"); | ||
let cleanupTempFiles; | ||
if (runningInPnPZip()) { | ||
// If we're running in a Yarn PnP environment inside a ZIP file, it's not possible to run | ||
// the Ruby server or the getInfo.js script directly. Instead, we need to copy them and all | ||
// the files they depend on to a temporary directory. | ||
const sourceFiles = [ | ||
"parser/server.rb", | ||
"parser/getInfo.js", | ||
"parser/netcat.js", | ||
"ruby/parser.rb", | ||
"rbs/parser.rb", | ||
"haml/parser.rb" | ||
]; | ||
serverRbPath = path_1.default.join(tempDir, "parser", "server.rb"); | ||
getInfoJsPath = path_1.default.join(tempDir, "parser", "getInfo.js"); | ||
sourceFiles.forEach((rubyFile) => { | ||
const destDir = path_1.default.join(tempDir, path_1.default.dirname(rubyFile)); | ||
if (!(0, fs_1.existsSync)(destDir)) { | ||
(0, fs_1.mkdirSync)(destDir); | ||
} | ||
(0, fs_1.copyFileSync)(path_1.default.join(__dirname, "..", rubyFile), path_1.default.join(tempDir, rubyFile)); | ||
}); | ||
cleanupTempFiles = () => { | ||
[ | ||
getInfoJsPath, | ||
...sourceFiles.map((rubyFile) => path_1.default.join(tempDir, rubyFile)) | ||
].forEach((tmpFilePath) => { | ||
if ((0, fs_1.existsSync)(tmpFilePath)) { | ||
(0, fs_1.unlinkSync)(tmpFilePath); | ||
} | ||
}); | ||
sourceFiles.forEach((rubyFile) => { | ||
const tempSubdir = path_1.default.join(tempDir, path_1.default.dirname(rubyFile)); | ||
if ((0, fs_1.existsSync)(tempSubdir)) { | ||
(0, fs_1.rmdirSync)(tempSubdir); | ||
} | ||
}); | ||
if ((0, fs_1.existsSync)(tempDir)) { | ||
(0, fs_1.rmdirSync)(tempDir); | ||
} | ||
}; | ||
} | ||
const server = (0, child_process_1.spawn)("ruby", [serverRbPath, filepath], { | ||
env: Object.assign({}, process_1.default.env, { LANG: getLang() }), | ||
@@ -73,2 +118,5 @@ detached: true, | ||
} | ||
if (cleanupTempFiles != null) { | ||
cleanupTempFiles(); | ||
} | ||
try { | ||
@@ -85,6 +133,3 @@ if (server.pid) { | ||
}); | ||
const info = (0, child_process_1.spawnSync)("node", [ | ||
path_1.default.join(__dirname, "./getInfo.js"), | ||
filepath | ||
]); | ||
const info = (0, child_process_1.spawnSync)("node", [getInfoJsPath, filepath]); | ||
if (info.status !== 0) { | ||
@@ -103,12 +148,5 @@ throw new Error(` | ||
// used by the parser server and the various scripts used to communicate | ||
// therein are not going to work with its virtual file system. Presumably | ||
// there's a way to fix this but I haven't figured out how yet. | ||
function checkPnP() { | ||
if (process_1.default.versions.pnp) { | ||
throw new Error(` | ||
@prettier/plugin-ruby does not current work within the yarn Plug'n'Play | ||
virtual file system. If you would like to help support the effort to fix | ||
this, please see https://github.com/prettier/plugin-ruby/issues/894. | ||
`); | ||
} | ||
// therein are not going to work with its virtual file system. | ||
function runningInPnPZip() { | ||
return process_1.default.versions.pnp && __dirname.includes(".zip"); | ||
} | ||
@@ -121,3 +159,2 @@ // Formats and sends a request to the parser server. We use netcat (or something | ||
if (!parserArgs) { | ||
checkPnP(); | ||
parserArgs = spawnServer(); | ||
@@ -124,0 +161,0 @@ } |
@@ -55,6 +55,9 @@ "use strict"; | ||
if (exception) { | ||
// If there's just one exception being rescued, then it's just going to be a | ||
// single doc node. | ||
let exceptionDoc = path.call(print, "body", 0); | ||
if (Array.isArray(exceptionDoc)) { | ||
const joiner = [",", line]; | ||
exceptionDoc = group(join(joiner, exceptionDoc)); | ||
// If there are multiple exceptions being rescued, then we're going to have | ||
// multiple doc nodes returned as an array that we need to join together. | ||
if (["mrhs_add_star", "mrhs_new_from_args"].includes(exception.type)) { | ||
exceptionDoc = group(join([",", line], exceptionDoc)); | ||
} | ||
@@ -61,0 +64,0 @@ parts.push(" ", exceptionDoc); |
{ | ||
"name": "@prettier/plugin-ruby", | ||
"version": "2.0.0-rc3", | ||
"version": "2.0.0-rc4", | ||
"description": "prettier plugin for the Ruby programming language", | ||
@@ -5,0 +5,0 @@ "main": "dist/plugin.js", |
import { spawn, spawnSync } from "child_process"; | ||
import { existsSync, unlinkSync } from "fs"; | ||
import { | ||
existsSync, | ||
unlinkSync, | ||
mkdtempSync, | ||
copyFileSync, | ||
mkdirSync, | ||
rmdirSync | ||
} from "fs"; | ||
import os from "os"; | ||
@@ -61,13 +68,65 @@ import path from "path"; | ||
function spawnServer(): ParserArgs { | ||
const tempDir = mkdtempSync(path.join(os.tmpdir(), "prettier-plugin-ruby-")); | ||
const filepath = getInfoFilepath(); | ||
const server = spawn( | ||
"ruby", | ||
[path.join(__dirname, "./server.rb"), filepath], | ||
{ | ||
env: Object.assign({}, process.env, { LANG: getLang() }), | ||
detached: true, | ||
stdio: "inherit" | ||
} | ||
); | ||
let serverRbPath = path.join(__dirname, "./server.rb"); | ||
let getInfoJsPath = path.join(__dirname, "./getInfo.js"); | ||
let cleanupTempFiles: () => void | undefined; | ||
if (runningInPnPZip()) { | ||
// If we're running in a Yarn PnP environment inside a ZIP file, it's not possible to run | ||
// the Ruby server or the getInfo.js script directly. Instead, we need to copy them and all | ||
// the files they depend on to a temporary directory. | ||
const sourceFiles = [ | ||
"parser/server.rb", | ||
"parser/getInfo.js", | ||
"parser/netcat.js", | ||
"ruby/parser.rb", | ||
"rbs/parser.rb", | ||
"haml/parser.rb" | ||
]; | ||
serverRbPath = path.join(tempDir, "parser", "server.rb"); | ||
getInfoJsPath = path.join(tempDir, "parser", "getInfo.js"); | ||
sourceFiles.forEach((rubyFile) => { | ||
const destDir = path.join(tempDir, path.dirname(rubyFile)); | ||
if (!existsSync(destDir)) { | ||
mkdirSync(destDir); | ||
} | ||
copyFileSync( | ||
path.join(__dirname, "..", rubyFile), | ||
path.join(tempDir, rubyFile) | ||
); | ||
}); | ||
cleanupTempFiles = () => { | ||
[ | ||
getInfoJsPath, | ||
...sourceFiles.map((rubyFile) => path.join(tempDir, rubyFile)) | ||
].forEach((tmpFilePath) => { | ||
if (existsSync(tmpFilePath)) { | ||
unlinkSync(tmpFilePath); | ||
} | ||
}); | ||
sourceFiles.forEach((rubyFile) => { | ||
const tempSubdir = path.join(tempDir, path.dirname(rubyFile)); | ||
if (existsSync(tempSubdir)) { | ||
rmdirSync(tempSubdir); | ||
} | ||
}); | ||
if (existsSync(tempDir)) { | ||
rmdirSync(tempDir); | ||
} | ||
}; | ||
} | ||
const server = spawn("ruby", [serverRbPath, filepath], { | ||
env: Object.assign({}, process.env, { LANG: getLang() }), | ||
detached: true, | ||
stdio: "inherit" | ||
}); | ||
server.unref(); | ||
@@ -79,2 +138,6 @@ process.on("exit", () => { | ||
if (cleanupTempFiles != null) { | ||
cleanupTempFiles(); | ||
} | ||
try { | ||
@@ -91,6 +154,3 @@ if (server.pid) { | ||
const info = spawnSync("node", [ | ||
path.join(__dirname, "./getInfo.js"), | ||
filepath | ||
]); | ||
const info = spawnSync("node", [getInfoJsPath, filepath]); | ||
@@ -112,12 +172,5 @@ if (info.status !== 0) { | ||
// used by the parser server and the various scripts used to communicate | ||
// therein are not going to work with its virtual file system. Presumably | ||
// there's a way to fix this but I haven't figured out how yet. | ||
function checkPnP() { | ||
if (process.versions.pnp) { | ||
throw new Error(` | ||
@prettier/plugin-ruby does not current work within the yarn Plug'n'Play | ||
virtual file system. If you would like to help support the effort to fix | ||
this, please see https://github.com/prettier/plugin-ruby/issues/894. | ||
`); | ||
} | ||
// therein are not going to work with its virtual file system. | ||
function runningInPnPZip() { | ||
return process.versions.pnp && __dirname.includes(".zip"); | ||
} | ||
@@ -135,3 +188,2 @@ | ||
if (!parserArgs) { | ||
checkPnP(); | ||
parserArgs = spawnServer(); | ||
@@ -138,0 +190,0 @@ } |
@@ -58,10 +58,13 @@ import type { Plugin, Ruby } from "../../types"; | ||
const [exception, variable] = path.getValue().body; | ||
const parts = []; | ||
const parts: Plugin.Doc[] = []; | ||
if (exception) { | ||
// If there's just one exception being rescued, then it's just going to be a | ||
// single doc node. | ||
let exceptionDoc = path.call(print, "body", 0); | ||
if (Array.isArray(exceptionDoc)) { | ||
const joiner = [",", line]; | ||
exceptionDoc = group(join(joiner, exceptionDoc)); | ||
// If there are multiple exceptions being rescued, then we're going to have | ||
// multiple doc nodes returned as an array that we need to join together. | ||
if (["mrhs_add_star", "mrhs_new_from_args"].includes(exception.type)) { | ||
exceptionDoc = group(join([",", line], exceptionDoc)); | ||
} | ||
@@ -68,0 +71,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
766619
10546