close
Skip to content

Refactor validation tools and update related scripts#77522

Merged
manzoorwanijk merged 21 commits into
WordPress:trunkfrom
kushagra-goyal-14:try/migrate-validation-tools-to-workspace
May 14, 2026
Merged

Refactor validation tools and update related scripts#77522
manzoorwanijk merged 21 commits into
WordPress:trunkfrom
kushagra-goyal-14:try/migrate-validation-tools-to-workspace

Conversation

@kushagra-goyal-14
Copy link
Copy Markdown
Contributor

What?

Part of #75041

Why?

The issue provides more context, but in short, this PR ensures the workspace package does not rely on root dependencies once dependency isolation is enforced.

How?

This PR converts validation tools into a new workspace @wordpress/validation-tools while still relating the functionality.

Testing Instructions

Testing Instructions for Keyboard

npm run lint:lockfile
npm run lint:tsconfig
npm run other:check-local-changes
npm run other:check-licenses

or

npm run lint

@kushagra-goyal-14 kushagra-goyal-14 marked this pull request as ready for review April 22, 2026 06:22
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 22, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: kushagra-goyal-14 <kush123@git.wordpress.org>
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@kushagra-goyal-14
Copy link
Copy Markdown
Contributor Author

Hi @manzoorwanijk
I've addressed the argument issue flagged in #77063 (comment). Could you take a look and let me know if anything was missed or needs further adjustment?

@manzoorwanijk
Copy link
Copy Markdown
Member

manzoorwanijk commented Apr 22, 2026

As I mentioned in the reported PR, I already have a simpler fix for it - #77541

EDIT: Never mind. I thought this PR is trying to fix that same issue.

@manzoorwanijk
Copy link
Copy Markdown
Member

Could you take a look and let me know if anything was missed or needs further adjustment?

Thanks. I’ll have a look at this soon.

Copy link
Copy Markdown
Member

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this. Let us tidy things a bit.

Comment thread tools/validation/package.json Outdated
Comment on lines +26 to +31
"ajv": "8.17.1",
"chalk": "4.1.1",
"cross-spawn": "^7.0.6",
"glob": "7.1.2",
"jsonc-parser": "3.3.1",
"simple-git": "3.24.0"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us use the version ranges here and remove the deps that are not used in the workspace.

Suggested change
"ajv": "8.17.1",
"chalk": "4.1.1",
"cross-spawn": "^7.0.6",
"glob": "7.1.2",
"jsonc-parser": "3.3.1",
"simple-git": "3.24.0"
"chalk": "^4.1.1",
"glob": "^7.1.2",
"jsonc-parser": "^3.3.1",
"simple-git": "^3.24.0"

Comment thread tools/validation/check-licenses.mjs Outdated
collectDeps,
readPackageJson,
} from '../packages/scripts/utils/license.js';
} from '../../packages/scripts/utils/license.js';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us add @wordpress/scripts as a dev dependency to this workspace and the use @wordpress/scripts/utils/license.js here.

Comment thread tools/validation/package.json Outdated
"gutenberg",
"api-docs"
],
"homepage": "https://github.com/WordPress/gutenberg/tree/HEAD/tools/validation/README.md",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README doesn't exist.

Comment thread tools/validation/package.json Outdated
"keywords": [
"wordpress",
"gutenberg",
"api-docs"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This keyword doesn't seem to be relevant.

Comment thread package.json Outdated
"test/unit",
"tools/api-docs"
"tools/api-docs",
"tools/validation"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you update this branch from trunk, you won't need this change here.

Comment thread package.json Outdated
Comment on lines +157 to +158
"lint:lockfile": "npm run validate-package-lock --workspace @wordpress/validation-tools --",
"lint:tsconfig": "npm run validate-tsconfig --workspace @wordpress/validation-tools --",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to have --workspace argument before the other arguments, just in case the script accepts arguments.

Comment thread tools/validation/validate-tsconfig.mjs
Comment thread tools/validation/package.json Outdated
@@ -0,0 +1,42 @@
{
"name": "@wordpress/validation-tools",
"version": "1.0.0",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us use version 0

Suggested change
"version": "1.0.0",
"version": "0.0.0",

@manzoorwanijk
Copy link
Copy Markdown
Member

This needs to be updated from trunk

kushagra-goyal-14 and others added 6 commits May 11, 2026 12:26
- Refactor linting commands in package.json to use the new npm run syntax for workspaces.
- Update check-licenses script to import dependencies from @wordpress/scripts.
- Change version of @wordpress/validation-tools to 0.0.0 in package.json.
- Modify validate-package-lock.js to correctly resolve the package-lock.json path.
- Fix tsconfig validation to use JSONC parser for reading tsconfig.json.
@kushagra-goyal-14
Copy link
Copy Markdown
Contributor Author

This needs to be updated from trunk

Done

Copy link
Copy Markdown
Member

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very close. Let us try to reduce the number of changes in check-licenses.mjs to try preserving its git history.

Comment thread tools/validation/check-licenses.mjs
Comment thread bin/check-licenses.mjs
Comment on lines -22 to -31
/*
* This script checks licenses for production dependencies of packages that are
* shipped with WordPress (those with wpScript or wpScriptModuleExports in package.json).
*
* It works independently of the package manager (npm, pnpm, etc.) by:
* 1. Reading package.json files to find wpScript packages
* 2. Reading their production dependencies
* 3. Resolving each dependency using Node's module resolution
* 4. Reading the license from each resolved package
*/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us not remove this comment please.

manzoorwanijk added a commit that referenced this pull request May 13, 2026
Replace bin/packages/validate-typescript-version.js with a generic
install-drift check that catches stale node_modules from any dependency,
not just typescript. The new script
(tools/validation/check-installed-deps.mjs) compares package-lock.json
against npm's hidden lockfile (node_modules/.package-lock.json) and
verifies installed integrity per registry-fetched entry, ignoring
workspace links and platform-skipped optional deps.

Set up tools/validation/ as a workspace (@wordpress/validation-tools,
picked up by the existing tools/* glob). Build, dev, and
build:profile-types invoke the check via
`npm run check-installed-deps --workspace @wordpress/validation-tools`.

Aligns with the validation-tools workspace direction from #77522 and

Also extends the CLI/bin/env eslint override (no-console: off) to cover
tools/validation/**, mirroring the same change in #77522.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now have tools/validation/package.json in trunk. So let us update the PR from trunk

Copy link
Copy Markdown
Member

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so close. Thank you for the changes.

Let us clean things up a bit before we can merge this

"bugs": {
"url": "https://github.com/WordPress/gutenberg/issues"
},
"type": "module",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing this? If any .js file errs, we can change the extention to .cjs.

Copy link
Copy Markdown
Contributor Author

@kushagra-goyal-14 kushagra-goyal-14 May 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right! I missed that there are two CommonJS files, validate-package-lock.js and check-local-changes.js. It's better to keep "type": "module" and rename the files to .cjs instead. Thanks (Updated after edit)

Comment thread tools/validation/package.json Outdated
Comment on lines +22 to +24
"engines": {
"node": ">=20.10.0"
},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really need the engines field here because this lives only in the monorepo.

Comment thread tools/validation/package.json Outdated
Comment on lines +36 to +40
"check-installed-deps": "node ./check-installed-deps.mjs",
"check-licenses": "node ./check-licenses.mjs",
"validate-package-lock": "node ./validate-package-lock.js",
"validate-tsconfig": "node ./validate-tsconfig.mjs",
"check-local-changes": "node ./check-local-changes.js"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us sort these alphabetically

Suggested change
"check-installed-deps": "node ./check-installed-deps.mjs",
"check-licenses": "node ./check-licenses.mjs",
"validate-package-lock": "node ./validate-package-lock.js",
"validate-tsconfig": "node ./validate-tsconfig.mjs",
"check-local-changes": "node ./check-local-changes.js"
"check-installed-deps": "node ./check-installed-deps.mjs",
"check-licenses": "node ./check-licenses.mjs",
"check-local-changes": "node ./check-local-changes.js",
"validate-package-lock": "node ./validate-package-lock.js",
"validate-tsconfig": "node ./validate-tsconfig.mjs"

Comment thread tools/eslint/config.mjs Outdated
Comment on lines +574 to +575
'tools/validation/**/*.js',
'tools/validation/**/*.mjs',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this, it's already covered by tools/** above

Suggested change
'tools/validation/**/*.js',
'tools/validation/**/*.mjs',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manzoorwanijk The linting tests are failing because the current tools/**/*.js and tools/**/*.mjs patterns don't cover .cjs files. Since there are only two cjs files in validation, should I add tools/**/*.cjs to the pattern, or would using eslint-disable-next-line no-console comments be a good idea here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we can add tools/**/*.cjs there.

Copy link
Copy Markdown
Member

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making the requested changes. This looks good now.

@manzoorwanijk manzoorwanijk merged commit f9a5024 into WordPress:trunk May 14, 2026
40 checks passed
@github-actions github-actions Bot added this to the Gutenberg 23.3 milestone May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Build Tooling Issues or PRs related to build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants