Skip to content

Commit

Permalink
refactor: use node: protocol imports
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Jun 1, 2022
1 parent 5fb6df9 commit eae9622
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions bin/lint-staged.js
@@ -1,8 +1,8 @@
#!/usr/bin/env node

import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

import { Option, program } from 'commander'
import debug from 'debug'
Expand Down
2 changes: 1 addition & 1 deletion lib/chunkFiles.js
@@ -1,4 +1,4 @@
import path from 'path'
import path from 'node:path'

import debug from 'debug'
import normalize from 'normalize-path'
Expand Down
2 changes: 1 addition & 1 deletion lib/dynamicImport.js
@@ -1,3 +1,3 @@
import { pathToFileURL } from 'url'
import { pathToFileURL } from 'node:url'

export const dynamicImport = (path) => import(pathToFileURL(path)).then((module) => module.default)
2 changes: 1 addition & 1 deletion lib/file.js
@@ -1,4 +1,4 @@
import { promises as fs } from 'fs'
import fs from 'node:fs/promises'

import debug from 'debug'

Expand Down
2 changes: 1 addition & 1 deletion lib/generateTasks.js
@@ -1,4 +1,4 @@
import path from 'path'
import path from 'node:path'

import debug from 'debug'
import micromatch from 'micromatch'
Expand Down
2 changes: 1 addition & 1 deletion lib/getStagedFiles.js
@@ -1,4 +1,4 @@
import path from 'path'
import path from 'node:path'

import normalize from 'normalize-path'

Expand Down
2 changes: 1 addition & 1 deletion lib/gitWorkflow.js
@@ -1,4 +1,4 @@
import path from 'path'
import path from 'node:path'

import debug from 'debug'

Expand Down
2 changes: 1 addition & 1 deletion lib/groupFilesByConfig.js
@@ -1,4 +1,4 @@
import path from 'path'
import path from 'node:path'

import debug from 'debug'

Expand Down
2 changes: 1 addition & 1 deletion lib/resolveConfig.js
@@ -1,4 +1,4 @@
import { createRequire } from 'module'
import { createRequire } from 'node:module'

/**
* require() does not exist for ESM, so we must create it to use require.resolve().
Expand Down
4 changes: 2 additions & 2 deletions lib/resolveGitRepo.js
@@ -1,5 +1,5 @@
import { promises as fs } from 'fs'
import path from 'path'
import fs from 'node:fs/promises'
import path from 'node:path'

import debug from 'debug'
import normalize from 'normalize-path'
Expand Down
2 changes: 1 addition & 1 deletion lib/runAll.js
@@ -1,6 +1,6 @@
/** @typedef {import('./index').Logger} Logger */

import path from 'path'
import path from 'node:path'

import { dim } from 'colorette'
import debug from 'debug'
Expand Down
6 changes: 3 additions & 3 deletions lib/searchConfigs.js
@@ -1,6 +1,6 @@
/** @typedef {import('./index').Logger} Logger */

import { basename, join } from 'path'
import path from 'node:path'

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

const filterPossibleConfigFiles = (files) =>
files.filter((file) => searchPlaces.includes(basename(file)))
files.filter((file) => searchPlaces.includes(path.basename(file)))

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

Expand Down Expand Up @@ -68,7 +68,7 @@ export const searchConfigs = async (

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

Expand Down
5 changes: 3 additions & 2 deletions lib/validateOptions.js
@@ -1,5 +1,6 @@
import { constants, promises as fs } from 'fs'
import path from 'path'
import { constants } from 'node:fs'
import fs from 'node:fs/promises'
import path from 'node:path'

import debug from 'debug'

Expand Down
2 changes: 1 addition & 1 deletion test/loadConfig.spec.js
Expand Up @@ -21,7 +21,7 @@ jest.unmock('execa')
* This converts paths into `file://` urls, but this doesn't
* work with `import()` when using babel + jest.
*/
jest.mock('url', () => ({
jest.mock('node:url', () => ({
pathToFileURL: (path) => path,
}))

Expand Down

0 comments on commit eae9622

Please sign in to comment.