Skip to content

Commit

Permalink
Merge pull request #606 from simschla/feature/use-native-npm
Browse files Browse the repository at this point in the history
Feature/use native npm
  • Loading branch information
simschla authored Jun 12, 2020
2 parents 7fb2333 + a69670e commit e7dbfc8
Show file tree
Hide file tree
Showing 46 changed files with 2,047 additions and 1,213 deletions.
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

0 comments on commit e7dbfc8

Please sign in to comment.