classification
Title: Add mimetype for extension .mjs
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, barry, benjamin.peterson, bradleymeck, christian.heimes, di, mylesborins, ned.deily, r.david.murray
Priority: normal Keywords: patch

Created on 2017-10-06 15:06 by bradleymeck, last changed 2018-12-24 16:31 by ned.deily. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3908 merged bradleymeck, 2017-10-06 15:27
PR 10976 merged mylesborins, 2018-12-06 05:23
PR 10977 merged mylesborins, 2018-12-06 05:23
PR 10978 merged mylesborins, 2018-12-06 05:24
Messages (14)
msg303824 - (view) Author: Bradley Meck (bradleymeck) * Date: 2017-10-06 15:06
I propose to add a mapping of file extension .mjs to mime type "text/javascript".
The "text/javascript" MIME is registered in https://www.iana.org/assignments/media-types, was moved to *should* as the MIME in HTML ( https://github.com/whatwg/html/pull/3096), and is being updated by https://datatracker.ietf.org/doc/draft-bfarias-javascript-mjs/

This extension is being used by Node.js for support of ECMAScript Modules (ESM).
msg327369 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2018-10-08 20:05
New changeset 0854b92cd25613269d21de3cb5239379ddc0f2fb by Andrew Svetlov (Bradley Meck) in branch 'master':
bpo-31715 Add mimetype for extension .mjs (#3908)
https://github.com/python/cpython/commit/0854b92cd25613269d21de3cb5239379ddc0f2fb
msg331143 - (view) Author: Myles Borins (mylesborins) * Date: 2018-12-05 19:18
I see that when this landed it appears that it was removed from landing on "Python 2.7, Python 3.6, Python 3.7".

Is there any chance to revisit this decision? I dug into the mimetype code and it doesn't appear that there is a way to rely on operating system mimetypes for systems aside from Windows... as such this is going to be a fairly large experience gap for people developing front-end applications that utilize the file extension on any version other than 3.8, which will likely take quite a while to be distributed as a default in various OS distributions.
msg331144 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2018-12-05 19:23
It's technically a new feature. New features are not added to existing releases unless there is a very compelling reason.
msg331157 - (view) Author: Myles Borins (mylesborins) * Date: 2018-12-05 20:29
There are a number of tutorials that suggest using the .mjs extension for working with ESM modules for front end development.

https://developers.google.com/web/fundamentals/primers/modules <https://developers.google.com/web/fundamentals/primers/modules>
https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/ <https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/>

There are many tutorials that suggest web developers use `python -m SimpleHTTPServer` as a way to spin up a quick development server.  If a .mjs file is not served with the correct mime type <https://html.spec.whatwg.org/multipage/infrastructure.html#javascript-mime-type> the browser will throw when trying to load the module, and the error is not the most obvious if developers are not aware of what mime types even are.

As such I would like propose that this is a bug fix, rather than a feature, as popular browser workflow is going to be broken without an obvious way to fix it for anyone using python right now.

> On Dec 5, 2018, at 2:23 PM, Christian Heimes <report@bugs.python.org> wrote:
> 
> 
> Christian Heimes <lists@cheimes.de> added the comment:
> 
> It's technically a new feature. New features are not added to existing releases unless there is a very compelling reason.
> 
> ----------
> nosy: +christian.heimes
> 
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue31715>
> _______________________________________
msg331164 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2018-12-05 21:00
Christian Heimes is right: it is a new feature, not a bug fix. 
I regret too often when I cannot backport a brilliant patch to old Python version but this is the price of API stability.

You can try to convince release managers (Benjamin and Ned, I've added you to nosy list) but I suspect you'll get a rejection.
msg331165 - (view) Author: Myles Borins (mylesborins) * Date: 2018-12-05 21:09
Thanks for cc'ing the other folks. I help run the Node.js release + LTS team... so I 100% understand the balance necessary to keep a stable API. In this particular case I would gauge that this has a near 0 case for breakage, but leaving it unpatched has a high risk of breaking user expectations

https://github.com/search?q=extension%3Amjs+function&type=Code

This is a really heavy handed search against github showing 13k+ files with the .mjs extension that include the word "function"
msg331169 - (view) Author: Myles Borins (mylesborins) * Date: 2018-12-05 21:19
Also wanted to point out some prior art of a mimetype (json) being backported to all active runtimes

https://bugs.python.org/issue30824#msg297527
msg331182 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2018-12-05 22:04
We have generally made an exception to the "new feature" rule for mimetypes.  That is, we don't really consider a mimetype addition to be a new feature in the sense that our backward compatibility rules mean.  It is true that an application could work on x.y.z and break on x.y.z-1, but this isn't because an *API* present in x.y.z is not there in x.y.z-1.  is more akin to a bugfix (it threw an exception before, now it works).  Think of the absence of the mimetype rule as a bug, rather than its presence as a feature.

And yes, this is a policy evolution.  This way of looking at mimetypes changes has been in effect for....maybe five years now?...and before that we treated them as features.  But then, too, before that we required there be an actual IANA accepted RFC, but that requirement too has had to evolve as mimetype management became more decentralized.
msg331204 - (view) Author: Myles Borins (mylesborins) * Date: 2018-12-06 05:25
Thanks for chiming in R. David Murray

> Think of the absence of the mimetype rule as a bug, rather than its presence as a feature.

Very much appreciate this sentiment.

I've opened backports to simplify the process if y'all decide to approve.

2.7: https://github.com/python/cpython/pull/10978
3.6: https://github.com/python/cpython/pull/10976
3.7: https://github.com/python/cpython/pull/10977
msg332254 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-12-20 20:26
New changeset c7b7a43cd8964a90669bb37735cdafc5b0ec60cc by Ned Deily (Myles Borins) in branch '3.7':
[3.7] bpo-31715 Add mimetype for extension .mjs (GH-3908) (GH-10977)
https://github.com/python/cpython/commit/c7b7a43cd8964a90669bb37735cdafc5b0ec60cc
msg332255 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-12-20 20:28
New changeset 70db385944ecf2ceed10ed7d91fce68399f9ca8a by Ned Deily (Myles Borins) in branch '3.6':
[3.6] bpo-31715 Add mimetype for extension .mjs (GH-3908) (GH-10976)
https://github.com/python/cpython/commit/70db385944ecf2ceed10ed7d91fce68399f9ca8a
msg332256 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-12-20 20:29
New changeset d9a2aca839b1326e011ecca17ba7b45123c47a64 by Ned Deily (Myles Borins) in branch '2.7':
[2.7] bpo-31715 Add mimetype for extension .mjs (GH-3908) (GH-10978)
https://github.com/python/cpython/commit/d9a2aca839b1326e011ecca17ba7b45123c47a64
msg332485 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-12-24 16:31
New changeset 25ee15a15c2d274afeea2dc5a0a0b4fb4bea904b by Ned Deily (Myles Borins) in branch '3.7':
[3.7] bpo-31715 Add mimetype for extension .mjs (GH-3908) (GH-10977)
https://github.com/python/cpython/commit/25ee15a15c2d274afeea2dc5a0a0b4fb4bea904b
History
Date User Action Args
2018-12-24 16:31:53ned.deilysetmessages: + msg332485
2018-12-20 20:30:11ned.deilysetversions: + Python 2.7, Python 3.6, Python 3.7
2018-12-20 20:29:36ned.deilysetmessages: + msg332256
2018-12-20 20:28:32ned.deilysetmessages: + msg332255
2018-12-20 20:26:06ned.deilysetmessages: + msg332254
2018-12-06 05:25:39mylesborinssetmessages: + msg331204
2018-12-06 05:24:04mylesborinssetpull_requests: + pull_request10219
2018-12-06 05:23:57mylesborinssetpull_requests: + pull_request10218
2018-12-06 05:23:48mylesborinssetpull_requests: + pull_request10217
2018-12-05 22:04:53r.david.murraysetmessages: + msg331182
2018-12-05 22:00:27disetnosy: + di
2018-12-05 21:19:20mylesborinssetmessages: + msg331169
2018-12-05 21:09:10mylesborinssetmessages: + msg331165
2018-12-05 21:00:13asvetlovsetnosy: + benjamin.peterson, ned.deily
messages: + msg331164
2018-12-05 20:29:51mylesborinssetmessages: + msg331157
2018-12-05 19:23:39christian.heimessetnosy: + christian.heimes
messages: + msg331144
2018-12-05 19:18:41mylesborinssetnosy: + mylesborins
messages: + msg331143
2018-10-08 20:05:22asvetlovsetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: - Python 2.7, Python 3.6, Python 3.7
2018-10-08 20:05:00asvetlovsetnosy: + asvetlov
messages: + msg327369
2018-08-20 16:55:24Mariattasetnosy: + barry, r.david.murray
2017-10-06 15:27:13bradleymecksetkeywords: + patch
stage: patch review
pull_requests: + pull_request3879
2017-10-06 15:06:33bradleymeckcreate