@moostjs/vite 0.5.33 → 0.6.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 CHANGED
@@ -1 +1,42 @@
1
- # @moostjs/vite
1
+ # @moostjs/vite
2
+
3
+ Vite dev plugin for [Moost](https://moost.org). Enables hot module replacement for Moost HTTP applications during development, automatic adapter detection, and production build configuration.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @moostjs/vite --save-dev
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```ts
14
+ // vite.config.ts
15
+ import { defineConfig } from 'vite'
16
+ import { moostVite } from '@moostjs/vite'
17
+
18
+ export default defineConfig({
19
+ plugins: [
20
+ moostVite({
21
+ entry: './src/main.ts',
22
+ port: 3000,
23
+ }),
24
+ ],
25
+ })
26
+ ```
27
+
28
+ ## Options
29
+
30
+ | Option | Type | Default | Description |
31
+ | ----------- | ------------------- | ------------- | --------------------------------- |
32
+ | `entry` | `string` | — | Application entry file (required) |
33
+ | `port` | `number` | `3000` | Dev server port |
34
+ | `host` | `string` | `'localhost'` | Dev server host |
35
+ | `outDir` | `string` | `'dist'` | Build output directory |
36
+ | `format` | `'cjs' \| 'esm'` | `'esm'` | Output module format |
37
+ | `sourcemap` | `boolean` | `true` | Generate source maps |
38
+ | `externals` | `boolean \| object` | `true` | Configure external dependencies |
39
+
40
+ ## License
41
+
42
+ MIT
package/dist/index.cjs CHANGED
@@ -64,9 +64,11 @@ function getExternals({ node, workspace }) {
64
64
  detected: false,
65
65
  regex: /* @__PURE__ */ new RegExp(`from\\s+["'](@moostjs\\/event-${adapter})["']`),
66
66
  constructor: null,
67
+ ssrLoadModule: null,
67
68
  async init() {
68
69
  this.detected = true;
69
- const module$1 = await import(`@moostjs/event-${adapter}`);
70
+ const moduleId = `@moostjs/event-${adapter}`;
71
+ const module$1 = this.ssrLoadModule ? await this.ssrLoadModule(moduleId) : await import(moduleId);
70
72
  const constructorName$1 = `Moost${adapter.charAt(0).toUpperCase() + adapter.slice(1)}`;
71
73
  getLogger().log(`🔍 Extracting Adapter "${constructorName$1}"`);
72
74
  this.constructor = module$1[constructorName$1];
@@ -252,17 +254,23 @@ function clearDependantRegistry(registry, onEject) {
252
254
  }
253
255
  for (const key of Object.getOwnPropertySymbols(registry)) {
254
256
  const instance = registry[key];
255
- scanParams(instance, (type) => {
256
- if (!objSet.has(type) && (!onEject || onEject(instance, type))) {
257
- delete registry[key];
258
- logger$1.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on "${type.name}" which is not in registry)`);
259
- somethingIsDeleted = true;
260
- return true;
261
- }
262
- });
257
+ const ejected = checkAndEject(instance, objSet, onEject, registry, key, logger$1);
258
+ if (ejected) somethingIsDeleted = true;
263
259
  }
264
260
  }
265
261
  }
262
+ function checkAndEject(instance, objSet, onEject, registry, key, logger$1) {
263
+ let ejected = false;
264
+ scanParams(instance, (type) => {
265
+ if (!objSet.has(type) && (!onEject || onEject(instance, type))) {
266
+ delete registry[key];
267
+ logger$1.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on "${type.name}" which is not in registry)`);
268
+ ejected = true;
269
+ return true;
270
+ }
271
+ });
272
+ return ejected;
273
+ }
266
274
  function scanParams(instance, cb) {
267
275
  const mate = (0, moost.getMoostMate)();
268
276
  const params = mate.read(instance)?.params;
@@ -311,7 +319,7 @@ const REG_REPLACE_EXPORT_CLASS = /(^\s*@(Injectable|Controller)\()/gm;
311
319
  const adapters = isTest ? [] : [
312
320
  createAdapterDetector("http", (MoostHttp) => {
313
321
  MoostHttp.prototype.listen = function(...args) {
314
- logger$1.log("🔌 \x1B[2mOvertaking HTTP.listen");
322
+ logger$1.log(`🔌 Overtaking HTTP.listen`);
315
323
  moostMiddleware = this.getServerCb();
316
324
  setTimeout(() => {
317
325
  args.filter((a) => typeof a === "function").forEach((a) => a());
@@ -391,6 +399,7 @@ const REG_REPLACE_EXPORT_CLASS = /(^\s*@(Injectable|Controller)\()/gm;
391
399
  };
392
400
  },
393
401
  async configureServer(server) {
402
+ for (const adapter of adapters) adapter.ssrLoadModule = (id) => server.ssrLoadModule(id);
394
403
  moostRestartCleanup(adapters, options.onEject);
395
404
  await server.ssrLoadModule(options.entry);
396
405
  server.middlewares.use(async (req, res, next) => {
package/dist/index.mjs CHANGED
@@ -41,9 +41,11 @@ function getExternals({ node, workspace }) {
41
41
  detected: false,
42
42
  regex: /* @__PURE__ */ new RegExp(`from\\s+["'](@moostjs\\/event-${adapter})["']`),
43
43
  constructor: null,
44
+ ssrLoadModule: null,
44
45
  async init() {
45
46
  this.detected = true;
46
- const module = await import(`@moostjs/event-${adapter}`);
47
+ const moduleId = `@moostjs/event-${adapter}`;
48
+ const module = this.ssrLoadModule ? await this.ssrLoadModule(moduleId) : await import(moduleId);
47
49
  const constructorName$1 = `Moost${adapter.charAt(0).toUpperCase() + adapter.slice(1)}`;
48
50
  getLogger().log(`🔍 Extracting Adapter "${constructorName$1}"`);
49
51
  this.constructor = module[constructorName$1];
@@ -229,17 +231,23 @@ function clearDependantRegistry(registry, onEject) {
229
231
  }
230
232
  for (const key of Object.getOwnPropertySymbols(registry)) {
231
233
  const instance = registry[key];
232
- scanParams(instance, (type) => {
233
- if (!objSet.has(type) && (!onEject || onEject(instance, type))) {
234
- delete registry[key];
235
- logger$1.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on "${type.name}" which is not in registry)`);
236
- somethingIsDeleted = true;
237
- return true;
238
- }
239
- });
234
+ const ejected = checkAndEject(instance, objSet, onEject, registry, key, logger$1);
235
+ if (ejected) somethingIsDeleted = true;
240
236
  }
241
237
  }
242
238
  }
239
+ function checkAndEject(instance, objSet, onEject, registry, key, logger$1) {
240
+ let ejected = false;
241
+ scanParams(instance, (type) => {
242
+ if (!objSet.has(type) && (!onEject || onEject(instance, type))) {
243
+ delete registry[key];
244
+ logger$1.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on "${type.name}" which is not in registry)`);
245
+ ejected = true;
246
+ return true;
247
+ }
248
+ });
249
+ return ejected;
250
+ }
243
251
  function scanParams(instance, cb) {
244
252
  const mate = getMoostMate();
245
253
  const params = mate.read(instance)?.params;
@@ -288,7 +296,7 @@ const REG_REPLACE_EXPORT_CLASS = /(^\s*@(Injectable|Controller)\()/gm;
288
296
  const adapters = isTest ? [] : [
289
297
  createAdapterDetector("http", (MoostHttp) => {
290
298
  MoostHttp.prototype.listen = function(...args) {
291
- logger$1.log("🔌 \x1B[2mOvertaking HTTP.listen");
299
+ logger$1.log(`🔌 Overtaking HTTP.listen`);
292
300
  moostMiddleware = this.getServerCb();
293
301
  setTimeout(() => {
294
302
  args.filter((a) => typeof a === "function").forEach((a) => a());
@@ -368,6 +376,7 @@ const REG_REPLACE_EXPORT_CLASS = /(^\s*@(Injectable|Controller)\()/gm;
368
376
  };
369
377
  },
370
378
  async configureServer(server) {
379
+ for (const adapter of adapters) adapter.ssrLoadModule = (id) => server.ssrLoadModule(id);
371
380
  moostRestartCleanup(adapters, options.onEject);
372
381
  await server.ssrLoadModule(options.entry);
373
382
  server.middlewares.use(async (req, res, next) => {
package/package.json CHANGED
@@ -1,11 +1,35 @@
1
1
  {
2
2
  "name": "@moostjs/vite",
3
- "version": "0.5.33",
3
+ "version": "0.6.1",
4
4
  "description": "Vite Dev plugin for moostjs",
5
+ "keywords": [
6
+ "composables",
7
+ "framework",
8
+ "moost",
9
+ "moostjs",
10
+ "prostojs",
11
+ "vite",
12
+ "wooksjs"
13
+ ],
14
+ "homepage": "https://github.com/moostjs/moostjs/tree/main/packages/vite#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/moostjs/moostjs/issues"
17
+ },
18
+ "license": "MIT",
19
+ "author": "Artem Maltsev",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/moostjs/moostjs.git",
23
+ "directory": "packages/vite"
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "type": "module",
29
+ "sideEffects": false,
5
30
  "main": "dist/index.cjs",
6
31
  "module": "dist/index.mjs",
7
32
  "types": "dist/index.d.ts",
8
- "sideEffects": false,
9
33
  "exports": {
10
34
  "./package.json": "./package.json",
11
35
  ".": {
@@ -14,39 +38,16 @@
14
38
  "require": "./dist/index.cjs"
15
39
  }
16
40
  },
17
- "files": [
18
- "dist"
19
- ],
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://github.com/moostjs/moostjs.git",
23
- "directory": "packages/vite"
24
- },
25
- "keywords": [
26
- "moost",
27
- "moostjs",
28
- "composables",
29
- "framework",
30
- "wooksjs",
31
- "prostojs",
32
- "vite"
33
- ],
34
- "author": "Artem Maltsev",
35
- "license": "MIT",
36
- "bugs": {
37
- "url": "https://github.com/moostjs/moostjs/issues"
38
- },
39
- "homepage": "https://github.com/moostjs/moostjs/tree/main/packages/vite#readme",
40
- "peerDependencies": {
41
- "vite": "^7.0.0",
42
- "moost": "^0.5.33",
43
- "@moostjs/event-http": "^0.5.33"
41
+ "dependencies": {
42
+ "magic-string": "^0.30.21"
44
43
  },
45
44
  "devDependencies": {
46
45
  "vitest": "3.2.4"
47
46
  },
48
- "dependencies": {
49
- "magic-string": "^0.30.17"
47
+ "peerDependencies": {
48
+ "vite": "^7.0.0",
49
+ "@moostjs/event-http": "^0.6.1",
50
+ "moost": "^0.6.1"
50
51
  },
51
52
  "scripts": {
52
53
  "pub": "pnpm publish --access public",