Skip to content

Commit eae9622

Browse files
committed
refactor: use node: protocol imports
1 parent 5fb6df9 commit eae9622

14 files changed

+21
-20
lines changed

bin/lint-staged.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env node
22

3-
import fs from 'fs'
4-
import path from 'path'
5-
import { fileURLToPath } from 'url'
3+
import fs from 'node:fs'
4+
import path from 'node:path'
5+
import { fileURLToPath } from 'node:url'
66

77
import { Option, program } from 'commander'
88
import debug from 'debug'

lib/chunkFiles.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path'
1+
import path from 'node:path'
22

33
import debug from 'debug'
44
import normalize from 'normalize-path'

lib/dynamicImport.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { pathToFileURL } from 'url'
1+
import { pathToFileURL } from 'node:url'
22

33
export const dynamicImport = (path) => import(pathToFileURL(path)).then((module) => module.default)

lib/file.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { promises as fs } from 'fs'
1+
import fs from 'node:fs/promises'
22

33
import debug from 'debug'
44

lib/generateTasks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path'
1+
import path from 'node:path'
22

33
import debug from 'debug'
44
import micromatch from 'micromatch'

lib/getStagedFiles.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path'
1+
import path from 'node:path'
22

33
import normalize from 'normalize-path'
44

lib/gitWorkflow.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path'
1+
import path from 'node:path'
22

33
import debug from 'debug'
44

lib/groupFilesByConfig.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path'
1+
import path from 'node:path'
22

33
import debug from 'debug'
44

lib/resolveConfig.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createRequire } from 'module'
1+
import { createRequire } from 'node:module'
22

33
/**
44
* require() does not exist for ESM, so we must create it to use require.resolve().

lib/resolveGitRepo.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { promises as fs } from 'fs'
2-
import path from 'path'
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
33

44
import debug from 'debug'
55
import normalize from 'normalize-path'

lib/runAll.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @typedef {import('./index').Logger} Logger */
22

3-
import path from 'path'
3+
import path from 'node:path'
44

55
import { dim } from 'colorette'
66
import debug from 'debug'

lib/searchConfigs.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @typedef {import('./index').Logger} Logger */
22

3-
import { basename, join } from 'path'
3+
import path from 'node:path'
44

55
import debug from 'debug'
66
import normalize from 'normalize-path'
@@ -15,7 +15,7 @@ const debugLog = debug('lint-staged:searchConfigs')
1515
const EXEC_GIT = ['ls-files', '-z', '--full-name']
1616

1717
const filterPossibleConfigFiles = (files) =>
18-
files.filter((file) => searchPlaces.includes(basename(file)))
18+
files.filter((file) => searchPlaces.includes(path.basename(file)))
1919

2020
const numberOfLevels = (file) => file.split('/').length
2121

@@ -68,7 +68,7 @@ export const searchConfigs = async (
6868

6969
/** Sort possible config files so that deepest is first */
7070
const possibleConfigFiles = [...cachedFiles, ...otherFiles]
71-
.map((file) => normalize(join(gitDir, file)))
71+
.map((file) => normalize(path.join(gitDir, file)))
7272
.filter(isInsideDirectory(cwd))
7373
.sort(sortDeepestParth)
7474

lib/validateOptions.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { constants, promises as fs } from 'fs'
2-
import path from 'path'
1+
import { constants } from 'node:fs'
2+
import fs from 'node:fs/promises'
3+
import path from 'node:path'
34

45
import debug from 'debug'
56

test/loadConfig.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jest.unmock('execa')
2121
* This converts paths into `file://` urls, but this doesn't
2222
* work with `import()` when using babel + jest.
2323
*/
24-
jest.mock('url', () => ({
24+
jest.mock('node:url', () => ({
2525
pathToFileURL: (path) => path,
2626
}))
2727

0 commit comments

Comments
 (0)