@sanity/plugin-kit 2.2.0 → 3.1.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.
- package/LICENSE +1 -1
- package/README.md +53 -38
- package/assets/inject/semver-workflow/lint-staged.template.js +1 -1
- package/bin/plugin-kit.js +2 -0
- package/dist/_chunks/cli-dbe00b65.js +162 -0
- package/dist/_chunks/cli-dbe00b65.js.map +1 -0
- package/dist/_chunks/init-2a3b4528.js +104 -0
- package/dist/_chunks/init-2a3b4528.js.map +1 -0
- package/dist/_chunks/init-7cd30f64.js +952 -0
- package/dist/_chunks/init-7cd30f64.js.map +1 -0
- package/dist/_chunks/inject-f8928379.js +49 -0
- package/dist/_chunks/inject-f8928379.js.map +1 -0
- package/dist/_chunks/link-watch-9e3f1174.js +94 -0
- package/dist/_chunks/link-watch-9e3f1174.js.map +1 -0
- package/dist/_chunks/package-bdb22a22.js +2314 -0
- package/dist/_chunks/package-bdb22a22.js.map +1 -0
- package/dist/_chunks/package-f79f12a7.js +152 -0
- package/dist/_chunks/package-f79f12a7.js.map +1 -0
- package/dist/_chunks/ts-5747e004.js +167 -0
- package/dist/_chunks/ts-5747e004.js.map +1 -0
- package/dist/_chunks/verify-package-73b843df.js +98 -0
- package/dist/_chunks/verify-package-73b843df.js.map +1 -0
- package/dist/_chunks/verify-studio-5e333969.js +75 -0
- package/dist/_chunks/verify-studio-5e333969.js.map +1 -0
- package/dist/_chunks/version-f89917d7.js +58 -0
- package/dist/_chunks/version-f89917d7.js.map +1 -0
- package/dist/cli.js +9 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +29 -17
- package/src/actions/init.ts +2 -0
- package/src/actions/inject.ts +66 -87
- package/src/actions/link-watch.ts +8 -5
- package/src/actions/verify/types.ts +0 -23
- package/src/actions/verify/validations.ts +142 -39
- package/src/actions/verify/verify-common.ts +5 -4
- package/src/actions/verify-package.ts +21 -7
- package/src/actions/verify-studio.ts +7 -4
- package/src/cli.ts +1 -3
- package/src/cmds/index.ts +18 -6
- package/src/cmds/inject.ts +5 -2
- package/src/cmds/link-watch.ts +0 -1
- package/src/configs/default-source.ts +10 -14
- package/src/configs/eslint.ts +51 -0
- package/src/configs/forced-package-versions.ts +8 -7
- package/src/configs/git.ts +68 -0
- package/src/configs/pkg-config.ts +31 -0
- package/src/configs/prettier.ts +11 -0
- package/src/configs/tsconfig.ts +79 -0
- package/src/configs/uselessFiles.ts +1 -1
- package/src/constants.ts +2 -0
- package/src/index.ts +1 -4
- package/src/npm/package.ts +62 -26
- package/src/presets/presets.ts +2 -1
- package/src/presets/renovatebot.ts +10 -1
- package/src/presets/semver-workflow.ts +26 -14
- package/src/presets/ui-workshop.ts +28 -12
- package/src/presets/ui.ts +68 -0
- package/src/sanity/manifest.ts +2 -2
- package/src/util/files.ts +8 -8
- package/src/util/readme.ts +17 -15
- package/src/util/ts.ts +13 -0
- package/assets/inject/gitignore +0 -57
- package/assets/inject/package.config.template +0 -16
- package/assets/inject/template-tsconfig.json +0 -24
- package/lib/package.json +0 -129
- package/lib/src/actions/init.d.ts +0 -73
- package/lib/src/actions/init.js +0 -79
- package/lib/src/actions/init.js.map +0 -1
- package/lib/src/actions/inject.d.ts +0 -31
- package/lib/src/actions/inject.js +0 -350
- package/lib/src/actions/inject.js.map +0 -1
- package/lib/src/actions/link-watch.d.ts +0 -3
- package/lib/src/actions/link-watch.js +0 -87
- package/lib/src/actions/link-watch.js.map +0 -1
- package/lib/src/actions/verify/types.d.ts +0 -75
- package/lib/src/actions/verify/types.js +0 -3
- package/lib/src/actions/verify/types.js.map +0 -1
- package/lib/src/actions/verify/validations.d.ts +0 -27
- package/lib/src/actions/verify/validations.js +0 -410
- package/lib/src/actions/verify/validations.js.map +0 -1
- package/lib/src/actions/verify/verify-common.d.ts +0 -44
- package/lib/src/actions/verify/verify-common.js +0 -89
- package/lib/src/actions/verify/verify-common.js.map +0 -1
- package/lib/src/actions/verify-package.d.ts +0 -5
- package/lib/src/actions/verify-package.js +0 -73
- package/lib/src/actions/verify-package.js.map +0 -1
- package/lib/src/actions/verify-studio.d.ts +0 -5
- package/lib/src/actions/verify-studio.js +0 -55
- package/lib/src/actions/verify-studio.js.map +0 -1
- package/lib/src/cli.d.ts +0 -2
- package/lib/src/cli.js +0 -87
- package/lib/src/cli.js.map +0 -1
- package/lib/src/cmds/index.d.ts +0 -9
- package/lib/src/cmds/index.js +0 -11
- package/lib/src/cmds/index.js.map +0 -1
- package/lib/src/cmds/init.d.ts +0 -4
- package/lib/src/cmds/init.js +0 -95
- package/lib/src/cmds/init.js.map +0 -1
- package/lib/src/cmds/inject.d.ts +0 -4
- package/lib/src/cmds/inject.js +0 -76
- package/lib/src/cmds/inject.js.map +0 -1
- package/lib/src/cmds/link-watch.d.ts +0 -4
- package/lib/src/cmds/link-watch.js +0 -49
- package/lib/src/cmds/link-watch.js.map +0 -1
- package/lib/src/cmds/verify-package.d.ts +0 -4
- package/lib/src/cmds/verify-package.js +0 -38
- package/lib/src/cmds/verify-package.js.map +0 -1
- package/lib/src/cmds/verify-studio.d.ts +0 -4
- package/lib/src/cmds/verify-studio.js +0 -38
- package/lib/src/cmds/verify-studio.js.map +0 -1
- package/lib/src/cmds/verify.d.ts +0 -0
- package/lib/src/cmds/verify.js +0 -42
- package/lib/src/cmds/verify.js.map +0 -1
- package/lib/src/cmds/version.d.ts +0 -4
- package/lib/src/cmds/version.js +0 -55
- package/lib/src/cmds/version.js.map +0 -1
- package/lib/src/configs/banned-packages.d.ts +0 -2
- package/lib/src/configs/banned-packages.js +0 -30
- package/lib/src/configs/banned-packages.js.map +0 -1
- package/lib/src/configs/buildExtensions.d.ts +0 -1
- package/lib/src/configs/buildExtensions.js +0 -5
- package/lib/src/configs/buildExtensions.js.map +0 -1
- package/lib/src/configs/default-source.d.ts +0 -3
- package/lib/src/configs/default-source.js +0 -70
- package/lib/src/configs/default-source.js.map +0 -1
- package/lib/src/configs/forced-package-versions.d.ts +0 -16
- package/lib/src/configs/forced-package-versions.js +0 -14
- package/lib/src/configs/forced-package-versions.js.map +0 -1
- package/lib/src/configs/uselessFiles.d.ts +0 -1
- package/lib/src/configs/uselessFiles.js +0 -33
- package/lib/src/configs/uselessFiles.js.map +0 -1
- package/lib/src/constants.d.ts +0 -11
- package/lib/src/constants.js +0 -15
- package/lib/src/constants.js.map +0 -1
- package/lib/src/dependencies/find.d.ts +0 -0
- package/lib/src/dependencies/find.js +0 -195
- package/lib/src/dependencies/find.js.map +0 -1
- package/lib/src/dependencies/import-linter.d.ts +0 -3
- package/lib/src/dependencies/import-linter.js +0 -112
- package/lib/src/dependencies/import-linter.js.map +0 -1
- package/lib/src/index.d.ts +0 -2
- package/lib/src/index.js +0 -6
- package/lib/src/index.js.map +0 -1
- package/lib/src/npm/manager.d.ts +0 -7
- package/lib/src/npm/manager.js +0 -62
- package/lib/src/npm/manager.js.map +0 -1
- package/lib/src/npm/package.d.ts +0 -11
- package/lib/src/npm/package.js +0 -302
- package/lib/src/npm/package.js.map +0 -1
- package/lib/src/npm/publish.d.ts +0 -1
- package/lib/src/npm/publish.js +0 -14
- package/lib/src/npm/publish.js.map +0 -1
- package/lib/src/npm/resolveLatestVersions.d.ts +0 -3
- package/lib/src/npm/resolveLatestVersions.js +0 -37
- package/lib/src/npm/resolveLatestVersions.js.map +0 -1
- package/lib/src/presets/presets.d.ts +0 -8
- package/lib/src/presets/presets.js +0 -53
- package/lib/src/presets/presets.js.map +0 -1
- package/lib/src/presets/renovatebot.d.ts +0 -2
- package/lib/src/presets/renovatebot.js +0 -24
- package/lib/src/presets/renovatebot.js.map +0 -1
- package/lib/src/presets/semver-workflow.d.ts +0 -8
- package/lib/src/presets/semver-workflow.js +0 -166
- package/lib/src/presets/semver-workflow.js.map +0 -1
- package/lib/src/presets/ui-workshop.d.ts +0 -2
- package/lib/src/presets/ui-workshop.js +0 -88
- package/lib/src/presets/ui-workshop.js.map +0 -1
- package/lib/src/sanity/manifest.d.ts +0 -48
- package/lib/src/sanity/manifest.js +0 -263
- package/lib/src/sanity/manifest.js.map +0 -1
- package/lib/src/sharedFlags.d.ts +0 -15
- package/lib/src/sharedFlags.js +0 -17
- package/lib/src/sharedFlags.js.map +0 -1
- package/lib/src/util/command-parser.d.ts +0 -9
- package/lib/src/util/command-parser.js +0 -46
- package/lib/src/util/command-parser.js.map +0 -1
- package/lib/src/util/errorToUndefined.d.ts +0 -1
- package/lib/src/util/errorToUndefined.js +0 -11
- package/lib/src/util/errorToUndefined.js.map +0 -1
- package/lib/src/util/files.d.ts +0 -36
- package/lib/src/util/files.js +0 -264
- package/lib/src/util/files.js.map +0 -1
- package/lib/src/util/log.d.ts +0 -14
- package/lib/src/util/log.js +0 -36
- package/lib/src/util/log.js.map +0 -1
- package/lib/src/util/prompt.d.ts +0 -14
- package/lib/src/util/prompt.js +0 -75
- package/lib/src/util/prompt.js.map +0 -1
- package/lib/src/util/readme.d.ts +0 -8
- package/lib/src/util/readme.js +0 -92
- package/lib/src/util/readme.js.map +0 -1
- package/lib/src/util/request.d.ts +0 -1
- package/lib/src/util/request.js +0 -19
- package/lib/src/util/request.js.map +0 -1
- package/lib/src/util/user.d.ts +0 -13
- package/lib/src/util/user.js +0 -111
- package/lib/src/util/user.js.map +0 -1
- package/lib/test/cli.test.d.ts +0 -1
- package/lib/test/cli.test.js +0 -64
- package/lib/test/cli.test.js.map +0 -1
- package/lib/test/fixture-utils.d.ts +0 -25
- package/lib/test/fixture-utils.js +0 -67
- package/lib/test/fixture-utils.js.map +0 -1
- package/lib/test/init-verify-build.test.d.ts +0 -1
- package/lib/test/init-verify-build.test.js +0 -68
- package/lib/test/init-verify-build.test.js.map +0 -1
- package/lib/test/init.test.d.ts +0 -1
- package/lib/test/init.test.js +0 -169
- package/lib/test/init.test.js.map +0 -1
- package/lib/test/inject.test.d.ts +0 -1
- package/lib/test/inject.test.js +0 -75
- package/lib/test/inject.test.js.map +0 -1
- package/lib/test/run-test-command.d.ts +0 -1
- package/lib/test/run-test-command.js +0 -6
- package/lib/test/run-test-command.js.map +0 -1
- package/lib/test/semver-workflow.test.d.ts +0 -1
- package/lib/test/semver-workflow.test.js +0 -93
- package/lib/test/semver-workflow.test.js.map +0 -1
- package/lib/test/verify-package.test.d.ts +0 -1
- package/lib/test/verify-package.test.js +0 -87
- package/lib/test/verify-package.test.js.map +0 -1
- package/lib/test/version.test.d.ts +0 -1
- package/lib/test/version.test.js +0 -48
- package/lib/test/version.test.js.map +0 -1
- package/src/cmds/verify.ts +0 -40
package/src/actions/inject.ts
CHANGED
|
@@ -18,8 +18,12 @@ import {
|
|
|
18
18
|
} from '../util/files'
|
|
19
19
|
import {InitFlags} from './init'
|
|
20
20
|
import {PackageJson} from './verify/types'
|
|
21
|
-
import outdent from 'outdent'
|
|
22
21
|
import {injectPresets} from '../presets/presets'
|
|
22
|
+
import {tsconfigTemplateDist, tsconfigTemplate, tsconfigTemplateSettings} from '../configs/tsconfig'
|
|
23
|
+
import {pkgConfigTemplate} from '../configs/pkg-config'
|
|
24
|
+
import {gitignoreTemplate} from '../configs/git'
|
|
25
|
+
import {eslintignoreTemplate, eslintrcTemplate} from '../configs/eslint'
|
|
26
|
+
import {prettierignoreTemplate} from '../configs/prettier'
|
|
23
27
|
|
|
24
28
|
const bannedFields = ['login', 'description', 'projecturl', 'email']
|
|
25
29
|
const preferredLicenses = ['MIT', 'ISC', 'BSD-3-Clause']
|
|
@@ -31,7 +35,20 @@ const otherLicenses = Object.keys(licenses.list).filter((id) => {
|
|
|
31
35
|
)
|
|
32
36
|
})
|
|
33
37
|
|
|
34
|
-
export
|
|
38
|
+
export interface InjectCopyFromTo {
|
|
39
|
+
type: 'copy'
|
|
40
|
+
from: string | string[]
|
|
41
|
+
to: string | string[]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface InjectTemplate {
|
|
45
|
+
type: 'template'
|
|
46
|
+
to: string | string[]
|
|
47
|
+
value: string
|
|
48
|
+
force?: boolean
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type Injectable = InjectCopyFromTo | InjectTemplate
|
|
35
52
|
|
|
36
53
|
export interface InjectOptions {
|
|
37
54
|
basePath: string
|
|
@@ -41,6 +58,7 @@ export interface InjectOptions {
|
|
|
41
58
|
devDependencies?: Record<string, string>
|
|
42
59
|
peerDependencies?: Record<string, string>
|
|
43
60
|
validate?: boolean
|
|
61
|
+
outDir: string
|
|
44
62
|
}
|
|
45
63
|
|
|
46
64
|
export interface PackageData {
|
|
@@ -111,11 +129,6 @@ async function injectBase(options: InjectOptions) {
|
|
|
111
129
|
didWrite = await writeStaticAssets(options)
|
|
112
130
|
info(didWrite.length > 0, 'Wrote static asset files: %s', didWrite.join(', '))
|
|
113
131
|
|
|
114
|
-
didWrite = await writeEslintrc(options)
|
|
115
|
-
info(didWrite, 'Wrote .eslintrc.js')
|
|
116
|
-
didWrite = await writeEslintIgnore(options)
|
|
117
|
-
info(didWrite, 'Wrote .eslintignore')
|
|
118
|
-
|
|
119
132
|
didWrite = await addBuildScripts(newPkg, options)
|
|
120
133
|
info(didWrite, 'Added build scripts to package.json')
|
|
121
134
|
|
|
@@ -140,61 +153,6 @@ async function writeReadme(data: PackageData, options: InjectOptions) {
|
|
|
140
153
|
return true
|
|
141
154
|
}
|
|
142
155
|
|
|
143
|
-
async function writeEslintrc(options: InjectOptions) {
|
|
144
|
-
if (!options.flags.eslint) {
|
|
145
|
-
return false
|
|
146
|
-
}
|
|
147
|
-
const {basePath} = options
|
|
148
|
-
|
|
149
|
-
const eslintrc = path.join(basePath, '.eslintrc')
|
|
150
|
-
|
|
151
|
-
const config = {
|
|
152
|
-
root: true,
|
|
153
|
-
env: {
|
|
154
|
-
node: true,
|
|
155
|
-
browser: true,
|
|
156
|
-
},
|
|
157
|
-
extends: [
|
|
158
|
-
'sanity',
|
|
159
|
-
options.flags.typescript && 'sanity/typescript',
|
|
160
|
-
'sanity/react',
|
|
161
|
-
'plugin:react-hooks/recommended',
|
|
162
|
-
options.flags.prettier && 'plugin:prettier/recommended',
|
|
163
|
-
].filter(Boolean),
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const content = JSON.stringify(config, null, 2)
|
|
167
|
-
await writeFileWithOverwritePrompt(eslintrc, content, {
|
|
168
|
-
encoding: 'utf8',
|
|
169
|
-
force: options.flags.force,
|
|
170
|
-
})
|
|
171
|
-
return true
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
async function writeEslintIgnore(options: InjectOptions) {
|
|
175
|
-
if (!options.flags.eslint) {
|
|
176
|
-
return false
|
|
177
|
-
}
|
|
178
|
-
const {basePath} = options
|
|
179
|
-
|
|
180
|
-
const eslintignore = path.join(basePath, '.eslintignore')
|
|
181
|
-
|
|
182
|
-
const content = outdent`
|
|
183
|
-
.eslintrc.js
|
|
184
|
-
commitlint.config.js
|
|
185
|
-
lib
|
|
186
|
-
lint-staged.config.js
|
|
187
|
-
package.config.ts
|
|
188
|
-
${options.flags.typescript ? '*.js' : ''}
|
|
189
|
-
`.trim()
|
|
190
|
-
|
|
191
|
-
await writeFileWithOverwritePrompt(eslintignore, content, {
|
|
192
|
-
encoding: 'utf8',
|
|
193
|
-
force: options.flags.force,
|
|
194
|
-
})
|
|
195
|
-
return true
|
|
196
|
-
}
|
|
197
|
-
|
|
198
156
|
async function writeLicense(
|
|
199
157
|
{license}: PackageData,
|
|
200
158
|
options: InjectOptions,
|
|
@@ -323,43 +281,64 @@ async function resolveProjectDescription(basePath: string, pkg: PackageJson | un
|
|
|
323
281
|
}
|
|
324
282
|
}
|
|
325
283
|
|
|
326
|
-
export async function writeAssets(
|
|
284
|
+
export async function writeAssets(injectables: Injectable[], {basePath, flags}: InjectOptions) {
|
|
327
285
|
const assetsDir = await findAssetsDir()
|
|
328
286
|
|
|
329
287
|
const from = (...segments: string[]) => path.join(assetsDir, 'inject', ...segments)
|
|
330
288
|
const to = (...segments: string[]) => path.join(basePath, ...segments)
|
|
331
289
|
|
|
332
290
|
const writes: string[] = []
|
|
333
|
-
for (const
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
291
|
+
for (const injectable of injectables) {
|
|
292
|
+
if (injectable.type === 'copy') {
|
|
293
|
+
const fromPath = asArray(injectable.from)
|
|
294
|
+
const toPath = asArray(injectable.to)
|
|
295
|
+
if (await copyFileWithOverwritePrompt(from(...fromPath), to(...toPath), flags)) {
|
|
296
|
+
writes.push(path.join(...toPath))
|
|
297
|
+
}
|
|
298
|
+
continue
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (injectable.type === 'template') {
|
|
302
|
+
const toPath = asArray(injectable.to)
|
|
303
|
+
|
|
304
|
+
await writeFileWithOverwritePrompt(to(...toPath), `${injectable.value.trim()}\n`, {
|
|
305
|
+
default: 'n',
|
|
306
|
+
force: injectable.force || flags.force,
|
|
307
|
+
})
|
|
308
|
+
|
|
337
309
|
writes.push(path.join(...toPath))
|
|
310
|
+
continue
|
|
338
311
|
}
|
|
312
|
+
|
|
313
|
+
throw new Error(`Unknown operation type "${(injectable as any).type}"`)
|
|
339
314
|
}
|
|
340
315
|
|
|
341
316
|
return writes
|
|
342
317
|
}
|
|
343
318
|
|
|
344
319
|
async function writeStaticAssets(options: InjectOptions) {
|
|
345
|
-
const {flags} = options
|
|
346
|
-
|
|
347
|
-
const files:
|
|
348
|
-
|
|
349
|
-
{
|
|
350
|
-
{from: '
|
|
351
|
-
{
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
flags.
|
|
356
|
-
flags.typescript && {
|
|
357
|
-
flags.
|
|
320
|
+
const {outDir, flags} = options
|
|
321
|
+
|
|
322
|
+
const files: Injectable[] = [
|
|
323
|
+
flags.eslint && eslintrcTemplate({flags: options.flags}),
|
|
324
|
+
flags.eslint && eslintignoreTemplate({outDir, flags: options.flags}),
|
|
325
|
+
{type: 'copy', from: 'editorconfig', to: '.editorconfig'},
|
|
326
|
+
{type: 'copy', from: 'sanity.json', to: 'sanity.json'},
|
|
327
|
+
{type: 'copy', from: 'v2-incompatible.js.template', to: 'v2-incompatible.js'},
|
|
328
|
+
pkgConfigTemplate({outDir, flags: options.flags}),
|
|
329
|
+
flags.gitignore && gitignoreTemplate(),
|
|
330
|
+
flags.typescript && tsconfigTemplate({flags: options.flags}),
|
|
331
|
+
flags.typescript && tsconfigTemplateDist({outDir, flags: options.flags}),
|
|
332
|
+
flags.typescript && tsconfigTemplateSettings({flags: options.flags}),
|
|
333
|
+
flags.prettier && prettierignoreTemplate({outDir}),
|
|
334
|
+
flags.prettier && {type: 'copy', from: 'prettierrc.json', to: '.prettierrc'},
|
|
358
335
|
]
|
|
359
|
-
.map((f) => (f ? (f as
|
|
360
|
-
.filter((f): f is
|
|
336
|
+
.map((f) => (f ? (f as Injectable) : undefined))
|
|
337
|
+
.filter((f): f is Injectable => !!f)
|
|
338
|
+
|
|
339
|
+
const result = writeAssets(files, options)
|
|
361
340
|
|
|
362
|
-
return
|
|
341
|
+
return result
|
|
363
342
|
}
|
|
364
343
|
|
|
365
344
|
function asArray(input: string | string[]): string[] {
|
|
@@ -368,7 +347,7 @@ function asArray(input: string | string[]): string[] {
|
|
|
368
347
|
|
|
369
348
|
/**
|
|
370
349
|
* assets dir might be in higher or lower in the dir hierarchy depending on
|
|
371
|
-
* if we run from
|
|
350
|
+
* if we run from `dist` or `src`
|
|
372
351
|
*/
|
|
373
352
|
async function findAssetsDir(): Promise<string> {
|
|
374
353
|
let maxBackpaddle = 3
|
|
@@ -408,13 +387,13 @@ async function addCompileDirToGitIgnore(data: PackageData, options: InjectOption
|
|
|
408
387
|
return false
|
|
409
388
|
}
|
|
410
389
|
|
|
411
|
-
const lines = gitignore.split('\n')
|
|
390
|
+
const lines = gitignore.trim().split('\n')
|
|
412
391
|
if (lines.includes(ignore)) {
|
|
413
392
|
return false
|
|
414
393
|
}
|
|
415
394
|
|
|
416
|
-
lines.push('# Compiled plugin', ignore
|
|
395
|
+
lines.push('', '# Compiled plugin', ignore)
|
|
417
396
|
|
|
418
|
-
await writeFile(gitIgnorePath, lines.join('\n'), {encoding: 'utf8'})
|
|
397
|
+
await writeFile(gitIgnorePath, lines.join('\n') + '\n', {encoding: 'utf8'})
|
|
419
398
|
return true
|
|
420
399
|
}
|
|
@@ -26,9 +26,10 @@ import log from '../util/log'
|
|
|
26
26
|
import {getPackage} from '../npm/package'
|
|
27
27
|
import outdent from 'outdent'
|
|
28
28
|
import {fileExists, mkdir} from '../util/files'
|
|
29
|
+
import {loadConfig as loadPackageConfig} from '@sanity/pkg-utils'
|
|
30
|
+
import {defaultOutDir} from '../constants'
|
|
29
31
|
|
|
30
32
|
interface YalcWatchConfig {
|
|
31
|
-
folder?: string
|
|
32
33
|
command?: string
|
|
33
34
|
extensions?: string
|
|
34
35
|
}
|
|
@@ -42,22 +43,24 @@ export async function linkWatch({basePath}: {basePath: string}) {
|
|
|
42
43
|
fs.readFileSync(path.join(basePath, 'package.json'), 'utf8')
|
|
43
44
|
)
|
|
44
45
|
|
|
46
|
+
const packageConfig = await loadPackageConfig({cwd: basePath})
|
|
47
|
+
const outDir = packageConfig?.dist ?? defaultOutDir
|
|
48
|
+
|
|
45
49
|
const watch: Required<YalcWatchConfig> = {
|
|
46
|
-
folder: 'lib',
|
|
47
50
|
command: 'npm run watch',
|
|
48
51
|
extensions: 'ts,js,png,svg,gif,jpeg,css',
|
|
49
52
|
...packageJson.sanityPlugin?.linkWatch,
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
nodemon({
|
|
53
|
-
watch: [
|
|
56
|
+
watch: [outDir],
|
|
54
57
|
ext: watch.extensions,
|
|
55
58
|
exec: 'yalc push --changed',
|
|
56
59
|
//delay: 1000
|
|
57
60
|
})
|
|
58
61
|
|
|
59
62
|
// ensure the folder exits so it can be watched
|
|
60
|
-
const folder = path.join(basePath,
|
|
63
|
+
const folder = path.join(basePath, outDir)
|
|
61
64
|
if (!(await fileExists(folder))) {
|
|
62
65
|
await mkdir(folder)
|
|
63
66
|
}
|
|
@@ -70,7 +73,7 @@ export async function linkWatch({basePath}: {basePath: string}) {
|
|
|
70
73
|
.on('start', function () {
|
|
71
74
|
log.info(
|
|
72
75
|
outdent`
|
|
73
|
-
Watching ${
|
|
76
|
+
Watching ${outDir} for changes to files with extensions: ${watch.extensions}
|
|
74
77
|
|
|
75
78
|
To test this package in Sanity Studio or another package, in a separate shell run:
|
|
76
79
|
cd /path/to/sanity/studio-or-package
|
|
@@ -34,29 +34,6 @@ export interface PackageJson {
|
|
|
34
34
|
[index: string]: unknown
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export interface CompilerOptions {
|
|
38
|
-
jsx?: string
|
|
39
|
-
moduleResolution?: string
|
|
40
|
-
target?: string
|
|
41
|
-
module?: string
|
|
42
|
-
sourceMap?: boolean
|
|
43
|
-
inlineSourceMap?: boolean
|
|
44
|
-
esModuleInterop?: boolean
|
|
45
|
-
skipLibCheck?: boolean
|
|
46
|
-
isolatedModules?: boolean
|
|
47
|
-
downlevelIteration?: boolean
|
|
48
|
-
declaration?: boolean
|
|
49
|
-
allowSyntheticDefaultImports?: boolean
|
|
50
|
-
outDir?: string
|
|
51
|
-
baseUrl?: string
|
|
52
|
-
checkJs?: false
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface TsConfig {
|
|
56
|
-
compilerOptions?: CompilerOptions
|
|
57
|
-
include?: string[]
|
|
58
|
-
}
|
|
59
|
-
|
|
60
37
|
export interface SanityV2Json {
|
|
61
38
|
parts?: [
|
|
62
39
|
{
|
|
@@ -6,34 +6,20 @@ import findBabelConfig from 'find-babel-config'
|
|
|
6
6
|
import {incompatiblePluginPackage, urls} from '../../constants'
|
|
7
7
|
import {deprecatedDevDeps, mergedPackages} from '../../configs/banned-packages'
|
|
8
8
|
import path from 'path'
|
|
9
|
-
import {fileExists,
|
|
9
|
+
import {fileExists, readJson5File} from '../../util/files'
|
|
10
10
|
import chalk from 'chalk'
|
|
11
|
-
import {
|
|
11
|
+
import {PackageJson, SanityStudioJson, SanityV2Json} from './types'
|
|
12
|
+
import {ParsedCommandLine} from 'typescript'
|
|
12
13
|
|
|
13
14
|
export const expectedScripts = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
watch: 'pkg-utils watch',
|
|
15
|
+
build:
|
|
16
|
+
'run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict',
|
|
17
|
+
watch: 'pkg-utils watch --strict',
|
|
17
18
|
'link-watch': 'plugin-kit link-watch',
|
|
18
|
-
prepublishOnly: '
|
|
19
|
+
prepublishOnly: 'run-s build',
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
const expectedModulesFields = ['source', 'exports', 'main', 'module', 'files']
|
|
22
|
-
const expectedCompilerOptions = {
|
|
23
|
-
jsx: 'preserve',
|
|
24
|
-
moduleResolution: 'node',
|
|
25
|
-
target: 'esnext',
|
|
26
|
-
module: 'esnext',
|
|
27
|
-
sourceMap: false,
|
|
28
|
-
inlineSourceMap: false,
|
|
29
|
-
esModuleInterop: true,
|
|
30
|
-
skipLibCheck: true,
|
|
31
|
-
isolatedModules: true,
|
|
32
|
-
downlevelIteration: true,
|
|
33
|
-
declaration: true,
|
|
34
|
-
allowSyntheticDefaultImports: true,
|
|
35
|
-
rootDir: 'src',
|
|
36
|
-
}
|
|
37
23
|
|
|
38
24
|
export function validateNodeEngine(packageJson: PackageJson) {
|
|
39
25
|
const nodeVersionRange = '>=14'
|
|
@@ -52,7 +38,8 @@ export function validateNodeEngine(packageJson: PackageJson) {
|
|
|
52
38
|
}
|
|
53
39
|
}
|
|
54
40
|
|
|
55
|
-
export function validateModule(packageJson: PackageJson): string[] {
|
|
41
|
+
export function validateModule(packageJson: PackageJson, options: {outDir: string}): string[] {
|
|
42
|
+
const {outDir} = options
|
|
56
43
|
const errors: string[] = []
|
|
57
44
|
|
|
58
45
|
const missingFields = expectedModulesFields.filter((field) => !packageJson[field])
|
|
@@ -67,24 +54,24 @@ export function validateModule(packageJson: PackageJson): string[] {
|
|
|
67
54
|
Example:
|
|
68
55
|
|
|
69
56
|
Given a plugin with entry-point in src/index.ts, using default @sanity/pkg-utils build command,
|
|
70
|
-
package.json should contain the following entries to ensure that commonjs and esm outputs are built into
|
|
57
|
+
package.json should contain the following entries to ensure that commonjs and esm outputs are built into ${outDir}:
|
|
71
58
|
|
|
72
59
|
"source": "./src/index.ts",
|
|
73
60
|
"exports": {
|
|
74
61
|
".": {
|
|
75
|
-
"types": "
|
|
62
|
+
"types": "./${outDir}/index.d.ts",
|
|
76
63
|
"source": "./src/index.ts",
|
|
77
|
-
"import": "
|
|
78
|
-
"require": "
|
|
79
|
-
"default": "
|
|
64
|
+
"import": "./${outDir}/index.esm.js",
|
|
65
|
+
"require": "./${outDir}/index.js",
|
|
66
|
+
"default": "./${outDir}/index.js"
|
|
80
67
|
}
|
|
81
68
|
},
|
|
82
|
-
"main": "
|
|
83
|
-
"module": "
|
|
84
|
-
"types": "
|
|
69
|
+
"main": "./${outDir}/index.js",
|
|
70
|
+
"module": "./${outDir}/index.esm.js",
|
|
71
|
+
"types": "./${outDir}/index.d.ts",
|
|
85
72
|
"files": [
|
|
86
|
-
"
|
|
87
|
-
"
|
|
73
|
+
"${outDir}",
|
|
74
|
+
"src"
|
|
88
75
|
],
|
|
89
76
|
|
|
90
77
|
Refer to @sanity/pkg-utils for more: https://github.com/sanity-io/pkg-utils#sanitypkg-utils
|
|
@@ -115,8 +102,6 @@ export function validateScripts(packageJson: PackageJson): string[] {
|
|
|
115
102
|
.join(', ')}
|
|
116
103
|
|
|
117
104
|
This checks for that the commands-strings includes these terms.
|
|
118
|
-
For example, this will validate ok:
|
|
119
|
-
"prebuild": "npm run clean && ${expectedScripts.prebuild}",
|
|
120
105
|
|
|
121
106
|
Please add the following to your package.json "scripts":
|
|
122
107
|
|
|
@@ -127,11 +112,52 @@ export function validateScripts(packageJson: PackageJson): string[] {
|
|
|
127
112
|
return errors
|
|
128
113
|
}
|
|
129
114
|
|
|
130
|
-
export async function validateTsConfig(
|
|
115
|
+
export async function validateTsConfig(
|
|
116
|
+
ts: ParsedCommandLine,
|
|
117
|
+
options: {basePath: string; outDir: string; tsconfig: string}
|
|
118
|
+
) {
|
|
119
|
+
const {basePath, outDir, tsconfig} = options
|
|
120
|
+
|
|
131
121
|
const errors: string[] = []
|
|
132
|
-
|
|
122
|
+
|
|
123
|
+
const expectedCompilerOptions = {
|
|
124
|
+
moduleResolution: 'node',
|
|
125
|
+
target: 'esnext',
|
|
126
|
+
module: 'esnext',
|
|
127
|
+
emitDeclarationOnly: true,
|
|
128
|
+
esModuleInterop: true,
|
|
129
|
+
skipLibCheck: true,
|
|
130
|
+
isolatedModules: true,
|
|
131
|
+
downlevelIteration: true,
|
|
132
|
+
declaration: true,
|
|
133
|
+
allowSyntheticDefaultImports: true,
|
|
134
|
+
rootDir: '.',
|
|
135
|
+
outDir,
|
|
136
|
+
}
|
|
137
|
+
|
|
133
138
|
const wrongEntries = Object.entries(expectedCompilerOptions).filter(([key, value]) => {
|
|
134
|
-
|
|
139
|
+
let option: any = ts.options[key]
|
|
140
|
+
|
|
141
|
+
if (key === 'rootDir' && typeof option === 'string') {
|
|
142
|
+
option = path.relative(basePath, option) || '.'
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (key === 'outDir' && typeof option === 'string') {
|
|
146
|
+
option = path.relative(basePath, option) || '.'
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (key === 'moduleResolution' && option === 2) {
|
|
150
|
+
option = 'node'
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (key === 'target' && option === 99) {
|
|
154
|
+
option = 'esnext'
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (key === 'module' && option === 99) {
|
|
158
|
+
option = 'esnext'
|
|
159
|
+
}
|
|
160
|
+
|
|
135
161
|
return typeof value === 'string' && typeof option === 'string'
|
|
136
162
|
? value.toLowerCase() !== option?.toLowerCase()
|
|
137
163
|
: value !== option
|
|
@@ -144,13 +170,13 @@ export async function validateTsConfig(tsConfig: TsConfig) {
|
|
|
144
170
|
|
|
145
171
|
errors.push(
|
|
146
172
|
outdent`
|
|
147
|
-
Recommended tsconfig
|
|
173
|
+
Recommended ${tsconfig} compilerOptions missing:
|
|
148
174
|
|
|
149
175
|
The following fields had unexpected values: [${wrongEntries.map(([key]) => key).join(', ')}]
|
|
150
176
|
Expected to find these values:
|
|
151
177
|
${expectedOutput}
|
|
152
178
|
|
|
153
|
-
Please update your tsconfig
|
|
179
|
+
Please update your ${tsconfig} accordingly.
|
|
154
180
|
`.trimStart()
|
|
155
181
|
)
|
|
156
182
|
}
|
|
@@ -443,3 +469,80 @@ export async function validateSrcIndexFile(basePath: string) {
|
|
|
443
469
|
|
|
444
470
|
return []
|
|
445
471
|
}
|
|
472
|
+
|
|
473
|
+
export async function disallowDuplicateConfig({
|
|
474
|
+
basePath,
|
|
475
|
+
pkgJson,
|
|
476
|
+
configKey,
|
|
477
|
+
files,
|
|
478
|
+
}: {
|
|
479
|
+
basePath: string
|
|
480
|
+
pkgJson: PackageJson
|
|
481
|
+
configKey: string
|
|
482
|
+
files: string[]
|
|
483
|
+
}) {
|
|
484
|
+
const found: string[] = []
|
|
485
|
+
for (const file of files) {
|
|
486
|
+
const filePath = path.join(basePath, file)
|
|
487
|
+
const exits = await fileExists(filePath)
|
|
488
|
+
if (exits) {
|
|
489
|
+
found.push(file)
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if (found.length > 1) {
|
|
493
|
+
return [
|
|
494
|
+
outdent`
|
|
495
|
+
Found multiple config files that serve the same purpose: [${found.join(', ')}].
|
|
496
|
+
|
|
497
|
+
There should be at most one of these files. Delete the rest.
|
|
498
|
+
`,
|
|
499
|
+
]
|
|
500
|
+
}
|
|
501
|
+
if (found.length && pkgJson[configKey]) {
|
|
502
|
+
return [
|
|
503
|
+
outdent`
|
|
504
|
+
package.json contains ${configKey}, but there also exists a config file that serves the same purpose.
|
|
505
|
+
Config file: ${found.join('')}]
|
|
506
|
+
|
|
507
|
+
Either delete the file or remove ${configKey} entry from package.json.
|
|
508
|
+
`,
|
|
509
|
+
]
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
return []
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
export async function disallowDuplicateEslintConfig(basePath: string, pkgJson: PackageJson) {
|
|
516
|
+
return disallowDuplicateConfig({
|
|
517
|
+
basePath,
|
|
518
|
+
pkgJson,
|
|
519
|
+
configKey: 'eslint',
|
|
520
|
+
files: [
|
|
521
|
+
'.eslintrc',
|
|
522
|
+
'.eslintrc.js',
|
|
523
|
+
'.eslintrc.cjs',
|
|
524
|
+
'.eslintrc.yaml',
|
|
525
|
+
'.eslintrc.yml',
|
|
526
|
+
'.eslintrc.json',
|
|
527
|
+
],
|
|
528
|
+
})
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
export async function disallowDuplicatePrettierConfig(basePath: string, pkgJson: PackageJson) {
|
|
532
|
+
return disallowDuplicateConfig({
|
|
533
|
+
basePath,
|
|
534
|
+
pkgJson,
|
|
535
|
+
configKey: 'prettier',
|
|
536
|
+
files: [
|
|
537
|
+
'.prettierrc',
|
|
538
|
+
'.prettierrc.json5',
|
|
539
|
+
'.prettierrc.yaml',
|
|
540
|
+
'.prettierrc.yml',
|
|
541
|
+
'.prettierrc.js',
|
|
542
|
+
'.prettierrc.cjs',
|
|
543
|
+
'.prettier.config,js',
|
|
544
|
+
'.prettier.config.cjs',
|
|
545
|
+
'.prettierrc.toml',
|
|
546
|
+
],
|
|
547
|
+
})
|
|
548
|
+
}
|
|
@@ -2,10 +2,10 @@ import log from '../../util/log'
|
|
|
2
2
|
import {TypedFlags} from 'meow'
|
|
3
3
|
import fs from 'fs'
|
|
4
4
|
import sharedFlags from '../../sharedFlags'
|
|
5
|
-
import {TsConfig} from './types'
|
|
6
5
|
import chalk from 'chalk'
|
|
7
6
|
import outdent from 'outdent'
|
|
8
7
|
import {runCommand} from '../../util/command-parser'
|
|
8
|
+
import {ParsedCommandLine} from 'typescript'
|
|
9
9
|
|
|
10
10
|
export const readFile = fs.promises.readFile
|
|
11
11
|
const splitLine = `\n----------------------------------------------------------`
|
|
@@ -25,6 +25,7 @@ export const verifyPackageConfigDefaults = {
|
|
|
25
25
|
nodeEngine: true,
|
|
26
26
|
studioConfig: true,
|
|
27
27
|
srcIndex: true,
|
|
28
|
+
duplicateConfig: true,
|
|
28
29
|
} as const
|
|
29
30
|
|
|
30
31
|
export type VerifyPackageConfig = Partial<Record<keyof typeof verifyPackageConfigDefaults, boolean>>
|
|
@@ -82,10 +83,10 @@ export function createValidator(
|
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
export async function runTscMaybe(verifyConfig: VerifyPackageConfig,
|
|
86
|
-
if (
|
|
86
|
+
export async function runTscMaybe(verifyConfig: VerifyPackageConfig, ts?: ParsedCommandLine) {
|
|
87
|
+
if (ts && verifyConfig.tsc !== false) {
|
|
87
88
|
log.info('All checks ok, running Typescript compiler.')
|
|
88
|
-
const {code} = await runCommand('tsc --
|
|
89
|
+
const {code} = await runCommand('tsc --build')
|
|
89
90
|
if (code !== 0) {
|
|
90
91
|
throw new Error('Compilation failed. See output above.\n\n' + disableCheckText('tsc'))
|
|
91
92
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import {loadConfig as loadPackageConfig} from '@sanity/pkg-utils'
|
|
1
2
|
import {getPackage} from '../npm/package'
|
|
2
3
|
import log from '../util/log'
|
|
3
|
-
import {cliName, urls} from '../constants'
|
|
4
|
+
import {cliName, defaultOutDir, urls} from '../constants'
|
|
4
5
|
import {validateImports} from '../dependencies/import-linter'
|
|
5
6
|
import outdent from 'outdent'
|
|
6
7
|
import {
|
|
@@ -9,7 +10,6 @@ import {
|
|
|
9
10
|
VerifyFlags,
|
|
10
11
|
VerifyPackageConfig,
|
|
11
12
|
} from './verify/verify-common'
|
|
12
|
-
import {readJson5File} from '../util/files'
|
|
13
13
|
import {
|
|
14
14
|
validateBabelConfig,
|
|
15
15
|
validateModule,
|
|
@@ -22,28 +22,42 @@ import {
|
|
|
22
22
|
validateTsConfig,
|
|
23
23
|
validateSanityDependencies,
|
|
24
24
|
validateSrcIndexFile,
|
|
25
|
+
disallowDuplicateEslintConfig,
|
|
26
|
+
disallowDuplicatePrettierConfig,
|
|
25
27
|
} from './verify/validations'
|
|
26
|
-
import {PackageJson
|
|
28
|
+
import {PackageJson} from './verify/types'
|
|
27
29
|
import chalk from 'chalk'
|
|
30
|
+
import {readTSConfig} from '../util/ts'
|
|
28
31
|
|
|
29
32
|
export async function verifyPackage({basePath, flags}: {basePath: string; flags: VerifyFlags}) {
|
|
30
33
|
let errors: string[] = []
|
|
31
34
|
|
|
32
35
|
const packageJson: PackageJson = await getPackage({basePath, validate: false})
|
|
33
36
|
const verifyConfig: VerifyPackageConfig = packageJson.sanityPlugin?.verifyPackage || {}
|
|
37
|
+
const packageConfig = await loadPackageConfig({cwd: basePath})
|
|
38
|
+
const outDir = packageConfig?.dist ?? defaultOutDir
|
|
39
|
+
const tsconfig = packageConfig?.tsconfig ?? 'tsconfig.json'
|
|
34
40
|
|
|
35
41
|
const validation = createValidator(verifyConfig, flags, errors)
|
|
36
42
|
|
|
37
|
-
const
|
|
43
|
+
const ts = await readTSConfig({basePath, filename: tsconfig})
|
|
38
44
|
|
|
39
45
|
await validation('packageName', async () => validatePackageName(packageJson))
|
|
40
46
|
await validation('pkg-utils', async () => validatePkgUtilsDependency(packageJson))
|
|
41
47
|
await validation('srcIndex', async () => validateSrcIndexFile(basePath))
|
|
42
48
|
await validation('scripts', async () => validateScripts(packageJson))
|
|
43
|
-
await validation('module', async () => validateModule(packageJson))
|
|
49
|
+
await validation('module', async () => validateModule(packageJson, {outDir}))
|
|
44
50
|
await validation('nodeEngine', async () => validateNodeEngine(packageJson))
|
|
51
|
+
await validation('duplicateConfig', async () =>
|
|
52
|
+
disallowDuplicateEslintConfig(basePath, packageJson)
|
|
53
|
+
)
|
|
54
|
+
await validation('duplicateConfig', async () =>
|
|
55
|
+
disallowDuplicatePrettierConfig(basePath, packageJson)
|
|
56
|
+
)
|
|
45
57
|
|
|
46
|
-
|
|
58
|
+
if (ts) {
|
|
59
|
+
await validation('tsconfig', async () => validateTsConfig(ts, {basePath, outDir, tsconfig}))
|
|
60
|
+
}
|
|
47
61
|
|
|
48
62
|
await validation('sanityV2Json', async () => validatePluginSanityJson({basePath, packageJson}))
|
|
49
63
|
|
|
@@ -76,7 +90,7 @@ export async function verifyPackage({basePath, flags}: {basePath: string; flags:
|
|
|
76
90
|
)
|
|
77
91
|
}
|
|
78
92
|
|
|
79
|
-
await runTscMaybe(verifyConfig,
|
|
93
|
+
await runTscMaybe(verifyConfig, ts)
|
|
80
94
|
|
|
81
95
|
log.success(
|
|
82
96
|
outdent`
|