| | |
| | | import path from 'path'; |
| | | import debounce from 'lodash.debounce'; |
| | | import requireResolve from 'resolve'; |
| | | import { createRequire } from 'module'; |
| | | |
| | | const { |
| | | types: t$1, |
| | |
| | | missingDependencies = {} |
| | | } = options; |
| | | if (missingDependencies === false) return false; |
| | | const caller = babelApi.caller(caller => caller?.name); |
| | | const caller = babelApi.caller(caller => caller == null ? void 0 : caller.name); |
| | | const { |
| | | log = "deferred", |
| | | inject = caller === "rollup-plugin-babel" ? "throw" : "import", |
| | |
| | | |
| | | })); |
| | | |
| | | const nativeRequireResolve = parseFloat(process.versions.node) >= 8.9; |
| | | const nativeRequireResolve = parseFloat(process.versions.node) >= 8.9; // $FlowIgnore |
| | | |
| | | const require = createRequire(import |
| | | /*::(_)*/ |
| | | .meta.url); // eslint-disable-line |
| | | |
| | | |
| | | function resolve(dirname, moduleName, absoluteImports) { |
| | | if (absoluteImports === false) return moduleName; |
| | | let basedir = dirname; |
| | |
| | | basedir = path.resolve(basedir, absoluteImports); |
| | | } |
| | | |
| | | let modulePackage, moduleNestedPath; |
| | | let slash = moduleName.indexOf("/"); |
| | | |
| | | if (moduleName[0] === "@") { |
| | | slash = moduleName.indexOf("/", slash + 1); |
| | | } |
| | | |
| | | if (slash === -1) { |
| | | modulePackage = moduleName; |
| | | moduleNestedPath = ""; |
| | | } else { |
| | | modulePackage = moduleName.slice(0, slash); |
| | | moduleNestedPath = moduleName.slice(slash); |
| | | } |
| | | |
| | | try { |
| | | let pkg; |
| | | |
| | | if (nativeRequireResolve) { |
| | | // $FlowIgnore |
| | | pkg = require.resolve(`${modulePackage}/package.json`, { |
| | | return require.resolve(moduleName, { |
| | | paths: [basedir] |
| | | }); |
| | | } else { |
| | | pkg = requireResolve.sync(`${modulePackage}/package.json`, { |
| | | return requireResolve.sync(moduleName, { |
| | | basedir |
| | | }); |
| | | } |
| | | |
| | | return path.dirname(pkg) + moduleNestedPath; |
| | | } catch (err) { |
| | | if (err.code !== "MODULE_NOT_FOUND") throw err; // $FlowIgnore |
| | | |
| | |
| | | function has(basedir, name) { |
| | | try { |
| | | if (nativeRequireResolve) { |
| | | // $FlowIgnore |
| | | require.resolve(name, { |
| | | paths: [basedir] |
| | | }); |
| | |
| | | method, |
| | | methodName, |
| | | targets, |
| | | absoluteImports: absoluteImports ?? false, |
| | | absoluteImports: absoluteImports != null ? absoluteImports : false, |
| | | shouldInjectPolyfill, |
| | | debug: !!debug, |
| | | providerOptions: providerOptions |
| | |
| | | visitor, |
| | | |
| | | pre() { |
| | | var _provider$pre; |
| | | |
| | | debugLog = { |
| | | polyfills: new Map(), |
| | | found: false, |
| | |
| | | missingDeps: new Set() |
| | | }; // $FlowIgnore - Flow doesn't support optional calls |
| | | |
| | | provider.pre?.apply(this, arguments); |
| | | (_provider$pre = provider.pre) == null ? void 0 : _provider$pre.apply(this, arguments); |
| | | }, |
| | | |
| | | post() { |
| | | var _provider$post; |
| | | |
| | | // $FlowIgnore - Flow doesn't support optional calls |
| | | provider.post?.apply(this, arguments); |
| | | (_provider$post = provider.post) == null ? void 0 : _provider$post.apply(this, arguments); |
| | | |
| | | if (missingDependencies !== false) { |
| | | if (missingDependencies.log === "per-file") { |