| | |
| | | |
| | | var _configChain = require("./config-chain"); |
| | | |
| | | var _deepArray = require("./helpers/deep-array"); |
| | | |
| | | function _traverse() { |
| | | const data = require("@babel/traverse"); |
| | | |
| | |
| | | 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 { |
| | | if (descriptor.ownPass) { |
| | | presets.push({ |
| | | preset: yield* loadPresetDescriptor(descriptor, presetContext), |
| | | pass: [] |
| | | }); |
| | | } else { |
| | | presets.unshift({ |
| | | preset: yield* loadPresetDescriptor(descriptor, presetContext), |
| | | pass: pluginDescriptorsPass |
| | | }); |
| | | } |
| | | var preset = yield* loadPresetDescriptor(descriptor, presetContext); |
| | | } catch (e) { |
| | | if (e.code === "BABEL_UNKNOWN_OPTION") { |
| | | (0, _options.checkNoUnwrappedItemOptionPairs)(rawPresets, i, "preset", e); |
| | | } |
| | | |
| | | throw e; |
| | | } |
| | | |
| | | externalDependencies.push(preset.externalDependencies); |
| | | |
| | | if (descriptor.ownPass) { |
| | | presets.push({ |
| | | preset: preset.chain, |
| | | pass: [] |
| | | }); |
| | | } else { |
| | | presets.unshift({ |
| | | preset: preset.chain, |
| | | pass: pluginDescriptorsPass |
| | | }); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | if (descriptor.options !== false) { |
| | | try { |
| | | pass.push(yield* loadPluginDescriptor(descriptor, pluginContext)); |
| | | 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.passPerPreset = opts.presets.length > 0; |
| | | return { |
| | | options: opts, |
| | | passes: passes |
| | | passes: passes, |
| | | externalDependencies: (0, _deepArray.finalize)(externalDependencies) |
| | | }; |
| | | }); |
| | | |
| | |
| | | }, cache) { |
| | | if (options === false) throw new Error("Assertion failure"); |
| | | options = options || {}; |
| | | const externalDependencies = []; |
| | | let item = value; |
| | | |
| | | if (typeof value === "function") { |
| | | 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)); |
| | | const api = Object.assign({}, context, apiFactory(cache, externalDependencies)); |
| | | |
| | | try { |
| | | item = yield* factory(api, options, dirname); |
| | |
| | | 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) |
| | | }; |
| | | }); |
| | | |
| | |
| | | value, |
| | | options, |
| | | dirname, |
| | | alias |
| | | alias, |
| | | externalDependencies |
| | | }, cache) { |
| | | const pluginObj = (0, _plugins.validatePluginObject)(value); |
| | | const plugin = Object.assign({}, pluginObj); |
| | |
| | | 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) => { |
| | |
| | | function* loadPresetDescriptor(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 |
| | | }; |
| | | }); |
| | | |