Skip to content

Commit

Permalink
feat(command): support import map in upgrade command (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x-jerry committed Aug 11, 2021
1 parent f4cee28 commit b400131
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
12 changes: 11 additions & 1 deletion command/upgrade/provider.ts
Expand Up @@ -13,6 +13,7 @@ export interface UpgradeOptions {
to: string;
args?: Array<string>;
main?: string;
importMap?: string;
}

export abstract class Provider {
Expand Down Expand Up @@ -76,7 +77,8 @@ export abstract class Provider {
}

async upgrade(
{ name, from, to, main = `${name}.ts`, args = [] }: UpgradeOptions,
{ name, from, to, importMap, main = `${name}.ts`, args = [] }:
UpgradeOptions,
): Promise<void> {
if (to === "latest") {
const { latest } = await this.getVersions(name);
Expand All @@ -85,6 +87,14 @@ export abstract class Provider {
const registry: string = new URL(main, this.getRegistryUrl(name, to)).href;

const cmd = [Deno.execPath(), "install"];

if (importMap) {
const importJson: string =
new URL(importMap, this.getRegistryUrl(name, to)).href;

cmd.push("--import-map", importJson);
}

if (args.length) {
cmd.push(...args, "--force", "--name", name, registry);
} else {
Expand Down
4 changes: 3 additions & 1 deletion command/upgrade/upgrade_command.ts
Expand Up @@ -9,14 +9,15 @@ export interface UpgradeCommandOptions<
> {
provider: V;
main?: string;
importMap?: string;
args?: Array<string>;
}

export class UpgradeCommand extends Command<void> {
private readonly providers: ReadonlyArray<Provider>;

constructor(
{ provider, main, args }: UpgradeCommandOptions,
{ provider, main, args, importMap }: UpgradeCommandOptions,
) {
super();
this.providers = Array.isArray(provider) ? provider : [provider];
Expand Down Expand Up @@ -71,6 +72,7 @@ export class UpgradeCommand extends Command<void> {
await registry.upgrade({
name,
main,
importMap,
from: currentVersion,
to: targetVersion,
args,
Expand Down
20 changes: 11 additions & 9 deletions pagic.config.tsx
Expand Up @@ -25,15 +25,17 @@ export default {
editOnGithub: false,
backToTop: true,
},
head: (<>
<link
rel="icon"
type="image/svg+xml"
href="/docs/assets/favicon.svg"
sizes="any"
/>
<link rel="stylesheet" href="/docs/custom.css" />
</>),
head: (
<>
<link
rel="icon"
type="image/svg+xml"
href="/docs/assets/favicon.svg"
sizes="any"
/>
<link rel="stylesheet" href="/docs/custom.css" />
</>
),
nav: [
{
text: "Ansi",
Expand Down

0 comments on commit b400131

Please sign in to comment.