mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-24 17:28:40 +00:00
Require prettier argument and library in the wrapper
This commit is contained in:
parent
1ff17bd15d
commit
86618a64c6
3 changed files with 61 additions and 29 deletions
35
crates/prettier/prettier_server/package-lock.json
generated
35
crates/prettier/prettier_server/package-lock.json
generated
|
@ -1,29 +1,12 @@
|
|||
{
|
||||
"name": "prettier_server",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "prettier_server",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"prettier": "^3.0.3"
|
||||
}
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz",
|
||||
"integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==",
|
||||
"bin": {
|
||||
"prettier": "bin/prettier.cjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||
}
|
||||
"name": "prettier_server",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "prettier_server",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Zed Industries",
|
||||
"dependencies": {
|
||||
"dev-dependencies": {
|
||||
"prettier": "^3.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,36 @@
|
|||
const { Buffer } = require('buffer');
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
let prettierContainerPath = process.argv[2];
|
||||
if (prettierContainerPath == null || prettierContainerPath.length == 0) {
|
||||
console.error(`Prettier path argument was not specified or empty.\nUsage: ${process.argv[0]} ${process.argv[1]} prettier/path`);
|
||||
process.exit(1);
|
||||
}
|
||||
fs.stat(prettierContainerPath, (err, stats) => {
|
||||
if (err) {
|
||||
console.error(`Path '${prettierContainerPath}' does not exist.`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!stats.isDirectory()) {
|
||||
console.log(`Path '${prettierContainerPath}' exists but is not a directory.`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
let prettierPath = path.join(prettierContainerPath, 'node_modules/prettier');
|
||||
|
||||
(async () => {
|
||||
let prettier;
|
||||
try {
|
||||
prettier = await loadPrettier(prettierPath);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log("Prettier loadded successfully.");
|
||||
// TODO kb do the rest here
|
||||
})()
|
||||
|
||||
let buffer = Buffer.alloc(0);
|
||||
process.stdin.resume();
|
||||
|
@ -28,14 +60,15 @@ function handleData() {
|
|||
try {
|
||||
const message = JSON.parse(bytes);
|
||||
handleMessage(message);
|
||||
} catch (_) {
|
||||
sendResponse(makeError("Request JSON parse error"));
|
||||
} catch (e) {
|
||||
sendResponse(makeError(`Request JSON parse error: ${e}`));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// format
|
||||
// clear_cache
|
||||
//
|
||||
// shutdown
|
||||
// error
|
||||
|
||||
|
@ -55,3 +88,19 @@ function sendResponse(response) {
|
|||
process.stdout.write(length);
|
||||
process.stdout.write(message);
|
||||
}
|
||||
|
||||
function loadPrettier(prettierPath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.access(prettierPath, fs.constants.F_OK, (err) => {
|
||||
if (err) {
|
||||
reject(`Path '${prettierPath}' does not exist.Error: ${err}`);
|
||||
} else {
|
||||
try {
|
||||
resolve(require(prettierPath));
|
||||
} catch (err) {
|
||||
reject(`Error requiring prettier module from path '${prettierPath}'.Error: ${err}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue