Some people say: Publish, what’s so hard? NPM publish can publish directly.

In fact, we still have questions like:

  • Did the unit tests pass?
  • How do I send test kits?
  • Can you tag it after Posting?

There is a package on Github, NP, that seems to solve the above problem.

Yes, up to a point.

First question

According to the package delivery process of NP, commit must be submitted first. But sometimes, we just say we want to send a test package to other partners, because we don’t know whether it is correct, so we don’t want to commit first.

So we have to implement — no-Git functionality, that is, with args, can bypass THE NP specification and commit packages.

One suggestion, however, is to put two commands inside scripts:

{
   "scripts": {
       "pub:test": "np --no-git"."pub": "np"}}Copy the code

Use the command above when sending test packages. To publish the official version, use the pub command.

Second question

When the version number is selected (confirmed), NP changes the version of package.json and commits to generate the local tag.

This causes a test package to be sent, and eventually a tag to be generated, as well as a COMMIT record.

So what causes it? After a long search, I finally found the culprit, and at first, I couldn’t believe it:

Yes, you read that right:

Yarn Version -- Version Version numberCopy the code

I did the following:

  • git add
  • git commit
  • git tag

Third question

Usually when we do a spec point component package, we use Commitizen.

Commitlintrc, of course, to regulate and constrain our Commit message.

So here’s the question:

  • How to modifyYarn Version -- Verion version numberthecommit message
  • releasedtypeWhat would be a better name?

Personally, I give the value of type publish. Then we looked in the documentation and found that yarn has a similar command provided :(NPM can also be found by looking in the documentation)

yarn config set version-git-message "v%s"
Copy the code

Fourth question

To protect NPM publish, disable NPM publish in the current module package and use YARN pub instead.

The antD-tools command provides guard. The antD-tools command provides guard. The antD-tools command provides guard.

See the source code, really want to send a package, can also be through:

npm publish --with-antd-tools
Copy the code

From an NP point of view, we also need to pass something like –with-antd-tools.

Fifth question

This is an extension of the fourth question, which is usually guarded like this:

{
    "scripts": {
      "prepublish": "antd-tools run guard"."prepare": "antd-tools run guard"."prepublishOnly": "antd-tools run guard",}}Copy the code

If we want to build or compile or run other commands before publish, where do we put them?

Of course you can select the prepublishOnly command and associate it with the daemon via &&.

Antd-tools does this by pre-publish. In antd-tools, pre-publish is run before publish.

So we can actually think about putting it in the np package. Of course, the execution time is after test, because test did not pass, execute build or other, personally feel not meaningful.

Sixth question

Is it over? No, no, no, this is just a normal component release.

In some scenarios, we need to use LERNA to create multiple packages.

How to maintain tags, because the default sending tags look like this:

I tried to find their solution from create-react-app:

OK, so we need to adjust the following parameter:

conclusion

Through thinking about the above six questions, we can see that there are many things in publish.

Some potholes, if we don’t step on them, we’ll never know what’s in them.