@sanity/plugin-kit 4.0.19 → 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.
- package/assets/inject/semver-workflow/.husky/commit-msg +0 -0
- package/assets/inject/semver-workflow/.husky/pre-commit +0 -0
- package/assets/inject/ui-workshop/src/__workshop__/props.tsx +2 -1
- package/bin/plugin-kit.js +3 -1
- package/dist/{_chunks-cjs/cli.js → _chunks-es/index.js} +53 -63
- package/dist/_chunks-es/index.js.map +1 -0
- package/dist/{_chunks-cjs/init2.js → _chunks-es/init.js} +25 -23
- package/dist/_chunks-es/init.js.map +1 -0
- package/dist/_chunks-es/init2.js +140 -0
- package/dist/_chunks-es/init2.js.map +1 -0
- package/{src/cmds/inject.ts → dist/_chunks-es/inject.js} +18 -32
- package/dist/{_chunks-cjs → _chunks-es}/inject.js.map +1 -1
- package/dist/_chunks-es/link-watch.js +91 -0
- package/dist/_chunks-es/link-watch.js.map +1 -0
- package/dist/_chunks-es/load-package-config.js +22 -0
- package/dist/_chunks-es/load-package-config.js.map +1 -0
- package/dist/_chunks-es/package.js +1759 -0
- package/dist/_chunks-es/package.js.map +1 -0
- package/dist/_chunks-es/package2.js +9 -0
- package/dist/_chunks-es/package2.js.map +1 -0
- package/dist/{_chunks-cjs → _chunks-es}/ts.js +101 -92
- package/dist/_chunks-es/ts.js.map +1 -0
- package/dist/_chunks-es/verify-package.js +92 -0
- package/dist/_chunks-es/verify-package.js.map +1 -0
- package/dist/_chunks-es/verify-studio.js +61 -0
- package/dist/_chunks-es/verify-studio.js.map +1 -0
- package/dist/_chunks-es/version.js +50 -0
- package/dist/_chunks-es/version.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/package.json +41 -88
- package/LICENSE +0 -21
- package/dist/_chunks-cjs/cli.js.map +0 -1
- package/dist/_chunks-cjs/init.js +0 -894
- package/dist/_chunks-cjs/init.js.map +0 -1
- package/dist/_chunks-cjs/init2.js.map +0 -1
- package/dist/_chunks-cjs/inject.js +0 -54
- package/dist/_chunks-cjs/link-watch.js +0 -84
- package/dist/_chunks-cjs/link-watch.js.map +0 -1
- package/dist/_chunks-cjs/package.js +0 -1809
- package/dist/_chunks-cjs/package.js.map +0 -1
- package/dist/_chunks-cjs/package2.js +0 -146
- package/dist/_chunks-cjs/package2.js.map +0 -1
- package/dist/_chunks-cjs/ts.js.map +0 -1
- package/dist/_chunks-cjs/verify-package.js +0 -75
- package/dist/_chunks-cjs/verify-package.js.map +0 -1
- package/dist/_chunks-cjs/verify-studio.js +0 -57
- package/dist/_chunks-cjs/verify-studio.js.map +0 -1
- package/dist/_chunks-cjs/version.js +0 -51
- package/dist/_chunks-cjs/version.js.map +0 -1
- package/dist/cli.d.ts +0 -4
- package/dist/cli.js +0 -6
- package/dist/cli.js.map +0 -1
- package/src/actions/init.ts +0 -95
- package/src/actions/inject.ts +0 -399
- package/src/actions/link-watch.ts +0 -98
- package/src/actions/verify/types.ts +0 -56
- package/src/actions/verify/validations.ts +0 -505
- package/src/actions/verify/verify-common.ts +0 -93
- package/src/actions/verify-package.ts +0 -103
- package/src/actions/verify-studio.ts +0 -58
- package/src/cli.ts +0 -77
- package/src/cmds/index.ts +0 -20
- package/src/cmds/init.ts +0 -90
- package/src/cmds/link-watch.ts +0 -50
- package/src/cmds/verify-package.ts +0 -36
- package/src/cmds/verify-studio.ts +0 -36
- package/src/cmds/version.ts +0 -67
- package/src/configs/banned-packages.ts +0 -27
- package/src/configs/buildExtensions.ts +0 -1
- package/src/configs/default-source.ts +0 -64
- package/src/configs/eslint.ts +0 -51
- package/src/configs/forced-package-versions.ts +0 -12
- package/src/configs/git.ts +0 -68
- package/src/configs/pkg-config.ts +0 -31
- package/src/configs/prettier.ts +0 -11
- package/src/configs/tsconfig.ts +0 -78
- package/src/configs/uselessFiles.ts +0 -29
- package/src/constants.ts +0 -15
- package/src/dependencies/find.ts +0 -193
- package/src/dependencies/import-linter.ts +0 -95
- package/src/index.ts +0 -1
- package/src/npm/manager.ts +0 -44
- package/src/npm/package.ts +0 -427
- package/src/npm/publish.ts +0 -9
- package/src/npm/resolveLatestVersions.ts +0 -31
- package/src/presets/presets.ts +0 -54
- package/src/presets/renovatebot.ts +0 -21
- package/src/presets/semver-workflow.ts +0 -193
- package/src/presets/ui-workshop.ts +0 -97
- package/src/presets/ui.ts +0 -67
- package/src/sanity/manifest.ts +0 -340
- package/src/sharedFlags.ts +0 -14
- package/src/util/command-parser.ts +0 -36
- package/src/util/errorToUndefined.ts +0 -7
- package/src/util/files.ts +0 -260
- package/src/util/log.ts +0 -44
- package/src/util/prompt.ts +0 -70
- package/src/util/readme.ts +0 -93
- package/src/util/request.ts +0 -11
- package/src/util/ts.ts +0 -13
- package/src/util/user.ts +0 -119
package/src/npm/package.ts
DELETED
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import util from 'util'
|
|
4
|
-
// @ts-expect-error missing types
|
|
5
|
-
import githubUrl from 'github-url-to-object'
|
|
6
|
-
// @ts-expect-error missing types
|
|
7
|
-
import validateNpmPackageName from 'validate-npm-package-name'
|
|
8
|
-
import {getPaths, ManifestOptions} from '../sanity/manifest'
|
|
9
|
-
import {resolveLatestVersions} from './resolveLatestVersions'
|
|
10
|
-
import {hasSourceEquivalent, writeJsonFile} from '../util/files'
|
|
11
|
-
import log from '../util/log'
|
|
12
|
-
import {cliName, incompatiblePluginPackage} from '../constants'
|
|
13
|
-
import {InjectOptions, PackageData} from '../actions/inject'
|
|
14
|
-
import {expectedScripts} from '../actions/verify/validations'
|
|
15
|
-
import {PackageJson} from '../actions/verify/types'
|
|
16
|
-
import {
|
|
17
|
-
forcedDevPackageVersions,
|
|
18
|
-
forcedPackageVersions,
|
|
19
|
-
forcedPeerPackageVersions,
|
|
20
|
-
} from '../configs/forced-package-versions'
|
|
21
|
-
const defaultDependencies = [incompatiblePluginPackage]
|
|
22
|
-
|
|
23
|
-
const defaultDevDependencies = [
|
|
24
|
-
'sanity',
|
|
25
|
-
|
|
26
|
-
// peer dependencies of `sanity`
|
|
27
|
-
'react',
|
|
28
|
-
'react-dom',
|
|
29
|
-
'styled-components',
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
const defaultPeerDependencies = ['react', 'sanity']
|
|
33
|
-
|
|
34
|
-
const readFile = util.promisify(fs.readFile)
|
|
35
|
-
|
|
36
|
-
const pathKeys: (keyof PackageJson)[] = ['main', 'module', 'browser', 'types']
|
|
37
|
-
|
|
38
|
-
export async function getPackage(opts: ManifestOptions): Promise<PackageJson> {
|
|
39
|
-
const options = {flags: {}, ...opts}
|
|
40
|
-
|
|
41
|
-
validateOptions(options)
|
|
42
|
-
|
|
43
|
-
const {basePath, validate = true} = options
|
|
44
|
-
const manifestPath = path.normalize(path.join(basePath, 'package.json'))
|
|
45
|
-
|
|
46
|
-
let content
|
|
47
|
-
try {
|
|
48
|
-
content = await readFile(manifestPath, 'utf8')
|
|
49
|
-
} catch (err: any) {
|
|
50
|
-
if (err.code === 'ENOENT') {
|
|
51
|
-
throw new Error(
|
|
52
|
-
`No package.json found. package.json is required to publish to npm. Use \`${cliName} init\` for a new plugin, or \`npm init\` for an existing one`,
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
throw new Error(`Failed to read "${manifestPath}": ${err.message}`)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
let parsed
|
|
60
|
-
try {
|
|
61
|
-
parsed = JSON.parse(content)
|
|
62
|
-
} catch (err: any) {
|
|
63
|
-
throw new Error(`Error parsing "${manifestPath}": ${err.message}`)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (!isObject(parsed)) {
|
|
67
|
-
throw new Error(`Invalid package.json: Root must be an object`)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (validate) {
|
|
71
|
-
await validatePackage(parsed, options)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return parsed
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export async function validatePackage(manifest: PackageJson, opts: ManifestOptions) {
|
|
78
|
-
validateOptions(opts)
|
|
79
|
-
|
|
80
|
-
const options = {isPlugin: true, ...opts}
|
|
81
|
-
|
|
82
|
-
if (options.isPlugin) {
|
|
83
|
-
await validatePluginPackage(manifest, options)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
validateLockFiles(options)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function validateOptions(opts: {basePath: string}) {
|
|
90
|
-
const options = opts || {}
|
|
91
|
-
if (!isObject(options)) {
|
|
92
|
-
throw new Error(`Options must be an object`)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (typeof options.basePath !== 'string') {
|
|
96
|
-
throw new Error(`"options.basePath" must be a string (path to plugin base path)`)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async function validatePluginPackage(manifest: PackageJson, options: ManifestOptions) {
|
|
101
|
-
validatePackageName(manifest)
|
|
102
|
-
await validatePaths(manifest, options)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function validatePackageName(manifest: PackageJson) {
|
|
106
|
-
if (typeof manifest.name !== 'string') {
|
|
107
|
-
throw new Error(`Invalid package.json: "name" must be a string`)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const valid: {validForNewPackages?: boolean; errors: string[]} = validateNpmPackageName(
|
|
111
|
-
manifest.name,
|
|
112
|
-
)
|
|
113
|
-
if (!valid.validForNewPackages) {
|
|
114
|
-
throw new Error(`Invalid package.json: "name" is invalid: ${valid.errors.join(', ')}`)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const isScoped = manifest.name[0] === '@'
|
|
118
|
-
if (!isScoped && !manifest.name.startsWith('sanity-plugin-')) {
|
|
119
|
-
throw new Error(
|
|
120
|
-
`Invalid package.json: "name" should be prefixed with "sanity-plugin-" (or scoped - @your-company/plugin-name)`,
|
|
121
|
-
)
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async function validatePaths(manifest: PackageJson, options: ManifestOptions) {
|
|
126
|
-
const paths = await getPaths({
|
|
127
|
-
...options,
|
|
128
|
-
pluginName: manifest.name ?? 'unknown',
|
|
129
|
-
verifySourceParts: false,
|
|
130
|
-
verifyCompiledParts: false,
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
const abs = (file: string) =>
|
|
134
|
-
path.isAbsolute(file) ? file : path.resolve(path.join(options.basePath, file))
|
|
135
|
-
|
|
136
|
-
const exists = (file: string) => fs.existsSync(abs(file))
|
|
137
|
-
const willExist = (file: string) => paths && hasSourceEquivalent(abs(file), paths)
|
|
138
|
-
const withinSourceDir = (file: string) => paths?.source && abs(file).startsWith(paths.source)
|
|
139
|
-
const withinTargetDir = (file: string) => paths?.compiled && abs(file).startsWith(paths.compiled)
|
|
140
|
-
|
|
141
|
-
for (const key of pathKeys) {
|
|
142
|
-
if (!(key in manifest)) {
|
|
143
|
-
continue
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const manifestValue = manifest[key]
|
|
147
|
-
if (typeof manifestValue !== 'string') {
|
|
148
|
-
throw new Error(`Invalid package.json: "${key}" must be a string if defined`)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// We don't want to reference `./src/MyComponent.js` containing a bunch of JSX and whatnot,
|
|
152
|
-
// instead we want to target `./dist/MyComponent.js` which is the location it'll be compiled to
|
|
153
|
-
if (!options?.flags?.allowSourceTarget && paths && withinSourceDir(manifestValue)) {
|
|
154
|
-
throw new Error(
|
|
155
|
-
`Invalid package.json: "${key}" points to file within source (uncompiled) directory. Use --allow-source-target if you really want to do this.`,
|
|
156
|
-
)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Does it exist only because it was there prior to compilation?
|
|
160
|
-
// We're clearing the folder on compilation, so we shouldn't allow it
|
|
161
|
-
const fileExists = exists(manifestValue)
|
|
162
|
-
if (
|
|
163
|
-
fileExists &&
|
|
164
|
-
paths &&
|
|
165
|
-
withinTargetDir(manifestValue) &&
|
|
166
|
-
!(await willExist(manifestValue))
|
|
167
|
-
) {
|
|
168
|
-
throw new Error(
|
|
169
|
-
`Invalid package.json: "${key}" points to file that will not exist after compiling`,
|
|
170
|
-
)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// If it _doesn't_ exist and it _won't_ exist, then there isn't much point in continuing, is there?
|
|
174
|
-
if (!exists(manifestValue) && !(await willExist(manifestValue))) {
|
|
175
|
-
if (!paths) {
|
|
176
|
-
throw new Error(`Invalid package.json: "${key}" points to file that does not exist`)
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const inOutDir = paths.compiled && !abs(manifestValue).startsWith(paths.compiled)
|
|
180
|
-
throw new Error(
|
|
181
|
-
inOutDir
|
|
182
|
-
? `Invalid package.json: "${key}" points to file that does not exist, and "paths" is not configured to compile to this location`
|
|
183
|
-
: `Invalid package.json: "${key}" points to file that does not exist, and no equivalent is found in source directory`,
|
|
184
|
-
)
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function isObject(obj: unknown): obj is Record<string, unknown> {
|
|
190
|
-
return !Array.isArray(obj) && obj !== null && typeof obj === 'object'
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function validateLockFiles(options: {basePath: string}) {
|
|
194
|
-
const npm = fs.existsSync(path.join(options.basePath, 'package-lock.json'))
|
|
195
|
-
const yarn = fs.existsSync(path.join(options.basePath, 'yarn.lock'))
|
|
196
|
-
if (npm && yarn) {
|
|
197
|
-
throw new Error(`Invalid plugin: contains both package-lock.json and yarn.lock`)
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export async function writePackageJson(data: PackageData, options: InjectOptions) {
|
|
202
|
-
const {user, pluginName, license, description, pkg: prevPkg, gitOrigin} = data
|
|
203
|
-
const {
|
|
204
|
-
outDir,
|
|
205
|
-
peerDependencies: addPeers,
|
|
206
|
-
dependencies: addDeps,
|
|
207
|
-
devDependencies: addDevDeps,
|
|
208
|
-
} = options
|
|
209
|
-
const {flags} = options
|
|
210
|
-
const prev = prevPkg || {}
|
|
211
|
-
|
|
212
|
-
const usePrettier = flags.prettier !== false
|
|
213
|
-
const useEslint = flags.eslint !== false
|
|
214
|
-
const useTypescript = flags.eslint !== false
|
|
215
|
-
|
|
216
|
-
const newDevDependencies = [cliName, '@sanity/pkg-utils']
|
|
217
|
-
|
|
218
|
-
if (useTypescript) {
|
|
219
|
-
log.debug('Using TypeScript. Adding to dev dependencies.')
|
|
220
|
-
newDevDependencies.push('@types/react', 'typescript')
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (usePrettier) {
|
|
224
|
-
log.debug('Using prettier. Adding to dev dependencies.')
|
|
225
|
-
newDevDependencies.push('prettier', 'prettier-plugin-packagejson')
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (useEslint) {
|
|
229
|
-
log.debug('Using eslint. Adding to dev dependencies.')
|
|
230
|
-
|
|
231
|
-
newDevDependencies.push(
|
|
232
|
-
'eslint',
|
|
233
|
-
'eslint-config-sanity',
|
|
234
|
-
'eslint-plugin-react',
|
|
235
|
-
'eslint-plugin-react-hooks',
|
|
236
|
-
)
|
|
237
|
-
|
|
238
|
-
if (usePrettier) {
|
|
239
|
-
newDevDependencies.push('eslint-config-prettier', 'eslint-plugin-prettier')
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (useTypescript) {
|
|
243
|
-
newDevDependencies.push('@typescript-eslint/eslint-plugin', '@typescript-eslint/parser')
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
log.debug('Resolving latest versions for %s', newDevDependencies.join(', '))
|
|
248
|
-
const dependencies = forceDependencyVersions(
|
|
249
|
-
{
|
|
250
|
-
...(prev.dependencies || {}),
|
|
251
|
-
...(addDeps || {}),
|
|
252
|
-
...(await resolveLatestVersions(defaultDependencies)),
|
|
253
|
-
},
|
|
254
|
-
forcedPackageVersions,
|
|
255
|
-
)
|
|
256
|
-
const devDependencies = forceDependencyVersions(
|
|
257
|
-
{
|
|
258
|
-
...(addDevDeps || {}),
|
|
259
|
-
...(prev.devDependencies || {}),
|
|
260
|
-
...(await resolveLatestVersions([...newDevDependencies, ...defaultDevDependencies])),
|
|
261
|
-
},
|
|
262
|
-
forcedDevPackageVersions,
|
|
263
|
-
)
|
|
264
|
-
const peerDependencies = forceDependencyVersions(
|
|
265
|
-
{
|
|
266
|
-
...(prev.peerDependencies || {}),
|
|
267
|
-
...(addPeers || {}),
|
|
268
|
-
...(await resolveLatestVersions(defaultPeerDependencies)),
|
|
269
|
-
},
|
|
270
|
-
forcedPeerPackageVersions,
|
|
271
|
-
)
|
|
272
|
-
|
|
273
|
-
const source = flags.typescript ? './src/index.ts' : './src/index.js'
|
|
274
|
-
|
|
275
|
-
const files = [outDir, 'sanity.json', 'src', 'v2-incompatible.js']
|
|
276
|
-
|
|
277
|
-
// sort alphabetically for scanability
|
|
278
|
-
files.sort()
|
|
279
|
-
|
|
280
|
-
// order should be compatible with prettier-plugin-packagejson
|
|
281
|
-
const forcedOrder = {
|
|
282
|
-
name: pluginName,
|
|
283
|
-
version: prev.version ?? '1.0.0',
|
|
284
|
-
description: description || '',
|
|
285
|
-
keywords: prev.keywords ?? ['sanity', 'sanity-plugin'],
|
|
286
|
-
...urlsFromOrigin(gitOrigin),
|
|
287
|
-
...repoFromOrigin(gitOrigin),
|
|
288
|
-
license: license ? license.id : 'UNLICENSED',
|
|
289
|
-
author: user?.email ? `${user.name} <${user.email}>` : user?.name,
|
|
290
|
-
sideEffects: false,
|
|
291
|
-
type: 'commonjs',
|
|
292
|
-
exports: {
|
|
293
|
-
'.': {
|
|
294
|
-
source,
|
|
295
|
-
import: `./${outDir}/index.mjs`,
|
|
296
|
-
default: `./${outDir}/index.js`,
|
|
297
|
-
},
|
|
298
|
-
'./package.json': './package.json',
|
|
299
|
-
},
|
|
300
|
-
main: `./${outDir}/index.js`,
|
|
301
|
-
...(flags.typescript ? {types: `./${outDir}/index.d.ts`} : {}),
|
|
302
|
-
files,
|
|
303
|
-
scripts: {...prev.scripts},
|
|
304
|
-
dependencies: sortKeys(dependencies),
|
|
305
|
-
devDependencies: sortKeys(devDependencies),
|
|
306
|
-
peerDependencies: sortKeys(peerDependencies),
|
|
307
|
-
engines: {
|
|
308
|
-
node: '>=18',
|
|
309
|
-
},
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
const manifest: PackageJson = {
|
|
313
|
-
...forcedOrder,
|
|
314
|
-
// Use already configured values by default (if not otherwise specified)
|
|
315
|
-
...(prev || {}),
|
|
316
|
-
// We're de-declaring properties because of key order in package.json
|
|
317
|
-
...forcedOrder,
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
const differs = JSON.stringify(prev) !== JSON.stringify(manifest)
|
|
321
|
-
log.debug('Does manifest differ? %s', differs ? 'yes' : 'no')
|
|
322
|
-
if (differs) {
|
|
323
|
-
await writePackageJsonDirect(manifest, options)
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
return differs ? manifest : prev
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
function urlsFromOrigin(gitOrigin?: string): {bugs?: {url: string}; homepage?: string} {
|
|
330
|
-
const details: {user: string; repo: string} | undefined = githubUrl(gitOrigin)
|
|
331
|
-
if (!details) {
|
|
332
|
-
return {}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
return {
|
|
336
|
-
homepage: `https://github.com/${details.user}/${details.repo}#readme`,
|
|
337
|
-
bugs: {
|
|
338
|
-
url: `https://github.com/${details.user}/${details.repo}/issues`,
|
|
339
|
-
},
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
function repoFromOrigin(gitOrigin?: string) {
|
|
344
|
-
console.log(gitOrigin)
|
|
345
|
-
if (!gitOrigin) {
|
|
346
|
-
return {}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
return {
|
|
350
|
-
repository: {
|
|
351
|
-
type: 'git',
|
|
352
|
-
url: gitOrigin,
|
|
353
|
-
},
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
export function addScript(cmd: string, existing: string) {
|
|
358
|
-
if (existing && existing.includes(cmd)) {
|
|
359
|
-
return existing
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
return cmd
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
export async function addPackageJsonScripts(
|
|
366
|
-
manifest: PackageJson,
|
|
367
|
-
options: InjectOptions,
|
|
368
|
-
updateScripts: (currentScripts: Record<string, string>) => Record<string, string>,
|
|
369
|
-
) {
|
|
370
|
-
const originalScripts = manifest.scripts || {}
|
|
371
|
-
const scripts = updateScripts({...originalScripts})
|
|
372
|
-
|
|
373
|
-
const differs = Object.keys(scripts).some((key) => scripts[key] !== originalScripts[key])
|
|
374
|
-
|
|
375
|
-
if (differs) {
|
|
376
|
-
await writePackageJsonDirect({...manifest, scripts}, options)
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
return differs
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
export async function writePackageJsonDirect(manifest: PackageJson, {basePath}: InjectOptions) {
|
|
383
|
-
await writeJsonFile(path.join(basePath, 'package.json'), manifest)
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
export async function addBuildScripts(manifest: PackageJson, options: InjectOptions) {
|
|
387
|
-
const {outDir} = options
|
|
388
|
-
|
|
389
|
-
if (!options.flags.scripts) {
|
|
390
|
-
return false
|
|
391
|
-
}
|
|
392
|
-
return addPackageJsonScripts(manifest, options, (scripts) => {
|
|
393
|
-
scripts.build = addScript(expectedScripts.build, scripts.build)
|
|
394
|
-
scripts.format = addScript(`prettier --write --cache --ignore-unknown .`, scripts.format)
|
|
395
|
-
scripts['link-watch'] = addScript(expectedScripts['link-watch'], scripts['link-watch'])
|
|
396
|
-
scripts.lint = addScript(`eslint .`, scripts.lint)
|
|
397
|
-
scripts.prepublishOnly = addScript(expectedScripts.prepublishOnly, scripts.prepublishOnly)
|
|
398
|
-
scripts.watch = addScript(expectedScripts.watch, scripts.watch)
|
|
399
|
-
return scripts
|
|
400
|
-
})
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
export function sortKeys<T extends Record<string, unknown>>(unordered: T): T {
|
|
404
|
-
return Object.keys(unordered)
|
|
405
|
-
.sort()
|
|
406
|
-
.reduce((obj, key) => {
|
|
407
|
-
// @ts-expect-error this WILL work
|
|
408
|
-
obj[key] = unordered[key]
|
|
409
|
-
return obj
|
|
410
|
-
}, {} as T)
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
/** @internal */
|
|
414
|
-
export function forceDependencyVersions(
|
|
415
|
-
deps: Record<string, string>,
|
|
416
|
-
versions = forcedPackageVersions,
|
|
417
|
-
): Record<string, string> {
|
|
418
|
-
const entries = Object.entries(deps).map((entry) => {
|
|
419
|
-
const [pkg] = entry
|
|
420
|
-
const forceVersion = versions[pkg as keyof typeof versions]
|
|
421
|
-
if (forceVersion) {
|
|
422
|
-
return [pkg, forceVersion]
|
|
423
|
-
}
|
|
424
|
-
return entry
|
|
425
|
-
})
|
|
426
|
-
return Object.fromEntries(entries)
|
|
427
|
-
}
|
package/src/npm/publish.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
// @ts-expect-error missing types
|
|
3
|
-
import npmPacklist from 'npm-packlist'
|
|
4
|
-
|
|
5
|
-
export function getPublishableFiles(basePath: string) {
|
|
6
|
-
return npmPacklist({basePath}).then((files: string[]) =>
|
|
7
|
-
files.map((file) => path.normalize(file)),
|
|
8
|
-
)
|
|
9
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import pProps from 'p-props'
|
|
2
|
-
import getLatestVersion from 'get-latest-version'
|
|
3
|
-
|
|
4
|
-
// We may want to lock certain dependencies to specific versions
|
|
5
|
-
const lockedDependencies: Record<string, string> = {
|
|
6
|
-
'styled-components': '^6.1',
|
|
7
|
-
eslint: '^8.57.0',
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function resolveLatestVersions(packages: string[]) {
|
|
11
|
-
const versions: Record<string, string> = {}
|
|
12
|
-
for (const pkgName of packages) {
|
|
13
|
-
versions[pkgName] = pkgName in lockedDependencies ? lockedDependencies[pkgName] : 'latest'
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return pProps(
|
|
17
|
-
versions,
|
|
18
|
-
async (range, pkgName) => {
|
|
19
|
-
const version = await getLatestVersion(pkgName, {range})
|
|
20
|
-
if (!version) {
|
|
21
|
-
throw new Error(`Found no version for ${pkgName}`)
|
|
22
|
-
}
|
|
23
|
-
return rangeify(version)
|
|
24
|
-
},
|
|
25
|
-
{concurrency: 8},
|
|
26
|
-
)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function rangeify(version: string) {
|
|
30
|
-
return `^${version}`
|
|
31
|
-
}
|
package/src/presets/presets.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import {InjectOptions} from '../actions/inject'
|
|
2
|
-
import {semverWorkflowPreset} from './semver-workflow'
|
|
3
|
-
import {renovatePreset} from './renovatebot'
|
|
4
|
-
import {ui} from './ui'
|
|
5
|
-
import {uiWorkshop} from './ui-workshop'
|
|
6
|
-
|
|
7
|
-
export interface Preset {
|
|
8
|
-
name: string
|
|
9
|
-
description: string
|
|
10
|
-
apply: (options: InjectOptions) => Promise<void>
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const presets: Preset[] = [semverWorkflowPreset, renovatePreset, ui, uiWorkshop]
|
|
14
|
-
const presetNames = presets.map((p) => p?.name)
|
|
15
|
-
|
|
16
|
-
export function presetHelpList(padStart: number) {
|
|
17
|
-
return presets
|
|
18
|
-
.map((p) => `${''.padStart(padStart)}${p.name.padEnd(20)}${p.description}`)
|
|
19
|
-
.join('\n')
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export async function injectPresets(options: InjectOptions) {
|
|
23
|
-
if (options.flags.presetOnly && !options.flags.preset?.length) {
|
|
24
|
-
throw new Error('--preset-only, but no --preset [preset-name] was provided.')
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const applyPresets = presetsFromInput(options.flags.preset)
|
|
28
|
-
for (const preset of applyPresets) {
|
|
29
|
-
await preset.apply(options)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function presetsFromInput(inputPresets: string[] | undefined): Preset[] {
|
|
34
|
-
if (!inputPresets) {
|
|
35
|
-
return []
|
|
36
|
-
}
|
|
37
|
-
const unknownPresets = inputPresets.filter((p) => !presetNames.includes(p))
|
|
38
|
-
if (unknownPresets.length) {
|
|
39
|
-
throw new Error(
|
|
40
|
-
`Unknown --preset(s): [${unknownPresets.join(', ')}]. Must be one of: [${presetNames.join(
|
|
41
|
-
', ',
|
|
42
|
-
)}]`,
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return inputPresets
|
|
47
|
-
.filter(onlyUnique)
|
|
48
|
-
.map((presetName) => presets.find((p) => p.name === presetName))
|
|
49
|
-
.filter((p): p is Preset => !!p)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function onlyUnique(value: string, index: number, arr: string[]) {
|
|
53
|
-
return arr.indexOf(value) === index
|
|
54
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {Preset} from './presets'
|
|
2
|
-
import {InjectOptions, writeAssets} from '../actions/inject'
|
|
3
|
-
|
|
4
|
-
export const renovatePreset: Preset = {
|
|
5
|
-
name: 'renovatebot',
|
|
6
|
-
description: 'Files to enable renovatebot.',
|
|
7
|
-
apply: applyPreset,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
async function applyPreset(options: InjectOptions) {
|
|
11
|
-
await writeAssets(
|
|
12
|
-
[
|
|
13
|
-
{
|
|
14
|
-
type: 'copy',
|
|
15
|
-
from: ['renovatebot', 'renovate.json'],
|
|
16
|
-
to: 'renovate.json',
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
options,
|
|
20
|
-
)
|
|
21
|
-
}
|