@sanity/runtime-cli 11.1.2 → 11.1.4
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 +22 -21
- package/dist/actions/functions/dev.d.ts +1 -1
- package/dist/actions/functions/dev.js +2 -2
- package/dist/actions/functions/test.js +3 -3
- package/dist/commands/functions/dev.d.ts +1 -0
- package/dist/commands/functions/dev.js +11 -2
- package/dist/cores/blueprints/plan.js +0 -2
- package/dist/cores/functions/dev.d.ts +1 -0
- package/dist/cores/functions/dev.js +3 -3
- package/dist/cores/functions/test.js +1 -1
- package/dist/cores/index.js +1 -1
- package/dist/server/app.d.ts +1 -1
- package/dist/server/app.js +1 -2
- package/dist/server/static/components/console-panel.js +1 -1
- package/dist/utils/child-process-wrapper.js +46 -28
- package/dist/utils/invoke-local.js +18 -5
- package/dist/utils/types.d.ts +7 -1
- package/oclif.manifest.json +12 -3
- package/package.json +1 -1
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/11.1.
|
|
23
|
+
@sanity/runtime-cli/11.1.4 linux-x64 node-v24.11.1
|
|
24
24
|
$ sanity-run --help [COMMAND]
|
|
25
25
|
USAGE
|
|
26
26
|
$ sanity-run COMMAND
|
|
@@ -92,7 +92,7 @@ EXAMPLES
|
|
|
92
92
|
$ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
-
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.
|
|
95
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.4/src/commands/blueprints/add.ts)_
|
|
96
96
|
|
|
97
97
|
## `sanity-run blueprints config`
|
|
98
98
|
|
|
@@ -124,7 +124,7 @@ EXAMPLES
|
|
|
124
124
|
$ sanity-run blueprints config --edit --project-id <projectId> --stack-id <stackId>
|
|
125
125
|
```
|
|
126
126
|
|
|
127
|
-
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.
|
|
127
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.4/src/commands/blueprints/config.ts)_
|
|
128
128
|
|
|
129
129
|
## `sanity-run blueprints deploy`
|
|
130
130
|
|
|
@@ -146,7 +146,7 @@ EXAMPLES
|
|
|
146
146
|
$ sanity-run blueprints deploy --no-wait
|
|
147
147
|
```
|
|
148
148
|
|
|
149
|
-
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.
|
|
149
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.4/src/commands/blueprints/deploy.ts)_
|
|
150
150
|
|
|
151
151
|
## `sanity-run blueprints destroy`
|
|
152
152
|
|
|
@@ -173,7 +173,7 @@ EXAMPLES
|
|
|
173
173
|
$ sanity-run blueprints destroy --stack-id <stackId> --project-id <projectId> --force --no-wait
|
|
174
174
|
```
|
|
175
175
|
|
|
176
|
-
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.
|
|
176
|
+
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.4/src/commands/blueprints/destroy.ts)_
|
|
177
177
|
|
|
178
178
|
## `sanity-run blueprints doctor`
|
|
179
179
|
|
|
@@ -191,7 +191,7 @@ DESCRIPTION
|
|
|
191
191
|
Diagnose potential issues with Blueprint configuration
|
|
192
192
|
```
|
|
193
193
|
|
|
194
|
-
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.
|
|
194
|
+
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.4/src/commands/blueprints/doctor.ts)_
|
|
195
195
|
|
|
196
196
|
## `sanity-run blueprints info`
|
|
197
197
|
|
|
@@ -213,7 +213,7 @@ EXAMPLES
|
|
|
213
213
|
$ sanity-run blueprints info --stack-id <stackId>
|
|
214
214
|
```
|
|
215
215
|
|
|
216
|
-
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.
|
|
216
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.4/src/commands/blueprints/info.ts)_
|
|
217
217
|
|
|
218
218
|
## `sanity-run blueprints init [DIR]`
|
|
219
219
|
|
|
@@ -252,7 +252,7 @@ EXAMPLES
|
|
|
252
252
|
$ sanity-run blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
|
|
253
253
|
```
|
|
254
254
|
|
|
255
|
-
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.
|
|
255
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.4/src/commands/blueprints/init.ts)_
|
|
256
256
|
|
|
257
257
|
## `sanity-run blueprints logs`
|
|
258
258
|
|
|
@@ -274,7 +274,7 @@ EXAMPLES
|
|
|
274
274
|
$ sanity-run blueprints logs --watch
|
|
275
275
|
```
|
|
276
276
|
|
|
277
|
-
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.
|
|
277
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.4/src/commands/blueprints/logs.ts)_
|
|
278
278
|
|
|
279
279
|
## `sanity-run blueprints plan`
|
|
280
280
|
|
|
@@ -291,7 +291,7 @@ EXAMPLES
|
|
|
291
291
|
$ sanity-run blueprints plan
|
|
292
292
|
```
|
|
293
293
|
|
|
294
|
-
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.
|
|
294
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.4/src/commands/blueprints/plan.ts)_
|
|
295
295
|
|
|
296
296
|
## `sanity-run blueprints stacks`
|
|
297
297
|
|
|
@@ -316,7 +316,7 @@ EXAMPLES
|
|
|
316
316
|
$ sanity-run blueprints stacks --organization-id <organizationId>
|
|
317
317
|
```
|
|
318
318
|
|
|
319
|
-
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.
|
|
319
|
+
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.4/src/commands/blueprints/stacks.ts)_
|
|
320
320
|
|
|
321
321
|
## `sanity-run functions add`
|
|
322
322
|
|
|
@@ -358,7 +358,7 @@ EXAMPLES
|
|
|
358
358
|
$ sanity-run functions add --name my-function --type document-create --type document-update --lang js
|
|
359
359
|
```
|
|
360
360
|
|
|
361
|
-
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.
|
|
361
|
+
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.4/src/commands/functions/add.ts)_
|
|
362
362
|
|
|
363
363
|
## `sanity-run functions dev`
|
|
364
364
|
|
|
@@ -366,10 +366,11 @@ Start the Sanity Function emulator
|
|
|
366
366
|
|
|
367
367
|
```
|
|
368
368
|
USAGE
|
|
369
|
-
$ sanity-run functions dev [-p <value>] [-t <value>]
|
|
369
|
+
$ sanity-run functions dev [-h <value>] [-p <value>] [-t <value>]
|
|
370
370
|
|
|
371
371
|
FLAGS
|
|
372
|
-
-
|
|
372
|
+
-h, --host=<value> The local network interface at which to listen. [default: "localhost"]
|
|
373
|
+
-p, --port=<value> TCP port to start emulator on. [default: 8080]
|
|
373
374
|
-t, --timeout=<value> Maximum execution time for all functions, in seconds. Takes precedence over function-specific
|
|
374
375
|
`timeout`
|
|
375
376
|
|
|
@@ -377,10 +378,10 @@ DESCRIPTION
|
|
|
377
378
|
Start the Sanity Function emulator
|
|
378
379
|
|
|
379
380
|
EXAMPLES
|
|
380
|
-
$ sanity-run functions dev --port 8974
|
|
381
|
+
$ sanity-run functions dev --host 127.0.0.1 --port 8974
|
|
381
382
|
```
|
|
382
383
|
|
|
383
|
-
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.
|
|
384
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.4/src/commands/functions/dev.ts)_
|
|
384
385
|
|
|
385
386
|
## `sanity-run functions env add NAME KEY VALUE`
|
|
386
387
|
|
|
@@ -402,7 +403,7 @@ EXAMPLES
|
|
|
402
403
|
$ sanity-run functions env add MyFunction API_URL https://api.example.com/
|
|
403
404
|
```
|
|
404
405
|
|
|
405
|
-
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.
|
|
406
|
+
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.4/src/commands/functions/env/add.ts)_
|
|
406
407
|
|
|
407
408
|
## `sanity-run functions env list NAME`
|
|
408
409
|
|
|
@@ -422,7 +423,7 @@ EXAMPLES
|
|
|
422
423
|
$ sanity-run functions env list MyFunction
|
|
423
424
|
```
|
|
424
425
|
|
|
425
|
-
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.
|
|
426
|
+
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.4/src/commands/functions/env/list.ts)_
|
|
426
427
|
|
|
427
428
|
## `sanity-run functions env remove NAME KEY`
|
|
428
429
|
|
|
@@ -443,7 +444,7 @@ EXAMPLES
|
|
|
443
444
|
$ sanity-run functions env remove MyFunction API_URL
|
|
444
445
|
```
|
|
445
446
|
|
|
446
|
-
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.
|
|
447
|
+
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.4/src/commands/functions/env/remove.ts)_
|
|
447
448
|
|
|
448
449
|
## `sanity-run functions logs NAME`
|
|
449
450
|
|
|
@@ -477,7 +478,7 @@ EXAMPLES
|
|
|
477
478
|
$ sanity-run functions logs <name> --delete
|
|
478
479
|
```
|
|
479
480
|
|
|
480
|
-
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.
|
|
481
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.4/src/commands/functions/logs.ts)_
|
|
481
482
|
|
|
482
483
|
## `sanity-run functions test NAME`
|
|
483
484
|
|
|
@@ -526,7 +527,7 @@ EXAMPLES
|
|
|
526
527
|
$ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
|
|
527
528
|
```
|
|
528
529
|
|
|
529
|
-
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.
|
|
530
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v11.1.4/src/commands/functions/test.ts)_
|
|
530
531
|
|
|
531
532
|
## `sanity-run help [COMMAND]`
|
|
532
533
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { InvokeExecutionOptions } from '../../utils/types.js';
|
|
2
|
-
export declare function dev(port: number, executionOptions?: Partial<InvokeExecutionOptions>): Promise<void>;
|
|
2
|
+
export declare function dev(host: string, port: number, executionOptions?: Partial<InvokeExecutionOptions>): Promise<void>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import invoke from '../../utils/invoke-local.js';
|
|
2
2
|
export async function testAction(resource, payload, context, options) {
|
|
3
3
|
try {
|
|
4
|
-
const { json, logs } = await invoke(resource, payload, context, options);
|
|
5
|
-
return { error:
|
|
4
|
+
const { json, logs, error } = await invoke(resource, payload, context, options);
|
|
5
|
+
return { error: error, json, logs };
|
|
6
6
|
}
|
|
7
7
|
catch (error) {
|
|
8
|
-
return { error, json: undefined, logs: undefined };
|
|
8
|
+
return { error: error, json: undefined, logs: undefined };
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -3,6 +3,7 @@ export default class DevCommand extends Command {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
+
host: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
7
|
port: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
8
|
timeout: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
9
|
};
|
|
@@ -2,9 +2,18 @@ import { Command, Flags } from '@oclif/core';
|
|
|
2
2
|
import { functionDevCore } from '../../cores/functions/dev.js';
|
|
3
3
|
export default class DevCommand extends Command {
|
|
4
4
|
static description = 'Start the Sanity Function emulator';
|
|
5
|
-
static examples = ['<%= config.bin %> <%= command.id %> --port 8974'];
|
|
5
|
+
static examples = ['<%= config.bin %> <%= command.id %> --host 127.0.0.1 --port 8974'];
|
|
6
6
|
static flags = {
|
|
7
|
-
|
|
7
|
+
host: Flags.string({
|
|
8
|
+
char: 'h',
|
|
9
|
+
description: 'The local network interface at which to listen. [default: "localhost"]',
|
|
10
|
+
required: false,
|
|
11
|
+
}),
|
|
12
|
+
port: Flags.integer({
|
|
13
|
+
char: 'p',
|
|
14
|
+
description: 'TCP port to start emulator on. [default: 8080]',
|
|
15
|
+
required: false,
|
|
16
|
+
}),
|
|
8
17
|
timeout: Flags.integer({
|
|
9
18
|
char: 't',
|
|
10
19
|
description: 'Maximum execution time for all functions, in seconds. Takes precedence over function-specific `timeout`',
|
|
@@ -18,8 +18,6 @@ export async function blueprintPlanCore(options) {
|
|
|
18
18
|
const diff = stackDeployDiff(parsedBlueprint, stackResponse.stack);
|
|
19
19
|
if (diff)
|
|
20
20
|
log(diff);
|
|
21
|
-
else
|
|
22
|
-
log(chalk.dim('No changes detected to live deployment'));
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
23
|
log(`\n Run "${chalk.bold.magenta(`${bin} blueprints deploy`)}" to deploy these changes`);
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { dev } from '../../actions/functions/dev.js';
|
|
2
2
|
export async function functionDevCore(options) {
|
|
3
3
|
const { log, flags } = options;
|
|
4
|
-
const { port = 8080, timeout } = flags;
|
|
4
|
+
const { host = 'localhost', port = 8080, timeout } = flags;
|
|
5
5
|
// Construct execution options only if timeout is provided
|
|
6
6
|
const executionOptions = timeout
|
|
7
7
|
? { timeout }
|
|
8
8
|
: undefined;
|
|
9
9
|
try {
|
|
10
|
-
await dev(Number(port), executionOptions);
|
|
11
|
-
log(`Server is running on http
|
|
10
|
+
await dev(host, Number(port), executionOptions);
|
|
11
|
+
log(`Server is running on http://${host}:${port}\n`);
|
|
12
12
|
return {
|
|
13
13
|
success: true,
|
|
14
14
|
// hold the line...
|
|
@@ -129,7 +129,7 @@ export async function functionTestCore(options) {
|
|
|
129
129
|
spinner.fail('Function execution failed.');
|
|
130
130
|
return {
|
|
131
131
|
success: false,
|
|
132
|
-
error: error.
|
|
132
|
+
error: error.stack || error.message || error.name,
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
135
|
spinner.succeed('Function execution succeeded.');
|
package/dist/cores/index.js
CHANGED
|
@@ -51,7 +51,7 @@ export async function initDeployedBlueprintConfig(config) {
|
|
|
51
51
|
const auth = { token: config.token, scopeType, scopeId };
|
|
52
52
|
const stackResponse = await getStack({ stackId, auth });
|
|
53
53
|
if (!stackResponse.ok) {
|
|
54
|
-
config.log(`Could not retrieve deployment info for ${niceId(stackId)}
|
|
54
|
+
config.log(`Could not retrieve deployment info for ${niceId(stackId)}.`);
|
|
55
55
|
config.log(`Run \`${config.bin} blueprints doctor\` for diagnostics.`);
|
|
56
56
|
return { ok: false, error: 'Missing deployment' };
|
|
57
57
|
}
|
package/dist/server/app.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type InvokeExecutionOptions } from '../utils/types.js';
|
|
2
|
-
declare const app: (port: number, executionOptions?: Partial<InvokeExecutionOptions>) => void;
|
|
2
|
+
declare const app: (host: string, port: number, executionOptions?: Partial<InvokeExecutionOptions>) => void;
|
|
3
3
|
declare function parseDocumentUrl(url: string): {
|
|
4
4
|
projectId: string;
|
|
5
5
|
dataset: string;
|
package/dist/server/app.js
CHANGED
|
@@ -7,8 +7,7 @@ import config from '../config.js';
|
|
|
7
7
|
import { isRecord } from '../utils/is-record.js';
|
|
8
8
|
import { isEventType, } from '../utils/types.js';
|
|
9
9
|
import { handleInvokeRequest } from './handlers/invoke.js';
|
|
10
|
-
const
|
|
11
|
-
const app = (port, executionOptions) => {
|
|
10
|
+
const app = (host, port, executionOptions) => {
|
|
12
11
|
const requestListener = async (req, res) => {
|
|
13
12
|
res.setHeader('Content-Type', 'application/json');
|
|
14
13
|
switch (true) {
|
|
@@ -29,7 +29,7 @@ class ConsolePanel extends ApiBaseElement {
|
|
|
29
29
|
let update = ''
|
|
30
30
|
if (error) {
|
|
31
31
|
// Display error details in the console
|
|
32
|
-
update = error
|
|
32
|
+
update = (error.stack || error.message || error.name) ?? 'An error occurred.'
|
|
33
33
|
} else {
|
|
34
34
|
// Display regular logs
|
|
35
35
|
update = logs ?? '' // Handle case where logs might be null/undefined
|
|
@@ -84,44 +84,62 @@ process.on('message', async (data) => {
|
|
|
84
84
|
// invalid payload so return early
|
|
85
85
|
return
|
|
86
86
|
}
|
|
87
|
+
|
|
87
88
|
const {srcPath, payload} = jsonData
|
|
88
89
|
const {context, ...event} = payload
|
|
90
|
+
|
|
89
91
|
let logs = ''
|
|
92
|
+
let errorLogs = ''
|
|
90
93
|
let json = null
|
|
91
94
|
|
|
92
|
-
//
|
|
93
|
-
const entry = await import(getFunctionSource(srcPath))
|
|
94
|
-
|
|
95
|
-
let eventHandler = null
|
|
96
|
-
|
|
97
|
-
if (typeof entry.handler === 'function') {
|
|
98
|
-
eventHandler = entry.handler
|
|
99
|
-
} else if (typeof entry.default === 'function') {
|
|
100
|
-
eventHandler = entry.default
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (!eventHandler) {
|
|
104
|
-
throw new Error(
|
|
105
|
-
'No valid handler found. Please provide a default export or a named export, "handler"',
|
|
106
|
-
)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// backup stdout
|
|
95
|
+
// Capture stdout and stderr
|
|
110
96
|
const originalStdoutWrite = process.stdout.write.bind(process.stdout)
|
|
97
|
+
const originalStderrWrite = process.stderr.write.bind(process.stderr)
|
|
111
98
|
|
|
112
|
-
// redirect stdout to a buffer
|
|
113
99
|
process.stdout.write = (chunk) => {
|
|
114
|
-
if (typeof chunk === 'string')
|
|
115
|
-
|
|
116
|
-
|
|
100
|
+
if (typeof chunk === 'string') logs += chunk
|
|
101
|
+
return true
|
|
102
|
+
}
|
|
103
|
+
process.stderr.write = (chunk) => {
|
|
104
|
+
if (typeof chunk === 'string') errorLogs += chunk
|
|
117
105
|
return true
|
|
118
106
|
}
|
|
119
107
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
108
|
+
try {
|
|
109
|
+
// Import the function code
|
|
110
|
+
const entry = await import(getFunctionSource(srcPath))
|
|
111
|
+
const eventHandler = entry.handler || entry.default
|
|
112
|
+
|
|
113
|
+
if (typeof eventHandler !== 'function') {
|
|
114
|
+
throw new Error(
|
|
115
|
+
'No valid handler found. Please provide a default export or a named export, "handler"',
|
|
116
|
+
)
|
|
117
|
+
}
|
|
124
118
|
|
|
125
|
-
|
|
126
|
-
|
|
119
|
+
json = await eventHandler({context, event})
|
|
120
|
+
|
|
121
|
+
// Restore streams
|
|
122
|
+
process.stdout.write = originalStdoutWrite
|
|
123
|
+
process.stderr.write = originalStderrWrite
|
|
124
|
+
|
|
125
|
+
// Send result to parent
|
|
126
|
+
process.send(JSON.stringify({json, logs, errorLogs}))
|
|
127
|
+
} catch (err) {
|
|
128
|
+
// Restore streams on error
|
|
129
|
+
process.stdout.write = originalStdoutWrite
|
|
130
|
+
process.stderr.write = originalStderrWrite
|
|
131
|
+
|
|
132
|
+
const errorInfo = {
|
|
133
|
+
json: null,
|
|
134
|
+
logs,
|
|
135
|
+
errorLogs,
|
|
136
|
+
error: {
|
|
137
|
+
message: err?.message,
|
|
138
|
+
stack: err?.stack,
|
|
139
|
+
name: err?.name,
|
|
140
|
+
},
|
|
141
|
+
}
|
|
142
|
+
process.send(JSON.stringify(errorInfo))
|
|
143
|
+
process.exit(1)
|
|
144
|
+
}
|
|
127
145
|
})
|
|
@@ -106,17 +106,26 @@ export default async function invoke(resource, payload, context, options) {
|
|
|
106
106
|
executionStart = performance.now();
|
|
107
107
|
child = spawn('node', ['--enable-source-maps', getChildProcessWrapperPath()], {
|
|
108
108
|
cwd: cwd(),
|
|
109
|
-
stdio: ['
|
|
109
|
+
stdio: ['pipe', 'pipe', 'pipe', 'ipc'], // changed: use 'pipe' so we can capture output
|
|
110
110
|
env: { ...process.env, ...resource.env, FORCE_COLOR: forceColor ? '1' : '0' },
|
|
111
111
|
});
|
|
112
|
+
// NEW: capture stdout and stderr
|
|
113
|
+
let stdout = '';
|
|
114
|
+
let stderr = '';
|
|
115
|
+
child.stdout?.on('data', (data) => {
|
|
116
|
+
stdout += data.toString();
|
|
117
|
+
});
|
|
118
|
+
child.stderr?.on('data', (data) => {
|
|
119
|
+
stderr += data.toString();
|
|
120
|
+
});
|
|
112
121
|
child.on('message', (data) => {
|
|
113
122
|
const executionTimeMs = performance.now() - executionStart;
|
|
114
|
-
const { json, logs } = JSON.parse(data.toString());
|
|
123
|
+
const { json, logs, error } = JSON.parse(data.toString());
|
|
115
124
|
shutdown();
|
|
116
125
|
resolve({
|
|
117
126
|
json,
|
|
118
127
|
logs: sanitizeLogs(logs),
|
|
119
|
-
error
|
|
128
|
+
error,
|
|
120
129
|
timings: {
|
|
121
130
|
...bundleTimings,
|
|
122
131
|
execute: executionTimeMs,
|
|
@@ -131,12 +140,16 @@ export default async function invoke(resource, payload, context, options) {
|
|
|
131
140
|
const executionTimeMs = performance.now() - executionStart;
|
|
132
141
|
shutdown();
|
|
133
142
|
if (code !== 0) {
|
|
134
|
-
|
|
143
|
+
// use captured stderr if available
|
|
144
|
+
const message = stderr.trim().length > 0
|
|
145
|
+
? `Process failed with code ${code}\n${stderr}`
|
|
146
|
+
: `exited with code ${code}`;
|
|
147
|
+
reject(new Error(message));
|
|
135
148
|
}
|
|
136
149
|
else {
|
|
137
150
|
resolve({
|
|
138
151
|
json: undefined,
|
|
139
|
-
logs:
|
|
152
|
+
logs: sanitizeLogs(stdout),
|
|
140
153
|
error: undefined,
|
|
141
154
|
timings: {
|
|
142
155
|
...bundleTimings,
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -138,12 +138,18 @@ export interface InvokeExecutionOptions {
|
|
|
138
138
|
}
|
|
139
139
|
/** @internal */
|
|
140
140
|
export interface InvocationResponse {
|
|
141
|
-
error:
|
|
141
|
+
error: InvocationError | undefined;
|
|
142
142
|
json: JsonInvocationResponse | undefined;
|
|
143
143
|
logs: string | undefined;
|
|
144
144
|
timings?: Record<string, number>;
|
|
145
145
|
}
|
|
146
146
|
/** @internal */
|
|
147
|
+
export interface InvocationError {
|
|
148
|
+
stack: string;
|
|
149
|
+
message: string;
|
|
150
|
+
name: string;
|
|
151
|
+
}
|
|
152
|
+
/** @internal */
|
|
147
153
|
export interface JsonInvocationResponse {
|
|
148
154
|
data: Record<string, unknown> | undefined;
|
|
149
155
|
}
|
package/oclif.manifest.json
CHANGED
|
@@ -866,12 +866,21 @@
|
|
|
866
866
|
"args": {},
|
|
867
867
|
"description": "Start the Sanity Function emulator",
|
|
868
868
|
"examples": [
|
|
869
|
-
"<%= config.bin %> <%= command.id %> --port 8974"
|
|
869
|
+
"<%= config.bin %> <%= command.id %> --host 127.0.0.1 --port 8974"
|
|
870
870
|
],
|
|
871
871
|
"flags": {
|
|
872
|
+
"host": {
|
|
873
|
+
"char": "h",
|
|
874
|
+
"description": "The local network interface at which to listen. [default: \"localhost\"]",
|
|
875
|
+
"name": "host",
|
|
876
|
+
"required": false,
|
|
877
|
+
"hasDynamicHelp": false,
|
|
878
|
+
"multiple": false,
|
|
879
|
+
"type": "option"
|
|
880
|
+
},
|
|
872
881
|
"port": {
|
|
873
882
|
"char": "p",
|
|
874
|
-
"description": "
|
|
883
|
+
"description": "TCP port to start emulator on. [default: 8080]",
|
|
875
884
|
"name": "port",
|
|
876
885
|
"required": false,
|
|
877
886
|
"hasDynamicHelp": false,
|
|
@@ -1408,5 +1417,5 @@
|
|
|
1408
1417
|
]
|
|
1409
1418
|
}
|
|
1410
1419
|
},
|
|
1411
|
-
"version": "11.1.
|
|
1420
|
+
"version": "11.1.4"
|
|
1412
1421
|
}
|