@ideasonpurpose/build-tools-wordpress 2.2.2 → 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 +12 -0
- package/README.md +1 -1
- package/bin/format-php-prettier.js +10 -4
- package/package.json +1 -1
- package/test/format-php-prettier.test.js +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,18 @@ 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
|
+
|
|
13
|
+
#### v2.2.2
|
|
14
|
+
|
|
15
|
+
> 9 September 2025
|
|
16
|
+
|
|
17
|
+
- tweaking deps
|
|
18
|
+
|
|
7
19
|
#### v2.2.1
|
|
8
20
|
|
|
9
21
|
> 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,6 +11,11 @@
|
|
|
11
11
|
import prettier from "prettier";
|
|
12
12
|
import prettierConfig from "@ideasonpurpose/prettier-config" with { type: "json" };
|
|
13
13
|
|
|
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];
|
|
18
|
+
|
|
14
19
|
import { readFile, writeFile } from "fs/promises";
|
|
15
20
|
import { resolve, basename } from "path";
|
|
16
21
|
|
|
@@ -53,7 +58,7 @@ const isInTag = (html, offset) => {
|
|
|
53
58
|
*/
|
|
54
59
|
export function tokenizeHTML(htmlContent) {
|
|
55
60
|
let tokenizedHTML = "";
|
|
56
|
-
const phpCodeBlocks =
|
|
61
|
+
const phpCodeBlocks = new Map(); // Changed to Map for better performance and type safety
|
|
57
62
|
let tokenCount = 0;
|
|
58
63
|
|
|
59
64
|
/**
|
|
@@ -98,7 +103,7 @@ export function tokenizeHTML(htmlContent) {
|
|
|
98
103
|
tokenizedHTML += htmlContent.slice(lastIndex, match.index);
|
|
99
104
|
|
|
100
105
|
token = tokenizeCodeBlock(match[0], tokenizedHTML);
|
|
101
|
-
phpCodeBlocks
|
|
106
|
+
phpCodeBlocks.set(token, match[0]);
|
|
102
107
|
tokenizedHTML += token;
|
|
103
108
|
|
|
104
109
|
lastIndex = match.index + match[0].length;
|
|
@@ -110,7 +115,7 @@ export function tokenizeHTML(htmlContent) {
|
|
|
110
115
|
|
|
111
116
|
export function unTokenizeHTML(tokenizedHTML, phpCodeBlocks) {
|
|
112
117
|
let phpContent = tokenizedHTML;
|
|
113
|
-
for (const token
|
|
118
|
+
for (const [token, phpBlock] of phpCodeBlocks) {
|
|
114
119
|
/**
|
|
115
120
|
* Create a pattern from token that matches whitespace breaks resulting
|
|
116
121
|
* from Prettier's HTML formatting, usually on very long lines.
|
|
@@ -120,7 +125,7 @@ export function unTokenizeHTML(tokenizedHTML, phpCodeBlocks) {
|
|
|
120
125
|
const regexToken = new RegExp(token.replace("_ />", "_\\s+\\/>"), "g");
|
|
121
126
|
phpContent = phpContent.replace(
|
|
122
127
|
regexToken,
|
|
123
|
-
|
|
128
|
+
phpBlock.replace(/\$/g, "$$$$"),
|
|
124
129
|
);
|
|
125
130
|
}
|
|
126
131
|
return phpContent;
|
|
@@ -157,6 +162,7 @@ async function formatHTMLThenPHP(filepath) {
|
|
|
157
162
|
...phpOptions,
|
|
158
163
|
parser: "php",
|
|
159
164
|
embeddedLanguageFormatting: "auto",
|
|
165
|
+
// plugins: [phpPlugin], // Explicitly pass the plugin
|
|
160
166
|
});
|
|
161
167
|
|
|
162
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
|
/**
|