@sanity/runtime-cli 17.10.0 → 17.11.1-next.gc1820a0
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/README.md +20 -20
- package/dist/actions/blueprints/blueprint.js +1 -1
- package/dist/actions/blueprints/pre-deploy.js +7 -6
- package/dist/actions/blueprints/wait-for-operation.js +2 -1
- package/dist/actions/sanity/examples.js +9 -2
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +2 -0
- package/dist/cores/blueprints/config.js +18 -8
- package/dist/cores/blueprints/deploy.js +9 -8
- package/dist/cores/blueprints/destroy.js +7 -6
- package/dist/cores/blueprints/doctor.js +15 -2
- package/dist/cores/blueprints/init.d.ts +2 -0
- package/dist/cores/blueprints/init.js +56 -20
- package/dist/cores/blueprints/plan.js +11 -6
- package/dist/cores/blueprints/promote.js +3 -2
- package/dist/cores/functions/add.js +11 -7
- package/dist/cores/functions/env/add.js +2 -1
- package/dist/cores/functions/logs.js +50 -6
- package/dist/cores/index.d.ts +5 -0
- package/dist/server/static/vendor/vendor.bundle.js +13 -6
- package/dist/utils/blueprints/hints.js +8 -3
- package/dist/utils/display/prompt.d.ts +15 -2
- package/dist/utils/display/prompt.js +70 -8
- package/dist/utils/package-manager.d.ts +20 -0
- package/dist/utils/package-manager.js +63 -0
- package/dist/utils/types.d.ts +9 -0
- package/oclif.manifest.json +1 -1
- package/package.json +21 -22
|
@@ -5,6 +5,13 @@ import { styleText } from '../style-text.js';
|
|
|
5
5
|
import { niceId } from './presenters.js';
|
|
6
6
|
// --- Wizard infrastructure ---
|
|
7
7
|
export const BACK = Symbol('back');
|
|
8
|
+
/** Thrown when the user picks "Cancel" in a prompt. Cores translate it to a clean result. */
|
|
9
|
+
export class CancelledError extends Error {
|
|
10
|
+
constructor(message = 'Cancelled by user.') {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'CancelledError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
8
15
|
/**
|
|
9
16
|
* Runs a sequence of prompt steps with back-navigation support.
|
|
10
17
|
* Each step can return BACK to go to the previous non-skipped step.
|
|
@@ -57,13 +64,53 @@ function withBackChoice(choices, allowBack) {
|
|
|
57
64
|
];
|
|
58
65
|
}
|
|
59
66
|
// --- Standalone prompts ---
|
|
67
|
+
/**
|
|
68
|
+
* Ask where a new Blueprint should go.
|
|
69
|
+
* Returns the chosen directory, or null to use the current one.
|
|
70
|
+
* @throws CancelledError when the user cancels.
|
|
71
|
+
*/
|
|
72
|
+
export async function promptForInitLocation(currentDir) {
|
|
73
|
+
const HERE = 'here';
|
|
74
|
+
const ELSEWHERE = 'elsewhere';
|
|
75
|
+
const CANCEL = 'cancel';
|
|
76
|
+
const choice = await select({
|
|
77
|
+
message: 'Where should the Blueprint go?',
|
|
78
|
+
choices: [
|
|
79
|
+
{ name: 'Here', value: HERE, description: currentDir },
|
|
80
|
+
{ name: 'In a new folder', value: ELSEWHERE, description: 'Name a folder to create' },
|
|
81
|
+
{ name: 'Cancel', value: CANCEL, description: 'Stop here and change nothing' },
|
|
82
|
+
],
|
|
83
|
+
default: HERE,
|
|
84
|
+
});
|
|
85
|
+
if (choice === CANCEL)
|
|
86
|
+
throw new CancelledError();
|
|
87
|
+
if (choice === HERE)
|
|
88
|
+
return null;
|
|
89
|
+
const folder = await input({
|
|
90
|
+
message: 'Folder name:',
|
|
91
|
+
validate: (val) => val.trim().length > 0 || 'A folder name is required',
|
|
92
|
+
});
|
|
93
|
+
return folder.trim();
|
|
94
|
+
}
|
|
60
95
|
export async function promptForBlueprintType() {
|
|
61
96
|
return await select({
|
|
62
97
|
message: 'Choose a Blueprint file type:',
|
|
63
98
|
choices: [
|
|
64
|
-
{
|
|
65
|
-
|
|
66
|
-
|
|
99
|
+
{
|
|
100
|
+
name: 'TypeScript',
|
|
101
|
+
value: 'ts',
|
|
102
|
+
description: 'Editor completion and type checks. Adds @sanity/blueprints.',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'JavaScript',
|
|
106
|
+
value: 'js',
|
|
107
|
+
description: 'The same define* helpers, without type checks. Adds @sanity/blueprints.',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'JSON',
|
|
111
|
+
value: 'json',
|
|
112
|
+
description: 'No dependency and no install step. Write each resource by hand.',
|
|
113
|
+
},
|
|
67
114
|
],
|
|
68
115
|
default: 'ts',
|
|
69
116
|
});
|
|
@@ -203,7 +250,7 @@ export async function promptForProjectInOrg({ projects, knownProjectId, logger,
|
|
|
203
250
|
* Prompt the user for a Stack after scope has been determined.
|
|
204
251
|
* Can create a new Stack or select an existing one.
|
|
205
252
|
*/
|
|
206
|
-
export async function promptForStack({ scopeType, scopeId, token, logger, allowBack = false, }) {
|
|
253
|
+
export async function promptForStack({ scopeType, scopeId, token, logger, allowBack = false, suggestedName, }) {
|
|
207
254
|
if (!scopeId) {
|
|
208
255
|
throw new Error(`Cannot list Stacks: no ${scopeType} ID provided. ` +
|
|
209
256
|
'Provide --project-id or --organization-id, or select a scope in the wizard.');
|
|
@@ -247,16 +294,30 @@ export async function promptForStack({ scopeType, scopeId, token, logger, allowB
|
|
|
247
294
|
pickedStackId = answer;
|
|
248
295
|
}
|
|
249
296
|
else if (allowBack) {
|
|
297
|
+
const CANCEL = 'cancel';
|
|
250
298
|
const proceed = await select({
|
|
251
|
-
message: '
|
|
252
|
-
choices: withBackChoice([
|
|
299
|
+
message: 'This scope has no Stacks yet:',
|
|
300
|
+
choices: withBackChoice([
|
|
301
|
+
{
|
|
302
|
+
name: 'Create the first Stack',
|
|
303
|
+
value: NEW_STACK_ID,
|
|
304
|
+
description: 'A Blueprint needs a Stack before it can deploy',
|
|
305
|
+
},
|
|
306
|
+
{ name: 'Cancel', value: CANCEL, description: 'Stop here and change nothing' },
|
|
307
|
+
], allowBack),
|
|
253
308
|
});
|
|
254
309
|
if (proceed === BACK)
|
|
255
310
|
return BACK;
|
|
311
|
+
if (proceed === CANCEL)
|
|
312
|
+
throw new CancelledError();
|
|
256
313
|
}
|
|
257
314
|
if (pickedStackId === NEW_STACK_ID) {
|
|
315
|
+
// only suggest a free name; the API rejects a duplicate within a scope
|
|
316
|
+
const isTaken = stacks.some((s) => s.name === suggestedName);
|
|
317
|
+
logger(styleText('dim', 'The name is a label. Sanity assigns the Stack ID.'));
|
|
258
318
|
const stackName = await input({
|
|
259
|
-
message: '
|
|
319
|
+
message: 'Name your new Stack:',
|
|
320
|
+
default: isTaken ? undefined : suggestedName,
|
|
260
321
|
validate: (val) => val.length > 0 || 'Stack name is required',
|
|
261
322
|
});
|
|
262
323
|
const stack = await createEmptyStack({
|
|
@@ -277,7 +338,7 @@ export async function promptForStack({ scopeType, scopeId, token, logger, allowB
|
|
|
277
338
|
* Full wizard: Organization -> Scope -> Project (if project-scoped) -> Stack.
|
|
278
339
|
* Supports back-navigation between steps.
|
|
279
340
|
*/
|
|
280
|
-
export async function runScopeAndStackWizard({ token, knownOrganizationId, knownProjectId, logger, }) {
|
|
341
|
+
export async function runScopeAndStackWizard({ token, knownOrganizationId, knownProjectId, logger, suggestedStackName, }) {
|
|
281
342
|
const steps = [
|
|
282
343
|
{
|
|
283
344
|
key: 'organization',
|
|
@@ -336,6 +397,7 @@ export async function runScopeAndStackWizard({ token, knownOrganizationId, known
|
|
|
336
397
|
token,
|
|
337
398
|
logger,
|
|
338
399
|
allowBack: true,
|
|
400
|
+
suggestedName: suggestedStackName,
|
|
339
401
|
});
|
|
340
402
|
},
|
|
341
403
|
},
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Package managers this CLI can name in the commands it prints. */
|
|
2
|
+
export type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun';
|
|
3
|
+
/**
|
|
4
|
+
* Detect the package manager for a project.
|
|
5
|
+
*
|
|
6
|
+
* `npm_config_user_agent` is first then lockfile detection.
|
|
7
|
+
*/
|
|
8
|
+
export declare function detectPackageManager(dir?: string): PackageManager | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* The command that runs this CLI, matched to the detected package manager.
|
|
11
|
+
* Falls back to `npx`
|
|
12
|
+
*
|
|
13
|
+
* Yarn is weird: detected from a lockfile alone also falls bac
|
|
14
|
+
* lockfile name does not differentiate Yarn 1 vs Yarn 2+
|
|
15
|
+
*/
|
|
16
|
+
export declare function runCommand(bin: string, dir?: string): string;
|
|
17
|
+
/** The command that installs dependencies, matched to the detected package manager. */
|
|
18
|
+
export declare function installCommand(dir?: string): string;
|
|
19
|
+
/** Clear the lockfile lookup cache. Tests use this after they move fixtures. */
|
|
20
|
+
export declare function resetPackageManagerCache(): void;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
import { getBinCommand, getRunningPackageManager } from '@sanity/cli-core/package-manager';
|
|
3
|
+
import * as find from 'empathic/find';
|
|
4
|
+
/**
|
|
5
|
+
* Lockfile names in priority order
|
|
6
|
+
*/
|
|
7
|
+
const LOCKFILES = {
|
|
8
|
+
'pnpm-lock.yaml': 'pnpm',
|
|
9
|
+
'yarn.lock': 'yarn',
|
|
10
|
+
'bun.lock': 'bun',
|
|
11
|
+
'bun.lockb': 'bun',
|
|
12
|
+
'package-lock.json': 'npm',
|
|
13
|
+
};
|
|
14
|
+
const LOCKFILE_NAMES = Object.keys(LOCKFILES);
|
|
15
|
+
/** Minimal user agents, so the lockfile path reuses the same command mapping. */
|
|
16
|
+
const SYNTHETIC_USER_AGENTS = {
|
|
17
|
+
npm: 'npm/0',
|
|
18
|
+
pnpm: 'pnpm/0',
|
|
19
|
+
yarn: 'yarn/0',
|
|
20
|
+
bun: 'bun/0',
|
|
21
|
+
};
|
|
22
|
+
const lockfileCache = new Map();
|
|
23
|
+
/** Find the package manager a lockfile at or above `dir` implies. */
|
|
24
|
+
function detectFromLockfile(dir) {
|
|
25
|
+
if (lockfileCache.has(dir))
|
|
26
|
+
return lockfileCache.get(dir);
|
|
27
|
+
const found = find.any(LOCKFILE_NAMES, { cwd: dir });
|
|
28
|
+
const manager = found ? LOCKFILES[basename(found)] : undefined;
|
|
29
|
+
lockfileCache.set(dir, manager);
|
|
30
|
+
return manager;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Detect the package manager for a project.
|
|
34
|
+
*
|
|
35
|
+
* `npm_config_user_agent` is first then lockfile detection.
|
|
36
|
+
*/
|
|
37
|
+
export function detectPackageManager(dir = process.cwd()) {
|
|
38
|
+
return getRunningPackageManager() ?? detectFromLockfile(dir);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The command that runs this CLI, matched to the detected package manager.
|
|
42
|
+
* Falls back to `npx`
|
|
43
|
+
*
|
|
44
|
+
* Yarn is weird: detected from a lockfile alone also falls bac
|
|
45
|
+
* lockfile name does not differentiate Yarn 1 vs Yarn 2+
|
|
46
|
+
*/
|
|
47
|
+
export function runCommand(bin, dir) {
|
|
48
|
+
const running = getRunningPackageManager();
|
|
49
|
+
if (running)
|
|
50
|
+
return getBinCommand({ bin });
|
|
51
|
+
const fromLockfile = detectFromLockfile(dir ?? process.cwd());
|
|
52
|
+
if (!fromLockfile || fromLockfile === 'yarn')
|
|
53
|
+
return `npx ${bin}`;
|
|
54
|
+
return getBinCommand({ bin, userAgent: SYNTHETIC_USER_AGENTS[fromLockfile] });
|
|
55
|
+
}
|
|
56
|
+
/** The command that installs dependencies, matched to the detected package manager. */
|
|
57
|
+
export function installCommand(dir) {
|
|
58
|
+
return `${detectPackageManager(dir) ?? 'npm'} install`;
|
|
59
|
+
}
|
|
60
|
+
/** Clear the lockfile lookup cache. Tests use this after they move fixtures. */
|
|
61
|
+
export function resetPackageManagerCache() {
|
|
62
|
+
lockfileCache.clear();
|
|
63
|
+
}
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -262,8 +262,17 @@ export interface FunctionLog {
|
|
|
262
262
|
requestId: string;
|
|
263
263
|
level: string;
|
|
264
264
|
message: string;
|
|
265
|
+
operationName?: string;
|
|
266
|
+
attempt?: number;
|
|
267
|
+
operationId?: string;
|
|
268
|
+
executionArn?: string;
|
|
265
269
|
}
|
|
266
270
|
/** @internal */
|
|
271
|
+
export type FunctionLogJson = Omit<FunctionLog, 'executionArn' | 'operationId' | 'operationName'> & {
|
|
272
|
+
durableContext?: 'handler' | 'step';
|
|
273
|
+
step?: string;
|
|
274
|
+
};
|
|
275
|
+
/** @internal */
|
|
267
276
|
export declare enum BlueprintParserErrorType {
|
|
268
277
|
InvalidProperty = "invalid_property",
|
|
269
278
|
InvalidVersion = "invalid_version",
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/runtime-cli",
|
|
3
3
|
"description": "Sanity's Runtime CLI for Blueprints and Functions",
|
|
4
|
-
"version": "17.
|
|
4
|
+
"version": "17.11.1-next.gc1820a0",
|
|
5
5
|
"author": "Sanity Runtime Team",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -64,21 +64,20 @@
|
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@architect/hydrate": "~6.0.2",
|
|
66
66
|
"@architect/inventory": "~6.1.0",
|
|
67
|
-
"@inquirer/prompts": "^8.
|
|
68
|
-
"@oclif/core": "^4.
|
|
69
|
-
"@oclif/plugin-help": "^6.
|
|
70
|
-
"@sanity-labs/design-tokens": "^0.0.2-alpha.2",
|
|
67
|
+
"@inquirer/prompts": "^8.7.0",
|
|
68
|
+
"@oclif/core": "^4.14.0",
|
|
69
|
+
"@oclif/plugin-help": "^6.3.0",
|
|
71
70
|
"@sanity-labs/oclif-plugin-skills-flag": "^0.2.1",
|
|
72
|
-
"@sanity/blueprints": "^0.
|
|
71
|
+
"@sanity/blueprints": "^0.24.0",
|
|
73
72
|
"@sanity/blueprints-parser": "^0.5.0",
|
|
74
73
|
"@sanity/cli-build": "^5.2.0",
|
|
75
|
-
"@sanity/cli-core": "^3.
|
|
76
|
-
"@sanity/client": "^8.
|
|
74
|
+
"@sanity/cli-core": "^3.5.0",
|
|
75
|
+
"@sanity/client": "^8.4.0",
|
|
77
76
|
"adm-zip": "^0.6.0",
|
|
78
77
|
"array-treeify": "^0.2.0",
|
|
79
78
|
"cardinal": "^2.1.1",
|
|
80
79
|
"empathic": "^2.0.1",
|
|
81
|
-
"eventsource": "^5.1.
|
|
80
|
+
"eventsource": "^5.1.1",
|
|
82
81
|
"groq-js": "^2.0.0",
|
|
83
82
|
"jiti": "^2.7.0",
|
|
84
83
|
"mime-types": "^3.0.2",
|
|
@@ -86,38 +85,38 @@
|
|
|
86
85
|
"signal-exit": "^4.1.0",
|
|
87
86
|
"strip-ansi": "^7.2.0",
|
|
88
87
|
"tar-fs": "^3.1.3",
|
|
89
|
-
"tar-stream": "^3.2.
|
|
90
|
-
"vite": "^8.2.
|
|
88
|
+
"tar-stream": "^3.2.1",
|
|
89
|
+
"vite": "^8.2.2",
|
|
91
90
|
"ws": "^8.21.3",
|
|
92
91
|
"xdg-basedir": "^5.1.0"
|
|
93
92
|
},
|
|
94
93
|
"devDependencies": {
|
|
95
|
-
"@biomejs/biome": "2.5.
|
|
94
|
+
"@biomejs/biome": "2.5.11",
|
|
96
95
|
"@codemirror/lang-json": "^6.0.2",
|
|
96
|
+
"@codemirror/language": "^6.12.4",
|
|
97
97
|
"@codemirror/state": "^6.7.1",
|
|
98
98
|
"@enhance/store": "^1.0.2",
|
|
99
99
|
"@lezer/highlight": "^1.2.3",
|
|
100
|
-
"@oclif/test": "^4.
|
|
100
|
+
"@oclif/test": "^4.2.0",
|
|
101
101
|
"@playwright/test": "^1.62.1",
|
|
102
102
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
103
|
-
"@sanity/
|
|
104
|
-
"@
|
|
103
|
+
"@sanity-labs/design-tokens": "^0.0.2-alpha.2",
|
|
104
|
+
"@sanity/functions": "^1.7.1",
|
|
105
105
|
"@types/cardinal": "^2.1.1",
|
|
106
106
|
"@types/mime-types": "^3.0.1",
|
|
107
107
|
"@types/node": "^22",
|
|
108
108
|
"@types/tar-fs": "^2.0.4",
|
|
109
|
-
"@types/tar-stream": "^3.1.4",
|
|
110
109
|
"@types/ws": "^8.18.1",
|
|
111
|
-
"@vitest/coverage-v8": "4.1.
|
|
110
|
+
"@vitest/coverage-v8": "4.1.11",
|
|
112
111
|
"codemirror": "^6.0.2",
|
|
113
112
|
"mentoss": "^0.13.0",
|
|
114
|
-
"oclif": "^4.
|
|
115
|
-
"pretty-bytes": "^7.1.
|
|
116
|
-
"pretty-ms": "^9.3.
|
|
117
|
-
"rollup": "^4.
|
|
113
|
+
"oclif": "^4.24.0",
|
|
114
|
+
"pretty-bytes": "^7.1.2",
|
|
115
|
+
"pretty-ms": "^9.3.1",
|
|
116
|
+
"rollup": "^4.63.1",
|
|
118
117
|
"shx": "^0.4.0",
|
|
119
118
|
"typescript": "^7.0.2",
|
|
120
|
-
"vitest": "4.1.
|
|
119
|
+
"vitest": "4.1.11"
|
|
121
120
|
},
|
|
122
121
|
"oclif": {
|
|
123
122
|
"bin": "sanity-run",
|