GoogleCloudPlatform / artifact-registry-npm-tools

15 stars 19 forks source link

Running npx command, keeps adding extra double quote character in .npmrc file #17

Closed kYem closed 3 years ago

kYem commented 3 years ago

.npmrc file content

//europe-west2-npm.pkg.dev/project-id/packages/:_authToken="ya29.cxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxZ8.................................................
...........................................................................................................
...........................................................................................................
...........................................................................................................
...........................................................................................................
...........................................................................................................
...........................................................................................................
...............................................................................................................
..................................................................................
"
"
"
"
"
"
"
"
"
"
//europe-west2-npm.pkg.dev/project-id/packages/:always-auth=true

After each run and extra " gets added

yihanzhen commented 3 years ago

Hi @kYem I can't seem to repro your problem. In fact if the original file has more than 1 double quote at the end of the token string, updating the credentials would fail. Can you share the version of the plugin you are using and maybe a bit more detailed repro steps? Thanks!

kYem commented 3 years ago

This happens consistently with initial .npmrc file

@test-registry:registry=https://europe-west2-npm.pkg.dev/test-registry/packages/
//europe-west2-npm.pkg.dev/test-registry/packages/:_authToken=""
//europe-west2-npm.pkg.dev/test-registry/packages/:always-auth=true

and then running npx google-artifactregistry-auth .npmrc

produce:

@test-registry:registry=https://europe-west2-npm.pkg.dev/test-registry/packages/
//europe-west2-npm.pkg.dev/test-registry/packages/:_authToken="ya29.xxxxxxxxxxxxxx-mbIvg
"
//europe-west2-npm.pkg.dev/test-registry/packages/:always-auth=true

running it again

@test-registry:registry=https://europe-west2-npm.pkg.dev/test-registry/packages/
//europe-west2-npm.pkg.dev/test-registry/packages/:_authToken="ya29.a0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaHddpMLFh-LVd765f-MopbnXCA2EWxdJQ
"
"
//europe-west2-npm.pkg.dev/test-registry/packages/:always-auth=true

System information: image

Just to confirm but I'm able to use the generated token to access registry files, so it does work, but keeps producing this extra " after each run

kYem commented 3 years ago

Running this in empty project with just image

produce the same issue, even running the the local version image

with .npmrc adding image

kYem commented 3 years ago

Well just decided to debug myself and turns out that image

getGcloudCredentials returns trailing \n at the end of access token (zsh shell)

then in updateConfigFile

current file contents are:

image

Actual regex match does not include new line image

with new contents after newContents = contents.replace(regex,$1"${creds}");

image

yihanzhen commented 3 years ago

Ahh got it. For me I had application default credentials in my environment so getGcloudCredentials never got called. Thanks for finding this! I'll put together a fix shortly.

yihanzhen commented 3 years ago

v2.2.1 is now released. Please let me know if you see any other problems!

kYem commented 3 years ago

Seems to be working, thanks for the update.