vite-plugin-php 3.0.0-beta.4 → 3.0.0-beta.5
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/LICENSE +0 -0
- package/README.md +4 -5
- package/dist/index.cjs +633 -589
- package/dist/index.d.cts +0 -0
- package/dist/index.d.mts +0 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.mjs +634 -590
- package/dist/router.php +21 -14
- package/package.json +6 -2
package/dist/index.cjs
CHANGED
|
@@ -8,14 +8,14 @@ const node_path = require('node:path');
|
|
|
8
8
|
const require$$1 = require('net');
|
|
9
9
|
const require$$0 = require('util');
|
|
10
10
|
const require$$0$1 = require('tty');
|
|
11
|
+
const node_fs = require('node:fs');
|
|
12
|
+
const vite = require('vite');
|
|
13
|
+
const http = require('node:http');
|
|
11
14
|
const require$$0$2 = require('os');
|
|
12
15
|
const require$$0$3 = require('path');
|
|
13
16
|
const require$$0$4 = require('stream');
|
|
14
17
|
const require$$0$6 = require('events');
|
|
15
18
|
const require$$0$5 = require('fs');
|
|
16
|
-
const node_fs = require('node:fs');
|
|
17
|
-
const vite = require('vite');
|
|
18
|
-
const http = require('node:http');
|
|
19
19
|
|
|
20
20
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
21
21
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
@@ -23,12 +23,12 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
23
23
|
const require$$1__default = /*#__PURE__*/_interopDefaultCompat(require$$1);
|
|
24
24
|
const require$$0__default = /*#__PURE__*/_interopDefaultCompat(require$$0);
|
|
25
25
|
const require$$0__default$1 = /*#__PURE__*/_interopDefaultCompat(require$$0$1);
|
|
26
|
+
const http__default = /*#__PURE__*/_interopDefaultCompat(http);
|
|
26
27
|
const require$$0__default$2 = /*#__PURE__*/_interopDefaultCompat(require$$0$2);
|
|
27
28
|
const require$$0__default$3 = /*#__PURE__*/_interopDefaultCompat(require$$0$3);
|
|
28
29
|
const require$$0__default$4 = /*#__PURE__*/_interopDefaultCompat(require$$0$4);
|
|
29
30
|
const require$$0__default$6 = /*#__PURE__*/_interopDefaultCompat(require$$0$6);
|
|
30
31
|
const require$$0__default$5 = /*#__PURE__*/_interopDefaultCompat(require$$0$5);
|
|
31
|
-
const http__default = /*#__PURE__*/_interopDefaultCompat(http);
|
|
32
32
|
|
|
33
33
|
const EPHPError = {
|
|
34
34
|
ERROR: 1,
|
|
@@ -57,7 +57,8 @@ const shared = {
|
|
|
57
57
|
cleanup: true,
|
|
58
58
|
errorLevels: EPHPError.ALL | EPHPError.STRICT
|
|
59
59
|
},
|
|
60
|
-
|
|
60
|
+
entryPatterns: ["index.php"],
|
|
61
|
+
entries: ["index.php"],
|
|
61
62
|
tempDir: ".php-tmp"
|
|
62
63
|
};
|
|
63
64
|
|
|
@@ -181,7 +182,7 @@ var picocolorsExports = /*@__PURE__*/ requirePicocolors();
|
|
|
181
182
|
const colors = /*@__PURE__*/getDefaultExportFromCjs(picocolorsExports);
|
|
182
183
|
|
|
183
184
|
function hasViteConfig(input) {
|
|
184
|
-
if (!input) {
|
|
185
|
+
if (!input || typeof input !== "object" || ["logger", "server"].some((key) => !(key in input))) {
|
|
185
186
|
throw new Error("Vite config not initialized!");
|
|
186
187
|
}
|
|
187
188
|
}
|
|
@@ -3339,203 +3340,529 @@ function stop(callBack) {
|
|
|
3339
3340
|
}
|
|
3340
3341
|
}
|
|
3341
3342
|
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
var utils$3 = {};
|
|
3345
|
-
|
|
3346
|
-
var array = {};
|
|
3347
|
-
|
|
3348
|
-
var hasRequiredArray;
|
|
3349
|
-
|
|
3350
|
-
function requireArray () {
|
|
3351
|
-
if (hasRequiredArray) return array;
|
|
3352
|
-
hasRequiredArray = 1;
|
|
3353
|
-
Object.defineProperty(array, "__esModule", { value: true });
|
|
3354
|
-
array.splitWhen = array.flatten = void 0;
|
|
3355
|
-
function flatten(items) {
|
|
3356
|
-
return items.reduce((collection, item) => [].concat(collection, item), []);
|
|
3357
|
-
}
|
|
3358
|
-
array.flatten = flatten;
|
|
3359
|
-
function splitWhen(items, predicate) {
|
|
3360
|
-
const result = [[]];
|
|
3361
|
-
let groupIndex = 0;
|
|
3362
|
-
for (const item of items) {
|
|
3363
|
-
if (predicate(item)) {
|
|
3364
|
-
groupIndex++;
|
|
3365
|
-
result[groupIndex] = [];
|
|
3366
|
-
}
|
|
3367
|
-
else {
|
|
3368
|
-
result[groupIndex].push(item);
|
|
3369
|
-
}
|
|
3370
|
-
}
|
|
3371
|
-
return result;
|
|
3372
|
-
}
|
|
3373
|
-
array.splitWhen = splitWhen;
|
|
3374
|
-
return array;
|
|
3343
|
+
function readFile(file) {
|
|
3344
|
+
return node_fs.readFileSync(file, "utf-8").toString();
|
|
3375
3345
|
}
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
var hasRequiredErrno;
|
|
3380
|
-
|
|
3381
|
-
function requireErrno () {
|
|
3382
|
-
if (hasRequiredErrno) return errno;
|
|
3383
|
-
hasRequiredErrno = 1;
|
|
3384
|
-
Object.defineProperty(errno, "__esModule", { value: true });
|
|
3385
|
-
errno.isEnoentCodeError = void 0;
|
|
3386
|
-
function isEnoentCodeError(error) {
|
|
3387
|
-
return error.code === 'ENOENT';
|
|
3388
|
-
}
|
|
3389
|
-
errno.isEnoentCodeError = isEnoentCodeError;
|
|
3390
|
-
return errno;
|
|
3346
|
+
function writeFile(file, data) {
|
|
3347
|
+
node_fs.mkdirSync(node_path.dirname(file), { recursive: true });
|
|
3348
|
+
node_fs.writeFileSync(file, data);
|
|
3391
3349
|
}
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
var hasRequiredFs$3;
|
|
3396
|
-
|
|
3397
|
-
function requireFs$3 () {
|
|
3398
|
-
if (hasRequiredFs$3) return fs$3;
|
|
3399
|
-
hasRequiredFs$3 = 1;
|
|
3400
|
-
Object.defineProperty(fs$3, "__esModule", { value: true });
|
|
3401
|
-
fs$3.createDirentFromStats = void 0;
|
|
3402
|
-
class DirentFromStats {
|
|
3403
|
-
constructor(name, stats) {
|
|
3404
|
-
this.name = name;
|
|
3405
|
-
this.isBlockDevice = stats.isBlockDevice.bind(stats);
|
|
3406
|
-
this.isCharacterDevice = stats.isCharacterDevice.bind(stats);
|
|
3407
|
-
this.isDirectory = stats.isDirectory.bind(stats);
|
|
3408
|
-
this.isFIFO = stats.isFIFO.bind(stats);
|
|
3409
|
-
this.isFile = stats.isFile.bind(stats);
|
|
3410
|
-
this.isSocket = stats.isSocket.bind(stats);
|
|
3411
|
-
this.isSymbolicLink = stats.isSymbolicLink.bind(stats);
|
|
3412
|
-
}
|
|
3413
|
-
}
|
|
3414
|
-
function createDirentFromStats(name, stats) {
|
|
3415
|
-
return new DirentFromStats(name, stats);
|
|
3416
|
-
}
|
|
3417
|
-
fs$3.createDirentFromStats = createDirentFromStats;
|
|
3418
|
-
return fs$3;
|
|
3350
|
+
function tempName(entry) {
|
|
3351
|
+
return `${shared.tempDir}/${entry}`;
|
|
3419
3352
|
}
|
|
3420
3353
|
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
var hasRequiredPath;
|
|
3424
|
-
|
|
3425
|
-
function requirePath () {
|
|
3426
|
-
if (hasRequiredPath) return path;
|
|
3427
|
-
hasRequiredPath = 1;
|
|
3428
|
-
Object.defineProperty(path, "__esModule", { value: true });
|
|
3429
|
-
path.convertPosixPathToPattern = path.convertWindowsPathToPattern = path.convertPathToPattern = path.escapePosixPath = path.escapeWindowsPath = path.escape = path.removeLeadingDotSegment = path.makeAbsolute = path.unixify = void 0;
|
|
3430
|
-
const os = require$$0__default$2;
|
|
3431
|
-
const path$1 = require$$0__default$3;
|
|
3432
|
-
const IS_WINDOWS_PLATFORM = os.platform() === 'win32';
|
|
3433
|
-
const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2; // ./ or .\\
|
|
3434
|
-
/**
|
|
3435
|
-
* All non-escaped special characters.
|
|
3436
|
-
* Posix: ()*?[]{|}, !+@ before (, ! at the beginning, \\ before non-special characters.
|
|
3437
|
-
* Windows: (){}[], !+@ before (, ! at the beginning.
|
|
3438
|
-
*/
|
|
3439
|
-
const POSIX_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\()|\\(?![!()*+?@[\]{|}]))/g;
|
|
3440
|
-
const WINDOWS_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()[\]{}]|^!|[!+@](?=\())/g;
|
|
3441
|
-
/**
|
|
3442
|
-
* The device path (\\.\ or \\?\).
|
|
3443
|
-
* https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#dos-device-paths
|
|
3444
|
-
*/
|
|
3445
|
-
const DOS_DEVICE_PATH_RE = /^\\\\([.?])/;
|
|
3446
|
-
/**
|
|
3447
|
-
* All backslashes except those escaping special characters.
|
|
3448
|
-
* Windows: !()+@{}
|
|
3449
|
-
* https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
|
|
3450
|
-
*/
|
|
3451
|
-
const WINDOWS_BACKSLASHES_RE = /\\(?![!()+@[\]{}])/g;
|
|
3452
|
-
/**
|
|
3453
|
-
* Designed to work only with simple paths: `dir\\file`.
|
|
3454
|
-
*/
|
|
3455
|
-
function unixify(filepath) {
|
|
3456
|
-
return filepath.replace(/\\/g, '/');
|
|
3457
|
-
}
|
|
3458
|
-
path.unixify = unixify;
|
|
3459
|
-
function makeAbsolute(cwd, filepath) {
|
|
3460
|
-
return path$1.resolve(cwd, filepath);
|
|
3461
|
-
}
|
|
3462
|
-
path.makeAbsolute = makeAbsolute;
|
|
3463
|
-
function removeLeadingDotSegment(entry) {
|
|
3464
|
-
// We do not use `startsWith` because this is 10x slower than current implementation for some cases.
|
|
3465
|
-
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
|
|
3466
|
-
if (entry.charAt(0) === '.') {
|
|
3467
|
-
const secondCharactery = entry.charAt(1);
|
|
3468
|
-
if (secondCharactery === '/' || secondCharactery === '\\') {
|
|
3469
|
-
return entry.slice(LEADING_DOT_SEGMENT_CHARACTERS_COUNT);
|
|
3470
|
-
}
|
|
3471
|
-
}
|
|
3472
|
-
return entry;
|
|
3473
|
-
}
|
|
3474
|
-
path.removeLeadingDotSegment = removeLeadingDotSegment;
|
|
3475
|
-
path.escape = IS_WINDOWS_PLATFORM ? escapeWindowsPath : escapePosixPath;
|
|
3476
|
-
function escapeWindowsPath(pattern) {
|
|
3477
|
-
return pattern.replace(WINDOWS_UNESCAPED_GLOB_SYMBOLS_RE, '\\$2');
|
|
3478
|
-
}
|
|
3479
|
-
path.escapeWindowsPath = escapeWindowsPath;
|
|
3480
|
-
function escapePosixPath(pattern) {
|
|
3481
|
-
return pattern.replace(POSIX_UNESCAPED_GLOB_SYMBOLS_RE, '\\$2');
|
|
3482
|
-
}
|
|
3483
|
-
path.escapePosixPath = escapePosixPath;
|
|
3484
|
-
path.convertPathToPattern = IS_WINDOWS_PLATFORM ? convertWindowsPathToPattern : convertPosixPathToPattern;
|
|
3485
|
-
function convertWindowsPathToPattern(filepath) {
|
|
3486
|
-
return escapeWindowsPath(filepath)
|
|
3487
|
-
.replace(DOS_DEVICE_PATH_RE, '//$1')
|
|
3488
|
-
.replace(WINDOWS_BACKSLASHES_RE, '/');
|
|
3489
|
-
}
|
|
3490
|
-
path.convertWindowsPathToPattern = convertWindowsPathToPattern;
|
|
3491
|
-
function convertPosixPathToPattern(filepath) {
|
|
3492
|
-
return escapePosixPath(filepath);
|
|
3493
|
-
}
|
|
3494
|
-
path.convertPosixPathToPattern = convertPosixPathToPattern;
|
|
3495
|
-
return path;
|
|
3354
|
+
function makeID() {
|
|
3355
|
+
return Date.now().toString(36) + Math.random() * 100;
|
|
3496
3356
|
}
|
|
3497
3357
|
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3358
|
+
function resolveEnvPrefix({ envPrefix = "VITE_" }) {
|
|
3359
|
+
envPrefix = Array.isArray(envPrefix) ? envPrefix : [envPrefix];
|
|
3360
|
+
if (envPrefix.includes("")) {
|
|
3361
|
+
throw new Error(
|
|
3362
|
+
`envPrefix option contains value '', which could lead unexpected exposure of sensitive information.`
|
|
3363
|
+
);
|
|
3364
|
+
}
|
|
3365
|
+
return envPrefix;
|
|
3366
|
+
}
|
|
3367
|
+
const envPattern = /%(\S+?)%/g;
|
|
3368
|
+
function initReplaceEnv() {
|
|
3369
|
+
hasViteConfig(shared.viteConfig);
|
|
3370
|
+
const { env, define, root, logger } = shared.viteConfig;
|
|
3371
|
+
const envPrefix = resolveEnvPrefix({
|
|
3372
|
+
envPrefix: shared.viteConfig.envPrefix
|
|
3373
|
+
});
|
|
3374
|
+
for (const key in define) {
|
|
3375
|
+
if (key.startsWith(`import.meta.env.`)) {
|
|
3376
|
+
const val = define[key];
|
|
3377
|
+
if (typeof val === "string") {
|
|
3378
|
+
try {
|
|
3379
|
+
const parsed = JSON.parse(val);
|
|
3380
|
+
env[key.slice(16)] = typeof parsed === "string" ? parsed : val;
|
|
3381
|
+
} catch {
|
|
3382
|
+
env[key.slice(16)] = val;
|
|
3383
|
+
}
|
|
3384
|
+
} else {
|
|
3385
|
+
env[key.slice(16)] = JSON.stringify(val);
|
|
3386
|
+
}
|
|
3387
|
+
}
|
|
3388
|
+
}
|
|
3389
|
+
return function replaceEnv(content, filename) {
|
|
3390
|
+
const relativeHtml = vite.normalizePath(node_path.relative(root, filename));
|
|
3391
|
+
return content.replace(envPattern, (text, key) => {
|
|
3392
|
+
if (key in env) {
|
|
3393
|
+
return env[key];
|
|
3394
|
+
} else {
|
|
3395
|
+
if (envPrefix.some((prefix) => key.startsWith(prefix))) {
|
|
3396
|
+
logger.warn(
|
|
3397
|
+
colors.yellow(
|
|
3398
|
+
colors.bold(
|
|
3399
|
+
`(!) ${text} is not defined in env variables found in /${relativeHtml}. Is the variable mistyped?`
|
|
3400
|
+
)
|
|
3401
|
+
)
|
|
3402
|
+
);
|
|
3403
|
+
}
|
|
3404
|
+
return text;
|
|
3405
|
+
}
|
|
3406
|
+
});
|
|
3407
|
+
};
|
|
3527
3408
|
}
|
|
3528
3409
|
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3410
|
+
const phpStartPattern = `<\\?(?:php|)`;
|
|
3411
|
+
const phpEndPattern = `\\?>`;
|
|
3412
|
+
const phpTagRegex = new RegExp(
|
|
3413
|
+
`${phpStartPattern}.+?(${phpEndPattern}|$)`,
|
|
3414
|
+
"gis"
|
|
3415
|
+
);
|
|
3416
|
+
class PHP_Code {
|
|
3417
|
+
file = "!!__VIRTUAL__!!.php";
|
|
3418
|
+
code;
|
|
3419
|
+
mapping = {};
|
|
3420
|
+
static fromFile(file) {
|
|
3421
|
+
const inst = new this(readFile(file));
|
|
3422
|
+
inst.file = file;
|
|
3423
|
+
return inst;
|
|
3424
|
+
}
|
|
3425
|
+
constructor(code) {
|
|
3426
|
+
this.code = code;
|
|
3427
|
+
return this;
|
|
3428
|
+
}
|
|
3429
|
+
applyEnv() {
|
|
3430
|
+
const replaceEnv = initReplaceEnv();
|
|
3431
|
+
this.code = replaceEnv(this.code, this.file || "");
|
|
3432
|
+
return this;
|
|
3433
|
+
}
|
|
3434
|
+
escape() {
|
|
3435
|
+
const isJS = this.file.includes(".js") || this.file.includes(".ts");
|
|
3436
|
+
const isML = this.file.includes(".php") || this.file.includes(".htm");
|
|
3437
|
+
this.code = this.code.replace(phpTagRegex, (match) => {
|
|
3438
|
+
let token = makeID();
|
|
3439
|
+
if (isJS) {
|
|
3440
|
+
token = `/*${token}*/`;
|
|
3441
|
+
} else if (isML) {
|
|
3442
|
+
token = `\u2400\u2400${token}\u2400\u2400`;
|
|
3443
|
+
}
|
|
3444
|
+
this.mapping[token] = match;
|
|
3445
|
+
return token;
|
|
3446
|
+
});
|
|
3447
|
+
return this;
|
|
3448
|
+
}
|
|
3449
|
+
write(file, mapping = false) {
|
|
3450
|
+
writeFile(file, this.code);
|
|
3451
|
+
mapping && writeFile(file + ".json", JSON.stringify(this.mapping));
|
|
3452
|
+
}
|
|
3453
|
+
static unescape(code, mapping) {
|
|
3454
|
+
let out = code;
|
|
3455
|
+
Object.entries(mapping).forEach(([token, code2]) => {
|
|
3456
|
+
out = out.replace(token, code2);
|
|
3457
|
+
});
|
|
3458
|
+
return out;
|
|
3459
|
+
}
|
|
3460
|
+
}
|
|
3461
|
+
|
|
3462
|
+
const exitSignals = [
|
|
3463
|
+
"exit",
|
|
3464
|
+
"SIGINT",
|
|
3465
|
+
"SIGUSR1",
|
|
3466
|
+
"SIGUSR2",
|
|
3467
|
+
"uncaughtException",
|
|
3468
|
+
"SIGTERM"
|
|
3469
|
+
];
|
|
3470
|
+
function exitHandler(signal) {
|
|
3471
|
+
if (signal === "SIGINT") {
|
|
3472
|
+
console.log();
|
|
3473
|
+
}
|
|
3474
|
+
const tempDir = node_path.resolve(shared.tempDir);
|
|
3475
|
+
if (shared.devConfig.cleanup && node_fs.existsSync(tempDir)) {
|
|
3476
|
+
log("Removing temporary files");
|
|
3477
|
+
node_fs.rmSync(tempDir, {
|
|
3478
|
+
recursive: true,
|
|
3479
|
+
force: true
|
|
3480
|
+
});
|
|
3481
|
+
}
|
|
3482
|
+
if (PHP_Server.process && shared.viteConfig?.command === "serve") {
|
|
3483
|
+
PHP_Server.stop(() => {
|
|
3484
|
+
process.exit();
|
|
3485
|
+
});
|
|
3486
|
+
} else {
|
|
3487
|
+
process.exit();
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
3491
|
+
const handleExit = {
|
|
3492
|
+
register() {
|
|
3493
|
+
exitSignals.forEach((eventType) => {
|
|
3494
|
+
new Promise((resolve2) => {
|
|
3495
|
+
listeners.set(eventType, resolve2);
|
|
3496
|
+
process.on(eventType, resolve2);
|
|
3497
|
+
}).then(exitHandler);
|
|
3498
|
+
});
|
|
3499
|
+
},
|
|
3500
|
+
unregister() {
|
|
3501
|
+
exitSignals.forEach((eventType) => {
|
|
3502
|
+
const listener = listeners.get(eventType);
|
|
3503
|
+
if (listener) {
|
|
3504
|
+
process.off(eventType, listener);
|
|
3505
|
+
listeners.delete(eventType);
|
|
3506
|
+
}
|
|
3507
|
+
});
|
|
3508
|
+
}
|
|
3509
|
+
};
|
|
3510
|
+
|
|
3511
|
+
const assetsPattern = new RegExp(
|
|
3512
|
+
`^(.+?)(${phpStartPattern}\\s+namespace\\s\\S+?(?:\\s*;|\\s*{).+)$`,
|
|
3513
|
+
"si"
|
|
3514
|
+
);
|
|
3515
|
+
const viteClientInjection = '<script type="module" src="/@vite/client"><\/script>\n';
|
|
3516
|
+
const viteClientInjectionPattern = new RegExp(
|
|
3517
|
+
'<script[^>]+?src="/@vite/client".+?<\/script>(\r\n|\n|\r)*',
|
|
3518
|
+
"si"
|
|
3519
|
+
);
|
|
3520
|
+
const lastTagPattern = new RegExp(`^(.+(?:</.+?>|<.+?/>))(.+|)$`, "si");
|
|
3521
|
+
const closingPattern = new RegExp(`^(.+)(${phpStartPattern}.+)$`, "si");
|
|
3522
|
+
function fixAssetsInjection(input) {
|
|
3523
|
+
let out = input;
|
|
3524
|
+
let assets = "";
|
|
3525
|
+
out = out.replace(assetsPattern, (match, p1, p2) => {
|
|
3526
|
+
assets = p1.trim();
|
|
3527
|
+
return p2;
|
|
3528
|
+
});
|
|
3529
|
+
const injectAssets = (_, part1, part2) => {
|
|
3530
|
+
let a = assets;
|
|
3531
|
+
if (!(part1.endsWith("\n") || part1.endsWith("\r"))) {
|
|
3532
|
+
a = "\r\n" + a;
|
|
3533
|
+
}
|
|
3534
|
+
if (!(part2.startsWith("\n") || part2.startsWith("\r"))) {
|
|
3535
|
+
a += "\r\n";
|
|
3536
|
+
}
|
|
3537
|
+
assets = "";
|
|
3538
|
+
return `${part1}${a}${part2}`;
|
|
3539
|
+
};
|
|
3540
|
+
if (assets) {
|
|
3541
|
+
out = out.replace(lastTagPattern, injectAssets);
|
|
3542
|
+
}
|
|
3543
|
+
if (assets) {
|
|
3544
|
+
out = out.replace(closingPattern, injectAssets);
|
|
3545
|
+
}
|
|
3546
|
+
if (assets) {
|
|
3547
|
+
out += assets;
|
|
3548
|
+
}
|
|
3549
|
+
return out;
|
|
3550
|
+
}
|
|
3551
|
+
|
|
3552
|
+
const phpProxy = async (req, res, next) => {
|
|
3553
|
+
try {
|
|
3554
|
+
if (req.url && !["/@vite", "/@fs", "/@id/__x00__", "/node_modules"].some(
|
|
3555
|
+
(path) => req.url.startsWith(path)
|
|
3556
|
+
)) {
|
|
3557
|
+
req.on("error", (error) => {
|
|
3558
|
+
throw error;
|
|
3559
|
+
});
|
|
3560
|
+
let url = new URL(req.url, "http://localhost");
|
|
3561
|
+
if (shared.viteConfig?.server.port) {
|
|
3562
|
+
url.port = shared.viteConfig.server.port.toString();
|
|
3563
|
+
}
|
|
3564
|
+
const requestUrl = new URL(url);
|
|
3565
|
+
if (url.pathname.endsWith("/")) {
|
|
3566
|
+
url.pathname += "index.php";
|
|
3567
|
+
}
|
|
3568
|
+
const routedUrl = serve.rewriteUrl(url);
|
|
3569
|
+
if (routedUrl) {
|
|
3570
|
+
if (routedUrl.origin !== requestUrl.origin) {
|
|
3571
|
+
res.writeHead(307, {
|
|
3572
|
+
location: routedUrl.toString()
|
|
3573
|
+
}).end();
|
|
3574
|
+
return;
|
|
3575
|
+
}
|
|
3576
|
+
url = routedUrl;
|
|
3577
|
+
}
|
|
3578
|
+
const entryPathname = url.pathname.substring(1);
|
|
3579
|
+
const entry = shared.entries.find((file) => {
|
|
3580
|
+
return file === entryPathname || file.substring(0, file.lastIndexOf(".")) === entryPathname;
|
|
3581
|
+
});
|
|
3582
|
+
if (entry) {
|
|
3583
|
+
const tempFile = tempName(entry);
|
|
3584
|
+
if (node_fs.existsSync(node_path.resolve(tempFile))) {
|
|
3585
|
+
url.pathname = tempFile;
|
|
3586
|
+
url.host = PHP_Server.host;
|
|
3587
|
+
url.port = PHP_Server.port.toString();
|
|
3588
|
+
url.searchParams.set(
|
|
3589
|
+
internalParam,
|
|
3590
|
+
new URLSearchParams({
|
|
3591
|
+
$REQUEST_URI: requestUrl.pathname,
|
|
3592
|
+
$PHP_SELF: "/" + entry,
|
|
3593
|
+
temp_dir: shared.tempDir,
|
|
3594
|
+
error_levels: shared.devConfig.errorLevels.toString()
|
|
3595
|
+
}).toString()
|
|
3596
|
+
);
|
|
3597
|
+
const body = await new Promise(
|
|
3598
|
+
(resolve2, reject) => {
|
|
3599
|
+
let data = [];
|
|
3600
|
+
req.on("data", (chunk) => {
|
|
3601
|
+
data.push(chunk);
|
|
3602
|
+
}).on("end", () => {
|
|
3603
|
+
resolve2(Buffer.concat(data));
|
|
3604
|
+
});
|
|
3605
|
+
}
|
|
3606
|
+
);
|
|
3607
|
+
const phpResult = await new Promise(async (resolve2, reject) => {
|
|
3608
|
+
const chunks = [];
|
|
3609
|
+
let statusCode;
|
|
3610
|
+
let incomingHeaders = {};
|
|
3611
|
+
const request = http__default.request(
|
|
3612
|
+
url.toString(),
|
|
3613
|
+
{
|
|
3614
|
+
method: req.method,
|
|
3615
|
+
headers: {
|
|
3616
|
+
...req.headers,
|
|
3617
|
+
"content-length": Buffer.byteLength(body)
|
|
3618
|
+
}
|
|
3619
|
+
},
|
|
3620
|
+
(msg) => {
|
|
3621
|
+
statusCode = msg.statusCode;
|
|
3622
|
+
incomingHeaders = msg.headers;
|
|
3623
|
+
msg.on("data", (data) => {
|
|
3624
|
+
chunks.push(data);
|
|
3625
|
+
});
|
|
3626
|
+
}
|
|
3627
|
+
).on("error", (error) => {
|
|
3628
|
+
reject(error);
|
|
3629
|
+
}).on("close", () => {
|
|
3630
|
+
let content = Buffer.concat(chunks).toString("utf8");
|
|
3631
|
+
if (incomingHeaders["content-type"]?.includes(
|
|
3632
|
+
"text/html"
|
|
3633
|
+
) && content.includes("</head>") && !viteClientInjectionPattern.test(content)) {
|
|
3634
|
+
content = content.replace(
|
|
3635
|
+
"</head>",
|
|
3636
|
+
`${viteClientInjection}</head>`
|
|
3637
|
+
);
|
|
3638
|
+
if (incomingHeaders["content-length"]) {
|
|
3639
|
+
incomingHeaders["content-length"] = `${content.length}`;
|
|
3640
|
+
}
|
|
3641
|
+
}
|
|
3642
|
+
resolve2({
|
|
3643
|
+
statusCode,
|
|
3644
|
+
headers: incomingHeaders,
|
|
3645
|
+
content
|
|
3646
|
+
});
|
|
3647
|
+
});
|
|
3648
|
+
request.write(body, (error) => {
|
|
3649
|
+
if (error) {
|
|
3650
|
+
reject(error);
|
|
3651
|
+
}
|
|
3652
|
+
});
|
|
3653
|
+
request.end();
|
|
3654
|
+
});
|
|
3655
|
+
res.writeHead(
|
|
3656
|
+
phpResult.statusCode || 200,
|
|
3657
|
+
phpResult.headers
|
|
3658
|
+
).end(phpResult.content);
|
|
3659
|
+
return;
|
|
3660
|
+
}
|
|
3661
|
+
}
|
|
3662
|
+
}
|
|
3663
|
+
} catch (error) {
|
|
3664
|
+
console.error("Vite-PHP Error: " + error);
|
|
3665
|
+
}
|
|
3666
|
+
next();
|
|
3667
|
+
};
|
|
3668
|
+
|
|
3669
|
+
var tasks = {};
|
|
3670
|
+
|
|
3671
|
+
var utils$3 = {};
|
|
3672
|
+
|
|
3673
|
+
var array = {};
|
|
3674
|
+
|
|
3675
|
+
var hasRequiredArray;
|
|
3676
|
+
|
|
3677
|
+
function requireArray () {
|
|
3678
|
+
if (hasRequiredArray) return array;
|
|
3679
|
+
hasRequiredArray = 1;
|
|
3680
|
+
Object.defineProperty(array, "__esModule", { value: true });
|
|
3681
|
+
array.splitWhen = array.flatten = void 0;
|
|
3682
|
+
function flatten(items) {
|
|
3683
|
+
return items.reduce((collection, item) => [].concat(collection, item), []);
|
|
3684
|
+
}
|
|
3685
|
+
array.flatten = flatten;
|
|
3686
|
+
function splitWhen(items, predicate) {
|
|
3687
|
+
const result = [[]];
|
|
3688
|
+
let groupIndex = 0;
|
|
3689
|
+
for (const item of items) {
|
|
3690
|
+
if (predicate(item)) {
|
|
3691
|
+
groupIndex++;
|
|
3692
|
+
result[groupIndex] = [];
|
|
3693
|
+
}
|
|
3694
|
+
else {
|
|
3695
|
+
result[groupIndex].push(item);
|
|
3696
|
+
}
|
|
3697
|
+
}
|
|
3698
|
+
return result;
|
|
3699
|
+
}
|
|
3700
|
+
array.splitWhen = splitWhen;
|
|
3701
|
+
return array;
|
|
3702
|
+
}
|
|
3703
|
+
|
|
3704
|
+
var errno = {};
|
|
3705
|
+
|
|
3706
|
+
var hasRequiredErrno;
|
|
3707
|
+
|
|
3708
|
+
function requireErrno () {
|
|
3709
|
+
if (hasRequiredErrno) return errno;
|
|
3710
|
+
hasRequiredErrno = 1;
|
|
3711
|
+
Object.defineProperty(errno, "__esModule", { value: true });
|
|
3712
|
+
errno.isEnoentCodeError = void 0;
|
|
3713
|
+
function isEnoentCodeError(error) {
|
|
3714
|
+
return error.code === 'ENOENT';
|
|
3715
|
+
}
|
|
3716
|
+
errno.isEnoentCodeError = isEnoentCodeError;
|
|
3717
|
+
return errno;
|
|
3718
|
+
}
|
|
3719
|
+
|
|
3720
|
+
var fs$3 = {};
|
|
3721
|
+
|
|
3722
|
+
var hasRequiredFs$3;
|
|
3723
|
+
|
|
3724
|
+
function requireFs$3 () {
|
|
3725
|
+
if (hasRequiredFs$3) return fs$3;
|
|
3726
|
+
hasRequiredFs$3 = 1;
|
|
3727
|
+
Object.defineProperty(fs$3, "__esModule", { value: true });
|
|
3728
|
+
fs$3.createDirentFromStats = void 0;
|
|
3729
|
+
class DirentFromStats {
|
|
3730
|
+
constructor(name, stats) {
|
|
3731
|
+
this.name = name;
|
|
3732
|
+
this.isBlockDevice = stats.isBlockDevice.bind(stats);
|
|
3733
|
+
this.isCharacterDevice = stats.isCharacterDevice.bind(stats);
|
|
3734
|
+
this.isDirectory = stats.isDirectory.bind(stats);
|
|
3735
|
+
this.isFIFO = stats.isFIFO.bind(stats);
|
|
3736
|
+
this.isFile = stats.isFile.bind(stats);
|
|
3737
|
+
this.isSocket = stats.isSocket.bind(stats);
|
|
3738
|
+
this.isSymbolicLink = stats.isSymbolicLink.bind(stats);
|
|
3739
|
+
}
|
|
3740
|
+
}
|
|
3741
|
+
function createDirentFromStats(name, stats) {
|
|
3742
|
+
return new DirentFromStats(name, stats);
|
|
3743
|
+
}
|
|
3744
|
+
fs$3.createDirentFromStats = createDirentFromStats;
|
|
3745
|
+
return fs$3;
|
|
3746
|
+
}
|
|
3747
|
+
|
|
3748
|
+
var path = {};
|
|
3749
|
+
|
|
3750
|
+
var hasRequiredPath;
|
|
3751
|
+
|
|
3752
|
+
function requirePath () {
|
|
3753
|
+
if (hasRequiredPath) return path;
|
|
3754
|
+
hasRequiredPath = 1;
|
|
3755
|
+
Object.defineProperty(path, "__esModule", { value: true });
|
|
3756
|
+
path.convertPosixPathToPattern = path.convertWindowsPathToPattern = path.convertPathToPattern = path.escapePosixPath = path.escapeWindowsPath = path.escape = path.removeLeadingDotSegment = path.makeAbsolute = path.unixify = void 0;
|
|
3757
|
+
const os = require$$0__default$2;
|
|
3758
|
+
const path$1 = require$$0__default$3;
|
|
3759
|
+
const IS_WINDOWS_PLATFORM = os.platform() === 'win32';
|
|
3760
|
+
const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2; // ./ or .\\
|
|
3761
|
+
/**
|
|
3762
|
+
* All non-escaped special characters.
|
|
3763
|
+
* Posix: ()*?[]{|}, !+@ before (, ! at the beginning, \\ before non-special characters.
|
|
3764
|
+
* Windows: (){}[], !+@ before (, ! at the beginning.
|
|
3765
|
+
*/
|
|
3766
|
+
const POSIX_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\()|\\(?![!()*+?@[\]{|}]))/g;
|
|
3767
|
+
const WINDOWS_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()[\]{}]|^!|[!+@](?=\())/g;
|
|
3768
|
+
/**
|
|
3769
|
+
* The device path (\\.\ or \\?\).
|
|
3770
|
+
* https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#dos-device-paths
|
|
3771
|
+
*/
|
|
3772
|
+
const DOS_DEVICE_PATH_RE = /^\\\\([.?])/;
|
|
3773
|
+
/**
|
|
3774
|
+
* All backslashes except those escaping special characters.
|
|
3775
|
+
* Windows: !()+@{}
|
|
3776
|
+
* https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
|
|
3777
|
+
*/
|
|
3778
|
+
const WINDOWS_BACKSLASHES_RE = /\\(?![!()+@[\]{}])/g;
|
|
3779
|
+
/**
|
|
3780
|
+
* Designed to work only with simple paths: `dir\\file`.
|
|
3781
|
+
*/
|
|
3782
|
+
function unixify(filepath) {
|
|
3783
|
+
return filepath.replace(/\\/g, '/');
|
|
3784
|
+
}
|
|
3785
|
+
path.unixify = unixify;
|
|
3786
|
+
function makeAbsolute(cwd, filepath) {
|
|
3787
|
+
return path$1.resolve(cwd, filepath);
|
|
3788
|
+
}
|
|
3789
|
+
path.makeAbsolute = makeAbsolute;
|
|
3790
|
+
function removeLeadingDotSegment(entry) {
|
|
3791
|
+
// We do not use `startsWith` because this is 10x slower than current implementation for some cases.
|
|
3792
|
+
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
|
|
3793
|
+
if (entry.charAt(0) === '.') {
|
|
3794
|
+
const secondCharactery = entry.charAt(1);
|
|
3795
|
+
if (secondCharactery === '/' || secondCharactery === '\\') {
|
|
3796
|
+
return entry.slice(LEADING_DOT_SEGMENT_CHARACTERS_COUNT);
|
|
3797
|
+
}
|
|
3798
|
+
}
|
|
3799
|
+
return entry;
|
|
3800
|
+
}
|
|
3801
|
+
path.removeLeadingDotSegment = removeLeadingDotSegment;
|
|
3802
|
+
path.escape = IS_WINDOWS_PLATFORM ? escapeWindowsPath : escapePosixPath;
|
|
3803
|
+
function escapeWindowsPath(pattern) {
|
|
3804
|
+
return pattern.replace(WINDOWS_UNESCAPED_GLOB_SYMBOLS_RE, '\\$2');
|
|
3805
|
+
}
|
|
3806
|
+
path.escapeWindowsPath = escapeWindowsPath;
|
|
3807
|
+
function escapePosixPath(pattern) {
|
|
3808
|
+
return pattern.replace(POSIX_UNESCAPED_GLOB_SYMBOLS_RE, '\\$2');
|
|
3809
|
+
}
|
|
3810
|
+
path.escapePosixPath = escapePosixPath;
|
|
3811
|
+
path.convertPathToPattern = IS_WINDOWS_PLATFORM ? convertWindowsPathToPattern : convertPosixPathToPattern;
|
|
3812
|
+
function convertWindowsPathToPattern(filepath) {
|
|
3813
|
+
return escapeWindowsPath(filepath)
|
|
3814
|
+
.replace(DOS_DEVICE_PATH_RE, '//$1')
|
|
3815
|
+
.replace(WINDOWS_BACKSLASHES_RE, '/');
|
|
3816
|
+
}
|
|
3817
|
+
path.convertWindowsPathToPattern = convertWindowsPathToPattern;
|
|
3818
|
+
function convertPosixPathToPattern(filepath) {
|
|
3819
|
+
return escapePosixPath(filepath);
|
|
3820
|
+
}
|
|
3821
|
+
path.convertPosixPathToPattern = convertPosixPathToPattern;
|
|
3822
|
+
return path;
|
|
3823
|
+
}
|
|
3824
|
+
|
|
3825
|
+
var pattern = {};
|
|
3826
|
+
|
|
3827
|
+
/*!
|
|
3828
|
+
* is-extglob <https://github.com/jonschlinkert/is-extglob>
|
|
3829
|
+
*
|
|
3830
|
+
* Copyright (c) 2014-2016, Jon Schlinkert.
|
|
3831
|
+
* Licensed under the MIT License.
|
|
3832
|
+
*/
|
|
3833
|
+
|
|
3834
|
+
var isExtglob;
|
|
3835
|
+
var hasRequiredIsExtglob;
|
|
3836
|
+
|
|
3837
|
+
function requireIsExtglob () {
|
|
3838
|
+
if (hasRequiredIsExtglob) return isExtglob;
|
|
3839
|
+
hasRequiredIsExtglob = 1;
|
|
3840
|
+
isExtglob = function isExtglob(str) {
|
|
3841
|
+
if (typeof str !== 'string' || str === '') {
|
|
3842
|
+
return false;
|
|
3843
|
+
}
|
|
3844
|
+
|
|
3845
|
+
var match;
|
|
3846
|
+
while ((match = /(\\).|([@?!+*]\(.*\))/g.exec(str))) {
|
|
3847
|
+
if (match[2]) return true;
|
|
3848
|
+
str = str.slice(match.index + match[0].length);
|
|
3849
|
+
}
|
|
3850
|
+
|
|
3851
|
+
return false;
|
|
3852
|
+
};
|
|
3853
|
+
return isExtglob;
|
|
3854
|
+
}
|
|
3855
|
+
|
|
3856
|
+
/*!
|
|
3857
|
+
* is-glob <https://github.com/jonschlinkert/is-glob>
|
|
3858
|
+
*
|
|
3859
|
+
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
3860
|
+
* Released under the MIT License.
|
|
3861
|
+
*/
|
|
3862
|
+
|
|
3863
|
+
var isGlob;
|
|
3864
|
+
var hasRequiredIsGlob;
|
|
3865
|
+
|
|
3539
3866
|
function requireIsGlob () {
|
|
3540
3867
|
if (hasRequiredIsGlob) return isGlob;
|
|
3541
3868
|
hasRequiredIsGlob = 1;
|
|
@@ -10624,377 +10951,80 @@ function requireOut () {
|
|
|
10624
10951
|
(function (posix) {
|
|
10625
10952
|
function escapePath(source) {
|
|
10626
10953
|
assertPatternsInput(source);
|
|
10627
|
-
return utils.path.escapePosixPath(source);
|
|
10628
|
-
}
|
|
10629
|
-
posix.escapePath = escapePath;
|
|
10630
|
-
function convertPathToPattern(source) {
|
|
10631
|
-
assertPatternsInput(source);
|
|
10632
|
-
return utils.path.convertPosixPathToPattern(source);
|
|
10633
|
-
}
|
|
10634
|
-
posix.convertPathToPattern = convertPathToPattern;
|
|
10635
|
-
})(FastGlob.posix || (FastGlob.posix = {}));
|
|
10636
|
-
(function (win32) {
|
|
10637
|
-
function escapePath(source) {
|
|
10638
|
-
assertPatternsInput(source);
|
|
10639
|
-
return utils.path.escapeWindowsPath(source);
|
|
10640
|
-
}
|
|
10641
|
-
win32.escapePath = escapePath;
|
|
10642
|
-
function convertPathToPattern(source) {
|
|
10643
|
-
assertPatternsInput(source);
|
|
10644
|
-
return utils.path.convertWindowsPathToPattern(source);
|
|
10645
|
-
}
|
|
10646
|
-
win32.convertPathToPattern = convertPathToPattern;
|
|
10647
|
-
})(FastGlob.win32 || (FastGlob.win32 = {}));
|
|
10648
|
-
})(FastGlob || (FastGlob = {}));
|
|
10649
|
-
function getWorks(source, _Provider, options) {
|
|
10650
|
-
const patterns = [].concat(source);
|
|
10651
|
-
const settings = new settings_1.default(options);
|
|
10652
|
-
const tasks = taskManager.generate(patterns, settings);
|
|
10653
|
-
const provider = new _Provider(settings);
|
|
10654
|
-
return tasks.map(provider.read, provider);
|
|
10655
|
-
}
|
|
10656
|
-
function assertPatternsInput(input) {
|
|
10657
|
-
const source = [].concat(input);
|
|
10658
|
-
const isValidSource = source.every((item) => utils.string.isString(item) && !utils.string.isEmpty(item));
|
|
10659
|
-
if (!isValidSource) {
|
|
10660
|
-
throw new TypeError('Patterns must be a string (non empty) or an array of strings');
|
|
10661
|
-
}
|
|
10662
|
-
}
|
|
10663
|
-
out = FastGlob;
|
|
10664
|
-
return out;
|
|
10665
|
-
}
|
|
10666
|
-
|
|
10667
|
-
var outExports = requireOut();
|
|
10668
|
-
const fastGlob = /*@__PURE__*/getDefaultExportFromCjs(outExports);
|
|
10669
|
-
|
|
10670
|
-
function readFile(file) {
|
|
10671
|
-
return node_fs.readFileSync(file, "utf-8").toString();
|
|
10672
|
-
}
|
|
10673
|
-
function writeFile(file, data) {
|
|
10674
|
-
node_fs.mkdirSync(node_path.dirname(file), { recursive: true });
|
|
10675
|
-
node_fs.writeFileSync(file, data);
|
|
10676
|
-
}
|
|
10677
|
-
function tempName(entry) {
|
|
10678
|
-
return `${shared.tempDir}/${entry}`;
|
|
10679
|
-
}
|
|
10680
|
-
|
|
10681
|
-
function makeID() {
|
|
10682
|
-
return Date.now().toString(36) + Math.random() * 100;
|
|
10683
|
-
}
|
|
10684
|
-
|
|
10685
|
-
function resolveEnvPrefix({ envPrefix = "VITE_" }) {
|
|
10686
|
-
envPrefix = Array.isArray(envPrefix) ? envPrefix : [envPrefix];
|
|
10687
|
-
if (envPrefix.includes("")) {
|
|
10688
|
-
throw new Error(
|
|
10689
|
-
`envPrefix option contains value '', which could lead unexpected exposure of sensitive information.`
|
|
10690
|
-
);
|
|
10691
|
-
}
|
|
10692
|
-
return envPrefix;
|
|
10693
|
-
}
|
|
10694
|
-
const envPattern = /%(\S+?)%/g;
|
|
10695
|
-
function initReplaceEnv() {
|
|
10696
|
-
hasViteConfig(shared.viteConfig);
|
|
10697
|
-
const { env, define, root, logger } = shared.viteConfig;
|
|
10698
|
-
const envPrefix = resolveEnvPrefix({
|
|
10699
|
-
envPrefix: shared.viteConfig.envPrefix
|
|
10700
|
-
});
|
|
10701
|
-
for (const key in define) {
|
|
10702
|
-
if (key.startsWith(`import.meta.env.`)) {
|
|
10703
|
-
const val = define[key];
|
|
10704
|
-
if (typeof val === "string") {
|
|
10705
|
-
try {
|
|
10706
|
-
const parsed = JSON.parse(val);
|
|
10707
|
-
env[key.slice(16)] = typeof parsed === "string" ? parsed : val;
|
|
10708
|
-
} catch {
|
|
10709
|
-
env[key.slice(16)] = val;
|
|
10710
|
-
}
|
|
10711
|
-
} else {
|
|
10712
|
-
env[key.slice(16)] = JSON.stringify(val);
|
|
10713
|
-
}
|
|
10714
|
-
}
|
|
10715
|
-
}
|
|
10716
|
-
return function replaceEnv(content, filename) {
|
|
10717
|
-
const relativeHtml = vite.normalizePath(node_path.relative(root, filename));
|
|
10718
|
-
return content.replace(envPattern, (text, key) => {
|
|
10719
|
-
if (key in env) {
|
|
10720
|
-
return env[key];
|
|
10721
|
-
} else {
|
|
10722
|
-
if (envPrefix.some((prefix) => key.startsWith(prefix))) {
|
|
10723
|
-
logger.warn(
|
|
10724
|
-
colors.yellow(
|
|
10725
|
-
colors.bold(
|
|
10726
|
-
`(!) ${text} is not defined in env variables found in /${relativeHtml}. Is the variable mistyped?`
|
|
10727
|
-
)
|
|
10728
|
-
)
|
|
10729
|
-
);
|
|
10730
|
-
}
|
|
10731
|
-
return text;
|
|
10732
|
-
}
|
|
10733
|
-
});
|
|
10734
|
-
};
|
|
10735
|
-
}
|
|
10736
|
-
|
|
10737
|
-
const phpStartPattern = `<\\?(?:php|)`;
|
|
10738
|
-
const phpEndPattern = `\\?>`;
|
|
10739
|
-
const phpTagRegex = new RegExp(
|
|
10740
|
-
`${phpStartPattern}.+?(${phpEndPattern}|$)`,
|
|
10741
|
-
"gis"
|
|
10742
|
-
);
|
|
10743
|
-
class PHP_Code {
|
|
10744
|
-
file = "!!__VIRTUAL__!!.php";
|
|
10745
|
-
code;
|
|
10746
|
-
mapping = {};
|
|
10747
|
-
static fromFile(file) {
|
|
10748
|
-
const inst = new this(readFile(file));
|
|
10749
|
-
inst.file = file;
|
|
10750
|
-
return inst;
|
|
10751
|
-
}
|
|
10752
|
-
constructor(code) {
|
|
10753
|
-
this.code = code;
|
|
10754
|
-
return this;
|
|
10755
|
-
}
|
|
10756
|
-
applyEnv() {
|
|
10757
|
-
const replaceEnv = initReplaceEnv();
|
|
10758
|
-
this.code = replaceEnv(this.code, this.file || "");
|
|
10759
|
-
return this;
|
|
10760
|
-
}
|
|
10761
|
-
escape() {
|
|
10762
|
-
const isJS = this.file.includes(".js") || this.file.includes(".ts");
|
|
10763
|
-
const isML = this.file.includes(".php") || this.file.includes(".htm");
|
|
10764
|
-
this.code = this.code.replace(phpTagRegex, (match) => {
|
|
10765
|
-
let token = makeID();
|
|
10766
|
-
if (isJS) {
|
|
10767
|
-
token = `/*${token}*/`;
|
|
10768
|
-
} else if (isML) {
|
|
10769
|
-
token = `\u2400\u2400${token}\u2400\u2400`;
|
|
10770
|
-
}
|
|
10771
|
-
this.mapping[token] = match;
|
|
10772
|
-
return token;
|
|
10773
|
-
});
|
|
10774
|
-
return this;
|
|
10775
|
-
}
|
|
10776
|
-
write(file, mapping = false) {
|
|
10777
|
-
writeFile(file, this.code);
|
|
10778
|
-
mapping && writeFile(file + ".json", JSON.stringify(this.mapping));
|
|
10779
|
-
}
|
|
10780
|
-
static unescape(code, mapping) {
|
|
10781
|
-
let out = code;
|
|
10782
|
-
Object.entries(mapping).forEach(([token, code2]) => {
|
|
10783
|
-
out = out.replace(token, code2);
|
|
10784
|
-
});
|
|
10785
|
-
return out;
|
|
10786
|
-
}
|
|
10954
|
+
return utils.path.escapePosixPath(source);
|
|
10955
|
+
}
|
|
10956
|
+
posix.escapePath = escapePath;
|
|
10957
|
+
function convertPathToPattern(source) {
|
|
10958
|
+
assertPatternsInput(source);
|
|
10959
|
+
return utils.path.convertPosixPathToPattern(source);
|
|
10960
|
+
}
|
|
10961
|
+
posix.convertPathToPattern = convertPathToPattern;
|
|
10962
|
+
})(FastGlob.posix || (FastGlob.posix = {}));
|
|
10963
|
+
(function (win32) {
|
|
10964
|
+
function escapePath(source) {
|
|
10965
|
+
assertPatternsInput(source);
|
|
10966
|
+
return utils.path.escapeWindowsPath(source);
|
|
10967
|
+
}
|
|
10968
|
+
win32.escapePath = escapePath;
|
|
10969
|
+
function convertPathToPattern(source) {
|
|
10970
|
+
assertPatternsInput(source);
|
|
10971
|
+
return utils.path.convertWindowsPathToPattern(source);
|
|
10972
|
+
}
|
|
10973
|
+
win32.convertPathToPattern = convertPathToPattern;
|
|
10974
|
+
})(FastGlob.win32 || (FastGlob.win32 = {}));
|
|
10975
|
+
})(FastGlob || (FastGlob = {}));
|
|
10976
|
+
function getWorks(source, _Provider, options) {
|
|
10977
|
+
const patterns = [].concat(source);
|
|
10978
|
+
const settings = new settings_1.default(options);
|
|
10979
|
+
const tasks = taskManager.generate(patterns, settings);
|
|
10980
|
+
const provider = new _Provider(settings);
|
|
10981
|
+
return tasks.map(provider.read, provider);
|
|
10982
|
+
}
|
|
10983
|
+
function assertPatternsInput(input) {
|
|
10984
|
+
const source = [].concat(input);
|
|
10985
|
+
const isValidSource = source.every((item) => utils.string.isString(item) && !utils.string.isEmpty(item));
|
|
10986
|
+
if (!isValidSource) {
|
|
10987
|
+
throw new TypeError('Patterns must be a string (non empty) or an array of strings');
|
|
10988
|
+
}
|
|
10989
|
+
}
|
|
10990
|
+
out = FastGlob;
|
|
10991
|
+
return out;
|
|
10787
10992
|
}
|
|
10788
10993
|
|
|
10789
|
-
|
|
10790
|
-
|
|
10791
|
-
"SIGINT",
|
|
10792
|
-
"SIGUSR1",
|
|
10793
|
-
"SIGUSR2",
|
|
10794
|
-
"uncaughtException",
|
|
10795
|
-
"SIGTERM"
|
|
10796
|
-
];
|
|
10797
|
-
function exitHandler(signal) {
|
|
10798
|
-
if (signal === "SIGINT") {
|
|
10799
|
-
console.log();
|
|
10800
|
-
}
|
|
10801
|
-
const tempDir = node_path.resolve(shared.tempDir);
|
|
10802
|
-
if (shared.devConfig.cleanup && node_fs.existsSync(tempDir)) {
|
|
10803
|
-
log("Removing temporary files");
|
|
10804
|
-
node_fs.rmSync(tempDir, {
|
|
10805
|
-
recursive: true,
|
|
10806
|
-
force: true
|
|
10807
|
-
});
|
|
10808
|
-
}
|
|
10809
|
-
if (PHP_Server.process && shared.viteConfig?.command === "serve") {
|
|
10810
|
-
PHP_Server.stop(() => {
|
|
10811
|
-
process.exit();
|
|
10812
|
-
});
|
|
10813
|
-
} else {
|
|
10814
|
-
process.exit();
|
|
10815
|
-
}
|
|
10816
|
-
}
|
|
10817
|
-
const listeners = /* @__PURE__ */ new Map();
|
|
10818
|
-
const handleExit = {
|
|
10819
|
-
register() {
|
|
10820
|
-
exitSignals.forEach((eventType) => {
|
|
10821
|
-
new Promise((resolve2) => {
|
|
10822
|
-
listeners.set(eventType, resolve2);
|
|
10823
|
-
process.on(eventType, resolve2);
|
|
10824
|
-
}).then(exitHandler);
|
|
10825
|
-
});
|
|
10826
|
-
},
|
|
10827
|
-
unregister() {
|
|
10828
|
-
exitSignals.forEach((eventType) => {
|
|
10829
|
-
const listener = listeners.get(eventType);
|
|
10830
|
-
if (listener) {
|
|
10831
|
-
process.off(eventType, listener);
|
|
10832
|
-
listeners.delete(eventType);
|
|
10833
|
-
}
|
|
10834
|
-
});
|
|
10835
|
-
}
|
|
10836
|
-
};
|
|
10994
|
+
var outExports = requireOut();
|
|
10995
|
+
const FastGlob = /*@__PURE__*/getDefaultExportFromCjs(outExports);
|
|
10837
10996
|
|
|
10838
|
-
|
|
10839
|
-
|
|
10840
|
-
|
|
10841
|
-
|
|
10842
|
-
|
|
10843
|
-
|
|
10844
|
-
|
|
10845
|
-
|
|
10846
|
-
|
|
10847
|
-
|
|
10848
|
-
|
|
10849
|
-
|
|
10850
|
-
|
|
10851
|
-
|
|
10852
|
-
out = out.replace(assetsPattern, (match, p1, p2) => {
|
|
10853
|
-
assets = p1.trim();
|
|
10854
|
-
return p2;
|
|
10855
|
-
});
|
|
10856
|
-
const injectAssets = (_, part1, part2) => {
|
|
10857
|
-
let a = assets;
|
|
10858
|
-
if (!(part1.endsWith("\n") || part1.endsWith("\r"))) {
|
|
10859
|
-
a = "\r\n" + a;
|
|
10860
|
-
}
|
|
10861
|
-
if (!(part2.startsWith("\n") || part2.startsWith("\r"))) {
|
|
10862
|
-
a += "\r\n";
|
|
10863
|
-
}
|
|
10864
|
-
assets = "";
|
|
10865
|
-
return `${part1}${a}${part2}`;
|
|
10866
|
-
};
|
|
10867
|
-
if (assets) {
|
|
10868
|
-
out = out.replace(lastTagPattern, injectAssets);
|
|
10869
|
-
}
|
|
10870
|
-
if (assets) {
|
|
10871
|
-
out = out.replace(closingPattern, injectAssets);
|
|
10872
|
-
}
|
|
10873
|
-
if (assets) {
|
|
10874
|
-
out += assets;
|
|
10875
|
-
}
|
|
10876
|
-
return out;
|
|
10997
|
+
function findFiles(pattern, root = process.cwd(), ignore) {
|
|
10998
|
+
return [
|
|
10999
|
+
...new Set(
|
|
11000
|
+
pattern.flatMap(
|
|
11001
|
+
(entry) => FastGlob.globSync(entry, {
|
|
11002
|
+
cwd: root,
|
|
11003
|
+
dot: true,
|
|
11004
|
+
onlyFiles: true,
|
|
11005
|
+
unique: true,
|
|
11006
|
+
ignore
|
|
11007
|
+
})
|
|
11008
|
+
)
|
|
11009
|
+
)
|
|
11010
|
+
];
|
|
10877
11011
|
}
|
|
10878
11012
|
|
|
10879
|
-
|
|
10880
|
-
|
|
10881
|
-
|
|
10882
|
-
(path) => req.url.startsWith(path)
|
|
10883
|
-
)) {
|
|
10884
|
-
req.on("error", (error) => {
|
|
10885
|
-
throw error;
|
|
10886
|
-
});
|
|
10887
|
-
let url = new URL(req.url, "http://localhost");
|
|
10888
|
-
if (shared.viteConfig?.server.port) {
|
|
10889
|
-
url.port = shared.viteConfig.server.port.toString();
|
|
10890
|
-
}
|
|
10891
|
-
const requestUrl = new URL(url);
|
|
10892
|
-
if (url.pathname.endsWith("/")) {
|
|
10893
|
-
url.pathname += "index.php";
|
|
10894
|
-
}
|
|
10895
|
-
const routedUrl = serve.rewriteUrl(url);
|
|
10896
|
-
if (routedUrl) {
|
|
10897
|
-
if (routedUrl.origin !== requestUrl.origin) {
|
|
10898
|
-
res.writeHead(307, {
|
|
10899
|
-
location: routedUrl.toString()
|
|
10900
|
-
}).end();
|
|
10901
|
-
return;
|
|
10902
|
-
}
|
|
10903
|
-
url = routedUrl;
|
|
10904
|
-
}
|
|
10905
|
-
const entryPathname = url.pathname.substring(1);
|
|
10906
|
-
const entry = shared.entries.find((file) => {
|
|
10907
|
-
return file === entryPathname || file.substring(0, file.lastIndexOf(".")) === entryPathname;
|
|
10908
|
-
});
|
|
10909
|
-
if (entry) {
|
|
10910
|
-
const tempFile = tempName(entry);
|
|
10911
|
-
if (node_fs.existsSync(node_path.resolve(tempFile))) {
|
|
10912
|
-
url.pathname = tempFile;
|
|
10913
|
-
url.host = PHP_Server.host;
|
|
10914
|
-
url.port = PHP_Server.port.toString();
|
|
10915
|
-
url.searchParams.set(
|
|
10916
|
-
internalParam,
|
|
10917
|
-
new URLSearchParams({
|
|
10918
|
-
$REQUEST_URI: requestUrl.pathname,
|
|
10919
|
-
$PHP_SELF: "/" + entry,
|
|
10920
|
-
temp_dir: shared.tempDir,
|
|
10921
|
-
error_levels: shared.devConfig.errorLevels.toString()
|
|
10922
|
-
}).toString()
|
|
10923
|
-
);
|
|
10924
|
-
const body = await new Promise(
|
|
10925
|
-
(resolve2, reject) => {
|
|
10926
|
-
let data = [];
|
|
10927
|
-
req.on("data", (chunk) => {
|
|
10928
|
-
data.push(chunk);
|
|
10929
|
-
}).on("end", () => {
|
|
10930
|
-
resolve2(Buffer.concat(data));
|
|
10931
|
-
});
|
|
10932
|
-
}
|
|
10933
|
-
);
|
|
10934
|
-
const phpResult = await new Promise(async (resolve2, reject) => {
|
|
10935
|
-
const chunks = [];
|
|
10936
|
-
let statusCode;
|
|
10937
|
-
let incomingHeaders = {};
|
|
10938
|
-
const request = http__default.request(
|
|
10939
|
-
url.toString(),
|
|
10940
|
-
{
|
|
10941
|
-
method: req.method,
|
|
10942
|
-
headers: {
|
|
10943
|
-
...req.headers,
|
|
10944
|
-
"content-length": Buffer.byteLength(body)
|
|
10945
|
-
}
|
|
10946
|
-
},
|
|
10947
|
-
(msg) => {
|
|
10948
|
-
statusCode = msg.statusCode;
|
|
10949
|
-
incomingHeaders = msg.headers;
|
|
10950
|
-
msg.on("data", (data) => {
|
|
10951
|
-
chunks.push(data);
|
|
10952
|
-
});
|
|
10953
|
-
}
|
|
10954
|
-
).on("error", (error) => {
|
|
10955
|
-
reject(error);
|
|
10956
|
-
}).on("close", () => {
|
|
10957
|
-
let content = Buffer.concat(chunks).toString("utf8");
|
|
10958
|
-
if (incomingHeaders["content-type"]?.includes(
|
|
10959
|
-
"text/html"
|
|
10960
|
-
) && !viteClientInjectionPattern.test(content)) {
|
|
10961
|
-
content = viteClientInjection + content;
|
|
10962
|
-
if (incomingHeaders["content-length"]) {
|
|
10963
|
-
incomingHeaders["content-length"] = `${content.length}`;
|
|
10964
|
-
}
|
|
10965
|
-
}
|
|
10966
|
-
resolve2({
|
|
10967
|
-
statusCode,
|
|
10968
|
-
headers: incomingHeaders,
|
|
10969
|
-
content
|
|
10970
|
-
});
|
|
10971
|
-
});
|
|
10972
|
-
request.write(body, (error) => {
|
|
10973
|
-
if (error) {
|
|
10974
|
-
reject(error);
|
|
10975
|
-
}
|
|
10976
|
-
});
|
|
10977
|
-
request.end();
|
|
10978
|
-
});
|
|
10979
|
-
res.writeHead(
|
|
10980
|
-
phpResult.statusCode || 200,
|
|
10981
|
-
phpResult.headers
|
|
10982
|
-
).end(phpResult.content);
|
|
10983
|
-
return;
|
|
10984
|
-
}
|
|
10985
|
-
}
|
|
10986
|
-
}
|
|
10987
|
-
} catch (error) {
|
|
10988
|
-
console.error("Vite-PHP Error: " + error);
|
|
10989
|
-
}
|
|
10990
|
-
next();
|
|
10991
|
-
};
|
|
11013
|
+
function escapeRegExp(str) {
|
|
11014
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
11015
|
+
}
|
|
10992
11016
|
|
|
10993
11017
|
const serve = {
|
|
10994
11018
|
rewriteUrl: (url) => url
|
|
10995
11019
|
};
|
|
10996
11020
|
let devServer = void 0;
|
|
10997
11021
|
let entryMatcher = new RegExp(``, "gs");
|
|
11022
|
+
function updateEntryMatcher() {
|
|
11023
|
+
entryMatcher = new RegExp(
|
|
11024
|
+
`(${shared.entries.map(escapeRegExp).join("|")}).html`,
|
|
11025
|
+
"gs"
|
|
11026
|
+
);
|
|
11027
|
+
}
|
|
10998
11028
|
const codeMap$1 = /* @__PURE__ */ new Map();
|
|
10999
11029
|
const servePlugin = [
|
|
11000
11030
|
{
|
|
@@ -11007,10 +11037,7 @@ const servePlugin = [
|
|
|
11007
11037
|
if (!node_fs.existsSync(gitIgnoreFile)) {
|
|
11008
11038
|
writeFile(gitIgnoreFile, "*\r\n**/*");
|
|
11009
11039
|
}
|
|
11010
|
-
|
|
11011
|
-
`(${shared.entries.join("|")}).html`,
|
|
11012
|
-
"gs"
|
|
11013
|
-
);
|
|
11040
|
+
updateEntryMatcher();
|
|
11014
11041
|
}
|
|
11015
11042
|
},
|
|
11016
11043
|
configureServer: {
|
|
@@ -11142,12 +11169,10 @@ const servePlugin = [
|
|
|
11142
11169
|
php.code = PHP_Code.unescape(php.code, escapes);
|
|
11143
11170
|
}
|
|
11144
11171
|
php.code = fixAssetsInjection(php.code);
|
|
11145
|
-
|
|
11146
|
-
|
|
11147
|
-
|
|
11148
|
-
|
|
11149
|
-
);
|
|
11150
|
-
}
|
|
11172
|
+
php.code = php.code.replace(
|
|
11173
|
+
new RegExp(viteClientInjectionPattern, "gsi"),
|
|
11174
|
+
""
|
|
11175
|
+
);
|
|
11151
11176
|
php.write(tempName(entry));
|
|
11152
11177
|
return php.code;
|
|
11153
11178
|
}
|
|
@@ -11158,23 +11183,53 @@ const servePlugin = [
|
|
|
11158
11183
|
name: "php:serve-watch",
|
|
11159
11184
|
apply: "serve",
|
|
11160
11185
|
async watchChange(id, change) {
|
|
11186
|
+
const resolvedId = node_path.resolve(id);
|
|
11187
|
+
const root = devServer?.config.root || process.cwd();
|
|
11161
11188
|
const entry = shared.entries.find(
|
|
11162
|
-
(entryFile) => node_path.resolve(entryFile) ===
|
|
11189
|
+
(entryFile) => node_path.resolve(root, entryFile) === resolvedId
|
|
11163
11190
|
);
|
|
11164
|
-
if (entry) {
|
|
11191
|
+
if (change.event === "delete" && entry) {
|
|
11165
11192
|
try {
|
|
11166
|
-
|
|
11167
|
-
id: entry
|
|
11168
|
-
});
|
|
11193
|
+
node_fs.rmSync(node_path.resolve(shared.tempDir, entry));
|
|
11169
11194
|
} catch (error) {
|
|
11170
11195
|
}
|
|
11196
|
+
} else {
|
|
11197
|
+
const loadEntry = async (entry2) => {
|
|
11198
|
+
try {
|
|
11199
|
+
await this.load({
|
|
11200
|
+
id: entry2
|
|
11201
|
+
});
|
|
11202
|
+
} catch (error) {
|
|
11203
|
+
}
|
|
11204
|
+
};
|
|
11205
|
+
if (entry) {
|
|
11206
|
+
await loadEntry(entry);
|
|
11207
|
+
} else if (devServer && !resolvedId.startsWith(node_path.resolve(shared.tempDir)) && resolvedId.includes(".php")) {
|
|
11208
|
+
const priorEntries = shared.entries;
|
|
11209
|
+
shared.entries = findFiles(
|
|
11210
|
+
shared.entryPatterns,
|
|
11211
|
+
devServer.config.root,
|
|
11212
|
+
[
|
|
11213
|
+
shared.tempDir,
|
|
11214
|
+
devServer.config.build?.outDir || "dist"
|
|
11215
|
+
]
|
|
11216
|
+
);
|
|
11217
|
+
updateEntryMatcher();
|
|
11218
|
+
const allEntries = shared.entries;
|
|
11219
|
+
const newEntries = allEntries.filter(
|
|
11220
|
+
(entry2) => !priorEntries.includes(entry2)
|
|
11221
|
+
);
|
|
11222
|
+
await Promise.allSettled(newEntries.map(loadEntry));
|
|
11223
|
+
}
|
|
11171
11224
|
}
|
|
11172
11225
|
},
|
|
11173
11226
|
handleHotUpdate({ server, file }) {
|
|
11227
|
+
const resolvedFile = node_path.resolve(file);
|
|
11228
|
+
const root = devServer?.config.root || process.cwd();
|
|
11174
11229
|
const entry = shared.entries.find(
|
|
11175
|
-
(entryFile) => node_path.resolve(entryFile) ===
|
|
11230
|
+
(entryFile) => node_path.resolve(root, entryFile) === resolvedFile
|
|
11176
11231
|
);
|
|
11177
|
-
if (entry || !
|
|
11232
|
+
if (entry || !resolvedFile.startsWith(node_path.resolve(shared.tempDir)) && resolvedFile.includes(".php")) {
|
|
11178
11233
|
server.ws.send({
|
|
11179
11234
|
type: "full-reload"
|
|
11180
11235
|
});
|
|
@@ -11287,11 +11342,11 @@ const buildPlugin = [
|
|
|
11287
11342
|
];
|
|
11288
11343
|
|
|
11289
11344
|
function usePHP(cfg = {}) {
|
|
11290
|
-
const { entry =
|
|
11345
|
+
const { entry = shared.entryPatterns } = cfg;
|
|
11291
11346
|
PHP_Server.binary = cfg.binary ?? PHP_Server.binary;
|
|
11292
11347
|
PHP_Server.host = cfg.php?.host ?? PHP_Server.host;
|
|
11293
11348
|
serve.rewriteUrl = cfg.rewriteUrl ?? serve.rewriteUrl;
|
|
11294
|
-
shared.
|
|
11349
|
+
shared.entryPatterns = Array.isArray(entry) ? entry : [entry];
|
|
11295
11350
|
shared.tempDir = cfg.tempDir ?? shared.tempDir;
|
|
11296
11351
|
shared.devConfig = {
|
|
11297
11352
|
cleanup: cfg.dev?.cleanup || shared.devConfig.cleanup,
|
|
@@ -11302,21 +11357,10 @@ function usePHP(cfg = {}) {
|
|
|
11302
11357
|
name: "php:init",
|
|
11303
11358
|
enforce: "post",
|
|
11304
11359
|
config(config, env) {
|
|
11305
|
-
shared.entries = [
|
|
11306
|
-
|
|
11307
|
-
|
|
11308
|
-
|
|
11309
|
-
dot: true,
|
|
11310
|
-
onlyFiles: true,
|
|
11311
|
-
unique: true,
|
|
11312
|
-
ignore: [
|
|
11313
|
-
shared.tempDir,
|
|
11314
|
-
config.build?.outDir || "dist"
|
|
11315
|
-
]
|
|
11316
|
-
})
|
|
11317
|
-
)
|
|
11318
|
-
)
|
|
11319
|
-
];
|
|
11360
|
+
shared.entries = findFiles(shared.entryPatterns, config.root, [
|
|
11361
|
+
shared.tempDir,
|
|
11362
|
+
config.build?.outDir || "dist"
|
|
11363
|
+
]);
|
|
11320
11364
|
return {
|
|
11321
11365
|
server: {
|
|
11322
11366
|
watch: {
|