fix(plugins): enhance plugin installation and script handling
- Updated the `pnpm install` command in `plugin-install.js` to include the `--ignore-workspace` flag, ensuring proper installation of plugins within the app tree. - Improved the `instantiateScriptSource` function in `script-sandbox.js` to resolve `pluginDir` more effectively, allowing for better package management. - Added a new smoke test in `plugins-smoke.js` to validate the ability to require additional packages from plugin directories, enhancing testing coverage for plugin functionality. - Updated documentation in `AGENTS.md` to reflect changes in the installation command.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "fs";
|
||||
import path from "node:path";
|
||||
import { migrate, db } from "../db.js";
|
||||
import { getAppVersion, satisfiesRange } from "../app-version.js";
|
||||
import {
|
||||
@@ -18,6 +19,7 @@ import {
|
||||
uninstallPlugin,
|
||||
listInstalledPlugins,
|
||||
createBlankPlugin,
|
||||
pluginDir,
|
||||
} from "../plugin-store.js";
|
||||
import { installExamplePlugin } from "../plugin-install.js";
|
||||
import {
|
||||
@@ -119,11 +121,58 @@ async function main() {
|
||||
);
|
||||
assert.ok(meta);
|
||||
|
||||
const extra = createBlankPlugin(
|
||||
"extra-require-smoke",
|
||||
`const extra = require("smoke-extra");
|
||||
async function main() {
|
||||
return { output: { n: extra.n } };
|
||||
}
|
||||
main.meta = {
|
||||
description: "smoke extra require",
|
||||
config: {},
|
||||
input: {},
|
||||
output: { n: { type: "number" } },
|
||||
example: { data: {}, config: {} },
|
||||
};
|
||||
export default main;
|
||||
`,
|
||||
);
|
||||
assert.equal(extra.scriptRef, "plugin/extra-require-smoke");
|
||||
const extraPkg = path.join(
|
||||
pluginDir("extra-require-smoke"),
|
||||
"node_modules",
|
||||
"smoke-extra",
|
||||
);
|
||||
fs.mkdirSync(extraPkg, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(extraPkg, "package.json"),
|
||||
`${JSON.stringify({ name: "smoke-extra", main: "index.js" })}\n`,
|
||||
);
|
||||
fs.writeFileSync(path.join(extraPkg, "index.js"), "module.exports = { n: 9 };\n");
|
||||
clearScriptCache();
|
||||
const extraSource = fs.readFileSync(
|
||||
path.join(pluginDir("extra-require-smoke"), "script.js"),
|
||||
"utf8",
|
||||
);
|
||||
const extraInspect = inspectScriptSource(
|
||||
"plugin/extra-require-smoke",
|
||||
extraSource,
|
||||
);
|
||||
assert.equal(extraInspect.metaError, null, extraInspect.metaError);
|
||||
assert.equal(extraInspect.meta?.description, "smoke extra require");
|
||||
const extraRun = await runScript(
|
||||
"plugin/extra-require-smoke",
|
||||
{ data: null, context: {}, config: null },
|
||||
{ log: silent, workflowName: "smoke", owner: "default" },
|
||||
);
|
||||
assert.equal(extraRun.output.n, 9);
|
||||
|
||||
assert.ok(listInstalledPlugins().some((p) => p.id === "get-current-time"));
|
||||
|
||||
uninstallPlugin("jsonata-smoke-fork");
|
||||
uninstallPlugin("blank-smoke");
|
||||
uninstallPlugin("blank-smoke-copy");
|
||||
uninstallPlugin("extra-require-smoke");
|
||||
uninstallPlugin("get-current-time");
|
||||
|
||||
console.log("plugins-smoke: ok");
|
||||
|
||||
Reference in New Issue
Block a user