-
-
Notifications
You must be signed in to change notification settings - Fork 82
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: Use async and batch stage commands #151
Open
C-Hess
wants to merge
12
commits into
prettier:master
Choose a base branch
from
C-Hess:async-experiment
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e6ea9e5
Async experiment
BTCameronHessler bcb4e2d
Batch stage files
BTCameronHessler ccce74d
Update npm package to custom release
BTCameronHessler f614c97
Release stage multiple
BTCameronHessler f79f8f0
Merge branch 'experiment/stage-multiple-release' into async-expirement
BTCameronHessler 97adc00
Version bumb
BTCameronHessler 5a9e212
Fix async issues and leftover console logs
BTCameronHessler 8da2369
Fix stage issue caused by lack of await
BTCameronHessler 3c64578
Update verbiage
invalid-email-address 4435907
Revert package.json changes
invalid-email-address f0716bc
Fixed tests
invalid-email-address 06f0041
Delete package-lock.json
C-Hess File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,20 +1,33 @@ | ||
const path = require('path'); | ||
|
||
const resolveConfigMock = jest.fn().mockImplementation((file) => | ||
Promise.resolve({ | ||
file, | ||
}), | ||
); | ||
resolveConfigMock.sync = jest.fn().mockImplementation((file) => ({ file })); | ||
|
||
const getFileInfoMock = jest.fn().mockImplementation((file) => { | ||
const ext = path.extname(file); | ||
if (ext === '.js' || ext === '.md') { | ||
return Promise.resolve({ ignored: false, inferredParser: 'babel' }); | ||
} else { | ||
return Promise.resolve({ ignored: false, inferredParser: null }); | ||
} | ||
}); | ||
getFileInfoMock.sync = jest.fn().mockImplementation((file) => { | ||
const ext = path.extname(file); | ||
if (ext === '.js' || ext === '.md') { | ||
return { ignored: false, inferredParser: 'babel' }; | ||
} else { | ||
return { ignored: false, inferredParser: null }; | ||
} | ||
}); | ||
|
||
const prettierMock = { | ||
format: jest.fn().mockImplementation((input) => 'formatted:' + input), | ||
resolveConfig: { | ||
sync: jest.fn().mockImplementation((file) => ({ file })), | ||
}, | ||
getFileInfo: { | ||
sync: jest.fn().mockImplementation((file) => { | ||
const ext = path.extname(file); | ||
if (ext === '.js' || ext === '.md') { | ||
return { ignored: false, inferredParser: 'babel' }; | ||
} else { | ||
return { ignored: false, inferredParser: null }; | ||
} | ||
}), | ||
}, | ||
resolveConfig: resolveConfigMock, | ||
getFileInfo: getFileInfoMock, | ||
}; | ||
|
||
module.exports = prettierMock; |
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 |
---|---|---|
|
@@ -14,63 +14,74 @@ const args = mri(process.argv.slice(2), { | |
}, | ||
}); | ||
|
||
const prettyQuickResult = prettyQuick( | ||
process.cwd(), | ||
Object.assign({}, args, { | ||
onFoundSinceRevision: (scm, revision) => { | ||
console.log( | ||
`🔍 Finding changed files since ${chalk.bold( | ||
scm, | ||
)} revision ${chalk.bold(revision)}.`, | ||
); | ||
}, | ||
(async () => { | ||
const prettyQuickResult = await prettyQuick( | ||
process.cwd(), | ||
Object.assign({}, args, { | ||
onFoundSinceRevision: (scm, revision) => { | ||
console.log( | ||
`🔍 Finding changed files since ${chalk.bold( | ||
scm, | ||
)} revision ${chalk.bold(revision)}.`, | ||
); | ||
}, | ||
|
||
onFoundChangedFiles: (changedFiles) => { | ||
console.log( | ||
`🎯 Found ${chalk.bold(changedFiles.length)} changed ${ | ||
changedFiles.length === 1 ? 'file' : 'files' | ||
}.`, | ||
); | ||
}, | ||
onFoundChangedFiles: (changedFiles) => { | ||
console.log( | ||
`🎯 Found ${chalk.bold(changedFiles.length)} changed ${ | ||
changedFiles.length === 1 ? 'file' : 'files' | ||
}.`, | ||
); | ||
}, | ||
|
||
onPartiallyStagedFile: (file) => { | ||
console.log(`✗ Found ${chalk.bold('partially')} staged file ${file}.`); | ||
}, | ||
onPartiallyStagedFile: (file) => { | ||
console.log(`✗ Found ${chalk.bold('partially')} staged file ${file}.`); | ||
}, | ||
|
||
onWriteFile: (file) => { | ||
console.log(`✍️ Fixing up ${chalk.bold(file)}.`); | ||
}, | ||
onWriteFile: (file) => { | ||
console.log(`✍️ Fixing up ${chalk.bold(file)}.`); | ||
}, | ||
|
||
onCheckFile: (file, isFormatted) => { | ||
if (!isFormatted) { | ||
console.log(`⛔️ Check failed: ${chalk.bold(file)}`); | ||
} | ||
}, | ||
onCheckFile: (file, isFormatted) => { | ||
if (!isFormatted) { | ||
console.log(`⛔️ Check failed: ${chalk.bold(file)}`); | ||
} | ||
}, | ||
|
||
onExamineFile: (file) => { | ||
console.log(`🔍 Examining ${chalk.bold(file)}.`); | ||
}, | ||
}), | ||
); | ||
onExamineFile: (file) => { | ||
console.log(`🔍 Examining ${chalk.bold(file)}.`); | ||
}, | ||
|
||
if (prettyQuickResult.success) { | ||
console.log('✅ Everything is awesome!'); | ||
} else { | ||
if (prettyQuickResult.errors.indexOf('PARTIALLY_STAGED_FILE') !== -1) { | ||
console.log( | ||
'✗ Partially staged files were fixed up.' + | ||
` ${chalk.bold('Please update stage before committing')}.`, | ||
); | ||
} | ||
if (prettyQuickResult.errors.indexOf('BAIL_ON_WRITE') !== -1) { | ||
console.log( | ||
'✗ File had to be prettified and prettyQuick was set to bail mode.', | ||
); | ||
} | ||
if (prettyQuickResult.errors.indexOf('CHECK_FAILED') !== -1) { | ||
console.log( | ||
'✗ Code style issues found in the above file(s). Forgot to run Prettier?', | ||
); | ||
onStageFiles: () => { | ||
console.log(`🏗️ Staging changed files.`); | ||
}, | ||
}), | ||
); | ||
|
||
if (prettyQuickResult.success) { | ||
console.log('✅ Everything is awesome!'); | ||
} else { | ||
if (prettyQuickResult.errors.indexOf('PARTIALLY_STAGED_FILE') !== -1) { | ||
console.log( | ||
'✗ Partially staged files were fixed up.' + | ||
` ${chalk.bold('Please update stage before committing')}.`, | ||
); | ||
} | ||
if (prettyQuickResult.errors.indexOf('BAIL_ON_WRITE') !== -1) { | ||
console.log( | ||
'✗ File had to be prettified and prettyQuick was set to bail mode.', | ||
); | ||
} | ||
if (prettyQuickResult.errors.indexOf('CHECK_FAILED') !== -1) { | ||
console.log( | ||
'✗ Code style issues found in the above file(s). Forgot to run Prettier?', | ||
); | ||
} | ||
if (prettyQuickResult.errors.indexOf('STAGE_FAILED') !== -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New error state due to the introduction of the "staging" step |
||
console.log( | ||
'✗ Failed to stage some or all of the above file(s). Please stage changes made by Prettier before committing.', | ||
); | ||
} | ||
process.exit(1); // ensure git hooks abort | ||
} | ||
process.exit(1); // ensure git hooks abort | ||
} | ||
})(); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure this isn't actually used anymore? I think execa is mocked in every test using jest.mock anyways