chore: fix deprecated npm script & add check for version and unexpected files before publishing to npm #998
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
According to recent mistakes in publishing to npm, sometimes some files neither tracked by git nor ignored by the
.npmignore
file are unexpectedly published [1], and more often, the versions in different files are inconsistent [2][3], which is more serious than the former. Therefore, I've added a scriptbuild/prepublish.js
that runs before really publishing distribution files to npm to reduce the possibility of this kind of mistake.Changes
1. Replace the deprecated
prepublish
hook in favor ofprepare
&prepublishOnly
.2. Check the consistency of versions in different key distribution files.
This will output the version in each file and the file path to help you confirm if they are all expected.
If the version in any file doesn't match the others, an error will be shown, and it will give the corresponding steps to fix it.
3. Check if there are unexpected files that probably shouldn't be published.
This will list all untracked files by git and check if they have been ignored by the
.npmignore
file.If not, an error will be shown and output all unexpected files for double-check.