Skip to content

Commit baa7c98

Browse files
committed
feat: remove current chunkFiles implementation
1 parent dbc7831 commit baa7c98

8 files changed

Lines changed: 109 additions & 319 deletions

File tree

‎.oxlintrc.json‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
"$schema": "./node_modules/oxlint/configuration_schema.json",
33
"categories": {
44
"correctness": "error",
5+
"nursery": "error",
56
"perf": "error"
67
},
7-
"plugins": ["import", "eslint", "oxc", "vitest"],
8+
"env": {
9+
"node": true
10+
},
11+
"plugins": ["import", "eslint", "node", "oxc", "vitest"],
812
"rules": {
913
"no-await-in-loop": "off"
1014
}

‎lib/chunkFiles.js‎

Lines changed: 0 additions & 65 deletions
This file was deleted.

‎lib/gitWorkflow.js‎

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class GitWorkflow {
8686
failOnChanges,
8787
gitConfigDir,
8888
logger,
89-
matchedFileChunks,
89+
matchedFiles,
9090
topLevelDir,
9191
}) {
9292
this.execGit = (args, options = {}) => execGit(args, { ...options, cwd: topLevelDir })
@@ -96,8 +96,8 @@ export class GitWorkflow {
9696
this.gitConfigDir = gitConfigDir
9797
this.failOnChanges = !!failOnChanges
9898
this.logger = logger
99-
/** @type {import('./getStagedFiles.js').StagedFile[][]} */
100-
this.matchedFileChunks = matchedFileChunks
99+
/** @type {Set<import('./getStagedFiles.js').StagedFile>} */
100+
this.matchedFiles = matchedFiles
101101
this.topLevelDir = topLevelDir
102102

103103
/**
@@ -369,46 +369,43 @@ export class GitWorkflow {
369369
? normalizePath(process.env.GIT_INDEX_FILE)
370370
: process.env.GIT_INDEX_FILE
371371

372-
/** Needs to be run serially because of locking Git operation */
373-
for (const files of this.matchedFileChunks) {
374-
const accessCheckedFiles = await Promise.allSettled(
375-
files.map(async (f) => {
376-
if (f.status === 'D') {
377-
await fs.access(f.filepath)
378-
return f.filepath // File is no longer deleted and can be added
379-
} else {
380-
return f.filepath
381-
}
382-
})
383-
)
372+
const accessCheckedFiles = await Promise.allSettled(
373+
Array.from(this.matchedFiles).map(async (f) => {
374+
if (f.status === 'D') {
375+
await fs.access(f.filepath)
376+
return f.filepath // File is no longer deleted and can be added
377+
} else {
378+
return f.filepath
379+
}
380+
})
381+
)
384382

385-
const addableFiles = accessCheckedFiles.flatMap((r) =>
386-
r.status === 'fulfilled' ? [r.value] : []
387-
)
383+
const addableFiles = accessCheckedFiles.flatMap((r) =>
384+
r.status === 'fulfilled' ? [r.value] : []
385+
)
388386

389-
debugLog('Updating active Git index: %s', activeIndexFile)
390-
await this.execGit(['add', '--', ...addableFiles])
391-
debugLog('Done updating Git index: %s', activeIndexFile)
387+
debugLog('Updating active Git index: %s', activeIndexFile)
388+
await this.execGit(['add', '--', ...addableFiles])
389+
debugLog('Done updating Git index: %s', activeIndexFile)
392390

393-
if (activeIndexFile?.endsWith('.lock')) {
394-
const defaultIndexLock = normalizePath(
395-
await this.execGit(['rev-parse', '--path-format=absolute', '--git-path', 'index.lock'])
396-
)
391+
if (activeIndexFile?.endsWith('.lock')) {
392+
const defaultIndexLock = normalizePath(
393+
await this.execGit(['rev-parse', '--path-format=absolute', '--git-path', 'index.lock'])
394+
)
397395

398-
/**
399-
* If the active index file is a non-default lockfile, we are committing with a pathspec
400-
* without having explicitly run `git add`. In this case we need to also update the
401-
* default index, otherwise there will be leftover diff after committing
402-
*/
403-
if (activeIndexFile !== defaultIndexLock) {
404-
debugLog('Updating default Git index again: %s', defaultIndexLock)
405-
await this.execGit(['add', '--', ...addableFiles], {
406-
env: {
407-
GIT_INDEX_FILE: defaultIndexLock,
408-
},
409-
})
410-
debugLog('Done updating default Git index lock: %s', defaultIndexLock)
411-
}
396+
/**
397+
* If the active index file is a non-default lockfile, we are committing with a pathspec
398+
* without having explicitly run `git add`. In this case we need to also update the
399+
* default index, otherwise there will be leftover diff after committing
400+
*/
401+
if (activeIndexFile !== defaultIndexLock) {
402+
debugLog('Updating default Git index again: %s', defaultIndexLock)
403+
await this.execGit(['add', '--', ...addableFiles], {
404+
env: {
405+
GIT_INDEX_FILE: defaultIndexLock,
406+
},
407+
})
408+
debugLog('Done updating default Git index lock: %s', defaultIndexLock)
412409
}
413410
}
414411

‎lib/index.js‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,6 @@ import { getVersion } from './version.js'
2727

2828
const debugLog = createDebug('lint-staged')
2929

30-
/**
31-
* Get the maximum length of a command-line argument string based on current platform,
32-
* roughly half of the real maximum length
33-
*
34-
* https://serverfault.com/questions/69430/what-is-the-maximum-length-of-a-command-line-in-mac-os-x
35-
* https://support.microsoft.com/en-us/help/830473/command-prompt-cmd-exe-command-line-string-limitation
36-
* https://unix.stackexchange.com/a/120652
37-
*/
38-
const getMaxArgLength = () => {
39-
switch (process.platform) {
40-
case 'darwin': // 262_144
41-
return 131_072
42-
case 'win32': // 8_191
43-
return 4_096
44-
default: // 131_072
45-
return 65_536
46-
}
47-
}
48-
4930
/**
5031
* @typedef {(...any) => void} LogFunction
5132
* @typedef {{ error: LogFunction, log: LogFunction, warn: LogFunction }} Logger
@@ -92,7 +73,7 @@ const lintStaged = async (
9273
hideAll = false,
9374
hideUnstaged = false,
9475
hidePartiallyStaged = !(hideAll || hideUnstaged),
95-
maxArgLength = getMaxArgLength(),
76+
maxArgLength,
9677
quiet = false,
9778
relative = false,
9879
// Stashing should be disabled by default when the `diff` option is used

0 commit comments

Comments
 (0)