{"action":"created","comment":{"url":"https://api.github.com/repos/babel/babel/pulls/comments/172027710","pull_request_review_id":100985906,"id":172027710,"diff_hunk":"@@ -0,0 +1,118 @@\n+// @flow\n+\n+import path from \"path\";\n+import Plugin from \"./plugin\";\n+import { mergeOptions } from \"./util\";\n+import { createItemFromDescriptor } from \"./item\";\n+import { buildRootChain, type ConfigContext } from \"./config-chain\";\n+import { getEnv } from \"./helpers/environment\";\n+import { validate, type ValidatedOptions } from \"./validation/options\";\n+\n+import type { ConfigFile, IgnoreFile } from \"./files\";\n+\n+export default function loadPrivatePartialConfig(\n+  inputOpts: mixed,\n+): {\n+  options: ValidatedOptions,\n+  context: ConfigContext,\n+  ignore: IgnoreFile | void,\n+  babelrc: ConfigFile | void,\n+} | null {\n+  if (\n+    inputOpts != null &&\n+    (typeof inputOpts !== \"object\" || Array.isArray(inputOpts))\n+  ) {\n+    throw new Error(\"Babel options must be an object, null, or undefined\");\n+  }\n+\n+  const args = inputOpts ? validate(\"arguments\", inputOpts) : {};\n+\n+  const { envName = getEnv(), cwd = \".\" } = args;\n+  const absoluteCwd = path.resolve(cwd);\n+\n+  const context: ConfigContext = {\n+    filename: args.filename ? path.resolve(cwd, args.filename) : null,\n+    cwd: absoluteCwd,\n+    envName,\n+  };\n+\n+  const configChain = buildRootChain(args, context);\n+  if (!configChain) return null;\n+\n+  const options = {};\n+  configChain.options.forEach(opts => {\n+    mergeOptions(options, opts);\n+  });\n+\n+  // Tack the passes onto the object itself so that, if this object is\n+  // passed back to Babel a second time, it will be in the right structure\n+  // to not change behavior.\n+  options.babelrc = false;\n+  options.envName = envName;\n+  options.cwd = absoluteCwd;\n+  options.passPerPreset = false;\n+\n+  options.plugins = configChain.plugins.map(descriptor =>\n+    createItemFromDescriptor(descriptor),\n+  );\n+  options.presets = configChain.presets.map(descriptor =>\n+    createItemFromDescriptor(descriptor),\n+  );\n+\n+  return {\n+    options,\n+    context,\n+    ignore: configChain.ignore,\n+    babelrc: configChain.babelrc,\n+  };\n+}\n+\n+export function loadPartialConfig(inputOpts: mixed): PartialConfig | null {\n+  const result = loadPrivatePartialConfig(inputOpts);\n+  if (!result) return null;\n+\n+  const { options, babelrc, ignore } = result;\n+\n+  (options.plugins || []).forEach(item => {\n+    if (item.value instanceof Plugin) {\n+      throw new Error(\n+        \"Passing cached plugin instances is not supported in \" +\n+          \"babel.loadPartialConfig()\",\n+      );\n+    }\n+  });\n+\n+  return new PartialConfig(\n+    options,\n+    babelrc ? babelrc.filepath : undefined,\n+    ignore ? ignore.filepath : undefined,\n+  );\n+}\n+\n+export type { PartialConfig };\n+\n+class PartialConfig {","path":"packages/babel-core/src/config/partial.js","position":94,"original_position":94,"commit_id":"e69413a357d47e1ea57763a17c7d270bea138605","original_commit_id":"e69413a357d47e1ea57763a17c7d270bea138605","user":{"login":"loganfsmyth","id":132260,"avatar_url":"https://avatars1.githubusercontent.com/u/132260?v=4","gravatar_id":"","url":"https://api.github.com/users/loganfsmyth","html_url":"https://github.com/loganfsmyth","followers_url":"https://api.github.com/users/loganfsmyth/followers","following_url":"https://api.github.com/users/loganfsmyth/following{/other_user}","gists_url":"https://api.github.com/users/loganfsmyth/gists{/gist_id}","starred_url":"https://api.github.com/users/loganfsmyth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/loganfsmyth/subscriptions","organizations_url":"https://api.github.com/users/loganfsmyth/orgs","repos_url":"https://api.github.com/users/loganfsmyth/repos","events_url":"https://api.github.com/users/loganfsmyth/events{/privacy}","received_events_url":"https://api.github.com/users/loganfsmyth/received_events","type":"User","site_admin":false},"body":"For instance I thought we might want a `.hasUserConfig()` to do `this.babelrc !== undefined || this.babelConfig !== undefined` once we add the `babel.config.js` file.","created_at":"2018-03-03T20:27:45Z","updated_at":"2018-03-03T20:27:45Z","html_url":"https://github.com/babel/babel/pull/7472#discussion_r172027710","pull_request_url":"https://api.github.com/repos/babel/babel/pulls/7472","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/babel/babel/pulls/comments/172027710"},"html":{"href":"https://github.com/babel/babel/pull/7472#discussion_r172027710"},"pull_request":{"href":"https://api.github.com/repos/babel/babel/pulls/7472"}},"in_reply_to_id":172015470},"pull_request":{"url":"https://api.github.com/repos/babel/babel/pulls/7472","id":172646618,"html_url":"https://github.com/babel/babel/pull/7472","diff_url":"https://github.com/babel/babel/pull/7472.diff","patch_url":"https://github.com/babel/babel/pull/7472.patch","issue_url":"https://api.github.com/repos/babel/babel/issues/7472","number":7472,"state":"open","locked":false,"title":"Expose the partial Babel config for callers to load and mutate.","user":{"login":"loganfsmyth","id":132260,"avatar_url":"https://avatars1.githubusercontent.com/u/132260?v=4","gravatar_id":"","url":"https://api.github.com/users/loganfsmyth","html_url":"https://github.com/loganfsmyth","followers_url":"https://api.github.com/users/loganfsmyth/followers","following_url":"https://api.github.com/users/loganfsmyth/following{/other_user}","gists_url":"https://api.github.com/users/loganfsmyth/gists{/gist_id}","starred_url":"https://api.github.com/users/loganfsmyth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/loganfsmyth/subscriptions","organizations_url":"https://api.github.com/users/loganfsmyth/orgs","repos_url":"https://api.github.com/users/loganfsmyth/repos","events_url":"https://api.github.com/users/loganfsmyth/events{/privacy}","received_events_url":"https://api.github.com/users/loganfsmyth/received_events","type":"User","site_admin":false},"body":"| Q                        | A <!--(Can use an emoji 👍) -->\r\n| ------------------------ | ---\r\n| Fixed Issues?            | Not necessarily fixes, but related to #5541\r\n| Patch: Bug Fix?          | N\r\n| Major: Breaking Change?  | N\r\n| Minor: New Feature?      | Y\r\n| Tests Added + Pass?      | Yes\r\n| Documentation PR         | <!-- If so, add `[skip ci]` to your commit message to skip CI -->\r\n| Any Dependency Changes?  |\r\n| License                  | MIT\r\n\r\nThis PR exposes `.loadPartialConfig` as a way to load the Babel configuration up to the point where the plugins and presets are all known, but have not yet loaded. It also exposes the path of the `.babelrc` and `.babelignore` files that Babel found, since a lot of tooling likes to toggle behavior based on whether the user has created a config file or not.\r\n\r\nThe goal of this PR is to expose enough of Babel's config that we can avoid tooling feeling like they have to implement it themselves. I think this achieves that, but if there are cases where that isn't the case I'd love to hear them.\r\n\r\nSee the README in this PR for more information, but the core of this PR is that it exposes a new first-class instance type `ConfigItem` that is allowed in `plugins` and `presets` lists, and the results of `.loadPartialConfig` ensures that each plugin and preset is a `ConfigItem`. From the README:\r\n\r\nEach `ConfigItem` exposes all of the information Babel knows. The fields are:\r\n \r\n* `value: {} | Function` - The resolved value of the plugin.\r\n* `options: {} | void` - The options object passed to the plugin.\r\n* `dirname: string` - The path that the options are relative to.\r\n* `name: string | void` - The name that the user gave the plugin instance, e.g. `plugins: [ ['env', {}, 'my-env'] ]` \r\n* `file: Object | void` - Information about the plugin's file, if Babel knows it.\r\n  * `request: string` - The file that the user requested, e.g. `\"@babel/env\"`\r\n  * `resolved: string` - The full path of the resolved file, e.g. `\"/tmp/node_modules/@babel/preset-env/lib/index.js\"`\r\n \r\nBeyond that, tooling can manipulate the config however they'd like before passing the config back off to Babel again.","created_at":"2018-03-03T03:02:04Z","updated_at":"2018-03-03T20:27:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3d0243da805398daa769757a07490abf083bbd43","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":311566482,"url":"https://api.github.com/repos/babel/babel/labels/PR:%20New%20Feature%20:rocket:","name":"PR: New Feature :rocket:","color":"fbca04","default":false}],"milestone":{"url":"https://api.github.com/repos/babel/babel/milestones/14","html_url":"https://github.com/babel/babel/milestone/14","labels_url":"https://api.github.com/repos/babel/babel/milestones/14/labels","id":2660920,"number":14,"title":"Babel 7.next","description":"","creator":{"login":"existentialism","id":56288,"avatar_url":"https://avatars3.githubusercontent.com/u/56288?v=4","gravatar_id":"","url":"https://api.github.com/users/existentialism","html_url":"https://github.com/existentialism","followers_url":"https://api.github.com/users/existentialism/followers","following_url":"https://api.github.com/users/existentialism/following{/other_user}","gists_url":"https://api.github.com/users/existentialism/gists{/gist_id}","starred_url":"https://api.github.com/users/existentialism/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/existentialism/subscriptions","organizations_url":"https://api.github.com/users/existentialism/orgs","repos_url":"https://api.github.com/users/existentialism/repos","events_url":"https://api.github.com/users/existentialism/events{/privacy}","received_events_url":"https://api.github.com/users/existentialism/received_events","type":"User","site_admin":false},"open_issues":17,"closed_issues":15,"state":"open","created_at":"2017-07-25T14:34:14Z","updated_at":"2018-03-03T03:02:14Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/babel/babel/pulls/7472/commits","review_comments_url":"https://api.github.com/repos/babel/babel/pulls/7472/comments","review_comment_url":"https://api.github.com/repos/babel/babel/pulls/comments{/number}","comments_url":"https://api.github.com/repos/babel/babel/issues/7472/comments","statuses_url":"https://api.github.com/repos/babel/babel/statuses/e69413a357d47e1ea57763a17c7d270bea138605","head":{"label":"loganfsmyth:expose-partial-config","ref":"expose-partial-config","sha":"e69413a357d47e1ea57763a17c7d270bea138605","user":{"login":"loganfsmyth","id":132260,"avatar_url":"https://avatars1.githubusercontent.com/u/132260?v=4","gravatar_id":"","url":"https://api.github.com/users/loganfsmyth","html_url":"https://github.com/loganfsmyth","followers_url":"https://api.github.com/users/loganfsmyth/followers","following_url":"https://api.github.com/users/loganfsmyth/following{/other_user}","gists_url":"https://api.github.com/users/loganfsmyth/gists{/gist_id}","starred_url":"https://api.github.com/users/loganfsmyth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/loganfsmyth/subscriptions","organizations_url":"https://api.github.com/users/loganfsmyth/orgs","repos_url":"https://api.github.com/users/loganfsmyth/repos","events_url":"https://api.github.com/users/loganfsmyth/events{/privacy}","received_events_url":"https://api.github.com/users/loganfsmyth/received_events","type":"User","site_admin":false},"repo":{"id":34920245,"name":"babel","full_name":"loganfsmyth/babel","owner":{"login":"loganfsmyth","id":132260,"avatar_url":"https://avatars1.githubusercontent.com/u/132260?v=4","gravatar_id":"","url":"https://api.github.com/users/loganfsmyth","html_url":"https://github.com/loganfsmyth","followers_url":"https://api.github.com/users/loganfsmyth/followers","following_url":"https://api.github.com/users/loganfsmyth/following{/other_user}","gists_url":"https://api.github.com/users/loganfsmyth/gists{/gist_id}","starred_url":"https://api.github.com/users/loganfsmyth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/loganfsmyth/subscriptions","organizations_url":"https://api.github.com/users/loganfsmyth/orgs","repos_url":"https://api.github.com/users/loganfsmyth/repos","events_url":"https://api.github.com/users/loganfsmyth/events{/privacy}","received_events_url":"https://api.github.com/users/loganfsmyth/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/loganfsmyth/babel","description":"Babel is a compiler for writing next generation JavaScript.","fork":true,"url":"https://api.github.com/repos/loganfsmyth/babel","forks_url":"https://api.github.com/repos/loganfsmyth/babel/forks","keys_url":"https://api.github.com/repos/loganfsmyth/babel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/loganfsmyth/babel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/loganfsmyth/babel/teams","hooks_url":"https://api.github.com/repos/loganfsmyth/babel/hooks","issue_events_url":"https://api.github.com/repos/loganfsmyth/babel/issues/events{/number}","events_url":"https://api.github.com/repos/loganfsmyth/babel/events","assignees_url":"https://api.github.com/repos/loganfsmyth/babel/assignees{/user}","branches_url":"https://api.github.com/repos/loganfsmyth/babel/branches{/branch}","tags_url":"https://api.github.com/repos/loganfsmyth/babel/tags","blobs_url":"https://api.github.com/repos/loganfsmyth/babel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/loganfsmyth/babel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/loganfsmyth/babel/git/refs{/sha}","trees_url":"https://api.github.com/repos/loganfsmyth/babel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/loganfsmyth/babel/statuses/{sha}","languages_url":"https://api.github.com/repos/loganfsmyth/babel/languages","stargazers_url":"https://api.github.com/repos/loganfsmyth/babel/stargazers","contributors_url":"https://api.github.com/repos/loganfsmyth/babel/contributors","subscribers_url":"https://api.github.com/repos/loganfsmyth/babel/subscribers","subscription_url":"https://api.github.com/repos/loganfsmyth/babel/subscription","commits_url":"https://api.github.com/repos/loganfsmyth/babel/commits{/sha}","git_commits_url":"https://api.github.com/repos/loganfsmyth/babel/git/commits{/sha}","comments_url":"https://api.github.com/repos/loganfsmyth/babel/comments{/number}","issue_comment_url":"https://api.github.com/repos/loganfsmyth/babel/issues/comments{/number}","contents_url":"https://api.github.com/repos/loganfsmyth/babel/contents/{+path}","compare_url":"https://api.github.com/repos/loganfsmyth/babel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/loganfsmyth/babel/merges","archive_url":"https://api.github.com/repos/loganfsmyth/babel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/loganfsmyth/babel/downloads","issues_url":"https://api.github.com/repos/loganfsmyth/babel/issues{/number}","pulls_url":"https://api.github.com/repos/loganfsmyth/babel/pulls{/number}","milestones_url":"https://api.github.com/repos/loganfsmyth/babel/milestones{/number}","notifications_url":"https://api.github.com/repos/loganfsmyth/babel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/loganfsmyth/babel/labels{/name}","releases_url":"https://api.github.com/repos/loganfsmyth/babel/releases{/id}","deployments_url":"https://api.github.com/repos/loganfsmyth/babel/deployments","created_at":"2015-05-01T19:33:26Z","updated_at":"2015-05-01T19:33:28Z","pushed_at":"2018-03-03T02:58:31Z","git_url":"git://github.com/loganfsmyth/babel.git","ssh_url":"git@github.com:loganfsmyth/babel.git","clone_url":"https://github.com/loganfsmyth/babel.git","svn_url":"https://github.com/loganfsmyth/babel","homepage":"https://babeljs.io/","size":31095,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"babel:master","ref":"master","sha":"fdfbd9a6f787f13f1674e9b6836b94413e632470","user":{"login":"babel","id":9637642,"avatar_url":"https://avatars1.githubusercontent.com/u/9637642?v=4","gravatar_id":"","url":"https://api.github.com/users/babel","html_url":"https://github.com/babel","followers_url":"https://api.github.com/users/babel/followers","following_url":"https://api.github.com/users/babel/following{/other_user}","gists_url":"https://api.github.com/users/babel/gists{/gist_id}","starred_url":"https://api.github.com/users/babel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/babel/subscriptions","organizations_url":"https://api.github.com/users/babel/orgs","repos_url":"https://api.github.com/users/babel/repos","events_url":"https://api.github.com/users/babel/events{/privacy}","received_events_url":"https://api.github.com/users/babel/received_events","type":"Organization","site_admin":false},"repo":{"id":24560307,"name":"babel","full_name":"babel/babel","owner":{"login":"babel","id":9637642,"avatar_url":"https://avatars1.githubusercontent.com/u/9637642?v=4","gravatar_id":"","url":"https://api.github.com/users/babel","html_url":"https://github.com/babel","followers_url":"https://api.github.com/users/babel/followers","following_url":"https://api.github.com/users/babel/following{/other_user}","gists_url":"https://api.github.com/users/babel/gists{/gist_id}","starred_url":"https://api.github.com/users/babel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/babel/subscriptions","organizations_url":"https://api.github.com/users/babel/orgs","repos_url":"https://api.github.com/users/babel/repos","events_url":"https://api.github.com/users/babel/events{/privacy}","received_events_url":"https://api.github.com/users/babel/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/babel/babel","description":":tropical_fish: Babel is a compiler for writing next generation JavaScript.","fork":false,"url":"https://api.github.com/repos/babel/babel","forks_url":"https://api.github.com/repos/babel/babel/forks","keys_url":"https://api.github.com/repos/babel/babel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/babel/babel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/babel/babel/teams","hooks_url":"https://api.github.com/repos/babel/babel/hooks","issue_events_url":"https://api.github.com/repos/babel/babel/issues/events{/number}","events_url":"https://api.github.com/repos/babel/babel/events","assignees_url":"https://api.github.com/repos/babel/babel/assignees{/user}","branches_url":"https://api.github.com/repos/babel/babel/branches{/branch}","tags_url":"https://api.github.com/repos/babel/babel/tags","blobs_url":"https://api.github.com/repos/babel/babel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/babel/babel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/babel/babel/git/refs{/sha}","trees_url":"https://api.github.com/repos/babel/babel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/babel/babel/statuses/{sha}","languages_url":"https://api.github.com/repos/babel/babel/languages","stargazers_url":"https://api.github.com/repos/babel/babel/stargazers","contributors_url":"https://api.github.com/repos/babel/babel/contributors","subscribers_url":"https://api.github.com/repos/babel/babel/subscribers","subscription_url":"https://api.github.com/repos/babel/babel/subscription","commits_url":"https://api.github.com/repos/babel/babel/commits{/sha}","git_commits_url":"https://api.github.com/repos/babel/babel/git/commits{/sha}","comments_url":"https://api.github.com/repos/babel/babel/comments{/number}","issue_comment_url":"https://api.github.com/repos/babel/babel/issues/comments{/number}","contents_url":"https://api.github.com/repos/babel/babel/contents/{+path}","compare_url":"https://api.github.com/repos/babel/babel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/babel/babel/merges","archive_url":"https://api.github.com/repos/babel/babel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/babel/babel/downloads","issues_url":"https://api.github.com/repos/babel/babel/issues{/number}","pulls_url":"https://api.github.com/repos/babel/babel/pulls{/number}","milestones_url":"https://api.github.com/repos/babel/babel/milestones{/number}","notifications_url":"https://api.github.com/repos/babel/babel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/babel/babel/labels{/name}","releases_url":"https://api.github.com/repos/babel/babel/releases{/id}","deployments_url":"https://api.github.com/repos/babel/babel/deployments","created_at":"2014-09-28T13:38:23Z","updated_at":"2018-03-03T20:24:57Z","pushed_at":"2018-03-03T17:45:40Z","git_url":"git://github.com/babel/babel.git","ssh_url":"git@github.com:babel/babel.git","clone_url":"https://github.com/babel/babel.git","svn_url":"https://github.com/babel/babel","homepage":"https://babeljs.io/","size":30781,"stargazers_count":26191,"watchers_count":26191,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2515,"mirror_url":null,"archived":false,"open_issues_count":618,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":2515,"open_issues":618,"watchers":26191,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/babel/babel/pulls/7472"},"html":{"href":"https://github.com/babel/babel/pull/7472"},"issue":{"href":"https://api.github.com/repos/babel/babel/issues/7472"},"comments":{"href":"https://api.github.com/repos/babel/babel/issues/7472/comments"},"review_comments":{"href":"https://api.github.com/repos/babel/babel/pulls/7472/comments"},"review_comment":{"href":"https://api.github.com/repos/babel/babel/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/babel/babel/pulls/7472/commits"},"statuses":{"href":"https://api.github.com/repos/babel/babel/statuses/e69413a357d47e1ea57763a17c7d270bea138605"}},"author_association":"OWNER"}}
{"actor":{"display_login":"loganfsmyth"}}