@vercube/vite 1.1.0 → 1.1.2
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 +19 -6
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +20 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -73,12 +73,25 @@ node dist/index.mjs # runs the built server
|
|
|
73
73
|
|
|
74
74
|
## Options
|
|
75
75
|
|
|
76
|
-
| Option
|
|
77
|
-
|
|
|
78
|
-
| `rootDir`
|
|
79
|
-
| `scanDirs`
|
|
80
|
-
| `setupFile`
|
|
81
|
-
| `runner`
|
|
76
|
+
| Option | Type | Default | Description |
|
|
77
|
+
| ------------ | ---------------------- | --------------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
78
|
+
| `rootDir` | `string` | Vite `root` | Project root used to resolve `scanDirs` and `setupFile`. |
|
|
79
|
+
| `scanDirs` | `string[]` | `['src']` | Directories scanned (recursively) for `@Controller` and `@Injectable` classes. |
|
|
80
|
+
| `setupFile` | `string` | `undefined` | Module whose default export `(app: App) => void \| Promise<void>` runs as `createApp`'s setup hook (before init). |
|
|
81
|
+
| `runner` | `string` | `'node-worker'` | The `env-runner` runner used to execute server code in dev. |
|
|
82
|
+
| `noExternal` | `(string \| RegExp)[]` | `undefined` | Extra dev `resolve.noExternal` patterns merged after `@vercube/*` (see below). |
|
|
83
|
+
|
|
84
|
+
### Dev `noExternal`
|
|
85
|
+
|
|
86
|
+
In dev, Vercube keeps `@vercube/*` inside Vite's module graph so class-reference DI tokens are not loaded twice. If a dependency imports `@vercube/core` from its published `dist` while your app imports it through Vite, inject tokens such as `RequestContext` will not match.
|
|
87
|
+
|
|
88
|
+
Add those packages via `noExternal`:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
vercube({
|
|
92
|
+
noExternal: [/^@org\//],
|
|
93
|
+
});
|
|
94
|
+
```
|
|
82
95
|
|
|
83
96
|
## Setup file
|
|
84
97
|
|
package/dist/index.d.mts
CHANGED
|
@@ -33,6 +33,18 @@ interface VercubePluginConfig {
|
|
|
33
33
|
* Defaults to `node-worker`.
|
|
34
34
|
*/
|
|
35
35
|
runner?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Additional package patterns passed to the Vercube environment's dev
|
|
38
|
+
* `resolve.noExternal`. They are merged after the built-in `@vercube/*`
|
|
39
|
+
* defaults so class-reference DI tokens are not duplicated in the module graph.
|
|
40
|
+
*
|
|
41
|
+
* Use this for workspace packages (for example `@org/*`) that import
|
|
42
|
+
* `@vercube/core` and register Vercube DI tokens.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* vercube({ noExternal: [/^@org\//] })
|
|
46
|
+
*/
|
|
47
|
+
noExternal?: (string | RegExp)[];
|
|
36
48
|
}
|
|
37
49
|
/**
|
|
38
50
|
* Internal plugin context shared across the plugin's sub-plugins and hooks.
|
package/dist/index.mjs
CHANGED
|
@@ -11,12 +11,24 @@ const devWorker = resolve(resolve(dirname(fileURLToPath(import.meta.url)), "runt
|
|
|
11
11
|
//#endregion
|
|
12
12
|
//#region src/env.ts
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
* module graph so class-reference DI tokens are not duplicated; other
|
|
16
|
-
* CJS-only `dotenv`) are left external and loaded via native
|
|
14
|
+
* Default dev-only `resolve.noExternal` patterns. `@vercube/*` must stay in
|
|
15
|
+
* Vite's module graph so class-reference DI tokens are not duplicated; other
|
|
16
|
+
* deps (e.g. CJS-only `dotenv`) are left external and loaded via native
|
|
17
|
+
* `import()`.
|
|
17
18
|
*/
|
|
18
19
|
const DEV_NO_EXTERNAL = [/^@vercube\//];
|
|
19
20
|
/**
|
|
21
|
+
* Resolves the full dev `noExternal` list for the Vercube environment by
|
|
22
|
+
* merging {@link DEV_NO_EXTERNAL} with optional plugin patterns.
|
|
23
|
+
*
|
|
24
|
+
* @param extra - Additional patterns from {@link VercubePluginConfig.noExternal}.
|
|
25
|
+
* @returns Patterns for `resolve.noExternal` in dev.
|
|
26
|
+
*/
|
|
27
|
+
function resolveDevNoExternal(extra) {
|
|
28
|
+
if (!extra?.length) return DEV_NO_EXTERNAL;
|
|
29
|
+
return [...DEV_NO_EXTERNAL, ...extra];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
20
32
|
* The custom message event used to tell the worker which entry an environment loads.
|
|
21
33
|
*/
|
|
22
34
|
const VITE_ENV_EVENT = "vercube:vite-env";
|
|
@@ -33,7 +45,7 @@ const VITE_ENV_EVENT = "vercube:vite-env";
|
|
|
33
45
|
function createVercubeEnvironment(ctx) {
|
|
34
46
|
return {
|
|
35
47
|
consumer: "server",
|
|
36
|
-
resolve: ctx.dev ? { noExternal:
|
|
48
|
+
resolve: ctx.dev ? { noExternal: resolveDevNoExternal(ctx.pluginConfig.noExternal) } : {},
|
|
37
49
|
build: {
|
|
38
50
|
outDir: resolve(ctx.root, "dist"),
|
|
39
51
|
emptyOutDir: false,
|
|
@@ -104,14 +116,16 @@ function getEnvRunner(ctx) {
|
|
|
104
116
|
}
|
|
105
117
|
/**
|
|
106
118
|
* Returns true for bare module specifiers (npm/workspace packages), which the
|
|
107
|
-
* production build externalizes. Relative paths, absolute paths
|
|
108
|
-
* (`\0`-prefixed) ids
|
|
119
|
+
* production build externalizes. Relative paths, absolute paths, virtual
|
|
120
|
+
* (`\0`-prefixed) ids, Vite path aliases (`@/…`), and bundler helper runtimes
|
|
121
|
+
* are bundled.
|
|
109
122
|
*
|
|
110
123
|
* @param id - The import specifier to classify.
|
|
111
124
|
* @returns Whether the specifier is a bare dependency.
|
|
112
125
|
*/
|
|
113
126
|
function isBareSpecifier(id) {
|
|
114
127
|
if (id.startsWith("\0") || id.startsWith(".") || isAbsolute(id)) return false;
|
|
128
|
+
if (id.startsWith("@/") || id.startsWith("@oxc-project/")) return false;
|
|
115
129
|
return true;
|
|
116
130
|
}
|
|
117
131
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercube/vite",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Vite plugin integrating Vercube with the Vite Environment API",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"pathe": "2.0.3",
|
|
37
37
|
"rou3": "0.8.1",
|
|
38
38
|
"srvx": "0.11.17",
|
|
39
|
-
"@vercube/scan": "1.1.
|
|
39
|
+
"@vercube/scan": "1.1.2"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"vite": "^8.0.0"
|