@sanity/plugin-kit 8.0.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +8 -63
  2. package/dist/constants-BIVJp2Jy.js +7 -0
  3. package/dist/constants-BIVJp2Jy.js.map +1 -0
  4. package/dist/index.js +9 -16
  5. package/dist/index.js.map +1 -1
  6. package/dist/{init-v15fyisU.js → init-Bfn8LX_B.js} +6 -8
  7. package/dist/init-Bfn8LX_B.js.map +1 -0
  8. package/dist/{inject-B41UktQ3.js → inject-B5Mh7aAX.js} +5 -6
  9. package/dist/inject-B5Mh7aAX.js.map +1 -0
  10. package/dist/{link-watch-B2ixqs1y.js → link-watch-DOvzqtol.js} +4 -4
  11. package/dist/{link-watch-B2ixqs1y.js.map → link-watch-DOvzqtol.js.map} +1 -1
  12. package/dist/oxfmt.js +1 -5
  13. package/dist/oxfmt.js.map +1 -1
  14. package/dist/oxlint.js +8 -0
  15. package/dist/oxlint.js.map +1 -1
  16. package/dist/{package-BrKrShA_.js → package-Cx3OyOx-.js} +20 -380
  17. package/dist/package-Cx3OyOx-.js.map +1 -0
  18. package/dist/package-D-XjdNv2.js +4 -0
  19. package/dist/package-D-XjdNv2.js.map +1 -0
  20. package/dist/{init-BDY7XRmJ.js → studio-detect-CnuSQGN_.js} +24 -7
  21. package/dist/studio-detect-CnuSQGN_.js.map +1 -0
  22. package/dist/{verify-package-B32oCYay.js → verify-package-fNlJK-qr.js} +41 -14
  23. package/dist/verify-package-fNlJK-qr.js.map +1 -0
  24. package/dist/{version-N9n1cr5G.js → version-2T4tSyv6.js} +2 -2
  25. package/dist/{version-N9n1cr5G.js.map → version-2T4tSyv6.js.map} +1 -1
  26. package/package.json +10 -12
  27. package/dist/constants-BLTUL_Wd.js +0 -11
  28. package/dist/constants-BLTUL_Wd.js.map +0 -1
  29. package/dist/init-BDY7XRmJ.js.map +0 -1
  30. package/dist/init-v15fyisU.js.map +0 -1
  31. package/dist/inject-B41UktQ3.js.map +0 -1
  32. package/dist/package-BrKrShA_.js.map +0 -1
  33. package/dist/package-z3cLp2Jt.js +0 -4
  34. package/dist/package-z3cLp2Jt.js.map +0 -1
  35. package/dist/verify-common-CzG3zw3J.js +0 -39
  36. package/dist/verify-common-CzG3zw3J.js.map +0 -1
  37. package/dist/verify-package-B32oCYay.js.map +0 -1
  38. package/dist/verify-studio-DUoKxnYy.js +0 -61
  39. package/dist/verify-studio-DUoKxnYy.js.map +0 -1
@@ -1,8 +1,6 @@
1
- import { a as urls, i as requiredNodeEngine, r as incompatiblePluginPackage, t as cliName } from "./constants-BLTUL_Wd.js";
1
+ import { r as requiredNodeEngine, t as cliName } from "./constants-BIVJp2Jy.js";
2
2
  import { t as log_default } from "./log-DgQL-Rv9.js";
3
- import { t as binname } from "./package-z3cLp2Jt.js";
4
3
  import { createRequire } from "node:module";
5
- import chalk from "chalk";
6
4
  import path from "path";
7
5
  import outdent from "outdent";
8
6
  import fs from "fs";
@@ -10,44 +8,16 @@ import util from "util";
10
8
  import githubUrlToObject from "github-url-to-object";
11
9
  import validNpmName from "validate-npm-package-name";
12
10
  import crypto from "crypto";
13
- import json5 from "json5";
14
- import pAny from "p-any";
15
11
  import { URL } from "url";
16
12
  import inquirer from "inquirer";
17
13
  import { getLatestVersion } from "get-latest-version";
18
14
  import pProps from "p-props";
19
- const mergedPackages = [
20
- "@sanity/base",
21
- "@sanity/core",
22
- "@sanity/types",
23
- "@sanity/data-aspects",
24
- "@sanity/default-layout",
25
- "@sanity/default-login",
26
- "@sanity/desk-tool",
27
- "@sanity/field",
28
- "@sanity/form-builder",
29
- "@sanity/initial-value-templates",
30
- "@sanity/language-filter",
31
- "@sanity/production-preview",
32
- "@sanity/react-hooks",
33
- "@sanity/resolver",
34
- "@sanity/state-router",
35
- "@sanity/structure",
36
- "@sanity/studio-hints"
37
- ].sort(), deprecatedDevDeps = [
15
+ const deprecatedDevDeps = [
38
16
  "tsdx",
39
17
  "sanipack",
40
18
  "parcel",
41
19
  "@parcel/packager-ts",
42
20
  "@parcel/transformer-typescript-types"
43
- ], buildExtensions = [
44
- ".js",
45
- ".jsx",
46
- ".es6",
47
- ".es",
48
- ".mjs",
49
- ".ts",
50
- ".tsx"
51
21
  ];
52
22
  async function prompt(message, options) {
53
23
  let type = options.choices ? "list" : options.type, result = await inquirer.prompt([{
@@ -89,30 +59,12 @@ function promptForRepoOrigin(_options, defaultVal) {
89
59
  }
90
60
  });
91
61
  }
92
- const stat$1 = util.promisify(fs.stat), mkdir = util.promisify(fs.mkdir), readdir = util.promisify(fs.readdir), copyFile = util.promisify(fs.copyFile), readFile$2 = util.promisify(fs.readFile), writeFile = util.promisify(fs.writeFile);
93
- function hasSourceEquivalent(compiledFile, paths) {
94
- if (!paths.source) return fileExists(path.isAbsolute(compiledFile) ? compiledFile : path.resolve(paths.basePath, compiledFile));
95
- let baseDir = path.dirname(compiledFile.replace(paths.compiled, paths.source)), baseName = path.basename(compiledFile, path.extname(compiledFile));
96
- return buildCandidateExists(path.join(baseDir, baseName));
97
- }
98
- async function hasSourceFile(filePath, paths) {
99
- if (!paths?.source) return fileExists(path.isAbsolute(filePath) ? filePath : path.resolve(paths?.basePath ?? "", filePath));
100
- let pathStub = path.isAbsolute(filePath) ? filePath : path.resolve(paths.source, filePath);
101
- return await fileExists(pathStub) ? !0 : buildCandidateExists(pathStub);
102
- }
103
- function hasCompiledFile(filePath, paths) {
104
- if (!paths?.compiled) return fileExists(path.isAbsolute(filePath) ? filePath : path.resolve(paths?.basePath ?? "", filePath));
105
- let absPath = path.isAbsolute(filePath) ? filePath : path.resolve(paths.compiled, filePath);
106
- return fileExists(path.extname(absPath) === "" ? `${absPath}.js` : absPath);
107
- }
108
- function buildCandidateExists(pathStub) {
109
- return pAny(buildExtensions.map((extCandidate) => `${pathStub}${extCandidate}`).map((candidate) => stat$1(candidate))).then(() => !0).catch(() => !1);
110
- }
62
+ const stat = util.promisify(fs.stat), mkdir = util.promisify(fs.mkdir), readdir = util.promisify(fs.readdir), copyFile = util.promisify(fs.copyFile), readFile$1 = util.promisify(fs.readFile), writeFile = util.promisify(fs.writeFile);
111
63
  function fileExists(filePath) {
112
- return stat$1(filePath).then(() => !0).catch(() => !1);
64
+ return stat(filePath).then(() => !0).catch(() => !1);
113
65
  }
114
66
  async function readJsonFile(filePath) {
115
- let content = await readFile$2(filePath, "utf8");
67
+ let content = await readFile$1(filePath, "utf8");
116
68
  return JSON.parse(content);
117
69
  }
118
70
  function writeJsonFile(filePath, content) {
@@ -168,32 +120,6 @@ async function isEmptyish(dirPath) {
168
120
  ];
169
121
  return (await readdir(dirPath).catch(() => [])).filter((file) => !ignoredFiles.includes(file.toLowerCase())).length === 0;
170
122
  }
171
- async function readFileContent({ filename, basePath }) {
172
- let filepath = path.normalize(path.join(basePath, filename));
173
- try {
174
- return await readFile$2(filepath, "utf8");
175
- } catch (err) {
176
- if (err.code === "ENOENT") {
177
- log_default.debug(`No ${filename} file found.`);
178
- return;
179
- }
180
- throw Error(`Failed to read "${filepath}": ${err.message}`);
181
- }
182
- }
183
- async function readJson5File({ filename, basePath }) {
184
- let content = await readFileContent({
185
- filename,
186
- basePath
187
- });
188
- if (content) return parseJson5(content, filename);
189
- }
190
- function parseJson5(content, errorKey) {
191
- try {
192
- return json5.parse(content);
193
- } catch (err) {
194
- throw Error(`Error parsing "${errorKey}": ${err.message}`);
195
- }
196
- }
197
123
  const expectedScripts = {
198
124
  build: "plugin-kit verify-package --silent && pkg-utils build --strict --check --clean",
199
125
  watch: "pkg-utils watch --strict",
@@ -351,22 +277,6 @@ function validatePkgUtilsVersion({ basePath }) {
351
277
  Please upgrade it by running 'npm install --save-dev @sanity/pkg-utils@latest'.
352
278
  `.trimStart()] : [];
353
279
  }
354
- function validateSanityDependencies(packageJson) {
355
- let { dependencies, devDependencies, peerDependencies } = packageJson, allDependencies = {
356
- ...dependencies,
357
- ...devDependencies,
358
- ...peerDependencies
359
- }, illegalDeps = Object.keys(allDependencies).filter((dep) => mergedPackages.includes(dep)), unique = [...new Set(illegalDeps).values()];
360
- return unique.length ? [outdent`
361
- package.json depends on "@sanity/*" packages that have moved into "sanity" package.
362
-
363
- The following dependencies should be replaced with "sanity":
364
- - ${unique.join("\n- ")}
365
-
366
- Refer to the reference docs to find replacement imports:
367
- ${urls.refDocs}
368
- `.trimStart()] : [];
369
- }
370
280
  function validateDeprecatedDependencies(packageJson) {
371
281
  let { dependencies, devDependencies, peerDependencies } = packageJson, allDependencies = {
372
282
  ...dependencies,
@@ -393,125 +303,21 @@ async function validateBabelConfig({ basePath }) {
393
303
  Delete the file, or disable this check.
394
304
  `.trimStart()] : [];
395
305
  }
396
- async function validateStudioConfig({ basePath }) {
397
- let suffixes = [
398
- "ts",
399
- "js",
400
- "tsx",
401
- "jsx"
402
- ], filenames = filesWithSuffixes(["sanity.config", "sanity.cli"], suffixes), files = {};
403
- for (let filename of filenames) files[filename] = await fileExists(path.normalize(path.join(basePath, filename)));
404
- let sanityJson = await readJson5File({
405
- basePath,
406
- filename: "sanity.json"
407
- }), hasConfigFile = (fileBase) => filesWithSuffixes([fileBase], suffixes).some((filename) => files[filename]), hasCliConfig = hasConfigFile("sanity.cli"), hasStudioConfig = hasConfigFile("sanity.config"), errors = [];
408
- if (sanityJson) {
409
- let info = [outdent`
410
- Found sanity.json. This file is not used by Sanity Studio V3.
411
-
412
- Please consult the Studio V3 migration guide:
413
- ${urls.migrationGuideStudio}
414
- It will detail how to convert sanity.json to sanity.config.ts (or .js) and sanity.cli.ts (or .js) equivalents.
415
- `.trimStart(), sanityJson.plugins?.length && outdent`
416
- For V3 versions and alternatives to V2 plugins, please refer to the Sanity Exchange:
417
- ${urls.sanityExchange}
418
- `.trimStart()].filter((s) => !!s);
419
- errors.push(info.join("\n\n"));
420
- }
421
- return hasCliConfig || errors.push(outdent`
422
- sanity.cli.(${suffixes.join(" | ")}) missing. Please create a file named sanity.cli.ts with the following content:
423
-
424
- ${chalk.green(outdent`
425
- import {createCliConfig} from 'sanity/cli'
426
-
427
- export default createCliConfig({
428
- api: {
429
- projectId: '${sanityJson?.api?.projectId ?? "project-id"}',
430
- dataset: '${sanityJson?.api?.dataset ?? "dataset"}',
431
- }
432
- })`)}
433
-
434
- Make sure to replace the projectId and dataset fields with your own.
435
-
436
- For more, see ${urls.migrationGuideStudio}
437
- `.trimStart()), hasStudioConfig || errors.push(outdent`
438
- sanity.config.(${suffixes.join(" | ")}) missing. At a minimum sanity.config.ts should contain:
439
-
440
- ${chalk.green(outdent`
441
- import { defineConfig } from "sanity"
442
- import { deskTool } from "sanity/desk"
443
-
444
- export default defineConfig({
445
- name: "default",
446
-
447
- projectId: '${sanityJson?.api?.projectId ?? "project-id"}',
448
- dataset: '${sanityJson?.api?.dataset ?? "dataset"}',
449
-
450
- plugins: [
451
- deskTool(),
452
- ],
453
-
454
- schema: {
455
- types: [
456
- /* put your v2 schema-types here */
457
- ],
458
- },
459
- })`).trimStart()}
460
-
461
- Make sure to replace the projectId and dataset fields with your own.
462
-
463
- For more, see ${urls.migrationGuideStudio}
464
- `.trimStart()), errors.length ? [errors.join("\n\n---\n\n")] : [];
465
- }
466
- /**
467
- * Detects leftover usage of the legacy `@sanity/incompatible-plugin` shim and asks for its removal.
468
- *
469
- * The shim (a `sanity.json` + `v2-incompatible.js` entry point, plus the `@sanity/incompatible-plugin`
470
- * dependency) only rendered an error dialog in the long end-of-life Sanity Studio v2 when a v3 plugin
471
- * was installed there. plugin-kit no longer scaffolds it, so a plugin should not ship it anymore.
472
- */
473
- async function validateIncompatiblePlugin({ basePath, packageJson }) {
474
- let { dependencies, devDependencies, peerDependencies } = packageJson, inDependencies = !!(dependencies?.["@sanity/incompatible-plugin"] || devDependencies?.["@sanity/incompatible-plugin"] || peerDependencies?.["@sanity/incompatible-plugin"]), hasShimFile = await fileExists(path.normalize(path.join(basePath, "v2-incompatible.js"))), sanityJsonReferencesShim = !!(await readJson5File({
475
- basePath,
476
- filename: "sanity.json"
477
- }))?.parts?.some((part) => part?.path?.includes("v2-incompatible"));
478
- return !inDependencies && !hasShimFile && !sanityJsonReferencesShim ? [] : [outdent`
479
- ${incompatiblePluginPackage} is no longer used and should be removed.
480
-
481
- It only rendered an error dialog in the long end-of-life Sanity Studio v2 when a v3 plugin was
482
- installed there. That compatibility shim is now obsolete, so plugin-kit no longer adds it.
483
-
484
- Found:
485
- ${[
486
- inDependencies ? `- "${incompatiblePluginPackage}" listed in package.json` : null,
487
- hasShimFile ? "- the v2-incompatible.js file" : null,
488
- sanityJsonReferencesShim ? "- a sanity.json referencing v2-incompatible.js" : null
489
- ].filter((e) => !!e).join("\n")}
490
-
491
- To fix this:
492
- - Remove "${incompatiblePluginPackage}" from package.json (dependencies/devDependencies/peerDependencies)
493
- - Delete the v2-incompatible.js file
494
- - Delete sanity.json (if it only contains the v2-incompatible "part")
495
- - Remove "sanity.json" and "v2-incompatible.js" from the package.json "files" array
496
-
497
- For more, see ${urls.incompatiblePlugin}
498
- `.trimStart()];
499
- }
500
306
  function validatePackageName$1(packageJson) {
501
307
  let valid = validNpmName(packageJson.name ?? "");
502
308
  return valid.validForNewPackages ? !packageJson.name?.startsWith("@") && !packageJson.name?.startsWith("sanity-plugin-") ? ["Invalid package.json: \"name\" should be prefixed with \"sanity-plugin-\" (or scoped - @your-company/plugin-name)"] : [] : [`Invalid package.json: "name" is invalid: ${(valid.errors ?? valid.warnings ?? []).join(", ")}`];
503
309
  }
504
310
  /**
505
- * Plugins built with @sanity/plugin-kit publish the compiled output (the `dist` directory) plus any
506
- * v2-compatibility files. The `src` directory should not be published: it bloats the package and can
507
- * cause bundlers that resolve the `source` export condition to pull in raw, uncompiled TypeScript.
311
+ * Plugins built with @sanity/plugin-kit publish the compiled output (the `dist` directory).
312
+ * The `src` directory should not be published: it bloats the package and can cause bundlers that
313
+ * resolve the `source` export condition to pull in raw, uncompiled TypeScript.
508
314
  */
509
315
  function validateBannedFiles(packageJson) {
510
316
  let { files } = packageJson;
511
317
  return !Array.isArray(files) || !files.some((entry) => typeof entry == "string" && entry.trim().replace(/^\.?\/+/, "").replace(/\/+$/, "") === "src") ? [] : [outdent`
512
318
  package.json "files" must not include "src".
513
319
 
514
- Plugins built with @sanity/plugin-kit publish the compiled output in "dist" (and any v2-compatibility files).
320
+ Plugins built with @sanity/plugin-kit publish the compiled output in "dist".
515
321
  Shipping the "src" directory bloats the published package and can cause bundlers that resolve the
516
322
  "source" export condition to import raw, uncompiled TypeScript.
517
323
 
@@ -633,7 +439,7 @@ async function checkOxfmtConfigDir(dir, describeDir) {
633
439
 
634
440
  ${oxfmtSetupSnippet}
635
441
  `
636
- } : (await readFile$2(path.join(dir, file), "utf8")).includes(oxfmtPresetSpecifier) ? { ok: !0 } : {
442
+ } : (await readFile$1(path.join(dir, file), "utf8")).includes(oxfmtPresetSpecifier) ? { ok: !0 } : {
637
443
  ok: !1,
638
444
  found: !0,
639
445
  error: outdent`
@@ -742,7 +548,7 @@ async function checkOxlintConfigDir(dir, describeDir) {
742
548
 
743
549
  ${oxlintSetupSnippet}
744
550
  `
745
- } : (await readFile$2(path.join(dir, file), "utf8")).includes(oxlintSharedConfig) ? { ok: !0 } : {
551
+ } : (await readFile$1(path.join(dir, file), "utf8")).includes(oxlintSharedConfig) ? { ok: !0 } : {
746
552
  ok: !1,
747
553
  found: !0,
748
554
  error: outdent`
@@ -805,141 +611,7 @@ const forcedPackageVersions = {}, forcedDevPackageVersions = {}, forcedPeerPacka
805
611
  "@types/react-dom": "^18",
806
612
  sanity: "^5 || ^6.0.0-0",
807
613
  "styled-components": "^5.2"
808
- };
809
- function errorToUndefined(err) {
810
- if (err instanceof TypeError) throw err;
811
- }
812
- const stat = util.promisify(fs.stat), readFile$1 = util.promisify(fs.readFile), allowedPartProps = [
813
- "name",
814
- "implements",
815
- "path",
816
- "description"
817
- ], disallowedPluginProps = [
818
- "api",
819
- "project",
820
- "plugins",
821
- "env"
822
- ];
823
- async function getPaths(options) {
824
- let { basePath } = options, manifest = await readManifest(options);
825
- return manifest.paths ? absolutifyPaths(manifest.paths, basePath) : null;
826
- }
827
- function absolutifyPaths(paths, basePath) {
828
- let getPath = (relative) => relative ? path.resolve(path.join(basePath, relative)) : void 0;
829
- return paths ? {
830
- basePath,
831
- compiled: getPath(paths.compiled),
832
- source: getPath(paths.source)
833
- } : { basePath };
834
- }
835
- async function readManifest(options) {
836
- let { basePath, validate = !0 } = options, manifestPath = path.normalize(path.join(basePath, "sanity.json")), content;
837
- try {
838
- content = await readFile$1(manifestPath, "utf8");
839
- } catch (err) {
840
- throw err.code === "ENOENT" ? Error(`No sanity.json found. sanity.json is required for plugins to function. Use \`${binname} init\` for a new plugin, or create an empty \`sanity.json\` with an empty object (\`{}\`) for existing ones.`) : Error(`Failed to read "${manifestPath}": ${err.message}`);
841
- }
842
- let parsed;
843
- try {
844
- parsed = JSON.parse(content);
845
- } catch (err) {
846
- throw Error(`Error parsing "${manifestPath}": ${err.message}`);
847
- }
848
- return validate && await validateManifest(parsed, options), parsed;
849
- }
850
- async function validateManifest(manifest, opts) {
851
- let options = {
852
- isPlugin: !0,
853
- ...opts
854
- };
855
- if (!isObject$1(manifest)) throw Error("Invalid sanity.json: Root must be an object");
856
- if (options.isPlugin ? await validatePluginManifest(manifest, options) : validateProjectManifest(manifest), "root" in manifest && typeof manifest.root != "boolean") throw Error("Invalid sanity.json: \"root\" property must be a boolean if declared");
857
- await validateParts(manifest, {
858
- ...options,
859
- paths: absolutifyPaths(manifest.paths, options.basePath)
860
- });
861
- }
862
- function validateProjectManifest(manifest) {
863
- if ("paths" in manifest) throw Error("Invalid sanity.json: \"paths\" property has no meaning in a project manifest");
864
- }
865
- async function validatePluginManifest(manifest, options) {
866
- let disallowed = Object.keys(manifest).filter((key) => disallowedPluginProps.includes(key)).map((key) => `"${key}"`);
867
- if (disallowed.length > 0) {
868
- let plural = disallowed.length > 1 ? "s" : "", joined = disallowed.join(", ");
869
- throw Error(`Invalid sanity.json: Key${plural} ${joined} ${plural ? "are" : "is"} not allowed in a plugin manifest`);
870
- }
871
- if (manifest.root) throw Error("Invalid sanity.json: \"root\" cannot be truthy in a plugin manifest");
872
- await validatePaths$1(manifest, options);
873
- }
874
- async function validatePaths$1(manifest, options) {
875
- if (!("paths" in manifest)) return;
876
- if (!isObject$1(manifest.paths)) throw Error("Invalid sanity.json: \"paths\" must be an object if declared");
877
- if (typeof manifest.paths.compiled != "string") throw Error("Invalid sanity.json: \"paths\" must have a (string) \"compiled\" property if declared");
878
- if (typeof manifest.paths.source != "string") throw Error("Invalid sanity.json: \"paths\" must have a (string) \"source\" property if declared");
879
- let sourcePath = path.resolve(options.basePath, manifest.paths.source), srcStats;
880
- try {
881
- srcStats = await stat(sourcePath);
882
- } catch (err) {
883
- if (err.code === "ENOENT") throw Error(`sanity.json references "source" path which does not exist: "${sourcePath}"`);
884
- }
885
- if (!srcStats?.isDirectory()) throw Error(`sanity.json references "source" path which is not a directory: "${sourcePath}"`);
886
- }
887
- async function validateParts(manifest, options) {
888
- if (!("parts" in manifest)) return;
889
- if (!Array.isArray(manifest.parts)) throw Error("Invalid sanity.json: \"parts\" must be an array if declared");
890
- let i = 0;
891
- for (let part of manifest.parts) await validatePart(part, i, options), i++;
892
- }
893
- async function validatePart(part, index, options) {
894
- if (!isObject$1(part)) throw Error(`Invalid sanity.json: "parts[${index}]" must be an object`);
895
- validateAllowedPartKeys(part, index), validatePartStringValues(part, index), validatePartNames(part, index, options), await validatePartFiles(part, index, options);
896
- }
897
- async function validatePartFiles(part, index, options) {
898
- let { verifyCompiledParts, verifySourceParts, paths } = options;
899
- if (!part?.path) return;
900
- let ext = path.extname(part.path);
901
- if (paths?.source && ext && ext !== ".js" && buildExtensions.includes(ext)) throw Error(`Invalid sanity.json: Part path has extension which is not applicable after compiling. ${ext} becomes .js after compiling. Specify filename without extension (${path.basename(part.path)}) (parts[${index}])`);
902
- if (!verifySourceParts && !verifyCompiledParts) return;
903
- let [srcExists, outDirExists] = await Promise.all([hasSourceFile(part.path, paths), verifyCompiledParts && hasCompiledFile(part.path, paths)]);
904
- if (!srcExists) throw Error(`Invalid sanity.json: Part path references file that does not exist in source directory (${paths?.source || paths?.basePath}) (parts[${index}])`);
905
- if (verifyCompiledParts && !outDirExists) throw Error(`Invalid sanity.json: Part path references file ("${part.path}") that does not exist in compiled directory (${paths?.compiled}) (parts[${index}])`);
906
- }
907
- function validatePartNames(part, index, options) {
908
- let pluginName = options.pluginName ? options.pluginName.replace(/^sanity-plugin-/, "") : "";
909
- if (!part?.name || !part?.name?.startsWith(`part:${pluginName}/`)) throw Error(`Invalid sanity.json: "name" must be prefixed with "part:${pluginName}/" - got "${part?.name}" (parts[${index}])`);
910
- if (!part?.implements?.startsWith("part:")) throw Error(`Invalid sanity.json: "implements" must be prefixed with "part:" - got "${part?.implements}" (parts[${index}])`);
911
- }
912
- function validateAllowedPartKeys(part, index) {
913
- let disallowed = Object.keys(part).filter((key) => !allowedPartProps.includes(key)).map((key) => `"${key}"`);
914
- if (disallowed.length > 0) {
915
- let plural = disallowed.length > 1 ? "s" : "", joined = disallowed.join(", ");
916
- throw Error(`Invalid sanity.json: Key${plural} ${joined} ${plural ? "are" : "is"} not allowed in a part declaration (parts[${index}])`);
917
- }
918
- }
919
- function validatePartStringValues(part, index) {
920
- let nonStrings = Object.keys(part).filter((key) => typeof part[key] != "string").map((key) => `"${key}"`);
921
- if (nonStrings.length > 0) {
922
- let plural = nonStrings.length > 1 ? "s" : "", joined = nonStrings.join(", ");
923
- throw Error(`Invalid sanity.json: Key${plural} ${joined} should be of type string (parts[${index}])`);
924
- }
925
- }
926
- function isObject$1(obj) {
927
- return !Array.isArray(obj) && typeof obj == "object" && !!obj;
928
- }
929
- async function hasSanityJson(basePath) {
930
- let file = await readJsonFile(path.join(basePath, "sanity.json")).catch(errorToUndefined);
931
- return {
932
- exists: !!file,
933
- isRoot: !!(file && file.root)
934
- };
935
- }
936
- async function findStudioV3Config(basePath) {
937
- let jsFile = "sanity.config.js";
938
- if (await fileExists(path.join(basePath, jsFile))) return { v3ConfigFile: jsFile };
939
- let tsFile = "sanity.config.ts";
940
- return { v3ConfigFile: await fileExists(path.join(basePath, tsFile)) ? tsFile : void 0 };
941
- }
942
- const lockedDependencies = {
614
+ }, lockedDependencies = {
943
615
  "styled-components": "^6.1",
944
616
  eslint: "^8.57.0",
945
617
  typescript: "^6"
@@ -961,19 +633,10 @@ const defaultDependencies = [], defaultDevDependencies = [
961
633
  "react",
962
634
  "react-dom",
963
635
  "styled-components"
964
- ], defaultPeerDependencies = ["react", "sanity"], readFile = util.promisify(fs.readFile), pathKeys = [
965
- "main",
966
- "module",
967
- "browser",
968
- "types"
969
- ];
636
+ ], defaultPeerDependencies = ["react", "sanity"], readFile = util.promisify(fs.readFile);
970
637
  async function getPackage(opts) {
971
- let options = {
972
- flags: {},
973
- ...opts
974
- };
975
- validateOptions(options);
976
- let { basePath, validate = !0 } = options, manifestPath = path.normalize(path.join(basePath, "package.json")), content;
638
+ validateOptions(opts);
639
+ let { basePath, validate = !0 } = opts, manifestPath = path.normalize(path.join(basePath, "package.json")), content;
977
640
  try {
978
641
  content = await readFile(manifestPath, "utf8");
979
642
  } catch (err) {
@@ -986,50 +649,27 @@ async function getPackage(opts) {
986
649
  throw Error(`Error parsing "${manifestPath}": ${err.message}`);
987
650
  }
988
651
  if (!isObject(parsed)) throw Error("Invalid package.json: Root must be an object");
989
- return validate && await validatePackage(parsed, options), parsed;
652
+ return validate && validatePackage(parsed, opts), parsed;
990
653
  }
991
- async function validatePackage(manifest, opts) {
654
+ function validatePackage(manifest, opts) {
992
655
  validateOptions(opts);
993
656
  let options = {
994
657
  isPlugin: !0,
995
658
  ...opts
996
659
  };
997
- options.isPlugin && await validatePluginPackage(manifest, options), validateLockFiles(options);
660
+ options.isPlugin && validatePackageName(manifest), validateLockFiles(options);
998
661
  }
999
662
  function validateOptions(opts) {
1000
663
  let options = opts || {};
1001
664
  if (!isObject(options)) throw Error("Options must be an object");
1002
665
  if (typeof options.basePath != "string") throw Error("\"options.basePath\" must be a string (path to plugin base path)");
1003
666
  }
1004
- async function validatePluginPackage(manifest, options) {
1005
- validatePackageName(manifest), await validatePaths(manifest, options);
1006
- }
1007
667
  function validatePackageName(manifest) {
1008
668
  if (typeof manifest.name != "string") throw Error("Invalid package.json: \"name\" must be a string");
1009
669
  let valid = validNpmName(manifest.name);
1010
670
  if (!valid.validForNewPackages) throw Error(`Invalid package.json: "name" is invalid: ${(valid.errors ?? []).join(", ")}`);
1011
671
  if (manifest.name[0] !== "@" && !manifest.name.startsWith("sanity-plugin-")) throw Error("Invalid package.json: \"name\" should be prefixed with \"sanity-plugin-\" (or scoped - @your-company/plugin-name)");
1012
672
  }
1013
- async function validatePaths(manifest, options) {
1014
- let paths = await getPaths({
1015
- ...options,
1016
- pluginName: manifest.name ?? "unknown",
1017
- verifySourceParts: !1,
1018
- verifyCompiledParts: !1
1019
- }), abs = (file) => path.isAbsolute(file) ? file : path.resolve(path.join(options.basePath, file)), exists = (file) => fs.existsSync(abs(file)), willExist = (file) => paths && hasSourceEquivalent(abs(file), paths), withinSourceDir = (file) => paths?.source && abs(file).startsWith(paths.source), withinTargetDir = (file) => paths?.compiled && abs(file).startsWith(paths.compiled);
1020
- for (let key of pathKeys) {
1021
- if (!(key in manifest)) continue;
1022
- let manifestValue = manifest[key];
1023
- if (typeof manifestValue != "string") throw Error(`Invalid package.json: "${key}" must be a string if defined`);
1024
- if (!options?.flags?.allowSourceTarget && paths && withinSourceDir(manifestValue)) throw Error(`Invalid package.json: "${key}" points to file within source (uncompiled) directory. Use --allow-source-target if you really want to do this.`);
1025
- if (exists(manifestValue) && paths && withinTargetDir(manifestValue) && !await willExist(manifestValue)) throw Error(`Invalid package.json: "${key}" points to file that will not exist after compiling`);
1026
- if (!exists(manifestValue) && !await willExist(manifestValue)) {
1027
- if (!paths) throw Error(`Invalid package.json: "${key}" points to file that does not exist`);
1028
- let inOutDir = paths.compiled && !abs(manifestValue).startsWith(paths.compiled);
1029
- throw Error(inOutDir ? `Invalid package.json: "${key}" points to file that does not exist, and "paths" is not configured to compile to this location` : `Invalid package.json: "${key}" points to file that does not exist, and no equivalent is found in source directory`);
1030
- }
1031
- }
1032
- }
1033
673
  function isObject(obj) {
1034
674
  return !Array.isArray(obj) && typeof obj == "object" && !!obj;
1035
675
  }
@@ -1137,6 +777,6 @@ function forceDependencyVersions(deps, versions = forcedPackageVersions) {
1137
777
  });
1138
778
  return Object.fromEntries(entries);
1139
779
  }
1140
- export { validateStudioConfig as A, writeFileWithOverwritePrompt as B, validatePackageName$1 as C, validateSanityDependencies as D, validatePkgUtilsVersion as E, isEmptyish as F, promptForPackageName as H, mkdir as I, readFile$2 as L, copyFileWithOverwritePrompt as M, ensureDir as N, validateScripts as O, fileExists as P, readJsonFile as R, validateOxlintConfig as S, validatePkgUtilsDependency as T, promptForRepoOrigin as U, prompt as V, validateDeprecatedDependencies as _, getPackage as a, validateNodeEngine as b, writePackageJsonDirect as c, hasSanityJson as d, errorToUndefined as f, validateBannedFiles as g, validateBabelConfig as h, forceDependencyVersions as i, validateTsConfig as j, validateSrcIndexFile as k, resolveLatestVersions as l, forcedPackageVersions as m, addPackageJsonScripts as n, sortKeys as o, forcedDevPackageVersions as p, addScript as r, writePackageJson as s, addBuildScripts as t, findStudioV3Config as u, validateEsmOnly as v, validatePackageType as w, validateOxfmtConfig as x, validateIncompatiblePlugin as y, writeFile as z };
780
+ export { mkdir as A, validateScripts as C, ensureDir as D, copyFileWithOverwritePrompt as E, prompt as F, promptForPackageName as I, promptForRepoOrigin as L, readJsonFile as M, writeFile as N, fileExists as O, writeFileWithOverwritePrompt as P, validatePkgUtilsVersion as S, validateTsConfig as T, validateOxfmtConfig as _, getPackage as a, validatePackageType as b, writePackageJsonDirect as c, forcedPackageVersions as d, validateBabelConfig as f, validateNodeEngine as g, validateEsmOnly as h, forceDependencyVersions as i, readFile$1 as j, isEmptyish as k, resolveLatestVersions as l, validateDeprecatedDependencies as m, addPackageJsonScripts as n, sortKeys as o, validateBannedFiles as p, addScript as r, writePackageJson as s, addBuildScripts as t, forcedDevPackageVersions as u, validateOxlintConfig as v, validateSrcIndexFile as w, validatePkgUtilsDependency as x, validatePackageName$1 as y };
1141
781
 
1142
- //# sourceMappingURL=package-BrKrShA_.js.map
782
+ //# sourceMappingURL=package-Cx3OyOx-.js.map