{"action":"created","comment":{"url":"https://api.github.com/repos/Polymer/polymer-build/pulls/comments/177638943","pull_request_review_id":107544953,"id":177638943,"diff_hunk":"@@ -102,52 +123,89 @@ export function htmlTransform(\n     }\n   }\n \n-  if (shouldTransformEsModuleToAmd) {\n-    // We need RequireJS to load the AMD modules we are declaring. Inject the\n-    // dependency as late as possible (just before the first module is\n-    // declared) because there may be some UMD dependencies that we want to\n-    // continue to load in global mode instead of AMD mode (which is detected\n-    // by the presence of the `require` global).\n-    if (firstModuleScript !== undefined && options.isEntryPoint) {\n-      const fragment = parse5.parseFragment(\n-          `<script src=\"${options.requireJsUrl}\"></script>\\n`);\n-      const requireJsScript = fragment.childNodes![0];\n+  if (shouldTransformEsModuleToAmd && finalModuleScript !== undefined) {\n+    // We've defined a bunch of modules and chained them together. Now we need\n+    // to initiate loading the chain by requiring the final one.\n+    const finalModuleName = generateModuleName(moduleScriptIdx - 1);\n+    const fragment = parse5.parseFragment(\n+        `<script>require(['${finalModuleName}']);</script>`);\n+    dom5.insertAfter(\n+        finalModuleScript.parentNode!, finalModuleScript, fragment);\n+  }\n+\n+  if (options.injectAmdLoader) {\n+    const fragment = parse5.parseFragment('<script></script>\\n');\n+    dom5.setTextContent(fragment.childNodes![0], getMinifiedRequireJs());\n+    const requireJsScript = fragment.childNodes![0];\n+\n+    // Inject as late as possible (just before the first module is declared, if\n+    // there is one) because there may be some UMD dependencies that we want to\n+    // continue to load in global mode instead of AMD mode (which is detected by\n+    // the presence of the `require` global).\n+    if (firstModuleScript !== undefined) {\n       dom5.insertBefore(\n           firstModuleScript.parentNode!, firstModuleScript, fragment);\n+    } else {\n+      // TODO(aomarks) If there were no modules, where do we put the AMD loader?","path":"src/html-transform.ts","position":157,"original_position":157,"commit_id":"20c6b1021d1cb48594eb8010ee3d4efe019d0ea0","original_commit_id":"20c6b1021d1cb48594eb8010ee3d4efe019d0ea0","user":{"login":"aomarks","id":48894,"avatar_url":"https://avatars0.githubusercontent.com/u/48894?v=4","gravatar_id":"","url":"https://api.github.com/users/aomarks","html_url":"https://github.com/aomarks","followers_url":"https://api.github.com/users/aomarks/followers","following_url":"https://api.github.com/users/aomarks/following{/other_user}","gists_url":"https://api.github.com/users/aomarks/gists{/gist_id}","starred_url":"https://api.github.com/users/aomarks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aomarks/subscriptions","organizations_url":"https://api.github.com/users/aomarks/orgs","repos_url":"https://api.github.com/users/aomarks/repos","events_url":"https://api.github.com/users/aomarks/events{/privacy}","received_events_url":"https://api.github.com/users/aomarks/received_events","type":"User","site_admin":false},"body":"I was thinking that you could be an entrypoint that has no modules of its own, but has an HTML import which uses modules...","created_at":"2018-03-28T05:00:29Z","updated_at":"2018-03-28T05:00:29Z","html_url":"https://github.com/Polymer/polymer-build/pull/334#discussion_r177638943","pull_request_url":"https://api.github.com/repos/Polymer/polymer-build/pulls/334","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/Polymer/polymer-build/pulls/comments/177638943"},"html":{"href":"https://github.com/Polymer/polymer-build/pull/334#discussion_r177638943"},"pull_request":{"href":"https://api.github.com/repos/Polymer/polymer-build/pulls/334"}},"in_reply_to_id":177638519},"pull_request":{"url":"https://api.github.com/repos/Polymer/polymer-build/pulls/334","id":177594687,"html_url":"https://github.com/Polymer/polymer-build/pull/334","diff_url":"https://github.com/Polymer/polymer-build/pull/334.diff","patch_url":"https://github.com/Polymer/polymer-build/pull/334.patch","issue_url":"https://api.github.com/repos/Polymer/polymer-build/issues/334","number":334,"state":"open","locked":false,"title":"Transform ES to AMD modules in build streams.","user":{"login":"aomarks","id":48894,"avatar_url":"https://avatars0.githubusercontent.com/u/48894?v=4","gravatar_id":"","url":"https://api.github.com/users/aomarks","html_url":"https://github.com/aomarks","followers_url":"https://api.github.com/users/aomarks/followers","following_url":"https://api.github.com/users/aomarks/following{/other_user}","gists_url":"https://api.github.com/users/aomarks/gists{/gist_id}","starred_url":"https://api.github.com/users/aomarks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aomarks/subscriptions","organizations_url":"https://api.github.com/users/aomarks/orgs","repos_url":"https://api.github.com/users/aomarks/repos","events_url":"https://api.github.com/users/aomarks/events{/privacy}","received_events_url":"https://api.github.com/users/aomarks/received_events","type":"User","site_admin":false},"body":"Fixes #269, but will need integration into CLI and a little more testing.\r\n\r\n- We now do ES to AMD module transformation from `getOptimizeStreams`. This was kind of tricky because of the `HtmlSplitter` flow. Previously, transformation of inline JS did not depend on any context from the document it came from. Now, it depends on the order that the script tag appeared in the document, because we maintain ordering of `type=module` scripts by generating an artificial AMD dependency chain.\r\n\r\n- We now inject an inline minified RequireJS AMD loader, instead of an external script. This is built by our gulpfile, exactly like the Babel helpers. This means that the `getOptimizeStreams` options now must provide the entrypoint path, in order for us to know where to inject it. (As an aside, I feel like the API/naming around \"optimize streams\" doesn't make a whole lot of sense anymore).\r\n\r\n- We now inject the Babel helpers from the `htmlTransform` function and `getOptimizeStreams`, whereas we used to use a separate transform step. This is some consolidation which eliminates redundant parsing. Maybe we should do the same with the ES5 adapter? Is this making our API better (less parsing, maybe simpler to understand) or worse (less modular, maybe harder to understand)? I don't know, but there it is.\r\n\r\n- The `htmlTransform` function now does minification, whereas it used to be a separate transformer. Again, just some consolidation.\r\n\r\n- The `htmlTransform` function now removes the phantom `<html>`, `<head>`, and `<body>` tags injected by parse5.\r\n\r\n - [x] CHANGELOG.md has been updated\r\n","created_at":"2018-03-26T23:29:30Z","updated_at":"2018-03-28T05:00:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ac3039f2e0656a907be6c6c5ce2093f8489821fd","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Polymer/polymer-build/pulls/334/commits","review_comments_url":"https://api.github.com/repos/Polymer/polymer-build/pulls/334/comments","review_comment_url":"https://api.github.com/repos/Polymer/polymer-build/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Polymer/polymer-build/issues/334/comments","statuses_url":"https://api.github.com/repos/Polymer/polymer-build/statuses/20c6b1021d1cb48594eb8010ee3d4efe019d0ea0","head":{"label":"Polymer:amd-streams","ref":"amd-streams","sha":"20c6b1021d1cb48594eb8010ee3d4efe019d0ea0","user":{"login":"Polymer","id":2159051,"avatar_url":"https://avatars3.githubusercontent.com/u/2159051?v=4","gravatar_id":"","url":"https://api.github.com/users/Polymer","html_url":"https://github.com/Polymer","followers_url":"https://api.github.com/users/Polymer/followers","following_url":"https://api.github.com/users/Polymer/following{/other_user}","gists_url":"https://api.github.com/users/Polymer/gists{/gist_id}","starred_url":"https://api.github.com/users/Polymer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Polymer/subscriptions","organizations_url":"https://api.github.com/users/Polymer/orgs","repos_url":"https://api.github.com/users/Polymer/repos","events_url":"https://api.github.com/users/Polymer/events{/privacy}","received_events_url":"https://api.github.com/users/Polymer/received_events","type":"Organization","site_admin":false},"repo":{"id":60874241,"name":"polymer-build","full_name":"Polymer/polymer-build","owner":{"login":"Polymer","id":2159051,"avatar_url":"https://avatars3.githubusercontent.com/u/2159051?v=4","gravatar_id":"","url":"https://api.github.com/users/Polymer","html_url":"https://github.com/Polymer","followers_url":"https://api.github.com/users/Polymer/followers","following_url":"https://api.github.com/users/Polymer/following{/other_user}","gists_url":"https://api.github.com/users/Polymer/gists{/gist_id}","starred_url":"https://api.github.com/users/Polymer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Polymer/subscriptions","organizations_url":"https://api.github.com/users/Polymer/orgs","repos_url":"https://api.github.com/users/Polymer/repos","events_url":"https://api.github.com/users/Polymer/events{/privacy}","received_events_url":"https://api.github.com/users/Polymer/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Polymer/polymer-build","description":"A library for building Polymer projects","fork":false,"url":"https://api.github.com/repos/Polymer/polymer-build","forks_url":"https://api.github.com/repos/Polymer/polymer-build/forks","keys_url":"https://api.github.com/repos/Polymer/polymer-build/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Polymer/polymer-build/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Polymer/polymer-build/teams","hooks_url":"https://api.github.com/repos/Polymer/polymer-build/hooks","issue_events_url":"https://api.github.com/repos/Polymer/polymer-build/issues/events{/number}","events_url":"https://api.github.com/repos/Polymer/polymer-build/events","assignees_url":"https://api.github.com/repos/Polymer/polymer-build/assignees{/user}","branches_url":"https://api.github.com/repos/Polymer/polymer-build/branches{/branch}","tags_url":"https://api.github.com/repos/Polymer/polymer-build/tags","blobs_url":"https://api.github.com/repos/Polymer/polymer-build/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Polymer/polymer-build/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Polymer/polymer-build/git/refs{/sha}","trees_url":"https://api.github.com/repos/Polymer/polymer-build/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Polymer/polymer-build/statuses/{sha}","languages_url":"https://api.github.com/repos/Polymer/polymer-build/languages","stargazers_url":"https://api.github.com/repos/Polymer/polymer-build/stargazers","contributors_url":"https://api.github.com/repos/Polymer/polymer-build/contributors","subscribers_url":"https://api.github.com/repos/Polymer/polymer-build/subscribers","subscription_url":"https://api.github.com/repos/Polymer/polymer-build/subscription","commits_url":"https://api.github.com/repos/Polymer/polymer-build/commits{/sha}","git_commits_url":"https://api.github.com/repos/Polymer/polymer-build/git/commits{/sha}","comments_url":"https://api.github.com/repos/Polymer/polymer-build/comments{/number}","issue_comment_url":"https://api.github.com/repos/Polymer/polymer-build/issues/comments{/number}","contents_url":"https://api.github.com/repos/Polymer/polymer-build/contents/{+path}","compare_url":"https://api.github.com/repos/Polymer/polymer-build/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Polymer/polymer-build/merges","archive_url":"https://api.github.com/repos/Polymer/polymer-build/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Polymer/polymer-build/downloads","issues_url":"https://api.github.com/repos/Polymer/polymer-build/issues{/number}","pulls_url":"https://api.github.com/repos/Polymer/polymer-build/pulls{/number}","milestones_url":"https://api.github.com/repos/Polymer/polymer-build/milestones{/number}","notifications_url":"https://api.github.com/repos/Polymer/polymer-build/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Polymer/polymer-build/labels{/name}","releases_url":"https://api.github.com/repos/Polymer/polymer-build/releases{/id}","deployments_url":"https://api.github.com/repos/Polymer/polymer-build/deployments","created_at":"2016-06-10T20:14:04Z","updated_at":"2018-03-26T23:56:20Z","pushed_at":"2018-03-28T04:27:57Z","git_url":"git://github.com/Polymer/polymer-build.git","ssh_url":"git@github.com:Polymer/polymer-build.git","clone_url":"https://github.com/Polymer/polymer-build.git","svn_url":"https://github.com/Polymer/polymer-build","homepage":"","size":20335,"stargazers_count":114,"watchers_count":114,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":43,"mirror_url":null,"archived":false,"open_issues_count":76,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":43,"open_issues":76,"watchers":114,"default_branch":"master"}},"base":{"label":"Polymer:master","ref":"master","sha":"eb47307a40d86aff75a2d86e413df25b3202125d","user":{"login":"Polymer","id":2159051,"avatar_url":"https://avatars3.githubusercontent.com/u/2159051?v=4","gravatar_id":"","url":"https://api.github.com/users/Polymer","html_url":"https://github.com/Polymer","followers_url":"https://api.github.com/users/Polymer/followers","following_url":"https://api.github.com/users/Polymer/following{/other_user}","gists_url":"https://api.github.com/users/Polymer/gists{/gist_id}","starred_url":"https://api.github.com/users/Polymer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Polymer/subscriptions","organizations_url":"https://api.github.com/users/Polymer/orgs","repos_url":"https://api.github.com/users/Polymer/repos","events_url":"https://api.github.com/users/Polymer/events{/privacy}","received_events_url":"https://api.github.com/users/Polymer/received_events","type":"Organization","site_admin":false},"repo":{"id":60874241,"name":"polymer-build","full_name":"Polymer/polymer-build","owner":{"login":"Polymer","id":2159051,"avatar_url":"https://avatars3.githubusercontent.com/u/2159051?v=4","gravatar_id":"","url":"https://api.github.com/users/Polymer","html_url":"https://github.com/Polymer","followers_url":"https://api.github.com/users/Polymer/followers","following_url":"https://api.github.com/users/Polymer/following{/other_user}","gists_url":"https://api.github.com/users/Polymer/gists{/gist_id}","starred_url":"https://api.github.com/users/Polymer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Polymer/subscriptions","organizations_url":"https://api.github.com/users/Polymer/orgs","repos_url":"https://api.github.com/users/Polymer/repos","events_url":"https://api.github.com/users/Polymer/events{/privacy}","received_events_url":"https://api.github.com/users/Polymer/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Polymer/polymer-build","description":"A library for building Polymer projects","fork":false,"url":"https://api.github.com/repos/Polymer/polymer-build","forks_url":"https://api.github.com/repos/Polymer/polymer-build/forks","keys_url":"https://api.github.com/repos/Polymer/polymer-build/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Polymer/polymer-build/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Polymer/polymer-build/teams","hooks_url":"https://api.github.com/repos/Polymer/polymer-build/hooks","issue_events_url":"https://api.github.com/repos/Polymer/polymer-build/issues/events{/number}","events_url":"https://api.github.com/repos/Polymer/polymer-build/events","assignees_url":"https://api.github.com/repos/Polymer/polymer-build/assignees{/user}","branches_url":"https://api.github.com/repos/Polymer/polymer-build/branches{/branch}","tags_url":"https://api.github.com/repos/Polymer/polymer-build/tags","blobs_url":"https://api.github.com/repos/Polymer/polymer-build/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Polymer/polymer-build/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Polymer/polymer-build/git/refs{/sha}","trees_url":"https://api.github.com/repos/Polymer/polymer-build/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Polymer/polymer-build/statuses/{sha}","languages_url":"https://api.github.com/repos/Polymer/polymer-build/languages","stargazers_url":"https://api.github.com/repos/Polymer/polymer-build/stargazers","contributors_url":"https://api.github.com/repos/Polymer/polymer-build/contributors","subscribers_url":"https://api.github.com/repos/Polymer/polymer-build/subscribers","subscription_url":"https://api.github.com/repos/Polymer/polymer-build/subscription","commits_url":"https://api.github.com/repos/Polymer/polymer-build/commits{/sha}","git_commits_url":"https://api.github.com/repos/Polymer/polymer-build/git/commits{/sha}","comments_url":"https://api.github.com/repos/Polymer/polymer-build/comments{/number}","issue_comment_url":"https://api.github.com/repos/Polymer/polymer-build/issues/comments{/number}","contents_url":"https://api.github.com/repos/Polymer/polymer-build/contents/{+path}","compare_url":"https://api.github.com/repos/Polymer/polymer-build/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Polymer/polymer-build/merges","archive_url":"https://api.github.com/repos/Polymer/polymer-build/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Polymer/polymer-build/downloads","issues_url":"https://api.github.com/repos/Polymer/polymer-build/issues{/number}","pulls_url":"https://api.github.com/repos/Polymer/polymer-build/pulls{/number}","milestones_url":"https://api.github.com/repos/Polymer/polymer-build/milestones{/number}","notifications_url":"https://api.github.com/repos/Polymer/polymer-build/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Polymer/polymer-build/labels{/name}","releases_url":"https://api.github.com/repos/Polymer/polymer-build/releases{/id}","deployments_url":"https://api.github.com/repos/Polymer/polymer-build/deployments","created_at":"2016-06-10T20:14:04Z","updated_at":"2018-03-26T23:56:20Z","pushed_at":"2018-03-28T04:27:57Z","git_url":"git://github.com/Polymer/polymer-build.git","ssh_url":"git@github.com:Polymer/polymer-build.git","clone_url":"https://github.com/Polymer/polymer-build.git","svn_url":"https://github.com/Polymer/polymer-build","homepage":"","size":20335,"stargazers_count":114,"watchers_count":114,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":43,"mirror_url":null,"archived":false,"open_issues_count":76,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":43,"open_issues":76,"watchers":114,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Polymer/polymer-build/pulls/334"},"html":{"href":"https://github.com/Polymer/polymer-build/pull/334"},"issue":{"href":"https://api.github.com/repos/Polymer/polymer-build/issues/334"},"comments":{"href":"https://api.github.com/repos/Polymer/polymer-build/issues/334/comments"},"review_comments":{"href":"https://api.github.com/repos/Polymer/polymer-build/pulls/334/comments"},"review_comment":{"href":"https://api.github.com/repos/Polymer/polymer-build/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Polymer/polymer-build/pulls/334/commits"},"statuses":{"href":"https://api.github.com/repos/Polymer/polymer-build/statuses/20c6b1021d1cb48594eb8010ee3d4efe019d0ea0"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"aomarks"}}