vite-plugin-php 1.0.1 → 1.0.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/dist/index.cjs +11 -7
- package/dist/index.mjs +11 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -23,7 +23,7 @@ function escapePHP(inputFile, outputFile) {
|
|
|
23
23
|
const codeTokens = {};
|
|
24
24
|
const isJS = inputFile.includes(".js") || inputFile.includes(".ts");
|
|
25
25
|
const isML = inputFile.includes(".php") || inputFile.includes(".htm");
|
|
26
|
-
const out = input.replaceAll(/<\?(?:php|).+?\?>/
|
|
26
|
+
const out = input.replaceAll(/<\?(?:php|).+?\?>/gis, (match) => {
|
|
27
27
|
let token = makeID();
|
|
28
28
|
if (isJS) {
|
|
29
29
|
token = `/*${token}*/`;
|
|
@@ -36,12 +36,12 @@ function escapePHP(inputFile, outputFile) {
|
|
|
36
36
|
writeFile(outputFile + ".json", JSON.stringify(codeTokens));
|
|
37
37
|
writeFile(outputFile, out);
|
|
38
38
|
}
|
|
39
|
-
function unescapePHP(file) {
|
|
39
|
+
function unescapePHP(file, tokensFile) {
|
|
40
40
|
const input = fs.readFileSync(file).toString();
|
|
41
41
|
let out = input;
|
|
42
|
-
const
|
|
43
|
-
if (fs.existsSync(
|
|
44
|
-
const codeTokens = JSON.parse(fs.readFileSync(
|
|
42
|
+
const tknsFile = tokensFile || file + ".json";
|
|
43
|
+
if (fs.existsSync(tknsFile)) {
|
|
44
|
+
const codeTokens = JSON.parse(fs.readFileSync(tknsFile).toString());
|
|
45
45
|
Object.entries(codeTokens).forEach(([token, code]) => {
|
|
46
46
|
out = out.replace(token, (match) => {
|
|
47
47
|
return `${code}`;
|
|
@@ -53,12 +53,13 @@ function unescapePHP(file) {
|
|
|
53
53
|
|
|
54
54
|
function start(root) {
|
|
55
55
|
if (!globalThis.php?.pid) {
|
|
56
|
+
const routerFileUrl = new URL("./router.php", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href)));
|
|
56
57
|
globalThis.php = child_process.spawn(phpServer.binary, [
|
|
57
58
|
"-S",
|
|
58
59
|
"localhost:" + phpServer.port,
|
|
59
60
|
"-t",
|
|
60
61
|
root,
|
|
61
|
-
|
|
62
|
+
decodeURI(routerFileUrl.pathname)
|
|
62
63
|
]).once("spawn", () => {
|
|
63
64
|
console.log(
|
|
64
65
|
`PHP development server started (PID: ${globalThis.php?.pid})`
|
|
@@ -230,7 +231,10 @@ function usePHP(cfg = {}) {
|
|
|
230
231
|
closeBundle() {
|
|
231
232
|
const distDir = config?.build.outDir;
|
|
232
233
|
entries.forEach((file) => {
|
|
233
|
-
const code = unescapePHP(
|
|
234
|
+
const code = unescapePHP(
|
|
235
|
+
`${distDir}/${tempDir}/${file}.html`,
|
|
236
|
+
`${tempDir}/${file}.html.json`
|
|
237
|
+
);
|
|
234
238
|
writeFile(`${distDir}/${file}`, code);
|
|
235
239
|
});
|
|
236
240
|
cleanupTemp(distDir);
|
package/dist/index.mjs
CHANGED
|
@@ -17,7 +17,7 @@ function escapePHP(inputFile, outputFile) {
|
|
|
17
17
|
const codeTokens = {};
|
|
18
18
|
const isJS = inputFile.includes(".js") || inputFile.includes(".ts");
|
|
19
19
|
const isML = inputFile.includes(".php") || inputFile.includes(".htm");
|
|
20
|
-
const out = input.replaceAll(/<\?(?:php|).+?\?>/
|
|
20
|
+
const out = input.replaceAll(/<\?(?:php|).+?\?>/gis, (match) => {
|
|
21
21
|
let token = makeID();
|
|
22
22
|
if (isJS) {
|
|
23
23
|
token = `/*${token}*/`;
|
|
@@ -30,12 +30,12 @@ function escapePHP(inputFile, outputFile) {
|
|
|
30
30
|
writeFile(outputFile + ".json", JSON.stringify(codeTokens));
|
|
31
31
|
writeFile(outputFile, out);
|
|
32
32
|
}
|
|
33
|
-
function unescapePHP(file) {
|
|
33
|
+
function unescapePHP(file, tokensFile) {
|
|
34
34
|
const input = readFileSync(file).toString();
|
|
35
35
|
let out = input;
|
|
36
|
-
const
|
|
37
|
-
if (existsSync(
|
|
38
|
-
const codeTokens = JSON.parse(readFileSync(
|
|
36
|
+
const tknsFile = tokensFile || file + ".json";
|
|
37
|
+
if (existsSync(tknsFile)) {
|
|
38
|
+
const codeTokens = JSON.parse(readFileSync(tknsFile).toString());
|
|
39
39
|
Object.entries(codeTokens).forEach(([token, code]) => {
|
|
40
40
|
out = out.replace(token, (match) => {
|
|
41
41
|
return `${code}`;
|
|
@@ -47,12 +47,13 @@ function unescapePHP(file) {
|
|
|
47
47
|
|
|
48
48
|
function start(root) {
|
|
49
49
|
if (!globalThis.php?.pid) {
|
|
50
|
+
const routerFileUrl = new URL("./router.php", import.meta.url);
|
|
50
51
|
globalThis.php = spawn(phpServer.binary, [
|
|
51
52
|
"-S",
|
|
52
53
|
"localhost:" + phpServer.port,
|
|
53
54
|
"-t",
|
|
54
55
|
root,
|
|
55
|
-
|
|
56
|
+
decodeURI(routerFileUrl.pathname)
|
|
56
57
|
]).once("spawn", () => {
|
|
57
58
|
console.log(
|
|
58
59
|
`PHP development server started (PID: ${globalThis.php?.pid})`
|
|
@@ -224,7 +225,10 @@ function usePHP(cfg = {}) {
|
|
|
224
225
|
closeBundle() {
|
|
225
226
|
const distDir = config?.build.outDir;
|
|
226
227
|
entries.forEach((file) => {
|
|
227
|
-
const code = unescapePHP(
|
|
228
|
+
const code = unescapePHP(
|
|
229
|
+
`${distDir}/${tempDir}/${file}.html`,
|
|
230
|
+
`${tempDir}/${file}.html.json`
|
|
231
|
+
);
|
|
228
232
|
writeFile(`${distDir}/${file}`, code);
|
|
229
233
|
});
|
|
230
234
|
cleanupTemp(distDir);
|