UNPKG

@sanity/pkg-utils

Version:

Simple utilities for modern npm packages.

37 lines (36 loc) 1.18 kB
import path from "node:path"; import { pathToFileURL } from "node:url"; import { tsImport } from "tsx/esm/api"; import findConfig from "find-config"; import { fileExists } from "./fileExists.js"; import config from "@sanity/browserslist-config"; const CONFIG_FILE_NAMES = [ "package.config.ts", "package.config.js", "package.config.cjs", "package.config.mts", "package.config.mjs" ]; function findConfigFile(cwd) { const pkgJsonPath = findConfig("package.json", { cwd }); if (!pkgJsonPath) return; const pkgPath = path.dirname(pkgJsonPath); for (const fileName of CONFIG_FILE_NAMES) { const configPath = path.resolve(pkgPath, fileName); if (fileExists(configPath)) return configPath; } } async function loadConfig(options) { const { cwd, pkgPath } = options, root = path.dirname(pkgPath), configFile = findConfigFile(root); if (!configFile || !configFile.startsWith(cwd)) return; const mod = await tsImport(pathToFileURL(configFile).toString(), import.meta.url); return mod?.default || mod || void 0; } const DEFAULT_BROWSERSLIST_QUERY = config; export { DEFAULT_BROWSERSLIST_QUERY, loadConfig }; //# sourceMappingURL=defaults.js.map