{"version":3,"file":"index.cjs","names":[],"sources":["../src/lookup.ts","../src/index.ts"],"sourcesContent":["import { execFileSync } from 'child_process';\nimport { LookupAddress, LookupAllOptions, LookupOneOptions, LookupOptions } from 'dns';\nimport path from 'path';\n\nconst errorPrefix = 'DNSLookupSyncError:';\nconst scriptRelativePath = '../scripts/dns-lookup-sync-script.cjs';\n\n/**\n * Creates a new error instance with a customised error message\n *\n * @param {string} message description of the dns error\n * @param {string} hostname hostname argument that resulted in the error\n * @param {number | LookupOptions} options options that resulted in the error\n * @returns {Error} a new instance of a NodeJS Error object\n */\nconst createError = (\n  message: string,\n  hostname: string,\n  options?: number | LookupOptions,\n): Error => {\n  return new Error(`\n================================================================================\n\nFailed to look up hostname '${hostname}':\n- ${message}\n\nUsing Options:\n${JSON.stringify(options)}\n\nPlease double check the documentation here:\n- https://nodejs.org/api/dns.html#dnslookuphostname-options-callback\n\n================================================================================\n  `);\n};\n\n/**\n * Synchronous version of dns.lookup\n *\n * @param {string} hostname name of the host to look up, e.g. localhost\n * @param {number | LookupOptions} options to configure dns.lookup\n * @returns {LookupAddress | LookupAddress[]} a single address if options.all\n * is false, otherwise a list of addresses\n */\nfunction dnsLookupSync(hostname: string, options?: number | LookupOneOptions): LookupAddress;\nfunction dnsLookupSync(\n  hostname: string,\n  options: LookupAllOptions | LookupOptions,\n): LookupAddress[];\nfunction dnsLookupSync(\n  hostname: string,\n  options?: number | LookupOptions,\n): LookupAddress | LookupAddress[] {\n  const scriptPath = path.join(__dirname, scriptRelativePath);\n\n  const args =\n    options === undefined\n      ? [scriptPath, hostname]\n      : [scriptPath, hostname, JSON.stringify(options)];\n\n  try {\n    const results = execFileSync(process.execPath, args, { encoding: 'utf-8' }).trim();\n    if (results.startsWith(errorPrefix)) {\n      throw new Error(results);\n    }\n    return JSON.parse(results);\n  } catch (error: unknown) {\n    if (error instanceof Error) {\n      throw createError(error.message, hostname, options);\n    } else {\n      throw createError(`Unknown error: ${error}`, hostname, options);\n    }\n  }\n}\n\nexport default dnsLookupSync;\n","import dnsLookupSync from './lookup';\nexport default dnsLookupSync;\n"],"mappings":"whBAIA,MAWM,GACJ,EACA,EACA,IAEW,MAAM;;;8BAGW,EAAS;IACnC,EAAQ;;;EAGV,KAAK,UAAU,EAAQ,CAAC;;;;;;IAMtB,CAgBJ,SAAS,EACP,EACA,EACiC,CACjC,IAAM,EAAa,EAAA,QAAK,KAAK,UAAW,wCAAmB,CAErD,EACJ,IAAY,IAAA,GACR,CAAC,EAAY,EAAS,CACtB,CAAC,EAAY,EAAU,KAAK,UAAU,EAAQ,CAAC,CAErD,GAAI,CACF,IAAM,GAAA,EAAA,EAAA,cAAuB,QAAQ,SAAU,EAAM,CAAE,SAAU,QAAS,CAAC,CAAC,MAAM,CAClF,GAAI,EAAQ,WAAW,sBAAY,CACjC,MAAU,MAAM,EAAQ,CAE1B,OAAO,KAAK,MAAM,EAAQ,OACnB,EAAgB,CAIrB,MAHE,aAAiB,MACb,EAAY,EAAM,QAAS,EAAU,EAAQ,CAE7C,EAAY,kBAAkB,IAAS,EAAU,EAAQ,ECrErE,IAAA,EAAe"}