vite-plugin-php 1.0.62 → 1.0.651
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 +1 -0
- package/dist/index.cjs +80 -26
- package/dist/index.mjs +80 -26
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ Check out the [starter repo](https://github.com/nititech/php-vite-starter) for a
|
|
|
22
22
|
|
|
23
23
|
| Version | Feature |
|
|
24
24
|
| ------- | ----------------------------------------------------------------------------------------------------------- |
|
|
25
|
+
| 1.0.65 | Fixed request body forwarding for all request methods |
|
|
25
26
|
| 1.0.62 | HTML transforms are now only applied to HTML contents during dev |
|
|
26
27
|
| 1.0.60 | Fixed inline module transpiling -> PHP code is being properly inserted into transpiled inline module chunks |
|
|
27
28
|
| 1.0.55 | Fixed pure PHP file processing |
|
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,7 @@ const require$$0$2 = require('fs');
|
|
|
4
4
|
const require$$0$1 = require('path');
|
|
5
5
|
const vite = require('vite');
|
|
6
6
|
const require$$0 = require('tty');
|
|
7
|
-
const http = require('http');
|
|
7
|
+
const http = require('node:http');
|
|
8
8
|
const child_process = require('child_process');
|
|
9
9
|
const url = require('url');
|
|
10
10
|
const require$$0$3 = require('os');
|
|
@@ -83,6 +83,7 @@ let createColors = (enabled = isColorSupported) => {
|
|
|
83
83
|
inverse: init("\x1b[7m", "\x1b[27m"),
|
|
84
84
|
hidden: init("\x1b[8m", "\x1b[28m"),
|
|
85
85
|
strikethrough: init("\x1b[9m", "\x1b[29m"),
|
|
86
|
+
|
|
86
87
|
black: init("\x1b[30m", "\x1b[39m"),
|
|
87
88
|
red: init("\x1b[31m", "\x1b[39m"),
|
|
88
89
|
green: init("\x1b[32m", "\x1b[39m"),
|
|
@@ -92,6 +93,7 @@ let createColors = (enabled = isColorSupported) => {
|
|
|
92
93
|
cyan: init("\x1b[36m", "\x1b[39m"),
|
|
93
94
|
white: init("\x1b[37m", "\x1b[39m"),
|
|
94
95
|
gray: init("\x1b[90m", "\x1b[39m"),
|
|
96
|
+
|
|
95
97
|
bgBlack: init("\x1b[40m", "\x1b[49m"),
|
|
96
98
|
bgRed: init("\x1b[41m", "\x1b[49m"),
|
|
97
99
|
bgGreen: init("\x1b[42m", "\x1b[49m"),
|
|
@@ -100,6 +102,24 @@ let createColors = (enabled = isColorSupported) => {
|
|
|
100
102
|
bgMagenta: init("\x1b[45m", "\x1b[49m"),
|
|
101
103
|
bgCyan: init("\x1b[46m", "\x1b[49m"),
|
|
102
104
|
bgWhite: init("\x1b[47m", "\x1b[49m"),
|
|
105
|
+
|
|
106
|
+
blackBright: init("\x1b[90m", "\x1b[39m"),
|
|
107
|
+
redBright: init("\x1b[91m", "\x1b[39m"),
|
|
108
|
+
greenBright: init("\x1b[92m", "\x1b[39m"),
|
|
109
|
+
yellowBright: init("\x1b[93m", "\x1b[39m"),
|
|
110
|
+
blueBright: init("\x1b[94m", "\x1b[39m"),
|
|
111
|
+
magentaBright: init("\x1b[95m", "\x1b[39m"),
|
|
112
|
+
cyanBright: init("\x1b[96m", "\x1b[39m"),
|
|
113
|
+
whiteBright: init("\x1b[97m", "\x1b[39m"),
|
|
114
|
+
|
|
115
|
+
bgBlackBright: init("\x1b[100m","\x1b[49m"),
|
|
116
|
+
bgRedBright: init("\x1b[101m","\x1b[49m"),
|
|
117
|
+
bgGreenBright: init("\x1b[102m","\x1b[49m"),
|
|
118
|
+
bgYellowBright: init("\x1b[103m","\x1b[49m"),
|
|
119
|
+
bgBlueBright: init("\x1b[104m","\x1b[49m"),
|
|
120
|
+
bgMagentaBright: init("\x1b[105m","\x1b[49m"),
|
|
121
|
+
bgCyanBright: init("\x1b[106m","\x1b[49m"),
|
|
122
|
+
bgWhiteBright: init("\x1b[107m","\x1b[49m"),
|
|
103
123
|
}
|
|
104
124
|
};
|
|
105
125
|
|
|
@@ -7065,9 +7085,18 @@ function usePHP(cfg = {}) {
|
|
|
7065
7085
|
phpServer.start(viteServer?.config.root);
|
|
7066
7086
|
server.middlewares.use(async (req, res, next) => {
|
|
7067
7087
|
try {
|
|
7068
|
-
if (req.url && ![
|
|
7069
|
-
|
|
7070
|
-
|
|
7088
|
+
if (req.url && ![
|
|
7089
|
+
"/@vite",
|
|
7090
|
+
"/@fs",
|
|
7091
|
+
"/@id/__x00__",
|
|
7092
|
+
"/node_modules"
|
|
7093
|
+
].some((path) => req.url.startsWith(path))) {
|
|
7094
|
+
req.on("error", (error) => {
|
|
7095
|
+
throw error;
|
|
7096
|
+
});
|
|
7097
|
+
res.on("error", (error) => {
|
|
7098
|
+
throw error;
|
|
7099
|
+
});
|
|
7071
7100
|
const url = new URL(req.url, "http://localhost");
|
|
7072
7101
|
if (config?.server.port) {
|
|
7073
7102
|
url.port = config.server.port.toString();
|
|
@@ -7098,31 +7127,56 @@ function usePHP(cfg = {}) {
|
|
|
7098
7127
|
PHP_SELF: "/" + entry2
|
|
7099
7128
|
}).toString()
|
|
7100
7129
|
);
|
|
7101
|
-
const
|
|
7130
|
+
const body = await new Promise(
|
|
7131
|
+
(resolve2, reject) => {
|
|
7132
|
+
let data = [];
|
|
7133
|
+
req.on("data", (chunk) => {
|
|
7134
|
+
data.push(chunk);
|
|
7135
|
+
}).on("end", () => {
|
|
7136
|
+
resolve2(Buffer.concat(data));
|
|
7137
|
+
});
|
|
7138
|
+
}
|
|
7139
|
+
);
|
|
7140
|
+
const phpResult = await new Promise(async (resolve2, reject) => {
|
|
7102
7141
|
const chunks = [];
|
|
7103
|
-
|
|
7142
|
+
let statusCode;
|
|
7143
|
+
let incomingHeaders = {};
|
|
7144
|
+
const request = http__default.request(
|
|
7104
7145
|
url.toString(),
|
|
7105
7146
|
{
|
|
7106
7147
|
method: req.method,
|
|
7107
|
-
headers:
|
|
7148
|
+
headers: {
|
|
7149
|
+
...req.headers,
|
|
7150
|
+
"content-length": Buffer.byteLength(
|
|
7151
|
+
body
|
|
7152
|
+
)
|
|
7153
|
+
}
|
|
7108
7154
|
},
|
|
7109
7155
|
(msg) => {
|
|
7110
|
-
msg.
|
|
7111
|
-
|
|
7112
|
-
|
|
7113
|
-
|
|
7114
|
-
msg.on("end", () => {
|
|
7115
|
-
const content = Buffer.concat(
|
|
7116
|
-
chunks
|
|
7117
|
-
).toString("utf8");
|
|
7118
|
-
resolve2({
|
|
7119
|
-
statusCode: msg.statusCode,
|
|
7120
|
-
headers: msg.headers,
|
|
7121
|
-
content
|
|
7122
|
-
});
|
|
7156
|
+
statusCode = msg.statusCode;
|
|
7157
|
+
incomingHeaders = msg.headers;
|
|
7158
|
+
msg.on("data", (data) => {
|
|
7159
|
+
chunks.push(data);
|
|
7123
7160
|
});
|
|
7124
7161
|
}
|
|
7125
|
-
).on("error",
|
|
7162
|
+
).on("error", (error) => {
|
|
7163
|
+
reject(error);
|
|
7164
|
+
}).on("close", () => {
|
|
7165
|
+
const content = Buffer.concat(
|
|
7166
|
+
chunks
|
|
7167
|
+
).toString("utf8");
|
|
7168
|
+
resolve2({
|
|
7169
|
+
statusCode,
|
|
7170
|
+
headers: incomingHeaders,
|
|
7171
|
+
content
|
|
7172
|
+
});
|
|
7173
|
+
});
|
|
7174
|
+
request.write(body, (error) => {
|
|
7175
|
+
if (error) {
|
|
7176
|
+
reject(error);
|
|
7177
|
+
}
|
|
7178
|
+
});
|
|
7179
|
+
request.end();
|
|
7126
7180
|
});
|
|
7127
7181
|
let out = phpResult.content;
|
|
7128
7182
|
if (phpResult.headers["content-type"]?.includes("html")) {
|
|
@@ -7132,16 +7186,16 @@ function usePHP(cfg = {}) {
|
|
|
7132
7186
|
"/" + entryPathname
|
|
7133
7187
|
);
|
|
7134
7188
|
}
|
|
7135
|
-
res.writeHead(
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7189
|
+
res.writeHead(
|
|
7190
|
+
phpResult.statusCode || 200,
|
|
7191
|
+
phpResult.headers
|
|
7192
|
+
).end(out);
|
|
7139
7193
|
return;
|
|
7140
7194
|
}
|
|
7141
7195
|
}
|
|
7142
7196
|
}
|
|
7143
7197
|
} catch (error) {
|
|
7144
|
-
console.error(
|
|
7198
|
+
console.error("Vite-PHP Error: " + error);
|
|
7145
7199
|
}
|
|
7146
7200
|
next();
|
|
7147
7201
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import require$$0$5, { mkdirSync, writeFileSync, readFileSync, existsSync, rmSyn
|
|
|
2
2
|
import require$$0$2, { relative, dirname, resolve } from 'path';
|
|
3
3
|
import { normalizePath } from 'vite';
|
|
4
4
|
import require$$0 from 'tty';
|
|
5
|
-
import http from 'http';
|
|
5
|
+
import http from 'node:http';
|
|
6
6
|
import { spawn } from 'child_process';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
import require$$0$1 from 'os';
|
|
@@ -69,6 +69,7 @@ let createColors = (enabled = isColorSupported) => {
|
|
|
69
69
|
inverse: init("\x1b[7m", "\x1b[27m"),
|
|
70
70
|
hidden: init("\x1b[8m", "\x1b[28m"),
|
|
71
71
|
strikethrough: init("\x1b[9m", "\x1b[29m"),
|
|
72
|
+
|
|
72
73
|
black: init("\x1b[30m", "\x1b[39m"),
|
|
73
74
|
red: init("\x1b[31m", "\x1b[39m"),
|
|
74
75
|
green: init("\x1b[32m", "\x1b[39m"),
|
|
@@ -78,6 +79,7 @@ let createColors = (enabled = isColorSupported) => {
|
|
|
78
79
|
cyan: init("\x1b[36m", "\x1b[39m"),
|
|
79
80
|
white: init("\x1b[37m", "\x1b[39m"),
|
|
80
81
|
gray: init("\x1b[90m", "\x1b[39m"),
|
|
82
|
+
|
|
81
83
|
bgBlack: init("\x1b[40m", "\x1b[49m"),
|
|
82
84
|
bgRed: init("\x1b[41m", "\x1b[49m"),
|
|
83
85
|
bgGreen: init("\x1b[42m", "\x1b[49m"),
|
|
@@ -86,6 +88,24 @@ let createColors = (enabled = isColorSupported) => {
|
|
|
86
88
|
bgMagenta: init("\x1b[45m", "\x1b[49m"),
|
|
87
89
|
bgCyan: init("\x1b[46m", "\x1b[49m"),
|
|
88
90
|
bgWhite: init("\x1b[47m", "\x1b[49m"),
|
|
91
|
+
|
|
92
|
+
blackBright: init("\x1b[90m", "\x1b[39m"),
|
|
93
|
+
redBright: init("\x1b[91m", "\x1b[39m"),
|
|
94
|
+
greenBright: init("\x1b[92m", "\x1b[39m"),
|
|
95
|
+
yellowBright: init("\x1b[93m", "\x1b[39m"),
|
|
96
|
+
blueBright: init("\x1b[94m", "\x1b[39m"),
|
|
97
|
+
magentaBright: init("\x1b[95m", "\x1b[39m"),
|
|
98
|
+
cyanBright: init("\x1b[96m", "\x1b[39m"),
|
|
99
|
+
whiteBright: init("\x1b[97m", "\x1b[39m"),
|
|
100
|
+
|
|
101
|
+
bgBlackBright: init("\x1b[100m","\x1b[49m"),
|
|
102
|
+
bgRedBright: init("\x1b[101m","\x1b[49m"),
|
|
103
|
+
bgGreenBright: init("\x1b[102m","\x1b[49m"),
|
|
104
|
+
bgYellowBright: init("\x1b[103m","\x1b[49m"),
|
|
105
|
+
bgBlueBright: init("\x1b[104m","\x1b[49m"),
|
|
106
|
+
bgMagentaBright: init("\x1b[105m","\x1b[49m"),
|
|
107
|
+
bgCyanBright: init("\x1b[106m","\x1b[49m"),
|
|
108
|
+
bgWhiteBright: init("\x1b[107m","\x1b[49m"),
|
|
89
109
|
}
|
|
90
110
|
};
|
|
91
111
|
|
|
@@ -7051,9 +7071,18 @@ function usePHP(cfg = {}) {
|
|
|
7051
7071
|
phpServer.start(viteServer?.config.root);
|
|
7052
7072
|
server.middlewares.use(async (req, res, next) => {
|
|
7053
7073
|
try {
|
|
7054
|
-
if (req.url && ![
|
|
7055
|
-
|
|
7056
|
-
|
|
7074
|
+
if (req.url && ![
|
|
7075
|
+
"/@vite",
|
|
7076
|
+
"/@fs",
|
|
7077
|
+
"/@id/__x00__",
|
|
7078
|
+
"/node_modules"
|
|
7079
|
+
].some((path) => req.url.startsWith(path))) {
|
|
7080
|
+
req.on("error", (error) => {
|
|
7081
|
+
throw error;
|
|
7082
|
+
});
|
|
7083
|
+
res.on("error", (error) => {
|
|
7084
|
+
throw error;
|
|
7085
|
+
});
|
|
7057
7086
|
const url = new URL(req.url, "http://localhost");
|
|
7058
7087
|
if (config?.server.port) {
|
|
7059
7088
|
url.port = config.server.port.toString();
|
|
@@ -7084,31 +7113,56 @@ function usePHP(cfg = {}) {
|
|
|
7084
7113
|
PHP_SELF: "/" + entry2
|
|
7085
7114
|
}).toString()
|
|
7086
7115
|
);
|
|
7087
|
-
const
|
|
7116
|
+
const body = await new Promise(
|
|
7117
|
+
(resolve2, reject) => {
|
|
7118
|
+
let data = [];
|
|
7119
|
+
req.on("data", (chunk) => {
|
|
7120
|
+
data.push(chunk);
|
|
7121
|
+
}).on("end", () => {
|
|
7122
|
+
resolve2(Buffer.concat(data));
|
|
7123
|
+
});
|
|
7124
|
+
}
|
|
7125
|
+
);
|
|
7126
|
+
const phpResult = await new Promise(async (resolve2, reject) => {
|
|
7088
7127
|
const chunks = [];
|
|
7089
|
-
|
|
7128
|
+
let statusCode;
|
|
7129
|
+
let incomingHeaders = {};
|
|
7130
|
+
const request = http.request(
|
|
7090
7131
|
url.toString(),
|
|
7091
7132
|
{
|
|
7092
7133
|
method: req.method,
|
|
7093
|
-
headers:
|
|
7134
|
+
headers: {
|
|
7135
|
+
...req.headers,
|
|
7136
|
+
"content-length": Buffer.byteLength(
|
|
7137
|
+
body
|
|
7138
|
+
)
|
|
7139
|
+
}
|
|
7094
7140
|
},
|
|
7095
7141
|
(msg) => {
|
|
7096
|
-
msg.
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
msg.on("end", () => {
|
|
7101
|
-
const content = Buffer.concat(
|
|
7102
|
-
chunks
|
|
7103
|
-
).toString("utf8");
|
|
7104
|
-
resolve2({
|
|
7105
|
-
statusCode: msg.statusCode,
|
|
7106
|
-
headers: msg.headers,
|
|
7107
|
-
content
|
|
7108
|
-
});
|
|
7142
|
+
statusCode = msg.statusCode;
|
|
7143
|
+
incomingHeaders = msg.headers;
|
|
7144
|
+
msg.on("data", (data) => {
|
|
7145
|
+
chunks.push(data);
|
|
7109
7146
|
});
|
|
7110
7147
|
}
|
|
7111
|
-
).on("error",
|
|
7148
|
+
).on("error", (error) => {
|
|
7149
|
+
reject(error);
|
|
7150
|
+
}).on("close", () => {
|
|
7151
|
+
const content = Buffer.concat(
|
|
7152
|
+
chunks
|
|
7153
|
+
).toString("utf8");
|
|
7154
|
+
resolve2({
|
|
7155
|
+
statusCode,
|
|
7156
|
+
headers: incomingHeaders,
|
|
7157
|
+
content
|
|
7158
|
+
});
|
|
7159
|
+
});
|
|
7160
|
+
request.write(body, (error) => {
|
|
7161
|
+
if (error) {
|
|
7162
|
+
reject(error);
|
|
7163
|
+
}
|
|
7164
|
+
});
|
|
7165
|
+
request.end();
|
|
7112
7166
|
});
|
|
7113
7167
|
let out = phpResult.content;
|
|
7114
7168
|
if (phpResult.headers["content-type"]?.includes("html")) {
|
|
@@ -7118,16 +7172,16 @@ function usePHP(cfg = {}) {
|
|
|
7118
7172
|
"/" + entryPathname
|
|
7119
7173
|
);
|
|
7120
7174
|
}
|
|
7121
|
-
res.writeHead(
|
|
7122
|
-
|
|
7123
|
-
|
|
7124
|
-
|
|
7175
|
+
res.writeHead(
|
|
7176
|
+
phpResult.statusCode || 200,
|
|
7177
|
+
phpResult.headers
|
|
7178
|
+
).end(out);
|
|
7125
7179
|
return;
|
|
7126
7180
|
}
|
|
7127
7181
|
}
|
|
7128
7182
|
}
|
|
7129
7183
|
} catch (error) {
|
|
7130
|
-
console.error(
|
|
7184
|
+
console.error("Vite-PHP Error: " + error);
|
|
7131
7185
|
}
|
|
7132
7186
|
next();
|
|
7133
7187
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-php",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.651",
|
|
4
4
|
"author": "Nikita 'donnikitos' Nitichevski <me@donnikitos.com> (https://donnikitos.com/)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
"main": "./dist/index.mjs",
|
|
10
10
|
"module": "./dist/index.mjs",
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@types/node": "^22.4
|
|
12
|
+
"@types/node": "^22.5.4",
|
|
13
13
|
"fast-glob": "^3.3.2",
|
|
14
14
|
"picocolors": "^1.0.1",
|
|
15
|
-
"typescript": "^5.
|
|
15
|
+
"typescript": "^5.6.2",
|
|
16
16
|
"unbuild": "^2.0.0",
|
|
17
|
-
"vite": "^5.4.
|
|
17
|
+
"vite": "^5.4.3"
|
|
18
18
|
},
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|