@sanity/plugin-kit
6.0.47.0.0
dist/_chunks-es/load-package-config.js+
dist/_chunks-es/load-package-config.jsNew file+31
Index: package/dist/_chunks-es/load-package-config.js
===================================================================
--- package/dist/_chunks-es/load-package-config.js
+++ package/dist/_chunks-es/load-package-config.js
@@ -0,0 +1,31 @@
+import { createRequire } from "node:module";
+import fs from "node:fs";
+import path from "node:path";
+import { pathToFileURL } from "node:url";
+const CONFIG_FILE_NAMES = [
+ "package.config.ts",
+ "package.config.js",
+ "package.config.cjs",
+ "package.config.mts",
+ "package.config.mjs"
+];
+/**
+* Loads the `@sanity/pkg-utils` package.config file for the plugin in `basePath`.
+*
+* `@sanity/pkg-utils` is a peer dependency, so we resolve `loadConfig` from the plugin's own
+* installation (relative to `basePath`). This guarantees the config is parsed with the exact
+* same pkg-utils version the plugin builds with, and lets plugin-kit run via `npx` without
+* bundling its own copy of pkg-utils.
+*/
+async function loadPackageConfig(options) {
+ let { basePath } = options;
+ if (!CONFIG_FILE_NAMES.some((file) => fs.existsSync(path.join(basePath, file)))) return;
+ let pkgPath = path.join(basePath, "package.json"), { loadConfig } = await import(pathToFileURL(createRequire(pkgPath).resolve("@sanity/pkg-utils")).href);
+ return loadConfig({
+ cwd: basePath,
+ pkgPath
+ });
+}
+export { loadPackageConfig as t };
+
+//# sourceMappingURL=load-package-config.js.map
\ No newline at end of file