meta-nodejs icon indicating copy to clipboard operation
meta-nodejs copied to clipboard

Authenticating to a private repository

Open dtoubelis opened this issue 7 years ago • 1 comments

I'm trying to use run npm install to pull packages from a private repository that requires authentication. Normally I would put .npmrc file with the proper token into user's home but this didn't work. I also tried few locations that I could think of and in particular ${NPM_HOME_DIR} and ${S} but neither did any good.

What would be correct location to put the .npmrc file for authentication to work.?

dtoubelis avatar Jan 30 '18 03:01 dtoubelis

Answering my own question here:

inherit node-base

NPM_TOKEN ?= "00000000-0000-0000-0000-000000000000"
NPM_REGISTRY ?= "https://nexus.example.com/repository/npm-all/"

do_configure () {
    echo "${NPM_REGISTRY}:_authToken=${NPM_TOKEN}" | sed "s/^https://" > ${NPM_HOME_DIR}/.npmrc
    echo "registry=${NPM_REGISTRY}" >> ${NPM_HOME_DIR}/.npmrc

    # Uncoment for nodejs 7.+
    #echo "always-auth=true" >> ${NPM_HOME_DIR}/.npmrc
}

do_compile () {
    ...
}

do_install () {
    ...
}

What thrown me off is that we use node-6 in the image but npm-base class uses nodejs-native for running npm. We were setting preferred version for nodejs but not for nodejs-native and as a result nodejs-7/npm-4 were used by oe_runnpm for pulling dependencies.

Apparently there is a subtle difference in how authentication works between node6/npm3 and node7/npm4 (the always-auth=true part) and it took me only 2 days to figure this out :-)

And this is the right way to setup preferred version:

PREFERRED_VERSION_nodejs = "6.%"
PREFERRED_VERSION_nodejs-native = "6.%"

I hope it helps someone some day.

dtoubelis avatar Mar 16 '18 01:03 dtoubelis