Skip to content

Commit

Permalink
TEC-1867 resolve package issues (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
patryk-w-bl authored Jan 16, 2025
1 parent d714181 commit fd8e7de
Show file tree
Hide file tree
Showing 33 changed files with 3,450 additions and 2,963 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "0.1.35",
"version": "0.1.39",
"npmClient": "yarn",
"useWorkspaces": true,
"stream": true
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ts-migrate",
"name": "@brightlocaldev/ts-migrate",
"version": "0.0.0",
"repository": {
"type": "git",
Expand Down Expand Up @@ -43,11 +43,13 @@
"prettier": "^2.6.2",
"react": "^16.12.0",
"rimraf": "^3.0.0",
"ts-jest": "^26.3.0",
"typescript": "4.7.2"
"ts-jest": "^26.3.0"
},
"workspaces": [
"packages/*"
],
"license": "MIT"
"license": "MIT",
"dependencies": {
"typescript": "4.7.2"
}
}
6 changes: 3 additions & 3 deletions packages/ts-migrate-example/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ts-migrate-example

`ts-migrate-example` is a basic example of usage of the [ts-migrate-server](https://github.com/airbnb/ts-migrate/tree/master/packages/ts-migrate-server) with writing a custom plugin.
`ts-migrate-example` is a basic example of usage of the [@brightlocaldev/ts-migrate-server](https://github.com/airbnb/ts-migrate/tree/master/packages/@brightlocaldev/ts-migrate-server) with writing a custom plugin.

### We have examples of the three categories of plugins:

Expand All @@ -14,15 +14,15 @@ We're using the following input:

```javascript
function mult(first, second) {
return first * second;
return first * second;
}
```

and with a [config of 3 simple plugins](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-example/src/index.ts#L18), produce the output:

```typescript
function tlum(tsrif: number, dnoces: number): number {
console.log(`args: ${arguments}`)
console.log(`args: ${arguments}`);
return tsrif * dnoces;
}
```
Expand Down
14 changes: 6 additions & 8 deletions packages/ts-migrate-example/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
{
"name": "ts-migrate-example",
"version": "0.1.35",
"name": "@brightlocaldev/ts-migrate-example",
"version": "0.1.39",
"private": "true",
"description": "Basic example of usage of the ts-migrate-server with writing a custom plugin",
"license": "MIT",
"scripts": {
"example": "ts-node -T -O '{ \"esModuleInterop\": true }' --skip-project src/index.ts"
},
"dependencies": {
"@brightlocaldev/ts-migrate-plugins": "^0.1.38",
"@brightlocaldev/ts-migrate-server": "^0.1.38",
"jscodeshift": "^0.12.0",
"ts-migrate-plugins": "^0.1.35",
"ts-migrate-server": "^0.1.33",
"ts-node": "^8.3.0"
},
"peerDependencies": {
"typescript": ">4.0"
"ts-node": "^8.3.0",
"typescript": "4.7.2"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import jscodeshift from 'jscodeshift';
import { Plugin } from 'ts-migrate-server';
import { Plugin } from '@brightlocaldev/ts-migrate-server';

type Options = {};

Expand Down
2 changes: 1 addition & 1 deletion packages/ts-migrate-example/src/example-plugin-text.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin } from 'ts-migrate-server';
import { Plugin } from '@brightlocaldev/ts-migrate-server';

type Options = {};

Expand Down
4 changes: 2 additions & 2 deletions packages/ts-migrate-example/src/example-plugin-ts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ts from 'typescript';
import { Plugin } from 'ts-migrate-server';
import { updateSourceText, SourceTextUpdate } from 'ts-migrate-plugins';
import { Plugin } from '@brightlocaldev/ts-migrate-server';
import { updateSourceText, SourceTextUpdate } from '@brightlocaldev/ts-migrate-plugins';

type Options = { shouldReplaceText?: boolean };

Expand Down
2 changes: 1 addition & 1 deletion packages/ts-migrate-example/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { migrate, MigrateConfig } from 'ts-migrate-server';
import { migrate, MigrateConfig } from '@brightlocaldev/ts-migrate-server';

import examplePluginTs from './example-plugin-ts';
import examplePluginText from './example-plugin-text';
Expand Down
59 changes: 26 additions & 33 deletions packages/ts-migrate-plugins/README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
# ts-migrate-plugins

*ts-migrate-plugins* is designed as a set of plugins, so that it can be pretty customizable for different use-cases.
_ts-migrate-plugins_ is designed as a set of plugins, so that it can be pretty customizable for different use-cases.
This package contains a set of [codemods](https://medium.com/@cpojer/effective-javascript-codemods-5a6686bb46fb) (plugins), which are doing transformation of js/jsx -> ts/tsx.

*ts-migrate-plugins* is designed around Airbnb projects. Use at your own risk.

_ts-migrate-plugins_ is designed around Airbnb projects. Use at your own risk.

# Install

Install *ts-migrate* using [npm](https://www.npmjs.com):
Install _ts-migrate_ using [npm](https://www.npmjs.com):

`npm install --save-dev ts-migrate-plugins`

Or [yarn](https://yarnpkg.com):

`yarn add --dev ts-migrate-plugins`


# Usage

```typescript
import path from 'path';
import { tsIgnorePlugin } from 'ts-migrate-plugins';
import { migrate, MigrateConfig } from 'ts-migrate-server';
import path from "path";
import { tsIgnorePlugin } from "ts-migrate-plugins";
import { migrate, MigrateConfig } from "@brightlocaldev/ts-migrate-server";

// get input files folder
const inputDir = path.resolve(__dirname, 'input');
const inputDir = path.resolve(__dirname, "input");

// create new migration config and add ts-ignore plugin with empty options
const config = new MigrateConfig().addPlugin(tsIgnorePlugin, {});
Expand All @@ -38,40 +36,38 @@ process.exit(exitCode);

# List of [plugins](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src)

| Name | Description |
| ---- | ----------- |
| [add-conversions](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/add-conversions.ts) | Add conversions to `any` (`$TSFixMe`) in the case of type errors. |
| [declare-missing-class-properties](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/declare-missing-class-properties.ts) | Declare missing class properties. |
| [eslint-fix](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/eslint-fix.ts) | Run eslint fix to fix any eslint violations that happened along the way. |
| [explicit-any](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/explicit-any.ts) | Annotate variables with `any` (`$TSFixMe`) in the case of an implicit any violation. |
| [hoist-class-statics](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/hoist-class-statics.ts) | Hoist static class members into the class body (vs. assigning them after the class definition). |
| [jsdoc](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/jsdoc.ts) | Convert JSDoc @param types to TypeScript annotations. |
| [member-accessibility](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/member-accessibility.ts) | Add accessibility modifiers (private, protected, or public) to class members according to naming conventions. |
| [react-class-lifecycle-methods](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/react-class-lifecycle-methods.ts) | Annotate React lifecycle method types. |
| [react-class-state](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/react-class-state.ts) | Declare React state type. |
| [react-default-props](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/react-default-props.ts) | Annotate React default props. |
| [react-props](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/react-props.ts) | Convert React prop types to TypeScript type. |
| [react-shape](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/react-shape.ts) | Convert prop types shapes to TypeScript type. |
| [strip-ts-ignore](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/strip-ts-ignore.ts) | Strip `// @ts-ignore`. comments |
| [ts-ignore](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/ts-ignore.ts) | Add `// @ts-ignore` comments for the remaining errors. |

| Name | Description |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| [add-conversions](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/add-conversions.ts) | Add conversions to `any` (`$TSFixMe`) in the case of type errors. |
| [declare-missing-class-properties](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/declare-missing-class-properties.ts) | Declare missing class properties. |
| [eslint-fix](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/eslint-fix.ts) | Run eslint fix to fix any eslint violations that happened along the way. |
| [explicit-any](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/explicit-any.ts) | Annotate variables with `any` (`$TSFixMe`) in the case of an implicit any violation. |
| [hoist-class-statics](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/hoist-class-statics.ts) | Hoist static class members into the class body (vs. assigning them after the class definition). |
| [jsdoc](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/jsdoc.ts) | Convert JSDoc @param types to TypeScript annotations. |
| [member-accessibility](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/member-accessibility.ts) | Add accessibility modifiers (private, protected, or public) to class members according to naming conventions. |
| [react-class-lifecycle-methods](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/react-class-lifecycle-methods.ts) | Annotate React lifecycle method types. |
| [react-class-state](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/react-class-state.ts) | Declare React state type. |
| [react-default-props](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/react-default-props.ts) | Annotate React default props. |
| [react-props](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/react-props.ts) | Convert React prop types to TypeScript type. |
| [react-shape](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/react-shape.ts) | Convert prop types shapes to TypeScript type. |
| [strip-ts-ignore](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/strip-ts-ignore.ts) | Strip `// @ts-ignore`. comments |
| [ts-ignore](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-plugins/src/plugins/ts-ignore.ts) | Add `// @ts-ignore` comments for the remaining errors. |

# Type of plugins

We have three main categories of plugins:

- Text based plugins. Plugins of this category are operating with a text of source files and operate based on this. Example: [example-plugin-text](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-example/src/example-plugin-text.ts).
- Text based plugins. Plugins of this category are operating with a text of source files and operate based on this. Example: [example-plugin-text](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-example/src/example-plugin-text.ts).

- Jscodeshift based plugins. These plugins are using a [jscodeshift toolkit](https://github.com/facebook/jscodeshift) as a base for operations and transformations around Abstract Syntax Tree. Example: [example-plugin-jscodeshift](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-example/src/example-plugin-jscodeshift.ts).

- TypeScript ast-based plugins. The main idea behind these plugins is by parsing Abstract Syntax Tree with [TypeScript compiler API](https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API), we can generate an array of updates for the text and apply them to the source file. Example: [example-plugin-ts](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-example/src/example-plugin-ts.ts).


# FAQ

> What is the ts-migrate plugin?
The plugin is an abstraction around codemods which provides centralized interfaces for the *ts-migrate*. Plugins should implement the following interface:
The plugin is an abstraction around codemods which provides centralized interfaces for the _ts-migrate_. Plugins should implement the following interface:

```typescript
interface Plugin {
Expand All @@ -89,18 +85,15 @@ interface PluginParams<TPluginOptions = {}> {
}
```


> How I can write my own plugin?
You can take a look into the [plugin examples](https://github.com/airbnb/ts-migrate/blob/master/packages/ts-migrate-example/src).
For more information, please check the [plugins implementation](https://github.com/airbnb/ts-migrate/tree/master/packages/ts-migrate-plugins/src/plugins) for the *ts-migrate*.

For more information, please check the [plugins implementation](https://github.com/airbnb/ts-migrate/tree/master/packages/ts-migrate-plugins/src/plugins) for the _ts-migrate_.

> I have an issue with a specific plugin, what should I do?
Please file an [issue here](https://github.com/airbnb/ts-migrate/issues/new).


# Contributing

See the [Contributors Guide](https://github.com/airbnb/ts-migrate/blob/master/CONTRIBUTING.md).
10 changes: 4 additions & 6 deletions packages/ts-migrate-plugins/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-migrate-plugins",
"version": "0.1.35",
"name": "@brightlocaldev/ts-migrate-plugins",
"version": "0.1.38",
"description": "Set of codemods, which are doing transformation of js/jsx to ts/tsx",
"main": "build/src/index.js",
"directories": {
Expand Down Expand Up @@ -59,18 +59,16 @@
"homepage": "https://github.com/airbnb/ts-migrate#readme",
"license": "MIT",
"dependencies": {
"@brightlocaldev/ts-migrate-server": "^0.1.38",
"eslint": "^7.14.0",
"jscodeshift": "^0.13.0",
"json-schema": "^0.4.0",
"ts-migrate-server": "^0.1.33"
"typescript": "4.7.2"
},
"gitHead": "7acf6067f15c9bb367cda9c47fcfb4203dcc54f3",
"devDependencies": {
"@ts-morph/bootstrap": "^0.16.0",
"@types/json-schema": "^7.0.7",
"jest": "26.6.3"
},
"peerDependencies": {
"typescript": ">4.0"
}
}
2 changes: 1 addition & 1 deletion packages/ts-migrate-plugins/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin as PluginType } from 'ts-migrate-server';
import { Plugin as PluginType } from '@brightlocaldev/ts-migrate-server';
import addConversionsPlugin from './plugins/add-conversions';
import declareMissingClassPropertiesPlugin from './plugins/declare-missing-class-properties';
import eslintFixPlugin from './plugins/eslint-fix';
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-migrate-plugins/src/plugins/add-conversions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ts from 'typescript';
import { Plugin } from 'ts-migrate-server';
import { Plugin } from '@brightlocaldev/ts-migrate-server';
import { isDiagnosticWithLinePosition } from '../utils/type-guards';
import getTokenAtPosition from './utils/token-pos';
import { AnyAliasOptions, validateAnyAliasOptions } from '../utils/validateOptions';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import jscodeshift, { ASTPath, ClassBody } from 'jscodeshift';
import { Plugin } from 'ts-migrate-server';
import { Plugin } from '@brightlocaldev/ts-migrate-server';
import { isDiagnosticWithLinePosition } from '../utils/type-guards';
import { AnyAliasOptions, validateAnyAliasOptions } from '../utils/validateOptions';

Expand Down
2 changes: 1 addition & 1 deletion packages/ts-migrate-plugins/src/plugins/eslint-fix.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ESLint } from 'eslint';
import { Plugin } from 'ts-migrate-server';
import { Plugin } from '@brightlocaldev/ts-migrate-server';

const cli = new ESLint({
fix: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-migrate-plugins/src/plugins/explicit-any.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import jscodeshift, { Identifier, TSTypeAnnotation } from 'jscodeshift';
import { Collection } from 'jscodeshift/src/Collection';
import ts from 'typescript';
import { Plugin } from 'ts-migrate-server';
import { Plugin } from '@brightlocaldev/ts-migrate-server';
import { isDiagnosticWithLinePosition } from '../utils/type-guards';
import { AnyAliasOptions, validateAnyAliasOptions } from '../utils/validateOptions';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-use-before-define, @typescript-eslint/no-use-before-define */
import ts from 'typescript';
import { Plugin } from 'ts-migrate-server';
import { Plugin } from '@brightlocaldev/ts-migrate-server';
import updateSourceText, { SourceTextUpdate } from '../utils/updateSourceText';
import {
findKnownImports,
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-migrate-plugins/src/plugins/jsdoc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-bitwise */
import ts from 'typescript';
import { Plugin } from 'ts-migrate-server';
import { Plugin } from '@brightlocaldev/ts-migrate-server';
import {
AnyAliasOptions,
Properties,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-bitwise */
import ts from 'typescript';
import { Plugin, PluginOptionsError } from 'ts-migrate-server';
import { Plugin, PluginOptionsError } from '@brightlocaldev/ts-migrate-server';

import { Properties, validateOptions } from '../utils/validateOptions';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ts from 'typescript';
import { Plugin } from 'ts-migrate-server';
import { Plugin } from '@brightlocaldev/ts-migrate-server';
import { getReactComponentHeritageType, isReactClassComponent } from './utils/react';
import updateSourceText, { SourceTextUpdate } from '../utils/updateSourceText';
import { createValidate, Properties } from '../utils/validateOptions';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ts from 'typescript';
import { Plugin } from 'ts-migrate-server';
import { Plugin } from '@brightlocaldev/ts-migrate-server';
import {
isReactClassComponent,
getReactComponentHeritageType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ts from 'typescript';
import { Plugin } from 'ts-migrate-server';
import { Plugin } from '@brightlocaldev/ts-migrate-server';
import updateSourceText, { SourceTextUpdate } from '../utils/updateSourceText';
import { createValidate, Properties } from '../utils/validateOptions';

Expand Down
2 changes: 1 addition & 1 deletion packages/ts-migrate-plugins/src/plugins/react-props.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-restricted-syntax, no-use-before-define, @typescript-eslint/no-use-before-define */
import ts from 'typescript';
import { Plugin } from 'ts-migrate-server';
import { Plugin } from '@brightlocaldev/ts-migrate-server';
import {
isReactClassComponent,
getReactComponentHeritageType,
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-migrate-plugins/src/plugins/react-shape.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-restricted-syntax, no-use-before-define, @typescript-eslint/no-use-before-define */
import ts from 'typescript';
import path from 'path';
import { Plugin } from 'ts-migrate-server';
import { Plugin } from '@brightlocaldev/ts-migrate-server';
import getTypeFromPropTypesObjectLiteral from './utils/react-props';
import updateSourceText, { SourceTextUpdate } from '../utils/updateSourceText';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-migrate-plugins/src/plugins/strip-ts-ignore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-use-before-define, @typescript-eslint/no-use-before-define */
import ts from 'typescript';
import { Plugin } from 'ts-migrate-server';
import { Plugin } from '@brightlocaldev/ts-migrate-server';
import updateSourceText, { SourceTextUpdate } from '../utils/updateSourceText';

const stripTSIgnorePlugin: Plugin = {
Expand Down
Loading

0 comments on commit fd8e7de

Please sign in to comment.