After an NPM package is published, it can be discarded or deleted. The difference between the discarded and deleted packages is as follows:

  • Deprecation does not remove packages or versions from the NPM repository, but downloads and installations can continue, with a warning at installation time
  • Deleting will completely remove the package from NPM and will not be downloaded and installed

Whether discarded or deleted, there are two levels:

  • Version deprecation/deletion
  • Package deprecation/deletion

A, waste

Reasons for abandonment:

  • Version: Users are encouraged to update the latest version
  • Package: The contents of this package are outdated and not worth maintaining

Step 1: Deprecate the specified version

Syntax: NPM deprecate < PKG >[@

]

Take YUYY-test-PKG as an example:

NPM deprecate [email protected]'test deprecate'
Copy the code

NPM view YUyy-test-pkg versions

Step 2: Install the obsolete version

Switch to the test-my-pkg directory and execute:

NPM I [email protected]Copy the code

Running results:

Step 3: Run index.js

In the test-my-pkg directory

node index.js
Copy the code

Results:

Second, delete,

NPM does not encourage any kind of deletion, mainly because the package we distribute may have been referenced by others, and if we delete this package, others may have problems finding the package when reinstalling the project that contains our package’s dependencies.

Based on this, NPM makes relevant deletion restrictions:

  • Deleted version can be reissued 24 hours later!
  • Only packages published within 72 hours can be deleted!

Step 1: Delete the published package

The packages we previously published in THE NPM Release Package Tutorial (2) : Release Package are for demonstration only, we have removed them to keep the NPM repository pure:

npm unpublish yuyy-test-pkg --force
npm unpublish @yuyy/babel --force
Copy the code

Step 2: Go to the official website

The second step

Switch to the test-my-pkg directory and uninstall the two packages:

npm rm yuyy-test-pkg @yuyy/babel
Copy the code

Results:

Then reinstall:

npm i yuyy-test-pkg @yuyy/babel
Copy the code

Results:

Deleted packages cannot be installed again.

Now that we have demonstrated the full life cycle of the NPM package, you can contribute your own package to NPM, which is another important way to open source.

Finally, as a developer, we all have a responsibility and responsibility to keep the community clean, so we should try to be as good as possible when releasing NPM packages, so as not to confuse others with something worthless. Building a better ecosystem is everyone’s responsibility.

Related articles:

1. NPM Release Package Tutorial (PART 1) : Starting with NPM

2. NPM Release Package Tutorial (II) : Release Package

3. “NPM Release Package Tutorial (iii) : Installation and Loading Principles”

4. NPM Release Package Tutorial (4) : Iteration

5. NPM Release Package Tutorial (5) : Discard/Delete