@ideasonpurpose/build-tools-wordpress 2.6.3 → 2.6.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.
@@ -15,10 +15,10 @@ jobs:
15
15
  runs-on: ubuntu-24.04
16
16
  steps:
17
17
  # https://github.com/marketplace/actions/checkout
18
- - uses: actions/checkout@v4
18
+ - uses: actions/checkout@v6
19
19
 
20
20
  # https://github.com/actions/setup-node
21
- - uses: actions/setup-node@v4
21
+ - uses: actions/setup-node@v6
22
22
  with:
23
23
  node-version: '24'
24
24
  registry-url: 'https://registry.npmjs.org'
package/CHANGELOG.md CHANGED
@@ -4,6 +4,20 @@ 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.6.4
8
+
9
+ > 5 April 2026
10
+
11
+ - chore: update actions versions in npm-publish workflow and bump version-everything dependency
12
+ - feat: add new formatting functions for handling list elements and normalize newlines
13
+
14
+ #### v2.6.3
15
+
16
+ > 4 April 2026
17
+
18
+ - bump deps
19
+ - feat: add formatter for WordPress block pattern PHP files and corresponding tests
20
+
7
21
  #### v2.6.2
8
22
 
9
23
  > 23 March 2026
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @ideasonpurpose/build-tools-wordpress
2
2
 
3
- #### Version 2.6.3
3
+ #### Version 2.6.5
4
4
 
5
5
  [![NPM Version](https://img.shields.io/npm/v/%40ideasonpurpose%2Fbuild-tools-wordpress?logo=npm)](https://www.npmjs.com/package/@ideasonpurpose/build-tools-wordpress)
6
6
  [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ideasonpurpose/build-tools-wordpress/npm-publish.yml?logo=github&logoColor=white)](https://github.com/ideasonpurpose/build-tools-wordpress#readme)
@@ -84,6 +84,7 @@ export function normalizeCommentTagSpacing(content) {
84
84
  "wp:heading",
85
85
  "wp:image",
86
86
  "wp:list",
87
+ "wp:list-item",
87
88
  "wp:media-text",
88
89
  "wp:paragraph",
89
90
  "wp:pattern",
@@ -111,6 +112,49 @@ export function normalizeCommentTagSpacing(content) {
111
112
  return newContent;
112
113
  }
113
114
 
115
+ /**
116
+ * Remove extra blank lines (more than 2) and trim leading/trailing whitespace
117
+ * @param {string} content
118
+ * @returns {string}
119
+ */
120
+ export function normalizeNewlines(content) {
121
+ return (
122
+ content
123
+ .replace(/^[ \t]+$/gm, "")
124
+ .replace(/\n{3,}/g, "\n\n")
125
+ .trim() + "\n"
126
+ );
127
+ }
128
+
129
+ /**
130
+ * Special handling of space inside <li> elements
131
+ * @param {string} content
132
+ * @returns {string}
133
+ */
134
+ export function trimInsideListElements(content) {
135
+ return content
136
+ .replace(/\s*<!-- wp:list /g, "<!-- wp:list ")
137
+ .replace(/>\s*<!-- wp:list /g, ">\n\n<!-- wp:list ")
138
+ .replace(/>\s*<!-- wp:list-item /g, ">\n\n<!-- wp:list-item ")
139
+ .replace(/<!-- \/wp:list-item -->\s*</g, "<!-- \/wp:list-item -->\n\n<")
140
+ .replace(/<li>\s*/g, "<li>")
141
+ .replace(/\s*<\/li>/g, "</li>");
142
+ }
143
+
144
+ /**
145
+ * @param {string} content
146
+ * @returns {Promise<string>}
147
+ */
148
+ export function formatWithPrettier(content) {
149
+ return prettier.format(content, {
150
+ parser: "html",
151
+ tabWidth: 2,
152
+ useTabs: false,
153
+ printWidth: 80,
154
+ htmlWhitespaceSensitivity: "css",
155
+ });
156
+ }
157
+
114
158
  /**
115
159
  * @param {String} filepath
116
160
  */
@@ -119,20 +163,20 @@ async function formatWPBlockPattern(filepath) {
119
163
  const startTime = process.hrtime.bigint();
120
164
  const rawFile = await readFile(filepath, "utf8");
121
165
 
122
- const formattedHTML = await prettier.format(rawFile, {
123
- parser: "html",
124
- tabWidth: 0,
125
- useTabs: false,
126
- printWidth: 80,
127
- htmlWhitespaceSensitivity: "css",
128
- });
129
-
130
- const cleanedWhiteSpace = normalizeCommentTagSpacing(formattedHTML);
131
- const formattedCommentsJSON = formatAllWpComments(cleanedWhiteSpace);
132
- const finalFormatted =
133
- formattedCommentsJSON.replace(/\n{3,}/g, "\n\n").trim() + "\n";
166
+ const formatters = [
167
+ formatWithPrettier,
168
+ normalizeCommentTagSpacing,
169
+ formatAllWpComments,
170
+ trimInsideListElements,
171
+ normalizeNewlines,
172
+ ];
173
+
174
+ const outputHtml = await formatters.reduce(
175
+ async (acc, fn) => fn(await acc),
176
+ Promise.resolve(rawFile),
177
+ );
134
178
 
135
- await writeFile(filepath, finalFormatted, "utf8");
179
+ await writeFile(filepath, outputHtml, "utf8");
136
180
  const endTime = process.hrtime.bigint();
137
181
  const duration = Number(endTime - startTime);
138
182
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ideasonpurpose/build-tools-wordpress",
3
- "version": "2.6.3",
3
+ "version": "2.6.5",
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": {
@@ -88,7 +88,7 @@
88
88
  "style-loader": "^4.0.0",
89
89
  "svgo": "^4.0.1",
90
90
  "svgo-loader": "^5.0.0",
91
- "version-everything": "^0.11.4",
91
+ "version-everything": "^0.12.2",
92
92
  "webpack": "^5.105.4",
93
93
  "webpack-bundle-analyzer": "^5.3.0",
94
94
  "webpack-dev-middleware": "^8.0.2",
@@ -8,6 +8,7 @@ import {
8
8
  formatWpCommentJson,
9
9
  formatAllWpComments,
10
10
  normalizeCommentTagSpacing,
11
+ trimInsideListElements,
11
12
  } from "../bin/format-wp-block-pattern.js";
12
13
 
13
14
  describe("Format JSON in WP Block comments", () => {
@@ -96,6 +97,17 @@ describe("Normalize whitespace", () => {
96
97
  const actual = normalizeCommentTagSpacing(input);
97
98
  expect(actual).toMatch(/<\/div>\n<!-- \/wp:group -->/);
98
99
  });
100
+
101
+ test("List handling", async () => {
102
+ const input = (
103
+ await readFile(
104
+ "./test/fixtures/format-wp-block-pattern/nested-list.php",
105
+ )
106
+ ).toString();
107
+
108
+ const actual = trimInsideListElements(input);
109
+ expect(actual).toMatch(/<\/div>\n<!-- \/wp:group -->/);
110
+ });
99
111
  });
100
112
 
101
113