Semantic versioning javascript projects but skipping NPM publish

Published on October 11, 2021

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"
    ],
}

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"
    ]
}

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 have 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"
}

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

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

Hi! I'm Darragh ORiordan.

I live and work in Sydney, Australia building and supporting happy teams that create high quality software for the web.

I also make tools for busy developers! Do you have a new M1 Mac to setup? Have you ever spent a week getting your dev environment just right?

My Universal DevShell tooling will save you 30+ hours of configuring your Windows or Mac dev environment with all the best, modern shell and dev tools.

Get DevShell here: ✨ https://usemiller.dev/dev-shell


Read more articles like this one...

List of article summaries

#nodejs

Running a NodeJS app with Postgres in Dokku

I have some side projects that don’t see much traffic so I run them on a 5$ Digital Ocean droplet running Dokku.

Dokku is an open source Heroku-like platform. It’s super easy to create and maintain multiple applications on a Dokku instance. It’s perfect for solo makers.

There are plugins for most of the common services you might want like PostgreSQL or Redis.

Here’s what we’re going to do

  1. A Brief overview of Dokku
  2. How to get a Dokku instance running
  3. Create a new Dokku application
  4. Add a database service
  5. Expose the database for debugging and testing (Optional)
  6. Add a domain to the application
  7. Add any configuration variables for your application
  8. Add SSL to the application
  9. Add the Dokku remote to your application
  10. Push your application to Dokku
  11. Maintaining your Dokku server
#nodejs

npmrc authentication for a private scoped organisation package

When you have to login to npm for multiple organisations it can be easier to use an .npmrc file that you move around rather than npm login command.

#nodejs

Avoid these issues when using new ECMAScript modules in your Node.js application

ECMAScript modules are the official standard format to package JavaScript code for reuse in the future. Es6 modules now have full support in Node.js 12 and above so it’s time to start using them.

JavaScript developers and node libraries have typically used commonjs for modules up to now. If you’ve used typescript in the past few years you will be familiar with the module import syntax in you application. Instead of commonjs require("module") most typescript applications use some variation of import module from "module".

Typescript will then transpile this import syntax into commonjs require statements for you. This step is not necessary in modern Node.js applications. You can just use import module from "module" directly in your transpiled code.

If you use typescript you can change just change your tsconfig settings to output ECMAScript es6 modules and you will be good to go. If you don’t use typescript you might have to do some rewriting if you want to get your app updated.

Here are solutions to the issues that took me a bit of time and investigation to figure out when I was upgrading my Node.js application to use ECMAScript modules like configuring typescript, setting up jest, configuring the package.json correctly and more.

Comments