Task #101782
closedUse TypeScript tsconfig include instead of exclude
100%
Description
This helps to prevent hard-to-discover build failures, that only
happen on clean installs (e.g. CI).
This is because TypeScript will by default scan the entire source
dictionary (Build/ in our case) for possible includes.
We previously excluded /Build/composer in #95046, but it is actually
much better to explicitly include the actually used source paths
to also exclude build output (Build/JavaScript/) from being
reinterpreted by subsequential eslint or tsc compile runs.
Note that we also refactor the types/ directory in order to
be a folder that conforms to the @types/* packages conventions,
by being actually usable in the compilerOptions.types property.
Note that our custom global type definitions (types/) were previously
implicitly loaded as globally available sourcepaths.
With the new `include` option we could add them back, but then we
wouldn't notice if we do not add proper index.d.ts files (like we
did until now). Therefore index.d.ts files are added in here.
Now, with TypeScript being "clean", we need a another small
adjustment in order for eslint to still being able to lint
our types/ folder. Therefore tsconfig.json is extended to
include the types directory. See [1] for more information on
why eslint needs that.
Note that this happened with https://review.typo3.org/c/Packages/TYPO3.CMS/+/80736 where clean installs failed with:
Build/Scripts/runTests.sh -s lintTypescript 00:35 npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility added 988 packages, and audited 989 packages in 9s 129 packages are looking for funding run `npm fund` for details found 0 vulnerabilities clean: postcss.plugin was deprecated. Migration guide: https://evilmartians.com/chronicles/postcss-8-plugin-migration Running "eslint:files" (eslint) task Warning: Debug Failure. Unhandled declaration kind! ModuleDeclaration for { name: TYPO3; flags: ExportDoesNotSupportDefaultModifier|Property|ValueModule|ExportHasLocal|NamespaceModule|Module|Namespace|AccessorExcludes|GetAccessorExcludes|SetAccessorExcludes|PropertyOrAccessor|MethodExcludes|ClassMember|ValueModuleExcludes|FunctionExcludes|FunctionScopedVariableExcludes|Value|BlockScopedVariableExcludes|ParameterExcludes|RegularEnumExcludes|ClassExcludes|ConstEnumExcludes|EnumMemberExcludes|ModuleMember|Classifiable|Transient|All|Assignment; declarations: PropertyAccessExpression,Identifier,ModuleDeclaration,ModuleDeclaration,ModuleDeclaration,ModuleDeclaration } Occurred while linting /builds/typo3/CI/cms/Build/Sources/TypeScript/backend/date-time-picker.ts:221 Rule: "@typescript-eslint/prefer-readonly" Use --force to continue.
Note that the error did not happen when the Build output Build/JavaScript
was present. Removing that folder, made the error appear, addeding it back, made it disappear.
That show that eslint plugin (@typescript-eslint/prefer-readonly), which uses the typescript node module underneath, actually took the previous build output into account for the new build – this MUST be avoided.