UNPKG

@babel/plugin-transform-runtime

Version:

Externalise references to helpers and builtins, automatically polyfilling your code without polluting globals

29 lines (26 loc) 972 B
import path from 'node:path'; import { createRequire } from 'node:module'; const require$1 = createRequire(import.meta.url); function index (moduleName, dirname, absoluteRuntime) { if (absoluteRuntime === false) return moduleName; return resolveAbsoluteRuntime(moduleName, path.resolve(dirname, absoluteRuntime === true ? "." : absoluteRuntime)); } function resolveAbsoluteRuntime(moduleName, dirname) { try { return path.dirname(require$1.resolve(`${moduleName}/package.json`, { paths: [dirname] })).replace(/\\/g, "/"); } catch (err) { if (err.code !== "MODULE_NOT_FOUND") throw err; throw Object.assign(new Error(`Failed to resolve "${moduleName}" relative to "${dirname}"`), { code: "BABEL_RUNTIME_NOT_FOUND", runtime: moduleName, dirname }); } } function resolveFSPath(path) { return require$1.resolve(path).replace(/\\/g, "/"); } export { index as default, resolveFSPath }; //# sourceMappingURL=index.js.map