@sanity/runtime-cli 8.3.0 → 8.3.1

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 (29) hide show
  1. package/README.md +16 -16
  2. package/dist/actions/blueprints/assets.js +5 -11
  3. package/dist/actions/blueprints/resources.js +22 -9
  4. package/dist/server/static/components/run-panel.js +1 -0
  5. package/dist/utils/{transpile/transpile-function.d.ts → bundle/bundle-function.d.ts} +1 -1
  6. package/dist/utils/{transpile/transpile-function.js → bundle/bundle-function.js} +16 -20
  7. package/dist/utils/{transpile → bundle}/verify-handler.js +1 -1
  8. package/dist/utils/functions/should-bundle.d.ts +2 -0
  9. package/dist/utils/functions/{should-transpile.js → should-bundle.js} +5 -4
  10. package/dist/utils/index.d.ts +0 -1
  11. package/dist/utils/index.js +0 -1
  12. package/dist/utils/invoke-local.js +7 -25
  13. package/dist/utils/types.d.ts +1 -2
  14. package/oclif.manifest.json +1 -1
  15. package/package.json +1 -6
  16. package/dist/utils/functions/packageJsonUtils.d.ts +0 -4
  17. package/dist/utils/functions/packageJsonUtils.js +0 -37
  18. package/dist/utils/functions/resolve-dependencies.d.ts +0 -2
  19. package/dist/utils/functions/resolve-dependencies.js +0 -18
  20. package/dist/utils/functions/resource-to-arc.d.ts +0 -2
  21. package/dist/utils/functions/resource-to-arc.js +0 -12
  22. package/dist/utils/functions/should-auto-resolve-deps.d.ts +0 -2
  23. package/dist/utils/functions/should-auto-resolve-deps.js +0 -7
  24. package/dist/utils/functions/should-transpile.d.ts +0 -2
  25. /package/dist/utils/{transpile → bundle}/cleanup-source-maps.d.ts +0 -0
  26. /package/dist/utils/{transpile → bundle}/cleanup-source-maps.js +0 -0
  27. /package/dist/utils/{transpile → bundle}/find-up.d.ts +0 -0
  28. /package/dist/utils/{transpile → bundle}/find-up.js +0 -0
  29. /package/dist/utils/{transpile → bundle}/verify-handler.d.ts +0 -0
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/8.3.0 linux-x64 node-v22.16.0
23
+ @sanity/runtime-cli/8.3.1 linux-x64 node-v22.16.0
24
24
  $ sanity-run --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity-run COMMAND
@@ -86,7 +86,7 @@ EXAMPLES
86
86
  $ sanity-run blueprints add function --name my-function --fn-type document-publish --lang js
87
87
  ```
88
88
 
89
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.0/src/commands/blueprints/add.ts)_
89
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.1/src/commands/blueprints/add.ts)_
90
90
 
91
91
  ## `sanity-run blueprints config`
92
92
 
@@ -117,7 +117,7 @@ EXAMPLES
117
117
  $ sanity-run blueprints config --edit --project-id <projectId> --stack-id <stackId>
118
118
  ```
119
119
 
120
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.0/src/commands/blueprints/config.ts)_
120
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.1/src/commands/blueprints/config.ts)_
121
121
 
122
122
  ## `sanity-run blueprints deploy`
123
123
 
@@ -139,7 +139,7 @@ EXAMPLES
139
139
  $ sanity-run blueprints deploy --no-wait
140
140
  ```
141
141
 
142
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.0/src/commands/blueprints/deploy.ts)_
142
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.1/src/commands/blueprints/deploy.ts)_
143
143
 
144
144
  ## `sanity-run blueprints destroy`
145
145
 
@@ -164,7 +164,7 @@ EXAMPLES
164
164
  $ sanity-run blueprints destroy --stack-id <stackId> --project-id <projectId> --force --no-wait
165
165
  ```
166
166
 
167
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.0/src/commands/blueprints/destroy.ts)_
167
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.1/src/commands/blueprints/destroy.ts)_
168
168
 
169
169
  ## `sanity-run blueprints info`
170
170
 
@@ -186,7 +186,7 @@ EXAMPLES
186
186
  $ sanity-run blueprints info --stack-id <stackId>
187
187
  ```
188
188
 
189
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.0/src/commands/blueprints/info.ts)_
189
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.1/src/commands/blueprints/info.ts)_
190
190
 
191
191
  ## `sanity-run blueprints init [DIR]`
192
192
 
@@ -224,7 +224,7 @@ EXAMPLES
224
224
  $ sanity-run blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
225
225
  ```
226
226
 
227
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.0/src/commands/blueprints/init.ts)_
227
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.1/src/commands/blueprints/init.ts)_
228
228
 
229
229
  ## `sanity-run blueprints logs`
230
230
 
@@ -246,7 +246,7 @@ EXAMPLES
246
246
  $ sanity-run blueprints logs --watch
247
247
  ```
248
248
 
249
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.0/src/commands/blueprints/logs.ts)_
249
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.1/src/commands/blueprints/logs.ts)_
250
250
 
251
251
  ## `sanity-run blueprints plan`
252
252
 
@@ -263,7 +263,7 @@ EXAMPLES
263
263
  $ sanity-run blueprints plan
264
264
  ```
265
265
 
266
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.0/src/commands/blueprints/plan.ts)_
266
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.1/src/commands/blueprints/plan.ts)_
267
267
 
268
268
  ## `sanity-run blueprints stacks`
269
269
 
@@ -285,7 +285,7 @@ EXAMPLES
285
285
  $ sanity-run blueprints stacks --project-id <projectId>
286
286
  ```
287
287
 
288
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.0/src/commands/blueprints/stacks.ts)_
288
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.1/src/commands/blueprints/stacks.ts)_
289
289
 
290
290
  ## `sanity-run functions dev`
291
291
 
@@ -305,7 +305,7 @@ EXAMPLES
305
305
  $ sanity-run functions dev --port 8974
306
306
  ```
307
307
 
308
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.0/src/commands/functions/dev.ts)_
308
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.1/src/commands/functions/dev.ts)_
309
309
 
310
310
  ## `sanity-run functions env add NAME KEY VALUE`
311
311
 
@@ -327,7 +327,7 @@ EXAMPLES
327
327
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
328
328
  ```
329
329
 
330
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.0/src/commands/functions/env/add.ts)_
330
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.1/src/commands/functions/env/add.ts)_
331
331
 
332
332
  ## `sanity-run functions env list NAME`
333
333
 
@@ -347,7 +347,7 @@ EXAMPLES
347
347
  $ sanity-run functions env list MyFunction
348
348
  ```
349
349
 
350
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.0/src/commands/functions/env/list.ts)_
350
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.1/src/commands/functions/env/list.ts)_
351
351
 
352
352
  ## `sanity-run functions env remove NAME KEY`
353
353
 
@@ -368,7 +368,7 @@ EXAMPLES
368
368
  $ sanity-run functions env remove MyFunction API_URL
369
369
  ```
370
370
 
371
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.0/src/commands/functions/env/remove.ts)_
371
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.1/src/commands/functions/env/remove.ts)_
372
372
 
373
373
  ## `sanity-run functions logs NAME`
374
374
 
@@ -402,7 +402,7 @@ EXAMPLES
402
402
  $ sanity-run functions logs <name> --delete
403
403
  ```
404
404
 
405
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.0/src/commands/functions/logs.ts)_
405
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.1/src/commands/functions/logs.ts)_
406
406
 
407
407
  ## `sanity-run functions test NAME`
408
408
 
@@ -435,7 +435,7 @@ EXAMPLES
435
435
  $ sanity-run functions test <name> --data '{ "id": 1 }' --timeout 60
436
436
  ```
437
437
 
438
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.0/src/commands/functions/test.ts)_
438
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v8.3.1/src/commands/functions/test.ts)_
439
439
 
440
440
  ## `sanity-run help [COMMAND]`
441
441
 
@@ -3,11 +3,9 @@ import path from 'node:path';
3
3
  import { cwd } from 'node:process';
4
4
  import AdmZip from 'adm-zip';
5
5
  import config from '../../config.js';
6
- import { resolveResourceDependencies } from '../../utils/functions/resolve-dependencies.js';
7
- import { shouldAutoResolveDependencies } from '../../utils/functions/should-auto-resolve-deps.js';
8
- import { shouldTranspileFunction } from '../../utils/functions/should-transpile.js';
6
+ import { bundleFunction } from '../../utils/bundle/bundle-function.js';
7
+ import { shouldBundleFunction } from '../../utils/functions/should-bundle.js';
9
8
  import getHeaders from '../../utils/get-headers.js';
10
- import { transpileFunction } from '../../utils/transpile/transpile-function.js';
11
9
  const { apiUrl } = config;
12
10
  export const stashUrl = `${apiUrl}vX/blueprints/assets/stash`;
13
11
  export async function stashAsset({ resource, auth, }) {
@@ -15,10 +13,10 @@ export async function stashAsset({ resource, auth, }) {
15
13
  throw new Error('Resource src is required');
16
14
  let functionPath = path.join(cwd(), resource.src);
17
15
  let cleanup = async () => { };
18
- const shouldTranspile = await shouldTranspileFunction(resource);
19
- if (shouldTranspile) {
16
+ const shouldBundle = await shouldBundleFunction(resource);
17
+ if (shouldBundle) {
20
18
  try {
21
- const result = await transpileFunction(resource);
19
+ const result = await bundleFunction(resource);
22
20
  functionPath = result.outputDir;
23
21
  cleanup = result.cleanup;
24
22
  }
@@ -26,10 +24,6 @@ export async function stashAsset({ resource, auth, }) {
26
24
  return { success: false, error: err instanceof Error ? err.message : `${err}` };
27
25
  }
28
26
  }
29
- const shouldResolveDependencies = await shouldAutoResolveDependencies(resource);
30
- if (shouldResolveDependencies) {
31
- await resolveResourceDependencies(resource, shouldTranspile);
32
- }
33
27
  try {
34
28
  const stats = await fs.promises.stat(functionPath);
35
29
  const zip = new AdmZip();
@@ -4,7 +4,8 @@ import { existsSync } from 'node:fs';
4
4
  import { dirname, join } from 'node:path';
5
5
  import { cwd } from 'node:process';
6
6
  import chalk from 'chalk';
7
- import { addResourceToBlueprint, writeOrUpdateNodeDependency } from './blueprint.js';
7
+ import { getLatestNpmVersion } from '../../utils/other/npmjs.js';
8
+ import { addResourceToBlueprint } from './blueprint.js';
8
9
  const DEFAULT_FUNCTION_TEMPLATE = /*js*/ `export async function handler({context, event}) {
9
10
  const time = new Date().toLocaleTimeString()
10
11
  console.log(\`👋 Your Sanity Function was called at \${time}\`)
@@ -15,6 +16,11 @@ export const handler = documentEventHandler(async ({ context, event }) => {
15
16
  const time = new Date().toLocaleTimeString()
16
17
  console.log(\`👋 Your Sanity Function was called at \${time}\`)
17
18
  })`;
19
+ const DEFAULT_PACKAGE_JSON = {
20
+ name: '',
21
+ type: 'module',
22
+ main: '',
23
+ };
18
24
  /**
19
25
  * Creates a new function resource file and adds it to the blueprint
20
26
  */
@@ -42,16 +48,23 @@ export async function createFunctionResource(options) {
42
48
  // Create index.<lang> with default template
43
49
  const indexPath = join(functionDir, `index.${lang}`);
44
50
  writeFileSync(indexPath, addHelpers ? DEFAULT_HELPER_FUNCTION_TEMPLATE : DEFAULT_FUNCTION_TEMPLATE);
45
- if (addHelpers && blueprintFilePath) {
46
- try {
47
- await writeOrUpdateNodeDependency({ blueprintFilePath, dependency: '@sanity/functions' });
48
- }
49
- catch (err) {
50
- throw new Error('Unable to add @sanity/functions to your project.', { cause: err });
51
- }
51
+ // Create package.json
52
+ const packagePath = join(functionDir, 'package.json');
53
+ const packageContent = {
54
+ ...DEFAULT_PACKAGE_JSON,
55
+ name,
56
+ main: `index.${lang}`,
57
+ dependencies: {},
58
+ };
59
+ if (addHelpers) {
60
+ const helpersVersion = await getLatestNpmVersion('@sanity/functions');
61
+ packageContent.dependencies = {
62
+ '@sanity/functions': helpersVersion,
63
+ };
52
64
  }
65
+ writeFileSync(packagePath, JSON.stringify(packageContent, null, 2));
53
66
  if (installCommand) {
54
- const success = await runPackageInstall(workingDir, installCommand);
67
+ const success = await runPackageInstall(functionDir, installCommand);
55
68
  if (!success) {
56
69
  throw new Error(`Failed to install dependencies using \`${installCommand}\``);
57
70
  }
@@ -16,6 +16,7 @@ class RunPanel extends ApiBaseElement {
16
16
  invoke = () => {
17
17
  this.api.store.result = {logs: '', time: 0}
18
18
  const payloadText = this.createPayloadText(this.api.store.payload.state.doc)
19
+ console.log(payloadText)
19
20
  const event = JSON.parse(payloadText)
20
21
  const context = {
21
22
  clientOptions: {
@@ -1,5 +1,5 @@
1
1
  import type { FunctionResource } from '../types.js';
2
- export declare function transpileFunction(resource: FunctionResource): Promise<{
2
+ export declare function bundleFunction(resource: FunctionResource): Promise<{
3
3
  type: string;
4
4
  outputDir: string;
5
5
  warnings: string[];
@@ -8,25 +8,25 @@ import { findFunctionEntryPoint } from '../functions/find-entry-point.js';
8
8
  import { cleanupSourceMaps } from './cleanup-source-maps.js';
9
9
  import { findDirUp } from './find-up.js';
10
10
  import { verifyHandler } from './verify-handler.js';
11
- export async function transpileFunction(resource) {
11
+ export async function bundleFunction(resource) {
12
12
  if (!resource.src)
13
13
  throw new Error('Resource src is required');
14
14
  if (!resource.name)
15
15
  throw new Error('Resource name is required');
16
16
  const timings = {};
17
- const transpileStart = performance.now();
17
+ const bundleStart = performance.now();
18
18
  const sourcePath = path.resolve(cwd(), resource.src);
19
19
  const stats = await stat(sourcePath);
20
20
  const fnDisplayName = resource.displayName ?? resource.name;
21
21
  const findEntryStart = performance.now();
22
22
  const entry = await findFunctionEntryPoint(sourcePath, fnDisplayName);
23
- timings['transpile:findEntry'] = performance.now() - findEntryStart;
23
+ timings['bundle:findEntry'] = performance.now() - findEntryStart;
24
24
  const entryDir = stats.isFile() ? path.dirname(sourcePath) : sourcePath;
25
25
  const outputPathStart = performance.now();
26
- const outputDir = await getTranspileOutputPath(entryDir, resource.name);
26
+ const outputDir = await getBundleOutputPath(entryDir, resource.name);
27
27
  const outputFile = path.join(outputDir, getOutputFilename(entry));
28
28
  const fnRootDir = (await findDirUp('node_modules', entryDir)) || entryDir;
29
- timings['transpile:setupOutput'] = performance.now() - outputPathStart;
29
+ timings['bundle:setupOutput'] = performance.now() - outputPathStart;
30
30
  async function cleanupTmpDir() {
31
31
  // Feel a certain way about leaving things uncleaned, but helps with debugging for now
32
32
  // await rm(outputDir, {recursive: true, force: true}).catch(logCleanupFailure)
@@ -48,32 +48,28 @@ export async function transpileFunction(resource) {
48
48
  output: {
49
49
  format: 'esm',
50
50
  entryFileNames: getOutputFilename(entry),
51
- // Do NOT inline anything from node_modules
52
- preserveModules: true, // Key setting
53
- preserveModulesRoot: fnRootDir,
54
51
  },
55
- external: [/node_modules/], // treat all node_modules as external
56
52
  },
57
53
  },
58
54
  ssr: {
59
- noExternal: [], // Do NOT bundle node_modules
55
+ noExternal: true,
60
56
  resolve: {
61
- conditions: ['node'],
57
+ conditions: ['sanity-function', 'node', 'vite'],
62
58
  },
63
59
  },
64
60
  plugins: [tsConfigPaths()],
65
61
  });
66
- timings['transpile:build'] = performance.now() - viteStart;
62
+ timings['bundle:build'] = performance.now() - viteStart;
67
63
  const verifyStart = performance.now();
68
64
  await verifyHandler(result);
69
- timings['transpile:verify'] = performance.now() - verifyStart;
65
+ timings['bundle:verify'] = performance.now() - verifyStart;
70
66
  const pkgStart = performance.now();
71
- await writeTranspiledPackageJson(entryDir, outputFile);
72
- timings['transpile:writePackage'] = performance.now() - pkgStart;
67
+ await writeBundledPackageJson(entryDir, outputFile);
68
+ timings['bundle:writePackage'] = performance.now() - pkgStart;
73
69
  const cleanupStart = performance.now();
74
70
  await cleanupSourceMaps(sourcePath, outputDir);
75
- timings['transpile:cleanupMaps'] = performance.now() - cleanupStart;
76
- timings.bundle = performance.now() - transpileStart;
71
+ timings['bundle:cleanupMaps'] = performance.now() - cleanupStart;
72
+ timings.bundle = performance.now() - bundleStart;
77
73
  return {
78
74
  type: 'success',
79
75
  outputDir,
@@ -84,12 +80,12 @@ export async function transpileFunction(resource) {
84
80
  }
85
81
  catch (err) {
86
82
  await cleanupTmpDir();
87
- throw new Error(`Transpiling of function failed: ${err instanceof Error ? err.message : err}`, {
83
+ throw new Error(`Bundling of function failed: ${err instanceof Error ? err.message : err}`, {
88
84
  cause: err,
89
85
  });
90
86
  }
91
87
  }
92
- async function writeTranspiledPackageJson(inputDir, outputFilePath) {
88
+ async function writeBundledPackageJson(inputDir, outputFilePath) {
93
89
  const baseName = path.basename(outputFilePath);
94
90
  let original;
95
91
  try {
@@ -111,7 +107,7 @@ async function writeTranspiledPackageJson(inputDir, outputFilePath) {
111
107
  const pkgJsonOutputPath = path.join(path.dirname(outputFilePath), 'package.json');
112
108
  await writeFile(pkgJsonOutputPath, JSON.stringify(bundled, null, 2));
113
109
  }
114
- async function getTranspileOutputPath(entryDir, fnName) {
110
+ async function getBundleOutputPath(entryDir, fnName) {
115
111
  const tmpPath = path.resolve(entryDir, '.build', `function-${fnName}`);
116
112
  await rm(tmpPath, { recursive: true, force: true }).catch(logCleanupFailure);
117
113
  await mkdir(tmpPath, { recursive: true });
@@ -3,7 +3,7 @@ export async function verifyHandler(result) {
3
3
  throw new Error('Incorrect build output, got watcher');
4
4
  }
5
5
  const outputs = (Array.isArray(result) ? result : [result]).flatMap(({ output }) => output);
6
- const bundledIndex = outputs.find((output) => output.type === 'chunk' && output.isEntry && output.fileName === 'index.js');
6
+ const bundledIndex = outputs.find((output) => output.type === 'chunk' && output.isEntry && output.name === 'index');
7
7
  if (!bundledIndex || bundledIndex.type !== 'chunk') {
8
8
  throw new Error('Unexpected build output, no bundled index found');
9
9
  }
@@ -0,0 +1,2 @@
1
+ import type { FunctionResource } from '../types.js';
2
+ export declare function shouldBundleFunction(resource: FunctionResource): Promise<boolean>;
@@ -1,7 +1,8 @@
1
1
  import { findFunctionEntryPoint } from './find-entry-point.js';
2
- export async function shouldTranspileFunction(resource) {
3
- if (typeof resource.transpile === 'boolean') {
4
- return resource.transpile;
2
+ export async function shouldBundleFunction(resource) {
3
+ // 1. Explicit configuration takes precedence
4
+ if (typeof resource.bundle === 'boolean') {
5
+ return resource.bundle;
5
6
  }
6
7
  if (!resource.src) {
7
8
  // Cannot determine without a source path
@@ -16,7 +17,7 @@ export async function shouldTranspileFunction(resource) {
16
17
  catch (err) {
17
18
  // If we cannot find the entry point, we cannot determine if it's TS.
18
19
  // Log a warning and default to false (don't bundle).
19
- console.warn(`[warn] Could not determine entry point for function "${resource.displayName ?? resource.name}" while checking if transpiling is needed: ${err instanceof Error ? err.message : err}`);
20
+ console.warn(`[warn] Could not determine entry point for function "${resource.displayName ?? resource.name}" while checking if bundling is needed: ${err instanceof Error ? err.message : err}`);
20
21
  return false;
21
22
  }
22
23
  }
@@ -1,6 +1,5 @@
1
1
  export * as display from './display/index.js';
2
2
  export * as findFunction from './find-function.js';
3
- export * as invokeLocal from './invoke-local.js';
4
3
  export * as types from './types.js';
5
4
  export * as validate from './validate/index.js';
6
5
  export * as vendor from './vendor/index.js';
@@ -1,6 +1,5 @@
1
1
  export * as display from './display/index.js';
2
2
  export * as findFunction from './find-function.js';
3
- export * as invokeLocal from './invoke-local.js';
4
3
  export * as types from './types.js';
5
4
  export * as validate from './validate/index.js';
6
5
  export * as vendor from './vendor/index.js';
@@ -5,12 +5,9 @@ import { setTimeout } from 'node:timers';
5
5
  import { fileURLToPath } from 'node:url';
6
6
  import * as groq from 'groq-js';
7
7
  import config from '../config.js';
8
+ import { bundleFunction } from './bundle/bundle-function.js';
8
9
  import { findFunctionEntryPoint } from './functions/find-entry-point.js';
9
- import { cleanupTempPackageJson, createTempPackageJson, doesPackageJsonExists, } from './functions/packageJsonUtils.js';
10
- import { resolveResourceDependencies } from './functions/resolve-dependencies.js';
11
- import { shouldAutoResolveDependencies } from './functions/should-auto-resolve-deps.js';
12
- import { shouldTranspileFunction } from './functions/should-transpile.js';
13
- import { transpileFunction } from './transpile/transpile-function.js';
10
+ import { shouldBundleFunction } from './functions/should-bundle.js';
14
11
  function getChildProcessWrapperPath() {
15
12
  return fileURLToPath(new URL('./child-process-wrapper.js', import.meta.url));
16
13
  }
@@ -70,26 +67,15 @@ export default async function invoke(resource, data, context, options) {
70
67
  let cleanupBundle = async () => { };
71
68
  let functionPath = '';
72
69
  let bundleTimings = undefined;
73
- // If no package.json exists we will create a temporary one to avoid the
74
- // Module Type warning from node
75
- const existingPackageJson = doesPackageJsonExists(resource);
76
- const shouldTranspile = await shouldTranspileFunction(resource);
77
- if (shouldTranspile) {
78
- const transpileResult = await transpileFunction(resource);
79
- functionPath = await findFunctionEntryPoint(transpileResult.outputDir);
80
- bundleTimings = transpileResult.timings;
81
- cleanupBundle = transpileResult.cleanup;
70
+ if (await shouldBundleFunction(resource)) {
71
+ const bundleResult = await bundleFunction(resource);
72
+ functionPath = await findFunctionEntryPoint(bundleResult.outputDir);
73
+ bundleTimings = bundleResult.timings;
74
+ cleanupBundle = bundleResult.cleanup;
82
75
  }
83
76
  else {
84
77
  functionPath = await findFunctionEntryPoint(resource.src, resource.displayName ?? resource.name);
85
78
  }
86
- const shouldResolveDependencies = await shouldAutoResolveDependencies(resource);
87
- if (shouldResolveDependencies && existingPackageJson) {
88
- await resolveResourceDependencies(resource, shouldTranspile);
89
- }
90
- if (!existingPackageJson) {
91
- createTempPackageJson(functionPath);
92
- }
93
79
  return new Promise((resolve, reject) => {
94
80
  let child;
95
81
  let timer;
@@ -160,10 +146,6 @@ export default async function invoke(resource, data, context, options) {
160
146
  if (child && !child.killed) {
161
147
  child.kill();
162
148
  }
163
- // If we previously created a temporary package.json, let's clean it up
164
- if (!existingPackageJson) {
165
- cleanupTempPackageJson(functionPath);
166
- }
167
149
  cleanupBundle().catch((err) => console.warn('Bundle cleanup failed:', err));
168
150
  }
169
151
  start();
@@ -71,8 +71,7 @@ export declare function isLocalFunctionResource(r: Resource): r is FunctionResou
71
71
  /** @internal */
72
72
  export interface FunctionResource extends Resource {
73
73
  src?: string;
74
- autoResolveDeps?: boolean;
75
- transpile?: boolean;
74
+ bundle?: boolean;
76
75
  memory?: number;
77
76
  timeout?: number;
78
77
  env?: Record<string, string>;
@@ -871,5 +871,5 @@
871
871
  ]
872
872
  }
873
873
  },
874
- "version": "8.3.0"
874
+ "version": "8.3.1"
875
875
  }
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": "8.3.0",
4
+ "version": "8.3.1",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",
@@ -69,14 +69,11 @@
69
69
  "postpack": "shx rm -f oclif.manifest.json",
70
70
  "pretest": "cd test/integration && npm install",
71
71
  "test": "vitest run",
72
- "test:depmgmt": "vitest run --config ./test-depmgmt/vitest.config.ts",
73
72
  "posttest": "npm run lint",
74
73
  "test:watch": "vitest",
75
74
  "watch": "tsc --watch"
76
75
  },
77
76
  "dependencies": {
78
- "@architect/hydrate": "^4.0.8",
79
- "@architect/inventory": "^4.0.9",
80
77
  "@oclif/core": "^4.3.0",
81
78
  "@oclif/plugin-help": "^6.2.28",
82
79
  "adm-zip": "^0.5.16",
@@ -105,9 +102,7 @@
105
102
  "@oclif/test": "^4.1.13",
106
103
  "@playwright/test": "^1.52.0",
107
104
  "@rollup/plugin-node-resolve": "^16.0.1",
108
- "@sanity/blueprints": "^0.1.0",
109
105
  "@sanity/client": "^7.3.0",
110
- "@sanity/functions": "^1.0.3",
111
106
  "@types/adm-zip": "^0.5.7",
112
107
  "@types/cardinal": "^2.1.1",
113
108
  "@types/mime-types": "^2.1.4",
@@ -1,4 +0,0 @@
1
- import type { FunctionResource } from '../types.js';
2
- export declare function doesPackageJsonExists(resource: FunctionResource): boolean;
3
- export declare function createTempPackageJson(functionPath: string): boolean;
4
- export declare function cleanupTempPackageJson(functionPath: string): boolean;
@@ -1,37 +0,0 @@
1
- import { existsSync, rmSync, writeFileSync } from 'node:fs';
2
- import { dirname, join, resolve } from 'node:path';
3
- import { cwd } from 'node:process';
4
- function getPackageJsonPath(functionPath) {
5
- const functionDir = dirname(functionPath);
6
- return join(functionDir, 'package.json');
7
- }
8
- export function doesPackageJsonExists(resource) {
9
- if (!resource.src) {
10
- // Cannot determine without a source path
11
- return false;
12
- }
13
- const absolutePath = resolve(cwd(), resource.src);
14
- const packageJsonPath = join(absolutePath, 'package.json');
15
- return existsSync(packageJsonPath);
16
- }
17
- export function createTempPackageJson(functionPath) {
18
- if (!functionPath) {
19
- // Cannot determine without a source path
20
- return false;
21
- }
22
- const packageJsonPath = getPackageJsonPath(functionPath);
23
- const packageContent = { type: 'module' };
24
- writeFileSync(packageJsonPath, JSON.stringify(packageContent, null, 2));
25
- return !existsSync(packageJsonPath);
26
- }
27
- export function cleanupTempPackageJson(functionPath) {
28
- if (!functionPath) {
29
- // Cannot determine without a source path
30
- return false;
31
- }
32
- const packageJsonPath = getPackageJsonPath(functionPath);
33
- if (existsSync(packageJsonPath)) {
34
- rmSync(packageJsonPath);
35
- }
36
- return !existsSync(packageJsonPath);
37
- }
@@ -1,2 +0,0 @@
1
- import type { FunctionResource } from '../types.js';
2
- export declare function resolveResourceDependencies(resource: FunctionResource, transpiled: boolean): Promise<void>;
@@ -1,18 +0,0 @@
1
- import hydrate from '@architect/hydrate';
2
- import inventory from '@architect/inventory';
3
- import { convertResourceToArcFormat } from './resource-to-arc.js';
4
- export async function resolveResourceDependencies(resource, transpiled) {
5
- const rawArc = await convertResourceToArcFormat(resource, transpiled);
6
- const inv = await inventory({ rawArc });
7
- try {
8
- await hydrate.install({ inventory: inv, hydrateShared: false, quiet: true });
9
- }
10
- catch (err) {
11
- // This is a temporary fix.
12
- const regex = /ENOTDIR: not a directory, unlink ['"].*[/\\]node_modules['"]/;
13
- const errorMessage = err instanceof Error ? err.message : String(err);
14
- if (!regex.test(errorMessage)) {
15
- throw err;
16
- }
17
- }
18
- }
@@ -1,2 +0,0 @@
1
- import type { FunctionResource } from '../types.js';
2
- export declare function convertResourceToArcFormat(resource: FunctionResource, transpiled: boolean): Promise<string>;
@@ -1,12 +0,0 @@
1
- import { sep } from 'node:path';
2
- export async function convertResourceToArcFormat(resource, transpiled) {
3
- const srcPath = resource.src?.split(sep).join('/');
4
- const functionPath = transpiled ? `${srcPath}/.build/function-${resource.name}` : srcPath;
5
- return `@app
6
- hydrate-function
7
-
8
- @events
9
- ${resource.name}
10
- src ${functionPath}
11
- `;
12
- }
@@ -1,2 +0,0 @@
1
- import type { FunctionResource } from '../types.js';
2
- export declare function shouldAutoResolveDependencies(resource: FunctionResource): Promise<boolean>;
@@ -1,7 +0,0 @@
1
- export async function shouldAutoResolveDependencies(resource) {
2
- if (typeof resource.autoResolveDeps === 'boolean') {
3
- return resource.autoResolveDeps;
4
- }
5
- // otherwise hydrate is the default
6
- return true;
7
- }
@@ -1,2 +0,0 @@
1
- import type { FunctionResource } from '../types.js';
2
- export declare function shouldTranspileFunction(resource: FunctionResource): Promise<boolean>;
File without changes
File without changes