@ideasonpurpose/build-tools-wordpress 2.2.3 → 2.2.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/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/bin/format-php-prettier.js +9 -7
- package/package.json +1 -1
- package/test/format-php-prettier.test.js +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
6
6
|
|
|
7
|
+
#### v2.2.3
|
|
8
|
+
|
|
9
|
+
> 9 September 2025
|
|
10
|
+
|
|
11
|
+
- trying explicit PHP plugin loading
|
|
12
|
+
|
|
7
13
|
#### v2.2.2
|
|
8
14
|
|
|
9
15
|
> 9 September 2025
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @ideasonpurpose/build-tools-wordpress
|
|
2
2
|
|
|
3
|
-
#### Version 2.2.
|
|
3
|
+
#### Version 2.2.4
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@ideasonpurpose/build-tools-wordpress)
|
|
6
6
|
[](https://github.com/ideasonpurpose/build-tools-wordpress#readme)
|
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
import prettier from "prettier";
|
|
12
12
|
import prettierConfig from "@ideasonpurpose/prettier-config" with { type: "json" };
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const phpPlugin = await import("@prettier/plugin-php");
|
|
15
|
+
|
|
16
|
+
// Explicitly reset the plugin because global installs can't resolve it
|
|
17
|
+
prettierConfig.plugins = [phpPlugin];
|
|
16
18
|
|
|
17
19
|
import { readFile, writeFile } from "fs/promises";
|
|
18
20
|
import { resolve, basename } from "path";
|
|
@@ -56,7 +58,7 @@ const isInTag = (html, offset) => {
|
|
|
56
58
|
*/
|
|
57
59
|
export function tokenizeHTML(htmlContent) {
|
|
58
60
|
let tokenizedHTML = "";
|
|
59
|
-
const phpCodeBlocks =
|
|
61
|
+
const phpCodeBlocks = new Map(); // Changed to Map for better performance and type safety
|
|
60
62
|
let tokenCount = 0;
|
|
61
63
|
|
|
62
64
|
/**
|
|
@@ -101,7 +103,7 @@ export function tokenizeHTML(htmlContent) {
|
|
|
101
103
|
tokenizedHTML += htmlContent.slice(lastIndex, match.index);
|
|
102
104
|
|
|
103
105
|
token = tokenizeCodeBlock(match[0], tokenizedHTML);
|
|
104
|
-
phpCodeBlocks
|
|
106
|
+
phpCodeBlocks.set(token, match[0]);
|
|
105
107
|
tokenizedHTML += token;
|
|
106
108
|
|
|
107
109
|
lastIndex = match.index + match[0].length;
|
|
@@ -113,7 +115,7 @@ export function tokenizeHTML(htmlContent) {
|
|
|
113
115
|
|
|
114
116
|
export function unTokenizeHTML(tokenizedHTML, phpCodeBlocks) {
|
|
115
117
|
let phpContent = tokenizedHTML;
|
|
116
|
-
for (const token
|
|
118
|
+
for (const [token, phpBlock] of phpCodeBlocks) {
|
|
117
119
|
/**
|
|
118
120
|
* Create a pattern from token that matches whitespace breaks resulting
|
|
119
121
|
* from Prettier's HTML formatting, usually on very long lines.
|
|
@@ -123,7 +125,7 @@ export function unTokenizeHTML(tokenizedHTML, phpCodeBlocks) {
|
|
|
123
125
|
const regexToken = new RegExp(token.replace("_ />", "_\\s+\\/>"), "g");
|
|
124
126
|
phpContent = phpContent.replace(
|
|
125
127
|
regexToken,
|
|
126
|
-
|
|
128
|
+
phpBlock.replace(/\$/g, "$$$$"),
|
|
127
129
|
);
|
|
128
130
|
}
|
|
129
131
|
return phpContent;
|
|
@@ -160,7 +162,7 @@ async function formatHTMLThenPHP(filepath) {
|
|
|
160
162
|
...phpOptions,
|
|
161
163
|
parser: "php",
|
|
162
164
|
embeddedLanguageFormatting: "auto",
|
|
163
|
-
plugins: [phpPlugin],
|
|
165
|
+
// plugins: [phpPlugin], // Explicitly pass the plugin
|
|
164
166
|
});
|
|
165
167
|
|
|
166
168
|
await writeFile(filepath, phpFormatted, "utf8");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ideasonpurpose/build-tools-wordpress",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.4",
|
|
4
4
|
"description": "Build scripts and dependencies for IOP's WordPress development environments.",
|
|
5
5
|
"homepage": "https://github.com/ideasonpurpose/build-tools-wordpress#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -34,9 +34,9 @@ describe("HTML-PHP Prettier", () => {
|
|
|
34
34
|
await readFile("./test/fixtures/format-php-prettier/basic-html.php")
|
|
35
35
|
).toString();
|
|
36
36
|
|
|
37
|
-
const { phpCodeBlocks
|
|
37
|
+
const { phpCodeBlocks } = tokenizeHTML(input);
|
|
38
38
|
|
|
39
|
-
const tokens =
|
|
39
|
+
const tokens = Array.from(phpCodeBlocks.keys());
|
|
40
40
|
|
|
41
41
|
expect(tokens[0]).toMatch(/^<php_\d+_* \/>$/);
|
|
42
42
|
expect(tokens[1]).toMatch(/^_php_\d+_*$/);
|
|
@@ -51,9 +51,9 @@ describe("HTML-PHP Prettier", () => {
|
|
|
51
51
|
)
|
|
52
52
|
).toString();
|
|
53
53
|
|
|
54
|
-
const { phpCodeBlocks
|
|
54
|
+
const { phpCodeBlocks } = tokenizeHTML(input);
|
|
55
55
|
|
|
56
|
-
const tokens =
|
|
56
|
+
const tokens = Array.from(phpCodeBlocks.keys());
|
|
57
57
|
|
|
58
58
|
expect(tokens).toHaveLength(1);
|
|
59
59
|
});
|
|
@@ -69,7 +69,8 @@ describe("HTML-PHP Prettier", () => {
|
|
|
69
69
|
|
|
70
70
|
// console.log({input, tokenizedHTML})
|
|
71
71
|
|
|
72
|
-
const tokens = Object.keys(phpCodeBlocks);
|
|
72
|
+
// const tokens = Object.keys(phpCodeBlocks);
|
|
73
|
+
const tokens = Array.from(phpCodeBlocks.keys());
|
|
73
74
|
|
|
74
75
|
expect(tokens[0]).toMatch(/^_php_\d+_*$/);
|
|
75
76
|
expect(tokens[1]).toMatch(/^_php_\d+_*$/);
|
|
@@ -141,8 +142,8 @@ describe("HTML-PHP Prettier", () => {
|
|
|
141
142
|
|
|
142
143
|
expect(tokenizedHTML).toContain("<php_0____ />");
|
|
143
144
|
expect(tokenizedHTML).toContain("<php_1____ />");
|
|
144
|
-
expect(phpCodeBlocks
|
|
145
|
-
expect(phpCodeBlocks
|
|
145
|
+
expect(phpCodeBlocks.has("<php_0____ />")).toBe(true);
|
|
146
|
+
expect(phpCodeBlocks.has("<php_1____ />")).toBe(true);
|
|
146
147
|
});
|
|
147
148
|
|
|
148
149
|
/**
|