@ryanatkn/gro 0.175.0 → 0.176.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/run.task.d.ts +5 -1
- package/dist/run.task.d.ts.map +1 -1
- package/dist/run.task.js +22 -12
- package/package.json +1 -1
- package/src/lib/run.task.ts +25 -14
package/dist/run.task.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { type Task } from './task.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Runs a TypeScript file with Gro's loader, forwarding all args to the script.
|
|
5
|
+
* Useful for scripts that need SvelteKit shims ($lib, $env, etc).
|
|
6
|
+
*/
|
|
3
7
|
/** @nodocs */
|
|
4
8
|
export declare const Args: z.ZodObject<{
|
|
5
9
|
_: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
6
|
-
}, z.core.$
|
|
10
|
+
}, z.core.$catchall<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>]>>>;
|
|
7
11
|
export type Args = z.infer<typeof Args>;
|
|
8
12
|
/** @nodocs */
|
|
9
13
|
export declare const task: Task<Args>;
|
package/dist/run.task.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/run.task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAItB,OAAO,EAAa,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"run.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/run.task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAItB,OAAO,EAAa,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAIhD;;;GAGG;AAEH,cAAc;AACd,eAAO,MAAM,IAAI;;8JAWf,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC,cAAc;AACd,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,CA2B3B,CAAC"}
|
package/dist/run.task.js
CHANGED
|
@@ -3,31 +3,41 @@ import { styleText as st } from 'node:util';
|
|
|
3
3
|
import { existsSync } from 'node:fs';
|
|
4
4
|
import { Task_Error } from "./task.js";
|
|
5
5
|
import { resolve_gro_module_path, spawn_with_loader } from "./gro_helpers.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
import { serialize_args } from "./args.js";
|
|
7
|
+
/**
|
|
8
|
+
* Runs a TypeScript file with Gro's loader, forwarding all args to the script.
|
|
9
|
+
* Useful for scripts that need SvelteKit shims ($lib, $env, etc).
|
|
10
|
+
*/
|
|
9
11
|
/** @nodocs */
|
|
10
|
-
export const Args = z
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
export const Args = z
|
|
13
|
+
.object({
|
|
14
|
+
_: z.array(z.string()).meta({ description: 'the file path to run' }).default([]),
|
|
15
|
+
})
|
|
16
|
+
.catchall(z.union([
|
|
17
|
+
z.string(),
|
|
18
|
+
z.number(),
|
|
19
|
+
z.boolean(),
|
|
20
|
+
z.array(z.union([z.string(), z.number(), z.boolean()])),
|
|
21
|
+
]));
|
|
16
22
|
/** @nodocs */
|
|
17
23
|
export const task = {
|
|
18
24
|
summary: 'execute a file with the loader, like `node` but works for TypeScript',
|
|
19
25
|
Args,
|
|
20
26
|
run: async ({ args, log }) => {
|
|
21
|
-
const { _
|
|
27
|
+
const { _, ...forwarded_args } = args;
|
|
28
|
+
const [path, ...positional_argv] = _;
|
|
22
29
|
if (!path) {
|
|
23
|
-
log.info(st('green', '\n\nUsage: ') + st('cyan', 'gro run path/to/file.ts [...
|
|
30
|
+
log.info(st('green', '\n\nUsage: ') + st('cyan', 'gro run path/to/file.ts [...args]\n'));
|
|
24
31
|
return;
|
|
25
32
|
}
|
|
26
33
|
if (!existsSync(path)) {
|
|
27
34
|
throw new Task_Error('Cannot find file to run at path: ' + path);
|
|
28
35
|
}
|
|
36
|
+
// Reconstruct argv: positional args + serialized named args
|
|
37
|
+
const named_argv = serialize_args(forwarded_args);
|
|
38
|
+
const full_argv = [...positional_argv, ...named_argv];
|
|
29
39
|
const loader_path = resolve_gro_module_path('loader.js');
|
|
30
|
-
const spawned = await spawn_with_loader(loader_path, path,
|
|
40
|
+
const spawned = await spawn_with_loader(loader_path, path, full_argv);
|
|
31
41
|
if (!spawned.ok) {
|
|
32
42
|
throw new Task_Error(`\`gro run ${path}\` failed with exit code ${spawned.code}`);
|
|
33
43
|
}
|
package/package.json
CHANGED
package/src/lib/run.task.ts
CHANGED
|
@@ -4,18 +4,26 @@ import {existsSync} from 'node:fs';
|
|
|
4
4
|
|
|
5
5
|
import {Task_Error, type Task} from './task.ts';
|
|
6
6
|
import {resolve_gro_module_path, spawn_with_loader} from './gro_helpers.ts';
|
|
7
|
+
import {serialize_args} from './args.ts';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Runs a TypeScript file with Gro's loader, forwarding all args to the script.
|
|
11
|
+
* Useful for scripts that need SvelteKit shims ($lib, $env, etc).
|
|
12
|
+
*/
|
|
11
13
|
|
|
12
14
|
/** @nodocs */
|
|
13
|
-
export const Args = z
|
|
14
|
-
|
|
15
|
-
.array(z.string())
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
export const Args = z
|
|
16
|
+
.object({
|
|
17
|
+
_: z.array(z.string()).meta({description: 'the file path to run'}).default([]),
|
|
18
|
+
})
|
|
19
|
+
.catchall(
|
|
20
|
+
z.union([
|
|
21
|
+
z.string(),
|
|
22
|
+
z.number(),
|
|
23
|
+
z.boolean(),
|
|
24
|
+
z.array(z.union([z.string(), z.number(), z.boolean()])),
|
|
25
|
+
]),
|
|
26
|
+
);
|
|
19
27
|
export type Args = z.infer<typeof Args>;
|
|
20
28
|
|
|
21
29
|
/** @nodocs */
|
|
@@ -23,12 +31,11 @@ export const task: Task<Args> = {
|
|
|
23
31
|
summary: 'execute a file with the loader, like `node` but works for TypeScript',
|
|
24
32
|
Args,
|
|
25
33
|
run: async ({args, log}) => {
|
|
26
|
-
const {
|
|
27
|
-
|
|
28
|
-
} = args;
|
|
34
|
+
const {_, ...forwarded_args} = args;
|
|
35
|
+
const [path, ...positional_argv] = _;
|
|
29
36
|
|
|
30
37
|
if (!path) {
|
|
31
|
-
log.info(st('green', '\n\nUsage: ') + st('cyan', 'gro run path/to/file.ts [...
|
|
38
|
+
log.info(st('green', '\n\nUsage: ') + st('cyan', 'gro run path/to/file.ts [...args]\n'));
|
|
32
39
|
return;
|
|
33
40
|
}
|
|
34
41
|
|
|
@@ -36,9 +43,13 @@ export const task: Task<Args> = {
|
|
|
36
43
|
throw new Task_Error('Cannot find file to run at path: ' + path);
|
|
37
44
|
}
|
|
38
45
|
|
|
46
|
+
// Reconstruct argv: positional args + serialized named args
|
|
47
|
+
const named_argv = serialize_args(forwarded_args);
|
|
48
|
+
const full_argv = [...positional_argv, ...named_argv];
|
|
49
|
+
|
|
39
50
|
const loader_path = resolve_gro_module_path('loader.js');
|
|
40
51
|
|
|
41
|
-
const spawned = await spawn_with_loader(loader_path, path,
|
|
52
|
+
const spawned = await spawn_with_loader(loader_path, path, full_argv);
|
|
42
53
|
if (!spawned.ok) {
|
|
43
54
|
throw new Task_Error(`\`gro run ${path}\` failed with exit code ${spawned.code}`);
|
|
44
55
|
}
|