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

Replace Grunt with wp-scripts #1541

Merged
merged 30 commits into from
Aug 6, 2024
Merged

Replace Grunt with wp-scripts #1541

merged 30 commits into from
Aug 6, 2024

Conversation

delawski
Copy link
Contributor

@delawski delawski commented Aug 2, 2024

Fixes #1502.

This PR replaces the legacy Grunt-based build workflow with @wordpress/scripts-based solution.

Along the way, some more general cleanup and reorg have been done:

  • JS and CSS assets have been moved from ui/ to src/ directory.
  • CSS files have been converted to SCSS for the ability to import one into another easily.
  • Select2 and jquery.timeago dependencies are now NPM packages and are copied over to the build directory by Webpack. They are also enqueued centrally in the plugin.
  • Image assets have been moved to assets directory.
  • The custom WP Stream font has been dropped in favor of using a SVG icon.
  • JS is now linted by eslint indirectly, through wp-scripts.
  • Playwright is run indirectly, through wp-scripts.
  • JS files have been slightly cleaned-up (e.g. var -> const or let) so that the linter is not complaining too much.

Checklist

  • Project documentation has been updated to reflect the changes in this pull request, if applicable.
  • I have tested the changes in the local development environment (see contributing.md).
  • I have added phpunit tests.

Release Changelog

  • Development: Replace Grunt-based build workflow with @wordpress/scripts

@delawski delawski requested a review from tharsheblows August 2, 2024 15:34
@delawski delawski added this to the 4.1.0 milestone Aug 2, 2024
@delawski delawski added enhancement tooling Development and deployment tooling improvements labels Aug 2, 2024
# Conflicts:
#	package-lock.json
#	package.json
Copy link
Contributor Author

Choose a reason for hiding this comment

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

📝 note: I just realized that JS files are incorrectly shown as new files. They have been primarily moved from the ui directory to src. Also, most of them have been modified slightly (import jquery instead of relying on a global object, replace vars with lets and consts, remove IIFEs).

I guess the best (although still no fun) way to see a real diff is to review relevant commits like:

Copy link
Contributor

@tharsheblows tharsheblows left a comment

Choose a reason for hiding this comment

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

There are two very small things which may not be issues. (This is one of those where you can see what's hurt me before 😊)

I love the tidiness of enqueuing the assets now. 💖

@@ -51,6 +51,9 @@ jobs:
- name: Install Composer dependencies
run: composer install

- name: Build
run: npm run build
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 thought
If we lint and test before building then if those fails, it should be slightly shorter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have moved the build step to before testing since - if I remember correctly - I was getting errors and tests were failing. It looks like the PHP unit tests may rely on the build step but I may be wrong and I'll have another look tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested it locally and, as expected, we can lint early, before building the assets, however we cannot run PHP Unit tests at that time. It's because now we are using the asset.php files when enqueuing JS files. They are generated as part of the build process. When there is no asset file found, a runtime exception is thrown and tests fail.

In 79b2879 I moved the lint step before the build step.

/**
* Main JS file script handle.
*/
const SCRIPT_HANDLE = 'wp-stream-alert-highlight-js';
Copy link
Contributor

Choose a reason for hiding this comment

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

🥜 nitpick
I think that just in case someone is dequeueing this for whatever reason that we should keep the constant or deprecate it?

Copy link
Contributor Author

@delawski delawski Aug 5, 2024

Choose a reason for hiding this comment

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

I must have missed it – definitely can be removed now :)

I'm sorry, I got it all wrong. You've got a valid point. Since we're not planning to release a major version anytime soon, it'd be wise to deprecate this constant instead of removing it. I'll add it back with a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 5e4acf1.

$this->plugin->get_version()
$this->plugin->enqueue_asset(
'alerts-list',
array( 'wp-stream-alerts' )
Copy link
Contributor

Choose a reason for hiding this comment

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

👏 praise
I love this! So much cleaner.

@delawski delawski merged commit a0bcd4f into develop Aug 6, 2024
2 checks passed
@delawski delawski deleted the feature/1502-remove-grunt branch August 6, 2024 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement tooling Development and deployment tooling improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove Grunt
2 participants