vite-plugin-php 1.0.1 → 1.0.4
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 +9 -6
- package/dist/index.mjs +9 -6
- 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}`;
|
|
@@ -230,7 +230,10 @@ function usePHP(cfg = {}) {
|
|
|
230
230
|
closeBundle() {
|
|
231
231
|
const distDir = config?.build.outDir;
|
|
232
232
|
entries.forEach((file) => {
|
|
233
|
-
const code = unescapePHP(
|
|
233
|
+
const code = unescapePHP(
|
|
234
|
+
`${distDir}/${tempDir}/${file}.html`,
|
|
235
|
+
`${tempDir}/${file}.html.json`
|
|
236
|
+
);
|
|
234
237
|
writeFile(`${distDir}/${file}`, code);
|
|
235
238
|
});
|
|
236
239
|
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}`;
|
|
@@ -224,7 +224,10 @@ function usePHP(cfg = {}) {
|
|
|
224
224
|
closeBundle() {
|
|
225
225
|
const distDir = config?.build.outDir;
|
|
226
226
|
entries.forEach((file) => {
|
|
227
|
-
const code = unescapePHP(
|
|
227
|
+
const code = unescapePHP(
|
|
228
|
+
`${distDir}/${tempDir}/${file}.html`,
|
|
229
|
+
`${tempDir}/${file}.html.json`
|
|
230
|
+
);
|
|
228
231
|
writeFile(`${distDir}/${file}`, code);
|
|
229
232
|
});
|
|
230
233
|
cleanupTemp(distDir);
|