shared.test.ts 2.7 KB

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