@moostjs/vite 0.5.20 → 0.5.22
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/LICENSE +21 -0
- package/dist/index.cjs +354 -294
- package/dist/index.d.ts +4 -7
- package/dist/index.mjs +331 -293
- package/package.json +14 -7
package/dist/index.mjs
CHANGED
|
@@ -1,327 +1,365 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { builtinModules } from 'node:module';
|
|
1
|
+
import { EventLogger, Moost, clearGlobalWooks, getMoostInfact, getMoostMate } from "moost";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { builtinModules } from "node:module";
|
|
5
4
|
|
|
5
|
+
//#region packages/vite/src/adapter-detector.ts
|
|
6
6
|
function createAdapterDetector(adapter, onInit) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
c instanceof this.constructor ||
|
|
23
|
-
c.prototype instanceof this.constructor);
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
},
|
|
27
|
-
};
|
|
7
|
+
return {
|
|
8
|
+
detected: false,
|
|
9
|
+
regex: new RegExp(`from\\s+["'](@moostjs\\/event-${adapter})["']`),
|
|
10
|
+
constructor: null,
|
|
11
|
+
async init() {
|
|
12
|
+
this.detected = true;
|
|
13
|
+
const module = await import(`@moostjs/event-${adapter}`);
|
|
14
|
+
this.constructor = module[`Moost${adapter.charAt(0).toUpperCase() + adapter.slice(1)}`];
|
|
15
|
+
if (onInit) onInit(this.constructor);
|
|
16
|
+
},
|
|
17
|
+
compare(c) {
|
|
18
|
+
if (this.detected && this.constructor) return this.constructor === c || c instanceof this.constructor || c.prototype instanceof this.constructor;
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
28
22
|
}
|
|
29
23
|
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region packages/vite/src/moost-logging.ts
|
|
26
|
+
function _define_property(obj, key, value) {
|
|
27
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
28
|
+
value,
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true
|
|
32
|
+
});
|
|
33
|
+
else obj[key] = value;
|
|
34
|
+
return obj;
|
|
32
35
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
startRecording() {
|
|
40
|
-
this.newItems = [];
|
|
41
|
-
}
|
|
42
|
-
record(item) {
|
|
43
|
-
const flat = flattenItem(item);
|
|
44
|
-
this.newItems.push(item);
|
|
45
|
-
return !this.oldMap.has(flat);
|
|
46
|
-
}
|
|
47
|
-
endRecording(logRemovedItem) {
|
|
48
|
-
const newMap = new Map();
|
|
49
|
-
for (const item of this.newItems) {
|
|
50
|
-
const flat = flattenItem(item);
|
|
51
|
-
newMap.set(flat, item);
|
|
52
|
-
}
|
|
53
|
-
for (const [flat, item] of this.oldMap.entries()) {
|
|
54
|
-
if (!newMap.has(flat)) {
|
|
55
|
-
logRemovedItem(item);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
this.oldMap = newMap;
|
|
59
|
-
this.newItems = [];
|
|
60
|
-
this.isFirstRun = false;
|
|
61
|
-
}
|
|
36
|
+
/**
|
|
37
|
+
* Converts a TItem into a flattened string to uniquely identify it.
|
|
38
|
+
* @param {TItem} item - The handler registration item to flatten.
|
|
39
|
+
* @returns {string} A unique string key for the item.
|
|
40
|
+
*/ function flattenItem(item) {
|
|
41
|
+
return `${item.eventName}||${item.classConstructor.name}||${item.method}`;
|
|
62
42
|
}
|
|
63
|
-
|
|
43
|
+
/**
|
|
44
|
+
* A storage mechanism to track old and new handler registrations
|
|
45
|
+
* across multiple initialization cycles. During each init:
|
|
46
|
+
* 1. Start recording newly encountered handlers.
|
|
47
|
+
* 2. Compare them against previously recorded handlers to detect
|
|
48
|
+
* which are newly added vs. removed.
|
|
49
|
+
* 3. Store the new state as the old map for the next cycle.
|
|
50
|
+
*/ let LogsStorage = class LogsStorage$1 {
|
|
51
|
+
/**
|
|
52
|
+
* Called at the start of an init cycle to
|
|
53
|
+
* clear out the list of new items.
|
|
54
|
+
*/ startRecording() {
|
|
55
|
+
this.newItems = [];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Records a newly encountered handler (via logMappedHandler).
|
|
59
|
+
*
|
|
60
|
+
* @param {TItem} item - The handler registration item to record.
|
|
61
|
+
* @returns {boolean} True if this item is newly added (not in oldMap),
|
|
62
|
+
* false if it existed already.
|
|
63
|
+
*/ record(item) {
|
|
64
|
+
const flat = flattenItem(item);
|
|
65
|
+
this.newItems.push(item);
|
|
66
|
+
return !this.oldMap.has(flat);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Called at the end of an init cycle.
|
|
70
|
+
* 1. Builds a newMap of all newly encountered handlers.
|
|
71
|
+
* 2. Logs/strokes out any handlers that have disappeared compared
|
|
72
|
+
* to the previous cycle.
|
|
73
|
+
* 3. Updates oldMap so it becomes the baseline for the next cycle.
|
|
74
|
+
*
|
|
75
|
+
* @param {(item: TItem) => void} logRemovedItem - A callback that logs
|
|
76
|
+
* removed items (presumably by striking them out).
|
|
77
|
+
*/ endRecording(logRemovedItem) {
|
|
78
|
+
const newMap = new Map();
|
|
79
|
+
for (const item of this.newItems) {
|
|
80
|
+
const flat = flattenItem(item);
|
|
81
|
+
newMap.set(flat, item);
|
|
82
|
+
}
|
|
83
|
+
for (const [flat, item] of this.oldMap.entries()) if (!newMap.has(flat)) logRemovedItem(item);
|
|
84
|
+
this.oldMap = newMap;
|
|
85
|
+
this.newItems = [];
|
|
86
|
+
this.isFirstRun = false;
|
|
87
|
+
}
|
|
88
|
+
constructor() {
|
|
89
|
+
/**
|
|
90
|
+
* A map of flattenItem() => TItem
|
|
91
|
+
* representing the previous cycle's known handlers.
|
|
92
|
+
*/ _define_property(this, "oldMap", new Map());
|
|
93
|
+
/**
|
|
94
|
+
* The handlers discovered in the current cycle,
|
|
95
|
+
* awaiting finalization.
|
|
96
|
+
*/ _define_property(this, "newItems", []);
|
|
97
|
+
_define_property(this, "isFirstRun", true);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* A reference to a shared LogsStorage instance that persists
|
|
102
|
+
* across init cycles in dev mode.
|
|
103
|
+
*/ let logsStorage;
|
|
64
104
|
function patchMoostHandlerLogging() {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
105
|
+
const origInit = Moost.prototype.init;
|
|
106
|
+
/**
|
|
107
|
+
* Monkey-patch Moost.init:
|
|
108
|
+
* 1. Start a new recording cycle in LogsStorage.
|
|
109
|
+
* 2. Call the real .init().
|
|
110
|
+
* 3. End the recording, logging any removed handlers.
|
|
111
|
+
*/ Moost.prototype.init = async function init() {
|
|
112
|
+
if (!logsStorage) logsStorage = new LogsStorage();
|
|
113
|
+
logsStorage.startRecording();
|
|
114
|
+
await origInit.call(this);
|
|
115
|
+
logsStorage.endRecording((item) => {
|
|
116
|
+
origLogMappedHandler.call(this, item.eventName, item.classConstructor, item.method, true, "❌ ");
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
const origLogMappedHandler = Moost.prototype.logMappedHandler;
|
|
120
|
+
/**
|
|
121
|
+
* Monkey-patch Moost.logMappedHandler:
|
|
122
|
+
* If we haven’t seen this particular route+class+method combination
|
|
123
|
+
* in a previous cycle, call the original logger. Otherwise, skip it
|
|
124
|
+
* to avoid duplicate logs.
|
|
125
|
+
*/ Moost.prototype.logMappedHandler = function logMappedHandler(eventName, classConstructor, method) {
|
|
126
|
+
if (logsStorage.record({
|
|
127
|
+
eventName,
|
|
128
|
+
classConstructor,
|
|
129
|
+
method
|
|
130
|
+
})) origLogMappedHandler.call(this, eventName, classConstructor, method, false, logsStorage.isFirstRun ? "" : "✅ ");
|
|
131
|
+
};
|
|
82
132
|
}
|
|
83
133
|
|
|
84
|
-
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region packages/vite/src/utils.ts
|
|
136
|
+
const PLUGIN_NAME = "moost-vite";
|
|
85
137
|
function gatherAllImporters(moduleNode, visited = new Set()) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
visited.add(moduleNode);
|
|
93
|
-
if (moduleNode.importers) {
|
|
94
|
-
for (const importer of moduleNode.importers) {
|
|
95
|
-
gatherAllImporters(importer, visited);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return visited;
|
|
138
|
+
if (!moduleNode) return visited;
|
|
139
|
+
if (visited.has(moduleNode)) return visited;
|
|
140
|
+
visited.add(moduleNode);
|
|
141
|
+
if (moduleNode.importers) for (const importer of moduleNode.importers) gatherAllImporters(importer, visited);
|
|
142
|
+
return visited;
|
|
99
143
|
}
|
|
100
|
-
const logger = new EventLogger(
|
|
144
|
+
const logger = new EventLogger("", { level: 99 }).createTopic("\x1B[2m\x1B[36m" + PLUGIN_NAME);
|
|
101
145
|
function getLogger() {
|
|
102
|
-
|
|
146
|
+
return logger;
|
|
103
147
|
}
|
|
104
|
-
function getExternals() {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
...Object.keys(pkg.dependencies || {}),
|
|
110
|
-
];
|
|
148
|
+
function getExternals({ node, workspace }) {
|
|
149
|
+
const pkg = JSON.parse(readFileSync("package.json", "utf8").toString());
|
|
150
|
+
const externals = workspace ? Object.keys(pkg.dependencies || {}) : Object.entries(pkg.dependencies || {}).filter(([key, ver]) => !ver.startsWith("workspace:")).map((i) => i[0]);
|
|
151
|
+
if (node) externals.push(...builtinModules, ...builtinModules.map((m) => `node:${m}`));
|
|
152
|
+
return externals;
|
|
111
153
|
}
|
|
112
154
|
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region packages/vite/src/restart-cleanup.ts
|
|
113
157
|
function moostRestartCleanup(adapters, onEject, cleanupInstances) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
getMoostMate()._cleanup();
|
|
154
|
-
clearGlobalWooks();
|
|
158
|
+
const logger$1 = getLogger();
|
|
159
|
+
const infact = getMoostInfact();
|
|
160
|
+
const { registry, scopes } = infact;
|
|
161
|
+
const registries = [registry, ...Object.values(scopes)];
|
|
162
|
+
infact._cleanup();
|
|
163
|
+
const mate = getMoostMate();
|
|
164
|
+
if (cleanupInstances) {
|
|
165
|
+
for (const reg of registries) {
|
|
166
|
+
for (const key of Object.getOwnPropertySymbols(reg)) {
|
|
167
|
+
const instance = reg[key];
|
|
168
|
+
const viteId = mate.read(instance)?.__vite_id;
|
|
169
|
+
if (viteId && cleanupInstances.has(viteId)) {
|
|
170
|
+
logger$1.debug(`🔃 Replacing "${constructorName(instance)}"`);
|
|
171
|
+
delete reg[key];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
for (const key of Object.getOwnPropertySymbols(reg)) {
|
|
175
|
+
const instance = reg[key];
|
|
176
|
+
scanParams(instance, (type) => {
|
|
177
|
+
if ((type === Moost || type instanceof Moost || type.prototype instanceof Moost) && (!onEject || onEject(instance, type))) {
|
|
178
|
+
delete reg[key];
|
|
179
|
+
logger$1.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on re-instantiated "Moost")`);
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
for (const adapter of adapters) if (adapter.compare(type) && (!onEject || onEject(instance, type))) {
|
|
183
|
+
delete reg[key];
|
|
184
|
+
logger$1.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on re-instantiated "${adapter.constructor.name}")`);
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
clearDependantRegistry(reg, onEject);
|
|
190
|
+
}
|
|
191
|
+
infact.registry = registry;
|
|
192
|
+
infact.scopes = scopes;
|
|
193
|
+
}
|
|
194
|
+
getMoostMate()._cleanup();
|
|
195
|
+
clearGlobalWooks();
|
|
155
196
|
}
|
|
156
197
|
function clearDependantRegistry(registry, onEject) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
198
|
+
const logger$1 = getLogger();
|
|
199
|
+
const objSet = new Set();
|
|
200
|
+
let somethingIsDeleted = true;
|
|
201
|
+
while (somethingIsDeleted) {
|
|
202
|
+
somethingIsDeleted = false;
|
|
203
|
+
for (const key of Object.getOwnPropertySymbols(registry)) {
|
|
204
|
+
const instance = registry[key];
|
|
205
|
+
objSet.add(Object.getPrototypeOf(instance).constructor);
|
|
206
|
+
}
|
|
207
|
+
for (const key of Object.getOwnPropertySymbols(registry)) {
|
|
208
|
+
const instance = registry[key];
|
|
209
|
+
scanParams(instance, (type) => {
|
|
210
|
+
if (!objSet.has(type) && (!onEject || onEject(instance, type))) {
|
|
211
|
+
delete registry[key];
|
|
212
|
+
logger$1.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on "${type.name}" which is not in registry)`);
|
|
213
|
+
somethingIsDeleted = true;
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
178
219
|
}
|
|
179
220
|
function scanParams(instance, cb) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
221
|
+
const mate = getMoostMate();
|
|
222
|
+
const params = mate.read(instance)?.params;
|
|
223
|
+
if (params?.length) for (const param of params) {
|
|
224
|
+
if (param.type === undefined || [
|
|
225
|
+
Array,
|
|
226
|
+
String,
|
|
227
|
+
Number,
|
|
228
|
+
Boolean,
|
|
229
|
+
Object
|
|
230
|
+
].includes(param.type)) continue;
|
|
231
|
+
if (cb(param.type)) break;
|
|
232
|
+
}
|
|
193
233
|
}
|
|
194
234
|
function constructorName(i) {
|
|
195
|
-
|
|
235
|
+
return Object.getPrototypeOf(i).constructor.name;
|
|
196
236
|
}
|
|
197
237
|
|
|
198
|
-
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region packages/vite/src/moost-vite.ts
|
|
240
|
+
/** Regex checks */ const REG_HAS_EXPORT_CLASS = /(^\s*@(Injectable|Controller)\()/m;
|
|
199
241
|
const REG_REPLACE_EXPORT_CLASS = /(^\s*@(Injectable|Controller)\()/gm;
|
|
200
242
|
function moostVite(options) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
return '\0virtual:vite-id';
|
|
271
|
-
}
|
|
272
|
-
},
|
|
273
|
-
load(id) {
|
|
274
|
-
if (id === '\0virtual:vite-id') {
|
|
275
|
-
return `
|
|
243
|
+
const isTest = false;
|
|
244
|
+
const isProd = false;
|
|
245
|
+
let moostMiddleware = null;
|
|
246
|
+
const adapters = isTest ? [] : [
|
|
247
|
+
createAdapterDetector("http", (MoostHttp) => {
|
|
248
|
+
MoostHttp.prototype.listen = function(...args) {
|
|
249
|
+
moostMiddleware = this.getServerCb();
|
|
250
|
+
setTimeout(() => {
|
|
251
|
+
args.filter((a) => typeof a === "function").forEach((a) => a());
|
|
252
|
+
}, 1);
|
|
253
|
+
return Promise.resolve();
|
|
254
|
+
};
|
|
255
|
+
}),
|
|
256
|
+
createAdapterDetector("cli"),
|
|
257
|
+
createAdapterDetector("wf")
|
|
258
|
+
];
|
|
259
|
+
/** A logger instance for plugin debug output. */ const logger$1 = isTest ? console : getLogger();
|
|
260
|
+
let reloadRequired = false;
|
|
261
|
+
patchMoostHandlerLogging();
|
|
262
|
+
const pluginConfig = {
|
|
263
|
+
name: PLUGIN_NAME,
|
|
264
|
+
enforce: "pre",
|
|
265
|
+
config(cfg) {
|
|
266
|
+
const entry = cfg.build?.rollupOptions?.input || options.entry;
|
|
267
|
+
const outfile = typeof entry === "string" ? entry.split("/").pop().replace(/\.ts$/, ".js") : undefined;
|
|
268
|
+
return {
|
|
269
|
+
server: {
|
|
270
|
+
port: cfg.server?.port || options.port || 3e3,
|
|
271
|
+
host: cfg.server?.host || options.host
|
|
272
|
+
},
|
|
273
|
+
optimizeDeps: {
|
|
274
|
+
noDiscovery: cfg.optimizeDeps?.noDiscovery === undefined ? true : cfg.optimizeDeps.noDiscovery,
|
|
275
|
+
exclude: cfg.optimizeDeps?.exclude || ["@swc/core"]
|
|
276
|
+
},
|
|
277
|
+
build: {
|
|
278
|
+
target: cfg.build?.target || "node",
|
|
279
|
+
outDir: cfg.build?.outDir || options.outDir || "dist",
|
|
280
|
+
ssr: cfg.build?.ssr ?? true,
|
|
281
|
+
minify: cfg.build?.minify || false,
|
|
282
|
+
rollupOptions: {
|
|
283
|
+
external: isTest ? cfg.build?.rollupOptions?.external : cfg.build?.rollupOptions?.external || (options.externals === false ? [] : getExternals({
|
|
284
|
+
node: Boolean(options.externals === true || options.externals?.node),
|
|
285
|
+
workspace: Boolean(options.externals === true || options.externals?.workspace)
|
|
286
|
+
})),
|
|
287
|
+
input: entry,
|
|
288
|
+
output: {
|
|
289
|
+
format: options.format,
|
|
290
|
+
sourcemap: !!(options.sourcemap ?? true),
|
|
291
|
+
entryFileNames: outfile,
|
|
292
|
+
...cfg.build?.rollupOptions?.output
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
},
|
|
298
|
+
async transform(code, id) {
|
|
299
|
+
if (!id.endsWith(".ts")) return code;
|
|
300
|
+
for (const adapter of adapters) if (!adapter.detected && adapter.regex.test(code)) await adapter.init();
|
|
301
|
+
if (REG_HAS_EXPORT_CLASS.test(code)) {
|
|
302
|
+
code = code.replace(REG_REPLACE_EXPORT_CLASS, "\n@__VITE_ID(import.meta.filename)\n$1");
|
|
303
|
+
code = `import { __VITE_ID } from 'virtual:vite-id'\n\n${code}`;
|
|
304
|
+
}
|
|
305
|
+
return code;
|
|
306
|
+
},
|
|
307
|
+
resolveId(id) {
|
|
308
|
+
if (id === "virtual:vite-id") return "\0virtual:vite-id";
|
|
309
|
+
},
|
|
310
|
+
load(id) {
|
|
311
|
+
if (id === "\0virtual:vite-id") return `
|
|
276
312
|
import { getMoostMate } from "moost";
|
|
277
313
|
const mate = getMoostMate();
|
|
278
314
|
export function __VITE_ID(id) {
|
|
279
315
|
return mate.decorate("__vite_id", id)
|
|
280
316
|
}
|
|
281
317
|
`;
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
318
|
+
},
|
|
319
|
+
async configureServer(server) {
|
|
320
|
+
moostRestartCleanup(adapters, options.onEject);
|
|
321
|
+
await server.ssrLoadModule(options.entry);
|
|
322
|
+
server.middlewares.use(async (req, res, next) => {
|
|
323
|
+
if (reloadRequired) {
|
|
324
|
+
reloadRequired = false;
|
|
325
|
+
console.log();
|
|
326
|
+
logger$1.debug("🚀 Reloading Moost App...");
|
|
327
|
+
console.log();
|
|
328
|
+
await server.ssrLoadModule(options.entry);
|
|
329
|
+
await new Promise((resolve) => setTimeout(resolve, 1));
|
|
330
|
+
}
|
|
331
|
+
if (moostMiddleware) return moostMiddleware(req, res);
|
|
332
|
+
next();
|
|
333
|
+
});
|
|
334
|
+
},
|
|
335
|
+
hotUpdate({ file }) {
|
|
336
|
+
if (file.endsWith(".ts")) {
|
|
337
|
+
const modules = this.environment.moduleGraph.getModulesByFile(file);
|
|
338
|
+
if (modules) {
|
|
339
|
+
logger$1.debug(`🔃 Hot update: ${file}`);
|
|
340
|
+
const cleanupInstances = new Set();
|
|
341
|
+
for (const mod of modules) {
|
|
342
|
+
const allImporters = gatherAllImporters(mod);
|
|
343
|
+
for (const impModule of allImporters) if (impModule.id) cleanupInstances.add(impModule.id);
|
|
344
|
+
this.environment.moduleGraph.invalidateModule(mod);
|
|
345
|
+
}
|
|
346
|
+
moostMiddleware = null;
|
|
347
|
+
moostRestartCleanup(adapters, options.onEject, cleanupInstances);
|
|
348
|
+
reloadRequired = true;
|
|
349
|
+
}
|
|
350
|
+
return [];
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
if (isProd || isTest) {
|
|
355
|
+
delete pluginConfig.configureServer;
|
|
356
|
+
delete pluginConfig.resolveId;
|
|
357
|
+
delete pluginConfig.load;
|
|
358
|
+
delete pluginConfig.transform;
|
|
359
|
+
delete pluginConfig.hotUpdate;
|
|
360
|
+
}
|
|
361
|
+
return pluginConfig;
|
|
325
362
|
}
|
|
326
363
|
|
|
327
|
-
|
|
364
|
+
//#endregion
|
|
365
|
+
export { moostVite };
|