You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Added new flags to `link` script to cover broader use cases:
7
+
-`--no-parallel`: Run the link command sequentially for each package. Useful for when the default parallel approach fails
8
+
-`--launch-env`: A string of environment variable lines as `KEY=VALUE`, separated by a newline. Only the specified environment variables will be used during npm link commands in the source and destination directories. This is useful to workaround environment variable pollution by tools such as version managers (e.g., asdf) or script runners (e.g., pnpm) that override the script's environment which impacts the launched `npm link` commands. We recommend using `--launch-env="$(env)"` to use your original shell environment.
9
+
- Improve documentation for linking in DEVELOPER.md
Copy file name to clipboardExpand all lines: DEVELOPER.md
+41-9Lines changed: 41 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,22 +68,54 @@ When you run the scaffold script, a `README` file will appear, which is a templa
68
68
69
69
### Locally
70
70
71
-
We use @testing-library/react for writing tests locally. This library helps mock out user interactions with components. You can run all tests by running `yarn test` or turn on watch mode with `yarn test --watch`.
71
+
We use @testing-library/react for writing tests locally. This library helps mock out user interactions with components. You can run all tests by running `pnpm test` or turn on watch mode with `pnpm test --watch`.
72
72
73
73
### Linking
74
74
75
-
We also have a link script, such that you can test components that are in development in environments beyond Storybook. To do so, run`yarn run link -- [path-to-application]`.
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:
76
76
77
-
Note: There are some known issues using `yarn link` from yarn workspaces. Using Verdaccio, while more involved, is the more reliable and recommended approach for testing in an external project.
77
+
```
78
+
pnpm run link --to=[path-to-application]
79
+
```
80
+
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:
92
+
93
+
- 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.
94
+
95
+
- 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.
96
+
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:
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.
78
108
79
109
### Using a local registry (Verdaccio)
80
110
81
-
Publishing test versions to a local registry can be helpful when you need to make changes and test in an external app (or other library). To do this, you can install and use [Verdaccio](https://verdaccio.org/)
111
+
Publishing test versions to a local registry can be helpful when you need to make changes and test
112
+
in an external app (or other library). To do this, you can install and
113
+
use [Verdaccio](https://verdaccio.org/)
82
114
83
115
#### 1. Install `verdaccio`
84
116
85
117
```bash
86
-
yarn install --global verdaccio
118
+
pnpm install --global verdaccio
87
119
```
88
120
89
121
#### 2. Start `verdaccio`, and make note on the localhost port (should be `http://localhost:4873/` by default)
@@ -147,23 +179,23 @@ With your local version published, open up some external app. If the app uses a
147
179
Next, install the newly published version of your package in the external project.
148
180
149
181
```bash
150
-
yarn install @leafygreen-ui/<package-name>
182
+
pnpm install @leafygreen-ui/<package-name>
151
183
```
152
184
153
185
#### 6. Publishing additional versions
154
186
155
-
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 `yarn 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>`.
156
188
157
189
#### 7. Publishing to NPM
158
190
159
191
If you want to stop publishing to and/or reading from your local Verdaccio server, remove the reference to the server URL in `~/.npmrc` (and the external project's local `.npmrc`/`.yarnrc`)
160
192
161
193
## Creating a new component
162
194
163
-
- Run `yarn create-package <package-name>` to create a new component directory with default configurations
195
+
- Run `pnpm create-package <package-name>` to create a new component directory with default configurations
164
196
- Add the new component to `build.tsconfig.json`
165
197
- If you are using any `leafygreen-ui` dependencies in your new component, add the dependency to the component directory's `tsconfig.json`.
166
-
- Run `yarn run init` to link all packages before starting development
198
+
- Run `pnpm run init` to link all packages before starting development
167
199
168
200
## Marking a Storybook story to be imported in mongodb.design
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.
Copy file name to clipboardExpand all lines: tools/cli/src/index.ts
+14-2Lines changed: 14 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -83,10 +83,22 @@ cli
83
83
'When running from a consuming application, defines the source of linked packages',
84
84
)
85
85
.option('-v --verbose','Prints additional information to the console',false)
86
-
.option('--scope <name>','The NPM organization')
86
+
.option(
87
+
'--no-parallel',
88
+
'Run the link command sequentially for each package. Useful for debugging or when the parallel approach fails',
89
+
)
90
+
.option(
91
+
'--launch-env <launchEnv>',
92
+
'A string of environment variable lines as `KEY=VALUE`, separated by a newline. '+
93
+
'Only the specified environment variables will be used during npm link commands in the source and destination directories. '+
94
+
'This is useful to workaround environment variable pollution by tools such as version managers (e.g., asdf) or script runners (e.g., pnpm) that interfere with `npm link`. '+
95
+
'We recommend using --launch-env="$(env)" to use your original shell environment.',
96
+
undefined,
97
+
)
98
+
.option('--scope <name>','The NPM organization, e.g. @lg-charts')
87
99
.option(
88
100
'--packages <names...>',
89
-
'Specific package names (requires `scope` option, or full package name)',
101
+
'Specific package names (requires `scope` option, or full package name) e.g. `@lg-charts/core` or `core` if @lg-charts is the scope',
0 commit comments