{"action":"closed","issue":{"url":"https://api.github.com/repos/babel/babel/issues/6885","repository_url":"https://api.github.com/repos/babel/babel","labels_url":"https://api.github.com/repos/babel/babel/issues/6885/labels{/name}","comments_url":"https://api.github.com/repos/babel/babel/issues/6885/comments","events_url":"https://api.github.com/repos/babel/babel/issues/6885/events","html_url":"https://github.com/babel/babel/issues/6885","id":276317127,"number":6885,"title":"transformFile generates incorrect AMD ids","user":{"login":"nico29","id":3858041,"avatar_url":"https://avatars2.githubusercontent.com/u/3858041?v=4","gravatar_id":"","url":"https://api.github.com/users/nico29","html_url":"https://github.com/nico29","followers_url":"https://api.github.com/users/nico29/followers","following_url":"https://api.github.com/users/nico29/following{/other_user}","gists_url":"https://api.github.com/users/nico29/gists{/gist_id}","starred_url":"https://api.github.com/users/nico29/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nico29/subscriptions","organizations_url":"https://api.github.com/users/nico29/orgs","repos_url":"https://api.github.com/users/nico29/repos","events_url":"https://api.github.com/users/nico29/events{/privacy}","received_events_url":"https://api.github.com/users/nico29/received_events","type":"User","site_admin":false},"labels":[{"id":438612746,"url":"https://api.github.com/repos/babel/babel/labels/good%20first%20issue","name":"good first issue","color":"bfdadc","default":true},{"id":441915610,"url":"https://api.github.com/repos/babel/babel/labels/help%20wanted","name":"help wanted","color":"bfdadc","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-11-23T09:58:52Z","updated_at":"2017-11-25T18:13:57Z","closed_at":"2017-11-25T18:13:57Z","author_association":"NONE","body":"I am not sure the following behavior is intended or not, hence this issue is more a question than a bug report. \r\n\r\nWhen using babel-core `transformFile` to perform async code conversion from es modules to AMD modules (with the `babel-plugin-transform-es2015-modules-amd` plugin), the generated AMD module ID is incorrect.\r\nLet's take the following exemple:\r\n\r\n### Input Code\r\n\r\n```js\r\nconst { promisify } = require('util');\r\nconst babel = require('babel-core');\r\nconst transformFile = promisify(babel.transformFile);\r\n\r\nconst config = {\r\n    presets: 'env',\r\n    plugins: ['transform-es2015-modules-amd'],\r\n    moduleRoot: 'ROOT',\r\n    moduleIds: true,\r\n    getModuleId (moduleName) {\r\n        return moduleName;\r\n    }\r\n};\r\n\r\nasync function transpile () {\r\n    const files = [\r\n        './src/a.js',\r\n        './src/b.js',\r\n        './src/c.js'\r\n    ]\r\n    return Promise.all(files.map(async file => {\r\n        let { code } = await transformFile(file, config);\r\n        console.log(code);\r\n        return Promise.resolve(code);\r\n    }));\r\n}\r\ntranspile();\r\n```\r\n\r\n### Current Behavior\r\n\r\nThe previous code outputs : \r\n\r\n```js\r\ndefine(\"ROOT/./src/c\", [], function () {\r\n  \"use strict\";\r\n});\r\ndefine(\"ROOT/./src/c\", [], function () {\r\n  \"use strict\";\r\n});\r\ndefine(\"ROOT/./src/c\", [], function () {\r\n  \"use strict\";\r\n});\r\n```\r\n\r\n### Expected Behavior\r\n\r\nwhere you would expect it to be:\r\n\r\n```js\r\ndefine(\"ROOT/./src/a\", [], function () {\r\n  \"use strict\";\r\n});\r\ndefine(\"ROOT/./src/b\", [], function () {\r\n  \"use strict\";\r\n});\r\ndefine(\"ROOT/./src/c\", [], function () {\r\n  \"use strict\";\r\n});\r\n```\r\n\r\n### Possible Solution\r\n\r\nI've found that `transformFile` stores the file name inside the configuration object by modifying the reference of the user provided object.\r\nSince this bit is done synchronously the configuration object will have the last file name (in our case './src/c.js'.\r\n\r\nI would like to know if the \"cloning\" of the config is to be done by the user or by `transformFile`: that is to say turn my code from what is was to something like:\r\n\r\n```js\r\nasync function transpile () {\r\n    const files = [\r\n        './src/a.js',\r\n        './src/b.js',\r\n        './src/c.js'\r\n    ]\r\n    return Promise.all(files.map(async file => {\r\n        let { code } = await transformFile(file, {...config});\r\n        console.log(code);\r\n        return Promise.resolve(code);\r\n    }));\r\n}\r\n```\r\n\r\nor turn [this line](https://github.com/babel/babel/blob/master/packages/babel-core/src/transform-file.js#L21) into something like `let options = Object.assign({}, opts, { filename })`. `options` being used to keep the user provided object intact.\r\n\r\n### Your Environment\r\n<!--- Include as many relevant details about the environment you experienced the bug in -->\r\n\r\n| software         | version(s)\r\n| ---------------- | -------\r\n| Babel            |  6.26.0\r\n| Babylon          | <!-- This is only needed if you are using Babylon directly -->\r\n| node             | 8.9.1\r\n| npm              | 5.5.1\r\n| Operating System | MacOS 10.12.6\r\n\r\nThank you 😸 \r\n"}}
{"actor":{"display_login":"loganfsmyth"}}