/** Drop repo-root smoke `tsx --tsconfig` settings so nested extractor `tsx` runs use package tsconfig. */
export function envForExtractorSubprocess(
  base: NodeJS.ProcessEnv,
): NodeJS.ProcessEnv {
  const env = { ...base };
  delete env.TSX_TSCONFIG;
  delete env.TSX_TSCONFIG_PATH;
  const nodeOptions = env.NODE_OPTIONS;
  if (
    typeof nodeOptions === "string" &&
    nodeOptions.includes("tsconfig.smoke")
  ) {
    env.NODE_OPTIONS = nodeOptions
      .split(/\s+/)
      .filter((part) => !part.includes("tsconfig.smoke"))
      .join(" ")
      .trim();
  }
  return env;
}
