@moostjs/vite 0.5.0 → 0.5.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/dist/index.cjs CHANGED
@@ -47,7 +47,7 @@ function getLogger() {
47
47
  return logger;
48
48
  }
49
49
 
50
- function moostRestartCleanup(adapters, cleanupInstances) {
50
+ function moostRestartCleanup(adapters, onEject, cleanupInstances) {
51
51
  const logger = getLogger();
52
52
  const infact = moost.getMoostInfact();
53
53
  const { registry } = infact;
@@ -65,13 +65,14 @@ function moostRestartCleanup(adapters, cleanupInstances) {
65
65
  for (const key of Object.getOwnPropertySymbols(registry)) {
66
66
  const instance = registry[key];
67
67
  scanParams(instance, (type) => {
68
- if (type === moost.Moost || type instanceof moost.Moost || type.prototype instanceof moost.Moost) {
68
+ if ((type === moost.Moost || type instanceof moost.Moost || type.prototype instanceof moost.Moost) &&
69
+ (!onEject || onEject(instance, type))) {
69
70
  delete registry[key];
70
71
  logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on re-instantiated "Moost")`);
71
72
  return true;
72
73
  }
73
74
  for (const adapter of adapters) {
74
- if (adapter.compare(type)) {
75
+ if (adapter.compare(type) && (!onEject || onEject(instance, type))) {
75
76
  delete registry[key];
76
77
  logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on re-instantiated "${adapter.constructor.name}")`);
77
78
  return true;
@@ -79,13 +80,13 @@ function moostRestartCleanup(adapters, cleanupInstances) {
79
80
  }
80
81
  });
81
82
  }
82
- clearDependantRegistry(registry);
83
+ clearDependantRegistry(registry, onEject);
83
84
  infact.registry = registry;
84
85
  }
85
86
  moost.getMoostMate()._cleanup();
86
87
  moost.getGlobalWooks(undefined, undefined, 'cleanup');
87
88
  }
88
- function clearDependantRegistry(registry) {
89
+ function clearDependantRegistry(registry, onEject) {
89
90
  const logger = getLogger();
90
91
  const objSet = new Set();
91
92
  let somethingIsDeleted = true;
@@ -98,7 +99,7 @@ function clearDependantRegistry(registry) {
98
99
  for (const key of Object.getOwnPropertySymbols(registry)) {
99
100
  const instance = registry[key];
100
101
  scanParams(instance, (type) => {
101
- if (!objSet.has(type)) {
102
+ if (!objSet.has(type) && (!onEject || onEject(instance, type))) {
102
103
  delete registry[key];
103
104
  logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on "${type.name}" which is not in registry)`);
104
105
  somethingIsDeleted = true;
@@ -208,7 +209,7 @@ function moostViteDev(options) {
208
209
  }
209
210
  },
210
211
  async configureServer(server) {
211
- moostRestartCleanup(adapters);
212
+ moostRestartCleanup(adapters, options.onEject);
212
213
  await server.ssrLoadModule(entry);
213
214
  server.middlewares.use(async (req, res, next) => {
214
215
  if (reloadRequired) {
@@ -240,7 +241,7 @@ function moostViteDev(options) {
240
241
  this.environment.moduleGraph.invalidateModule(mod);
241
242
  }
242
243
  moostMiddleware = null;
243
- moostRestartCleanup(adapters, cleanupInstances);
244
+ moostRestartCleanup(adapters, options.onEject, cleanupInstances);
244
245
  reloadRequired = true;
245
246
  }
246
247
  return [];
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ interface TMoostViteDevOptions {
7
7
  outDir?: string;
8
8
  format?: 'cjs' | 'esm';
9
9
  sourcemap?: boolean;
10
+ onEject?: (instance: object, dependency: Function) => boolean;
10
11
  }
11
12
  /**
12
13
  * The main Vite plugin that:
package/dist/index.mjs CHANGED
@@ -45,7 +45,7 @@ function getLogger() {
45
45
  return logger;
46
46
  }
47
47
 
48
- function moostRestartCleanup(adapters, cleanupInstances) {
48
+ function moostRestartCleanup(adapters, onEject, cleanupInstances) {
49
49
  const logger = getLogger();
50
50
  const infact = getMoostInfact();
51
51
  const { registry } = infact;
@@ -63,13 +63,14 @@ function moostRestartCleanup(adapters, cleanupInstances) {
63
63
  for (const key of Object.getOwnPropertySymbols(registry)) {
64
64
  const instance = registry[key];
65
65
  scanParams(instance, (type) => {
66
- if (type === Moost || type instanceof Moost || type.prototype instanceof Moost) {
66
+ if ((type === Moost || type instanceof Moost || type.prototype instanceof Moost) &&
67
+ (!onEject || onEject(instance, type))) {
67
68
  delete registry[key];
68
69
  logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on re-instantiated "Moost")`);
69
70
  return true;
70
71
  }
71
72
  for (const adapter of adapters) {
72
- if (adapter.compare(type)) {
73
+ if (adapter.compare(type) && (!onEject || onEject(instance, type))) {
73
74
  delete registry[key];
74
75
  logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on re-instantiated "${adapter.constructor.name}")`);
75
76
  return true;
@@ -77,13 +78,13 @@ function moostRestartCleanup(adapters, cleanupInstances) {
77
78
  }
78
79
  });
79
80
  }
80
- clearDependantRegistry(registry);
81
+ clearDependantRegistry(registry, onEject);
81
82
  infact.registry = registry;
82
83
  }
83
84
  getMoostMate()._cleanup();
84
85
  getGlobalWooks(undefined, undefined, 'cleanup');
85
86
  }
86
- function clearDependantRegistry(registry) {
87
+ function clearDependantRegistry(registry, onEject) {
87
88
  const logger = getLogger();
88
89
  const objSet = new Set();
89
90
  let somethingIsDeleted = true;
@@ -96,7 +97,7 @@ function clearDependantRegistry(registry) {
96
97
  for (const key of Object.getOwnPropertySymbols(registry)) {
97
98
  const instance = registry[key];
98
99
  scanParams(instance, (type) => {
99
- if (!objSet.has(type)) {
100
+ if (!objSet.has(type) && (!onEject || onEject(instance, type))) {
100
101
  delete registry[key];
101
102
  logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on "${type.name}" which is not in registry)`);
102
103
  somethingIsDeleted = true;
@@ -206,7 +207,7 @@ function moostViteDev(options) {
206
207
  }
207
208
  },
208
209
  async configureServer(server) {
209
- moostRestartCleanup(adapters);
210
+ moostRestartCleanup(adapters, options.onEject);
210
211
  await server.ssrLoadModule(entry);
211
212
  server.middlewares.use(async (req, res, next) => {
212
213
  if (reloadRequired) {
@@ -238,7 +239,7 @@ function moostViteDev(options) {
238
239
  this.environment.moduleGraph.invalidateModule(mod);
239
240
  }
240
241
  moostMiddleware = null;
241
- moostRestartCleanup(adapters, cleanupInstances);
242
+ moostRestartCleanup(adapters, options.onEject, cleanupInstances);
242
243
  reloadRequired = true;
243
244
  }
244
245
  return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moostjs/vite",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
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.0",
42
- "@moostjs/event-http": "0.5.0",
41
+ "moost": "0.5.1",
42
+ "@moostjs/event-http": "0.5.1",
43
43
  "vite": "^6.0.5"
44
44
  }
45
45
  }