pretty-quick
Advanced tools
Comparing version 3.1.4 to 3.2.0
@@ -1,76 +0,3 @@ | ||
#!/usr/bin/env node | ||
// ! warning: this file is only here for compatibility, you should change to use `dist/cli.js` directly instead | ||
'use strict' | ||
const chalk = require('chalk') | ||
const mri = require('mri') | ||
const prettyQuick = require('..').default | ||
const args = mri(process.argv.slice(2), { | ||
alias: { | ||
'resolve-config': 'resolveConfig', | ||
'ignore-path': 'ignorePath', | ||
}, | ||
}) | ||
const prettyQuickResult = 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' | ||
}.`, | ||
) | ||
}, | ||
onPartiallyStagedFile: file => { | ||
console.log(`✗ Found ${chalk.bold('partially')} staged file ${file}.`) | ||
}, | ||
onWriteFile: file => { | ||
console.log(`✍️ Fixing up ${chalk.bold(file)}.`) | ||
}, | ||
onCheckFile: (file, isFormatted) => { | ||
if (!isFormatted) { | ||
console.log(`⛔️ Check failed: ${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?', | ||
) | ||
} | ||
process.exit(1) // ensure git hooks abort | ||
} | ||
module.exports = require('../dist/cli') |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _fs = require("fs"); | ||
var _path = require("path"); | ||
var _ignore = _interopRequireDefault(require("ignore")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _default = (directory, filename = '.prettierignore') => { | ||
const file = (0, _path.join)(directory, filename); | ||
if ((0, _fs.existsSync)(file)) { | ||
const text = (0, _fs.readFileSync)(file, 'utf8'); | ||
const filter = (0, _ignore.default)().add(text).createFilter(); | ||
return path => filter((0, _path.join)(path)); | ||
} | ||
return () => true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const fs_1 = (0, tslib_1.__importDefault)(require("fs")); | ||
const path_1 = (0, tslib_1.__importDefault)(require("path")); | ||
const ignore_1 = (0, tslib_1.__importDefault)(require("ignore")); | ||
exports.default = (directory, filename = '.prettierignore') => { | ||
const file = path_1.default.join(directory, filename); | ||
if (fs_1.default.existsSync(file)) { | ||
const text = fs_1.default.readFileSync(file, 'utf8'); | ||
const filter = (0, ignore_1.default)().add(text).createFilter(); | ||
return (filepath) => filter(path_1.default.join(filepath)); | ||
} | ||
return () => true; | ||
}; | ||
exports.default = _default; | ||
//# sourceMappingURL=createIgnorer.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _multimatch = _interopRequireDefault(require("multimatch")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const path = require('path'); | ||
var _default = pattern => { | ||
// Match everything if no pattern was given | ||
if (typeof pattern !== 'string' && !Array.isArray(pattern)) { | ||
return () => true; | ||
} | ||
const patterns = Array.isArray(pattern) ? pattern : [pattern]; | ||
return file => (0, _multimatch.default)(path.normalize(file), patterns, { | ||
dot: true | ||
}).length > 0; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const path_1 = (0, tslib_1.__importDefault)(require("path")); | ||
const multimatch_1 = (0, tslib_1.__importDefault)(require("multimatch")); | ||
exports.default = (pattern) => { | ||
if (typeof pattern !== 'string' && !Array.isArray(pattern)) { | ||
return () => true; | ||
} | ||
const patterns = Array.isArray(pattern) ? pattern : [pattern]; | ||
return (file) => (0, multimatch_1.default)(path_1.default.normalize(file), patterns, { dot: true }).length > 0; | ||
}; | ||
exports.default = _default; | ||
//# sourceMappingURL=createMatcher.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _scms = _interopRequireDefault(require("./scms")); | ||
var _processFiles = _interopRequireDefault(require("./processFiles")); | ||
var _createIgnorer = _interopRequireDefault(require("./createIgnorer")); | ||
var _createMatcher = _interopRequireDefault(require("./createMatcher")); | ||
var _isSupportedExtension = _interopRequireDefault(require("./isSupportedExtension")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _default = (currentDirectory, { | ||
config, | ||
since, | ||
staged, | ||
pattern, | ||
restage = true, | ||
branch, | ||
bail, | ||
check, | ||
ignorePath, | ||
verbose, | ||
onFoundSinceRevision, | ||
onFoundChangedFiles, | ||
onPartiallyStagedFile, | ||
onExamineFile, | ||
onCheckFile, | ||
onWriteFile, | ||
resolveConfig = true | ||
} = {}) => { | ||
const scm = (0, _scms.default)(currentDirectory); | ||
if (!scm) { | ||
throw new Error('Unable to detect a source control manager.'); | ||
} | ||
const directory = scm.rootDirectory; | ||
const revision = since || scm.getSinceRevision(directory, { | ||
staged, | ||
branch | ||
}); | ||
onFoundSinceRevision && onFoundSinceRevision(scm.name, revision); | ||
const rootIgnorer = (0, _createIgnorer.default)(directory, ignorePath); | ||
const cwdIgnorer = currentDirectory !== directory ? (0, _createIgnorer.default)(currentDirectory, ignorePath) : () => true; | ||
const changedFiles = scm.getChangedFiles(directory, revision, staged).filter((0, _createMatcher.default)(pattern)).filter(rootIgnorer).filter(cwdIgnorer).filter((0, _isSupportedExtension.default)(resolveConfig)); | ||
const unstagedFiles = staged ? scm.getUnstagedChangedFiles(directory, revision).filter(_isSupportedExtension.default).filter((0, _createMatcher.default)(pattern)).filter(rootIgnorer).filter(cwdIgnorer) : []; | ||
const wasFullyStaged = f => unstagedFiles.indexOf(f) < 0; | ||
onFoundChangedFiles && onFoundChangedFiles(changedFiles); | ||
const failReasons = new Set(); | ||
(0, _processFiles.default)(directory, changedFiles, { | ||
check, | ||
config, | ||
onWriteFile: file => { | ||
onWriteFile && onWriteFile(file); | ||
if (bail) { | ||
failReasons.add('BAIL_ON_WRITE'); | ||
} | ||
if (staged && restage) { | ||
if (wasFullyStaged(file)) { | ||
scm.stageFile(directory, file); | ||
} else { | ||
onPartiallyStagedFile && onPartiallyStagedFile(file); | ||
failReasons.add('PARTIALLY_STAGED_FILE'); | ||
} | ||
} | ||
}, | ||
onCheckFile: (file, isFormatted) => { | ||
onCheckFile && onCheckFile(file, isFormatted); | ||
if (!isFormatted) { | ||
failReasons.add('CHECK_FAILED'); | ||
} | ||
}, | ||
onExamineFile: verbose && onExamineFile | ||
}); | ||
return { | ||
success: failReasons.size === 0, | ||
errors: Array.from(failReasons) | ||
}; | ||
const tslib_1 = require("tslib"); | ||
const createIgnorer_1 = (0, tslib_1.__importDefault)(require("./createIgnorer")); | ||
const createMatcher_1 = (0, tslib_1.__importDefault)(require("./createMatcher")); | ||
const isSupportedExtension_1 = (0, tslib_1.__importDefault)(require("./isSupportedExtension")); | ||
const processFiles_1 = (0, tslib_1.__importDefault)(require("./processFiles")); | ||
const scms_1 = (0, tslib_1.__importDefault)(require("./scms")); | ||
module.exports = (currentDirectory, { config, since, staged, pattern, restage = true, branch, bail, check, ignorePath, verbose, onFoundSinceRevision, onFoundChangedFiles, onPartiallyStagedFile, onExamineFile, onCheckFile, onWriteFile, resolveConfig = true, } = {}) => { | ||
const scm = (0, scms_1.default)(currentDirectory); | ||
if (!scm) { | ||
throw new Error('Unable to detect a source control manager.'); | ||
} | ||
const directory = scm.rootDirectory; | ||
const revision = since || scm.getSinceRevision(directory, { staged, branch }); | ||
onFoundSinceRevision === null || onFoundSinceRevision === void 0 ? void 0 : onFoundSinceRevision(scm.name, revision); | ||
const rootIgnorer = (0, createIgnorer_1.default)(directory, ignorePath); | ||
const cwdIgnorer = currentDirectory === directory | ||
? () => true | ||
: (0, createIgnorer_1.default)(currentDirectory, ignorePath); | ||
const changedFiles = scm | ||
.getChangedFiles(directory, revision, staged) | ||
.filter((0, createMatcher_1.default)(pattern)) | ||
.filter(rootIgnorer) | ||
.filter(cwdIgnorer) | ||
.filter((0, isSupportedExtension_1.default)(resolveConfig)); | ||
const unstagedFiles = staged | ||
? scm | ||
.getUnstagedChangedFiles(directory, revision) | ||
.filter((0, isSupportedExtension_1.default)(resolveConfig)) | ||
.filter((0, createMatcher_1.default)(pattern)) | ||
.filter(rootIgnorer) | ||
.filter(cwdIgnorer) | ||
: []; | ||
const wasFullyStaged = (f) => !unstagedFiles.includes(f); | ||
onFoundChangedFiles === null || onFoundChangedFiles === void 0 ? void 0 : onFoundChangedFiles(changedFiles); | ||
const failReasons = new Set(); | ||
(0, processFiles_1.default)(directory, changedFiles, { | ||
check, | ||
config, | ||
onWriteFile(file) { | ||
onWriteFile === null || onWriteFile === void 0 ? void 0 : onWriteFile(file); | ||
if (bail) { | ||
failReasons.add('BAIL_ON_WRITE'); | ||
} | ||
if (staged && restage) { | ||
if (wasFullyStaged(file)) { | ||
scm.stageFile(directory, file); | ||
} | ||
else { | ||
onPartiallyStagedFile === null || onPartiallyStagedFile === void 0 ? void 0 : onPartiallyStagedFile(file); | ||
failReasons.add('PARTIALLY_STAGED_FILE'); | ||
} | ||
} | ||
}, | ||
onCheckFile: (file, isFormatted) => { | ||
onCheckFile === null || onCheckFile === void 0 ? void 0 : onCheckFile(file, isFormatted); | ||
if (!isFormatted) { | ||
failReasons.add('CHECK_FAILED'); | ||
} | ||
}, | ||
onExamineFile: verbose ? onExamineFile : undefined, | ||
}); | ||
return { | ||
success: failReasons.size === 0, | ||
errors: [...failReasons], | ||
}; | ||
}; | ||
exports.default = _default; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _prettier = require("prettier"); | ||
var _default = resolveConfig => file => Boolean(_prettier.getFileInfo.sync(file, { | ||
resolveConfig, | ||
..._prettier.resolveConfig.sync(file, { | ||
editorconfig: true | ||
}, { | ||
filepath: file | ||
}) | ||
}).inferredParser); | ||
exports.default = _default; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const prettier = (0, tslib_1.__importStar)(require("prettier")); | ||
exports.default = (resolveConfig) => (file) => { | ||
const config = prettier.resolveConfig.sync(file, { | ||
editorconfig: true, | ||
}); | ||
const fileInfo = prettier.getFileInfo.sync(file, Object.assign({ resolveConfig }, config)); | ||
return !!fileInfo.inferredParser; | ||
}; | ||
//# sourceMappingURL=isSupportedExtension.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _fs = require("fs"); | ||
var prettier = _interopRequireWildcard(require("prettier")); | ||
var _path = require("path"); | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
var _default = (directory, files, { | ||
check, | ||
config, | ||
onExamineFile, | ||
onCheckFile, | ||
onWriteFile | ||
} = {}) => { | ||
for (const relative of files) { | ||
onExamineFile && onExamineFile(relative); | ||
const file = (0, _path.join)(directory, relative); | ||
const options = Object.assign({}, prettier.resolveConfig.sync(file, { | ||
config, | ||
editorconfig: true | ||
}), { | ||
filepath: file | ||
}); | ||
const input = (0, _fs.readFileSync)(file, 'utf8'); | ||
if (check) { | ||
const isFormatted = prettier.check(input, options); | ||
onCheckFile && onCheckFile(relative, isFormatted); | ||
continue; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const fs_1 = (0, tslib_1.__importDefault)(require("fs")); | ||
const path_1 = (0, tslib_1.__importDefault)(require("path")); | ||
const prettier_1 = (0, tslib_1.__importDefault)(require("prettier")); | ||
exports.default = (directory, files, { check, config, onExamineFile, onCheckFile, onWriteFile, } = {}) => { | ||
for (const relative of files) { | ||
onExamineFile === null || onExamineFile === void 0 ? void 0 : onExamineFile(relative); | ||
const file = path_1.default.join(directory, relative); | ||
const options = Object.assign(Object.assign({}, prettier_1.default.resolveConfig.sync(file, { | ||
config, | ||
editorconfig: true, | ||
})), { filepath: file }); | ||
const input = fs_1.default.readFileSync(file, 'utf8'); | ||
if (check) { | ||
const isFormatted = prettier_1.default.check(input, options); | ||
onCheckFile === null || onCheckFile === void 0 ? void 0 : onCheckFile(relative, isFormatted); | ||
continue; | ||
} | ||
const output = prettier_1.default.format(input, options); | ||
if (output !== input) { | ||
fs_1.default.writeFileSync(file, output); | ||
onWriteFile === null || onWriteFile === void 0 ? void 0 : onWriteFile(relative); | ||
} | ||
} | ||
const output = prettier.format(input, options); | ||
if (output !== input) { | ||
(0, _fs.writeFileSync)(file, output); | ||
onWriteFile && onWriteFile(relative); | ||
} | ||
} | ||
}; | ||
exports.default = _default; | ||
//# sourceMappingURL=processFiles.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.stageFile = exports.name = exports.getUnstagedChangedFiles = exports.getSinceRevision = exports.getChangedFiles = exports.detect = void 0; | ||
var _findUp = _interopRequireDefault(require("find-up")); | ||
var _execa = _interopRequireDefault(require("execa")); | ||
var _path = require("path"); | ||
var fs = _interopRequireWildcard(require("fs")); | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const name = exports.name = 'git'; | ||
const detect = directory => { | ||
if (fs.existsSync((0, _path.join)(directory, '.git'))) { | ||
return directory; | ||
} | ||
const gitDirectory = _findUp.default.sync('.git', { | ||
cwd: directory, | ||
type: 'directory' | ||
}); | ||
if (gitDirectory) { | ||
return (0, _path.dirname)(gitDirectory); | ||
} | ||
const gitWorktreeFile = _findUp.default.sync('.git', { | ||
cwd: directory, | ||
type: 'file' | ||
}); | ||
if (gitWorktreeFile) { | ||
return (0, _path.dirname)(gitWorktreeFile); | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stageFile = exports.getUnstagedChangedFiles = exports.getChangedFiles = exports.getSinceRevision = exports.detect = exports.name = void 0; | ||
const tslib_1 = require("tslib"); | ||
const fs_1 = (0, tslib_1.__importDefault)(require("fs")); | ||
const path_1 = (0, tslib_1.__importDefault)(require("path")); | ||
const execa_1 = (0, tslib_1.__importDefault)(require("execa")); | ||
const find_up_1 = (0, tslib_1.__importDefault)(require("find-up")); | ||
exports.name = 'git'; | ||
const detect = (directory) => { | ||
if (fs_1.default.existsSync(path_1.default.join(directory, '.git'))) { | ||
return directory; | ||
} | ||
const gitDirectory = find_up_1.default.sync('.git', { | ||
cwd: directory, | ||
type: 'directory', | ||
}); | ||
if (gitDirectory) { | ||
return path_1.default.dirname(gitDirectory); | ||
} | ||
const gitWorkTreeFile = find_up_1.default.sync('.git', { | ||
cwd: directory, | ||
type: 'file', | ||
}); | ||
if (gitWorkTreeFile) { | ||
return path_1.default.dirname(gitWorkTreeFile); | ||
} | ||
}; | ||
exports.detect = detect; | ||
const runGit = (directory, args) => _execa.default.sync('git', args, { | ||
cwd: directory | ||
const runGit = (directory, args) => execa_1.default.sync('git', args, { | ||
cwd: directory, | ||
}); | ||
const getLines = execaResult => execaResult.stdout.split('\n'); | ||
const getSinceRevision = (directory, { | ||
staged, | ||
branch | ||
}) => { | ||
try { | ||
const revision = staged ? 'HEAD' : runGit(directory, ['merge-base', 'HEAD', branch || 'master']).stdout.trim(); | ||
return runGit(directory, ['rev-parse', '--short', revision]).stdout.trim(); | ||
} catch (error) { | ||
if (/HEAD/.test(error.message) || staged && /Needed a single revision/.test(error.message)) { | ||
return null; | ||
const getLines = (execaResult) => execaResult.stdout.split('\n'); | ||
const getSinceRevision = (directory, { staged, branch }) => { | ||
try { | ||
const revision = staged | ||
? 'HEAD' | ||
: runGit(directory, [ | ||
'merge-base', | ||
'HEAD', | ||
branch || 'master', | ||
]).stdout.trim(); | ||
return runGit(directory, ['rev-parse', '--short', revision]).stdout.trim(); | ||
} | ||
throw error; | ||
} | ||
catch (err) { | ||
const error = err; | ||
if (/HEAD/.test(error.message) || | ||
(staged && /Needed a single revision/.test(error.message))) { | ||
return null; | ||
} | ||
throw error; | ||
} | ||
}; | ||
exports.getSinceRevision = getSinceRevision; | ||
const getChangedFiles = (directory, revision, staged) => { | ||
return [...getLines(runGit(directory, ['diff', '--name-only', staged ? '--cached' : null, '--diff-filter=ACMRTUB', revision].filter(Boolean))), ...(staged ? [] : getLines(runGit(directory, ['ls-files', '--others', '--exclude-standard'])))].filter(Boolean); | ||
}; | ||
const getChangedFiles = (directory, revision, staged) => [ | ||
...getLines(runGit(directory, [ | ||
'diff', | ||
'--name-only', | ||
staged ? '--cached' : null, | ||
'--diff-filter=ACMRTUB', | ||
revision, | ||
].filter(Boolean))), | ||
...(staged | ||
? [] | ||
: getLines(runGit(directory, ['ls-files', '--others', '--exclude-standard']))), | ||
].filter(Boolean); | ||
exports.getChangedFiles = getChangedFiles; | ||
const getUnstagedChangedFiles = directory => { | ||
return getChangedFiles(directory, null, false); | ||
const getUnstagedChangedFiles = (directory) => { | ||
return (0, exports.getChangedFiles)(directory, null, false); | ||
}; | ||
exports.getUnstagedChangedFiles = getUnstagedChangedFiles; | ||
const stageFile = (directory, file) => { | ||
runGit(directory, ['add', file]); | ||
runGit(directory, ['add', file]); | ||
}; | ||
exports.stageFile = stageFile; | ||
exports.stageFile = stageFile; | ||
//# sourceMappingURL=git.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.stageFile = exports.name = exports.getUnstagedChangedFiles = exports.getSinceRevision = exports.getChangedFiles = exports.detect = void 0; | ||
var _findUp = _interopRequireDefault(require("find-up")); | ||
var _execa = _interopRequireDefault(require("execa")); | ||
var _path = require("path"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const name = exports.name = 'hg'; | ||
const detect = directory => { | ||
const hgDirectory = _findUp.default.sync('.hg', { | ||
cwd: directory, | ||
type: 'directory' | ||
}); | ||
if (hgDirectory) { | ||
return (0, _path.dirname)(hgDirectory); | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stageFile = exports.getUnstagedChangedFiles = exports.getChangedFiles = exports.getSinceRevision = exports.detect = exports.name = void 0; | ||
const tslib_1 = require("tslib"); | ||
const path_1 = (0, tslib_1.__importDefault)(require("path")); | ||
const execa_1 = (0, tslib_1.__importDefault)(require("execa")); | ||
const find_up_1 = (0, tslib_1.__importDefault)(require("find-up")); | ||
exports.name = 'hg'; | ||
const detect = (directory) => { | ||
const hgDirectory = find_up_1.default.sync('.hg', { | ||
cwd: directory, | ||
type: 'directory', | ||
}); | ||
if (hgDirectory) { | ||
return path_1.default.dirname(hgDirectory); | ||
} | ||
}; | ||
exports.detect = detect; | ||
const runHg = (directory, args) => _execa.default.sync('hg', args, { | ||
cwd: directory | ||
const runHg = (directory, args) => execa_1.default.sync('hg', args, { | ||
cwd: directory, | ||
}); | ||
const getLines = execaResult => execaResult.stdout.split('\n'); | ||
const getSinceRevision = (directory, { | ||
branch | ||
}) => { | ||
const revision = runHg(directory, ['debugancestor', 'tip', branch || 'default']).stdout.trim(); | ||
return runHg(directory, ['id', '-i', '-r', revision]).stdout.trim(); | ||
const getLines = (execaResult) => execaResult.stdout.split('\n'); | ||
const getSinceRevision = (directory, { branch }) => { | ||
const revision = runHg(directory, [ | ||
'debugancestor', | ||
'tip', | ||
branch || 'default', | ||
]).stdout.trim(); | ||
return runHg(directory, ['id', '-i', '-r', revision]).stdout.trim(); | ||
}; | ||
exports.getSinceRevision = getSinceRevision; | ||
const getChangedFiles = (directory, revision) => { | ||
return [...getLines(runHg(directory, ['status', '-n', '-a', '-m', '--rev', revision]))].filter(Boolean); | ||
}; | ||
const getChangedFiles = (directory, revision, _staged) => [ | ||
...getLines(runHg(directory, [ | ||
'status', | ||
'-n', | ||
'-a', | ||
'-m', | ||
...(revision ? ['--rev', revision] : []), | ||
])), | ||
].filter(Boolean); | ||
exports.getChangedFiles = getChangedFiles; | ||
const getUnstagedChangedFiles = () => { | ||
return []; | ||
}; | ||
const getUnstagedChangedFiles = () => []; | ||
exports.getUnstagedChangedFiles = getUnstagedChangedFiles; | ||
const stageFile = (directory, file) => { | ||
runHg(directory, ['add', file]); | ||
runHg(directory, ['add', file]); | ||
}; | ||
exports.stageFile = stageFile; | ||
exports.stageFile = stageFile; | ||
//# sourceMappingURL=hg.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var gitScm = _interopRequireWildcard(require("./git")); | ||
var hgScm = _interopRequireWildcard(require("./hg")); | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const gitScm = (0, tslib_1.__importStar)(require("./git")); | ||
const hgScm = (0, tslib_1.__importStar)(require("./hg")); | ||
const scms = [gitScm, hgScm]; | ||
var _default = directory => { | ||
for (const scm of scms) { | ||
const rootDirectory = scm.detect(directory); | ||
if (rootDirectory) { | ||
return Object.assign({ | ||
rootDirectory | ||
}, scm); | ||
exports.default = (directory) => { | ||
for (const scm of scms) { | ||
const rootDirectory = scm.detect(directory); | ||
if (rootDirectory) { | ||
return Object.assign({ rootDirectory }, scm); | ||
} | ||
} | ||
} | ||
}; | ||
exports.default = _default; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "pretty-quick", | ||
"version": "3.1.4", | ||
"version": "3.2.0", | ||
"description": "Get Pretty Quick", | ||
@@ -11,4 +11,6 @@ "repository": "prettier/pretty-quick", | ||
}, | ||
"bin": "./bin/pretty-quick.js", | ||
"main": "./dist", | ||
"bin": "dist/cli.js", | ||
"main": "dist/index.js", | ||
"module": "dist/index.esm.mjs", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
@@ -15,0 +17,0 @@ "bin", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
98399
37
702
5