@sanity/runtime-cli 17.21.6-blueprinit.gc247877 → 17.21.6-next.g34627a4

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.
Files changed (70) hide show
  1. package/README.md +19 -19
  2. package/dist/actions/blueprints/assets.d.ts +2 -1
  3. package/dist/actions/blueprints/assets.js +8 -2
  4. package/dist/actions/blueprints/pre-deploy.d.ts +1 -1
  5. package/dist/actions/blueprints/pre-deploy.js +38 -5
  6. package/dist/actions/blueprints/process-assets.d.ts +3 -0
  7. package/dist/actions/blueprints/process-assets.js +13 -4
  8. package/dist/cores/blueprints/deploy.js +2 -1
  9. package/dist/utils/bundles/prepare-asset.d.ts +6 -2
  10. package/dist/utils/bundles/prepare-asset.js +10 -2
  11. package/dist/utils/bundles/resolve-resource-bindings.d.ts +10 -0
  12. package/dist/utils/bundles/resolve-resource-bindings.js +37 -0
  13. package/dist/utils/functions/blocked-modules.d.ts +14 -0
  14. package/dist/utils/functions/blocked-modules.js +41 -0
  15. package/dist/utils/functions/prepare-asset.js +5 -0
  16. package/dist/utils/functions/transpile/function.js +4 -1
  17. package/dist/utils/icons/prepare-asset.d.ts +10 -0
  18. package/dist/utils/icons/prepare-asset.js +40 -0
  19. package/dist/utils/types.d.ts +17 -2
  20. package/oclif.manifest.json +1 -152
  21. package/package.json +3 -3
  22. package/dist/actions/blueprinit/manifest.d.ts +0 -52
  23. package/dist/actions/blueprinit/manifest.js +0 -139
  24. package/dist/actions/blueprinit/quote.d.ts +0 -6
  25. package/dist/actions/blueprinit/quote.js +0 -8
  26. package/dist/actions/blueprinit/studio.d.ts +0 -6
  27. package/dist/actions/blueprinit/studio.js +0 -43
  28. package/dist/actions/blueprinit/templates.d.ts +0 -73
  29. package/dist/actions/blueprinit/templates.js +0 -143
  30. package/dist/actions/blueprinit/versions.d.ts +0 -8
  31. package/dist/actions/blueprinit/versions.js +0 -11
  32. package/dist/actions/blueprinit/workspace.d.ts +0 -36
  33. package/dist/actions/blueprinit/workspace.js +0 -174
  34. package/dist/actions/sanity/create-project.d.ts +0 -19
  35. package/dist/actions/sanity/create-project.js +0 -32
  36. package/dist/actions/sanity/datasets.d.ts +0 -15
  37. package/dist/actions/sanity/datasets.js +0 -26
  38. package/dist/commands/init.d.ts +0 -21
  39. package/dist/commands/init.js +0 -82
  40. package/dist/cores/blueprinit/adopt.d.ts +0 -6
  41. package/dist/cores/blueprinit/adopt.js +0 -137
  42. package/dist/cores/blueprinit/columns.d.ts +0 -26
  43. package/dist/cores/blueprinit/columns.js +0 -27
  44. package/dist/cores/blueprinit/finish.d.ts +0 -15
  45. package/dist/cores/blueprinit/finish.js +0 -72
  46. package/dist/cores/blueprinit/fresh.d.ts +0 -3
  47. package/dist/cores/blueprinit/fresh.js +0 -230
  48. package/dist/cores/blueprinit/naming.d.ts +0 -27
  49. package/dist/cores/blueprinit/naming.js +0 -43
  50. package/dist/cores/blueprinit/preview.d.ts +0 -34
  51. package/dist/cores/blueprinit/preview.js +0 -118
  52. package/dist/cores/blueprinit/project-choice.d.ts +0 -28
  53. package/dist/cores/blueprinit/project-choice.js +0 -82
  54. package/dist/cores/blueprinit/prompts.d.ts +0 -13
  55. package/dist/cores/blueprinit/prompts.js +0 -42
  56. package/dist/cores/blueprinit/results.d.ts +0 -8
  57. package/dist/cores/blueprinit/results.js +0 -4
  58. package/dist/cores/blueprinit/selection.d.ts +0 -15
  59. package/dist/cores/blueprinit/selection.js +0 -90
  60. package/dist/cores/blueprinit/stack-name.d.ts +0 -39
  61. package/dist/cores/blueprinit/stack-name.js +0 -56
  62. package/dist/cores/blueprinit/target.d.ts +0 -33
  63. package/dist/cores/blueprinit/target.js +0 -80
  64. package/dist/cores/blueprinit/types.d.ts +0 -20
  65. package/dist/cores/blueprinit/types.js +0 -1
  66. package/dist/cores/blueprinit.d.ts +0 -7
  67. package/dist/cores/blueprinit.js +0 -64
  68. package/dist/utils/display/intro.d.ts +0 -6
  69. package/dist/utils/display/intro.js +0 -63
  70. package/skills/init.md +0 -199
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.21.6-blueprinit.gc247877/src/commands/blueprints/add.ts)_
93
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/src/commands/blueprints/config.ts)_
130
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/src/commands/blueprints/deploy.ts)_
186
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/src/commands/blueprints/destroy.ts)_
224
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/src/commands/blueprints/doctor.ts)_
256
+ _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/src/commands/blueprints/info.ts)_
294
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/src/commands/blueprints/init.ts)_
358
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/src/commands/blueprints/logs.ts)_
404
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/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.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/src/commands/blueprints/plan.ts)_
482
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/src/commands/blueprints/promote.ts)_
518
+ _See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/src/commands/blueprints/stacks.ts)_
559
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/src/commands/functions/add.ts)_
611
+ _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/src/commands/functions/dev.ts)_
646
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/src/commands/functions/env/add.ts)_
679
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/src/commands/functions/env/list.ts)_
709
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/src/commands/functions/env/remove.ts)_
741
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/src/commands/functions/logs.ts)_
781
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/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.21.6-blueprinit.gc247877/src/commands/functions/test.ts)_
839
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.g34627a4/src/commands/functions/test.ts)_
840
840
 
841
841
  ## `sanity-run help [COMMAND]`
842
842
 
@@ -18,9 +18,10 @@ export type StashAssetResult = {
18
18
  success: false;
19
19
  error: string;
20
20
  };
21
- export declare function stashAsset<R extends BlueprintResource>({ resolvedResource, prepAsset, auth, blueprintFileDir, fetchFn, installer, }: {
21
+ export declare function stashAsset<R extends BlueprintResource>({ resolvedResource, prepAsset, stackId, auth, blueprintFileDir, fetchFn, installer, }: {
22
22
  resolvedResource: ResolvedResource<R>;
23
23
  prepAsset: PrepAssetFn<R>;
24
+ stackId: string;
24
25
  auth: AuthParams;
25
26
  blueprintFileDir: string;
26
27
  fetchFn: typeof fetch;
@@ -4,10 +4,16 @@ import getHeaders from '../../utils/get-headers.js';
4
4
  const assetsUrl = blueprintsUrl('assets');
5
5
  export const assetCheckUrl = `${assetsUrl}/check`;
6
6
  export const assetStashUrl = `${assetsUrl}/stash`;
7
- export async function stashAsset({ resolvedResource, prepAsset, auth, blueprintFileDir, fetchFn, installer, }) {
7
+ export async function stashAsset({ resolvedResource, prepAsset, stackId, auth, blueprintFileDir, fetchFn, installer, }) {
8
8
  let cleanup = async () => { };
9
9
  try {
10
- const prepResult = await prepAsset({ resolvedResource, blueprintFileDir, installer, auth });
10
+ const prepResult = await prepAsset({
11
+ resolvedResource,
12
+ blueprintFileDir,
13
+ installer,
14
+ stackId,
15
+ auth,
16
+ });
11
17
  if (prepResult.success === false) {
12
18
  await prepResult.cleanup();
13
19
  return {
@@ -12,7 +12,7 @@ type PreDeployFailure = {
12
12
  };
13
13
  export type PreDeployResult = PreDeployFailure | {
14
14
  success: true;
15
- /** One entry per prepared asset, for the deploy metadata */
15
+ /** One entry per prepared bundle or source asset (icons get none), for the deploy metadata */
16
16
  resourceMetadata: ResourceMetadata[];
17
17
  };
18
18
  export type PreDeployAssetEvent<R extends BlueprintResource> = {
@@ -1,3 +1,4 @@
1
+ import path from 'node:path';
1
2
  import { SANITY_AGENT_TYPE, SANITY_FUNCTION_PREFIX } from '../../constants.js';
2
3
  import { prepareAsset as prepareAgentAsset } from '../../utils/agents/prepare-asset.js';
3
4
  import { resolveDeployedResources } from '../../utils/blueprints/resolve-deployed-resources.js';
@@ -6,6 +7,7 @@ import { stampConfigVersion } from '../../utils/bundles/stamp-config-version.js'
6
7
  import { CODE_OPERATION_UNCONFIRMED, EXIT_OPERATION_UNCONFIRMED } from '../../utils/exit-codes.js';
7
8
  import { extractDurableConfig } from '../../utils/functions/extract-durable-config.js';
8
9
  import { prepareAsset as prepareFunctionAsset } from '../../utils/functions/prepare-asset.js';
10
+ import { prepareIconAsset } from '../../utils/icons/prepare-asset.js';
9
11
  import { runCommand } from '../../utils/package-manager.js';
10
12
  import { setupLogPolling } from './logs-polling.js';
11
13
  import { getOperationStateInfo } from './operations-state.js';
@@ -21,11 +23,20 @@ const preDeployConfigs = [
21
23
  return prepareBundleAsset({
22
24
  resolvedResource: options.resolvedResource,
23
25
  blueprintFileDir: options.blueprintFileDir,
26
+ stackId: options.stackId,
27
+ token: options.auth.token,
24
28
  });
25
29
  },
26
30
  async prepareResource(options) {
27
31
  await stampConfigVersion(options.resource, options.blueprintFileDir);
28
32
  },
33
+ getIconInfo({ resolvedResource, blueprintFileDir }) {
34
+ // An installation config is a bundle too, but only applications and studios have an icon
35
+ const { icon, root } = resolvedResource.resource;
36
+ if (!icon || !root)
37
+ return undefined;
38
+ return { iconKey: 'icon', workDir: path.resolve(blueprintFileDir, root) };
39
+ },
29
40
  },
30
41
  {
31
42
  resourceType: (type) => type.startsWith(SANITY_FUNCTION_PREFIX),
@@ -51,9 +62,14 @@ const preDeployConfigs = [
51
62
  },
52
63
  },
53
64
  ];
54
- function hasPreDeployResources(resources) {
65
+ function hasPreDeployResources(resources, blueprintFileDir) {
55
66
  return resources.some((r) => {
56
- return !!getPredeployConfig(r);
67
+ const config = getPredeployConfig(r);
68
+ if (!config)
69
+ return false;
70
+ return (!!config.prepareAsset ||
71
+ !!config.prepareResource ||
72
+ !!config.getIconInfo?.({ resolvedResource: { resource: r }, blueprintFileDir }));
57
73
  });
58
74
  }
59
75
  function getPredeployConfig(r) {
@@ -65,7 +81,7 @@ function getPredeployConfig(r) {
65
81
  export async function preDeploy(options) {
66
82
  const { resources, stackId, auth, blueprintFileDir, installer, fetchFn } = options;
67
83
  const resourceMetadata = [];
68
- if (hasPreDeployResources(resources)) {
84
+ if (hasPreDeployResources(resources, blueprintFileDir)) {
69
85
  for (const r of resources) {
70
86
  const config = getPredeployConfig(r);
71
87
  if (typeof config !== 'undefined' && typeof config.prepareResource === 'function') {
@@ -89,11 +105,20 @@ export async function preDeploy(options) {
89
105
  if (typeof config !== 'undefined' && typeof config.prepareAsset === 'function') {
90
106
  assetResources.push({ resource: r, prepareAsset: config.prepareAsset });
91
107
  }
108
+ const iconInfo = config?.getIconInfo?.({ resolvedResource: r, blueprintFileDir });
109
+ if (iconInfo) {
110
+ assetResources.push({
111
+ resource: r,
112
+ prepareAsset: ({ blueprintFileDir }) => prepareIconAsset({ resolvedResource: r, blueprintFileDir, ...iconInfo }),
113
+ isIcon: true,
114
+ });
115
+ }
92
116
  }
93
117
  let processedAssets = [];
94
118
  try {
95
119
  processedAssets = await processAssets({
96
120
  assetResources,
121
+ stackId,
97
122
  auth,
98
123
  blueprintFileDir,
99
124
  installer,
@@ -114,8 +139,16 @@ export async function preDeploy(options) {
114
139
  // ! I think this error message is wrong. we somehow have an extra asset
115
140
  if (idx === -1)
116
141
  throw new Error('Unable to update resource asset');
117
- resources[idx] = asset.resource;
118
- if (asset.success) {
142
+ if (!asset.success)
143
+ continue;
144
+ // A resource can have two assets (its bundle and its icon), so set only this one's parameter
145
+ const { assetParameter } = asset;
146
+ resources[idx] = {
147
+ ...resources[idx],
148
+ [assetParameter]: asset.resource[assetParameter],
149
+ };
150
+ // the deploy metadata describes a resource's bundle, so an icon adds no second entry for it
151
+ if (!asset.isIcon) {
119
152
  const { name, type } = asset.resource;
120
153
  resourceMetadata.push({
121
154
  name,
@@ -2,6 +2,7 @@ import type { BlueprintResource } from '@sanity/blueprints';
2
2
  import type { AssetResource, AuthParams, InstallerType } from '../../utils/types.js';
3
3
  type ProcessAssetsOptions<R extends BlueprintResource> = {
4
4
  assetResources: AssetResource<R>[];
5
+ stackId: string;
5
6
  auth: AuthParams;
6
7
  blueprintFileDir: string;
7
8
  installer: InstallerType;
@@ -23,6 +24,8 @@ export type ProcessedAsset<R extends BlueprintResource> = {
23
24
  success: true;
24
25
  resource: R;
25
26
  assetParameter: string;
27
+ /** The asset is the resource's icon, not its source. */
28
+ isIcon?: boolean;
26
29
  hash: string;
27
30
  exists: boolean;
28
31
  metadata?: Record<string, unknown>;
@@ -22,7 +22,7 @@ export async function processAssets(options) {
22
22
  for (let start = 0; start < total; start += concurrency) {
23
23
  const batch = assetResources.slice(start, start + concurrency);
24
24
  const batchResults = await Promise.all(batch.map(async (assetResource) => {
25
- const result = await processAsset(assetResource.resource, assetResource.prepareAsset, options);
25
+ const result = await processAsset(assetResource, options);
26
26
  completed += 1;
27
27
  reportProgress();
28
28
  onResult?.(result);
@@ -42,14 +42,22 @@ function getAssetConcurrency() {
42
42
  const configured = Number(env.SANITY_ASSET_CONCURRENCY);
43
43
  return Number.isSafeInteger(configured) && configured > 0 ? configured : DEFAULT_ASSET_CONCURRENCY;
44
44
  }
45
- async function processAsset(resolvedResource, prepAsset, options) {
45
+ async function processAsset({ resource: resolvedResource, prepareAsset: prepAsset, isIcon }, options) {
46
46
  const { resource } = resolvedResource;
47
- const { auth, blueprintFileDir, installer, fetchFn } = options;
47
+ const { stackId, auth, blueprintFileDir, installer, fetchFn } = options;
48
48
  let assetTimeoutTimer;
49
49
  let result;
50
50
  try {
51
51
  result = await Promise.race([
52
- stashAsset({ resolvedResource, prepAsset, blueprintFileDir, auth, fetchFn, installer }),
52
+ stashAsset({
53
+ resolvedResource,
54
+ prepAsset,
55
+ blueprintFileDir,
56
+ stackId,
57
+ auth,
58
+ fetchFn,
59
+ installer,
60
+ }),
53
61
  new Promise((_, reject) => {
54
62
  assetTimeoutTimer = setTimeout(() => {
55
63
  reject(new Error(`Processing ${resource.name} timed out after ${assetTimeoutS}s`));
@@ -69,6 +77,7 @@ async function processAsset(resolvedResource, prepAsset, options) {
69
77
  success: true,
70
78
  resource: { ...resource, [result.assetParameter]: result.assetId },
71
79
  assetParameter: result.assetParameter,
80
+ isIcon,
72
81
  hash: result.hash,
73
82
  exists: result.exists,
74
83
  metadata: result.metadata,
@@ -228,7 +228,8 @@ function createAssetEventHandler(logger) {
228
228
  }
229
229
  const r = resource;
230
230
  const assetParameter = String(r[result.assetParameter]);
231
- logger(` ${check(`${resource.name} ${niceId(assetParameter)}`)}`);
231
+ const label = result.isIcon ? `${resource.name} ${result.assetParameter}` : resource.name;
232
+ logger(` ${check(`${label} ${niceId(assetParameter)}`)}`);
232
233
  logger(` Source: ${assetParameter}`);
233
234
  if (result.hash) {
234
235
  const hash = result.hash;
@@ -2,6 +2,7 @@ import type { BlueprintApplicationResource, BlueprintInstallationConfigResource,
2
2
  import { type BuildStudioEventListener } from '@sanity/cli-build/_internal/build';
3
3
  import type { Output } from '@sanity/cli-core';
4
4
  import type { AssetPrepResult, ResolvedResource } from '../types.js';
5
+ import { type ResourceBinding } from './resolve-resource-bindings.js';
5
6
  export type BundleResource = BlueprintStudioResource | BlueprintApplicationResource | BlueprintInstallationConfigResource;
6
7
  type BuildContext<R extends BundleResource> = {
7
8
  resource: R;
@@ -9,6 +10,7 @@ type BuildContext<R extends BundleResource> = {
9
10
  workDir: string;
10
11
  outDir: string;
11
12
  output: Output;
13
+ resourceBindings: ResourceBinding[];
12
14
  eventListener: Partial<BuildStudioEventListener>;
13
15
  };
14
16
  type BuildResult = {
@@ -28,11 +30,13 @@ export declare const BUNDLE_SPECS: {
28
30
  build: typeof buildInstallationConfigBundle;
29
31
  };
30
32
  };
31
- export declare function prepareBundleAsset<R extends BundleResource>({ blueprintFileDir, resolvedResource, }: {
33
+ export declare function prepareBundleAsset<R extends BundleResource>({ blueprintFileDir, resolvedResource, stackId, token, }: {
32
34
  blueprintFileDir: string;
33
35
  resolvedResource: ResolvedResource<R>;
36
+ stackId: string;
37
+ token: string;
34
38
  }): Promise<AssetPrepResult>;
35
- declare function buildStudioBundle({ resource, appId, workDir, outDir, output, eventListener, }: BuildContext<BlueprintStudioResource>): Promise<BuildResult>;
39
+ declare function buildStudioBundle({ resource, appId, workDir, outDir, output, resourceBindings, eventListener, }: BuildContext<BlueprintStudioResource>): Promise<BuildResult>;
36
40
  declare function buildApplicationBundle({ resource, appId, workDir, outDir, output, eventListener, }: BuildContext<BlueprintApplicationResource>): Promise<BuildResult>;
37
41
  declare function buildInstallationConfigBundle({ resource, workDir, outDir, output, eventListener, }: BuildContext<BlueprintInstallationConfigResource>): Promise<BuildResult>;
38
42
  export {};
@@ -9,12 +9,13 @@ import { buildStudioSchemasAndManifests } from '@sanity/cli-build/_internal/extr
9
9
  import { getLocalPackageVersion } from '@sanity/cli-core';
10
10
  import { pack } from 'tar-fs';
11
11
  import { isRecord } from '../is-record.js';
12
+ import { resolveResourceBindings } from './resolve-resource-bindings.js';
12
13
  export const BUNDLE_SPECS = {
13
14
  'sanity.studio': { requiresAppId: true, build: buildStudioBundle },
14
15
  'sanity.application': { requiresAppId: true, build: buildApplicationBundle },
15
16
  'sanity.installation.config': { requiresAppId: false, build: buildInstallationConfigBundle },
16
17
  };
17
- export async function prepareBundleAsset({ blueprintFileDir, resolvedResource, }) {
18
+ export async function prepareBundleAsset({ blueprintFileDir, resolvedResource, stackId, token, }) {
18
19
  const resource = resolvedResource.resource;
19
20
  // The lookup can't prove it yields the spec matching this R, so it's asserted once here.
20
21
  const spec = BUNDLE_SPECS[resource.type];
@@ -63,6 +64,11 @@ export async function prepareBundleAsset({ blueprintFileDir, resolvedResource, }
63
64
  await rm(outDir, { force: true, recursive: true });
64
65
  await rm(outFile, { force: true });
65
66
  };
67
+ const resourceBindings = await resolveResourceBindings({
68
+ projectRootDir: workDir,
69
+ stackId,
70
+ token,
71
+ });
66
72
  let mismatchedPackages;
67
73
  try {
68
74
  ;
@@ -72,6 +78,7 @@ export async function prepareBundleAsset({ blueprintFileDir, resolvedResource, }
72
78
  workDir,
73
79
  outDir,
74
80
  output: createSilentOutput(),
81
+ resourceBindings,
75
82
  eventListener,
76
83
  }));
77
84
  }
@@ -106,7 +113,7 @@ export async function prepareBundleAsset({ blueprintFileDir, resolvedResource, }
106
113
  };
107
114
  }
108
115
  }
109
- async function buildStudioBundle({ resource, appId, workDir, outDir, output, eventListener, }) {
116
+ async function buildStudioBundle({ resource, appId, workDir, outDir, output, resourceBindings, eventListener, }) {
110
117
  // this has been checked before we got here but this helps the type checker
111
118
  if (!appId)
112
119
  throw new Error(`Unable to determine appId for ${resource.type} resource '${resource.name}'`);
@@ -148,6 +155,7 @@ async function buildStudioBundle({ resource, appId, workDir, outDir, output, eve
148
155
  configPath: resource.root,
149
156
  isExternal: false,
150
157
  outPath: outDir,
158
+ resourceBindings,
151
159
  schemaRequired: false,
152
160
  verbose: false,
153
161
  workDir,
@@ -0,0 +1,10 @@
1
+ export type ResourceBinding = {
2
+ type: string;
3
+ name: string;
4
+ id: string;
5
+ };
6
+ export declare function resolveResourceBindings({ projectRootDir, stackId, token, }: {
7
+ projectRootDir: string;
8
+ stackId: string;
9
+ token: string;
10
+ }): Promise<ResourceBinding[]>;
@@ -0,0 +1,37 @@
1
+ import { dirname, resolve } from 'node:path';
2
+ import { findBlueprintFile, readBlueprint, readStack } from '@sanity/blueprints/resolve';
3
+ export async function resolveResourceBindings({ projectRootDir, stackId, token, }) {
4
+ try {
5
+ const blueprintFile = findBlueprintFile(projectRootDir);
6
+ if (!blueprintFile)
7
+ return [];
8
+ const localBlueprint = await readBlueprint({
9
+ path: blueprintFile,
10
+ });
11
+ const blueprintReferencesStudio = localBlueprint.resources.some((r) => {
12
+ if ('root' in r && typeof r.root === 'string') {
13
+ const root = resolve(dirname(blueprintFile), r.root);
14
+ return root === projectRootDir;
15
+ }
16
+ return false;
17
+ });
18
+ if (!blueprintReferencesStudio)
19
+ return [];
20
+ const stack = await readStack({
21
+ token,
22
+ overrides: { stackId },
23
+ });
24
+ return stack.resources
25
+ .filter((r) => r.externalId)
26
+ .map((r) => ({
27
+ type: r.type,
28
+ name: r.name,
29
+ id: r.externalId || '',
30
+ }));
31
+ }
32
+ catch (error) {
33
+ throw new Error(`Unable to resolve resources from blueprint in ${projectRootDir}`, {
34
+ cause: error,
35
+ });
36
+ }
37
+ }
@@ -0,0 +1,14 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * Packages that do not work in a Sanity Function execution environment, with the reason shown to the user.
4
+ */
5
+ export declare const BLOCKED_MODULES: Readonly<Record<string, string>>;
6
+ export declare function blockedModulesErrorMessage(names: string[]): string;
7
+ /**
8
+ * Return the names of blocked packages installed in the given node_modules directory.
9
+ */
10
+ export declare function detectBlockedModules(nodeModules: string): string[];
11
+ /**
12
+ * A vite plugin that fails the build when a function imports a blocked package.
13
+ */
14
+ export declare function blockedModulesPlugin(): Plugin;
@@ -0,0 +1,41 @@
1
+ import { existsSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ /**
4
+ * Packages that do not work in a Sanity Function execution environment, with the reason shown to the user.
5
+ */
6
+ export const BLOCKED_MODULES = {
7
+ '@anthropic-ai/claude-agent-sdk': 'spawns the `claude` CLI, which throws in a Sanity Function execution environment. Investigate `@anthropic-ai/sdk` instead.',
8
+ };
9
+ export function blockedModulesErrorMessage(names) {
10
+ return `Unsupported modules detected:\n${names.map((name) => `${name}: ${BLOCKED_MODULES[name]}`).join('\n')}`;
11
+ }
12
+ /**
13
+ * Return the names of blocked packages installed in the given node_modules directory.
14
+ */
15
+ export function detectBlockedModules(nodeModules) {
16
+ return Object.keys(BLOCKED_MODULES).filter((name) => existsSync(path.join(nodeModules, name, 'package.json')));
17
+ }
18
+ function blockedPackageFor(source) {
19
+ return Object.keys(BLOCKED_MODULES).find((name) => source === name || source.startsWith(`${name}/`));
20
+ }
21
+ /**
22
+ * A vite plugin that fails the build when a function imports a blocked package.
23
+ */
24
+ export function blockedModulesPlugin() {
25
+ const flagged = new Set();
26
+ return {
27
+ name: 'blocked-modules',
28
+ enforce: 'pre',
29
+ resolveId(source) {
30
+ const name = blockedPackageFor(source);
31
+ if (name)
32
+ flagged.add(name);
33
+ return null;
34
+ },
35
+ buildEnd() {
36
+ if (flagged.size > 0) {
37
+ this.error(blockedModulesErrorMessage([...flagged]));
38
+ }
39
+ },
40
+ };
41
+ }
@@ -3,6 +3,7 @@ import { stat } from 'node:fs/promises';
3
3
  import path from 'node:path';
4
4
  import AdmZip from 'adm-zip';
5
5
  import { CONVERT_BYTES_TO_MB, MAX_ASSET_SIZE } from '../../constants.js';
6
+ import { blockedModulesErrorMessage, detectBlockedModules } from './blocked-modules.js';
6
7
  import { getDependencyInfo, takeAutoInstallManifest, } from './dependency-info.js';
7
8
  import { detectNativeModules, errorMessage } from './detect-native-modules.js';
8
9
  import { isFolderLargerThan } from './is-folder-larger-than.js';
@@ -50,6 +51,10 @@ export async function prepareAsset({ blueprintFileDir, resource, installer, }) {
50
51
  }
51
52
  if (existsSync(path.join(functionPath, 'node_modules'))) {
52
53
  const modulesPath = path.join(functionPath, 'node_modules');
54
+ const blocked = detectBlockedModules(modulesPath);
55
+ if (blocked.length > 0) {
56
+ throw new Error(blockedModulesErrorMessage(blocked));
57
+ }
53
58
  const flagged = detectNativeModules(modulesPath);
54
59
  if (flagged.length > 0) {
55
60
  throw new Error(errorMessage(flagged));
@@ -5,6 +5,7 @@ import { cwd } from 'node:process';
5
5
  import * as find from 'empathic/find';
6
6
  import stripAnsi from 'strip-ansi';
7
7
  import { build as viteBuild } from 'vite';
8
+ import { blockedModulesPlugin } from '../blocked-modules.js';
8
9
  import { detectNativeModulesPlugin } from '../detect-native-modules.js';
9
10
  import { cleanupSourceMaps } from './cleanup-source-maps.js';
10
11
  import { createPnpmRequire } from './pnpm.js';
@@ -74,7 +75,9 @@ export async function transpileFunction({ resource, functionPath, entryPoint, in
74
75
  conditions: ['node'],
75
76
  },
76
77
  },
77
- plugins: bundle ? [detectNativeModulesPlugin(), pnpmResolvePlugin(cwd())] : [],
78
+ plugins: bundle
79
+ ? [blockedModulesPlugin(), detectNativeModulesPlugin(), pnpmResolvePlugin(cwd())]
80
+ : [],
78
81
  });
79
82
  timings['transpile:build'] = performance.now() - viteStart;
80
83
  const verifyStart = performance.now();
@@ -0,0 +1,10 @@
1
+ import type { BlueprintResource } from '@sanity/blueprints';
2
+ import type { AssetPrepResult, IconInfo, ResolvedResource } from '../types.js';
3
+ /**
4
+ * Reads the image at `resource[iconKey]`. The returned `assetParameter` is `iconKey`, so once
5
+ * the bytes are stashed that property is rewritten from the path to the asset ID.
6
+ */
7
+ export declare function prepareIconAsset({ blueprintFileDir, resolvedResource, iconKey, workDir, }: IconInfo & {
8
+ blueprintFileDir: string;
9
+ resolvedResource: ResolvedResource<BlueprintResource>;
10
+ }): Promise<AssetPrepResult>;