{"action":"created","issue":{"url":"https://api.github.com/repos/ember-cli/ember-cli/issues/7897","repository_url":"https://api.github.com/repos/ember-cli/ember-cli","labels_url":"https://api.github.com/repos/ember-cli/ember-cli/issues/7897/labels{/name}","comments_url":"https://api.github.com/repos/ember-cli/ember-cli/issues/7897/comments","events_url":"https://api.github.com/repos/ember-cli/ember-cli/issues/7897/events","html_url":"https://github.com/ember-cli/ember-cli/pull/7897","id":338777175,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk5NjI1MjY2","number":7897,"title":"Introduce Standard ESM","user":{"login":"twokul","id":1131196,"node_id":"MDQ6VXNlcjExMzExOTY=","avatar_url":"https://avatars2.githubusercontent.com/u/1131196?v=4","gravatar_id":"","url":"https://api.github.com/users/twokul","html_url":"https://github.com/twokul","followers_url":"https://api.github.com/users/twokul/followers","following_url":"https://api.github.com/users/twokul/following{/other_user}","gists_url":"https://api.github.com/users/twokul/gists{/gist_id}","starred_url":"https://api.github.com/users/twokul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twokul/subscriptions","organizations_url":"https://api.github.com/users/twokul/orgs","repos_url":"https://api.github.com/users/twokul/repos","events_url":"https://api.github.com/users/twokul/events{/privacy}","received_events_url":"https://api.github.com/users/twokul/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-07-06T01:43:40Z","updated_at":"2018-07-09T20:11:30Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/ember-cli/ember-cli/pulls/7897","html_url":"https://github.com/ember-cli/ember-cli/pull/7897","diff_url":"https://github.com/ember-cli/ember-cli/pull/7897.diff","patch_url":"https://github.com/ember-cli/ember-cli/pull/7897.patch"},"body":"This change enables a smooth transition between Node and ES module\r\nformats and compensates for CJS and ESM incompatibility.\r\n\r\nThe tool used to enable this transition is\r\n[esm](https://github.com/standard-things/esm).\r\n\r\nThe `esm` loader is intended for runtime use, so no build step or\r\npre-publish step is required of the user. There is a 1 time transform\r\ncost per ESM module, after that the result is cached and loading is on\r\npar with CJS. The loader itself when published will be a small, ~40kb,\r\nzero dependency package.\r\n\r\nChanges:\r\n\r\n+ add `esm` as a dependency\r\n+ add `esm` config to `package.json`\r\n  + `\"cjs\": true` means we get to use `require` in files until we’re ready to convert to `import`\r\n+ repurpose `lib/cli/index.js` to use `esm` loader\r\n+ move `lib/cli/index.js` code to `lib/cli/main.js` and replaced `require`s with `import`s\r\n+ remove `use strict;` from files as `esm` adds it by default\r\n+ add `overrides` to `.eslintrc.js` to hint different parse option\r\n+ add a note on ESM support\r\n\r\nPreviously, we ran into an issue w/ having to change our public API\r\n`require`s:\r\n\r\n```javascript\r\n// Now\r\nconst EmberApp = require('ember-cli/lib/broccoli/ember-app');\r\n\r\n// After conversion (w/o making changes)\r\nconst EmberApp = require('ember-cli/lib/broccoli/ember-app').default;\r\n```\r\n\r\nWe don't want to break our public API of course, so we can do the\r\nfollowing:\r\n\r\n```javascript\r\n// lib/broccoli/ember-app/index.js\r\nrequire = require('esm')(module)\r\nmodule.exports = require('./main.js').default\r\n\r\n// lib/broccoli/ember-app/main.js\r\n/* current `ember-app.js` converted to ES module */\r\n```\r\n\r\nThat way public API won't break.\r\n\r\nUseful links:\r\n\r\n+ [Prior art](https://github.com/ember-cli/ember-cli/pull/7331)"},"comment":{"url":"https://api.github.com/repos/ember-cli/ember-cli/issues/comments/403604794","html_url":"https://github.com/ember-cli/ember-cli/pull/7897#issuecomment-403604794","issue_url":"https://api.github.com/repos/ember-cli/ember-cli/issues/7897","id":403604794,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMzYwNDc5NA==","user":{"login":"jdalton","id":4303,"node_id":"MDQ6VXNlcjQzMDM=","avatar_url":"https://avatars2.githubusercontent.com/u/4303?v=4","gravatar_id":"","url":"https://api.github.com/users/jdalton","html_url":"https://github.com/jdalton","followers_url":"https://api.github.com/users/jdalton/followers","following_url":"https://api.github.com/users/jdalton/following{/other_user}","gists_url":"https://api.github.com/users/jdalton/gists{/gist_id}","starred_url":"https://api.github.com/users/jdalton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdalton/subscriptions","organizations_url":"https://api.github.com/users/jdalton/orgs","repos_url":"https://api.github.com/users/jdalton/repos","events_url":"https://api.github.com/users/jdalton/events{/privacy}","received_events_url":"https://api.github.com/users/jdalton/received_events","type":"User","site_admin":false},"created_at":"2018-07-09T20:11:30Z","updated_at":"2018-07-09T20:11:30Z","author_association":"NONE","body":"@rwjblue \r\n\r\n> but I'm still not sure how it would resolve the issue fully.\r\n>\r\n> As far as I can tell, it would still require that the file being required by the end user be the one with a snippet like this\r\n\r\nThe option would be enabled by default and allow you to export your package as \r\n#### main.js\r\n```js\r\nexport default someFunction\r\n```\r\nwith a CJS bridge of \r\n\r\n#### index.js\r\n```js\r\nrequire = require('esm')(module)\r\nmodule.exports = require(\"./main.js\")\r\n```\r\nthe consumer unaware of what syntax you've written your package in can do\r\n```js\r\nconst someFunction = require(\"someFunction\")\r\n```\r\nand it receive the `someFunction` export without the dangling `.default`.\r\n\r\n> For that to work, wouldn't we would need to ensure that all files that may be deeply required from the ember-cli package by apps are modified?\r\n\r\nAnything that is written in ESM but that you want accessible via CJS should have a bridge.\r\nHowever, the convention _(naming of entry files and all that)_ is up to you though.\r\n"}}
{"actor":{"display_login":"jdalton"}}