prettier-plugin-apex
Advanced tools
Comparing version 1.0.0-alpha.1 to 1.0.0-alpha.2
{ | ||
"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) { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
11640675
26
3193
89
3