Search code examples
node.jspnpm

pnpm deploy deleted my entire project, including .git losing all local changes


Background: I've been trying to Dockerize a monorepo using pnpm. During the process, I was working on trying some commands locally which weren't acting the way I expected in the Docker image. Because I didn't understand the pnpm deploy command well, I decided to try it locally.

When I ran pnpm deploy --filter=app --prod ., I soon realized that every file in my project, including files outside of the folder I was in (one of the workspaces of the monorepo) had been deleted. Seems like they've been hard-deleted, nothing in my trash, not sure where to look for them. The only things I have to rebuild from are the remote files (last checked in 2-3 days ago, not terrible but not great) and the in-memory files still in VS Code.

Two questions, I guess: 1) if anyone has any ideas on how to get these files back and 2) how to confidently run pnpm deploy locally in the near future, that would be appreciated. Fwiw, I tried running pnpm deploy in many other folders, and I continuously got errors like the following: ENOENT: no such file or directory, mkdir '/prod' so I tried to run in a folder that existed.


Solution

  • The . is the target directory for deploy – yeah, I suppose it would be prudent for pnpm to not allow trashing the source directory without some --force flag.

    Looking at the source for the deploy command, the directory is rimraf'd (rm -rf'd), and then recreated. That's rough. :( I created an issue in pnpm for this: https://github.com/pnpm/pnpm/issues/7351

    1. From backups and/or looking for "undelete" instructions for your file system, though the more time has passed since the files were yeeted, the lesser your chances of recovering them.
    2. That would probably depend on what you need pnpm deploy for in the first case, which isn't very clear from the question.