Skip to content

Commit 521851c

Browse files
apply: review comments + docs update
1 parent b03d30c commit 521851c

File tree

4 files changed

+18
-28
lines changed

4 files changed

+18
-28
lines changed

DEVELOPER.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,29 @@ We use @testing-library/react for writing tests locally. This library helps mock
7272

7373
### Linking
7474

75-
We provide a `link` script to help you test in-development components within environments outside of Storybook. To do this, run:
75+
We provide a `link` script to help you test in-development components within environments outside of Storybook such as in your application. To do this, run:
7676

7777
```
7878
pnpm run link --to=[path-to-application]
7979
```
8080

81-
If you encounter issues while linking, try the following troubleshooting flags:
81+
The script does the following in order:
82+
83+
- It scans the destination application for any installed `leafygreen-ui` components in its `node_modules` folder.
84+
**NOTE:** If the package is new and unpublished/not installed, you will need to create a directory for the new component within the destination application inside `node_modules` before running this command.
85+
- If any `leafygreen-ui` components are found then:
86+
- The script runs `pnpm link` in the corresponding leafygreen-ui package directory to publish a link to the package in the pnpm global registry.
87+
- The script then runs `pnpm link <package-name>` in the destination application directory to install the package from the published link in the pnpm global registry.
88+
89+
After the script completes, you can make changes directly to the component in your local `leafygreen-ui` repository. Once you do this, make sure to rebuild the component and the changes will be visible on your running application.
90+
91+
If you encounter issues while linking, try the following any of the following flags:
8292

8393
- When linking multiple packages with `--scope` or multiple `--packages` options, link processes run in parallel by default. If you experience failures, add the `--no-parallel` flag to run the linking tasks sequentially, which can help avoid race conditions.
8494

8595
- If you are using a Node version manager such as `asdf` or `nvm`, add the `--launch-env="$(env)"` flag. This ensures the link script spawns commands using your current shell’s environment, preventing environment pollutions that may happen through the tooling of the version manager.
8696

87-
- In your external project, make sure your module resolver picks up `'react'` from your own `node_modules` (not from LeafyGreen’s). If using webpack, you can enforce this by adding an alias in your webpack configuration:
97+
- In your destination application project, make sure your module resolver picks up `'react'` from your own `node_modules` (not from LeafyGreen’s). If using webpack, you can enforce this by adding an alias in your webpack configuration:
8898

8999
```js
90100
resolve: {
@@ -94,8 +104,7 @@ If you encounter issues while linking, try the following troubleshooting flags:
94104
},
95105
```
96106

97-
Note: There are some known issues using `pnpm link` from pnpm workspaces. Using Verdaccio, while
98-
more involved, is the more reliable and recommended approach for testing in an external project.
107+
Note: There are some known issues in linking packages with `pnpm link`, if you encounter issues, try using a local registry instead. `Verdaccio` for example is a more reliable and recommended approach for testing in an external project.
99108

100109
### Using a local registry (Verdaccio)
101110

@@ -175,7 +184,7 @@ pnpm install @leafygreen-ui/<package-name>
175184

176185
#### 6. Publishing additional versions
177186

178-
To publish additional versions, manually the version number in `packages/<package-name>/package.json`, and re-run step 4. Then, either manually update the external project's `package.json`, or re-run `pnpm install @leafygreen-ui/<package-name>`.
187+
To publish additional versions, manually update the version number in `packages/<package-name>/package.json`, and re-run step 4. Then, either manually update the external project's `package.json`, or re-run `pnpm install @leafygreen-ui/<package-name>`.
179188

180189
#### 7. Publishing to NPM
181190

README.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -240,26 +240,7 @@ pnpm build --filter="[package]"
240240

241241
### Development within an Application
242242

243-
To actively develop `leafygreen-ui` components within an application, the following script will link all `leafygreen-ui` components within your application to the local `leafygreen-ui` repository.
244-
245-
This will allow you to make changes to your local repository of `leafygreen-ui` and see those changes immediately reflected within your running application. This allows you to develop both in isolation (within `leafygreen-ui`) and in the context of your application.
246-
247-
To do this, clone this repository and navigate to the root directory (where `package.json` is located), then run the following:
248-
249-
```
250-
pnpm run link -- ${PATH_TO_APPLICATION}
251-
```
252-
253-
The script does several things in order:
254-
255-
1. This builds every `leafygreen-ui` component so they are ready to be linked
256-
257-
2. It scans your application for any installed `leafygreen-ui` components in your `node_modules/@leafygreen-ui` folder.
258-
**NOTE:** If the package is new and unpublished/not installed, you will need to create a directory for the new component within your application inside `node_modules/@leafygreen-ui` before running this command.
259-
260-
3. If any `leafygreen-ui` components are found then the script uses `pnpm link` to link every `node_modules/@leafygreen-ui` module to your local `leafygreen-ui` repository.
261-
262-
After the script completes, you can make changes directly to the component in your local `leafygreen-ui` repository. Once you do this, run `pnpm build` in the root of the `leafygreen-ui` repository and the changes will be visible on your running application.
243+
To actively develop `leafygreen-ui` components within an application, we have a `link` script that will link all `leafygreen-ui` components within your application to the local `leafygreen-ui` repository. See the [DEVELOPER.md](./DEVELOPER.md) file for more information.
263244

264245
## Creating New Component
265246

tools/link/src/link.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function linkPackages(
3636
const keyValuePairs = launchEnvString
3737
.split('\n')
3838
.filter(line => line.trim() && line.includes('='))
39-
.map(line => line.trim().split(/=(.*)/));
39+
.map(line => line.trim().split(/=(.*)/).slice(0, 2));
4040
launchEnv = Object.fromEntries(keyValuePairs);
4141
}
4242

tools/link/src/utils/linkPackagesForScope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ export async function linkPackagesForScope(
118118

119119
await linkPackagesForScope(
120120
{ scopeName, scopePath },
121-
destination,
122121
source,
122+
destination,
123123
packages,
124124
verbose,
125125
parallel,

0 commit comments

Comments
 (0)