@nestbridge/unplugin 2.0.2 → 2.0.3
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 +86 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# @nestbridge/unplugin
|
|
2
|
+
|
|
3
|
+
[](https://github.com/MDReal32/nestbridge/actions/workflows/release.yml)
|
|
4
|
+
[](https://github.com/MDReal32/nestbridge/actions/workflows/ci.yml)
|
|
5
|
+
[](https://www.npmjs.com/package/@nestbridge/unplugin)
|
|
6
|
+
|
|
7
|
+
The bundler-agnostic plugin logic behind NestBridge: discovery of NestJS
|
|
8
|
+
controllers and GraphQL resolvers, `.d.ts` declaration writing, and the
|
|
9
|
+
virtual-module code generation that turns an imported controller/resolver
|
|
10
|
+
into a `fetch()` call or GraphQL request. It contains no Vite- or
|
|
11
|
+
webpack-specific code — bundler bindings are produced by
|
|
12
|
+
[`unplugin`](https://github.com/unjs/unplugin), which builds one plugin
|
|
13
|
+
implementation into per-bundler outputs.
|
|
14
|
+
|
|
15
|
+
This package is the engine behind [`@nestbridge/vite`](../vite) and
|
|
16
|
+
[`@nestbridge/webpack`](../webpack) and is not usually installed directly;
|
|
17
|
+
see the [repository README](../../README.md) for the full picture of how the
|
|
18
|
+
pieces fit together.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
yarn add @nestbridge/unplugin
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## API
|
|
27
|
+
|
|
28
|
+
### `nestBridgeUnplugin`
|
|
29
|
+
|
|
30
|
+
An `unplugin` `UnpluginInstance<NestBridgeOptions>`. Each property is the
|
|
31
|
+
same plugin logic, bound to that bundler's plugin shape:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { nestBridgeUnplugin } from '@nestbridge/unplugin';
|
|
35
|
+
|
|
36
|
+
nestBridgeUnplugin.vite(options); // Vite Plugin — used by @nestbridge/vite
|
|
37
|
+
nestBridgeUnplugin.webpack(options); // WebpackPluginInstance — used by @nestbridge/webpack
|
|
38
|
+
nestBridgeUnplugin.rollup(options); // Rollup Plugin
|
|
39
|
+
nestBridgeUnplugin.esbuild(options); // esbuild Plugin
|
|
40
|
+
nestBridgeUnplugin.rspack(options); // Rspack Plugin
|
|
41
|
+
nestBridgeUnplugin.farm(options); // Farm JsPlugin
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`@nestbridge/vite` and `@nestbridge/webpack` are thin, typed wrappers around
|
|
45
|
+
`.vite` and `.webpack` respectively. The other targets are available from
|
|
46
|
+
`unplugin` today but don't yet have a dedicated NestBridge package.
|
|
47
|
+
|
|
48
|
+
### `NestBridgeOptions`
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
interface NestBridgeOptions {
|
|
52
|
+
controllers: string | string[]; // glob(s), resolved relative to `root`
|
|
53
|
+
resolvers?: string | string[]; // glob(s) for GraphQL resolvers; defaults to none
|
|
54
|
+
baseURL?: string; // informational; call configureNestBridge for the runtime effect
|
|
55
|
+
debug?: boolean; // logs discovery/analysis/HMR activity
|
|
56
|
+
outputDir?: string; // defaults to ".nestbridge"
|
|
57
|
+
root?: string; // defaults to the bundler's project root, or process.cwd()
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`resolveNestBridgeOptions` fills in the defaults above and is what the
|
|
62
|
+
plugin factory calls internally; it's exported for bundler bindings (or
|
|
63
|
+
tests) that need the resolved shape ahead of time.
|
|
64
|
+
|
|
65
|
+
## What the plugin does
|
|
66
|
+
|
|
67
|
+
1. On `buildStart`, it globs `controllers`/`resolvers`, runs each file
|
|
68
|
+
through [`@nestbridge/core`](../core)'s static analysis, and writes the
|
|
69
|
+
generated `.d.ts` declarations to `outputDir` so TypeScript sees a
|
|
70
|
+
client-facing shape instead of the real file.
|
|
71
|
+
2. It intercepts the bundler's resolution of that same import (`resolveId`/
|
|
72
|
+
`transform`) and serves generated code that calls
|
|
73
|
+
[`@nestbridge/runtime`](../runtime) instead of the real controller or
|
|
74
|
+
resolver — the real source, its NestJS decorators, and its dependencies
|
|
75
|
+
never enter the bundle.
|
|
76
|
+
3. On watched file changes (`watchChange`), it re-analyzes only the affected
|
|
77
|
+
file and rewrites its declaration and generated module.
|
|
78
|
+
|
|
79
|
+
Diagnostics from `@nestbridge/core` (an unsupported decorator, a
|
|
80
|
+
non-literal route path, etc.) are thrown during a one-shot build and logged
|
|
81
|
+
as warnings during watch mode, so a bad decorator doesn't kill an active dev
|
|
82
|
+
server.
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
MIT
|