Skip to content

Commit

Permalink
feat(types): DependencyMap
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Dec 1, 2022
1 parent 78a4cbd commit 50a80ee
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/types/__tests__/dependency-map.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @file Unit Tests - DependencyMap
* @module pkg-types/types/tests/DependencyMap
*/

import type { DependencyMeta, PeerDependencyMeta } from '#src/interfaces'
import pkg from '../../../package.json' assert { type: 'json' }
import type TestSubject from '../dependency-map'

describe('unit:types/DependencyMap', () => {
it('should allow dependency map', () => {
assertType<TestSubject<string>>(pkg.devDependencies)
})

it('should allow dependency for browsers', () => {
assertType<TestSubject<string | false>>({
fs: false,
path: './dist/browser-shims/path.mjs'
})
})

it('should allow dependency metadata map', () => {
assertType<TestSubject<DependencyMeta>>({
fsevents: { built: false, optional: false, unplugged: true }
})
})

it('should allow peer dependency metadata map', () => {
assertType<TestSubject<PeerDependencyMeta>>({
'@flex-development/tutils': { optional: false }
})
})

it('should allow empty object', () => {
// Arrange
type T = DependencyMeta | PeerDependencyMeta | string | false

// Expect
assertType<TestSubject<T>>({})
})
})
17 changes: 17 additions & 0 deletions src/types/dependency-map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @file Type Definitions - DependencyMap
* @module pkg-types/types/DependencyMap
*/

import type { DependencyMeta, PeerDependencyMeta } from '#src/interfaces'

/**
* Maps dependency names to version ranges, files, or metadata.
*
* @template T - Version range, file, or metadata type
*/
type DependencyMap<
T extends DependencyMeta | PeerDependencyMeta | string | false
> = Partial<Record<string, T>>

export type { DependencyMap as default }
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

export type { default as Access } from './access'
export type { default as CPU } from './cpu'
export type { default as DependencyMap } from './dependency-map'
export type { default as Engine } from './engine'
export type { default as ExportCondition } from './export-condition'
export type { default as FundingType } from './funding-type'
Expand Down

0 comments on commit 50a80ee

Please sign in to comment.