"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = register;
var _pirates = require("pirates");
var _getTsconfig = require("get-tsconfig");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
async function register(config) {
  (0, _pirates.addHook)(() => '', {
    exts: ['.jpg', '.jpeg', '.png', '.gif', '.eot', '.otf', '.svg', '.ttf', '.woff', '.woff2', '.css', '.less', '.scss', '.styl'],
    ignoreNodeModules: false
  });
  const {
    path: tsConfigPath
  } = (0, _getTsconfig.getTsconfig)(config.tsConfig) || {};

  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
  (await Promise.resolve().then(() => _interopRequireWildcard(require('@babel/register')))).default(config.babelOptions({
    babelrc: false,
    rootMode: 'upward-optional',
    ignore: [/node_modules/],
    extensions: ['.js', '.jsx', '.ts', '.tsx'],
    parserOpts: {
      sourceType: 'module',
      plugins: ['jsx', 'typescript']
    },
    presets: ['@babel/preset-typescript', ['@babel/preset-env', {
      targets: {
        node: '10'
      },
      modules: 'commonjs'
    }]],
    plugins: [['@babel/plugin-transform-runtime'], ...(tsConfigPath ? [['babel-plugin-tsconfig-paths', {
      tsconfig: tsConfigPath
    }]] : [])]
  }));

  // (await import('ts-node')).register({ project: tsConfigPath, transpileOnly: true });
}