[bugfix] Ensured that normalizeFileExt ignores .css.d.ts files #1450
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
I created
sample-v2-addon
to investigate how we can introduce CSS modules to v2 addons (while supporting Glint). The key is, for each CSS file*.css
, to create the corresponding declaration file*.css.d.ts
.When the addon's
publicEntrypoints
andappReexports
include the "normal" wildcard patterncomponents/**/*.js
, the resultingdist
will include files that are not supposed to be present:I worked around the problem by providing the pattern
components/**/!(*.css.d).js
, but find the additional complexity in regular expression to be a tech risk (not easy to understand—what is.css.d.js
?—and maintain):Proposed solution
I suspect, the current implementation of
normalizeFileExt
didn't consider file extensions that include.ts
as a substring.By making an early exit, we can consider
*.ts
cases and define a more specific rule that ignores.css.d.ts
.Admittedly, the regular expression
/(^.?|\.[^d]|[^.]d|[^.][^d])\.ts$/
, copied from StackOverflow, is complex and forms another tech risk. Ideally, unit tests fornormalizeFileExt
would be present to document its input and output. (I didn't know in which package such tests can be written.)