vite-plugin-php 1.0.62 → 1.0.65

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 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
 
@@ -7068,6 +7088,12 @@ function usePHP(cfg = {}) {
7068
7088
  if (req.url && !["/@vite", "/@fs", "/@id/__x00__"].some(
7069
7089
  (path) => req.url.startsWith(path)
7070
7090
  )) {
7091
+ req.on("error", (error) => {
7092
+ throw error;
7093
+ });
7094
+ res.on("error", (error) => {
7095
+ throw error;
7096
+ });
7071
7097
  const url = new URL(req.url, "http://localhost");
7072
7098
  if (config?.server.port) {
7073
7099
  url.port = config.server.port.toString();
@@ -7098,31 +7124,56 @@ function usePHP(cfg = {}) {
7098
7124
  PHP_SELF: "/" + entry2
7099
7125
  }).toString()
7100
7126
  );
7101
- const phpResult = await new Promise((resolve2, reject) => {
7127
+ const body = await new Promise(
7128
+ (resolve2, reject) => {
7129
+ let data = [];
7130
+ req.on("data", (chunk) => {
7131
+ data.push(chunk);
7132
+ }).on("end", () => {
7133
+ resolve2(Buffer.concat(data));
7134
+ });
7135
+ }
7136
+ );
7137
+ const phpResult = await new Promise(async (resolve2, reject) => {
7102
7138
  const chunks = [];
7103
- http__default.request(
7139
+ let statusCode;
7140
+ let incomingHeaders = {};
7141
+ const request = http__default.request(
7104
7142
  url.toString(),
7105
7143
  {
7106
7144
  method: req.method,
7107
- headers: req.headers
7145
+ headers: {
7146
+ ...req.headers,
7147
+ "content-length": Buffer.byteLength(
7148
+ body
7149
+ )
7150
+ }
7108
7151
  },
7109
7152
  (msg) => {
7110
- msg.on(
7111
- "data",
7112
- (data) => chunks.push(data)
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
- });
7153
+ statusCode = msg.statusCode;
7154
+ incomingHeaders = msg.headers;
7155
+ msg.on("data", (data) => {
7156
+ chunks.push(data);
7123
7157
  });
7124
7158
  }
7125
- ).on("error", reject).end();
7159
+ ).on("error", (error) => {
7160
+ reject(error);
7161
+ }).on("close", () => {
7162
+ const content = Buffer.concat(
7163
+ chunks
7164
+ ).toString("utf8");
7165
+ resolve2({
7166
+ statusCode,
7167
+ headers: incomingHeaders,
7168
+ content
7169
+ });
7170
+ });
7171
+ request.write(body, (error) => {
7172
+ if (error) {
7173
+ reject(error);
7174
+ }
7175
+ });
7176
+ request.end();
7126
7177
  });
7127
7178
  let out = phpResult.content;
7128
7179
  if (phpResult.headers["content-type"]?.includes("html")) {
@@ -7132,16 +7183,16 @@ function usePHP(cfg = {}) {
7132
7183
  "/" + entryPathname
7133
7184
  );
7134
7185
  }
7135
- res.writeHead(phpResult.statusCode || 200, {
7136
- ...req.headers,
7137
- ...phpResult.headers
7138
- }).end(out);
7186
+ res.writeHead(
7187
+ phpResult.statusCode || 200,
7188
+ phpResult.headers
7189
+ ).end(out);
7139
7190
  return;
7140
7191
  }
7141
7192
  }
7142
7193
  }
7143
7194
  } catch (error) {
7144
- console.error(`Error: ${error}`);
7195
+ console.error("Vite-PHP Error: " + error);
7145
7196
  }
7146
7197
  next();
7147
7198
  });
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
 
@@ -7054,6 +7074,12 @@ function usePHP(cfg = {}) {
7054
7074
  if (req.url && !["/@vite", "/@fs", "/@id/__x00__"].some(
7055
7075
  (path) => req.url.startsWith(path)
7056
7076
  )) {
7077
+ req.on("error", (error) => {
7078
+ throw error;
7079
+ });
7080
+ res.on("error", (error) => {
7081
+ throw error;
7082
+ });
7057
7083
  const url = new URL(req.url, "http://localhost");
7058
7084
  if (config?.server.port) {
7059
7085
  url.port = config.server.port.toString();
@@ -7084,31 +7110,56 @@ function usePHP(cfg = {}) {
7084
7110
  PHP_SELF: "/" + entry2
7085
7111
  }).toString()
7086
7112
  );
7087
- const phpResult = await new Promise((resolve2, reject) => {
7113
+ const body = await new Promise(
7114
+ (resolve2, reject) => {
7115
+ let data = [];
7116
+ req.on("data", (chunk) => {
7117
+ data.push(chunk);
7118
+ }).on("end", () => {
7119
+ resolve2(Buffer.concat(data));
7120
+ });
7121
+ }
7122
+ );
7123
+ const phpResult = await new Promise(async (resolve2, reject) => {
7088
7124
  const chunks = [];
7089
- http.request(
7125
+ let statusCode;
7126
+ let incomingHeaders = {};
7127
+ const request = http.request(
7090
7128
  url.toString(),
7091
7129
  {
7092
7130
  method: req.method,
7093
- headers: req.headers
7131
+ headers: {
7132
+ ...req.headers,
7133
+ "content-length": Buffer.byteLength(
7134
+ body
7135
+ )
7136
+ }
7094
7137
  },
7095
7138
  (msg) => {
7096
- msg.on(
7097
- "data",
7098
- (data) => chunks.push(data)
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
- });
7139
+ statusCode = msg.statusCode;
7140
+ incomingHeaders = msg.headers;
7141
+ msg.on("data", (data) => {
7142
+ chunks.push(data);
7109
7143
  });
7110
7144
  }
7111
- ).on("error", reject).end();
7145
+ ).on("error", (error) => {
7146
+ reject(error);
7147
+ }).on("close", () => {
7148
+ const content = Buffer.concat(
7149
+ chunks
7150
+ ).toString("utf8");
7151
+ resolve2({
7152
+ statusCode,
7153
+ headers: incomingHeaders,
7154
+ content
7155
+ });
7156
+ });
7157
+ request.write(body, (error) => {
7158
+ if (error) {
7159
+ reject(error);
7160
+ }
7161
+ });
7162
+ request.end();
7112
7163
  });
7113
7164
  let out = phpResult.content;
7114
7165
  if (phpResult.headers["content-type"]?.includes("html")) {
@@ -7118,16 +7169,16 @@ function usePHP(cfg = {}) {
7118
7169
  "/" + entryPathname
7119
7170
  );
7120
7171
  }
7121
- res.writeHead(phpResult.statusCode || 200, {
7122
- ...req.headers,
7123
- ...phpResult.headers
7124
- }).end(out);
7172
+ res.writeHead(
7173
+ phpResult.statusCode || 200,
7174
+ phpResult.headers
7175
+ ).end(out);
7125
7176
  return;
7126
7177
  }
7127
7178
  }
7128
7179
  }
7129
7180
  } catch (error) {
7130
- console.error(`Error: ${error}`);
7181
+ console.error("Vite-PHP Error: " + error);
7131
7182
  }
7132
7183
  next();
7133
7184
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-php",
3
- "version": "1.0.62",
3
+ "version": "1.0.65",
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.0",
12
+ "@types/node": "^22.5.4",
13
13
  "fast-glob": "^3.3.2",
14
14
  "picocolors": "^1.0.1",
15
- "typescript": "^5.5.4",
15
+ "typescript": "^5.6.2",
16
16
  "unbuild": "^2.0.0",
17
- "vite": "^5.4.1"
17
+ "vite": "^5.4.3"
18
18
  },
19
19
  "exports": {
20
20
  ".": {