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

feat: Add debug logs #344

Merged
merged 2 commits into from Dec 1, 2017
Merged

feat: Add debug logs #344

merged 2 commits into from Dec 1, 2017

Conversation

sudo-suhas
Copy link
Collaborator

@sudo-suhas sudo-suhas commented Nov 26, 2017

This integrates debug which can be enabled by setting the environment variable $DEBUG to lint-staged*. It can also be specified inline by doing the following:

# on *nix
$ DEBUG=lint-staged* git commit

# on Windows
λ set DEBUG=lint-staged* && git commit

Example output:

λ node . --debug
  lint-staged:bin Running `lint-staged@0.0.0-development` +0ms
  lint-staged Loading config using `cosmiconfig` +0ms
  lint-staged Successfully loaded config from `E:\Projects\repos\lint-staged\.lintstagedrc`:
  lint-staged { linters: { '*.js': [ 'eslint --fix', 'git add' ], '.*rc': 'jsonlint' } } +34ms
  lint-staged:cfg Normalizing config +0ms
  lint-staged:cfg Validating config +11ms
Running lint-staged with the following config:
{
  linters: {
    '*.js': [
      'eslint --fix',
      'git add'
    ],
    '.*rc': 'jsonlint'
  },
  concurrent: true,
  chunkSize: 9007199254740991,
  globOptions: {
    matchBase: true,
    dot: true
  },
  subTaskConcurrency: 1,
  renderer: 'verbose'
}
  lint-staged Loaded scripts from package.json:
  lint-staged { precommit: 'remove-lockfiles && node index.js',
  lint-staged   cz: 'git-cz',
  lint-staged   lint: 'eslint .',
  lint-staged   'lint:fix': 'npm run lint -- --fix',
  lint-staged   pretest: 'npm run lint',
  lint-staged   test: 'jest --coverage',
  lint-staged   'test:watch': 'jest --watch' } +80ms
  lint-staged:run Running all linter scripts +0ms
  lint-staged:run Resolved git directory to be `E:\Projects\repos\lint-staged` +4ms
  lint-staged:run Loaded list of staged files in git:
  lint-staged:run [ 'test/runScript.spec.js',
  lint-staged:run   'test/index.spec.js',
  lint-staged:run   'test/getConfig.spec.js',
  lint-staged:run   'test/findBin.spec.js',
  lint-staged:run   'test/__snapshots__/index.spec.js.snap',
  lint-staged:run   'test/__snapshots__/getConfig.spec.js.snap',
  lint-staged:run   'test/__mocks__/my-config.json',
  lint-staged:run   'src/runScript.js',
  lint-staged:run   'src/runAll.js',
  lint-staged:run   'src/index.js',
  lint-staged:run   'src/getConfig.js',
  lint-staged:run   'src/findBin.js',
  lint-staged:run   'index.js',
  lint-staged:run   'README.md' ] +205ms
  lint-staged:gen-tasks Generating linter tasks +0ms
  lint-staged:cfg Normalizing config +322ms
  lint-staged:gen-tasks Generated task:
  lint-staged:gen-tasks { pattern: '*.js',
  lint-staged:gen-tasks   commands: [ 'eslint --fix', 'git add' ],
  lint-staged:gen-tasks   fileList:
  lint-staged:gen-tasks    [ 'E:\\Projects\\repos\\lint-staged\\test\\runScript.spec.js',
  lint-staged:gen-tasks      'E:\\Projects\\repos\\lint-staged\\test\\index.spec.js',
  lint-staged:gen-tasks      'E:\\Projects\\repos\\lint-staged\\test\\getConfig.spec.js',
  lint-staged:gen-tasks      'E:\\Projects\\repos\\lint-staged\\test\\findBin.spec.js',
  lint-staged:gen-tasks      'E:\\Projects\\repos\\lint-staged\\src\\runScript.js',
  lint-staged:gen-tasks      'E:\\Projects\\repos\\lint-staged\\src\\runAll.js',
  lint-staged:gen-tasks      'E:\\Projects\\repos\\lint-staged\\src\\index.js',
  lint-staged:gen-tasks      'E:\\Projects\\repos\\lint-staged\\src\\getConfig.js',
  lint-staged:gen-tasks      'E:\\Projects\\repos\\lint-staged\\src\\findBin.js',
  lint-staged:gen-tasks      'E:\\Projects\\repos\\lint-staged\\index.js' ] } +25ms
  lint-staged:gen-tasks Generated task:
  lint-staged:gen-tasks { pattern: '.*rc', commands: 'jsonlint', fileList: [] } +41ms
Running tasks for *.js [started]
Running tasks for .*rc [started]
  lint-staged:run-script Running script with commands [ 'eslint --fix', 'git add' ] +0ms
  lint-staged:cfg Normalizing config +96ms
Running tasks for .*rc [skipped]
→ No staged files match .*rc
eslint --fix [started]
  lint-staged:find-bin Resolving binary for command `eslint --fix` +0ms
  lint-staged:find-bin Binary for `eslint --fix` resolved to `E:\Projects\repos\lint-staged\node_modules\.bin\eslint.CMD` +50ms
  lint-staged:run-script bin: E:\Projects\repos\lint-staged\node_modules\.bin\eslint.CMD +73ms
  lint-staged:run-script args: [ '--fix',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\test\\runScript.spec.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\test\\index.spec.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\test\\getConfig.spec.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\test\\findBin.spec.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\src\\runScript.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\src\\runAll.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\src\\index.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\src\\getConfig.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\src\\findBin.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\index.js' ] +3ms
  lint-staged:run-script opts: {} +28ms
eslint --fix [completed]
git add [started]
  lint-staged:find-bin Resolving binary for command `git add` +8s
  lint-staged:find-bin Binary for `git add` resolved to `C:\Program Files\Git\cmd\git.EXE` +62ms
  lint-staged:run-script bin: C:\Program Files\Git\cmd\git.EXE +8s
  lint-staged:run-script args: [ 'add',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\test\\runScript.spec.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\test\\index.spec.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\test\\getConfig.spec.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\test\\findBin.spec.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\src\\runScript.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\src\\runAll.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\src\\index.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\src\\getConfig.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\src\\findBin.js',
  lint-staged:run-script   'E:\\Projects\\repos\\lint-staged\\index.js' ] +2ms
  lint-staged:run-script opts: {} +25ms

Edit: Closes #319.

@codecov
Copy link

codecov bot commented Nov 26, 2017

Codecov Report

Merging #344 into master will increase coverage by 0.31%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #344      +/-   ##
=========================================
+ Coverage   97.79%   98.1%   +0.31%     
=========================================
  Files          10      10              
  Lines         181     211      +30     
  Branches       23      23              
=========================================
+ Hits          177     207      +30     
  Misses          4       4
Impacted Files Coverage Δ
src/getConfig.js 100% <100%> (ø) ⬆️
src/generateTasks.js 100% <100%> (ø) ⬆️
src/runAll.js 100% <100%> (ø) ⬆️
src/runScript.js 100% <100%> (ø) ⬆️
src/index.js 90.47% <100%> (+1.58%) ⬆️
src/findBin.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c22fbc2...b1a228f. Read the comment docs.

@okonet
Copy link
Collaborator

okonet commented Nov 27, 2017

@sudo-suhas this looks amazing. I'm wondering if we should close #319 in favor of this?

okonet
okonet previously approved these changes Nov 27, 2017
@sudo-suhas
Copy link
Collaborator Author

We could. I also felt that debug and verbose have some over lapping functionality. One thing which is missing here is the ability to enable debug logs using a command line flag. If we wanted to, we would need to modify process.env if the flag is present(I think). Thoughts?

@okonet
Copy link
Collaborator

okonet commented Nov 28, 2017

Overriding the process.env sounds legit to me in case if flag is present. Let's do that!

@sudo-suhas
Copy link
Collaborator Author

sudo-suhas commented Nov 28, 2017

Okay. Here's what I am going to do:

  • Remove verbose config option
  • Use --debug to override process.env and set config.renderer to verbose.

Let me know if you have any concerns or any suggestions.

- Parse command line option `--debug` and enable debug logs if it was passed.
- Propagate debug mode - `src/index.js -> runAll -> runScript -> findBin`.
- Set npm `--silent` flag using debug mode.
- Remove `verbose` from default config, add entry to deprecated options.
- Set `listr` renderer using debug mode.
- Tweak logs in `src/index.js` depending on debug mode.
- Update tests.
- Update readme, add section on command line flags.

BREAKING CHANGE: `verbose` config option has been deprecated and is superseded
by the command line option `--debug`.
@luftywiranda13
Copy link
Collaborator

what do you guys think about meow? I use it in some of my CLI projects and I love it

IMO it'll make our jobs easier here

@sudo-suhas
Copy link
Collaborator Author

I am not clear on how it is better. In any case, even if we do wish to switch to it, it probably shouldn't be a part of this PR.

@okonet
Copy link
Collaborator

okonet commented Nov 30, 2017

@sudo-suhas your plan sounds good to me! Please go ahead since I'll need this work in #75

@sudo-suhas
Copy link
Collaborator Author

@okonet This PR is ready for a review. I have done the changes we discussed in b1a228f.

@sudo-suhas
Copy link
Collaborator Author

Please note that I have marked it as a breaking change in the commit message. We should take care while squashing and merging.

@okonet
Copy link
Collaborator

okonet commented Nov 30, 2017

Looks good!

@okonet
Copy link
Collaborator

okonet commented Nov 30, 2017

Please merge it. I’m on my 📱

@sudo-suhas sudo-suhas merged commit 8f214f0 into master Dec 1, 2017
@sudo-suhas sudo-suhas deleted the feat/debug-logs branch December 1, 2017 04:27
@sudo-suhas
Copy link
Collaborator Author

Merged and release 🎉.

@okonet okonet mentioned this pull request Jan 21, 2018
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants