|
| 1 | +import { describe, expect, test } from "bun:test" |
| 2 | +import { parsePluginSpecifier } from "../../src/plugin/shared" |
| 3 | + |
| 4 | +describe("parsePluginSpecifier", () => { |
| 5 | + test("parses standard npm package without version", () => { |
| 6 | + expect(parsePluginSpecifier("acme")).toEqual({ |
| 7 | + pkg: "acme", |
| 8 | + version: "latest", |
| 9 | + }) |
| 10 | + }) |
| 11 | + |
| 12 | + test("parses standard npm package with version", () => { |
| 13 | + expect(parsePluginSpecifier("acme@1.0.0")).toEqual({ |
| 14 | + pkg: "acme", |
| 15 | + version: "1.0.0", |
| 16 | + }) |
| 17 | + }) |
| 18 | + |
| 19 | + test("parses scoped npm package without version", () => { |
| 20 | + expect(parsePluginSpecifier("@opencode/acme")).toEqual({ |
| 21 | + pkg: "@opencode/acme", |
| 22 | + version: "latest", |
| 23 | + }) |
| 24 | + }) |
| 25 | + |
| 26 | + test("parses scoped npm package with version", () => { |
| 27 | + expect(parsePluginSpecifier("@opencode/acme@1.0.0")).toEqual({ |
| 28 | + pkg: "@opencode/acme", |
| 29 | + version: "1.0.0", |
| 30 | + }) |
| 31 | + }) |
| 32 | + |
| 33 | + test("parses package with git+https url", () => { |
| 34 | + expect(parsePluginSpecifier("acme@git+https://github.com/opencode/acme.git")).toEqual({ |
| 35 | + pkg: "acme", |
| 36 | + version: "git+https://github.com/opencode/acme.git", |
| 37 | + }) |
| 38 | + }) |
| 39 | + |
| 40 | + test("parses scoped package with git+https url", () => { |
| 41 | + expect(parsePluginSpecifier("@opencode/acme@git+https://github.com/opencode/acme.git")).toEqual({ |
| 42 | + pkg: "@opencode/acme", |
| 43 | + version: "git+https://github.com/opencode/acme.git", |
| 44 | + }) |
| 45 | + }) |
| 46 | + |
| 47 | + test("parses package with git+ssh url containing another @", () => { |
| 48 | + expect(parsePluginSpecifier("acme@git+ssh://git@github.com/opencode/acme.git")).toEqual({ |
| 49 | + pkg: "acme", |
| 50 | + version: "git+ssh://git@github.com/opencode/acme.git", |
| 51 | + }) |
| 52 | + }) |
| 53 | + |
| 54 | + test("parses scoped package with git+ssh url containing another @", () => { |
| 55 | + expect(parsePluginSpecifier("@opencode/acme@git+ssh://git@github.com/opencode/acme.git")).toEqual({ |
| 56 | + pkg: "@opencode/acme", |
| 57 | + version: "git+ssh://git@github.com/opencode/acme.git", |
| 58 | + }) |
| 59 | + }) |
| 60 | + |
| 61 | + test("parses unaliased git+ssh url", () => { |
| 62 | + expect(parsePluginSpecifier("git+ssh://git@github.com/opencode/acme.git")).toEqual({ |
| 63 | + pkg: "git+ssh://git@github.com/opencode/acme.git", |
| 64 | + version: "", |
| 65 | + }) |
| 66 | + }) |
| 67 | + |
| 68 | + test("parses npm alias using the alias name", () => { |
| 69 | + expect(parsePluginSpecifier("acme@npm:@opencode/acme@1.0.0")).toEqual({ |
| 70 | + pkg: "acme", |
| 71 | + version: "npm:@opencode/acme@1.0.0", |
| 72 | + }) |
| 73 | + }) |
| 74 | + |
| 75 | + test("parses bare npm protocol specifier using the target package", () => { |
| 76 | + expect(parsePluginSpecifier("npm:@opencode/acme@1.0.0")).toEqual({ |
| 77 | + pkg: "@opencode/acme", |
| 78 | + version: "1.0.0", |
| 79 | + }) |
| 80 | + }) |
| 81 | + |
| 82 | + test("parses unversioned npm protocol specifier", () => { |
| 83 | + expect(parsePluginSpecifier("npm:@opencode/acme")).toEqual({ |
| 84 | + pkg: "@opencode/acme", |
| 85 | + version: "latest", |
| 86 | + }) |
| 87 | + }) |
| 88 | +}) |
0 commit comments