@moostjs/vite 0.5.20 → 0.5.21
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/index.cjs +35 -12
- package/dist/index.d.ts +74 -5
- package/dist/index.mjs +35 -12
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -83,7 +83,7 @@ function patchMoostHandlerLogging() {
|
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
const PLUGIN_NAME = 'moost-vite
|
|
86
|
+
const PLUGIN_NAME = 'moost-vite';
|
|
87
87
|
function gatherAllImporters(moduleNode, visited = new Set()) {
|
|
88
88
|
if (!moduleNode) {
|
|
89
89
|
return visited;
|
|
@@ -103,13 +103,17 @@ const logger = new moost.EventLogger('', { level: 99 }).createTopic('[2m' + '[
|
|
|
103
103
|
function getLogger() {
|
|
104
104
|
return logger;
|
|
105
105
|
}
|
|
106
|
-
function getExternals() {
|
|
106
|
+
function getExternals({ node, workspace }) {
|
|
107
107
|
const pkg = JSON.parse(node_fs.readFileSync('package.json', 'utf8').toString());
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
108
|
+
const externals = workspace
|
|
109
|
+
? Object.keys(pkg.dependencies || {})
|
|
110
|
+
: Object.entries(pkg.dependencies || {})
|
|
111
|
+
.filter(([key, ver]) => !ver.startsWith('workspace:'))
|
|
112
|
+
.map(i => i[0]);
|
|
113
|
+
if (node) {
|
|
114
|
+
externals.push(...node_module.builtinModules, ...node_module.builtinModules.map(m => `node:${m}`));
|
|
115
|
+
}
|
|
116
|
+
return externals;
|
|
113
117
|
}
|
|
114
118
|
|
|
115
119
|
function moostRestartCleanup(adapters, onEject, cleanupInstances) {
|
|
@@ -200,8 +204,12 @@ function constructorName(i) {
|
|
|
200
204
|
const REG_HAS_EXPORT_CLASS = /(^\s*@(Injectable|Controller)\()/m;
|
|
201
205
|
const REG_REPLACE_EXPORT_CLASS = /(^\s*@(Injectable|Controller)\()/gm;
|
|
202
206
|
function moostVite(options) {
|
|
207
|
+
const isTest = process.env.NODE_ENV === 'test';
|
|
208
|
+
const isProd = process.env.NODE_ENV === 'production';
|
|
203
209
|
let moostMiddleware = null;
|
|
204
|
-
const adapters =
|
|
210
|
+
const adapters = isTest
|
|
211
|
+
? []
|
|
212
|
+
: [
|
|
205
213
|
createAdapterDetector('http', MoostHttp => {
|
|
206
214
|
MoostHttp.prototype.listen = function (...args) {
|
|
207
215
|
moostMiddleware = this.getServerCb();
|
|
@@ -214,12 +222,11 @@ function moostVite(options) {
|
|
|
214
222
|
createAdapterDetector('cli'),
|
|
215
223
|
createAdapterDetector('wf'),
|
|
216
224
|
];
|
|
217
|
-
const logger = getLogger();
|
|
225
|
+
const logger = isTest ? console : getLogger();
|
|
218
226
|
let reloadRequired = false;
|
|
219
227
|
patchMoostHandlerLogging();
|
|
220
|
-
|
|
228
|
+
const pluginConfig = {
|
|
221
229
|
name: PLUGIN_NAME,
|
|
222
|
-
apply: 'serve',
|
|
223
230
|
enforce: 'pre',
|
|
224
231
|
config(cfg) {
|
|
225
232
|
const entry = cfg.build?.rollupOptions?.input || options.entry;
|
|
@@ -239,7 +246,15 @@ function moostVite(options) {
|
|
|
239
246
|
ssr: cfg.build?.ssr ?? true,
|
|
240
247
|
minify: cfg.build?.minify || false,
|
|
241
248
|
rollupOptions: {
|
|
242
|
-
external:
|
|
249
|
+
external: isTest
|
|
250
|
+
? cfg.build?.rollupOptions?.external
|
|
251
|
+
: cfg.build?.rollupOptions?.external ||
|
|
252
|
+
(options.externals === false
|
|
253
|
+
? []
|
|
254
|
+
: getExternals({
|
|
255
|
+
node: Boolean(options.externals === true || options.externals?.node),
|
|
256
|
+
workspace: Boolean(options.externals === true || options.externals?.workspace),
|
|
257
|
+
})),
|
|
243
258
|
input: entry,
|
|
244
259
|
output: {
|
|
245
260
|
format: options.format,
|
|
@@ -324,6 +339,14 @@ function moostVite(options) {
|
|
|
324
339
|
}
|
|
325
340
|
},
|
|
326
341
|
};
|
|
342
|
+
if (isProd || isTest) {
|
|
343
|
+
delete pluginConfig.configureServer;
|
|
344
|
+
delete pluginConfig.resolveId;
|
|
345
|
+
delete pluginConfig.load;
|
|
346
|
+
delete pluginConfig.transform;
|
|
347
|
+
delete pluginConfig.hotUpdate;
|
|
348
|
+
}
|
|
349
|
+
return pluginConfig;
|
|
327
350
|
}
|
|
328
351
|
|
|
329
352
|
exports.moostVite = moostVite;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,89 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
|
|
3
3
|
interface TMoostViteDevOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The entry file for the application.
|
|
6
|
+
* This file serves as the main entry point for the build process and SSR server.
|
|
7
|
+
*
|
|
8
|
+
* Example: './src/main.ts'
|
|
9
|
+
*/
|
|
4
10
|
entry: string;
|
|
11
|
+
/**
|
|
12
|
+
* The port number for the Vite dev server.
|
|
13
|
+
*
|
|
14
|
+
* Default: `3000`.
|
|
15
|
+
*/
|
|
5
16
|
port?: number;
|
|
17
|
+
/**
|
|
18
|
+
* The hostname or IP address for the Vite dev server.
|
|
19
|
+
* If not specified, defaults to `'localhost'`.
|
|
20
|
+
*
|
|
21
|
+
* Example: '0.0.0.0'
|
|
22
|
+
*/
|
|
6
23
|
host?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The output directory for the build artifacts.
|
|
26
|
+
*
|
|
27
|
+
* Default to: `'dist'`.
|
|
28
|
+
*/
|
|
7
29
|
outDir?: string;
|
|
30
|
+
/**
|
|
31
|
+
* The output format for the build artifacts.
|
|
32
|
+
* - `'cjs'`: CommonJS, suitable for Node.js environments.
|
|
33
|
+
* - `'esm'`: ES Module, suitable for modern environments.
|
|
34
|
+
*
|
|
35
|
+
* Default: `'esm'`.
|
|
36
|
+
*/
|
|
8
37
|
format?: 'cjs' | 'esm';
|
|
38
|
+
/**
|
|
39
|
+
* Whether to generate source maps for the build output.
|
|
40
|
+
* Source maps are useful for debugging purposes by mapping minified code back to the original source.
|
|
41
|
+
*
|
|
42
|
+
* Default: `true`.
|
|
43
|
+
*/
|
|
9
44
|
sourcemap?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Configuration for defining external dependencies during the build process.
|
|
47
|
+
*
|
|
48
|
+
* This helps in excluding certain modules from the bundled output, reducing the bundle size and
|
|
49
|
+
* allowing them to be resolved at runtime instead.
|
|
50
|
+
*
|
|
51
|
+
* Default: `true`.
|
|
52
|
+
*/
|
|
53
|
+
externals?: {
|
|
54
|
+
/**
|
|
55
|
+
* Whether to exclude Node.js built-in modules (e.g., `fs`, `path`, `node:fs`) from the build output.
|
|
56
|
+
* If `true`, all Node.js built-ins will be marked as external.
|
|
57
|
+
* Default: `false`.
|
|
58
|
+
*/
|
|
59
|
+
node?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Whether to exclude workspace dependencies (e.g., packages marked with `workspace:*` in `package.json`) from the build output.
|
|
62
|
+
* If `true`, all workspace dependencies will be marked as external.
|
|
63
|
+
* Default: `false`.
|
|
64
|
+
*/
|
|
65
|
+
workspace?: boolean;
|
|
66
|
+
} | boolean;
|
|
10
67
|
onEject?: (instance: object, dependency: Function) => boolean;
|
|
11
68
|
}
|
|
12
69
|
/**
|
|
13
|
-
* The main Vite plugin
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* -
|
|
17
|
-
* -
|
|
70
|
+
* The main Vite plugin for integrating Moost applications.
|
|
71
|
+
*
|
|
72
|
+
* Features:
|
|
73
|
+
* - **Adapter Detection**: Detects Moost adapter usage (`http`, `cli`, `wf`) and applies relevant configurations.
|
|
74
|
+
* - **Dev Mode Middleware**:
|
|
75
|
+
* - Patches `MoostHttp.prototype.listen` to register a custom middleware for serving the app via Vite's dev server instead of binding to a port.
|
|
76
|
+
* - Handles Moost state cleanup and hot module replacement (HMR) during development.
|
|
77
|
+
* - **Class Tracking**: Injects a `__VITE_ID()` decorator into exported classes to enable tracking and cleanup during hot reloads.
|
|
78
|
+
* - **Externals Support**:
|
|
79
|
+
* - Allows marking Node.js built-in modules and dependencies from `package.json` (optionally excluding workspace dependencies) as external during builds.
|
|
80
|
+
* - Configured via the `externals` option, which helps reduce bundle size and ensures compatibility with runtime environments.
|
|
81
|
+
* - **Build and Test Friendly**:
|
|
82
|
+
* - Avoids interfering with Vitest runs by skipping dev-specific behaviors during tests.
|
|
83
|
+
* - Ensures proper SSR entry setup and Rollup configurations for production builds.
|
|
84
|
+
*
|
|
85
|
+
* @param {TMoostViteDevOptions} options - Configuration options for the Moost Vite plugin.
|
|
86
|
+
* @returns {Plugin} The configured Vite plugin.
|
|
18
87
|
*/
|
|
19
88
|
declare function moostVite(options: TMoostViteDevOptions): Plugin;
|
|
20
89
|
|
package/dist/index.mjs
CHANGED
|
@@ -81,7 +81,7 @@ function patchMoostHandlerLogging() {
|
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
const PLUGIN_NAME = 'moost-vite
|
|
84
|
+
const PLUGIN_NAME = 'moost-vite';
|
|
85
85
|
function gatherAllImporters(moduleNode, visited = new Set()) {
|
|
86
86
|
if (!moduleNode) {
|
|
87
87
|
return visited;
|
|
@@ -101,13 +101,17 @@ const logger = new EventLogger('', { level: 99 }).createTopic('[2m' + '[36m' +
|
|
|
101
101
|
function getLogger() {
|
|
102
102
|
return logger;
|
|
103
103
|
}
|
|
104
|
-
function getExternals() {
|
|
104
|
+
function getExternals({ node, workspace }) {
|
|
105
105
|
const pkg = JSON.parse(readFileSync('package.json', 'utf8').toString());
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
const externals = workspace
|
|
107
|
+
? Object.keys(pkg.dependencies || {})
|
|
108
|
+
: Object.entries(pkg.dependencies || {})
|
|
109
|
+
.filter(([key, ver]) => !ver.startsWith('workspace:'))
|
|
110
|
+
.map(i => i[0]);
|
|
111
|
+
if (node) {
|
|
112
|
+
externals.push(...builtinModules, ...builtinModules.map(m => `node:${m}`));
|
|
113
|
+
}
|
|
114
|
+
return externals;
|
|
111
115
|
}
|
|
112
116
|
|
|
113
117
|
function moostRestartCleanup(adapters, onEject, cleanupInstances) {
|
|
@@ -198,8 +202,12 @@ function constructorName(i) {
|
|
|
198
202
|
const REG_HAS_EXPORT_CLASS = /(^\s*@(Injectable|Controller)\()/m;
|
|
199
203
|
const REG_REPLACE_EXPORT_CLASS = /(^\s*@(Injectable|Controller)\()/gm;
|
|
200
204
|
function moostVite(options) {
|
|
205
|
+
const isTest = process.env.NODE_ENV === 'test';
|
|
206
|
+
const isProd = process.env.NODE_ENV === 'production';
|
|
201
207
|
let moostMiddleware = null;
|
|
202
|
-
const adapters =
|
|
208
|
+
const adapters = isTest
|
|
209
|
+
? []
|
|
210
|
+
: [
|
|
203
211
|
createAdapterDetector('http', MoostHttp => {
|
|
204
212
|
MoostHttp.prototype.listen = function (...args) {
|
|
205
213
|
moostMiddleware = this.getServerCb();
|
|
@@ -212,12 +220,11 @@ function moostVite(options) {
|
|
|
212
220
|
createAdapterDetector('cli'),
|
|
213
221
|
createAdapterDetector('wf'),
|
|
214
222
|
];
|
|
215
|
-
const logger = getLogger();
|
|
223
|
+
const logger = isTest ? console : getLogger();
|
|
216
224
|
let reloadRequired = false;
|
|
217
225
|
patchMoostHandlerLogging();
|
|
218
|
-
|
|
226
|
+
const pluginConfig = {
|
|
219
227
|
name: PLUGIN_NAME,
|
|
220
|
-
apply: 'serve',
|
|
221
228
|
enforce: 'pre',
|
|
222
229
|
config(cfg) {
|
|
223
230
|
const entry = cfg.build?.rollupOptions?.input || options.entry;
|
|
@@ -237,7 +244,15 @@ function moostVite(options) {
|
|
|
237
244
|
ssr: cfg.build?.ssr ?? true,
|
|
238
245
|
minify: cfg.build?.minify || false,
|
|
239
246
|
rollupOptions: {
|
|
240
|
-
external:
|
|
247
|
+
external: isTest
|
|
248
|
+
? cfg.build?.rollupOptions?.external
|
|
249
|
+
: cfg.build?.rollupOptions?.external ||
|
|
250
|
+
(options.externals === false
|
|
251
|
+
? []
|
|
252
|
+
: getExternals({
|
|
253
|
+
node: Boolean(options.externals === true || options.externals?.node),
|
|
254
|
+
workspace: Boolean(options.externals === true || options.externals?.workspace),
|
|
255
|
+
})),
|
|
241
256
|
input: entry,
|
|
242
257
|
output: {
|
|
243
258
|
format: options.format,
|
|
@@ -322,6 +337,14 @@ function moostVite(options) {
|
|
|
322
337
|
}
|
|
323
338
|
},
|
|
324
339
|
};
|
|
340
|
+
if (isProd || isTest) {
|
|
341
|
+
delete pluginConfig.configureServer;
|
|
342
|
+
delete pluginConfig.resolveId;
|
|
343
|
+
delete pluginConfig.load;
|
|
344
|
+
delete pluginConfig.transform;
|
|
345
|
+
delete pluginConfig.hotUpdate;
|
|
346
|
+
}
|
|
347
|
+
return pluginConfig;
|
|
325
348
|
}
|
|
326
349
|
|
|
327
350
|
export { moostVite };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/vite",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.21",
|
|
4
4
|
"description": "Vite Dev plugin for moostjs",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://github.com/moostjs/moostjs/tree/main/packages/vite#readme",
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"moost": "0.5.
|
|
42
|
-
"@moostjs/event-http": "0.5.
|
|
41
|
+
"moost": "0.5.21",
|
|
42
|
+
"@moostjs/event-http": "0.5.21",
|
|
43
43
|
"vite": "^6.0.5"
|
|
44
44
|
}
|
|
45
45
|
}
|