Skip to content

Commit

Permalink
feat(hilla): make tsconfig.json React compatible (#15084)
Browse files Browse the repository at this point in the history
* feat(hilla): make tsconfig.json React compatible

* chore: update tsconfig-reference.json

* chore: update tsconfig version

* test: update tsconfig latest version and instructions

* chore: set tsconfig flow_version to 23.3.0.1
  • Loading branch information
platosha authored Nov 29, 2022
1 parent 719a3dd commit 448ed9b
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public class TaskGenerateTsConfig extends AbstractTaskClientGenerator {
private static final String VERSION = "flow_version";
private static final String ES_TARGET_VERSION = "target";
private static final String TSCONFIG_JSON_OLDER_VERSIONS_TEMPLATE = "tsconfig-%s.json";
private static final String[] vaadinVersions = { "latest", "v23.2", "v23.1",
"v22", "v14", "osgi" };
private static final String[] vaadinVersions = { "latest", "v23.3.0",
"v23.2", "v23.1", "v22", "v14", "osgi" };

//@formatter:off
static final String ERROR_MESSAGE =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// This TypeScript configuration file is generated by vaadin-maven-plugin.
// This is needed for TypeScript compiler to compile your TypeScript code in the project.
// It is recommended to commit this file to the VCS.
// You might want to change the configurations to fit your preferences
// For more information about the configurations, please refer to http://www.typescriptlang.org/docs/handbook/tsconfig-json.html
{
"flow_version": "23.3.0",
"compilerOptions": {
"sourceMap": true,
"inlineSources": true,
"module": "esNext",
"target": "es2020",
"moduleResolution": "node",
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noImplicitAny": true,
"noImplicitThis": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"experimentalDecorators": true,
"useDefineForClassFields": false,
"baseUrl": "frontend",
"paths": {
"@vaadin/flow-frontend": ["generated/jar-resources"],
"@vaadin/flow-frontend/*": ["generated/jar-resources/*"],
"Frontend/*": ["*"]
}
},
"include": [
"frontend/**/*.ts",
"frontend/index.js",
"types.d.ts"
],
"exclude": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
// You might want to change the configurations to fit your preferences
// For more information about the configurations, please refer to http://www.typescriptlang.org/docs/handbook/tsconfig-json.html
{
"flow_version": "23.3.0",
"flow_version": "23.3.0.1",
"compilerOptions": {
"sourceMap": true,
"jsx": "react-jsx",
"inlineSources": true,
"module": "esNext",
"target": "es2020",
Expand All @@ -29,8 +30,7 @@
}
},
"include": [
"frontend/**/*.ts",
"frontend/index.js",
"frontend/**/*",
"types.d.ts"
],
"exclude": []
Expand Down
1 change: 1 addition & 0 deletions flow-server/src/main/resources/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"sourceMap": true,
"jsx": "react-jsx",
"inlineSources": true,
"module": "esNext",
"target": "es2020",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import static java.nio.charset.StandardCharsets.UTF_8;

public class TaskGenerateTsConfigTest {
static private String LATEST_VERSION = "23.3.0.1";

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();

Expand Down Expand Up @@ -186,7 +188,8 @@ public void tsConfigUpdated_remindsUpdateVersionAndTemplates()
+ "Please also: 1. Increment version in tsconfig.json (\"flow_version\" property) "
+ "2. create a new tsconfig-vX.Y.json template in flow-server resources and put the old content there "
+ "3. update vaadinVersion array in TaskGenerateTsConfig with X.Y "
+ "4. put a new content in tsconfig-reference.json in tests",
+ "4. put a new content in tsconfig-reference.json in tests "
+ "5. update LATEST_VERSION in TaskGenerateTsConfigTest",
testTsConfig, tsConfigLatest);

}
Expand All @@ -196,17 +199,19 @@ public void tsConfigHasLatestVersion_noUpdates()
throws IOException, ExecutionFailedException {
File tsconfig = new File(npmFolder, "tsconfig.json");
Files.createFile(tsconfig.toPath());
FileUtils.writeStringToFile(tsconfig, "{\"flow_version\": \"23.3.0\"}",
UTF_8);
FileUtils.writeStringToFile(tsconfig,
"{\"flow_version\": \"" + LATEST_VERSION + "\"}", UTF_8);
taskGenerateTsConfig.execute();

String tsConfigString = FileUtils.readFileToString(tsconfig, UTF_8);

String expected = IOUtils.toString(
Objects.requireNonNull(TaskGenerateTsConfigTest.class
.getClassLoader()
.getResourceAsStream("tsconfig-latest-version.json")),
StandardCharsets.UTF_8);
String expected = IOUtils
.toString(
Objects.requireNonNull(TaskGenerateTsConfigTest.class
.getClassLoader().getResourceAsStream(
"tsconfig-latest-version.json")),
StandardCharsets.UTF_8)
.replace("latest", LATEST_VERSION);

Assert.assertEquals(expected, tsConfigString);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"flow_version": "23.3.0"}
{"flow_version": "latest"}
6 changes: 3 additions & 3 deletions flow-server/src/test/resources/tsconfig-reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
// You might want to change the configurations to fit your preferences
// For more information about the configurations, please refer to http://www.typescriptlang.org/docs/handbook/tsconfig-json.html
{
"flow_version": "23.3.0",
"flow_version": "23.3.0.1",
"compilerOptions": {
"sourceMap": true,
"jsx": "react-jsx",
"inlineSources": true,
"module": "esNext",
"target": "es2020",
Expand All @@ -29,8 +30,7 @@
}
},
"include": [
"frontend/**/*.ts",
"frontend/index.js",
"frontend/**/*",
"types.d.ts"
],
"exclude": []
Expand Down

0 comments on commit 448ed9b

Please sign in to comment.