|
|
@@ -0,0 +1,88 @@
|
|
|
+import { describe, expect, test } from "bun:test"
|
|
|
+import { parsePluginSpecifier } from "../../src/plugin/shared"
|
|
|
+
|
|
|
+describe("parsePluginSpecifier", () => {
|
|
|
+ test("parses standard npm package without version", () => {
|
|
|
+ expect(parsePluginSpecifier("acme")).toEqual({
|
|
|
+ pkg: "acme",
|
|
|
+ version: "latest",
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ test("parses standard npm package with version", () => {
|
|
|
+ expect(parsePluginSpecifier("[email protected]")).toEqual({
|
|
|
+ pkg: "acme",
|
|
|
+ version: "1.0.0",
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ test("parses scoped npm package without version", () => {
|
|
|
+ expect(parsePluginSpecifier("@opencode/acme")).toEqual({
|
|
|
+ pkg: "@opencode/acme",
|
|
|
+ version: "latest",
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ test("parses scoped npm package with version", () => {
|
|
|
+ expect(parsePluginSpecifier("@opencode/[email protected]")).toEqual({
|
|
|
+ pkg: "@opencode/acme",
|
|
|
+ version: "1.0.0",
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ test("parses package with git+https url", () => {
|
|
|
+ expect(parsePluginSpecifier("acme@git+https://github.com/opencode/acme.git")).toEqual({
|
|
|
+ pkg: "acme",
|
|
|
+ version: "git+https://github.com/opencode/acme.git",
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ test("parses scoped package with git+https url", () => {
|
|
|
+ expect(parsePluginSpecifier("@opencode/acme@git+https://github.com/opencode/acme.git")).toEqual({
|
|
|
+ pkg: "@opencode/acme",
|
|
|
+ version: "git+https://github.com/opencode/acme.git",
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ test("parses package with git+ssh url containing another @", () => {
|
|
|
+ expect(parsePluginSpecifier("acme@git+ssh://[email protected]/opencode/acme.git")).toEqual({
|
|
|
+ pkg: "acme",
|
|
|
+ version: "git+ssh://[email protected]/opencode/acme.git",
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ test("parses scoped package with git+ssh url containing another @", () => {
|
|
|
+ expect(parsePluginSpecifier("@opencode/acme@git+ssh://[email protected]/opencode/acme.git")).toEqual({
|
|
|
+ pkg: "@opencode/acme",
|
|
|
+ version: "git+ssh://[email protected]/opencode/acme.git",
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ test("parses unaliased git+ssh url", () => {
|
|
|
+ expect(parsePluginSpecifier("git+ssh://[email protected]/opencode/acme.git")).toEqual({
|
|
|
+ pkg: "git+ssh://[email protected]/opencode/acme.git",
|
|
|
+ version: "",
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ test("parses npm alias using the alias name", () => {
|
|
|
+ expect(parsePluginSpecifier("acme@npm:@opencode/[email protected]")).toEqual({
|
|
|
+ pkg: "acme",
|
|
|
+ version: "npm:@opencode/[email protected]",
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ test("parses bare npm protocol specifier using the target package", () => {
|
|
|
+ expect(parsePluginSpecifier("npm:@opencode/[email protected]")).toEqual({
|
|
|
+ pkg: "@opencode/acme",
|
|
|
+ version: "1.0.0",
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ test("parses unversioned npm protocol specifier", () => {
|
|
|
+ expect(parsePluginSpecifier("npm:@opencode/acme")).toEqual({
|
|
|
+ pkg: "@opencode/acme",
|
|
|
+ version: "latest",
|
|
|
+ })
|
|
|
+ })
|
|
|
+})
|