From 049cb3d6848b9f72771ea8b42762d022c1eddc32 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Thu, 10 Mar 2022 16:50:23 +0100 Subject: [PATCH] Support dependencies fetched from a tarball file --- build.gradle.kts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 6bcd5ce..644335a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -103,5 +103,18 @@ fun getPackageVersion(projectName: String): String { projectName == "react-native-clipboard" -> "@react-native-clipboard/clipboard" else -> projectName } - return packageDevDependencies.optString(jsonProperty) + val packageVersion = packageDevDependencies.optString(jsonProperty) + + // Extract version from filename of tarball URL + val isTarball = packageVersion.endsWith(".tgz") + if (isTarball) { + // Replace special characters of package name as "npm pack" command does, to be used in the filename. + // Reference: https://github.com/npm/cli/blob/699c2d708d2a24b4f495a74974b2a345f33ee08a/lib/pack.js#L66-L67 + val packageNameSanitized = jsonProperty.replace("@", "").replace("/", "-") + val fileName = packageVersion.substring(packageVersion.lastIndexOf("/") + 1) + val version = fileName.replace(packageNameSanitized + "-", "").replace(".tgz", "") + return version + } + + return packageVersion }