Skip to content

Configure CLI build pipeline for npm publishing#2697

Open
ivan-ottinger wants to merge 2 commits intotrunkfrom
stu-1362-cli-npm-build-pipeline
Open

Configure CLI build pipeline for npm publishing#2697
ivan-ottinger wants to merge 2 commits intotrunkfrom
stu-1362-cli-npm-build-pipeline

Conversation

@ivan-ottinger
Copy link
Contributor

@ivan-ottinger ivan-ottinger commented Mar 3, 2026

Related issues

In this PR I am proposing to add a new CLI build - for now with manual package creation. As the next step I am planning to look into our organization npm access so we could manually publish it (privately-first) to npm under @automattic/studio-cli - if we agree on that name.

Then we can continue with making the publishing automated.

How AI was used in this PR

Claude Code implemented the plan from STU-1362 and iterated on build issues (externalized dependency resolution, shebang injection, ...) based on my feedback and manual testing. I have reviewed the whole generated code myself and with Copilot as well.

Proposed Changes

  • Rename CLI package to @automattic/studio-cli with version, bin, files, engines, and publishConfig fields for npm publishing
  • Add vite.config.npm.ts — a separate Vite config that externalizes all runtime dependencies (npm handles them) and adds a #!/usr/bin/env node shebang to the main entry point
  • Add scripts/postinstall-npm.mjs — prunes PHP WASM asyncify/web binaries and cross-platform fs-ext binaries after npm install (no-op in workspace context)
  • Update workspace references across root and studio app package.json files to use the new scoped package name
  • Add cli:build:npm root script for the npm build

Testing Instructions

  1. Verify the existing Electron build still works:
    npm run cli:build
    
  2. Verify the npm build works:
    npm run cli:build:npm
    
  3. Verify no node_modules/ in npm build output and shebang is present:
    ls apps/cli/dist/cli/node_modules  # should not exist
    head -1 apps/cli/dist/cli/main.js  # should be #!/usr/bin/env node
    
  4. Test end-to-end from a tarball:
    cd apps/cli && npm pack
    mkdir /tmp/test-studio-cli && cd /tmp/test-studio-cli
    npm init -y && npm install /path/to/automattic-studio-cli-0.1.0.tgz
    npx studio --version
    npx studio --help
    

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

Add a separate Vite config (vite.config.npm.ts) that externalizes all
runtime dependencies and adds a Node.js shebang, producing a standalone
CLI package publishable to npm as @automattic/studio-cli.

The existing Electron-bundled build (vite.config.ts) is unchanged.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR prepares the Studio CLI workspace package for publishing to npm under the new scoped name @automattic/studio-cli, including a dedicated npm-oriented build (externalized deps + shebang) and an npm-consumer postinstall pruning step.

Changes:

  • Renames the CLI workspace/package to @automattic/studio-cli and updates workspace script references.
  • Adds a dedicated vite.config.npm.ts build that externalizes runtime dependencies and prepends a Node shebang to main.js.
  • Adds an npm postinstall script to apply patches and prune large/unneeded binaries after install.

Reviewed changes

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

Show a summary per file
File Description
package.json Updates root scripts to reference the new scoped CLI workspace and adds cli:build:npm.
package-lock.json Reflects the CLI rename/versioning and dependency reshaping needed for npm publishing.
apps/studio/package.json Updates Studio app scripts to call the renamed CLI workspace.
apps/cli/vite.config.npm.ts Introduces npm-specific Vite build config (externalization + shebang injection + locales copy).
apps/cli/scripts/postinstall-npm.mjs Adds npm-consumer postinstall actions (patches + binary pruning).
apps/cli/package.json Updates CLI package metadata for npm publishing (name/version/bin/files/engines/scripts).

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

- Remove unused `main` field (CLI-only package)
- Include source maps in `files` whitelist
- Use `npx --no-install` for deterministic postinstall
@ivan-ottinger ivan-ottinger marked this pull request as ready for review March 3, 2026 15:21
@ivan-ottinger ivan-ottinger requested a review from a team March 3, 2026 15:22
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.

2 participants