Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict";

async function loadPlugin() {
const mod = await import("./src/index.js");
return mod.default || mod.WorktreeWorkflowPlugin;
}

async function WorktreeWorkflowPlugin(...args) {
const plugin = await loadPlugin();
if (typeof plugin !== "function") {
throw new TypeError("Plugin export is not a function");
}
return plugin(...args);
}

module.exports = WorktreeWorkflowPlugin;
module.exports.default = WorktreeWorkflowPlugin;
module.exports.WorktreeWorkflowPlugin = WorktreeWorkflowPlugin;
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
"version": "0.1.0",
"description": "OpenCode plugin for creating and cleaning up git worktrees.",
"type": "module",
"main": "./src/index.js",
"main": "./index.cjs",
"bin": {
"opencode-worktree-workflow": "./src/cli.js"
},
"exports": {
".": "./src/index.js"
".": {
"require": "./index.cjs",
"import": "./src/index.js",
"default": "./index.cjs"
}
},
"files": [
"index.cjs",
"src",
"schemas",
"skills"
Expand Down
43 changes: 43 additions & 0 deletions test/plugin-entrypoint.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import test from "node:test";
import assert from "node:assert/strict";
import { createRequire } from "node:module";
import path from "node:path";
import { fileURLToPath } from "node:url";

const require = createRequire(import.meta.url);
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");

test("package root resolves to a callable plugin factory for require loaders", async () => {
const pluginModule = require(repoRoot);

assert.equal(typeof pluginModule, "function");
assert.equal(pluginModule, pluginModule.default);
assert.equal(pluginModule, pluginModule.WorktreeWorkflowPlugin);

const plugin = await pluginModule({
$: Object.assign(
() => ({
cwd() {
return this;
},
quiet() {
return this;
},
async nothrow() {
return {
text() {
return "";
},
stderr: Buffer.from(""),
exitCode: 0,
};
},
}),
{ escape(value) { return JSON.stringify(String(value)); } },
),
directory: repoRoot,
});

assert.equal(typeof plugin, "object");
assert.equal(typeof plugin.hooks["tool.execute.before"], "function");
});
Loading