vite-plugin-php 1.0.31 → 1.0.40
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 +6 -5
- package/dist/index.cjs +195 -54
- package/dist/index.mjs +191 -51
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -20,11 +20,12 @@ Check out the [starter repo](https://github.com/nititech/php-vite-starter) for a
|
|
|
20
20
|
|
|
21
21
|
## ⚡ Latest changes
|
|
22
22
|
|
|
23
|
-
| Version | Feature
|
|
24
|
-
| ------- |
|
|
25
|
-
| 1.0.
|
|
26
|
-
| 1.0.
|
|
27
|
-
| 1.0.
|
|
23
|
+
| Version | Feature |
|
|
24
|
+
| ------- | ------------------------------------------------------------ |
|
|
25
|
+
| 1.0.40 | Vite's "HTML Env Replacement" feature in transpiled PHP file |
|
|
26
|
+
| 1.0.30 | Proper PHP header forwarding during development |
|
|
27
|
+
| 1.0.20 | URL rewrite functionality to mimic mod_rewrite & friends |
|
|
28
|
+
| 1.0.11 | Improved Windows support |
|
|
28
29
|
|
|
29
30
|
## Write some PHP code in your `index.php`
|
|
30
31
|
|
package/dist/index.cjs
CHANGED
|
@@ -2,24 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
const require$$0 = require('fs');
|
|
4
4
|
const require$$0$1 = require('path');
|
|
5
|
+
const vite = require('vite');
|
|
6
|
+
const require$$0$2 = require('tty');
|
|
5
7
|
const http = require('http');
|
|
6
8
|
const child_process = require('child_process');
|
|
7
9
|
const url = require('url');
|
|
8
|
-
const require$$0$
|
|
9
|
-
const require$$0$
|
|
10
|
-
const require$$0$
|
|
11
|
-
const require$$0$
|
|
10
|
+
const require$$0$3 = require('os');
|
|
11
|
+
const require$$0$4 = require('util');
|
|
12
|
+
const require$$0$5 = require('stream');
|
|
13
|
+
const require$$0$6 = require('events');
|
|
12
14
|
|
|
13
15
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
14
16
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
15
17
|
|
|
16
|
-
const require$$0__default$
|
|
17
|
-
const require$$0__default$
|
|
18
|
-
const http__default = /*#__PURE__*/_interopDefaultCompat(http);
|
|
18
|
+
const require$$0__default$5 = /*#__PURE__*/_interopDefaultCompat(require$$0);
|
|
19
|
+
const require$$0__default$2 = /*#__PURE__*/_interopDefaultCompat(require$$0$1);
|
|
19
20
|
const require$$0__default = /*#__PURE__*/_interopDefaultCompat(require$$0$2);
|
|
20
|
-
const
|
|
21
|
+
const http__default = /*#__PURE__*/_interopDefaultCompat(http);
|
|
22
|
+
const require$$0__default$1 = /*#__PURE__*/_interopDefaultCompat(require$$0$3);
|
|
21
23
|
const require$$0__default$3 = /*#__PURE__*/_interopDefaultCompat(require$$0$4);
|
|
22
|
-
const require$$0__default$
|
|
24
|
+
const require$$0__default$4 = /*#__PURE__*/_interopDefaultCompat(require$$0$5);
|
|
25
|
+
const require$$0__default$6 = /*#__PURE__*/_interopDefaultCompat(require$$0$6);
|
|
23
26
|
|
|
24
27
|
function makeID() {
|
|
25
28
|
return Date.now().toString(36) + Math.random() * 100;
|
|
@@ -30,25 +33,159 @@ function writeFile(file, data) {
|
|
|
30
33
|
require$$0.writeFileSync(file, data);
|
|
31
34
|
}
|
|
32
35
|
|
|
33
|
-
|
|
36
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
37
|
+
|
|
38
|
+
function getDefaultExportFromCjs (x) {
|
|
39
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function commonjsRequire(path) {
|
|
43
|
+
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var picocolors = {exports: {}};
|
|
47
|
+
|
|
48
|
+
let argv = process.argv || [],
|
|
49
|
+
env = process.env;
|
|
50
|
+
let isColorSupported =
|
|
51
|
+
!("NO_COLOR" in env || argv.includes("--no-color")) &&
|
|
52
|
+
("FORCE_COLOR" in env ||
|
|
53
|
+
argv.includes("--color") ||
|
|
54
|
+
process.platform === "win32" ||
|
|
55
|
+
(commonjsRequire != null && require$$0__default.isatty(1) && env.TERM !== "dumb") ||
|
|
56
|
+
"CI" in env);
|
|
57
|
+
|
|
58
|
+
let formatter =
|
|
59
|
+
(open, close, replace = open) =>
|
|
60
|
+
input => {
|
|
61
|
+
let string = "" + input;
|
|
62
|
+
let index = string.indexOf(close, open.length);
|
|
63
|
+
return ~index
|
|
64
|
+
? open + replaceClose(string, close, replace, index) + close
|
|
65
|
+
: open + string + close
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
let replaceClose = (string, close, replace, index) => {
|
|
69
|
+
let result = "";
|
|
70
|
+
let cursor = 0;
|
|
71
|
+
do {
|
|
72
|
+
result += string.substring(cursor, index) + replace;
|
|
73
|
+
cursor = index + close.length;
|
|
74
|
+
index = string.indexOf(close, cursor);
|
|
75
|
+
} while (~index)
|
|
76
|
+
return result + string.substring(cursor)
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
let createColors = (enabled = isColorSupported) => {
|
|
80
|
+
let init = enabled ? formatter : () => String;
|
|
81
|
+
return {
|
|
82
|
+
isColorSupported: enabled,
|
|
83
|
+
reset: init("\x1b[0m", "\x1b[0m"),
|
|
84
|
+
bold: init("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
|
|
85
|
+
dim: init("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
|
|
86
|
+
italic: init("\x1b[3m", "\x1b[23m"),
|
|
87
|
+
underline: init("\x1b[4m", "\x1b[24m"),
|
|
88
|
+
inverse: init("\x1b[7m", "\x1b[27m"),
|
|
89
|
+
hidden: init("\x1b[8m", "\x1b[28m"),
|
|
90
|
+
strikethrough: init("\x1b[9m", "\x1b[29m"),
|
|
91
|
+
black: init("\x1b[30m", "\x1b[39m"),
|
|
92
|
+
red: init("\x1b[31m", "\x1b[39m"),
|
|
93
|
+
green: init("\x1b[32m", "\x1b[39m"),
|
|
94
|
+
yellow: init("\x1b[33m", "\x1b[39m"),
|
|
95
|
+
blue: init("\x1b[34m", "\x1b[39m"),
|
|
96
|
+
magenta: init("\x1b[35m", "\x1b[39m"),
|
|
97
|
+
cyan: init("\x1b[36m", "\x1b[39m"),
|
|
98
|
+
white: init("\x1b[37m", "\x1b[39m"),
|
|
99
|
+
gray: init("\x1b[90m", "\x1b[39m"),
|
|
100
|
+
bgBlack: init("\x1b[40m", "\x1b[49m"),
|
|
101
|
+
bgRed: init("\x1b[41m", "\x1b[49m"),
|
|
102
|
+
bgGreen: init("\x1b[42m", "\x1b[49m"),
|
|
103
|
+
bgYellow: init("\x1b[43m", "\x1b[49m"),
|
|
104
|
+
bgBlue: init("\x1b[44m", "\x1b[49m"),
|
|
105
|
+
bgMagenta: init("\x1b[45m", "\x1b[49m"),
|
|
106
|
+
bgCyan: init("\x1b[46m", "\x1b[49m"),
|
|
107
|
+
bgWhite: init("\x1b[47m", "\x1b[49m"),
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
picocolors.exports = createColors();
|
|
112
|
+
picocolors.exports.createColors = createColors;
|
|
113
|
+
|
|
114
|
+
var picocolorsExports = picocolors.exports;
|
|
115
|
+
const colors = /*@__PURE__*/getDefaultExportFromCjs(picocolorsExports);
|
|
116
|
+
|
|
117
|
+
function resolveEnvPrefix({ envPrefix = "VITE_" }) {
|
|
118
|
+
envPrefix = Array.isArray(envPrefix) ? envPrefix : [envPrefix];
|
|
119
|
+
if (envPrefix.includes("")) {
|
|
120
|
+
throw new Error(
|
|
121
|
+
`envPrefix option contains value '', which could lead unexpected exposure of sensitive information.`
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
return envPrefix;
|
|
125
|
+
}
|
|
126
|
+
const envPattern = /%(\S+?)%/g;
|
|
127
|
+
function initReplaceEnv(config) {
|
|
128
|
+
const envPrefix = resolveEnvPrefix({ envPrefix: config.envPrefix });
|
|
129
|
+
const env = { ...config.env };
|
|
130
|
+
for (const key in config.define) {
|
|
131
|
+
if (key.startsWith(`import.meta.env.`)) {
|
|
132
|
+
const val = config.define[key];
|
|
133
|
+
if (typeof val === "string") {
|
|
134
|
+
try {
|
|
135
|
+
const parsed = JSON.parse(val);
|
|
136
|
+
env[key.slice(16)] = typeof parsed === "string" ? parsed : val;
|
|
137
|
+
} catch {
|
|
138
|
+
env[key.slice(16)] = val;
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
env[key.slice(16)] = JSON.stringify(val);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return function replaceEnv(content, filename) {
|
|
146
|
+
return content.replace(envPattern, (text, key) => {
|
|
147
|
+
if (key in env) {
|
|
148
|
+
return env[key];
|
|
149
|
+
} else {
|
|
150
|
+
if (envPrefix.some((prefix) => key.startsWith(prefix))) {
|
|
151
|
+
const relativeHtml = vite.normalizePath(
|
|
152
|
+
require$$0$1.relative(config.root, filename)
|
|
153
|
+
);
|
|
154
|
+
config.logger.warn(
|
|
155
|
+
colors.yellow(
|
|
156
|
+
colors.bold(
|
|
157
|
+
`(!) ${text} is not defined in env variables found in /${relativeHtml}. Is the variable mistyped?`
|
|
158
|
+
)
|
|
159
|
+
)
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
return text;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const phpTagPattern = /<\?(?:php|).+?(\?>|$)/gis;
|
|
169
|
+
function escapePHP({ inputFile, outputFile, config }) {
|
|
170
|
+
const replaceEnv = initReplaceEnv(config);
|
|
34
171
|
const input = require$$0.readFileSync(inputFile).toString();
|
|
35
172
|
const codeTokens = {};
|
|
36
173
|
const isJS = inputFile.includes(".js") || inputFile.includes(".ts");
|
|
37
174
|
const isML = inputFile.includes(".php") || inputFile.includes(".htm");
|
|
38
|
-
const out = input.replace(
|
|
175
|
+
const out = input.replace(phpTagPattern, (match) => {
|
|
39
176
|
let token = makeID();
|
|
40
177
|
if (isJS) {
|
|
41
178
|
token = `/*${token}*/`;
|
|
42
179
|
} else if (isML) {
|
|
43
180
|
token = `<!--${token}-->`;
|
|
44
181
|
}
|
|
45
|
-
codeTokens[token] = match;
|
|
182
|
+
codeTokens[token] = replaceEnv(match, inputFile);
|
|
46
183
|
return token;
|
|
47
184
|
});
|
|
48
185
|
writeFile(outputFile + ".json", JSON.stringify(codeTokens));
|
|
49
186
|
writeFile(outputFile, out);
|
|
50
187
|
}
|
|
51
|
-
function unescapePHP(file, tokensFile) {
|
|
188
|
+
function unescapePHP({ file, tokensFile }) {
|
|
52
189
|
const input = require$$0.readFileSync(file).toString();
|
|
53
190
|
let out = input;
|
|
54
191
|
const tknsFile = tokensFile || file + ".json";
|
|
@@ -102,12 +239,6 @@ const phpServer = {
|
|
|
102
239
|
stop
|
|
103
240
|
};
|
|
104
241
|
|
|
105
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
106
|
-
|
|
107
|
-
function getDefaultExportFromCjs (x) {
|
|
108
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
242
|
var tasks = {};
|
|
112
243
|
|
|
113
244
|
var utils$k = {};
|
|
@@ -170,8 +301,8 @@ var path$9 = {};
|
|
|
170
301
|
|
|
171
302
|
Object.defineProperty(path$9, "__esModule", { value: true });
|
|
172
303
|
path$9.convertPosixPathToPattern = path$9.convertWindowsPathToPattern = path$9.convertPathToPattern = path$9.escapePosixPath = path$9.escapeWindowsPath = path$9.escape = path$9.removeLeadingDotSegment = path$9.makeAbsolute = path$9.unixify = void 0;
|
|
173
|
-
const os = require$$0__default;
|
|
174
|
-
const path$8 = require$$0__default$
|
|
304
|
+
const os = require$$0__default$1;
|
|
305
|
+
const path$8 = require$$0__default$2;
|
|
175
306
|
const IS_WINDOWS_PLATFORM = os.platform() === 'win32';
|
|
176
307
|
const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2; // ./ or .\\
|
|
177
308
|
/**
|
|
@@ -411,8 +542,8 @@ var isGlob$1 = function isGlob(str, options) {
|
|
|
411
542
|
};
|
|
412
543
|
|
|
413
544
|
var isGlob = isGlob$1;
|
|
414
|
-
var pathPosixDirname = require$$0__default$
|
|
415
|
-
var isWin32 = require$$0__default.platform() === 'win32';
|
|
545
|
+
var pathPosixDirname = require$$0__default$2.posix.dirname;
|
|
546
|
+
var isWin32 = require$$0__default$1.platform() === 'win32';
|
|
416
547
|
|
|
417
548
|
var slash = '/';
|
|
418
549
|
var backslash = /\\/g;
|
|
@@ -908,7 +1039,7 @@ var toRegexRange_1 = toRegexRange$1;
|
|
|
908
1039
|
* Licensed under the MIT License.
|
|
909
1040
|
*/
|
|
910
1041
|
|
|
911
|
-
const util$1 = require$$0__default$
|
|
1042
|
+
const util$1 = require$$0__default$3;
|
|
912
1043
|
const toRegexRange = toRegexRange_1;
|
|
913
1044
|
|
|
914
1045
|
const isObject$1 = val => val !== null && typeof val === 'object' && !Array.isArray(val);
|
|
@@ -1873,7 +2004,7 @@ var braces_1 = braces$1;
|
|
|
1873
2004
|
|
|
1874
2005
|
var utils$f = {};
|
|
1875
2006
|
|
|
1876
|
-
const path$7 = require$$0__default$
|
|
2007
|
+
const path$7 = require$$0__default$2;
|
|
1877
2008
|
const WIN_SLASH = '\\\\/';
|
|
1878
2009
|
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
1879
2010
|
|
|
@@ -2053,7 +2184,7 @@ var constants$3 = {
|
|
|
2053
2184
|
|
|
2054
2185
|
(function (exports) {
|
|
2055
2186
|
|
|
2056
|
-
const path = require$$0__default$
|
|
2187
|
+
const path = require$$0__default$2;
|
|
2057
2188
|
const win32 = process.platform === 'win32';
|
|
2058
2189
|
const {
|
|
2059
2190
|
REGEX_BACKSLASH,
|
|
@@ -3597,7 +3728,7 @@ parse$1.fastpaths = (input, options) => {
|
|
|
3597
3728
|
|
|
3598
3729
|
var parse_1 = parse$1;
|
|
3599
3730
|
|
|
3600
|
-
const path$6 = require$$0__default$
|
|
3731
|
+
const path$6 = require$$0__default$2;
|
|
3601
3732
|
const scan = scan_1;
|
|
3602
3733
|
const parse = parse_1;
|
|
3603
3734
|
const utils$c = utils$f;
|
|
@@ -3940,7 +4071,7 @@ var picomatch_1 = picomatch$2;
|
|
|
3940
4071
|
|
|
3941
4072
|
var picomatch$1 = picomatch_1;
|
|
3942
4073
|
|
|
3943
|
-
const util = require$$0__default$
|
|
4074
|
+
const util = require$$0__default$3;
|
|
3944
4075
|
const braces = braces_1;
|
|
3945
4076
|
const picomatch = picomatch$1;
|
|
3946
4077
|
const utils$b = utils$f;
|
|
@@ -4408,7 +4539,7 @@ var micromatch_1 = micromatch$1;
|
|
|
4408
4539
|
|
|
4409
4540
|
Object.defineProperty(pattern$1, "__esModule", { value: true });
|
|
4410
4541
|
pattern$1.removeDuplicateSlashes = pattern$1.matchAny = pattern$1.convertPatternsToRe = pattern$1.makeRe = pattern$1.getPatternParts = pattern$1.expandBraceExpansion = pattern$1.expandPatternsWithBraceExpansion = pattern$1.isAffectDepthOfReadingPattern = pattern$1.endsWithSlashGlobStar = pattern$1.hasGlobStar = pattern$1.getBaseDirectory = pattern$1.isPatternRelatedToParentDirectory = pattern$1.getPatternsOutsideCurrentDirectory = pattern$1.getPatternsInsideCurrentDirectory = pattern$1.getPositivePatterns = pattern$1.getNegativePatterns = pattern$1.isPositivePattern = pattern$1.isNegativePattern = pattern$1.convertToNegativePattern = pattern$1.convertToPositivePattern = pattern$1.isDynamicPattern = pattern$1.isStaticPattern = void 0;
|
|
4411
|
-
const path$5 = require$$0__default$
|
|
4542
|
+
const path$5 = require$$0__default$2;
|
|
4412
4543
|
const globParent = globParent$1;
|
|
4413
4544
|
const micromatch = micromatch_1;
|
|
4414
4545
|
const GLOBSTAR = '**';
|
|
@@ -4603,7 +4734,7 @@ var stream$4 = {};
|
|
|
4603
4734
|
* Copyright (c) 2014-2020 Teambition
|
|
4604
4735
|
* Licensed under the MIT license.
|
|
4605
4736
|
*/
|
|
4606
|
-
const Stream = require$$0__default$
|
|
4737
|
+
const Stream = require$$0__default$4;
|
|
4607
4738
|
const PassThrough = Stream.PassThrough;
|
|
4608
4739
|
const slice = Array.prototype.slice;
|
|
4609
4740
|
|
|
@@ -4983,7 +5114,7 @@ var fs$5 = {};
|
|
|
4983
5114
|
(function (exports) {
|
|
4984
5115
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4985
5116
|
exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0;
|
|
4986
|
-
const fs = require$$0__default$
|
|
5117
|
+
const fs = require$$0__default$5;
|
|
4987
5118
|
exports.FILE_SYSTEM_ADAPTER = {
|
|
4988
5119
|
lstat: fs.lstat,
|
|
4989
5120
|
stat: fs.stat,
|
|
@@ -5334,7 +5465,7 @@ var fs$1 = {};
|
|
|
5334
5465
|
(function (exports) {
|
|
5335
5466
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5336
5467
|
exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0;
|
|
5337
|
-
const fs = require$$0__default$
|
|
5468
|
+
const fs = require$$0__default$5;
|
|
5338
5469
|
exports.FILE_SYSTEM_ADAPTER = {
|
|
5339
5470
|
lstat: fs.lstat,
|
|
5340
5471
|
stat: fs.stat,
|
|
@@ -5353,7 +5484,7 @@ var fs$1 = {};
|
|
|
5353
5484
|
} (fs$1));
|
|
5354
5485
|
|
|
5355
5486
|
Object.defineProperty(settings$2, "__esModule", { value: true });
|
|
5356
|
-
const path$3 = require$$0__default$
|
|
5487
|
+
const path$3 = require$$0__default$2;
|
|
5357
5488
|
const fsStat$3 = out$1;
|
|
5358
5489
|
const fs = fs$1;
|
|
5359
5490
|
let Settings$1 = class Settings {
|
|
@@ -5795,7 +5926,7 @@ let Reader$1 = class Reader {
|
|
|
5795
5926
|
reader$1.default = Reader$1;
|
|
5796
5927
|
|
|
5797
5928
|
Object.defineProperty(async$4, "__esModule", { value: true });
|
|
5798
|
-
const events_1 = require$$0__default$
|
|
5929
|
+
const events_1 = require$$0__default$6;
|
|
5799
5930
|
const fsScandir$2 = out$2;
|
|
5800
5931
|
const fastq = queueExports;
|
|
5801
5932
|
const common$1 = common$3;
|
|
@@ -5924,7 +6055,7 @@ function callSuccessCallback(callback, entries) {
|
|
|
5924
6055
|
var stream$2 = {};
|
|
5925
6056
|
|
|
5926
6057
|
Object.defineProperty(stream$2, "__esModule", { value: true });
|
|
5927
|
-
const stream_1$5 = require$$0__default$
|
|
6058
|
+
const stream_1$5 = require$$0__default$4;
|
|
5928
6059
|
const async_1$3 = async$4;
|
|
5929
6060
|
class StreamProvider {
|
|
5930
6061
|
constructor(_root, _settings) {
|
|
@@ -6037,7 +6168,7 @@ sync$3.default = SyncProvider;
|
|
|
6037
6168
|
var settings$1 = {};
|
|
6038
6169
|
|
|
6039
6170
|
Object.defineProperty(settings$1, "__esModule", { value: true });
|
|
6040
|
-
const path$2 = require$$0__default$
|
|
6171
|
+
const path$2 = require$$0__default$2;
|
|
6041
6172
|
const fsScandir = out$2;
|
|
6042
6173
|
class Settings {
|
|
6043
6174
|
constructor(_options = {}) {
|
|
@@ -6099,7 +6230,7 @@ function getSettings(settingsOrOptions = {}) {
|
|
|
6099
6230
|
var reader = {};
|
|
6100
6231
|
|
|
6101
6232
|
Object.defineProperty(reader, "__esModule", { value: true });
|
|
6102
|
-
const path$1 = require$$0__default$
|
|
6233
|
+
const path$1 = require$$0__default$2;
|
|
6103
6234
|
const fsStat$2 = out$1;
|
|
6104
6235
|
const utils$6 = utils$k;
|
|
6105
6236
|
class Reader {
|
|
@@ -6134,7 +6265,7 @@ reader.default = Reader;
|
|
|
6134
6265
|
var stream$1 = {};
|
|
6135
6266
|
|
|
6136
6267
|
Object.defineProperty(stream$1, "__esModule", { value: true });
|
|
6137
|
-
const stream_1$3 = require$$0__default$
|
|
6268
|
+
const stream_1$3 = require$$0__default$4;
|
|
6138
6269
|
const fsStat$1 = out$1;
|
|
6139
6270
|
const fsWalk$2 = out$3;
|
|
6140
6271
|
const reader_1$2 = reader;
|
|
@@ -6487,7 +6618,7 @@ class EntryTransformer {
|
|
|
6487
6618
|
entry.default = EntryTransformer;
|
|
6488
6619
|
|
|
6489
6620
|
Object.defineProperty(provider, "__esModule", { value: true });
|
|
6490
|
-
const path = require$$0__default$
|
|
6621
|
+
const path = require$$0__default$2;
|
|
6491
6622
|
const deep_1 = deep;
|
|
6492
6623
|
const entry_1 = entry$1;
|
|
6493
6624
|
const error_1 = error;
|
|
@@ -6560,7 +6691,7 @@ async$7.default = ProviderAsync;
|
|
|
6560
6691
|
var stream = {};
|
|
6561
6692
|
|
|
6562
6693
|
Object.defineProperty(stream, "__esModule", { value: true });
|
|
6563
|
-
const stream_1$1 = require$$0__default$
|
|
6694
|
+
const stream_1$1 = require$$0__default$4;
|
|
6564
6695
|
const stream_2 = stream$1;
|
|
6565
6696
|
const provider_1$1 = provider;
|
|
6566
6697
|
class ProviderStream extends provider_1$1.default {
|
|
@@ -6665,8 +6796,8 @@ var settings = {};
|
|
|
6665
6796
|
(function (exports) {
|
|
6666
6797
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6667
6798
|
exports.DEFAULT_FILE_SYSTEM_ADAPTER = void 0;
|
|
6668
|
-
const fs = require$$0__default$
|
|
6669
|
-
const os = require$$0__default;
|
|
6799
|
+
const fs = require$$0__default$5;
|
|
6800
|
+
const os = require$$0__default$1;
|
|
6670
6801
|
/**
|
|
6671
6802
|
* The `os.cpus` method can return zero. We expect the number of cores to be greater than zero.
|
|
6672
6803
|
* https://github.com/nodejs/node/blob/7faeddf23a98c53896f8b574a6e66589e8fb1eb8/lib/os.js#L106-L107
|
|
@@ -6839,10 +6970,8 @@ function usePHP(cfg = {}) {
|
|
|
6839
6970
|
let config = void 0;
|
|
6840
6971
|
let viteServer = void 0;
|
|
6841
6972
|
let entries = Array.isArray(entry) ? entry : [entry];
|
|
6842
|
-
function
|
|
6843
|
-
|
|
6844
|
-
escapePHP(file, tempFile);
|
|
6845
|
-
return tempFile;
|
|
6973
|
+
function getTempFileName(file) {
|
|
6974
|
+
return `${tempDir}/${file}.html`;
|
|
6846
6975
|
}
|
|
6847
6976
|
function cleanupTemp(dir = "") {
|
|
6848
6977
|
const parentDir = dir ? dir + "/" : dir;
|
|
@@ -6882,7 +7011,7 @@ function usePHP(cfg = {}) {
|
|
|
6882
7011
|
ignore: [tempDir, config2.build?.outDir || "dist"]
|
|
6883
7012
|
})
|
|
6884
7013
|
);
|
|
6885
|
-
const inputs = entries.map(
|
|
7014
|
+
const inputs = entries.map(getTempFileName);
|
|
6886
7015
|
return {
|
|
6887
7016
|
build: {
|
|
6888
7017
|
rollupOptions: { input: inputs }
|
|
@@ -6892,6 +7021,13 @@ function usePHP(cfg = {}) {
|
|
|
6892
7021
|
},
|
|
6893
7022
|
configResolved(_config) {
|
|
6894
7023
|
config = _config;
|
|
7024
|
+
entries.forEach(
|
|
7025
|
+
(entry2) => escapePHP({
|
|
7026
|
+
inputFile: entry2,
|
|
7027
|
+
outputFile: getTempFileName(entry2),
|
|
7028
|
+
config
|
|
7029
|
+
})
|
|
7030
|
+
);
|
|
6895
7031
|
}
|
|
6896
7032
|
},
|
|
6897
7033
|
{
|
|
@@ -6925,7 +7061,7 @@ function usePHP(cfg = {}) {
|
|
|
6925
7061
|
return file === entryPathname || file.substring(0, file.lastIndexOf(".")) === entryPathname;
|
|
6926
7062
|
});
|
|
6927
7063
|
if (entry2) {
|
|
6928
|
-
const tempFile =
|
|
7064
|
+
const tempFile = getTempFileName(entry2);
|
|
6929
7065
|
if (require$$0.existsSync(require$$0$1.resolve(tempFile))) {
|
|
6930
7066
|
url.pathname = tempFile;
|
|
6931
7067
|
url.port = phpServer.port.toString();
|
|
@@ -6963,7 +7099,7 @@ function usePHP(cfg = {}) {
|
|
|
6963
7099
|
).on("error", reject).end();
|
|
6964
7100
|
});
|
|
6965
7101
|
const out = await server.transformIndexHtml(
|
|
6966
|
-
|
|
7102
|
+
"/" + entryPathname,
|
|
6967
7103
|
phpResult.content,
|
|
6968
7104
|
req.originalUrl
|
|
6969
7105
|
);
|
|
@@ -6986,7 +7122,11 @@ function usePHP(cfg = {}) {
|
|
|
6986
7122
|
(entryFile) => file.endsWith(entryFile) && require$$0$1.resolve(entryFile) === file
|
|
6987
7123
|
);
|
|
6988
7124
|
if (entry2) {
|
|
6989
|
-
|
|
7125
|
+
escapePHP({
|
|
7126
|
+
inputFile: entry2,
|
|
7127
|
+
outputFile: getTempFileName(entry2),
|
|
7128
|
+
config
|
|
7129
|
+
});
|
|
6990
7130
|
server.ws.send({
|
|
6991
7131
|
type: "full-reload",
|
|
6992
7132
|
path: "*"
|
|
@@ -7005,10 +7145,11 @@ function usePHP(cfg = {}) {
|
|
|
7005
7145
|
closeBundle() {
|
|
7006
7146
|
const distDir = config?.build.outDir;
|
|
7007
7147
|
entries.forEach((file) => {
|
|
7008
|
-
const
|
|
7009
|
-
|
|
7010
|
-
`${
|
|
7011
|
-
|
|
7148
|
+
const tempFileName = getTempFileName(file);
|
|
7149
|
+
const code = unescapePHP({
|
|
7150
|
+
file: `${distDir}/${tempFileName}`,
|
|
7151
|
+
tokensFile: `${tempFileName}.json`
|
|
7152
|
+
});
|
|
7012
7153
|
writeFile(`${distDir}/${file}`, code);
|
|
7013
7154
|
});
|
|
7014
7155
|
cleanupTemp(distDir);
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import require$$0$
|
|
2
|
-
import require$$0$
|
|
1
|
+
import require$$0$5, { mkdirSync, writeFileSync, readFileSync, existsSync, rmSync } from 'fs';
|
|
2
|
+
import require$$0$2, { dirname, relative, resolve } from 'path';
|
|
3
|
+
import { normalizePath } from 'vite';
|
|
4
|
+
import require$$0 from 'tty';
|
|
3
5
|
import http from 'http';
|
|
4
6
|
import { spawn } from 'child_process';
|
|
5
7
|
import { fileURLToPath } from 'url';
|
|
6
|
-
import require$$0 from 'os';
|
|
7
|
-
import require$$0$
|
|
8
|
-
import require$$0$
|
|
9
|
-
import require$$0$
|
|
8
|
+
import require$$0$1 from 'os';
|
|
9
|
+
import require$$0$3 from 'util';
|
|
10
|
+
import require$$0$4 from 'stream';
|
|
11
|
+
import require$$0$6 from 'events';
|
|
10
12
|
|
|
11
13
|
function makeID() {
|
|
12
14
|
return Date.now().toString(36) + Math.random() * 100;
|
|
@@ -17,25 +19,159 @@ function writeFile(file, data) {
|
|
|
17
19
|
writeFileSync(file, data);
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
23
|
+
|
|
24
|
+
function getDefaultExportFromCjs (x) {
|
|
25
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function commonjsRequire(path) {
|
|
29
|
+
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var picocolors = {exports: {}};
|
|
33
|
+
|
|
34
|
+
let argv = process.argv || [],
|
|
35
|
+
env = process.env;
|
|
36
|
+
let isColorSupported =
|
|
37
|
+
!("NO_COLOR" in env || argv.includes("--no-color")) &&
|
|
38
|
+
("FORCE_COLOR" in env ||
|
|
39
|
+
argv.includes("--color") ||
|
|
40
|
+
process.platform === "win32" ||
|
|
41
|
+
(commonjsRequire != null && require$$0.isatty(1) && env.TERM !== "dumb") ||
|
|
42
|
+
"CI" in env);
|
|
43
|
+
|
|
44
|
+
let formatter =
|
|
45
|
+
(open, close, replace = open) =>
|
|
46
|
+
input => {
|
|
47
|
+
let string = "" + input;
|
|
48
|
+
let index = string.indexOf(close, open.length);
|
|
49
|
+
return ~index
|
|
50
|
+
? open + replaceClose(string, close, replace, index) + close
|
|
51
|
+
: open + string + close
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
let replaceClose = (string, close, replace, index) => {
|
|
55
|
+
let result = "";
|
|
56
|
+
let cursor = 0;
|
|
57
|
+
do {
|
|
58
|
+
result += string.substring(cursor, index) + replace;
|
|
59
|
+
cursor = index + close.length;
|
|
60
|
+
index = string.indexOf(close, cursor);
|
|
61
|
+
} while (~index)
|
|
62
|
+
return result + string.substring(cursor)
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
let createColors = (enabled = isColorSupported) => {
|
|
66
|
+
let init = enabled ? formatter : () => String;
|
|
67
|
+
return {
|
|
68
|
+
isColorSupported: enabled,
|
|
69
|
+
reset: init("\x1b[0m", "\x1b[0m"),
|
|
70
|
+
bold: init("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
|
|
71
|
+
dim: init("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
|
|
72
|
+
italic: init("\x1b[3m", "\x1b[23m"),
|
|
73
|
+
underline: init("\x1b[4m", "\x1b[24m"),
|
|
74
|
+
inverse: init("\x1b[7m", "\x1b[27m"),
|
|
75
|
+
hidden: init("\x1b[8m", "\x1b[28m"),
|
|
76
|
+
strikethrough: init("\x1b[9m", "\x1b[29m"),
|
|
77
|
+
black: init("\x1b[30m", "\x1b[39m"),
|
|
78
|
+
red: init("\x1b[31m", "\x1b[39m"),
|
|
79
|
+
green: init("\x1b[32m", "\x1b[39m"),
|
|
80
|
+
yellow: init("\x1b[33m", "\x1b[39m"),
|
|
81
|
+
blue: init("\x1b[34m", "\x1b[39m"),
|
|
82
|
+
magenta: init("\x1b[35m", "\x1b[39m"),
|
|
83
|
+
cyan: init("\x1b[36m", "\x1b[39m"),
|
|
84
|
+
white: init("\x1b[37m", "\x1b[39m"),
|
|
85
|
+
gray: init("\x1b[90m", "\x1b[39m"),
|
|
86
|
+
bgBlack: init("\x1b[40m", "\x1b[49m"),
|
|
87
|
+
bgRed: init("\x1b[41m", "\x1b[49m"),
|
|
88
|
+
bgGreen: init("\x1b[42m", "\x1b[49m"),
|
|
89
|
+
bgYellow: init("\x1b[43m", "\x1b[49m"),
|
|
90
|
+
bgBlue: init("\x1b[44m", "\x1b[49m"),
|
|
91
|
+
bgMagenta: init("\x1b[45m", "\x1b[49m"),
|
|
92
|
+
bgCyan: init("\x1b[46m", "\x1b[49m"),
|
|
93
|
+
bgWhite: init("\x1b[47m", "\x1b[49m"),
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
picocolors.exports = createColors();
|
|
98
|
+
picocolors.exports.createColors = createColors;
|
|
99
|
+
|
|
100
|
+
var picocolorsExports = picocolors.exports;
|
|
101
|
+
const colors = /*@__PURE__*/getDefaultExportFromCjs(picocolorsExports);
|
|
102
|
+
|
|
103
|
+
function resolveEnvPrefix({ envPrefix = "VITE_" }) {
|
|
104
|
+
envPrefix = Array.isArray(envPrefix) ? envPrefix : [envPrefix];
|
|
105
|
+
if (envPrefix.includes("")) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
`envPrefix option contains value '', which could lead unexpected exposure of sensitive information.`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
return envPrefix;
|
|
111
|
+
}
|
|
112
|
+
const envPattern = /%(\S+?)%/g;
|
|
113
|
+
function initReplaceEnv(config) {
|
|
114
|
+
const envPrefix = resolveEnvPrefix({ envPrefix: config.envPrefix });
|
|
115
|
+
const env = { ...config.env };
|
|
116
|
+
for (const key in config.define) {
|
|
117
|
+
if (key.startsWith(`import.meta.env.`)) {
|
|
118
|
+
const val = config.define[key];
|
|
119
|
+
if (typeof val === "string") {
|
|
120
|
+
try {
|
|
121
|
+
const parsed = JSON.parse(val);
|
|
122
|
+
env[key.slice(16)] = typeof parsed === "string" ? parsed : val;
|
|
123
|
+
} catch {
|
|
124
|
+
env[key.slice(16)] = val;
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
env[key.slice(16)] = JSON.stringify(val);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return function replaceEnv(content, filename) {
|
|
132
|
+
return content.replace(envPattern, (text, key) => {
|
|
133
|
+
if (key in env) {
|
|
134
|
+
return env[key];
|
|
135
|
+
} else {
|
|
136
|
+
if (envPrefix.some((prefix) => key.startsWith(prefix))) {
|
|
137
|
+
const relativeHtml = normalizePath(
|
|
138
|
+
relative(config.root, filename)
|
|
139
|
+
);
|
|
140
|
+
config.logger.warn(
|
|
141
|
+
colors.yellow(
|
|
142
|
+
colors.bold(
|
|
143
|
+
`(!) ${text} is not defined in env variables found in /${relativeHtml}. Is the variable mistyped?`
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
return text;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const phpTagPattern = /<\?(?:php|).+?(\?>|$)/gis;
|
|
155
|
+
function escapePHP({ inputFile, outputFile, config }) {
|
|
156
|
+
const replaceEnv = initReplaceEnv(config);
|
|
21
157
|
const input = readFileSync(inputFile).toString();
|
|
22
158
|
const codeTokens = {};
|
|
23
159
|
const isJS = inputFile.includes(".js") || inputFile.includes(".ts");
|
|
24
160
|
const isML = inputFile.includes(".php") || inputFile.includes(".htm");
|
|
25
|
-
const out = input.replace(
|
|
161
|
+
const out = input.replace(phpTagPattern, (match) => {
|
|
26
162
|
let token = makeID();
|
|
27
163
|
if (isJS) {
|
|
28
164
|
token = `/*${token}*/`;
|
|
29
165
|
} else if (isML) {
|
|
30
166
|
token = `<!--${token}-->`;
|
|
31
167
|
}
|
|
32
|
-
codeTokens[token] = match;
|
|
168
|
+
codeTokens[token] = replaceEnv(match, inputFile);
|
|
33
169
|
return token;
|
|
34
170
|
});
|
|
35
171
|
writeFile(outputFile + ".json", JSON.stringify(codeTokens));
|
|
36
172
|
writeFile(outputFile, out);
|
|
37
173
|
}
|
|
38
|
-
function unescapePHP(file, tokensFile) {
|
|
174
|
+
function unescapePHP({ file, tokensFile }) {
|
|
39
175
|
const input = readFileSync(file).toString();
|
|
40
176
|
let out = input;
|
|
41
177
|
const tknsFile = tokensFile || file + ".json";
|
|
@@ -89,12 +225,6 @@ const phpServer = {
|
|
|
89
225
|
stop
|
|
90
226
|
};
|
|
91
227
|
|
|
92
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
93
|
-
|
|
94
|
-
function getDefaultExportFromCjs (x) {
|
|
95
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
228
|
var tasks = {};
|
|
99
229
|
|
|
100
230
|
var utils$k = {};
|
|
@@ -157,8 +287,8 @@ var path$9 = {};
|
|
|
157
287
|
|
|
158
288
|
Object.defineProperty(path$9, "__esModule", { value: true });
|
|
159
289
|
path$9.convertPosixPathToPattern = path$9.convertWindowsPathToPattern = path$9.convertPathToPattern = path$9.escapePosixPath = path$9.escapeWindowsPath = path$9.escape = path$9.removeLeadingDotSegment = path$9.makeAbsolute = path$9.unixify = void 0;
|
|
160
|
-
const os = require$$0;
|
|
161
|
-
const path$8 = require$$0$
|
|
290
|
+
const os = require$$0$1;
|
|
291
|
+
const path$8 = require$$0$2;
|
|
162
292
|
const IS_WINDOWS_PLATFORM = os.platform() === 'win32';
|
|
163
293
|
const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2; // ./ or .\\
|
|
164
294
|
/**
|
|
@@ -398,8 +528,8 @@ var isGlob$1 = function isGlob(str, options) {
|
|
|
398
528
|
};
|
|
399
529
|
|
|
400
530
|
var isGlob = isGlob$1;
|
|
401
|
-
var pathPosixDirname = require$$0$
|
|
402
|
-
var isWin32 = require$$0.platform() === 'win32';
|
|
531
|
+
var pathPosixDirname = require$$0$2.posix.dirname;
|
|
532
|
+
var isWin32 = require$$0$1.platform() === 'win32';
|
|
403
533
|
|
|
404
534
|
var slash = '/';
|
|
405
535
|
var backslash = /\\/g;
|
|
@@ -895,7 +1025,7 @@ var toRegexRange_1 = toRegexRange$1;
|
|
|
895
1025
|
* Licensed under the MIT License.
|
|
896
1026
|
*/
|
|
897
1027
|
|
|
898
|
-
const util$1 = require$$0$
|
|
1028
|
+
const util$1 = require$$0$3;
|
|
899
1029
|
const toRegexRange = toRegexRange_1;
|
|
900
1030
|
|
|
901
1031
|
const isObject$1 = val => val !== null && typeof val === 'object' && !Array.isArray(val);
|
|
@@ -1860,7 +1990,7 @@ var braces_1 = braces$1;
|
|
|
1860
1990
|
|
|
1861
1991
|
var utils$f = {};
|
|
1862
1992
|
|
|
1863
|
-
const path$7 = require$$0$
|
|
1993
|
+
const path$7 = require$$0$2;
|
|
1864
1994
|
const WIN_SLASH = '\\\\/';
|
|
1865
1995
|
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
1866
1996
|
|
|
@@ -2040,7 +2170,7 @@ var constants$3 = {
|
|
|
2040
2170
|
|
|
2041
2171
|
(function (exports) {
|
|
2042
2172
|
|
|
2043
|
-
const path = require$$0$
|
|
2173
|
+
const path = require$$0$2;
|
|
2044
2174
|
const win32 = process.platform === 'win32';
|
|
2045
2175
|
const {
|
|
2046
2176
|
REGEX_BACKSLASH,
|
|
@@ -3584,7 +3714,7 @@ parse$1.fastpaths = (input, options) => {
|
|
|
3584
3714
|
|
|
3585
3715
|
var parse_1 = parse$1;
|
|
3586
3716
|
|
|
3587
|
-
const path$6 = require$$0$
|
|
3717
|
+
const path$6 = require$$0$2;
|
|
3588
3718
|
const scan = scan_1;
|
|
3589
3719
|
const parse = parse_1;
|
|
3590
3720
|
const utils$c = utils$f;
|
|
@@ -3927,7 +4057,7 @@ var picomatch_1 = picomatch$2;
|
|
|
3927
4057
|
|
|
3928
4058
|
var picomatch$1 = picomatch_1;
|
|
3929
4059
|
|
|
3930
|
-
const util = require$$0$
|
|
4060
|
+
const util = require$$0$3;
|
|
3931
4061
|
const braces = braces_1;
|
|
3932
4062
|
const picomatch = picomatch$1;
|
|
3933
4063
|
const utils$b = utils$f;
|
|
@@ -4395,7 +4525,7 @@ var micromatch_1 = micromatch$1;
|
|
|
4395
4525
|
|
|
4396
4526
|
Object.defineProperty(pattern$1, "__esModule", { value: true });
|
|
4397
4527
|
pattern$1.removeDuplicateSlashes = pattern$1.matchAny = pattern$1.convertPatternsToRe = pattern$1.makeRe = pattern$1.getPatternParts = pattern$1.expandBraceExpansion = pattern$1.expandPatternsWithBraceExpansion = pattern$1.isAffectDepthOfReadingPattern = pattern$1.endsWithSlashGlobStar = pattern$1.hasGlobStar = pattern$1.getBaseDirectory = pattern$1.isPatternRelatedToParentDirectory = pattern$1.getPatternsOutsideCurrentDirectory = pattern$1.getPatternsInsideCurrentDirectory = pattern$1.getPositivePatterns = pattern$1.getNegativePatterns = pattern$1.isPositivePattern = pattern$1.isNegativePattern = pattern$1.convertToNegativePattern = pattern$1.convertToPositivePattern = pattern$1.isDynamicPattern = pattern$1.isStaticPattern = void 0;
|
|
4398
|
-
const path$5 = require$$0$
|
|
4528
|
+
const path$5 = require$$0$2;
|
|
4399
4529
|
const globParent = globParent$1;
|
|
4400
4530
|
const micromatch = micromatch_1;
|
|
4401
4531
|
const GLOBSTAR = '**';
|
|
@@ -4590,7 +4720,7 @@ var stream$4 = {};
|
|
|
4590
4720
|
* Copyright (c) 2014-2020 Teambition
|
|
4591
4721
|
* Licensed under the MIT license.
|
|
4592
4722
|
*/
|
|
4593
|
-
const Stream = require$$0$
|
|
4723
|
+
const Stream = require$$0$4;
|
|
4594
4724
|
const PassThrough = Stream.PassThrough;
|
|
4595
4725
|
const slice = Array.prototype.slice;
|
|
4596
4726
|
|
|
@@ -4970,7 +5100,7 @@ var fs$5 = {};
|
|
|
4970
5100
|
(function (exports) {
|
|
4971
5101
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4972
5102
|
exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0;
|
|
4973
|
-
const fs = require$$0$
|
|
5103
|
+
const fs = require$$0$5;
|
|
4974
5104
|
exports.FILE_SYSTEM_ADAPTER = {
|
|
4975
5105
|
lstat: fs.lstat,
|
|
4976
5106
|
stat: fs.stat,
|
|
@@ -5321,7 +5451,7 @@ var fs$1 = {};
|
|
|
5321
5451
|
(function (exports) {
|
|
5322
5452
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5323
5453
|
exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0;
|
|
5324
|
-
const fs = require$$0$
|
|
5454
|
+
const fs = require$$0$5;
|
|
5325
5455
|
exports.FILE_SYSTEM_ADAPTER = {
|
|
5326
5456
|
lstat: fs.lstat,
|
|
5327
5457
|
stat: fs.stat,
|
|
@@ -5340,7 +5470,7 @@ var fs$1 = {};
|
|
|
5340
5470
|
} (fs$1));
|
|
5341
5471
|
|
|
5342
5472
|
Object.defineProperty(settings$2, "__esModule", { value: true });
|
|
5343
|
-
const path$3 = require$$0$
|
|
5473
|
+
const path$3 = require$$0$2;
|
|
5344
5474
|
const fsStat$3 = out$1;
|
|
5345
5475
|
const fs = fs$1;
|
|
5346
5476
|
let Settings$1 = class Settings {
|
|
@@ -5782,7 +5912,7 @@ let Reader$1 = class Reader {
|
|
|
5782
5912
|
reader$1.default = Reader$1;
|
|
5783
5913
|
|
|
5784
5914
|
Object.defineProperty(async$4, "__esModule", { value: true });
|
|
5785
|
-
const events_1 = require$$0$
|
|
5915
|
+
const events_1 = require$$0$6;
|
|
5786
5916
|
const fsScandir$2 = out$2;
|
|
5787
5917
|
const fastq = queueExports;
|
|
5788
5918
|
const common$1 = common$3;
|
|
@@ -5911,7 +6041,7 @@ function callSuccessCallback(callback, entries) {
|
|
|
5911
6041
|
var stream$2 = {};
|
|
5912
6042
|
|
|
5913
6043
|
Object.defineProperty(stream$2, "__esModule", { value: true });
|
|
5914
|
-
const stream_1$5 = require$$0$
|
|
6044
|
+
const stream_1$5 = require$$0$4;
|
|
5915
6045
|
const async_1$3 = async$4;
|
|
5916
6046
|
class StreamProvider {
|
|
5917
6047
|
constructor(_root, _settings) {
|
|
@@ -6024,7 +6154,7 @@ sync$3.default = SyncProvider;
|
|
|
6024
6154
|
var settings$1 = {};
|
|
6025
6155
|
|
|
6026
6156
|
Object.defineProperty(settings$1, "__esModule", { value: true });
|
|
6027
|
-
const path$2 = require$$0$
|
|
6157
|
+
const path$2 = require$$0$2;
|
|
6028
6158
|
const fsScandir = out$2;
|
|
6029
6159
|
class Settings {
|
|
6030
6160
|
constructor(_options = {}) {
|
|
@@ -6086,7 +6216,7 @@ function getSettings(settingsOrOptions = {}) {
|
|
|
6086
6216
|
var reader = {};
|
|
6087
6217
|
|
|
6088
6218
|
Object.defineProperty(reader, "__esModule", { value: true });
|
|
6089
|
-
const path$1 = require$$0$
|
|
6219
|
+
const path$1 = require$$0$2;
|
|
6090
6220
|
const fsStat$2 = out$1;
|
|
6091
6221
|
const utils$6 = utils$k;
|
|
6092
6222
|
class Reader {
|
|
@@ -6121,7 +6251,7 @@ reader.default = Reader;
|
|
|
6121
6251
|
var stream$1 = {};
|
|
6122
6252
|
|
|
6123
6253
|
Object.defineProperty(stream$1, "__esModule", { value: true });
|
|
6124
|
-
const stream_1$3 = require$$0$
|
|
6254
|
+
const stream_1$3 = require$$0$4;
|
|
6125
6255
|
const fsStat$1 = out$1;
|
|
6126
6256
|
const fsWalk$2 = out$3;
|
|
6127
6257
|
const reader_1$2 = reader;
|
|
@@ -6474,7 +6604,7 @@ class EntryTransformer {
|
|
|
6474
6604
|
entry.default = EntryTransformer;
|
|
6475
6605
|
|
|
6476
6606
|
Object.defineProperty(provider, "__esModule", { value: true });
|
|
6477
|
-
const path = require$$0$
|
|
6607
|
+
const path = require$$0$2;
|
|
6478
6608
|
const deep_1 = deep;
|
|
6479
6609
|
const entry_1 = entry$1;
|
|
6480
6610
|
const error_1 = error;
|
|
@@ -6547,7 +6677,7 @@ async$7.default = ProviderAsync;
|
|
|
6547
6677
|
var stream = {};
|
|
6548
6678
|
|
|
6549
6679
|
Object.defineProperty(stream, "__esModule", { value: true });
|
|
6550
|
-
const stream_1$1 = require$$0$
|
|
6680
|
+
const stream_1$1 = require$$0$4;
|
|
6551
6681
|
const stream_2 = stream$1;
|
|
6552
6682
|
const provider_1$1 = provider;
|
|
6553
6683
|
class ProviderStream extends provider_1$1.default {
|
|
@@ -6652,8 +6782,8 @@ var settings = {};
|
|
|
6652
6782
|
(function (exports) {
|
|
6653
6783
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6654
6784
|
exports.DEFAULT_FILE_SYSTEM_ADAPTER = void 0;
|
|
6655
|
-
const fs = require$$0$
|
|
6656
|
-
const os = require$$0;
|
|
6785
|
+
const fs = require$$0$5;
|
|
6786
|
+
const os = require$$0$1;
|
|
6657
6787
|
/**
|
|
6658
6788
|
* The `os.cpus` method can return zero. We expect the number of cores to be greater than zero.
|
|
6659
6789
|
* https://github.com/nodejs/node/blob/7faeddf23a98c53896f8b574a6e66589e8fb1eb8/lib/os.js#L106-L107
|
|
@@ -6826,10 +6956,8 @@ function usePHP(cfg = {}) {
|
|
|
6826
6956
|
let config = void 0;
|
|
6827
6957
|
let viteServer = void 0;
|
|
6828
6958
|
let entries = Array.isArray(entry) ? entry : [entry];
|
|
6829
|
-
function
|
|
6830
|
-
|
|
6831
|
-
escapePHP(file, tempFile);
|
|
6832
|
-
return tempFile;
|
|
6959
|
+
function getTempFileName(file) {
|
|
6960
|
+
return `${tempDir}/${file}.html`;
|
|
6833
6961
|
}
|
|
6834
6962
|
function cleanupTemp(dir = "") {
|
|
6835
6963
|
const parentDir = dir ? dir + "/" : dir;
|
|
@@ -6869,7 +6997,7 @@ function usePHP(cfg = {}) {
|
|
|
6869
6997
|
ignore: [tempDir, config2.build?.outDir || "dist"]
|
|
6870
6998
|
})
|
|
6871
6999
|
);
|
|
6872
|
-
const inputs = entries.map(
|
|
7000
|
+
const inputs = entries.map(getTempFileName);
|
|
6873
7001
|
return {
|
|
6874
7002
|
build: {
|
|
6875
7003
|
rollupOptions: { input: inputs }
|
|
@@ -6879,6 +7007,13 @@ function usePHP(cfg = {}) {
|
|
|
6879
7007
|
},
|
|
6880
7008
|
configResolved(_config) {
|
|
6881
7009
|
config = _config;
|
|
7010
|
+
entries.forEach(
|
|
7011
|
+
(entry2) => escapePHP({
|
|
7012
|
+
inputFile: entry2,
|
|
7013
|
+
outputFile: getTempFileName(entry2),
|
|
7014
|
+
config
|
|
7015
|
+
})
|
|
7016
|
+
);
|
|
6882
7017
|
}
|
|
6883
7018
|
},
|
|
6884
7019
|
{
|
|
@@ -6912,7 +7047,7 @@ function usePHP(cfg = {}) {
|
|
|
6912
7047
|
return file === entryPathname || file.substring(0, file.lastIndexOf(".")) === entryPathname;
|
|
6913
7048
|
});
|
|
6914
7049
|
if (entry2) {
|
|
6915
|
-
const tempFile =
|
|
7050
|
+
const tempFile = getTempFileName(entry2);
|
|
6916
7051
|
if (existsSync(resolve(tempFile))) {
|
|
6917
7052
|
url.pathname = tempFile;
|
|
6918
7053
|
url.port = phpServer.port.toString();
|
|
@@ -6950,7 +7085,7 @@ function usePHP(cfg = {}) {
|
|
|
6950
7085
|
).on("error", reject).end();
|
|
6951
7086
|
});
|
|
6952
7087
|
const out = await server.transformIndexHtml(
|
|
6953
|
-
|
|
7088
|
+
"/" + entryPathname,
|
|
6954
7089
|
phpResult.content,
|
|
6955
7090
|
req.originalUrl
|
|
6956
7091
|
);
|
|
@@ -6973,7 +7108,11 @@ function usePHP(cfg = {}) {
|
|
|
6973
7108
|
(entryFile) => file.endsWith(entryFile) && resolve(entryFile) === file
|
|
6974
7109
|
);
|
|
6975
7110
|
if (entry2) {
|
|
6976
|
-
|
|
7111
|
+
escapePHP({
|
|
7112
|
+
inputFile: entry2,
|
|
7113
|
+
outputFile: getTempFileName(entry2),
|
|
7114
|
+
config
|
|
7115
|
+
});
|
|
6977
7116
|
server.ws.send({
|
|
6978
7117
|
type: "full-reload",
|
|
6979
7118
|
path: "*"
|
|
@@ -6992,10 +7131,11 @@ function usePHP(cfg = {}) {
|
|
|
6992
7131
|
closeBundle() {
|
|
6993
7132
|
const distDir = config?.build.outDir;
|
|
6994
7133
|
entries.forEach((file) => {
|
|
6995
|
-
const
|
|
6996
|
-
|
|
6997
|
-
`${
|
|
6998
|
-
|
|
7134
|
+
const tempFileName = getTempFileName(file);
|
|
7135
|
+
const code = unescapePHP({
|
|
7136
|
+
file: `${distDir}/${tempFileName}`,
|
|
7137
|
+
tokensFile: `${tempFileName}.json`
|
|
7138
|
+
});
|
|
6999
7139
|
writeFile(`${distDir}/${file}`, code);
|
|
7000
7140
|
});
|
|
7001
7141
|
cleanupTemp(distDir);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-php",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.40",
|
|
4
4
|
"description": "Process PHP-files with the speed and tools of Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/node": "^20.14.11",
|
|
62
62
|
"fast-glob": "^3.3.2",
|
|
63
|
+
"picocolors": "^1.0.1",
|
|
63
64
|
"typescript": "^5.5.3",
|
|
64
65
|
"unbuild": "^2.0.0",
|
|
65
66
|
"vite": "^5.3.4"
|