-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
269 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
releases: | ||
ts-overrides-plugin: minor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["@babel/preset-env", "@babel/preset-typescript"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# ts-overrides-plugin example | ||
|
||
Before all: | ||
|
||
```bash | ||
yarn ts-patch install | ||
``` | ||
|
||
Commands: | ||
|
||
```bash | ||
yarn build:tsc | ||
yarn build:ts-loader | ||
yarn build:fork-ts | ||
yarn watch:tsc | ||
yarn watch:ts-loader | ||
yarn watch:fork-ts | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "example-ts3", | ||
"scripts": { | ||
"build:tsc": "tsc", | ||
"build:ts-loader": "webpack --config webpack.config.ts-loader.js", | ||
"build:fork-ts": "webpack --config webpack.config.fork-ts.js", | ||
"watch:tsc": "tsc --watch", | ||
"watch:ts-loader": "webpack --config webpack.config.ts-loader.js --watch", | ||
"watch:fork-ts": "webpack --config webpack.config.fork-ts.js --watch", | ||
"prepare": "ts-patch install -s" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.23.6", | ||
"@babel/preset-env": "^7.23.6", | ||
"@babel/preset-typescript": "^7.23.3", | ||
"@types/babel__core": "^7", | ||
"@types/babel__preset-env": "^7", | ||
"babel-loader": "^9.1.3", | ||
"fork-ts-checker-webpack-plugin": "^9.0.2", | ||
"ts-loader": "^9.5.1", | ||
"ts-node": "^10.9.2", | ||
"ts-overrides-plugin": "workspce:*", | ||
"ts-patch": "1.4.5", | ||
"typescript": "3.9.10", | ||
"webpack": "^5.89.0", | ||
"webpack-cli": "^5.1.4" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { getDate as getDateLegacy } from './legacy/getDate'; | ||
import { getDate as getDateModern } from './modern/getDate'; | ||
|
||
console.log({ getDateLegacy, getDateModern }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// ok with strict: false | ||
export const getDate = (date) => { | ||
const modern: string | undefined = undefined; | ||
|
||
// ok with strict: false | ||
modern.split(''); | ||
|
||
return date.toLocaleDateString('ru-RU', { | ||
day: 'numeric', | ||
month: 'long', | ||
year: 'numeric', | ||
}); | ||
} | ||
|
||
// show `string` on hover in IDE | ||
export const someVar: string | undefined = undefined; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { someVar } from '../legacy/getDate'; | ||
|
||
// Parameter 'date' implicitly has an 'any' type. | ||
export const getDate = (date) => { | ||
const modern: string | undefined = undefined; | ||
|
||
// Show `string | undefined` on hover in IDE | ||
console.log(someVar); | ||
|
||
// 'modern' is possibly 'undefined' | ||
modern.split(''); | ||
|
||
return date.toLocaleDateString('ru-RU', { | ||
day: 'numeric', | ||
month: 'long', | ||
year: 'numeric', | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "ESNext", | ||
"outDir": "./dist", | ||
"baseUrl": "./src", | ||
"strict": false, | ||
"noEmit": false, | ||
"skipLibCheck": true, | ||
"typeRoots": [], // A hack to avoid global types that are incompatible with older versions of TS | ||
"plugins": [ | ||
{ | ||
"name": "ts-overrides-plugin", | ||
"transform": "ts-overrides-plugin", | ||
"transformProgram": true, | ||
"overrides": [ | ||
{ | ||
"files": ["src/modern/**/*.{ts,tsx}"], | ||
"compilerOptions": { | ||
"strict": true, | ||
}, | ||
}, | ||
] | ||
}, | ||
] | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const path = require('path'); | ||
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); | ||
|
||
module.exports = [ | ||
{ | ||
mode: 'production', | ||
entry: './src/index.ts', | ||
output: { | ||
path: path.join(__dirname, 'build'), | ||
filename: 'main.js', | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.ts$/, | ||
exclude: /node_modules/, | ||
loader: 'babel-loader', | ||
}, | ||
], | ||
}, | ||
plugins: [ | ||
new ForkTsCheckerWebpackPlugin(), | ||
], | ||
resolve: { | ||
extensions: ['.ts', '.js'], | ||
}, | ||
target: 'web', | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const path = require('path'); | ||
|
||
module.exports = [ | ||
{ | ||
mode: 'production', | ||
entry: './src/index.ts', | ||
output: { | ||
path: path.join(__dirname, 'build'), | ||
filename: 'main.js', | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.ts$/, | ||
exclude: /node_modules/, | ||
loader: 'ts-loader', | ||
}, | ||
], | ||
}, | ||
resolve: { | ||
extensions: ['.ts', '.js'], | ||
}, | ||
target: 'web', | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,8 @@ any other cases where you need to override the `tsconfig` settings for specific | |
## Installation and setup | ||
|
||
Examples can be seen in the [`example`](https://github.com/DiFuks/ts-overrides-plugin/tree/main/packages/example) folder. | ||
Specially for TS4, a separate [`example`](https://github.com/DiFuks/ts-overrides-plugin/tree/main/packages/example-ts4) folder. | ||
Specially for `TS4`, a separate [`example`](https://github.com/DiFuks/ts-overrides-plugin/tree/main/packages/example-ts4) folder. | ||
Specially for `TS3`, a separate [`example`](https://github.com/DiFuks/ts-overrides-plugin/tree/main/packages/example-ts3) folder. | ||
|
||
### For using the plugin only in the IDE | ||
|
||
|
@@ -76,7 +77,9 @@ For the plugin to work correctly in `webpack`, `tsc`, it's necessary to use the | |
Execute in the terminal: | ||
|
||
```bash | ||
yarn add -D ts-overrides-plugin ts-patch | ||
yarn add -D ts-overrides-plugin ts-patch # For TS5 | ||
yarn add -D ts-overrides-plugin [email protected] # For TS4 | ||
yarn add -D ts-overrides-plugin [email protected] # For TS3 | ||
``` | ||
|
||
In the `tsconfig.json` file, add: | ||
|
@@ -88,7 +91,7 @@ In the `tsconfig.json` file, add: | |
"plugins": [ | ||
{ | ||
"name": "ts-overrides-plugin", | ||
"transform": "ts-overrides-plugin/cli", | ||
"transform": "ts-overrides-plugin", | ||
"transformProgram": true, | ||
"overrides": [ | ||
{ | ||
|
@@ -112,12 +115,12 @@ In the `tsconfig.json` file, add: | |
``` | ||
|
||
If you are using [`Persistent Patch`](https://github.com/nonara/ts-patch?tab=readme-ov-file#method-2-persistent-patch) | ||
with `ts-patch`, then there is nothing more to do. | ||
with `ts-patch` (`yarn ts-patch install`), then there is nothing more to do. | ||
|
||
For TS4 version, it is possible to use only the Persistent Patch option with [ts-patch version 2.1.0](https://github.com/nonara/ts-patch/tree/v2.1.0). | ||
For `TypesSript 3` and `TypesSript 4` version, it is possible to use only the Persistent Patch option with. | ||
|
||
If, however, you are using [`Live Compiler`](https://github.com/nonara/ts-patch?tab=readme-ov-file#method-1-live-compiler), the | ||
following steps are necessary: | ||
If, however, you are using [`Live Compiler`](https://github.com/nonara/ts-patch?tab=readme-ov-file#method-1-live-compiler) (Only `TypeScript 5`, | ||
the following steps are necessary: | ||
|
||
For the `tsc` command – replace it with `tspc` in `package.json`: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-return,@typescript-eslint/no-explicit-any */ | ||
import type { ProgramTransformer } from 'ts-patch'; | ||
import type ts from 'typescript'; | ||
|
||
import cliPlugin from './cli'; | ||
import idePlugin from './ide'; | ||
|
||
type Plugin = { | ||
// For IDE plugins | ||
(...args: Parameters<ts.server.PluginModuleFactory>): ReturnType<ts.server.PluginModuleFactory>; | ||
// For CLI plugins | ||
(...args: Parameters<ProgramTransformer>): ReturnType<ProgramTransformer>; | ||
}; | ||
|
||
const plugin: Plugin = (...args: unknown[]) => { | ||
if (args.length === 1) { | ||
return idePlugin(...(args as Parameters<ts.server.PluginModuleFactory>)) as any; | ||
} | ||
|
||
return cliPlugin(...(args as Parameters<ProgramTransformer>)) as any; | ||
}; | ||
|
||
export = plugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters