Skip to content

Commit 5aeb696

Browse files
Fixes out of memory exception (#46)
* Fixes out of memory exception
1 parent 30716e9 commit 5aeb696

File tree

13 files changed

+1211
-9968
lines changed

13 files changed

+1211
-9968
lines changed

.eslintrc

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
{
22
"root": true,
33
"parser": "@typescript-eslint/parser",
4-
"plugins": [
5-
"@typescript-eslint"
6-
],
4+
"plugins": ["@typescript-eslint"],
75
"extends": [
86
"eslint:recommended",
97
"plugin:@typescript-eslint/eslint-recommended",
108
"plugin:@typescript-eslint/recommended"
119
],
1210
"rules": {
11+
"@typescript-eslint/no-unused-vars": "error",
1312
"@typescript-eslint/explicit-module-boundary-types": "off",
1413
"@typescript-eslint/ban-ts-comment": "warn"
1514
}

.github/workflows/ci.yml

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
name: CI
22

3-
on:
4-
[pull_request]
3+
on: [pull_request]
54

65
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Use Node.js 14.x
11+
uses: actions/setup-node@v2
12+
with:
13+
node-version: '14.x'
14+
- run: npm i
15+
- run: npm run lint
16+
- run: npm run prettier:ci
17+
718
build:
819
runs-on: ${{ matrix.os }}
920
strategy:

CHANGELOG.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project
66
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.0.2] - 2022-07-28
9+
10+
### Fixed
11+
12+
- Incorrect handling of out of memory exception
13+
814
## [2.0.1] - 2022-07-28
915

1016
### Fixed
@@ -14,16 +20,18 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1420
## [2.0.0] - 2021-29-11
1521

1622
### Changed
23+
1724
- Strict by default without `@ts-strict` comment
1825
- Ignores file with `@ts-strict-ignore` comment
19-
- Migration tool `update-strict-comments` which updates comments in files which contain at least 1 strict error
26+
- Migration tool `update-strict-comments` which updates comments in files which contain at least 1
27+
strict error
2028
- Fixes error when `pretty: true` option was set in `tsconfig.json`
21-
- Adds a cache to compilation for `tsc-strict` process resulting in
22-
50% speedup
29+
- Adds a cache to compilation for `tsc-strict` process resulting in 50% speedup
2330

2431
## [1.1.2] - 2021-06-15
2532

2633
### Added
34+
2735
- Rewrites some tests to `jest`
2836
- Adds feature to pass `tsc` parameters to `tsc-strict` command
2937

README.md

+67-22
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,38 @@
33
Typescript plugin that allows turning on strict mode in specific files or directories.
44

55
## Do I need this plugin?
6-
`typescript-strict-plugin` was created mainly for existing projects that want to incorporate typescript strict mode, but project is so big that refactoring everything would take ages.
76

7+
`typescript-strict-plugin` was created mainly for existing projects that want to incorporate
8+
typescript strict mode, but project is so big that refactoring everything would take ages.
89

9-
Our plugin allows adding strict mode to a TypeScript project without fixing all the errors at once. By adding `//@ts-strict-ignore` comment at the top of a file, its whole content will be removed from strict type checking. To ease migrating a project to use this plugin, you can use `update-strict-comments` script, which adds the ignore comment to all files that contain at least one strict error.
10-
11-
12-
TypeScript plugins don't work at compile-time. They will show errors in your IDE, but they won't appear during compilation.
13-
To check strict errors in marked files you can use `tsc-strict` script. This command line tool is created to check for files that should be checked with strict rules in compilation time.
14-
It finds all relevant files and checks for strict typescript errors only for that files.
15-
Therefore, we have strict errors inside our files and during build time.
10+
Our plugin allows adding strict mode to a TypeScript project without fixing all the errors at once.
11+
By adding `//@ts-strict-ignore` comment at the top of a file, its whole content will be removed from
12+
strict type checking. To ease migrating a project to use this plugin, you can use
13+
`update-strict-comments` script, which adds the ignore comment to all files that contain at least
14+
one strict error.
1615

16+
TypeScript plugins don't work at compile-time. They will show errors in your IDE, but they won't
17+
appear during compilation. To check strict errors in marked files you can use `tsc-strict` script.
18+
This command line tool is created to check for files that should be checked with strict rules in
19+
compilation time. It finds all relevant files and checks for strict typescript errors only for that
20+
files. Therefore, we have strict errors inside our files and during build time.
1721

1822
## How to install
1923

20-
Use `npm`:
24+
Use `npm`:
25+
2126
```bash
2227
npm i --save-dev typescript-strict-plugin
2328
```
24-
or yarn
29+
30+
or yarn
31+
2532
```bash
2633
yarn add -D typescript-strict-plugin
2734
```
35+
2836
add plugin to your `tsconfig.json`:
37+
2938
```json
3039
{
3140
"compilerOptions": {
@@ -39,14 +48,22 @@ add plugin to your `tsconfig.json`:
3948
}
4049
}
4150
```
51+
4252
and run the migration script
53+
4354
```
4455
update-strict-comments
4556
```
46-
That's it! You should be able to see strict typechecking in files without the `@ts-strict-ignore` comment. To make these files strict too, just remove its' ignore comments.
57+
58+
That's it! You should be able to see strict typechecking in files without the `@ts-strict-ignore`
59+
comment. To make these files strict too, just remove its' ignore comments.
4760

4861
## Configuration
49-
Plugin takes one extra non-mandatory argument `paths` that is an array of relative or absolute paths of directories that should be included. To add strict mode to files from ignored paths you can insert `//@ts-strict` comment.
62+
63+
Plugin takes one extra non-mandatory argument `paths` that is an array of relative or absolute paths
64+
of directories that should be included. To add strict mode to files from ignored paths you can
65+
insert `//@ts-strict` comment.
66+
5067
```json
5168
{
5269
"compilerOptions": {
@@ -64,9 +81,11 @@ Plugin takes one extra non-mandatory argument `paths` that is an array of relati
6481
}
6582
}
6683
```
84+
6785
All files contained in those paths will be strictly checked. Yay!
6886

6987
To add cli tool to your build time you can add a script to scripts list in package.json
88+
7089
```json
7190
{
7291
"scripts": {
@@ -76,55 +95,81 @@ To add cli tool to your build time you can add a script to scripts list in packa
7695
}
7796
```
7897

79-
Then you can simply run
98+
Then you can simply run
99+
80100
```shell
81101
yarn tsc-strict
82102
```
83103

84104
All your strict files should be checked from command line.
85105

86106
You can also pass some `tsc` arguments to the `tsc-strict` to override default compiler options e.g.
107+
87108
```shell
88109
yarn tsc-strict --strictNullChecks false
89110
```
90-
would not check for the strict null check in your files. The `tsc-strict` accepts all the arguments that regular `tsc` command
91-
accepts.
111+
112+
would not check for the strict null check in your files. The `tsc-strict` accepts all the arguments
113+
that regular `tsc` command accepts.
92114

93115
## Migrating to v2
94-
Because of difficulties with migrating large projects to strict mode with original `//@ts-strict` comment, we've taken an another approach. Now in version 2.0+ typescript files are strict by default, and to ignore a file, you can use special `//@ts-strict-ignore` comment. It allows to have strict mode in newly created files without remembering about adding strict comment at the top of it. Version 2.0 comes with a new script `update-strict-comments`, which detects all files with at least one strict error and adds the ignore comment to ease the migration. To update from v1 to v2, you just need to run:
116+
117+
Because of difficulties with migrating large projects to strict mode with original `//@ts-strict`
118+
comment, we've taken an another approach. Now in version 2.0+ typescript files are strict by
119+
default, and to ignore a file, you can use special `//@ts-strict-ignore` comment. It allows to have
120+
strict mode in newly created files without remembering about adding strict comment at the top of it.
121+
Version 2.0 comes with a new script `update-strict-comments`, which detects all files with at least
122+
one strict error and adds the ignore comment to ease the migration. To update from v1 to v2, you
123+
just need to run:
124+
95125
```
96126
update-strict-comments
97127
```
128+
98129
## VSCode support
99-
VSCode supports this plugin out of the box. However, sometimes it can use its own typescript version instead of the project one, resulting in not reading the local tsconfig. If you are using VSCode be sure to have `Use workspace version` option selected in `Typescript: Select Typescript Version...` command available in the [command pallete](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette).
100130

131+
VSCode supports this plugin out of the box. However, sometimes it can use its own typescript version
132+
instead of the project one, resulting in not reading the local tsconfig. If you are using VSCode be
133+
sure to have `Use workspace version` option selected in `Typescript: Select Typescript Version...`
134+
command available in the
135+
[command pallete](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette).
101136

102137
<img width="729" alt="image" src="https://user-images.githubusercontent.com/35625949/153884371-e0f488d4-05b8-4b88-93d2-1caa7e6081f7.png">
103138

104-
105139
## Testing the plugin
140+
106141
### Manually
142+
107143
run
144+
108145
```bash
109146
npm i
110147
```
111-
inside root folder and `sample-project` folder and then run
148+
149+
inside root folder and `sample-project` folder and then run
150+
112151
```bash
113152
npm run build
114153
```
154+
115155
or
156+
116157
```bash
117158
npm run dev
118159
```
119-
and restart typescript service inside `sample-project`. Files in `sample-project` folder should use a local plugin.
120-
After you made changes to a plugin you should probably restart typescript service in order to reload the plugin.
160+
161+
and restart typescript service inside `sample-project`. Files in `sample-project` folder should use
162+
a local plugin. After you made changes to a plugin you should probably restart typescript service in
163+
order to reload the plugin.
121164

122165
### Tests
123-
In order to run tests run
166+
167+
In order to run tests run
124168

125169
```bash
126170
npm run test
127171
```
128172

129173
## Contributing
174+
130175
Feel free to create PR's and issues.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"typescript.tsdk": "node_modules/typescript/lib"
3-
}
3+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"typescript.tsdk": "node_modules/typescript/lib"
3-
}
3+
}

e2e/fixtures/path-config/tsconfig.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
"plugins": [
1212
{
1313
"name": "../../dist/plugin",
14-
"paths": [
15-
"./included"
16-
]
14+
"paths": ["./included"]
1715
}
1816
]
1917
}

e2e/tsc-strict/tsc-strict.spec.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import execa from 'execa';
22
import { join } from 'path';
33
import { fixtureWithDefaultConfig, fixtureWithPathConfig } from '../fixtures/paths';
44

5-
const runInPath = async (path: string, args: string[] = []): Promise<string> => {
5+
const runInPath = async (
6+
path: string,
7+
args: string[] = [],
8+
envArgs: Record<string, string> = {},
9+
): Promise<string> => {
610
const cwd = process.cwd();
711
const cli = join(cwd, 'dist/cli/tsc-strict/index.js');
812

@@ -12,6 +16,7 @@ const runInPath = async (path: string, args: string[] = []): Promise<string> =>
1216
//the assertions break in an environment that supports color
1317
//override chalk color detection https://github.com/chalk/supports-color/blob/master/index.js
1418
FORCE_COLOR: 'false',
19+
...envArgs,
1520
},
1621
})
1722
.then((response) => {
@@ -36,6 +41,20 @@ it('should detect strict file errors', async () => {
3641
expect(stdout).toMatch(/Found 1 error/i);
3742
});
3843

44+
it('should detect heap out of memory exception', async () => {
45+
//given
46+
const { projectPath } = fixtureWithDefaultConfig;
47+
48+
// when
49+
const stdout = await runInPath(projectPath, [], {
50+
NODE_OPTIONS: '--max-old-space-size=20',
51+
});
52+
53+
// then
54+
expect(stdout).toMatch(/heap out of memory/i);
55+
expect(stdout).toMatch(/Typescript task was aborted. Full error log/i);
56+
});
57+
3958
it('should enable strict mode with a relative path config', async () => {
4059
//given
4160
const { projectPath, filePaths } = fixtureWithPathConfig;

package.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-strict-plugin",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "Typescript tools that help with migration to the strict mode",
55
"author": "Allegro",
66
"contributors": [
@@ -31,13 +31,19 @@
3131
],
3232
"scripts": {
3333
"test": "jest",
34+
"lint": "./node_modules/.bin/eslint './src/**/*.ts' --env jest --quiet",
35+
"prettier": "prettier --loglevel error --write .",
36+
"prettier:ci": "prettier --check .",
3437
"build": "tsc",
3538
"dev": "tsc --watch -p ."
3639
},
3740
"jest": {
3841
"preset": "ts-jest",
3942
"testTimeout": 10000,
40-
"roots": ["src", "e2e"]
43+
"roots": [
44+
"src",
45+
"e2e"
46+
]
4147
},
4248
"dependencies": {
4349
"chalk": "^3.0.0",

0 commit comments

Comments
 (0)