Skip to content

Commit

Permalink
refactor: create hash file
Browse files Browse the repository at this point in the history
  • Loading branch information
btea committed Oct 14, 2024
1 parent f5f2ed5 commit 2162740
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/vitest/src/integrations/css/css-modules.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hash } from '../../utils'
import { hash } from '../../node/hash'
import type { CSSModuleScopeStrategy } from '../../node/types/config'

export function generateCssFilenameHash(filepath: string) {
Expand Down
3 changes: 2 additions & 1 deletion packages/vitest/src/node/cache/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { resolve } from 'pathe'
import { hash, slash } from '../../utils'
import { slash } from '../../utils'
import { hash } from '../hash'
import { FilesStatsCache } from './files'
import { ResultsCache } from './results'

Expand Down
7 changes: 7 additions & 0 deletions packages/vitest/src/node/hash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import crypto from 'node:crypto'

export const hash = crypto.hash ?? ((
algorithm: string,

Check failure on line 4 in packages/vitest/src/node/hash.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Expected indentation of 2 spaces but found 4
data: crypto.BinaryLike,

Check failure on line 5 in packages/vitest/src/node/hash.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Expected indentation of 2 spaces but found 4
outputEncoding: crypto.BinaryToTextEncoding,

Check failure on line 6 in packages/vitest/src/node/hash.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Expected indentation of 2 spaces but found 4
) => crypto.createHash(algorithm).update(data).digest(outputEncoding))

Check failure on line 7 in packages/vitest/src/node/hash.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Expected indentation of 0 spaces but found 2

Check failure on line 7 in packages/vitest/src/node/hash.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Newline required at end of file but not found
2 changes: 1 addition & 1 deletion packages/vitest/src/node/pools/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { RawSourceMap } from 'vite-node'
import { join } from 'pathe'
import type { WorkspaceProject } from '../workspace'
import type { RuntimeRPC } from '../../types/rpc'
import { hash } from '../../utils'
import { hash } from '../hash'

const created = new Set()
const promises = new Map<string, Promise<void>>()
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/sequencers/BaseSequencer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { relative, resolve } from 'pathe'
import { slash } from 'vite-node/utils'
import { hash } from '../../utils'
import { hash } from '../hash'
import type { Vitest } from '../core'
import type { WorkspaceSpec } from '../pool'
import type { TestSequencer } from './types'
Expand Down
7 changes: 0 additions & 7 deletions packages/vitest/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import crypto from 'node:crypto'
import { relative } from 'pathe'
import { getWorkerState } from '../utils'

Expand Down Expand Up @@ -55,9 +54,3 @@ export function objectAttr(
}
return result
}

export const hash = crypto.hash ?? ((
algorithm: string,
data: crypto.BinaryLike,
outputEncoding: crypto.BinaryToTextEncoding,
) => crypto.createHash(algorithm).update(data).digest(outputEncoding))

0 comments on commit 2162740

Please sign in to comment.