From 6c53e7aee41e5b5cb369e62976bf8830f71410ac Mon Sep 17 00:00:00 2001 From: masnagam Date: Sun, 11 Apr 2021 16:00:18 +0900 Subject: [PATCH 1/2] Support branch names Skip updating if `url.version()` is not a semver (probably, it's a branch name). --- mod.ts | 8 ++++++++ test.ts | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/mod.ts b/mod.ts index fc81da4..318bddb 100644 --- a/mod.ts +++ b/mod.ts @@ -92,6 +92,14 @@ export class Udd { url.url = `${url.at(initVersion.slice(1)).url}#${newFragmentToken}`; } + try { + new Semver(url.version()); + } catch (e) { + // probably, the version string is a branch name. + await this.progress.log(`Using a branch: ${url.url}`); + return { initUrl, initVersion }; + } + // if we pass a fragment with semver let filter: ((other: Semver) => boolean) | undefined = undefined; try { diff --git a/test.ts b/test.ts index 2befde3..47e665d 100644 --- a/test.ts +++ b/test.ts @@ -151,3 +151,16 @@ Deno.test("uddFakeregistryFragmentMoveEq", async () => { const expected = 'import "https://fakeregistry.com/foo@0.0.1/mod.ts#=";'; await testUdd(contents, expected); }); + +Deno.test("uddGitHubRawBranchName", async () => { + const contents = ` +import "https://raw.githubusercontent.com/foo/bar/main/mod.ts"; +import "https://raw.githubusercontent.com/foo/bar/main/mod.ts#="; +`; + const expected = ` +import "https://raw.githubusercontent.com/foo/bar/main/mod.ts"; +import "https://raw.githubusercontent.com/foo/bar/main/mod.ts#="; +`; + const results = await testUdd(contents, expected); + assertEquals(results.length, 0); +}); From b97aecaab7aa8743f9ac502a17c625758067ce55 Mon Sep 17 00:00:00 2001 From: masnagam Date: Sun, 18 Apr 2021 10:57:51 +0900 Subject: [PATCH 2/2] Change the log message and the comment more precisely --- mod.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod.ts b/mod.ts index 318bddb..ec19408 100644 --- a/mod.ts +++ b/mod.ts @@ -95,8 +95,8 @@ export class Udd { try { new Semver(url.version()); } catch (e) { - // probably, the version string is a branch name. - await this.progress.log(`Using a branch: ${url.url}`); + // The version string is a non-semver string like a branch name. + await this.progress.log(`Skip updating: ${url.url}`); return { initUrl, initVersion }; }