@wolfstar/http-framework 6.0.0 → 6.0.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.
- package/README.md +101 -8
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -480,27 +480,34 @@ export default defineConfig({
|
|
|
480
480
|
|
|
481
481
|
Anything in `tsdown` wins over the defaults, and `plugins` are appended rather than replaced.
|
|
482
482
|
|
|
483
|
-
With `future.compatibilityVersion: 3` (legacy mode) a `tsdown.config.*` in the project root is still
|
|
484
|
-
`tsdown` is merged over it, so a project can move its options across one at a time.
|
|
485
|
-
configuration, and a leftover `tsdown.config.*` is reported instead of being silently ignored.
|
|
483
|
+
With `future.compatibilityVersion: 3` (end-of-life legacy mode) a `tsdown.config.*` in the project root is still
|
|
484
|
+
loaded and `tsdown` is merged over it, so a project can move its options across one at a time. From `4` on the block is
|
|
485
|
+
the whole configuration, and a leftover `tsdown.config.*` is reported instead of being silently ignored.
|
|
486
486
|
|
|
487
487
|
`vite: {}` works the same way for `build.tool: 'vite'` (see [experimental flags](#experimental-flags)): it is merged
|
|
488
488
|
into the project's own `vite.config.*`, the way `vite: {}` in a Nuxt config is.
|
|
489
489
|
|
|
490
490
|
### Compatibility version
|
|
491
491
|
|
|
492
|
-
`future.compatibilityVersion` selects the build-default generation. Version
|
|
493
|
-
|
|
492
|
+
`future.compatibilityVersion` selects the build-default generation. Version 5 is the default and version 4 remains
|
|
493
|
+
supported. Version 3 is **end-of-life**: it still works for projects that have a standalone `tsdown.config.*`, but
|
|
494
|
+
every command prints a `COMPATIBILITY_VERSION_EOL` warning, and it is removed in the next major.
|
|
494
495
|
|
|
495
496
|
```typescript
|
|
496
497
|
export default defineConfig({
|
|
497
498
|
future: {
|
|
498
|
-
compatibilityVersion:
|
|
499
|
+
compatibilityVersion: 4
|
|
499
500
|
}
|
|
500
501
|
});
|
|
501
502
|
```
|
|
502
503
|
|
|
503
|
-
|
|
504
|
+
| Version | What it changes |
|
|
505
|
+
| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
506
|
+
| `3` (EOL) | Legacy behaviour: a `tsdown.config.*` drives the build, auto imports off unless asked for |
|
|
507
|
+
| `4` | `tsdown` configured from `stars.config` alone, auto imports on and wired in, `'auto'` picks `tsdown` for TypeScript; [`env`](#environment-env) is opt-in |
|
|
508
|
+
| `5` (default) | Everything in `4`, plus [`env`](#environment-env) registered automatically when the project depends on `@wolfstar/env-utilities` |
|
|
509
|
+
|
|
510
|
+
From version 4 on:
|
|
504
511
|
|
|
505
512
|
- **Auto imports are on** with the `tsdown` build tool, and the `autoImports()` plugin is wired into the build by
|
|
506
513
|
`stars` itself instead of by the project's own configuration file — the framework's exports and the project's
|
|
@@ -511,7 +518,93 @@ The default version 4 provides three things:
|
|
|
511
518
|
- **`build.tool: 'auto'` resolves to `tsdown`** for any TypeScript entry, rather than looking for a `tsdown.config.*`
|
|
512
519
|
or a `tsdown` dependency first. `tsc` stays available as an explicit choice.
|
|
513
520
|
|
|
514
|
-
|
|
521
|
+
Version 5 adds one thing: **the environment is registered for you.** `stars` calls `setup()` from
|
|
522
|
+
`@wolfstar/env-utilities` before any module of the bot runs, so the bot no longer loads its `.env*` files by hand.
|
|
523
|
+
|
|
524
|
+
`stars info` prints the version in effect, and any warning about it.
|
|
525
|
+
|
|
526
|
+
### Environment (`env`)
|
|
527
|
+
|
|
528
|
+
`env` mirrors the options of `setup()` from `@wolfstar/env-utilities`. `stars` writes them into the built entry and
|
|
529
|
+
calls `setup()` with them as the entry's very first import — before `@wolfstar/plugin-*` registrations and the bot's
|
|
530
|
+
own modules, all of which may read `process.env` as soon as they load.
|
|
531
|
+
|
|
532
|
+
```typescript
|
|
533
|
+
export default defineConfig({
|
|
534
|
+
env: { prefix: 'BOT_', loader: 'varlock' }
|
|
535
|
+
});
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
| Option | Type | Default |
|
|
539
|
+
| ---------- | ----------------------- | ------------------------- |
|
|
540
|
+
| `enabled` | `boolean` | see below |
|
|
541
|
+
| `path` | `string` | `src/.env*`, then `.env*` |
|
|
542
|
+
| `env` | `string` | `NODE_ENV` |
|
|
543
|
+
| `prefix` | `string` | none |
|
|
544
|
+
| `loader` | `'dotenv' \| 'varlock'` | `'dotenv'` |
|
|
545
|
+
| `debug` | `boolean` | `false` |
|
|
546
|
+
| `encoding` | `string` | `'utf8'` |
|
|
547
|
+
|
|
548
|
+
- `env: false` turns the registration off; `env: true` turns it on with the defaults. Any option at all is an opt-in
|
|
549
|
+
as well, which requires `@wolfstar/env-utilities` in the project's dependencies (`ENV_REQUIRES_ENV_UTILITIES`).
|
|
550
|
+
- Without an `env` block it is on from compatibility version 5, when the project depends on
|
|
551
|
+
`@wolfstar/env-utilities`, and off with `experimental.enableNitro` — serverless presets have no `.env` files to load.
|
|
552
|
+
- Only the serializable options are mirrored: they end up in the build output as JSON. `path` stays relative and is
|
|
553
|
+
resolved against the bot's working directory at runtime, so the output does not depend on the machine that built it.
|
|
554
|
+
- tsdown, Vite and Nitro builds register it through the entry transform. `build.tool: 'tsc'` and `'none'` never pass
|
|
555
|
+
through it: `stars dev` preloads it with `node --import`, but in production such a bot loads its environment itself
|
|
556
|
+
(or runs with `node --import @wolfstar/env-utilities/setup`). The projects `@wolfstar/create-http-framework`
|
|
557
|
+
generates for them set `env: false` and keep calling `setup()` in `src/lib/setup`.
|
|
558
|
+
- `stars dev` reads `HTTP_PORT` for the default `dev.url` from the same `path`/`env` files, after `env:options`. With
|
|
559
|
+
`loader: 'varlock'` it reads it, and the tunnel's Discord credentials, from `varlock load` in the project instead —
|
|
560
|
+
run the way the bot loads it, without `env.env`, which varlock ignores.
|
|
561
|
+
|
|
562
|
+
### Hooks
|
|
563
|
+
|
|
564
|
+
`hooks` registers lifecycle hooks of the `stars` CLI, run with [`hookable`](https://github.com/unjs/hookable) the way
|
|
565
|
+
Nuxt's own `hooks` are. Each hook is keyed by its full name or nested under its namespace, as a function or an array
|
|
566
|
+
of functions:
|
|
567
|
+
|
|
568
|
+
```typescript
|
|
569
|
+
export default defineConfig({
|
|
570
|
+
hooks: {
|
|
571
|
+
'env:options'(options) {
|
|
572
|
+
if (process.env.CI) options.path = '.env.ci';
|
|
573
|
+
},
|
|
574
|
+
build: {
|
|
575
|
+
done(outcome) {
|
|
576
|
+
if (!outcome.ok) console.error(outcome.message);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
| Hook | Arguments | Runs |
|
|
584
|
+
| ----------------- | ------------------- | --------------------------------------------------------------------- |
|
|
585
|
+
| `config:resolved` | `config` | after `stars.config` is loaded and validated, in every command |
|
|
586
|
+
| `env:options` | `options`, `config` | before `env` is written into the build; mutate `options` to change it |
|
|
587
|
+
| `prepare:before` | `config` | before `.stars/` is generated |
|
|
588
|
+
| `prepare:done` | `config`, `result` | after `.stars/` is generated |
|
|
589
|
+
| `builder:created` | `builder`, `config` | once the builder for `build.tool` exists, before it builds |
|
|
590
|
+
| `tsdown:options` | `options`, `config` | before `tsdown.build()`; mutate `options` to change the build |
|
|
591
|
+
| `build:before` | `config` | before each build (every rebuild in `stars dev`) |
|
|
592
|
+
| `build:done` | `outcome`, `config` | after each build, successful or not (`outcome.ok`) |
|
|
593
|
+
| `dev:start` | `config` | once `stars dev` is watching |
|
|
594
|
+
| `dev:restart` | `reason`, `config` | before `stars dev` (re)starts the bot |
|
|
595
|
+
| `dev:close` | `config` | when `stars dev` shuts down |
|
|
596
|
+
|
|
597
|
+
Hooks run in the CLI process, never in the bot — `env:options` is how a hook changes what the bot receives. An unknown
|
|
598
|
+
hook name fails with `UNKNOWN_HOOK` rather than registering a hook that never runs. In `stars dev` a hook that throws
|
|
599
|
+
is logged and the watcher keeps going; in `stars build` it fails the build.
|
|
600
|
+
|
|
601
|
+
`stars build` and `stars dev` run them in the same order: `config:resolved` → `env:options` → `builder:created` →
|
|
602
|
+
`prepare:before` → `prepare:done`, then `build:before` → `build:done` for each build. `stars dev` adds `dev:start` once
|
|
603
|
+
it is watching, `dev:restart` before each (re)start of the bot, and `dev:close` on shutdown. `stars build` awaits every
|
|
604
|
+
hook. In `stars dev` the builder drives rebuilds on its own: `build:before` starts when it reports a build, without
|
|
605
|
+
delaying it, while `build:done`, `dev:restart` and `dev:close` run one after another — a slow `build:done` settles before
|
|
606
|
+
the restart it triggered, and before shutdown. `build:done` gets the final outcome, including a failure to copy
|
|
607
|
+
`src/locales`.
|
|
515
608
|
|
|
516
609
|
### Experimental flags
|
|
517
610
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wolfstar/http-framework",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "The framework for Star Network's HTTP-only bots",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -77,8 +77,8 @@
|
|
|
77
77
|
"@sapphire/result": "^2.8.0",
|
|
78
78
|
"@sapphire/utilities": "^3.18.2",
|
|
79
79
|
"@vladfrangu/async_event_emitter": "^2.4.7",
|
|
80
|
-
"@wolfstar/cli": "^2.0
|
|
81
|
-
"@wolfstar/schema": "^0.
|
|
80
|
+
"@wolfstar/cli": "^2.1.0",
|
|
81
|
+
"@wolfstar/schema": "^0.4.0",
|
|
82
82
|
"chokidar": "^5.0.0",
|
|
83
83
|
"discord-api-types": "^0.38.8",
|
|
84
84
|
"mlly": "^1.8.2",
|