From b522bfe822ab482ded78325ff541e0ed81f37324 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Thu, 9 Jul 2015 21:25:06 +0100 Subject: [PATCH] update babel/register to work with new option manager and add filename option type --- src/babel/api/register/node.js | 10 ++++------ src/babel/transformation/file/index.js | 12 ++---------- src/babel/transformation/file/options/config.json | 6 +++--- .../transformation/file/options/option-manager.js | 12 +++++++----- src/babel/transformation/file/options/parsers.js | 3 +++ 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/babel/api/register/node.js b/src/babel/api/register/node.js index 710b9b1152..00310feded 100644 --- a/src/babel/api/register/node.js +++ b/src/babel/api/register/node.js @@ -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}`; diff --git a/src/babel/transformation/file/index.js b/src/babel/transformation/file/index.js index 3aee64ded9..38cdeb4b5a 100644 --- a/src/babel/transformation/file/index.js +++ b/src/babel/transformation/file/index.js @@ -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 diff --git a/src/babel/transformation/file/options/config.json b/src/babel/transformation/file/options/config.json index b22f409bce..ad38102420 100644 --- a/src/babel/transformation/file/options/config.json +++ b/src/babel/transformation/file/options/config.json @@ -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" }, diff --git a/src/babel/transformation/file/options/option-manager.js b/src/babel/transformation/file/options/option-manager.js index e2fdfe58de..487b0320e3 100644 --- a/src/babel/transformation/file/options/option-manager.js +++ b/src/babel/transformation/file/options/option-manager.js @@ -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) { diff --git a/src/babel/transformation/file/options/parsers.js b/src/babel/transformation/file/options/parsers.js index eda258c6c6..951a51bdc2 100644 --- a/src/babel/transformation/file/options/parsers.js +++ b/src/babel/transformation/file/options/parsers.js @@ -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; }