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

Spurious ${LOCALAPPDATA} folder created when hovering a dependency name in package.json #211914

Closed
Septh opened this issue May 3, 2024 · 4 comments · May be fixed by #212856
Closed

Spurious ${LOCALAPPDATA} folder created when hovering a dependency name in package.json #211914

Septh opened this issue May 3, 2024 · 4 comments · May be fixed by #212856
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug debt Code quality issues
Milestone

Comments

@Septh
Copy link

Septh commented May 3, 2024

Type: Bug

  1. Open any folder with a package.json file.
  2. Hover any dependency name in package.json to display the package's details.
  3. An extra folder named ${LOCALAPPDATA} appears in the same directory where the package.json file resides.

image

It appears from the logs in that folder that vscode launches npm view to get the package details:

image

So I tried the same command from the shell:

npm view --json -- eslint description dist-tags.latest homepage version time

The extra folder was not created.

VS Code version: Code 1.89.0 (b58957e, 2024-05-01T02:09:22.859Z)
OS version: Windows_NT x64 10.0.22631
Modes:

System Info
Item Value
CPUs 12th Gen Intel(R) Core(TM) i7-12700K (20 x 3610)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 31.75GB (17.10GB free)
Process Argv --disable-extensions . --crash-reporter-id 365a2674-a228-4abd-82c2-408321056497
Screen Reader no
VM 0%
Extensions disabled
@VSCodeTriageBot VSCodeTriageBot added the stale Issues that have not been triaged in an appropriate amount of time label May 13, 2024
@aiday-mar
Copy link
Contributor

Not sure who to assign this to. I was wondering @joaomoreno if you would know?

@Septh
Copy link
Author

Septh commented May 16, 2024

I did some digging and it turns out that this may well be a bug in Node's execFile API.
EDIT: this is not a bug, only execFile missing environment information.

The following script is a stripped down version of the npmView() method in the VSCode's builtin npm extension.

import { execFile } from 'node:child_process'
import which from 'which'

const npmCommandPath = await which(process.platform === 'win32' ? 'npm.cmd' : 'npm')
const pack = 'eslint'

const result = await new Promise((resolve, _reject) => {
    const args = ['view', '--json', '--', pack, 'description', 'dist-tags.latest', 'homepage', 'version', 'time']
    const cwd = process.cwd()

    // corepack npm wrapper would automatically update package.json. disable that behavior.
    // COREPACK_ENABLE_AUTO_PIN disables the package.json overwrite, and
    // COREPACK_ENABLE_PROJECT_SPEC makes the npm view command succeed
    //   even if packageManager specified a package manager other than npm.
    const env = { COREPACK_ENABLE_AUTO_PIN: "0", COREPACK_ENABLE_PROJECT_SPEC: "0" }
    execFile(npmCommandPath, args, { cwd, env, shell: true }, (error, stdout) => {
        if (!error) {
            try {
                const content = JSON.parse(stdout)
                const version = content['dist-tags.latest'] || content['version']
                resolve({
                    description: content['description'],
                    version,
                    time: content.time?.[version],
                    homepage: content['homepage']
                })
                return
            } catch (e) {
                // ignore
            }
        }
        resolve(undefined)
    })
}).catch(e => null)

console.log(result)

When run from the command line, the script creates the ${LOCALAPPDATA} folder, just like VSCode does. However, if I remove the env option object in the call to execFile(), then the folder is not created. I confirmed this with the latest versions of Node 21, 20, 18 and 16.

The env object was added in #210601.

Not sure where to go from here.

One last remark: the shell: true option is now mandatory to run .cmd files on Windows with execFile() - this is something to keep in mind when upgrading the version of Electron used in VSCode.

@meganrogge meganrogge removed triage-needed stale Issues that have not been triaged in an appropriate amount of time labels May 16, 2024
@meganrogge meganrogge added bug Issue identified by VS Code Team member as probable bug debt Code quality issues labels May 16, 2024
@meganrogge meganrogge added this to the June 2024 milestone May 16, 2024
@frankli0324
Copy link
Contributor

should be resolved by #213306

@meganrogge meganrogge assigned aeschli and unassigned meganrogge May 24, 2024
@aeschli
Copy link
Contributor

aeschli commented May 24, 2024

#213306 fixes the issue

@aeschli aeschli closed this as completed May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug debt Code quality issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants