diff --git a/package-lock.json b/package-lock.json index f6cbebd..e38f955 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@rama_nigg/open-cursor", - "version": "2.3.1", + "version": "2.3.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@rama_nigg/open-cursor", - "version": "2.3.1", + "version": "2.3.2", "license": "ISC", "dependencies": { "@opencode-ai/plugin": "1.1.53", diff --git a/package.json b/package.json index 4f0eaa6..9536835 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "2.3.2", "description": "No prompt limits. No broken streams. Full thinking + tool support. Your Cursor subscription, properly integrated.", "type": "module", - "main": "dist/index.js", + "main": "dist/plugin-entry.js", "module": "src/plugin-entry.ts", "scripts": { "build": "bun build ./src/index.ts ./src/plugin-entry.ts ./src/cli/discover.ts ./src/cli/opencode-cursor.ts --outdir ./dist --target node", @@ -23,6 +23,11 @@ "exports": { ".": { "bun": "./src/plugin-entry.ts", + "import": "./dist/plugin-entry.js", + "default": "./dist/plugin-entry.js" + }, + "./lib": { + "bun": "./src/index.ts", "import": "./dist/index.js", "default": "./dist/index.js" } diff --git a/src/plugin-toggle.ts b/src/plugin-toggle.ts index 68b8843..fa94531 100644 --- a/src/plugin-toggle.ts +++ b/src/plugin-toggle.ts @@ -3,6 +3,7 @@ import { homedir } from "os"; import { join, resolve } from "path"; const CURSOR_PROVIDER_ID = "cursor-acp"; +const NPM_PACKAGE_NAME = "@rama_nigg/open-cursor"; type EnvLike = Record; @@ -18,6 +19,13 @@ export function resolveOpenCodeConfigPath(env: EnvLike = process.env): string { return join(configHome, "opencode", "opencode.json"); } +function matchesPlugin(entry: unknown): boolean { + if (typeof entry !== "string") return false; + if (entry === CURSOR_PROVIDER_ID) return true; + if (entry === NPM_PACKAGE_NAME || entry.startsWith(NPM_PACKAGE_NAME + "@")) return true; + return false; +} + export function isCursorPluginEnabledInConfig(config: unknown): boolean { if (!config || typeof config !== "object") { return true; @@ -26,7 +34,7 @@ export function isCursorPluginEnabledInConfig(config: unknown): boolean { const configObject = config as { plugin?: unknown; provider?: unknown }; if (Array.isArray(configObject.plugin)) { - return configObject.plugin.some((entry) => entry === CURSOR_PROVIDER_ID); + return configObject.plugin.some(matchesPlugin); } return true; diff --git a/tests/unit/plugin-toggle.test.ts b/tests/unit/plugin-toggle.test.ts index 1ef1172..e8e9c6c 100644 --- a/tests/unit/plugin-toggle.test.ts +++ b/tests/unit/plugin-toggle.test.ts @@ -14,6 +14,15 @@ describe("plugin toggle", () => { expect(isCursorPluginEnabledInConfig({ plugin: ["cursor-acp"] })).toBe(true); }); + it("enables plugin when plugin array includes npm package name", () => { + expect(isCursorPluginEnabledInConfig({ plugin: ["@rama_nigg/open-cursor"] })).toBe(true); + }); + + it("enables plugin when plugin array includes npm package name with version", () => { + expect(isCursorPluginEnabledInConfig({ plugin: ["@rama_nigg/open-cursor@latest"] })).toBe(true); + expect(isCursorPluginEnabledInConfig({ plugin: ["@rama_nigg/open-cursor@2.3.2"] })).toBe(true); + }); + it("disables plugin when plugin array excludes cursor-acp", () => { expect(isCursorPluginEnabledInConfig({ plugin: ["other-plugin"] })).toBe(false); });