Skip to content

Conversation

@funct7
Copy link
Contributor

@funct7 funct7 commented Jan 28, 2026

Related issues

Proposed Changes

  • Work around PM2 treating space-containing script paths as shell commands by linking the CLI child script to a space-free path before starting it.

Testing Instructions

    • Run studio site create from a path that includes spaces (e.g., “WP Studio.app”) and confirm the WordPress server starts.

Pre-merge Checklist

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

@funct7
Copy link
Contributor Author

funct7 commented Jan 28, 2026

I got the Studio app to run properly by applying this same change to {App}/Contents/Resources/cli/main.js.

@ivan-ottinger ivan-ottinger requested a review from a team January 28, 2026 13:44
@bcotrim
Copy link
Contributor

bcotrim commented Jan 28, 2026

Hey @funct7, welcome to the project and thanks for your first contribution! 🎉

Great find on the PM2 space-handling issue. Your analysis seems correct and PM2 incorrectly treats paths with spaces as shell commands.

Your fix looks good, but I'd suggest another approach: we already patch PM2 for type fixes (cli/patches/pm2+6.0.14.patch), so we can fix the root cause directly in lib/Common.js with a one-line change:

  // Line 726 - add fs.existsSync check:
  if (app.script && app.script.indexOf(' ') > -1 && cst.IS_WINDOWS === false && !fs.existsSync(app.script)) {

This way:

  • We fix PM2's bug at the source instead of working around it
  • No need for symlinks/copies at runtime
  • Any future scripts are automatically covered

Let me know if you'd like to update the PR with this approach or if you'd prefer I take it from here. Either way, thanks for tracking this down! 🙏

@funct7
Copy link
Contributor Author

funct7 commented Jan 28, 2026

@bcotrim It's probably best if you took over since you seem to know a lot more about the code base.
Let me know how to hand it over to you--close the PR, or change the assignee, etc.

The original symlink approach worked but required runtime file management.
This patches PM2's Common.js directly to check if the script file exists
before wrapping paths with spaces in bash -c.

Fixes Automattic#2482
@bcotrim
Copy link
Contributor

bcotrim commented Jan 29, 2026

Thanks for handing this over! I've pushed a commit that replaces the symlink approach with a PM2 patch.

The patch adds a fs.existsSync() check to PM2's Common.js so it only wraps paths in bash -c when the file doesn't exist (preserving the original shell command feature while fixing the spaced-path bug).

Tested manually by building the CLI, copying to /private/tmp/Studio Test App/ (path with spaces), and verifying site creation works. 🎉

@funct7
Copy link
Contributor Author

funct7 commented Jan 29, 2026

Looks good. Let me know if there's anything to be done on my part.

@funct7 funct7 removed their assignment Jan 29, 2026
Copy link
Contributor

@ivan-ottinger ivan-ottinger left a comment

Choose a reason for hiding this comment

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

The fix looks good and works as expected. 👍🏼 Here's the behavior before / after:

Before:

CleanShot.2026-01-29.at.13.23.04.mp4

After:

CleanShot.2026-01-29.at.13.16.46.mp4

@bcotrim bcotrim self-assigned this Jan 29, 2026
@bcotrim bcotrim merged commit 02283c1 into Automattic:trunk Jan 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Studio failing to start local server

3 participants