Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#49594 closed enhancement (fixed)

Consider using the "install-changed" package

Reported by: azaozz's profile azaozz Owned by: azaozz's profile azaozz
Milestone: 5.5 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch
Focuses: Cc:

Description

Follow-up from #48154.

From https://www.npmjs.com/package/install-changed:

This package is a quick and easy way of figuring out whether or not package.json has been modified. It executes npm install if the file has been modified, otherwise it does nothing.

This would be a convenience/nice-to-have to prevent building with outdated packages, then wandering why things don't work. Would also prevent erroneous changes in built files that are committed like in wp-includes/blocks or wp-includes/assets.

Attachments (1)

49594.diff (2.2 KB) - added by azaozz 5 years ago.

Download all attachments as: .zip

Change History (9)

#1 @azaozz
5 years ago

The long version of this is to always do npm install (programmatically, hard-coded) before npm run build and npm run dev, but that would slow down every build.

@azaozz
5 years ago

#2 @azaozz
5 years ago

  • Keywords has-patch needs-testing added

In 49594.diff: Add install-changed and run it when starting Grunt.

#3 @azaozz
5 years ago

  • Milestone changed from Future Release to 5.5

#4 follow-up: @bookdude13
5 years ago

  • Keywords needs-testing removed

This worked for me when changing the version of @babel/polyfill.

Note that package.js was not marked as modified when the WordPress version was updated. The plugin only appears to check if package versions change, not general file changes.

Ready for commit?

#5 in reply to: ↑ 4 @azaozz
5 years ago

Replying to bookdude13:

Ready for commit?

Yes, think so. Thanks for testing.

The plugin only appears to check if package versions change, not general file changes.

Yep, it is pretty simple. Stores a hash from package.json and compares it when run. This makes it very good not only after the packages have been updated but also when the working copy was "reverted" to an earlier revision. It will "revert" node_modules to the proper versions.

#6 @azaozz
5 years ago

  • Owner set to azaozz
  • Resolution set to fixed
  • Status changed from new to closed

In 47497:

Build/Test Tools: Introduce Install-changed. It keeps a hash of package.json and compares it when run. If it has any changes, it runs npm install.

This keeps node_modules always updated and is useful not only when the packages have been updated, but also when the working copy has been "reverted" to an earlier revision.

Fixes #49594.

#7 @ocean90
5 years ago

There's just one minor issue with install-changed: The hash isn't updated when running npm install manually. The next task will call npm install again although node_modules is already up to date.

#8 @desrosj
4 years ago

In 49369:

Build/Test Tools: Use install-changed to install NPM dependencies in GitHub Action workflows.

The install-changed package records a hash of the package.json file locally in a text file and only runs npm install when there are changes to account for.

This builds on [47497], which only hashes the package.json file after a Grunt task is called. By using npx install-changed within the workflow files, the package is hashed before the first Grunt task is run.

Props ocean90.
See #50401, #49594.

Note: See TracTickets for help on using tickets.