Skip to content

Commit

Permalink
Merge pull request #2 from ElonVolo/rxjs
Browse files Browse the repository at this point in the history
Adding support for logging rxjs pipe() stages
  • Loading branch information
ElonVolo authored Oct 9, 2020
2 parents 3f1bd6c + 8b9b54f commit f5902be
Show file tree
Hide file tree
Showing 12 changed files with 1,206 additions and 807 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,45 @@ Passing in the __--named-functions-only__ flag to logitall command limits loggin

This feature can be useful when you need an uncluttered, 50,000 ft view of what basic functions/methods are being called in your program.

#### rxjs support

logitall now has experimental support for adding logging statements to rxjs. When the --rxjs flag is passed to logitall, logging statements are inserted before and after each stage of an rxjs pipeline.

For example, the following code:

```
import { of, pipe } from 'rxjs';
import { map, filter } from 'rxjs/operators';
let myStream$ = of(7).pipe(
map(x => x + 1),
filter(x => x > 2)
);
```

is transformed into
```
import { of, pipe } from 'rxjs';
import { map, tap, filter } from 'rxjs/operators';
let myStream$ = of(7).pipe(tap(x => {
console.log(
`[logitall] Stage 0 value for rxjs pipe starting at line 4 in actual-rxjs-project/index.ts is:
${x}\n`
);
}), map(x => x + 1), tap(x => {
console.log(
`[logitall] Stage 1 value for rxjs pipe starting at line 4 in actual-rxjs-project/index.ts is:
${x}\n`
);
}), filter(x => x > 2), tap(x => {
console.log(
`[logitall] Final value for rxjs pipe starting at line 4 in actual-rxjs-project/index.ts is:
${x}\n`
);
}), );
```

#### Undoing logitall

* The best, most safest way to use logitall is to make a complete duplicate of your project folder and run logitall on a copy of your code.
Expand Down
7 changes: 7 additions & 0 deletions __testfixtures__/rxjs-basic-existing-tap-import.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { of, pipe } from 'rxjs';
import { map, tap, filter } from 'rxjs/operators';

let myStream$ = of(7).pipe(
map(x => x + 1),
filter(x => x > 2)
);
19 changes: 19 additions & 0 deletions __testfixtures__/rxjs-basic-existing-tap-import.output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { of, pipe } from 'rxjs';
import { map, tap, filter } from 'rxjs/operators';

let myStream$ = of(7).pipe(tap(x => {
console.log(
`[logitall] Stage 0 value for rxjs pipe starting at line 4 in __testfixtures__/rxjs-basic-existing-tap-import.input.ts is:
${x}\n`
);
}), map(x => x + 1), tap(x => {
console.log(
`[logitall] Stage 1 value for rxjs pipe starting at line 4 in __testfixtures__/rxjs-basic-existing-tap-import.input.ts is:
${x}\n`
);
}), filter(x => x > 2), tap(x => {
console.log(
`[logitall] Final value for rxjs pipe starting at line 4 in __testfixtures__/rxjs-basic-existing-tap-import.input.ts is:
${x}\n`
);
}), );
7 changes: 7 additions & 0 deletions __testfixtures__/rxjs-basic.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { of, pipe } from 'rxjs';
import { map, filter } from 'rxjs/operators';

let myStream$ = of(7).pipe(
map(x => x + 1),
filter(x => x > 2)
);
20 changes: 20 additions & 0 deletions __testfixtures__/rxjs-basic.output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { tap } from "rxjs/operators";
import { of, pipe } from 'rxjs';
import { map, filter } from 'rxjs/operators';

let myStream$ = of(7).pipe(tap(x => {
console.log(
`[logitall] Stage 0 value for rxjs pipe starting at line 4 in __testfixtures__/rxjs-basic.input.ts is:
${x}\n`
);
}), map(x => x + 1), tap(x => {
console.log(
`[logitall] Stage 1 value for rxjs pipe starting at line 4 in __testfixtures__/rxjs-basic.input.ts is:
${x}\n`
);
}), filter(x => x > 2), tap(x => {
console.log(
`[logitall] Final value for rxjs pipe starting at line 4 in __testfixtures__/rxjs-basic.input.ts is:
${x}\n`
);
}), );
7 changes: 7 additions & 0 deletions __testfixtures__/rxjs-internal-tap-import.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { of, pipe } from 'rxjs';
import { map, tap, filter } from 'rxjs/internal/operators';

let myStream$ = of(7).pipe(
map(x => x + 1),
filter(x => x > 2)
);
19 changes: 19 additions & 0 deletions __testfixtures__/rxjs-internal-tap-import.output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { of, pipe } from 'rxjs';
import { map, tap, filter } from 'rxjs/internal/operators';

let myStream$ = of(7).pipe(tap(x => {
console.log(
`[logitall] Stage 0 value for rxjs pipe starting at line 4 in __testfixtures__/rxjs-internal-tap-import.input.ts is:
${x}\n`
);
}), map(x => x + 1), tap(x => {
console.log(
`[logitall] Stage 1 value for rxjs pipe starting at line 4 in __testfixtures__/rxjs-internal-tap-import.input.ts is:
${x}\n`
);
}), filter(x => x > 2), tap(x => {
console.log(
`[logitall] Final value for rxjs pipe starting at line 4 in __testfixtures__/rxjs-internal-tap-import.input.ts is:
${x}\n`
);
}), );
3 changes: 3 additions & 0 deletions __tests__/transform-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ defineTest(__dirname + "../", 'transform', {'relpath': '__testfixtures__'}, 'met
defineTest(__dirname + "../", 'transform', {'relpath': '__testfixtures__'}, 'method-instance', { 'parser': 'ts' });
defineTest(__dirname + "../", 'transform', {'relpath': '__testfixtures__'}, 'method-static', { 'parser': 'ts' });
defineTest(__dirname + "../", 'transform', {'relpath': '__testfixtures__'}, 'statement-expression', { 'parser': 'ts' });
defineTest(__dirname + "../", 'transform', {'relpath': '__testfixtures__', 'rxjs' : true }, 'rxjs-basic', { 'parser': 'ts' });
defineTest(__dirname + "../", 'transform', {'relpath': '__testfixtures__', 'rxjs' : true }, 'rxjs-basic-existing-tap-import', { 'parser': 'ts' });
defineTest(__dirname + "../", 'transform', {'relpath': '__testfixtures__', 'rxjs' : true } , 'rxjs-internal-tap-import', { 'parser': 'ts' });
7 changes: 6 additions & 1 deletion bin/logitall.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ commander
.usage('(filepath | dirpath)')
.option('--ignore-config <configfile>', 'a .gitignore-style list of file patterns to ignore')
.option('--named-functions-only', 'only log non-anonymous functions and methods')
.option('--rxjs', 'support for adding logging to rxjs pipe stages')
.arguments('<filepath>')
.parse(process.argv)

Expand All @@ -35,7 +36,11 @@ if (commander.ignoreConfig) {
}

if (commander.namedFunctionsOnly) {
args.push('--named-functions-only')
args.push('--named-functions-only');
}

if (commander.rxjs) {
args.push('--rxjs');
}

args.push(`--relpath=${commander.args[2]}`);
Expand Down
Loading

0 comments on commit f5902be

Please sign in to comment.