update
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
> Babel compiler core.
|
||||
|
||||
See our website [@babel/core](https://babeljs.io/docs/en/next/babel-core.html) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20core%22+is%3Aopen) associated with this package.
|
||||
See our website [@babel/core](https://babeljs.io/docs/en/babel-core) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20core%22+is%3Aopen) associated with this package.
|
||||
|
||||
## Install
|
||||
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
0 && 0;
|
||||
+12
-9
@@ -3,14 +3,14 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.makeWeakCache = makeWeakCache;
|
||||
exports.makeWeakCacheSync = makeWeakCacheSync;
|
||||
exports.assertSimpleType = assertSimpleType;
|
||||
exports.makeStrongCache = makeStrongCache;
|
||||
exports.makeStrongCacheSync = makeStrongCacheSync;
|
||||
exports.assertSimpleType = assertSimpleType;
|
||||
exports.makeWeakCache = makeWeakCache;
|
||||
exports.makeWeakCacheSync = makeWeakCacheSync;
|
||||
|
||||
function _gensync() {
|
||||
const data = _interopRequireDefault(require("gensync"));
|
||||
const data = require("gensync");
|
||||
|
||||
_gensync = function () {
|
||||
return data;
|
||||
@@ -23,13 +23,11 @@ var _async = require("../gensync-utils/async");
|
||||
|
||||
var _util = require("./util");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const synchronize = gen => {
|
||||
return (0, _gensync().default)(gen).sync;
|
||||
return _gensync()(gen).sync;
|
||||
};
|
||||
|
||||
function* genTrue(data) {
|
||||
function* genTrue() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -182,6 +180,7 @@ class CacheConfigurator {
|
||||
this._invalidate = false;
|
||||
this._configured = false;
|
||||
this._pairs = [];
|
||||
this._data = void 0;
|
||||
this._data = data;
|
||||
}
|
||||
|
||||
@@ -310,6 +309,8 @@ function assertSimpleType(value) {
|
||||
class Lock {
|
||||
constructor() {
|
||||
this.released = false;
|
||||
this.promise = void 0;
|
||||
this._resolve = void 0;
|
||||
this.promise = new Promise(resolve => {
|
||||
this._resolve = resolve;
|
||||
});
|
||||
@@ -321,4 +322,6 @@ class Lock {
|
||||
this._resolve(value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+182
-54
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.buildPresetChain = buildPresetChain;
|
||||
exports.buildRootChain = buildRootChain;
|
||||
exports.buildPresetChainWalker = void 0;
|
||||
exports.buildRootChain = buildRootChain;
|
||||
|
||||
function _path() {
|
||||
const data = _interopRequireDefault(require("path"));
|
||||
const data = require("path");
|
||||
|
||||
_path = function () {
|
||||
return data;
|
||||
@@ -18,7 +18,7 @@ function _path() {
|
||||
}
|
||||
|
||||
function _debug() {
|
||||
const data = _interopRequireDefault(require("debug"));
|
||||
const data = require("debug");
|
||||
|
||||
_debug = function () {
|
||||
return data;
|
||||
@@ -29,7 +29,9 @@ function _debug() {
|
||||
|
||||
var _options = require("./validation/options");
|
||||
|
||||
var _patternToRegex = _interopRequireDefault(require("./pattern-to-regex"));
|
||||
var _patternToRegex = require("./pattern-to-regex");
|
||||
|
||||
var _printer = require("./printer");
|
||||
|
||||
var _files = require("./files");
|
||||
|
||||
@@ -37,9 +39,7 @@ var _caching = require("./caching");
|
||||
|
||||
var _configDescriptors = require("./config-descriptors");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const debug = (0, _debug().default)("babel:config:config-chain");
|
||||
const debug = _debug()("babel:config:config-chain");
|
||||
|
||||
function* buildPresetChain(arg, context) {
|
||||
const chain = yield* buildPresetChainWalker(arg, context);
|
||||
@@ -47,7 +47,8 @@ function* buildPresetChain(arg, context) {
|
||||
return {
|
||||
plugins: dedupDescriptors(chain.plugins),
|
||||
presets: dedupDescriptors(chain.presets),
|
||||
options: chain.options.map(o => normalizeOptions(o))
|
||||
options: chain.options.map(o => normalizeOptions(o)),
|
||||
files: new Set()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -55,7 +56,8 @@ const buildPresetChainWalker = makeChainWalker({
|
||||
root: preset => loadPresetDescriptors(preset),
|
||||
env: (preset, envName) => loadPresetEnvDescriptors(preset)(envName),
|
||||
overrides: (preset, index) => loadPresetOverridesDescriptors(preset)(index),
|
||||
overridesEnv: (preset, index, envName) => loadPresetOverridesEnvDescriptors(preset)(index)(envName)
|
||||
overridesEnv: (preset, index, envName) => loadPresetOverridesEnvDescriptors(preset)(index)(envName),
|
||||
createLogger: () => () => {}
|
||||
});
|
||||
exports.buildPresetChainWalker = buildPresetChainWalker;
|
||||
const loadPresetDescriptors = (0, _caching.makeWeakCacheSync)(preset => buildRootDescriptors(preset, preset.alias, _configDescriptors.createUncachedDescriptors));
|
||||
@@ -64,11 +66,14 @@ const loadPresetOverridesDescriptors = (0, _caching.makeWeakCacheSync)(preset =>
|
||||
const loadPresetOverridesEnvDescriptors = (0, _caching.makeWeakCacheSync)(preset => (0, _caching.makeStrongCacheSync)(index => (0, _caching.makeStrongCacheSync)(envName => buildOverrideEnvDescriptors(preset, preset.alias, _configDescriptors.createUncachedDescriptors, index, envName))));
|
||||
|
||||
function* buildRootChain(opts, context) {
|
||||
let configReport, babelRcReport;
|
||||
const programmaticLogger = new _printer.ConfigPrinter();
|
||||
const programmaticChain = yield* loadProgrammaticChain({
|
||||
options: opts,
|
||||
dirname: context.cwd
|
||||
}, context);
|
||||
}, context, undefined, programmaticLogger);
|
||||
if (!programmaticChain) return null;
|
||||
const programmaticReport = yield* programmaticLogger.output();
|
||||
let configFile;
|
||||
|
||||
if (typeof opts.configFile === "string") {
|
||||
@@ -83,11 +88,13 @@ function* buildRootChain(opts, context) {
|
||||
} = opts;
|
||||
let babelrcRootsDirectory = context.cwd;
|
||||
const configFileChain = emptyChain();
|
||||
const configFileLogger = new _printer.ConfigPrinter();
|
||||
|
||||
if (configFile) {
|
||||
const validatedFile = validateConfigFile(configFile);
|
||||
const result = yield* loadFileChain(validatedFile, context);
|
||||
const result = yield* loadFileChain(validatedFile, context, undefined, configFileLogger);
|
||||
if (!result) return null;
|
||||
configReport = yield* configFileLogger.output();
|
||||
|
||||
if (babelrc === undefined) {
|
||||
babelrc = validatedFile.options.babelrc;
|
||||
@@ -101,35 +108,60 @@ function* buildRootChain(opts, context) {
|
||||
mergeChain(configFileChain, result);
|
||||
}
|
||||
|
||||
const pkgData = typeof context.filename === "string" ? yield* (0, _files.findPackageData)(context.filename) : null;
|
||||
let ignoreFile, babelrcFile;
|
||||
let isIgnored = false;
|
||||
const fileChain = emptyChain();
|
||||
|
||||
if ((babelrc === true || babelrc === undefined) && pkgData && babelrcLoadEnabled(context, pkgData, babelrcRoots, babelrcRootsDirectory)) {
|
||||
({
|
||||
ignore: ignoreFile,
|
||||
config: babelrcFile
|
||||
} = yield* (0, _files.findRelativeConfig)(pkgData, context.envName, context.caller));
|
||||
if ((babelrc === true || babelrc === undefined) && typeof context.filename === "string") {
|
||||
const pkgData = yield* (0, _files.findPackageData)(context.filename);
|
||||
|
||||
if (ignoreFile && shouldIgnore(context, ignoreFile.ignore, null, ignoreFile.dirname)) {
|
||||
return null;
|
||||
}
|
||||
if (pkgData && babelrcLoadEnabled(context, pkgData, babelrcRoots, babelrcRootsDirectory)) {
|
||||
({
|
||||
ignore: ignoreFile,
|
||||
config: babelrcFile
|
||||
} = yield* (0, _files.findRelativeConfig)(pkgData, context.envName, context.caller));
|
||||
|
||||
if (babelrcFile) {
|
||||
const result = yield* loadFileChain(validateBabelrcFile(babelrcFile), context);
|
||||
if (!result) return null;
|
||||
mergeChain(fileChain, result);
|
||||
if (ignoreFile) {
|
||||
fileChain.files.add(ignoreFile.filepath);
|
||||
}
|
||||
|
||||
if (ignoreFile && shouldIgnore(context, ignoreFile.ignore, null, ignoreFile.dirname)) {
|
||||
isIgnored = true;
|
||||
}
|
||||
|
||||
if (babelrcFile && !isIgnored) {
|
||||
const validatedFile = validateBabelrcFile(babelrcFile);
|
||||
const babelrcLogger = new _printer.ConfigPrinter();
|
||||
const result = yield* loadFileChain(validatedFile, context, undefined, babelrcLogger);
|
||||
|
||||
if (!result) {
|
||||
isIgnored = true;
|
||||
} else {
|
||||
babelRcReport = yield* babelrcLogger.output();
|
||||
mergeChain(fileChain, result);
|
||||
}
|
||||
}
|
||||
|
||||
if (babelrcFile && isIgnored) {
|
||||
fileChain.files.add(babelrcFile.filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (context.showConfig) {
|
||||
console.log(`Babel configs on "${context.filename}" (ascending priority):\n` + [configReport, babelRcReport, programmaticReport].filter(x => !!x).join("\n\n") + "\n-----End Babel configs-----");
|
||||
}
|
||||
|
||||
const chain = mergeChain(mergeChain(mergeChain(emptyChain(), configFileChain), fileChain), programmaticChain);
|
||||
return {
|
||||
plugins: dedupDescriptors(chain.plugins),
|
||||
presets: dedupDescriptors(chain.presets),
|
||||
options: chain.options.map(o => normalizeOptions(o)),
|
||||
plugins: isIgnored ? [] : dedupDescriptors(chain.plugins),
|
||||
presets: isIgnored ? [] : dedupDescriptors(chain.presets),
|
||||
options: isIgnored ? [] : chain.options.map(o => normalizeOptions(o)),
|
||||
fileHandling: isIgnored ? "ignored" : "transpile",
|
||||
ignore: ignoreFile || undefined,
|
||||
babelrc: babelrcFile || undefined,
|
||||
config: configFile || undefined
|
||||
config: configFile || undefined,
|
||||
files: chain.files
|
||||
};
|
||||
}
|
||||
|
||||
@@ -142,9 +174,13 @@ function babelrcLoadEnabled(context, pkgData, babelrcRoots, babelrcRootsDirector
|
||||
}
|
||||
|
||||
let babelrcPatterns = babelrcRoots;
|
||||
if (!Array.isArray(babelrcPatterns)) babelrcPatterns = [babelrcPatterns];
|
||||
|
||||
if (!Array.isArray(babelrcPatterns)) {
|
||||
babelrcPatterns = [babelrcPatterns];
|
||||
}
|
||||
|
||||
babelrcPatterns = babelrcPatterns.map(pat => {
|
||||
return typeof pat === "string" ? _path().default.resolve(babelrcRootsDirectory, pat) : pat;
|
||||
return typeof pat === "string" ? _path().resolve(babelrcRootsDirectory, pat) : pat;
|
||||
});
|
||||
|
||||
if (babelrcPatterns.length === 1 && babelrcPatterns[0] === absoluteRoot) {
|
||||
@@ -181,19 +217,42 @@ const loadProgrammaticChain = makeChainWalker({
|
||||
root: input => buildRootDescriptors(input, "base", _configDescriptors.createCachedDescriptors),
|
||||
env: (input, envName) => buildEnvDescriptors(input, "base", _configDescriptors.createCachedDescriptors, envName),
|
||||
overrides: (input, index) => buildOverrideDescriptors(input, "base", _configDescriptors.createCachedDescriptors, index),
|
||||
overridesEnv: (input, index, envName) => buildOverrideEnvDescriptors(input, "base", _configDescriptors.createCachedDescriptors, index, envName)
|
||||
overridesEnv: (input, index, envName) => buildOverrideEnvDescriptors(input, "base", _configDescriptors.createCachedDescriptors, index, envName),
|
||||
createLogger: (input, context, baseLogger) => buildProgrammaticLogger(input, context, baseLogger)
|
||||
});
|
||||
const loadFileChain = makeChainWalker({
|
||||
const loadFileChainWalker = makeChainWalker({
|
||||
root: file => loadFileDescriptors(file),
|
||||
env: (file, envName) => loadFileEnvDescriptors(file)(envName),
|
||||
overrides: (file, index) => loadFileOverridesDescriptors(file)(index),
|
||||
overridesEnv: (file, index, envName) => loadFileOverridesEnvDescriptors(file)(index)(envName)
|
||||
overridesEnv: (file, index, envName) => loadFileOverridesEnvDescriptors(file)(index)(envName),
|
||||
createLogger: (file, context, baseLogger) => buildFileLogger(file.filepath, context, baseLogger)
|
||||
});
|
||||
|
||||
function* loadFileChain(input, context, files, baseLogger) {
|
||||
const chain = yield* loadFileChainWalker(input, context, files, baseLogger);
|
||||
|
||||
if (chain) {
|
||||
chain.files.add(input.filepath);
|
||||
}
|
||||
|
||||
return chain;
|
||||
}
|
||||
|
||||
const loadFileDescriptors = (0, _caching.makeWeakCacheSync)(file => buildRootDescriptors(file, file.filepath, _configDescriptors.createUncachedDescriptors));
|
||||
const loadFileEnvDescriptors = (0, _caching.makeWeakCacheSync)(file => (0, _caching.makeStrongCacheSync)(envName => buildEnvDescriptors(file, file.filepath, _configDescriptors.createUncachedDescriptors, envName)));
|
||||
const loadFileOverridesDescriptors = (0, _caching.makeWeakCacheSync)(file => (0, _caching.makeStrongCacheSync)(index => buildOverrideDescriptors(file, file.filepath, _configDescriptors.createUncachedDescriptors, index)));
|
||||
const loadFileOverridesEnvDescriptors = (0, _caching.makeWeakCacheSync)(file => (0, _caching.makeStrongCacheSync)(index => (0, _caching.makeStrongCacheSync)(envName => buildOverrideEnvDescriptors(file, file.filepath, _configDescriptors.createUncachedDescriptors, index, envName))));
|
||||
|
||||
function buildFileLogger(filepath, context, baseLogger) {
|
||||
if (!baseLogger) {
|
||||
return () => {};
|
||||
}
|
||||
|
||||
return baseLogger.configure(context.showConfig, _printer.ChainFormatter.Config, {
|
||||
filepath
|
||||
});
|
||||
}
|
||||
|
||||
function buildRootDescriptors({
|
||||
dirname,
|
||||
options
|
||||
@@ -201,6 +260,18 @@ function buildRootDescriptors({
|
||||
return descriptors(dirname, options, alias);
|
||||
}
|
||||
|
||||
function buildProgrammaticLogger(_, context, baseLogger) {
|
||||
var _context$caller;
|
||||
|
||||
if (!baseLogger) {
|
||||
return () => {};
|
||||
}
|
||||
|
||||
return baseLogger.configure(context.showConfig, _printer.ChainFormatter.Programmatic, {
|
||||
callerName: (_context$caller = context.caller) == null ? void 0 : _context$caller.name
|
||||
});
|
||||
}
|
||||
|
||||
function buildEnvDescriptors({
|
||||
dirname,
|
||||
options
|
||||
@@ -232,9 +303,10 @@ function makeChainWalker({
|
||||
root,
|
||||
env,
|
||||
overrides,
|
||||
overridesEnv
|
||||
overridesEnv,
|
||||
createLogger
|
||||
}) {
|
||||
return function* (input, context, files = new Set()) {
|
||||
return function* (input, context, files = new Set(), baseLogger) {
|
||||
const {
|
||||
dirname
|
||||
} = input;
|
||||
@@ -242,51 +314,75 @@ function makeChainWalker({
|
||||
const rootOpts = root(input);
|
||||
|
||||
if (configIsApplicable(rootOpts, dirname, context)) {
|
||||
flattenedConfigs.push(rootOpts);
|
||||
flattenedConfigs.push({
|
||||
config: rootOpts,
|
||||
envName: undefined,
|
||||
index: undefined
|
||||
});
|
||||
const envOpts = env(input, context.envName);
|
||||
|
||||
if (envOpts && configIsApplicable(envOpts, dirname, context)) {
|
||||
flattenedConfigs.push(envOpts);
|
||||
flattenedConfigs.push({
|
||||
config: envOpts,
|
||||
envName: context.envName,
|
||||
index: undefined
|
||||
});
|
||||
}
|
||||
|
||||
(rootOpts.options.overrides || []).forEach((_, index) => {
|
||||
const overrideOps = overrides(input, index);
|
||||
|
||||
if (configIsApplicable(overrideOps, dirname, context)) {
|
||||
flattenedConfigs.push(overrideOps);
|
||||
flattenedConfigs.push({
|
||||
config: overrideOps,
|
||||
index,
|
||||
envName: undefined
|
||||
});
|
||||
const overrideEnvOpts = overridesEnv(input, index, context.envName);
|
||||
|
||||
if (overrideEnvOpts && configIsApplicable(overrideEnvOpts, dirname, context)) {
|
||||
flattenedConfigs.push(overrideEnvOpts);
|
||||
flattenedConfigs.push({
|
||||
config: overrideEnvOpts,
|
||||
index,
|
||||
envName: context.envName
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (flattenedConfigs.some(({
|
||||
options: {
|
||||
ignore,
|
||||
only
|
||||
config: {
|
||||
options: {
|
||||
ignore,
|
||||
only
|
||||
}
|
||||
}
|
||||
}) => shouldIgnore(context, ignore, only, dirname))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const chain = emptyChain();
|
||||
const logger = createLogger(input, context, baseLogger);
|
||||
|
||||
for (const op of flattenedConfigs) {
|
||||
if (!(yield* mergeExtendsChain(chain, op.options, dirname, context, files))) {
|
||||
for (const {
|
||||
config,
|
||||
index,
|
||||
envName
|
||||
} of flattenedConfigs) {
|
||||
if (!(yield* mergeExtendsChain(chain, config.options, dirname, context, files, baseLogger))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
mergeChainOpts(chain, op);
|
||||
logger(config, index, envName);
|
||||
yield* mergeChainOpts(chain, config);
|
||||
}
|
||||
|
||||
return chain;
|
||||
};
|
||||
}
|
||||
|
||||
function* mergeExtendsChain(chain, opts, dirname, context, files) {
|
||||
function* mergeExtendsChain(chain, opts, dirname, context, files, baseLogger) {
|
||||
if (opts.extends === undefined) return true;
|
||||
const file = yield* (0, _files.loadConfig)(opts.extends, dirname, context.envName, context.caller);
|
||||
|
||||
@@ -295,7 +391,7 @@ function* mergeExtendsChain(chain, opts, dirname, context, files) {
|
||||
}
|
||||
|
||||
files.add(file);
|
||||
const fileChain = yield* loadFileChain(validateExtendFile(file), context, files);
|
||||
const fileChain = yield* loadFileChain(validateExtendFile(file), context, files, baseLogger);
|
||||
files.delete(file);
|
||||
if (!fileChain) return false;
|
||||
mergeChain(chain, fileChain);
|
||||
@@ -306,17 +402,22 @@ function mergeChain(target, source) {
|
||||
target.options.push(...source.options);
|
||||
target.plugins.push(...source.plugins);
|
||||
target.presets.push(...source.presets);
|
||||
|
||||
for (const file of source.files) {
|
||||
target.files.add(file);
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
function mergeChainOpts(target, {
|
||||
function* mergeChainOpts(target, {
|
||||
options,
|
||||
plugins,
|
||||
presets
|
||||
}) {
|
||||
target.options.push(options);
|
||||
target.plugins.push(...plugins());
|
||||
target.presets.push(...presets());
|
||||
target.plugins.push(...(yield* plugins()));
|
||||
target.presets.push(...(yield* presets()));
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -324,7 +425,8 @@ function emptyChain() {
|
||||
return {
|
||||
options: [],
|
||||
presets: [],
|
||||
plugins: []
|
||||
plugins: [],
|
||||
files: new Set()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -399,14 +501,38 @@ function configFieldIsApplicable(context, test, dirname) {
|
||||
return matchesPatterns(context, patterns, dirname);
|
||||
}
|
||||
|
||||
function ignoreListReplacer(_key, value) {
|
||||
if (value instanceof RegExp) {
|
||||
return String(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function shouldIgnore(context, ignore, only, dirname) {
|
||||
if (ignore && matchesPatterns(context, ignore, dirname)) {
|
||||
debug("Ignored %o because it matched one of %O from %o", context.filename, ignore, dirname);
|
||||
var _context$filename;
|
||||
|
||||
const message = `No config is applied to "${(_context$filename = context.filename) != null ? _context$filename : "(unknown)"}" because it matches one of \`ignore: ${JSON.stringify(ignore, ignoreListReplacer)}\` from "${dirname}"`;
|
||||
debug(message);
|
||||
|
||||
if (context.showConfig) {
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (only && !matchesPatterns(context, only, dirname)) {
|
||||
debug("Ignored %o because it failed to match one of %O from %o", context.filename, only, dirname);
|
||||
var _context$filename2;
|
||||
|
||||
const message = `No config is applied to "${(_context$filename2 = context.filename) != null ? _context$filename2 : "(unknown)"}" because it fails to match one of \`only: ${JSON.stringify(only, ignoreListReplacer)}\` from "${dirname}"`;
|
||||
debug(message);
|
||||
|
||||
if (context.showConfig) {
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -435,4 +561,6 @@ function matchPattern(pattern, dirname, pathToTest, context) {
|
||||
}
|
||||
|
||||
return pattern.test(pathToTest);
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+56
-21
@@ -4,8 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.createCachedDescriptors = createCachedDescriptors;
|
||||
exports.createUncachedDescriptors = createUncachedDescriptors;
|
||||
exports.createDescriptor = createDescriptor;
|
||||
exports.createUncachedDescriptors = createUncachedDescriptors;
|
||||
|
||||
function _gensync() {
|
||||
const data = require("gensync");
|
||||
|
||||
_gensync = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
var _files = require("./files");
|
||||
|
||||
@@ -13,10 +23,24 @@ var _item = require("./item");
|
||||
|
||||
var _caching = require("./caching");
|
||||
|
||||
var _resolveTargets = require("./resolve-targets");
|
||||
|
||||
function isEqualDescriptor(a, b) {
|
||||
return a.name === b.name && a.value === b.value && a.options === b.options && a.dirname === b.dirname && a.alias === b.alias && a.ownPass === b.ownPass && (a.file && a.file.request) === (b.file && b.file.request) && (a.file && a.file.resolved) === (b.file && b.file.resolved);
|
||||
}
|
||||
|
||||
function* handlerOf(value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
function optionsWithResolvedBrowserslistConfigFile(options, dirname) {
|
||||
if (typeof options.browserslistConfigFile === "string") {
|
||||
options.browserslistConfigFile = (0, _resolveTargets.resolveBrowserslistConfigFile)(options.browserslistConfigFile, dirname);
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
function createCachedDescriptors(dirname, options, alias) {
|
||||
const {
|
||||
plugins,
|
||||
@@ -24,9 +48,9 @@ function createCachedDescriptors(dirname, options, alias) {
|
||||
passPerPreset
|
||||
} = options;
|
||||
return {
|
||||
options,
|
||||
plugins: plugins ? () => createCachedPluginDescriptors(plugins, dirname)(alias) : () => [],
|
||||
presets: presets ? () => createCachedPresetDescriptors(presets, dirname)(alias)(!!passPerPreset) : () => []
|
||||
options: optionsWithResolvedBrowserslistConfigFile(options, dirname),
|
||||
plugins: plugins ? () => createCachedPluginDescriptors(plugins, dirname)(alias) : () => handlerOf([]),
|
||||
presets: presets ? () => createCachedPresetDescriptors(presets, dirname)(alias)(!!passPerPreset) : () => handlerOf([])
|
||||
};
|
||||
}
|
||||
|
||||
@@ -34,33 +58,42 @@ function createUncachedDescriptors(dirname, options, alias) {
|
||||
let plugins;
|
||||
let presets;
|
||||
return {
|
||||
options,
|
||||
plugins: () => {
|
||||
options: optionsWithResolvedBrowserslistConfigFile(options, dirname),
|
||||
|
||||
*plugins() {
|
||||
if (!plugins) {
|
||||
plugins = createPluginDescriptors(options.plugins || [], dirname, alias);
|
||||
plugins = yield* createPluginDescriptors(options.plugins || [], dirname, alias);
|
||||
}
|
||||
|
||||
return plugins;
|
||||
},
|
||||
presets: () => {
|
||||
|
||||
*presets() {
|
||||
if (!presets) {
|
||||
presets = createPresetDescriptors(options.presets || [], dirname, alias, !!options.passPerPreset);
|
||||
presets = yield* createPresetDescriptors(options.presets || [], dirname, alias, !!options.passPerPreset);
|
||||
}
|
||||
|
||||
return presets;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
const PRESET_DESCRIPTOR_CACHE = new WeakMap();
|
||||
const createCachedPresetDescriptors = (0, _caching.makeWeakCacheSync)((items, cache) => {
|
||||
const dirname = cache.using(dir => dir);
|
||||
return (0, _caching.makeStrongCacheSync)(alias => (0, _caching.makeStrongCacheSync)(passPerPreset => createPresetDescriptors(items, dirname, alias, passPerPreset).map(desc => loadCachedDescriptor(PRESET_DESCRIPTOR_CACHE, desc))));
|
||||
return (0, _caching.makeStrongCacheSync)(alias => (0, _caching.makeStrongCache)(function* (passPerPreset) {
|
||||
const descriptors = yield* createPresetDescriptors(items, dirname, alias, passPerPreset);
|
||||
return descriptors.map(desc => loadCachedDescriptor(PRESET_DESCRIPTOR_CACHE, desc));
|
||||
}));
|
||||
});
|
||||
const PLUGIN_DESCRIPTOR_CACHE = new WeakMap();
|
||||
const createCachedPluginDescriptors = (0, _caching.makeWeakCacheSync)((items, cache) => {
|
||||
const dirname = cache.using(dir => dir);
|
||||
return (0, _caching.makeStrongCacheSync)(alias => createPluginDescriptors(items, dirname, alias).map(desc => loadCachedDescriptor(PLUGIN_DESCRIPTOR_CACHE, desc)));
|
||||
return (0, _caching.makeStrongCache)(function* (alias) {
|
||||
const descriptors = yield* createPluginDescriptors(items, dirname, alias);
|
||||
return descriptors.map(desc => loadCachedDescriptor(PLUGIN_DESCRIPTOR_CACHE, desc));
|
||||
});
|
||||
});
|
||||
const DEFAULT_OPTIONS = {};
|
||||
|
||||
@@ -97,25 +130,25 @@ function loadCachedDescriptor(cache, desc) {
|
||||
return desc;
|
||||
}
|
||||
|
||||
function createPresetDescriptors(items, dirname, alias, passPerPreset) {
|
||||
return createDescriptors("preset", items, dirname, alias, passPerPreset);
|
||||
function* createPresetDescriptors(items, dirname, alias, passPerPreset) {
|
||||
return yield* createDescriptors("preset", items, dirname, alias, passPerPreset);
|
||||
}
|
||||
|
||||
function createPluginDescriptors(items, dirname, alias) {
|
||||
return createDescriptors("plugin", items, dirname, alias);
|
||||
function* createPluginDescriptors(items, dirname, alias) {
|
||||
return yield* createDescriptors("plugin", items, dirname, alias);
|
||||
}
|
||||
|
||||
function createDescriptors(type, items, dirname, alias, ownPass) {
|
||||
const descriptors = items.map((item, index) => createDescriptor(item, dirname, {
|
||||
function* createDescriptors(type, items, dirname, alias, ownPass) {
|
||||
const descriptors = yield* _gensync().all(items.map((item, index) => createDescriptor(item, dirname, {
|
||||
type,
|
||||
alias: `${alias}$${index}`,
|
||||
ownPass: !!ownPass
|
||||
}));
|
||||
})));
|
||||
assertNoDuplicates(descriptors);
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
function createDescriptor(pair, dirname, {
|
||||
function* createDescriptor(pair, dirname, {
|
||||
type,
|
||||
alias,
|
||||
ownPass
|
||||
@@ -151,7 +184,7 @@ function createDescriptor(pair, dirname, {
|
||||
({
|
||||
filepath,
|
||||
value
|
||||
} = resolver(value, dirname));
|
||||
} = yield* resolver(value, dirname));
|
||||
file = {
|
||||
request,
|
||||
resolved: filepath
|
||||
@@ -208,4 +241,6 @@ function assertNoDuplicates(items) {
|
||||
|
||||
nameMap.add(item.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+79
-35
@@ -3,14 +3,15 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.ROOT_CONFIG_FILENAMES = void 0;
|
||||
exports.findConfigUpwards = findConfigUpwards;
|
||||
exports.findRelativeConfig = findRelativeConfig;
|
||||
exports.findRootConfig = findRootConfig;
|
||||
exports.loadConfig = loadConfig;
|
||||
exports.ROOT_CONFIG_FILENAMES = void 0;
|
||||
exports.resolveShowConfigPath = resolveShowConfigPath;
|
||||
|
||||
function _debug() {
|
||||
const data = _interopRequireDefault(require("debug"));
|
||||
const data = require("debug");
|
||||
|
||||
_debug = function () {
|
||||
return data;
|
||||
@@ -19,8 +20,18 @@ function _debug() {
|
||||
return data;
|
||||
}
|
||||
|
||||
function _fs() {
|
||||
const data = require("fs");
|
||||
|
||||
_fs = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _path() {
|
||||
const data = _interopRequireDefault(require("path"));
|
||||
const data = require("path");
|
||||
|
||||
_path = function () {
|
||||
return data;
|
||||
@@ -30,7 +41,7 @@ function _path() {
|
||||
}
|
||||
|
||||
function _json() {
|
||||
const data = _interopRequireDefault(require("json5"));
|
||||
const data = require("json5");
|
||||
|
||||
_json = function () {
|
||||
return data;
|
||||
@@ -40,7 +51,7 @@ function _json() {
|
||||
}
|
||||
|
||||
function _gensync() {
|
||||
const data = _interopRequireDefault(require("gensync"));
|
||||
const data = require("gensync");
|
||||
|
||||
_gensync = function () {
|
||||
return data;
|
||||
@@ -51,41 +62,44 @@ function _gensync() {
|
||||
|
||||
var _caching = require("../caching");
|
||||
|
||||
var _configApi = _interopRequireDefault(require("../helpers/config-api"));
|
||||
var _configApi = require("../helpers/config-api");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
var _moduleTypes = _interopRequireDefault(require("./module-types"));
|
||||
var _moduleTypes = require("./module-types");
|
||||
|
||||
var _patternToRegex = _interopRequireDefault(require("../pattern-to-regex"));
|
||||
var _patternToRegex = require("../pattern-to-regex");
|
||||
|
||||
var fs = _interopRequireWildcard(require("../../gensync-utils/fs"));
|
||||
var fs = require("../../gensync-utils/fs");
|
||||
|
||||
var _resolve = _interopRequireDefault(require("../../gensync-utils/resolve"));
|
||||
function _module() {
|
||||
const data = require("module");
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
_module = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
return data;
|
||||
}
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
const debug = _debug()("babel:config:loading:files:configuration");
|
||||
|
||||
const debug = (0, _debug().default)("babel:config:loading:files:configuration");
|
||||
const ROOT_CONFIG_FILENAMES = ["babel.config.js", "babel.config.cjs", "babel.config.mjs", "babel.config.json"];
|
||||
exports.ROOT_CONFIG_FILENAMES = ROOT_CONFIG_FILENAMES;
|
||||
const RELATIVE_CONFIG_FILENAMES = [".babelrc", ".babelrc.js", ".babelrc.cjs", ".babelrc.mjs", ".babelrc.json"];
|
||||
const BABELIGNORE_FILENAME = ".babelignore";
|
||||
|
||||
function* findConfigUpwards(rootDir) {
|
||||
function findConfigUpwards(rootDir) {
|
||||
let dirname = rootDir;
|
||||
|
||||
while (true) {
|
||||
for (;;) {
|
||||
for (const filename of ROOT_CONFIG_FILENAMES) {
|
||||
if (yield* fs.exists(_path().default.join(dirname, filename))) {
|
||||
if (_fs().existsSync(_path().join(dirname, filename))) {
|
||||
return dirname;
|
||||
}
|
||||
}
|
||||
|
||||
const nextDir = _path().default.dirname(dirname);
|
||||
const nextDir = _path().dirname(dirname);
|
||||
|
||||
if (dirname === nextDir) break;
|
||||
dirname = nextDir;
|
||||
@@ -98,7 +112,7 @@ function* findRelativeConfig(packageData, envName, caller) {
|
||||
let config = null;
|
||||
let ignore = null;
|
||||
|
||||
const dirname = _path().default.dirname(packageData.filepath);
|
||||
const dirname = _path().dirname(packageData.filepath);
|
||||
|
||||
for (const loc of packageData.directories) {
|
||||
if (!config) {
|
||||
@@ -108,7 +122,7 @@ function* findRelativeConfig(packageData, envName, caller) {
|
||||
}
|
||||
|
||||
if (!ignore) {
|
||||
const ignoreLoc = _path().default.join(loc, BABELIGNORE_FILENAME);
|
||||
const ignoreLoc = _path().join(loc, BABELIGNORE_FILENAME);
|
||||
|
||||
ignore = yield* readIgnoreConfig(ignoreLoc);
|
||||
|
||||
@@ -129,10 +143,10 @@ function findRootConfig(dirname, envName, caller) {
|
||||
}
|
||||
|
||||
function* loadOneConfig(names, dirname, envName, caller, previousConfig = null) {
|
||||
const configs = yield* _gensync().default.all(names.map(filename => readConfig(_path().default.join(dirname, filename), envName, caller)));
|
||||
const configs = yield* _gensync().all(names.map(filename => readConfig(_path().join(dirname, filename), envName, caller)));
|
||||
const config = configs.reduce((previousConfig, config) => {
|
||||
if (config && previousConfig) {
|
||||
throw new Error(`Multiple configuration files found. Please remove one:\n` + ` - ${_path().default.basename(previousConfig.filepath)}\n` + ` - ${config.filepath}\n` + `from ${dirname}`);
|
||||
throw new Error(`Multiple configuration files found. Please remove one:\n` + ` - ${_path().basename(previousConfig.filepath)}\n` + ` - ${config.filepath}\n` + `from ${dirname}`);
|
||||
}
|
||||
|
||||
return config || previousConfig;
|
||||
@@ -146,8 +160,17 @@ function* loadOneConfig(names, dirname, envName, caller, previousConfig = null)
|
||||
}
|
||||
|
||||
function* loadConfig(name, dirname, envName, caller) {
|
||||
const filepath = yield* (0, _resolve.default)(name, {
|
||||
basedir: dirname
|
||||
const filepath = (((v, w) => (v = v.split("."), w = w.split("."), +v[0] > +w[0] || v[0] == w[0] && +v[1] >= +w[1]))(process.versions.node, "8.9") ? require.resolve : (r, {
|
||||
paths: [b]
|
||||
}, M = require("module")) => {
|
||||
let f = M._findPath(r, M._nodeModulePaths(b).concat(b));
|
||||
|
||||
if (f) return f;
|
||||
f = new Error(`Cannot resolve module '${r}'`);
|
||||
f.code = "MODULE_NOT_FOUND";
|
||||
throw f;
|
||||
})(name, {
|
||||
paths: [dirname]
|
||||
});
|
||||
const conf = yield* readConfig(filepath, envName, caller);
|
||||
|
||||
@@ -160,7 +183,7 @@ function* loadConfig(name, dirname, envName, caller) {
|
||||
}
|
||||
|
||||
function readConfig(filepath, envName, caller) {
|
||||
const ext = _path().default.extname(filepath);
|
||||
const ext = _path().extname(filepath);
|
||||
|
||||
return ext === ".js" || ext === ".cjs" || ext === ".mjs" ? readConfigJS(filepath, {
|
||||
envName,
|
||||
@@ -170,8 +193,8 @@ function readConfig(filepath, envName, caller) {
|
||||
|
||||
const LOADING_CONFIGS = new Set();
|
||||
const readConfigJS = (0, _caching.makeStrongCache)(function* readConfigJS(filepath, cache) {
|
||||
if (!fs.exists.sync(filepath)) {
|
||||
cache.forever();
|
||||
if (!_fs().existsSync(filepath)) {
|
||||
cache.never();
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -180,7 +203,7 @@ const readConfigJS = (0, _caching.makeStrongCache)(function* readConfigJS(filepa
|
||||
debug("Auto-ignoring usage of config %o.", filepath);
|
||||
return {
|
||||
filepath,
|
||||
dirname: _path().default.dirname(filepath),
|
||||
dirname: _path().dirname(filepath),
|
||||
options: {}
|
||||
};
|
||||
}
|
||||
@@ -201,7 +224,7 @@ const readConfigJS = (0, _caching.makeStrongCache)(function* readConfigJS(filepa
|
||||
|
||||
if (typeof options === "function") {
|
||||
yield* [];
|
||||
options = options((0, _configApi.default)(cache));
|
||||
options = options((0, _configApi.makeConfigAPI)(cache));
|
||||
assertCache = true;
|
||||
}
|
||||
|
||||
@@ -216,7 +239,7 @@ const readConfigJS = (0, _caching.makeStrongCache)(function* readConfigJS(filepa
|
||||
if (assertCache && !cache.configured()) throwConfigError();
|
||||
return {
|
||||
filepath,
|
||||
dirname: _path().default.dirname(filepath),
|
||||
dirname: _path().dirname(filepath),
|
||||
options
|
||||
};
|
||||
});
|
||||
@@ -238,7 +261,7 @@ const readConfigJSON5 = (0, _utils.makeStaticFileCache)((filepath, content) => {
|
||||
let options;
|
||||
|
||||
try {
|
||||
options = _json().default.parse(content);
|
||||
options = _json().parse(content);
|
||||
} catch (err) {
|
||||
err.message = `${filepath}: Error while parsing config - ${err.message}`;
|
||||
throw err;
|
||||
@@ -254,14 +277,15 @@ const readConfigJSON5 = (0, _utils.makeStaticFileCache)((filepath, content) => {
|
||||
throw new Error(`${filepath}: Expected config object but found array`);
|
||||
}
|
||||
|
||||
delete options["$schema"];
|
||||
return {
|
||||
filepath,
|
||||
dirname: _path().default.dirname(filepath),
|
||||
dirname: _path().dirname(filepath),
|
||||
options
|
||||
};
|
||||
});
|
||||
const readIgnoreConfig = (0, _utils.makeStaticFileCache)((filepath, content) => {
|
||||
const ignoreDir = _path().default.dirname(filepath);
|
||||
const ignoreDir = _path().dirname(filepath);
|
||||
|
||||
const ignorePatterns = content.split("\n").map(line => line.replace(/#(.*?)$/, "").trim()).filter(line => !!line);
|
||||
|
||||
@@ -273,11 +297,29 @@ const readIgnoreConfig = (0, _utils.makeStaticFileCache)((filepath, content) =>
|
||||
|
||||
return {
|
||||
filepath,
|
||||
dirname: _path().default.dirname(filepath),
|
||||
dirname: _path().dirname(filepath),
|
||||
ignore: ignorePatterns.map(pattern => (0, _patternToRegex.default)(pattern, ignoreDir))
|
||||
};
|
||||
});
|
||||
|
||||
function* resolveShowConfigPath(dirname) {
|
||||
const targetPath = process.env.BABEL_SHOW_CONFIG_FOR;
|
||||
|
||||
if (targetPath != null) {
|
||||
const absolutePath = _path().resolve(dirname, targetPath);
|
||||
|
||||
const stats = yield* fs.stat(absolutePath);
|
||||
|
||||
if (!stats.isFile()) {
|
||||
throw new Error(`${absolutePath}: BABEL_SHOW_CONFIG_FOR must refer to a regular file, directories are not supported.`);
|
||||
}
|
||||
|
||||
return absolutePath;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function throwConfigError() {
|
||||
throw new Error(`\
|
||||
Caching was left unconfigured. Babel's plugins, presets, and .babelrc.js files can be configured
|
||||
@@ -313,4 +355,6 @@ module.exports = function(api) {
|
||||
// Return the value that will be cached.
|
||||
return { };
|
||||
};`);
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = resolve;
|
||||
|
||||
function _module() {
|
||||
const data = require("module");
|
||||
|
||||
_module = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
var _importMetaResolve = require("../../vendor/import-meta-resolve");
|
||||
|
||||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
||||
|
||||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
||||
|
||||
let import_;
|
||||
|
||||
try {
|
||||
import_ = require("./import").default;
|
||||
} catch (_unused) {}
|
||||
|
||||
const importMetaResolveP = import_ && process.execArgv.includes("--experimental-import-meta-resolve") ? import_("data:text/javascript,export default import.meta.resolve").then(m => m.default || _importMetaResolve.resolve, () => _importMetaResolve.resolve) : Promise.resolve(_importMetaResolve.resolve);
|
||||
|
||||
function resolve(_x, _x2) {
|
||||
return _resolve.apply(this, arguments);
|
||||
}
|
||||
|
||||
function _resolve() {
|
||||
_resolve = _asyncToGenerator(function* (specifier, parent) {
|
||||
return (yield importMetaResolveP)(specifier, parent);
|
||||
});
|
||||
return _resolve.apply(this, arguments);
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+3
-1
@@ -7,4 +7,6 @@ exports.default = import_;
|
||||
|
||||
function import_(filepath) {
|
||||
return import(filepath);
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+12
-6
@@ -3,18 +3,19 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.ROOT_CONFIG_FILENAMES = void 0;
|
||||
exports.findConfigUpwards = findConfigUpwards;
|
||||
exports.findPackageData = findPackageData;
|
||||
exports.findRelativeConfig = findRelativeConfig;
|
||||
exports.findRootConfig = findRootConfig;
|
||||
exports.loadConfig = loadConfig;
|
||||
exports.resolvePlugin = resolvePlugin;
|
||||
exports.resolvePreset = resolvePreset;
|
||||
exports.loadPlugin = loadPlugin;
|
||||
exports.loadPreset = loadPreset;
|
||||
exports.ROOT_CONFIG_FILENAMES = void 0;
|
||||
exports.resolvePlugin = resolvePlugin;
|
||||
exports.resolvePreset = resolvePreset;
|
||||
exports.resolveShowConfigPath = resolveShowConfigPath;
|
||||
|
||||
function* findConfigUpwards(rootDir) {
|
||||
function findConfigUpwards(rootDir) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -29,7 +30,6 @@ function* findPackageData(filepath) {
|
||||
|
||||
function* findRelativeConfig(pkgData, envName, caller) {
|
||||
return {
|
||||
pkg: null,
|
||||
config: null,
|
||||
ignore: null
|
||||
};
|
||||
@@ -43,6 +43,10 @@ function* loadConfig(name, dirname, envName, caller) {
|
||||
throw new Error(`Cannot load ${name} relative to ${dirname} in a browser`);
|
||||
}
|
||||
|
||||
function* resolveShowConfigPath(dirname) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const ROOT_CONFIG_FILENAMES = [];
|
||||
exports.ROOT_CONFIG_FILENAMES = ROOT_CONFIG_FILENAMES;
|
||||
|
||||
@@ -60,4 +64,6 @@ function loadPlugin(name, dirname) {
|
||||
|
||||
function loadPreset(name, dirname) {
|
||||
throw new Error(`Cannot load preset ${name} relative to ${dirname} in a browser`);
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+38
-24
@@ -3,10 +3,10 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "findPackageData", {
|
||||
Object.defineProperty(exports, "ROOT_CONFIG_FILENAMES", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _package.findPackageData;
|
||||
return _configuration.ROOT_CONFIG_FILENAMES;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "findConfigUpwards", {
|
||||
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "findConfigUpwards", {
|
||||
return _configuration.findConfigUpwards;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "findPackageData", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _package.findPackageData;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "findRelativeConfig", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
@@ -33,34 +39,23 @@ Object.defineProperty(exports, "loadConfig", {
|
||||
return _configuration.loadConfig;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "ROOT_CONFIG_FILENAMES", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _configuration.ROOT_CONFIG_FILENAMES;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "resolvePlugin", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _plugins.resolvePlugin;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "resolvePreset", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _plugins.resolvePreset;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "loadPlugin", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _plugins.loadPlugin;
|
||||
return plugins.loadPlugin;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "loadPreset", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _plugins.loadPreset;
|
||||
return plugins.loadPreset;
|
||||
}
|
||||
});
|
||||
exports.resolvePreset = exports.resolvePlugin = void 0;
|
||||
Object.defineProperty(exports, "resolveShowConfigPath", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _configuration.resolveShowConfigPath;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -68,6 +63,25 @@ var _package = require("./package");
|
||||
|
||||
var _configuration = require("./configuration");
|
||||
|
||||
var _plugins = require("./plugins");
|
||||
var plugins = require("./plugins");
|
||||
|
||||
({});
|
||||
function _gensync() {
|
||||
const data = require("gensync");
|
||||
|
||||
_gensync = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
({});
|
||||
|
||||
const resolvePlugin = _gensync()(plugins.resolvePlugin).sync;
|
||||
|
||||
exports.resolvePlugin = resolvePlugin;
|
||||
|
||||
const resolvePreset = _gensync()(plugins.resolvePreset).sync;
|
||||
|
||||
exports.resolvePreset = resolvePreset;
|
||||
0 && 0;
|
||||
+34
-9
@@ -4,11 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = loadCjsOrMjsDefault;
|
||||
exports.supportsESM = void 0;
|
||||
|
||||
var _async = require("../../gensync-utils/async");
|
||||
|
||||
function _path() {
|
||||
const data = _interopRequireDefault(require("path"));
|
||||
const data = require("path");
|
||||
|
||||
_path = function () {
|
||||
return data;
|
||||
@@ -27,7 +28,25 @@ function _url() {
|
||||
return data;
|
||||
}
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
function _module() {
|
||||
const data = require("module");
|
||||
|
||||
_module = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _semver() {
|
||||
const data = require("semver");
|
||||
|
||||
_semver = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
||||
|
||||
@@ -39,14 +58,18 @@ try {
|
||||
import_ = require("./import").default;
|
||||
} catch (_unused) {}
|
||||
|
||||
function* loadCjsOrMjsDefault(filepath, asyncError) {
|
||||
const supportsESM = _semver().satisfies(process.versions.node, "^12.17 || >=13.2");
|
||||
|
||||
exports.supportsESM = supportsESM;
|
||||
|
||||
function* loadCjsOrMjsDefault(filepath, asyncError, fallbackToTranspiledModule = false) {
|
||||
switch (guessJSModuleType(filepath)) {
|
||||
case "cjs":
|
||||
return loadCjsDefault(filepath);
|
||||
return loadCjsDefault(filepath, fallbackToTranspiledModule);
|
||||
|
||||
case "unknown":
|
||||
try {
|
||||
return loadCjsDefault(filepath);
|
||||
return loadCjsDefault(filepath, fallbackToTranspiledModule);
|
||||
} catch (e) {
|
||||
if (e.code !== "ERR_REQUIRE_ESM") throw e;
|
||||
}
|
||||
@@ -61,7 +84,7 @@ function* loadCjsOrMjsDefault(filepath, asyncError) {
|
||||
}
|
||||
|
||||
function guessJSModuleType(filename) {
|
||||
switch (_path().default.extname(filename)) {
|
||||
switch (_path().extname(filename)) {
|
||||
case ".cjs":
|
||||
return "cjs";
|
||||
|
||||
@@ -73,10 +96,10 @@ function guessJSModuleType(filename) {
|
||||
}
|
||||
}
|
||||
|
||||
function loadCjsDefault(filepath) {
|
||||
function loadCjsDefault(filepath, fallbackToTranspiledModule) {
|
||||
const module = require(filepath);
|
||||
|
||||
return (module == null ? void 0 : module.__esModule) ? module.default || undefined : module;
|
||||
return module != null && module.__esModule ? module.default || (fallbackToTranspiledModule ? module : undefined) : module;
|
||||
}
|
||||
|
||||
function loadMjsDefault(_x) {
|
||||
@@ -93,4 +116,6 @@ function _loadMjsDefault() {
|
||||
return module.default;
|
||||
});
|
||||
return _loadMjsDefault.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+8
-9
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
||||
exports.findPackageData = findPackageData;
|
||||
|
||||
function _path() {
|
||||
const data = _interopRequireDefault(require("path"));
|
||||
const data = require("path");
|
||||
|
||||
_path = function () {
|
||||
return data;
|
||||
@@ -17,8 +17,6 @@ function _path() {
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const PACKAGE_FILENAME = "package.json";
|
||||
|
||||
function* findPackageData(filepath) {
|
||||
@@ -26,13 +24,13 @@ function* findPackageData(filepath) {
|
||||
const directories = [];
|
||||
let isPackage = true;
|
||||
|
||||
let dirname = _path().default.dirname(filepath);
|
||||
let dirname = _path().dirname(filepath);
|
||||
|
||||
while (!pkg && _path().default.basename(dirname) !== "node_modules") {
|
||||
while (!pkg && _path().basename(dirname) !== "node_modules") {
|
||||
directories.push(dirname);
|
||||
pkg = yield* readConfigPackage(_path().default.join(dirname, PACKAGE_FILENAME));
|
||||
pkg = yield* readConfigPackage(_path().join(dirname, PACKAGE_FILENAME));
|
||||
|
||||
const nextLoc = _path().default.dirname(dirname);
|
||||
const nextLoc = _path().dirname(dirname);
|
||||
|
||||
if (dirname === nextLoc) {
|
||||
isPackage = false;
|
||||
@@ -72,7 +70,8 @@ const readConfigPackage = (0, _utils.makeStaticFileCache)((filepath, content) =>
|
||||
|
||||
return {
|
||||
filepath,
|
||||
dirname: _path().default.dirname(filepath),
|
||||
dirname: _path().dirname(filepath),
|
||||
options
|
||||
};
|
||||
});
|
||||
});
|
||||
0 && 0;
|
||||
+203
-97
@@ -3,13 +3,13 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.resolvePlugin = resolvePlugin;
|
||||
exports.resolvePreset = resolvePreset;
|
||||
exports.loadPlugin = loadPlugin;
|
||||
exports.loadPreset = loadPreset;
|
||||
exports.resolvePlugin = resolvePlugin;
|
||||
exports.resolvePreset = resolvePreset;
|
||||
|
||||
function _debug() {
|
||||
const data = _interopRequireDefault(require("debug"));
|
||||
const data = require("debug");
|
||||
|
||||
_debug = function () {
|
||||
return data;
|
||||
@@ -18,18 +18,8 @@ function _debug() {
|
||||
return data;
|
||||
}
|
||||
|
||||
function _resolve() {
|
||||
const data = _interopRequireDefault(require("resolve"));
|
||||
|
||||
_resolve = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _path() {
|
||||
const data = _interopRequireDefault(require("path"));
|
||||
const data = require("path");
|
||||
|
||||
_path = function () {
|
||||
return data;
|
||||
@@ -38,9 +28,48 @@ function _path() {
|
||||
return data;
|
||||
}
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
function _gensync() {
|
||||
const data = require("gensync");
|
||||
|
||||
_gensync = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
var _async = require("../../gensync-utils/async");
|
||||
|
||||
var _moduleTypes = require("./module-types");
|
||||
|
||||
function _url() {
|
||||
const data = require("url");
|
||||
|
||||
_url = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
var _importMetaResolve = require("./import-meta-resolve");
|
||||
|
||||
function _module() {
|
||||
const data = require("module");
|
||||
|
||||
_module = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
||||
|
||||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
||||
|
||||
const debug = _debug()("babel:config:loading:files:plugins");
|
||||
|
||||
const debug = (0, _debug().default)("babel:config:loading:files:plugins");
|
||||
const EXACT_RE = /^module:/;
|
||||
const BABEL_PLUGIN_PREFIX_RE = /^(?!@|module:|[^/]+\/|babel-plugin-)/;
|
||||
const BABEL_PRESET_PREFIX_RE = /^(?!@|module:|[^/]+\/|babel-preset-)/;
|
||||
@@ -50,22 +79,17 @@ const OTHER_PLUGIN_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?![^/]*babel-plugin(?:-|\/|$
|
||||
const OTHER_PRESET_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?![^/]*babel-preset(?:-|\/|$)|[^/]+\/)/;
|
||||
const OTHER_ORG_DEFAULT_RE = /^(@(?!babel$)[^/]+)$/;
|
||||
|
||||
function resolvePlugin(name, dirname) {
|
||||
return resolveStandardizedName("plugin", name, dirname);
|
||||
function* resolvePlugin(name, dirname) {
|
||||
return yield* resolveStandardizedName("plugin", name, dirname);
|
||||
}
|
||||
|
||||
function resolvePreset(name, dirname) {
|
||||
return resolveStandardizedName("preset", name, dirname);
|
||||
function* resolvePreset(name, dirname) {
|
||||
return yield* resolveStandardizedName("preset", name, dirname);
|
||||
}
|
||||
|
||||
function loadPlugin(name, dirname) {
|
||||
const filepath = resolvePlugin(name, dirname);
|
||||
|
||||
if (!filepath) {
|
||||
throw new Error(`Plugin ${name} not found relative to ${dirname}`);
|
||||
}
|
||||
|
||||
const value = requireModule("plugin", filepath);
|
||||
function* loadPlugin(name, dirname) {
|
||||
const filepath = yield* resolvePlugin(name, dirname);
|
||||
const value = yield* requireModule("plugin", filepath);
|
||||
debug("Loaded plugin %o from %o.", name, dirname);
|
||||
return {
|
||||
filepath,
|
||||
@@ -73,14 +97,9 @@ function loadPlugin(name, dirname) {
|
||||
};
|
||||
}
|
||||
|
||||
function loadPreset(name, dirname) {
|
||||
const filepath = resolvePreset(name, dirname);
|
||||
|
||||
if (!filepath) {
|
||||
throw new Error(`Preset ${name} not found relative to ${dirname}`);
|
||||
}
|
||||
|
||||
const value = requireModule("preset", filepath);
|
||||
function* loadPreset(name, dirname) {
|
||||
const filepath = yield* resolvePreset(name, dirname);
|
||||
const value = yield* requireModule("preset", filepath);
|
||||
debug("Loaded preset %o from %o.", name, dirname);
|
||||
return {
|
||||
filepath,
|
||||
@@ -89,81 +108,168 @@ function loadPreset(name, dirname) {
|
||||
}
|
||||
|
||||
function standardizeName(type, name) {
|
||||
if (_path().default.isAbsolute(name)) return name;
|
||||
if (_path().isAbsolute(name)) return name;
|
||||
const isPreset = type === "preset";
|
||||
return name.replace(isPreset ? BABEL_PRESET_PREFIX_RE : BABEL_PLUGIN_PREFIX_RE, `babel-${type}-`).replace(isPreset ? BABEL_PRESET_ORG_RE : BABEL_PLUGIN_ORG_RE, `$1${type}-`).replace(isPreset ? OTHER_PRESET_ORG_RE : OTHER_PLUGIN_ORG_RE, `$1babel-${type}-`).replace(OTHER_ORG_DEFAULT_RE, `$1/babel-${type}`).replace(EXACT_RE, "");
|
||||
}
|
||||
|
||||
function resolveStandardizedName(type, name, dirname = process.cwd()) {
|
||||
function* resolveAlternativesHelper(type, name) {
|
||||
const standardizedName = standardizeName(type, name);
|
||||
const {
|
||||
error,
|
||||
value
|
||||
} = yield standardizedName;
|
||||
if (!error) return value;
|
||||
if (error.code !== "MODULE_NOT_FOUND") throw error;
|
||||
|
||||
if (standardizedName !== name && !(yield name).error) {
|
||||
error.message += `\n- If you want to resolve "${name}", use "module:${name}"`;
|
||||
}
|
||||
|
||||
if (!(yield standardizeName(type, "@babel/" + name)).error) {
|
||||
error.message += `\n- Did you mean "@babel/${name}"?`;
|
||||
}
|
||||
|
||||
const oppositeType = type === "preset" ? "plugin" : "preset";
|
||||
|
||||
if (!(yield standardizeName(oppositeType, name)).error) {
|
||||
error.message += `\n- Did you accidentally pass a ${oppositeType} as a ${type}?`;
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
function tryRequireResolve(id, {
|
||||
paths: [dirname]
|
||||
}) {
|
||||
try {
|
||||
return _resolve().default.sync(standardizedName, {
|
||||
basedir: dirname
|
||||
});
|
||||
} catch (e) {
|
||||
if (e.code !== "MODULE_NOT_FOUND") throw e;
|
||||
return {
|
||||
error: null,
|
||||
value: (((v, w) => (v = v.split("."), w = w.split("."), +v[0] > +w[0] || v[0] == w[0] && +v[1] >= +w[1]))(process.versions.node, "8.9") ? require.resolve : (r, {
|
||||
paths: [b]
|
||||
}, M = require("module")) => {
|
||||
let f = M._findPath(r, M._nodeModulePaths(b).concat(b));
|
||||
|
||||
if (standardizedName !== name) {
|
||||
let resolvedOriginal = false;
|
||||
|
||||
try {
|
||||
_resolve().default.sync(name, {
|
||||
basedir: dirname
|
||||
});
|
||||
|
||||
resolvedOriginal = true;
|
||||
} catch (_unused) {}
|
||||
|
||||
if (resolvedOriginal) {
|
||||
e.message += `\n- If you want to resolve "${name}", use "module:${name}"`;
|
||||
}
|
||||
}
|
||||
|
||||
let resolvedBabel = false;
|
||||
|
||||
try {
|
||||
_resolve().default.sync(standardizeName(type, "@babel/" + name), {
|
||||
basedir: dirname
|
||||
});
|
||||
|
||||
resolvedBabel = true;
|
||||
} catch (_unused2) {}
|
||||
|
||||
if (resolvedBabel) {
|
||||
e.message += `\n- Did you mean "@babel/${name}"?`;
|
||||
}
|
||||
|
||||
let resolvedOppositeType = false;
|
||||
const oppositeType = type === "preset" ? "plugin" : "preset";
|
||||
|
||||
try {
|
||||
_resolve().default.sync(standardizeName(oppositeType, name), {
|
||||
basedir: dirname
|
||||
});
|
||||
|
||||
resolvedOppositeType = true;
|
||||
} catch (_unused3) {}
|
||||
|
||||
if (resolvedOppositeType) {
|
||||
e.message += `\n- Did you accidentally pass a ${oppositeType} as a ${type}?`;
|
||||
}
|
||||
|
||||
throw e;
|
||||
if (f) return f;
|
||||
f = new Error(`Cannot resolve module '${r}'`);
|
||||
f.code = "MODULE_NOT_FOUND";
|
||||
throw f;
|
||||
})(id, {
|
||||
paths: [dirname]
|
||||
})
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
error,
|
||||
value: null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const LOADING_MODULES = new Set();
|
||||
function tryImportMetaResolve(_x, _x2) {
|
||||
return _tryImportMetaResolve.apply(this, arguments);
|
||||
}
|
||||
|
||||
function requireModule(type, name) {
|
||||
if (LOADING_MODULES.has(name)) {
|
||||
throw new Error(`Reentrant ${type} detected trying to load "${name}". This module is not ignored ` + "and is trying to load itself while compiling itself, leading to a dependency cycle. " + 'We recommend adding it to your "ignore" list in your babelrc, or to a .babelignore.');
|
||||
function _tryImportMetaResolve() {
|
||||
_tryImportMetaResolve = _asyncToGenerator(function* (id, options) {
|
||||
try {
|
||||
return {
|
||||
error: null,
|
||||
value: yield (0, _importMetaResolve.default)(id, options)
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
error,
|
||||
value: null
|
||||
};
|
||||
}
|
||||
});
|
||||
return _tryImportMetaResolve.apply(this, arguments);
|
||||
}
|
||||
|
||||
function resolveStandardizedNameForRequire(type, name, dirname) {
|
||||
const it = resolveAlternativesHelper(type, name);
|
||||
let res = it.next();
|
||||
|
||||
while (!res.done) {
|
||||
res = it.next(tryRequireResolve(res.value, {
|
||||
paths: [dirname]
|
||||
}));
|
||||
}
|
||||
|
||||
return res.value;
|
||||
}
|
||||
|
||||
function resolveStandardizedNameForImport(_x3, _x4, _x5) {
|
||||
return _resolveStandardizedNameForImport.apply(this, arguments);
|
||||
}
|
||||
|
||||
function _resolveStandardizedNameForImport() {
|
||||
_resolveStandardizedNameForImport = _asyncToGenerator(function* (type, name, dirname) {
|
||||
const parentUrl = (0, _url().pathToFileURL)(_path().join(dirname, "./babel-virtual-resolve-base.js")).href;
|
||||
const it = resolveAlternativesHelper(type, name);
|
||||
let res = it.next();
|
||||
|
||||
while (!res.done) {
|
||||
res = it.next(yield tryImportMetaResolve(res.value, parentUrl));
|
||||
}
|
||||
|
||||
return (0, _url().fileURLToPath)(res.value);
|
||||
});
|
||||
return _resolveStandardizedNameForImport.apply(this, arguments);
|
||||
}
|
||||
|
||||
const resolveStandardizedName = _gensync()({
|
||||
sync(type, name, dirname = process.cwd()) {
|
||||
return resolveStandardizedNameForRequire(type, name, dirname);
|
||||
},
|
||||
|
||||
async(type, name, dirname = process.cwd()) {
|
||||
return _asyncToGenerator(function* () {
|
||||
if (!_moduleTypes.supportsESM) {
|
||||
return resolveStandardizedNameForRequire(type, name, dirname);
|
||||
}
|
||||
|
||||
try {
|
||||
return yield resolveStandardizedNameForImport(type, name, dirname);
|
||||
} catch (e) {
|
||||
try {
|
||||
return resolveStandardizedNameForRequire(type, name, dirname);
|
||||
} catch (e2) {
|
||||
if (e.type === "MODULE_NOT_FOUND") throw e;
|
||||
if (e2.type === "MODULE_NOT_FOUND") throw e2;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
{
|
||||
var LOADING_MODULES = new Set();
|
||||
}
|
||||
|
||||
function* requireModule(type, name) {
|
||||
{
|
||||
if (!(yield* (0, _async.isAsync)()) && LOADING_MODULES.has(name)) {
|
||||
throw new Error(`Reentrant ${type} detected trying to load "${name}". This module is not ignored ` + "and is trying to load itself while compiling itself, leading to a dependency cycle. " + 'We recommend adding it to your "ignore" list in your babelrc, or to a .babelignore.');
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
LOADING_MODULES.add(name);
|
||||
return require(name);
|
||||
{
|
||||
LOADING_MODULES.add(name);
|
||||
}
|
||||
return yield* (0, _moduleTypes.default)(name, `You appear to be using a native ECMAScript module ${type}, ` + "which is only supported when running Babel asynchronously.", true);
|
||||
} catch (err) {
|
||||
err.message = `[BABEL]: ${err.message} (While processing: ${name})`;
|
||||
throw err;
|
||||
} finally {
|
||||
LOADING_MODULES.delete(name);
|
||||
{
|
||||
LOADING_MODULES.delete(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+1
@@ -0,0 +1 @@
|
||||
0 && 0;
|
||||
+8
-11
@@ -7,10 +7,10 @@ exports.makeStaticFileCache = makeStaticFileCache;
|
||||
|
||||
var _caching = require("../caching");
|
||||
|
||||
var fs = _interopRequireWildcard(require("../../gensync-utils/fs"));
|
||||
var fs = require("../../gensync-utils/fs");
|
||||
|
||||
function _fs2() {
|
||||
const data = _interopRequireDefault(require("fs"));
|
||||
const data = require("fs");
|
||||
|
||||
_fs2 = function () {
|
||||
return data;
|
||||
@@ -19,18 +19,11 @@ function _fs2() {
|
||||
return data;
|
||||
}
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
function makeStaticFileCache(fn) {
|
||||
return (0, _caching.makeStrongCache)(function* (filepath, cache) {
|
||||
const cached = cache.invalidate(() => fileMtime(filepath));
|
||||
|
||||
if (cached === null) {
|
||||
cache.forever();
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -39,11 +32,15 @@ function makeStaticFileCache(fn) {
|
||||
}
|
||||
|
||||
function fileMtime(filepath) {
|
||||
if (!_fs2().existsSync(filepath)) return null;
|
||||
|
||||
try {
|
||||
return +_fs2().default.statSync(filepath).mtime;
|
||||
return +_fs2().statSync(filepath).mtime;
|
||||
} catch (e) {
|
||||
if (e.code !== "ENOENT" && e.code !== "ENOTDIR") throw e;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+177
-114
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
||||
exports.default = void 0;
|
||||
|
||||
function _gensync() {
|
||||
const data = _interopRequireDefault(require("gensync"));
|
||||
const data = require("gensync");
|
||||
|
||||
_gensync = function () {
|
||||
return data;
|
||||
@@ -19,16 +19,18 @@ var _async = require("../gensync-utils/async");
|
||||
|
||||
var _util = require("./util");
|
||||
|
||||
var context = _interopRequireWildcard(require("../index"));
|
||||
var context = require("../index");
|
||||
|
||||
var _plugin = _interopRequireDefault(require("./plugin"));
|
||||
var _plugin = require("./plugin");
|
||||
|
||||
var _item = require("./item");
|
||||
|
||||
var _configChain = require("./config-chain");
|
||||
|
||||
var _deepArray = require("./helpers/deep-array");
|
||||
|
||||
function _traverse() {
|
||||
const data = _interopRequireDefault(require("@babel/traverse"));
|
||||
const data = require("@babel/traverse");
|
||||
|
||||
_traverse = function () {
|
||||
return data;
|
||||
@@ -43,17 +45,15 @@ var _options = require("./validation/options");
|
||||
|
||||
var _plugins = require("./validation/plugins");
|
||||
|
||||
var _configApi = _interopRequireDefault(require("./helpers/config-api"));
|
||||
var _configApi = require("./helpers/config-api");
|
||||
|
||||
var _partial = _interopRequireDefault(require("./partial"));
|
||||
var _partial = require("./partial");
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
var Context = require("./cache-contexts");
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
var _default = _gensync()(function* loadFullConfig(inputOpts) {
|
||||
var _opts$assumptions;
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var _default = (0, _gensync().default)(function* loadFullConfig(inputOpts) {
|
||||
const result = yield* (0, _partial.default)(inputOpts);
|
||||
|
||||
if (!result) {
|
||||
@@ -62,114 +62,126 @@ var _default = (0, _gensync().default)(function* loadFullConfig(inputOpts) {
|
||||
|
||||
const {
|
||||
options,
|
||||
context
|
||||
context,
|
||||
fileHandling
|
||||
} = result;
|
||||
|
||||
if (fileHandling === "ignored") {
|
||||
return null;
|
||||
}
|
||||
|
||||
const optionDefaults = {};
|
||||
const passes = [[]];
|
||||
const {
|
||||
plugins,
|
||||
presets
|
||||
} = options;
|
||||
|
||||
try {
|
||||
const {
|
||||
plugins,
|
||||
presets
|
||||
} = options;
|
||||
if (!plugins || !presets) {
|
||||
throw new Error("Assertion failure - plugins and presets exist");
|
||||
}
|
||||
|
||||
if (!plugins || !presets) {
|
||||
throw new Error("Assertion failure - plugins and presets exist");
|
||||
const presetContext = Object.assign({}, context, {
|
||||
targets: options.targets
|
||||
});
|
||||
|
||||
const toDescriptor = item => {
|
||||
const desc = (0, _item.getItemDescriptor)(item);
|
||||
|
||||
if (!desc) {
|
||||
throw new Error("Assertion failure - must be config item");
|
||||
}
|
||||
|
||||
const ignored = yield* function* recurseDescriptors(config, pass) {
|
||||
const plugins = [];
|
||||
return desc;
|
||||
};
|
||||
|
||||
for (let i = 0; i < config.plugins.length; i++) {
|
||||
const descriptor = config.plugins[i];
|
||||
const presetsDescriptors = presets.map(toDescriptor);
|
||||
const initialPluginsDescriptors = plugins.map(toDescriptor);
|
||||
const pluginDescriptorsByPass = [[]];
|
||||
const passes = [];
|
||||
const externalDependencies = [];
|
||||
const ignored = yield* enhanceError(context, function* recursePresetDescriptors(rawPresets, pluginDescriptorsPass) {
|
||||
const presets = [];
|
||||
|
||||
if (descriptor.options !== false) {
|
||||
try {
|
||||
plugins.push(yield* loadPluginDescriptor(descriptor, context));
|
||||
} catch (e) {
|
||||
if (i > 0 && e.code === "BABEL_UNKNOWN_PLUGIN_PROPERTY") {
|
||||
(0, _options.checkNoUnwrappedItemOptionPairs)(config.plugins[i - 1], descriptor, "plugin", i, e);
|
||||
}
|
||||
for (let i = 0; i < rawPresets.length; i++) {
|
||||
const descriptor = rawPresets[i];
|
||||
|
||||
throw e;
|
||||
if (descriptor.options !== false) {
|
||||
try {
|
||||
var preset = yield* loadPresetDescriptor(descriptor, presetContext);
|
||||
} catch (e) {
|
||||
if (e.code === "BABEL_UNKNOWN_OPTION") {
|
||||
(0, _options.checkNoUnwrappedItemOptionPairs)(rawPresets, i, "preset", e);
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
const presets = [];
|
||||
externalDependencies.push(preset.externalDependencies);
|
||||
|
||||
for (let i = 0; i < config.presets.length; i++) {
|
||||
const descriptor = config.presets[i];
|
||||
|
||||
if (descriptor.options !== false) {
|
||||
try {
|
||||
presets.push({
|
||||
preset: yield* loadPresetDescriptor(descriptor, context),
|
||||
pass: descriptor.ownPass ? [] : pass
|
||||
});
|
||||
} catch (e) {
|
||||
if (i > 0 && e.code === "BABEL_UNKNOWN_OPTION") {
|
||||
(0, _options.checkNoUnwrappedItemOptionPairs)(config.presets[i - 1], descriptor, "preset", i, e);
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (presets.length > 0) {
|
||||
passes.splice(1, 0, ...presets.map(o => o.pass).filter(p => p !== pass));
|
||||
|
||||
for (const {
|
||||
preset,
|
||||
pass
|
||||
} of presets) {
|
||||
if (!preset) return true;
|
||||
const ignored = yield* recurseDescriptors({
|
||||
plugins: preset.plugins,
|
||||
presets: preset.presets
|
||||
}, pass);
|
||||
if (ignored) return true;
|
||||
preset.options.forEach(opts => {
|
||||
(0, _util.mergeOptions)(optionDefaults, opts);
|
||||
if (descriptor.ownPass) {
|
||||
presets.push({
|
||||
preset: preset.chain,
|
||||
pass: []
|
||||
});
|
||||
} else {
|
||||
presets.unshift({
|
||||
preset: preset.chain,
|
||||
pass: pluginDescriptorsPass
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (plugins.length > 0) {
|
||||
pass.unshift(...plugins);
|
||||
}
|
||||
}({
|
||||
plugins: plugins.map(item => {
|
||||
const desc = (0, _item.getItemDescriptor)(item);
|
||||
|
||||
if (!desc) {
|
||||
throw new Error("Assertion failure - must be config item");
|
||||
}
|
||||
|
||||
return desc;
|
||||
}),
|
||||
presets: presets.map(item => {
|
||||
const desc = (0, _item.getItemDescriptor)(item);
|
||||
|
||||
if (!desc) {
|
||||
throw new Error("Assertion failure - must be config item");
|
||||
}
|
||||
|
||||
return desc;
|
||||
})
|
||||
}, passes[0]);
|
||||
if (ignored) return null;
|
||||
} catch (e) {
|
||||
if (!/^\[BABEL\]/.test(e.message)) {
|
||||
e.message = `[BABEL] ${context.filename || "unknown"}: ${e.message}`;
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
if (presets.length > 0) {
|
||||
pluginDescriptorsByPass.splice(1, 0, ...presets.map(o => o.pass).filter(p => p !== pluginDescriptorsPass));
|
||||
|
||||
for (const {
|
||||
preset,
|
||||
pass
|
||||
} of presets) {
|
||||
if (!preset) return true;
|
||||
pass.push(...preset.plugins);
|
||||
const ignored = yield* recursePresetDescriptors(preset.presets, pass);
|
||||
if (ignored) return true;
|
||||
preset.options.forEach(opts => {
|
||||
(0, _util.mergeOptions)(optionDefaults, opts);
|
||||
});
|
||||
}
|
||||
}
|
||||
})(presetsDescriptors, pluginDescriptorsByPass[0]);
|
||||
if (ignored) return null;
|
||||
const opts = optionDefaults;
|
||||
(0, _util.mergeOptions)(opts, options);
|
||||
const pluginContext = Object.assign({}, presetContext, {
|
||||
assumptions: (_opts$assumptions = opts.assumptions) != null ? _opts$assumptions : {}
|
||||
});
|
||||
yield* enhanceError(context, function* loadPluginDescriptors() {
|
||||
pluginDescriptorsByPass[0].unshift(...initialPluginsDescriptors);
|
||||
|
||||
for (const descs of pluginDescriptorsByPass) {
|
||||
const pass = [];
|
||||
passes.push(pass);
|
||||
|
||||
for (let i = 0; i < descs.length; i++) {
|
||||
const descriptor = descs[i];
|
||||
|
||||
if (descriptor.options !== false) {
|
||||
try {
|
||||
var plugin = yield* loadPluginDescriptor(descriptor, pluginContext);
|
||||
} catch (e) {
|
||||
if (e.code === "BABEL_UNKNOWN_PLUGIN_PROPERTY") {
|
||||
(0, _options.checkNoUnwrappedItemOptionPairs)(descs, i, "plugin", e);
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
||||
pass.push(plugin);
|
||||
externalDependencies.push(plugin.externalDependencies);
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
opts.plugins = passes[0];
|
||||
opts.presets = passes.slice(1).filter(plugins => plugins.length > 0).map(plugins => ({
|
||||
plugins
|
||||
@@ -177,12 +189,28 @@ var _default = (0, _gensync().default)(function* loadFullConfig(inputOpts) {
|
||||
opts.passPerPreset = opts.presets.length > 0;
|
||||
return {
|
||||
options: opts,
|
||||
passes: passes
|
||||
passes: passes,
|
||||
externalDependencies: (0, _deepArray.finalize)(externalDependencies)
|
||||
};
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
const loadDescriptor = (0, _caching.makeWeakCache)(function* ({
|
||||
|
||||
function enhanceError(context, fn) {
|
||||
return function* (arg1, arg2) {
|
||||
try {
|
||||
return yield* fn(arg1, arg2);
|
||||
} catch (e) {
|
||||
if (!/^\[BABEL\]/.test(e.message)) {
|
||||
e.message = `[BABEL] ${context.filename || "unknown"}: ${e.message}`;
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const makeDescriptorLoader = apiFactory => (0, _caching.makeWeakCache)(function* ({
|
||||
value,
|
||||
options,
|
||||
dirname,
|
||||
@@ -190,13 +218,15 @@ const loadDescriptor = (0, _caching.makeWeakCache)(function* ({
|
||||
}, cache) {
|
||||
if (options === false) throw new Error("Assertion failure");
|
||||
options = options || {};
|
||||
const externalDependencies = [];
|
||||
let item = value;
|
||||
|
||||
if (typeof value === "function") {
|
||||
const api = Object.assign({}, context, (0, _configApi.default)(cache));
|
||||
const factory = (0, _async.maybeAsync)(value, `You appear to be using an async plugin/preset, but Babel has been called synchronously`);
|
||||
const api = Object.assign({}, context, apiFactory(cache, externalDependencies));
|
||||
|
||||
try {
|
||||
item = value(api, options, dirname);
|
||||
item = yield* factory(api, options, dirname);
|
||||
} catch (e) {
|
||||
if (alias) {
|
||||
e.message += ` (While processing: ${JSON.stringify(alias)})`;
|
||||
@@ -210,19 +240,36 @@ const loadDescriptor = (0, _caching.makeWeakCache)(function* ({
|
||||
throw new Error("Plugin/Preset did not return an object.");
|
||||
}
|
||||
|
||||
if (typeof item.then === "function") {
|
||||
if ((0, _async.isThenable)(item)) {
|
||||
yield* [];
|
||||
throw new Error(`You appear to be using an async plugin, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, ` + `you may need to upgrade your @babel/core version.`);
|
||||
throw new Error(`You appear to be using a promise as a plugin, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, ` + `you may need to upgrade your @babel/core version. ` + `As an alternative, you can prefix the promise with "await". ` + `(While processing: ${JSON.stringify(alias)})`);
|
||||
}
|
||||
|
||||
if (externalDependencies.length > 0 && (!cache.configured() || cache.mode() === "forever")) {
|
||||
let error = `A plugin/preset has external untracked dependencies ` + `(${externalDependencies[0]}), but the cache `;
|
||||
|
||||
if (!cache.configured()) {
|
||||
error += `has not been configured to be invalidated when the external dependencies change. `;
|
||||
} else {
|
||||
error += ` has been configured to never be invalidated. `;
|
||||
}
|
||||
|
||||
error += `Plugins/presets should configure their cache to be invalidated when the external ` + `dependencies change, for example using \`api.cache.invalidate(() => ` + `statSync(filepath).mtimeMs)\` or \`api.cache.never()\`\n` + `(While processing: ${JSON.stringify(alias)})`;
|
||||
throw new Error(error);
|
||||
}
|
||||
|
||||
return {
|
||||
value: item,
|
||||
options,
|
||||
dirname,
|
||||
alias
|
||||
alias,
|
||||
externalDependencies: (0, _deepArray.finalize)(externalDependencies)
|
||||
};
|
||||
});
|
||||
|
||||
const pluginDescriptorLoader = makeDescriptorLoader(_configApi.makePluginAPI);
|
||||
const presetDescriptorLoader = makeDescriptorLoader(_configApi.makePresetAPI);
|
||||
|
||||
function* loadPluginDescriptor(descriptor, context) {
|
||||
if (descriptor.value instanceof _plugin.default) {
|
||||
if (descriptor.options) {
|
||||
@@ -232,14 +279,15 @@ function* loadPluginDescriptor(descriptor, context) {
|
||||
return descriptor.value;
|
||||
}
|
||||
|
||||
return yield* instantiatePlugin(yield* loadDescriptor(descriptor, context), context);
|
||||
return yield* instantiatePlugin(yield* pluginDescriptorLoader(descriptor, context), context);
|
||||
}
|
||||
|
||||
const instantiatePlugin = (0, _caching.makeWeakCache)(function* ({
|
||||
value,
|
||||
options,
|
||||
dirname,
|
||||
alias
|
||||
alias,
|
||||
externalDependencies
|
||||
}, cache) {
|
||||
const pluginObj = (0, _plugins.validatePluginObject)(value);
|
||||
const plugin = Object.assign({}, pluginObj);
|
||||
@@ -263,15 +311,23 @@ const instantiatePlugin = (0, _caching.makeWeakCache)(function* ({
|
||||
plugin.post = chain(inherits.post, plugin.post);
|
||||
plugin.manipulateOptions = chain(inherits.manipulateOptions, plugin.manipulateOptions);
|
||||
plugin.visitor = _traverse().default.visitors.merge([inherits.visitor || {}, plugin.visitor || {}]);
|
||||
|
||||
if (inherits.externalDependencies.length > 0) {
|
||||
if (externalDependencies.length === 0) {
|
||||
externalDependencies = inherits.externalDependencies;
|
||||
} else {
|
||||
externalDependencies = (0, _deepArray.finalize)([externalDependencies, inherits.externalDependencies]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new _plugin.default(plugin, options, alias);
|
||||
return new _plugin.default(plugin, options, alias, externalDependencies);
|
||||
});
|
||||
|
||||
const validateIfOptionNeedsFilename = (options, descriptor) => {
|
||||
if (options.test || options.include || options.exclude) {
|
||||
const formattedPresetName = descriptor.name ? `"${descriptor.name}"` : "/* your preset */";
|
||||
throw new Error([`Preset ${formattedPresetName} requires a filename to be set when babel is called directly,`, `\`\`\``, `babel.transform(code, { filename: 'file.ts', presets: [${formattedPresetName}] });`, `\`\`\``, `See https://babeljs.io/docs/en/options#filename for more information.`].join("\n"));
|
||||
throw new Error([`Preset ${formattedPresetName} requires a filename to be set when babel is called directly,`, `\`\`\``, `babel.transformSync(code, { filename: 'file.ts', presets: [${formattedPresetName}] });`, `\`\`\``, `See https://babeljs.io/docs/en/options#filename for more information.`].join("\n"));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -289,20 +345,25 @@ const validatePreset = (preset, context, descriptor) => {
|
||||
};
|
||||
|
||||
function* loadPresetDescriptor(descriptor, context) {
|
||||
const preset = instantiatePreset(yield* loadDescriptor(descriptor, context));
|
||||
const preset = instantiatePreset(yield* presetDescriptorLoader(descriptor, context));
|
||||
validatePreset(preset, context, descriptor);
|
||||
return yield* (0, _configChain.buildPresetChain)(preset, context);
|
||||
return {
|
||||
chain: yield* (0, _configChain.buildPresetChain)(preset, context),
|
||||
externalDependencies: preset.externalDependencies
|
||||
};
|
||||
}
|
||||
|
||||
const instantiatePreset = (0, _caching.makeWeakCacheSync)(({
|
||||
value,
|
||||
dirname,
|
||||
alias
|
||||
alias,
|
||||
externalDependencies
|
||||
}) => {
|
||||
return {
|
||||
options: (0, _options.validate)("preset", value),
|
||||
alias,
|
||||
dirname
|
||||
dirname,
|
||||
externalDependencies
|
||||
};
|
||||
});
|
||||
|
||||
@@ -314,4 +375,6 @@ function chain(a, b) {
|
||||
fn.apply(this, args);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+32
-8
@@ -3,10 +3,12 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = makeAPI;
|
||||
exports.makeConfigAPI = makeConfigAPI;
|
||||
exports.makePluginAPI = makePluginAPI;
|
||||
exports.makePresetAPI = makePresetAPI;
|
||||
|
||||
function _semver() {
|
||||
const data = _interopRequireDefault(require("semver"));
|
||||
const data = require("semver");
|
||||
|
||||
_semver = function () {
|
||||
return data;
|
||||
@@ -19,9 +21,9 @@ var _ = require("../../");
|
||||
|
||||
var _caching = require("../caching");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
var Context = require("../cache-contexts");
|
||||
|
||||
function makeAPI(cache) {
|
||||
function makeConfigAPI(cache) {
|
||||
const env = value => cache.using(data => {
|
||||
if (typeof value === "undefined") return data.envName;
|
||||
|
||||
@@ -29,8 +31,7 @@ function makeAPI(cache) {
|
||||
return (0, _caching.assertSimpleType)(value(data.envName));
|
||||
}
|
||||
|
||||
if (!Array.isArray(value)) value = [value];
|
||||
return value.some(entry => {
|
||||
return (Array.isArray(value) ? value : [value]).some(entry => {
|
||||
if (typeof entry !== "string") {
|
||||
throw new Error("Unexpected non-string value");
|
||||
}
|
||||
@@ -51,6 +52,27 @@ function makeAPI(cache) {
|
||||
};
|
||||
}
|
||||
|
||||
function makePresetAPI(cache, externalDependencies) {
|
||||
const targets = () => JSON.parse(cache.using(data => JSON.stringify(data.targets)));
|
||||
|
||||
const addExternalDependency = ref => {
|
||||
externalDependencies.push(ref);
|
||||
};
|
||||
|
||||
return Object.assign({}, makeConfigAPI(cache), {
|
||||
targets,
|
||||
addExternalDependency
|
||||
});
|
||||
}
|
||||
|
||||
function makePluginAPI(cache, externalDependencies) {
|
||||
const assumption = name => cache.using(data => data.assumptions[name]);
|
||||
|
||||
return Object.assign({}, makePresetAPI(cache, externalDependencies), {
|
||||
assumption
|
||||
});
|
||||
}
|
||||
|
||||
function assertVersion(range) {
|
||||
if (typeof range === "number") {
|
||||
if (!Number.isInteger(range)) {
|
||||
@@ -64,7 +86,7 @@ function assertVersion(range) {
|
||||
throw new Error("Expected string or integer value.");
|
||||
}
|
||||
|
||||
if (_semver().default.satisfies(_.version, range)) return;
|
||||
if (_semver().satisfies(_.version, range)) return;
|
||||
const limit = Error.stackTraceLimit;
|
||||
|
||||
if (typeof limit === "number" && limit < 25) {
|
||||
@@ -82,4 +104,6 @@ function assertVersion(range) {
|
||||
version: _.version,
|
||||
range
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.finalize = finalize;
|
||||
exports.flattenToSet = flattenToSet;
|
||||
|
||||
function finalize(deepArr) {
|
||||
return Object.freeze(deepArr);
|
||||
}
|
||||
|
||||
function flattenToSet(arr) {
|
||||
const result = new Set();
|
||||
const stack = [arr];
|
||||
|
||||
while (stack.length > 0) {
|
||||
for (const el of stack.pop()) {
|
||||
if (Array.isArray(el)) stack.push(el);else result.add(el);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+3
-1
@@ -7,4 +7,6 @@ exports.getEnv = getEnv;
|
||||
|
||||
function getEnv(defaultValue = "development") {
|
||||
return process.env.BABEL_ENV || process.env.NODE_ENV || defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+26
-6
@@ -3,16 +3,18 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.createConfigItem = createConfigItem;
|
||||
exports.createConfigItemSync = exports.createConfigItemAsync = void 0;
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _full.default;
|
||||
}
|
||||
});
|
||||
exports.loadOptionsAsync = exports.loadOptionsSync = exports.loadOptions = exports.loadPartialConfigAsync = exports.loadPartialConfigSync = exports.loadPartialConfig = void 0;
|
||||
exports.loadPartialConfigSync = exports.loadPartialConfigAsync = exports.loadPartialConfig = exports.loadOptionsSync = exports.loadOptionsAsync = exports.loadOptions = void 0;
|
||||
|
||||
function _gensync() {
|
||||
const data = _interopRequireDefault(require("gensync"));
|
||||
const data = require("gensync");
|
||||
|
||||
_gensync = function () {
|
||||
return data;
|
||||
@@ -21,19 +23,21 @@ function _gensync() {
|
||||
return data;
|
||||
}
|
||||
|
||||
var _full = _interopRequireDefault(require("./full"));
|
||||
var _full = require("./full");
|
||||
|
||||
var _partial = require("./partial");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
var _item = require("./item");
|
||||
|
||||
const loadOptionsRunner = (0, _gensync().default)(function* (opts) {
|
||||
const loadOptionsRunner = _gensync()(function* (opts) {
|
||||
var _config$options;
|
||||
|
||||
const config = yield* (0, _full.default)(opts);
|
||||
return (_config$options = config == null ? void 0 : config.options) != null ? _config$options : null;
|
||||
});
|
||||
|
||||
const createConfigItemRunner = _gensync()(_item.createConfigItem);
|
||||
|
||||
const maybeErrback = runner => (opts, callback) => {
|
||||
if (callback === undefined && typeof opts === "function") {
|
||||
callback = opts;
|
||||
@@ -54,4 +58,20 @@ exports.loadOptions = loadOptions;
|
||||
const loadOptionsSync = loadOptionsRunner.sync;
|
||||
exports.loadOptionsSync = loadOptionsSync;
|
||||
const loadOptionsAsync = loadOptionsRunner.async;
|
||||
exports.loadOptionsAsync = loadOptionsAsync;
|
||||
exports.loadOptionsAsync = loadOptionsAsync;
|
||||
const createConfigItemSync = createConfigItemRunner.sync;
|
||||
exports.createConfigItemSync = createConfigItemSync;
|
||||
const createConfigItemAsync = createConfigItemRunner.async;
|
||||
exports.createConfigItemAsync = createConfigItemAsync;
|
||||
|
||||
function createConfigItem(target, options, callback) {
|
||||
if (callback !== undefined) {
|
||||
return createConfigItemRunner.errback(target, options, callback);
|
||||
} else if (typeof options === "function") {
|
||||
return createConfigItemRunner.errback(target, undefined, callback);
|
||||
} else {
|
||||
return createConfigItemRunner.sync(target, options);
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+19
-8
@@ -3,12 +3,12 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.createItemFromDescriptor = createItemFromDescriptor;
|
||||
exports.createConfigItem = createConfigItem;
|
||||
exports.createItemFromDescriptor = createItemFromDescriptor;
|
||||
exports.getItemDescriptor = getItemDescriptor;
|
||||
|
||||
function _path() {
|
||||
const data = _interopRequireDefault(require("path"));
|
||||
const data = require("path");
|
||||
|
||||
_path = function () {
|
||||
return data;
|
||||
@@ -19,17 +19,15 @@ function _path() {
|
||||
|
||||
var _configDescriptors = require("./config-descriptors");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function createItemFromDescriptor(desc) {
|
||||
return new ConfigItem(desc);
|
||||
}
|
||||
|
||||
function createConfigItem(value, {
|
||||
function* createConfigItem(value, {
|
||||
dirname = ".",
|
||||
type
|
||||
} = {}) {
|
||||
const descriptor = (0, _configDescriptors.createDescriptor)(value, _path().default.resolve(dirname), {
|
||||
const descriptor = yield* (0, _configDescriptors.createDescriptor)(value, _path().resolve(dirname), {
|
||||
type,
|
||||
alias: "programmatic item"
|
||||
});
|
||||
@@ -37,19 +35,31 @@ function createConfigItem(value, {
|
||||
}
|
||||
|
||||
function getItemDescriptor(item) {
|
||||
if (item instanceof ConfigItem) {
|
||||
if (item != null && item[CONFIG_ITEM_BRAND]) {
|
||||
return item._descriptor;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const CONFIG_ITEM_BRAND = Symbol.for("@babel/core@7 - ConfigItem");
|
||||
|
||||
class ConfigItem {
|
||||
constructor(descriptor) {
|
||||
this._descriptor = void 0;
|
||||
this[CONFIG_ITEM_BRAND] = true;
|
||||
this.value = void 0;
|
||||
this.options = void 0;
|
||||
this.dirname = void 0;
|
||||
this.name = void 0;
|
||||
this.file = void 0;
|
||||
this._descriptor = descriptor;
|
||||
Object.defineProperty(this, "_descriptor", {
|
||||
enumerable: false
|
||||
});
|
||||
Object.defineProperty(this, CONFIG_ITEM_BRAND, {
|
||||
enumerable: false
|
||||
});
|
||||
this.value = this._descriptor.value;
|
||||
this.options = this._descriptor.options;
|
||||
this.dirname = this._descriptor.dirname;
|
||||
@@ -63,4 +73,5 @@ class ConfigItem {
|
||||
|
||||
}
|
||||
|
||||
Object.freeze(ConfigItem.prototype);
|
||||
Object.freeze(ConfigItem.prototype);
|
||||
0 && 0;
|
||||
+76
-30
@@ -7,7 +7,7 @@ exports.default = loadPrivatePartialConfig;
|
||||
exports.loadPartialConfig = void 0;
|
||||
|
||||
function _path() {
|
||||
const data = _interopRequireDefault(require("path"));
|
||||
const data = require("path");
|
||||
|
||||
_path = function () {
|
||||
return data;
|
||||
@@ -17,7 +17,7 @@ function _path() {
|
||||
}
|
||||
|
||||
function _gensync() {
|
||||
const data = _interopRequireDefault(require("gensync"));
|
||||
const data = require("gensync");
|
||||
|
||||
_gensync = function () {
|
||||
return data;
|
||||
@@ -26,7 +26,7 @@ function _gensync() {
|
||||
return data;
|
||||
}
|
||||
|
||||
var _plugin = _interopRequireDefault(require("./plugin"));
|
||||
var _plugin = require("./plugin");
|
||||
|
||||
var _util = require("./util");
|
||||
|
||||
@@ -40,22 +40,26 @@ var _options = require("./validation/options");
|
||||
|
||||
var _files = require("./files");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
var _resolveTargets = require("./resolve-targets");
|
||||
|
||||
function* resolveRootMode(rootDir, rootMode) {
|
||||
const _excluded = ["showIgnoredFiles"];
|
||||
|
||||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
||||
|
||||
function resolveRootMode(rootDir, rootMode) {
|
||||
switch (rootMode) {
|
||||
case "root":
|
||||
return rootDir;
|
||||
|
||||
case "upward-optional":
|
||||
{
|
||||
const upwardRootDir = yield* (0, _files.findConfigUpwards)(rootDir);
|
||||
const upwardRootDir = (0, _files.findConfigUpwards)(rootDir);
|
||||
return upwardRootDir === null ? rootDir : upwardRootDir;
|
||||
}
|
||||
|
||||
case "upward":
|
||||
{
|
||||
const upwardRootDir = yield* (0, _files.findConfigUpwards)(rootDir);
|
||||
const upwardRootDir = (0, _files.findConfigUpwards)(rootDir);
|
||||
if (upwardRootDir !== null) return upwardRootDir;
|
||||
throw Object.assign(new Error(`Babel was run with rootMode:"upward" but a root could not ` + `be found when searching upward from "${rootDir}".\n` + `One of the following config files must be in the directory tree: ` + `"${_files.ROOT_CONFIG_FILENAMES.join(", ")}".`), {
|
||||
code: "BABEL_ROOT_NOT_FOUND",
|
||||
@@ -79,67 +83,108 @@ function* loadPrivatePartialConfig(inputOpts) {
|
||||
cwd = ".",
|
||||
root: rootDir = ".",
|
||||
rootMode = "root",
|
||||
caller
|
||||
caller,
|
||||
cloneInputAst = true
|
||||
} = args;
|
||||
|
||||
const absoluteCwd = _path().default.resolve(cwd);
|
||||
const absoluteCwd = _path().resolve(cwd);
|
||||
|
||||
const absoluteRootDir = yield* resolveRootMode(_path().default.resolve(absoluteCwd, rootDir), rootMode);
|
||||
const absoluteRootDir = resolveRootMode(_path().resolve(absoluteCwd, rootDir), rootMode);
|
||||
const filename = typeof args.filename === "string" ? _path().resolve(cwd, args.filename) : undefined;
|
||||
const showConfigPath = yield* (0, _files.resolveShowConfigPath)(absoluteCwd);
|
||||
const context = {
|
||||
filename: typeof args.filename === "string" ? _path().default.resolve(cwd, args.filename) : undefined,
|
||||
filename,
|
||||
cwd: absoluteCwd,
|
||||
root: absoluteRootDir,
|
||||
envName,
|
||||
caller
|
||||
caller,
|
||||
showConfig: showConfigPath === filename
|
||||
};
|
||||
const configChain = yield* (0, _configChain.buildRootChain)(args, context);
|
||||
if (!configChain) return null;
|
||||
const options = {};
|
||||
const merged = {
|
||||
assumptions: {}
|
||||
};
|
||||
configChain.options.forEach(opts => {
|
||||
(0, _util.mergeOptions)(options, opts);
|
||||
(0, _util.mergeOptions)(merged, opts);
|
||||
});
|
||||
const options = Object.assign({}, merged, {
|
||||
targets: (0, _resolveTargets.resolveTargets)(merged, absoluteRootDir),
|
||||
cloneInputAst,
|
||||
babelrc: false,
|
||||
configFile: false,
|
||||
browserslistConfigFile: false,
|
||||
passPerPreset: false,
|
||||
envName: context.envName,
|
||||
cwd: context.cwd,
|
||||
root: context.root,
|
||||
rootMode: "root",
|
||||
filename: typeof context.filename === "string" ? context.filename : undefined,
|
||||
plugins: configChain.plugins.map(descriptor => (0, _item.createItemFromDescriptor)(descriptor)),
|
||||
presets: configChain.presets.map(descriptor => (0, _item.createItemFromDescriptor)(descriptor))
|
||||
});
|
||||
options.babelrc = false;
|
||||
options.configFile = false;
|
||||
options.passPerPreset = false;
|
||||
options.envName = context.envName;
|
||||
options.cwd = context.cwd;
|
||||
options.root = context.root;
|
||||
options.filename = typeof context.filename === "string" ? context.filename : undefined;
|
||||
options.plugins = configChain.plugins.map(descriptor => (0, _item.createItemFromDescriptor)(descriptor));
|
||||
options.presets = configChain.presets.map(descriptor => (0, _item.createItemFromDescriptor)(descriptor));
|
||||
return {
|
||||
options,
|
||||
context,
|
||||
fileHandling: configChain.fileHandling,
|
||||
ignore: configChain.ignore,
|
||||
babelrc: configChain.babelrc,
|
||||
config: configChain.config
|
||||
config: configChain.config,
|
||||
files: configChain.files
|
||||
};
|
||||
}
|
||||
|
||||
const loadPartialConfig = (0, _gensync().default)(function* (inputOpts) {
|
||||
const result = yield* loadPrivatePartialConfig(inputOpts);
|
||||
const loadPartialConfig = _gensync()(function* (opts) {
|
||||
let showIgnoredFiles = false;
|
||||
|
||||
if (typeof opts === "object" && opts !== null && !Array.isArray(opts)) {
|
||||
var _opts = opts;
|
||||
({
|
||||
showIgnoredFiles
|
||||
} = _opts);
|
||||
opts = _objectWithoutPropertiesLoose(_opts, _excluded);
|
||||
_opts;
|
||||
}
|
||||
|
||||
const result = yield* loadPrivatePartialConfig(opts);
|
||||
if (!result) return null;
|
||||
const {
|
||||
options,
|
||||
babelrc,
|
||||
ignore,
|
||||
config
|
||||
config,
|
||||
fileHandling,
|
||||
files
|
||||
} = result;
|
||||
|
||||
if (fileHandling === "ignored" && !showIgnoredFiles) {
|
||||
return null;
|
||||
}
|
||||
|
||||
(options.plugins || []).forEach(item => {
|
||||
if (item.value instanceof _plugin.default) {
|
||||
throw new Error("Passing cached plugin instances is not supported in " + "babel.loadPartialConfig()");
|
||||
}
|
||||
});
|
||||
return new PartialConfig(options, babelrc ? babelrc.filepath : undefined, ignore ? ignore.filepath : undefined, config ? config.filepath : undefined);
|
||||
return new PartialConfig(options, babelrc ? babelrc.filepath : undefined, ignore ? ignore.filepath : undefined, config ? config.filepath : undefined, fileHandling, files);
|
||||
});
|
||||
|
||||
exports.loadPartialConfig = loadPartialConfig;
|
||||
|
||||
class PartialConfig {
|
||||
constructor(options, babelrc, ignore, config) {
|
||||
constructor(options, babelrc, ignore, config, fileHandling, files) {
|
||||
this.options = void 0;
|
||||
this.babelrc = void 0;
|
||||
this.babelignore = void 0;
|
||||
this.config = void 0;
|
||||
this.fileHandling = void 0;
|
||||
this.files = void 0;
|
||||
this.options = options;
|
||||
this.babelignore = ignore;
|
||||
this.babelrc = babelrc;
|
||||
this.config = config;
|
||||
this.fileHandling = fileHandling;
|
||||
this.files = files;
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
@@ -149,4 +194,5 @@ class PartialConfig {
|
||||
|
||||
}
|
||||
|
||||
Object.freeze(PartialConfig.prototype);
|
||||
Object.freeze(PartialConfig.prototype);
|
||||
0 && 0;
|
||||
+12
-18
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
||||
exports.default = pathToPattern;
|
||||
|
||||
function _path() {
|
||||
const data = _interopRequireDefault(require("path"));
|
||||
const data = require("path");
|
||||
|
||||
_path = function () {
|
||||
return data;
|
||||
@@ -15,19 +15,7 @@ function _path() {
|
||||
return data;
|
||||
}
|
||||
|
||||
function _escapeRegExp() {
|
||||
const data = _interopRequireDefault(require("lodash/escapeRegExp"));
|
||||
|
||||
_escapeRegExp = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const sep = `\\${_path().default.sep}`;
|
||||
const sep = `\\${_path().sep}`;
|
||||
const endSep = `(?:${sep}|$)`;
|
||||
const substitution = `[^${sep}]+`;
|
||||
const starPat = `(?:${substitution}${sep})`;
|
||||
@@ -35,8 +23,12 @@ const starPatLast = `(?:${substitution}${endSep})`;
|
||||
const starStarPat = `${starPat}*?`;
|
||||
const starStarPatLast = `${starPat}*?${starPatLast}?`;
|
||||
|
||||
function escapeRegExp(string) {
|
||||
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
|
||||
}
|
||||
|
||||
function pathToPattern(pattern, dirname) {
|
||||
const parts = _path().default.resolve(dirname, pattern).split(_path().default.sep);
|
||||
const parts = _path().resolve(dirname, pattern).split(_path().sep);
|
||||
|
||||
return new RegExp(["^", ...parts.map((part, i) => {
|
||||
const last = i === parts.length - 1;
|
||||
@@ -44,9 +36,11 @@ function pathToPattern(pattern, dirname) {
|
||||
if (part === "*") return last ? starPatLast : starPat;
|
||||
|
||||
if (part.indexOf("*.") === 0) {
|
||||
return substitution + (0, _escapeRegExp().default)(part.slice(1)) + (last ? endSep : sep);
|
||||
return substitution + escapeRegExp(part.slice(1)) + (last ? endSep : sep);
|
||||
}
|
||||
|
||||
return (0, _escapeRegExp().default)(part) + (last ? endSep : sep);
|
||||
return escapeRegExp(part) + (last ? endSep : sep);
|
||||
})].join(""));
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+15
-2
@@ -5,8 +5,19 @@ Object.defineProperty(exports, "__esModule", {
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _deepArray = require("./helpers/deep-array");
|
||||
|
||||
class Plugin {
|
||||
constructor(plugin, options, key) {
|
||||
constructor(plugin, options, key, externalDependencies = (0, _deepArray.finalize)([])) {
|
||||
this.key = void 0;
|
||||
this.manipulateOptions = void 0;
|
||||
this.post = void 0;
|
||||
this.pre = void 0;
|
||||
this.visitor = void 0;
|
||||
this.parserOverride = void 0;
|
||||
this.generatorOverride = void 0;
|
||||
this.options = void 0;
|
||||
this.externalDependencies = void 0;
|
||||
this.key = plugin.name || key;
|
||||
this.manipulateOptions = plugin.manipulateOptions;
|
||||
this.post = plugin.post;
|
||||
@@ -15,8 +26,10 @@ class Plugin {
|
||||
this.parserOverride = plugin.parserOverride;
|
||||
this.generatorOverride = plugin.generatorOverride;
|
||||
this.options = options;
|
||||
this.externalDependencies = externalDependencies;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = Plugin;
|
||||
exports.default = Plugin;
|
||||
0 && 0;
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.ConfigPrinter = exports.ChainFormatter = void 0;
|
||||
|
||||
function _gensync() {
|
||||
const data = require("gensync");
|
||||
|
||||
_gensync = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
const ChainFormatter = {
|
||||
Programmatic: 0,
|
||||
Config: 1
|
||||
};
|
||||
exports.ChainFormatter = ChainFormatter;
|
||||
const Formatter = {
|
||||
title(type, callerName, filepath) {
|
||||
let title = "";
|
||||
|
||||
if (type === ChainFormatter.Programmatic) {
|
||||
title = "programmatic options";
|
||||
|
||||
if (callerName) {
|
||||
title += " from " + callerName;
|
||||
}
|
||||
} else {
|
||||
title = "config " + filepath;
|
||||
}
|
||||
|
||||
return title;
|
||||
},
|
||||
|
||||
loc(index, envName) {
|
||||
let loc = "";
|
||||
|
||||
if (index != null) {
|
||||
loc += `.overrides[${index}]`;
|
||||
}
|
||||
|
||||
if (envName != null) {
|
||||
loc += `.env["${envName}"]`;
|
||||
}
|
||||
|
||||
return loc;
|
||||
},
|
||||
|
||||
*optionsAndDescriptors(opt) {
|
||||
const content = Object.assign({}, opt.options);
|
||||
delete content.overrides;
|
||||
delete content.env;
|
||||
const pluginDescriptors = [...(yield* opt.plugins())];
|
||||
|
||||
if (pluginDescriptors.length) {
|
||||
content.plugins = pluginDescriptors.map(d => descriptorToConfig(d));
|
||||
}
|
||||
|
||||
const presetDescriptors = [...(yield* opt.presets())];
|
||||
|
||||
if (presetDescriptors.length) {
|
||||
content.presets = [...presetDescriptors].map(d => descriptorToConfig(d));
|
||||
}
|
||||
|
||||
return JSON.stringify(content, undefined, 2);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function descriptorToConfig(d) {
|
||||
var _d$file;
|
||||
|
||||
let name = (_d$file = d.file) == null ? void 0 : _d$file.request;
|
||||
|
||||
if (name == null) {
|
||||
if (typeof d.value === "object") {
|
||||
name = d.value;
|
||||
} else if (typeof d.value === "function") {
|
||||
name = `[Function: ${d.value.toString().slice(0, 50)} ... ]`;
|
||||
}
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
name = "[Unknown]";
|
||||
}
|
||||
|
||||
if (d.options === undefined) {
|
||||
return name;
|
||||
} else if (d.name == null) {
|
||||
return [name, d.options];
|
||||
} else {
|
||||
return [name, d.options, d.name];
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigPrinter {
|
||||
constructor() {
|
||||
this._stack = [];
|
||||
}
|
||||
|
||||
configure(enabled, type, {
|
||||
callerName,
|
||||
filepath
|
||||
}) {
|
||||
if (!enabled) return () => {};
|
||||
return (content, index, envName) => {
|
||||
this._stack.push({
|
||||
type,
|
||||
callerName,
|
||||
filepath,
|
||||
content,
|
||||
index,
|
||||
envName
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
static *format(config) {
|
||||
let title = Formatter.title(config.type, config.callerName, config.filepath);
|
||||
const loc = Formatter.loc(config.index, config.envName);
|
||||
if (loc) title += ` ${loc}`;
|
||||
const content = yield* Formatter.optionsAndDescriptors(config.content);
|
||||
return `${title}\n${content}`;
|
||||
}
|
||||
|
||||
*output() {
|
||||
if (this._stack.length === 0) return "";
|
||||
const configs = yield* _gensync().all(this._stack.map(s => ConfigPrinter.format(s)));
|
||||
return configs.join("\n\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.ConfigPrinter = ConfigPrinter;
|
||||
0 && 0;
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.resolveBrowserslistConfigFile = resolveBrowserslistConfigFile;
|
||||
exports.resolveTargets = resolveTargets;
|
||||
|
||||
function _helperCompilationTargets() {
|
||||
const data = require("@babel/helper-compilation-targets");
|
||||
|
||||
_helperCompilationTargets = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function resolveBrowserslistConfigFile(browserslistConfigFile, configFilePath) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function resolveTargets(options, root) {
|
||||
const optTargets = options.targets;
|
||||
let targets;
|
||||
|
||||
if (typeof optTargets === "string" || Array.isArray(optTargets)) {
|
||||
targets = {
|
||||
browsers: optTargets
|
||||
};
|
||||
} else if (optTargets) {
|
||||
if ("esmodules" in optTargets) {
|
||||
targets = Object.assign({}, optTargets, {
|
||||
esmodules: "intersect"
|
||||
});
|
||||
} else {
|
||||
targets = optTargets;
|
||||
}
|
||||
}
|
||||
|
||||
return (0, _helperCompilationTargets().default)(targets, {
|
||||
ignoreBrowserslistConfig: true,
|
||||
browserslistEnv: options.browserslistEnv
|
||||
});
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.resolveBrowserslistConfigFile = resolveBrowserslistConfigFile;
|
||||
exports.resolveTargets = resolveTargets;
|
||||
|
||||
function _path() {
|
||||
const data = require("path");
|
||||
|
||||
_path = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _helperCompilationTargets() {
|
||||
const data = require("@babel/helper-compilation-targets");
|
||||
|
||||
_helperCompilationTargets = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
({});
|
||||
|
||||
function resolveBrowserslistConfigFile(browserslistConfigFile, configFileDir) {
|
||||
return _path().resolve(configFileDir, browserslistConfigFile);
|
||||
}
|
||||
|
||||
function resolveTargets(options, root) {
|
||||
const optTargets = options.targets;
|
||||
let targets;
|
||||
|
||||
if (typeof optTargets === "string" || Array.isArray(optTargets)) {
|
||||
targets = {
|
||||
browsers: optTargets
|
||||
};
|
||||
} else if (optTargets) {
|
||||
if ("esmodules" in optTargets) {
|
||||
targets = Object.assign({}, optTargets, {
|
||||
esmodules: "intersect"
|
||||
});
|
||||
} else {
|
||||
targets = optTargets;
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
browserslistConfigFile
|
||||
} = options;
|
||||
let configFile;
|
||||
let ignoreBrowserslistConfig = false;
|
||||
|
||||
if (typeof browserslistConfigFile === "string") {
|
||||
configFile = browserslistConfigFile;
|
||||
} else {
|
||||
ignoreBrowserslistConfig = browserslistConfigFile === false;
|
||||
}
|
||||
|
||||
return (0, _helperCompilationTargets().default)(targets, {
|
||||
ignoreBrowserslistConfig,
|
||||
configFile,
|
||||
configPath: root,
|
||||
browserslistEnv: options.browserslistEnv
|
||||
});
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+7
-9
@@ -3,19 +3,15 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.mergeOptions = mergeOptions;
|
||||
exports.isIterableIterator = isIterableIterator;
|
||||
exports.mergeOptions = mergeOptions;
|
||||
|
||||
function mergeOptions(target, source) {
|
||||
for (const k of Object.keys(source)) {
|
||||
if (k === "parserOpts" && source.parserOpts) {
|
||||
const parserOpts = source.parserOpts;
|
||||
const targetObj = target.parserOpts = target.parserOpts || {};
|
||||
if ((k === "parserOpts" || k === "generatorOpts" || k === "assumptions") && source[k]) {
|
||||
const parserOpts = source[k];
|
||||
const targetObj = target[k] || (target[k] = {});
|
||||
mergeDefaultFields(targetObj, parserOpts);
|
||||
} else if (k === "generatorOpts" && source.generatorOpts) {
|
||||
const generatorOpts = source.generatorOpts;
|
||||
const targetObj = target.generatorOpts = target.generatorOpts || {};
|
||||
mergeDefaultFields(targetObj, generatorOpts);
|
||||
} else {
|
||||
const val = source[k];
|
||||
if (val !== undefined) target[k] = val;
|
||||
@@ -32,4 +28,6 @@ function mergeDefaultFields(target, source) {
|
||||
|
||||
function isIterableIterator(value) {
|
||||
return !!value && typeof value.next === "function" && typeof value[Symbol.iterator] === "function";
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+101
-15
@@ -3,24 +3,38 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.msg = msg;
|
||||
exports.access = access;
|
||||
exports.assertRootMode = assertRootMode;
|
||||
exports.assertSourceMaps = assertSourceMaps;
|
||||
exports.assertCompact = assertCompact;
|
||||
exports.assertSourceType = assertSourceType;
|
||||
exports.assertCallerMetadata = assertCallerMetadata;
|
||||
exports.assertInputSourceMap = assertInputSourceMap;
|
||||
exports.assertString = assertString;
|
||||
exports.assertFunction = assertFunction;
|
||||
exports.assertBoolean = assertBoolean;
|
||||
exports.assertObject = assertObject;
|
||||
exports.assertArray = assertArray;
|
||||
exports.assertIgnoreList = assertIgnoreList;
|
||||
exports.assertAssumptions = assertAssumptions;
|
||||
exports.assertBabelrcSearch = assertBabelrcSearch;
|
||||
exports.assertBoolean = assertBoolean;
|
||||
exports.assertCallerMetadata = assertCallerMetadata;
|
||||
exports.assertCompact = assertCompact;
|
||||
exports.assertConfigApplicableTest = assertConfigApplicableTest;
|
||||
exports.assertConfigFileSearch = assertConfigFileSearch;
|
||||
exports.assertBabelrcSearch = assertBabelrcSearch;
|
||||
exports.assertFunction = assertFunction;
|
||||
exports.assertIgnoreList = assertIgnoreList;
|
||||
exports.assertInputSourceMap = assertInputSourceMap;
|
||||
exports.assertObject = assertObject;
|
||||
exports.assertPluginList = assertPluginList;
|
||||
exports.assertRootMode = assertRootMode;
|
||||
exports.assertSourceMaps = assertSourceMaps;
|
||||
exports.assertSourceType = assertSourceType;
|
||||
exports.assertString = assertString;
|
||||
exports.assertTargets = assertTargets;
|
||||
exports.msg = msg;
|
||||
|
||||
function _helperCompilationTargets() {
|
||||
const data = require("@babel/helper-compilation-targets");
|
||||
|
||||
_helperCompilationTargets = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
var _options = require("./options");
|
||||
|
||||
function msg(loc) {
|
||||
switch (loc.type) {
|
||||
@@ -88,7 +102,7 @@ function assertCallerMetadata(loc, value) {
|
||||
const obj = assertObject(loc, value);
|
||||
|
||||
if (obj) {
|
||||
if (typeof obj["name"] !== "string") {
|
||||
if (typeof obj.name !== "string") {
|
||||
throw new Error(`${msg(loc)} set but does not contain "name" property string`);
|
||||
}
|
||||
|
||||
@@ -265,4 +279,76 @@ function assertPluginTarget(loc, value) {
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
function assertTargets(loc, value) {
|
||||
if ((0, _helperCompilationTargets().isBrowsersQueryValid)(value)) return value;
|
||||
|
||||
if (typeof value !== "object" || !value || Array.isArray(value)) {
|
||||
throw new Error(`${msg(loc)} must be a string, an array of strings or an object`);
|
||||
}
|
||||
|
||||
const browsersLoc = access(loc, "browsers");
|
||||
const esmodulesLoc = access(loc, "esmodules");
|
||||
assertBrowsersList(browsersLoc, value.browsers);
|
||||
assertBoolean(esmodulesLoc, value.esmodules);
|
||||
|
||||
for (const key of Object.keys(value)) {
|
||||
const val = value[key];
|
||||
const subLoc = access(loc, key);
|
||||
if (key === "esmodules") assertBoolean(subLoc, val);else if (key === "browsers") assertBrowsersList(subLoc, val);else if (!Object.hasOwnProperty.call(_helperCompilationTargets().TargetNames, key)) {
|
||||
const validTargets = Object.keys(_helperCompilationTargets().TargetNames).join(", ");
|
||||
throw new Error(`${msg(subLoc)} is not a valid target. Supported targets are ${validTargets}`);
|
||||
} else assertBrowserVersion(subLoc, val);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function assertBrowsersList(loc, value) {
|
||||
if (value !== undefined && !(0, _helperCompilationTargets().isBrowsersQueryValid)(value)) {
|
||||
throw new Error(`${msg(loc)} must be undefined, a string or an array of strings`);
|
||||
}
|
||||
}
|
||||
|
||||
function assertBrowserVersion(loc, value) {
|
||||
if (typeof value === "number" && Math.round(value) === value) return;
|
||||
if (typeof value === "string") return;
|
||||
throw new Error(`${msg(loc)} must be a string or an integer number`);
|
||||
}
|
||||
|
||||
function assertAssumptions(loc, value) {
|
||||
if (value === undefined) return;
|
||||
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${msg(loc)} must be an object or undefined.`);
|
||||
}
|
||||
|
||||
let root = loc;
|
||||
|
||||
do {
|
||||
root = root.parent;
|
||||
} while (root.type !== "root");
|
||||
|
||||
const inPreset = root.source === "preset";
|
||||
|
||||
for (const name of Object.keys(value)) {
|
||||
const subLoc = access(loc, name);
|
||||
|
||||
if (!_options.assumptionsNames.has(name)) {
|
||||
throw new Error(`${msg(subLoc)} is not a supported assumption.`);
|
||||
}
|
||||
|
||||
if (typeof value[name] !== "boolean") {
|
||||
throw new Error(`${msg(subLoc)} must be a boolean.`);
|
||||
}
|
||||
|
||||
if (inPreset && value[name] === false) {
|
||||
throw new Error(`${msg(subLoc)} cannot be set to 'false' inside presets.`);
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+30
-13
@@ -3,17 +3,16 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.validate = validate;
|
||||
exports.assumptionsNames = void 0;
|
||||
exports.checkNoUnwrappedItemOptionPairs = checkNoUnwrappedItemOptionPairs;
|
||||
exports.validate = validate;
|
||||
|
||||
var _plugin = _interopRequireDefault(require("../plugin"));
|
||||
var _plugin = require("../plugin");
|
||||
|
||||
var _removed = _interopRequireDefault(require("./removed"));
|
||||
var _removed = require("./removed");
|
||||
|
||||
var _optionAssertions = require("./option-assertions");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const ROOT_VALIDATORS = {
|
||||
cwd: _optionAssertions.assertString,
|
||||
root: _optionAssertions.assertString,
|
||||
@@ -24,6 +23,7 @@ const ROOT_VALIDATORS = {
|
||||
filenameRelative: _optionAssertions.assertString,
|
||||
code: _optionAssertions.assertBoolean,
|
||||
ast: _optionAssertions.assertBoolean,
|
||||
cloneInputAst: _optionAssertions.assertBoolean,
|
||||
envName: _optionAssertions.assertString
|
||||
};
|
||||
const BABELRC_VALIDATORS = {
|
||||
@@ -33,13 +33,17 @@ const BABELRC_VALIDATORS = {
|
||||
const NONPRESET_VALIDATORS = {
|
||||
extends: _optionAssertions.assertString,
|
||||
ignore: _optionAssertions.assertIgnoreList,
|
||||
only: _optionAssertions.assertIgnoreList
|
||||
only: _optionAssertions.assertIgnoreList,
|
||||
targets: _optionAssertions.assertTargets,
|
||||
browserslistConfigFile: _optionAssertions.assertConfigFileSearch,
|
||||
browserslistEnv: _optionAssertions.assertString
|
||||
};
|
||||
const COMMON_VALIDATORS = {
|
||||
inputSourceMap: _optionAssertions.assertInputSourceMap,
|
||||
presets: _optionAssertions.assertPluginList,
|
||||
plugins: _optionAssertions.assertPluginList,
|
||||
passPerPreset: _optionAssertions.assertBoolean,
|
||||
assumptions: _optionAssertions.assertAssumptions,
|
||||
env: assertEnvSet,
|
||||
overrides: assertOverridesList,
|
||||
test: _optionAssertions.assertConfigApplicableTest,
|
||||
@@ -59,13 +63,20 @@ const COMMON_VALIDATORS = {
|
||||
sourceMap: _optionAssertions.assertSourceMaps,
|
||||
sourceFileName: _optionAssertions.assertString,
|
||||
sourceRoot: _optionAssertions.assertString,
|
||||
getModuleId: _optionAssertions.assertFunction,
|
||||
moduleRoot: _optionAssertions.assertString,
|
||||
moduleIds: _optionAssertions.assertBoolean,
|
||||
moduleId: _optionAssertions.assertString,
|
||||
parserOpts: _optionAssertions.assertObject,
|
||||
generatorOpts: _optionAssertions.assertObject
|
||||
};
|
||||
{
|
||||
Object.assign(COMMON_VALIDATORS, {
|
||||
getModuleId: _optionAssertions.assertFunction,
|
||||
moduleRoot: _optionAssertions.assertString,
|
||||
moduleIds: _optionAssertions.assertBoolean,
|
||||
moduleId: _optionAssertions.assertString
|
||||
});
|
||||
}
|
||||
const knownAssumptions = ["arrayLikeIsIterable", "constantReexports", "constantSuper", "enumerableModuleMeta", "ignoreFunctionLength", "ignoreToPrimitiveHint", "iterableIsArray", "mutableTemplateObject", "noClassCalls", "noDocumentAll", "noIncompleteNsImportDetection", "noNewArrows", "objectRestNoSymbols", "privateFieldsAsProperties", "pureGetters", "setClassMethods", "setComputedProperties", "setPublicClassFields", "setSpreadProperties", "skipForOfIteratorClosing", "superIsCallableConstructor"];
|
||||
const assumptionsNames = new Set(knownAssumptions);
|
||||
exports.assumptionsNames = assumptionsNames;
|
||||
|
||||
function getSource(loc) {
|
||||
return loc.type === "root" ? loc.source : getSource(loc.parent);
|
||||
@@ -189,8 +200,14 @@ function assertOverridesList(loc, value) {
|
||||
return arr;
|
||||
}
|
||||
|
||||
function checkNoUnwrappedItemOptionPairs(lastItem, thisItem, type, index, e) {
|
||||
function checkNoUnwrappedItemOptionPairs(items, index, type, e) {
|
||||
if (index === 0) return;
|
||||
const lastItem = items[index - 1];
|
||||
const thisItem = items[index];
|
||||
|
||||
if (lastItem.file && lastItem.options === undefined && typeof thisItem.value === "object") {
|
||||
e.message += `\n- Maybe you meant to use\n` + `"${type}": [\n ["${lastItem.file.request}", ${JSON.stringify(thisItem.value, undefined, 2)}]\n]\n` + `To be a valid ${type}, its name and options should be wrapped in a pair of brackets`;
|
||||
e.message += `\n- Maybe you meant to use\n` + `"${type}s": [\n ["${lastItem.file.request}", ${JSON.stringify(thisItem.value, undefined, 2)}]\n]\n` + `To be a valid ${type}, its name and options should be wrapped in a pair of brackets`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+3
-1
@@ -68,4 +68,6 @@ function validatePluginObject(obj) {
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+2
-1
@@ -63,4 +63,5 @@ var _default = {
|
||||
message: "The `sourceMapTarget` option has been removed because it makes more sense for the tooling " + "that calls Babel to assign `map.file` themselves."
|
||||
}
|
||||
};
|
||||
exports.default = _default;
|
||||
exports.default = _default;
|
||||
0 && 0;
|
||||
+20
-13
@@ -3,13 +3,14 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.maybeAsync = maybeAsync;
|
||||
exports.forwardAsync = forwardAsync;
|
||||
exports.isAsync = void 0;
|
||||
exports.isThenable = isThenable;
|
||||
exports.waitFor = exports.onFirstPause = exports.isAsync = void 0;
|
||||
exports.maybeAsync = maybeAsync;
|
||||
exports.waitFor = exports.onFirstPause = void 0;
|
||||
|
||||
function _gensync() {
|
||||
const data = _interopRequireDefault(require("gensync"));
|
||||
const data = require("gensync");
|
||||
|
||||
_gensync = function () {
|
||||
return data;
|
||||
@@ -18,21 +19,21 @@ function _gensync() {
|
||||
return data;
|
||||
}
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const id = x => x;
|
||||
|
||||
const runGenerator = (0, _gensync().default)(function* (item) {
|
||||
const runGenerator = _gensync()(function* (item) {
|
||||
return yield* item;
|
||||
});
|
||||
const isAsync = (0, _gensync().default)({
|
||||
|
||||
const isAsync = _gensync()({
|
||||
sync: () => false,
|
||||
errback: cb => cb(null, true)
|
||||
});
|
||||
|
||||
exports.isAsync = isAsync;
|
||||
|
||||
function maybeAsync(fn, message) {
|
||||
return (0, _gensync().default)({
|
||||
return _gensync()({
|
||||
sync(...args) {
|
||||
const result = fn.apply(this, args);
|
||||
if (isThenable(result)) throw new Error(message);
|
||||
@@ -46,20 +47,21 @@ function maybeAsync(fn, message) {
|
||||
});
|
||||
}
|
||||
|
||||
const withKind = (0, _gensync().default)({
|
||||
const withKind = _gensync()({
|
||||
sync: cb => cb("sync"),
|
||||
async: cb => cb("async")
|
||||
});
|
||||
|
||||
function forwardAsync(action, cb) {
|
||||
const g = (0, _gensync().default)(action);
|
||||
const g = _gensync()(action);
|
||||
|
||||
return withKind(kind => {
|
||||
const adapted = g[kind];
|
||||
return cb(adapted);
|
||||
});
|
||||
}
|
||||
|
||||
const onFirstPause = (0, _gensync().default)({
|
||||
const onFirstPause = _gensync()({
|
||||
name: "onFirstPause",
|
||||
arity: 2,
|
||||
sync: function (item) {
|
||||
@@ -77,13 +79,18 @@ const onFirstPause = (0, _gensync().default)({
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
exports.onFirstPause = onFirstPause;
|
||||
const waitFor = (0, _gensync().default)({
|
||||
|
||||
const waitFor = _gensync()({
|
||||
sync: id,
|
||||
async: id
|
||||
});
|
||||
|
||||
exports.waitFor = waitFor;
|
||||
|
||||
function isThenable(val) {
|
||||
return !!val && (typeof val === "object" || typeof val === "function") && !!val.then && typeof val.then === "function";
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+13
-20
@@ -3,10 +3,10 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.exists = exports.readFile = void 0;
|
||||
exports.stat = exports.readFile = void 0;
|
||||
|
||||
function _fs() {
|
||||
const data = _interopRequireDefault(require("fs"));
|
||||
const data = require("fs");
|
||||
|
||||
_fs = function () {
|
||||
return data;
|
||||
@@ -16,7 +16,7 @@ function _fs() {
|
||||
}
|
||||
|
||||
function _gensync() {
|
||||
const data = _interopRequireDefault(require("gensync"));
|
||||
const data = require("gensync");
|
||||
|
||||
_gensync = function () {
|
||||
return data;
|
||||
@@ -25,24 +25,17 @@ function _gensync() {
|
||||
return data;
|
||||
}
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const readFile = (0, _gensync().default)({
|
||||
sync: _fs().default.readFileSync,
|
||||
errback: _fs().default.readFile
|
||||
const readFile = _gensync()({
|
||||
sync: _fs().readFileSync,
|
||||
errback: _fs().readFile
|
||||
});
|
||||
|
||||
exports.readFile = readFile;
|
||||
const exists = (0, _gensync().default)({
|
||||
sync(path) {
|
||||
try {
|
||||
_fs().default.accessSync(path);
|
||||
|
||||
return true;
|
||||
} catch (_unused) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
errback: (path, cb) => _fs().default.access(path, undefined, err => cb(null, !err))
|
||||
const stat = _gensync()({
|
||||
sync: _fs().statSync,
|
||||
errback: _fs().stat
|
||||
});
|
||||
exports.exists = exists;
|
||||
|
||||
exports.stat = stat;
|
||||
0 && 0;
|
||||
+110
-108
@@ -3,19 +3,99 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.Plugin = Plugin;
|
||||
exports.DEFAULT_EXTENSIONS = void 0;
|
||||
Object.defineProperty(exports, "File", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _file.default;
|
||||
}
|
||||
});
|
||||
exports.OptionManager = void 0;
|
||||
exports.Plugin = Plugin;
|
||||
Object.defineProperty(exports, "buildExternalHelpers", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _buildExternalHelpers.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "createConfigItem", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _config.createConfigItem;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "createConfigItemAsync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _config.createConfigItemAsync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "createConfigItemSync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _config.createConfigItemSync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "getEnv", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _environment.getEnv;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "loadOptions", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _config.loadOptions;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "loadOptionsAsync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _config.loadOptionsAsync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "loadOptionsSync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _config.loadOptionsSync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "loadPartialConfig", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _config.loadPartialConfig;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "loadPartialConfigAsync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _config.loadPartialConfigAsync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "loadPartialConfigSync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _config.loadPartialConfigSync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "parse", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _parse.parse;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "parseAsync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _parse.parseAsync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "parseSync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _parse.parseSync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "resolvePlugin", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
@@ -28,76 +108,16 @@ Object.defineProperty(exports, "resolvePreset", {
|
||||
return _files.resolvePreset;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "version", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _package.version;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "getEnv", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _environment.getEnv;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "tokTypes", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _parser().tokTypes;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "traverse", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _traverse().default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "template", {
|
||||
Object.defineProperty((0, exports), "template", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _template().default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "createConfigItem", {
|
||||
Object.defineProperty((0, exports), "tokTypes", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _item.createConfigItem;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "loadPartialConfig", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _config.loadPartialConfig;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "loadPartialConfigSync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _config.loadPartialConfigSync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "loadPartialConfigAsync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _config.loadPartialConfigAsync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "loadOptions", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _config.loadOptions;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "loadOptionsSync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _config.loadOptionsSync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "loadOptionsAsync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _config.loadOptionsAsync;
|
||||
return _parser().tokTypes;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "transform", {
|
||||
@@ -106,12 +126,6 @@ Object.defineProperty(exports, "transform", {
|
||||
return _transform.transform;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "transformSync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _transform.transformSync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "transformAsync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
@@ -124,68 +138,60 @@ Object.defineProperty(exports, "transformFile", {
|
||||
return _transformFile.transformFile;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "transformFileSync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _transformFile.transformFileSync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "transformFileAsync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _transformFile.transformFileAsync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "transformFileSync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _transformFile.transformFileSync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "transformFromAst", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _transformAst.transformFromAst;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "transformFromAstSync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _transformAst.transformFromAstSync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "transformFromAstAsync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _transformAst.transformFromAstAsync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "parse", {
|
||||
Object.defineProperty(exports, "transformFromAstSync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _parse.parse;
|
||||
return _transformAst.transformFromAstSync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "parseSync", {
|
||||
Object.defineProperty(exports, "transformSync", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _parse.parseSync;
|
||||
return _transform.transformSync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "parseAsync", {
|
||||
Object.defineProperty((0, exports), "traverse", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _parse.parseAsync;
|
||||
return _traverse().default;
|
||||
}
|
||||
});
|
||||
exports.types = exports.OptionManager = exports.DEFAULT_EXTENSIONS = void 0;
|
||||
exports.version = exports.types = void 0;
|
||||
|
||||
var _file = _interopRequireDefault(require("./transformation/file/file"));
|
||||
var _file = require("./transformation/file/file");
|
||||
|
||||
var _buildExternalHelpers = _interopRequireDefault(require("./tools/build-external-helpers"));
|
||||
var _buildExternalHelpers = require("./tools/build-external-helpers");
|
||||
|
||||
var _files = require("./config/files");
|
||||
|
||||
var _package = require("../package.json");
|
||||
|
||||
var _environment = require("./config/helpers/environment");
|
||||
|
||||
function _types() {
|
||||
const data = _interopRequireWildcard(require("@babel/types"));
|
||||
const data = require("@babel/types");
|
||||
|
||||
_types = function () {
|
||||
return data;
|
||||
@@ -194,7 +200,7 @@ function _types() {
|
||||
return data;
|
||||
}
|
||||
|
||||
Object.defineProperty(exports, "types", {
|
||||
Object.defineProperty((0, exports), "types", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _types();
|
||||
@@ -212,7 +218,7 @@ function _parser() {
|
||||
}
|
||||
|
||||
function _traverse() {
|
||||
const data = _interopRequireDefault(require("@babel/traverse"));
|
||||
const data = require("@babel/traverse");
|
||||
|
||||
_traverse = function () {
|
||||
return data;
|
||||
@@ -222,7 +228,7 @@ function _traverse() {
|
||||
}
|
||||
|
||||
function _template() {
|
||||
const data = _interopRequireDefault(require("@babel/template"));
|
||||
const data = require("@babel/template");
|
||||
|
||||
_template = function () {
|
||||
return data;
|
||||
@@ -231,8 +237,6 @@ function _template() {
|
||||
return data;
|
||||
}
|
||||
|
||||
var _item = require("./config/item");
|
||||
|
||||
var _config = require("./config");
|
||||
|
||||
var _transform = require("./transform");
|
||||
@@ -243,18 +247,14 @@ var _transformAst = require("./transform-ast");
|
||||
|
||||
var _parse = require("./parse");
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const DEFAULT_EXTENSIONS = Object.freeze([".js", ".jsx", ".es6", ".es", ".mjs"]);
|
||||
const version = "7.18.6";
|
||||
exports.version = version;
|
||||
const DEFAULT_EXTENSIONS = Object.freeze([".js", ".jsx", ".es6", ".es", ".mjs", ".cjs"]);
|
||||
exports.DEFAULT_EXTENSIONS = DEFAULT_EXTENSIONS;
|
||||
|
||||
class OptionManager {
|
||||
init(opts) {
|
||||
return (0, _config.loadOptions)(opts);
|
||||
return (0, _config.loadOptionsSync)(opts);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -263,4 +263,6 @@ exports.OptionManager = OptionManager;
|
||||
|
||||
function Plugin(alias) {
|
||||
throw new Error(`The (${alias}) Babel 5 plugin is being run with an unsupported Babel version.`);
|
||||
}
|
||||
}
|
||||
|
||||
0 && (exports.types = exports.traverse = exports.tokTypes = exports.template = 0);
|
||||
+14
-10
@@ -3,10 +3,10 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.parseAsync = exports.parseSync = exports.parse = void 0;
|
||||
exports.parseSync = exports.parseAsync = exports.parse = void 0;
|
||||
|
||||
function _gensync() {
|
||||
const data = _interopRequireDefault(require("gensync"));
|
||||
const data = require("gensync");
|
||||
|
||||
_gensync = function () {
|
||||
return data;
|
||||
@@ -15,15 +15,13 @@ function _gensync() {
|
||||
return data;
|
||||
}
|
||||
|
||||
var _config = _interopRequireDefault(require("./config"));
|
||||
var _config = require("./config");
|
||||
|
||||
var _parser = _interopRequireDefault(require("./parser"));
|
||||
var _parser = require("./parser");
|
||||
|
||||
var _normalizeOpts = _interopRequireDefault(require("./transformation/normalize-opts"));
|
||||
var _normalizeOpts = require("./transformation/normalize-opts");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const parseRunner = (0, _gensync().default)(function* parse(code, opts) {
|
||||
const parseRunner = _gensync()(function* parse(code, opts) {
|
||||
const config = yield* (0, _config.default)(opts);
|
||||
|
||||
if (config === null) {
|
||||
@@ -39,7 +37,12 @@ const parse = function parse(code, opts, callback) {
|
||||
opts = undefined;
|
||||
}
|
||||
|
||||
if (callback === undefined) return parseRunner.sync(code, opts);
|
||||
if (callback === undefined) {
|
||||
{
|
||||
return parseRunner.sync(code, opts);
|
||||
}
|
||||
}
|
||||
|
||||
parseRunner.errback(code, opts, callback);
|
||||
};
|
||||
|
||||
@@ -47,4 +50,5 @@ exports.parse = parse;
|
||||
const parseSync = parseRunner.sync;
|
||||
exports.parseSync = parseSync;
|
||||
const parseAsync = parseRunner.async;
|
||||
exports.parseAsync = parseAsync;
|
||||
exports.parseAsync = parseAsync;
|
||||
0 && 0;
|
||||
+4
-4
@@ -25,9 +25,7 @@ function _codeFrame() {
|
||||
return data;
|
||||
}
|
||||
|
||||
var _missingPluginHelper = _interopRequireDefault(require("./util/missing-plugin-helper"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
var _missingPluginHelper = require("./util/missing-plugin-helper");
|
||||
|
||||
function* parser(pluginPasses, {
|
||||
parserOpts,
|
||||
@@ -94,4 +92,6 @@ function* parser(pluginPasses, {
|
||||
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+96
-56
@@ -5,248 +5,286 @@ Object.defineProperty(exports, "__esModule", {
|
||||
});
|
||||
exports.default = generateMissingPluginMessage;
|
||||
const pluginNameMap = {
|
||||
asyncDoExpressions: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-async-do-expressions",
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-async-do-expressions"
|
||||
}
|
||||
},
|
||||
classProperties: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-class-properties",
|
||||
url: "https://git.io/vb4yQ"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-class-properties"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-class-properties",
|
||||
url: "https://git.io/vb4SL"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-class-properties"
|
||||
}
|
||||
},
|
||||
classPrivateProperties: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-class-properties",
|
||||
url: "https://git.io/vb4yQ"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-class-properties"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-class-properties",
|
||||
url: "https://git.io/vb4SL"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-class-properties"
|
||||
}
|
||||
},
|
||||
classPrivateMethods: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-class-properties",
|
||||
url: "https://git.io/vb4yQ"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-class-properties"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-private-methods",
|
||||
url: "https://git.io/JvpRG"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-private-methods"
|
||||
}
|
||||
},
|
||||
classStaticBlock: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-class-static-block",
|
||||
url: "https://github.com/babel/babel/tree/HEAD/packages/babel-plugin-syntax-class-static-block"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-class-static-block",
|
||||
url: "https://github.com/babel/babel/tree/HEAD/packages/babel-plugin-proposal-class-static-block"
|
||||
}
|
||||
},
|
||||
decimal: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-decimal",
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-decimal"
|
||||
}
|
||||
},
|
||||
decorators: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-decorators",
|
||||
url: "https://git.io/vb4y9"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-decorators"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-decorators",
|
||||
url: "https://git.io/vb4ST"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-decorators"
|
||||
}
|
||||
},
|
||||
doExpressions: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-do-expressions",
|
||||
url: "https://git.io/vb4yh"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-do-expressions"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-do-expressions",
|
||||
url: "https://git.io/vb4S3"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-do-expressions"
|
||||
}
|
||||
},
|
||||
dynamicImport: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-dynamic-import",
|
||||
url: "https://git.io/vb4Sv"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-dynamic-import"
|
||||
}
|
||||
},
|
||||
exportDefaultFrom: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-export-default-from",
|
||||
url: "https://git.io/vb4SO"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-export-default-from"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-export-default-from",
|
||||
url: "https://git.io/vb4yH"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-export-default-from"
|
||||
}
|
||||
},
|
||||
exportNamespaceFrom: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-export-namespace-from",
|
||||
url: "https://git.io/vb4Sf"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-export-namespace-from"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-export-namespace-from",
|
||||
url: "https://git.io/vb4SG"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-export-namespace-from"
|
||||
}
|
||||
},
|
||||
flow: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-flow",
|
||||
url: "https://git.io/vb4yb"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-flow"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/preset-flow",
|
||||
url: "https://git.io/JfeDn"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-preset-flow"
|
||||
}
|
||||
},
|
||||
functionBind: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-function-bind",
|
||||
url: "https://git.io/vb4y7"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-function-bind"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-function-bind",
|
||||
url: "https://git.io/vb4St"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-function-bind"
|
||||
}
|
||||
},
|
||||
functionSent: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-function-sent",
|
||||
url: "https://git.io/vb4yN"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-function-sent"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-function-sent",
|
||||
url: "https://git.io/vb4SZ"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-function-sent"
|
||||
}
|
||||
},
|
||||
importMeta: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-import-meta",
|
||||
url: "https://git.io/vbKK6"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-import-meta"
|
||||
}
|
||||
},
|
||||
jsx: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-jsx",
|
||||
url: "https://git.io/vb4yA"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-jsx"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/preset-react",
|
||||
url: "https://git.io/JfeDR"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-preset-react"
|
||||
}
|
||||
},
|
||||
logicalAssignment: {
|
||||
importAssertions: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-logical-assignment-operators",
|
||||
url: "https://git.io/vAlBp"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-logical-assignment-operators",
|
||||
url: "https://git.io/vAlRe"
|
||||
name: "@babel/plugin-syntax-import-assertions",
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-import-assertions"
|
||||
}
|
||||
},
|
||||
moduleAttributes: {
|
||||
moduleStringNames: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-module-attributes",
|
||||
url: "https://git.io/JfK3k"
|
||||
name: "@babel/plugin-syntax-module-string-names",
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-module-string-names"
|
||||
}
|
||||
},
|
||||
numericSeparator: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-numeric-separator",
|
||||
url: "https://git.io/vb4Sq"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-numeric-separator"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-numeric-separator",
|
||||
url: "https://git.io/vb4yS"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-numeric-separator"
|
||||
}
|
||||
},
|
||||
optionalChaining: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-optional-chaining",
|
||||
url: "https://git.io/vb4Sc"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-optional-chaining"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-optional-chaining",
|
||||
url: "https://git.io/vb4Sk"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-optional-chaining"
|
||||
}
|
||||
},
|
||||
pipelineOperator: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-pipeline-operator",
|
||||
url: "https://git.io/vb4yj"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-pipeline-operator"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-pipeline-operator",
|
||||
url: "https://git.io/vb4SU"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-pipeline-operator"
|
||||
}
|
||||
},
|
||||
privateIn: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-private-property-in-object",
|
||||
url: "https://git.io/JfK3q"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-private-property-in-object"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-private-property-in-object",
|
||||
url: "https://git.io/JfK3O"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-private-property-in-object"
|
||||
}
|
||||
},
|
||||
recordAndTuple: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-record-and-tuple",
|
||||
url: "https://git.io/JvKp3"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-record-and-tuple"
|
||||
}
|
||||
},
|
||||
regexpUnicodeSets: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-unicode-sets-regex",
|
||||
url: "https://github.com/babel/babel/blob/main/packages/babel-plugin-syntax-unicode-sets-regex/README.md"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-unicode-sets-regex",
|
||||
url: "https://github.com/babel/babel/blob/main/packages/babel-plugin-proposalunicode-sets-regex/README.md"
|
||||
}
|
||||
},
|
||||
throwExpressions: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-throw-expressions",
|
||||
url: "https://git.io/vb4SJ"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-throw-expressions"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-throw-expressions",
|
||||
url: "https://git.io/vb4yF"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-throw-expressions"
|
||||
}
|
||||
},
|
||||
typescript: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-typescript",
|
||||
url: "https://git.io/vb4SC"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-typescript"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/preset-typescript",
|
||||
url: "https://git.io/JfeDz"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-preset-typescript"
|
||||
}
|
||||
},
|
||||
asyncGenerators: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-async-generators",
|
||||
url: "https://git.io/vb4SY"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-async-generators"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-async-generator-functions",
|
||||
url: "https://git.io/vb4yp"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-async-generator-functions"
|
||||
}
|
||||
},
|
||||
logicalAssignment: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-logical-assignment-operators",
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-logical-assignment-operators"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-logical-assignment-operators",
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-logical-assignment-operators"
|
||||
}
|
||||
},
|
||||
nullishCoalescingOperator: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-nullish-coalescing-operator",
|
||||
url: "https://git.io/vb4yx"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-nullish-coalescing-operator"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-nullish-coalescing-operator",
|
||||
url: "https://git.io/vb4Se"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-nullish-coalescing-opearator"
|
||||
}
|
||||
},
|
||||
objectRestSpread: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-object-rest-spread",
|
||||
url: "https://git.io/vb4y5"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-object-rest-spread"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-object-rest-spread",
|
||||
url: "https://git.io/vb4Ss"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-object-rest-spread"
|
||||
}
|
||||
},
|
||||
optionalCatchBinding: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-optional-catch-binding",
|
||||
url: "https://git.io/vb4Sn"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-optional-catch-binding"
|
||||
},
|
||||
transform: {
|
||||
name: "@babel/plugin-proposal-optional-catch-binding",
|
||||
url: "https://git.io/vb4SI"
|
||||
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-optional-catch-binding"
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -282,4 +320,6 @@ If you want to leave it as-is, add ${syntaxPluginInfo} to the 'plugins' section
|
||||
}
|
||||
|
||||
return helpMessage;
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+52
-34
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
||||
exports.default = _default;
|
||||
|
||||
function helpers() {
|
||||
const data = _interopRequireWildcard(require("@babel/helpers"));
|
||||
const data = require("@babel/helpers");
|
||||
|
||||
helpers = function () {
|
||||
return data;
|
||||
@@ -16,7 +16,7 @@ function helpers() {
|
||||
}
|
||||
|
||||
function _generator() {
|
||||
const data = _interopRequireDefault(require("@babel/generator"));
|
||||
const data = require("@babel/generator");
|
||||
|
||||
_generator = function () {
|
||||
return data;
|
||||
@@ -26,7 +26,7 @@ function _generator() {
|
||||
}
|
||||
|
||||
function _template() {
|
||||
const data = _interopRequireDefault(require("@babel/template"));
|
||||
const data = require("@babel/template");
|
||||
|
||||
_template = function () {
|
||||
return data;
|
||||
@@ -35,25 +35,41 @@ function _template() {
|
||||
return data;
|
||||
}
|
||||
|
||||
function t() {
|
||||
const data = _interopRequireWildcard(require("@babel/types"));
|
||||
function _t() {
|
||||
const data = require("@babel/types");
|
||||
|
||||
t = function () {
|
||||
_t = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
var _file = _interopRequireDefault(require("../transformation/file/file"));
|
||||
var _file = require("../transformation/file/file");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
const {
|
||||
arrayExpression,
|
||||
assignmentExpression,
|
||||
binaryExpression,
|
||||
blockStatement,
|
||||
callExpression,
|
||||
cloneNode,
|
||||
conditionalExpression,
|
||||
exportNamedDeclaration,
|
||||
exportSpecifier,
|
||||
expressionStatement,
|
||||
functionExpression,
|
||||
identifier,
|
||||
memberExpression,
|
||||
objectExpression,
|
||||
program,
|
||||
stringLiteral,
|
||||
unaryExpression,
|
||||
variableDeclaration,
|
||||
variableDeclarator
|
||||
} = _t();
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
const buildUmdWrapper = replacements => (0, _template().default)`
|
||||
const buildUmdWrapper = replacements => _template().default.statement`
|
||||
(function (root, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(AMD_ARGUMENTS, factory);
|
||||
@@ -68,11 +84,11 @@ const buildUmdWrapper = replacements => (0, _template().default)`
|
||||
`(replacements);
|
||||
|
||||
function buildGlobal(allowlist) {
|
||||
const namespace = t().identifier("babelHelpers");
|
||||
const namespace = identifier("babelHelpers");
|
||||
const body = [];
|
||||
const container = t().functionExpression(null, [t().identifier("global")], t().blockStatement(body));
|
||||
const tree = t().program([t().expressionStatement(t().callExpression(container, [t().conditionalExpression(t().binaryExpression("===", t().unaryExpression("typeof", t().identifier("global")), t().stringLiteral("undefined")), t().identifier("self"), t().identifier("global"))]))]);
|
||||
body.push(t().variableDeclaration("var", [t().variableDeclarator(namespace, t().assignmentExpression("=", t().memberExpression(t().identifier("global"), namespace), t().objectExpression([])))]));
|
||||
const container = functionExpression(null, [identifier("global")], blockStatement(body));
|
||||
const tree = program([expressionStatement(callExpression(container, [conditionalExpression(binaryExpression("===", unaryExpression("typeof", identifier("global")), stringLiteral("undefined")), identifier("self"), identifier("global"))]))]);
|
||||
body.push(variableDeclaration("var", [variableDeclarator(namespace, assignmentExpression("=", memberExpression(identifier("global"), namespace), objectExpression([])))]));
|
||||
buildHelpers(body, namespace, allowlist);
|
||||
return tree;
|
||||
}
|
||||
@@ -80,40 +96,40 @@ function buildGlobal(allowlist) {
|
||||
function buildModule(allowlist) {
|
||||
const body = [];
|
||||
const refs = buildHelpers(body, null, allowlist);
|
||||
body.unshift(t().exportNamedDeclaration(null, Object.keys(refs).map(name => {
|
||||
return t().exportSpecifier(t().cloneNode(refs[name]), t().identifier(name));
|
||||
body.unshift(exportNamedDeclaration(null, Object.keys(refs).map(name => {
|
||||
return exportSpecifier(cloneNode(refs[name]), identifier(name));
|
||||
})));
|
||||
return t().program(body, [], "module");
|
||||
return program(body, [], "module");
|
||||
}
|
||||
|
||||
function buildUmd(allowlist) {
|
||||
const namespace = t().identifier("babelHelpers");
|
||||
const namespace = identifier("babelHelpers");
|
||||
const body = [];
|
||||
body.push(t().variableDeclaration("var", [t().variableDeclarator(namespace, t().identifier("global"))]));
|
||||
body.push(variableDeclaration("var", [variableDeclarator(namespace, identifier("global"))]));
|
||||
buildHelpers(body, namespace, allowlist);
|
||||
return t().program([buildUmdWrapper({
|
||||
FACTORY_PARAMETERS: t().identifier("global"),
|
||||
BROWSER_ARGUMENTS: t().assignmentExpression("=", t().memberExpression(t().identifier("root"), namespace), t().objectExpression([])),
|
||||
COMMON_ARGUMENTS: t().identifier("exports"),
|
||||
AMD_ARGUMENTS: t().arrayExpression([t().stringLiteral("exports")]),
|
||||
return program([buildUmdWrapper({
|
||||
FACTORY_PARAMETERS: identifier("global"),
|
||||
BROWSER_ARGUMENTS: assignmentExpression("=", memberExpression(identifier("root"), namespace), objectExpression([])),
|
||||
COMMON_ARGUMENTS: identifier("exports"),
|
||||
AMD_ARGUMENTS: arrayExpression([stringLiteral("exports")]),
|
||||
FACTORY_BODY: body,
|
||||
UMD_ROOT: t().identifier("this")
|
||||
UMD_ROOT: identifier("this")
|
||||
})]);
|
||||
}
|
||||
|
||||
function buildVar(allowlist) {
|
||||
const namespace = t().identifier("babelHelpers");
|
||||
const namespace = identifier("babelHelpers");
|
||||
const body = [];
|
||||
body.push(t().variableDeclaration("var", [t().variableDeclarator(namespace, t().objectExpression([]))]));
|
||||
const tree = t().program(body);
|
||||
body.push(variableDeclaration("var", [variableDeclarator(namespace, objectExpression([]))]));
|
||||
const tree = program(body);
|
||||
buildHelpers(body, namespace, allowlist);
|
||||
body.push(t().expressionStatement(namespace));
|
||||
body.push(expressionStatement(namespace));
|
||||
return tree;
|
||||
}
|
||||
|
||||
function buildHelpers(body, namespace, allowlist) {
|
||||
const getHelperReference = name => {
|
||||
return namespace ? t().memberExpression(namespace, t().identifier(name)) : t().identifier(`_${name}`);
|
||||
return namespace ? memberExpression(namespace, identifier(name)) : identifier(`_${name}`);
|
||||
};
|
||||
|
||||
const refs = {};
|
||||
@@ -145,4 +161,6 @@ function _default(allowlist, outputType = "global") {
|
||||
}
|
||||
|
||||
return (0, _generator().default)(tree).code;
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+18
-11
@@ -3,10 +3,10 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.transformFromAstAsync = exports.transformFromAstSync = exports.transformFromAst = void 0;
|
||||
exports.transformFromAstSync = exports.transformFromAstAsync = exports.transformFromAst = void 0;
|
||||
|
||||
function _gensync() {
|
||||
const data = _interopRequireDefault(require("gensync"));
|
||||
const data = require("gensync");
|
||||
|
||||
_gensync = function () {
|
||||
return data;
|
||||
@@ -15,27 +15,33 @@ function _gensync() {
|
||||
return data;
|
||||
}
|
||||
|
||||
var _config = _interopRequireDefault(require("./config"));
|
||||
var _config = require("./config");
|
||||
|
||||
var _transformation = require("./transformation");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const transformFromAstRunner = (0, _gensync().default)(function* (ast, code, opts) {
|
||||
const transformFromAstRunner = _gensync()(function* (ast, code, opts) {
|
||||
const config = yield* (0, _config.default)(opts);
|
||||
if (config === null) return null;
|
||||
if (!ast) throw new Error("No AST given");
|
||||
return yield* (0, _transformation.run)(config, code, ast);
|
||||
});
|
||||
|
||||
const transformFromAst = function transformFromAst(ast, code, opts, callback) {
|
||||
if (typeof opts === "function") {
|
||||
callback = opts;
|
||||
const transformFromAst = function transformFromAst(ast, code, optsOrCallback, maybeCallback) {
|
||||
let opts;
|
||||
let callback;
|
||||
|
||||
if (typeof optsOrCallback === "function") {
|
||||
callback = optsOrCallback;
|
||||
opts = undefined;
|
||||
} else {
|
||||
opts = optsOrCallback;
|
||||
callback = maybeCallback;
|
||||
}
|
||||
|
||||
if (callback === undefined) {
|
||||
return transformFromAstRunner.sync(ast, code, opts);
|
||||
{
|
||||
return transformFromAstRunner.sync(ast, code, opts);
|
||||
}
|
||||
}
|
||||
|
||||
transformFromAstRunner.errback(ast, code, opts, callback);
|
||||
@@ -45,4 +51,5 @@ exports.transformFromAst = transformFromAst;
|
||||
const transformFromAstSync = transformFromAstRunner.sync;
|
||||
exports.transformFromAstSync = transformFromAstSync;
|
||||
const transformFromAstAsync = transformFromAstRunner.async;
|
||||
exports.transformFromAstAsync = transformFromAstAsync;
|
||||
exports.transformFromAstAsync = transformFromAstAsync;
|
||||
0 && 0;
|
||||
+5
-3
@@ -3,9 +3,9 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.transformFileSync = transformFileSync;
|
||||
exports.transformFileAsync = transformFileAsync;
|
||||
exports.transformFile = void 0;
|
||||
exports.transformFileAsync = transformFileAsync;
|
||||
exports.transformFileSync = transformFileSync;
|
||||
|
||||
const transformFile = function transformFile(filename, opts, callback) {
|
||||
if (typeof opts === "function") {
|
||||
@@ -23,4 +23,6 @@ function transformFileSync() {
|
||||
|
||||
function transformFileAsync() {
|
||||
return Promise.reject(new Error("Transforming files is not supported in browsers"));
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+9
-12
@@ -3,10 +3,10 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.transformFileAsync = exports.transformFileSync = exports.transformFile = void 0;
|
||||
exports.transformFileSync = exports.transformFileAsync = exports.transformFile = void 0;
|
||||
|
||||
function _gensync() {
|
||||
const data = _interopRequireDefault(require("gensync"));
|
||||
const data = require("gensync");
|
||||
|
||||
_gensync = function () {
|
||||
return data;
|
||||
@@ -15,20 +15,15 @@ function _gensync() {
|
||||
return data;
|
||||
}
|
||||
|
||||
var _config = _interopRequireDefault(require("./config"));
|
||||
var _config = require("./config");
|
||||
|
||||
var _transformation = require("./transformation");
|
||||
|
||||
var fs = _interopRequireWildcard(require("./gensync-utils/fs"));
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
var fs = require("./gensync-utils/fs");
|
||||
|
||||
({});
|
||||
const transformFileRunner = (0, _gensync().default)(function* (filename, opts) {
|
||||
|
||||
const transformFileRunner = _gensync()(function* (filename, opts) {
|
||||
const options = Object.assign({}, opts, {
|
||||
filename
|
||||
});
|
||||
@@ -37,9 +32,11 @@ const transformFileRunner = (0, _gensync().default)(function* (filename, opts) {
|
||||
const code = yield* fs.readFile(filename, "utf8");
|
||||
return yield* (0, _transformation.run)(config, code);
|
||||
});
|
||||
|
||||
const transformFile = transformFileRunner.errback;
|
||||
exports.transformFile = transformFile;
|
||||
const transformFileSync = transformFileRunner.sync;
|
||||
exports.transformFileSync = transformFileSync;
|
||||
const transformFileAsync = transformFileRunner.async;
|
||||
exports.transformFileAsync = transformFileAsync;
|
||||
exports.transformFileAsync = transformFileAsync;
|
||||
0 && 0;
|
||||
+21
-11
@@ -3,10 +3,10 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.transformAsync = exports.transformSync = exports.transform = void 0;
|
||||
exports.transformSync = exports.transformAsync = exports.transform = void 0;
|
||||
|
||||
function _gensync() {
|
||||
const data = _interopRequireDefault(require("gensync"));
|
||||
const data = require("gensync");
|
||||
|
||||
_gensync = function () {
|
||||
return data;
|
||||
@@ -15,25 +15,34 @@ function _gensync() {
|
||||
return data;
|
||||
}
|
||||
|
||||
var _config = _interopRequireDefault(require("./config"));
|
||||
var _config = require("./config");
|
||||
|
||||
var _transformation = require("./transformation");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const transformRunner = (0, _gensync().default)(function* transform(code, opts) {
|
||||
const transformRunner = _gensync()(function* transform(code, opts) {
|
||||
const config = yield* (0, _config.default)(opts);
|
||||
if (config === null) return null;
|
||||
return yield* (0, _transformation.run)(config, code);
|
||||
});
|
||||
|
||||
const transform = function transform(code, opts, callback) {
|
||||
if (typeof opts === "function") {
|
||||
callback = opts;
|
||||
const transform = function transform(code, optsOrCallback, maybeCallback) {
|
||||
let opts;
|
||||
let callback;
|
||||
|
||||
if (typeof optsOrCallback === "function") {
|
||||
callback = optsOrCallback;
|
||||
opts = undefined;
|
||||
} else {
|
||||
opts = optsOrCallback;
|
||||
callback = maybeCallback;
|
||||
}
|
||||
|
||||
if (callback === undefined) {
|
||||
{
|
||||
return transformRunner.sync(code, opts);
|
||||
}
|
||||
}
|
||||
|
||||
if (callback === undefined) return transformRunner.sync(code, opts);
|
||||
transformRunner.errback(code, opts, callback);
|
||||
};
|
||||
|
||||
@@ -41,4 +50,5 @@ exports.transform = transform;
|
||||
const transformSync = transformRunner.sync;
|
||||
exports.transformSync = transformSync;
|
||||
const transformAsync = transformRunner.async;
|
||||
exports.transformAsync = transformAsync;
|
||||
exports.transformAsync = transformAsync;
|
||||
0 && 0;
|
||||
+51
-24
@@ -5,37 +5,61 @@ Object.defineProperty(exports, "__esModule", {
|
||||
});
|
||||
exports.default = loadBlockHoistPlugin;
|
||||
|
||||
function _sortBy() {
|
||||
const data = _interopRequireDefault(require("lodash/sortBy"));
|
||||
function _traverse() {
|
||||
const data = require("@babel/traverse");
|
||||
|
||||
_sortBy = function () {
|
||||
_traverse = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
var _config = _interopRequireDefault(require("../config"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
var _plugin = require("../config/plugin");
|
||||
|
||||
let LOADED_PLUGIN;
|
||||
|
||||
function loadBlockHoistPlugin() {
|
||||
if (!LOADED_PLUGIN) {
|
||||
const config = _config.default.sync({
|
||||
babelrc: false,
|
||||
configFile: false,
|
||||
plugins: [blockHoistPlugin]
|
||||
});
|
||||
|
||||
LOADED_PLUGIN = config ? config.passes[0][0] : undefined;
|
||||
if (!LOADED_PLUGIN) throw new Error("Assertion failure");
|
||||
LOADED_PLUGIN = new _plugin.default(Object.assign({}, blockHoistPlugin, {
|
||||
visitor: _traverse().default.explode(blockHoistPlugin.visitor)
|
||||
}), {});
|
||||
}
|
||||
|
||||
return LOADED_PLUGIN;
|
||||
}
|
||||
|
||||
function priority(bodyNode) {
|
||||
const priority = bodyNode == null ? void 0 : bodyNode._blockHoist;
|
||||
if (priority == null) return 1;
|
||||
if (priority === true) return 2;
|
||||
return priority;
|
||||
}
|
||||
|
||||
function stableSort(body) {
|
||||
const buckets = Object.create(null);
|
||||
|
||||
for (let i = 0; i < body.length; i++) {
|
||||
const n = body[i];
|
||||
const p = priority(n);
|
||||
const bucket = buckets[p] || (buckets[p] = []);
|
||||
bucket.push(n);
|
||||
}
|
||||
|
||||
const keys = Object.keys(buckets).map(k => +k).sort((a, b) => b - a);
|
||||
let index = 0;
|
||||
|
||||
for (const key of keys) {
|
||||
const bucket = buckets[key];
|
||||
|
||||
for (const n of bucket) {
|
||||
body[index++] = n;
|
||||
}
|
||||
}
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
const blockHoistPlugin = {
|
||||
name: "internal.blockHoist",
|
||||
visitor: {
|
||||
@@ -43,26 +67,29 @@ const blockHoistPlugin = {
|
||||
exit({
|
||||
node
|
||||
}) {
|
||||
const {
|
||||
body
|
||||
} = node;
|
||||
let max = Math.pow(2, 30) - 1;
|
||||
let hasChange = false;
|
||||
|
||||
for (let i = 0; i < node.body.length; i++) {
|
||||
const bodyNode = node.body[i];
|
||||
for (let i = 0; i < body.length; i++) {
|
||||
const n = body[i];
|
||||
const p = priority(n);
|
||||
|
||||
if ((bodyNode == null ? void 0 : bodyNode._blockHoist) != null) {
|
||||
if (p > max) {
|
||||
hasChange = true;
|
||||
break;
|
||||
}
|
||||
|
||||
max = p;
|
||||
}
|
||||
|
||||
if (!hasChange) return;
|
||||
node.body = (0, _sortBy().default)(node.body, function (bodyNode) {
|
||||
let priority = bodyNode == null ? void 0 : bodyNode._blockHoist;
|
||||
if (priority == null) priority = 1;
|
||||
if (priority === true) priority = 2;
|
||||
return -1 * priority;
|
||||
});
|
||||
node.body = stableSort(body.slice());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
0 && 0;
|
||||
+23
-21
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
||||
exports.default = void 0;
|
||||
|
||||
function helpers() {
|
||||
const data = _interopRequireWildcard(require("@babel/helpers"));
|
||||
const data = require("@babel/helpers");
|
||||
|
||||
helpers = function () {
|
||||
return data;
|
||||
@@ -16,7 +16,7 @@ function helpers() {
|
||||
}
|
||||
|
||||
function _traverse() {
|
||||
const data = _interopRequireWildcard(require("@babel/traverse"));
|
||||
const data = require("@babel/traverse");
|
||||
|
||||
_traverse = function () {
|
||||
return data;
|
||||
@@ -35,10 +35,10 @@ function _codeFrame() {
|
||||
return data;
|
||||
}
|
||||
|
||||
function t() {
|
||||
const data = _interopRequireWildcard(require("@babel/types"));
|
||||
function _t() {
|
||||
const data = require("@babel/types");
|
||||
|
||||
t = function () {
|
||||
_t = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -56,7 +56,7 @@ function _helperModuleTransforms() {
|
||||
}
|
||||
|
||||
function _semver() {
|
||||
const data = _interopRequireDefault(require("semver"));
|
||||
const data = require("semver");
|
||||
|
||||
_semver = function () {
|
||||
return data;
|
||||
@@ -65,11 +65,10 @@ function _semver() {
|
||||
return data;
|
||||
}
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
const {
|
||||
cloneNode,
|
||||
interpreterDirective
|
||||
} = _t();
|
||||
|
||||
const errorVisitor = {
|
||||
enter(path, state) {
|
||||
@@ -90,12 +89,14 @@ class File {
|
||||
inputMap
|
||||
}) {
|
||||
this._map = new Map();
|
||||
this.opts = void 0;
|
||||
this.declarations = {};
|
||||
this.path = null;
|
||||
this.ast = {};
|
||||
this.path = void 0;
|
||||
this.ast = void 0;
|
||||
this.scope = void 0;
|
||||
this.metadata = {};
|
||||
this.code = "";
|
||||
this.inputMap = null;
|
||||
this.inputMap = void 0;
|
||||
this.hub = {
|
||||
file: this,
|
||||
getCode: () => this.code,
|
||||
@@ -126,7 +127,7 @@ class File {
|
||||
|
||||
set shebang(value) {
|
||||
if (value) {
|
||||
this.path.get("interpreter").replaceWith(t().interpreterDirective(value));
|
||||
this.path.get("interpreter").replaceWith(interpreterDirective(value));
|
||||
} else {
|
||||
this.path.get("interpreter").remove();
|
||||
}
|
||||
@@ -167,13 +168,13 @@ class File {
|
||||
}
|
||||
|
||||
if (typeof versionRange !== "string") return true;
|
||||
if (_semver().default.valid(versionRange)) versionRange = `^${versionRange}`;
|
||||
return !_semver().default.intersects(`<${minVersion}`, versionRange) && !_semver().default.intersects(`>=8.0.0`, versionRange);
|
||||
if (_semver().valid(versionRange)) versionRange = `^${versionRange}`;
|
||||
return !_semver().intersects(`<${minVersion}`, versionRange) && !_semver().intersects(`>=8.0.0`, versionRange);
|
||||
}
|
||||
|
||||
addHelper(name) {
|
||||
const declar = this.declarations[name];
|
||||
if (declar) return t().cloneNode(declar);
|
||||
if (declar) return cloneNode(declar);
|
||||
const generator = this.get("helperGenerator");
|
||||
|
||||
if (generator) {
|
||||
@@ -213,7 +214,7 @@ class File {
|
||||
throw new Error("This function has been moved into the template literal transform itself.");
|
||||
}
|
||||
|
||||
buildCodeFrameError(node, msg, Error = SyntaxError) {
|
||||
buildCodeFrameError(node, msg, _Error = SyntaxError) {
|
||||
let loc = node && (node.loc || node._loc);
|
||||
|
||||
if (!loc && node) {
|
||||
@@ -245,9 +246,10 @@ class File {
|
||||
});
|
||||
}
|
||||
|
||||
return new Error(msg);
|
||||
return new _Error(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = File;
|
||||
exports.default = File;
|
||||
0 && 0;
|
||||
+19
-12
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
||||
exports.default = generateCode;
|
||||
|
||||
function _convertSourceMap() {
|
||||
const data = _interopRequireDefault(require("convert-source-map"));
|
||||
const data = require("convert-source-map");
|
||||
|
||||
_convertSourceMap = function () {
|
||||
return data;
|
||||
@@ -16,7 +16,7 @@ function _convertSourceMap() {
|
||||
}
|
||||
|
||||
function _generator() {
|
||||
const data = _interopRequireDefault(require("@babel/generator"));
|
||||
const data = require("@babel/generator");
|
||||
|
||||
_generator = function () {
|
||||
return data;
|
||||
@@ -25,9 +25,7 @@ function _generator() {
|
||||
return data;
|
||||
}
|
||||
|
||||
var _mergeMap = _interopRequireDefault(require("./merge-map"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
var _mergeMap = require("./merge-map");
|
||||
|
||||
function generateCode(pluginPasses, file) {
|
||||
const {
|
||||
@@ -36,6 +34,9 @@ function generateCode(pluginPasses, file) {
|
||||
code,
|
||||
inputMap
|
||||
} = file;
|
||||
const {
|
||||
generatorOpts
|
||||
} = opts;
|
||||
const results = [];
|
||||
|
||||
for (const plugins of pluginPasses) {
|
||||
@@ -45,7 +46,7 @@ function generateCode(pluginPasses, file) {
|
||||
} = plugin;
|
||||
|
||||
if (generatorOverride) {
|
||||
const result = generatorOverride(ast, opts.generatorOpts, code, _generator().default);
|
||||
const result = generatorOverride(ast, generatorOpts, code, _generator().default);
|
||||
if (result !== undefined) results.push(result);
|
||||
}
|
||||
}
|
||||
@@ -54,7 +55,7 @@ function generateCode(pluginPasses, file) {
|
||||
let result;
|
||||
|
||||
if (results.length === 0) {
|
||||
result = (0, _generator().default)(ast, opts.generatorOpts, code);
|
||||
result = (0, _generator().default)(ast, generatorOpts, code);
|
||||
} else if (results.length === 1) {
|
||||
result = results[0];
|
||||
|
||||
@@ -67,15 +68,19 @@ function generateCode(pluginPasses, file) {
|
||||
|
||||
let {
|
||||
code: outputCode,
|
||||
map: outputMap
|
||||
decodedMap: outputMap = result.map
|
||||
} = result;
|
||||
|
||||
if (outputMap && inputMap) {
|
||||
outputMap = (0, _mergeMap.default)(inputMap.toObject(), outputMap);
|
||||
if (outputMap) {
|
||||
if (inputMap) {
|
||||
outputMap = (0, _mergeMap.default)(inputMap.toObject(), outputMap, generatorOpts.sourceFileName);
|
||||
} else {
|
||||
outputMap = result.map;
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.sourceMaps === "inline" || opts.sourceMaps === "both") {
|
||||
outputCode += "\n" + _convertSourceMap().default.fromObject(outputMap).toComment();
|
||||
outputCode += "\n" + _convertSourceMap().fromObject(outputMap).toComment();
|
||||
}
|
||||
|
||||
if (opts.sourceMaps === "inline") {
|
||||
@@ -86,4 +91,6 @@ function generateCode(pluginPasses, file) {
|
||||
outputCode,
|
||||
outputMap
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+22
-224
@@ -5,243 +5,41 @@ Object.defineProperty(exports, "__esModule", {
|
||||
});
|
||||
exports.default = mergeSourceMap;
|
||||
|
||||
function _sourceMap() {
|
||||
const data = _interopRequireDefault(require("source-map"));
|
||||
function _remapping() {
|
||||
const data = require("@ampproject/remapping");
|
||||
|
||||
_sourceMap = function () {
|
||||
_remapping = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
function mergeSourceMap(inputMap, map, sourceFileName) {
|
||||
const source = sourceFileName.replace(/\\/g, "/");
|
||||
let found = false;
|
||||
|
||||
function mergeSourceMap(inputMap, map) {
|
||||
const input = buildMappingData(inputMap);
|
||||
const output = buildMappingData(map);
|
||||
const mergedGenerator = new (_sourceMap().default.SourceMapGenerator)();
|
||||
|
||||
for (const {
|
||||
source
|
||||
} of input.sources) {
|
||||
if (typeof source.content === "string") {
|
||||
mergedGenerator.setSourceContent(source.path, source.content);
|
||||
const result = _remapping()(rootless(map), (s, ctx) => {
|
||||
if (s === source && !found) {
|
||||
found = true;
|
||||
ctx.source = "";
|
||||
return rootless(inputMap);
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
if (typeof inputMap.sourceRoot === "string") {
|
||||
result.sourceRoot = inputMap.sourceRoot;
|
||||
}
|
||||
|
||||
if (output.sources.length === 1) {
|
||||
const defaultSource = output.sources[0];
|
||||
const insertedMappings = new Map();
|
||||
eachInputGeneratedRange(input, (generated, original, source) => {
|
||||
eachOverlappingGeneratedOutputRange(defaultSource, generated, item => {
|
||||
const key = makeMappingKey(item);
|
||||
if (insertedMappings.has(key)) return;
|
||||
insertedMappings.set(key, item);
|
||||
mergedGenerator.addMapping({
|
||||
source: source.path,
|
||||
original: {
|
||||
line: original.line,
|
||||
column: original.columnStart
|
||||
},
|
||||
generated: {
|
||||
line: item.line,
|
||||
column: item.columnStart
|
||||
},
|
||||
name: original.name
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
for (const item of insertedMappings.values()) {
|
||||
if (item.columnEnd === Infinity) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const clearItem = {
|
||||
line: item.line,
|
||||
columnStart: item.columnEnd
|
||||
};
|
||||
const key = makeMappingKey(clearItem);
|
||||
|
||||
if (insertedMappings.has(key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
mergedGenerator.addMapping({
|
||||
generated: {
|
||||
line: clearItem.line,
|
||||
column: clearItem.columnStart
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const result = mergedGenerator.toJSON();
|
||||
|
||||
if (typeof input.sourceRoot === "string") {
|
||||
result.sourceRoot = input.sourceRoot;
|
||||
}
|
||||
|
||||
return result;
|
||||
return Object.assign({}, result);
|
||||
}
|
||||
|
||||
function makeMappingKey(item) {
|
||||
return `${item.line}/${item.columnStart}`;
|
||||
}
|
||||
|
||||
function eachOverlappingGeneratedOutputRange(outputFile, inputGeneratedRange, callback) {
|
||||
const overlappingOriginal = filterApplicableOriginalRanges(outputFile, inputGeneratedRange);
|
||||
|
||||
for (const {
|
||||
generated
|
||||
} of overlappingOriginal) {
|
||||
for (const item of generated) {
|
||||
callback(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function filterApplicableOriginalRanges({
|
||||
mappings
|
||||
}, {
|
||||
line,
|
||||
columnStart,
|
||||
columnEnd
|
||||
}) {
|
||||
return filterSortedArray(mappings, ({
|
||||
original: outOriginal
|
||||
}) => {
|
||||
if (line > outOriginal.line) return -1;
|
||||
if (line < outOriginal.line) return 1;
|
||||
if (columnStart >= outOriginal.columnEnd) return -1;
|
||||
if (columnEnd <= outOriginal.columnStart) return 1;
|
||||
return 0;
|
||||
function rootless(map) {
|
||||
return Object.assign({}, map, {
|
||||
sourceRoot: null
|
||||
});
|
||||
}
|
||||
|
||||
function eachInputGeneratedRange(map, callback) {
|
||||
for (const {
|
||||
source,
|
||||
mappings
|
||||
} of map.sources) {
|
||||
for (const {
|
||||
original,
|
||||
generated
|
||||
} of mappings) {
|
||||
for (const item of generated) {
|
||||
callback(item, original, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function buildMappingData(map) {
|
||||
const consumer = new (_sourceMap().default.SourceMapConsumer)(Object.assign({}, map, {
|
||||
sourceRoot: null
|
||||
}));
|
||||
const sources = new Map();
|
||||
const mappings = new Map();
|
||||
let last = null;
|
||||
consumer.computeColumnSpans();
|
||||
consumer.eachMapping(m => {
|
||||
if (m.originalLine === null) return;
|
||||
let source = sources.get(m.source);
|
||||
|
||||
if (!source) {
|
||||
source = {
|
||||
path: m.source,
|
||||
content: consumer.sourceContentFor(m.source, true)
|
||||
};
|
||||
sources.set(m.source, source);
|
||||
}
|
||||
|
||||
let sourceData = mappings.get(source);
|
||||
|
||||
if (!sourceData) {
|
||||
sourceData = {
|
||||
source,
|
||||
mappings: []
|
||||
};
|
||||
mappings.set(source, sourceData);
|
||||
}
|
||||
|
||||
const obj = {
|
||||
line: m.originalLine,
|
||||
columnStart: m.originalColumn,
|
||||
columnEnd: Infinity,
|
||||
name: m.name
|
||||
};
|
||||
|
||||
if (last && last.source === source && last.mapping.line === m.originalLine) {
|
||||
last.mapping.columnEnd = m.originalColumn;
|
||||
}
|
||||
|
||||
last = {
|
||||
source,
|
||||
mapping: obj
|
||||
};
|
||||
sourceData.mappings.push({
|
||||
original: obj,
|
||||
generated: consumer.allGeneratedPositionsFor({
|
||||
source: m.source,
|
||||
line: m.originalLine,
|
||||
column: m.originalColumn
|
||||
}).map(item => ({
|
||||
line: item.line,
|
||||
columnStart: item.column,
|
||||
columnEnd: item.lastColumn + 1
|
||||
}))
|
||||
});
|
||||
}, null, _sourceMap().default.SourceMapConsumer.ORIGINAL_ORDER);
|
||||
return {
|
||||
file: map.file,
|
||||
sourceRoot: map.sourceRoot,
|
||||
sources: Array.from(mappings.values())
|
||||
};
|
||||
}
|
||||
|
||||
function findInsertionLocation(array, callback) {
|
||||
let left = 0;
|
||||
let right = array.length;
|
||||
|
||||
while (left < right) {
|
||||
const mid = Math.floor((left + right) / 2);
|
||||
const item = array[mid];
|
||||
const result = callback(item);
|
||||
|
||||
if (result === 0) {
|
||||
left = mid;
|
||||
break;
|
||||
}
|
||||
|
||||
if (result >= 0) {
|
||||
right = mid;
|
||||
} else {
|
||||
left = mid + 1;
|
||||
}
|
||||
}
|
||||
|
||||
let i = left;
|
||||
|
||||
if (i < array.length) {
|
||||
while (i >= 0 && callback(array[i]) >= 0) {
|
||||
i--;
|
||||
}
|
||||
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
function filterSortedArray(array, callback) {
|
||||
const start = findInsertionLocation(array, callback);
|
||||
const results = [];
|
||||
|
||||
for (let i = start; i < array.length && callback(array[i]) === 0; i++) {
|
||||
results.push(array[i]);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
0 && 0;
|
||||
+12
-9
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
||||
exports.run = run;
|
||||
|
||||
function _traverse() {
|
||||
const data = _interopRequireDefault(require("@babel/traverse"));
|
||||
const data = require("@babel/traverse");
|
||||
|
||||
_traverse = function () {
|
||||
return data;
|
||||
@@ -15,17 +15,17 @@ function _traverse() {
|
||||
return data;
|
||||
}
|
||||
|
||||
var _pluginPass = _interopRequireDefault(require("./plugin-pass"));
|
||||
var _pluginPass = require("./plugin-pass");
|
||||
|
||||
var _blockHoistPlugin = _interopRequireDefault(require("./block-hoist-plugin"));
|
||||
var _blockHoistPlugin = require("./block-hoist-plugin");
|
||||
|
||||
var _normalizeOpts = _interopRequireDefault(require("./normalize-opts"));
|
||||
var _normalizeOpts = require("./normalize-opts");
|
||||
|
||||
var _normalizeFile = _interopRequireDefault(require("./normalize-file"));
|
||||
var _normalizeFile = require("./normalize-file");
|
||||
|
||||
var _generate = _interopRequireDefault(require("./file/generate"));
|
||||
var _generate = require("./file/generate");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
var _deepArray = require("../config/helpers/deep-array");
|
||||
|
||||
function* run(config, code, ast) {
|
||||
const file = yield* (0, _normalizeFile.default)(config.passes, (0, _normalizeOpts.default)(config), code, ast);
|
||||
@@ -72,7 +72,8 @@ function* run(config, code, ast) {
|
||||
ast: opts.ast === true ? file.ast : null,
|
||||
code: outputCode === undefined ? null : outputCode,
|
||||
map: outputMap === undefined ? null : outputMap,
|
||||
sourceType: file.ast.program.sourceType
|
||||
sourceType: file.ast.program.sourceType,
|
||||
externalDependencies: (0, _deepArray.flattenToSet)(config.externalDependencies)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -123,4 +124,6 @@ function* transformFile(file, pluginPasses) {
|
||||
|
||||
function isThenable(val) {
|
||||
return !!val && (typeof val === "object" || typeof val === "function") && !!val.then && typeof val.then === "function";
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+28
-32
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
||||
exports.default = normalizeFile;
|
||||
|
||||
function _fs() {
|
||||
const data = _interopRequireDefault(require("fs"));
|
||||
const data = require("fs");
|
||||
|
||||
_fs = function () {
|
||||
return data;
|
||||
@@ -16,7 +16,7 @@ function _fs() {
|
||||
}
|
||||
|
||||
function _path() {
|
||||
const data = _interopRequireDefault(require("path"));
|
||||
const data = require("path");
|
||||
|
||||
_path = function () {
|
||||
return data;
|
||||
@@ -26,7 +26,7 @@ function _path() {
|
||||
}
|
||||
|
||||
function _debug() {
|
||||
const data = _interopRequireDefault(require("debug"));
|
||||
const data = require("debug");
|
||||
|
||||
_debug = function () {
|
||||
return data;
|
||||
@@ -35,20 +35,10 @@ function _debug() {
|
||||
return data;
|
||||
}
|
||||
|
||||
function _cloneDeep() {
|
||||
const data = _interopRequireDefault(require("lodash/cloneDeep"));
|
||||
function _t() {
|
||||
const data = require("@babel/types");
|
||||
|
||||
_cloneDeep = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function t() {
|
||||
const data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function () {
|
||||
_t = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -56,7 +46,7 @@ function t() {
|
||||
}
|
||||
|
||||
function _convertSourceMap() {
|
||||
const data = _interopRequireDefault(require("convert-source-map"));
|
||||
const data = require("convert-source-map");
|
||||
|
||||
_convertSourceMap = function () {
|
||||
return data;
|
||||
@@ -65,30 +55,34 @@ function _convertSourceMap() {
|
||||
return data;
|
||||
}
|
||||
|
||||
var _file = _interopRequireDefault(require("./file/file"));
|
||||
var _file = require("./file/file");
|
||||
|
||||
var _parser = _interopRequireDefault(require("../parser"));
|
||||
var _parser = require("../parser");
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
var _cloneDeep = require("./util/clone-deep");
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
const {
|
||||
file,
|
||||
traverseFast
|
||||
} = _t();
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
const debug = _debug()("babel:transform:file");
|
||||
|
||||
const debug = (0, _debug().default)("babel:transform:file");
|
||||
const LARGE_INPUT_SOURCEMAP_THRESHOLD = 1000000;
|
||||
const LARGE_INPUT_SOURCEMAP_THRESHOLD = 3000000;
|
||||
|
||||
function* normalizeFile(pluginPasses, options, code, ast) {
|
||||
code = `${code || ""}`;
|
||||
|
||||
if (ast) {
|
||||
if (ast.type === "Program") {
|
||||
ast = t().file(ast, [], []);
|
||||
ast = file(ast, [], []);
|
||||
} else if (ast.type !== "File") {
|
||||
throw new Error("AST root must be a Program or File node");
|
||||
}
|
||||
|
||||
ast = (0, _cloneDeep().default)(ast);
|
||||
if (options.cloneInputAst) {
|
||||
ast = (0, _cloneDeep.default)(ast);
|
||||
}
|
||||
} else {
|
||||
ast = yield* (0, _parser.default)(pluginPasses, options, code);
|
||||
}
|
||||
@@ -97,7 +91,7 @@ function* normalizeFile(pluginPasses, options, code, ast) {
|
||||
|
||||
if (options.inputSourceMap !== false) {
|
||||
if (typeof options.inputSourceMap === "object") {
|
||||
inputMap = _convertSourceMap().default.fromObject(options.inputSourceMap);
|
||||
inputMap = _convertSourceMap().fromObject(options.inputSourceMap);
|
||||
}
|
||||
|
||||
if (!inputMap) {
|
||||
@@ -105,7 +99,7 @@ function* normalizeFile(pluginPasses, options, code, ast) {
|
||||
|
||||
if (lastComment) {
|
||||
try {
|
||||
inputMap = _convertSourceMap().default.fromComment(lastComment);
|
||||
inputMap = _convertSourceMap().fromComment(lastComment);
|
||||
} catch (err) {
|
||||
debug("discarding unknown inline input sourcemap", err);
|
||||
}
|
||||
@@ -119,12 +113,12 @@ function* normalizeFile(pluginPasses, options, code, ast) {
|
||||
try {
|
||||
const match = EXTERNAL_SOURCEMAP_REGEX.exec(lastComment);
|
||||
|
||||
const inputMapContent = _fs().default.readFileSync(_path().default.resolve(_path().default.dirname(options.filename), match[1]));
|
||||
const inputMapContent = _fs().readFileSync(_path().resolve(_path().dirname(options.filename), match[1]));
|
||||
|
||||
if (inputMapContent.length > LARGE_INPUT_SOURCEMAP_THRESHOLD) {
|
||||
debug("skip merging input map > 1 MB");
|
||||
} else {
|
||||
inputMap = _convertSourceMap().default.fromJSON(inputMapContent);
|
||||
inputMap = _convertSourceMap().fromJSON(inputMapContent);
|
||||
}
|
||||
} catch (err) {
|
||||
debug("discarding unknown file input sourcemap", err);
|
||||
@@ -164,10 +158,12 @@ function extractCommentsFromList(regex, comments, lastComment) {
|
||||
|
||||
function extractComments(regex, ast) {
|
||||
let lastComment = null;
|
||||
t().traverseFast(ast, node => {
|
||||
traverseFast(ast, node => {
|
||||
[node.leadingComments, lastComment] = extractCommentsFromList(regex, node.leadingComments, lastComment);
|
||||
[node.innerComments, lastComment] = extractCommentsFromList(regex, node.innerComments, lastComment);
|
||||
[node.trailingComments, lastComment] = extractCommentsFromList(regex, node.trailingComments, lastComment);
|
||||
});
|
||||
return lastComment;
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+8
-9
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
||||
exports.default = normalizeOptions;
|
||||
|
||||
function _path() {
|
||||
const data = _interopRequireDefault(require("path"));
|
||||
const data = require("path");
|
||||
|
||||
_path = function () {
|
||||
return data;
|
||||
@@ -15,26 +15,23 @@ function _path() {
|
||||
return data;
|
||||
}
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function normalizeOptions(config) {
|
||||
const {
|
||||
filename,
|
||||
cwd,
|
||||
filenameRelative = typeof filename === "string" ? _path().default.relative(cwd, filename) : "unknown",
|
||||
filenameRelative = typeof filename === "string" ? _path().relative(cwd, filename) : "unknown",
|
||||
sourceType = "module",
|
||||
inputSourceMap,
|
||||
sourceMaps = !!inputSourceMap,
|
||||
moduleRoot,
|
||||
sourceRoot = moduleRoot,
|
||||
sourceFileName = _path().default.basename(filenameRelative),
|
||||
sourceRoot = config.options.moduleRoot,
|
||||
sourceFileName = _path().basename(filenameRelative),
|
||||
comments = true,
|
||||
compact = "auto"
|
||||
} = config.options;
|
||||
const opts = config.options;
|
||||
const options = Object.assign({}, opts, {
|
||||
parserOpts: Object.assign({
|
||||
sourceType: _path().default.extname(filenameRelative) === ".mjs" ? "module" : sourceType,
|
||||
sourceType: _path().extname(filenameRelative) === ".mjs" ? "module" : sourceType,
|
||||
sourceFileName: filename,
|
||||
plugins: []
|
||||
}, opts.parserOpts),
|
||||
@@ -62,4 +59,6 @@ function normalizeOptions(config) {
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+14
-7
@@ -8,6 +8,11 @@ exports.default = void 0;
|
||||
class PluginPass {
|
||||
constructor(file, key, options) {
|
||||
this._map = new Map();
|
||||
this.key = void 0;
|
||||
this.file = void 0;
|
||||
this.opts = void 0;
|
||||
this.cwd = void 0;
|
||||
this.filename = void 0;
|
||||
this.key = key;
|
||||
this.file = file;
|
||||
this.opts = options || {};
|
||||
@@ -35,14 +40,16 @@ class PluginPass {
|
||||
return this.file.addImport();
|
||||
}
|
||||
|
||||
getModuleName() {
|
||||
return this.file.getModuleName();
|
||||
}
|
||||
|
||||
buildCodeFrameError(node, msg, Error) {
|
||||
return this.file.buildCodeFrameError(node, msg, Error);
|
||||
buildCodeFrameError(node, msg, _Error) {
|
||||
return this.file.buildCodeFrameError(node, msg, _Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = PluginPass;
|
||||
exports.default = PluginPass;
|
||||
{
|
||||
PluginPass.prototype.getModuleName = function getModuleName() {
|
||||
return this.file.getModuleName();
|
||||
};
|
||||
}
|
||||
0 && 0;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = _default;
|
||||
|
||||
function deepClone(value, cache) {
|
||||
if (value !== null) {
|
||||
if (cache.has(value)) return cache.get(value);
|
||||
let cloned;
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
cloned = new Array(value.length);
|
||||
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
cloned[i] = typeof value[i] !== "object" ? value[i] : deepClone(value[i], cache);
|
||||
}
|
||||
} else {
|
||||
cloned = {};
|
||||
const keys = Object.keys(value);
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const key = keys[i];
|
||||
cloned[key] = typeof value[key] !== "object" ? value[key] : deepClone(value[key], cache);
|
||||
}
|
||||
}
|
||||
|
||||
cache.set(value, cloned);
|
||||
return cloned;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function _default(value) {
|
||||
if (typeof value !== "object") return value;
|
||||
return deepClone(value, new Map());
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
+3431
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -1 +1 @@
|
||||
../semver/bin/semver
|
||||
../semver/bin/semver.js
|
||||
+10
-9
@@ -1,19 +1,20 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014 TJ Holowaychuk <tj@vision-media.ca>
|
||||
Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca>
|
||||
Copyright (c) 2018-2021 Josh Junon
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the 'Software'), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the 'Software'), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial
|
||||
portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
||||
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
||||
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
+27
-1
@@ -1,5 +1,5 @@
|
||||
# debug
|
||||
[](https://travis-ci.org/visionmedia/debug) [](https://coveralls.io/github/visionmedia/debug?branch=master) [](https://visionmedia-community-slackin.now.sh/) [](#backers)
|
||||
[](https://travis-ci.org/debug-js/debug) [](https://coveralls.io/github/debug-js/debug?branch=master) [](https://visionmedia-community-slackin.now.sh/) [](#backers)
|
||||
[](#sponsors)
|
||||
|
||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091486-fa38524c-7c37-11e7-895f-e7ec8e1039b6.png">
|
||||
@@ -241,6 +241,9 @@ setInterval(function(){
|
||||
}, 1200);
|
||||
```
|
||||
|
||||
In Chromium-based web browsers (e.g. Brave, Chrome, and Electron), the JavaScript console will—by default—only show messages logged by `debug` if the "Verbose" log level is _enabled_.
|
||||
|
||||
<img width="647" src="https://user-images.githubusercontent.com/7143133/152083257-29034707-c42c-4959-8add-3cee850e6fcf.png">
|
||||
|
||||
## Output streams
|
||||
|
||||
@@ -351,12 +354,34 @@ if (debug.enabled) {
|
||||
You can also manually toggle this property to force the debug instance to be
|
||||
enabled or disabled.
|
||||
|
||||
## Usage in child processes
|
||||
|
||||
Due to the way `debug` detects if the output is a TTY or not, colors are not shown in child processes when `stderr` is piped. A solution is to pass the `DEBUG_COLORS=1` environment variable to the child process.
|
||||
For example:
|
||||
|
||||
```javascript
|
||||
worker = fork(WORKER_WRAP_PATH, [workerPath], {
|
||||
stdio: [
|
||||
/* stdin: */ 0,
|
||||
/* stdout: */ 'pipe',
|
||||
/* stderr: */ 'pipe',
|
||||
'ipc',
|
||||
],
|
||||
env: Object.assign({}, process.env, {
|
||||
DEBUG_COLORS: 1 // without this settings, colors won't be shown
|
||||
}),
|
||||
});
|
||||
|
||||
worker.stderr.pipe(process.stderr, { end: false });
|
||||
```
|
||||
|
||||
|
||||
## Authors
|
||||
|
||||
- TJ Holowaychuk
|
||||
- Nathan Rajlich
|
||||
- Andrew Rhyne
|
||||
- Josh Junon
|
||||
|
||||
## Backers
|
||||
|
||||
@@ -434,6 +459,7 @@ Become a sponsor and get your logo on our README on Github with a link to your s
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca>
|
||||
Copyright (c) 2018-2021 Josh Junon
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
+37
-38
@@ -1,41 +1,45 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"debug@4.1.1",
|
||||
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
|
||||
"debug@4.3.4",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "debug@4.1.1",
|
||||
"_id": "debug@4.1.1",
|
||||
"_from": "debug@4.3.4",
|
||||
"_id": "debug@4.3.4",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
|
||||
"_integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
||||
"_location": "/@babel/core/debug",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "debug@4.1.1",
|
||||
"raw": "debug@4.3.4",
|
||||
"name": "debug",
|
||||
"escapedName": "debug",
|
||||
"rawSpec": "4.1.1",
|
||||
"rawSpec": "4.3.4",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "4.1.1"
|
||||
"fetchSpec": "4.3.4"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@babel/core"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
||||
"_spec": "4.1.1",
|
||||
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
|
||||
"_resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||
"_spec": "4.3.4",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "TJ Holowaychuk",
|
||||
"email": "tj@vision-media.ca"
|
||||
"name": "Josh Junon",
|
||||
"email": "josh.junon@protonmail.com"
|
||||
},
|
||||
"browser": "./src/browser.js",
|
||||
"bugs": {
|
||||
"url": "https://github.com/visionmedia/debug/issues"
|
||||
"url": "https://github.com/debug-js/debug/issues"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "TJ Holowaychuk",
|
||||
"email": "tj@vision-media.ca"
|
||||
},
|
||||
{
|
||||
"name": "Nathan Rajlich",
|
||||
"email": "nathan@tootallnate.net",
|
||||
@@ -47,34 +51,31 @@
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"ms": "^2.1.1"
|
||||
"ms": "2.1.2"
|
||||
},
|
||||
"description": "small debugging utility",
|
||||
"description": "Lightweight debugging utility for Node.js and the browser",
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.0.0",
|
||||
"@babel/core": "^7.0.0",
|
||||
"@babel/preset-env": "^7.0.0",
|
||||
"browserify": "14.4.0",
|
||||
"chai": "^3.5.0",
|
||||
"concurrently": "^3.1.0",
|
||||
"brfs": "^2.0.1",
|
||||
"browserify": "^16.2.3",
|
||||
"coveralls": "^3.0.2",
|
||||
"istanbul": "^0.4.5",
|
||||
"karma": "^3.0.0",
|
||||
"karma-chai": "^0.1.0",
|
||||
"karma": "^3.1.4",
|
||||
"karma-browserify": "^6.0.0",
|
||||
"karma-chrome-launcher": "^2.2.0",
|
||||
"karma-mocha": "^1.3.0",
|
||||
"karma-phantomjs-launcher": "^1.0.2",
|
||||
"mocha": "^5.2.0",
|
||||
"mocha-lcov-reporter": "^1.2.0",
|
||||
"rimraf": "^2.5.4",
|
||||
"xo": "^0.23.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
"dist/debug.js",
|
||||
"LICENSE",
|
||||
"README.md"
|
||||
],
|
||||
"homepage": "https://github.com/visionmedia/debug#readme",
|
||||
"homepage": "https://github.com/debug-js/debug#readme",
|
||||
"keywords": [
|
||||
"debug",
|
||||
"log",
|
||||
@@ -83,23 +84,21 @@
|
||||
"license": "MIT",
|
||||
"main": "./src/index.js",
|
||||
"name": "debug",
|
||||
"peerDependenciesMeta": {
|
||||
"supports-color": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/visionmedia/debug.git"
|
||||
"url": "git://github.com/debug-js/debug.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run build:debug && npm run build:test",
|
||||
"build:debug": "babel -o dist/debug.js dist/debug.es6.js > dist/debug.js",
|
||||
"build:test": "babel -d dist test.js",
|
||||
"clean": "rimraf dist coverage",
|
||||
"lint": "xo",
|
||||
"prebuild:debug": "mkdir -p dist && browserify --standalone debug -o dist/debug.es6.js .",
|
||||
"pretest:browser": "npm run build",
|
||||
"test": "npm run test:node && npm run test:browser",
|
||||
"test": "npm run test:node && npm run test:browser && npm run lint",
|
||||
"test:browser": "karma start --single-run",
|
||||
"test:coverage": "cat ./coverage/lcov.info | coveralls",
|
||||
"test:node": "istanbul cover _mocha -- test.js"
|
||||
},
|
||||
"unpkg": "./dist/debug.js",
|
||||
"version": "4.1.1"
|
||||
"version": "4.3.4"
|
||||
}
|
||||
|
||||
+15
-10
@@ -4,12 +4,21 @@
|
||||
* This is the web browser implementation of `debug()`.
|
||||
*/
|
||||
|
||||
exports.log = log;
|
||||
exports.formatArgs = formatArgs;
|
||||
exports.save = save;
|
||||
exports.load = load;
|
||||
exports.useColors = useColors;
|
||||
exports.storage = localstorage();
|
||||
exports.destroy = (() => {
|
||||
let warned = false;
|
||||
|
||||
return () => {
|
||||
if (!warned) {
|
||||
warned = true;
|
||||
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
/**
|
||||
* Colors.
|
||||
@@ -170,18 +179,14 @@ function formatArgs(args) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes `console.log()` when available.
|
||||
* No-op when `console.log` is not a "function".
|
||||
* Invokes `console.debug()` when available.
|
||||
* No-op when `console.debug` is not a "function".
|
||||
* If `console.debug` is not available, falls back
|
||||
* to `console.log`.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
function log(...args) {
|
||||
// This hackery is required for IE8/9, where
|
||||
// the `console.log` function doesn't have 'apply'
|
||||
return typeof console === 'object' &&
|
||||
console.log &&
|
||||
console.log(...args);
|
||||
}
|
||||
exports.log = console.debug || console.log || (() => {});
|
||||
|
||||
/**
|
||||
* Save `namespaces`.
|
||||
|
||||
+38
-30
@@ -12,16 +12,12 @@ function setup(env) {
|
||||
createDebug.enable = enable;
|
||||
createDebug.enabled = enabled;
|
||||
createDebug.humanize = require('ms');
|
||||
createDebug.destroy = destroy;
|
||||
|
||||
Object.keys(env).forEach(key => {
|
||||
createDebug[key] = env[key];
|
||||
});
|
||||
|
||||
/**
|
||||
* Active `debug` instances.
|
||||
*/
|
||||
createDebug.instances = [];
|
||||
|
||||
/**
|
||||
* The currently active debug mode names, and names to skip.
|
||||
*/
|
||||
@@ -38,7 +34,7 @@ function setup(env) {
|
||||
|
||||
/**
|
||||
* Selects a color for a debug namespace
|
||||
* @param {String} namespace The namespace string for the for the debug instance to be colored
|
||||
* @param {String} namespace The namespace string for the debug instance to be colored
|
||||
* @return {Number|String} An ANSI color code for the given namespace
|
||||
* @api private
|
||||
*/
|
||||
@@ -63,6 +59,9 @@ function setup(env) {
|
||||
*/
|
||||
function createDebug(namespace) {
|
||||
let prevTime;
|
||||
let enableOverride = null;
|
||||
let namespacesCache;
|
||||
let enabledCache;
|
||||
|
||||
function debug(...args) {
|
||||
// Disabled?
|
||||
@@ -92,7 +91,7 @@ function setup(env) {
|
||||
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
||||
// If we encounter an escaped % then don't increase the array index
|
||||
if (match === '%%') {
|
||||
return match;
|
||||
return '%';
|
||||
}
|
||||
index++;
|
||||
const formatter = createDebug.formatters[format];
|
||||
@@ -115,33 +114,38 @@ function setup(env) {
|
||||
}
|
||||
|
||||
debug.namespace = namespace;
|
||||
debug.enabled = createDebug.enabled(namespace);
|
||||
debug.useColors = createDebug.useColors();
|
||||
debug.color = selectColor(namespace);
|
||||
debug.destroy = destroy;
|
||||
debug.color = createDebug.selectColor(namespace);
|
||||
debug.extend = extend;
|
||||
// Debug.formatArgs = formatArgs;
|
||||
// debug.rawLog = rawLog;
|
||||
debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
|
||||
|
||||
// env-specific initialization logic for debug instances
|
||||
Object.defineProperty(debug, 'enabled', {
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
get: () => {
|
||||
if (enableOverride !== null) {
|
||||
return enableOverride;
|
||||
}
|
||||
if (namespacesCache !== createDebug.namespaces) {
|
||||
namespacesCache = createDebug.namespaces;
|
||||
enabledCache = createDebug.enabled(namespace);
|
||||
}
|
||||
|
||||
return enabledCache;
|
||||
},
|
||||
set: v => {
|
||||
enableOverride = v;
|
||||
}
|
||||
});
|
||||
|
||||
// Env-specific initialization logic for debug instances
|
||||
if (typeof createDebug.init === 'function') {
|
||||
createDebug.init(debug);
|
||||
}
|
||||
|
||||
createDebug.instances.push(debug);
|
||||
|
||||
return debug;
|
||||
}
|
||||
|
||||
function destroy() {
|
||||
const index = createDebug.instances.indexOf(this);
|
||||
if (index !== -1) {
|
||||
createDebug.instances.splice(index, 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function extend(namespace, delimiter) {
|
||||
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
||||
newDebug.log = this.log;
|
||||
@@ -157,6 +161,7 @@ function setup(env) {
|
||||
*/
|
||||
function enable(namespaces) {
|
||||
createDebug.save(namespaces);
|
||||
createDebug.namespaces = namespaces;
|
||||
|
||||
createDebug.names = [];
|
||||
createDebug.skips = [];
|
||||
@@ -174,16 +179,11 @@ function setup(env) {
|
||||
namespaces = split[i].replace(/\*/g, '.*?');
|
||||
|
||||
if (namespaces[0] === '-') {
|
||||
createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
||||
createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
|
||||
} else {
|
||||
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < createDebug.instances.length; i++) {
|
||||
const instance = createDebug.instances[i];
|
||||
instance.enabled = createDebug.enabled(instance.namespace);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,6 +258,14 @@ function setup(env) {
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* XXX DO NOT USE. This is a temporary stub function.
|
||||
* XXX It WILL be removed in the next major release.
|
||||
*/
|
||||
function destroy() {
|
||||
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
||||
}
|
||||
|
||||
createDebug.enable(createDebug.load());
|
||||
|
||||
return createDebug;
|
||||
|
||||
+7
-1
@@ -15,6 +15,10 @@ exports.formatArgs = formatArgs;
|
||||
exports.save = save;
|
||||
exports.load = load;
|
||||
exports.useColors = useColors;
|
||||
exports.destroy = util.deprecate(
|
||||
() => {},
|
||||
'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
|
||||
);
|
||||
|
||||
/**
|
||||
* Colors.
|
||||
@@ -244,7 +248,9 @@ const {formatters} = module.exports;
|
||||
formatters.o = function (v) {
|
||||
this.inspectOpts.colors = this.useColors;
|
||||
return util.inspect(v, this.inspectOpts)
|
||||
.replace(/\s*\n\s*/g, ' ');
|
||||
.split('\n')
|
||||
.map(str => str.trim())
|
||||
.join(' ');
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
+31
@@ -1,5 +1,36 @@
|
||||
# changes log
|
||||
|
||||
## 6.2.0
|
||||
|
||||
* Coerce numbers to strings when passed to semver.coerce()
|
||||
* Add `rtl` option to coerce from right to left
|
||||
|
||||
## 6.1.3
|
||||
|
||||
* Handle X-ranges properly in includePrerelease mode
|
||||
|
||||
## 6.1.2
|
||||
|
||||
* Do not throw when testing invalid version strings
|
||||
|
||||
## 6.1.1
|
||||
|
||||
* Add options support for semver.coerce()
|
||||
* Handle undefined version passed to Range.test
|
||||
|
||||
## 6.1.0
|
||||
|
||||
* Add semver.compareBuild function
|
||||
* Support `*` in semver.intersects
|
||||
|
||||
## 6.0
|
||||
|
||||
* Fix `intersects` logic.
|
||||
|
||||
This is technically a bug fix, but since it is also a change to behavior
|
||||
that may require users updating their code, it is marked as a major
|
||||
version increment.
|
||||
|
||||
## 5.7
|
||||
|
||||
* Add `minVersion` method
|
||||
|
||||
+35
-4
@@ -4,7 +4,7 @@ semver(1) -- The semantic versioner for npm
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm install --save semver
|
||||
npm install semver
|
||||
````
|
||||
|
||||
## Usage
|
||||
@@ -60,6 +60,12 @@ Options:
|
||||
Coerce a string into SemVer if possible
|
||||
(does not imply --loose)
|
||||
|
||||
--rtl
|
||||
Coerce version strings right to left
|
||||
|
||||
--ltr
|
||||
Coerce version strings left to right (default)
|
||||
|
||||
Program exits successfully if any valid version satisfies
|
||||
all supplied ranges, and prints all satisfying versions.
|
||||
|
||||
@@ -231,7 +237,7 @@ comparator. Allows minor-level changes if not.
|
||||
|
||||
#### Caret Ranges `^1.2.3` `^0.2.5` `^0.0.4`
|
||||
|
||||
Allows changes that do not modify the left-most non-zero digit in the
|
||||
Allows changes that do not modify the left-most non-zero element in the
|
||||
`[major, minor, patch]` tuple. In other words, this allows patch and
|
||||
minor updates for versions `1.0.0` and above, patch updates for
|
||||
versions `0.X >=0.1.0`, and *no* updates for versions `0.0.X`.
|
||||
@@ -354,6 +360,9 @@ strings that they parse.
|
||||
`v2` is greater. Sorts in ascending order if passed to `Array.sort()`.
|
||||
* `rcompare(v1, v2)`: The reverse of compare. Sorts an array of versions
|
||||
in descending order when passed to `Array.sort()`.
|
||||
* `compareBuild(v1, v2)`: The same as `compare` but considers `build` when two versions
|
||||
are equal. Sorts in ascending order if passed to `Array.sort()`.
|
||||
`v2` is greater. Sorts in ascending order if passed to `Array.sort()`.
|
||||
* `diff(v1, v2)`: Returns difference between two versions by the release type
|
||||
(`major`, `premajor`, `minor`, `preminor`, `patch`, `prepatch`, or `prerelease`),
|
||||
or null if the versions are the same.
|
||||
@@ -396,7 +405,7 @@ range, use the `satisfies(version, range)` function.
|
||||
|
||||
### Coercion
|
||||
|
||||
* `coerce(version)`: Coerces a string to semver if possible
|
||||
* `coerce(version, options)`: Coerces a string to semver if possible
|
||||
|
||||
This aims to provide a very forgiving translation of a non-semver string to
|
||||
semver. It looks for the first digit in a string, and consumes all
|
||||
@@ -408,5 +417,27 @@ surrounding text is simply ignored (`v3.4 replaces v3.3.1` becomes
|
||||
is not valid). The maximum length for any semver component considered for
|
||||
coercion is 16 characters; longer components will be ignored
|
||||
(`10000000000000000.4.7.4` becomes `4.7.4`). The maximum value for any
|
||||
semver component is `Number.MAX_SAFE_INTEGER || (2**53 - 1)`; higher value
|
||||
semver component is `Integer.MAX_SAFE_INTEGER || (2**53 - 1)`; higher value
|
||||
components are invalid (`9999999999999999.4.7.4` is likely invalid).
|
||||
|
||||
If the `options.rtl` flag is set, then `coerce` will return the right-most
|
||||
coercible tuple that does not share an ending index with a longer coercible
|
||||
tuple. For example, `1.2.3.4` will return `2.3.4` in rtl mode, not
|
||||
`4.0.0`. `1.2.3/4` will return `4.0.0`, because the `4` is not a part of
|
||||
any other overlapping SemVer tuple.
|
||||
|
||||
### Clean
|
||||
|
||||
* `clean(version)`: Clean a string to be a valid semver if possible
|
||||
|
||||
This will return a cleaned and trimmed semver version. If the provided version is not valid a null will be returned. This does not work for ranges.
|
||||
|
||||
ex.
|
||||
* `s.clean(' = v 2.1.5foo')`: `null`
|
||||
* `s.clean(' = v 2.1.5foo', { loose: true })`: `'2.1.5-foo'`
|
||||
* `s.clean(' = v 2.1.5-foo')`: `null`
|
||||
* `s.clean(' = v 2.1.5-foo', { loose: true })`: `'2.1.5-foo'`
|
||||
* `s.clean('=v2.1.5')`: `'2.1.5'`
|
||||
* `s.clean(' =v2.1.5')`: `2.1.5`
|
||||
* `s.clean(' 2.1.5 ')`: `'2.1.5'`
|
||||
* `s.clean('~1.0.0')`: `null`
|
||||
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
#!/usr/bin/env node
|
||||
// Standalone semver comparison program.
|
||||
// Exits successfully and prints matching version(s) if
|
||||
// any supplied version is valid and passes all tests.
|
||||
|
||||
var argv = process.argv.slice(2)
|
||||
|
||||
var versions = []
|
||||
|
||||
var range = []
|
||||
|
||||
var inc = null
|
||||
|
||||
var version = require('../package.json').version
|
||||
|
||||
var loose = false
|
||||
|
||||
var includePrerelease = false
|
||||
|
||||
var coerce = false
|
||||
|
||||
var rtl = false
|
||||
|
||||
var identifier
|
||||
|
||||
var semver = require('../semver')
|
||||
|
||||
var reverse = false
|
||||
|
||||
var options = {}
|
||||
|
||||
main()
|
||||
|
||||
function main () {
|
||||
if (!argv.length) return help()
|
||||
while (argv.length) {
|
||||
var a = argv.shift()
|
||||
var indexOfEqualSign = a.indexOf('=')
|
||||
if (indexOfEqualSign !== -1) {
|
||||
a = a.slice(0, indexOfEqualSign)
|
||||
argv.unshift(a.slice(indexOfEqualSign + 1))
|
||||
}
|
||||
switch (a) {
|
||||
case '-rv': case '-rev': case '--rev': case '--reverse':
|
||||
reverse = true
|
||||
break
|
||||
case '-l': case '--loose':
|
||||
loose = true
|
||||
break
|
||||
case '-p': case '--include-prerelease':
|
||||
includePrerelease = true
|
||||
break
|
||||
case '-v': case '--version':
|
||||
versions.push(argv.shift())
|
||||
break
|
||||
case '-i': case '--inc': case '--increment':
|
||||
switch (argv[0]) {
|
||||
case 'major': case 'minor': case 'patch': case 'prerelease':
|
||||
case 'premajor': case 'preminor': case 'prepatch':
|
||||
inc = argv.shift()
|
||||
break
|
||||
default:
|
||||
inc = 'patch'
|
||||
break
|
||||
}
|
||||
break
|
||||
case '--preid':
|
||||
identifier = argv.shift()
|
||||
break
|
||||
case '-r': case '--range':
|
||||
range.push(argv.shift())
|
||||
break
|
||||
case '-c': case '--coerce':
|
||||
coerce = true
|
||||
break
|
||||
case '--rtl':
|
||||
rtl = true
|
||||
break
|
||||
case '--ltr':
|
||||
rtl = false
|
||||
break
|
||||
case '-h': case '--help': case '-?':
|
||||
return help()
|
||||
default:
|
||||
versions.push(a)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
var options = { loose: loose, includePrerelease: includePrerelease, rtl: rtl }
|
||||
|
||||
versions = versions.map(function (v) {
|
||||
return coerce ? (semver.coerce(v, options) || { version: v }).version : v
|
||||
}).filter(function (v) {
|
||||
return semver.valid(v)
|
||||
})
|
||||
if (!versions.length) return fail()
|
||||
if (inc && (versions.length !== 1 || range.length)) { return failInc() }
|
||||
|
||||
for (var i = 0, l = range.length; i < l; i++) {
|
||||
versions = versions.filter(function (v) {
|
||||
return semver.satisfies(v, range[i], options)
|
||||
})
|
||||
if (!versions.length) return fail()
|
||||
}
|
||||
return success(versions)
|
||||
}
|
||||
|
||||
function failInc () {
|
||||
console.error('--inc can only be used on a single version with no range')
|
||||
fail()
|
||||
}
|
||||
|
||||
function fail () { process.exit(1) }
|
||||
|
||||
function success () {
|
||||
var compare = reverse ? 'rcompare' : 'compare'
|
||||
versions.sort(function (a, b) {
|
||||
return semver[compare](a, b, options)
|
||||
}).map(function (v) {
|
||||
return semver.clean(v, options)
|
||||
}).map(function (v) {
|
||||
return inc ? semver.inc(v, inc, options, identifier) : v
|
||||
}).forEach(function (v, i, _) { console.log(v) })
|
||||
}
|
||||
|
||||
function help () {
|
||||
console.log(['SemVer ' + version,
|
||||
'',
|
||||
'A JavaScript implementation of the https://semver.org/ specification',
|
||||
'Copyright Isaac Z. Schlueter',
|
||||
'',
|
||||
'Usage: semver [options] <version> [<version> [...]]',
|
||||
'Prints valid versions sorted by SemVer precedence',
|
||||
'',
|
||||
'Options:',
|
||||
'-r --range <range>',
|
||||
' Print versions that match the specified range.',
|
||||
'',
|
||||
'-i --increment [<level>]',
|
||||
' Increment a version by the specified level. Level can',
|
||||
' be one of: major, minor, patch, premajor, preminor,',
|
||||
" prepatch, or prerelease. Default level is 'patch'.",
|
||||
' Only one version may be specified.',
|
||||
'',
|
||||
'--preid <identifier>',
|
||||
' Identifier to be used to prefix premajor, preminor,',
|
||||
' prepatch or prerelease version increments.',
|
||||
'',
|
||||
'-l --loose',
|
||||
' Interpret versions and ranges loosely',
|
||||
'',
|
||||
'-p --include-prerelease',
|
||||
' Always include prerelease versions in range matching',
|
||||
'',
|
||||
'-c --coerce',
|
||||
' Coerce a string into SemVer if possible',
|
||||
' (does not imply --loose)',
|
||||
'',
|
||||
'--rtl',
|
||||
' Coerce version strings right to left',
|
||||
'',
|
||||
'--ltr',
|
||||
' Coerce version strings left to right (default)',
|
||||
'',
|
||||
'Program exits successfully if any valid version satisfies',
|
||||
'all supplied ranges, and prints all satisfying versions.',
|
||||
'',
|
||||
'If no satisfying versions are found, then exits failure.',
|
||||
'',
|
||||
'Versions are printed in ascending order, so supplying',
|
||||
'multiple versions to the utility will just sort them.'
|
||||
].join('\n'))
|
||||
}
|
||||
+15
-15
@@ -1,41 +1,41 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"semver@5.7.1",
|
||||
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
|
||||
"semver@6.3.0",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "semver@5.7.1",
|
||||
"_id": "semver@5.7.1",
|
||||
"_from": "semver@6.3.0",
|
||||
"_id": "semver@6.3.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==",
|
||||
"_integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
|
||||
"_location": "/@babel/core/semver",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "semver@5.7.1",
|
||||
"raw": "semver@6.3.0",
|
||||
"name": "semver",
|
||||
"escapedName": "semver",
|
||||
"rawSpec": "5.7.1",
|
||||
"rawSpec": "6.3.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "5.7.1"
|
||||
"fetchSpec": "6.3.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@babel/core"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz",
|
||||
"_spec": "5.7.1",
|
||||
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
|
||||
"_resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
|
||||
"_spec": "6.3.0",
|
||||
"_where": "/home/node/nuxt",
|
||||
"bin": {
|
||||
"semver": "bin/semver"
|
||||
"semver": "bin/semver.js"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/npm/node-semver/issues"
|
||||
},
|
||||
"description": "The semantic version parser used by npm.",
|
||||
"devDependencies": {
|
||||
"tap": "^13.0.0-rc.18"
|
||||
"tap": "^14.3.1"
|
||||
},
|
||||
"files": [
|
||||
"bin",
|
||||
@@ -51,7 +51,7 @@
|
||||
"url": "git+https://github.com/npm/node-semver.git"
|
||||
},
|
||||
"scripts": {
|
||||
"postpublish": "git push origin --all; git push origin --tags",
|
||||
"postpublish": "git push origin --follow-tags",
|
||||
"postversion": "npm publish",
|
||||
"preversion": "npm test",
|
||||
"test": "tap"
|
||||
@@ -59,5 +59,5 @@
|
||||
"tap": {
|
||||
"check-coverage": true
|
||||
},
|
||||
"version": "5.7.1"
|
||||
"version": "6.3.0"
|
||||
}
|
||||
|
||||
+248
-135
@@ -29,75 +29,80 @@ var MAX_SAFE_COMPONENT_LENGTH = 16
|
||||
// The actual regexps go on exports.re
|
||||
var re = exports.re = []
|
||||
var src = exports.src = []
|
||||
var t = exports.tokens = {}
|
||||
var R = 0
|
||||
|
||||
function tok (n) {
|
||||
t[n] = R++
|
||||
}
|
||||
|
||||
// The following Regular Expressions can be used for tokenizing,
|
||||
// validating, and parsing SemVer version strings.
|
||||
|
||||
// ## Numeric Identifier
|
||||
// A single `0`, or a non-zero digit followed by zero or more digits.
|
||||
|
||||
var NUMERICIDENTIFIER = R++
|
||||
src[NUMERICIDENTIFIER] = '0|[1-9]\\d*'
|
||||
var NUMERICIDENTIFIERLOOSE = R++
|
||||
src[NUMERICIDENTIFIERLOOSE] = '[0-9]+'
|
||||
tok('NUMERICIDENTIFIER')
|
||||
src[t.NUMERICIDENTIFIER] = '0|[1-9]\\d*'
|
||||
tok('NUMERICIDENTIFIERLOOSE')
|
||||
src[t.NUMERICIDENTIFIERLOOSE] = '[0-9]+'
|
||||
|
||||
// ## Non-numeric Identifier
|
||||
// Zero or more digits, followed by a letter or hyphen, and then zero or
|
||||
// more letters, digits, or hyphens.
|
||||
|
||||
var NONNUMERICIDENTIFIER = R++
|
||||
src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'
|
||||
tok('NONNUMERICIDENTIFIER')
|
||||
src[t.NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'
|
||||
|
||||
// ## Main Version
|
||||
// Three dot-separated numeric identifiers.
|
||||
|
||||
var MAINVERSION = R++
|
||||
src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' +
|
||||
'(' + src[NUMERICIDENTIFIER] + ')\\.' +
|
||||
'(' + src[NUMERICIDENTIFIER] + ')'
|
||||
tok('MAINVERSION')
|
||||
src[t.MAINVERSION] = '(' + src[t.NUMERICIDENTIFIER] + ')\\.' +
|
||||
'(' + src[t.NUMERICIDENTIFIER] + ')\\.' +
|
||||
'(' + src[t.NUMERICIDENTIFIER] + ')'
|
||||
|
||||
var MAINVERSIONLOOSE = R++
|
||||
src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
|
||||
'(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
|
||||
'(' + src[NUMERICIDENTIFIERLOOSE] + ')'
|
||||
tok('MAINVERSIONLOOSE')
|
||||
src[t.MAINVERSIONLOOSE] = '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' +
|
||||
'(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' +
|
||||
'(' + src[t.NUMERICIDENTIFIERLOOSE] + ')'
|
||||
|
||||
// ## Pre-release Version Identifier
|
||||
// A numeric identifier, or a non-numeric identifier.
|
||||
|
||||
var PRERELEASEIDENTIFIER = R++
|
||||
src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] +
|
||||
'|' + src[NONNUMERICIDENTIFIER] + ')'
|
||||
tok('PRERELEASEIDENTIFIER')
|
||||
src[t.PRERELEASEIDENTIFIER] = '(?:' + src[t.NUMERICIDENTIFIER] +
|
||||
'|' + src[t.NONNUMERICIDENTIFIER] + ')'
|
||||
|
||||
var PRERELEASEIDENTIFIERLOOSE = R++
|
||||
src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] +
|
||||
'|' + src[NONNUMERICIDENTIFIER] + ')'
|
||||
tok('PRERELEASEIDENTIFIERLOOSE')
|
||||
src[t.PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[t.NUMERICIDENTIFIERLOOSE] +
|
||||
'|' + src[t.NONNUMERICIDENTIFIER] + ')'
|
||||
|
||||
// ## Pre-release Version
|
||||
// Hyphen, followed by one or more dot-separated pre-release version
|
||||
// identifiers.
|
||||
|
||||
var PRERELEASE = R++
|
||||
src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] +
|
||||
'(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))'
|
||||
tok('PRERELEASE')
|
||||
src[t.PRERELEASE] = '(?:-(' + src[t.PRERELEASEIDENTIFIER] +
|
||||
'(?:\\.' + src[t.PRERELEASEIDENTIFIER] + ')*))'
|
||||
|
||||
var PRERELEASELOOSE = R++
|
||||
src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] +
|
||||
'(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))'
|
||||
tok('PRERELEASELOOSE')
|
||||
src[t.PRERELEASELOOSE] = '(?:-?(' + src[t.PRERELEASEIDENTIFIERLOOSE] +
|
||||
'(?:\\.' + src[t.PRERELEASEIDENTIFIERLOOSE] + ')*))'
|
||||
|
||||
// ## Build Metadata Identifier
|
||||
// Any combination of digits, letters, or hyphens.
|
||||
|
||||
var BUILDIDENTIFIER = R++
|
||||
src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+'
|
||||
tok('BUILDIDENTIFIER')
|
||||
src[t.BUILDIDENTIFIER] = '[0-9A-Za-z-]+'
|
||||
|
||||
// ## Build Metadata
|
||||
// Plus sign, followed by one or more period-separated build metadata
|
||||
// identifiers.
|
||||
|
||||
var BUILD = R++
|
||||
src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] +
|
||||
'(?:\\.' + src[BUILDIDENTIFIER] + ')*))'
|
||||
tok('BUILD')
|
||||
src[t.BUILD] = '(?:\\+(' + src[t.BUILDIDENTIFIER] +
|
||||
'(?:\\.' + src[t.BUILDIDENTIFIER] + ')*))'
|
||||
|
||||
// ## Full Version String
|
||||
// A main version, followed optionally by a pre-release version and
|
||||
@@ -108,129 +113,133 @@ src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] +
|
||||
// capturing group, because it should not ever be used in version
|
||||
// comparison.
|
||||
|
||||
var FULL = R++
|
||||
var FULLPLAIN = 'v?' + src[MAINVERSION] +
|
||||
src[PRERELEASE] + '?' +
|
||||
src[BUILD] + '?'
|
||||
tok('FULL')
|
||||
tok('FULLPLAIN')
|
||||
src[t.FULLPLAIN] = 'v?' + src[t.MAINVERSION] +
|
||||
src[t.PRERELEASE] + '?' +
|
||||
src[t.BUILD] + '?'
|
||||
|
||||
src[FULL] = '^' + FULLPLAIN + '$'
|
||||
src[t.FULL] = '^' + src[t.FULLPLAIN] + '$'
|
||||
|
||||
// like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
|
||||
// also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
|
||||
// common in the npm registry.
|
||||
var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] +
|
||||
src[PRERELEASELOOSE] + '?' +
|
||||
src[BUILD] + '?'
|
||||
tok('LOOSEPLAIN')
|
||||
src[t.LOOSEPLAIN] = '[v=\\s]*' + src[t.MAINVERSIONLOOSE] +
|
||||
src[t.PRERELEASELOOSE] + '?' +
|
||||
src[t.BUILD] + '?'
|
||||
|
||||
var LOOSE = R++
|
||||
src[LOOSE] = '^' + LOOSEPLAIN + '$'
|
||||
tok('LOOSE')
|
||||
src[t.LOOSE] = '^' + src[t.LOOSEPLAIN] + '$'
|
||||
|
||||
var GTLT = R++
|
||||
src[GTLT] = '((?:<|>)?=?)'
|
||||
tok('GTLT')
|
||||
src[t.GTLT] = '((?:<|>)?=?)'
|
||||
|
||||
// Something like "2.*" or "1.2.x".
|
||||
// Note that "x.x" is a valid xRange identifer, meaning "any version"
|
||||
// Only the first item is strictly required.
|
||||
var XRANGEIDENTIFIERLOOSE = R++
|
||||
src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*'
|
||||
var XRANGEIDENTIFIER = R++
|
||||
src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*'
|
||||
tok('XRANGEIDENTIFIERLOOSE')
|
||||
src[t.XRANGEIDENTIFIERLOOSE] = src[t.NUMERICIDENTIFIERLOOSE] + '|x|X|\\*'
|
||||
tok('XRANGEIDENTIFIER')
|
||||
src[t.XRANGEIDENTIFIER] = src[t.NUMERICIDENTIFIER] + '|x|X|\\*'
|
||||
|
||||
var XRANGEPLAIN = R++
|
||||
src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' +
|
||||
'(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
|
||||
'(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
|
||||
'(?:' + src[PRERELEASE] + ')?' +
|
||||
src[BUILD] + '?' +
|
||||
tok('XRANGEPLAIN')
|
||||
src[t.XRANGEPLAIN] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIER] + ')' +
|
||||
'(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' +
|
||||
'(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' +
|
||||
'(?:' + src[t.PRERELEASE] + ')?' +
|
||||
src[t.BUILD] + '?' +
|
||||
')?)?'
|
||||
|
||||
var XRANGEPLAINLOOSE = R++
|
||||
src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
|
||||
'(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
|
||||
'(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
|
||||
'(?:' + src[PRERELEASELOOSE] + ')?' +
|
||||
src[BUILD] + '?' +
|
||||
tok('XRANGEPLAINLOOSE')
|
||||
src[t.XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' +
|
||||
'(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' +
|
||||
'(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' +
|
||||
'(?:' + src[t.PRERELEASELOOSE] + ')?' +
|
||||
src[t.BUILD] + '?' +
|
||||
')?)?'
|
||||
|
||||
var XRANGE = R++
|
||||
src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$'
|
||||
var XRANGELOOSE = R++
|
||||
src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$'
|
||||
tok('XRANGE')
|
||||
src[t.XRANGE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAIN] + '$'
|
||||
tok('XRANGELOOSE')
|
||||
src[t.XRANGELOOSE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAINLOOSE] + '$'
|
||||
|
||||
// Coercion.
|
||||
// Extract anything that could conceivably be a part of a valid semver
|
||||
var COERCE = R++
|
||||
src[COERCE] = '(?:^|[^\\d])' +
|
||||
tok('COERCE')
|
||||
src[t.COERCE] = '(^|[^\\d])' +
|
||||
'(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' +
|
||||
'(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
|
||||
'(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
|
||||
'(?:$|[^\\d])'
|
||||
tok('COERCERTL')
|
||||
re[t.COERCERTL] = new RegExp(src[t.COERCE], 'g')
|
||||
|
||||
// Tilde ranges.
|
||||
// Meaning is "reasonably at or greater than"
|
||||
var LONETILDE = R++
|
||||
src[LONETILDE] = '(?:~>?)'
|
||||
tok('LONETILDE')
|
||||
src[t.LONETILDE] = '(?:~>?)'
|
||||
|
||||
var TILDETRIM = R++
|
||||
src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+'
|
||||
re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g')
|
||||
tok('TILDETRIM')
|
||||
src[t.TILDETRIM] = '(\\s*)' + src[t.LONETILDE] + '\\s+'
|
||||
re[t.TILDETRIM] = new RegExp(src[t.TILDETRIM], 'g')
|
||||
var tildeTrimReplace = '$1~'
|
||||
|
||||
var TILDE = R++
|
||||
src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$'
|
||||
var TILDELOOSE = R++
|
||||
src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$'
|
||||
tok('TILDE')
|
||||
src[t.TILDE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAIN] + '$'
|
||||
tok('TILDELOOSE')
|
||||
src[t.TILDELOOSE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAINLOOSE] + '$'
|
||||
|
||||
// Caret ranges.
|
||||
// Meaning is "at least and backwards compatible with"
|
||||
var LONECARET = R++
|
||||
src[LONECARET] = '(?:\\^)'
|
||||
tok('LONECARET')
|
||||
src[t.LONECARET] = '(?:\\^)'
|
||||
|
||||
var CARETTRIM = R++
|
||||
src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+'
|
||||
re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g')
|
||||
tok('CARETTRIM')
|
||||
src[t.CARETTRIM] = '(\\s*)' + src[t.LONECARET] + '\\s+'
|
||||
re[t.CARETTRIM] = new RegExp(src[t.CARETTRIM], 'g')
|
||||
var caretTrimReplace = '$1^'
|
||||
|
||||
var CARET = R++
|
||||
src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$'
|
||||
var CARETLOOSE = R++
|
||||
src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$'
|
||||
tok('CARET')
|
||||
src[t.CARET] = '^' + src[t.LONECARET] + src[t.XRANGEPLAIN] + '$'
|
||||
tok('CARETLOOSE')
|
||||
src[t.CARETLOOSE] = '^' + src[t.LONECARET] + src[t.XRANGEPLAINLOOSE] + '$'
|
||||
|
||||
// A simple gt/lt/eq thing, or just "" to indicate "any version"
|
||||
var COMPARATORLOOSE = R++
|
||||
src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$'
|
||||
var COMPARATOR = R++
|
||||
src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$'
|
||||
tok('COMPARATORLOOSE')
|
||||
src[t.COMPARATORLOOSE] = '^' + src[t.GTLT] + '\\s*(' + src[t.LOOSEPLAIN] + ')$|^$'
|
||||
tok('COMPARATOR')
|
||||
src[t.COMPARATOR] = '^' + src[t.GTLT] + '\\s*(' + src[t.FULLPLAIN] + ')$|^$'
|
||||
|
||||
// An expression to strip any whitespace between the gtlt and the thing
|
||||
// it modifies, so that `> 1.2.3` ==> `>1.2.3`
|
||||
var COMPARATORTRIM = R++
|
||||
src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] +
|
||||
'\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')'
|
||||
tok('COMPARATORTRIM')
|
||||
src[t.COMPARATORTRIM] = '(\\s*)' + src[t.GTLT] +
|
||||
'\\s*(' + src[t.LOOSEPLAIN] + '|' + src[t.XRANGEPLAIN] + ')'
|
||||
|
||||
// this one has to use the /g flag
|
||||
re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g')
|
||||
re[t.COMPARATORTRIM] = new RegExp(src[t.COMPARATORTRIM], 'g')
|
||||
var comparatorTrimReplace = '$1$2$3'
|
||||
|
||||
// Something like `1.2.3 - 1.2.4`
|
||||
// Note that these all use the loose form, because they'll be
|
||||
// checked against either the strict or loose comparator form
|
||||
// later.
|
||||
var HYPHENRANGE = R++
|
||||
src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' +
|
||||
tok('HYPHENRANGE')
|
||||
src[t.HYPHENRANGE] = '^\\s*(' + src[t.XRANGEPLAIN] + ')' +
|
||||
'\\s+-\\s+' +
|
||||
'(' + src[XRANGEPLAIN] + ')' +
|
||||
'(' + src[t.XRANGEPLAIN] + ')' +
|
||||
'\\s*$'
|
||||
|
||||
var HYPHENRANGELOOSE = R++
|
||||
src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' +
|
||||
tok('HYPHENRANGELOOSE')
|
||||
src[t.HYPHENRANGELOOSE] = '^\\s*(' + src[t.XRANGEPLAINLOOSE] + ')' +
|
||||
'\\s+-\\s+' +
|
||||
'(' + src[XRANGEPLAINLOOSE] + ')' +
|
||||
'(' + src[t.XRANGEPLAINLOOSE] + ')' +
|
||||
'\\s*$'
|
||||
|
||||
// Star ranges basically just allow anything at all.
|
||||
var STAR = R++
|
||||
src[STAR] = '(<|>)?=?\\s*\\*'
|
||||
tok('STAR')
|
||||
src[t.STAR] = '(<|>)?=?\\s*\\*'
|
||||
|
||||
// Compile to actual regexp objects.
|
||||
// All are flag-free, unless they were created above with a flag.
|
||||
@@ -262,7 +271,7 @@ function parse (version, options) {
|
||||
return null
|
||||
}
|
||||
|
||||
var r = options.loose ? re[LOOSE] : re[FULL]
|
||||
var r = options.loose ? re[t.LOOSE] : re[t.FULL]
|
||||
if (!r.test(version)) {
|
||||
return null
|
||||
}
|
||||
@@ -317,7 +326,7 @@ function SemVer (version, options) {
|
||||
this.options = options
|
||||
this.loose = !!options.loose
|
||||
|
||||
var m = version.trim().match(options.loose ? re[LOOSE] : re[FULL])
|
||||
var m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL])
|
||||
|
||||
if (!m) {
|
||||
throw new TypeError('Invalid Version: ' + version)
|
||||
@@ -425,6 +434,30 @@ SemVer.prototype.comparePre = function (other) {
|
||||
} while (++i)
|
||||
}
|
||||
|
||||
SemVer.prototype.compareBuild = function (other) {
|
||||
if (!(other instanceof SemVer)) {
|
||||
other = new SemVer(other, this.options)
|
||||
}
|
||||
|
||||
var i = 0
|
||||
do {
|
||||
var a = this.build[i]
|
||||
var b = other.build[i]
|
||||
debug('prerelease compare', i, a, b)
|
||||
if (a === undefined && b === undefined) {
|
||||
return 0
|
||||
} else if (b === undefined) {
|
||||
return 1
|
||||
} else if (a === undefined) {
|
||||
return -1
|
||||
} else if (a === b) {
|
||||
continue
|
||||
} else {
|
||||
return compareIdentifiers(a, b)
|
||||
}
|
||||
} while (++i)
|
||||
}
|
||||
|
||||
// preminor will bump the version up to the next minor release, and immediately
|
||||
// down to pre-release. premajor and prepatch work the same way.
|
||||
SemVer.prototype.inc = function (release, identifier) {
|
||||
@@ -619,6 +652,13 @@ function compareLoose (a, b) {
|
||||
return compare(a, b, true)
|
||||
}
|
||||
|
||||
exports.compareBuild = compareBuild
|
||||
function compareBuild (a, b, loose) {
|
||||
var versionA = new SemVer(a, loose)
|
||||
var versionB = new SemVer(b, loose)
|
||||
return versionA.compare(versionB) || versionA.compareBuild(versionB)
|
||||
}
|
||||
|
||||
exports.rcompare = rcompare
|
||||
function rcompare (a, b, loose) {
|
||||
return compare(b, a, loose)
|
||||
@@ -627,14 +667,14 @@ function rcompare (a, b, loose) {
|
||||
exports.sort = sort
|
||||
function sort (list, loose) {
|
||||
return list.sort(function (a, b) {
|
||||
return exports.compare(a, b, loose)
|
||||
return exports.compareBuild(a, b, loose)
|
||||
})
|
||||
}
|
||||
|
||||
exports.rsort = rsort
|
||||
function rsort (list, loose) {
|
||||
return list.sort(function (a, b) {
|
||||
return exports.rcompare(a, b, loose)
|
||||
return exports.compareBuild(b, a, loose)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -747,14 +787,14 @@ function Comparator (comp, options) {
|
||||
|
||||
var ANY = {}
|
||||
Comparator.prototype.parse = function (comp) {
|
||||
var r = this.options.loose ? re[COMPARATORLOOSE] : re[COMPARATOR]
|
||||
var r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR]
|
||||
var m = comp.match(r)
|
||||
|
||||
if (!m) {
|
||||
throw new TypeError('Invalid comparator: ' + comp)
|
||||
}
|
||||
|
||||
this.operator = m[1]
|
||||
this.operator = m[1] !== undefined ? m[1] : ''
|
||||
if (this.operator === '=') {
|
||||
this.operator = ''
|
||||
}
|
||||
@@ -774,12 +814,16 @@ Comparator.prototype.toString = function () {
|
||||
Comparator.prototype.test = function (version) {
|
||||
debug('Comparator.test', version, this.options.loose)
|
||||
|
||||
if (this.semver === ANY) {
|
||||
if (this.semver === ANY || version === ANY) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (typeof version === 'string') {
|
||||
version = new SemVer(version, this.options)
|
||||
try {
|
||||
version = new SemVer(version, this.options)
|
||||
} catch (er) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return cmp(version, this.operator, this.semver, this.options)
|
||||
@@ -800,9 +844,15 @@ Comparator.prototype.intersects = function (comp, options) {
|
||||
var rangeTmp
|
||||
|
||||
if (this.operator === '') {
|
||||
if (this.value === '') {
|
||||
return true
|
||||
}
|
||||
rangeTmp = new Range(comp.value, options)
|
||||
return satisfies(this.value, rangeTmp, options)
|
||||
} else if (comp.operator === '') {
|
||||
if (comp.value === '') {
|
||||
return true
|
||||
}
|
||||
rangeTmp = new Range(this.value, options)
|
||||
return satisfies(comp.semver, rangeTmp, options)
|
||||
}
|
||||
@@ -892,18 +942,18 @@ Range.prototype.parseRange = function (range) {
|
||||
var loose = this.options.loose
|
||||
range = range.trim()
|
||||
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
|
||||
var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE]
|
||||
var hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE]
|
||||
range = range.replace(hr, hyphenReplace)
|
||||
debug('hyphen replace', range)
|
||||
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
|
||||
range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace)
|
||||
debug('comparator trim', range, re[COMPARATORTRIM])
|
||||
range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace)
|
||||
debug('comparator trim', range, re[t.COMPARATORTRIM])
|
||||
|
||||
// `~ 1.2.3` => `~1.2.3`
|
||||
range = range.replace(re[TILDETRIM], tildeTrimReplace)
|
||||
range = range.replace(re[t.TILDETRIM], tildeTrimReplace)
|
||||
|
||||
// `^ 1.2.3` => `^1.2.3`
|
||||
range = range.replace(re[CARETTRIM], caretTrimReplace)
|
||||
range = range.replace(re[t.CARETTRIM], caretTrimReplace)
|
||||
|
||||
// normalize spaces
|
||||
range = range.split(/\s+/).join(' ')
|
||||
@@ -911,7 +961,7 @@ Range.prototype.parseRange = function (range) {
|
||||
// At this point, the range is completely trimmed and
|
||||
// ready to be split into comparators.
|
||||
|
||||
var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR]
|
||||
var compRe = loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR]
|
||||
var set = range.split(' ').map(function (comp) {
|
||||
return parseComparator(comp, this.options)
|
||||
}, this).join(' ').split(/\s+/)
|
||||
@@ -934,16 +984,40 @@ Range.prototype.intersects = function (range, options) {
|
||||
}
|
||||
|
||||
return this.set.some(function (thisComparators) {
|
||||
return thisComparators.every(function (thisComparator) {
|
||||
return range.set.some(function (rangeComparators) {
|
||||
return rangeComparators.every(function (rangeComparator) {
|
||||
return thisComparator.intersects(rangeComparator, options)
|
||||
})
|
||||
return (
|
||||
isSatisfiable(thisComparators, options) &&
|
||||
range.set.some(function (rangeComparators) {
|
||||
return (
|
||||
isSatisfiable(rangeComparators, options) &&
|
||||
thisComparators.every(function (thisComparator) {
|
||||
return rangeComparators.every(function (rangeComparator) {
|
||||
return thisComparator.intersects(rangeComparator, options)
|
||||
})
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
// take a set of comparators and determine whether there
|
||||
// exists a version which can satisfy it
|
||||
function isSatisfiable (comparators, options) {
|
||||
var result = true
|
||||
var remainingComparators = comparators.slice()
|
||||
var testComparator = remainingComparators.pop()
|
||||
|
||||
while (result && remainingComparators.length) {
|
||||
result = remainingComparators.every(function (otherComparator) {
|
||||
return testComparator.intersects(otherComparator, options)
|
||||
})
|
||||
|
||||
testComparator = remainingComparators.pop()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Mostly just for testing and legacy API reasons
|
||||
exports.toComparators = toComparators
|
||||
function toComparators (range, options) {
|
||||
@@ -987,7 +1061,7 @@ function replaceTildes (comp, options) {
|
||||
}
|
||||
|
||||
function replaceTilde (comp, options) {
|
||||
var r = options.loose ? re[TILDELOOSE] : re[TILDE]
|
||||
var r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE]
|
||||
return comp.replace(r, function (_, M, m, p, pr) {
|
||||
debug('tilde', comp, _, M, m, p, pr)
|
||||
var ret
|
||||
@@ -1028,7 +1102,7 @@ function replaceCarets (comp, options) {
|
||||
|
||||
function replaceCaret (comp, options) {
|
||||
debug('caret', comp, options)
|
||||
var r = options.loose ? re[CARETLOOSE] : re[CARET]
|
||||
var r = options.loose ? re[t.CARETLOOSE] : re[t.CARET]
|
||||
return comp.replace(r, function (_, M, m, p, pr) {
|
||||
debug('caret', comp, _, M, m, p, pr)
|
||||
var ret
|
||||
@@ -1087,7 +1161,7 @@ function replaceXRanges (comp, options) {
|
||||
|
||||
function replaceXRange (comp, options) {
|
||||
comp = comp.trim()
|
||||
var r = options.loose ? re[XRANGELOOSE] : re[XRANGE]
|
||||
var r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE]
|
||||
return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
|
||||
debug('xRange', comp, ret, gtlt, M, m, p, pr)
|
||||
var xM = isX(M)
|
||||
@@ -1099,10 +1173,14 @@ function replaceXRange (comp, options) {
|
||||
gtlt = ''
|
||||
}
|
||||
|
||||
// if we're including prereleases in the match, then we need
|
||||
// to fix this to -0, the lowest possible prerelease value
|
||||
pr = options.includePrerelease ? '-0' : ''
|
||||
|
||||
if (xM) {
|
||||
if (gtlt === '>' || gtlt === '<') {
|
||||
// nothing is allowed
|
||||
ret = '<0.0.0'
|
||||
ret = '<0.0.0-0'
|
||||
} else {
|
||||
// nothing is forbidden
|
||||
ret = '*'
|
||||
@@ -1139,11 +1217,12 @@ function replaceXRange (comp, options) {
|
||||
}
|
||||
}
|
||||
|
||||
ret = gtlt + M + '.' + m + '.' + p
|
||||
ret = gtlt + M + '.' + m + '.' + p + pr
|
||||
} else if (xm) {
|
||||
ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0'
|
||||
ret = '>=' + M + '.0.0' + pr + ' <' + (+M + 1) + '.0.0' + pr
|
||||
} else if (xp) {
|
||||
ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'
|
||||
ret = '>=' + M + '.' + m + '.0' + pr +
|
||||
' <' + M + '.' + (+m + 1) + '.0' + pr
|
||||
}
|
||||
|
||||
debug('xRange return', ret)
|
||||
@@ -1157,10 +1236,10 @@ function replaceXRange (comp, options) {
|
||||
function replaceStars (comp, options) {
|
||||
debug('replaceStars', comp, options)
|
||||
// Looseness is ignored here. star is always as loose as it gets!
|
||||
return comp.trim().replace(re[STAR], '')
|
||||
return comp.trim().replace(re[t.STAR], '')
|
||||
}
|
||||
|
||||
// This function is passed to string.replace(re[HYPHENRANGE])
|
||||
// This function is passed to string.replace(re[t.HYPHENRANGE])
|
||||
// M, m, patch, prerelease, build
|
||||
// 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
|
||||
// 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
|
||||
@@ -1200,7 +1279,11 @@ Range.prototype.test = function (version) {
|
||||
}
|
||||
|
||||
if (typeof version === 'string') {
|
||||
version = new SemVer(version, this.options)
|
||||
try {
|
||||
version = new SemVer(version, this.options)
|
||||
} catch (er) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.set.length; i++) {
|
||||
@@ -1462,22 +1545,52 @@ function intersects (r1, r2, options) {
|
||||
}
|
||||
|
||||
exports.coerce = coerce
|
||||
function coerce (version) {
|
||||
function coerce (version, options) {
|
||||
if (version instanceof SemVer) {
|
||||
return version
|
||||
}
|
||||
|
||||
if (typeof version === 'number') {
|
||||
version = String(version)
|
||||
}
|
||||
|
||||
if (typeof version !== 'string') {
|
||||
return null
|
||||
}
|
||||
|
||||
var match = version.match(re[COERCE])
|
||||
options = options || {}
|
||||
|
||||
if (match == null) {
|
||||
var match = null
|
||||
if (!options.rtl) {
|
||||
match = version.match(re[t.COERCE])
|
||||
} else {
|
||||
// Find the right-most coercible string that does not share
|
||||
// a terminus with a more left-ward coercible string.
|
||||
// Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
|
||||
//
|
||||
// Walk through the string checking with a /g regexp
|
||||
// Manually set the index so as to pick up overlapping matches.
|
||||
// Stop when we get a match that ends at the string end, since no
|
||||
// coercible string can be more right-ward without the same terminus.
|
||||
var next
|
||||
while ((next = re[t.COERCERTL].exec(version)) &&
|
||||
(!match || match.index + match[0].length !== version.length)
|
||||
) {
|
||||
if (!match ||
|
||||
next.index + next[0].length !== match.index + match[0].length) {
|
||||
match = next
|
||||
}
|
||||
re[t.COERCERTL].lastIndex = next.index + next[1].length + next[2].length
|
||||
}
|
||||
// leave it in a clean state
|
||||
re[t.COERCERTL].lastIndex = -1
|
||||
}
|
||||
|
||||
if (match === null) {
|
||||
return null
|
||||
}
|
||||
|
||||
return parse(match[1] +
|
||||
'.' + (match[2] || '0') +
|
||||
'.' + (match[3] || '0'))
|
||||
return parse(match[2] +
|
||||
'.' + (match[3] || '0') +
|
||||
'.' + (match[4] || '0'), options)
|
||||
}
|
||||
|
||||
+46
-35
@@ -1,68 +1,79 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"@babel/core@7.10.4",
|
||||
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
|
||||
"@babel/core@7.18.6",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "@babel/core@7.10.4",
|
||||
"_id": "@babel/core@7.10.4",
|
||||
"_from": "@babel/core@7.18.6",
|
||||
"_id": "@babel/core@7.18.6",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-3A0tS0HWpy4XujGc7QtOIHTeNwUgWaZc/WuS5YQrfhU67jnVmsD6OGPc1AKHH0LJHQICGncy3+YUjIhVlfDdcA==",
|
||||
"_integrity": "sha512-cQbWBpxcbbs/IUredIPkHiAGULLV8iwgNRMFzvbhEXISp4f3rUUXE5+TIw6KwUWUR3DwyI6gmBRnmAtYaWehwQ==",
|
||||
"_location": "/@babel/core",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "@babel/core@7.10.4",
|
||||
"raw": "@babel/core@7.18.6",
|
||||
"name": "@babel/core",
|
||||
"escapedName": "@babel%2fcore",
|
||||
"scope": "@babel",
|
||||
"rawSpec": "7.10.4",
|
||||
"rawSpec": "7.18.6",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "7.10.4"
|
||||
"fetchSpec": "7.18.6"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@nuxt/babel-preset-app",
|
||||
"/@nuxt/webpack"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/@babel/core/-/core-7.10.4.tgz",
|
||||
"_spec": "7.10.4",
|
||||
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
|
||||
"_resolved": "https://registry.npmjs.org/@babel/core/-/core-7.18.6.tgz",
|
||||
"_spec": "7.18.6",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "Sebastian McKenzie",
|
||||
"email": "sebmck@gmail.com"
|
||||
"name": "The Babel Team",
|
||||
"url": "https://babel.dev/team"
|
||||
},
|
||||
"browser": {
|
||||
"./lib/config/files/index.js": "./lib/config/files/index-browser.js",
|
||||
"./lib/config/resolve-targets.js": "./lib/config/resolve-targets-browser.js",
|
||||
"./lib/transform-file.js": "./lib/transform-file-browser.js",
|
||||
"./src/config/files/index.js": "./src/config/files/index-browser.js",
|
||||
"./src/transform-file.js": "./src/transform-file-browser.js"
|
||||
"./src/config/files/index.ts": "./src/config/files/index-browser.ts",
|
||||
"./src/config/resolve-targets.ts": "./src/config/resolve-targets-browser.ts",
|
||||
"./src/transform-file.ts": "./src/transform-file-browser.ts"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/babel/babel/issues"
|
||||
"url": "https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20core%22+is%3Aopen"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.10.4",
|
||||
"@babel/generator": "^7.10.4",
|
||||
"@babel/helper-module-transforms": "^7.10.4",
|
||||
"@babel/helpers": "^7.10.4",
|
||||
"@babel/parser": "^7.10.4",
|
||||
"@babel/template": "^7.10.4",
|
||||
"@babel/traverse": "^7.10.4",
|
||||
"@babel/types": "^7.10.4",
|
||||
"@ampproject/remapping": "^2.1.0",
|
||||
"@babel/code-frame": "^7.18.6",
|
||||
"@babel/generator": "^7.18.6",
|
||||
"@babel/helper-compilation-targets": "^7.18.6",
|
||||
"@babel/helper-module-transforms": "^7.18.6",
|
||||
"@babel/helpers": "^7.18.6",
|
||||
"@babel/parser": "^7.18.6",
|
||||
"@babel/template": "^7.18.6",
|
||||
"@babel/traverse": "^7.18.6",
|
||||
"@babel/types": "^7.18.6",
|
||||
"convert-source-map": "^1.7.0",
|
||||
"debug": "^4.1.0",
|
||||
"gensync": "^1.0.0-beta.1",
|
||||
"json5": "^2.1.2",
|
||||
"lodash": "^4.17.13",
|
||||
"resolve": "^1.3.2",
|
||||
"semver": "^5.4.1",
|
||||
"source-map": "^0.5.0"
|
||||
"gensync": "^1.0.0-beta.2",
|
||||
"json5": "^2.2.1",
|
||||
"semver": "^6.3.0"
|
||||
},
|
||||
"description": "Babel compiler core.",
|
||||
"devDependencies": {
|
||||
"@babel/helper-transform-fixture-test-runner": "^7.10.4"
|
||||
"@babel/helper-transform-fixture-test-runner": "^7.18.6",
|
||||
"@babel/plugin-syntax-flow": "^7.18.6",
|
||||
"@babel/plugin-transform-flow-strip-types": "^7.18.6",
|
||||
"@babel/plugin-transform-modules-commonjs": "^7.18.6",
|
||||
"@babel/preset-env": "^7.18.6",
|
||||
"@jridgewell/trace-mapping": "^0.3.8",
|
||||
"@types/convert-source-map": "^1.5.1",
|
||||
"@types/debug": "^4.1.0",
|
||||
"@types/resolve": "^1.3.2",
|
||||
"@types/semver": "^5.4.0",
|
||||
"rimraf": "^3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
@@ -71,8 +82,7 @@
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/babel"
|
||||
},
|
||||
"gitHead": "7fd40d86a0d03ff0e9c3ea16b29689945433d4df",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-core",
|
||||
"keywords": [
|
||||
"6to5",
|
||||
"babel",
|
||||
@@ -89,7 +99,7 @@
|
||||
"compiler"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"main": "./lib/index.js",
|
||||
"name": "@babel/core",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
@@ -99,5 +109,6 @@
|
||||
"url": "git+https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-core"
|
||||
},
|
||||
"version": "7.10.4"
|
||||
"type": "commonjs",
|
||||
"version": "7.18.6"
|
||||
}
|
||||
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
import type { Handler } from "gensync";
|
||||
|
||||
import type {
|
||||
ConfigFile,
|
||||
IgnoreFile,
|
||||
RelativeConfig,
|
||||
FilePackageData,
|
||||
} from "./types";
|
||||
|
||||
import type { CallerMetadata } from "../validation/options";
|
||||
|
||||
export type { ConfigFile, IgnoreFile, RelativeConfig, FilePackageData };
|
||||
|
||||
export function findConfigUpwards(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
rootDir: string,
|
||||
): string | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line require-yield
|
||||
export function* findPackageData(filepath: string): Handler<FilePackageData> {
|
||||
return {
|
||||
filepath,
|
||||
directories: [],
|
||||
pkg: null,
|
||||
isPackage: false,
|
||||
};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line require-yield
|
||||
export function* findRelativeConfig(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
pkgData: FilePackageData,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
envName: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
caller: CallerMetadata | undefined,
|
||||
): Handler<RelativeConfig> {
|
||||
return { config: null, ignore: null };
|
||||
}
|
||||
|
||||
// eslint-disable-next-line require-yield
|
||||
export function* findRootConfig(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
dirname: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
envName: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
caller: CallerMetadata | undefined,
|
||||
): Handler<ConfigFile | null> {
|
||||
return null;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line require-yield
|
||||
export function* loadConfig(
|
||||
name: string,
|
||||
dirname: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
envName: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
caller: CallerMetadata | undefined,
|
||||
): Handler<ConfigFile> {
|
||||
throw new Error(`Cannot load ${name} relative to ${dirname} in a browser`);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line require-yield
|
||||
export function* resolveShowConfigPath(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
dirname: string,
|
||||
): Handler<string | null> {
|
||||
return null;
|
||||
}
|
||||
|
||||
export const ROOT_CONFIG_FILENAMES: string[] = [];
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function resolvePlugin(name: string, dirname: string): string | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function resolvePreset(name: string, dirname: string): string | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
export function loadPlugin(
|
||||
name: string,
|
||||
dirname: string,
|
||||
): Handler<{
|
||||
filepath: string;
|
||||
value: unknown;
|
||||
}> {
|
||||
throw new Error(
|
||||
`Cannot load plugin ${name} relative to ${dirname} in a browser`,
|
||||
);
|
||||
}
|
||||
|
||||
export function loadPreset(
|
||||
name: string,
|
||||
dirname: string,
|
||||
): Handler<{
|
||||
filepath: string;
|
||||
value: unknown;
|
||||
}> {
|
||||
throw new Error(
|
||||
`Cannot load preset ${name} relative to ${dirname} in a browser`,
|
||||
);
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
type indexBrowserType = typeof import("./index-browser");
|
||||
type indexType = typeof import("./index");
|
||||
|
||||
// Kind of gross, but essentially asserting that the exports of this module are the same as the
|
||||
// exports of index-browser, since this file may be replaced at bundle time with index-browser.
|
||||
({} as any as indexBrowserType as indexType);
|
||||
|
||||
export { findPackageData } from "./package";
|
||||
|
||||
export {
|
||||
findConfigUpwards,
|
||||
findRelativeConfig,
|
||||
findRootConfig,
|
||||
loadConfig,
|
||||
resolveShowConfigPath,
|
||||
ROOT_CONFIG_FILENAMES,
|
||||
} from "./configuration";
|
||||
export type {
|
||||
ConfigFile,
|
||||
IgnoreFile,
|
||||
RelativeConfig,
|
||||
FilePackageData,
|
||||
} from "./types";
|
||||
export { loadPlugin, loadPreset } from "./plugins";
|
||||
|
||||
import gensync from "gensync";
|
||||
import * as plugins from "./plugins";
|
||||
|
||||
export const resolvePlugin = gensync(plugins.resolvePlugin).sync;
|
||||
export const resolvePreset = gensync(plugins.resolvePreset).sync;
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
import type { ValidatedOptions } from "./validation/options";
|
||||
import getTargets, {
|
||||
type InputTargets,
|
||||
} from "@babel/helper-compilation-targets";
|
||||
|
||||
import type { Targets } from "@babel/helper-compilation-targets";
|
||||
|
||||
export function resolveBrowserslistConfigFile(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
browserslistConfigFile: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
configFilePath: string,
|
||||
): string | void {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function resolveTargets(
|
||||
options: ValidatedOptions,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
root: string,
|
||||
): Targets {
|
||||
const optTargets = options.targets;
|
||||
let targets: InputTargets;
|
||||
|
||||
if (typeof optTargets === "string" || Array.isArray(optTargets)) {
|
||||
targets = { browsers: optTargets };
|
||||
} else if (optTargets) {
|
||||
if ("esmodules" in optTargets) {
|
||||
targets = { ...optTargets, esmodules: "intersect" };
|
||||
} else {
|
||||
// https://github.com/microsoft/TypeScript/issues/17002
|
||||
targets = optTargets as InputTargets;
|
||||
}
|
||||
}
|
||||
|
||||
return getTargets(targets, {
|
||||
ignoreBrowserslistConfig: true,
|
||||
browserslistEnv: options.browserslistEnv,
|
||||
});
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
type browserType = typeof import("./resolve-targets-browser");
|
||||
type nodeType = typeof import("./resolve-targets");
|
||||
|
||||
// Kind of gross, but essentially asserting that the exports of this module are the same as the
|
||||
// exports of index-browser, since this file may be replaced at bundle time with index-browser.
|
||||
({} as any as browserType as nodeType);
|
||||
|
||||
import type { ValidatedOptions } from "./validation/options";
|
||||
import path from "path";
|
||||
import getTargets, {
|
||||
type InputTargets,
|
||||
} from "@babel/helper-compilation-targets";
|
||||
|
||||
import type { Targets } from "@babel/helper-compilation-targets";
|
||||
|
||||
export function resolveBrowserslistConfigFile(
|
||||
browserslistConfigFile: string,
|
||||
configFileDir: string,
|
||||
): string | undefined {
|
||||
return path.resolve(configFileDir, browserslistConfigFile);
|
||||
}
|
||||
|
||||
export function resolveTargets(
|
||||
options: ValidatedOptions,
|
||||
root: string,
|
||||
): Targets {
|
||||
const optTargets = options.targets;
|
||||
let targets: InputTargets;
|
||||
|
||||
if (typeof optTargets === "string" || Array.isArray(optTargets)) {
|
||||
targets = { browsers: optTargets };
|
||||
} else if (optTargets) {
|
||||
if ("esmodules" in optTargets) {
|
||||
targets = { ...optTargets, esmodules: "intersect" };
|
||||
} else {
|
||||
// https://github.com/microsoft/TypeScript/issues/17002
|
||||
targets = optTargets as InputTargets;
|
||||
}
|
||||
}
|
||||
|
||||
const { browserslistConfigFile } = options;
|
||||
let configFile;
|
||||
let ignoreBrowserslistConfig = false;
|
||||
if (typeof browserslistConfigFile === "string") {
|
||||
configFile = browserslistConfigFile;
|
||||
} else {
|
||||
ignoreBrowserslistConfig = browserslistConfigFile === false;
|
||||
}
|
||||
|
||||
return getTargets(targets, {
|
||||
ignoreBrowserslistConfig,
|
||||
configFile,
|
||||
configPath: root,
|
||||
browserslistEnv: options.browserslistEnv,
|
||||
});
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// duplicated from transform-file so we do not have to import anything here
|
||||
type TransformFile = {
|
||||
(filename: string, callback: (error: Error, file: null) => void): void;
|
||||
(
|
||||
filename: string,
|
||||
opts: any,
|
||||
callback: (error: Error, file: null) => void,
|
||||
): void;
|
||||
};
|
||||
|
||||
export const transformFile: TransformFile = function transformFile(
|
||||
filename,
|
||||
opts,
|
||||
callback?: (error: Error, file: null) => void,
|
||||
) {
|
||||
if (typeof opts === "function") {
|
||||
callback = opts;
|
||||
}
|
||||
|
||||
callback(new Error("Transforming files is not supported in browsers"), null);
|
||||
};
|
||||
|
||||
export function transformFileSync(): never {
|
||||
throw new Error("Transforming files is not supported in browsers");
|
||||
}
|
||||
|
||||
export function transformFileAsync() {
|
||||
return Promise.reject(
|
||||
new Error("Transforming files is not supported in browsers"),
|
||||
);
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
import gensync from "gensync";
|
||||
|
||||
import loadConfig from "./config";
|
||||
import type { InputOptions, ResolvedConfig } from "./config";
|
||||
import { run } from "./transformation";
|
||||
import type { FileResult, FileResultCallback } from "./transformation";
|
||||
import * as fs from "./gensync-utils/fs";
|
||||
|
||||
type transformFileBrowserType = typeof import("./transform-file-browser");
|
||||
type transformFileType = typeof import("./transform-file");
|
||||
|
||||
// Kind of gross, but essentially asserting that the exports of this module are the same as the
|
||||
// exports of transform-file-browser, since this file may be replaced at bundle time with
|
||||
// transform-file-browser.
|
||||
({} as any as transformFileBrowserType as transformFileType);
|
||||
|
||||
type TransformFile = {
|
||||
(filename: string, callback: FileResultCallback): void;
|
||||
(
|
||||
filename: string,
|
||||
opts: InputOptions | undefined | null,
|
||||
callback: FileResultCallback,
|
||||
): void;
|
||||
};
|
||||
|
||||
const transformFileRunner = gensync<
|
||||
(filename: string, opts?: InputOptions) => FileResult | null
|
||||
>(function* (filename, opts: InputOptions) {
|
||||
const options = { ...opts, filename };
|
||||
|
||||
const config: ResolvedConfig | null = yield* loadConfig(options);
|
||||
if (config === null) return null;
|
||||
|
||||
const code = yield* fs.readFile(filename, "utf8");
|
||||
return yield* run(config, code);
|
||||
});
|
||||
|
||||
export const transformFile = transformFileRunner.errback as TransformFile;
|
||||
export const transformFileSync = transformFileRunner.sync;
|
||||
export const transformFileAsync = transformFileRunner.async;
|
||||
Reference in New Issue
Block a user