Skip to content

Instantly share code, notes, and snippets.

@micheleb
Created May 24, 2024 15:06
Show Gist options
  • Save micheleb/87a987dfeae2a313c79baa1ece906f64 to your computer and use it in GitHub Desktop.
Save micheleb/87a987dfeae2a313c79baa1ece906f64 to your computer and use it in GitHub Desktop.
Make vscode-react-native's react-native version parser understand npm:[email protected] format
diff --git a/src/common/projectVersionHelper.ts b/src/common/projectVersionHelper.ts
index eb1ba2f4..4bbfda65 100644
--- a/src/common/projectVersionHelper.ts
+++ b/src/common/projectVersionHelper.ts
@@ -242,6 +242,13 @@ export class ProjectVersionHelper {
public static processVersion(version: string, useSemverCoerce: boolean = true): string {
try {
+ if (version.startsWith("npm:")) {
+ const v = version.slice(version.indexOf("@") + 1);
+ return (
+ semver.clean(v.replace(/[<>^~]/g, ""), { loose: true })?.toString() ||
+ this.SEMVER_INVALID
+ );
+ }
return new URL(version) && `${this.SEMVER_INVALID}: URL`;
} catch {
// As some of 'react-native-windows' versions contain postfixes we cannot use 'coerce' function to parse them
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment