@sanity/plugin-kit 3.1.12 → 3.1.13-canary.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 (61) hide show
  1. package/assets/inject/semver-workflow/.github/workflows/main.yml +6 -6
  2. package/dist/_chunks-cjs/cli.js +135 -0
  3. package/dist/_chunks-cjs/cli.js.map +1 -0
  4. package/dist/_chunks-cjs/init.js +894 -0
  5. package/dist/_chunks-cjs/init.js.map +1 -0
  6. package/dist/_chunks-cjs/init2.js +83 -0
  7. package/dist/_chunks-cjs/init2.js.map +1 -0
  8. package/dist/_chunks-cjs/inject.js +54 -0
  9. package/dist/_chunks-cjs/inject.js.map +1 -0
  10. package/dist/_chunks-cjs/link-watch.js +84 -0
  11. package/dist/_chunks-cjs/link-watch.js.map +1 -0
  12. package/dist/_chunks-cjs/package.js +1808 -0
  13. package/dist/_chunks-cjs/package.js.map +1 -0
  14. package/dist/_chunks-cjs/package2.js +143 -0
  15. package/dist/_chunks-cjs/package2.js.map +1 -0
  16. package/dist/_chunks-cjs/ts.js +162 -0
  17. package/dist/_chunks-cjs/ts.js.map +1 -0
  18. package/dist/_chunks-cjs/verify-package.js +75 -0
  19. package/dist/_chunks-cjs/verify-package.js.map +1 -0
  20. package/dist/_chunks-cjs/verify-studio.js +57 -0
  21. package/dist/_chunks-cjs/verify-studio.js.map +1 -0
  22. package/dist/_chunks-cjs/version.js +51 -0
  23. package/dist/_chunks-cjs/version.js.map +1 -0
  24. package/dist/cli.d.ts +4 -0
  25. package/dist/cli.js +4 -7
  26. package/dist/cli.js.map +1 -1
  27. package/dist/index.js +1 -1
  28. package/package.json +57 -59
  29. package/src/actions/inject.ts +1 -1
  30. package/src/actions/verify/types.ts +0 -1
  31. package/src/actions/verify/validations.ts +13 -69
  32. package/src/actions/verify/verify-common.ts +0 -1
  33. package/src/actions/verify-package.ts +0 -2
  34. package/src/cli.ts +1 -0
  35. package/src/configs/forced-package-versions.ts +0 -1
  36. package/src/configs/pkg-config.ts +0 -1
  37. package/src/configs/tsconfig.ts +20 -21
  38. package/src/npm/package.ts +6 -17
  39. package/src/presets/ui.ts +0 -1
  40. package/dist/_chunks/cli-cFLCCBOO.js +0 -168
  41. package/dist/_chunks/cli-cFLCCBOO.js.map +0 -1
  42. package/dist/_chunks/init-RizSz7N7.js +0 -104
  43. package/dist/_chunks/init-RizSz7N7.js.map +0 -1
  44. package/dist/_chunks/init-iwJScjA2.js +0 -966
  45. package/dist/_chunks/init-iwJScjA2.js.map +0 -1
  46. package/dist/_chunks/inject-p1N6jT0L.js +0 -49
  47. package/dist/_chunks/inject-p1N6jT0L.js.map +0 -1
  48. package/dist/_chunks/link-watch-hESx--O4.js +0 -91
  49. package/dist/_chunks/link-watch-hESx--O4.js.map +0 -1
  50. package/dist/_chunks/package-LD2bWiQM.js +0 -2358
  51. package/dist/_chunks/package-LD2bWiQM.js.map +0 -1
  52. package/dist/_chunks/package-hEMm6olE.js +0 -155
  53. package/dist/_chunks/package-hEMm6olE.js.map +0 -1
  54. package/dist/_chunks/ts--PkJtFoh.js +0 -165
  55. package/dist/_chunks/ts--PkJtFoh.js.map +0 -1
  56. package/dist/_chunks/verify-package-88yI8VXr.js +0 -97
  57. package/dist/_chunks/verify-package-88yI8VXr.js.map +0 -1
  58. package/dist/_chunks/verify-studio-t8s7BSdb.js +0 -74
  59. package/dist/_chunks/verify-studio-t8s7BSdb.js.map +0 -1
  60. package/dist/_chunks/version-UQqnNiud.js +0 -54
  61. package/dist/_chunks/version-UQqnNiud.js.map +0 -1
@@ -10,25 +10,22 @@ import {PackageJson, SanityStudioJson, SanityV2Json} from './types'
10
10
  import {ParsedCommandLine} from 'typescript'
11
11
 
12
12
  export const expectedScripts = {
13
- build:
14
- 'run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict',
13
+ build: 'plugin-kit verify-package --silent && pkg-utils build --strict --check --clean',
15
14
  watch: 'pkg-utils watch --strict',
16
15
  'link-watch': 'plugin-kit link-watch',
17
- prepublishOnly: 'run-s build',
16
+ prepublishOnly: 'npm run build',
18
17
  }
19
18
 
20
- const expectedModulesFields = ['source', 'exports', 'main', 'module', 'files']
21
-
22
19
  function filesWithSuffixes(fileBases: string[], suffixes: string[]): string[] {
23
20
  return fileBases.flatMap((file) => suffixes.map((suffix) => `${file}.${suffix}`))
24
21
  }
25
22
 
26
23
  export function validateNodeEngine(packageJson: PackageJson) {
27
- const nodeVersionRange = '>=14'
24
+ const nodeVersionRange = '>=18'
28
25
  if (!packageJson.engines?.node?.startsWith(nodeVersionRange)) {
29
26
  return [
30
27
  outdent`
31
- Expected package.json to contain engines.node: ">=14" to ensure Studio compatible builds,
28
+ Expected package.json to contain engines.node: ">=18" to ensure Studio compatible builds,
32
29
  but it was: ${packageJson.engines?.node}
33
30
 
34
31
  Please add the following to package.json:
@@ -40,53 +37,6 @@ export function validateNodeEngine(packageJson: PackageJson) {
40
37
  }
41
38
  }
42
39
 
43
- export function validateModule(packageJson: PackageJson, options: {outDir: string}): string[] {
44
- const {outDir} = options
45
- const errors: string[] = []
46
-
47
- const missingFields = expectedModulesFields.filter((field) => !packageJson[field])
48
-
49
- if (missingFields.length) {
50
- errors.push(
51
- outdent`
52
- Expected source, exports, main, module and files entries in package.json, but ${missingFields.join(
53
- ', ',
54
- )} where missing.
55
-
56
- Example:
57
-
58
- Given a plugin with entry-point in src/index.ts, using default @sanity/pkg-utils build command,
59
- package.json should contain the following entries to ensure that commonjs and esm outputs are built into ${outDir}:
60
-
61
- "source": "./src/index.ts",
62
- "exports": {
63
- ".": {
64
- "types": "./${outDir}/index.d.ts",
65
- "source": "./src/index.ts",
66
- "require": "./${outDir}/index.js",
67
- "import": "./${outDir}/index.esm.js",
68
- "default": "./${outDir}/index.js"
69
- }
70
- },
71
- "main": "./${outDir}/index.js",
72
- "module": "./${outDir}/index.esm.js",
73
- "types": "./${outDir}/index.d.ts",
74
- "files": [
75
- "${outDir}",
76
- "src"
77
- ],
78
-
79
- Refer to @sanity/pkg-utils for more: https://github.com/sanity-io/pkg-utils#sanitypkg-utils
80
- `.trimStart(),
81
- )
82
- }
83
-
84
- if (packageJson.typings) {
85
- errors.push(outdent`Found typings field in package.json. Use types instead.`)
86
- }
87
- return errors
88
- }
89
-
90
40
  export function validateScripts(packageJson: PackageJson): string[] {
91
41
  const errors: string[] = []
92
42
 
@@ -123,18 +73,12 @@ export async function validateTsConfig(
123
73
  const errors: string[] = []
124
74
 
125
75
  const expectedCompilerOptions = {
126
- moduleResolution: 'node',
127
76
  target: 'esnext',
128
- module: 'esnext',
129
- emitDeclarationOnly: true,
130
- esModuleInterop: true,
131
- skipLibCheck: true,
132
- isolatedModules: true,
133
- downlevelIteration: true,
134
- declaration: true,
135
- allowSyntheticDefaultImports: true,
77
+ jsx: 'preserve',
78
+ module: 'preserve',
136
79
  rootDir: '.',
137
80
  outDir,
81
+ noEmit: true,
138
82
  }
139
83
 
140
84
  const wrongEntries = Object.entries(expectedCompilerOptions).filter(([key, value]) => {
@@ -148,16 +92,16 @@ export async function validateTsConfig(
148
92
  option = path.relative(basePath, option) || '.'
149
93
  }
150
94
 
151
- if (key === 'moduleResolution' && option === 2) {
152
- option = 'node'
153
- }
154
-
155
95
  if (key === 'target' && option === 99) {
156
96
  option = 'esnext'
157
97
  }
158
98
 
159
- if (key === 'module' && option === 99) {
160
- option = 'esnext'
99
+ if (key === 'module' && option === 200) {
100
+ option = 'preserve'
101
+ }
102
+
103
+ if (key === 'jsx' && option === 1) {
104
+ option = 'preserve'
161
105
  }
162
106
 
163
107
  return typeof value === 'string' && typeof option === 'string'
@@ -12,7 +12,6 @@ const splitLine = `\n----------------------------------------------------------`
12
12
 
13
13
  export const verifyPackageConfigDefaults = {
14
14
  packageName: true,
15
- module: true,
16
15
  tsconfig: true,
17
16
  tsc: true,
18
17
  dependencies: true,
@@ -12,7 +12,6 @@ import {
12
12
  } from './verify/verify-common'
13
13
  import {
14
14
  validateBabelConfig,
15
- validateModule,
16
15
  validateNodeEngine,
17
16
  validatePackageName,
18
17
  validatePkgUtilsDependency,
@@ -46,7 +45,6 @@ export async function verifyPackage({basePath, flags}: {basePath: string; flags:
46
45
  await validation('pkg-utils', async () => validatePkgUtilsDependency(packageJson))
47
46
  await validation('srcIndex', async () => validateSrcIndexFile(basePath))
48
47
  await validation('scripts', async () => validateScripts(packageJson))
49
- await validation('module', async () => validateModule(packageJson, {outDir}))
50
48
  await validation('nodeEngine', async () => validateNodeEngine(packageJson))
51
49
  await validation('duplicateConfig', async () =>
52
50
  disallowDuplicateEslintConfig(basePath, packageJson),
package/src/cli.ts CHANGED
@@ -4,6 +4,7 @@ import commands from './cmds'
4
4
  import sharedFlags from './sharedFlags'
5
5
  import {cliName} from './constants'
6
6
 
7
+ /** @public */
7
8
  export async function cliEntry(argv = process.argv, autoExit = true) {
8
9
  const cli = meow(
9
10
  `
@@ -5,7 +5,6 @@ export const forcedDevPackageVersions = forcedPackageVersions
5
5
  export const forcedPeerPackageVersions = {
6
6
  react: '^18',
7
7
  'react-dom': '^18',
8
- 'react-is': '^18',
9
8
  '@types/react': '^18',
10
9
  '@types/react-dom': '^18',
11
10
  sanity: '^3',
@@ -13,7 +13,6 @@ export function pkgConfigTemplate(options: {outDir: string; flags: InitFlags}):
13
13
  import {defineConfig} from '@sanity/pkg-utils'
14
14
 
15
15
  export default defineConfig({
16
- legacyExports: true,
17
16
  dist: '${outDir}',
18
17
  tsconfig: 'tsconfig.${outDir}.json',
19
18
 
@@ -12,12 +12,7 @@ export function tsconfigTemplate(options: {flags: InitFlags}): InjectTemplate {
12
12
  value: outdent`
13
13
  {
14
14
  "extends": "./tsconfig.settings",
15
- "include": ["./src", "./package.config.ts"],
16
- "compilerOptions": {
17
- "rootDir": ".",
18
- "jsx": "react-jsx",
19
- "noEmit": true
20
- }
15
+ "include": ["./src", "./package.config.ts"]
21
16
  }
22
17
  `,
23
18
  }
@@ -39,20 +34,17 @@ export function tsconfigTemplateDist(options: {outDir: string; flags: InitFlags}
39
34
  "./src/**/__mocks__",
40
35
  "./src/**/*.test.ts",
41
36
  "./src/**/*.test.tsx"
42
- ],
43
- "compilerOptions": {
44
- "rootDir": ".",
45
- "outDir": "./${outDir}",
46
- "jsx": "react-jsx",
47
- "emitDeclarationOnly": true
48
- }
37
+ ]
49
38
  }
50
39
  `,
51
40
  }
52
41
  }
53
42
 
54
- export function tsconfigTemplateSettings(options: {flags: InitFlags}): InjectTemplate {
55
- const {flags} = options
43
+ export function tsconfigTemplateSettings(options: {
44
+ outDir: string
45
+ flags: InitFlags
46
+ }): InjectTemplate {
47
+ const {flags, outDir} = options
56
48
 
57
49
  return {
58
50
  type: 'template',
@@ -61,17 +53,24 @@ export function tsconfigTemplateSettings(options: {flags: InitFlags}): InjectTem
61
53
  value: outdent`
62
54
  {
63
55
  "compilerOptions": {
64
- "moduleResolution": "node",
56
+ "rootDir": ".",
57
+ "outDir": "./${outDir}",
58
+
65
59
  "target": "esnext",
66
- "module": "esnext",
67
- "lib": ["DOM", "DOM.Iterable", "ESNext"],
60
+ "jsx": "preserve",
61
+ "module": "preserve",
62
+ "moduleResolution": "bundler",
68
63
  "esModuleInterop": true,
64
+ "resolveJsonModule": true,
65
+ "moduleDetection": "force",
69
66
  "strict": true,
70
- "downlevelIteration": true,
71
- "declaration": true,
72
67
  "allowSyntheticDefaultImports": true,
73
68
  "skipLibCheck": true,
74
- "isolatedModules": true
69
+ "forceConsistentCasingInFileNames": true,
70
+ "isolatedModules": true,
71
+
72
+ // Don't emit by default, pkg-utils will ignore this when generating .d.ts files
73
+ "noEmit": true
75
74
  }
76
75
  }
77
76
  `,
@@ -21,24 +21,19 @@ import {
21
21
  const defaultDependencies = [incompatiblePluginPackage]
22
22
 
23
23
  const defaultDevDependencies = [
24
- 'npm-run-all',
25
- 'rimraf',
26
24
  'sanity',
27
25
 
28
26
  // peer dependencies of `sanity`
29
27
  'react',
30
28
  'react-dom',
31
29
  'styled-components',
32
-
33
- // peer dependencies of `styled-components`
34
- 'react-is',
35
30
  ]
36
31
 
37
32
  const defaultPeerDependencies = ['react', 'sanity']
38
33
 
39
34
  const readFile = util.promisify(fs.readFile)
40
35
 
41
- const pathKeys: (keyof PackageJson)[] = ['main', 'module', 'browser', 'types', 'typings']
36
+ const pathKeys: (keyof PackageJson)[] = ['main', 'module', 'browser', 'types']
42
37
 
43
38
  export async function getPackage(opts: ManifestOptions): Promise<PackageJson> {
44
39
  const options = {flags: {}, ...opts}
@@ -292,19 +287,17 @@ export async function writePackageJson(data: PackageData, options: InjectOptions
292
287
  ...repoFromOrigin(gitOrigin),
293
288
  license: license ? license.id : 'UNLICENSED',
294
289
  author: user?.email ? `${user.name} <${user.email}>` : user?.name,
290
+ sideEffects: false,
291
+ type: 'commonjs',
295
292
  exports: {
296
293
  '.': {
297
- ...(flags.typescript ? {types: `./${outDir}/index.d.ts`} : {}),
298
294
  source,
299
- import: `./${outDir}/index.esm.js`,
300
- require: `./${outDir}/index.js`,
301
- default: `./${outDir}/index.esm.js`,
295
+ import: `./${outDir}/index.mjs`,
296
+ default: `./${outDir}/index.js`,
302
297
  },
303
298
  './package.json': './package.json',
304
299
  },
305
300
  main: `./${outDir}/index.js`,
306
- module: `./${outDir}/index.esm.js`,
307
- source,
308
301
  ...(flags.typescript ? {types: `./${outDir}/index.d.ts`} : {}),
309
302
  files,
310
303
  scripts: {...prev.scripts},
@@ -312,7 +305,7 @@ export async function writePackageJson(data: PackageData, options: InjectOptions
312
305
  devDependencies: sortKeys(devDependencies),
313
306
  peerDependencies: sortKeys(peerDependencies),
314
307
  engines: {
315
- node: '>=14',
308
+ node: '>=18',
316
309
  },
317
310
  }
318
311
 
@@ -324,9 +317,6 @@ export async function writePackageJson(data: PackageData, options: InjectOptions
324
317
  ...forcedOrder,
325
318
  }
326
319
 
327
- // we use types, not typings
328
- delete manifest.typings
329
-
330
320
  const differs = JSON.stringify(prev) !== JSON.stringify(manifest)
331
321
  log.debug('Does manifest differ? %s', differs ? 'yes' : 'no')
332
322
  if (differs) {
@@ -401,7 +391,6 @@ export async function addBuildScripts(manifest: PackageJson, options: InjectOpti
401
391
  }
402
392
  return addPackageJsonScripts(manifest, options, (scripts) => {
403
393
  scripts.build = addScript(expectedScripts.build, scripts.build)
404
- scripts.clean = addScript(`rimraf ${outDir}`, scripts.clean)
405
394
  scripts.format = addScript(`prettier --write --cache --ignore-unknown .`, scripts.format)
406
395
  scripts['link-watch'] = addScript(expectedScripts['link-watch'], scripts['link-watch'])
407
396
  scripts.lint = addScript(`eslint .`, scripts.lint)
package/src/presets/ui.ts CHANGED
@@ -62,7 +62,6 @@ async function resolveDevDependencyList(): Promise<Record<string, string>> {
62
62
  // install the peer dependencies of `@sanity/ui` as dev dependencies
63
63
  'react',
64
64
  'react-dom',
65
- 'react-is',
66
65
  'styled-components',
67
66
  ])
68
67
  }
@@ -1,168 +0,0 @@
1
- 'use strict';
2
-
3
- var meow = require('meow');
4
- var chalk = require('chalk');
5
- function _interopDefaultCompat(e) {
6
- return e && typeof e === 'object' && 'default' in e ? e : {
7
- default: e
8
- };
9
- }
10
- var meow__default = /*#__PURE__*/_interopDefaultCompat(meow);
11
- var chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
12
- let beQuiet = false;
13
- let beVerbose = false;
14
- function setVerbosity(_ref) {
15
- let {
16
- verbose,
17
- silent
18
- } = _ref;
19
- if (silent) {
20
- beVerbose = false;
21
- beQuiet = true;
22
- } else if (verbose) {
23
- beVerbose = true;
24
- beQuiet = false;
25
- }
26
- }
27
- var log = {
28
- setVerbosity,
29
- // Bypasses any checks, prints regardless (only use for things like `cli --version`)
30
- msg: function (msg) {
31
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
32
- args[_key - 1] = arguments[_key];
33
- }
34
- return !beQuiet && console.log(msg, ...args);
35
- },
36
- // Debug only printed on --verbose
37
- debug: function (msg) {
38
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
39
- args[_key2 - 1] = arguments[_key2];
40
- }
41
- return !beQuiet && beVerbose && console.debug("".concat(chalk__default.default.bgBlack.white("[debug]"), " ").concat(msg), ...args);
42
- },
43
- // Success messages only printed if not --silent
44
- success: function (msg) {
45
- for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
46
- args[_key3 - 1] = arguments[_key3];
47
- }
48
- return !beQuiet && console.info("".concat(chalk__default.default.bgBlack.greenBright("[success]"), " ").concat(msg), ...args);
49
- },
50
- // Info only printed if not --silent ("standard" level)
51
- info: function (msg) {
52
- for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
53
- args[_key4 - 1] = arguments[_key4];
54
- }
55
- return !beQuiet && console.info("".concat(chalk__default.default.bgBlack.cyanBright("[info]"), " ").concat(msg), ...args);
56
- },
57
- // Warning only printed if not --silent
58
- warn: function (msg) {
59
- for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
60
- args[_key5 - 1] = arguments[_key5];
61
- }
62
- return !beQuiet && console.warn("".concat(chalk__default.default.bgBlack.yellowBright("[warn]"), " ").concat(msg), ...args);
63
- },
64
- // Errors are always printed
65
- error: function (msg) {
66
- for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
67
- args[_key6 - 1] = arguments[_key6];
68
- }
69
- return console.error("".concat(chalk__default.default.bgBlack.redBright("[error]"), " ").concat(msg), ...args);
70
- }
71
- };
72
- var commands = {
73
- init: async options => {
74
- await (await Promise.resolve().then(function () {
75
- return require('./init-RizSz7N7.js');
76
- })).default(options);
77
- },
78
- inject: async options => {
79
- await (await Promise.resolve().then(function () {
80
- return require('./inject-p1N6jT0L.js');
81
- })).default(options);
82
- },
83
- "link-watch": async options => {
84
- await (await Promise.resolve().then(function () {
85
- return require('./link-watch-hESx--O4.js');
86
- })).default(options);
87
- },
88
- "verify-package": async options => {
89
- await (await Promise.resolve().then(function () {
90
- return require('./verify-package-88yI8VXr.js');
91
- })).default(options);
92
- },
93
- "verify-studio": async options => {
94
- await (await Promise.resolve().then(function () {
95
- return require('./verify-studio-t8s7BSdb.js');
96
- })).default(options);
97
- },
98
- version: async options => {
99
- await (await Promise.resolve().then(function () {
100
- return require('./version-UQqnNiud.js');
101
- })).default(options);
102
- }
103
- };
104
- var sharedFlags = {
105
- debug: {
106
- default: false,
107
- type: "boolean"
108
- },
109
- silent: {
110
- type: "boolean",
111
- default: false
112
- },
113
- verbose: {
114
- type: "boolean",
115
- default: false
116
- }
117
- };
118
- const cliName = "@sanity/plugin-kit";
119
- const urls = {
120
- refDocs: "https://beta.sanity.io/docs/reference",
121
- migrationGuideStudio: "https://beta.sanity.io/docs/platform/v2-to-v3",
122
- migrationGuidePlugin: "https://beta.sanity.io/docs/platform/v2-to-v3/plugins",
123
- pluginReadme: "https://github.com/sanity-io/plugin-kit",
124
- incompatiblePlugin: "https://github.com/sanity-io/incompatible-plugin",
125
- sanityExchange: "https://www.sanity.io/exchange",
126
- linterPackage: "https://github.com/sanity-io/eslint-config-no-v2-imports"
127
- };
128
- const incompatiblePluginPackage = "@sanity/incompatible-plugin";
129
- const defaultOutDir = "dist";
130
- async function cliEntry() {
131
- let argv = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : process.argv;
132
- let autoExit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
133
- const cli = meow__default.default("\n\tUsage\n\t $ ".concat(cliName, " [--help] [--debug] <command> [<args>]\n\n These are common commands used in various situations:\n\n init Create a new Sanity plugin\n inject Inject config into an existing Sanity v3 plugin\n verify-package Check that a Sanity plugin package follows V3 conventions. Prints upgrade steps.\n verify-studio Check that a Sanity Studio follows V3 conventions. Prints upgrade steps.\n link-watch Recompiles plugin automatically on changes and runs yalc push --publish\n version Show the version of ").concat(cliName, " currently installed\n\n Options\n --silent Do not print info and warning messages\n --verbose Log everything. This option conflicts with --silent\n --debug Print stack trace on errors\n --version Output the version number\n --help Output usage information\n\n Examples\n # Init a new plugin in current directory\n $ ").concat(cliName, " init\n\n # Init a new plugin in my-sanity-plugin directory\n $ ").concat(cliName, " init my-sanity-plugin\n\n # Check that a Sanity plugin package in current directory follows V3 conventions\n $ ").concat(cliName, " verify-package\n\n # Check that a Sanity Studio in current directory follows V3 conventions\n $ ").concat(cliName, " verify-studio\n"), {
134
- autoHelp: false,
135
- flags: sharedFlags,
136
- argv: argv.slice(2)
137
- });
138
- const commandName = cli.input[0];
139
- if (!commandName) {
140
- cli.showHelp();
141
- }
142
- if (!(commandName in commands)) {
143
- console.error("Unknown command \"".concat(commandName, "\""));
144
- cli.showHelp();
145
- }
146
- if (cli.flags.silent && cli.flags.verbose) {
147
- log.error("--silent and --verbose are mutually exclusive");
148
- cli.showHelp();
149
- }
150
- const cmd = commands[commandName];
151
- try {
152
- log.setVerbosity(cli.flags);
153
- await cmd({
154
- argv: argv.slice(3)
155
- });
156
- } catch (err) {
157
- log.error(err instanceof TypeError || cli.flags.debug ? err.stack : err.message);
158
- process.exit(1);
159
- }
160
- }
161
- exports.cliEntry = cliEntry;
162
- exports.cliName = cliName;
163
- exports.defaultOutDir = defaultOutDir;
164
- exports.incompatiblePluginPackage = incompatiblePluginPackage;
165
- exports.log = log;
166
- exports.sharedFlags = sharedFlags;
167
- exports.urls = urls;
168
- //# sourceMappingURL=cli-cFLCCBOO.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli-cFLCCBOO.js","sources":["../../src/util/log.ts","../../src/cmds/index.ts","../../src/sharedFlags.ts","../../src/constants.ts","../../src/cli.ts"],"sourcesContent":["// Note: This is _specifically_ meant for CLI usage,\n// I realize that \"singletons\" are bad.\n\nimport chalk from 'chalk'\n\nlet beQuiet = false\nlet beVerbose = false\n\nfunction setVerbosity({verbose, silent}: {verbose: boolean; silent: boolean}) {\n if (silent) {\n beVerbose = false\n beQuiet = true\n } else if (verbose) {\n beVerbose = true\n beQuiet = false\n }\n}\n\nexport default {\n setVerbosity: setVerbosity,\n\n // Bypasses any checks, prints regardless (only use for things like `cli --version`)\n msg: (msg: any, ...args: any[]) => !beQuiet && console.log(msg, ...args),\n\n // Debug only printed on --verbose\n debug: (msg: any, ...args: any[]) =>\n !beQuiet && beVerbose && console.debug(`${chalk.bgBlack.white('[debug]')} ${msg}`, ...args),\n\n // Success messages only printed if not --silent\n success: (msg: any, ...args: any[]) =>\n !beQuiet && console.info(`${chalk.bgBlack.greenBright('[success]')} ${msg}`, ...args),\n\n // Info only printed if not --silent (\"standard\" level)\n info: (msg: any, ...args: any[]) =>\n !beQuiet && console.info(`${chalk.bgBlack.cyanBright('[info]')} ${msg}`, ...args),\n\n // Warning only printed if not --silent\n warn: (msg: any, ...args: any[]) =>\n !beQuiet && console.warn(`${chalk.bgBlack.yellowBright('[warn]')} ${msg}`, ...args),\n\n // Errors are always printed\n error: (msg: any, ...args: any[]) =>\n console.error(`${chalk.bgBlack.redBright('[error]')} ${msg}`, ...args),\n}\n","export default {\n init: async (options: {argv: string[]}) => {\n await (await import('./init')).default(options)\n },\n inject: async (options: {argv: string[]}) => {\n await (await import('./inject')).default(options)\n },\n 'link-watch': async (options: {argv: string[]}) => {\n await (await import('./link-watch')).default(options)\n },\n 'verify-package': async (options: {argv: string[]}) => {\n await (await import('./verify-package')).default(options)\n },\n 'verify-studio': async (options: {argv: string[]}) => {\n await (await import('./verify-studio')).default(options)\n },\n version: async (options: {argv: string[]}) => {\n await (await import('./version')).default(options)\n },\n}\n","export default {\n debug: {\n default: false,\n type: 'boolean',\n },\n silent: {\n type: 'boolean',\n default: false,\n },\n verbose: {\n type: 'boolean',\n default: false,\n },\n} as const\n","export const cliName = '@sanity/plugin-kit'\n\nexport const urls = {\n refDocs: 'https://beta.sanity.io/docs/reference',\n migrationGuideStudio: 'https://beta.sanity.io/docs/platform/v2-to-v3',\n migrationGuidePlugin: 'https://beta.sanity.io/docs/platform/v2-to-v3/plugins',\n pluginReadme: 'https://github.com/sanity-io/plugin-kit',\n incompatiblePlugin: 'https://github.com/sanity-io/incompatible-plugin',\n sanityExchange: 'https://www.sanity.io/exchange',\n linterPackage: 'https://github.com/sanity-io/eslint-config-no-v2-imports',\n}\n\nexport const incompatiblePluginPackage = '@sanity/incompatible-plugin'\n\nexport const defaultOutDir = 'dist'\n","import meow from 'meow'\nimport log from './util/log'\nimport commands from './cmds'\nimport sharedFlags from './sharedFlags'\nimport {cliName} from './constants'\n\nexport async function cliEntry(argv = process.argv, autoExit = true) {\n const cli = meow(\n `\n\tUsage\n\t $ ${cliName} [--help] [--debug] <command> [<args>]\n\n These are common commands used in various situations:\n\n init Create a new Sanity plugin\n inject Inject config into an existing Sanity v3 plugin\n verify-package Check that a Sanity plugin package follows V3 conventions. Prints upgrade steps.\n verify-studio Check that a Sanity Studio follows V3 conventions. Prints upgrade steps.\n link-watch Recompiles plugin automatically on changes and runs yalc push --publish\n version Show the version of ${cliName} currently installed\n\n Options\n --silent Do not print info and warning messages\n --verbose Log everything. This option conflicts with --silent\n --debug Print stack trace on errors\n --version Output the version number\n --help Output usage information\n\n Examples\n # Init a new plugin in current directory\n $ ${cliName} init\n\n # Init a new plugin in my-sanity-plugin directory\n $ ${cliName} init my-sanity-plugin\n\n # Check that a Sanity plugin package in current directory follows V3 conventions\n $ ${cliName} verify-package\n\n # Check that a Sanity Studio in current directory follows V3 conventions\n $ ${cliName} verify-studio\n`,\n {\n autoHelp: false,\n flags: sharedFlags,\n argv: argv.slice(2),\n },\n )\n\n const commandName = cli.input[0]\n if (!commandName) {\n cli.showHelp() // Exits\n }\n\n if (!(commandName in commands)) {\n console.error(`Unknown command \"${commandName}\"`)\n cli.showHelp() // Exits\n }\n\n if (cli.flags.silent && cli.flags.verbose) {\n log.error(`--silent and --verbose are mutually exclusive`)\n cli.showHelp() // Exits\n }\n\n // Lazy-load command\n const cmd = commands[commandName as keyof typeof commands]\n\n try {\n log.setVerbosity(cli.flags)\n await cmd({argv: argv.slice(3)})\n } catch (err: any) {\n log.error(err instanceof TypeError || cli.flags.debug ? err.stack : err.message)\n\n // eslint-disable-next-line no-process-exit\n process.exit(1)\n }\n}\n"],"names":["beQuiet","beVerbose","setVerbosity","_ref","verbose","silent","log","msg","_len","arguments","length","args","Array","_key","console","debug","_len2","concat","chalk","bgBlack","white","success","_len3","info","default","greenBright","_len4","cyanBright","warn","_len5","yellowBright","error","_len6","_key6","redBright","commands","init","options","Promise","resolve","then","require","inject","version","sharedFlags","type","cliName","urls","refDocs","migrationGuideStudio","migrationGuidePlugin","pluginReadme","incompatiblePlugin","sanityExchange","linterPackage","incompatiblePluginPackage","defaultOutDir","cliEntry","argv","undefined","process","autoExit","cli","meow","autoHelp","flags","slice","commandName","input","showHelp","cmd","err","TypeError","stack","message","exit"],"mappings":";;;;;;;;;;;AAKA,IAAIA,OAAU,GAAA,KAAA;AACd,IAAIC,SAAY,GAAA,KAAA;AAEhB,SAASC,YAAaA,CAAAC,IAAA,EAAwD;EAAA,IAAxD;IAACC,OAAS;IAAAC;GAA8C,GAAAF,IAAA;EAC5E,IAAIE,MAAQ,EAAA;IACEJ,SAAA,GAAA,KAAA;IACFD,OAAA,GAAA,IAAA;aACDI,OAAS,EAAA;IACNH,SAAA,GAAA,IAAA;IACFD,OAAA,GAAA,KAAA;EACZ;AACF;AAEA,IAAeM,GAAA,GAAA;EACbJ,YAAA;EAAA;EAGAK,GAAA,EAAK,SAAAA,CAACA,GAAA;IAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAaC,IAAgB,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAhBF,IAAgB,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;IAAA;IAAA,OAAA,CAACb,WAAWc,OAAQ,CAAAR,GAAA,CAAIC,GAAK,E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;;"}
@@ -1,104 +0,0 @@
1
- 'use strict';
2
-
3
- var path = require('path');
4
- var meow = require('meow');
5
- var cli = require('./cli-cFLCCBOO.js');
6
- var init = require('./init-iwJScjA2.js');
7
- var _package = require('./package-LD2bWiQM.js');
8
- var execa = require('execa');
9
- function _interopDefaultCompat(e) {
10
- return e && typeof e === 'object' && 'default' in e ? e : {
11
- default: e
12
- };
13
- }
14
- var path__default = /*#__PURE__*/_interopDefaultCompat(path);
15
- var meow__default = /*#__PURE__*/_interopDefaultCompat(meow);
16
- var execa__default = /*#__PURE__*/_interopDefaultCompat(execa);
17
- function npmIsAvailable() {
18
- return execa__default.default("npm", ["-v"]).then(() => true).catch(() => false);
19
- }
20
- function yarnIsAvailable() {
21
- return execa__default.default("yarn", ["-v"]).then(() => true).catch(() => false);
22
- }
23
- function pnpmAvailable() {
24
- return execa__default.default("pnpm", ["-v"]).then(() => true).catch(() => false);
25
- }
26
- async function promptForPackageManager() {
27
- const [npm, yarn, pnpm] = await Promise.all([npmIsAvailable(), yarnIsAvailable(), pnpmAvailable()]);
28
- const choices = [npm && "npm", yarn && "yarn", pnpm && "pnpm"].filter(Boolean);
29
- if (choices.length < 2) {
30
- return choices[0] || "npm";
31
- }
32
- return _package.prompt("Which package manager do you prefer?", {
33
- choices: choices.map(value => ({
34
- value,
35
- name: value
36
- })),
37
- default: choices[0]
38
- });
39
- }
40
- async function installDependencies(pm, _ref) {
41
- let {
42
- cwd
43
- } = _ref;
44
- const proc = execa__default.default(pm, ["install"], {
45
- cwd,
46
- stdio: "inherit"
47
- });
48
- const {
49
- exitCode
50
- } = await proc;
51
- return exitCode <= 0;
52
- }
53
- const description = "Initialize a new Sanity plugin";
54
- const help = "\nUsage\n $ ".concat(cli.cliName, " init [dir] [<args>]\n\nOptions\n --no-eslint Disables ESLint config and dependencies from being added\n --no-prettier Disables prettier config and dependencies from being added\n --no-typescript Disables typescript config and dependencies from being added\n --no-license Disables LICENSE + package.json license field from being added\n --no-editorconfig Disables .editorconfig from being added\n --no-gitignore Disables .gitignore from being added\n --no-scripts Disables scripts from being added to package.json\n --no-install Disables automatically running package manager install\n\n --name [package-name] Use the provided package-name\n --author [name] Use the provided author\n --repo [url] Use the provided repo url\n --license [spdx] Use the license with the given SPDX identifier\n --force No promt when overwriting files\n\n --preset [preset-name] Adds config and files from a named preset. --preset can be supplied multiple times.\n The following presets are available:\n").concat(init.presetHelpList(30), "\n\nExamples\n # Initialize a new plugin in the current directory\n $ ").concat(cli.cliName, " init\n\n # Initialize a plugin in the directory ~/my-plugin\n $ ").concat(cli.cliName, " init ~/my-plugin\n\n # Don't add eslint or prettier\n $ ").concat(cli.cliName, " init --no-eslint --no-prettier\n");
55
- async function run(_ref2) {
56
- let {
57
- argv
58
- } = _ref2;
59
- const cli$1 = meow__default.default(help, {
60
- flags: init.initFlags,
61
- argv,
62
- description
63
- });
64
- const basePath = path__default.default.resolve(cli$1.input[0] || process.cwd());
65
- const {
66
- exists,
67
- isRoot
68
- } = await _package.hasSanityJson(basePath);
69
- if (exists && isRoot) {
70
- throw new Error("sanity.json has a \"root\" property set to true - are you trying to init into a studio instead of a plugin?");
71
- }
72
- const {
73
- v3ConfigFile
74
- } = await _package.findStudioV3Config(basePath);
75
- if (v3ConfigFile) {
76
- throw new Error("".concat(v3ConfigFile, " exsists - are you trying to init into a studio instead of a plugin?"));
77
- }
78
- cli.log.info('Initializing new plugin in "%s"', basePath);
79
- if (!cli$1.flags.force && !(await _package.isEmptyish(basePath)) && !(await _package.prompt("Directory is not empty, proceed?", {
80
- type: "confirm",
81
- default: false
82
- }))) {
83
- cli.log.error("Directory is not empty. Cancelled.");
84
- return;
85
- }
86
- await _package.ensureDir(basePath);
87
- await init.init({
88
- basePath,
89
- flags: cli$1.flags
90
- });
91
- if (cli$1.flags.install) {
92
- if (await installDependencies(await promptForPackageManager(), {
93
- cwd: basePath
94
- })) {
95
- cli.log.info("Done!");
96
- } else {
97
- cli.log.error("Failed to install dependencies, try manually running `npm install`");
98
- }
99
- } else {
100
- cli.log.info("Dependency installation skipped.");
101
- }
102
- }
103
- exports.default = run;
104
- //# sourceMappingURL=init-RizSz7N7.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"init-RizSz7N7.js","sources":["../../src/npm/manager.ts","../../src/cmds/init.ts"],"sourcesContent":["import execa from 'execa'\nimport {prompt} from '../util/prompt'\n\nexport function npmIsAvailable() {\n return execa('npm', ['-v'])\n .then(() => true)\n .catch(() => false)\n}\n\nexport function yarnIsAvailable() {\n return execa('yarn', ['-v'])\n .then(() => true)\n .catch(() => false)\n}\n\nexport function pnpmAvailable() {\n return execa('pnpm', ['-v'])\n .then(() => true)\n .catch(() => false)\n}\n\nexport async function promptForPackageManager() {\n const [npm, yarn, pnpm] = await Promise.all([\n npmIsAvailable(),\n yarnIsAvailable(),\n pnpmAvailable(),\n ])\n\n const choices = [npm && 'npm', yarn && 'yarn', pnpm && 'pnpm'].filter(Boolean)\n if (choices.length < 2) {\n return choices[0] || 'npm'\n }\n\n return prompt('Which package manager do you prefer?', {\n choices: choices.map((value) => ({value, name: value})),\n default: choices[0],\n })\n}\n\nexport async function installDependencies(pm: string, {cwd}: {cwd?: string}) {\n const proc = execa(pm, ['install'], {cwd, stdio: 'inherit'})\n const {exitCode} = await proc\n return exitCode <= 0\n}\n","import path from 'path'\nimport meow from 'meow'\nimport log from '../util/log'\nimport {init, initFlags} from '../actions/init'\nimport {isEmptyish, ensureDir} from '../util/files'\nimport {installDependencies, promptForPackageManager} from '../npm/manager'\nimport {findStudioV3Config, hasSanityJson} from '../sanity/manifest'\nimport {prompt} from '../util/prompt'\nimport {cliName} from '../constants'\nimport {presetHelpList} from '../presets/presets'\n\nconst description = `Initialize a new Sanity plugin`\n\nconst help = `\nUsage\n $ ${cliName} init [dir] [<args>]\n\nOptions\n --no-eslint Disables ESLint config and dependencies from being added\n --no-prettier Disables prettier config and dependencies from being added\n --no-typescript Disables typescript config and dependencies from being added\n --no-license Disables LICENSE + package.json license field from being added\n --no-editorconfig Disables .editorconfig from being added\n --no-gitignore Disables .gitignore from being added\n --no-scripts Disables scripts from being added to package.json\n --no-install Disables automatically running package manager install\n\n --name [package-name] Use the provided package-name\n --author [name] Use the provided author\n --repo [url] Use the provided repo url\n --license [spdx] Use the license with the given SPDX identifier\n --force No promt when overwriting files\n\n --preset [preset-name] Adds config and files from a named preset. --preset can be supplied multiple times.\n The following presets are available:\n${presetHelpList(30)}\n\nExamples\n # Initialize a new plugin in the current directory\n $ ${cliName} init\n\n # Initialize a plugin in the directory ~/my-plugin\n $ ${cliName} init ~/my-plugin\n\n # Don't add eslint or prettier\n $ ${cliName} init --no-eslint --no-prettier\n`\n\nasync function run({argv}: {argv: string[]}) {\n const cli = meow(help, {flags: initFlags, argv, description})\n const basePath = path.resolve(cli.input[0] || process.cwd())\n\n const {exists, isRoot} = await hasSanityJson(basePath)\n if (exists && isRoot) {\n throw new Error(\n `sanity.json has a \"root\" property set to true - are you trying to init into a studio instead of a plugin?`,\n )\n }\n\n const {v3ConfigFile} = await findStudioV3Config(basePath)\n if (v3ConfigFile) {\n throw new Error(\n `${v3ConfigFile} exsists - are you trying to init into a studio instead of a plugin?`,\n )\n }\n\n log.info('Initializing new plugin in \"%s\"', basePath)\n if (\n !cli.flags.force &&\n !(await isEmptyish(basePath)) &&\n !(await prompt('Directory is not empty, proceed?', {type: 'confirm', default: false}))\n ) {\n log.error('Directory is not empty. Cancelled.')\n return\n }\n\n await ensureDir(basePath)\n await init({basePath, flags: cli.flags})\n if (cli.flags.install) {\n if (await installDependencies(await promptForPackageManager(), {cwd: basePath})) {\n log.info('Done!')\n } else {\n log.error('Failed to install dependencies, try manually running `npm install`')\n }\n } else {\n log.info('Dependency installation skipped.')\n }\n}\n\nexport default run\n"],"names":["npmIsAvailable","execa","then","catch","yarnIsAvailable","pnpmAvailable","promptForPackageManager","npm","yarn","pnpm","Promise","all","choices","filter","Boolean","length","prompt","map","value","name","default","installDependencies","pm","_ref","cwd","proc","stdio","exitCode","description","help","concat","cliName","presetHelpList","run","_ref2","argv","cli","meow","flags","initFlags","basePath","path","resolve","input","process","exists","isRoot","hasSanityJson","Error","v3ConfigFile","findStudioV3Config","log","info","force","isEmptyish","type","error","ensureDir","init","install"],"mappings":";;;;;;;;;;;;;;;;AAGO,SAASA,cAAiBA,CAAA,EAAA;EAC/B,OAAOC,sBAAM,CAAA,KAAA,EAAO,CAAC,IAAI,CAAC,CAAA,CACvBC,IAAK,CAAA,MAAM,IAAI,CAAA,CACfC,KAAM,CAAA,MAAM,KAAK,CAAA;AACtB;AAEO,SAASC,eAAkBA,CAAA,EAAA;EAChC,OAAOH,sBAAM,CAAA,MAAA,EAAQ,CAAC,IAAI,CAAC,CAAA,CACxBC,IAAK,CAAA,MAAM,IAAI,CAAA,CACfC,KAAM,CAAA,MAAM,KAAK,CAAA;AACtB;AAEO,SAASE,aAAgBA,CAAA,EAAA;EAC9B,OAAOJ,sBAAM,CAAA,MAAA,EAAQ,CAAC,IAAI,CAAC,CAAA,CACxBC,IAAK,CAAA,MAAM,IAAI,CAAA,CACfC,KAAM,CAAA,MAAM,KAAK,CAAA;AACtB;AAEA,eAAsBG,uBAA0BA,CAAA,EAAA;EAC9C,MAAM,CAACC,GAAK,EAAAC,IAAA,EAAMC,IAAI,CAAI,GAAA,MAAMC,QAAQC,GAAI,CAAA,CAC1CX,cAAe,CAAA,CAAA,EACfI,eAAgB,CAAA,CAAA,EAChBC,aAAc,CAAA,CAAA,CACf,CAAA;EAEK,MAAAO,OAAA,GAAU,CAACL,GAAA,IAAO,KAAO,EAAAC,IAAA,IAAQ,QAAQC,IAAQ,IAAA,MAAM,CAAE,CAAAI,MAAA,CAAOC,OAAO,CAAA;EACzE,IAAAF,OAAA,CAAQG,SAAS,CAAG,EAAA;IACf,OAAAH,OAAA,CAAQ,CAAC,CAAK,IAAA,KAAA;EACvB;EAEA,OAAOI,QAAAA,CAAAA,OAAO,sCAAwC,EAAA;IACpDJ,OAAA,EAASA,QAAQK,GAAI,CAACC,UAA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