update babel/register to work with new option manager and add filename option type

This commit is contained in:
Sebastian McKenzie 2015-07-09 21:25:06 +01:00
parent 9efb02f60f
commit b522bfe822
5 changed files with 19 additions and 24 deletions

View File

@ -1,6 +1,6 @@
import sourceMapSupport from "source-map-support";
import * as registerCache from "./cache";
import resolveRc from "../../transformation/file/options/resolve-rc";
import OptionManager from "../../transformation/file/options/option-manager";
import extend from "lodash/object/extend";
import * as babel from "../node";
import each from "lodash/collection/each";
@ -51,11 +51,9 @@ var mtime = function (filename) {
var compile = function (filename, opts = {}) {
var result;
opts = extend(opts, transformOpts);
// this will be done when the file is transformed anyway but we need all
// the options so we can generate the cache key
resolveRc(filename, opts);
var optsManager = new OptionManager;
optsManager.mergeOptions(transformOpts);
opts = optsManager.init(opts);
var cacheKey = `${filename}:${JSON.stringify(opts)}:${babel.version}`;

View File

@ -87,7 +87,7 @@ export default class File {
"instanceof",
// legacy
"interop-require",
"interop-require"
];
static soloHelpers = [];
@ -99,12 +99,6 @@ export default class File {
opts.sourceMaps = true;
}
// normalize windows path separators to unix
opts.filename = slash(opts.filename);
if (opts.sourceRoot) {
opts.sourceRoot = slash(opts.sourceRoot);
}
if (opts.moduleId) {
opts.moduleIds = true;
}
@ -113,9 +107,7 @@ export default class File {
opts.ignore = util.arrayify(opts.ignore, util.regexify);
if (opts.only) {
opts.only = util.arrayify(opts.only, util.regexify);
}
if (opts.only) opts.only = util.arrayify(opts.only, util.regexify);
defaults(opts, {
moduleRoot: opts.sourceRoot

View File

@ -1,6 +1,6 @@
{
"filename": {
"type": "string",
"type": "filename",
"description": "filename to use when reading from stdin - this will be used in source-maps, errors etc",
"default": "unknown",
"shorthand": "f"
@ -236,12 +236,12 @@
},
"sourceRoot": {
"type": "string",
"type": "filename",
"description": "the root from which all sources are relative"
},
"moduleRoot": {
"type": "string",
"type": "filename",
"description": "optional prefix for the AMD module formatter that will be prepend to the filename on module definitions"
},

View File

@ -1,12 +1,12 @@
import stripJsonComments from "strip-json-comments";
import { validateOption, normaliseOptions } from "./index";
import stripJsonComments from "strip-json-comments";
import isAbsolute from "path-is-absolute";
import pathExists from "path-exists";
import clone from "lodash/lang/clone";
import merge from "../../../helpers/merge";
import config from "./config";
import path from "path";
import fs from "fs";
import pathExists from "path-exists";
var existsCache = {};
var jsonCache = {};
@ -70,7 +70,7 @@ export default class OptionManager {
* Description
*/
mergeOptions(opts, alias) {
mergeOptions(opts, alias = "foreign") {
if (!opts) return;
for (let key in opts) {
@ -123,12 +123,14 @@ export default class OptionManager {
if (!val && option.optional) continue;
// deprecated
if (val && option.deprecated) {
if (this.log && val && option.deprecated) {
this.log.deprecate(`Deprecated option ${key}: ${option.deprecated}`);
}
// validate
if (val) val = validateOption(key, val, this.pipeline);
if (this.pipeline && val) {
val = validateOption(key, val, this.pipeline);
}
// aaliases
if (option.alias) {

View File

@ -1,3 +1,4 @@
import slash from "slash";
import * as util from "../../../util";
export function transformerList(val) {
@ -16,6 +17,8 @@ export function number(val) {
return +val;
}
export var filename = slash;
export function boolean(val) {
return !!val;
}