question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Non-standard version parsing for recursive dependencies.

See original GitHub issue

Summary

runpkg appears to have some issues with a non-standard version like x.x.x-beta.x.

Reproduction

The spinny wheel is stuck because of errors like:

GET https://unpkg.com/fast-deep-equal@3.0.0/package.json 404
  | fetchPkg | @ | recursiveDependencyFetch.js:59
  | recursiveDependantsFetch | @ | recursiveDependencyFetch.js:96
  | async function (async) |   |  
  | recursiveDependantsFetch | @ | recursiveDependencyFetch.js:95
  | default | @ | recursiveDependencyFetch.js:146
  | (anonymous) | @ | Aside.js:51
  | Qb | @ | react-dom.js:3260
  | si | @ | react-dom.js:3814
  | Q | @ | react.js:86
  | ta | @ | react.js:144
  | e.port1.onmessage | @ | react.js:508

So the issue appears to be that https://unpkg.com/fast-deep-equal@3.0.0/package.json is fetched under the hood instead of the non-404-ing https://unpkg.com/fast-deep-equal@3.0.0-beta.1/package.json

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ryan-roemercommented, Nov 8, 2019

Here’s another option – don’t regex. Instead use / as the delimiter to split against since semver + package names cannot contain a slash.

Maybe something like:


const parseVersion = (url) => {
  const parts = url
    .toLowerCase()
    .trim()
    .replace("https://unpkg.com", "")
    .split("/")
    .map((part) => part.trim())
    .filter(Boolean);

  if (parts.length >= 2 && parts[0][0] === "@") {
    // Scoped package.
    return `${parts[0]}/${parts[1]}`;
  } else if (parts.length >= 1) {
    // Normal package.
    return parts[0];
  }

  return null;
};

const urls = `
https://unpkg.com
https://unpkg.com/pkg@1.0.0-beta.1
https://unpkg.com/pkg@1.0.0-beta.1/extra.js
https://unpkg.com/pkg-dash@1.0.0-beta.1/extra.js
https://unpkg.com/@scope/pkg@1.0.0-beta.1
https://unpkg.com/@scope/pkg@1.0.0-beta.1/extra.js
https://unpkg.com/@scope/pkg-dash@1.0.0-beta.1/extra.js
`.split("\n").filter(Boolean).map((s) => s.trim());

urls.forEach((url) => {
  console.log(url, "->", parseVersion(url) || "NO MATCH");
});

0reactions
kiraarghycommented, Nov 8, 2019

I can pick this up!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug]: Stack Overflow on Recursive Dependencies #3434
Describe the bug​​ This appears to be caused by cyclic dependencies where blindly following dependency/devDependency gets you into an infinite ...
Read more >
"too much recursion" error when calling JSON.stringify on a ...
I get the error "too much recursion", not surprisingly. The "child" object has a reference to its "parent" and the parent has a...
Read more >
pkgdepends: Package Dependency Resolution and Downloads
The dependency solver takes the resolution information, and works out the exact versions of each package that must be installed, such that version...
Read more >
parsit - crates.io: Rust Package Registry
This library provides a very simple and lightweight parser (recursive descendant ll(1)) to combine and express a grammar.
Read more >
Parsing in Java: all the tools and libraries you can use
The AST instead is a polished version of the parse tree where the ... Some parser generators support direct left-recursive rules, but not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found