@sanity/plugin-kit 4.0.20 → 5.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 (104) hide show
  1. package/assets/inject/semver-workflow/.husky/commit-msg +0 -0
  2. package/assets/inject/semver-workflow/.husky/pre-commit +0 -0
  3. package/assets/inject/ui-workshop/src/__workshop__/props.tsx +2 -1
  4. package/bin/plugin-kit.js +3 -1
  5. package/dist/{_chunks-cjs/cli.js → _chunks-es/index.js} +53 -63
  6. package/dist/_chunks-es/index.js.map +1 -0
  7. package/dist/{_chunks-cjs/init2.js → _chunks-es/init.js} +25 -23
  8. package/dist/_chunks-es/init.js.map +1 -0
  9. package/dist/_chunks-es/init2.js +140 -0
  10. package/dist/_chunks-es/init2.js.map +1 -0
  11. package/{src/cmds/inject.ts → dist/_chunks-es/inject.js} +18 -32
  12. package/dist/{_chunks-cjs → _chunks-es}/inject.js.map +1 -1
  13. package/dist/_chunks-es/link-watch.js +91 -0
  14. package/dist/_chunks-es/link-watch.js.map +1 -0
  15. package/dist/_chunks-es/load-package-config.js +22 -0
  16. package/dist/_chunks-es/load-package-config.js.map +1 -0
  17. package/dist/_chunks-es/package.js +1759 -0
  18. package/dist/_chunks-es/package.js.map +1 -0
  19. package/dist/_chunks-es/package2.js +9 -0
  20. package/dist/{_chunks-cjs → _chunks-es}/package2.js.map +1 -1
  21. package/dist/_chunks-es/ts.js +171 -0
  22. package/dist/_chunks-es/ts.js.map +1 -0
  23. package/dist/_chunks-es/verify-package.js +92 -0
  24. package/dist/_chunks-es/verify-package.js.map +1 -0
  25. package/dist/_chunks-es/verify-studio.js +61 -0
  26. package/dist/_chunks-es/verify-studio.js.map +1 -0
  27. package/dist/_chunks-es/version.js +50 -0
  28. package/dist/_chunks-es/version.js.map +1 -0
  29. package/dist/index.d.ts +4 -1
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +4 -1
  32. package/dist/index.js.map +1 -1
  33. package/package.json +40 -98
  34. package/LICENSE +0 -21
  35. package/dist/_chunks-cjs/cli.js.map +0 -1
  36. package/dist/_chunks-cjs/init.js +0 -892
  37. package/dist/_chunks-cjs/init.js.map +0 -1
  38. package/dist/_chunks-cjs/init2.js.map +0 -1
  39. package/dist/_chunks-cjs/inject.js +0 -54
  40. package/dist/_chunks-cjs/link-watch.js +0 -84
  41. package/dist/_chunks-cjs/link-watch.js.map +0 -1
  42. package/dist/_chunks-cjs/package.js +0 -1809
  43. package/dist/_chunks-cjs/package.js.map +0 -1
  44. package/dist/_chunks-cjs/package2.js +0 -8
  45. package/dist/_chunks-cjs/ts.js +0 -160732
  46. package/dist/_chunks-cjs/ts.js.map +0 -1
  47. package/dist/_chunks-cjs/verify-package.js +0 -75
  48. package/dist/_chunks-cjs/verify-package.js.map +0 -1
  49. package/dist/_chunks-cjs/verify-studio.js +0 -57
  50. package/dist/_chunks-cjs/verify-studio.js.map +0 -1
  51. package/dist/_chunks-cjs/version.js +0 -51
  52. package/dist/_chunks-cjs/version.js.map +0 -1
  53. package/dist/cli.d.ts +0 -4
  54. package/dist/cli.js +0 -6
  55. package/dist/cli.js.map +0 -1
  56. package/src/actions/init.ts +0 -95
  57. package/src/actions/inject.ts +0 -399
  58. package/src/actions/link-watch.ts +0 -98
  59. package/src/actions/verify/types.ts +0 -56
  60. package/src/actions/verify/validations.ts +0 -505
  61. package/src/actions/verify/verify-common.ts +0 -93
  62. package/src/actions/verify-package.ts +0 -103
  63. package/src/actions/verify-studio.ts +0 -58
  64. package/src/cli.ts +0 -77
  65. package/src/cmds/index.ts +0 -20
  66. package/src/cmds/init.ts +0 -90
  67. package/src/cmds/link-watch.ts +0 -50
  68. package/src/cmds/verify-package.ts +0 -36
  69. package/src/cmds/verify-studio.ts +0 -36
  70. package/src/cmds/version.ts +0 -67
  71. package/src/configs/banned-packages.ts +0 -27
  72. package/src/configs/buildExtensions.ts +0 -1
  73. package/src/configs/default-source.ts +0 -64
  74. package/src/configs/eslint.ts +0 -51
  75. package/src/configs/forced-package-versions.ts +0 -12
  76. package/src/configs/git.ts +0 -68
  77. package/src/configs/pkg-config.ts +0 -30
  78. package/src/configs/prettier.ts +0 -11
  79. package/src/configs/tsconfig.ts +0 -78
  80. package/src/configs/uselessFiles.ts +0 -29
  81. package/src/constants.ts +0 -15
  82. package/src/dependencies/find.ts +0 -193
  83. package/src/dependencies/import-linter.ts +0 -95
  84. package/src/index.ts +0 -1
  85. package/src/npm/manager.ts +0 -44
  86. package/src/npm/package.ts +0 -427
  87. package/src/npm/publish.ts +0 -9
  88. package/src/npm/resolveLatestVersions.ts +0 -31
  89. package/src/presets/presets.ts +0 -54
  90. package/src/presets/renovatebot.ts +0 -21
  91. package/src/presets/semver-workflow.ts +0 -186
  92. package/src/presets/ui-workshop.ts +0 -97
  93. package/src/presets/ui.ts +0 -67
  94. package/src/sanity/manifest.ts +0 -340
  95. package/src/sharedFlags.ts +0 -14
  96. package/src/util/command-parser.ts +0 -36
  97. package/src/util/errorToUndefined.ts +0 -7
  98. package/src/util/files.ts +0 -260
  99. package/src/util/log.ts +0 -44
  100. package/src/util/prompt.ts +0 -70
  101. package/src/util/readme.ts +0 -88
  102. package/src/util/request.ts +0 -11
  103. package/src/util/ts.ts +0 -19
  104. package/src/util/user.ts +0 -129
@@ -1,30 +0,0 @@
1
- import {outdent} from 'outdent'
2
- import {InjectTemplate} from '../actions/inject'
3
- import {InitFlags} from '../actions/init'
4
-
5
- export function pkgConfigTemplate(options: {outDir: string; flags: InitFlags}): InjectTemplate {
6
- const {flags, outDir} = options
7
-
8
- return {
9
- type: 'template',
10
- force: flags.force,
11
- to: flags.typescript ? 'package.config.ts' : 'package.config.js',
12
- value: outdent`
13
- import {defineConfig} from '@sanity/pkg-utils'
14
-
15
- export default defineConfig({
16
- dist: '${outDir}',
17
- tsconfig: 'tsconfig.${outDir}.json',
18
-
19
- // Remove this block to enable strict export validation
20
- extract: {
21
- rules: {
22
- 'ae-incompatible-release-tags': 'off',
23
- 'ae-internal-missing-underscore': 'off',
24
- 'ae-missing-release-tag': 'off',
25
- },
26
- },
27
- })
28
- `,
29
- }
30
- }
@@ -1,11 +0,0 @@
1
- import {InjectTemplate} from '../actions/inject'
2
-
3
- export function prettierignoreTemplate(options: {outDir: string}): InjectTemplate {
4
- const {outDir} = options
5
-
6
- return {
7
- type: 'template',
8
- to: '.prettierignore',
9
- value: [outDir, 'pnpm-lock.yaml', 'yarn.lock', 'package-lock.json'].join('\n'),
10
- }
11
- }
@@ -1,78 +0,0 @@
1
- import {outdent} from 'outdent'
2
- import {InjectTemplate} from '../actions/inject'
3
- import {InitFlags} from '../actions/init'
4
-
5
- export function tsconfigTemplate(options: {flags: InitFlags}): InjectTemplate {
6
- const {flags} = options
7
-
8
- return {
9
- type: 'template',
10
- force: flags.force,
11
- to: 'tsconfig.json',
12
- value: outdent`
13
- {
14
- "extends": "./tsconfig.settings",
15
- "include": ["./src", "./package.config.ts"]
16
- }
17
- `,
18
- }
19
- }
20
-
21
- export function tsconfigTemplateDist(options: {outDir: string; flags: InitFlags}): InjectTemplate {
22
- const {flags, outDir} = options
23
-
24
- return {
25
- type: 'template',
26
- force: flags.force,
27
- to: `tsconfig.${outDir}.json`,
28
- value: outdent`
29
- {
30
- "extends": "./tsconfig.settings",
31
- "include": ["./src"],
32
- "exclude": [
33
- "./src/**/__fixtures__",
34
- "./src/**/__mocks__",
35
- "./src/**/*.test.ts",
36
- "./src/**/*.test.tsx"
37
- ]
38
- }
39
- `,
40
- }
41
- }
42
-
43
- export function tsconfigTemplateSettings(options: {
44
- outDir: string
45
- flags: InitFlags
46
- }): InjectTemplate {
47
- const {flags, outDir} = options
48
-
49
- return {
50
- type: 'template',
51
- force: flags.force,
52
- to: `tsconfig.settings.json`,
53
- value: outdent`
54
- {
55
- "compilerOptions": {
56
- "rootDir": ".",
57
- "outDir": "./${outDir}",
58
-
59
- "target": "esnext",
60
- "jsx": "preserve",
61
- "module": "preserve",
62
- "moduleResolution": "bundler",
63
- "esModuleInterop": true,
64
- "resolveJsonModule": true,
65
- "moduleDetection": "force",
66
- "strict": true,
67
- "allowSyntheticDefaultImports": true,
68
- "skipLibCheck": 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
74
- }
75
- }
76
- `,
77
- }
78
- }
@@ -1,29 +0,0 @@
1
- export const uselessFiles = [
2
- '.babel.config.js',
3
- '.babelrc',
4
- '.drone.yml',
5
- '.editorconfig',
6
- '.eslintignore',
7
- '.eslintrc-ts.js',
8
- '.eslintrc-ts',
9
- '.eslintrc',
10
- '.gitignore',
11
- '.github',
12
- '.nyc_output',
13
- '.prettierrc',
14
- '.stylelintignore',
15
- '.stylelintrc.json',
16
- '.stylelintrc',
17
- '.travis.yaml',
18
- '.travis.yml',
19
- 'babel.config.js',
20
- 'coverage',
21
- 'gulpfile.js',
22
- 'lcov-report',
23
- 'lerna.json',
24
- 'now.json',
25
- 'vercel.json',
26
- 'netlify.toml',
27
- 'postcss.config.js',
28
- 'tsconfig.json',
29
- ]
package/src/constants.ts DELETED
@@ -1,15 +0,0 @@
1
- export const cliName = '@sanity/plugin-kit'
2
-
3
- export const urls = {
4
- refDocs: 'https://beta.sanity.io/docs/reference',
5
- migrationGuideStudio: 'https://beta.sanity.io/docs/platform/v2-to-v3',
6
- migrationGuidePlugin: 'https://beta.sanity.io/docs/platform/v2-to-v3/plugins',
7
- pluginReadme: 'https://github.com/sanity-io/plugin-kit',
8
- incompatiblePlugin: 'https://github.com/sanity-io/incompatible-plugin',
9
- sanityExchange: 'https://www.sanity.io/exchange',
10
- linterPackage: 'https://github.com/sanity-io/eslint-config-no-v2-imports',
11
- }
12
-
13
- export const incompatiblePluginPackage = '@sanity/incompatible-plugin'
14
-
15
- export const defaultOutDir = 'dist'
@@ -1,193 +0,0 @@
1
- /*
2
- import fs from 'fs'
3
- import path from 'path'
4
- import postcss from 'postcss'
5
- import {discoverPathSync} from 'discover-path'
6
- import traverse from '@babel/traverse'
7
- import {parseSync} from '@babel/core'
8
-
9
- export default {findDependencies}
10
-
11
- const partReg = /^(all:part|part|config|sanity):/
12
- const importReg = /^(?:"([^"]+)"|'([^']+)')$/
13
- const composesReg = /^(.+?)\s+from\s+(?:"([^"]+)"|'([^']+)'|(global))$/
14
-
15
- function findDependenciesFromFiles(files, seen = new Set<string>()): string[] {
16
- const dependencies = new Set<string>()
17
- files.forEach((file) => findDependencies(file, seen).forEach((dep) => dependencies.add(dep)))
18
- return Array.from(dependencies)
19
- }
20
-
21
- function findDependenciesInCss(css, entryPath, processDependency) {
22
- let ast
23
- try {
24
- ast = postcss.parse(css)
25
- } catch (err: any) {
26
- throw new Error(`Error parsing file (${entryPath}): ${err.message}`)
27
- }
28
-
29
- ast.walkDecls(/^composes/, (decl) => {
30
- const matches = decl.value.match(composesReg)
31
- if (!matches) {
32
- return
33
- }
34
-
35
- const [, , doubleQuotePath, singleQuotePath] = matches
36
- const importPath = doubleQuotePath || singleQuotePath
37
- if (importPath) {
38
- processDependency(importPath)
39
- }
40
- })
41
-
42
- ast.walkAtRules('import', (rule) => {
43
- const matches = rule.params.match(importReg)
44
- if (!matches) {
45
- return
46
- }
47
-
48
- const [, doubleQuotePath, singleQuotePath] = matches
49
- const importPath = doubleQuotePath || singleQuotePath
50
- if (importPath) {
51
- processDependency(importPath)
52
- }
53
- })
54
- }
55
-
56
- interface Traverse {
57
- node: {callee: {name: string}; source: {value: string}; arguments: {value: string}[]}
58
- }
59
-
60
- function findDependenciesInJs(
61
- js: string,
62
- entryPath: string,
63
- processDependency: (val: string) => void
64
- ) {
65
- let ast
66
- try {
67
- ast = parseSync(js, {babelrc: false})
68
- } catch (err: any) {
69
- throw new Error(`Error parsing file (${entryPath}): ${err.message}`)
70
- }
71
-
72
- traverse(ast, {
73
- ImportDeclaration({node}: Traverse) {
74
- processDependency(node.source.value)
75
- },
76
-
77
- CallExpression({node}: Traverse) {
78
- if (node.callee.name === 'require') {
79
- processDependency(node.arguments[0].value)
80
- }
81
- },
82
- })
83
- }
84
-
85
- export function findDependencies(entryPath: string, seen = new Set<string>()): string[] {
86
- if (Array.isArray(entryPath)) {
87
- return findDependenciesFromFiles(entryPath, seen)
88
- }
89
-
90
- seen.add(entryPath)
91
-
92
- let content
93
- try {
94
- content = fs.readFileSync(entryPath, 'utf8')
95
- } catch (err: any) {
96
- throw new Error(`Error reading file (${entryPath}): ${err.message}`)
97
- }
98
-
99
- const dir = path.dirname(entryPath)
100
- const dependencies = new Set<string>()
101
-
102
- if (entryPath.endsWith('.css')) {
103
- findDependenciesInCss(content, entryPath, processDependency)
104
- } else {
105
- findDependenciesInJs(content, entryPath, processDependency)
106
- }
107
-
108
- function processDependency(requirePath: string) {
109
- if (typeof requirePath !== 'string') {
110
- return
111
- }
112
-
113
- // Don't allow absolute requires
114
- if (path.isAbsolute(requirePath)) {
115
- throw new Error(
116
- `Absolute paths cannot be used in require/import statements: ${entryPath} references path "${requirePath}"`
117
- )
118
- }
119
-
120
- const isRelative = requirePath.startsWith('.')
121
- const depPath = isRelative && resolveDependency(dir, requirePath, entryPath)
122
-
123
- if (
124
- depPath &&
125
- ['.js', '.css', '.esm', '.mjs', '.jsx'].includes(path.extname(depPath)) &&
126
- !seen.has(depPath)
127
- ) {
128
- // For relative javascript/css requires, recurse to find all depdendencies
129
- findDependencies(depPath, seen).forEach((dep) => dependencies.add(dep))
130
- return
131
- }
132
-
133
- if (isRelative) {
134
- // Not JS? Skip it
135
- return
136
- }
137
-
138
- // For parts, we want the entire path, as we might want to validate them
139
- if (partReg.test(requirePath)) {
140
- dependencies.add(requirePath)
141
- return
142
- }
143
-
144
- // For modules, resolve the base module name, then add them
145
- // eg: `codemirror/mode/javascript` => `codemirror`
146
- // eg: `@sanity/base/foo/bar.js` => `@sanity/base`
147
- const dep = requirePath.startsWith('@')
148
- ? requirePath.replace(/^(@[^/]+\/[^/]+)(\/.*|$)/, '$1')
149
- : requirePath.replace(/^([^/]+)(\/.*|$)/, '$1')
150
-
151
- dependencies.add(dep)
152
- }
153
-
154
- return Array.from(dependencies)
155
- }
156
-
157
- function resolveDependency(fromDir: string, toPath: string, entryPath: string) {
158
- const [querylessPath] = toPath.split('?', 1)
159
-
160
- let depPath
161
- try {
162
- depPath = require.resolve(path.resolve(fromDir, querylessPath))
163
- } catch (err) {
164
- throw new Error(`Unable to resolve "${querylessPath}" from ${entryPath}`)
165
- }
166
-
167
- let actualPath
168
- try {
169
- actualPath = discoverPathSync(depPath)
170
- } catch (err: any) {
171
- const paths = (err.suggestions || []).map((suggested: string) =>
172
- getDidYouMeanPath(querylessPath, suggested)
173
- )
174
- const didYouMean = paths ? `Did you mean:\n${paths.join('\n- ')}` : ''
175
- throw new Error(`Unable to resolve "${querylessPath}" from ${entryPath}. ${didYouMean}`)
176
- }
177
-
178
- if (actualPath !== depPath) {
179
- const didYouMean = getDidYouMeanPath(querylessPath, actualPath)
180
- throw new Error(
181
- `Unable to resolve "${querylessPath} from ${entryPath}. Did you mean "${didYouMean}"?`
182
- )
183
- }
184
-
185
- return actualPath
186
- }
187
-
188
- function getDidYouMeanPath(wanted: string, suggested: string) {
189
- const end = wanted.replace(/[./]+/, '')
190
- const start = wanted.slice(0, 0 - end.length)
191
- return `${start}${suggested.slice(0 - end.length)}`
192
- }
193
- */
@@ -1,95 +0,0 @@
1
- import log from '../util/log'
2
- import {mergedPackages} from '../configs/banned-packages'
3
- import {urls} from '../constants'
4
- import {ESLint} from 'eslint'
5
- import path from 'path'
6
- import outdent from 'outdent'
7
-
8
- const removedImportSuffix = `imports where removed in Sanity v3. Please refer to the migration guide: ${urls.migrationGuideStudio}, or new API-reference docs: ${urls.refDocs}`
9
-
10
- export async function validateImports({basePath}: {basePath: string}): Promise<string[]> {
11
- log.debug('Running ESLint with Sanity Studio import hints...')
12
- const eslint = new ESLint({
13
- cwd: basePath,
14
- overrideConfig: {
15
- ignorePatterns: ['node_modules'],
16
- rules: {
17
- 'no-restricted-imports': [
18
- 'error',
19
- {
20
- patterns: [
21
- ...mergedPackages.map((packageName) => ({
22
- group: [`${packageName}*`],
23
- message: `Use sanity instead of ${packageName}.`,
24
- })),
25
- {
26
- group: ['config:*'],
27
- message: `config: imports are no longer supported. Please see the new plugin API for alternatives: ${urls.migrationGuideStudio}`,
28
- },
29
- {
30
- group: ['part:*'],
31
- message: `part: ${removedImportSuffix}`,
32
- },
33
- {
34
- group: ['all:part:*'],
35
- message: `all:part: ${removedImportSuffix}`,
36
- },
37
- {
38
- group: ['sanity:*'],
39
- message: `sanity: ${removedImportSuffix}`,
40
- },
41
- ],
42
- },
43
- ],
44
- },
45
- },
46
- })
47
-
48
- try {
49
- const results = await eslint.lintFiles([path.join(basePath, '**/*.{js,jsx,ts,tsx}')])
50
-
51
- const onlyImportErrors = results
52
- .map((r) => {
53
- const limitErrors = r.messages.filter((m) => m.ruleId === 'no-restricted-imports')
54
- return {
55
- ...r,
56
- messages: limitErrors,
57
- errorCount: limitErrors.length,
58
- }
59
- })
60
- .filter((r) => r.errorCount)
61
-
62
- if (onlyImportErrors.length) {
63
- const formatter = await eslint.loadFormatter('stylish')
64
- const resultText = await formatter.format(onlyImportErrors)
65
-
66
- const addtionalInfo = outdent`
67
- ESLint detected Studio V2 imports that are no longer available.
68
- It is recommended configure @sanity/eslint-config-no-v2-imports for ESLint.
69
-
70
- Run:
71
- npm install --save-dev @sanity/eslint-config-no-v2-imports
72
-
73
- In .eslintrc add:
74
- "extends": ["@sanity/no-v2-imports"]
75
-
76
- This way, V2-imports can be identified directly in the IDE, or using eslint CLI.
77
- For more, see ${urls.linterPackage}
78
-
79
- If the plugin package does not use eslint, disable this check.
80
- `
81
- return [resultText + addtionalInfo]
82
- }
83
- } catch (e) {
84
- log.error('Failed to run eslint check', e)
85
- return [
86
- outdent`
87
- Failed to run ESLint. Is ESLint configured?
88
-
89
- If the package does not use eslint, disable this check.
90
- `,
91
- ]
92
- }
93
-
94
- return []
95
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export {}
@@ -1,44 +0,0 @@
1
- import execa from 'execa'
2
- import {prompt} from '../util/prompt'
3
-
4
- export function npmIsAvailable() {
5
- return execa('npm', ['-v'])
6
- .then(() => true)
7
- .catch(() => false)
8
- }
9
-
10
- export function yarnIsAvailable() {
11
- return execa('yarn', ['-v'])
12
- .then(() => true)
13
- .catch(() => false)
14
- }
15
-
16
- export function pnpmAvailable() {
17
- return execa('pnpm', ['-v'])
18
- .then(() => true)
19
- .catch(() => false)
20
- }
21
-
22
- export async function promptForPackageManager() {
23
- const [npm, yarn, pnpm] = await Promise.all([
24
- npmIsAvailable(),
25
- yarnIsAvailable(),
26
- pnpmAvailable(),
27
- ])
28
-
29
- const choices = [npm && 'npm', yarn && 'yarn', pnpm && 'pnpm'].filter(Boolean)
30
- if (choices.length < 2) {
31
- return choices[0] || 'npm'
32
- }
33
-
34
- return prompt('Which package manager do you prefer?', {
35
- choices: choices.map((value) => ({value, name: value})),
36
- default: choices[0],
37
- })
38
- }
39
-
40
- export async function installDependencies(pm: string, {cwd}: {cwd?: string}) {
41
- const proc = execa(pm, ['install'], {cwd, stdio: 'inherit'})
42
- const {exitCode} = await proc
43
- return exitCode <= 0
44
- }