{"action":"created","comment":{"url":"https://api.github.com/repos/nodejs/node-eps/pulls/comments/78016009","id":78016009,"diff_hunk":"@@ -0,0 +1,175 @@\n+| Title  | ESM Interoperability |\n+|--------|-----------------------------|\n+| Author | @bmeck                      |\n+| Status | DRAFT                       |\n+| Date   | 2016-08-26                  |\n+\n+**NOTE:** `DRAFT` status does not mean ESM will be implemented in Node\n+core. Instead that this is the standard, should Node core decide to implement\n+ESM. At which time this draft would be moved to `ACCEPTED`.\n+\n+---\n+\n+Abbreviations:\n+* `ESM` - Ecma262 Modules (ES Modules)\n+* `NCJS` - Node Modules (a CommonJS variant)\n+* `NM2` - Node v2.0 Modules (Node Modules using the Module parse goal)\n+* `RMR` - Reflective Module Record (`ModuleRecord` type)\n+\n+The intent of this standard is to:\n+\n+* implement interoperability for the Module Parse Goal and Node's existing\n+module system\n+\n+## 1. Purpose\n+\n+1. Allow Node.js modules to use \"Module Mode\" without hitting the Reflective\n+Module Record.\n+  - The Reflective Module Record is described below as the `ModuleRecord` type.\n+2. Allow Node.js modules to use \"Module Mode\" without using Async Module Resolution.\n+\n+### 1.1. Avoidance of the Reflective Module Record\n+\n+Note: The RMR is only a collection of direct pointers in a JIT'd environment.\n+\n+The RMR poses several interoperability and tooling problems:\n+\n+1. Importing from NCJS has no support for Named Imports.\n+  - All core modules must stay as NCJS for the forseeable future due to interoperability constraints.\n+  - As such, all core modules can only have a default export under the RMR.\n+  - e.g. no `import { readfile } from 'fs';`\n+2. Inspecting the RMR is impossible\n+  - Hooks to inspect only pointers is not possible.\n+  - This renders APMs, tracing tools, test mocking tools, etc, impossible.\n+3. Wrapping the RMR is impossible.\n+  - Wrapping only pointers is not possible.\n+  - Most tooling vendors use this approach in current NCJS due to a lack of hooks.\n+  - This, however, is not an option under the RMR.\n+4. Conditional imports & exports are impossible.\n+  - (The RMR must be constructed at parse time.)\n+  - This renders writing Native Modules in ESM impossible.\n+\n+### 1.2. Avoidance of Async Module Resolution\n+\n+1. Allows modules to both use Module Mode and be `require()`'d as usual.\n+  - Prevents any further interop issues related to timing.\n+  - Allows existing modules to transition to NM2 while dependants can continue using NCJS to require them without any changes.\n+\n+## 2. Related\n+\n+[ECMA262](tc39.github.io/ecma262/) discusses the syntax and semantics of\n+related syntax, and introduces:\n+\n+### 2.1. Types\n+\n+* **[ModuleRecord]\n+(https://tc39.github.io/ecma262/#sec-abstract-module-records)**\n+    - Defines the list of imports via `[[ImportEntry]]`.\n+    - Defines the list of exports via `[[ExportEntry]]`.\n+\n+* **[ModuleNamespace]\n+(https://tc39.github.io/ecma262/#sec-module-namespace-objects)**\n+    - Represents a read-only static set of bindings to a module's exports.\n+\n+### 2.2. Operations\n+\n+* **[ParseModule](https://tc39.github.io/ecma262/#sec-parsemodule)**\n+    - Creates a [SourceTextModuleRecord]\n+    (https://tc39.github.io/ecma262/#sec-source-text-module-records) from\n+    source code.\n+\n+* **[HostResolveImportedModule]\n+(https://tc39.github.io/ecma262/#sec-hostresolveimportedmodule)**\n+    - A hook for when an import is exactly performed. This returns a\n+      `ModuleRecord`. Used as a means to grab modules from Node's loader/cache.\n+\n+* **[ModuleNamespaceCreate]\n+(https://tc39.github.io/ecma262/#sec-modulenamespacecreate)**\n+    - Provides a means of creating a list of exports manually, used so that\n+      NCJS `module.exports` can create `ModuleRecord`s that are\n+      prepopulated.\n+\n+## 3. Semantics\n+\n+### 3.1. Determining if source is an ES Module\n+\n+A new file type will be used for Node v2.0 Modules, `.mjs`. Files with this extension\n+will be treated using the loading semantics in this document, but retain a way\n+to load existing extensions of `.json`, `.node`, and `.js`. The file type for\n+JavaScript with IANA as an official file type needs to have this extensions\n+added. This comes from browsers being unable to implement a new MIME for the\n+differing parse goals. In order to make this change, contact the IESG.\n+\n+The `.mjs` file extension will be searched for prior to any `.js` file in any\n+algorithm that uses searching (`require`); e.g. once the Node\n+resolution algorithm reaches file expansion, `path + '.mjs'` would be searched\n+prior to `path + '.js'` when performing `require(path)`.\n+\n+# 3.1.1. Inter package loading using file extension breakage.\n+\n+There is knowledge of breakage for code that upgrades inner package\n+dependencies such as `require('foo/bar.js')`. As `bar.js` may move to\n+`bar.mjs`. Since `bar.js` is not the listed entry point this was considered\n+acceptable.\n+\n+### 3.2. Importing Modules in NM2\n+\n+Node v2.0 Modules do not implement `import` and `export`.","path":"002-es-modules.md","position":117,"original_position":117,"commit_id":"4099338da4a76508cb83131e33856c478a2468cd","original_commit_id":"4099338da4a76508cb83131e33856c478a2468cd","user":{"login":"bmeck","id":234659,"avatar_url":"https://avatars.githubusercontent.com/u/234659?v=3","gravatar_id":"","url":"https://api.github.com/users/bmeck","html_url":"https://github.com/bmeck","followers_url":"https://api.github.com/users/bmeck/followers","following_url":"https://api.github.com/users/bmeck/following{/other_user}","gists_url":"https://api.github.com/users/bmeck/gists{/gist_id}","starred_url":"https://api.github.com/users/bmeck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bmeck/subscriptions","organizations_url":"https://api.github.com/users/bmeck/orgs","repos_url":"https://api.github.com/users/bmeck/repos","events_url":"https://api.github.com/users/bmeck/events{/privacy}","received_events_url":"https://api.github.com/users/bmeck/received_events","type":"User","site_admin":false},"body":"node could also special case those in `require()` and defer to an intermediate internal module to grab the values pretty easily.","created_at":"2016-09-08T14:24:19Z","updated_at":"2016-09-08T14:24:19Z","html_url":"https://github.com/nodejs/node-eps/pull/43#discussion_r78016009","pull_request_url":"https://api.github.com/repos/nodejs/node-eps/pulls/43","_links":{"self":{"href":"https://api.github.com/repos/nodejs/node-eps/pulls/comments/78016009"},"html":{"href":"https://github.com/nodejs/node-eps/pull/43#discussion_r78016009"},"pull_request":{"href":"https://api.github.com/repos/nodejs/node-eps/pulls/43"}}},"pull_request":{"url":"https://api.github.com/repos/nodejs/node-eps/pulls/43","id":84398908,"html_url":"https://github.com/nodejs/node-eps/pull/43","diff_url":"https://github.com/nodejs/node-eps/pull/43.diff","patch_url":"https://github.com/nodejs/node-eps/pull/43.patch","issue_url":"https://api.github.com/repos/nodejs/node-eps/issues/43","number":43,"state":"open","locked":false,"title":"Node v2.0 modules","user":{"login":"Fishrock123","id":1093990,"avatar_url":"https://avatars.githubusercontent.com/u/1093990?v=3","gravatar_id":"","url":"https://api.github.com/users/Fishrock123","html_url":"https://github.com/Fishrock123","followers_url":"https://api.github.com/users/Fishrock123/followers","following_url":"https://api.github.com/users/Fishrock123/following{/other_user}","gists_url":"https://api.github.com/users/Fishrock123/gists{/gist_id}","starred_url":"https://api.github.com/users/Fishrock123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fishrock123/subscriptions","organizations_url":"https://api.github.com/users/Fishrock123/orgs","repos_url":"https://api.github.com/users/Fishrock123/repos","events_url":"https://api.github.com/users/Fishrock123/events{/privacy}","received_events_url":"https://api.github.com/users/Fishrock123/received_events","type":"User","site_admin":false},"body":"My, possibly transitional, \"counter-proposal\" to https://github.com/nodejs/node-eps/pull/39.\r\n\r\nMostly hashed out, some details may be missing as this style of thing is not my forte.\r\nThis is what is roughly described in a recent meeting with other CTC members.\r\n\r\nIt is driven by an interest of our existing ecosystem, to maintain as much compatibility with everyone's existing hard work as possible, while allowing newer functionality to be used without major consequence.\r\n\r\nLike many other things in node core, it is a compromise. A compromise from idealism to better suit the reality of our platform.\r\n\r\ncc @bmeck, @ljharb, @nodejs/ctc i guess\r\n\r\n_Dear lord I hope this doesn't gather a ton of hate._\r\n\r\nEdit: this is rebased on #39 for some language simplicity reasons. I can probably merge those directly into his commit though.\r\n\r\n--\r\n\r\n[**Rendered**](https://github.com/Fishrock123/node-eps/blob/4099338da4a76508cb83131e33856c478a2468cd/002-es-modules.md)","created_at":"2016-09-08T01:01:40Z","updated_at":"2016-09-08T14:24:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8e0d615ca6c9679ad3a1b5408ecdf5c9a73216cf","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/nodejs/node-eps/pulls/43/commits","review_comments_url":"https://api.github.com/repos/nodejs/node-eps/pulls/43/comments","review_comment_url":"https://api.github.com/repos/nodejs/node-eps/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nodejs/node-eps/issues/43/comments","statuses_url":"https://api.github.com/repos/nodejs/node-eps/statuses/4099338da4a76508cb83131e33856c478a2468cd","head":{"label":"Fishrock123:node-v2.0-modules","ref":"node-v2.0-modules","sha":"4099338da4a76508cb83131e33856c478a2468cd","user":{"login":"Fishrock123","id":1093990,"avatar_url":"https://avatars.githubusercontent.com/u/1093990?v=3","gravatar_id":"","url":"https://api.github.com/users/Fishrock123","html_url":"https://github.com/Fishrock123","followers_url":"https://api.github.com/users/Fishrock123/followers","following_url":"https://api.github.com/users/Fishrock123/following{/other_user}","gists_url":"https://api.github.com/users/Fishrock123/gists{/gist_id}","starred_url":"https://api.github.com/users/Fishrock123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fishrock123/subscriptions","organizations_url":"https://api.github.com/users/Fishrock123/orgs","repos_url":"https://api.github.com/users/Fishrock123/repos","events_url":"https://api.github.com/users/Fishrock123/events{/privacy}","received_events_url":"https://api.github.com/users/Fishrock123/received_events","type":"User","site_admin":false},"repo":{"id":67655045,"name":"node-eps","full_name":"Fishrock123/node-eps","owner":{"login":"Fishrock123","id":1093990,"avatar_url":"https://avatars.githubusercontent.com/u/1093990?v=3","gravatar_id":"","url":"https://api.github.com/users/Fishrock123","html_url":"https://github.com/Fishrock123","followers_url":"https://api.github.com/users/Fishrock123/followers","following_url":"https://api.github.com/users/Fishrock123/following{/other_user}","gists_url":"https://api.github.com/users/Fishrock123/gists{/gist_id}","starred_url":"https://api.github.com/users/Fishrock123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fishrock123/subscriptions","organizations_url":"https://api.github.com/users/Fishrock123/orgs","repos_url":"https://api.github.com/users/Fishrock123/repos","events_url":"https://api.github.com/users/Fishrock123/events{/privacy}","received_events_url":"https://api.github.com/users/Fishrock123/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Fishrock123/node-eps","description":"Node.js Enhancement Proposals for discussion on future API additions/changes to Node core","fork":true,"url":"https://api.github.com/repos/Fishrock123/node-eps","forks_url":"https://api.github.com/repos/Fishrock123/node-eps/forks","keys_url":"https://api.github.com/repos/Fishrock123/node-eps/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Fishrock123/node-eps/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Fishrock123/node-eps/teams","hooks_url":"https://api.github.com/repos/Fishrock123/node-eps/hooks","issue_events_url":"https://api.github.com/repos/Fishrock123/node-eps/issues/events{/number}","events_url":"https://api.github.com/repos/Fishrock123/node-eps/events","assignees_url":"https://api.github.com/repos/Fishrock123/node-eps/assignees{/user}","branches_url":"https://api.github.com/repos/Fishrock123/node-eps/branches{/branch}","tags_url":"https://api.github.com/repos/Fishrock123/node-eps/tags","blobs_url":"https://api.github.com/repos/Fishrock123/node-eps/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Fishrock123/node-eps/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Fishrock123/node-eps/git/refs{/sha}","trees_url":"https://api.github.com/repos/Fishrock123/node-eps/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Fishrock123/node-eps/statuses/{sha}","languages_url":"https://api.github.com/repos/Fishrock123/node-eps/languages","stargazers_url":"https://api.github.com/repos/Fishrock123/node-eps/stargazers","contributors_url":"https://api.github.com/repos/Fishrock123/node-eps/contributors","subscribers_url":"https://api.github.com/repos/Fishrock123/node-eps/subscribers","subscription_url":"https://api.github.com/repos/Fishrock123/node-eps/subscription","commits_url":"https://api.github.com/repos/Fishrock123/node-eps/commits{/sha}","git_commits_url":"https://api.github.com/repos/Fishrock123/node-eps/git/commits{/sha}","comments_url":"https://api.github.com/repos/Fishrock123/node-eps/comments{/number}","issue_comment_url":"https://api.github.com/repos/Fishrock123/node-eps/issues/comments{/number}","contents_url":"https://api.github.com/repos/Fishrock123/node-eps/contents/{+path}","compare_url":"https://api.github.com/repos/Fishrock123/node-eps/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Fishrock123/node-eps/merges","archive_url":"https://api.github.com/repos/Fishrock123/node-eps/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Fishrock123/node-eps/downloads","issues_url":"https://api.github.com/repos/Fishrock123/node-eps/issues{/number}","pulls_url":"https://api.github.com/repos/Fishrock123/node-eps/pulls{/number}","milestones_url":"https://api.github.com/repos/Fishrock123/node-eps/milestones{/number}","notifications_url":"https://api.github.com/repos/Fishrock123/node-eps/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Fishrock123/node-eps/labels{/name}","releases_url":"https://api.github.com/repos/Fishrock123/node-eps/releases{/id}","deployments_url":"https://api.github.com/repos/Fishrock123/node-eps/deployments","created_at":"2016-09-08T00:55:04Z","updated_at":"2016-09-07T22:56:30Z","pushed_at":"2016-09-08T00:55:49Z","git_url":"git://github.com/Fishrock123/node-eps.git","ssh_url":"git@github.com:Fishrock123/node-eps.git","clone_url":"https://github.com/Fishrock123/node-eps.git","svn_url":"https://github.com/Fishrock123/node-eps","homepage":null,"size":63,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"nodejs:master","ref":"master","sha":"f16f7707ba2814bd545e4fced9c5a7d5a5d828de","user":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"repo":{"id":48204104,"name":"node-eps","full_name":"nodejs/node-eps","owner":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nodejs/node-eps","description":"Node.js Enhancement Proposals for discussion on future API additions/changes to Node core","fork":false,"url":"https://api.github.com/repos/nodejs/node-eps","forks_url":"https://api.github.com/repos/nodejs/node-eps/forks","keys_url":"https://api.github.com/repos/nodejs/node-eps/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nodejs/node-eps/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nodejs/node-eps/teams","hooks_url":"https://api.github.com/repos/nodejs/node-eps/hooks","issue_events_url":"https://api.github.com/repos/nodejs/node-eps/issues/events{/number}","events_url":"https://api.github.com/repos/nodejs/node-eps/events","assignees_url":"https://api.github.com/repos/nodejs/node-eps/assignees{/user}","branches_url":"https://api.github.com/repos/nodejs/node-eps/branches{/branch}","tags_url":"https://api.github.com/repos/nodejs/node-eps/tags","blobs_url":"https://api.github.com/repos/nodejs/node-eps/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nodejs/node-eps/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nodejs/node-eps/git/refs{/sha}","trees_url":"https://api.github.com/repos/nodejs/node-eps/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nodejs/node-eps/statuses/{sha}","languages_url":"https://api.github.com/repos/nodejs/node-eps/languages","stargazers_url":"https://api.github.com/repos/nodejs/node-eps/stargazers","contributors_url":"https://api.github.com/repos/nodejs/node-eps/contributors","subscribers_url":"https://api.github.com/repos/nodejs/node-eps/subscribers","subscription_url":"https://api.github.com/repos/nodejs/node-eps/subscription","commits_url":"https://api.github.com/repos/nodejs/node-eps/commits{/sha}","git_commits_url":"https://api.github.com/repos/nodejs/node-eps/git/commits{/sha}","comments_url":"https://api.github.com/repos/nodejs/node-eps/comments{/number}","issue_comment_url":"https://api.github.com/repos/nodejs/node-eps/issues/comments{/number}","contents_url":"https://api.github.com/repos/nodejs/node-eps/contents/{+path}","compare_url":"https://api.github.com/repos/nodejs/node-eps/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nodejs/node-eps/merges","archive_url":"https://api.github.com/repos/nodejs/node-eps/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nodejs/node-eps/downloads","issues_url":"https://api.github.com/repos/nodejs/node-eps/issues{/number}","pulls_url":"https://api.github.com/repos/nodejs/node-eps/pulls{/number}","milestones_url":"https://api.github.com/repos/nodejs/node-eps/milestones{/number}","notifications_url":"https://api.github.com/repos/nodejs/node-eps/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nodejs/node-eps/labels{/name}","releases_url":"https://api.github.com/repos/nodejs/node-eps/releases{/id}","deployments_url":"https://api.github.com/repos/nodejs/node-eps/deployments","created_at":"2015-12-17T23:39:07Z","updated_at":"2016-09-07T22:56:30Z","pushed_at":"2016-09-08T06:21:44Z","git_url":"git://github.com/nodejs/node-eps.git","ssh_url":"git@github.com:nodejs/node-eps.git","clone_url":"https://github.com/nodejs/node-eps.git","svn_url":"https://github.com/nodejs/node-eps","homepage":null,"size":167,"stargazers_count":163,"watchers_count":163,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":26,"mirror_url":null,"open_issues_count":22,"forks":26,"open_issues":22,"watchers":163,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nodejs/node-eps/pulls/43"},"html":{"href":"https://github.com/nodejs/node-eps/pull/43"},"issue":{"href":"https://api.github.com/repos/nodejs/node-eps/issues/43"},"comments":{"href":"https://api.github.com/repos/nodejs/node-eps/issues/43/comments"},"review_comments":{"href":"https://api.github.com/repos/nodejs/node-eps/pulls/43/comments"},"review_comment":{"href":"https://api.github.com/repos/nodejs/node-eps/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nodejs/node-eps/pulls/43/commits"},"statuses":{"href":"https://api.github.com/repos/nodejs/node-eps/statuses/4099338da4a76508cb83131e33856c478a2468cd"}}}}
{"actor":{"display_login":"bmeck"}}