Skip to content

Fix TypeScript config #2029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
"core": null,
"plugins": [
"./plugins/optimization-detective",
Expand Down
21 changes: 13 additions & 8 deletions bin/plugin/commands/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const PRIMARY_TYPE_LABELS = {
const PRIMARY_TYPE_ORDER = Object.values( PRIMARY_TYPE_LABELS );
const SKIP_CHANGELOG_LABEL = 'skip changelog';

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

/**
* @typedef WPChangelogCommandOptions
Expand Down Expand Up @@ -115,7 +115,7 @@ async function fetchAllPullRequests( octokit, settings ) {
*/
function getIssueType( issue ) {
const typeLabels = issue.labels
.map( ( { name } ) => name )
.map( ( label ) => ( typeof label === 'string' ? label : label.name ) )
.filter( ( label ) => label.startsWith( TYPE_PREFIX ) );

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

// Group PRs by type.
const typeGroups = groupBy( pullRequests, getIssueType );
const typeGroups =
/** @type {Object<string, IssuesListForRepoResponseItem[]>} */ (
groupBy( pullRequests, getIssueType )
);
if ( typeGroups[ MISSING_TYPE ] ) {
const prURLs = typeGroups[ MISSING_TYPE ].map(
( { html_url } ) => html_url // eslint-disable-line camelcase
Expand All @@ -161,7 +164,7 @@ function formatChangelog( milestone, pullRequests ) {
return aIndex - bIndex;
}
if ( aIndex === -1 && bIndex === -1 ) {
return a - b;
return a.localeCompare( b );
}
return aIndex > -1 ? -1 : 1;
} );
Expand Down Expand Up @@ -219,9 +222,11 @@ async function getChangelog( settings ) {

const nonSkippedPullRequests = pullRequests.filter(
( pullRequest ) =>
! pullRequest.labels.find(
( { name } ) => name === SKIP_CHANGELOG_LABEL
)
! pullRequest.labels
.map( ( label ) =>
typeof label === 'string' ? label : label.name
)
.find( ( name ) => name === SKIP_CHANGELOG_LABEL )
);
if ( ! nonSkippedPullRequests.length ) {
throw new Error(
Expand Down
1 change: 0 additions & 1 deletion bin/plugin/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
const config = {
githubRepositoryOwner: 'WordPress',
githubRepositoryName: 'performance',
textDomain: 'performance-lab',
};

module.exports = config;
5 changes: 2 additions & 3 deletions bin/plugin/lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ const { styleText } = require( 'node:util' );
/**
* Create a function that applies a style to text using `node:util.styleText`.
*
* @param {string} style Style to apply to the text
*
* @return {Function} Function that applies the style to the text
* @param {Parameters<typeof import('node:util').styleText>[0]} style - Style to apply to the text.
* @return {function(string):string} Function that applies the style to the text.
*/
const createStyledText = ( style ) => ( text ) => styleText( style, text );

Expand Down
31 changes: 6 additions & 25 deletions bin/plugin/lib/milestone.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @typedef {import('@octokit/rest')} GitHub */
/** @typedef {import('@octokit/rest').IssuesListForRepoResponseItem} IssuesListForRepoResponseItem */
/** @typedef {import('@octokit/rest').IssuesListMilestonesForRepoResponseItem} OktokitIssuesListMilestonesForRepoResponseItem */
/** @typedef {import('@octokit/rest').Octokit} GitHub */
/** @typedef {import('@octokit/rest').RestEndpointMethodTypes['issues']['listForRepo']['response']} IssuesListForRepoResponseItem */
/** @typedef {import('@octokit/rest').RestEndpointMethodTypes['issues']['listMilestones']['response']} IssuesListMilestonesForRepoResponseItem */

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

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

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

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

/**
* @type {import('@octokit/rest').IssuesListForRepoResponse}
*/
const pulls = [];

for await ( const response of responses ) {
Expand All @@ -91,15 +80,7 @@ async function getIssuesByMilestone(
return pulls.filter(
( pull ) =>
pull.closed_at &&
closedSinceTimestamp <
new Date(
// The ugly `as unknown as string` cast is required because of
// https://github.com/octokit/plugin-rest-endpoint-methods.js/issues/64
// Fixed in Octokit v18.1.1, see https://github.com/WordPress/gutenberg/pull/29043
/** @type {string} */ (
/** @type {unknown} */ ( pull.closed_at )
)
)
closedSinceTimestamp < new Date( pull.closed_at )
);
}

Expand Down
20 changes: 16 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"devDependencies": {
"@octokit/rest": "^22.0.0",
"@playwright/test": "^1.51.1",
"@types/node": "^22.15.29",
"@wordpress/e2e-test-utils-playwright": "^1.21.0",
"@wordpress/env": "^10.24.0",
"@wordpress/prettier-config": "^4.24.0",
Expand Down
2 changes: 1 addition & 1 deletion plugins/speculation-rules/wp-core-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
function plsr_filter_speculation_rules_configuration( $config ): ?array {
/*
* If speculative loading should be disable per the WordPress Core configuration, respect that value, unless pretty
* If speculative loading should be disabled per the WordPress Core configuration, respect that value, unless pretty
* permalinks are disabled and the plugin-specific filter to opt in to the feature despite that is set to true.
* This is present for backward compatibility so that usage of the plugin-specific filter does not break.
*/
Expand Down
11 changes: 7 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
"resolveJsonModule": true
},
"include": [
"*.js",
"*.mjs",
"*.ts",
"**/*.js",
"**/*.mjs",
"**/*.ts",
],
"exclude": [
"plugins/*/build/*"
"plugins/*/build/*",
"build/*",
"vendor/*",
"node_modules/*"
]
}
Loading