@ryanatkn/gro 0.112.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/LICENSE +21 -0
- package/README.md +257 -0
- package/dist/args.d.ts +59 -0
- package/dist/args.js +132 -0
- package/dist/args.test.d.ts +1 -0
- package/dist/args.test.js +43 -0
- package/dist/build.task.d.ts +11 -0
- package/dist/build.task.js +24 -0
- package/dist/changelog.d.ts +8 -0
- package/dist/changelog.js +47 -0
- package/dist/changelog.test.d.ts +1 -0
- package/dist/changelog.test.js +118 -0
- package/dist/changeset.task.d.ts +49 -0
- package/dist/changeset.task.js +141 -0
- package/dist/check.task.d.ts +47 -0
- package/dist/check.task.js +77 -0
- package/dist/clean.task.d.ts +26 -0
- package/dist/clean.task.js +41 -0
- package/dist/clean_fs.d.ts +9 -0
- package/dist/clean_fs.js +27 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +25 -0
- package/dist/commit.task.d.ts +11 -0
- package/dist/commit.task.js +22 -0
- package/dist/config.d.ts +21 -0
- package/dist/config.js +42 -0
- package/dist/config.test.d.ts +1 -0
- package/dist/config.test.js +8 -0
- package/dist/deploy.task.d.ts +47 -0
- package/dist/deploy.task.js +198 -0
- package/dist/dev.task.d.ts +22 -0
- package/dist/dev.task.js +32 -0
- package/dist/docs/README.gen.md.d.ts +5 -0
- package/dist/docs/README.gen.md.js +53 -0
- package/dist/docs/README.md +20 -0
- package/dist/docs/build.md +41 -0
- package/dist/docs/config.md +162 -0
- package/dist/docs/deploy.md +32 -0
- package/dist/docs/dev.md +40 -0
- package/dist/docs/gen.md +241 -0
- package/dist/docs/gro_plugin_sveltekit_frontend.md +97 -0
- package/dist/docs/package_json.md +29 -0
- package/dist/docs/plugin.md +50 -0
- package/dist/docs/publish.md +144 -0
- package/dist/docs/task.md +377 -0
- package/dist/docs/tasks.gen.md.d.ts +2 -0
- package/dist/docs/tasks.gen.md.js +60 -0
- package/dist/docs/tasks.md +35 -0
- package/dist/docs/test.md +52 -0
- package/dist/env.d.ts +10 -0
- package/dist/env.js +47 -0
- package/dist/esbuild_helpers.d.ts +14 -0
- package/dist/esbuild_helpers.js +36 -0
- package/dist/esbuild_plugin_external_worker.d.ts +22 -0
- package/dist/esbuild_plugin_external_worker.js +49 -0
- package/dist/esbuild_plugin_svelte.d.ts +9 -0
- package/dist/esbuild_plugin_svelte.js +49 -0
- package/dist/esbuild_plugin_sveltekit_local_imports.d.ts +7 -0
- package/dist/esbuild_plugin_sveltekit_local_imports.js +30 -0
- package/dist/esbuild_plugin_sveltekit_shim_alias.d.ts +6 -0
- package/dist/esbuild_plugin_sveltekit_shim_alias.js +16 -0
- package/dist/esbuild_plugin_sveltekit_shim_app.d.ts +8 -0
- package/dist/esbuild_plugin_sveltekit_shim_app.js +23 -0
- package/dist/esbuild_plugin_sveltekit_shim_env.d.ts +10 -0
- package/dist/esbuild_plugin_sveltekit_shim_env.js +18 -0
- package/dist/format.task.d.ts +11 -0
- package/dist/format.task.js +24 -0
- package/dist/format_directory.d.ts +2 -0
- package/dist/format_directory.js +27 -0
- package/dist/format_file.d.ts +8 -0
- package/dist/format_file.js +42 -0
- package/dist/format_file.test.d.ts +1 -0
- package/dist/format_file.test.js +16 -0
- package/dist/fs.d.ts +7 -0
- package/dist/fs.js +19 -0
- package/dist/fs.test.d.ts +1 -0
- package/dist/fs.test.js +16 -0
- package/dist/gen.d.ts +57 -0
- package/dist/gen.js +81 -0
- package/dist/gen.task.d.ts +14 -0
- package/dist/gen.task.js +103 -0
- package/dist/gen.test.d.ts +1 -0
- package/dist/gen.test.js +239 -0
- package/dist/gen_module.d.ts +46 -0
- package/dist/gen_module.js +54 -0
- package/dist/gen_module.test.d.ts +1 -0
- package/dist/gen_module.test.js +30 -0
- package/dist/git.d.ts +76 -0
- package/dist/git.js +200 -0
- package/dist/git.test.d.ts +1 -0
- package/dist/git.test.js +18 -0
- package/dist/github.d.ts +35 -0
- package/dist/github.js +32 -0
- package/dist/gro.config.default.d.ts +12 -0
- package/dist/gro.config.default.js +31 -0
- package/dist/gro.d.ts +2 -0
- package/dist/gro.js +19 -0
- package/dist/gro_helpers.d.ts +43 -0
- package/dist/gro_helpers.js +79 -0
- package/dist/gro_plugin_gen.d.ts +6 -0
- package/dist/gro_plugin_gen.js +80 -0
- package/dist/gro_plugin_server.d.ts +77 -0
- package/dist/gro_plugin_server.js +152 -0
- package/dist/gro_plugin_sveltekit_app.d.ts +27 -0
- package/dist/gro_plugin_sveltekit_app.js +180 -0
- package/dist/gro_plugin_sveltekit_library.d.ts +4 -0
- package/dist/gro_plugin_sveltekit_library.js +42 -0
- package/dist/hash.d.ts +5 -0
- package/dist/hash.js +14 -0
- package/dist/hash.test.d.ts +1 -0
- package/dist/hash.test.js +25 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/input_path.d.ts +48 -0
- package/dist/input_path.js +161 -0
- package/dist/input_path.test.d.ts +1 -0
- package/dist/input_path.test.js +106 -0
- package/dist/invoke.d.ts +1 -0
- package/dist/invoke.js +18 -0
- package/dist/invoke_task.d.ts +20 -0
- package/dist/invoke_task.js +140 -0
- package/dist/lint.task.d.ts +11 -0
- package/dist/lint.task.js +29 -0
- package/dist/loader.d.ts +4 -0
- package/dist/loader.js +153 -0
- package/dist/module.d.ts +3 -0
- package/dist/module.js +6 -0
- package/dist/module.test.d.ts +1 -0
- package/dist/module.test.js +41 -0
- package/dist/modules.d.ts +60 -0
- package/dist/modules.js +103 -0
- package/dist/modules.test.d.ts +1 -0
- package/dist/modules.test.js +182 -0
- package/dist/package.d.ts +939 -0
- package/dist/package.gen.d.ts +7 -0
- package/dist/package.gen.js +26 -0
- package/dist/package.js +887 -0
- package/dist/package_json.d.ts +342 -0
- package/dist/package_json.js +212 -0
- package/dist/package_json.test.d.ts +1 -0
- package/dist/package_json.test.js +77 -0
- package/dist/path.d.ts +12 -0
- package/dist/path.js +8 -0
- package/dist/paths.d.ts +60 -0
- package/dist/paths.js +128 -0
- package/dist/paths.test.d.ts +1 -0
- package/dist/paths.test.js +49 -0
- package/dist/plugin.d.ts +36 -0
- package/dist/plugin.js +80 -0
- package/dist/plugin.test.d.ts +1 -0
- package/dist/plugin.test.js +54 -0
- package/dist/print_task.d.ts +4 -0
- package/dist/print_task.js +124 -0
- package/dist/publish.task.d.ts +32 -0
- package/dist/publish.task.js +125 -0
- package/dist/release.task.d.ts +5 -0
- package/dist/release.task.js +18 -0
- package/dist/resolve_node_specifier.d.ts +8 -0
- package/dist/resolve_node_specifier.js +39 -0
- package/dist/resolve_node_specifier.test.d.ts +1 -0
- package/dist/resolve_node_specifier.test.js +21 -0
- package/dist/resolve_specifier.d.ts +15 -0
- package/dist/resolve_specifier.js +51 -0
- package/dist/resolve_specifier.test.d.ts +1 -0
- package/dist/resolve_specifier.test.js +66 -0
- package/dist/run.task.d.ts +11 -0
- package/dist/run.task.js +31 -0
- package/dist/run_gen.d.ts +6 -0
- package/dist/run_gen.js +74 -0
- package/dist/run_gen.test.d.ts +1 -0
- package/dist/run_gen.test.js +182 -0
- package/dist/run_task.d.ts +13 -0
- package/dist/run_task.js +44 -0
- package/dist/run_task.test.d.ts +1 -0
- package/dist/run_task.test.js +63 -0
- package/dist/search_fs.d.ts +11 -0
- package/dist/search_fs.js +22 -0
- package/dist/search_fs.test.d.ts +1 -0
- package/dist/search_fs.test.js +46 -0
- package/dist/src_json.d.ts +256 -0
- package/dist/src_json.js +110 -0
- package/dist/src_json.test.d.ts +1 -0
- package/dist/src_json.test.js +52 -0
- package/dist/sveltekit_config.d.ts +36 -0
- package/dist/sveltekit_config.js +51 -0
- package/dist/sveltekit_shim_app.d.ts +10 -0
- package/dist/sveltekit_shim_app.js +31 -0
- package/dist/sveltekit_shim_app_environment.d.ts +10 -0
- package/dist/sveltekit_shim_app_environment.js +12 -0
- package/dist/sveltekit_shim_app_forms.d.ts +5 -0
- package/dist/sveltekit_shim_app_forms.js +13 -0
- package/dist/sveltekit_shim_app_navigation.d.ts +10 -0
- package/dist/sveltekit_shim_app_navigation.js +11 -0
- package/dist/sveltekit_shim_app_paths.d.ts +11 -0
- package/dist/sveltekit_shim_app_paths.js +6 -0
- package/dist/sveltekit_shim_app_stores.d.ts +6 -0
- package/dist/sveltekit_shim_app_stores.js +17 -0
- package/dist/sveltekit_shim_env.d.ts +4 -0
- package/dist/sveltekit_shim_env.js +23 -0
- package/dist/sync.task.d.ts +30 -0
- package/dist/sync.task.js +45 -0
- package/dist/task.d.ts +29 -0
- package/dist/task.js +17 -0
- package/dist/task.test.d.ts +1 -0
- package/dist/task.test.js +22 -0
- package/dist/task_module.d.ts +14 -0
- package/dist/task_module.js +19 -0
- package/dist/task_module.test.d.ts +1 -0
- package/dist/task_module.test.js +70 -0
- package/dist/test.task.d.ts +20 -0
- package/dist/test.task.js +43 -0
- package/dist/throttle.d.ts +16 -0
- package/dist/throttle.js +59 -0
- package/dist/throttle.test.d.ts +1 -0
- package/dist/throttle.test.js +49 -0
- package/dist/typecheck.task.d.ts +5 -0
- package/dist/typecheck.task.js +38 -0
- package/dist/upgrade.task.d.ts +14 -0
- package/dist/upgrade.task.js +37 -0
- package/dist/watch_dir.d.ts +30 -0
- package/dist/watch_dir.js +59 -0
- package/package.json +422 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
# task
|
|
2
|
+
|
|
3
|
+
> task runner for
|
|
4
|
+
> [Gro](https://github.com/ryanatkn/gro)
|
|
5
|
+
|
|
6
|
+
## contents
|
|
7
|
+
|
|
8
|
+
- [what](#what)
|
|
9
|
+
- [usage](#usage)
|
|
10
|
+
- [why?](#why)
|
|
11
|
+
|
|
12
|
+
## what
|
|
13
|
+
|
|
14
|
+
A Gro `Task` is just an object with a `run` function and some optional metadata.
|
|
15
|
+
Gro prefers conventions and code over configuration,
|
|
16
|
+
and its task runner leverages the filesystem as the API
|
|
17
|
+
and defers composition to the user in regular TypeScript modules.
|
|
18
|
+
|
|
19
|
+
> Tasks are a special Gro construct.
|
|
20
|
+
> If you want to simply execute regular TypeScript files,
|
|
21
|
+
> use the `gro run` task, which works like the normal `node` CLI
|
|
22
|
+
> but uses the Gro loader to support `.ts`.
|
|
23
|
+
|
|
24
|
+
- Gro automatically discovers [all `*.task.ts` files](../docs/tasks.md)
|
|
25
|
+
in your source directory, so creating a new task
|
|
26
|
+
is as simple as [creating a new file](#define-a-task), no config needed,
|
|
27
|
+
but part of the convention is that Gro expects all source code to be in `src/`
|
|
28
|
+
- task definitions are just objects with an async `run` function and some optional properties,
|
|
29
|
+
so composing tasks is explicit in your code, just like any other module
|
|
30
|
+
(but there's also the helper `invoke_task`: see more below)
|
|
31
|
+
- on the command line, tasks replace the concept of commands,
|
|
32
|
+
so running them is as simple as `gro <task>`,
|
|
33
|
+
and in code the task object's `run` function has access to CLI args;
|
|
34
|
+
to view [the available tasks](https://github.com/ryanatkn/gro/blob/main/src/lib/docs/tasks.md)
|
|
35
|
+
run `gro` with no arguments
|
|
36
|
+
- tasks optionally use [zod](https://github.com/colinhacks/zod) schemas
|
|
37
|
+
for `args` types, runtime parsing with helpful validation errors,
|
|
38
|
+
and automatic help output, with DRY co-located definitions
|
|
39
|
+
- it's easy to hook into or override any of Gro's builtin tasks,
|
|
40
|
+
like [`gro test`](/src/lib/test.task.ts) and [`gro gen`](/src/lib/gen.task.ts)
|
|
41
|
+
(tasks are copy-paste friendly! just update the imports)
|
|
42
|
+
- the task execution environment is filesystem agnostic by default; `run` receives a
|
|
43
|
+
[`Task_Context` argument](#user-content-types-task-and-taskcontext) with an `fs` property
|
|
44
|
+
- the `Task_Context` provides a rich baseline context object
|
|
45
|
+
for both development/build tasks and one-off script authoring/execution;
|
|
46
|
+
it attempts to be portable and extensibile, but there's a _lot_ of room for improvement
|
|
47
|
+
- it's fast because it imports only the modules that your chosen tasks need
|
|
48
|
+
|
|
49
|
+
The task runner's purpose is to provide an ergonomic interface
|
|
50
|
+
between the CLI, build tools, and app code.
|
|
51
|
+
As a developer, it's nice to be able to reuse TypeScript modules in every context.
|
|
52
|
+
|
|
53
|
+
## usage
|
|
54
|
+
|
|
55
|
+
### show all available tasks
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# This looks through `src/` in both the current working directory
|
|
59
|
+
# and Gro's source for all files matching `*.task.ts` and logs them out.
|
|
60
|
+
$ gro
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
> notice that Gro is hardcoded to expect all tasks to be in `src/` --
|
|
64
|
+
> it would be nice to loosen this up, but the API isn't obvious to me right now
|
|
65
|
+
|
|
66
|
+
### show tasks in a directory
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# Logs all `*.task.ts` files in `src/lib/some/dir` and `gro/src/lib/some/dir`.
|
|
70
|
+
# If no tasks are found, it displays an error.
|
|
71
|
+
$ gro some/dir
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
> To learn more about the Gro CLI path conventions,
|
|
75
|
+
> see [the `input_paths` comments](../input_path.ts)
|
|
76
|
+
|
|
77
|
+
### run a task
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# This runs `src/lib/some/file.task.ts`,
|
|
81
|
+
# or if it doesn't exist, `gro/src/lib/some/file.task.ts`.
|
|
82
|
+
# If neither exists, it displays an error.
|
|
83
|
+
$ gro some/file arg1 arg2 --arg3 example
|
|
84
|
+
|
|
85
|
+
# This runs `gro/src/lib/some/file.task.ts` directly
|
|
86
|
+
# without checking the current working directory,
|
|
87
|
+
# and displays an error if it doesn't exist.
|
|
88
|
+
$ gro gro/some/file
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### define a task
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
// src/lib/some/file.task.ts
|
|
95
|
+
import type {Task} from '@ryanatkn/gro';
|
|
96
|
+
|
|
97
|
+
export const task: Task = {
|
|
98
|
+
run: async ({log, args}) => {
|
|
99
|
+
log.info('CLI args', args); // => {_: ['arg1', 'arg2'], arg3: 'example'}
|
|
100
|
+
await whatever();
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The minimum:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
// src/lib/some/minimal.task.ts
|
|
109
|
+
export const task = {
|
|
110
|
+
run: () => console.log('a minimal example'),
|
|
111
|
+
};
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Minimum with [`Args`](#task-args):
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
// src/lib/some/withargs.task.ts
|
|
118
|
+
import type {Task} from '@ryanatkn/gro';
|
|
119
|
+
import {z} from 'zod';
|
|
120
|
+
|
|
121
|
+
export const Args = z
|
|
122
|
+
.object({
|
|
123
|
+
arg: z.number({description: 'example number arg'}).default(2),
|
|
124
|
+
})
|
|
125
|
+
.strict();
|
|
126
|
+
export type Args = z.infer<typeof Args>;
|
|
127
|
+
|
|
128
|
+
export const task: Task = {
|
|
129
|
+
Args,
|
|
130
|
+
run: async ({args}) => {
|
|
131
|
+
args.arg; // `number` that defaults to `2`
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### type `Task`
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import type {Task} from '@ryanatkn/gro';
|
|
140
|
+
|
|
141
|
+
export interface Task<
|
|
142
|
+
T_Args = Args, // same as `z.infer<typeof Args>`
|
|
143
|
+
T_Args_Schema extends z.ZodType = z.ZodType,
|
|
144
|
+
T_Return = unknown,
|
|
145
|
+
> {
|
|
146
|
+
run: (ctx: Task_Context<T_Args>) => Promise<T_Return>;
|
|
147
|
+
summary?: string;
|
|
148
|
+
Args?: T_Args_Schema;
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### type `Task_Context`
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
import type {Task_Context} from '@ryanatkn/gro';
|
|
156
|
+
|
|
157
|
+
export interface Task_Context<T_Args = object> {
|
|
158
|
+
args: T_Args;
|
|
159
|
+
config: Gro_Config;
|
|
160
|
+
log: Logger;
|
|
161
|
+
timings: Timings;
|
|
162
|
+
invoke_task: (task_name: string, args?: Args, config?: Gro_Config) => Promise<void>;
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### run a task inside another task with `invoke_task`
|
|
167
|
+
|
|
168
|
+
Because Gro tasks are just functions,
|
|
169
|
+
you can directly import them from within other tasks and run them.
|
|
170
|
+
However, we recommend using the `invoke_task` helper
|
|
171
|
+
for its ergonomics and automatic logging and diagnostics.
|
|
172
|
+
|
|
173
|
+
The `invoke_task` helper uses Gro's task resolution rules
|
|
174
|
+
to allow user code to override builtin tasks.
|
|
175
|
+
For example, Gro's `check.task.ts` calls `invoke_task('test')`
|
|
176
|
+
so that it calls your `src/lib/test.task.ts` if it exists
|
|
177
|
+
and falls back to `gro/src/lib/test.task.ts` if not.
|
|
178
|
+
|
|
179
|
+
It's less important to use `invoke_task` over explicit imports in user code
|
|
180
|
+
because you don't need to rely on the task override rules to get desired behavior,
|
|
181
|
+
but the logging and diagnostics it provides are nice to have.
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
gro some/file
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
// src/lib/some/file.task.ts
|
|
189
|
+
import type {Task} from '@ryanatkn/gro';
|
|
190
|
+
|
|
191
|
+
export const task: Task = {
|
|
192
|
+
run: async ({args, invoke_task}) => {
|
|
193
|
+
// runs `src/lib/some/file.task.ts`, automatically forwarding `args`
|
|
194
|
+
await invoke_task('some/file');
|
|
195
|
+
// as documented above, the following is similar but lacks nice features:
|
|
196
|
+
// await (await import('./some/file.task.js')).run(ctx);
|
|
197
|
+
|
|
198
|
+
// runs `src/lib/other/file.task.ts` and falls back to `gro/src/other/file.task.ts`,
|
|
199
|
+
// forwarding both custom args and a different event emitter (warning: spaghetti)
|
|
200
|
+
await invoke_task(
|
|
201
|
+
'other/file',
|
|
202
|
+
{...args, optionally: 'extended'},
|
|
203
|
+
optionalEventEmitterForSubtree,
|
|
204
|
+
optionalDevFlagForSubtree,
|
|
205
|
+
optionalFsForSubtree,
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
// runs `gro/src/lib/other/file.task.ts` directly, bypassing any local version
|
|
209
|
+
await invoke_task('gro/other/file');
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### hook into one of [Gro's builtin tasks](../docs/tasks.md)
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# This normally loads Gro's version of the test task at `gro/src/lib/test.task.ts`,
|
|
218
|
+
# but projects can define `src/lib/test.task.ts` to extend or replace it.
|
|
219
|
+
$ gro test
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
// src/lib/test.task.ts
|
|
224
|
+
import type {Task} from '@ryanatkn/gro';
|
|
225
|
+
|
|
226
|
+
export const task: Task = {
|
|
227
|
+
run: async ({args, invoke_task}) => {
|
|
228
|
+
await doSomethingFirst();
|
|
229
|
+
// As discussed in the `invoke_task` section above,
|
|
230
|
+
// it's possible to `import {task as groBuiltinTestTask} from '@ryanatkn/gro/test.task.js'`
|
|
231
|
+
// and then call `groBuiltinTestTask.run` directly,
|
|
232
|
+
// but that loses some important benefits.
|
|
233
|
+
// Still, the task is available to import if you want it for any reason!
|
|
234
|
+
await invoke_task('gro/test', {...args, optionally: 'extended'}, newEventEmitterForSubtree);
|
|
235
|
+
await emailEveryoneWithTestResults();
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Note that when hooking into [Gro's builtin tasks](../docs/tasks.md),
|
|
241
|
+
like `test.task.ts` above, you don't have to call its version.
|
|
242
|
+
You can copy/paste an existing task and customize it,
|
|
243
|
+
rewrite a task from scratch, compose them together, or whatever is needed for each project.
|
|
244
|
+
|
|
245
|
+
### task `Args`
|
|
246
|
+
|
|
247
|
+
The **`Args` property** of each `Task` (not the task context **`args` param** described above!)
|
|
248
|
+
is an optional [zod](https://github.com/colinhacks/zod) schema.
|
|
249
|
+
Using zod has some benefits:
|
|
250
|
+
|
|
251
|
+
- automatically print helpful text on the CLI with `gro` and `gro taskname --help`
|
|
252
|
+
- automated args parsing/validation using the schema with initialized defaults
|
|
253
|
+
- type safety using args in tasks
|
|
254
|
+
- concise source of truth
|
|
255
|
+
|
|
256
|
+
```ts
|
|
257
|
+
// src/lib/dosomething.task.ts
|
|
258
|
+
import type {Task} from '@ryanatkn/gro';
|
|
259
|
+
import type {z} from 'zod';
|
|
260
|
+
|
|
261
|
+
export const Args = z
|
|
262
|
+
.object({
|
|
263
|
+
_: z.array(z.string(), {description: 'rest args'}).default([]),
|
|
264
|
+
yepyep: z.string({description: 'helpful info'}).default('ya'),
|
|
265
|
+
okcool: z.number({description: 'that prints to the CLI'}).default(1234),
|
|
266
|
+
maybee: z.boolean({description: 'and optional args work too'}),
|
|
267
|
+
})
|
|
268
|
+
.strict();
|
|
269
|
+
export type Args = z.infer<typeof Args>;
|
|
270
|
+
|
|
271
|
+
export const task: Task<Args> = {
|
|
272
|
+
Args,
|
|
273
|
+
run: async ({args}) => {
|
|
274
|
+
args._; // string[]
|
|
275
|
+
args.yepyep; // string
|
|
276
|
+
args.okcool; // number
|
|
277
|
+
args.maybee; // boolean | undefined
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Running `gro dosomething --help` prints the schema information in a friendly format.
|
|
283
|
+
|
|
284
|
+
### task args forwarding
|
|
285
|
+
|
|
286
|
+
Some builtin Gro tasks call external commands like
|
|
287
|
+
[`svelte-kit`](https://github.com/sveltejs/kit),
|
|
288
|
+
[`vite`](https://github.com/vitejs/vite),
|
|
289
|
+
[`uvu`](https://github.com/lukeed/uvu),
|
|
290
|
+
[`tsc`](https://github.com/microsoft/typescript),
|
|
291
|
+
and [`prettier`](https://github.com/prettier/prettier).
|
|
292
|
+
Gro supports generic agnostic args forwarding to these tasks via the `--` pattern:
|
|
293
|
+
for example, to forward args to `svelte-kit` and `uvu`, no matter which task invokes them,
|
|
294
|
+
use `gro taskname --taskname-arg -- uvu --arg1 neat --arg2 22 -- svelte-kit --arg3`.
|
|
295
|
+
|
|
296
|
+
Any number of sections separated by `--` may be defined, and the first arg
|
|
297
|
+
that appears after each `--` is assumed to be the CLI command.
|
|
298
|
+
If `gro taskname` or its invoked tasks don't call `uvu` or `svelte-kit`,
|
|
299
|
+
the `--` args will be ignored.
|
|
300
|
+
|
|
301
|
+
There's one special case for task args forwarding: running Gro tasks.
|
|
302
|
+
If `gro` is the command following a `--`, e.g. the second `gro` of
|
|
303
|
+
`gro taskname -- gro taskname2 --a --b`,
|
|
304
|
+
then `--a` and `--b` will be forwarded to `taskname2`.
|
|
305
|
+
Forwarded args to Gro tasks override direct args, including args to `invoke_task`,
|
|
306
|
+
so `gro taskname --a 1 -- gro taskname --a 2` will invoke `taskname` with `{a: 2}`.
|
|
307
|
+
|
|
308
|
+
### throwing errors
|
|
309
|
+
|
|
310
|
+
If a task encounters an error, normally it should throw rather than exiting the process.
|
|
311
|
+
This defers control to the caller, like your own parent tasks.
|
|
312
|
+
|
|
313
|
+
Often, errors that tasks encounter do not need a stack trace,
|
|
314
|
+
and we don't want the added noise to be logged.
|
|
315
|
+
To suppress logging the stack trace for an error,
|
|
316
|
+
throw a `Task_Error`.
|
|
317
|
+
|
|
318
|
+
```ts
|
|
319
|
+
import {Task, Task_Error} from '@ryanatkn/gro';
|
|
320
|
+
|
|
321
|
+
export const task: Task = {
|
|
322
|
+
run: async () => {
|
|
323
|
+
if (someErrorCondition) {
|
|
324
|
+
throw new Task_Error('We hit a known error - ignore the stack trace!');
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## why?
|
|
331
|
+
|
|
332
|
+
Gro usage on the command line (`gro <taskOrDirectory> [...flags]`)
|
|
333
|
+
looks a lot like using `node`.
|
|
334
|
+
What makes Gro different?
|
|
335
|
+
|
|
336
|
+
- The `*.task.ts` file name convention signals to Gro that your application
|
|
337
|
+
contains task modules that conform to some interface.
|
|
338
|
+
This allows them to be discoverable by convention,
|
|
339
|
+
so running `gro` displays them all without any config, and it puts generic handles on them,
|
|
340
|
+
enabling various verbs (e.g. `run`) and structured metadata (e.g. `summary`).
|
|
341
|
+
- Tasks aren't just a script, they can be inspected, composed, and manipulated in code.
|
|
342
|
+
Task modules do not have any side effects when imported,
|
|
343
|
+
while Node scripts just execute when imported -
|
|
344
|
+
their primary purpose is to cause side effects.
|
|
345
|
+
This is useful in many cases - for example `gro taskname --help`
|
|
346
|
+
inspects the args schema and other metadata to print help to the console,
|
|
347
|
+
and `gro` prints the `summary` property of each task it finds.
|
|
348
|
+
There's lots more to explore here, like task composition
|
|
349
|
+
and improved DX with new capabilities.
|
|
350
|
+
- Tasks support CLI args that are validated and typesafe
|
|
351
|
+
via colocated Zod schemas with minimal boilerplate.
|
|
352
|
+
- Module resolution differs and leverages discoverability:
|
|
353
|
+
- When a task name is given to Gro,
|
|
354
|
+
it first searches `src/lib/` in the current working directory and
|
|
355
|
+
falls back to searching the Gro directory.
|
|
356
|
+
This allows your code and CLI commands to use Gro's builtin tasks
|
|
357
|
+
or override or extend them without changing how you invoke them.
|
|
358
|
+
Gro reserves no special behavior for its own commands -
|
|
359
|
+
`gro test`, `gro gen`, and all the rest are just tasks that all follow the same rules.
|
|
360
|
+
(see its task at [`src/lib/test.task.ts`](/src/lib/test.task.ts)).
|
|
361
|
+
- When a directory is given to Gro,
|
|
362
|
+
it prints all of the tasks found inside it,
|
|
363
|
+
both relative to the current working directory and Gro's directory.
|
|
364
|
+
So when you run `gro` by itself,
|
|
365
|
+
it prints all tasks available both in your project and Gro.
|
|
366
|
+
- The trailing `.task.ts` in the file path provided to `gro` is optional,
|
|
367
|
+
so for example, `gro foo/bar` is the same as `gro foo/bar.task.ts`, a nice convenience.
|
|
368
|
+
|
|
369
|
+
## :turtle:<sub>:turtle:</sub><sub><sub>:turtle:</sub></sub>
|
|
370
|
+
|
|
371
|
+
Gro's task runner has many inspirations:
|
|
372
|
+
|
|
373
|
+
- [mgutz/task](https://github.com/mgutz/task)
|
|
374
|
+
- [Gulp](https://github.com/gulpjs/gulp)
|
|
375
|
+
- [@mgutz](https://github.com/mgutz)' [Projmate](https://github.com/projmate/projmate-core)
|
|
376
|
+
- [Grunt](https://github.com/gruntjs/grunt)
|
|
377
|
+
- [npm scripts](https://docs.npmjs.com/v8/using-npm/scripts)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { dirname, relative, basename } from 'node:path';
|
|
2
|
+
import { parse_path_parts, parse_path_segments } from '@ryanatkn/belt/path.js';
|
|
3
|
+
import { strip_start } from '@ryanatkn/belt/string.js';
|
|
4
|
+
import { to_output_file_name } from '../gen.js';
|
|
5
|
+
import { paths, base_path_to_source_id } from '../paths.js';
|
|
6
|
+
import { load_task_modules } from '../task_module.js';
|
|
7
|
+
import { log_error_reasons } from '../print_task.js';
|
|
8
|
+
// This is the first simple implementation of Gro's automated docs.
|
|
9
|
+
// It combines Gro's gen and task systems
|
|
10
|
+
// to generate a markdown file describing all of the project's tasks.
|
|
11
|
+
// Other projects that use Gro should be able to import this module
|
|
12
|
+
// or other otherwise get frictionless access to this specific use case,
|
|
13
|
+
// and they should be able to extend or customize it to any degree.
|
|
14
|
+
// TODO display more info about each task, including a summary and params
|
|
15
|
+
// TODO needs some cleanup and better APIs - paths are confusing and verbose!
|
|
16
|
+
// TODO add backlinks to every document that links to this one
|
|
17
|
+
export const gen = async ({ origin_id, log }) => {
|
|
18
|
+
const result = await load_task_modules();
|
|
19
|
+
if (!result.ok) {
|
|
20
|
+
log_error_reasons(log, result.reasons);
|
|
21
|
+
throw new Error(result.type);
|
|
22
|
+
}
|
|
23
|
+
const tasks = result.modules;
|
|
24
|
+
// TODO need to get this from project config or something
|
|
25
|
+
const root_path = parse_path_segments(paths.root).at(-1);
|
|
26
|
+
const origin_dir = dirname(origin_id);
|
|
27
|
+
const origin_base = basename(origin_id);
|
|
28
|
+
const base_dir = paths.source;
|
|
29
|
+
const relative_path = strip_start(origin_id, base_dir);
|
|
30
|
+
const relative_dir = dirname(relative_path);
|
|
31
|
+
// TODO should this be passed in the context, like `defaultOutputFileName`?
|
|
32
|
+
const output_file_name = to_output_file_name(origin_base);
|
|
33
|
+
// TODO this is GitHub-specific
|
|
34
|
+
const root_link = `[${root_path}](/../..)`;
|
|
35
|
+
// TODO do we want to use absolute paths instead of relative paths,
|
|
36
|
+
// because GitHub works with them and it simplifies the code?
|
|
37
|
+
const path_parts = parse_path_parts(relative_dir).map((relative_path_part) => `[${parse_path_segments(relative_path_part).at(-1)}](${relative(origin_dir, base_path_to_source_id(relative_path_part)) || './'})`);
|
|
38
|
+
const breadcrumbs = '> <sub>' + [root_link, ...path_parts, output_file_name].join(' / ') + '</sub>';
|
|
39
|
+
// TODO render the footer with the origin_id
|
|
40
|
+
return `# tasks
|
|
41
|
+
|
|
42
|
+
${breadcrumbs}
|
|
43
|
+
|
|
44
|
+
What is a \`Task\`? See [\`task.md\`](./task.md).
|
|
45
|
+
|
|
46
|
+
## all tasks
|
|
47
|
+
|
|
48
|
+
${tasks.reduce((taskList, task) => taskList +
|
|
49
|
+
`- [${task.name}](${relative(origin_dir, task.id)})${task.mod.task.summary ? ` - ${task.mod.task.summary}` : ''}\n`, '')}
|
|
50
|
+
## usage
|
|
51
|
+
|
|
52
|
+
\`\`\`bash
|
|
53
|
+
$ gro some/name
|
|
54
|
+
\`\`\`
|
|
55
|
+
|
|
56
|
+
${breadcrumbs}
|
|
57
|
+
|
|
58
|
+
> <sub>generated by [${origin_base}](${origin_base})</sub>
|
|
59
|
+
`;
|
|
60
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# tasks
|
|
2
|
+
|
|
3
|
+
> <sub>[gro](/../..) / [lib](..) / [docs](./) / tasks.md</sub>
|
|
4
|
+
|
|
5
|
+
What is a `Task`? See [`task.md`](./task.md).
|
|
6
|
+
|
|
7
|
+
## all tasks
|
|
8
|
+
|
|
9
|
+
- [build](../build.task.ts) - build the project
|
|
10
|
+
- [changeset](../changeset.task.ts) - call changeset with gro patterns
|
|
11
|
+
- [check](../check.task.ts) - check that everything is ready to commit
|
|
12
|
+
- [clean](../clean.task.ts) - remove temporary dev and build files, and optionally prune git branches
|
|
13
|
+
- [commit](../commit.task.ts) - commit and push to a new branch
|
|
14
|
+
- [deploy](../deploy.task.ts) - deploy to a branch
|
|
15
|
+
- [dev](../dev.task.ts) - start SvelteKit and other dev plugins
|
|
16
|
+
- [format](../format.task.ts) - format source files
|
|
17
|
+
- [gen](../gen.task.ts) - run code generation scripts
|
|
18
|
+
- [lint](../lint.task.ts) - run eslint
|
|
19
|
+
- [publish](../publish.task.ts) - bump version, publish to npm, and git push
|
|
20
|
+
- [release](../release.task.ts) - publish and deploy
|
|
21
|
+
- [run](../run.task.ts) - execute a file with the loader, like `node` but works for TypeScript
|
|
22
|
+
- [sync](../sync.task.ts) - run `gro gen`, update `package.json`, and optionally `npm i` to sync up
|
|
23
|
+
- [test](../test.task.ts) - run tests with uvu
|
|
24
|
+
- [typecheck](../typecheck.task.ts) - run tsc on the project without emitting any files
|
|
25
|
+
- [upgrade](../upgrade.task.ts) - upgrade deps
|
|
26
|
+
|
|
27
|
+
## usage
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
$ gro some/name
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
> <sub>[gro](/../..) / [lib](..) / [docs](./) / tasks.md</sub>
|
|
34
|
+
|
|
35
|
+
> <sub>generated by [tasks.gen.md.ts](tasks.gen.md.ts)</sub>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# test
|
|
2
|
+
|
|
3
|
+
Gro integrates [`uvu`](https://github.com/lukeed/uvu) for tests:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
gro test # run all tests with Gro's default `*.test.ts` pattern
|
|
7
|
+
gro test thing.test somedir test/a.+b # run tests matching regexp patterns
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
> Running `gro test [...args]` calls `uvu`'s `parse` and `run` helpers
|
|
11
|
+
> inside Gro's normal [task context](/src/lib/docs/task.md) instead of using the `uvu` CLI.
|
|
12
|
+
> Gro typically defers to a tool's CLI, so it can transparently forward args without wrapping,
|
|
13
|
+
> but in this case `uvu` doesn't support [loaders](https://nodejs.org/api/esm.html#loaders)
|
|
14
|
+
> for running TypeScript files directly.
|
|
15
|
+
> `uvu` does support require hooks, but Gro prefers the loader API.
|
|
16
|
+
|
|
17
|
+
Like other tasks, use `--help` to see the args info:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
gro test --help
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
outputs:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
gro test: run tests
|
|
27
|
+
[...args] string[] ["\\.test\\.ts$"] file patterns to test
|
|
28
|
+
bail boolean false the bail option to uvu run, exit immediately on failure
|
|
29
|
+
cwd string undefined the cwd option to uvu parse
|
|
30
|
+
ignore string | string[] undefined the ignore option to uvu parse
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
[`gro test`](/src/lib/test.task.ts) runs all `*.test.ts`
|
|
34
|
+
files in your project by default using the regexp `"\\.test\\.ts$"`.
|
|
35
|
+
So to add a new test, create a new file:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
// by convention, create `src/lib/thing.ts`
|
|
39
|
+
// to test `src/lib/thing.test.ts`
|
|
40
|
+
import {test} from 'uvu';
|
|
41
|
+
import * as assert from 'uvu/assert';
|
|
42
|
+
|
|
43
|
+
import {thing} from '$lib/thing.js';
|
|
44
|
+
|
|
45
|
+
test('the thing', async () => {
|
|
46
|
+
assert.equal(thing, {expected: true});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test.run();
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
See [the `uvu` docs](https://github.com/lukeed/uvu) for more.
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare const load_env: (dev: boolean, visibility: 'public' | 'private', public_prefix: string, private_prefix: string, env_dir?: string, env_files?: string[], ambient_env?: NodeJS.ProcessEnv) => Promise<Record<string, string>>;
|
|
3
|
+
export declare const merge_envs: (envs: Array<Record<string, string | undefined>>, visibility: 'public' | 'private', public_prefix: string, private_prefix: string) => Record<string, string>;
|
|
4
|
+
export declare const is_private_env: (key: string, public_prefix: string, private_prefix: string) => boolean;
|
|
5
|
+
export declare const is_public_env: (key: string, public_prefix: string, private_prefix: string) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Loads a single env value without merging it into `process.env`.
|
|
8
|
+
* By default searches process.env, then a local `.env` if one exists, then `../.env` if it exists.
|
|
9
|
+
*/
|
|
10
|
+
export declare const load_from_env: (key: string, paths?: string[]) => Promise<string | undefined>;
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { exists } from './fs.js';
|
|
5
|
+
export const load_env = async (dev, visibility, public_prefix, private_prefix, env_dir, env_files = ['.env', '.env.' + (dev ? 'development' : 'production')], ambient_env = process.env) => {
|
|
6
|
+
const envs = await Promise.all(env_files
|
|
7
|
+
.map(async (path) => (await load(env_dir === undefined ? path : resolve(env_dir, path))))
|
|
8
|
+
.filter(Boolean));
|
|
9
|
+
envs.push(ambient_env);
|
|
10
|
+
return merge_envs(envs, visibility, public_prefix, private_prefix);
|
|
11
|
+
};
|
|
12
|
+
const load = async (path) => {
|
|
13
|
+
if (!(await exists(path)))
|
|
14
|
+
return undefined;
|
|
15
|
+
const loaded = await readFile(path, 'utf8');
|
|
16
|
+
return dotenv.parse(loaded);
|
|
17
|
+
};
|
|
18
|
+
export const merge_envs = (envs, visibility, public_prefix, private_prefix) => {
|
|
19
|
+
const env = {};
|
|
20
|
+
for (const e of envs) {
|
|
21
|
+
for (const key in e) {
|
|
22
|
+
if ((visibility === 'private' && is_private_env(key, public_prefix, private_prefix)) ||
|
|
23
|
+
(visibility === 'public' && is_public_env(key, public_prefix, private_prefix))) {
|
|
24
|
+
const value = e[key];
|
|
25
|
+
if (value !== undefined)
|
|
26
|
+
env[key] = value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return env;
|
|
31
|
+
};
|
|
32
|
+
export const is_private_env = (key, public_prefix, private_prefix) => key.startsWith(private_prefix) && (public_prefix === '' || !key.startsWith(public_prefix));
|
|
33
|
+
export const is_public_env = (key, public_prefix, private_prefix) => key.startsWith(public_prefix) && (private_prefix === '' || !key.startsWith(private_prefix));
|
|
34
|
+
/**
|
|
35
|
+
* Loads a single env value without merging it into `process.env`.
|
|
36
|
+
* By default searches process.env, then a local `.env` if one exists, then `../.env` if it exists.
|
|
37
|
+
*/
|
|
38
|
+
export const load_from_env = async (key, paths = ['.env', '../.env']) => {
|
|
39
|
+
if (process.env[key])
|
|
40
|
+
return process.env[key];
|
|
41
|
+
for (const path of paths) {
|
|
42
|
+
const env = await load(path); // eslint-disable-line no-await-in-loop
|
|
43
|
+
if (env?.[key])
|
|
44
|
+
return env[key];
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type * as esbuild from 'esbuild';
|
|
2
|
+
import type { Parsed_Sveltekit_Config } from './sveltekit_config.js';
|
|
3
|
+
export declare const print_build_result: (log: Logger, build_result: esbuild.BuildResult) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Creates an esbuild `define` shim for Vite's `import.meta\.env`.
|
|
6
|
+
* @see https://esbuild.github.io/api/#define
|
|
7
|
+
* @param dev
|
|
8
|
+
* @param base_url - best-effort shim from SvelteKit's `base` to Vite's `import.meta\.env.BASE_URL`
|
|
9
|
+
* @param ssr
|
|
10
|
+
* @param mode
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare const to_define_import_meta_env: (dev: boolean, base_url: Parsed_Sveltekit_Config['base_url'], ssr?: boolean, mode?: string) => Record<string, string>;
|
|
14
|
+
export declare const ts_transform_options: esbuild.TransformOptions;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { yellow, red } from 'kleur/colors';
|
|
2
|
+
export const print_build_result = (log, build_result) => {
|
|
3
|
+
for (const error of build_result.errors) {
|
|
4
|
+
log.error(red('esbuild error'), error);
|
|
5
|
+
}
|
|
6
|
+
for (const warning of build_result.warnings) {
|
|
7
|
+
log.warn(yellow('esbuild warning'), warning);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
// This concatenates weirdly to avoid a SvelteKit warning,
|
|
11
|
+
// because SvelteKit detects usage as a string and not the AST.
|
|
12
|
+
const import_meta_env = 'import.' + 'meta.env.'; // eslint-disable-line no-useless-concat
|
|
13
|
+
/**
|
|
14
|
+
* Creates an esbuild `define` shim for Vite's `import.meta\.env`.
|
|
15
|
+
* @see https://esbuild.github.io/api/#define
|
|
16
|
+
* @param dev
|
|
17
|
+
* @param base_url - best-effort shim from SvelteKit's `base` to Vite's `import.meta\.env.BASE_URL`
|
|
18
|
+
* @param ssr
|
|
19
|
+
* @param mode
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export const to_define_import_meta_env = (dev, base_url, ssr = true, mode = dev ? 'development' : 'production') => ({
|
|
23
|
+
// see `import_meta_env` for why this is defined weirdly instead of statically
|
|
24
|
+
[import_meta_env + 'DEV']: JSON.stringify(dev),
|
|
25
|
+
[import_meta_env + 'PROD']: JSON.stringify(!dev),
|
|
26
|
+
[import_meta_env + 'SSR']: JSON.stringify(ssr),
|
|
27
|
+
[import_meta_env + 'MODE']: JSON.stringify(mode),
|
|
28
|
+
[import_meta_env + 'BASE_URL']: JSON.stringify(base_url || '/'), // it appears SvelteKit's `''` translates to Vite's `'/'`, so this intentionally falls back for falsy values, not just undefined
|
|
29
|
+
});
|
|
30
|
+
export const ts_transform_options = {
|
|
31
|
+
target: 'esnext',
|
|
32
|
+
format: 'esm',
|
|
33
|
+
loader: 'ts',
|
|
34
|
+
charset: 'utf8',
|
|
35
|
+
// TODO load local tsconfig
|
|
36
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
import * as esbuild from 'esbuild';
|
|
3
|
+
import type { Logger } from '@ryanatkn/belt/log.js';
|
|
4
|
+
import type { CompileOptions, PreprocessorGroup } from 'svelte/compiler';
|
|
5
|
+
import type { Parsed_Sveltekit_Config } from './sveltekit_config.js';
|
|
6
|
+
export interface Options {
|
|
7
|
+
dev: boolean;
|
|
8
|
+
build_options: esbuild.BuildOptions;
|
|
9
|
+
dir?: string;
|
|
10
|
+
svelte_compile_options?: CompileOptions;
|
|
11
|
+
svelte_preprocessors?: PreprocessorGroup | PreprocessorGroup[];
|
|
12
|
+
alias?: Record<string, string>;
|
|
13
|
+
base_url?: Parsed_Sveltekit_Config['base_url'];
|
|
14
|
+
assets_url?: Parsed_Sveltekit_Config['assets_url'];
|
|
15
|
+
public_prefix?: string;
|
|
16
|
+
private_prefix?: string;
|
|
17
|
+
env_dir?: string;
|
|
18
|
+
env_files?: string[];
|
|
19
|
+
ambient_env?: Record<string, string>;
|
|
20
|
+
log?: Logger;
|
|
21
|
+
}
|
|
22
|
+
export declare const esbuild_plugin_external_worker: ({ dev, build_options, dir, svelte_compile_options, svelte_preprocessors, alias, base_url, assets_url, public_prefix, private_prefix, env_dir, env_files, ambient_env, log, }: Options) => esbuild.Plugin;
|