@sanity/runtime-cli 17.14.0-next.g1c33580 → 17.14.0-next.g792820f

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
@@ -90,7 +90,7 @@ EXAMPLES
90
90
  $ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
91
91
  ```
92
92
 
93
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/blueprints/add.ts)_
93
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/blueprints/add.ts)_
94
94
 
95
95
  ## `sanity-run blueprints config`
96
96
 
@@ -127,7 +127,7 @@ EXAMPLES
127
127
  $ sanity-run blueprints config --edit --project-id <projectId> --stack <name-or-id>
128
128
  ```
129
129
 
130
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/blueprints/config.ts)_
130
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/blueprints/config.ts)_
131
131
 
132
132
  ## `sanity-run blueprints deploy`
133
133
 
@@ -183,7 +183,7 @@ EXAMPLES
183
183
  $ sanity-run blueprints deploy --new-stack-name <new-name>
184
184
  ```
185
185
 
186
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/blueprints/deploy.ts)_
186
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/blueprints/deploy.ts)_
187
187
 
188
188
  ## `sanity-run blueprints destroy`
189
189
 
@@ -221,7 +221,7 @@ EXAMPLES
221
221
  $ sanity-run blueprints destroy --stack <name-or-id> --project-id <projectId> --force --no-wait
222
222
  ```
223
223
 
224
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/blueprints/destroy.ts)_
224
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/blueprints/destroy.ts)_
225
225
 
226
226
  ## `sanity-run blueprints doctor`
227
227
 
@@ -253,7 +253,7 @@ EXAMPLES
253
253
  $ sanity-run blueprints doctor --fix
254
254
  ```
255
255
 
256
- _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/blueprints/doctor.ts)_
256
+ _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/blueprints/doctor.ts)_
257
257
 
258
258
  ## `sanity-run blueprints info`
259
259
 
@@ -291,7 +291,7 @@ EXAMPLES
291
291
  $ sanity-run blueprints info --organization-id <orgId> --stack <name-or-id>
292
292
  ```
293
293
 
294
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/blueprints/info.ts)_
294
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/blueprints/info.ts)_
295
295
 
296
296
  ## `sanity-run blueprints init [DIR]`
297
297
 
@@ -355,7 +355,7 @@ EXAMPLES
355
355
  $ sanity-run blueprints init old-stack --type <json|js|ts> --project-id <projectId> --stack-id <existingStackId>
356
356
  ```
357
357
 
358
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/blueprints/init.ts)_
358
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/blueprints/init.ts)_
359
359
 
360
360
  ## `sanity-run blueprints logs`
361
361
 
@@ -401,7 +401,7 @@ EXAMPLES
401
401
  $ sanity-run blueprints logs --before 2026-05-01T00:00:00Z
402
402
  ```
403
403
 
404
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/blueprints/logs.ts)_
404
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/blueprints/logs.ts)_
405
405
 
406
406
  ## `sanity-run blueprints mint-deploy-token`
407
407
 
@@ -446,7 +446,7 @@ EXAMPLES
446
446
  $ sanity-run blueprints mint-deploy-token --organization-id <orgId>
447
447
  ```
448
448
 
449
- _See code: [src/commands/blueprints/mint-deploy-token.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/blueprints/mint-deploy-token.ts)_
449
+ _See code: [src/commands/blueprints/mint-deploy-token.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/blueprints/mint-deploy-token.ts)_
450
450
 
451
451
  ## `sanity-run blueprints plan`
452
452
 
@@ -479,7 +479,7 @@ EXAMPLES
479
479
  $ sanity-run blueprints plan --organization-id <orgId> --stack <name-or-id>
480
480
  ```
481
481
 
482
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/blueprints/plan.ts)_
482
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/blueprints/plan.ts)_
483
483
 
484
484
  ## `sanity-run blueprints promote`
485
485
 
@@ -515,7 +515,7 @@ EXAMPLES
515
515
  $ sanity-run blueprints promote --new-stack-name <new-name>
516
516
  ```
517
517
 
518
- _See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/blueprints/promote.ts)_
518
+ _See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/blueprints/promote.ts)_
519
519
 
520
520
  ## `sanity-run blueprints stacks`
521
521
 
@@ -556,7 +556,7 @@ EXAMPLES
556
556
  $ sanity-run blueprints stacks --organization-id <organizationId> --include-projects
557
557
  ```
558
558
 
559
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/blueprints/stacks.ts)_
559
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/blueprints/stacks.ts)_
560
560
 
561
561
  ## `sanity-run functions add`
562
562
 
@@ -608,7 +608,7 @@ EXAMPLES
608
608
  $ sanity-run functions add --name my-function --type document-create --type document-update --lang js
609
609
  ```
610
610
 
611
- _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/functions/add.ts)_
611
+ _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/functions/add.ts)_
612
612
 
613
613
  ## `sanity-run functions dev`
614
614
 
@@ -643,7 +643,7 @@ EXAMPLES
643
643
  $ sanity-run functions dev --timeout 60
644
644
  ```
645
645
 
646
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/functions/dev.ts)_
646
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/functions/dev.ts)_
647
647
 
648
648
  ## `sanity-run functions env add NAME KEY VALUE`
649
649
 
@@ -676,7 +676,7 @@ EXAMPLES
676
676
  $ sanity-run functions env add --stack <name-or-id> MyFunction API_URL https://api.example.com/
677
677
  ```
678
678
 
679
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/functions/env/add.ts)_
679
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/functions/env/add.ts)_
680
680
 
681
681
  ## `sanity-run functions env list NAME`
682
682
 
@@ -706,7 +706,7 @@ EXAMPLES
706
706
  $ sanity-run functions env list --stack <name-or-id> MyFunction
707
707
  ```
708
708
 
709
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/functions/env/list.ts)_
709
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/functions/env/list.ts)_
710
710
 
711
711
  ## `sanity-run functions env remove NAME KEY`
712
712
 
@@ -738,7 +738,7 @@ EXAMPLES
738
738
  $ sanity-run functions env remove --stack <name-or-id> MyFunction API_URL
739
739
  ```
740
740
 
741
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/functions/env/remove.ts)_
741
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/functions/env/remove.ts)_
742
742
 
743
743
  ## `sanity-run functions logs [NAME]`
744
744
 
@@ -778,7 +778,7 @@ EXAMPLES
778
778
  $ sanity-run functions logs <name> --delete
779
779
  ```
780
780
 
781
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/functions/logs.ts)_
781
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/functions/logs.ts)_
782
782
 
783
783
  ## `sanity-run functions test [NAME]`
784
784
 
@@ -836,7 +836,7 @@ EXAMPLES
836
836
  $ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
837
837
  ```
838
838
 
839
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g1c33580/src/commands/functions/test.ts)_
839
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.14.0-next.g792820f/src/commands/functions/test.ts)_
840
840
 
841
841
  ## `sanity-run help [COMMAND]`
842
842
 
@@ -1,7 +1,9 @@
1
1
  import { SANITY_FUNCTION_PREFIX } from '../../constants.js';
2
2
  import { resolveDeployedResources } from '../../utils/blueprints/resolve-deployed-resources.js';
3
3
  import { BUNDLE_SPECS, prepareBundleAsset, } from '../../utils/bundles/prepare-asset.js';
4
+ import { stampConfigVersion } from '../../utils/bundles/stamp-config-version.js';
4
5
  import { CODE_OPERATION_UNCONFIRMED, EXIT_OPERATION_UNCONFIRMED } from '../../utils/exit-codes.js';
6
+ import { extractDurableConfig } from '../../utils/functions/extract-durable-config.js';
5
7
  import { prepareAsset as prepareFunctionAsset } from '../../utils/functions/prepare-asset.js';
6
8
  import { runCommand } from '../../utils/package-manager.js';
7
9
  import { setupLogPolling } from './logs-polling.js';
@@ -20,6 +22,9 @@ const preDeployConfigs = [
20
22
  blueprintFileDir: options.blueprintFileDir,
21
23
  });
22
24
  },
25
+ async prepareResource(options) {
26
+ await stampConfigVersion(options.resource, options.blueprintFileDir);
27
+ },
23
28
  },
24
29
  {
25
30
  resourceType: (type) => type.startsWith(SANITY_FUNCTION_PREFIX),
@@ -30,6 +35,9 @@ const preDeployConfigs = [
30
35
  installer: options.installer,
31
36
  });
32
37
  },
38
+ async prepareResource(options) {
39
+ await extractDurableConfig(options.resource, options.blueprintFileDir);
40
+ },
33
41
  },
34
42
  ];
35
43
  function hasPreDeployResources(resources) {
@@ -47,6 +55,12 @@ export async function preDeploy(options) {
47
55
  const { resources, stackId, auth, blueprintFileDir, installer, fetchFn } = options;
48
56
  const resourceMetadata = [];
49
57
  if (hasPreDeployResources(resources)) {
58
+ for (const r of resources) {
59
+ const config = getPredeployConfig(r);
60
+ if (typeof config !== 'undefined' && typeof config.prepareResource === 'function') {
61
+ await config.prepareResource({ resource: r, blueprintFileDir });
62
+ }
63
+ }
50
64
  const preDeployStackResult = await preDeployStack(options);
51
65
  if (!preDeployStackResult.success) {
52
66
  return preDeployStackResult;
@@ -4,9 +4,7 @@ import { getStack, updateStack } from '../../actions/blueprints/stacks.js';
4
4
  import { waitForOperation } from '../../actions/blueprints/wait-for-operation.js';
5
5
  import { checkUserPermission } from '../../actions/sanity/access.js';
6
6
  import { getClientMetadata } from '../../utils/blueprints/deploy-metadata.js';
7
- import { extractDurableConfig } from '../../utils/blueprints/extract-durable-config.js';
8
7
  import { createHintCollector } from '../../utils/blueprints/hints.js';
9
- import { stampInstallationConfigVersion } from '../../utils/blueprints/stamp-installation-config-version.js';
10
8
  import { createWaitFor } from '../../utils/blueprints/wait-for.js';
11
9
  import { formatStudioUrls } from '../../utils/display/blueprints-formatting.js';
12
10
  import { check, niceId, severe } from '../../utils/display/presenters.js';
@@ -42,8 +40,6 @@ export async function blueprintDeployCore(options) {
42
40
  };
43
41
  }
44
42
  const resources = [...blueprint.resources];
45
- await extractDurableConfig(resources, blueprintFileDir);
46
- await stampInstallationConfigVersion(resources, blueprintFileDir);
47
43
  let spinner;
48
44
  const preDeployResult = await preDeploy({
49
45
  scopeType,
@@ -1,9 +1,9 @@
1
1
  import { dirname } from 'node:path';
2
2
  import { planStack, resolveStackIdByNameOrId } from '../../actions/blueprints/stacks.js';
3
- import { extractDurableConfig } from '../../utils/blueprints/extract-durable-config.js';
4
3
  import { createHintCollector } from '../../utils/blueprints/hints.js';
5
- import { stampInstallationConfigVersion } from '../../utils/blueprints/stamp-installation-config-version.js';
4
+ import { stampConfigVersion } from '../../utils/bundles/stamp-config-version.js';
6
5
  import { formatDeploymentPlan, formatResourceTree, hasActionableChanges, } from '../../utils/display/blueprints-formatting.js';
6
+ import { extractDurableConfig } from '../../utils/functions/extract-durable-config.js';
7
7
  import { runCommand } from '../../utils/package-manager.js';
8
8
  import { styleText } from '../../utils/style-text.js';
9
9
  import { getWarnings } from '../../utils/warnings.js';
@@ -12,8 +12,10 @@ export async function blueprintPlanCore(options) {
12
12
  const { verbose: _verbose = false } = flags;
13
13
  const { scopeType, scopeId, stackId: blueprintStackId, parsedBlueprint, resources, fileInfo, } = blueprint;
14
14
  log(`${styleText(['bold', 'blueBright'], 'Local Blueprint')} ${styleText('dim', `(${fileInfo.fileName})`)}`);
15
- await extractDurableConfig(resources, dirname(fileInfo.blueprintFilePath));
16
- await stampInstallationConfigVersion(resources, dirname(fileInfo.blueprintFilePath));
15
+ for (const resource of resources) {
16
+ await extractDurableConfig(resource, dirname(fileInfo.blueprintFilePath));
17
+ await stampConfigVersion(resource, dirname(fileInfo.blueprintFilePath));
18
+ }
17
19
  log(formatResourceTree(resources));
18
20
  if (!token || !scopeType || !scopeId) {
19
21
  log(styleText('dim', 'Unable to retrieve live Stack deployment for comparison'));
@@ -1,7 +1,7 @@
1
+ import type { BlueprintApplicationResource, BlueprintInstallationConfigResource, BlueprintStudioResource } from '@sanity/blueprints';
1
2
  import { type BuildStudioEventListener } from '@sanity/cli-build/_internal/build';
2
3
  import type { Output } from '@sanity/cli-core';
3
4
  import type { AssetPrepResult } from '../types.js';
4
- import type { BlueprintApplicationResource, BlueprintInstallationConfigResource, BlueprintStudioResource } from './types.js';
5
5
  export type BundleResource = BlueprintStudioResource | BlueprintApplicationResource | BlueprintInstallationConfigResource;
6
6
  type BuildContext<R extends BundleResource> = {
7
7
  resource: R;
@@ -0,0 +1,5 @@
1
+ import type { BlueprintResource } from '@sanity/blueprints';
2
+ /**
3
+ * Stamps the installed `sanity` version onto each media-library config resource and studio resource.
4
+ */
5
+ export declare const stampConfigVersion: (resource: BlueprintResource, blueprintFileDir: string) => Promise<void>;
@@ -0,0 +1,45 @@
1
+ import { resolve } from 'node:path';
2
+ import { getLocalPackageVersion } from '@sanity/cli-core/package-manager';
3
+ import { SANITY_INSTALLATION_CONFIG, SANITY_STUDIO } from '../../constants.js';
4
+ /**
5
+ * Stamps the installed `sanity` version onto each media-library config resource and studio resource.
6
+ */
7
+ export const stampConfigVersion = async (resource, blueprintFileDir) => {
8
+ let update;
9
+ let root;
10
+ if (resource.type === SANITY_INSTALLATION_CONFIG) {
11
+ const config = resource;
12
+ if (config.appType !== 'media-library')
13
+ return;
14
+ // Leave values included in the blueprint.
15
+ if (config.version !== undefined)
16
+ return;
17
+ root = config.root;
18
+ update = (version) => {
19
+ config.version = version;
20
+ };
21
+ }
22
+ else if (resource.type === SANITY_STUDIO) {
23
+ const config = resource;
24
+ // Leave values included in the blueprint.
25
+ if (config.autoUpdates?.version !== undefined)
26
+ return;
27
+ root = config.root;
28
+ update = (version) => {
29
+ if (config.autoUpdates) {
30
+ config.autoUpdates.version = version;
31
+ }
32
+ else {
33
+ config.autoUpdates = { enabled: true, version };
34
+ }
35
+ };
36
+ }
37
+ if (update && root) {
38
+ const workDir = resolve(blueprintFileDir, root);
39
+ const version = await getLocalPackageVersion('sanity', workDir);
40
+ if (!version) {
41
+ throw new Error(`Unable to determine the installed 'sanity' version for resource '${resource.name}'; is 'sanity' installed in '${root}'?`);
42
+ }
43
+ update(version);
44
+ }
45
+ };
@@ -2,7 +2,7 @@ import { type BlueprintResource } from '@sanity/blueprints';
2
2
  /**
3
3
  * Extracts the blueprint config from the function source code and mutates it to the resource object.
4
4
  * This is used for durable functions that may not have a config defined in the blueprint.
5
- * @param resources
5
+ * @param resource
6
6
  * @param blueprintFileDir
7
7
  */
8
- export declare const extractDurableConfig: (resources: BlueprintResource[], blueprintFileDir: string) => Promise<void>;
8
+ export declare const extractDurableConfig: (resource: BlueprintResource, blueprintFileDir: string) => Promise<void>;
@@ -0,0 +1,58 @@
1
+ import { resolve } from 'node:path';
2
+ import { pathToFileURL } from 'node:url';
3
+ import { validateDurableFunction, } from '@sanity/blueprints';
4
+ import { SANITY_FUNCTION_DURABLE } from '../../constants.js';
5
+ import { isLocalFunctionResource } from '../types.js';
6
+ import { findFunctionEntryPoint } from './find-entry-point.js';
7
+ import { transpileFunction } from './transpile/function.js';
8
+ const DURABLE_CONFIG_KEYS = ['event', 'concurrency', 'debounce', 'debounceKey'];
9
+ /**
10
+ * Extracts the blueprint config from the function source code and mutates it to the resource object.
11
+ * This is used for durable functions that may not have a config defined in the blueprint.
12
+ * @param resource
13
+ * @param blueprintFileDir
14
+ */
15
+ export const extractDurableConfig = async (resource, blueprintFileDir) => {
16
+ if (!isLocalFunctionResource(resource))
17
+ return;
18
+ // skip if not a durable function
19
+ if (resource.type !== SANITY_FUNCTION_DURABLE)
20
+ return;
21
+ // Check if source needs to be transpiled before attempting to get config
22
+ const resourceSrc = resolve(blueprintFileDir, resource.src);
23
+ const entryPoint = await findFunctionEntryPoint(resourceSrc, resource.name);
24
+ let importPath = entryPoint;
25
+ let cleanup = async () => { };
26
+ // need to transpile and grab the config from the built output if the entry point is a TypeScript file
27
+ if (entryPoint.endsWith('.ts')) {
28
+ const built = await transpileFunction({ resource, functionPath: resourceSrc, entryPoint });
29
+ importPath = await findFunctionEntryPoint(built.outputDir, resource.name);
30
+ cleanup = built.cleanup;
31
+ }
32
+ let config = {};
33
+ try {
34
+ const mod = await import(pathToFileURL(importPath).href);
35
+ config = (mod.handler || mod.default)?.config;
36
+ }
37
+ finally {
38
+ await cleanup();
39
+ }
40
+ // Update values not included in the blueprint.
41
+ if (resource.event === undefined && config?.event !== undefined) {
42
+ resource.event = config.event;
43
+ }
44
+ if (resource.concurrency === undefined && config?.concurrency !== undefined) {
45
+ resource.concurrency = config.concurrency;
46
+ }
47
+ if (resource.debounce === undefined && config?.debounce !== undefined) {
48
+ resource.debounce = config.debounce;
49
+ }
50
+ if (resource.debounceKey === undefined && config?.debounceKey !== undefined) {
51
+ resource.debounceKey = config.debounceKey;
52
+ }
53
+ // Validate the resource after merging the config values
54
+ const errors = validateDurableFunction(resource);
55
+ if (errors.length > 0) {
56
+ throw new Error(`Invalid durable resource "${resource.name}": ${errors.map((error) => error.message).join('; ')}`);
57
+ }
58
+ };
@@ -338,11 +338,17 @@ export type PrepAssetFn<R extends BlueprintResource> = (options: {
338
338
  blueprintFileDir: string;
339
339
  installer?: InstallerType;
340
340
  }) => Promise<AssetPrepResult>;
341
+ export type PrepResourceFn<R extends BlueprintResource> = (options: {
342
+ resource: R;
343
+ blueprintFileDir: string;
344
+ }) => Promise<void>;
341
345
  export type PreDeployConfig = {
342
346
  /** The resource type this config applies to or a function that returns true if this config applies to the given type. */
343
347
  resourceType: string | ((type: string) => boolean);
344
348
  /** Function that takes a resource and returns a buffer to be sent to blueprints. */
345
349
  prepareAsset?: PrepAssetFn<BlueprintResource>;
350
+ /** Function that mutates the resource before the pre-deploy is executed. */
351
+ prepareResource?: PrepResourceFn<BlueprintResource>;
346
352
  };
347
353
  export type AssetResource<R extends BlueprintResource> = {
348
354
  resource: R;
@@ -3148,5 +3148,5 @@
3148
3148
  ]
3149
3149
  }
3150
3150
  },
3151
- "version": "17.14.0-next.g1c33580"
3151
+ "version": "17.14.0-next.g792820f"
3152
3152
  }
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.14.0-next.g1c33580",
4
+ "version": "17.14.0-next.g792820f",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",
@@ -68,7 +68,7 @@
68
68
  "@oclif/core": "^4.14.0",
69
69
  "@oclif/plugin-help": "^6.3.0",
70
70
  "@sanity-labs/oclif-plugin-skills-flag": "^0.2.1",
71
- "@sanity/blueprints": "^0.24.0",
71
+ "@sanity/blueprints": "^0.27.0",
72
72
  "@sanity/blueprints-parser": "^0.5.0",
73
73
  "@sanity/cli-build": "^6.3.0",
74
74
  "@sanity/cli-core": "^3.7.0",
@@ -1,60 +0,0 @@
1
- import { resolve } from 'node:path';
2
- import { pathToFileURL } from 'node:url';
3
- import { validateDurableFunction, } from '@sanity/blueprints';
4
- import { SANITY_FUNCTION_DURABLE } from '../../constants.js';
5
- import { findFunctionEntryPoint } from '../functions/find-entry-point.js';
6
- import { transpileFunction } from '../functions/transpile/function.js';
7
- import { isLocalFunctionResource } from '../types.js';
8
- const DURABLE_CONFIG_KEYS = ['event', 'concurrency', 'debounce', 'debounceKey'];
9
- /**
10
- * Extracts the blueprint config from the function source code and mutates it to the resource object.
11
- * This is used for durable functions that may not have a config defined in the blueprint.
12
- * @param resources
13
- * @param blueprintFileDir
14
- */
15
- export const extractDurableConfig = async (resources, blueprintFileDir) => {
16
- for (const resource of resources) {
17
- if (!isLocalFunctionResource(resource))
18
- continue;
19
- // skip if not a durable function
20
- if (resource.type !== SANITY_FUNCTION_DURABLE)
21
- continue;
22
- // Check if source needs to be transpiled before attempting to get config
23
- const resourceSrc = resolve(blueprintFileDir, resource.src);
24
- const entryPoint = await findFunctionEntryPoint(resourceSrc, resource.name);
25
- let importPath = entryPoint;
26
- let cleanup = async () => { };
27
- // need to transpile and grab the config from the built output if the entry point is a TypeScript file
28
- if (entryPoint.endsWith('.ts')) {
29
- const built = await transpileFunction({ resource, functionPath: resourceSrc, entryPoint });
30
- importPath = await findFunctionEntryPoint(built.outputDir, resource.name);
31
- cleanup = built.cleanup;
32
- }
33
- let config = {};
34
- try {
35
- const mod = await import(pathToFileURL(importPath).href);
36
- config = (mod.handler || mod.default)?.config;
37
- }
38
- finally {
39
- await cleanup();
40
- }
41
- // Update values not included in the blueprint.
42
- if (resource.event === undefined && config?.event !== undefined) {
43
- resource.event = config.event;
44
- }
45
- if (resource.concurrency === undefined && config?.concurrency !== undefined) {
46
- resource.concurrency = config.concurrency;
47
- }
48
- if (resource.debounce === undefined && config?.debounce !== undefined) {
49
- resource.debounce = config.debounce;
50
- }
51
- if (resource.debounceKey === undefined && config?.debounceKey !== undefined) {
52
- resource.debounceKey = config.debounceKey;
53
- }
54
- // Validate the resource after merging the config values
55
- const errors = validateDurableFunction(resource);
56
- if (errors.length > 0) {
57
- throw new Error(`Invalid durable resource "${resource.name}": ${errors.map((error) => error.message).join('; ')}`);
58
- }
59
- }
60
- };
@@ -1,9 +0,0 @@
1
- import type { BlueprintResource } from '@sanity/blueprints';
2
- /**
3
- * Stamps the installed `sanity` version onto each media-library config resource
4
- * before pre-deploy. The version is a label Brett stores on the config snapshot,
5
- * mirroring what `sanity deploy` sends for a media-library config; it is not what
6
- * the runtime loads. Other installation config types are left alone: the
7
- * media-library tie to the `sanity` package is specific to it.
8
- */
9
- export declare const stampInstallationConfigVersion: (resources: BlueprintResource[], blueprintFileDir: string) => Promise<void>;
@@ -1,28 +0,0 @@
1
- import { resolve } from 'node:path';
2
- import { getLocalPackageVersion } from '@sanity/cli-core/package-manager';
3
- import { SANITY_INSTALLATION_CONFIG } from '../../constants.js';
4
- /**
5
- * Stamps the installed `sanity` version onto each media-library config resource
6
- * before pre-deploy. The version is a label Brett stores on the config snapshot,
7
- * mirroring what `sanity deploy` sends for a media-library config; it is not what
8
- * the runtime loads. Other installation config types are left alone: the
9
- * media-library tie to the `sanity` package is specific to it.
10
- */
11
- export const stampInstallationConfigVersion = async (resources, blueprintFileDir) => {
12
- for (const resource of resources) {
13
- if (resource.type !== SANITY_INSTALLATION_CONFIG)
14
- continue;
15
- const config = resource;
16
- if (config.appType !== 'media-library')
17
- continue;
18
- // Update values not included in the blueprint.
19
- if (config.version !== undefined)
20
- continue;
21
- const workDir = resolve(blueprintFileDir, config.root);
22
- const version = await getLocalPackageVersion('sanity', workDir);
23
- if (!version) {
24
- throw new Error(`Unable to determine the installed 'sanity' version for installation config resource '${config.name}'; is 'sanity' installed in '${config.root}'?`);
25
- }
26
- config.version = version;
27
- }
28
- };
@@ -1,61 +0,0 @@
1
- import type { BlueprintProjectResourceLifecycle, BlueprintResource, BlueprintStudioResource as PublishedStudioResource } from '@sanity/blueprints';
2
- /** Studios point at their directory with `root`, same as applications. */
3
- export type BlueprintStudioResource = Omit<PublishedStudioResource, 'src'> & {
4
- root: string;
5
- };
6
- type ApplicationDock = {
7
- group?: 'system' | 'applications' | 'user';
8
- order?: number;
9
- };
10
- type ChildBase = {
11
- name: string;
12
- title: string;
13
- src: string;
14
- };
15
- type WindowView = ChildBase & {
16
- type: 'app';
17
- dock?: ApplicationDock;
18
- };
19
- type PanelView = ChildBase & {
20
- type: 'panel';
21
- dock?: ApplicationDock;
22
- };
23
- type AssetSourceView = ChildBase & {
24
- type: 'asset_source';
25
- };
26
- type TileView = ChildBase & {
27
- type: 'tile';
28
- size: 'small' | 'large' | 'banner';
29
- order?: number;
30
- };
31
- type WebWorker = ChildBase & {
32
- type: 'worker';
33
- };
34
- export type ApplicationView = WindowView | PanelView | AssetSourceView | TileView;
35
- export interface BlueprintApplicationResource extends BlueprintResource<BlueprintProjectResourceLifecycle> {
36
- type: 'sanity.application';
37
- slug: string;
38
- title: string;
39
- /** Application directory, relative to the blueprint file; contains package.json. */
40
- root: string;
41
- icon?: string;
42
- visibility?: 'default' | 'unlisted' | 'disabled';
43
- views?: ApplicationView[];
44
- webWorkers?: WebWorker[];
45
- }
46
- type InstallationConfigField = {
47
- name: string;
48
- title: string;
49
- src: string;
50
- public?: boolean;
51
- };
52
- export interface BlueprintInstallationConfigResource extends BlueprintResource {
53
- type: 'sanity.installation.config';
54
- appType: 'media-library';
55
- /** Build directory, relative to the blueprint file; contains package.json. Field `src` resolves against it. */
56
- root: string;
57
- fields: InstallationConfigField[];
58
- /** Stamped by the CLI before pre-deploy; the authored shape from blueprints-node has none. */
59
- version?: string;
60
- }
61
- export {};
@@ -1 +0,0 @@
1
- export {};