@sanity/runtime-cli 14.1.2 → 14.2.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/README.md CHANGED
@@ -20,7 +20,7 @@ $ npm install -g @sanity/runtime-cli
20
20
  $ sanity-run COMMAND
21
21
  running command...
22
22
  $ sanity-run (--version)
23
- @sanity/runtime-cli/14.1.2 linux-x64 node-v24.13.1
23
+ @sanity/runtime-cli/14.2.0 linux-x64 node-v24.13.1
24
24
  $ sanity-run --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity-run COMMAND
@@ -98,7 +98,7 @@ EXAMPLES
98
98
  $ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
99
99
  ```
100
100
 
101
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.1.2/src/commands/blueprints/add.ts)_
101
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.2.0/src/commands/blueprints/add.ts)_
102
102
 
103
103
  ## `sanity-run blueprints config`
104
104
 
@@ -133,7 +133,7 @@ EXAMPLES
133
133
  $ sanity-run blueprints config --edit --project-id <projectId> --stack <name-or-id>
134
134
  ```
135
135
 
136
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v14.1.2/src/commands/blueprints/config.ts)_
136
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v14.2.0/src/commands/blueprints/config.ts)_
137
137
 
138
138
  ## `sanity-run blueprints deploy`
139
139
 
@@ -166,7 +166,7 @@ EXAMPLES
166
166
  $ sanity-run blueprints deploy --no-wait
167
167
  ```
168
168
 
169
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.1.2/src/commands/blueprints/deploy.ts)_
169
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.2.0/src/commands/blueprints/deploy.ts)_
170
170
 
171
171
  ## `sanity-run blueprints destroy`
172
172
 
@@ -198,7 +198,7 @@ EXAMPLES
198
198
  $ sanity-run blueprints destroy --stack <name-or-id> --project-id <projectId> --force --no-wait
199
199
  ```
200
200
 
201
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.1.2/src/commands/blueprints/destroy.ts)_
201
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.2.0/src/commands/blueprints/destroy.ts)_
202
202
 
203
203
  ## `sanity-run blueprints doctor`
204
204
 
@@ -224,7 +224,7 @@ DESCRIPTION
224
224
  issues.
225
225
  ```
226
226
 
227
- _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v14.1.2/src/commands/blueprints/doctor.ts)_
227
+ _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v14.2.0/src/commands/blueprints/doctor.ts)_
228
228
 
229
229
  ## `sanity-run blueprints info`
230
230
 
@@ -254,7 +254,7 @@ EXAMPLES
254
254
  $ sanity-run blueprints info --stack <name-or-id>
255
255
  ```
256
256
 
257
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v14.1.2/src/commands/blueprints/info.ts)_
257
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v14.2.0/src/commands/blueprints/info.ts)_
258
258
 
259
259
  ## `sanity-run blueprints init [DIR]`
260
260
 
@@ -304,7 +304,7 @@ EXAMPLES
304
304
  $ sanity-run blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
305
305
  ```
306
306
 
307
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v14.1.2/src/commands/blueprints/init.ts)_
307
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v14.2.0/src/commands/blueprints/init.ts)_
308
308
 
309
309
  ## `sanity-run blueprints logs`
310
310
 
@@ -333,7 +333,7 @@ EXAMPLES
333
333
  $ sanity-run blueprints logs --watch
334
334
  ```
335
335
 
336
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.1.2/src/commands/blueprints/logs.ts)_
336
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.2.0/src/commands/blueprints/logs.ts)_
337
337
 
338
338
  ## `sanity-run blueprints plan`
339
339
 
@@ -359,7 +359,7 @@ EXAMPLES
359
359
  $ sanity-run blueprints plan
360
360
  ```
361
361
 
362
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v14.1.2/src/commands/blueprints/plan.ts)_
362
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v14.2.0/src/commands/blueprints/plan.ts)_
363
363
 
364
364
  ## `sanity-run blueprints stacks`
365
365
 
@@ -388,7 +388,7 @@ EXAMPLES
388
388
  $ sanity-run blueprints stacks --organization-id <organizationId>
389
389
  ```
390
390
 
391
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v14.1.2/src/commands/blueprints/stacks.ts)_
391
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v14.2.0/src/commands/blueprints/stacks.ts)_
392
392
 
393
393
  ## `sanity-run functions add`
394
394
 
@@ -437,7 +437,7 @@ EXAMPLES
437
437
  $ sanity-run functions add --name my-function --type document-create --type document-update --lang js
438
438
  ```
439
439
 
440
- _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.1.2/src/commands/functions/add.ts)_
440
+ _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.2.0/src/commands/functions/add.ts)_
441
441
 
442
442
  ## `sanity-run functions dev`
443
443
 
@@ -471,7 +471,7 @@ EXAMPLES
471
471
  $ sanity-run functions dev --timeout 60
472
472
  ```
473
473
 
474
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v14.1.2/src/commands/functions/dev.ts)_
474
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v14.2.0/src/commands/functions/dev.ts)_
475
475
 
476
476
  ## `sanity-run functions env add NAME KEY VALUE`
477
477
 
@@ -498,7 +498,7 @@ EXAMPLES
498
498
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
499
499
  ```
500
500
 
501
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.1.2/src/commands/functions/env/add.ts)_
501
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.2.0/src/commands/functions/env/add.ts)_
502
502
 
503
503
  ## `sanity-run functions env list NAME`
504
504
 
@@ -522,7 +522,7 @@ EXAMPLES
522
522
  $ sanity-run functions env list MyFunction
523
523
  ```
524
524
 
525
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v14.1.2/src/commands/functions/env/list.ts)_
525
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v14.2.0/src/commands/functions/env/list.ts)_
526
526
 
527
527
  ## `sanity-run functions env remove NAME KEY`
528
528
 
@@ -548,7 +548,7 @@ EXAMPLES
548
548
  $ sanity-run functions env remove MyFunction API_URL
549
549
  ```
550
550
 
551
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v14.1.2/src/commands/functions/env/remove.ts)_
551
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v14.2.0/src/commands/functions/env/remove.ts)_
552
552
 
553
553
  ## `sanity-run functions logs [NAME]`
554
554
 
@@ -588,7 +588,7 @@ EXAMPLES
588
588
  $ sanity-run functions logs <name> --delete
589
589
  ```
590
590
 
591
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.1.2/src/commands/functions/logs.ts)_
591
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.2.0/src/commands/functions/logs.ts)_
592
592
 
593
593
  ## `sanity-run functions test [NAME]`
594
594
 
@@ -642,7 +642,7 @@ EXAMPLES
642
642
  $ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
643
643
  ```
644
644
 
645
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v14.1.2/src/commands/functions/test.ts)_
645
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v14.2.0/src/commands/functions/test.ts)_
646
646
 
647
647
  ## `sanity-run help [COMMAND]`
648
648
 
@@ -2,23 +2,17 @@ import crypto from 'node:crypto';
2
2
  import fs from 'node:fs';
3
3
  import os from 'node:os';
4
4
  import path from 'node:path';
5
- import { cwd } from 'node:process';
6
5
  import AdmZip from 'adm-zip';
7
- import getFolderSize from 'get-folder-size';
8
6
  import config from '../../config.js';
9
7
  import { detectNativeModules } from '../../utils/functions/detect-native-modules.js';
10
- import { resolveResourceDependencies } from '../../utils/functions/resolve-dependencies.js';
11
- import { shouldAutoResolveDependencies } from '../../utils/functions/should-auto-resolve-deps.js';
12
- import { shouldTranspileFunction } from '../../utils/functions/should-transpile.js';
8
+ import { prepareAsset } from '../../utils/functions/prepare-asset.js';
13
9
  import getHeaders from '../../utils/get-headers.js';
14
10
  import { createTracedFetch } from '../../utils/traced-fetch.js';
15
- import { transpileFunction } from '../../utils/transpile/transpile-function.js';
16
11
  import { isLocalFunctionCollection } from '../../utils/types.js';
17
12
  const { apiUrl } = config;
18
13
  const ASSETS_URL = `${apiUrl}vX/blueprints/assets`;
19
14
  export const ASSET_CHECK_URL = `${ASSETS_URL}/check`;
20
15
  export const ASSET_STASH_URL = `${ASSETS_URL}/stash`;
21
- const MAX_ASSET_SIZE = 209_715_200; // 200 MB in bytes
22
16
  export async function stashAsset({ resource, auth, logger, }) {
23
17
  const isCollection = isLocalFunctionCollection(resource);
24
18
  const functions = isCollection ? resource.functions : [resource];
@@ -26,7 +20,7 @@ export async function stashAsset({ resource, auth, logger, }) {
26
20
  const prepareErrors = [];
27
21
  try {
28
22
  for (const func of functions) {
29
- const prepResult = await prepareAsset({ resource: func, auth });
23
+ const prepResult = await prepareAsset({ resource: func });
30
24
  if (prepResult.success && prepResult.outputPath && prepResult.cleanup) {
31
25
  combinedAsset.push({
32
26
  name: func.name,
@@ -82,38 +76,6 @@ export async function stashAsset({ resource, auth, logger, }) {
82
76
  return { success: false, error: err instanceof Error ? err.message : `${err}` };
83
77
  }
84
78
  }
85
- async function prepareAsset({ resource, }) {
86
- if (!resource.src)
87
- throw new Error('Resource src is required');
88
- let functionPath = path.join(cwd(), resource.src);
89
- let cleanup = async () => { };
90
- const shouldTranspile = await shouldTranspileFunction(resource);
91
- if (shouldTranspile) {
92
- try {
93
- const result = await transpileFunction(resource);
94
- functionPath = result.outputDir;
95
- cleanup = result.cleanup;
96
- }
97
- catch (err) {
98
- return { success: false, error: err instanceof Error ? err.message : `${err}` };
99
- }
100
- }
101
- const shouldResolveDependencies = await shouldAutoResolveDependencies(resource);
102
- if (shouldResolveDependencies) {
103
- await resolveResourceDependencies(resource, shouldTranspile);
104
- }
105
- try {
106
- // This works for files and folders
107
- const size = await getFolderSize.loose(functionPath);
108
- if (size > MAX_ASSET_SIZE) {
109
- throw new Error('Resource is larger than max asset size of 200 MB.');
110
- }
111
- return { success: true, outputPath: functionPath, cleanup };
112
- }
113
- catch (err) {
114
- return { success: false, error: err instanceof Error ? err.message : `${err}` };
115
- }
116
- }
117
79
  async function combineAssets(allAssets) {
118
80
  const combinedPath = path.join(os.tmpdir(), `assets-${Date.now()}`);
119
81
  await fs.promises.mkdir(combinedPath, { recursive: true });
@@ -1,11 +1,11 @@
1
1
  import type { Blueprint } from '@sanity/blueprints-parser';
2
2
  import type { Logger } from '../../utils/logger.js';
3
- import type { AuthParams, ScopeType, Stack, StackMutation } from '../../utils/types.js';
3
+ import type { AuthParams, ScopeType, Stack, StackMutation, StackSummary } from '../../utils/types.js';
4
4
  export declare const stacksUrl: string;
5
5
  type ListStacksResponse = {
6
6
  ok: true;
7
7
  error: null;
8
- stacks: Stack[];
8
+ stacks: StackSummary[];
9
9
  } | {
10
10
  ok: false;
11
11
  error: string;
@@ -0,0 +1,12 @@
1
+ import { LocalBlueprintCommand } from '../../baseCommands.js';
2
+ export default class BuildCommand extends LocalBlueprintCommand<typeof BuildCommand> {
3
+ static summary: string;
4
+ static hidden: boolean;
5
+ static args: {
6
+ name: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
7
+ };
8
+ static flags: {
9
+ 'out-dir': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ };
11
+ run(): Promise<void>;
12
+ }
@@ -0,0 +1,26 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { LocalBlueprintCommand } from '../../baseCommands.js';
3
+ import { functionBuildCore } from '../../cores/functions/build.js';
4
+ import { Logger } from '../../utils/logger.js';
5
+ export default class BuildCommand extends LocalBlueprintCommand {
6
+ static summary = 'Build Sanity Function(s) to zip archives';
7
+ static hidden = true;
8
+ static args = {
9
+ name: Args.string({ description: 'The name of the Sanity Function', required: false }),
10
+ };
11
+ static flags = {
12
+ 'out-dir': Flags.string({ char: 'o', description: 'Output directory for zip files' }),
13
+ };
14
+ async run() {
15
+ const { success, error } = await functionBuildCore({
16
+ bin: this.config.bin,
17
+ log: Logger(this.log.bind(this), this.flags),
18
+ args: { name: this.args.name },
19
+ flags: this.flags,
20
+ blueprint: this.blueprint,
21
+ validateResources: this.flags['validate-resources'],
22
+ });
23
+ if (!success)
24
+ this.error(error);
25
+ }
26
+ }
@@ -40,12 +40,15 @@ export async function blueprintDeployCore(options) {
40
40
  const warnTimer = setTimeout(() => {
41
41
  fnSpinner.text = `Still processing ${resource.name}, this can take a moment...`;
42
42
  }, warnTimeoutMs);
43
+ let assetTimeoutTimer;
43
44
  let result;
44
45
  try {
45
46
  result = await Promise.race([
46
47
  stashAsset({ resource, auth, logger: log }),
47
- sleep(assetTimeoutMs).then(() => {
48
- throw new Error(`Processing ${resource.name} timed out after ${assetTimeoutS}s`);
48
+ new Promise((_, reject) => {
49
+ assetTimeoutTimer = setTimeout(() => {
50
+ reject(new Error(`Processing ${resource.name} timed out after ${assetTimeoutS}s`));
51
+ }, assetTimeoutMs);
49
52
  }),
50
53
  ]);
51
54
  }
@@ -56,6 +59,7 @@ export async function blueprintDeployCore(options) {
56
59
  }
57
60
  finally {
58
61
  clearTimeout(warnTimer);
62
+ clearTimeout(assetTimeoutTimer);
59
63
  }
60
64
  if (result.success && result.assetId) {
61
65
  resource.src = result.assetId;
@@ -0,0 +1,12 @@
1
+ import type { ReadBlueprintResult } from '../../actions/blueprints/blueprint.js';
2
+ import type { CoreConfig, CoreResult } from '../index.js';
3
+ export interface FunctionBuildOptions extends CoreConfig {
4
+ blueprint: ReadBlueprintResult;
5
+ args: {
6
+ name: string | undefined;
7
+ };
8
+ flags: {
9
+ 'out-dir'?: string;
10
+ };
11
+ }
12
+ export declare function functionBuildCore(options: FunctionBuildOptions): Promise<CoreResult>;
@@ -0,0 +1,61 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { pathToZip } from '../../actions/blueprints/assets.js';
4
+ import { findFunctionInBlueprint } from '../../utils/find-function.js';
5
+ import { detectNativeModules } from '../../utils/functions/detect-native-modules.js';
6
+ import { prepareAsset } from '../../utils/functions/prepare-asset.js';
7
+ import { isLocalFunctionResource } from '../../utils/types.js';
8
+ export async function functionBuildCore(options) {
9
+ const { blueprint, log, args, flags } = options;
10
+ const { parsedBlueprint } = blueprint;
11
+ const allFunctions = (parsedBlueprint.resources ?? []).filter(isLocalFunctionResource);
12
+ if (allFunctions.length === 0) {
13
+ return { success: false, error: 'No functions found in blueprint.' };
14
+ }
15
+ let functions;
16
+ if (args.name) {
17
+ const resource = findFunctionInBlueprint(parsedBlueprint, args.name);
18
+ functions = [resource];
19
+ }
20
+ else {
21
+ functions = allFunctions;
22
+ }
23
+ const outDir = flags['out-dir'] || path.join(path.dirname(blueprint.fileInfo.blueprintFilePath), '.build');
24
+ await fs.promises.mkdir(outDir, { recursive: true });
25
+ const errors = [];
26
+ const built = [];
27
+ for (const resource of functions) {
28
+ const spinner = log.ora(`Building ${resource.name}...`).start();
29
+ const prepResult = await prepareAsset({ resource });
30
+ if (!prepResult.success || !prepResult.outputPath) {
31
+ spinner.fail(`Failed to build ${resource.name}`);
32
+ errors.push({ name: resource.name, error: prepResult.error ?? 'Unknown error' });
33
+ continue;
34
+ }
35
+ const zip = await pathToZip(prepResult.outputPath);
36
+ const nativeModules = detectNativeModules(zip);
37
+ if (nativeModules?.length > 0) {
38
+ log.warn(`Native modules detected in ${resource.name}: ${nativeModules.join(', ')}`);
39
+ }
40
+ const buffer = zip.toBuffer();
41
+ const zipPath = path.join(outDir, `${resource.name}.zip`);
42
+ await fs.promises.writeFile(zipPath, buffer);
43
+ if (prepResult.cleanup) {
44
+ await prepResult.cleanup();
45
+ }
46
+ const sizeMb = (buffer.length / 1_048_576).toFixed(1);
47
+ spinner.succeed(`${resource.name}.zip (${sizeMb} MB) → ${zipPath}`);
48
+ built.push({ name: resource.name, size: buffer.length, path: zipPath });
49
+ }
50
+ if (errors.length > 0 && built.length === 0) {
51
+ return {
52
+ success: false,
53
+ error: errors.map((e) => `${e.name}: ${e.error}`).join('\n'),
54
+ };
55
+ }
56
+ if (errors.length > 0) {
57
+ log.warn(`${errors.length} function(s) failed to build`);
58
+ }
59
+ log(`\nBuild complete: ${built.length} function(s)`);
60
+ return { success: true };
61
+ }
@@ -1,5 +1,7 @@
1
1
  export type { FunctionAddOptions } from './add.js';
2
2
  export { functionAddCore } from './add.js';
3
+ export type { FunctionBuildOptions } from './build.js';
4
+ export { functionBuildCore } from './build.js';
3
5
  export type { FunctionDevOptions } from './dev.js';
4
6
  export { functionDevCore } from './dev.js';
5
7
  export type { FunctionEnvAddOptions } from './env/add.js';
@@ -1,4 +1,5 @@
1
1
  export { functionAddCore } from './add.js';
2
+ export { functionBuildCore } from './build.js';
2
3
  export { functionDevCore } from './dev.js';
3
4
  export { functionEnvAddCore } from './env/add.js';
4
5
  export { functionEnvListCore } from './env/list.js';
@@ -1,10 +1,10 @@
1
1
  import type { Blueprint, Resource } from '@sanity/blueprints-parser';
2
2
  import type { DeploymentPlan } from '../../actions/blueprints/stacks.js';
3
- import { type BlueprintResourceRecord, type Stack } from '../types.js';
3
+ import { type BlueprintResourceRecord, type Stack, type StackSummary } from '../types.js';
4
4
  export declare function formatTitle(title: string, name: string): string;
5
5
  export declare function formatDeployedResourceTree(resources: BlueprintResourceRecord[] | undefined, verbose?: boolean): string;
6
6
  export declare function formatResourceTree(resources: Resource[] | undefined, verbose?: boolean): string;
7
- export declare function formatStackInfo(stack: Stack | Blueprint, isCurrentStack?: boolean): string;
8
- export declare function formatStacksListing(stacks: Stack[], currentStackId?: string): string;
7
+ export declare function formatStackInfo(stack: Stack | StackSummary | Blueprint, isCurrentStack?: boolean): string;
8
+ export declare function formatStacksListing(stacks: StackSummary[], currentStackId?: string): string;
9
9
  export declare function hasActionableChanges(deploymentPlan: DeploymentPlan): boolean;
10
10
  export declare function formatDeploymentPlan(deploymentPlan: DeploymentPlan): string;
@@ -165,8 +165,9 @@ export function formatStackInfo(stack, isCurrentStack = false) {
165
165
  output.push('Local Blueprint');
166
166
  }
167
167
  const infoOutput = [];
168
- if (stack.resources) {
169
- infoOutput.push(`${stack.resources.length} resource${stack.resources.length === 1 ? '' : 's'}`);
168
+ const resourceCount = 'resourceCount' in stack ? stack.resourceCount : stack.resources?.length;
169
+ if (resourceCount != null) {
170
+ infoOutput.push(`${resourceCount} resource${resourceCount === 1 ? '' : 's'}`);
170
171
  }
171
172
  else {
172
173
  infoOutput.push('No resources');
@@ -95,7 +95,7 @@ export async function promptForStack({ projectId, token, logger, }) {
95
95
  stackChoices.push({ name: styleText('bold', 'New Stack ✨'), value: NEW_STACK_ID });
96
96
  stackChoices.push(new Separator(styleText('underline', 'Use an existing Stack:')));
97
97
  stackChoices.push(...stacks.map((s) => ({
98
- name: `"${s.name}" ${niceId(s.id)} ${styleText('dim', `(${s.resources.length} res)`)}`,
98
+ name: `"${s.name}" ${niceId(s.id)} ${styleText('dim', `(${s.resourceCount} res)`)}`,
99
99
  value: s.id,
100
100
  })));
101
101
  pickedStackId = await select({
@@ -0,0 +1,9 @@
1
+ import type { CollectionFunction, FunctionResource } from '../types.js';
2
+ export declare function prepareAsset({ resource, }: {
3
+ resource: FunctionResource | CollectionFunction;
4
+ }): Promise<{
5
+ success: boolean;
6
+ outputPath?: string;
7
+ cleanup?: () => Promise<void>;
8
+ error?: string;
9
+ }>;
@@ -0,0 +1,39 @@
1
+ import path from 'node:path';
2
+ import { cwd } from 'node:process';
3
+ import getFolderSize from 'get-folder-size';
4
+ import { transpileFunction } from '../transpile/transpile-function.js';
5
+ import { resolveResourceDependencies } from './resolve-dependencies.js';
6
+ import { shouldAutoResolveDependencies } from './should-auto-resolve-deps.js';
7
+ import { shouldTranspileFunction } from './should-transpile.js';
8
+ const MAX_ASSET_SIZE = 209_715_200; // 200 MB in bytes
9
+ export async function prepareAsset({ resource, }) {
10
+ if (!resource.src)
11
+ throw new Error('Resource src is required');
12
+ let functionPath = path.join(cwd(), resource.src);
13
+ let cleanup = async () => { };
14
+ const shouldTranspile = await shouldTranspileFunction(resource);
15
+ if (shouldTranspile) {
16
+ try {
17
+ const result = await transpileFunction(resource);
18
+ functionPath = result.outputDir;
19
+ cleanup = result.cleanup;
20
+ }
21
+ catch (err) {
22
+ return { success: false, error: err instanceof Error ? err.message : `${err}` };
23
+ }
24
+ }
25
+ const shouldResolveDependencies = await shouldAutoResolveDependencies(resource);
26
+ if (shouldResolveDependencies) {
27
+ await resolveResourceDependencies(resource, shouldTranspile);
28
+ }
29
+ try {
30
+ const size = await getFolderSize.loose(functionPath);
31
+ if (size > MAX_ASSET_SIZE) {
32
+ throw new Error('Resource is larger than max asset size of 200 MB.');
33
+ }
34
+ return { success: true, outputPath: functionPath, cleanup };
35
+ }
36
+ catch (err) {
37
+ return { success: false, error: err instanceof Error ? err.message : `${err}` };
38
+ }
39
+ }
@@ -114,16 +114,21 @@ export interface FunctionsCollection extends BlueprintResource {
114
114
  export interface CorsResource extends BlueprintResource {
115
115
  origin?: string;
116
116
  }
117
- export interface Stack {
117
+ interface StackBase {
118
118
  id: string;
119
119
  name: string;
120
120
  displayName: string;
121
121
  scopeType: ScopeType;
122
122
  scopeId: string;
123
- resources: Array<BlueprintResourceRecord>;
123
+ recentOperation?: StackOperation;
124
124
  createdAt?: string;
125
125
  updatedAt?: string;
126
- recentOperation?: StackOperation;
126
+ }
127
+ export interface Stack extends StackBase {
128
+ resources: Array<BlueprintResourceRecord>;
129
+ }
130
+ export interface StackSummary extends StackBase {
131
+ resourceCount: number;
127
132
  }
128
133
  /** @internal */
129
134
  export interface StackOperation {
@@ -1283,6 +1283,84 @@
1283
1283
  "add.js"
1284
1284
  ]
1285
1285
  },
1286
+ "functions:build": {
1287
+ "aliases": [],
1288
+ "args": {
1289
+ "name": {
1290
+ "description": "The name of the Sanity Function",
1291
+ "name": "name",
1292
+ "required": false
1293
+ }
1294
+ },
1295
+ "flags": {
1296
+ "json": {
1297
+ "description": "Format output as json.",
1298
+ "hidden": true,
1299
+ "name": "json",
1300
+ "allowNo": false,
1301
+ "type": "boolean"
1302
+ },
1303
+ "path": {
1304
+ "aliases": [
1305
+ "blueprint-path"
1306
+ ],
1307
+ "char": "p",
1308
+ "description": "Path to a Blueprint file or directory containing one",
1309
+ "env": "SANITY_BLUEPRINT_PATH",
1310
+ "hidden": true,
1311
+ "name": "path",
1312
+ "hasDynamicHelp": false,
1313
+ "multiple": false,
1314
+ "type": "option"
1315
+ },
1316
+ "trace": {
1317
+ "description": "Trace output",
1318
+ "hidden": true,
1319
+ "name": "trace",
1320
+ "allowNo": false,
1321
+ "type": "boolean"
1322
+ },
1323
+ "validate-resources": {
1324
+ "description": "Validate resources",
1325
+ "hidden": true,
1326
+ "name": "validate-resources",
1327
+ "allowNo": true,
1328
+ "type": "boolean"
1329
+ },
1330
+ "verbose": {
1331
+ "description": "Verbose output",
1332
+ "hidden": true,
1333
+ "name": "verbose",
1334
+ "allowNo": false,
1335
+ "type": "boolean"
1336
+ },
1337
+ "out-dir": {
1338
+ "char": "o",
1339
+ "description": "Output directory for zip files",
1340
+ "name": "out-dir",
1341
+ "hasDynamicHelp": false,
1342
+ "multiple": false,
1343
+ "type": "option"
1344
+ }
1345
+ },
1346
+ "hasDynamicHelp": false,
1347
+ "hidden": true,
1348
+ "hiddenAliases": [],
1349
+ "id": "functions:build",
1350
+ "pluginAlias": "@sanity/runtime-cli",
1351
+ "pluginName": "@sanity/runtime-cli",
1352
+ "pluginType": "core",
1353
+ "strict": true,
1354
+ "summary": "Build Sanity Function(s) to zip archives",
1355
+ "enableJsonFlag": true,
1356
+ "isESM": true,
1357
+ "relativePath": [
1358
+ "dist",
1359
+ "commands",
1360
+ "functions",
1361
+ "build.js"
1362
+ ]
1363
+ },
1286
1364
  "functions:dev": {
1287
1365
  "aliases": [],
1288
1366
  "args": {},
@@ -2083,5 +2161,5 @@
2083
2161
  ]
2084
2162
  }
2085
2163
  },
2086
- "version": "14.1.2"
2164
+ "version": "14.2.0"
2087
2165
  }
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": "14.1.2",
4
+ "version": "14.2.0",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",