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

feat(hilla): make tsconfig.json React compatible #15084

Merged
merged 11 commits into from
Nov 29, 2022
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",
platosha marked this conversation as resolved.
Show resolved Hide resolved
"inlineSources": true,
"module": "esNext",
"target": "es2020",
Expand All @@ -29,8 +30,7 @@
}
},
"include": [
"frontend/**/*.ts",
"frontend/index.js",
"frontend/**/*",
platosha marked this conversation as resolved.
Show resolved Hide resolved
"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