Skip to content
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

Introduce React Scanner for component usage stats #65463

Merged
merged 17 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ coverage
# Directories/files that may appear in your environment
*.log
yarn.lock
results
/artifacts
/test/e2e/artifacts
/perf-envs
Expand Down
240 changes: 236 additions & 4 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"react-native": "0.73.3",
"react-native-url-polyfill": "1.1.2",
"react-refresh": "0.14.0",
"react-scanner": "1.2.0",
"react-test-renderer": "18.3.1",
"reassure": "0.7.1",
"redux": "4.1.2",
Expand Down Expand Up @@ -179,6 +180,7 @@
"build:plugin-zip": "bash ./bin/build-plugin-zip.sh",
"clean:package-types": "tsc --build --clean && rimraf \"./packages/*/build-types\"",
"clean:packages": "rimraf \"./packages/*/@(build|build-module|build-style)\"",
"component-usage-stats": "node ./node_modules/react-scanner/bin/react-scanner -c ./react-scanner.config.js",
"dev": "cross-env NODE_ENV=development npm run build:packages && concurrently \"wp-scripts start\" \"npm run dev:packages\"",
"dev:packages": "cross-env NODE_ENV=development concurrently \"node ./bin/packages/watch.js\" \"tsc --build --watch\"",
"distclean": "git clean --force -d -X",
Expand Down
34 changes: 34 additions & 0 deletions react-scanner.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = {
// Crawl the entire repo
crawlFrom: './',
// Needed for properly reporting components with dot notation
includeSubComponents: true,
// Exclude usage in tests, stories, and React Native files.
Copy link
Contributor

Choose a reason for hiding this comment

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

I ran the command on my machine and it looks like the report is including some React Native usage information. I don't think that's expected?

Screenshot 2024-10-23 at 23 51 48

Copy link
Member Author

@tyxla tyxla Oct 25, 2024

Choose a reason for hiding this comment

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

Ah, good catch. Seems like the globs doesn't work as expected. Seems like under the hood it uses a custom tool for the globbing part with different syntax - I'll fine-tune it next week to make it work.

Copy link
Member Author

Choose a reason for hiding this comment

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

This should be fixed in a39d4db.

globs: [ '**/!(test|stories)/!(*native).@(js|ts)?(x)' ],
// Exclude any vendor or docs directories
exclude: [
'bin',
'build',
'build-module',
'docs',
'node_modules',
'patches',
'platform-docs',
'test',
'tools',
'typings',
'vendor',
],
/*
* Filter out any non-component React elements and consider only imports of
* `@wordpress/components` outside of the package.
*/
importedFrom: '@wordpress/components',
// Merge experimental and unstable stats into the canonical component name
getComponentName: ( { imported, local } ) => {
return ( imported || local )
.replace( '__experimental', '' )
.replace( '__unstable', '' );
},
tyxla marked this conversation as resolved.
Show resolved Hide resolved
processors: [ [ 'raw-report', { outputTo: './results/gutenberg.json' } ] ],
tyxla marked this conversation as resolved.
Show resolved Hide resolved
};
Loading