vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
589 stars 164 forks source link

Default tsconfig.json exclude property breaks maven multi module project compilation #18186

Open ggecy opened 7 months ago

ggecy commented 7 months ago

Description of the bug

Hi, we have a big maven multi module project where typescript files are located in many modules on src/main/resources/META-INF/resources/frontend/src/... paths. We are using aliases defined in tsconfig.json together with filesystem links to fake the file locations during development to make the editing of files in different modules at least somehow tolerable, so Intellij Idea doesn't just display a ton of errors in editor. However tsconfig.json that is generated by vaadin by default contains the property "exclude": ["frontend/generated/jar-resources/**"] , which prevents the project from compiling because the aliases are not resolved in exlcluded files and all files from all maven modules in the project end up in that frontend/generated/jar-resources folder. This is an example tsconfig.json from our project from one of the bootstrap modules - see additianl alias in "paths" property:

// 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
{
  "_version": "9",
  "compilerOptions": {
    "sourceMap": true,
    "jsx": "react-jsx",
    "inlineSources": true,
    "module": "esNext",
    "target": "es2020",
    "moduleResolution": "bundler",
    "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/*": ["*"],
      "CommonsWeb/*": ["generated/jar-resources/src/*"]
    }
  },
  "include": [
    "frontend/**/*",
    "types.d.ts"
  ],
  "exclude": ["frontend/generated/jar-resources/**"]
}

Each maven module containing the typescript source files has its own "fake" tsconfig.json inside where the CommonsWeb alias has different relative path pointing to a linked src dir from common web module. That way idea can resolve the imports correctly while editing files in their respective modules while vaadin can also compile them when they end up all together inside frontend/generated/jar-resources folder in bootstrap module. Project can only compile if I remove the "exclude" property value in tsconfig.json. vite-config.ts also need the vite-tsconfig-paths plugin to respect the aliases defined in tsconfig.json file:

import { UserConfigFn } from 'vite';
import { overrideVaadinConfig } from './vite.generated';
import tsconfigPaths from "vite-tsconfig-paths";

const customConfig: UserConfigFn = (env) => ({
    plugins: [tsconfigPaths()]
});

export default overrideVaadinConfig(customConfig);

Expected behavior

Default generated tsconfig.json file should work in multimodule environment.

Minimal reproducible example

-

Versions

mshabarov commented 7 months ago

This exclude parameter was introduced in https://github.com/vaadin/flow/pull/15700 in order to dix the compilation problems of third-party JS/TS add-ons/libraries in Flow applications, see https://github.com/vaadin/flow/issues/15485. Thus, we cannot remove it completely.

Originally the idea was to exclude JS from JAR resources, but we haven't taken into account multi-module projects.

mshabarov commented 7 months ago

One can modify the tsconfig.json file and then this file shouldn't be overridden by Vaadin for next run. Thus, I think that just removing the exclude parameter would be enough to fix the issue and it's not a bug in Vaadin.

ggecy commented 7 months ago

Yes, I had to remove exclude from all tsconfig.json files after migration to v24 and it stays removed after that. However it wasn't really obvious what's broken at first glance so I created the issue because it wasn't in migration instructions and it broke the build.

mshabarov commented 7 months ago

Thanks, then I believe this is a matter of documenting this case in our migration guide.