vite-plugin-phpsandbox 0.1.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/README.md +70 -0
- package/dist/index.cjs +174 -0
- package/dist/index.d.cts +35 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +138 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# vite-plugin-phpsandbox
|
|
2
|
+
|
|
3
|
+
`vite-plugin-phpsandbox` makes Vite's dev server and HMR work reliably behind PHP sandbox and notebook proxy environments.
|
|
4
|
+
|
|
5
|
+
It is a Vite-only plugin because it mutates Vite's `server` config during dev, including `server.hmr`, `server.allowedHosts`, and a stable HMR server binding.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install -D vite-plugin-phpsandbox
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { defineConfig } from "vite";
|
|
17
|
+
import phpSandboxPlugin from "vite-plugin-phpsandbox";
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
plugins: [phpSandboxPlugin()],
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The plugin only applies when `PHPSANDBOX_TYPE` is set.
|
|
25
|
+
|
|
26
|
+
## Options
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
type PhpSandboxOptions = {
|
|
30
|
+
allowedHosts?: true | string[];
|
|
31
|
+
enabled?: boolean;
|
|
32
|
+
hmrPort?: number;
|
|
33
|
+
publicHost?: string;
|
|
34
|
+
publicClientPort?: number;
|
|
35
|
+
};
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Environment Variables
|
|
39
|
+
|
|
40
|
+
The plugin reads these environment variables by default:
|
|
41
|
+
|
|
42
|
+
- `SUBDOMAIN`
|
|
43
|
+
- `NOTEBOOK_HOST`
|
|
44
|
+
- `PHPSANDBOX_TYPE`
|
|
45
|
+
|
|
46
|
+
## Behavior
|
|
47
|
+
|
|
48
|
+
- Does nothing unless `PHPSANDBOX_TYPE` is set.
|
|
49
|
+
- Resolves the HMR port from the `hmrPort` option only.
|
|
50
|
+
- Resolves the public host from `publicHost`, or derives `${SUBDOMAIN}-${hmrPort}.${NOTEBOOK_HOST}`.
|
|
51
|
+
- Resolves the public client port from the `publicClientPort` option only.
|
|
52
|
+
- Defaults `server.host` to `true` only when the project has not set `server.host`.
|
|
53
|
+
- Merges the derived public host into `server.allowedHosts` by default instead of disabling host checks globally.
|
|
54
|
+
- Creates a stable local HMR server on `0.0.0.0:${hmrPort}` unless `PHPSANDBOX_TYPE=laravel`.
|
|
55
|
+
- Advertises HMR over `wss://${publicHost}:${publicClientPort}` when a public host is available.
|
|
56
|
+
- Preserves `server.hmr = false` if the consuming project disables HMR explicitly.
|
|
57
|
+
|
|
58
|
+
## Laravel Mode
|
|
59
|
+
|
|
60
|
+
When `PHPSANDBOX_TYPE=laravel`, the plugin does not create a standalone HMR server. It sets `server.port` to the resolved HMR port and configures the advertised HMR endpoint instead.
|
|
61
|
+
|
|
62
|
+
## API
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import phpSandboxPlugin, {
|
|
66
|
+
phpSandbox,
|
|
67
|
+
type PhpSandboxEnv,
|
|
68
|
+
type PhpSandboxOptions,
|
|
69
|
+
} from "vite-plugin-phpsandbox";
|
|
70
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
default: () => index_default,
|
|
34
|
+
phpSandbox: () => phpSandbox,
|
|
35
|
+
phpSandboxPlugin: () => phpSandboxPlugin
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
var import_node_http = __toESM(require("http"), 1);
|
|
39
|
+
var DEFAULT_HMR_PORT = 5173;
|
|
40
|
+
var DEFAULT_PUBLIC_CLIENT_PORT = 443;
|
|
41
|
+
var GLOBAL_KEY = "__phpSandboxViteState__";
|
|
42
|
+
function getGlobalState() {
|
|
43
|
+
const g = globalThis;
|
|
44
|
+
const existing = g[GLOBAL_KEY];
|
|
45
|
+
const refs = existing?.refs instanceof Map ? existing.refs : /* @__PURE__ */ new Map();
|
|
46
|
+
const servers = existing?.servers instanceof Map ? existing.servers : /* @__PURE__ */ new Map();
|
|
47
|
+
const normalized = { refs, servers };
|
|
48
|
+
g[GLOBAL_KEY] = normalized;
|
|
49
|
+
return normalized;
|
|
50
|
+
}
|
|
51
|
+
function normalizeSandboxType(value) {
|
|
52
|
+
const normalized = value?.trim().toLowerCase();
|
|
53
|
+
return normalized ? normalized : void 0;
|
|
54
|
+
}
|
|
55
|
+
function resolveHmrPort(options) {
|
|
56
|
+
return options.hmrPort ?? DEFAULT_HMR_PORT;
|
|
57
|
+
}
|
|
58
|
+
function resolvePublicClientPort(options) {
|
|
59
|
+
return options.publicClientPort ?? DEFAULT_PUBLIC_CLIENT_PORT;
|
|
60
|
+
}
|
|
61
|
+
function resolvePublicHost(options, env, hmrPort) {
|
|
62
|
+
return options.publicHost ?? (env.SUBDOMAIN && env.NOTEBOOK_HOST ? `${env.SUBDOMAIN}-${hmrPort}.${env.NOTEBOOK_HOST}` : void 0);
|
|
63
|
+
}
|
|
64
|
+
function isRecord(value) {
|
|
65
|
+
return typeof value === "object" && value !== null;
|
|
66
|
+
}
|
|
67
|
+
function acquireServer(state, port) {
|
|
68
|
+
const existing = state.servers.get(port);
|
|
69
|
+
if (existing) {
|
|
70
|
+
state.refs.set(port, (state.refs.get(port) ?? 0) + 1);
|
|
71
|
+
return existing;
|
|
72
|
+
}
|
|
73
|
+
const server = import_node_http.default.createServer();
|
|
74
|
+
server.on("error", (error) => {
|
|
75
|
+
if (error.code === "EADDRINUSE") return;
|
|
76
|
+
console.error("[vite-plugin-phpsandbox] HMR server error:", error);
|
|
77
|
+
});
|
|
78
|
+
server.listen(port, "0.0.0.0");
|
|
79
|
+
state.servers.set(port, server);
|
|
80
|
+
state.refs.set(port, 1);
|
|
81
|
+
return server;
|
|
82
|
+
}
|
|
83
|
+
function releaseServer(state, port, server) {
|
|
84
|
+
const nextRefs = (state.refs.get(port) ?? 1) - 1;
|
|
85
|
+
if (nextRefs > 0) {
|
|
86
|
+
state.refs.set(port, nextRefs);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
state.refs.delete(port);
|
|
90
|
+
if (state.servers.get(port) !== server) return;
|
|
91
|
+
state.servers.delete(port);
|
|
92
|
+
if (server.listening) {
|
|
93
|
+
server.close();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function resolveAllowedHosts(existingAllowedHosts, optionAllowedHosts, publicHost) {
|
|
97
|
+
if (optionAllowedHosts === true || existingAllowedHosts === true) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
const merged = new Set(Array.isArray(existingAllowedHosts) ? existingAllowedHosts : []);
|
|
101
|
+
if (Array.isArray(optionAllowedHosts)) {
|
|
102
|
+
for (const host of optionAllowedHosts) {
|
|
103
|
+
merged.add(host);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (publicHost) {
|
|
107
|
+
merged.add(publicHost);
|
|
108
|
+
}
|
|
109
|
+
return merged.size > 0 ? Array.from(merged) : existingAllowedHosts;
|
|
110
|
+
}
|
|
111
|
+
function phpSandboxPlugin(options = {}, env = process.env) {
|
|
112
|
+
let managedHmrPort;
|
|
113
|
+
let managedHmrServer;
|
|
114
|
+
return {
|
|
115
|
+
name: "vite-plugin-phpsandbox",
|
|
116
|
+
apply: "serve",
|
|
117
|
+
enforce: "post",
|
|
118
|
+
config(userConfig) {
|
|
119
|
+
if (options.enabled === false) return {};
|
|
120
|
+
const sandboxType = normalizeSandboxType(env.PHPSANDBOX_TYPE);
|
|
121
|
+
if (!sandboxType) return {};
|
|
122
|
+
const hmrPort = resolveHmrPort(options);
|
|
123
|
+
const publicClientPort = resolvePublicClientPort(options);
|
|
124
|
+
const publicHost = resolvePublicHost(options, env, hmrPort);
|
|
125
|
+
const isLaravel = sandboxType === "laravel";
|
|
126
|
+
const existingServer = userConfig.server ?? {};
|
|
127
|
+
const existingHmr = isRecord(existingServer.hmr) ? existingServer.hmr : void 0;
|
|
128
|
+
const hmrDisabled = existingServer.hmr === false;
|
|
129
|
+
const allowedHosts = resolveAllowedHosts(
|
|
130
|
+
existingServer.allowedHosts,
|
|
131
|
+
options.allowedHosts,
|
|
132
|
+
publicHost
|
|
133
|
+
);
|
|
134
|
+
const hmrServer = isLaravel || hmrDisabled ? void 0 : acquireServer(getGlobalState(), hmrPort);
|
|
135
|
+
managedHmrPort = hmrServer ? hmrPort : void 0;
|
|
136
|
+
managedHmrServer = hmrServer;
|
|
137
|
+
return {
|
|
138
|
+
server: {
|
|
139
|
+
...existingServer,
|
|
140
|
+
host: existingServer.host ?? true,
|
|
141
|
+
...isLaravel ? { port: hmrPort } : {},
|
|
142
|
+
...hmrDisabled ? { hmr: false } : {
|
|
143
|
+
hmr: {
|
|
144
|
+
...existingHmr,
|
|
145
|
+
port: hmrPort,
|
|
146
|
+
...hmrServer ? { server: hmrServer } : {},
|
|
147
|
+
...publicHost ? {
|
|
148
|
+
protocol: "wss",
|
|
149
|
+
host: publicHost,
|
|
150
|
+
clientPort: publicClientPort
|
|
151
|
+
} : {}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
allowedHosts
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
configureServer(server) {
|
|
159
|
+
if (!managedHmrServer || managedHmrPort === void 0) return;
|
|
160
|
+
const hmrPort = managedHmrPort;
|
|
161
|
+
const hmrServer = managedHmrServer;
|
|
162
|
+
server.httpServer?.once("close", () => {
|
|
163
|
+
releaseServer(getGlobalState(), hmrPort, hmrServer);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
var phpSandbox = phpSandboxPlugin;
|
|
169
|
+
var index_default = phpSandboxPlugin;
|
|
170
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
171
|
+
0 && (module.exports = {
|
|
172
|
+
phpSandbox,
|
|
173
|
+
phpSandboxPlugin
|
|
174
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
type PhpSandboxEnv = {
|
|
4
|
+
SUBDOMAIN?: string;
|
|
5
|
+
NOTEBOOK_HOST?: string;
|
|
6
|
+
PHPSANDBOX_TYPE?: string;
|
|
7
|
+
};
|
|
8
|
+
type PhpSandboxOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* Defaults to merging the derived public host into `server.allowedHosts`.
|
|
11
|
+
* - true: disable host checks entirely
|
|
12
|
+
* - array: merge with existing allowedHosts
|
|
13
|
+
*/
|
|
14
|
+
allowedHosts?: true | string[];
|
|
15
|
+
/**
|
|
16
|
+
* Explicitly disable the plugin.
|
|
17
|
+
*/
|
|
18
|
+
enabled?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Defaults to 5173.
|
|
21
|
+
*/
|
|
22
|
+
hmrPort?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Defaults to `${SUBDOMAIN}-${port}.${NOTEBOOK_HOST}` when env values exist.
|
|
25
|
+
*/
|
|
26
|
+
publicHost?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Defaults to 443.
|
|
29
|
+
*/
|
|
30
|
+
publicClientPort?: number;
|
|
31
|
+
};
|
|
32
|
+
declare function phpSandboxPlugin(options?: PhpSandboxOptions, env?: PhpSandboxEnv): Plugin;
|
|
33
|
+
declare const phpSandbox: typeof phpSandboxPlugin;
|
|
34
|
+
|
|
35
|
+
export { type PhpSandboxEnv, type PhpSandboxOptions, phpSandboxPlugin as default, phpSandbox, phpSandboxPlugin };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
type PhpSandboxEnv = {
|
|
4
|
+
SUBDOMAIN?: string;
|
|
5
|
+
NOTEBOOK_HOST?: string;
|
|
6
|
+
PHPSANDBOX_TYPE?: string;
|
|
7
|
+
};
|
|
8
|
+
type PhpSandboxOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* Defaults to merging the derived public host into `server.allowedHosts`.
|
|
11
|
+
* - true: disable host checks entirely
|
|
12
|
+
* - array: merge with existing allowedHosts
|
|
13
|
+
*/
|
|
14
|
+
allowedHosts?: true | string[];
|
|
15
|
+
/**
|
|
16
|
+
* Explicitly disable the plugin.
|
|
17
|
+
*/
|
|
18
|
+
enabled?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Defaults to 5173.
|
|
21
|
+
*/
|
|
22
|
+
hmrPort?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Defaults to `${SUBDOMAIN}-${port}.${NOTEBOOK_HOST}` when env values exist.
|
|
25
|
+
*/
|
|
26
|
+
publicHost?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Defaults to 443.
|
|
29
|
+
*/
|
|
30
|
+
publicClientPort?: number;
|
|
31
|
+
};
|
|
32
|
+
declare function phpSandboxPlugin(options?: PhpSandboxOptions, env?: PhpSandboxEnv): Plugin;
|
|
33
|
+
declare const phpSandbox: typeof phpSandboxPlugin;
|
|
34
|
+
|
|
35
|
+
export { type PhpSandboxEnv, type PhpSandboxOptions, phpSandboxPlugin as default, phpSandbox, phpSandboxPlugin };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import http from "http";
|
|
3
|
+
var DEFAULT_HMR_PORT = 5173;
|
|
4
|
+
var DEFAULT_PUBLIC_CLIENT_PORT = 443;
|
|
5
|
+
var GLOBAL_KEY = "__phpSandboxViteState__";
|
|
6
|
+
function getGlobalState() {
|
|
7
|
+
const g = globalThis;
|
|
8
|
+
const existing = g[GLOBAL_KEY];
|
|
9
|
+
const refs = existing?.refs instanceof Map ? existing.refs : /* @__PURE__ */ new Map();
|
|
10
|
+
const servers = existing?.servers instanceof Map ? existing.servers : /* @__PURE__ */ new Map();
|
|
11
|
+
const normalized = { refs, servers };
|
|
12
|
+
g[GLOBAL_KEY] = normalized;
|
|
13
|
+
return normalized;
|
|
14
|
+
}
|
|
15
|
+
function normalizeSandboxType(value) {
|
|
16
|
+
const normalized = value?.trim().toLowerCase();
|
|
17
|
+
return normalized ? normalized : void 0;
|
|
18
|
+
}
|
|
19
|
+
function resolveHmrPort(options) {
|
|
20
|
+
return options.hmrPort ?? DEFAULT_HMR_PORT;
|
|
21
|
+
}
|
|
22
|
+
function resolvePublicClientPort(options) {
|
|
23
|
+
return options.publicClientPort ?? DEFAULT_PUBLIC_CLIENT_PORT;
|
|
24
|
+
}
|
|
25
|
+
function resolvePublicHost(options, env, hmrPort) {
|
|
26
|
+
return options.publicHost ?? (env.SUBDOMAIN && env.NOTEBOOK_HOST ? `${env.SUBDOMAIN}-${hmrPort}.${env.NOTEBOOK_HOST}` : void 0);
|
|
27
|
+
}
|
|
28
|
+
function isRecord(value) {
|
|
29
|
+
return typeof value === "object" && value !== null;
|
|
30
|
+
}
|
|
31
|
+
function acquireServer(state, port) {
|
|
32
|
+
const existing = state.servers.get(port);
|
|
33
|
+
if (existing) {
|
|
34
|
+
state.refs.set(port, (state.refs.get(port) ?? 0) + 1);
|
|
35
|
+
return existing;
|
|
36
|
+
}
|
|
37
|
+
const server = http.createServer();
|
|
38
|
+
server.on("error", (error) => {
|
|
39
|
+
if (error.code === "EADDRINUSE") return;
|
|
40
|
+
console.error("[vite-plugin-phpsandbox] HMR server error:", error);
|
|
41
|
+
});
|
|
42
|
+
server.listen(port, "0.0.0.0");
|
|
43
|
+
state.servers.set(port, server);
|
|
44
|
+
state.refs.set(port, 1);
|
|
45
|
+
return server;
|
|
46
|
+
}
|
|
47
|
+
function releaseServer(state, port, server) {
|
|
48
|
+
const nextRefs = (state.refs.get(port) ?? 1) - 1;
|
|
49
|
+
if (nextRefs > 0) {
|
|
50
|
+
state.refs.set(port, nextRefs);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
state.refs.delete(port);
|
|
54
|
+
if (state.servers.get(port) !== server) return;
|
|
55
|
+
state.servers.delete(port);
|
|
56
|
+
if (server.listening) {
|
|
57
|
+
server.close();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function resolveAllowedHosts(existingAllowedHosts, optionAllowedHosts, publicHost) {
|
|
61
|
+
if (optionAllowedHosts === true || existingAllowedHosts === true) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
const merged = new Set(Array.isArray(existingAllowedHosts) ? existingAllowedHosts : []);
|
|
65
|
+
if (Array.isArray(optionAllowedHosts)) {
|
|
66
|
+
for (const host of optionAllowedHosts) {
|
|
67
|
+
merged.add(host);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (publicHost) {
|
|
71
|
+
merged.add(publicHost);
|
|
72
|
+
}
|
|
73
|
+
return merged.size > 0 ? Array.from(merged) : existingAllowedHosts;
|
|
74
|
+
}
|
|
75
|
+
function phpSandboxPlugin(options = {}, env = process.env) {
|
|
76
|
+
let managedHmrPort;
|
|
77
|
+
let managedHmrServer;
|
|
78
|
+
return {
|
|
79
|
+
name: "vite-plugin-phpsandbox",
|
|
80
|
+
apply: "serve",
|
|
81
|
+
enforce: "post",
|
|
82
|
+
config(userConfig) {
|
|
83
|
+
if (options.enabled === false) return {};
|
|
84
|
+
const sandboxType = normalizeSandboxType(env.PHPSANDBOX_TYPE);
|
|
85
|
+
if (!sandboxType) return {};
|
|
86
|
+
const hmrPort = resolveHmrPort(options);
|
|
87
|
+
const publicClientPort = resolvePublicClientPort(options);
|
|
88
|
+
const publicHost = resolvePublicHost(options, env, hmrPort);
|
|
89
|
+
const isLaravel = sandboxType === "laravel";
|
|
90
|
+
const existingServer = userConfig.server ?? {};
|
|
91
|
+
const existingHmr = isRecord(existingServer.hmr) ? existingServer.hmr : void 0;
|
|
92
|
+
const hmrDisabled = existingServer.hmr === false;
|
|
93
|
+
const allowedHosts = resolveAllowedHosts(
|
|
94
|
+
existingServer.allowedHosts,
|
|
95
|
+
options.allowedHosts,
|
|
96
|
+
publicHost
|
|
97
|
+
);
|
|
98
|
+
const hmrServer = isLaravel || hmrDisabled ? void 0 : acquireServer(getGlobalState(), hmrPort);
|
|
99
|
+
managedHmrPort = hmrServer ? hmrPort : void 0;
|
|
100
|
+
managedHmrServer = hmrServer;
|
|
101
|
+
return {
|
|
102
|
+
server: {
|
|
103
|
+
...existingServer,
|
|
104
|
+
host: existingServer.host ?? true,
|
|
105
|
+
...isLaravel ? { port: hmrPort } : {},
|
|
106
|
+
...hmrDisabled ? { hmr: false } : {
|
|
107
|
+
hmr: {
|
|
108
|
+
...existingHmr,
|
|
109
|
+
port: hmrPort,
|
|
110
|
+
...hmrServer ? { server: hmrServer } : {},
|
|
111
|
+
...publicHost ? {
|
|
112
|
+
protocol: "wss",
|
|
113
|
+
host: publicHost,
|
|
114
|
+
clientPort: publicClientPort
|
|
115
|
+
} : {}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
allowedHosts
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
configureServer(server) {
|
|
123
|
+
if (!managedHmrServer || managedHmrPort === void 0) return;
|
|
124
|
+
const hmrPort = managedHmrPort;
|
|
125
|
+
const hmrServer = managedHmrServer;
|
|
126
|
+
server.httpServer?.once("close", () => {
|
|
127
|
+
releaseServer(getGlobalState(), hmrPort, hmrServer);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
var phpSandbox = phpSandboxPlugin;
|
|
133
|
+
var index_default = phpSandboxPlugin;
|
|
134
|
+
export {
|
|
135
|
+
index_default as default,
|
|
136
|
+
phpSandbox,
|
|
137
|
+
phpSandboxPlugin
|
|
138
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vite-plugin-phpsandbox",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vite plugin for PHP sandbox environments that need stable HMR over public proxy hosts.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"keywords": [
|
|
25
|
+
"vite-plugin",
|
|
26
|
+
"phpsandbox",
|
|
27
|
+
"hmr",
|
|
28
|
+
"sandbox"
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
38
|
+
"check": "tsc --noEmit",
|
|
39
|
+
"release:check": "npm run check && npm run build && npm pack --dry-run",
|
|
40
|
+
"release": "npm run release:check && npm publish",
|
|
41
|
+
"prepublishOnly": "npm run build && npm run check"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^24.0.0",
|
|
45
|
+
"tsup": "^8.0.0",
|
|
46
|
+
"typescript": "^5.0.0",
|
|
47
|
+
"vite": "^8.0.0"
|
|
48
|
+
}
|
|
49
|
+
}
|