Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add built-in jsr upgrade provider (rework) #692

Merged
merged 64 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
e79c45b
chore: :package: add jsr module metadatas
JOTSR Feb 29, 2024
4e104e5
refactor: :package: replace remote url imports by jsr or npm
JOTSR Feb 29, 2024
6daec80
fix: :wrench: prefix exports with `./`
JOTSR Feb 29, 2024
d6af963
fix: :package: remove `/mod` from `@std/path`
JOTSR Feb 29, 2024
564d1bf
refactor: :label: fix all slow types for jsr exports
JOTSR Feb 29, 2024
3fe231a
chore(upgrade): :arrow_up: deno/[email protected]
JOTSR Feb 29, 2024
eb72f6b
ci: add jsr publish workflow
JOTSR Feb 29, 2024
5cec103
style: run deno fmt on deno.jsonc
JOTSR Mar 8, 2024
ac01ba4
refactor: :truck: rename cliffy scope
JOTSR Mar 8, 2024
cc44644
refactor: :recycle: split cliffy in submodules with deno workspaces
JOTSR Mar 8, 2024
b7c5a7d
refactor: :label: simplify literals types to string
JOTSR Mar 8, 2024
aebf585
refactor: :recycle: replace `deps`/`dev_deps` by direct imports
JOTSR Mar 8, 2024
be0f0d2
ci: publish on release and dry run on main push
JOTSR Mar 8, 2024
587cfd1
fix: update missing import
JOTSR Mar 8, 2024
df78f58
refactor: dissociate examples imports
JOTSR Mar 13, 2024
f06d9c1
fix: :package: remove `examples` from workspace
JOTSR Mar 14, 2024
706e2c9
style: :art: apply `deno fmt` to harmonize sources
JOTSR Mar 14, 2024
3513bf4
fix cross package imports
c4spar Mar 17, 2024
2a8f296
fix: :construction_worker: `deno.jsonc` not loaded during tests in `s…
JOTSR Mar 18, 2024
1008ac2
Merge branch 'main' of github.com:JOTSR/deno-cliffy
JOTSR Mar 18, 2024
31c9d73
style: fix fmt
JOTSR Mar 18, 2024
766634a
Merge remote-tracking branch 'origin/main' into JOTSR-main
c4spar Mar 18, 2024
eb19021
Merge remote-tracking branch 'origin/main' into JOTSR-main
c4spar Mar 18, 2024
269648c
import ValidationError from @cliffy/flags
c4spar Mar 18, 2024
cd621ec
Merge remote-tracking branch 'origin/main' into JOTSR-main
c4spar Mar 18, 2024
0c34bbd
refactor: :recycle: don't force `deno.jsonc` prefers default options
JOTSR Mar 19, 2024
af3d77f
Merge branch 'main' of github.com:JOTSR/deno-cliffy
JOTSR Mar 19, 2024
3016d1f
remove examples/deno.json
c4spar Mar 19, 2024
820c260
Merge remote-tracking branch 'origin/main' into JOTSR-main
c4spar Mar 19, 2024
87a954b
fix imports
c4spar Mar 19, 2024
d7e3de6
fix test imports
c4spar Mar 19, 2024
0e6ce61
remove config option
c4spar Mar 19, 2024
1b69821
merge main branch
c4spar Apr 7, 2024
ef3046f
fmt
c4spar Apr 7, 2024
6c5bd08
fix
c4spar Apr 7, 2024
2d306d1
Merge remote-tracking branch 'origin/main' into JOTSR-main
c4spar Apr 7, 2024
bfe0dde
fix import
c4spar Apr 7, 2024
10c77f4
feat: :sparkles: implement `jsr` as buit-in upgrade provider
JOTSR Mar 19, 2024
959b0f7
fix: :label: update and fix types errors
JOTSR Mar 19, 2024
5730d71
refactor: :children_crossing: provide better `JsrProvider` API
JOTSR Mar 19, 2024
4881b7d
fix: :bug: use jsr specifier for install instead of url
JOTSR Apr 7, 2024
297574f
remove name and version from main deno.jsonc
c4spar Apr 9, 2024
9a7ebae
remove submodule exports from command/mod.ts
c4spar May 5, 2024
00397c2
add exports to ansi/deno.json
c4spar May 5, 2024
ee17e96
fix imports
c4spar May 5, 2024
7e4f76e
add workaround for workspace issue
c4spar May 5, 2024
c4171e5
fix examples
c4spar May 5, 2024
87b3a95
debug
c4spar May 5, 2024
ae2c9d8
debug
c4spar May 5, 2024
bd469ec
debug
c4spar May 5, 2024
df989de
debug
c4spar May 5, 2024
2e442fd
debug
c4spar May 5, 2024
682ccfd
debug
c4spar May 5, 2024
058d093
debug
c4spar May 5, 2024
463c41e
debug
c4spar May 5, 2024
e5d618e
adapt ansi exports
c4spar May 5, 2024
6ac036c
adapt publish workflow
c4spar May 5, 2024
1a0a3a4
cleanup
c4spar May 5, 2024
05e84b0
Merge branch 'main' of github.com:c4spar/deno-cliffy
JOTSR May 10, 2024
56268e4
Merge branch 'main' of github.com:JOTSR/deno-cliffy into feat/jsr_pro…
JOTSR May 10, 2024
444b038
refactor!: :recycle: remove default value for `main` in upgrade command
JOTSR May 10, 2024
3bd7376
style: :art: fix formatting
JOTSR May 10, 2024
68ffc07
cleanup
c4spar May 13, 2024
f91cf40
Merge remote-tracking branch 'origin/main' into feat/jsr_provider_rework
c4spar May 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions command/upgrade/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {
type GithubProviderOptions,
type GithubVersions,
} from "./provider/github.ts";
export { JsrProvider, type JsrProviderOptions } from "./provider/jsr.ts";
export {
NestLandProvider,
type NestLandProviderOptions,
Expand Down
9 changes: 6 additions & 3 deletions command/upgrade/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,17 @@ export abstract class Provider {
}

async upgrade(
{ name, from, to, importMap, main = `${name}.ts`, args = [] }:
UpgradeOptions,
{ name, from, to, importMap, main, args = [] }: UpgradeOptions,
): Promise<void> {
if (to === "latest") {
const { latest } = await this.getVersions(name);
to = latest;
}
const registry: string = new URL(main, this.getRegistryUrl(name, to)).href;

const registryUrl = this.getRegistryUrl(name, to);
const registry: string = registryUrl.startsWith("jsr:")
? registryUrl
: new URL(main || `${name}.ts`, registryUrl).href;

const cmdArgs = ["install"];

Expand Down
72 changes: 72 additions & 0 deletions command/upgrade/provider/jsr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Provider, Versions } from "../provider.ts";

type Semver =
| `${number}.${number}.${number}`
| `${number}.${number}.${number}-${string}`;
type Package = `@${string}/${string}`;

type JsrApiPackageMetadata = {
scope: string;
name: string;
latest: Semver;
versions: {
[version: Semver]: { yanked?: boolean };
};
};

export type JsrProviderOptions = {
package: Package;
} | {
scope: string;
name?: string;
};

export class JsrProvider extends Provider {
name = "jsr";
private readonly repositoryUrl = "https://jsr.io/";
private readonly packageName?: string;
private readonly packageScope: string;

constructor(options: JsrProviderOptions) {
super();
this.packageScope = "package" in options
? options.package.split("/")[0].slice(1)
: options.scope;
this.packageName = "package" in options
? options.package.split("/")[1]
: options.name;
}

async getVersions(
name: string,
): Promise<Versions> {
const response = await fetch(
`${this.repositoryUrl}/@${this.packageScope}/${
this.packageName ?? name
}/meta.json`,
);
if (!response.ok) {
throw new Error(
"couldn't fetch the latest version - try again after sometime",
);
}

const { latest, versions } = await response.json() as JsrApiPackageMetadata;

return {
latest,
versions: Object.keys(versions),
};
}

getRepositoryUrl(name: string): string {
return new URL(
`@${this.packageScope}/${this.packageName ?? name}`,
this.repositoryUrl,
).href;
}

getRegistryUrl(name: string, version: Semver): string {
return `jsr:@${this.packageScope}/${this.packageName ?? name}@${version}`;
}
}
Loading