vite-plugin-php 3.0.0-beta.1 → 3.0.0-beta.2
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/dist/index.cjs +56 -37
- package/dist/index.mjs +56 -37
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -10835,6 +10835,47 @@ const handleExit = {
|
|
|
10835
10835
|
}
|
|
10836
10836
|
};
|
|
10837
10837
|
|
|
10838
|
+
const assetsPattern = new RegExp(
|
|
10839
|
+
`^(.+?)(${phpStartPattern}\\s+namespace\\s\\S+?(?:\\s*;|\\s*{).+)$`,
|
|
10840
|
+
"si"
|
|
10841
|
+
);
|
|
10842
|
+
const viteClientInjection = '<script type="module" src="/@vite/client"><\/script>\n';
|
|
10843
|
+
const viteClientInjectionPattern = new RegExp(
|
|
10844
|
+
'<script.+?src="/@vite/client".+?<\/script>(\r\n|\n|\r)',
|
|
10845
|
+
"si"
|
|
10846
|
+
);
|
|
10847
|
+
const lastTagPattern = new RegExp(`^(.+(?:</.+?>|<.+?/>))(.+|)$`, "si");
|
|
10848
|
+
const closingPattern = new RegExp(`^(.+)(${phpStartPattern}.+)$`, "si");
|
|
10849
|
+
function fixAssetsInjection(input) {
|
|
10850
|
+
let out = input;
|
|
10851
|
+
let assets = "";
|
|
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;
|
|
10877
|
+
}
|
|
10878
|
+
|
|
10838
10879
|
const phpProxy = async (req, res, next) => {
|
|
10839
10880
|
try {
|
|
10840
10881
|
if (req.url && !["/@vite", "/@fs", "/@id/__x00__", "/node_modules"].some(
|
|
@@ -10909,7 +10950,15 @@ const phpProxy = async (req, res, next) => {
|
|
|
10909
10950
|
).on("error", (error) => {
|
|
10910
10951
|
reject(error);
|
|
10911
10952
|
}).on("close", () => {
|
|
10912
|
-
|
|
10953
|
+
let content = Buffer.concat(chunks).toString("utf8");
|
|
10954
|
+
if (incomingHeaders["content-type"]?.includes(
|
|
10955
|
+
"text/html"
|
|
10956
|
+
) && !viteClientInjectionPattern.test(content)) {
|
|
10957
|
+
content = viteClientInjection + content;
|
|
10958
|
+
if (incomingHeaders["content-length"]) {
|
|
10959
|
+
incomingHeaders["content-length"] = `${content.length}`;
|
|
10960
|
+
}
|
|
10961
|
+
}
|
|
10913
10962
|
resolve2({
|
|
10914
10963
|
statusCode,
|
|
10915
10964
|
headers: incomingHeaders,
|
|
@@ -10937,42 +10986,6 @@ const phpProxy = async (req, res, next) => {
|
|
|
10937
10986
|
next();
|
|
10938
10987
|
};
|
|
10939
10988
|
|
|
10940
|
-
const assetsPattern = new RegExp(
|
|
10941
|
-
`^(.+?)(${phpStartPattern}\\s+namespace\\s\\S+?(?:\\s*;|\\s*{).+)$`,
|
|
10942
|
-
"si"
|
|
10943
|
-
);
|
|
10944
|
-
const lastTagPattern = new RegExp(`^(.+(?:</.+?>|<.+?/>))(.+|)$`, "si");
|
|
10945
|
-
const closingPattern = new RegExp(`^(.+)(${phpStartPattern}.+)$`, "si");
|
|
10946
|
-
function fixAssetsInjection(input) {
|
|
10947
|
-
let out = input;
|
|
10948
|
-
let assets = "";
|
|
10949
|
-
out = out.replace(assetsPattern, (match, p1, p2) => {
|
|
10950
|
-
assets = p1.trim();
|
|
10951
|
-
return p2;
|
|
10952
|
-
});
|
|
10953
|
-
const injectAssets = (_, part1, part2) => {
|
|
10954
|
-
let a = assets;
|
|
10955
|
-
if (!(part1.endsWith("\n") || part1.endsWith("\r"))) {
|
|
10956
|
-
a = "\r\n" + a;
|
|
10957
|
-
}
|
|
10958
|
-
if (!(part2.startsWith("\n") || part2.startsWith("\r"))) {
|
|
10959
|
-
a += "\r\n";
|
|
10960
|
-
}
|
|
10961
|
-
assets = "";
|
|
10962
|
-
return `${part1}${a}${part2}`;
|
|
10963
|
-
};
|
|
10964
|
-
if (assets) {
|
|
10965
|
-
out = out.replace(lastTagPattern, injectAssets);
|
|
10966
|
-
}
|
|
10967
|
-
if (assets) {
|
|
10968
|
-
out = out.replace(closingPattern, injectAssets);
|
|
10969
|
-
}
|
|
10970
|
-
if (assets) {
|
|
10971
|
-
out += assets;
|
|
10972
|
-
}
|
|
10973
|
-
return out;
|
|
10974
|
-
}
|
|
10975
|
-
|
|
10976
10989
|
const serve = {
|
|
10977
10990
|
rewriteUrl: (url) => url
|
|
10978
10991
|
};
|
|
@@ -11125,6 +11138,12 @@ const servePlugin = [
|
|
|
11125
11138
|
php.code = PHP_Code.unescape(php.code, escapes);
|
|
11126
11139
|
}
|
|
11127
11140
|
php.code = fixAssetsInjection(php.code);
|
|
11141
|
+
if (!php.code.includes("</head>")) {
|
|
11142
|
+
php.code = php.code.replace(
|
|
11143
|
+
new RegExp(viteClientInjectionPattern, "gsi"),
|
|
11144
|
+
""
|
|
11145
|
+
);
|
|
11146
|
+
}
|
|
11128
11147
|
php.write(tempName(entry));
|
|
11129
11148
|
return php.code;
|
|
11130
11149
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -10818,6 +10818,47 @@ const handleExit = {
|
|
|
10818
10818
|
}
|
|
10819
10819
|
};
|
|
10820
10820
|
|
|
10821
|
+
const assetsPattern = new RegExp(
|
|
10822
|
+
`^(.+?)(${phpStartPattern}\\s+namespace\\s\\S+?(?:\\s*;|\\s*{).+)$`,
|
|
10823
|
+
"si"
|
|
10824
|
+
);
|
|
10825
|
+
const viteClientInjection = '<script type="module" src="/@vite/client"><\/script>\n';
|
|
10826
|
+
const viteClientInjectionPattern = new RegExp(
|
|
10827
|
+
'<script.+?src="/@vite/client".+?<\/script>(\r\n|\n|\r)',
|
|
10828
|
+
"si"
|
|
10829
|
+
);
|
|
10830
|
+
const lastTagPattern = new RegExp(`^(.+(?:</.+?>|<.+?/>))(.+|)$`, "si");
|
|
10831
|
+
const closingPattern = new RegExp(`^(.+)(${phpStartPattern}.+)$`, "si");
|
|
10832
|
+
function fixAssetsInjection(input) {
|
|
10833
|
+
let out = input;
|
|
10834
|
+
let assets = "";
|
|
10835
|
+
out = out.replace(assetsPattern, (match, p1, p2) => {
|
|
10836
|
+
assets = p1.trim();
|
|
10837
|
+
return p2;
|
|
10838
|
+
});
|
|
10839
|
+
const injectAssets = (_, part1, part2) => {
|
|
10840
|
+
let a = assets;
|
|
10841
|
+
if (!(part1.endsWith("\n") || part1.endsWith("\r"))) {
|
|
10842
|
+
a = "\r\n" + a;
|
|
10843
|
+
}
|
|
10844
|
+
if (!(part2.startsWith("\n") || part2.startsWith("\r"))) {
|
|
10845
|
+
a += "\r\n";
|
|
10846
|
+
}
|
|
10847
|
+
assets = "";
|
|
10848
|
+
return `${part1}${a}${part2}`;
|
|
10849
|
+
};
|
|
10850
|
+
if (assets) {
|
|
10851
|
+
out = out.replace(lastTagPattern, injectAssets);
|
|
10852
|
+
}
|
|
10853
|
+
if (assets) {
|
|
10854
|
+
out = out.replace(closingPattern, injectAssets);
|
|
10855
|
+
}
|
|
10856
|
+
if (assets) {
|
|
10857
|
+
out += assets;
|
|
10858
|
+
}
|
|
10859
|
+
return out;
|
|
10860
|
+
}
|
|
10861
|
+
|
|
10821
10862
|
const phpProxy = async (req, res, next) => {
|
|
10822
10863
|
try {
|
|
10823
10864
|
if (req.url && !["/@vite", "/@fs", "/@id/__x00__", "/node_modules"].some(
|
|
@@ -10892,7 +10933,15 @@ const phpProxy = async (req, res, next) => {
|
|
|
10892
10933
|
).on("error", (error) => {
|
|
10893
10934
|
reject(error);
|
|
10894
10935
|
}).on("close", () => {
|
|
10895
|
-
|
|
10936
|
+
let content = Buffer.concat(chunks).toString("utf8");
|
|
10937
|
+
if (incomingHeaders["content-type"]?.includes(
|
|
10938
|
+
"text/html"
|
|
10939
|
+
) && !viteClientInjectionPattern.test(content)) {
|
|
10940
|
+
content = viteClientInjection + content;
|
|
10941
|
+
if (incomingHeaders["content-length"]) {
|
|
10942
|
+
incomingHeaders["content-length"] = `${content.length}`;
|
|
10943
|
+
}
|
|
10944
|
+
}
|
|
10896
10945
|
resolve2({
|
|
10897
10946
|
statusCode,
|
|
10898
10947
|
headers: incomingHeaders,
|
|
@@ -10920,42 +10969,6 @@ const phpProxy = async (req, res, next) => {
|
|
|
10920
10969
|
next();
|
|
10921
10970
|
};
|
|
10922
10971
|
|
|
10923
|
-
const assetsPattern = new RegExp(
|
|
10924
|
-
`^(.+?)(${phpStartPattern}\\s+namespace\\s\\S+?(?:\\s*;|\\s*{).+)$`,
|
|
10925
|
-
"si"
|
|
10926
|
-
);
|
|
10927
|
-
const lastTagPattern = new RegExp(`^(.+(?:</.+?>|<.+?/>))(.+|)$`, "si");
|
|
10928
|
-
const closingPattern = new RegExp(`^(.+)(${phpStartPattern}.+)$`, "si");
|
|
10929
|
-
function fixAssetsInjection(input) {
|
|
10930
|
-
let out = input;
|
|
10931
|
-
let assets = "";
|
|
10932
|
-
out = out.replace(assetsPattern, (match, p1, p2) => {
|
|
10933
|
-
assets = p1.trim();
|
|
10934
|
-
return p2;
|
|
10935
|
-
});
|
|
10936
|
-
const injectAssets = (_, part1, part2) => {
|
|
10937
|
-
let a = assets;
|
|
10938
|
-
if (!(part1.endsWith("\n") || part1.endsWith("\r"))) {
|
|
10939
|
-
a = "\r\n" + a;
|
|
10940
|
-
}
|
|
10941
|
-
if (!(part2.startsWith("\n") || part2.startsWith("\r"))) {
|
|
10942
|
-
a += "\r\n";
|
|
10943
|
-
}
|
|
10944
|
-
assets = "";
|
|
10945
|
-
return `${part1}${a}${part2}`;
|
|
10946
|
-
};
|
|
10947
|
-
if (assets) {
|
|
10948
|
-
out = out.replace(lastTagPattern, injectAssets);
|
|
10949
|
-
}
|
|
10950
|
-
if (assets) {
|
|
10951
|
-
out = out.replace(closingPattern, injectAssets);
|
|
10952
|
-
}
|
|
10953
|
-
if (assets) {
|
|
10954
|
-
out += assets;
|
|
10955
|
-
}
|
|
10956
|
-
return out;
|
|
10957
|
-
}
|
|
10958
|
-
|
|
10959
10972
|
const serve = {
|
|
10960
10973
|
rewriteUrl: (url) => url
|
|
10961
10974
|
};
|
|
@@ -11108,6 +11121,12 @@ const servePlugin = [
|
|
|
11108
11121
|
php.code = PHP_Code.unescape(php.code, escapes);
|
|
11109
11122
|
}
|
|
11110
11123
|
php.code = fixAssetsInjection(php.code);
|
|
11124
|
+
if (!php.code.includes("</head>")) {
|
|
11125
|
+
php.code = php.code.replace(
|
|
11126
|
+
new RegExp(viteClientInjectionPattern, "gsi"),
|
|
11127
|
+
""
|
|
11128
|
+
);
|
|
11129
|
+
}
|
|
11111
11130
|
php.write(tempName(entry));
|
|
11112
11131
|
return php.code;
|
|
11113
11132
|
}
|