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

[BUG] npm view returning string without quotes with version 10.8.0 #7537

Closed
2 tasks done
byCedric opened this issue May 16, 2024 · 1 comment · Fixed by #7540
Closed
2 tasks done

[BUG] npm view returning string without quotes with version 10.8.0 #7537

byCedric opened this issue May 16, 2024 · 1 comment · Fixed by #7540
Assignees
Labels
Bug thing that needs fixing Priority 1 high priority issue

Comments

@byCedric
Copy link

byCedric commented May 16, 2024

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

When using npm view <package> <selector> --json, I expect only to receive JSON data types. Unfortunately, for npm@10.8.0 that's not the case anymore.

Running npm view expo-template-bare-minimum@sdk-51 dist.tarball --json now yields the tarball string, without quotes, making it not a JSON result anymore.

image

Expected Behavior

When using this same command with npm@10.7.0, the response is wrapped in quotes, making it a valid JSON response (or at least parsable through JSON.parse(...).

image

Steps To Reproduce

Result that's not parsable with JSON.parse:

  1. $ npm i -g npm@10.8.0
  2. $ npm -v → Should return 10.8.0
  3. $ npm view expo-template-bare-minimum@sdk-51 dist.tarball --json
    → Should return https://... (without quotes)

Result that is parsable with JSON.parse:

  1. $ npm i -g npm@10.7.0
  2. $ npm -v → Should return 10.7.0
  3. $ npm view expo-template-bare-minimum@sdk-51 dist.tarball --json
    → Should return "https://..." (with quotes)

Environment

  • npm: 10.8.0
  • Node.js: 22.2.0
  • OS Name: macOS Sanoma 14.4.1
  • System Model Name: MacBook Pro (14" 2023)
  • npm config:
; "user" config from /Users/cedric/.npmrc

//registry.npmjs.org/:_authToken = (protected)
store-dir = "/Users/cedric/.pnpm"

; node bin location = /Users/cedric/.nvm/versions/node/v22.2.0/bin/node
; node version = v22.2.0
; npm local prefix = /Users/cedric/Desktop
; npm version = 10.8.0
; cwd = /Users/cedric/Desktop
; HOME = /Users/cedric
; Run `npm config ls -l` to show all defaults.
@byCedric byCedric added Bug thing that needs fixing Needs Triage needs review for next steps labels May 16, 2024
byCedric added a commit to expo/expo that referenced this issue May 16, 2024
# Why

Fixes #28916

# How

Instead of relying on the (escaped) quotes to be included in `npm view`
output, this just parses the full object instead.

Unfortunately, this seems to be caused by npm 10.8.0. Starting from this
version, the output of `npm view <package> dist.tarball --json` is not
wrapped in quotes anymore, meaning that the value is not a JSON value
anymore (and can't be parsed by `JSON.parse`).

See: npm/cli#7537

# Test Plan

See prebuild e2e

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [x] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).
@lukekarrys lukekarrys removed the Needs Triage needs review for next steps label May 16, 2024
@lukekarrys lukekarrys self-assigned this May 16, 2024
@lukekarrys lukekarrys added the Priority 1 high priority issue label May 16, 2024
@lukekarrys
Copy link
Contributor

I introduced this in #7513. Will have a PR to fix it shortly.

lukekarrys added a commit that referenced this issue May 16, 2024
In refactoring this behavior previously plain strings were no longer
being passed through JSON.stringify even in json mode. This commit
changes that to the previous behavior which fixes the bug in `npm view`.
This also required changing the behavior of `npm pkg` which relied on this.

Fixes #7537
lukekarrys added a commit that referenced this issue May 17, 2024
In refactoring this behavior previously plain strings were no longer
being passed through JSON.stringify even in json mode. This commit
changes that to the previous behavior which fixes the bug in `npm view`.
This also required changing the behavior of `npm pkg` which relied on this.

Fixes #7537
lukekarrys added a commit that referenced this issue May 17, 2024
In refactoring this behavior previously plain strings were no longer
being passed through JSON.stringify even in json mode. This commit
changes that to the previous behavior which fixes the bug in `npm view`.
This also required changing the behavior of `npm pkg` which relied on this.

Fixes #7537
lukekarrys added a commit that referenced this issue May 17, 2024
In refactoring this behavior previously plain strings were no longer
being passed through JSON.stringify even in json mode. This commit
changes that to the previous behavior which fixes the bug in `npm view`.
This also required changing the behavior of `npm pkg` which relied on
this.

Fixes #7537
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 1 high priority issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants