Remove the sourceMapTarget option from core and implement it in babel-cli. (#7500)
This commit is contained in:
parent
0389035e15
commit
b5e6536f26
@ -28,7 +28,6 @@ export default function(commander, filenames, opts) {
|
||||
defaults(
|
||||
{
|
||||
sourceFileName: slash(path.relative(dest + "/..", src)),
|
||||
sourceMapTarget: path.basename(relative),
|
||||
},
|
||||
opts,
|
||||
),
|
||||
@ -44,6 +43,7 @@ export default function(commander, filenames, opts) {
|
||||
) {
|
||||
const mapLoc = dest + ".map";
|
||||
res.code = util.addSourceMappingUrl(res.code, mapLoc);
|
||||
res.map.file = path.basename(relative);
|
||||
outputFileSync(mapLoc, JSON.stringify(res.map));
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,10 @@ export default function(commander, filenames, opts) {
|
||||
|
||||
const buildResult = function() {
|
||||
const map = new sourceMap.SourceMapGenerator({
|
||||
file: path.basename(commander.outFile || "") || "stdout",
|
||||
file:
|
||||
commander.sourceMapTarget ||
|
||||
path.basename(commander.outFile || "") ||
|
||||
"stdout",
|
||||
sourceRoot: opts.sourceRoot,
|
||||
});
|
||||
|
||||
|
||||
@ -259,6 +259,7 @@ delete opts.configFile;
|
||||
delete opts.deleteDirOnStart;
|
||||
delete opts.keepFileExtension;
|
||||
delete opts.relative;
|
||||
delete opts.sourceMapTarget;
|
||||
|
||||
// Commander will default the "--no-" arguments to true, but we want to leave them undefined so that
|
||||
// @babel/core can handle the default-assignment logic on its own.
|
||||
|
||||
@ -7,4 +7,4 @@ function _classCallCheck(instance, Constructor) { if (!_instanceof(instance, Con
|
||||
var Test = function Test() {
|
||||
_classCallCheck(this, Test);
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXIvYmFyLmpzIl0sIm5hbWVzIjpbIlRlc3QiXSwibWFwcGluZ3MiOiI7Ozs7OztJQUFNQSxJIiwiZmlsZSI6ImJhci5qcyIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIFRlc3Qge1xuXG59Il19
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXIvYmFyLmpzIl0sIm5hbWVzIjpbIlRlc3QiXSwibWFwcGluZ3MiOiI7Ozs7OztJQUFNQSxJIiwic291cmNlc0NvbnRlbnQiOlsiY2xhc3MgVGVzdCB7XG5cbn0iXX0=
|
||||
|
||||
@ -3,4 +3,4 @@
|
||||
arr.map(function (x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwibmFtZXMiOlsiYXJyIiwibWFwIiwieCIsIk1VTFRJUExJRVIiXSwibWFwcGluZ3MiOiI7O0FBQUFBLElBQUlDLEdBQUosQ0FBUTtBQUFBLFNBQUtDLElBQUlDLFVBQVQ7QUFBQSxDQUFSIiwiZmlsZSI6ImZvby5qcyIsInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogTVVMVElQTElFUik7Il19
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwibmFtZXMiOlsiYXJyIiwibWFwIiwieCIsIk1VTFRJUExJRVIiXSwibWFwcGluZ3MiOiI7O0FBQUFBLElBQUlDLEdBQUosQ0FBUTtBQUFBLFNBQUtDLElBQUlDLFVBQVQ7QUFBQSxDQUFSIiwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXX0=
|
||||
|
||||
@ -1 +1 @@
|
||||
{"version":3,"sources":["../../src/bar/bar.js"],"names":["Test"],"mappings":";;;;;;IAAMA,I","file":"bar.js","sourcesContent":["class Test {\n\n}"]}
|
||||
{"version":3,"sources":["../../src/bar/bar.js"],"names":["Test"],"mappings":";;;;;;IAAMA,I","sourcesContent":["class Test {\n\n}"],"file":"bar.js"}
|
||||
|
||||
@ -1 +1 @@
|
||||
{"version":3,"sources":["../src/foo.js"],"names":["arr","map","x","MULTIPLIER"],"mappings":";;AAAAA,IAAIC,GAAJ,CAAQ;AAAA,SAAKC,IAAIC,UAAT;AAAA,CAAR","file":"foo.js","sourcesContent":["arr.map(x => x * MULTIPLIER);"]}
|
||||
{"version":3,"sources":["../src/foo.js"],"names":["arr","map","x","MULTIPLIER"],"mappings":";;AAAAA,IAAIC,GAAJ,CAAQ;AAAA,SAAKC,IAAIC,UAAT;AAAA,CAAR","sourcesContent":["arr.map(x => x * MULTIPLIER);"],"file":"foo.js"}
|
||||
|
||||
@ -242,7 +242,6 @@ Following is a table of the options you can use:
|
||||
| `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 |
|
||||
| `sourceMapTarget` | `(filenameRelative)` | Set `file` on returned source map |
|
||||
| `sourceRoot` | `(moduleRoot)` | The root from which all sources are relative |
|
||||
| `sourceType` | `"module"` | Indicate the mode the code should be parsed in. Can be one of "script", "module", or "unambiguous". `"unambiguous"` will make Babel attempt to _guess_, based on the presence of ES6 `import` or `export` statements. Files with ES6 `import`s and `export`s are considered `"module"` and are otherwise `"script"`. |
|
||||
| `wrapPluginVisitorMethod`| `null` | An optional callback that can be used to wrap visitor methods. **NOTE:** This is useful for things like introspection, and not really needed for implementing anything. Called as `wrapPluginVisitorMethod(pluginAlias, visitorType, callback)`.
|
||||
|
||||
@ -119,9 +119,6 @@ const COMMON_VALIDATORS: ValidatorSet = {
|
||||
sourceMap: (assertSourceMaps: Validator<
|
||||
$PropertyType<ValidatedOptions, "sourceMap">,
|
||||
>),
|
||||
sourceMapTarget: (assertString: Validator<
|
||||
$PropertyType<ValidatedOptions, "sourceMapTarget">,
|
||||
>),
|
||||
sourceFileName: (assertString: Validator<
|
||||
$PropertyType<ValidatedOptions, "sourceFileName">,
|
||||
>),
|
||||
@ -192,7 +189,6 @@ export type ValidatedOptions = {
|
||||
// Sourcemap generation options.
|
||||
sourceMaps?: SourceMapsOption,
|
||||
sourceMap?: SourceMapsOption,
|
||||
sourceMapTarget?: string,
|
||||
sourceFileName?: string,
|
||||
sourceRoot?: string,
|
||||
|
||||
|
||||
@ -44,7 +44,8 @@ export default {
|
||||
message: "Put the specific transforms you want in the `plugins` option",
|
||||
},
|
||||
sourceMapName: {
|
||||
message: "Use the `sourceMapTarget` option",
|
||||
message:
|
||||
"The `sourceMapName` option has been removed because it makes more sense for the tooling that calls Babel to assign `map.file` themselves.",
|
||||
},
|
||||
stage: {
|
||||
message:
|
||||
@ -64,4 +65,10 @@ export default {
|
||||
message:
|
||||
"Generated plugin metadata is always included in the output result",
|
||||
},
|
||||
|
||||
sourceMapTarget: {
|
||||
version: 6,
|
||||
message:
|
||||
"The `sourceMapTarget` option has been removed because it makes more sense for the tooling that calls Babel to assign `map.file` themselves.",
|
||||
},
|
||||
};
|
||||
|
||||
@ -15,7 +15,6 @@ export default function normalizeOptions(config: ResolvedConfig): {} {
|
||||
sourceRoot = moduleRoot,
|
||||
|
||||
sourceFileName = filenameRelative,
|
||||
sourceMapTarget = filenameRelative,
|
||||
|
||||
comments = true,
|
||||
compact = "auto",
|
||||
@ -47,7 +46,6 @@ export default function normalizeOptions(config: ResolvedConfig): {} {
|
||||
|
||||
// Source-map generation flags.
|
||||
sourceMaps,
|
||||
sourceMapTarget,
|
||||
sourceRoot,
|
||||
sourceFileName,
|
||||
},
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
{
|
||||
"version": 3,
|
||||
"file": "source-maps/full/output.js",
|
||||
"sources": ["source-maps/full/input.js"],
|
||||
"names": [
|
||||
"arr",
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
arr.map(function (x) {
|
||||
return x * x;
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNvdXJjZS1tYXBzL2lubGluZS9pbnB1dC5qcyJdLCJuYW1lcyI6WyJhcnIiLCJtYXAiLCJ4Il0sIm1hcHBpbmdzIjoiQUFBQUEsSUFBSUMsR0FBSixDQUFRO0FBQUEsU0FBS0MsSUFBSUEsQ0FBVDtBQUFBLENBQVIiLCJmaWxlIjoic291cmNlLW1hcHMvaW5saW5lL291dHB1dC5qcyIsInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogeCk7Il19
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNvdXJjZS1tYXBzL2lubGluZS9pbnB1dC5qcyJdLCJuYW1lcyI6WyJhcnIiLCJtYXAiLCJ4Il0sIm1hcHBpbmdzIjoiQUFBQUEsSUFBSUMsR0FBSixDQUFRO0FBQUEsU0FBS0MsSUFBSUEsQ0FBVDtBQUFBLENBQVIiLCJzb3VyY2VzQ29udGVudCI6WyJhcnIubWFwKHggPT4geCAqIHgpOyJdfQ==
|
||||
|
||||
@ -43,7 +43,6 @@ Options for source maps:
|
||||
name | type | default | description
|
||||
-----------------------|----------|-----------------|--------------------------------------------------------------------------
|
||||
sourceMaps | boolean | `false` | Enable generating source maps
|
||||
sourceMapTarget | string | | The filename of the generated code that the source map will be associated with
|
||||
sourceRoot | string | | A root for all relative URLs in the source map
|
||||
sourceFileName | string | | The filename for the source code (i.e. the code in the `code` argument). This will only be used if `code` is a string.
|
||||
|
||||
|
||||
@ -19,7 +19,6 @@ export default class SourceMap {
|
||||
get() {
|
||||
if (!this._cachedMap) {
|
||||
const map = (this._cachedMap = new sourceMap.SourceMapGenerator({
|
||||
file: this._opts.sourceMapTarget,
|
||||
sourceRoot: this._opts.sourceRoot,
|
||||
}));
|
||||
|
||||
|
||||
@ -382,15 +382,7 @@ function run(task) {
|
||||
let actualCode = actual.code;
|
||||
const expectCode = expected.code;
|
||||
if (!execCode || actualCode) {
|
||||
result = babel.transform(
|
||||
actualCode,
|
||||
Object.assign(
|
||||
{
|
||||
sourceMapTarget: task.expect.filename,
|
||||
},
|
||||
getOpts(actual),
|
||||
),
|
||||
);
|
||||
result = babel.transform(actualCode, getOpts(actual));
|
||||
checkDuplicatedNodes(result.ast);
|
||||
if (
|
||||
!expected.code &&
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user