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

Include extensions in preserveModules output filenames for scriptified assets #3116

Conversation

Andarist
Copy link
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

fixes #3107

Description

This adds support for ext and extname replacements for entryFileNames when using preserveModules.

Using this I include extname in output filenames for "scriptified" assets.

@codecov
Copy link

codecov bot commented Sep 15, 2019

Codecov Report

Merging #3116 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3116      +/-   ##
==========================================
+ Coverage   89.31%   89.32%   +0.01%     
==========================================
  Files         165      165              
  Lines        5728     5734       +6     
  Branches     1738     1739       +1     
==========================================
+ Hits         5116     5122       +6     
  Misses        379      379              
  Partials      233      233
Impacted Files Coverage Δ
src/Chunk.ts 92.88% <100%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 55dddd8...18ecfe0. Read the comment docs.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot and sorry for the wait, just some minor comments from my side

src/Chunk.ts Outdated Show resolved Hide resolved
src/Chunk.ts Outdated
const name = renderNamePattern(
options.entryFileNames || '[name].js',
options.entryFileNames ||
(COMMON_JS_EXTENSIONS.includes(extension) ? '[name].js' : '[name].[ext].js'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why the name is COMMON_JS... as I do not see the connection. How about JAVASCRIPT_EXTENSION or IGNORED_EXTENSIONS? Also, I would rather have the default pattern to be [name][extname].js, the reason being that otherwise, files without extension would have two subsequent . in their name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAVASCRIPT_EXTENSIONS would work, just seemed a little bit inaccurate as it also includes TS extensions - i'm ok with renaming it though to whatever you see consider fitting here

Also, I would rather have the default pattern to be [name][extname].js

I've wanted to avoid output files being named like Buttonscss.js, like - having some separator seems visually nice

files without extension would have two subsequent . in their name.

Gonna add some special handling for it + tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've wanted to avoid output files being named like Buttonscss.js, like - having some separator seems visually nice

Definitely, but the point of [extname] vs [ext] should be that [extname] contains a leading . if there is an extension and is an empty string otherwise. So it basically solves exactly this issue. So

filename ext extname [name][extname].js [name].[ext].js
"test.css" "css" ".css" "test.css.js" "test.css.js"
"test" "" "" "test.js" "test..js" ⚠️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm ok with renaming it though to whatever you see consider fitting here

How about NON_ASSET_EXTENSIONS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely, but the point of [extname] vs [ext] should be that [extname] contains a leading . if there is an extension and is an empty string otherwise.

Cool, didn't notice I could use it like this.

How about NON_ASSET_EXTENSIONS?

Sure, sounds good!

'output.entryFileNames',
{
ext: () => extension.substr(1),
extname: () => extension,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to also have a test that directly uses the new pattern elements in entryFileNames. Could also be an extension of an existing test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, gonna tweak it.

@Andarist
Copy link
Member Author

@lukastaegert thanks for the review, gonna address your concerns in following days and ping you once I'm done with it.

@Andarist Andarist force-pushed the preserve-modules/scriptified-assets-ext-in-filenames branch from 24fde1a to 3560bfb Compare September 30, 2019 17:18
@Andarist
Copy link
Member Author

@lukastaegert I believe I've addressed all of your comment

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the issues, looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for file extension placeholder and function in output.entryFileNames option
2 participants