vite-plugin-phpsandbox 0.2.0 → 0.3.0
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 +16 -7
- package/dist/index.js +16 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -200,6 +200,7 @@ function phpSandboxPlugin() {
|
|
|
200
200
|
let managedHmrServer;
|
|
201
201
|
let releaseManagedHmrServer;
|
|
202
202
|
let sandboxType;
|
|
203
|
+
let needsHmrServer = false;
|
|
203
204
|
let startupLog;
|
|
204
205
|
function setManagedHmrServer(server) {
|
|
205
206
|
if (managedHmrServer === server) return;
|
|
@@ -224,26 +225,25 @@ function phpSandboxPlugin() {
|
|
|
224
225
|
name: "vite-plugin-phpsandbox",
|
|
225
226
|
apply: "serve",
|
|
226
227
|
enforce: "post",
|
|
227
|
-
|
|
228
|
+
config(userConfig) {
|
|
228
229
|
const env = process.env;
|
|
229
230
|
sandboxType = normalizeSandboxType(env.PHPSANDBOX_TYPE);
|
|
230
231
|
if (!sandboxType) {
|
|
231
|
-
|
|
232
|
+
needsHmrServer = false;
|
|
232
233
|
startupLog = void 0;
|
|
233
234
|
return {};
|
|
234
235
|
}
|
|
235
236
|
const isLaravel = sandboxType === "laravel";
|
|
236
237
|
const publicHost = resolvePublicHost(env);
|
|
237
238
|
const existingServer = userConfig.server ?? {};
|
|
238
|
-
|
|
239
|
-
setManagedHmrServer(hmrServer);
|
|
239
|
+
needsHmrServer = shouldCreateHmrServer(existingServer, isLaravel);
|
|
240
240
|
return {
|
|
241
241
|
server: resolveServerConfig(
|
|
242
242
|
existingServer,
|
|
243
243
|
env,
|
|
244
244
|
isLaravel,
|
|
245
245
|
publicHost,
|
|
246
|
-
|
|
246
|
+
void 0
|
|
247
247
|
)
|
|
248
248
|
};
|
|
249
249
|
},
|
|
@@ -252,13 +252,22 @@ function phpSandboxPlugin() {
|
|
|
252
252
|
const nextStartupLog = formatStartupLog(
|
|
253
253
|
sandboxType,
|
|
254
254
|
config.server,
|
|
255
|
-
|
|
255
|
+
needsHmrServer
|
|
256
256
|
);
|
|
257
257
|
if (nextStartupLog === startupLog) return;
|
|
258
258
|
startupLog = nextStartupLog;
|
|
259
259
|
console.info(nextStartupLog);
|
|
260
260
|
},
|
|
261
|
-
configureServer(server) {
|
|
261
|
+
async configureServer(server) {
|
|
262
|
+
if (!sandboxType) return;
|
|
263
|
+
if (needsHmrServer) {
|
|
264
|
+
const hmrServer = managedHmrServer ?? await acquireServer(getGlobalState(), HMR_PORT);
|
|
265
|
+
setManagedHmrServer(hmrServer);
|
|
266
|
+
const hmrConfig = server.config.server.hmr;
|
|
267
|
+
if (isRecord(hmrConfig)) {
|
|
268
|
+
hmrConfig.server = hmrServer;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
262
271
|
const release = releaseManagedHmrServer;
|
|
263
272
|
if (!release) return;
|
|
264
273
|
server.httpServer?.once("close", release);
|
package/dist/index.js
CHANGED
|
@@ -164,6 +164,7 @@ function phpSandboxPlugin() {
|
|
|
164
164
|
let managedHmrServer;
|
|
165
165
|
let releaseManagedHmrServer;
|
|
166
166
|
let sandboxType;
|
|
167
|
+
let needsHmrServer = false;
|
|
167
168
|
let startupLog;
|
|
168
169
|
function setManagedHmrServer(server) {
|
|
169
170
|
if (managedHmrServer === server) return;
|
|
@@ -188,26 +189,25 @@ function phpSandboxPlugin() {
|
|
|
188
189
|
name: "vite-plugin-phpsandbox",
|
|
189
190
|
apply: "serve",
|
|
190
191
|
enforce: "post",
|
|
191
|
-
|
|
192
|
+
config(userConfig) {
|
|
192
193
|
const env = process.env;
|
|
193
194
|
sandboxType = normalizeSandboxType(env.PHPSANDBOX_TYPE);
|
|
194
195
|
if (!sandboxType) {
|
|
195
|
-
|
|
196
|
+
needsHmrServer = false;
|
|
196
197
|
startupLog = void 0;
|
|
197
198
|
return {};
|
|
198
199
|
}
|
|
199
200
|
const isLaravel = sandboxType === "laravel";
|
|
200
201
|
const publicHost = resolvePublicHost(env);
|
|
201
202
|
const existingServer = userConfig.server ?? {};
|
|
202
|
-
|
|
203
|
-
setManagedHmrServer(hmrServer);
|
|
203
|
+
needsHmrServer = shouldCreateHmrServer(existingServer, isLaravel);
|
|
204
204
|
return {
|
|
205
205
|
server: resolveServerConfig(
|
|
206
206
|
existingServer,
|
|
207
207
|
env,
|
|
208
208
|
isLaravel,
|
|
209
209
|
publicHost,
|
|
210
|
-
|
|
210
|
+
void 0
|
|
211
211
|
)
|
|
212
212
|
};
|
|
213
213
|
},
|
|
@@ -216,13 +216,22 @@ function phpSandboxPlugin() {
|
|
|
216
216
|
const nextStartupLog = formatStartupLog(
|
|
217
217
|
sandboxType,
|
|
218
218
|
config.server,
|
|
219
|
-
|
|
219
|
+
needsHmrServer
|
|
220
220
|
);
|
|
221
221
|
if (nextStartupLog === startupLog) return;
|
|
222
222
|
startupLog = nextStartupLog;
|
|
223
223
|
console.info(nextStartupLog);
|
|
224
224
|
},
|
|
225
|
-
configureServer(server) {
|
|
225
|
+
async configureServer(server) {
|
|
226
|
+
if (!sandboxType) return;
|
|
227
|
+
if (needsHmrServer) {
|
|
228
|
+
const hmrServer = managedHmrServer ?? await acquireServer(getGlobalState(), HMR_PORT);
|
|
229
|
+
setManagedHmrServer(hmrServer);
|
|
230
|
+
const hmrConfig = server.config.server.hmr;
|
|
231
|
+
if (isRecord(hmrConfig)) {
|
|
232
|
+
hmrConfig.server = hmrServer;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
226
235
|
const release = releaseManagedHmrServer;
|
|
227
236
|
if (!release) return;
|
|
228
237
|
server.httpServer?.once("close", release);
|