@sanity/plugin-kit

7.0.28.0.0
dist/verify-package-B32oCYay.js
+dist/verify-package-B32oCYay.jsNew file
+96
Index: package/dist/verify-package-B32oCYay.js
===================================================================
--- package/dist/verify-package-B32oCYay.js
+++ package/dist/verify-package-B32oCYay.js
@@ -0,0 +1,96 @@
+import { a as urls, t as cliName } from "./constants-BLTUL_Wd.js";
+import { t as log_default } from "./log-DgQL-Rv9.js";
+import { C as validatePackageName, D as validateSanityDependencies, E as validatePkgUtilsVersion, O as validateScripts, P as fileExists, S as validateOxlintConfig, T as validatePkgUtilsDependency, _ as validateDeprecatedDependencies, a as getPackage, b as validateNodeEngine, g as validateBannedFiles, h as validateBabelConfig, j as validateTsConfig, k as validateSrcIndexFile, v as validateEsmOnly, w as validatePackageType, x as validateOxfmtConfig, y as validateIncompatiblePlugin } from "./package-BrKrShA_.js";
+import { t as loadPackageConfig } from "./load-package-config-CNQRvdGW.js";
+import { n as verifyFlags, t as createValidator } from "./verify-common-CzG3zw3J.js";
+import meow from "meow";
+import chalk from "chalk";
+import path from "path";
+import outdent from "outdent";
+import * as ts from "@typescript/typescript6";
+async function readTSConfig(options) {
+	let { basePath, filename } = options, filePath = path.resolve(basePath, filename);
+	if (!await fileExists(filePath)) return;
+	let { config } = ts.readConfigFile(filePath, ts.sys.readFile);
+	if (config) return ts.parseJsonConfigFileContent(config, ts.sys, basePath);
+}
+async function verifyPackage({ basePath, flags }) {
+	let errors = [], packageJson = await getPackage({
+		basePath,
+		validate: !1
+	}), verifyConfig = packageJson.sanityPlugin?.verifyPackage || {};
+	for (let hardError of [...validatePackageType(packageJson), ...validatePkgUtilsVersion({ basePath })]) errors.push(hardError), log_default.error(`\n${hardError}`);
+	let packageConfig;
+	try {
+		packageConfig = await loadPackageConfig({ basePath });
+	} catch (err) {
+		log_default.debug("Failed to load package.config: %s", err);
+	}
+	let outDir = packageConfig?.dist ?? "dist", tsconfig = packageConfig?.tsconfig ?? "tsconfig.json", validation = createValidator(verifyConfig, flags, errors), ts = await readTSConfig({
+		basePath,
+		filename: tsconfig
+	});
+	if (await validation("packageName", async () => validatePackageName(packageJson)), await validation("esmOnly", async () => validateEsmOnly(packageJson)), await validation("pkg-utils", async () => validatePkgUtilsDependency(packageJson)), await validation("srcIndex", async () => validateSrcIndexFile(basePath)), await validation("bannedFiles", async () => validateBannedFiles(packageJson)), await validation("scripts", async () => validateScripts(packageJson)), await validation("nodeEngine", async () => validateNodeEngine(packageJson)), await validation("oxfmt", async () => validateOxfmtConfig(basePath, packageJson)), await validation("oxlint", async () => validateOxlintConfig(basePath, packageJson)), ts && await validation("tsconfig", async () => validateTsConfig(ts, {
+		basePath,
+		outDir,
+		tsconfig
+	})), await validation("incompatiblePlugin", async () => validateIncompatiblePlugin({
+		basePath,
+		packageJson
+	})), await validation("babelConfig", async () => validateBabelConfig({ basePath })), await validation("dependencies", async () => validateSanityDependencies(packageJson)), await validation("deprecatedDependencies", async () => validateDeprecatedDependencies(packageJson)), errors.length) throw Error(outdent`
+        Detected validation issues!
+        To make this package Sanity v3 compatible, fix the issues starting from the top, or disable any checks you deem unnecessary.
+
+        These issues assume the package uses @sanity/plugin-kit defaults for development and building.
+        Refer to ${urls.pluginReadme} for configuration options.
+
+        More information is available here:
+        - Studio migration guide: ${urls.migrationGuideStudio}
+        - Plugin migration guide: ${urls.migrationGuidePlugin}
+        - Reference documentation: ${urls.refDocs}
+
+        ${chalk.grey(`To fail-fast on first detected issue run:\nnpx ${cliName} verify-package --single`)}
+      `.trimStart());
+	log_default.success(outdent`
+    No outstanding upgrade issues detected.
+
+    Suggested next steps:
+      - Use plugin-kit to build and develop the plugin according to ${urls.pluginReadme}.
+      - Build the plugin and fix any compilation errors
+      - Test the plugin using the link-watch command
+  `.trim());
+}
+const help = `
+Usage
+  $ ${cliName} verify-package [dir] [<args>]
+
+Options
+  --single      Enables fail-fast mode: Will only output the first validation that fails.
+  --silent      Do not print info and warning messages
+  --verbose     Log everything. This option conflicts with --silent
+  --version     Output the version number
+  --help        Output usage information
+
+Each check will describe how they can be individually disabled.
+
+Examples
+  # Verify Sanity plugin package in current directory
+  $ ${cliName} verify-package
+
+  # Verify Sanity plugin package in my-plugin directory in silent mode
+  $ ${cliName} verify-package my-plugin-directory --silent
+`;
+function run({ argv }) {
+	let cli = meow(help, {
+		flags: verifyFlags,
+		argv,
+		description: "Verify that a Sanity plugin package is v3 compatible, and print upgrade steps if not."
+	});
+	return verifyPackage({
+		basePath: path.resolve(cli.input[0] || process.cwd()),
+		flags: cli.flags
+	});
+}
+export { run as default };
+
+//# sourceMappingURL=verify-package-B32oCYay.js.map
\ No newline at end of file