mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-09 15:59:30 +00:00
fix(release): validate plugin npm publish args
This commit is contained in:
parent
a1201e99fc
commit
1706bfda2c
2 changed files with 77 additions and 5 deletions
|
|
@ -2,18 +2,40 @@
|
|||
|
||||
set -euo pipefail
|
||||
|
||||
mode="${1:-}"
|
||||
package_dir="${2:-}"
|
||||
usage() {
|
||||
echo "usage: bash scripts/plugin-npm-publish.sh [--dry-run|--pack-dry-run|--publish] <package-dir>"
|
||||
}
|
||||
|
||||
if [[ "${mode}" != "--dry-run" && "${mode}" != "--pack-dry-run" && "${mode}" != "--publish" ]]; then
|
||||
echo "usage: bash scripts/plugin-npm-publish.sh [--dry-run|--pack-dry-run|--publish] <package-dir>" >&2
|
||||
exit 2
|
||||
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
|
||||
usage
|
||||
exit 0
|
||||
fi
|
||||
|
||||
mode="${1:-}"
|
||||
if [[ "${mode}" != "--dry-run" && "${mode}" != "--pack-dry-run" && "${mode}" != "--publish" ]]; then
|
||||
usage >&2
|
||||
exit 2
|
||||
fi
|
||||
shift
|
||||
|
||||
if [[ "${1:-}" == "--" ]]; then
|
||||
shift
|
||||
fi
|
||||
package_dir=""
|
||||
if [[ "$#" -gt 0 ]]; then
|
||||
case "$1" in
|
||||
-*) echo "unexpected plugin npm package-dir option: $1" >&2; exit 2 ;;
|
||||
*) package_dir="$1"; shift ;;
|
||||
esac
|
||||
fi
|
||||
if [[ -z "${package_dir}" ]]; then
|
||||
echo "missing package dir" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [[ "$#" -gt 0 ]]; then
|
||||
echo "unexpected plugin npm publish argument: $1" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
package_name="$(node -e 'const pkg = require(require("node:path").resolve(process.argv[1], "package.json")); console.log(pkg.name)' "${package_dir}")"
|
||||
package_version="$(node -e 'const pkg = require(require("node:path").resolve(process.argv[1], "package.json")); console.log(pkg.version)' "${package_dir}")"
|
||||
|
|
|
|||
50
test/scripts/plugin-npm-publish.test.ts
Normal file
50
test/scripts/plugin-npm-publish.test.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// Plugin NPM Publish tests cover publish wrapper argument safety.
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const scriptPath = "scripts/plugin-npm-publish.sh";
|
||||
|
||||
function runPluginPublishWrapper(args: string[]) {
|
||||
return spawnSync("bash", [scriptPath, ...args], {
|
||||
cwd: process.cwd(),
|
||||
encoding: "utf8",
|
||||
});
|
||||
}
|
||||
|
||||
describe("plugin npm publish wrapper", () => {
|
||||
it("prints help before package or npm checks", () => {
|
||||
const result = runPluginPublishWrapper(["--help"]);
|
||||
|
||||
expect(result.status).toBe(0);
|
||||
expect(result.stdout.trim()).toBe(
|
||||
"usage: bash scripts/plugin-npm-publish.sh [--dry-run|--pack-dry-run|--publish] <package-dir>",
|
||||
);
|
||||
expect(result.stderr).toBe("");
|
||||
});
|
||||
|
||||
it("rejects missing mode before package checks", () => {
|
||||
const result = runPluginPublishWrapper([]);
|
||||
|
||||
expect(result.status).toBe(2);
|
||||
expect(result.stdout).toBe("");
|
||||
expect(result.stderr.trim()).toBe(
|
||||
"usage: bash scripts/plugin-npm-publish.sh [--dry-run|--pack-dry-run|--publish] <package-dir>",
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects option-like package dirs before package checks", () => {
|
||||
const result = runPluginPublishWrapper(["--dry-run", "--wat"]);
|
||||
|
||||
expect(result.status).toBe(2);
|
||||
expect(result.stdout).toBe("");
|
||||
expect(result.stderr.trim()).toBe("unexpected plugin npm package-dir option: --wat");
|
||||
});
|
||||
|
||||
it("rejects extra arguments before package checks", () => {
|
||||
const result = runPluginPublishWrapper(["--dry-run", "extensions/telegram", "extra"]);
|
||||
|
||||
expect(result.status).toBe(2);
|
||||
expect(result.stdout).toBe("");
|
||||
expect(result.stderr.trim()).toBe("unexpected plugin npm publish argument: extra");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue