import { readFileSync } from "fs" ; import { dirname } from "path" ; import _module = require ( "module" ) ; const { Module , builtinModules } = _module ; function stripBOM ( str ) { if ( str . charCodeAt ( 0 ) === 0xfeff ) { return str . slice ( 1 ) ; } return str ; } /**
 * This function emulates the behavior of `require()`, enabling us to call it
 * multiple times without worrying about having to clear out the cache (useful
 * for watch mode).
 */ export function fauxRequire ( spec , cache = { } ) { if ( builtinModules . includes ( spec ) ) { return require ( spec ) ; } const filename = require . resolve ( spec ) ; if ( filename . indexOf ( "/node_modules/" ) >= 0 ) { return require ( spec ) ; } if ( ! filename . endsWith ( ".js" ) ) { return require ( spec ) ; } if ( cache [ filename ] ) { return cache [ filename ] . exports ; } const contents = readFileSync ( filename , "utf8" ) ; const code = stripBOM ( contents ) ; const replacementModule = new Module ( filename , this ) ; replacementModule . filename = filename ; replacementModule . paths = Module . _nodeModulePaths ( dirname ( filename ) ) ; const codeWithWrapper = `\
const { resolve } = require('path');

const fauxRequire = (path) => {
  const spec =
    path.startsWith(".") || path.startsWith("/")
      ? resolve(__dirname, path)
      : path;
  return global.graphileWorker_fauxRequire(spec, fauxRequire.cache);
}
fauxRequire.resolve = require.resolve;
fauxRequire.cache = global.graphileWorker_fauxRequireCache;

(function(module, exports, require) {
${ code };
})(module, exports, fauxRequire);
` ; global [ "graphileWorker_fauxRequireCache" ] = cache ; cache [ filename ] = replacementModule ; replacementModule . _compile ( codeWithWrapper , filename ) ; global [ "graphileWorker_fauxRequireCache" ] = null ; replacementModule . loaded = true ; return replacementModule . exports ; } global [ "graphileWorker_fauxRequire" ] = fauxRequire ;