diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2bb6ab9..8aa30d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,10 +26,11 @@ jobs: with: bun-version: 1.3.10 - # The e2e tests (tests/e2e) run the npm package on Node, so src/ - # can't use Bun-only APIs. Test on the oldest Node that package.json's engines allows, - # exactly: `node-version: 20` would pick the newest 20.x and miss APIs that older 20.x - # releases lack (@clack/prompts needs util.styleText, new in 20.12.0). + # The e2e tests (packages/cli/tests/e2e) run the npm package on Node, so + # packages/*/src can't use Bun-only APIs. Test on the oldest Node that + # packages/cli/package.json's engines allows, exactly: `node-version: 20` would pick + # the newest 20.x and miss APIs that older 20.x releases lack (@clack/prompts needs + # util.styleText, new in 20.12.0). - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: 20.12.0 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8b4054b..e388ebf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,21 +1,27 @@ name: Release # On every push to main: -# - release-please opens or updates a release PR. It reads the Conventional Commit -# messages (fix:, feat:, feat!:) since the last release, and bumps the version in -# package.json and adds the changes to CHANGELOG.md to match. +# - release-please opens or updates the CLI's release PR (release-please/cli-config.json). +# It reads the Conventional Commit messages (fix:, feat:, feat!:) since the last +# release, leaving out commits that only change packages/mcp: so a change to +# packages/core, which isn't published, or to the lockfile or the build releases the +# CLI too. It bumps the version in packages/cli/version.txt and package.json and adds +# the changes to packages/cli/CHANGELOG.md to match. # - The binaries and the npm package of HEAD are built with a -dev version and kept as a # workflow artifact, tinify-. The Windows binary is checked on Windows, since # the build runs on macOS; nothing is published unless that check passes. -# - Unless the push creates a release, that build replaces the unstable pre-release on +# - Unless the push creates a release, that build replaces the cli-main pre-release on # GitHub. Unreleased builds never go to npm. -# Merging the release PR tags the release and creates the GitHub Release; the binaries are -# then attached to it and the npm package is published. +# Merging the release PR tags the release cli-v and creates its GitHub Release as +# a draft. Once the binaries are attached it's published as the latest release, which the +# README's download links use, so they never reach a release without them. The npm package +# is published too. # # Run it by hand with a release's tag to build and publish that release again, for example -# after a failed upload or publish. What is already published is kept: only missing -# binaries are uploaded, replacing what a failed upload left behind, and SHA256SUMS is -# made from the binaries on the release. +# after a failed upload or publish. Pick that tag under "Use workflow from" too, so this +# file matches the release's files, which older releases lay out differently. What is +# already published is kept: only missing binaries are uploaded, replacing what a failed +# upload left behind, and SHA256SUMS is made from the binaries on the release. on: push: @@ -23,7 +29,7 @@ on: workflow_dispatch: inputs: tag: - description: Tag of an existing GitHub Release, e.g. v1.0.0 + description: Tag of an existing GitHub Release, e.g. cli-v1.1.0. Pick it under "Use workflow from" too. required: true type: string @@ -46,16 +52,18 @@ jobs: pull-requests: write issues: write outputs: - release_created: ${{ steps.release.outputs.release_created }} - tag_name: ${{ steps.release.outputs.tag_name }} + release_created: ${{ steps.cli.outputs.release_created }} + tag_name: ${{ steps.cli.outputs.tag_name }} steps: - uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0 - id: release + id: cli with: # PRs opened with the default GITHUB_TOKEN don't trigger the CI workflow, so the # release PR gets no checks. To fix that, add a RELEASE_PLEASE_TOKEN secret: a # fine-grained token with contents and pull requests read/write on this repo. token: ${{ secrets.RELEASE_PLEASE_TOKEN || github.token }} + config-file: release-please/cli-config.json + manifest-file: release-please/cli-manifest.json build: needs: release-please @@ -87,16 +95,16 @@ jobs: - name: Set the version id: version run: | - version=$(bun -p 'require("./package.json").version') + version=$(bun -p 'require("./packages/cli/package.json").version') if [ "$RELEASE" = true ]; then - if [ "$TAG" != "v$version" ]; then - echo "::error::Tag $TAG doesn't match version $version in package.json" + if [ "$TAG" != "cli-v$version" ]; then + echo "::error::Tag $TAG doesn't match version $version in packages/cli/package.json" exit 1 fi else # Builds of HEAD can't be mistaken for the release they come after. version="$version-dev+${GITHUB_SHA:0:7}" - npm pkg set version="$version" + (cd packages/cli && npm pkg set version="$version") fi echo "version=$version" >> "$GITHUB_OUTPUT" @@ -105,10 +113,10 @@ jobs: - name: Check the binary runs and reports the version env: VERSION: ${{ steps.version.outputs.version }} - run: test "$(./dist/tinify-darwin-arm64 --version)" = "$VERSION" + run: test "$(packages/cli/dist/tinify-darwin-arm64 --version)" = "$VERSION" # The npm package is plain JavaScript for Node; check it runs on exactly the oldest - # Node that package.json's engines allows. + # Node that packages/cli/package.json's engines allows. - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: 20.12.0 @@ -121,16 +129,16 @@ jobs: env: VERSION: ${{ steps.version.outputs.version }} run: | - npm install --global --prefix "$RUNNER_TEMP/npm-check" --no-audit --no-fund dist/npm/*.tgz + npm install --global --prefix "$RUNNER_TEMP/npm-check" --no-audit --no-fund packages/cli/dist/npm/*.tgz test "$("$RUNNER_TEMP/npm-check/bin/tinify" --version)" = "$VERSION" - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: tinify-${{ steps.version.outputs.version }} - path: dist/ + path: packages/cli/dist/ if-no-files-found: error - # It carries the build to the publish jobs below; the unstable release keeps the - # latest one. + # It carries the build to the publish jobs below; the cli-main pre-release keeps + # the latest one. retention-days: 14 check-windows: @@ -211,6 +219,18 @@ jobs: (cd published && sha256sum tinify-* > SHA256SUMS) upload published/SHA256SUMS fi + # release-please made the release a draft; with its binaries attached, it's + # published. A release published before, which a manual run only completes, stays + # as it is. The latest release, which the README's download links use, only moves + # forward: a manual run that publishes an older release's draft leaves it alone. + # The lookups are assigned first, so a failed one fails the job. + draft=$(gh release view "$TAG" --json isDraft --jq .isDraft --repo "$GITHUB_REPOSITORY") + if [ "$draft" = true ]; then + latest=$(gh release view --json tagName --jq .tagName --repo "$GITHUB_REPOSITORY") + newest=$(printf '%s\n' "${latest##*v}" "${TAG##*v}" | sort -V | tail -n 1) + make_latest=$([ "$newest" = "${TAG##*v}" ] && echo true || echo false) + gh release edit "$TAG" --draft=false --latest="$make_latest" --repo "$GITHUB_REPOSITORY" + fi npm: # Listing check-windows in needs isn't enough: with !cancelled(), a job runs even @@ -246,10 +266,11 @@ jobs: npm publish "dist/npm/tinify-cli-$VERSION.tgz" fi - # Every push to main that doesn't cut a release replaces the "unstable" pre-release with - # its build, so a fix can be tried before it's released. Unreleased builds never go to - # npm: a version published there can't be taken back. - unstable: + # Every push to main that doesn't cut a release replaces the "cli-main" pre-release with + # its build, so a fix can be tried before it's released. Each published package has a + # -main of its own, so their builds don't replace each other's. Unreleased builds + # never go to npm: a version published there can't be taken back. + prerelease: # Listing check-windows in needs isn't enough: with !cancelled(), a job runs even # after a job it needs failed, so its result is checked too. needs: [build, check-windows] @@ -263,7 +284,7 @@ jobs: name: tinify-${{ needs.build.outputs.version }} path: dist - - name: Replace the unstable pre-release + - name: Replace the cli-main pre-release env: GH_TOKEN: ${{ github.token }} GH_REPO: ${{ github.repository }} @@ -274,11 +295,12 @@ jobs: # "+" of the version in it, which GitHub would rewrite. mv dist/npm/*.tgz dist/npm/tinify-cli.tgz # There's none on the first run. - gh release delete unstable --cleanup-tag --yes || true + gh release delete cli-main --cleanup-tag --yes || true notes="Unreleased build of $GITHUB_SHA on main, version $VERSION, for trying a fix before it's released. Not for production use: use the [latest release](https://github.com/$GITHUB_REPOSITORY/releases/latest) for that. The macOS binaries aren't notarized, so macOS refuses to run one downloaded in a browser: \`xattr -d com.apple.quarantine tinify-darwin-arm64\` (or \`tinify-darwin-x64\` on an Intel Mac) lifts that. The npm package installs with \`npm install -g ./tinify-cli.tgz\`." # gh publishes the release only once every file is uploaded. - gh release create unstable dist/tinify-* dist/SHA256SUMS dist/npm/tinify-cli.tgz \ - --prerelease --target "$GITHUB_SHA" --title "$VERSION" \ + # Titled like release-please's releases ("cli: v1.0.1"). + gh release create cli-main dist/tinify-* dist/SHA256SUMS dist/npm/tinify-cli.tgz \ + --prerelease --target "$GITHUB_SHA" --title "cli: $VERSION" \ --notes "$notes" diff --git a/.oxlintrc.json b/.oxlintrc.json index d0023e6..af9cd86 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -16,7 +16,7 @@ }, "overrides": [ { - "files": ["tests/**"], + "files": ["packages/*/tests/**"], "rules": { "typescript/no-explicit-any": "off", "typescript/no-non-null-assertion": "off" diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 592bfc7..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,5 +0,0 @@ -# Changelog - -## [1.0.0](https://github.com/tinify/tinify-cli/releases/tag/v1.0.0) - -Initial release. diff --git a/Makefile b/Makefile index 22f4f17..5129975 100644 --- a/Makefile +++ b/Makefile @@ -1,42 +1,8 @@ .PHONY: build clean release npm test typecheck lint check -NAME := tinify -SRC := src/index.ts -DIST := dist - -# On Windows, Git Bash rewrites arguments that look like POSIX paths before running a -# Windows program: the npm bundle's shebang `#!/usr/bin/env node` would become -# `#!C:/Program Files/Git/usr/bin/env node`, which npm's .cmd shim can't run. Turn that off. -export MSYS_NO_PATHCONV := 1 -export MSYS2_ARG_CONV_EXCL := * - -build: - bun build --compile $(SRC) --outfile $(DIST)/$(NAME) - -# macOS binaries must be signed to run on Apple Silicon, and codesign only -# exists on macOS, so releases are built there. --force: Bun leaves the x64 binary -# with Bun's own Developer ID signature, now broken, and codesign only replaces -# an existing signature with --force. -release: clean - @command -v codesign >/dev/null || { echo "release: codesign not found; run this on macOS" >&2; exit 1; } - mkdir -p $(DIST) - bun build --compile --target=bun-darwin-arm64 $(SRC) --outfile $(DIST)/$(NAME)-darwin-arm64 - bun build --compile --target=bun-darwin-x64 $(SRC) --outfile $(DIST)/$(NAME)-darwin-x64 - bun build --compile --target=bun-linux-arm64 $(SRC) --outfile $(DIST)/$(NAME)-linux-arm64 - bun build --compile --target=bun-linux-x64 $(SRC) --outfile $(DIST)/$(NAME)-linux-x64 - bun build --compile --target=bun-windows-x64 $(SRC) --outfile $(DIST)/$(NAME)-windows-x64.exe - codesign --force -s - $(DIST)/$(NAME)-darwin-arm64 - codesign --force -s - $(DIST)/$(NAME)-darwin-x64 - cd $(DIST) && shasum -a 256 $(NAME)-* > SHA256SUMS - -# The npm package: src/ built into one JavaScript file for Node, and its tarball. Its -# dependencies stay external (--packages=external): npm installs them from package.json's -# dependencies. The binaries above bundle them; --compile always does. -# The banner is the shebang that lets npm run it as the `tinify` command. -npm: - bun build --target=node --packages=external --banner="#!/usr/bin/env node" $(SRC) --outfile $(DIST)/$(NAME).mjs - mkdir -p $(DIST)/npm - npm pack --pack-destination $(DIST)/npm +# The CLI's builds: packages/cli/Makefile, with its output in packages/cli/dist. +build clean release npm: + $(MAKE) -C packages/cli $@ test: bun test @@ -49,6 +15,3 @@ lint: bun run format:check check: typecheck lint test - -clean: - rm -rf $(DIST) diff --git a/README.md b/README.md index 51fdd53..83f2e7a 100644 --- a/README.md +++ b/README.md @@ -52,15 +52,15 @@ You need [Bun](https://bun.sh) installed. If you don't have it: curl -fsSL https://bun.sh/install | bash ``` -Then build and install `tinify` (on Windows, `make build` gives `dist\tinify.exe`; move it -to a folder on your `PATH`): +Then build and install `tinify` (on Windows, `make build` gives +`packages\cli\dist\tinify.exe`; move it to a folder on your `PATH`): ```bash git clone https://github.com/tinify/tinify-cli.git cd tinify-cli bun install make build -sudo mv dist/tinify /usr/local/bin/tinify +sudo mv packages/cli/dist/tinify /usr/local/bin/tinify ``` Check that it worked: @@ -73,7 +73,7 @@ That prints a version number. If you get `command not found`, `/usr/local/bin` i ```bash mkdir -p ~/.local/bin -mv dist/tinify ~/.local/bin/tinify +mv packages/cli/dist/tinify ~/.local/bin/tinify echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc source ~/.zshrc ``` @@ -344,6 +344,14 @@ There is no other cache or log. To forget what tinify compressed, delete `compre ## Development +The repo is a [Bun workspace](https://bun.sh/docs/install/workspaces) of two packages: + +- `packages/cli`: `@tinify/cli`, the `tinify` command: its options, messages and progress + display. +- `packages/core`: finding images, compressing them through the Tinify API, writing the + results, the record of what was compressed and the saved API key. It isn't published: + the CLI's builds include it. + ```bash bun install bun test # unit tests, and e2e tests that build and run the CLI against a fake API @@ -352,31 +360,33 @@ bun run typecheck # tsc --noEmit bun run lint # oxlint bun run format # oxfmt (format:check to verify only) make check # typecheck, lint, format:check and bun test, as CI runs them -make build # binary at dist/tinify +make build # binary at packages/cli/dist/tinify make release # macOS, Linux and Windows binaries and SHA256SUMS; run on macOS (needs codesign) -make npm # npm package: dist/tinify.mjs for Node, and its tarball in dist/npm +make npm # npm package: packages/cli/dist/tinify.mjs for Node, and its tarball in packages/cli/dist/npm ``` -The npm package is `src/` built into one JavaScript file that runs on Node, so `src/` -can't use Bun-only APIs (`Bun.*`, `bun:*` imports). Tests can use Bun's APIs. Its -dependencies aren't in that file: npm installs them, from `dependencies` in -`package.json`. The binaries have them built in. +The npm package is the CLI's `src/` and `packages/core/src/` built into one JavaScript +file that runs on Node, so neither can use Bun-only APIs (`Bun.*`, `bun:*` imports). +Tests can use Bun's APIs. The CLI's dependencies aren't in that file: npm installs them, +from `dependencies` in `packages/cli/package.json`. Since the core is built in, the +packages it uses must be listed there too. The binaries have them built in. -The e2e tests (`tests/e2e/`) run `make build` and `make npm`, install the npm package from -its tarball into `dist/e2e npm/`, and run both the package (on Node) and the Bun binary as +The e2e tests (`packages/cli/tests/e2e/`) run `make build` and `make npm`, install the npm +package from its tarball into `packages/cli/dist/e2e npm/`, and run both the package (on +Node) and the Bun binary as a user would: every command, error and dry run, real compressing, converting and resizing, with folder trees that differ per OS, and, on Linux and macOS, stopping with a signal. CI runs them on Linux, macOS and Windows. They need `make`, Node 20.12 or later, npm and access to the npm registry (for the -package's dependencies), and they leave their builds in `dist/`. +package's dependencies), and they leave their builds in `packages/cli/dist/`. They don't call the Tinify API. They start a fake one on `127.0.0.1` and point the CLI at it with the `TINIFY_API_ENDPOINT` environment variable. The fake serves HTTPS with a -test-only certificate (`tests/e2e/fixtures/`), which the CLI trusts because the tests pass +test-only certificate (`packages/cli/tests/e2e/fixtures/`), which the CLI trusts because the tests pass it in `NODE_EXTRA_CA_CERTS`. `TINIFY_API_ENDPOINT` must be an `https://` URL; it's meant for tests, not for users. -The integration tests (`tests/integration.ts`) run the npm package, and the Bun binary +The integration tests (`packages/cli/tests/integration.ts`) run the npm package, and the Bun binary where it matters, against the real Tinify API: compressing, converting, resizing, a wrong key, an unusable `--output`, an S3 store that Tinify refuses, and Ctrl-C or `kill` during a run. Put a key in `.env` as `TINIFY_KEY=...` (Bun reads it; git ignores it). A run @@ -399,18 +409,26 @@ the PR title. | `feat!: ...`, or a `BREAKING CHANGE:` footer | major: 1.0.0 → 2.0.0 | | `docs:`, `chore:`, `ci:`, `test:`, `refactor:`, `build:` | no release | +Each published package has its own version, tags, `CHANGELOG.md` and release-please config +in `release-please/`. Its release counts every commit except those that only change another +published package, so a change to `packages/core`, which isn't published, or to the lockfile +or the build releases each of them. The CLI's version is in `packages/cli/version.txt` and +`package.json`; release-please bumps both. + On every push to `main`, the Release workflow keeps a release PR open with the next version -and its CHANGELOG entry. Merging it tags the release, attaches the binaries to the GitHub -Release, and publishes `@tinify/cli` to npm. +and its CHANGELOG entry. Merging it tags the release `cli-v` and creates its GitHub +Release as a draft. Once the binaries are attached, the release is published, and so is +`@tinify/cli` on npm. Every push to `main` that doesn't cut a release replaces the -[`unstable`](https://github.com/tinify/tinify-cli/releases/tag/unstable) pre-release with +[`cli-main`](https://github.com/tinify/tinify-cli/releases/tag/cli-main) pre-release with the binaries and the npm package of that commit, versioned `-dev+`, so a fix can be tried before it's released. These builds never go to npm. If uploading or publishing a release fails, run the Release workflow by hand with the -release's tag. It skips what's already published. +release's tag, and pick that tag under "Use workflow from" too, so the workflow matches +the release's files. It skips what's already published. ## License diff --git a/bun.lock b/bun.lock index 6d9c823..5c0b519 100644 --- a/bun.lock +++ b/bun.lock @@ -4,10 +4,6 @@ "workspaces": { "": { "name": "tinycli", - "dependencies": { - "@clack/prompts": "^1.9.0", - "tinify": "^2.0.0", - }, "devDependencies": { "@types/bun": "1.4.4", "oxfmt": "0.79.0", @@ -15,6 +11,26 @@ "typescript": "7.0.2", }, }, + "packages/cli": { + "name": "@tinify/cli", + "version": "1.0.0", + "bin": { + "tinify": "dist/tinify.mjs", + }, + "dependencies": { + "@clack/prompts": "^1.9.0", + "tinify": "^2.0.0", + }, + "devDependencies": { + "@tinify/core": "workspace:*", + }, + }, + "packages/core": { + "name": "@tinify/core", + "dependencies": { + "tinify": "^2.0.0", + }, + }, }, "packages": { "@clack/core": ["@clack/core@1.6.0", "", { "dependencies": { "fast-string-width": "^3.0.2", "fast-wrap-ansi": "^0.2.0", "sisteransi": "^2.0.0" } }, "sha512-4GZynIB2IIe431odxesswvWTCP6orvqd6e2b07b3VFWBQRqUqIHc/EPIZwFoKS692QBp+ooPuXKaJV8g4kXuYA=="], @@ -97,6 +113,10 @@ "@oxlint/binding-win32-x64-msvc": ["@oxlint/binding-win32-x64-msvc@1.94.0", "", { "os": "win32", "cpu": "x64" }, "sha512-I3eZdd4bemIJQDNv9XDV/FEofDxIoN32tzCv98wIgLdW05EqxZb5hF4AwPrRzHD/dQhl0n7KgPy5AQPfM0HWrA=="], + "@tinify/cli": ["@tinify/cli@workspace:packages/cli"], + + "@tinify/core": ["@tinify/core@workspace:packages/core"], + "@types/bun": ["@types/bun@1.4.4", "", { "dependencies": { "bun-types": "1.4.4" } }, "sha512-9wkRDXUXK124pEnAutE6n/l18j+i9GC5IAHK8TmX/2nlySETmky0OU6yL5U8pW1AoKh++AN9auDCr647BfurjQ=="], "@types/node": ["@types/node@25.5.0", "", { "dependencies": { "undici-types": "~7.18.0" } }, "sha512-jp2P3tQMSxWugkCUKLRPVUpGaL5MVFwF8RDuSRztfwgN1wmqJeMSbKlnEtQqU8UrhTmzEmZdu2I6v2dpp7XIxw=="], diff --git a/package.json b/package.json index 6207e42..1f8340d 100644 --- a/package.json +++ b/package.json @@ -1,38 +1,20 @@ { - "name": "@tinify/cli", - "version": "1.0.0", - "description": "Compress, convert and resize images from the command line with the Tinify API", + "name": "tinify-cli", + "private": true, "license": "MIT", - "repository": { - "type": "git", - "url": "git+https://github.com/tinify/tinify-cli.git" - }, "type": "module", - "bin": { - "tinify": "dist/tinify.mjs" - }, - "files": [ - "dist/tinify.mjs" + "workspaces": [ + "packages/*" ], - "engines": { - "node": "^20.12.0 || >=21.7.0" - }, - "publishConfig": { - "access": "public" - }, "scripts": { "test": "bun test", - "test:integration": "bun test ./tests/integration.ts", + "test:integration": "bun test ./packages/cli/tests/integration.ts", "typecheck": "tsc --noEmit", "lint": "oxlint --deny-warnings", "format": "oxfmt", "format:check": "oxfmt --check", "build": "make build" }, - "dependencies": { - "@clack/prompts": "^1.9.0", - "tinify": "^2.0.0" - }, "devDependencies": { "@types/bun": "1.4.4", "oxfmt": "0.79.0", diff --git a/packages/cli/.gitignore b/packages/cli/.gitignore new file mode 100644 index 0000000..918c23b --- /dev/null +++ b/packages/cli/.gitignore @@ -0,0 +1,3 @@ +# Copied from the repo's by `make npm`, for the npm package +README.md +LICENSE diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md new file mode 100644 index 0000000..2d6cba0 --- /dev/null +++ b/packages/cli/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## [1.0.0](https://github.com/tinify/tinify-cli/releases/tag/cli-v1.0.0) + +Initial release. diff --git a/packages/cli/Makefile b/packages/cli/Makefile new file mode 100644 index 0000000..6e9cc09 --- /dev/null +++ b/packages/cli/Makefile @@ -0,0 +1,47 @@ +.PHONY: build clean release npm + +NAME := tinify +SRC := src/index.ts +DIST := dist + +# On Windows, Git Bash rewrites arguments that look like POSIX paths before running a +# Windows program: the npm bundle's shebang `#!/usr/bin/env node` would become +# `#!C:/Program Files/Git/usr/bin/env node`, which npm's .cmd shim can't run. Turn that off. +export MSYS_NO_PATHCONV := 1 +export MSYS2_ARG_CONV_EXCL := * + +build: + bun build --compile $(SRC) --outfile $(DIST)/$(NAME) + +# macOS binaries must be signed to run on Apple Silicon, and codesign only +# exists on macOS, so releases are built there. --force: Bun leaves the x64 binary +# with Bun's own Developer ID signature, now broken, and codesign only replaces +# an existing signature with --force. +release: clean + @command -v codesign >/dev/null || { echo "release: codesign not found; run this on macOS" >&2; exit 1; } + mkdir -p $(DIST) + bun build --compile --target=bun-darwin-arm64 $(SRC) --outfile $(DIST)/$(NAME)-darwin-arm64 + bun build --compile --target=bun-darwin-x64 $(SRC) --outfile $(DIST)/$(NAME)-darwin-x64 + bun build --compile --target=bun-linux-arm64 $(SRC) --outfile $(DIST)/$(NAME)-linux-arm64 + bun build --compile --target=bun-linux-x64 $(SRC) --outfile $(DIST)/$(NAME)-linux-x64 + bun build --compile --target=bun-windows-x64 $(SRC) --outfile $(DIST)/$(NAME)-windows-x64.exe + codesign --force -s - $(DIST)/$(NAME)-darwin-arm64 + codesign --force -s - $(DIST)/$(NAME)-darwin-x64 + cd $(DIST) && shasum -a 256 $(NAME)-* > SHA256SUMS + +# The npm package: src/ and ../core built into one JavaScript file for Node, and its +# tarball. The dependencies in package.json stay external: npm installs them. Not +# --packages=external, which would leave @tinify/core out too, and it isn't on npm. The +# binaries above bundle everything; --compile always does. +# The banner is the shebang that lets npm run it as the `tinify` command. +# npm packs the README and LICENSE only from this folder, so they're copied from the repo's. +DEPENDENCIES = $(shell bun -p 'Object.keys(require("./package.json").dependencies).join(" ")') + +npm: + bun build --target=node $(addprefix --external=,$(DEPENDENCIES)) --banner="#!/usr/bin/env node" $(SRC) --outfile $(DIST)/$(NAME).mjs + cp ../../README.md ../../LICENSE . + mkdir -p $(DIST)/npm + npm pack --pack-destination $(DIST)/npm + +clean: + rm -rf $(DIST) README.md LICENSE diff --git a/packages/cli/package.json b/packages/cli/package.json new file mode 100644 index 0000000..277ca8d --- /dev/null +++ b/packages/cli/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tinify/cli", + "version": "1.0.0", + "description": "Compress, convert and resize images from the command line with the Tinify API", + "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/tinify/tinify-cli.git", + "directory": "packages/cli" + }, + "type": "module", + "bin": { + "tinify": "dist/tinify.mjs" + }, + "files": [ + "dist/tinify.mjs" + ], + "engines": { + "node": "^20.12.0 || >=21.7.0" + }, + "publishConfig": { + "access": "public" + }, + "dependencies": { + "@clack/prompts": "^1.9.0", + "tinify": "^2.0.0" + }, + "devDependencies": { + "@tinify/core": "workspace:*" + } +} diff --git a/src/index.ts b/packages/cli/src/index.ts similarity index 95% rename from src/index.ts rename to packages/cli/src/index.ts index 3ff8587..fd83af6 100644 --- a/src/index.ts +++ b/packages/cli/src/index.ts @@ -1,20 +1,25 @@ import { constants } from "node:os"; import { parseArgs as parseArgv } from "node:util"; +import { + type CompressOptions, + type CompressSummary, + compressFiles, + type UI, +} from "@tinify/core/compress"; +import { getApiKey, setApiKey } from "@tinify/core/config"; +import { setApiEndpoint } from "@tinify/core/endpoint"; +import { CliError } from "@tinify/core/errors"; +import { resolveFiles } from "@tinify/core/files"; +import { CONVERT_FORMATS, CONVERT_HELP, isConvertFormat } from "@tinify/core/formats"; +import { parseOutputTarget } from "@tinify/core/output"; +import { type CompressedRecord, loadRecord } from "@tinify/core/record"; +import { buildResizeOptions, RESIZE_HELP } from "@tinify/core/resize"; import tinify from "tinify"; import pkg from "../package.json"; -import { type CompressOptions, type CompressSummary, compressFiles } from "./compress"; -import { getApiKey, setApiKey } from "./config"; -import { setApiEndpoint } from "./endpoint"; -import { CliError } from "./errors"; -import { resolveFiles } from "./files"; -import { CONVERT_FORMATS, CONVERT_HELP, isConvertFormat } from "./formats"; -import { parseOutputTarget } from "./output"; -import { type CompressedRecord, loadRecord } from "./record"; import { register } from "./register"; -import { buildResizeOptions, RESIZE_HELP } from "./resize"; -import { createUI, isTTY, type UI } from "./ui"; +import { createUI, isTTY } from "./ui"; const HELP = `tinify — Compress images using the Tinify API diff --git a/src/register.ts b/packages/cli/src/register.ts similarity index 100% rename from src/register.ts rename to packages/cli/src/register.ts diff --git a/src/ui.ts b/packages/cli/src/ui.ts similarity index 91% rename from src/ui.ts rename to packages/cli/src/ui.ts index 801627c..fb29edf 100644 --- a/src/ui.ts +++ b/packages/cli/src/ui.ts @@ -1,40 +1,22 @@ import { basename } from "node:path"; import * as clack from "@clack/prompts"; - -import { formatBytes } from "./bytes"; +import { formatBytes } from "@tinify/core/bytes"; import { type CompressOptions, type CompressResult, type CompressSummary, isCopy, - type SkippedFile, type SkipReason, -} from "./compress"; -import { CliError } from "./errors"; -import { displayPath } from "./files"; -import { writeAll } from "./write-file"; + type SummaryOptions, + type UI, +} from "@tinify/core/compress"; +import { CliError } from "@tinify/core/errors"; +import { displayPath } from "@tinify/core/files"; +import { writeAll } from "@tinify/core/write-file"; -type SummaryOptions = Pick; type LineOptions = Pick; -export interface UI { - start(fileCount: number): void; - onFileComplete(result: CompressResult): void; - /** `filePath` is in full, as in the failure. */ - onFileError(filePath: string, error: Error): void; - /** An image left as it is, decided before its upload. */ - onFileSkipped(skip: SkippedFile): void; - /** - * Shows the summary, written whole before it resolves, unless `stop` is aborted - * meanwhile: tinify is being stopped, so what isn't written yet is given up. - */ - finish(summary: CompressSummary, options: SummaryOptions, stop?: AbortSignal): Promise; - error(message: string): void; - warn(message: string): void; - verbose(message: string): void; -} - export function isTTY(): boolean { return !!process.stdout.isTTY; } diff --git a/tests/args.test.ts b/packages/cli/tests/args.test.ts similarity index 98% rename from tests/args.test.ts rename to packages/cli/tests/args.test.ts index 8fa0a3b..181effa 100644 --- a/tests/args.test.ts +++ b/packages/cli/tests/args.test.ts @@ -1,6 +1,7 @@ import { describe, expect, test } from "bun:test"; -import { CliError } from "../src/errors"; +import { CliError } from "@tinify/core/errors"; + import { type ParsedArgs, parseArgs } from "../src/index"; const parse = (...args: string[]) => parseArgs(["bun", "tinify", ...args]); diff --git a/tests/e2e/api-errors.test.ts b/packages/cli/tests/e2e/api-errors.test.ts similarity index 100% rename from tests/e2e/api-errors.test.ts rename to packages/cli/tests/e2e/api-errors.test.ts diff --git a/tests/e2e/commands.test.ts b/packages/cli/tests/e2e/commands.test.ts similarity index 100% rename from tests/e2e/commands.test.ts rename to packages/cli/tests/e2e/commands.test.ts diff --git a/tests/e2e/compress.test.ts b/packages/cli/tests/e2e/compress.test.ts similarity index 100% rename from tests/e2e/compress.test.ts rename to packages/cli/tests/e2e/compress.test.ts diff --git a/tests/e2e/fake-api.test.ts b/packages/cli/tests/e2e/fake-api.test.ts similarity index 100% rename from tests/e2e/fake-api.test.ts rename to packages/cli/tests/e2e/fake-api.test.ts diff --git a/tests/e2e/fake-api.ts b/packages/cli/tests/e2e/fake-api.ts similarity index 100% rename from tests/e2e/fake-api.ts rename to packages/cli/tests/e2e/fake-api.ts diff --git a/tests/e2e/fixtures/README.md b/packages/cli/tests/e2e/fixtures/README.md similarity index 100% rename from tests/e2e/fixtures/README.md rename to packages/cli/tests/e2e/fixtures/README.md diff --git a/tests/e2e/fixtures/localhost.crt b/packages/cli/tests/e2e/fixtures/localhost.crt similarity index 100% rename from tests/e2e/fixtures/localhost.crt rename to packages/cli/tests/e2e/fixtures/localhost.crt diff --git a/tests/e2e/fixtures/localhost.key b/packages/cli/tests/e2e/fixtures/localhost.key similarity index 100% rename from tests/e2e/fixtures/localhost.key rename to packages/cli/tests/e2e/fixtures/localhost.key diff --git a/tests/e2e/harness.ts b/packages/cli/tests/e2e/harness.ts similarity index 99% rename from tests/e2e/harness.ts rename to packages/cli/tests/e2e/harness.ts index bd208ed..aed83c6 100644 --- a/tests/e2e/harness.ts +++ b/packages/cli/tests/e2e/harness.ts @@ -65,7 +65,7 @@ function exec(command: string, args: string[], cwd: string): void { let built: BuiltCli | Error | undefined; /** - * Runs `make build npm` in the repo (into its git-ignored dist/), then installs the packed + * Runs `make build npm` in packages/cli (into its git-ignored dist/), then installs the packed * tarball into `dist/e2e npm`, as `npm install -g @tinify/cli` would. Once per test * process: every e2e file shares the result, or the error. Needs make, node and npm, and * the npm registry for the package's dependencies. diff --git a/tests/e2e/images.ts b/packages/cli/tests/e2e/images.ts similarity index 100% rename from tests/e2e/images.ts rename to packages/cli/tests/e2e/images.ts diff --git a/tests/e2e/known-bug.ts b/packages/cli/tests/e2e/known-bug.ts similarity index 100% rename from tests/e2e/known-bug.ts rename to packages/cli/tests/e2e/known-bug.ts diff --git a/tests/e2e/os.ts b/packages/cli/tests/e2e/os.ts similarity index 100% rename from tests/e2e/os.ts rename to packages/cli/tests/e2e/os.ts diff --git a/tests/e2e/permissions.test.ts b/packages/cli/tests/e2e/permissions.test.ts similarity index 100% rename from tests/e2e/permissions.test.ts rename to packages/cli/tests/e2e/permissions.test.ts diff --git a/tests/e2e/reruns.test.ts b/packages/cli/tests/e2e/reruns.test.ts similarity index 100% rename from tests/e2e/reruns.test.ts rename to packages/cli/tests/e2e/reruns.test.ts diff --git a/tests/e2e/s3.test.ts b/packages/cli/tests/e2e/s3.test.ts similarity index 100% rename from tests/e2e/s3.test.ts rename to packages/cli/tests/e2e/s3.test.ts diff --git a/tests/e2e/setup.ts b/packages/cli/tests/e2e/setup.ts similarity index 100% rename from tests/e2e/setup.ts rename to packages/cli/tests/e2e/setup.ts diff --git a/tests/e2e/stopping.test.ts b/packages/cli/tests/e2e/stopping.test.ts similarity index 100% rename from tests/e2e/stopping.test.ts rename to packages/cli/tests/e2e/stopping.test.ts diff --git a/tests/e2e/terminal.test.ts b/packages/cli/tests/e2e/terminal.test.ts similarity index 100% rename from tests/e2e/terminal.test.ts rename to packages/cli/tests/e2e/terminal.test.ts diff --git a/tests/e2e/tls.test.ts b/packages/cli/tests/e2e/tls.test.ts similarity index 100% rename from tests/e2e/tls.test.ts rename to packages/cli/tests/e2e/tls.test.ts diff --git a/tests/e2e/trees.test.ts b/packages/cli/tests/e2e/trees.test.ts similarity index 100% rename from tests/e2e/trees.test.ts rename to packages/cli/tests/e2e/trees.test.ts diff --git a/tests/e2e/trees.ts b/packages/cli/tests/e2e/trees.ts similarity index 100% rename from tests/e2e/trees.ts rename to packages/cli/tests/e2e/trees.ts diff --git a/packages/cli/tests/helpers.ts b/packages/cli/tests/helpers.ts new file mode 100644 index 0000000..96b4473 --- /dev/null +++ b/packages/cli/tests/helpers.ts @@ -0,0 +1,41 @@ +import { mock, spyOn } from "bun:test"; + +export * from "../../core/tests/helpers"; + +/** + * One @clack/prompts mock for every test file. Bun's mock.module is global to + * the test run, so files that mocked different subsets would depend on load order. + */ +export const clackMock = { + progress: mock(() => ({ + start: mock(() => {}), + advance: mock(() => {}), + stop: mock(() => {}), + })), + log: { + info: mock(() => {}), + success: mock(() => {}), + step: mock(() => {}), + warn: mock(() => {}), + error: mock(() => {}), + }, +}; + +export function resetClackMock() { + clackMock.progress.mockClear(); + for (const fn of Object.values(clackMock.log)) fn.mockClear(); +} + +/** Silences console.log/error; returns the spies and a `restore` to call in afterEach. */ +export function silenceConsole() { + const log = spyOn(console, "log").mockImplementation(() => {}); + const error = spyOn(console, "error").mockImplementation(() => {}); + return { + log, + error, + restore() { + log.mockRestore(); + error.mockRestore(); + }, + }; +} diff --git a/tests/integration.ts b/packages/cli/tests/integration.ts similarity index 100% rename from tests/integration.ts rename to packages/cli/tests/integration.ts diff --git a/tests/main.test.ts b/packages/cli/tests/main.test.ts similarity index 98% rename from tests/main.test.ts rename to packages/cli/tests/main.test.ts index 9b17939..9410b92 100644 --- a/tests/main.test.ts +++ b/packages/cli/tests/main.test.ts @@ -1,10 +1,11 @@ import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test"; -import type { CompressOptions } from "../src/compress"; -import { CliError } from "../src/errors"; -import type { ResolvedFile } from "../src/files"; +import type { CompressOptions } from "@tinify/core/compress"; +import { CliError } from "@tinify/core/errors"; +import type { ResolvedFile } from "@tinify/core/files"; +import type { CompressedRecord } from "@tinify/core/record"; + import { type Deps, run } from "../src/index"; -import type { CompressedRecord } from "../src/record"; import { mockUI, setEnv, silenceConsole } from "./helpers"; function makeDeps(overrides: Partial = {}): Deps { diff --git a/tests/register.test.ts b/packages/cli/tests/register.test.ts similarity index 100% rename from tests/register.test.ts rename to packages/cli/tests/register.test.ts diff --git a/tests/ui.test.ts b/packages/cli/tests/ui.test.ts similarity index 99% rename from tests/ui.test.ts rename to packages/cli/tests/ui.test.ts index 41c393b..5d13a3c 100644 --- a/tests/ui.test.ts +++ b/packages/cli/tests/ui.test.ts @@ -5,11 +5,12 @@ import { clackMock, IS_WINDOWS, resetClackMock, silenceConsole } from "./helpers mock.module("@clack/prompts", () => clackMock); -import type { CompressResult, FileFailure, SkippedFile, SkipReason } from "../src/compress"; -import { CliError } from "../src/errors"; -import { parseOutputTarget } from "../src/output"; +import type { CompressResult, FileFailure, SkippedFile, SkipReason } from "@tinify/core/compress"; +import { CliError } from "@tinify/core/errors"; +import { parseOutputTarget } from "@tinify/core/output"; +import * as writeFile from "@tinify/core/write-file"; + import { createUI, formatResultLine, isTTY, summaryMessage } from "../src/ui"; -import * as writeFile from "../src/write-file"; const inPlace = parseOutputTarget(undefined); const toS3 = parseOutputTarget("s3://bucket/"); diff --git a/packages/cli/version.txt b/packages/cli/version.txt new file mode 100644 index 0000000..3eefcb9 --- /dev/null +++ b/packages/cli/version.txt @@ -0,0 +1 @@ +1.0.0 diff --git a/packages/core/package.json b/packages/core/package.json new file mode 100644 index 0000000..82b0818 --- /dev/null +++ b/packages/core/package.json @@ -0,0 +1,12 @@ +{ + "name": "@tinify/core", + "private": true, + "license": "MIT", + "type": "module", + "exports": { + "./*": "./src/*.ts" + }, + "dependencies": { + "tinify": "^2.0.0" + } +} diff --git a/src/bytes.ts b/packages/core/src/bytes.ts similarity index 100% rename from src/bytes.ts rename to packages/core/src/bytes.ts diff --git a/src/compress.ts b/packages/core/src/compress.ts similarity index 97% rename from src/compress.ts rename to packages/core/src/compress.ts index fca8b3a..c22cd29 100644 --- a/src/compress.ts +++ b/packages/core/src/compress.ts @@ -32,7 +32,6 @@ import { import { type CompressedRecord, type RecordQuery, sha256 } from "./record"; import type { ResizeOptions } from "./resize"; import { type S3Credentials, s3Credentials } from "./s3"; -import type { UI } from "./ui"; import { checkFileWritable, checkFolderWritable, writeInPlace, writeNew } from "./write-file"; export interface CompressOptions { @@ -59,6 +58,26 @@ export interface CompressOptions { concurrency?: number; } +export type SummaryOptions = Pick; + +/** How compressFiles reports its progress, and the rest of tinify its messages. */ +export interface UI { + start(fileCount: number): void; + onFileComplete(result: CompressResult): void; + /** `filePath` is in full, as in the failure. */ + onFileError(filePath: string, error: Error): void; + /** An image left as it is, decided before its upload. */ + onFileSkipped(skip: SkippedFile): void; + /** + * Shows the summary, written whole before it resolves, unless `stop` is aborted + * meanwhile: tinify is being stopped, so what isn't written yet is given up. + */ + finish(summary: CompressSummary, options: SummaryOptions, stop?: AbortSignal): Promise; + error(message: string): void; + warn(message: string): void; + verbose(message: string): void; +} + /** Mirrors the Tinify API response shape, plus path metadata for CLI use. */ export interface CompressResult { input: { size: number; type: string }; diff --git a/src/config.ts b/packages/core/src/config.ts similarity index 100% rename from src/config.ts rename to packages/core/src/config.ts diff --git a/src/endpoint.ts b/packages/core/src/endpoint.ts similarity index 100% rename from src/endpoint.ts rename to packages/core/src/endpoint.ts diff --git a/src/errors.ts b/packages/core/src/errors.ts similarity index 100% rename from src/errors.ts rename to packages/core/src/errors.ts diff --git a/src/files.ts b/packages/core/src/files.ts similarity index 100% rename from src/files.ts rename to packages/core/src/files.ts diff --git a/src/formats.ts b/packages/core/src/formats.ts similarity index 100% rename from src/formats.ts rename to packages/core/src/formats.ts diff --git a/src/output.ts b/packages/core/src/output.ts similarity index 100% rename from src/output.ts rename to packages/core/src/output.ts diff --git a/src/record.ts b/packages/core/src/record.ts similarity index 100% rename from src/record.ts rename to packages/core/src/record.ts diff --git a/src/resize.ts b/packages/core/src/resize.ts similarity index 100% rename from src/resize.ts rename to packages/core/src/resize.ts diff --git a/src/s3.ts b/packages/core/src/s3.ts similarity index 100% rename from src/s3.ts rename to packages/core/src/s3.ts diff --git a/src/write-file.ts b/packages/core/src/write-file.ts similarity index 100% rename from src/write-file.ts rename to packages/core/src/write-file.ts diff --git a/tests/bytes.test.ts b/packages/core/tests/bytes.test.ts similarity index 100% rename from tests/bytes.test.ts rename to packages/core/tests/bytes.test.ts diff --git a/tests/compress.test.ts b/packages/core/tests/compress.test.ts similarity index 99% rename from tests/compress.test.ts rename to packages/core/tests/compress.test.ts index 1de8bd2..bbcfc43 100644 --- a/tests/compress.test.ts +++ b/packages/core/tests/compress.test.ts @@ -571,7 +571,7 @@ describe("writing the result", () => { expect(readFileSync(webp, "utf-8")).toBe("someone else's"); }); - // Windows ignores the read-only flag on folders; tests/e2e denies writes with an ACL there. + // Windows ignores the read-only flag on folders; the e2e tests deny writes with an ACL there. test.skipIf(IS_ROOT || IS_WINDOWS)( "a writable image in a read-only folder is compressed in place", async () => { @@ -653,7 +653,7 @@ describe("writing the result", () => { }); // Linux and macOS allow 255 bytes per name; Windows counts UTF-16 units, and its paths - // have limits of their own. tests/e2e covers long paths there. + // have limits of their own. The e2e tests cover long paths there. test.skipIf(IS_WINDOWS)( "a 255-byte name is compressed in place; a 254-byte .png converts to a 255-byte .webp", async () => { @@ -873,7 +873,7 @@ describe("dry run", () => { expect(t.default.fromFile).not.toHaveBeenCalled(); }); - // Windows ignores the read-only flag on folders; tests/e2e denies writes with an ACL there. + // Windows ignores the read-only flag on folders; the e2e tests deny writes with an ACL there. test.skipIf(IS_ROOT || IS_WINDOWS)("reports a folder that won't take results", async () => { const locked = join(dir, "locked"); const photo = imageFile(locked, "photo.png"); @@ -936,7 +936,7 @@ describe("local destination is checked before anything is uploaded", () => { expect(readFileSync(out, "utf-8")).toBe("not a folder"); }); - // Windows ignores the read-only flag on folders; tests/e2e denies writes with an ACL there. + // Windows ignores the read-only flag on folders; the e2e tests deny writes with an ACL there. test.skipIf(IS_ROOT || IS_WINDOWS)("--output folder isn't writable → CliError", async () => { const out = join(dir, "locked"); mkdirSync(out); diff --git a/tests/config.test.ts b/packages/core/tests/config.test.ts similarity index 97% rename from tests/config.test.ts rename to packages/core/tests/config.test.ts index 6c430b0..16d0583 100644 --- a/tests/config.test.ts +++ b/packages/core/tests/config.test.ts @@ -95,7 +95,7 @@ describe("setApiKey", () => { expect(await getApiKey(dir)).toBe("second-key"); }); - // Windows has no owner-only mode bits; tests/e2e checks the key is saved there. + // Windows has no owner-only mode bits; the e2e tests check the key is saved there. test.skipIf(IS_WINDOWS)("the key file and its folder are private to the owner", async () => { await setApiKey("secret", dir); expect(statSync(configFile(dir)).mode & 0o777).toBe(0o600); diff --git a/tests/endpoint.test.ts b/packages/core/tests/endpoint.test.ts similarity index 100% rename from tests/endpoint.test.ts rename to packages/core/tests/endpoint.test.ts diff --git a/tests/files.test.ts b/packages/core/tests/files.test.ts similarity index 100% rename from tests/files.test.ts rename to packages/core/tests/files.test.ts diff --git a/tests/formats.test.ts b/packages/core/tests/formats.test.ts similarity index 100% rename from tests/formats.test.ts rename to packages/core/tests/formats.test.ts diff --git a/tests/helpers.ts b/packages/core/tests/helpers.ts similarity index 76% rename from tests/helpers.ts rename to packages/core/tests/helpers.ts index fa3027b..23d3c5f 100644 --- a/tests/helpers.ts +++ b/packages/core/tests/helpers.ts @@ -1,4 +1,4 @@ -import { mock, spyOn } from "bun:test"; +import { mock } from "bun:test"; import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { dirname, join } from "node:path"; @@ -6,8 +6,8 @@ import { dirname, join } from "node:path"; // The real media type constants: mocking "tinify" doesn't reach this path. import Format from "tinify/lib/tinify/Format"; +import type { UI } from "../src/compress"; import type { ResolvedFile } from "../src/files"; -import type { UI } from "../src/ui"; /** Stand-ins for tinify's error classes, with the same hierarchy and `status` field. */ class TinifyError extends Error { @@ -60,30 +60,6 @@ export function makeTinifyMock() { }; } -/** - * One @clack/prompts mock for every test file. Bun's mock.module is global to - * the test run, so files that mocked different subsets would depend on load order. - */ -export const clackMock = { - progress: mock(() => ({ - start: mock(() => {}), - advance: mock(() => {}), - stop: mock(() => {}), - })), - log: { - info: mock(() => {}), - success: mock(() => {}), - step: mock(() => {}), - warn: mock(() => {}), - error: mock(() => {}), - }, -}; - -export function resetClackMock() { - clackMock.progress.mockClear(); - for (const fn of Object.values(clackMock.log)) fn.mockClear(); -} - /** Sets environment variables; the returned function restores them, deleting any that were unset. */ export function setEnv(vars: Record): () => void { const saved = Object.fromEntries(Object.keys(vars).map((k) => [k, process.env[k]])); @@ -99,20 +75,6 @@ function applyEnv(values: Record) { } } -/** Silences console.log/error; returns the spies and a `restore` to call in afterEach. */ -export function silenceConsole() { - const log = spyOn(console, "log").mockImplementation(() => {}); - const error = spyOn(console, "error").mockImplementation(() => {}); - return { - log, - error, - restore() { - log.mockRestore(); - error.mockRestore(); - }, - }; -} - export const IS_WINDOWS = process.platform === "win32"; export const IS_ROOT = process.getuid?.() === 0; diff --git a/tests/output.test.ts b/packages/core/tests/output.test.ts similarity index 100% rename from tests/output.test.ts rename to packages/core/tests/output.test.ts diff --git a/tests/record.test.ts b/packages/core/tests/record.test.ts similarity index 100% rename from tests/record.test.ts rename to packages/core/tests/record.test.ts diff --git a/tests/resize.test.ts b/packages/core/tests/resize.test.ts similarity index 100% rename from tests/resize.test.ts rename to packages/core/tests/resize.test.ts diff --git a/tests/s3.test.ts b/packages/core/tests/s3.test.ts similarity index 100% rename from tests/s3.test.ts rename to packages/core/tests/s3.test.ts diff --git a/tests/write-file.test.ts b/packages/core/tests/write-file.test.ts similarity index 98% rename from tests/write-file.test.ts rename to packages/core/tests/write-file.test.ts index c710135..ac131be 100644 --- a/tests/write-file.test.ts +++ b/packages/core/tests/write-file.test.ts @@ -92,7 +92,7 @@ describe("writeFileAtomic", () => { expect(readFileSync(path, "utf-8")).toBe("hello"); }); - // Windows has no mode bits beyond read-only; tests/e2e covers it there. + // Windows has no mode bits beyond read-only; the e2e tests cover it there. test.skipIf(IS_WINDOWS)("replaces an existing file, keeping its permissions", async () => { const path = join(dir, "img.png"); writeFileSync(path, "old"); @@ -120,7 +120,7 @@ describe("writeFileAtomic", () => { expect(readFileSync(target, "utf-8")).toBe("new"); }); - // Windows ignores the read-only flag on folders; tests/e2e denies writes with an ACL there. + // Windows ignores the read-only flag on folders; the e2e tests deny writes with an ACL there. test.skipIf(IS_ROOT || IS_WINDOWS)( "a folder that won't take the temp file is refused, and the file left unchanged", async () => { @@ -358,7 +358,7 @@ describe("checkFolderWritable", () => { expect(err.code).toBe("ENOTDIR"); }); - // Windows ignores the read-only flag on folders; tests/e2e denies writes with an ACL there. + // Windows ignores the read-only flag on folders; the e2e tests deny writes with an ACL there. test.skipIf(IS_ROOT || IS_WINDOWS)("a 0555 folder is a FolderNotWritableError", async () => { const p = join(dir, "locked"); mkdirSync(p); diff --git a/release-please-config.json b/release-please-config.json deleted file mode 100644 index 0562345..0000000 --- a/release-please-config.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", - "packages": { - ".": { - "release-type": "node", - "include-component-in-tag": false, - "changelog-path": "CHANGELOG.md" - } - } -} diff --git a/release-please/cli-config.json b/release-please/cli-config.json new file mode 100644 index 0000000..080623a --- /dev/null +++ b/release-please/cli-config.json @@ -0,0 +1,26 @@ +{ + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "release-type": "simple", + "include-component-in-tag": true, + "separate-pull-requests": true, + "label": "autorelease: pending:cli", + "release-label": "autorelease: tagged:cli", + "draft": true, + "force-tag-creation": true, + "bootstrap-sha": "43d1ce7dc9fc9d643f5690dd80764e3de43cad5a", + "packages": { + ".": { + "component": "cli", + "exclude-paths": ["packages/mcp"], + "version-file": "packages/cli/version.txt", + "changelog-path": "packages/cli/CHANGELOG.md", + "extra-files": [ + { + "type": "json", + "path": "packages/cli/package.json", + "jsonpath": "$.version" + } + ] + } + } +} diff --git a/.release-please-manifest.json b/release-please/cli-manifest.json similarity index 100% rename from .release-please-manifest.json rename to release-please/cli-manifest.json diff --git a/tsconfig.json b/tsconfig.json index f25996d..ca77685 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,5 +19,5 @@ "noUnusedLocals": true, "noUnusedParameters": true }, - "include": ["src", "tests"] + "include": ["packages/*/src", "packages/*/tests"] }