Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/use native npm #606

Merged
merged 43 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
cf00d4d
poc: call native node-server from within java
simschla Jun 3, 2020
b07af27
resolve prettier config once only
simschla Jun 5, 2020
2180d35
extract http/url handling part into a pretty simple client...
simschla Jun 5, 2020
3c8d2ca
raw state: start node server and execute rest calls to it
simschla Jun 6, 2020
372107a
use native node approach for tsfmt
simschla Jun 7, 2020
51da6fe
remove dependency to j2v8
simschla Jun 7, 2020
9999bdd
spotlessApply
simschla Jun 7, 2020
03fbd98
add more details in case npm autodiscovery fails
simschla Jun 7, 2020
8f88dc2
remove j2v8 reference from readme
simschla Jun 7, 2020
589940c
cleanup server startup code
simschla Jun 7, 2020
48ce207
extract file handling to helper class
simschla Jun 7, 2020
3dcb1ec
refactor and use npmProcess helper instance
simschla Jun 7, 2020
78a0ea8
reduce log noise from npm install call
simschla Jun 7, 2020
bc3c86a
only listen on localhost
simschla Jun 7, 2020
57f97b9
cleanup logging
simschla Jun 7, 2020
d7f3564
enable spotless for js formatting
simschla Jun 7, 2020
ee2dd1d
format js files using spotless
simschla Jun 7, 2020
fbb3961
refactoring: extract inner classes and renamings
simschla Jun 7, 2020
eafb850
adapt changelog
simschla Jun 7, 2020
d47a949
adapt to newer copyright header
simschla Jun 7, 2020
674044b
try to fix circle-ci (use node for running internal spotlessJavascript)
simschla Jun 7, 2020
c70bc85
Remove javascript from our dogfooding.
nedtwigg Jun 8, 2020
12680c5
Fix spotbugs warning.
nedtwigg Jun 8, 2020
92197e1
Windows cache seems to be broken, we'll just let it be slow.
nedtwigg Jun 8, 2020
c0879e1
fixing ci build
simschla Jun 8, 2020
0d6bd65
fixing ci build
simschla Jun 9, 2020
7c91e93
Revert "fixing ci build"
simschla Jun 9, 2020
a3c5614
cleanup accidential sysout checkin
simschla Jun 9, 2020
42309c7
Make the windows build run the npmTest
nedtwigg Jun 11, 2020
f5e7e6c
Oops, windows build doesn't want './'
nedtwigg Jun 11, 2020
d319266
Oops, we need to store the test results too!
nedtwigg Jun 11, 2020
5764f4c
Add a test that recreates the problem I'm seeing.
nedtwigg Jun 11, 2020
a12343f
bump version numbers to latest
simschla Jun 10, 2020
2bc0464
improve robustness and error feedback
simschla Jun 11, 2020
6f8c550
adding a test to prove that we can support prettier-plugins now
simschla Jun 11, 2020
0808fc2
documenting the community-plugin benefit and adding more examples
simschla Jun 11, 2020
e2981e5
PR feedback: try to avoid `**/*.filetype` as target examples
simschla Jun 12, 2020
8eff924
PR feedback: add links to prettier plugins
simschla Jun 12, 2020
dd6f120
add support for prettier-plugins to maven-builds and document in README
simschla Jun 12, 2020
bc9410b
adapting test for new output format
simschla Jun 12, 2020
38053bc
and verify what we actually learned: error message needs to be relaye…
simschla Jun 12, 2020
08d8321
Update changes.
nedtwigg Jun 12, 2020
a69670e
Remove some empty newlines.
nedtwigg Jun 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,9 @@ jobs:
shell: cmd.exe
steps:
- checkout
# install openjdk8
- restore_cache:
key: choco2-ojdkbuild8
- run:
name: install
command: choco install ojdkbuild8
- save_cache:
key: choco2-ojdkbuild8
paths:
- ~\AppData\Local\Temp\chocolatey\ojdkbuild8
# do the test
- restore_cache:
keys:
- gradle-deps-win2-{{ checksum "build.gradle" }}-{{ checksum "gradle.properties" }}
- gradle-deps-win2-
- run:
name: gradlew check
command: gradlew check --build-cache
Expand All @@ -152,13 +140,15 @@ jobs:
path: plugin-gradle/build/test-results/test
- store_test_results:
path: plugin-maven/build/test-results/test
- save_cache:
key: gradle-deps-win2-{{ checksum "build.gradle" }}-{{ checksum "gradle.properties" }}
paths:
- ~/.gradle/caches
- ~/.gradle/wrapper
- ~/.m2
- ~/project/plugin-maven/build/localMavenRepository
- run:
name: gradlew npmTest
command: gradlew npmTest --build-cache
- store_test_results:
path: testlib/build/test-results/npm
- store_test_results:
path: plugin-maven/build/test-results/npm
- store_test_results:
path: plugin-gradle/build/test-results/npm
changelog_print:
<< : *env_gradle
steps:
Expand Down
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ This document is intended for Spotless developers.
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).

## [Unreleased]
### Changed
* Nodejs-based formatters `prettier` and `tsfmt` now use native node instead of the J2V8 approach. ([#606](https://github.com/diffplug/spotless/pull/606))
* This removes the dependency to the no-longer-maintained Linux/Windows/macOs variants of J2V8.
* This enables spotless to use the latest `prettier` versions (instead of being stuck at prettier version <= `1.19.0`)
* Bumped default versions, prettier `1.16.4` -> `2.0.5`, tslint `5.12.1` -> `6.1.2`


## [1.34.0] - 2020-06-05
### Added
Expand Down
110 changes: 110 additions & 0 deletions lib/src/main/java/com/diffplug/spotless/npm/JsonEscaper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright 2016-2020 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.spotless.npm;

import static java.util.Objects.requireNonNull;

/**
* Simple implementation on how to escape values when printing json.
* Implementation is partly based on https://github.com/stleary/JSON-java
*/
final class JsonEscaper {
private JsonEscaper() {
// no instance
}

public static String jsonEscape(Object val) {
requireNonNull(val);
if (val instanceof JsonRawValue) {
return jsonEscape((JsonRawValue) val);
}
if (val instanceof String) {
return jsonEscape((String) val);
}
return val.toString();
}

private static String jsonEscape(JsonRawValue jsonRawValue) {
return jsonRawValue.getRawJson();
}

private static String jsonEscape(String unescaped) {
/**
* the following characters are reserved in JSON and must be properly escaped to be used in strings:
*
* Backspace is replaced with \b
* Form feed is replaced with \f
* Newline is replaced with \n
* Carriage return is replaced with \r
* Tab is replaced with \t
* Double quote is replaced with \"
* Backslash is replaced with \\
*
* additionally we handle xhtml '</bla>' string
* and non-ascii chars
*/
StringBuilder escaped = new StringBuilder();
escaped.append('"');
char b;
char c = 0;
for (int i = 0; i < unescaped.length(); i++) {
b = c;
c = unescaped.charAt(i);
switch (c) {
case '\"':
escaped.append('\\').append('"');
break;
case '\n':
escaped.append('\\').append('n');
break;
case '\r':
escaped.append('\\').append('r');
break;
case '\t':
escaped.append('\\').append('t');
break;
case '\b':
escaped.append('\\').append('b');
break;
case '\f':
escaped.append('\\').append('f');
break;
case '\\':
escaped.append('\\').append('\\');
break;
case '/':
if (b == '<') {
escaped.append('\\');
}
escaped.append(c);
break;
default:
if (c < ' ' || (c >= '\u0080' && c < '\u00a0')
|| (c >= '\u2000' && c < '\u2100')) {
escaped.append('\\').append('u');
String hexString = Integer.toHexString(c);
escaped.append("0000", 0, 4 - hexString.length());
escaped.append(hexString);
} else {
escaped.append(c);
}
}
}
escaped.append('"');
return escaped.toString();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 DiffPlug
* Copyright 2016-2020 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,27 +15,23 @@
*/
package com.diffplug.spotless.npm;

class TsFmtResult {
import static java.util.Objects.requireNonNull;

private final String message;
private final Boolean error;
private final String formatted;

TsFmtResult(String message, Boolean error, String formatted) {
this.message = message;
this.error = error;
this.formatted = formatted;
}
/**
* Wrapper class to signal the contained string must not be escaped when printing to json.
*/
class JsonRawValue {
private final String rawJson;

String getMessage() {
return message;
private JsonRawValue(String rawJson) {
this.rawJson = requireNonNull(rawJson);
}

Boolean isError() {
return error;
static JsonRawValue wrap(String rawJson) {
return new JsonRawValue(rawJson);
}

String getFormatted() {
return formatted;
public String getRawJson() {
return rawJson;
}
}
132 changes: 0 additions & 132 deletions lib/src/main/java/com/diffplug/spotless/npm/NodeJSWrapper.java

This file was deleted.

Loading