npm publish: with tag and kind? - npm

We have a storybook / react component library, we have a master branch which is being published like so: make publish kind=patch
The Makefile command which works as expected:
.PHONY: publish
publish:
npm version $(kind)
tsc && cp ./package.json ./dist
(cd dist; npm publish) && rm -fr ./dist
git push && git push --tags
This takes the patch, applies a version then compiles to ./dist, and publishes, then deletes ./dist, pushes the git commit and git tags... great...
But we have a new development branch that needs to be published as well, how do you tag or label the development version without interfering with the master branch?

Related

NPM Version Not Committing Workspace package.json

When trying to set the version of all work-spaces I have found that only the root workspace change is committed. Steps to reproduce using Angular CLI:
ng new test-workspace --create-application false
cd test-workspace
ng generate application test-app
git add --all
git commit -m "Application"
ng generate library test-lib
git add --all
git commit -m "Library"
Change root-level package.json to include:
"workspaces": [
"projects/test-lib"
]
git add --all
git commit -m "Workspaces"
npm version --workspaces --include-workspace-root true --workspaces-update false 0.0.2
After the final step test-lib/package.json has been changed to the new version but has not been commited.

npm workspaces: update workspace package.json's embedded in package-lock.json

I am using npm workspaces to manage a monorepo. I've noticed that the top-level package-lock.json includes a cached copy of each workspace's package.json, in its "package" field. How can I refresh these cached copies without also updating all dependency versions in package-lock.json?
So far, the best approach I've found is:
Delete the top-level package-lock.json.
Run npm i.
This works, but also updates all dependency versions in package-lock.json. I would prefer to avoid that, in case updating a dependency breaks something, and because this creates enormous git diffs for package-lock.json.
Non-solutions
Running npm update <workspace package name> does not work, at least if I have changed a workspace's package version number (No matching version found for <package name>#<new version>).
Same issue if I try npm i --package-lock-only as suggested here.
Motivation
package-lock.json is checked into my git monorepo, so I presume I need to update it like this each time I bump the workspace packages' versions.
I've also experienced a problem in the past where I updated the bin field in a workspace's package.json, but npm ci kept using the old version. That was fixed by refreshing package-lock.json, but again at the cost of updating all dependency versions.
you can write your own script for e.g.:
get the workspaces:
WORKSPACES=`jq -r '.workspaces | #sh' package.json | tr -d \\'`
then run a bash for loop:
for w in ${WORKSPACES[#]}; do echo \"$w\" && pushd . && cd $w && npm i && rm -rf node_modules; popd; done;"
so in pacakge.json you could combinging in a script:
"update": "WORKSPACES=`jq -r '.workspaces | #sh' package.json | tr -d \\'` && for w in ${WORKSPACES[#]}; do echo \"$w\" && pushd . && cd $w && npm i && rm -rf node_modules; popd; done;"
or something like that.
Hope it helps.
Use npm version command to update the version in both package.json and package-lock.json
npm version <version> --workspace=<package-name>

How to get the sources of a npm package locally when developing?

I am very new to node and npm and I am wondering if it is possible to work on a application, but also work on a local git repository for some node modules.
Let's say I am starting a new project that uses chalk and I would like to develop both on my project and on chalk.
mkdir my-project && cd my-project
npm install
npm install --save chalk/chalk
With the above command I will the source of chalk into node_modules but I cannot contribute to it.
Is there a way to directly get the Git repository?
Asumming '~/projects' is your projects folder, first clone chalk:
cd ~/projects
git clone https://github.com/chalk/chalk.git
Then create your project:
mkdir my-project && cd my-project
npm init
And set your project to use your local chalk. Look for package.json file inside my-project and include chalk in dependencies:
"dependencies": {
"chalk": "file:../chalk"
....
....
Then install chalk in your project:
cd ~/my-project
npm install chalk
Or simply 'npm install' to install all your dependencies. Every time you need to include in your project changes you made on chalk type again 'npm install chalk'. It copies ~/chalk on ~/my-project/node_modules and uses it.
You can continue working on your project and on chalk.

How to run the official vue.js examples?

I git cloned vue, cd'ed into one of the examples folder and ran npm install. Everything went fine, then I ran npm run dev and it gets stuck at this stage. Is there anything else I should do to run this locally?
npm run dev
> vue#2.4.2 dev /vue
> rollup -w -c build/config.js --environment TARGET:web-full-dev
bundling...
bundled in 2456ms. Watching for changes...
You need to run a local web server.
Try this:
Install http-server package with npm:
$ sudo npm install -g http-server
Run it in the root of the vue cloned folder:
$ git clone git#github.com:vuejs/vue.git
$ cd vue
$ http-server -o -c .
In yout browser, navigate to the examples folder, for instance:
http://127.0.0.1:8081/examples/select2/
They are the same from here:
https://v2.vuejs.org/v2/examples/

How to install bower component with git submodules as a dependency?

I have a library which requires 2 dependencies to exist in the "vendor" directory. This library has these 2 dependencies installed as git submodules on Github, so to install my library from a Git clone you would do:
git clone --recursive https://github.com/MYLIBRARY.git
And to install it as another Git submodule, you would do:
git submodule add https://github.com/MYLIBRARY.git && git submodule update --init --recursive
The issue comes when trying to install it with Bower, as the Git submodules do not get downloaded with the bower package (the dependency folders exist, but are empty). The 2 dependencies exist separately on bower, but as they are required to be in the "vendor" directory of the main library, I cannot include them as bower dependencies. I also can't assume that any project installing my library will be a Git repo, so I can't do something like:
bower install MYLIBRARY && git submodule update --init --recursive
Which would work if the parent project you installed my library in was a Git repo, but would error if not.
I'm worried I may have to have an instruction similar to:
bower install MYLIBRARY && cd bower_componets/MYLIBRARY && git clone https://github.com/DEPENDENCY1.git vendor/DEPENDENCY1 && git clone https://github.com/DEPENDENCY2.git vendor/DEPENDENCY2
This can be tidied slightly by adding an npm run script in package.json:
"scripts": {
"bower_vendor": "git clone https://github.com/DEPENDENCY1.git vendor/DEPENDENCY1 && git clone https://github.com/DEPENDENCY2.git vendor/DEPENDENCY2"
}
Then the installation instruction would become:
bower install MYLIBRARY && cd bower_componets/MYLIBRARY && npm run bower_vendor
Which is a little neater, but again wouldn't work if the user has customised their bower_components directory (which is simple enough to change in the above command, but is still another concern).
I'm hoping I've just missed something somewhere which will solve my issue. I read that bower performs a git clone of the repo, so if there was a way to get it to perform git clone --recursive that would be amazing.
Thanks