@sanity/cli 3.93.0 → 3.93.1-bump-pkg-utils.34.5d0c0b3d22
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/lib/_chunks-cjs/cli.js +5 -5
- package/lib/_chunks-cjs/cli.js.map +1 -1
- package/lib/_chunks-cjs/cliWorker.js.map +1 -1
- package/lib/_chunks-cjs/generateAction.js.map +1 -1
- package/lib/_chunks-cjs/getCliConfig.js.map +1 -1
- package/lib/_chunks-cjs/journeyConfig.js.map +1 -1
- package/lib/_chunks-cjs/loadEnv.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/index.mjs.map +1 -1
- package/lib/run.js.map +1 -1
- package/lib/workers/getAndWriteJourneySchema.js.map +1 -1
- package/lib/workers/getCliConfig.js.map +1 -1
- package/lib/workers/typegenGenerate.js.map +1 -1
- package/package.json +6 -7
- package/templates/blog/README.md +1 -1
- package/templates/clean/README.md +1 -1
- package/templates/ecommerce/README.md +1 -1
- package/templates/get-started/README.md +1 -1
- package/templates/moviedb/README.md +1 -1
- package/templates/quickstart/README.md +1 -1
- package/src/CommandRunner.ts +0 -219
- package/src/__telemetry__/cli.telemetry.ts +0 -29
- package/src/__telemetry__/init.telemetry.ts +0 -95
- package/src/actions/codemod/codemodAction.ts +0 -109
- package/src/actions/codemod/mods/deskRename.ts +0 -19
- package/src/actions/codemod/mods/index.ts +0 -9
- package/src/actions/codemod/mods/partsTypeDirective.ts +0 -28
- package/src/actions/codemod/mods/reactIconsV3.ts +0 -54
- package/src/actions/codemod/types.ts +0 -10
- package/src/actions/init-plugin/bootstrapFromTemplate.ts +0 -196
- package/src/actions/init-project/bootstrapLocalTemplate.ts +0 -201
- package/src/actions/init-project/bootstrapRemoteTemplate.ts +0 -118
- package/src/actions/init-project/createAppCliConfig.ts +0 -24
- package/src/actions/init-project/createCliConfig.ts +0 -31
- package/src/actions/init-project/createPackageManifest.ts +0 -102
- package/src/actions/init-project/createStudioConfig.ts +0 -53
- package/src/actions/init-project/determineAppTemplate.ts +0 -13
- package/src/actions/init-project/fsUtils.ts +0 -40
- package/src/actions/init-project/git.ts +0 -59
- package/src/actions/init-project/initProject.ts +0 -1708
- package/src/actions/init-project/processTemplate.ts +0 -55
- package/src/actions/init-project/promptForDatasetName.ts +0 -68
- package/src/actions/init-project/prompts/index.ts +0 -51
- package/src/actions/init-project/prompts/nextjs.ts +0 -59
- package/src/actions/init-project/readPackageJson.ts +0 -17
- package/src/actions/init-project/templates/appQuickstart.ts +0 -23
- package/src/actions/init-project/templates/appSanityUi.ts +0 -25
- package/src/actions/init-project/templates/blog.ts +0 -5
- package/src/actions/init-project/templates/clean.ts +0 -5
- package/src/actions/init-project/templates/getStarted.ts +0 -37
- package/src/actions/init-project/templates/index.ts +0 -24
- package/src/actions/init-project/templates/moviedb.ts +0 -35
- package/src/actions/init-project/templates/nextjs/index.ts +0 -238
- package/src/actions/init-project/templates/nextjs/schemaTypes/blog.ts +0 -252
- package/src/actions/init-project/templates/quickstart.ts +0 -5
- package/src/actions/init-project/templates/shopify.ts +0 -78
- package/src/actions/init-project/templates/shopifyOnline.ts +0 -50
- package/src/actions/init-project/updateInitialTemplateMetadata.ts +0 -24
- package/src/actions/login/login.telemetry.ts +0 -18
- package/src/actions/login/login.ts +0 -350
- package/src/actions/login/types.ts +0 -19
- package/src/actions/project/createProject.ts +0 -36
- package/src/actions/telemetry/setTelemetryConsent.ts +0 -101
- package/src/actions/typegen/generate.telemetry.ts +0 -20
- package/src/actions/typegen/generateAction.ts +0 -210
- package/src/actions/versions/findSanityModuleVersions.ts +0 -185
- package/src/actions/yarn/events.ts +0 -73
- package/src/cli.ts +0 -350
- package/src/cliClient.ts +0 -62
- package/src/commands/blueprints/addBlueprintsCommand.ts +0 -155
- package/src/commands/blueprints/blueprintsGroup.ts +0 -10
- package/src/commands/blueprints/configBlueprintsCommand.ts +0 -86
- package/src/commands/blueprints/deployBlueprintsCommand.ts +0 -63
- package/src/commands/blueprints/destroyBlueprintsCommand.ts +0 -78
- package/src/commands/blueprints/infoBlueprintsCommand.ts +0 -55
- package/src/commands/blueprints/initBlueprintsCommand.ts +0 -99
- package/src/commands/blueprints/logsBlueprintsCommand.ts +0 -66
- package/src/commands/blueprints/planBlueprintsCommand.ts +0 -51
- package/src/commands/blueprints/stacksBlueprintsCommand.ts +0 -66
- package/src/commands/codemod/codemodCommand.ts +0 -32
- package/src/commands/debug/debugCommand.ts +0 -26
- package/src/commands/debug/printDebugInfo.ts +0 -243
- package/src/commands/docs/docsCommand.ts +0 -20
- package/src/commands/functions/devFunctionsCommand.ts +0 -73
- package/src/commands/functions/envFunctionsCommand.ts +0 -105
- package/src/commands/functions/functionsGroup.ts +0 -10
- package/src/commands/functions/logsFunctionsCommand.ts +0 -94
- package/src/commands/functions/testFunctionsCommand.ts +0 -93
- package/src/commands/help/helpCommand.ts +0 -21
- package/src/commands/help/showHelp.ts +0 -58
- package/src/commands/index.ts +0 -72
- package/src/commands/init/initCommand.ts +0 -123
- package/src/commands/install/installCommand.ts +0 -38
- package/src/commands/learn/learnCommand.ts +0 -20
- package/src/commands/login/loginCommand.ts +0 -29
- package/src/commands/logout/logoutCommand.ts +0 -52
- package/src/commands/manage/manageCommand.ts +0 -24
- package/src/commands/projects/listProjectsCommand.ts +0 -62
- package/src/commands/projects/projectsGroup.ts +0 -10
- package/src/commands/telemetry/disableTelemetryCommand.ts +0 -19
- package/src/commands/telemetry/enableTelemetryCommand.ts +0 -19
- package/src/commands/telemetry/telemetryGroup.ts +0 -10
- package/src/commands/telemetry/telemetryStatusCommand.ts +0 -89
- package/src/commands/typegen/generateTypesCommand.ts +0 -56
- package/src/commands/typegen/typegenGroup.ts +0 -10
- package/src/commands/versions/printVersionResult.ts +0 -51
- package/src/commands/versions/versionsCommand.ts +0 -13
- package/src/config.ts +0 -14
- package/src/debug.ts +0 -3
- package/src/index.ts +0 -6
- package/src/outputters/cliOutputter.ts +0 -47
- package/src/packageManager/getInstallCommand.ts +0 -26
- package/src/packageManager/getUpgradeCommand.ts +0 -52
- package/src/packageManager/index.ts +0 -33
- package/src/packageManager/installPackages.ts +0 -99
- package/src/packageManager/packageManagerChoice.ts +0 -204
- package/src/packageManager/uninstallPackages.ts +0 -44
- package/src/packageManager/yarnStub.ts +0 -22
- package/src/prompters/cliPrompter.ts +0 -9
- package/src/run.ts +0 -8
- package/src/studioDependencies.ts +0 -25
- package/src/types.ts +0 -387
- package/src/util/canLaunchBrowser.ts +0 -12
- package/src/util/cliWorker.ts +0 -34
- package/src/util/clientWrapper.ts +0 -119
- package/src/util/copy.ts +0 -50
- package/src/util/createExpiringConfig.ts +0 -80
- package/src/util/createTelemetryStore.ts +0 -204
- package/src/util/detectRuntime.ts +0 -12
- package/src/util/dynamicRequire.ts +0 -17
- package/src/util/frameworkPort.ts +0 -63
- package/src/util/generateCommandsDocumentation.ts +0 -62
- package/src/util/getCliConfig.ts +0 -172
- package/src/util/getCliVersion.ts +0 -22
- package/src/util/getLocalVersion.ts +0 -35
- package/src/util/getProjectDefaults.ts +0 -103
- package/src/util/getProviderName.ts +0 -9
- package/src/util/getUserConfig.ts +0 -15
- package/src/util/isCi.ts +0 -7
- package/src/util/isCommandGroup.ts +0 -7
- package/src/util/isInteractive.ts +0 -3
- package/src/util/isTrueish.ts +0 -8
- package/src/util/journeyConfig.ts +0 -280
- package/src/util/loadEnv.ts +0 -110
- package/src/util/mergeCommands.ts +0 -78
- package/src/util/neatStack.ts +0 -30
- package/src/util/noSuchCommandText.ts +0 -91
- package/src/util/parseArguments.ts +0 -76
- package/src/util/pathExists.ts +0 -14
- package/src/util/readJson.ts +0 -6
- package/src/util/readdirRecursive.ts +0 -26
- package/src/util/remoteTemplate.ts +0 -320
- package/src/util/resolveLatestVersions.ts +0 -24
- package/src/util/resolveRootDir.ts +0 -59
- package/src/util/telemetryDisclosure.ts +0 -45
- package/src/util/updateNotifier.ts +0 -158
- package/src/util/writeJson.ts +0 -6
- package/src/workers/getAndWriteJourneySchema.ts +0 -7
- package/src/workers/getCliConfig.ts +0 -14
- package/src/workers/typegenGenerate.ts +0 -228
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import {constants, mkdir, open, stat} from 'node:fs/promises'
|
|
2
|
-
import {dirname, join} from 'node:path'
|
|
3
|
-
import {Worker} from 'node:worker_threads'
|
|
4
|
-
|
|
5
|
-
import {readConfig} from '@sanity/codegen'
|
|
6
|
-
import {format as prettierFormat, resolveConfig as resolvePrettierConfig} from 'prettier'
|
|
7
|
-
|
|
8
|
-
import {type CliCommandArguments, type CliCommandContext} from '../../types'
|
|
9
|
-
import {getCliWorkerPath} from '../../util/cliWorker'
|
|
10
|
-
import {
|
|
11
|
-
type TypegenGenerateTypesWorkerData,
|
|
12
|
-
type TypegenGenerateTypesWorkerMessage,
|
|
13
|
-
} from '../../workers/typegenGenerate'
|
|
14
|
-
import {TypesGeneratedTrace} from './generate.telemetry'
|
|
15
|
-
|
|
16
|
-
export interface TypegenGenerateTypesCommandFlags {
|
|
17
|
-
'config-path'?: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const generatedFileWarning = `/**
|
|
21
|
-
* ---------------------------------------------------------------------------------
|
|
22
|
-
* This file has been generated by Sanity TypeGen.
|
|
23
|
-
* Command: \`sanity typegen generate\`
|
|
24
|
-
*
|
|
25
|
-
* Any modifications made directly to this file will be overwritten the next time
|
|
26
|
-
* the TypeScript definitions are generated. Please make changes to the Sanity
|
|
27
|
-
* schema definitions and/or GROQ queries if you need to update these types.
|
|
28
|
-
*
|
|
29
|
-
* For more information on how to use Sanity TypeGen, visit the official documentation:
|
|
30
|
-
* https://www.sanity.io/docs/sanity-typegen
|
|
31
|
-
* ---------------------------------------------------------------------------------
|
|
32
|
-
*/\n\n`
|
|
33
|
-
|
|
34
|
-
export default async function typegenGenerateAction(
|
|
35
|
-
args: CliCommandArguments<TypegenGenerateTypesCommandFlags>,
|
|
36
|
-
context: CliCommandContext,
|
|
37
|
-
): Promise<void> {
|
|
38
|
-
const flags = args.extOptions
|
|
39
|
-
const {output, workDir, telemetry} = context
|
|
40
|
-
|
|
41
|
-
const trace = telemetry.trace(TypesGeneratedTrace)
|
|
42
|
-
trace.start()
|
|
43
|
-
|
|
44
|
-
const codegenConfig = await readConfig(flags['config-path'] || 'sanity-typegen.json')
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
const schemaStats = await stat(codegenConfig.schema)
|
|
48
|
-
if (!schemaStats.isFile()) {
|
|
49
|
-
throw new Error(`Schema path is not a file: ${codegenConfig.schema}`)
|
|
50
|
-
}
|
|
51
|
-
} catch (err) {
|
|
52
|
-
if (err.code === 'ENOENT') {
|
|
53
|
-
// If the user has not provided a specific schema path (eg we're using the default), give some help
|
|
54
|
-
const hint =
|
|
55
|
-
codegenConfig.schema === './schema.json' ? ` - did you run "sanity schema extract"?` : ''
|
|
56
|
-
throw new Error(`Schema file not found: ${codegenConfig.schema}${hint}`)
|
|
57
|
-
}
|
|
58
|
-
throw err
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const outputPath = join(process.cwd(), codegenConfig.generates)
|
|
62
|
-
const outputDir = dirname(outputPath)
|
|
63
|
-
await mkdir(outputDir, {recursive: true})
|
|
64
|
-
const workerPath = await getCliWorkerPath('typegenGenerate')
|
|
65
|
-
|
|
66
|
-
const spinner = output.spinner({}).start('Generating types')
|
|
67
|
-
|
|
68
|
-
const worker = new Worker(workerPath, {
|
|
69
|
-
workerData: {
|
|
70
|
-
workDir,
|
|
71
|
-
schemaPath: codegenConfig.schema,
|
|
72
|
-
searchPath: codegenConfig.path,
|
|
73
|
-
overloadClientMethods: codegenConfig.overloadClientMethods,
|
|
74
|
-
} satisfies TypegenGenerateTypesWorkerData,
|
|
75
|
-
// eslint-disable-next-line no-process-env
|
|
76
|
-
env: process.env,
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
const typeFile = await open(
|
|
80
|
-
outputPath,
|
|
81
|
-
// eslint-disable-next-line no-bitwise
|
|
82
|
-
constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY,
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
typeFile.write(generatedFileWarning)
|
|
86
|
-
|
|
87
|
-
const stats = {
|
|
88
|
-
queryFilesCount: 0,
|
|
89
|
-
errors: 0,
|
|
90
|
-
queriesCount: 0,
|
|
91
|
-
schemaTypesCount: 0,
|
|
92
|
-
unknownTypeNodesGenerated: 0,
|
|
93
|
-
typeNodesGenerated: 0,
|
|
94
|
-
emptyUnionTypeNodesGenerated: 0,
|
|
95
|
-
size: 0,
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
await new Promise<void>((resolve, reject) => {
|
|
99
|
-
worker.addListener('message', (msg: TypegenGenerateTypesWorkerMessage) => {
|
|
100
|
-
if (msg.type === 'error') {
|
|
101
|
-
if (msg.fatal) {
|
|
102
|
-
trace.error(msg.error)
|
|
103
|
-
reject(msg.error)
|
|
104
|
-
return
|
|
105
|
-
}
|
|
106
|
-
const errorMessage = msg.filename
|
|
107
|
-
? `${msg.error.message} in "${msg.filename}"`
|
|
108
|
-
: msg.error.message
|
|
109
|
-
spinner.fail(errorMessage)
|
|
110
|
-
stats.errors++
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
if (msg.type === 'complete') {
|
|
114
|
-
resolve()
|
|
115
|
-
return
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (msg.type === 'typemap') {
|
|
119
|
-
let typeMapStr = `// Query TypeMap\n`
|
|
120
|
-
typeMapStr += msg.typeMap
|
|
121
|
-
typeFile.write(typeMapStr)
|
|
122
|
-
stats.size += Buffer.byteLength(typeMapStr)
|
|
123
|
-
return
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
let fileTypeString = `// Source: ${msg.filename}\n`
|
|
127
|
-
|
|
128
|
-
if (msg.type === 'schema') {
|
|
129
|
-
stats.schemaTypesCount += msg.length
|
|
130
|
-
fileTypeString += msg.schema
|
|
131
|
-
typeFile.write(fileTypeString)
|
|
132
|
-
return
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (msg.type === 'types') {
|
|
136
|
-
stats.queryFilesCount++
|
|
137
|
-
for (const {
|
|
138
|
-
queryName,
|
|
139
|
-
query,
|
|
140
|
-
type,
|
|
141
|
-
typeNodesGenerated,
|
|
142
|
-
unknownTypeNodesGenerated,
|
|
143
|
-
emptyUnionTypeNodesGenerated,
|
|
144
|
-
} of msg.types) {
|
|
145
|
-
fileTypeString += `// Variable: ${queryName}\n`
|
|
146
|
-
fileTypeString += `// Query: ${query.replace(/(\r\n|\n|\r)/gm, '').trim()}\n`
|
|
147
|
-
fileTypeString += type
|
|
148
|
-
stats.queriesCount++
|
|
149
|
-
stats.typeNodesGenerated += typeNodesGenerated
|
|
150
|
-
stats.unknownTypeNodesGenerated += unknownTypeNodesGenerated
|
|
151
|
-
stats.emptyUnionTypeNodesGenerated += emptyUnionTypeNodesGenerated
|
|
152
|
-
}
|
|
153
|
-
typeFile.write(`${fileTypeString}\n`)
|
|
154
|
-
stats.size += Buffer.byteLength(fileTypeString)
|
|
155
|
-
}
|
|
156
|
-
})
|
|
157
|
-
worker.addListener('error', reject)
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
await typeFile.close()
|
|
161
|
-
|
|
162
|
-
const prettierConfig = codegenConfig.formatGeneratedCode
|
|
163
|
-
? await resolvePrettierConfig(outputPath).catch((err) => {
|
|
164
|
-
output.warn(`Failed to load prettier config: ${err.message}`)
|
|
165
|
-
return null
|
|
166
|
-
})
|
|
167
|
-
: null
|
|
168
|
-
|
|
169
|
-
if (prettierConfig) {
|
|
170
|
-
const formatFile = await open(outputPath, constants.O_RDWR)
|
|
171
|
-
try {
|
|
172
|
-
const code = await formatFile.readFile()
|
|
173
|
-
const formattedCode = await prettierFormat(code.toString(), {
|
|
174
|
-
...prettierConfig,
|
|
175
|
-
parser: 'typescript' as const,
|
|
176
|
-
})
|
|
177
|
-
await formatFile.truncate()
|
|
178
|
-
await formatFile.write(formattedCode, 0)
|
|
179
|
-
|
|
180
|
-
spinner.info('Formatted generated types with Prettier')
|
|
181
|
-
} catch (err) {
|
|
182
|
-
output.warn(`Failed to format generated types with Prettier: ${err.message}`)
|
|
183
|
-
} finally {
|
|
184
|
-
await formatFile.close()
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
trace.log({
|
|
189
|
-
outputSize: stats.size,
|
|
190
|
-
queriesCount: stats.queriesCount,
|
|
191
|
-
schemaTypesCount: stats.schemaTypesCount,
|
|
192
|
-
queryFilesCount: stats.queryFilesCount,
|
|
193
|
-
filesWithErrors: stats.errors,
|
|
194
|
-
typeNodesGenerated: stats.typeNodesGenerated,
|
|
195
|
-
unknownTypeNodesGenerated: stats.unknownTypeNodesGenerated,
|
|
196
|
-
unknownTypeNodesRatio:
|
|
197
|
-
stats.typeNodesGenerated > 0 ? stats.unknownTypeNodesGenerated / stats.typeNodesGenerated : 0,
|
|
198
|
-
emptyUnionTypeNodesGenerated: stats.emptyUnionTypeNodesGenerated,
|
|
199
|
-
configOverloadClientMethods: codegenConfig.overloadClientMethods,
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
trace.complete()
|
|
203
|
-
if (stats.errors > 0) {
|
|
204
|
-
spinner.warn(`Encountered errors in ${stats.errors} files while generating types`)
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
spinner.succeed(
|
|
208
|
-
`Generated TypeScript types for ${stats.schemaTypesCount} schema types and ${stats.queriesCount} GROQ queries in ${stats.queryFilesCount} files into: ${codegenConfig.generates}`,
|
|
209
|
-
)
|
|
210
|
-
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import {readFileSync} from 'node:fs'
|
|
2
|
-
import {join as joinPath} from 'node:path'
|
|
3
|
-
|
|
4
|
-
import getLatestVersion from 'get-latest-version'
|
|
5
|
-
import promiseProps from 'promise-props-recursive'
|
|
6
|
-
import semver from 'semver'
|
|
7
|
-
import semverCompare from 'semver-compare'
|
|
8
|
-
|
|
9
|
-
import {type CliCommandContext, type PackageJson} from '../../types'
|
|
10
|
-
import {getCliVersion} from '../../util/getCliVersion'
|
|
11
|
-
import {getLocalVersion} from '../../util/getLocalVersion'
|
|
12
|
-
|
|
13
|
-
/*
|
|
14
|
-
* The `sanity upgrade` command should only be responsible for upgrading the
|
|
15
|
-
* _studio_ related dependencies. Modules like @sanity/block-content-to-react
|
|
16
|
-
* shouldn't be upgraded using the same tag/range as the other studio modules.
|
|
17
|
-
*
|
|
18
|
-
* We don't have a guaranteed list of the "studio modules", so instead we
|
|
19
|
-
* explicitly exclude certain modules from being upgraded.
|
|
20
|
-
*/
|
|
21
|
-
const PACKAGES_TO_EXCLUDE = [
|
|
22
|
-
'@sanity/block-content-to-html',
|
|
23
|
-
'@sanity/block-content-to-react',
|
|
24
|
-
'@sanity/client',
|
|
25
|
-
]
|
|
26
|
-
|
|
27
|
-
const defaultOptions: FindModuleVersionOptions = {
|
|
28
|
-
includeCli: true,
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
interface PromisedModuleVersionInfo {
|
|
32
|
-
name: string
|
|
33
|
-
declared: string
|
|
34
|
-
installed: string | undefined
|
|
35
|
-
latest: Promise<string | undefined>
|
|
36
|
-
latestInRange: Promise<string | undefined>
|
|
37
|
-
isPinned: boolean
|
|
38
|
-
isGlobal: boolean
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface ModuleVersionInfo {
|
|
42
|
-
name: string
|
|
43
|
-
declared: string
|
|
44
|
-
installed: string | undefined
|
|
45
|
-
latest: string
|
|
46
|
-
latestInRange: string
|
|
47
|
-
isPinned: boolean
|
|
48
|
-
isGlobal: boolean
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface ModuleVersionResult extends ModuleVersionInfo {
|
|
52
|
-
needsUpdate: boolean
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface FindModuleVersionOptions {
|
|
56
|
-
includeCli?: boolean
|
|
57
|
-
target?: string
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export async function findSanityModuleVersions(
|
|
61
|
-
context: CliCommandContext,
|
|
62
|
-
options: FindModuleVersionOptions = {},
|
|
63
|
-
): Promise<ModuleVersionResult[]> {
|
|
64
|
-
const {spinner} = context.output
|
|
65
|
-
const {target, includeCli} = {...defaultOptions, ...options}
|
|
66
|
-
const cliVersion = await getCliVersion()
|
|
67
|
-
|
|
68
|
-
// Declared @sanity modules and their wanted version ranges in package.json
|
|
69
|
-
const sanityModules = filterSanityModules(getLocalManifest(context.workDir))
|
|
70
|
-
|
|
71
|
-
// Figure out the latest versions which match the wanted range
|
|
72
|
-
const resolveOpts = {includeCli, target}
|
|
73
|
-
const spin = spinner('Resolving latest versions').start()
|
|
74
|
-
const versions = await promiseProps<ModuleVersionInfo[]>(
|
|
75
|
-
buildPackageArray(sanityModules, context.workDir, resolveOpts, cliVersion),
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
const packages = Object.values(versions)
|
|
79
|
-
spin.stop()
|
|
80
|
-
|
|
81
|
-
return packages.map((mod) => {
|
|
82
|
-
const current = mod.installed || semver.minVersion(mod.declared)?.toString() || ''
|
|
83
|
-
const needsUpdate =
|
|
84
|
-
target === 'latest'
|
|
85
|
-
? semverCompare(current, mod.latest) === -1
|
|
86
|
-
: typeof mod.latestInRange !== 'undefined' && mod.installed !== mod.latestInRange
|
|
87
|
-
|
|
88
|
-
return {...mod, needsUpdate}
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function getLocalManifest(workDir: string): Partial<PackageJson> {
|
|
93
|
-
try {
|
|
94
|
-
const fileContent = readFileSync(joinPath(workDir, 'package.json'), 'utf8')
|
|
95
|
-
return JSON.parse(fileContent)
|
|
96
|
-
} catch {
|
|
97
|
-
return {}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function filterSanityModules(manifest: Partial<PackageJson>): Record<string, string> {
|
|
102
|
-
const dependencies = {
|
|
103
|
-
...manifest.dependencies,
|
|
104
|
-
...manifest.devDependencies,
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return Object.keys(dependencies)
|
|
108
|
-
.filter((mod) => mod.startsWith('@sanity/') || mod === 'sanity')
|
|
109
|
-
.filter((mod) => !PACKAGES_TO_EXCLUDE.includes(mod))
|
|
110
|
-
.sort()
|
|
111
|
-
.reduce(
|
|
112
|
-
(versions, dependency) => {
|
|
113
|
-
versions[dependency] = dependencies[dependency]
|
|
114
|
-
return versions
|
|
115
|
-
},
|
|
116
|
-
{} as Record<string, string>,
|
|
117
|
-
)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function buildPackageArray(
|
|
121
|
-
packages: Record<string, string>,
|
|
122
|
-
workDir: string,
|
|
123
|
-
options: FindModuleVersionOptions = {},
|
|
124
|
-
cliVersion: string,
|
|
125
|
-
): PromisedModuleVersionInfo[] {
|
|
126
|
-
const {includeCli, target} = options
|
|
127
|
-
|
|
128
|
-
const modules = []
|
|
129
|
-
if (includeCli) {
|
|
130
|
-
const [cliMajor] = cliVersion.split('.')
|
|
131
|
-
const latest = tryFindLatestVersion('@sanity/cli', target || `^${cliMajor}`)
|
|
132
|
-
modules.push({
|
|
133
|
-
name: '@sanity/cli',
|
|
134
|
-
declared: `^${cliVersion}`,
|
|
135
|
-
installed: trimHash(cliVersion),
|
|
136
|
-
latest: latest.then((versions) => versions.latest),
|
|
137
|
-
latestInRange: latest.then((versions) => versions.latestInRange),
|
|
138
|
-
isPinned: false,
|
|
139
|
-
isGlobal: true,
|
|
140
|
-
})
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return [
|
|
144
|
-
...modules,
|
|
145
|
-
...Object.keys(packages).map((pkgName) => {
|
|
146
|
-
const latest = tryFindLatestVersion(pkgName, target || packages[pkgName] || 'latest')
|
|
147
|
-
const localVersion = getLocalVersion(pkgName, workDir)
|
|
148
|
-
return {
|
|
149
|
-
name: pkgName,
|
|
150
|
-
declared: packages[pkgName],
|
|
151
|
-
installed: localVersion ? trimHash(localVersion) : undefined,
|
|
152
|
-
latest: latest.then((versions) => versions.latest),
|
|
153
|
-
latestInRange: latest.then((versions) => versions.latestInRange),
|
|
154
|
-
isPinned: isPinnedVersion(packages[pkgName]),
|
|
155
|
-
isGlobal: false,
|
|
156
|
-
}
|
|
157
|
-
}),
|
|
158
|
-
]
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
async function tryFindLatestVersion(pkgName: string, range: string) {
|
|
162
|
-
try {
|
|
163
|
-
const {latest, inRange} = await getLatestVersion(pkgName, {range, includeLatest: true})
|
|
164
|
-
return {latest, latestInRange: inRange}
|
|
165
|
-
} catch (err) {
|
|
166
|
-
if (!(err instanceof Error) || !err.message.includes('No version exists')) {
|
|
167
|
-
throw err
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const latest = await getLatestVersion(pkgName)
|
|
171
|
-
return {latest, latestInRange: undefined}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function isPinnedVersion(version: string): boolean {
|
|
176
|
-
return /^\d+\.\d+\.\d+/.test(version)
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* `2.27.3-cookieless-auth.34+8ba9c1504` →
|
|
181
|
-
* `2.27.3-cookieless-auth.34`
|
|
182
|
-
*/
|
|
183
|
-
function trimHash(version: string) {
|
|
184
|
-
return version.replace(/\+[a-z0-9]{8,}$/, '')
|
|
185
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
export interface YarnErrorEvent {
|
|
2
|
-
type: 'error'
|
|
3
|
-
data: string
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface YarnWarningEvent {
|
|
7
|
-
type: 'warning'
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface YarnStepEvent {
|
|
11
|
-
type: 'step'
|
|
12
|
-
data: {message: string}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface YarnActivityStartEvent {
|
|
16
|
-
type: 'activityStart'
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface YarnActivityTickEvent {
|
|
20
|
-
type: 'activityTick'
|
|
21
|
-
data: {
|
|
22
|
-
name: string
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface YarnActivitySetEndEvent {
|
|
27
|
-
type: 'activitySetEnd'
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface YarnActivityEndEvent {
|
|
31
|
-
type: 'activityEnd'
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface YarnProgressStartEvent {
|
|
35
|
-
type: 'progressStart'
|
|
36
|
-
data: {
|
|
37
|
-
total: number
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface YarnProgressTickEvent {
|
|
42
|
-
type: 'progressTick'
|
|
43
|
-
data: {
|
|
44
|
-
current: number
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface YarnProgressFinishEvent {
|
|
49
|
-
type: 'progressFinish'
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface YarnSuccessEvent {
|
|
53
|
-
type: 'success'
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface YarnFinishedEvent {
|
|
57
|
-
type: 'finished'
|
|
58
|
-
data: number
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export type YarnEvent =
|
|
62
|
-
| YarnErrorEvent
|
|
63
|
-
| YarnWarningEvent
|
|
64
|
-
| YarnStepEvent
|
|
65
|
-
| YarnActivityStartEvent
|
|
66
|
-
| YarnActivityTickEvent
|
|
67
|
-
| YarnActivitySetEndEvent
|
|
68
|
-
| YarnActivityEndEvent
|
|
69
|
-
| YarnProgressStartEvent
|
|
70
|
-
| YarnProgressTickEvent
|
|
71
|
-
| YarnProgressFinishEvent
|
|
72
|
-
| YarnSuccessEvent
|
|
73
|
-
| YarnFinishedEvent
|