') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); fix(view): error on missing version by wraithgar · Pull Request #5035 · npm/cli · GitHub
Skip to content

fix(view): error on missing version - #5035

Merged
fritzy merged 15 commits into
latestfrom
gar/5011
Jun 22, 2022
Merged

fix(view): error on missing version#5035
fritzy merged 15 commits into
latestfrom
gar/5011

Conversation

@wraithgar

@wraithgarwraithgar commented Jun 16, 2022

Copy link
Copy Markdown
Contributor

This fixes an error in npm show. When calling npm show with a specific
version of a package that does not exist, it does not show anything and
gives a zero exit code. This has been changed: now it gives a 404 Error
similar to if the package does not exist. Can be tested with npm show
express@5.0.0 (local: node bin/npm-cli.js info express@5.0.0)

Fixes#4964

Credit: @lukaskuhn-lku

@wraithgar
wraithgar requested a review from a team as a code ownerJune 16, 2022 16:23
@wraithgar

Copy link
Copy Markdown
ContributorAuthor

This is a continuation of #5011, I fixed the tests.

nlf
nlf approved these changes Jun 16, 2022
@wraithgarwraithgar mentioned this pull request Jun 16, 2022
@npm-cli-bot

npm-cli-bot commented Jun 16, 2022

Copy link
Copy Markdown
Collaborator

no statistically significant performance changes detected

timing results
app-largecleanlock-onlycache-onlycache-only
peer-deps
modules-onlyno-lockno-cacheno-modulesno-cleanno-clean
audit
npm@839.943 ±0.0821.314 ±0.2919.670 ±0.0022.354 ±0.733.307 ±0.013.318 ±0.082.720 ±0.0313.198 ±0.102.640 ±0.053.792 ±0.04
#503542.364 ±0.0421.445 ±0.3818.401 ±0.1521.432 ±0.313.240 ±0.033.266 ±0.072.587 ±0.0112.577 ±0.172.574 ±0.013.770 ±0.10
app-mediumcleanlock-onlycache-onlycache-only
peer-deps
modules-onlyno-lockno-cacheno-modulesno-cleanno-clean
audit
npm@830.172 ±0.9515.573 ±0.1113.788 ±0.1814.835 ±0.263.027 ±0.013.136 ±0.072.644 ±0.039.374 ±0.092.497 ±0.043.425 ±0.01
#503529.501 ±0.2415.553 ±0.0613.798 ±0.0415.021 ±0.392.999 ±0.052.971 ±0.052.653 ±0.039.268 ±0.032.522 ±0.043.383 ±0.02

@ljharbljharb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about a dist-tag that doesn’t exist?

Comment threadlib/commands/view.js
@wraithgar

Copy link
Copy Markdown
ContributorAuthor

What about a dist-tag that doesn’t exist?

This PR also fixes that situation

~/D/n/cli (gar/5011|✔) $ node . view lodash@asdf
npm ERR! code E404
npm ERR! 404 No match found for version asdf
npm ERR! 404 npm ERR! 404 'lodash@asdf' is not in this registry.

@fritzy
fritzy merged commit 2953983 into latestJun 22, 2022
@fritzy
fritzy deleted the gar/5011 branch June 22, 2022 20:52
@fritzyfritzy mentioned this pull request Jun 22, 2022
@lukas-kuhnlukas-kuhn mentioned this pull request Jun 29, 2022
jsjoeio added a commit to coder/code-server that referenced this pull request Aug 23, 2022
npm changed the way the `npm view` command handles missing versions.
Before it exited with a non-error. Now it errors.
Ref: npm/cli#5035
This modifies the script logic to handle those new changes.
jsjoeio added a commit to coder/code-server that referenced this pull request Aug 23, 2022
* chore: clean up logging in npm script
* fix: catch error if npm version missing
npm changed the way the `npm view` command handles missing versions.
Before it exited with a non-error. Now it errors.
Ref: npm/cli#5035
This modifies the script logic to handle those new changes.
@MarshallOfSound

MarshallOfSound commented Oct 27, 2022

Copy link
Copy Markdown

@wraithgar Probably not worth a new issue but I wanted to note that this caused a catastrophic relatively bad release infrastructure failure for the Electron project.

We have since recovered and worked around the issue and ensured the npm is correctly pinned in our deployment environment but this was IMO a drastic breaking change in behaviour in a patch bump of the NPM cli.

Specifically we were checking if a version had been published to npm via the CLI using:

npm show electron@1.2.3 --json

And assuming that "no output" meant the version had not been published and "valid output" could be parsed into the registry metadata. In both cases since the dawn of npm the command exited cleanly, this change caused a non-zero exit code in the unpublished scenario which then propagated as an error through our release scripts causing an infinite backoff-and-retry (as we assumed a non-zero exit code meant npm was having issues).

Not sure if this is even gonna scratch on the radar, but I'd consider a change in exit code semantics for a CLI tool a breaking change and would be reserved for the next major version of npm.

Sign up for freeto 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.

[BUG] npm info exits with zero exit code if package@version is not found

7 participants

@wraithgar@npm-cli-bot@MarshallOfSound@ljharb@nlf@fritzy@lukas-kuhn