How could I change the name of my Yarn Workspace package?

5.3k views Asked by At

I starting with a yarn workspace that has packages that are already named. I'd like to change the name of one of the packages but have not been able to find the necessary procedure for doing this.

Here's the current structure of the file:

{
  "name": "gatsby-starter-theme-workspace",
  "private": true,
  "version": "0.0.1",
  "main": "index.js",
  "license": "0BSD",
  "scripts": {
    "build": "yarn workspace example build"
  },
  "workspaces": [
    "gatsby-theme-minimal",
    "example"
  ]
}

The workspace name that I'd like to change is gatsby-theme-minimal, I'd also like to know how I'd change the other one example when that becomes necessary, so advice on that would also be appreciated. I appreciate that this is probably a simple process but I am as yet unaware of how it is done.

1

There are 1 answers

3
Viktor Vlasenko On BEST ANSWER

There are two concepts that is used in your question.

  1. The directory name of the workspace. To change it just rename the directory and update workspaces field to refer to the new directory name
  2. The package name of the workspace - it is provided in package.json inside name field for the corresponding workspace. For gatsby-theme-minimal it is provided inside gatsby-theme-minimal/package.json -> name. Just edit package.json and change the name.

After making changes via 1) or 2) or both of them you need to run yarn in order for Yarn to update any installation files that refer to them. If you change workspace package name as per 2) you should also edit and update any code that requires/imports workspace by the old package name.