Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prettier-plugin-apex

Package Overview
Dependencies
Maintainers
2
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier-plugin-apex - npm Package Compare versions

Comparing version 1.0.0-alpha.1 to 1.0.0-alpha.2

CHANGELOG.md

2

package.json
{
"name": "prettier-plugin-apex",
"version": "1.0.0-alpha.1",
"version": "1.0.0-alpha.2",
"description": "Salesforce Apex plugin for Prettier",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -19,3 +19,3 @@ # Prettier Apex [![Build Status](https://travis-ci.org/dangmai/prettier-plugin-apex.svg)](https://travis-ci.org/dangmai/prettier-plugin-apex)

### Usage
## Usage

@@ -61,4 +61,30 @@ ### Requirements

### License
## Performance Tips/3rd party integration
By default,
this library invokes a CLI application to get the AST of the Apex code.
However, since this CLI application is written in Java,
there is a heavy start up cost associated with it.
In order to alleviate this issue,
we also have an optional [Nailgun](https://github.com/facebook/nailgun) server
that makes sure the start up is invoked exactly once.
This is especially useful if this library is integrated in a 3rd party application.
In order to use this server,
you have to evoke it out of band before running Prettier,
as well as specifying a special flag when running Prettier:
```bash
# Start the server
node /path/to/libary/tests_config/set_up.js
# In a separate console
prettier --use-standalone-server --write "/path/to/project/**/*.{trigger,cls}"
# After you are done, stop the server
node /path/to/libary/tests_config/tear_down.js
```
## License
MIT

@@ -40,10 +40,9 @@ const parse = require("./parser");

// TODO we have to take out serverHost here, since prettier does not like string
// option - look at optionInfoToSchema in options-normalizer.js
const options = {
serverAutoStart: {
useStandaloneServer: {
type: "boolean",
category: "Global",
default: true,
description: "Whether the nailgun server should be autostarted",
default: false,
description:
"Use a standalone server to speed up the parsing process. This server needs to be started and stopped separately from the Prettier process",
},

@@ -54,10 +53,8 @@ serverPort: {

default: 2113,
description: "Nailgun server port",
description:
"The standalone server port to connect to. Only applicable if useStandaloneServer is true",
},
};
const defaultOptions = {
tabWidth: 4,
printWidth: 100,
};
const defaultOptions = {};

@@ -64,0 +61,0 @@ module.exports = {

@@ -6,2 +6,3 @@ /* eslint no-param-reassign:0 */

const { spawnSync } = childProcess;
const attachComments = require("./comments").attach;

@@ -12,8 +13,25 @@ const values = require("./values");

function parseText(text, options) {
const runClientLocation = path.join(__dirname, "run_client.js");
const args = [runClientLocation, "-a", "localhost", "-p", options.serverPort];
if (options.serverAutoStart) {
args.push("-s");
function parseTextWithSpawn(text) {
let serializerBin = path.join(__dirname, "../vendor/apex-ast-serializer/bin");
if (process.platform === "win32") {
serializerBin = path.join(serializerBin, "apex-ast-serializer.bat");
} else {
serializerBin = path.join(serializerBin, "apex-ast-serializer");
}
const executionResult = spawnSync(serializerBin, ["-f", "json", "-i"], {
input: text,
});
const executionError = executionResult.error;
if (executionError) {
throw executionError;
}
return executionResult.stdout.toString();
}
function parseTextWithNailgun(text, serverPort) {
const ngClientLocation = path.join(__dirname, "ng-client.js");
const args = [ngClientLocation, "-a", "localhost", "-p", serverPort];
const executionResult = childProcess.spawnSync(process.argv[0], args, {

@@ -28,3 +46,3 @@ input: text,

return executionResult;
return executionResult.stdout.toString();
}

@@ -261,4 +279,8 @@

const lineIndexes = getLineIndexes(sourceCode);
const executionResult = parseText(sourceCode, options);
const serializedAst = executionResult.stdout.toString();
let serializedAst;
if (options.useStandaloneServer) {
serializedAst = parseTextWithNailgun(sourceCode, options.serverPort);
} else {
serializedAst = parseTextWithSpawn(sourceCode);
}
let ast = {};

@@ -265,0 +287,0 @@ if (serializedAst) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc