Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip .d.ts files in the migration CLI #777

Merged
merged 4 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions packages/connect-migrate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,52 @@

This tool updates your Connect project to use the new `@connectrpc` packages.

Usage:

## Usage

To migrate, run the following command in your project root directory:

```shell
npx @connectrpc/connect-migrate --help
npx @connectrpc/connect-migrate
```

Add the `--help` flag to the command to learn more about the available flags.


## What it does

This package is made up of a few migration steps

1. Updates `package.json` files to point to the new `@connectrpc` organization
1. Updates references to these packages in any javascript/typescript files
1. Runs the appropriate install command for your package manager
1. Updates references to these packages in JavaScript and TypeScript files
1. Runs the appropriate `install` command for your package manager

## What files are changed

We ignore all files within node_modules but will update any other files that end with the following extensions: .ts, .tsx, .js, .jsx, .cjs, mjs.
We ignore all files within `node_modules` but will update any other files that
end with the following extensions: `.ts`, `.tsx`, `.js`, `.jsx`, `.cjs`, `.mjs`.


## Prerequisites

- Make sure that you have updated to the latest version of `@bufbuild/connect` and
related packages before you migrate.
- Commit any unstaged changes to your project, so that you can revert in case the migration failed.
- After migration, run your generate scripts to re-generate code with the latest
plugin versions.


## Alternative running methods

This tool leverages jscodeshift in order to find all references to packages and update them. As a result, we've assumed a parser to parser your javascript/typescript files. If you see errors due to parsing,
you may be using a custom babel config or another custom parser. You can work around this while leveraging
our transforms by calling jscodeshift directly.
This tool leverages jscodeshift in order to find all references to packages and
update them. As a result, we've assumed a parser to parse your JavaScript/TypeScript
files. If you see errors due to parsing, you may be using a custom babel config
or another custom parser. You can work around this while leveraging our
transforms by calling `jscodeshift` directly.

```shell
npx jscodeshift -t ./node_modules/@connectrpc/connect-migrate/dist/cjs/transforms/modify-imports.js .
```

And add any additional params you feel are necessary. You can find more information about jscodeshift [here](https://github.com/facebook/jscodeshift/blob/main/README.md#usage-cli)
And add any additional params you feel are necessary. You can find more
information about `jscodeshift` [here](https://github.com/facebook/jscodeshift/blob/main/README.md#usage-cli).
7 changes: 4 additions & 3 deletions packages/connect-migrate/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ import {
import { Logger } from "./log";
import modifyImports from "./transforms/modify-imports";

const usage = `USAGE: connect-migrate
const usage = `USAGE: connect-migrate [flags]
Updates references to connect-es packages in your project to use @connectrpc.

Options:
--version Print the version of connect-migrate.
Flags:
--ignore-pattern <pattern> Glob pattern to ignore source and package files. Defaults to **/dist/**. Supports multiples.
--no-install Skip dependency installation after updating package.json files.
--version Print the version of connect-migrate.
--help Print this help.
`;

const logger = new Logger();
Expand Down
1 change: 1 addition & 0 deletions packages/connect-migrate/src/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function scan(ignorePatterns: string[], cwd: string, logger: Logger) {
...lockFilename.map((f) => `**/${f}`),
// source files
"**/*.ts",
"!**/*.d.ts",
"**/*.js",
"**/*.jsx",
"**/*.cjs",
Expand Down