"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.compileGatsbyConfig = compileGatsbyConfig;

var _core = require("@parcel/core");

var _reporter = _interopRequireDefault(require("gatsby-cli/lib/reporter"));

function constructBundler(dir) {
  return new _core.Parcel({
    entries: `${dir}/gatsby-+(node|config).{ts,tsx,js}`,
    defaultConfig: `@parcel/config-default`,
    mode: `production`,
    targets: {
      default: {
        distDir: `${dir}/.cache/compiled`,
        outputFormat: `commonjs`,
        includeNodeModules: false,
        sourceMap: false,
        engines: {
          node: `>= 14.15.0`
        }
      }
    },
    cacheDir: `${dir}/.cache/.parcel-cache`
  });
}

async function compileGatsbyConfig(dir) {
  const bundler = constructBundler(dir);

  try {
    const {
      bundleGraph,
      buildTime
    } = await bundler.run();
    const bundles = bundleGraph.getBundles();

    _reporter.default.log(`Built gatsby files (${bundles.length}) in ${buildTime}ms`);
  } catch (err) {
    _reporter.default.panicOnBuild(err.diagnostics);
  }
}
//# sourceMappingURL=compile-gatsby-config.js.map