npmrepositorynpm-package

Create two version for a package


Is it possible provide two version of a same package npm ?

I have a git repository with :

MyRepo
|- library
|- FolderToHide
|- package.json
|- .npmignore

File package.json is containing :

{
   "name": "myRepo",
   "repository": {
     "type": "git",
     "url": "https://somewhere"
   },
   ...
}

How can I configure my package to create a version with FolderToHide and another without ?

I want to have something like this :

MyRepo2
|- node_modules
  |- myRepo
    |- library

MyRepo3
|- node_modules
  |- myRepo
    |- library
    |- FolderToHide

MyRepo3 can be used as debug repository, maybe is it possible to create a debug version for a package ?


Solution

  • If you want it to be single npm package, e.g. my-package (not two separate packages my-package and my-package-with-hidden-folder) you can use dist-tags for this.

    1. When you made changes to your package which you want to publish, add FolderToHide to your .npmignore.
    2. Add -limited to version of your package in package.json (so it looks like 2.1.0-limited) and run npm publish --tag limited (you can replace limited with any name you want). This will publish version of package without FolderToHide with tag limited.
    3. Remove FolderToHide from .npmignore
    4. Change -limited in package.json to -full and run npm publish --tag full (again, full can be any name you wish). This will publish new version of package with FolderToHide included.

    Then, when you want to install your package in another project you run either npm install my-package@limited or npm install my-package@full.

    Alternatively, you can decide to have one of versions as default option. In this case you should omit dist-tag for it. So instead of npm publish --tag full you just run npm publish. This will (implicitly) assign tag latest to published version. And when you install package without specifying tag (npm install my-package), npm will use package with latest tag.