Skip to content

feat(pkg-manifest): add native set-script command with ss alias - #11504

Merged
zkochan merged 3 commits into
pnpm:mainfrom
kairosci:feat/set-script-pure
May 23, 2026
Merged

zkochan merged 3 commits into
pnpm:mainfrom
kairosci:feat/set-script-pure

Conversation

@kairosci

@kairosci kairosci commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Adds a native pnpm set-script <name> <command> (alias ss) implemented in @pnpm/pkg-manifest.commands, alongside the existing pnpm pkg command.

  • Removed from notImplemented.ts and registered in pnpm/src/cmd/index.ts.
  • Reads/writes via readProjectManifest, so package.json, package.json5, and package.yaml are all updated in place — no stray package.json is created next to an existing alternate manifest.
  • Shares the underlying writer (setObjectValueByPropertyPath) with pkg set, which inherits the prototype-pollution rejection for keys like __proto__.
  • Script names containing ., -, ", or = are all handled correctly.

Summary by CodeRabbit

  • New Features
    • Added native pnpm set-script command (alias ss) to update or create the scripts field in project manifests, supporting package.json, package.json5, and package.yaml formats.
  • Tests
    • Added test coverage for alias, creation, overwrite, argument handling, and unsafe-name rejection.
  • Documentation
    • Added release note documenting the minor version bump and new command.

Review Change Stack

Copilot AI review requested due to automatic review settings May 6, 2026 20:06
@kairosci
kairosci requested a review from zkochan as a code owner May 6, 2026 20:06
@coderabbitai

coderabbitai Bot commented May 6, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds a native pnpm set-script/ss command (CLI, handler, help text), a Jest test suite covering expected and negative cases, and a changeset announcing minor version bumps and multi-format manifest support.

Changes

Set-Script Command Release Note

Layer / File(s) Summary
Native set-script implementation announcement
.changeset/native-set-script-command.md
Changeset entry declares minor version bumps and documents the new native pnpm set-script command that modifies the scripts field in package.json, package.json5, and package.yaml.
CLI surface and option types
pkg-manifest/commands/src/setScript.ts
Exports CLI option typing and command names; dir is exposed as the option for the handler.
Command handler implementation
pkg-manifest/commands/src/setScript.ts
Handler validates args, reads project manifest, sets manifest.scripts[name] to the joined command string, persists the manifest, and throws a PnpmError with help hint on missing args.
Help text rendering
pkg-manifest/commands/src/setScript.ts
Adds help() which renders usage and includes the docs URL for set-script.
Test suite for set-script
pkg-manifest/commands/test/setScript.test.ts
Jest tests for alias ss, adding/overwriting scripts, argument joining, special-character script names, and negative cases for missing args and unsafe names.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

A rabbit hops to tweak the script,
ss whispers commands with a skip,
Manifests updated, tests in tow,
Bumps announced — now off we go! 🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a native set-script command with an ss alias to pnpm, which is directly reflected in the code changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
pkg/commands/src/setScript.ts (1)

21-27: ⚡ Quick win

Move help() below handler() to match the hoisting convention.

help() is currently declared before its call site; this file can follow the project’s “declare after use” pattern for consistency.

As per coding guidelines: "Declare functions after they are used, relying on hoisting".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/commands/src/setScript.ts` around lines 21 - 27, The help() function is
declared before its use; move its declaration below the handler() function to
follow the project's "declare after use" hoisting convention—locate the help()
export and cut/paste it so it appears after the handler() implementation (ensure
any imports it depends on remain accessible) so handler() calls resolve
correctly while preserving the same function body and export.
pkg/commands/test/setScript.ts (1)

7-34: ⚡ Quick win

Add a small test asserting the ss alias is exposed.

Since alias support is part of this PR’s objective, a focused assertion (e.g., expect(setScript.commandNames).toContain('ss')) would guard against regressions in command registration.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/commands/test/setScript.ts` around lines 7 - 34, Add an assertion that
the command alias `ss` is exposed by the setScript command: in the test file for
setScript (pkg/commands/test/setScript.ts) add a test or extend an existing test
to assert that setScript.commandNames includes 'ss' using
expect(setScript.commandNames).toContain('ss'); ensure you reference the
exported setScript symbol so the test fails if the alias is removed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pkg/commands/src/setScript.ts`:
- Around line 21-27: The help() function is declared before its use; move its
declaration below the handler() function to follow the project's "declare after
use" hoisting convention—locate the help() export and cut/paste it so it appears
after the handler() implementation (ensure any imports it depends on remain
accessible) so handler() calls resolve correctly while preserving the same
function body and export.

In `@pkg/commands/test/setScript.ts`:
- Around line 7-34: Add an assertion that the command alias `ss` is exposed by
the setScript command: in the test file for setScript
(pkg/commands/test/setScript.ts) add a test or extend an existing test to assert
that setScript.commandNames includes 'ss' using
expect(setScript.commandNames).toContain('ss'); ensure you reference the
exported setScript symbol so the test fails if the alias is removed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2690d8fe-470c-4fb2-8c35-d61513a330c4

📥 Commits

Reviewing files that changed from the base of the PR and between 6a5156b and 9df287e.

📒 Files selected for processing (4)
  • pkg/commands/package.json
  • pkg/commands/src/index.ts
  • pkg/commands/src/setScript.ts
  • pkg/commands/test/setScript.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new @pnpm/pkg.commands package that implements a native set-script command (with ss alias) intended to update the scripts field in a project manifest.

Changes:

  • Introduces set-script command implementation and help/options wiring in pkg/commands/src/setScript.ts.
  • Exports the new command from pkg/commands/src/index.ts.
  • Adds Jest tests covering add/update and missing-args behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
pkg/commands/src/setScript.ts Implements set-script/ss handler and help/options.
pkg/commands/src/index.ts Exposes setScript from the package entrypoint.
pkg/commands/test/setScript.ts Adds basic tests for adding/updating a script and missing args error.
pkg/commands/package.json Defines the new @pnpm/pkg.commands package, scripts, and deps.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/commands/src/setScript.ts Resolved
Comment thread pkg/commands/src/setScript.ts Resolved
Comment thread pkg/commands/src/setScript.ts Resolved
@kairosci

Copy link
Copy Markdown
Contributor Author

@zkochan could you take a look at it? Thanks

kairosci and others added 2 commits May 23, 2026 23:00
- Move set-script into @pnpm/pkg-manifest.commands (drops the orphan
  @pnpm/pkg.commands package; pkg/* is not in the workspace).
- Use readProjectManifest from @pnpm/cli.utils so package.json5 and
  package.yaml are updated in place instead of growing a stray
  package.json.
- Remove set-script from notImplemented and register the command in
  pnpm/src/cmd/index.ts.
- Cover the ss alias and the multi-word command path in tests.
Copilot AI review requested due to automatic review settings May 23, 2026 21:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Replace direct manifest.scripts mutation with
setObjectValueByPropertyPath - the same primitive pkg-set uses. Reuses
the prototype-pollution rejection for free and keeps the two commands
on the same write path. Avoids the pkg-set string-CLI's first-equals
key/value split, so script names containing '=' work too.
@zkochan zkochan changed the title feat(pkg): add native set-script command with ss alias feat(pkg-manifest): add native set-script command with ss alias May 23, 2026
@zkochan
zkochan merged commit d55263f into pnpm:main May 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants