@ideasonpurpose/build-tools-wordpress 2.1.7 → 2.1.9
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 +14 -0
- package/README.md +2 -2
- package/bin/format-php-prettier.js +12 -1
- package/lib/ImageminPlugins.js +1 -1
- package/package.json +24 -24
- package/test/format-php-prettier.test.js +61 -2
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.1.8
|
|
8
|
+
|
|
9
|
+
> 29 May 2025
|
|
10
|
+
|
|
11
|
+
- Fix inline-whitespace wrapped php token bug
|
|
12
|
+
- typo
|
|
13
|
+
|
|
14
|
+
#### v2.1.7
|
|
15
|
+
|
|
16
|
+
> 28 May 2025
|
|
17
|
+
|
|
18
|
+
- bump deps
|
|
19
|
+
- enable sourcemaps on all CSS loaders
|
|
20
|
+
|
|
7
21
|
#### v2.1.6
|
|
8
22
|
|
|
9
23
|
> 1 May 2025
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @ideasonpurpose/build-tools-wordpress
|
|
2
2
|
|
|
3
|
-
#### Version 2.1.
|
|
3
|
+
#### Version 2.1.9
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@ideasonpurpose/build-tools-wordpress)
|
|
6
6
|
[](https://github.com/ideasonpurpose/build-tools-wordpress#readme)
|
|
@@ -31,7 +31,7 @@ Each project may optionally include an **ideasonpurpose.config.js** file in the
|
|
|
31
31
|
|
|
32
32
|
## Local Development
|
|
33
33
|
|
|
34
|
-
Because this project makes use of bin scripts, conventional `npm link` workflows won't work correctly. To work on this code
|
|
34
|
+
Because this project makes use of bin scripts, conventional `npm link` workflows won't work correctly. To work on this code in a development project, change the project's package.json to install from a local file path, probably something like this:
|
|
35
35
|
|
|
36
36
|
```json
|
|
37
37
|
"devDependencies": {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
//@ts-check
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* This is an experimental proof-of-concept for formatting mixed HTML & PHP
|
|
5
7
|
* files from a single function.
|
|
@@ -109,8 +111,15 @@ export function tokenizeHTML(htmlContent) {
|
|
|
109
111
|
export function unTokenizeHTML(tokenizedHTML, phpCodeBlocks) {
|
|
110
112
|
let phpContent = tokenizedHTML;
|
|
111
113
|
for (const token in phpCodeBlocks) {
|
|
114
|
+
/**
|
|
115
|
+
* Create a pattern from token that matches whitespace breaks resulting
|
|
116
|
+
* from Prettier's HTML formatting, usually on very long lines.
|
|
117
|
+
* eg. the token `<php_4___ />` formats to `<php_4___ \n />`
|
|
118
|
+
* This changes the token to `/<php_4___\s+\/>/g`
|
|
119
|
+
*/
|
|
120
|
+
const regexToken = new RegExp(token.replace("_ />", "_\\s+\\/>"), "g");
|
|
112
121
|
phpContent = phpContent.replace(
|
|
113
|
-
|
|
122
|
+
regexToken,
|
|
114
123
|
phpCodeBlocks[token].replace(/\$/g, "$$$$"),
|
|
115
124
|
);
|
|
116
125
|
}
|
|
@@ -128,6 +137,7 @@ async function formatHTMLThenPHP(filepath) {
|
|
|
128
137
|
...prettierConfig,
|
|
129
138
|
...htmlOptions,
|
|
130
139
|
parser: "html",
|
|
140
|
+
embeddedLanguageFormatting: "auto",
|
|
131
141
|
});
|
|
132
142
|
|
|
133
143
|
const phpUnTokenized = unTokenizeHTML(htmlFormatted, phpCodeBlocks);
|
|
@@ -136,6 +146,7 @@ async function formatHTMLThenPHP(filepath) {
|
|
|
136
146
|
...prettierConfig,
|
|
137
147
|
...phpOptions,
|
|
138
148
|
parser: "php",
|
|
149
|
+
embeddedLanguageFormatting: "auto",
|
|
139
150
|
});
|
|
140
151
|
|
|
141
152
|
await writeFile(filepath, phpFormatted, "utf8");
|
package/lib/ImageminPlugins.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ideasonpurpose/build-tools-wordpress",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.9",
|
|
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": {
|
|
@@ -35,66 +35,66 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@ideasonpurpose/prettier-config": "^1.0.1",
|
|
37
37
|
"@ideasonpurpose/stylelint-config": "^1.1.1",
|
|
38
|
-
"@rollup/plugin-commonjs": "^28.0.
|
|
38
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
39
39
|
"@rollup/plugin-json": "^6.1.0",
|
|
40
40
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
41
41
|
"@svgr/webpack": "^8.1.0",
|
|
42
|
-
"@wordpress/dependency-extraction-webpack-plugin": "^6.
|
|
42
|
+
"@wordpress/dependency-extraction-webpack-plugin": "^6.29.0",
|
|
43
43
|
"ansi-html": "^0.0.9",
|
|
44
44
|
"archiver": "^7.0.1",
|
|
45
45
|
"auto-changelog": "^2.5.0",
|
|
46
46
|
"autoprefixer": "^10.4.21",
|
|
47
47
|
"babel-loader": "^10.0.0",
|
|
48
|
-
"caniuse-lite": "^1.0.
|
|
49
|
-
"chalk": "^5.
|
|
48
|
+
"caniuse-lite": "^1.0.30001737",
|
|
49
|
+
"chalk": "^5.6.0",
|
|
50
50
|
"chalk-cli": "^6.0.0",
|
|
51
51
|
"classnames": "^2.5.1",
|
|
52
52
|
"cli-truncate": "^4.0.0",
|
|
53
|
-
"copy-webpack-plugin": "^13.0.
|
|
53
|
+
"copy-webpack-plugin": "^13.0.1",
|
|
54
54
|
"cosmiconfig": "^9.0.0",
|
|
55
|
-
"cross-env": "^
|
|
55
|
+
"cross-env": "^10.0.0",
|
|
56
56
|
"css-loader": "^7.1.2",
|
|
57
|
-
"cssnano": "^7.
|
|
58
|
-
"dotenv": "^
|
|
57
|
+
"cssnano": "^7.1.1",
|
|
58
|
+
"dotenv": "^17.2.1",
|
|
59
59
|
"esbuild-loader": "^4.3.0",
|
|
60
|
-
"eslint": "^9.
|
|
61
|
-
"filesize": "^
|
|
62
|
-
"fs-extra": "^11.3.
|
|
60
|
+
"eslint": "^9.34.0",
|
|
61
|
+
"filesize": "^11.0.2",
|
|
62
|
+
"fs-extra": "^11.3.1",
|
|
63
63
|
"globby": "^14.1.0",
|
|
64
64
|
"http-proxy": "^1.18.1",
|
|
65
|
-
"humanize-duration": "^3.
|
|
66
|
-
"image-minimizer-webpack-plugin": "^4.1.
|
|
65
|
+
"humanize-duration": "^3.33.0",
|
|
66
|
+
"image-minimizer-webpack-plugin": "^4.1.4",
|
|
67
67
|
"is-text-path": "^3.0.0",
|
|
68
68
|
"lodash": "^4.17.21",
|
|
69
|
-
"mini-css-extract-plugin": "^2.9.
|
|
69
|
+
"mini-css-extract-plugin": "^2.9.4",
|
|
70
70
|
"ora": "^8.2.0",
|
|
71
|
-
"postcss": "^8.5.
|
|
71
|
+
"postcss": "^8.5.6",
|
|
72
72
|
"postcss-loader": "^8.1.1",
|
|
73
73
|
"postcss-scss": "^4.0.9",
|
|
74
74
|
"pretty-hrtime": "^1.0.3",
|
|
75
75
|
"read-package-up": "^11.0.0",
|
|
76
76
|
"replacestream": "^4.0.3",
|
|
77
|
-
"sass-embedded": "^1.
|
|
77
|
+
"sass-embedded": "^1.90.0",
|
|
78
78
|
"sass-loader": "^16.0.5",
|
|
79
79
|
"semver": "^7.7.2",
|
|
80
|
-
"sharp": "^0.34.
|
|
81
|
-
"sort-package-json": "^3.
|
|
80
|
+
"sharp": "^0.34.3",
|
|
81
|
+
"sort-package-json": "^3.4.0",
|
|
82
82
|
"string-length": "^6.0.0",
|
|
83
83
|
"style-loader": "^4.0.0",
|
|
84
|
-
"svgo": "^
|
|
84
|
+
"svgo": "^4.0.0",
|
|
85
85
|
"svgo-loader": "^4.0.0",
|
|
86
86
|
"version-everything": "^0.11.4",
|
|
87
|
-
"webpack": "^5.
|
|
87
|
+
"webpack": "^5.101.3",
|
|
88
88
|
"webpack-bundle-analyzer": "^4.10.2",
|
|
89
89
|
"webpack-dev-middleware": "^7.4.2",
|
|
90
|
-
"webpack-dev-server": "^5.2.
|
|
90
|
+
"webpack-dev-server": "^5.2.2"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
93
93
|
"webpack-cli": "^6.0.1"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
|
-
"@vitest/coverage-v8": "^3.
|
|
97
|
-
"vitest": "^3.
|
|
96
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
97
|
+
"vitest": "^3.2.4"
|
|
98
98
|
},
|
|
99
99
|
"version-everything": {
|
|
100
100
|
"files": [
|
|
@@ -6,6 +6,16 @@ import { readFile } from "node:fs/promises";
|
|
|
6
6
|
|
|
7
7
|
import { tokenizeHTML, unTokenizeHTML } from "../bin/format-php-prettier.js";
|
|
8
8
|
|
|
9
|
+
import prettier from "prettier";
|
|
10
|
+
import prettierConfig from "@ideasonpurpose/prettier-config" with { type: "json" };
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Prettier API doesn't recognize overrides, so we extract them
|
|
14
|
+
*/
|
|
15
|
+
const htmlOptions = prettierConfig.overrides.find(
|
|
16
|
+
(o) => o.files === "*.html",
|
|
17
|
+
)?.options;
|
|
18
|
+
|
|
9
19
|
describe("HTML-PHP Prettier", () => {
|
|
10
20
|
test("All tokens exist", async () => {
|
|
11
21
|
const input = (
|
|
@@ -55,7 +65,7 @@ describe("HTML-PHP Prettier", () => {
|
|
|
55
65
|
)
|
|
56
66
|
).toString();
|
|
57
67
|
|
|
58
|
-
const { tokenizedHTML, phpCodeBlocks
|
|
68
|
+
const { tokenizedHTML, phpCodeBlocks } = tokenizeHTML(input);
|
|
59
69
|
|
|
60
70
|
// console.log({input, tokenizedHTML})
|
|
61
71
|
|
|
@@ -129,10 +139,59 @@ describe("HTML-PHP Prettier", () => {
|
|
|
129
139
|
|
|
130
140
|
// console.log({input, tokenizedHTML, phpCodeBlocks});
|
|
131
141
|
|
|
132
|
-
|
|
133
142
|
expect(tokenizedHTML).toContain("<php_0____ />");
|
|
134
143
|
expect(tokenizedHTML).toContain("<php_1____ />");
|
|
135
144
|
expect(phpCodeBlocks).toHaveProperty("<php_0____ />");
|
|
136
145
|
expect(phpCodeBlocks).toHaveProperty("<php_1____ />");
|
|
137
146
|
});
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
*
|
|
150
|
+
* Tag-style tokens towards the end of long lines may be line-wrapped by Prettier's HTML
|
|
151
|
+
* formatting, where the token `<php_4___ />` ends up as `<php_4___ \n />`
|
|
152
|
+
*
|
|
153
|
+
* That line-break means a simple string match won't work and the PHP token must be converted
|
|
154
|
+
* to a regexp that matches more than one whitespace character.
|
|
155
|
+
*
|
|
156
|
+
* This example is tricky because the <time> is an inline tag so whitespace is significant. The inner
|
|
157
|
+
* PHP codeblock has a space before it, but not after: <time> <?php ... ?></time>
|
|
158
|
+
* More here: @link https://prettier.io/blog/2018/11/07/1.15.0.html#whitespace-sensitive-formatting
|
|
159
|
+
*
|
|
160
|
+
* Input:
|
|
161
|
+
* <time class="type-eyebrow" datetime="<?= get_the_date('c') ?>"> <?= date('F j, Y', get_post_time()) ?></time>
|
|
162
|
+
*
|
|
163
|
+
* Expected:
|
|
164
|
+
* <time class="type-eyebrow" datetime="<?= get_the_date('c') ?>">
|
|
165
|
+
* <?= date('F j, Y', get_post_time()) ?></time>
|
|
166
|
+
*
|
|
167
|
+
* This is an edge case on line-length.
|
|
168
|
+
* TODO: I think the token replacement pattern needs to replace the literal space between ___ and /> with a regex token
|
|
169
|
+
* so any acquired whitespace from prettier's HTML formatter.
|
|
170
|
+
*
|
|
171
|
+
*/
|
|
172
|
+
test("extra space bug", async () => {
|
|
173
|
+
const input = `<time class="type" datetime="<?= get_the_date('c') ?>"> <?= date('F j, Y', get_post_time()) ?></time>`;
|
|
174
|
+
// const input = `<time class="typ" datetime="<?= get_the_date('c') ?>"> <?= date('F j, Y', get_post_time()) ?></time>`;
|
|
175
|
+
const { tokenizedHTML, phpCodeBlocks } = tokenizeHTML(input);
|
|
176
|
+
|
|
177
|
+
const htmlFormatted = await prettier.format(tokenizedHTML, {
|
|
178
|
+
...prettierConfig,
|
|
179
|
+
...htmlOptions,
|
|
180
|
+
parser: "html",
|
|
181
|
+
embeddedLanguageFormatting: "auto",
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const formattedContent = unTokenizeHTML(htmlFormatted, phpCodeBlocks);
|
|
185
|
+
console.log({
|
|
186
|
+
phpCodeBlocks,
|
|
187
|
+
tokenizedHTML,
|
|
188
|
+
htmlFormatted,
|
|
189
|
+
formattedContent,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
expect(tokenizedHTML).toContain("_php_0___");
|
|
193
|
+
expect(tokenizedHTML).toContain("<php_1___");
|
|
194
|
+
expect(htmlFormatted).toContain("_____\n/>");
|
|
195
|
+
expect(formattedContent).not.toContain("<php_1___");
|
|
196
|
+
});
|
|
138
197
|
});
|