DEV Community

Darragh O'Riordan
Darragh O'Riordan

Posted on • Originally published at darraghoriordan.com on

Semantic versioning javascript projects with no npm publish

If you want to use semantic versioning and automate release versions using semantic-release for your front-end client application you probably don’t want to actually publish it to npm.

Here is how to use semantic-release while not releasing to npm.

Semantic release overview

The semantic-release package comes with default plugins that are perfect for publishing libraries. It will

  1. Analyse the commit message and find the latest version
  2. Update the package.json
  3. Publish to npm
  4. Publish release notes to github

For front end applications we don’t want to publish to npm but we still want to update the package.json. So we can’t fully disable the npm plugin.

There are a couple of ways to prevent publishing.

Set private package

If you set the package.json to private then the npm plugin should detect that the package is not meant to be published and will skip publishing.

You have to be careful with this setting. It is a boolean, not a string! This caught me out before. Notice the boolean private property below.

{
  "name": "darragh-o-riordan-com",
  "description": "Personal site for Darragh ORiordan",
  "version": "2.0.0",
  "author": "Darragh ORiordan <darragh.oriordan@gmail.com>",
  "private": true,
  "repository": {
    "type": "git",
    "url": "git+https://github.com/myAccount/my-repo.git"
  },
  "release": {
    "branches": [
      "main"
    ],
}
Enter fullscreen mode Exit fullscreen mode

Explicitly disable publishing

You can provide settings to the semantic-release plugins, once you override a plugin setting you have to specify all plugins, it will override all the default plugins. So remember to add them all back.

Here I set npmPublish to false.

{
  "name": "darragh-o-riordan-com",
  "description": "Personal site for Darragh ORiordan",
  "version": "2.0.0",
  "author": "Darragh ORiordan <darragh.oriordan@gmail.com>",
  "private": true,
  "repository": {
    "type": "git",
    "url": "git+https://github.com/myAccount/my-repo.git"
  },
  "release": {
    "branches": [
      "main"
    ],
    "plugins": [
      "@semantic-release/commit-analyzer",
      "@semantic-release/release-notes-generator",
      [
        "@semantic-release/npm",
        {
          "npmPublish": false
        }
      ],
      "@semantic-release/github"
    ]
}
Enter fullscreen mode Exit fullscreen mode

Set a repository

Don’t forget to set a repository when configuring semantic-release. This is required for tagging and publishing github release notes if you’re doing those.

Package name and scope

If you aren’t publishing the package you might hae skipped setting a proper name on the package but if you’re using semantic release and the npm plugin you should set the correct scope.

e.g. this is fine if i don’t have a scope or organisation

{
  "name": "darragh-o-riordan-com",
  "description": "Personal site for Darragh ORiordan"
}
Enter fullscreen mode Exit fullscreen mode

but if i’m using an organisation or scope (very common for most businesses) then i need to specify this.

{
  "name": "@myOrganisation/darragh-o-riordan-com",
  "description": "Personal site for Darragh ORiordan"
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)