Skip to content

Instantly share code, notes, and snippets.

Publishing pre-release versions of an NPM package

There are times when we want to be able to publish pre-release (ala SNAPSHOT in maven terminology) versions of NPM packages to the NPM registry. We want to do this so as to provide these pre-release versions to CI builds of other dependant components etc. But what we do NOT want is for these pre-release packages to be unknowingly installed by someone that simply runs npm install <packagename> (i.e. does not specify an @<version> suffix).

Key Concepts

Here are the key things you need to understand in order to be able to publish pre-release versons of packages:

  1. By default, the npm publish command publishes the package and gives a tag of latest to the version in the package.json, overwriting the lasts latest tag version.
  2. By default, the npm install command installs the package version that has the latest tag.
{
"customer": {
"label": "Customer",
"fields" : [
{"name":"id", "label":"Id", "provideOn": {"create": "mandatory"}},
{"name":"firstName","label":"First Name", "provideOn": {"create": "mandatory"}},
{"name":"lastName", "label":"Last Name", "provideOn": {"create": "mandatory"}},
{"name":"email","label":"Email", "provideOn": {"create": "mandatory"}}
],
"rest": "/api/customer"
package com.cloudbees.weave.sample.shopping;
import com.cloudbees.weave.api.webhook.WEAVEHook;
import com.cloudbees.weave.sample.shopping.model.Response;
import com.cloudbees.weave.sample.shopping.model.Shipment;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
package com.cloudbees.weave.sample.shopping;
import com.cloudbees.weave.sample.shopping.model.Customer;
import com.cloudbees.weave.sample.shopping.model.Response;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
package com.foxweave.mocksaas;
import com.cloudbees.weave.api.webhook.WEAVEHook;
import com.foxweave.mocksaas.model.Contact;
import com.foxweave.mocksaas.model.Response;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
package com.foxweave.mocksaas;
import com.cloudbees.weave.api.webhook.WEAVEHook;
import com.foxweave.mocksaas.model.Contact;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
package com.foxweave.mocksaas;
import com.cloudbees.weave.api.webhook.WEAVEHook;
import com.foxweave.mocksaas.model.Contact;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
package com.foxweave.mocksaas.model;
import com.cloudbees.weave.api.webhook.JSONSerializable;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.ObjectMapper;
import java.io.IOException;
/**
* @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
package com.foxweave.mocksaas;
@Path("/geolocation")
@Produces("application/json")
@Consumes("application/json")
public class ContactService {
@Inject
private WEAVEHook weaveHook;
{
"contact": {
"runtime": "com.foxweave.mocksaas.model.Contact",
"label": "Contact",
"fields" : [
{"name":"id", "label":"Id", "provideOn": {"read": "mandatory", "create": "exclude"}},
{"name":"firstName","label":"First Name", "provideOn": {"create": "mandatory"}},
{"name":"lastName", "label":"Last Name", "provideOn": {"create": "mandatory"}},
{"name":"email","label":"Email", "provideOn": {"create": "mandatory"}}
],