mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-02 02:07:25 +08:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Its CLI is published as the paperclipai npm package, with the root README shown on the package page > - The root README uses repository-relative image paths so images render correctly on GitHub > - npm resolves those paths under the package repository directory, which is cli, so the image requests point to missing cli/doc/assets files > - This pull request prepares the generated npm README by converting only image src and srcset asset paths to stable raw GitHub URLs > - The benefit is that the same source README remains correct on GitHub and the published npm README displays its images ## Linked Issues or Issue Description **Where is the issue?** The issue is in the root README image assets and the npm packaging step in scripts/build-npm.sh. The affected public page is https://www.npmjs.com/package/paperclipai. **What's wrong?** The npm build copies README.md into cli/ before publishing. npm resolves relative image paths beneath the package repository directory, so doc/assets/banner.jpg becomes cli/doc/assets/banner.jpg. Those files do not exist, and the images render as broken on npm. **Suggested fix** Keep the root README paths relative for GitHub. Rewrite repository-relative image paths only in the generated npm README copy to absolute raw.githubusercontent.com URLs. ## What Changed - Added a small npm README preparation script that rewrites relative image src and srcset asset paths. - Updated scripts/build-npm.sh to use the preparation step when generating the npm package README. - Added a regression test for src, srcset, immutable refs, absolute URLs, and non-image Markdown links. - Pinned release-build image URLs to the source commit, while preserving tarball builds by passing their known source refs. ## Verification - Passed: node --test scripts/prepare-npm-readme.test.mjs - Passed: bash -n scripts/build-npm.sh scripts/e2e-install-lifecycle.sh scripts/e2e-update-migrations.sh - Passed: focused README and E2E migration harness tests - Passed: git diff origin/master...HEAD --check - Generated README asset URLs were checked against raw GitHub and all seven returned HTTP 200. ## Risks Low risk. The change affects only the temporary README generated for npm packaging. It does not change the GitHub README or runtime code. The generated npm README depends on the public raw GitHub asset URLs remaining available. ## Model Used OpenAI Codex, GPT-5. Tool-enabled repository inspection, code execution, browser verification, and git/GitHub operations were used. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with Fixes: # / Closes: # / Refs: # OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub #NNN / github.com/paperclipai/paperclip URLs) - [x] My branch name describes the change (e.g. docs/... or fix/...) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented risks above - [ ] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
91 lines
3.5 KiB
Bash
Executable File
91 lines
3.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# build-npm.sh — Build the paperclipai CLI package for npm publishing.
|
|
#
|
|
# Uses esbuild to bundle all workspace code into a single file,
|
|
# keeping external npm dependencies as regular package dependencies.
|
|
#
|
|
# Usage:
|
|
# ./scripts/build-npm.sh # full build
|
|
# ./scripts/build-npm.sh --skip-checks # skip forbidden-token check (CI without token list)
|
|
|
|
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
CLI_DIR="$REPO_ROOT/cli"
|
|
DIST_DIR="$CLI_DIR/dist"
|
|
|
|
skip_checks=false
|
|
skip_typecheck=false
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--skip-checks) skip_checks=true ;;
|
|
--skip-typecheck) skip_typecheck=true ;;
|
|
esac
|
|
done
|
|
|
|
echo "==> Building paperclipai for npm"
|
|
|
|
# ── Step 1: Forbidden token check ──────────────────────────────────────────────
|
|
if [ "$skip_checks" = false ]; then
|
|
echo " [1/5] Running forbidden token check..."
|
|
node "$REPO_ROOT/scripts/check-forbidden-tokens.mjs"
|
|
else
|
|
echo " [1/5] Skipping forbidden token check (--skip-checks)"
|
|
fi
|
|
|
|
# ── Step 2: TypeScript type-check ──────────────────────────────────────────────
|
|
if [ "$skip_typecheck" = false ]; then
|
|
echo " [2/6] Type-checking..."
|
|
cd "$REPO_ROOT"
|
|
corepack pnpm -r typecheck
|
|
else
|
|
echo " [2/6] Skipping type-check (--skip-typecheck)"
|
|
fi
|
|
|
|
# ── Step 3: Bundle CLI with esbuild ────────────────────────────────────────────
|
|
echo " [3/6] Bundling CLI with esbuild..."
|
|
cd "$CLI_DIR"
|
|
rm -rf dist
|
|
|
|
node --input-type=module -e "
|
|
import esbuild from 'esbuild';
|
|
import config from './esbuild.config.mjs';
|
|
await esbuild.build(config);
|
|
"
|
|
|
|
chmod +x dist/index.js
|
|
|
|
# ── Step 4: Validate bundled entrypoint syntax ─────────────────────────────────
|
|
echo " [4/6] Verifying bundled entrypoint syntax..."
|
|
node --check "$DIST_DIR/index.js"
|
|
|
|
# ── Step 5: Back up dev package.json, generate publishable one ─────────────────
|
|
echo " [5/6] Generating publishable package.json..."
|
|
cp "$CLI_DIR/package.json" "$CLI_DIR/package.dev.json"
|
|
node "$REPO_ROOT/scripts/generate-npm-package-json.mjs"
|
|
|
|
# Copy the root README so npm shows the repo README on the package page, but
|
|
# rewrite repository-relative image assets because npm resolves README links
|
|
# under the package's `repository.directory` (`cli`), not the repository root.
|
|
README_ASSET_REF="${PAPERCLIP_README_ASSET_REF:-}"
|
|
if [ -z "$README_ASSET_REF" ]; then
|
|
README_ASSET_REF="$(git -C "$REPO_ROOT" rev-parse HEAD 2>/dev/null || true)"
|
|
fi
|
|
README_ASSET_REF="${README_ASSET_REF:-master}"
|
|
node "$REPO_ROOT/scripts/prepare-npm-readme.mjs" \
|
|
"$REPO_ROOT/README.md" \
|
|
"$CLI_DIR/README.md" \
|
|
"$README_ASSET_REF"
|
|
|
|
# ── Step 6: Summary ───────────────────────────────────────────────────────────
|
|
BUNDLE_SIZE=$(wc -c < "$DIST_DIR/index.js" | xargs)
|
|
echo " [6/6] Build verification..."
|
|
echo ""
|
|
echo "Build complete."
|
|
echo " Bundle: cli/dist/index.js (${BUNDLE_SIZE} bytes)"
|
|
echo " Source map: cli/dist/index.js.map"
|
|
echo ""
|
|
echo "To preview: cd cli && npm pack --dry-run"
|
|
echo "To publish: cd cli && npm publish --access public"
|
|
echo "To restore: mv cli/package.dev.json cli/package.json"
|