diff --git a/packages/babel-core/README.md b/packages/babel-core/README.md index a176d469a5..719f1c856a 100644 --- a/packages/babel-core/README.md +++ b/packages/babel-core/README.md @@ -111,7 +111,6 @@ Following is a table of the options you can use: | `plugins` | `[]` | List of [plugins](https://babeljs.io/docs/plugins/) to load and use | | `presets` | `[]` | List of [presets](https://babeljs.io/docs/plugins/#presets) (a set of plugins) to load and use | | `retainLines` | `false` | Retain line numbers. This will lead to wacky code but is handy for scenarios where you can't use source maps. (**NOTE:** This will not retain the columns) | -| `resolveModuleSource` | `null` | Resolve a module source ie. `import "SOURCE";` to a custom value. Called as `resolveModuleSource(source, filename)` | | `shouldPrintComment` | `null` | An optional callback that controls whether a comment should be output or not. Called as `shouldPrintComment(commentContents)`. **NOTE:** This overrides the `comment` option when used | | `sourceFileName` | `(filenameRelative)` | Set `sources[0]` on returned source map | | `sourceMaps` | `false` | If truthy, adds a `map` property to returned output. If set to `"inline"`, a comment with a sourceMappingURL directive is added to the bottom of the returned code. If set to `"both"` then a `map` property is returned as well as a source map comment appended. **This does not emit sourcemap files by itself!** To have sourcemaps emitted using the CLI, you must pass it the `--source-maps` option | diff --git a/packages/babel-core/src/config/option-manager.js b/packages/babel-core/src/config/option-manager.js index 6bd6757080..ab614ac93d 100644 --- a/packages/babel-core/src/config/option-manager.js +++ b/packages/babel-core/src/config/option-manager.js @@ -57,7 +57,6 @@ const optionNames = new Set([ "sourceType", "auxiliaryCommentBefore", "auxiliaryCommentAfter", - "resolveModuleSource", "getModuleId", "moduleRoot", "moduleIds", @@ -450,9 +449,10 @@ function normalizeOptions(config) { // check for an unknown option if (!optionNames.has(key)) { if (removed[key]) { + const { message, version = 5 } = removed[key]; + throw new ReferenceError( - `Using removed Babel 5 option: ${alias}.${key} - ${removed[key] - .message}`, + `Using removed Babel ${version} option: ${alias}.${key} - ${message}`, ); } else { // eslint-disable-next-line max-len diff --git a/packages/babel-core/src/config/removed.js b/packages/babel-core/src/config/removed.js index 751209e8e6..8d441c5fee 100644 --- a/packages/babel-core/src/config/removed.js +++ b/packages/babel-core/src/config/removed.js @@ -56,4 +56,9 @@ export default { whitelist: { message: "Put the specific transforms you want in the `plugins` option", }, + + resolveModuleSource: { + version: 6, + message: "Use `babel-plugin-module-resolver@3`'s 'resolvePath' options", + }, }; diff --git a/packages/babel-core/src/transformation/file/index.js b/packages/babel-core/src/transformation/file/index.js index f8b833d910..e9dccd5a2a 100644 --- a/packages/babel-core/src/transformation/file/index.js +++ b/packages/babel-core/src/transformation/file/index.js @@ -166,11 +166,9 @@ export default class File { } } + // TODO: Remove this before 7.x's official release. Leaving it in for now to + // prevent unnecessary breakage between beta versions. resolveModuleSource(source: string): string { - const resolveModuleSource = this.opts.resolveModuleSource; - if (resolveModuleSource) { - source = resolveModuleSource(source, this.opts.filename); - } return source; } diff --git a/packages/babel-core/test/api.js b/packages/babel-core/test/api.js index 3ca191eb44..e703d87140 100644 --- a/packages/babel-core/test/api.js +++ b/packages/babel-core/test/api.js @@ -484,26 +484,6 @@ describe("api", function() { }); }), - transformAsync('import localName from "./array";', { - resolveModuleSource: function() { - return "override-source"; - }, - }).then(function(result) { - assert.deepEqual(result.metadata.modules.imports, [ - { - source: "override-source", - imported: ["default"], - specifiers: [ - { - kind: "named", - imported: "default", - local: "localName", - }, - ], - }, - ]); - }), - transformAsync('export * as externalName1 from "external";', { plugins: [require("../../babel-plugin-syntax-export-extensions")], }).then(function(result) { @@ -748,23 +728,6 @@ describe("api", function() { }); }); - it("resolveModuleSource option", function() { - /* eslint-disable max-len */ - const actual = - 'import foo from "foo-import-default";\nimport "foo-import-bare";\nexport { foo } from "foo-export-named";'; - const expected = - 'import foo from "resolved/foo-import-default";\nimport "resolved/foo-import-bare";\nexport { foo } from "resolved/foo-export-named";'; - /* eslint-enable max-len */ - - return transformAsync(actual, { - resolveModuleSource: function(originalSource) { - return "resolved/" + originalSource; - }, - }).then(function(result) { - assert.equal(result.code.trim(), expected); - }); - }); - describe("buildExternalHelpers", function() { describe("smoke tests", function() { it("builds external helpers in global output type", function() { diff --git a/packages/babel-helper-module-imports/src/import-builder.js b/packages/babel-helper-module-imports/src/import-builder.js index bbde6fdef9..0eda1c8663 100644 --- a/packages/babel-helper-module-imports/src/import-builder.js +++ b/packages/babel-helper-module-imports/src/import-builder.js @@ -26,21 +26,17 @@ export default class ImportBuilder { } import() { - const importedSource = this._file.resolveModuleSource(this._importedSource); - this._statements.push( - t.importDeclaration([], t.stringLiteral(importedSource)), + t.importDeclaration([], t.stringLiteral(this._importedSource)), ); return this; } require() { - const importedSource = this._file.resolveModuleSource(this._importedSource); - this._statements.push( t.expressionStatement( t.callExpression(t.identifier("require"), [ - t.stringLiteral(importedSource), + t.stringLiteral(this._importedSource), ]), ), );