Created Updating code using legacy Fluid APIs (markdown)

Tyler Butler 2024-05-08 10:03:53 -07:00
Родитель ef734f12a2
Коммит 2b5007d2e5
1 изменённых файлов: 67 добавлений и 0 удалений

@ -0,0 +1,67 @@
## Background
Beginning with version 2.0.0-rc.3.0.0, Fluid Framework packages have narrowed the public API that is exposed via the default package entry point. This means that some existing code will need to be updated to import the APIs from the `./legacy` entry point.
For example, consider this import statement:
```ts
import { ContainerRuntime } from "@fluidframework/container-rutime";
```
In version 2.0.0-rc.3.0.0 and beyond, that import statement must be updated to be:
```ts
import { ContainerRuntime } from "@fluidframework/container-rutime/legacy";
```
The Fluid Framework provides a tool to automate the rewriting of imports in your source files. This command-line tool is distributed as part of the @fluid-tools/build-cli package.
## Installation
It's easiest to install the build-cli globally:
```shell
npm install --global @fluid-tools/build-cli@latest
OR
yarn install --global @fluid-tools/build-cli@latest
```
## Usage
Once installed, you can rewrite the imports for a project by running `flub modify fluid-imports` and pointing it to the tsconfig.json file for your project.
```shell
flub modify fluid-imports --tsconfig tsconfig.json
```
The flag defaults to `tsconfig.json` so it coule be omitted in the example above.
If you have multiple tsconfigs, for example a primary tsconfig and a test tsconfig, you can use the `--tsconfig` lag multiple times. For example:
```shell
flub modify fluid-imports --tsconfig tsconfig.json --tsconfig test/tsconfig.json
```
### Monorepo usage
Using `flub modify fluid-imports` in a monorepo is straightforward. At a high level, the process is: for each package in the monorepo, run `flub modify fluid-imports` pointing at the project's tsconfig.json file.
If a project has multiple tsconfigs, or if some projects in the monorepo use a different structure, you may need to manually run `flub modify fluid-imports` multiple times.
Most monorepo workspace managers have a way to execute a command for each package in the workspace. However, an alternative is to use [manypkg](https://github.com/Thinkmill/manypkg#manypkg-exec-cli-command), which understands yarn, pnpm, and npm workspaces. To use it, install the manypkg cli globally:
```
npm install --global @manypkg/cli
```
Once installed, you can run a command like the following from the root of your workdspace to update the imports for multiple projects:
```shell
manypkg exec flub modify fluid-imports --tsconfigs tsconfig.json
```
## Advanced options
You may want to update imports from only some Fluid Framework packages. To do this, use the `--packageRegex` flag. Only packages matching the expression will have their imports updated.