Skip to content

Support wider set of web extensions - #2211

Merged
lukastaegert merged 4 commits into
masterfrom
wellknown-extensions
May 27, 2018
Merged

Support wider set of web extensions#2211
lukastaegert merged 4 commits into
masterfrom
wellknown-extensions

Conversation

@guybedford

Copy link
Copy Markdown
Contributor

From #2206, we can strip a wider list of well-known web extensions.

I'd be happy to expand this list as well to anything that could be considered as a MIME.

@guybedford
guybedford force-pushed the wellknown-extensions branch from 33b6adc to b14fa2b Compare May 23, 2018 09:10

@lukastaegert lukastaegert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is a good idea but why not actually make this a configuration? For once, the more file types we add, the more things like extension priority starts to matter. And at the same time, users could tailor it to their needs.

I would also suggest to give .mjs the highest priority by default, not .js.

@guybedford

Copy link
Copy Markdown
Contributor Author

This isn't affecting what extensions can be loaded in the resolver at all (that remains .js only). But rather is affecting how we detect a name from an input (x.asdf -> x only if .asdf is a known extension).

Ideally I would actually want to pull in the MIME module here and accept anything that is registered as a MIME, but due to the bundle requirements for Rollup, would rather let this grow into an internal registry tailored to the JS ecosystem.

Perhaps I can try and make the first pass more comprehensive if that would help?

Comment thread src/utils/relativeId.ts Outdated
'.js': true,
'.mjs': true,
'.jsx': true,
'.ts': true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typescript forces to use tsx extension with jsx

@lukastaegert

Copy link
Copy Markdown
Member

This isn't affecting what extensions can be loaded in the resolver at all

Ah you are right. I had those two connected in my head but yes, those are separate things. I think this is ok but @TrySound's suggestion is surely valid.

@guybedford

Copy link
Copy Markdown
Contributor Author

I've actually modified the approach to no longer need an extension lookup, and instead flexibly determine the extension - basically by stripping the resolved extension from the alias.

@guybedford
guybedford force-pushed the wellknown-extensions branch from 7228a32 to c8fd10f Compare May 26, 2018 12:51

@lukastaegert lukastaegert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like the update but still think we should add a configuration, see my comment

Comment thread src/utils/defaults.ts Outdated
}
found = findFile(file + '.js', preserveSymlinks);
if (found) return found;
return findFile(file + '.mjs', preserveSymlinks);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But going back to my original comment, wouldn't this allow .mjs to be used without an extension while giving precedence to .js in these situations which is probably not in rollup's best interest? If we do this, I think these two extensions + their precedence should be configurable as an array with the default being ['mjs', 'js']. On the other hand, this would FINALLY settle some long-standing feature requests, cf #1894

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I forgot we were supporting mjs here actually, also only just saw this again when refactoring the above. I've fixed this up to at least check in the right order, meaning yes we can properly support .mjs now!

Personally, I don't think we should have an array here - anything that configures the resolver should also configure the loader to support the translate for that file extension. .mjs and .js are the only valid registered MIMES for JavaScript files, with a well-defined precedence, and anything else will be a different module format.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense 👍 I still think that we may want to configure this at some point (if people ask about it?) but with this behaviour in place, this can definitely wait for another PR. I just remember struggling with some linter settings around this behaviour at work and being happy that Webpack has an option to configure just that.

@lukastaegert
lukastaegert force-pushed the wellknown-extensions branch from 8098238 to 69f94e4 Compare May 27, 2018 18:22
@lukastaegert
lukastaegert merged commit 69f94e4 into master May 27, 2018
@lukastaegert lukastaegert added this to the 0.60.0 milestone May 27, 2018
@lukastaegert
lukastaegert deleted the wellknown-extensions branch May 27, 2018 18:26
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.

3 participants