@babel/core
Advanced tools
Comparing version 7.0.0-beta.44 to 7.0.0-beta.45
@@ -95,25 +95,51 @@ "use strict"; | ||
if (!programmaticChain) return null; | ||
var ignore, babelrc; | ||
var _opts$root = opts.root, | ||
rootDir = _opts$root === void 0 ? "." : _opts$root, | ||
_opts$babelrc = opts.babelrc, | ||
babelrc = _opts$babelrc === void 0 ? true : _opts$babelrc, | ||
babelrcRoots = opts.babelrcRoots, | ||
_opts$configFile = opts.configFile, | ||
configFileName = _opts$configFile === void 0 ? true : _opts$configFile; | ||
var absoluteRoot = _path().default.resolve(context.cwd, rootDir); | ||
var configFile; | ||
if (typeof configFileName === "string") { | ||
configFile = (0, _files.loadConfig)(configFileName, context.cwd, context.envName); | ||
} else if (configFileName === true) { | ||
configFile = (0, _files.findRootConfig)(absoluteRoot, context.envName); | ||
} | ||
var configFileChain = emptyChain(); | ||
if (configFile) { | ||
var result = loadFileChain(configFile, context); | ||
if (!result) return null; | ||
mergeChain(configFileChain, result); | ||
} | ||
var pkgData = typeof context.filename === "string" ? (0, _files.findPackageData)(context.filename) : null; | ||
var ignoreFile, babelrcFile; | ||
var fileChain = emptyChain(); | ||
if (opts.babelrc !== false && context.filename !== null) { | ||
var _filename = context.filename; | ||
if (babelrc && pkgData && babelrcLoadEnabled(context, pkgData, babelrcRoots, absoluteRoot)) { | ||
var _findRelativeConfig = (0, _files.findRelativeConfig)(pkgData, context.envName); | ||
var _findRelativeConfig = (0, _files.findRelativeConfig)(_filename, context.envName); | ||
ignoreFile = _findRelativeConfig.ignore; | ||
babelrcFile = _findRelativeConfig.config; | ||
ignore = _findRelativeConfig.ignore; | ||
babelrc = _findRelativeConfig.config; | ||
if (ignore && shouldIgnore(context, ignore.ignore, null, ignore.dirname)) { | ||
if (ignoreFile && shouldIgnore(context, ignoreFile.ignore, null, ignoreFile.dirname)) { | ||
return null; | ||
} | ||
if (babelrc) { | ||
var result = loadFileChain(babelrc, context); | ||
if (!result) return null; | ||
mergeChain(fileChain, result); | ||
if (babelrcFile) { | ||
var _result = loadFileChain(babelrcFile, context); | ||
if (!_result) return null; | ||
mergeChain(fileChain, _result); | ||
} | ||
} | ||
var chain = mergeChain(mergeChain(emptyChain(), fileChain), programmaticChain); | ||
var chain = mergeChain(mergeChain(mergeChain(emptyChain(), configFileChain), fileChain), programmaticChain); | ||
return { | ||
@@ -125,7 +151,28 @@ plugins: dedupDescriptors(chain.plugins), | ||
}), | ||
ignore: ignore || undefined, | ||
babelrc: babelrc || undefined | ||
ignore: ignoreFile || undefined, | ||
babelrc: babelrcFile || undefined, | ||
config: configFile || undefined | ||
}; | ||
} | ||
function babelrcLoadEnabled(context, pkgData, babelrcRoots, absoluteRoot) { | ||
if (typeof babelrcRoots === "boolean") return babelrcRoots; | ||
if (babelrcRoots === undefined) { | ||
return pkgData.directories.indexOf(absoluteRoot) !== -1; | ||
} | ||
var babelrcPatterns = babelrcRoots; | ||
if (!Array.isArray(babelrcPatterns)) babelrcPatterns = [babelrcPatterns]; | ||
babelrcPatterns = babelrcPatterns.map(function (pat) { | ||
return _path().default.resolve(context.cwd, pat); | ||
}); | ||
if (babelrcPatterns.length === 1 && babelrcPatterns[0] === absoluteRoot) { | ||
return pkgData.directories.indexOf(absoluteRoot) !== -1; | ||
} | ||
return (0, _micromatch().default)(pkgData.directories, babelrcPatterns).length > 0; | ||
} | ||
var loadProgrammaticChain = makeChainWalker({ | ||
@@ -132,0 +179,0 @@ init: function init(arg) { |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.findRelativeConfig = findRelativeConfig; | ||
exports.findRootConfig = findRootConfig; | ||
exports.loadConfig = loadConfig; | ||
@@ -64,21 +65,32 @@ | ||
var _utils = require("./utils"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var debug = (0, _debug().default)("babel:config:loading:files:configuration"); | ||
var BABEL_CONFIG_JS_FILENAME = "babel.config.js"; | ||
var BABELRC_FILENAME = ".babelrc"; | ||
var BABELRC_JS_FILENAME = ".babelrc.js"; | ||
var PACKAGE_FILENAME = "package.json"; | ||
var BABELIGNORE_FILENAME = ".babelignore"; | ||
function findRelativeConfig(filepath, envName) { | ||
function findRelativeConfig(packageData, envName) { | ||
var config = null; | ||
var ignore = null; | ||
var dirname = _path().default.dirname(filepath); | ||
var dirname = _path().default.dirname(packageData.filepath); | ||
var loc = dirname; | ||
var _loop = function _loop() { | ||
if (_isArray) { | ||
if (_i >= _iterator.length) return "break"; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) return "break"; | ||
_ref = _i.value; | ||
} | ||
while (true) { | ||
var loc = _ref; | ||
if (!config) { | ||
config = [BABELRC_FILENAME, BABELRC_JS_FILENAME, PACKAGE_FILENAME].reduce(function (previousConfig, name) { | ||
config = [BABELRC_FILENAME, BABELRC_JS_FILENAME].reduce(function (previousConfig, name) { | ||
var filepath = _path().default.join(loc, name); | ||
@@ -94,3 +106,12 @@ | ||
}, null); | ||
var pkgConfig = packageData.pkg && packageData.pkg.dirname === loc ? packageToBabelConfig(packageData.pkg) : null; | ||
if (pkgConfig) { | ||
if (config) { | ||
throw new Error("Multiple configuration files found. Please remove one:\n" + (" - " + _path().default.basename(pkgConfig.filepath) + "#babel\n") + (" - " + _path().default.basename(config.filepath) + "\n") + ("from " + loc)); | ||
} | ||
config = pkgConfig; | ||
} | ||
if (config) { | ||
@@ -110,7 +131,10 @@ debug("Found configuration %o from %o.", config.filepath, dirname); | ||
} | ||
}; | ||
var nextLoc = _path().default.dirname(loc); | ||
for (var _iterator = packageData.directories, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (loc === nextLoc) break; | ||
loc = nextLoc; | ||
var _ret = _loop(); | ||
if (_ret === "break") break; | ||
} | ||
@@ -124,2 +148,14 @@ | ||
function findRootConfig(dirname, envName) { | ||
var filepath = _path().default.resolve(dirname, BABEL_CONFIG_JS_FILENAME); | ||
var conf = readConfig(filepath, envName); | ||
if (conf) { | ||
debug("Found root config %o in $o.", BABEL_CONFIG_JS_FILENAME, dirname); | ||
} | ||
return conf; | ||
} | ||
function loadConfig(name, dirname, envName) { | ||
@@ -143,3 +179,3 @@ var filepath = _resolve().default.sync(name, { | ||
envName: envName | ||
}) : readConfigFile(filepath); | ||
}) : readConfigJSON5(filepath); | ||
} | ||
@@ -198,25 +234,28 @@ | ||
}); | ||
var readConfigFile = makeStaticFileCache(function (filepath, content) { | ||
var options; | ||
var packageToBabelConfig = (0, _caching.makeWeakCache)(function (file) { | ||
if (typeof file.options.babel === "undefined") return null; | ||
var babel = file.options.babel; | ||
if (_path().default.basename(filepath) === PACKAGE_FILENAME) { | ||
try { | ||
options = JSON.parse(content).babel; | ||
} catch (err) { | ||
err.message = filepath + ": Error while parsing JSON - " + err.message; | ||
throw err; | ||
} | ||
if (typeof babel !== "object" || Array.isArray(babel) || babel === null) { | ||
throw new Error(file.filepath + ": .babel property must be an object"); | ||
} | ||
if (!options) return null; | ||
} else { | ||
try { | ||
options = _json().default.parse(content); | ||
} catch (err) { | ||
err.message = filepath + ": Error while parsing config - " + err.message; | ||
throw err; | ||
} | ||
return { | ||
filepath: file.filepath, | ||
dirname: file.dirname, | ||
options: babel | ||
}; | ||
}); | ||
var readConfigJSON5 = (0, _utils.makeStaticFileCache)(function (filepath, content) { | ||
var options; | ||
if (!options) throw new Error(filepath + ": No config detected"); | ||
try { | ||
options = _json().default.parse(content); | ||
} catch (err) { | ||
err.message = filepath + ": Error while parsing config - " + err.message; | ||
throw err; | ||
} | ||
if (!options) throw new Error(filepath + ": No config detected"); | ||
if (typeof options !== "object") { | ||
@@ -236,3 +275,3 @@ throw new Error(filepath + ": Config returned typeof " + typeof options); | ||
}); | ||
var readIgnoreConfig = makeStaticFileCache(function (filepath, content) { | ||
var readIgnoreConfig = (0, _utils.makeStaticFileCache)(function (filepath, content) { | ||
var ignore = content.split("\n").map(function (line) { | ||
@@ -250,27 +289,4 @@ return line.replace(/#(.*?)$/, "").trim(); | ||
function makeStaticFileCache(fn) { | ||
return (0, _caching.makeStrongCache)(function (filepath, cache) { | ||
if (cache.invalidate(function () { | ||
return fileMtime(filepath); | ||
}) === null) { | ||
cache.forever(); | ||
return null; | ||
} | ||
return fn(filepath, _fs().default.readFileSync(filepath, "utf8")); | ||
}); | ||
} | ||
function fileMtime(filepath) { | ||
try { | ||
return +_fs().default.statSync(filepath).mtime; | ||
} catch (e) { | ||
if (e.code !== "ENOENT") throw e; | ||
} | ||
return null; | ||
} | ||
function throwConfigError() { | ||
throw new Error("Caching was left unconfigured. Babel's plugins, presets, and .babelrc.js files can be configured\nfor various types of caching, using the first param of their handler functions:\n\nmodule.exports = function(api) {\n // The API exposes the following:\n\n // Cache the returned value forever and don't call this function again.\n api.cache(true);\n\n // Don't cache at all. Not recommended because it will be very slow.\n api.cache(false);\n\n // Cached based on the value of some function. If this function returns a value different from\n // a previously-encountered value, the plugins will re-evaluate.\n var env = api.cache(() => process.env.NODE_ENV);\n\n // If testing for a specific env, we recommend specifics to avoid instantiating a plugin for\n // any possible NODE_ENV value that might come up during plugin execution.\n var isProd = api.cache(() => process.env.NODE_ENV === \"production\");\n\n // .cache(fn) will perform a linear search though instances to find the matching plugin based\n // based on previous instantiated plugins. If you want to recreate the plugin and discard the\n // previous instance whenever something changes, you may use:\n var isProd = api.cache.invalidate(() => process.env.NODE_ENV === \"production\");\n\n // Note, we also expose the following more-verbose versions of the above examples:\n api.cache.forever(); // api.cache(true)\n api.cache.never(); // api.cache(false)\n api.cache.using(fn); // api.cache(fn)\n\n // Return the value that will be cached.\n return { };\n};"); | ||
} |
@@ -6,3 +6,5 @@ "use strict"; | ||
}); | ||
exports.findPackageData = findPackageData; | ||
exports.findRelativeConfig = findRelativeConfig; | ||
exports.findRootConfig = findRootConfig; | ||
exports.loadConfig = loadConfig; | ||
@@ -14,4 +16,14 @@ exports.resolvePlugin = resolvePlugin; | ||
function findRelativeConfig(filepath, envName) { | ||
function findPackageData(filepath) { | ||
return { | ||
filepath: filepath, | ||
directories: [], | ||
pkg: null, | ||
isPackage: false | ||
}; | ||
} | ||
function findRelativeConfig(pkgData, envName) { | ||
return { | ||
pkg: null, | ||
config: null, | ||
@@ -22,3 +34,7 @@ ignore: null | ||
function loadConfig(name, dirname) { | ||
function findRootConfig(dirname, envName) { | ||
return null; | ||
} | ||
function loadConfig(name, dirname, envName) { | ||
throw new Error("Cannot load " + name + " relative to " + dirname + " in a browser"); | ||
@@ -25,0 +41,0 @@ } |
@@ -6,26 +6,57 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "findPackageData", { | ||
enumerable: true, | ||
get: function get() { | ||
return _package.findPackageData; | ||
} | ||
}); | ||
Object.defineProperty(exports, "findRelativeConfig", { | ||
enumerable: true, | ||
get: function get() { | ||
return _configuration.findRelativeConfig; | ||
} | ||
}); | ||
Object.defineProperty(exports, "findRootConfig", { | ||
enumerable: true, | ||
get: function get() { | ||
return _configuration.findRootConfig; | ||
} | ||
}); | ||
Object.defineProperty(exports, "loadConfig", { | ||
enumerable: true, | ||
get: function get() { | ||
return _configuration.loadConfig; | ||
} | ||
}); | ||
Object.defineProperty(exports, "resolvePlugin", { | ||
enumerable: true, | ||
get: function get() { | ||
return _plugins.resolvePlugin; | ||
} | ||
}); | ||
Object.defineProperty(exports, "resolvePreset", { | ||
enumerable: true, | ||
get: function get() { | ||
return _plugins.resolvePreset; | ||
} | ||
}); | ||
Object.defineProperty(exports, "loadPlugin", { | ||
enumerable: true, | ||
get: function get() { | ||
return _plugins.loadPlugin; | ||
} | ||
}); | ||
Object.defineProperty(exports, "loadPreset", { | ||
enumerable: true, | ||
get: function get() { | ||
return _plugins.loadPreset; | ||
} | ||
}); | ||
var _package = require("./package"); | ||
var _configuration = require("./configuration"); | ||
Object.keys(_configuration).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _configuration[key]; | ||
} | ||
}); | ||
}); | ||
var _plugins = require("./plugins"); | ||
Object.keys(_plugins).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _plugins[key]; | ||
} | ||
}); | ||
}); | ||
({}); |
@@ -71,3 +71,4 @@ "use strict"; | ||
ignore: configChain.ignore, | ||
babelrc: configChain.babelrc | ||
babelrc: configChain.babelrc, | ||
config: configChain.config | ||
}; | ||
@@ -81,3 +82,4 @@ } | ||
babelrc = result.babelrc, | ||
ignore = result.ignore; | ||
ignore = result.ignore, | ||
config = result.config; | ||
(options.plugins || []).forEach(function (item) { | ||
@@ -88,10 +90,11 @@ if (item.value instanceof _plugin.default) { | ||
}); | ||
return new PartialConfig(options, babelrc ? babelrc.filepath : undefined, ignore ? ignore.filepath : undefined); | ||
return new PartialConfig(options, babelrc ? babelrc.filepath : undefined, ignore ? ignore.filepath : undefined, config ? config.filepath : undefined); | ||
} | ||
var PartialConfig = function () { | ||
function PartialConfig(options, babelrc, ignore) { | ||
function PartialConfig(options, babelrc, ignore, config) { | ||
this.options = options; | ||
this.babelignore = ignore; | ||
this.babelrc = babelrc; | ||
this.config = config; | ||
Object.freeze(this); | ||
@@ -103,3 +106,3 @@ } | ||
_proto.hasFilesystemConfig = function hasFilesystemConfig() { | ||
return this.babelrc !== undefined; | ||
return this.babelrc !== undefined || this.config !== undefined; | ||
}; | ||
@@ -106,0 +109,0 @@ |
@@ -17,2 +17,4 @@ "use strict"; | ||
exports.assertConfigApplicableTest = assertConfigApplicableTest; | ||
exports.assertConfigFileSearch = assertConfigFileSearch; | ||
exports.assertBabelrcSearch = assertBabelrcSearch; | ||
exports.assertPluginList = assertPluginList; | ||
@@ -132,2 +134,26 @@ | ||
function assertConfigFileSearch(key, value) { | ||
if (value !== undefined && typeof value !== "boolean" && typeof value !== "string") { | ||
throw new Error("." + key + " must be a undefined, a boolean, a string, " + ("got " + JSON.stringify(value))); | ||
} | ||
return value; | ||
} | ||
function assertBabelrcSearch(key, value) { | ||
if (value === undefined || typeof value === "boolean") return value; | ||
if (Array.isArray(value)) { | ||
value.forEach(function (item, i) { | ||
if (typeof item !== "string") { | ||
throw new Error("." + key + "[" + i + "] must be a string."); | ||
} | ||
}); | ||
} else if (typeof value !== "string") { | ||
throw new Error("." + key + " must be a undefined, a boolean, a string, " + ("or an array of strings, got " + JSON.stringify(value))); | ||
} | ||
return value; | ||
} | ||
function assertPluginList(key, value) { | ||
@@ -134,0 +160,0 @@ var arr = assertArray(key, value); |
@@ -18,5 +18,8 @@ "use strict"; | ||
cwd: _optionAssertions.assertString, | ||
root: _optionAssertions.assertString, | ||
configFile: _optionAssertions.assertConfigFileSearch, | ||
filename: _optionAssertions.assertString, | ||
filenameRelative: _optionAssertions.assertString, | ||
babelrc: _optionAssertions.assertBoolean, | ||
babelrcRoots: _optionAssertions.assertBabelrcSearch, | ||
code: _optionAssertions.assertBoolean, | ||
@@ -23,0 +26,0 @@ ast: _optionAssertions.assertBoolean, |
{ | ||
"name": "@babel/core", | ||
"version": "7.0.0-beta.44", | ||
"version": "7.0.0-beta.45", | ||
"description": "Babel compiler core.", | ||
@@ -31,9 +31,9 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@babel/code-frame": "7.0.0-beta.44", | ||
"@babel/generator": "7.0.0-beta.44", | ||
"@babel/helpers": "7.0.0-beta.44", | ||
"@babel/template": "7.0.0-beta.44", | ||
"@babel/traverse": "7.0.0-beta.44", | ||
"@babel/types": "7.0.0-beta.44", | ||
"babylon": "7.0.0-beta.44", | ||
"@babel/code-frame": "7.0.0-beta.45", | ||
"@babel/generator": "7.0.0-beta.45", | ||
"@babel/helpers": "7.0.0-beta.45", | ||
"@babel/template": "7.0.0-beta.45", | ||
"@babel/traverse": "7.0.0-beta.45", | ||
"@babel/types": "7.0.0-beta.45", | ||
"babylon": "7.0.0-beta.45", | ||
"convert-source-map": "^1.1.0", | ||
@@ -49,5 +49,5 @@ "debug": "^3.1.0", | ||
"devDependencies": { | ||
"@babel/helper-transform-fixture-test-runner": "7.0.0-beta.44", | ||
"@babel/register": "7.0.0-beta.44" | ||
"@babel/helper-transform-fixture-test-runner": "7.0.0-beta.45", | ||
"@babel/register": "7.0.0-beta.45" | ||
} | ||
} |
@@ -216,6 +216,9 @@ # @babel/core | ||
| ------------------------ | -------------------- | ------------------------------- | | ||
| `ast` | `true` | Include the AST in the returned object | | ||
| `ast` | `false` | Include the AST in the returned object | | ||
| `auxiliaryCommentAfter` | `null` | Attach a comment after all non-user injected code | | ||
| `auxiliaryCommentBefore` | `null` | Attach a comment before all non-user injected code | | ||
| `root` | `"."` | Specify the "root" folder that defines the location to search for "babel.config.js", and the default folder to allow `.babelrc` files inside of.| | ||
| `configFile` | `undefined` | The config file to load Babel's config from. Defaults to searching for "babel.config.js" inside the "root" folder. `false` will disable searching for config files.| | ||
| `babelrc` | `true` | Specify whether or not to use .babelrc and .babelignore files. Not available when using the CLI, [use `--no-babelrc` instead](https://babeljs.io/docs/usage/cli/#babel-ignoring-babelrc) | | ||
| `babelrcRoots` | `(root)` | Specify which packages should be search for .babelrc files when they are being compiled. `true` to _always_ search, or a path string or an array of paths to packages to search inside of. Defaults to only searching the "root" package. | | ||
| `envName` | env vars | Defaults to environment variable `BABEL_ENV` if set, or else `NODE_ENV` if set, or else it defaults to `"development"` | | ||
@@ -222,0 +225,0 @@ | `code` | `true` | Enable code generation | |
144395
43
3720
251
8
+ Added@babel/code-frame@7.0.0-beta.45(transitive)
+ Added@babel/generator@7.0.0-beta.45(transitive)
+ Added@babel/helper-function-name@7.0.0-beta.45(transitive)
+ Added@babel/helper-get-function-arity@7.0.0-beta.45(transitive)
+ Added@babel/helper-split-export-declaration@7.0.0-beta.45(transitive)
+ Added@babel/helpers@7.0.0-beta.45(transitive)
+ Added@babel/highlight@7.0.0-beta.45(transitive)
+ Added@babel/template@7.0.0-beta.45(transitive)
+ Added@babel/traverse@7.0.0-beta.45(transitive)
+ Added@babel/types@7.0.0-beta.45(transitive)
+ Addedbabylon@7.0.0-beta.45(transitive)
- Removed@babel/code-frame@7.0.0-beta.44(transitive)
- Removed@babel/generator@7.0.0-beta.44(transitive)
- Removed@babel/helper-function-name@7.0.0-beta.44(transitive)
- Removed@babel/helper-get-function-arity@7.0.0-beta.44(transitive)
- Removed@babel/helper-split-export-declaration@7.0.0-beta.44(transitive)
- Removed@babel/helpers@7.0.0-beta.44(transitive)
- Removed@babel/highlight@7.0.0-beta.44(transitive)
- Removed@babel/template@7.0.0-beta.44(transitive)
- Removed@babel/traverse@7.0.0-beta.44(transitive)
- Removed@babel/types@7.0.0-beta.44(transitive)
- Removedbabylon@7.0.0-beta.44(transitive)
Updated@babel/helpers@7.0.0-beta.45
Updated@babel/types@7.0.0-beta.45
Updatedbabylon@7.0.0-beta.45