Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lsp): support .npmrc #24042

Merged
merged 4 commits into from
May 30, 2024
Merged

feat(lsp): support .npmrc #24042

merged 4 commits into from
May 30, 2024

Conversation

nayeemrmn
Copy link
Collaborator

Closes #24040.

temp_dir.write(
temp_dir.path().join("deno.json"),
json!({
"nodeModulesDir": true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to leave this test as byonm (default from DENO_FUTURE), but the npm install invocation was hitting an auth error. Maybe it doesn't like the .npmrc below for some reason? Not a problem for Deno's npm client.

Log from `npm install`:
0 verbose cli /home/nayeem/.nvm/versions/node/v21.7.1/bin/node /home/nayeem/.nvm/versions/node/v21.7.1/bin/npm
1 info using [email protected]
2 info using [email protected]
3 timing npm:load:whichnode Completed in 1ms
4 timing config:load:defaults Completed in 1ms
5 timing config:load:file:/home/nayeem/.nvm/versions/node/v21.7.1/lib/node_modules/npm/npmrc Completed in 1ms
6 timing config:load:builtin Completed in 1ms
7 timing config:load:cli Completed in 1ms
8 timing config:load:env Completed in 1ms
9 timing config:load:file:/tmp/deno-cli-testLnM6rz/.npmrc Completed in 1ms
10 timing config:load:project Completed in 1ms
11 timing config:load:file:/home/nayeem/.npmrc Completed in 0ms
12 timing config:load:user Completed in 0ms
13 timing config:load:file:/home/nayeem/.nvm/versions/node/v21.7.1/etc/npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:setEnvs Completed in 1ms
16 timing config:load Completed in 6ms
17 timing npm:load:configload Completed in 6ms
18 timing config:load:flatten Completed in 1ms
19 timing npm:load:mkdirpcache Completed in 1ms
20 timing npm:load:mkdirplogs Completed in 0ms
21 verbose title npm install
22 verbose argv "install"
23 timing npm:load:setTitle Completed in 0ms
24 timing npm:load:display Completed in 1ms
25 verbose logfile logs-max:10 dir:/home/nayeem/.npm/_logs/2024-05-30T01_06_09_454Z-
26 verbose logfile /home/nayeem/.npm/_logs/2024-05-30T01_06_09_454Z-debug-0.log
27 timing npm:load:logFile Completed in 17ms
28 timing npm:load:timers Completed in 0ms
29 timing npm:load:configScope Completed in 0ms
30 timing npm:load Completed in 36ms
31 timing arborist:ctor Completed in 0ms
32 silly logfile start cleaning logs, removing 1 files
33 silly logfile done cleaning log files
34 timing arborist:ctor Completed in 0ms
35 timing idealTree:init Completed in 6ms
36 timing idealTree:userRequests Completed in 0ms
37 silly idealTree buildDeps
38 silly fetch manifest @denotest/[email protected]
39 http fetch GET 401 https://127.0.0.1:4261/@denotest%2fbasic 11ms (cache skip)
40 silly placeDep ROOT @denotest/basic@ OK for: [email protected] want: 1.0.0
41 timing idealTree:#root Completed in 16ms
42 timing idealTree:node_modules/@denotest/basic Completed in 0ms
43 timing idealTree:buildDeps Completed in 16ms
44 timing idealTree:fixDepFlags Completed in 0ms
45 timing idealTree Completed in 24ms
46 timing command:install Completed in 29ms
47 verbose stack HttpErrorGeneral: 401 Unauthorized - GET https://127.0.0.1:4261/@denotest%2fbasic
47 verbose stack     at /home/nayeem/.nvm/versions/node/v21.7.1/lib/node_modules/npm/node_modules/npm-registry-fetch/lib/check-response.js:95:15
47 verbose stack     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
47 verbose stack     at async RegistryFetcher.packument (/home/nayeem/.nvm/versions/node/v21.7.1/lib/node_modules/npm/node_modules/pacote/lib/registry.js:91:19)
47 verbose stack     at async RegistryFetcher.manifest (/home/nayeem/.nvm/versions/node/v21.7.1/lib/node_modules/npm/node_modules/pacote/lib/registry.js:129:23)
47 verbose stack     at async #nodeFromEdge (/home/nayeem/.nvm/versions/node/v21.7.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1056:19)
47 verbose stack     at async #buildDepStep (/home/nayeem/.nvm/versions/node/v21.7.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:924:11)
47 verbose stack     at async Arborist.buildIdealTree (/home/nayeem/.nvm/versions/node/v21.7.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:203:7)
47 verbose stack     at async Promise.all (index 1)
47 verbose stack     at async Arborist.reify (/home/nayeem/.nvm/versions/node/v21.7.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:154:5)
47 verbose stack     at async Install.exec (/home/nayeem/.nvm/versions/node/v21.7.1/lib/node_modules/npm/lib/commands/install.js:153:5)
48 verbose statusCode 401
49 verbose pkgid @denotest/[email protected]
50 verbose cwd /tmp/deno-cli-testLnM6rz
51 verbose Linux 4.4.0-26200-Microsoft
52 verbose node v21.7.1
53 verbose npm  v10.5.0
54 error code E401
55 error 401 Unauthorized - GET https://127.0.0.1:4261/@denotest%2fbasic
56 verbose exit 1
57 timing npm Completed in 279ms
58 verbose unfinished npm timer reify 1717031169704
59 verbose unfinished npm timer reify:loadTrees 1717031169707
60 verbose code 1
61 error A complete log of this run can be found in: /home/nayeem/.npm/_logs/2024-05-30T01_06_09_454Z-debug-0.log

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it wasn't what I thought it was (the %2F). I'm looking into it though

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the request headers it's sending, no authorization:

{
    "user-agent": "npm/10.8.1 node/v21.7.1 linux x64 workspaces/false",
    "pacote-version": "18.0.6",
    "pacote-req-type": "packument",
    "pacote-pkg-id": "registry:@denotest/basic",
    "accept": "application/json",
    "npm-auth-type": "web",
    "npm-command": "install",
    "accept-encoding": "gzip,deflate",
    "host": "127.0.0.1:4261",
    "connection": "keep-alive",
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's strange. It works for the following though:

@denotest:registry=https://127.0.0.1:4261
//127.0.0.1:4261/:_authToken=private-reg-token

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so the following defines the registry root and not the root + scope, so it needs to be:

//127.0.0.1:4261/:_authToken=private-reg-token

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.npmjs.com/cli/v10/configuring-npm/npmrc#auth-related-configuration

If you look closely with:

@myorg:registry=https://somewhere-else.com/myorg

...what it's actually saying is to request the scope at the url...

https://somewhere-else.com/myorg/myorg

So the following works:

//somewhere-else.com/myorg/:_authToken=MYTOKEN1

But this doesn't:

//somewhere-else.com/myorg/myorg:_authToken=MYTOKEN1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me I still get an error:

OUTPUT
npm warn registry No auth for URI, but auth present for scoped registry.
npm warn registry
npm warn registry URI: https://localhost:4261/@denotest/basic/1.0.0.tgz
npm warn registry Scoped Registry Key: //127.0.0.1:4261/
npm warn registry
npm warn registry More info here: https://github.com/npm/cli/wiki/No-auth-for-URI,-but-auth-present-for-scoped-registry
npm error code E401
npm error 401 Unauthorized - GET https://localhost:4261/@denotest/basic/1.0.0.tgz
npm error A complete log of this run can be found in: /home/nayeem/.npm/_logs/2024-05-30T02_24_06_941Z-debug-0.log

OUTPUT

And these two requests:

uri: /@denotest%2fbasic
body: Body(
    Empty,
)
headers: {
    "accept": "application/json",
    "authorization": "Bearer private-reg-token",
    "npm-auth-type": "web",
    "npm-command": "install",
    "pacote-pkg-id": "registry:@denotest/basic",
    "pacote-req-type": "packument",
    "pacote-version": "18.0.6",
    "user-agent": "npm/10.8.1 node/v21.7.1 linux x64 workspaces/false",
    "connection": "keep-alive",
    "accept-encoding": "gzip,deflate",
    "host": "127.0.0.1:4261",
}
uri: /@denotest/basic/1.0.0.tgz
body: Body(
    Empty,
)
headers: {
    "user-agent": "npm/10.8.1 node/v21.7.1 linux x64 workspaces/false",
    "pacote-version": "18.0.6",
    "pacote-req-type": "tarball",
    "pacote-pkg-id": "remote:@denotest/basic@https://localhost:4261/@denotest/basic/1.0.0.tgz",
    "pacote-integrity": "sha512-M7ZOJPEImBcduhmJ1EmgmEMUJMFtZ19H/VvAJxcXokOfjM22CBWz7YbqvdBJXJ+aimsbqn0k/SwwknsozUzwUQ==",
    "npm-auth-type": "web",
    "npm-command": "install",
    "accept": "*/*",
    "accept-encoding": "gzip,deflate",
    "host": "localhost:4261",
    "connection": "keep-alive",
}

I guess we'll see how CI does...

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! LGTM

@dsherret dsherret merged commit 5560123 into denoland:main May 30, 2024
17 checks passed
@nayeemrmn nayeemrmn deleted the lsp-npmrc branch May 30, 2024 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.npmrc: doesn't work with the LSP
3 participants