Skip to content

Commit deb4ee7

Browse files
committed
Merge branch 'trunk' of https://github.com/WordPress/performance into update/od-detect-loader
2 parents 4deb0c7 + b837d81 commit deb4ee7

File tree

68 files changed

+2706
-615
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2706
-615
lines changed

.github/workflows/php-test-plugins.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ jobs:
4747
wp: '6.6'
4848
- php: '8.3'
4949
wp: 'trunk'
50+
- php: '8.4'
51+
wp: 'trunk'
5052
- php: '8.2'
5153
phpunit: '9.6'
5254
wp: 'latest'

.wp-env.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
23
"core": null,
34
"plugins": [
45
"./plugins/optimization-detective",

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ The feature plugins which are currently featured by this plugin are:
1414
Plugin | Slug | Experimental | Links
1515
--------------------------------|---------------------------|--------------|-------------
1616
[Embed Optimizer][5] | `embed-optimizer` | No | [Source][13], [Issues][21], [PRs][29]
17+
[Enhanced Responsive Images][6] | `auto-sizes` | No | [Source][14], [Issues][22], [PRs][30]
1718
[Image Placeholders][1] | `dominant-color-images` | No | [Source][9], [Issues][17], [PRs][25]
1819
[Image Prioritizer][7] | `image-prioritizer` | No | [Source][15], [Issues][23], [PRs][31]
1920
[Modern Image Formats][2] | `webp-uploads` | No | [Source][10], [Issues][18], [PRs][26]
2021
[Optimization Detective][33] | `optimization-detective` | No | [Source][34], [Issues][35], [PRs][36]
2122
[Performant Translations][3] | `performant-translations` | No | [Source][11], [Issues][19], [PRs][27]
2223
[Speculative Loading][4] | `speculation-rules` | No | [Source][12], [Issues][20], [PRs][28]
23-
[Enhanced Responsive Images][6] | `auto-sizes` | Yes | [Source][14], [Issues][22], [PRs][30]
24+
[View Transitions][37] | `view-transitions` | Yes | [Source][38], [Issues][39], [PRs][40]
2425
[Web Worker Offloading][8] | `web-worker-offloading` | Yes | [Source][16], [Issues][24], [PRs][32]
2526

2627
[1]: https://wordpress.org/plugins/dominant-color-images/
@@ -32,6 +33,7 @@ Plugin | Slug | Experimental | Lin
3233
[7]: https://wordpress.org/plugins/image-prioritizer/
3334
[8]: https://wordpress.org/plugins/web-worker-offloading/
3435
[33]: https://wordpress.org/plugins/optimization-detective/
36+
[37]: https://wordpress.org/plugins/view-transitions/
3537

3638
[9]: https://github.com/WordPress/performance/tree/trunk/plugins/dominant-color-images
3739
[10]: https://github.com/WordPress/performance/tree/trunk/plugins/webp-uploads
@@ -42,6 +44,7 @@ Plugin | Slug | Experimental | Lin
4244
[15]: https://github.com/WordPress/performance/tree/trunk/plugins/image-prioritizer
4345
[16]: https://github.com/WordPress/performance/tree/trunk/plugins/web-worker-offloading
4446
[34]: https://github.com/WordPress/performance/tree/trunk/plugins/optimization-detective
47+
[38]: https://github.com/WordPress/performance/tree/trunk/plugins/view-transitions
4548

4649
[17]: https://github.com/WordPress/performance/issues?q=is%3Aopen+label%3A%22%5BPlugin%5D+Image+Placeholders%22
4750
[18]: https://github.com/WordPress/performance/issues?q=is%3Aopen+label%3A%22%5BPlugin%5D+Modern+Image+Formats%22
@@ -52,6 +55,7 @@ Plugin | Slug | Experimental | Lin
5255
[23]: https://github.com/WordPress/performance/issues?q=is%3Aopen+label%3A%22%5BPlugin%5D+Image+Prioritizer%22
5356
[24]: https://github.com/WordPress/performance/issues?q=is%3Aopen%20label%3A%22%5BPlugin%5D%20Web%20Worker%20Offloading%22
5457
[35]: https://github.com/WordPress/performance/issues?q=is%3Aopen%20label%3A%22%5BPlugin%5D%20Optimization%20Detective%22
58+
[39]: https://github.com/WordPress/performance/issues?q=is%3Aopen%20label%3A%22%5BPlugin%5D%20View%20Transitions%22
5559

5660
[25]: https://github.com/WordPress/performance/pulls?q=is%3Apr+is%3Aopen+label%3A%22%5BPlugin%5D+Image+Placeholders%22
5761
[26]: https://github.com/WordPress/performance/pulls?q=is%3Apr+is%3Aopen+label%3A%22%5BPlugin%5D+Modern+Image+Formats%22
@@ -62,5 +66,6 @@ Plugin | Slug | Experimental | Lin
6266
[31]: https://github.com/WordPress/performance/pulls?q=is%3Apr+is%3Aopen+label%3A%22%5BPlugin%5D+Image+Prioritizer%22
6367
[32]: https://github.com/WordPress/performance/pulls?q=is%3Apr+is%3Aopen+label%3A%22%5BPlugin%5D+Web%20Worker%20Offloading%22
6468
[36]: https://github.com/WordPress/performance/pulls?q=is%3Apr+is%3Aopen+label%3A%22%5BPlugin%5D+Optimization%20Detective%22
69+
[40]: https://github.com/WordPress/performance/pulls?q=is%3Apr+is%3Aopen+label%3A%22%5BPlugin%5D+View%20Transitions%22
6570

6671
Note that the plugin names sometimes diverge from the plugin slugs due to scope changes. For example, a plugin's purpose may change as some of its features are merged into WordPress core.

bin/plugin/commands/changelog.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const PRIMARY_TYPE_LABELS = {
2323
const PRIMARY_TYPE_ORDER = Object.values( PRIMARY_TYPE_LABELS );
2424
const SKIP_CHANGELOG_LABEL = 'skip changelog';
2525

26-
/** @typedef {import('@octokit/rest')} GitHub */
27-
/** @typedef {import('@octokit/rest').IssuesListForRepoResponseItem} IssuesListForRepoResponseItem */
26+
/** @typedef {import('@octokit/rest').Octokit} GitHub */
27+
/** @typedef {import('@octokit/rest').RestEndpointMethodTypes['issues']['listForRepo']['response']['data'][0]} IssuesListForRepoResponseItem */
2828

2929
/**
3030
* @typedef WPChangelogCommandOptions
@@ -115,7 +115,7 @@ async function fetchAllPullRequests( octokit, settings ) {
115115
*/
116116
function getIssueType( issue ) {
117117
const typeLabels = issue.labels
118-
.map( ( { name } ) => name )
118+
.map( ( label ) => ( typeof label === 'string' ? label : label.name ) )
119119
.filter( ( label ) => label.startsWith( TYPE_PREFIX ) );
120120

121121
if ( ! typeLabels.length ) {
@@ -141,7 +141,10 @@ function formatChangelog( milestone, pullRequests ) {
141141
let changelog = '';
142142

143143
// Group PRs by type.
144-
const typeGroups = groupBy( pullRequests, getIssueType );
144+
const typeGroups =
145+
/** @type {Object<string, IssuesListForRepoResponseItem[]>} */ (
146+
groupBy( pullRequests, getIssueType )
147+
);
145148
if ( typeGroups[ MISSING_TYPE ] ) {
146149
const prURLs = typeGroups[ MISSING_TYPE ].map(
147150
( { html_url } ) => html_url // eslint-disable-line camelcase
@@ -161,7 +164,7 @@ function formatChangelog( milestone, pullRequests ) {
161164
return aIndex - bIndex;
162165
}
163166
if ( aIndex === -1 && bIndex === -1 ) {
164-
return a - b;
167+
return a.localeCompare( b );
165168
}
166169
return aIndex > -1 ? -1 : 1;
167170
} );
@@ -219,9 +222,11 @@ async function getChangelog( settings ) {
219222

220223
const nonSkippedPullRequests = pullRequests.filter(
221224
( pullRequest ) =>
222-
! pullRequest.labels.find(
223-
( { name } ) => name === SKIP_CHANGELOG_LABEL
224-
)
225+
! pullRequest.labels
226+
.map( ( label ) =>
227+
typeof label === 'string' ? label : label.name
228+
)
229+
.find( ( name ) => name === SKIP_CHANGELOG_LABEL )
225230
);
226231
if ( ! nonSkippedPullRequests.length ) {
227232
throw new Error(

bin/plugin/config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
const config = {
1212
githubRepositoryOwner: 'WordPress',
1313
githubRepositoryName: 'performance',
14-
textDomain: 'performance-lab',
1514
};
1615

1716
module.exports = config;

bin/plugin/lib/logger.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ const { styleText } = require( 'node:util' );
66
/**
77
* Create a function that applies a style to text using `node:util.styleText`.
88
*
9-
* @param {string} style Style to apply to the text
10-
*
11-
* @return {Function} Function that applies the style to the text
9+
* @param {Parameters<typeof import('node:util').styleText>[0]} style - Style to apply to the text.
10+
* @return {function(string):string} Function that applies the style to the text.
1211
*/
1312
const createStyledText = ( style ) => ( text ) => styleText( style, text );
1413

bin/plugin/lib/milestone.js

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/** @typedef {import('@octokit/rest')} GitHub */
2-
/** @typedef {import('@octokit/rest').IssuesListForRepoResponseItem} IssuesListForRepoResponseItem */
3-
/** @typedef {import('@octokit/rest').IssuesListMilestonesForRepoResponseItem} OktokitIssuesListMilestonesForRepoResponseItem */
1+
/** @typedef {import('@octokit/rest').Octokit} GitHub */
2+
/** @typedef {import('@octokit/rest').RestEndpointMethodTypes['issues']['listForRepo']['response']} IssuesListForRepoResponseItem */
3+
/** @typedef {import('@octokit/rest').RestEndpointMethodTypes['issues']['listMilestones']['response']} IssuesListMilestonesForRepoResponseItem */
44

55
/**
66
* @typedef {"open"|"closed"|"all"} IssueState
@@ -14,7 +14,7 @@
1414
* @param {string} repo Repository name.
1515
* @param {string} title Milestone title.
1616
*
17-
* @return {Promise<OktokitIssuesListMilestonesForRepoResponseItem|void>} Promise resolving to milestone, if exists.
17+
* @return {Promise<import('@octokit/rest').RestEndpointMethodTypes['issues']['listMilestones']['response']['data'][0]|void>} Promise resolving to milestone, if exists.
1818
*/
1919
async function getMilestoneByTitle( octokit, owner, repo, title ) {
2020
const options = octokit.issues.listMilestones.endpoint.merge( {
@@ -23,9 +23,6 @@ async function getMilestoneByTitle( octokit, owner, repo, title ) {
2323
state: 'all',
2424
} );
2525

26-
/**
27-
* @type {AsyncIterableIterator<import('@octokit/rest').Response<import('@octokit/rest').IssuesListMilestonesForRepoResponse>>}
28-
*/
2926
const responses = octokit.paginate.iterator( options );
3027

3128
for await ( const response of responses ) {
@@ -48,9 +45,7 @@ async function getMilestoneByTitle( octokit, owner, repo, title ) {
4845
* @param {IssueState} [state] Optional issue state.
4946
* @param {string} [closedSince] Optional timestamp.
5047
*
51-
* @return {Promise<IssuesListForRepoResponseItem[]>} Promise resolving to pull
52-
* requests for the given
53-
* milestone.
48+
* @return {Promise<import('@octokit/rest').RestEndpointMethodTypes['issues']['listForRepo']['response']['data']>} Promise resolving to pull requests for the given milestone.
5449
*/
5550
async function getIssuesByMilestone(
5651
octokit,
@@ -70,14 +65,8 @@ async function getIssuesByMilestone(
7065
} ),
7166
} );
7267

73-
/**
74-
* @type {AsyncIterableIterator<import('@octokit/rest').Response<import('@octokit/rest').IssuesListForRepoResponse>>}
75-
*/
7668
const responses = octokit.paginate.iterator( options );
7769

78-
/**
79-
* @type {import('@octokit/rest').IssuesListForRepoResponse}
80-
*/
8170
const pulls = [];
8271

8372
for await ( const response of responses ) {
@@ -91,15 +80,7 @@ async function getIssuesByMilestone(
9180
return pulls.filter(
9281
( pull ) =>
9382
pull.closed_at &&
94-
closedSinceTimestamp <
95-
new Date(
96-
// The ugly `as unknown as string` cast is required because of
97-
// https://github.com/octokit/plugin-rest-endpoint-methods.js/issues/64
98-
// Fixed in Octokit v18.1.1, see https://github.com/WordPress/gutenberg/pull/29043
99-
/** @type {string} */ (
100-
/** @type {unknown} */ ( pull.closed_at )
101-
)
102-
)
83+
closedSinceTimestamp < new Date( pull.closed_at )
10384
);
10485
}
10586

bin/test-php-watch.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
#!/bin/bash
2-
if ! which inotifywait >/dev/null 2>&1; then
3-
echo "Error: the inotifywait command is not available. Make sure you have inotify-tools installed."
4-
exit 1
2+
3+
# Check for the fswatch command
4+
if ! command -v fswatch >/dev/null 2>&1; then
5+
echo "Error: The fswatch command is not available."
6+
echo "On macOS, you can install it with Homebrew: brew install fswatch"
7+
exit 1
58
fi
69

10+
cd "$(git rev-parse --show-toplevel)"
11+
712
while true; do
813
echo "Waiting for a change in the plugins directory..."
9-
output=$(inotifywait -e modify,create,delete -r ./plugins --include '.*(\.php$|/tests/.*)' 2> /dev/null)
10-
plugin_slug=$(echo "$output" | awk -F/ '{print $3}')
14+
15+
file=$(fswatch -1 -r \
16+
--event Created \
17+
--event Updated \
18+
--event Removed \
19+
--include '\.php$' \
20+
--include '/tests/' \
21+
./plugins 2>/dev/null | head -n 1)
22+
23+
# Make the file path relative.
24+
file="${file#"$PWD/"}"
25+
26+
plugin_slug=$(echo "$file" | awk -F/ '{print $2}')
1127
sleep 1 # Give the user a chance to copy text from terminal before IDE auto-saves.
1228
clear
1329
echo "Running phpunit tests for $(tput bold)$plugin_slug$(tput sgr0):"

composer.json

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@
2020
"ext-gd": "Required to use Modern Image Format's Dominant_Color_Image_Editor_GD class",
2121
"ext-zlib": "Required for compression of URL Metric data submitted to the REST API for storage in Optimization Detective"
2222
},
23+
"repositories":[
24+
{
25+
"type":"composer",
26+
"url":"https://wpackagist.org",
27+
"only": [
28+
"wpackagist-plugin/*",
29+
"wpackagist-theme/*"
30+
]
31+
}
32+
],
33+
"extra": {
34+
"installer-paths": {
35+
"vendor/{$vendor}/{$name}/": [
36+
"wpackagist-plugin/plugin-check"
37+
]
38+
}
39+
},
2340
"require-dev": {
2441
"phpcompatibility/php-compatibility": "^9.3",
2542
"phpstan/extension-installer": "^1.3",
@@ -33,12 +50,14 @@
3350
"wp-phpunit/wp-phpunit": "^6.5",
3451
"yoast/phpunit-polyfills": "^4.0",
3552
"phpstan/php-8-stubs": "^0.4.0",
36-
"phpstan/phpstan-strict-rules": "^1.6"
53+
"phpstan/phpstan-strict-rules": "^1.6",
54+
"wpackagist-plugin/plugin-check": "^1.6"
3755
},
3856
"config": {
3957
"allow-plugins": {
4058
"dealerdirect/phpcodesniffer-composer-installer": true,
41-
"phpstan/extension-installer": true
59+
"phpstan/extension-installer": true,
60+
"composer/installers": true
4261
},
4362
"platform": {
4463
"php": "7.2"

0 commit comments

Comments
 (0)