Skip to content

Commit

Permalink
fix!: package exports/imports
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Sep 1, 2024
1 parent b54dbbb commit 871f2a7
Show file tree
Hide file tree
Showing 26 changed files with 238 additions and 211 deletions.
43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,72 +45,73 @@ yarn add @flex-development/pkg-types
import type {
Condition,
ConditionMap,
ExportConditions,
ConditionalTargets,
Exports,
ExportsKey,
ExportsList,
ExportsObject,
ImportConditions,
ExportsSubpath,
Imports,
ImportsKey,
ImportsSubpath,
PackageJson,
PackageType,
SubpathExports
SubpathExports,
Target,
TargetList
} from '@flex-development/pkg-types'
```

## API

- [`Access`](./src/access.ts)
- [`Bin`](./src/bin.ts)
- [`BinObject`](./src/bin-object.ts)
- [`Browser`](./src/browser.ts)
- [`Bin`](./src/bin.ts)
- [`BrowserObject`](./src/browser-object.ts)
- [`Browser`](./src/browser.ts)
- [`Bugs`](./src/bugs.ts)
- [`Condition`](./src/condition.ts)
- [`CPUMap`](./src/cpu-map.ts)
- [`CPU`](./src/cpu.ts)
- [`ConditionMap`](./src/condition-map.ts)
- [`Condition`](./src/condition.ts)
- [`ConditionalTargets`](./src/conditional-targets.ts)
- [`Config`](./src/config.ts)
- [`CPU`](./src/cpu.ts)
- [`CPUMap`](./src/cpu-map.ts)
- [`Dependencies`](./src/dependencies.ts)
- [`DevDependencies`](./src/dev-dependencies.ts)
- [`Directories`](./src/directories.ts)
- [`Engine`](./src/engine.ts)
- [`EngineMap`](./src/engine-map.ts)
- [`Engine`](./src/engine.ts)
- [`Engines`](./src/engines.ts)
- [`ExportConditions`](./src/export-conditions.ts)
- [`Exports`](./src/exports.ts)
- [`ExportsKey`](./src/exports-key.ts)
- [`ExportsList`](./src/exports-list.ts)
- [`ExportsObject`](./src/exports-object.ts)
- [`ExportsSubpath`](./src/exports-subpath.ts)
- [`ImportConditions`](./src/import-conditions.ts)
- [`Exports`](./src/exports.ts)
- [`ImportsSubpath`](./src/imports-subpath.ts)
- [`Imports`](./src/imports.ts)
- [`ImportsKey`](./src/imports-key.ts)
- [`JsonArray`](./src/json-array.ts)
- [`JsonObject`](./src/json-object.ts)
- [`JsonPrimitive`](./src/json-primitive.ts)
- [`JsonValue`](./src/json-value.ts)
- [`LicenseInfo`](./src/license-info.ts)
- [`OptionalDependencies`](./src/optional-dependencies.ts)
- [`OS`](./src/os.ts)
- [`OSMap`](./src/os-map.ts)
- [`OS`](./src/os.ts)
- [`OptionalDependencies`](./src/optional-dependencies.ts)
- [`PackageJson`](./src/package-json.ts)
- [`PackageManager`](./src/package-manager.ts)
- [`PackageManagerMap`](./src/package-manager-map.ts)
- [`PackageManager`](./src/package-manager.ts)
- [`PackageType`](./src/package-type.ts)
- [`PeerDependencies`](./src/peer-dependencies.ts)
- [`PeerDependenciesMeta`](./src/peer-dependencies-meta.ts)
- [`PeerDependencies`](./src/peer-dependencies.ts)
- [`PeerDependencyMetadata`](./src/peer-dependency-metadata.ts)
- [`People`](./src/people.ts)
- [`Person`](./src/person.ts)
- [`PublishConfig`](./src/publish-config.ts)
- [`RepositoryInfo`](./src/repository-info.ts)
- [`RepositoryType`](./src/repository-type.ts)
- [`RepositoryTypeMap`](./src/repository-type-map.ts)
- [`RepositoryType`](./src/repository-type.ts)
- [`Scripts`](./src/scripts.ts)
- [`SemanticVersion`](./src/semantic-version.ts)
- [`SubpathExports`](./src/subpath-exports.ts)
- [`TargetList`](./src/target-list.ts)
- [`Target`](./src/target.ts)
- [`TypesVersions`](./src/types-versions.ts)
- [`WorkspacesConfig`](./src/workspaces-config.ts)

Expand Down
24 changes: 24 additions & 0 deletions src/__tests__/conditional-targets.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @file Unit Tests - ConditionalTargets
* @module pkg-types/tests/unit-d/ConditionalTargets
*/

import type Condition from '../condition'
import type TestSubject from '../conditional-targets'
import type JsonObject from '../json-object'
import type Target from '../target'

describe('unit-d:ConditionalTargets', () => {
it('should allow empty object', () => {
assertType<TestSubject>({})
})

it('should match JsonObject', () => {
expectTypeOf<TestSubject>().toMatchTypeOf<JsonObject>()
})

it('should match Partial<Record<Condition, Target>>', () => {
expectTypeOf<TestSubject>()
.toMatchTypeOf<Partial<Record<Condition, Target>>>()
})
})
24 changes: 0 additions & 24 deletions src/__tests__/export-conditions.spec-d.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/__tests__/exports-list.spec-d.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/__tests__/exports-object.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* @module pkg-types/tests/unit-d/ExportsObject
*/

import type ExportConditions from '../export-conditions'
import type ConditionalTargets from '../conditional-targets'
import type TestSubject from '../exports-object'
import type SubpathExports from '../subpath-exports'

describe('unit-d:ExportsObject', () => {
it('should extract ExportConditions', () => {
expectTypeOf<TestSubject>().extract<ExportConditions>().not.toBeNever()
it('should extract ConditionalTargets', () => {
expectTypeOf<TestSubject>().extract<ConditionalTargets>().not.toBeNever()
})

it('should extract SubpathExports', () => {
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/exports.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
*/

import type TestSubject from '../exports'
import type ExportsList from '../exports-list'
import type ExportsObject from '../exports-object'
import type TargetList from '../target-list'

describe('unit-d:Exports', () => {
it('should extract ExportsList', () => {
expectTypeOf<TestSubject>().extract<ExportsList>().not.toBeNever()
})

it('should extract ExportsObject', () => {
expectTypeOf<TestSubject>().extract<ExportsObject>().not.toBeNever()
})

it('should extract TargetList', () => {
expectTypeOf<TestSubject>().extract<TargetList>().not.toBeNever()
})

it('should extract string', () => {
expectTypeOf<TestSubject>().extract<string>().not.toBeNever()
})
Expand Down
24 changes: 0 additions & 24 deletions src/__tests__/import-conditions.spec-d.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/__tests__/imports-key.spec-d.ts

This file was deleted.

12 changes: 12 additions & 0 deletions src/__tests__/imports-subpath.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @file Unit Tests - ImportsSubpath
* @module pkg-types/tests/unit-d/ImportsSubpath
*/

import type TestSubject from '../imports-subpath'

describe('unit-d:ImportsSubpath', () => {
it('should equal `#${string}`', () => {
expectTypeOf<TestSubject>().toEqualTypeOf<`#${string}`>()
})
})
15 changes: 11 additions & 4 deletions src/__tests__/imports.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* @module pkg-types/tests/unit-d/Imports
*/

import type ImportConditions from '../import-conditions'
import type TestSubject from '../imports'
import type ImportsKey from '../imports-key'
import type ImportsSubpath from '../imports-subpath'
import type JsonObject from '../json-object'
import type Target from '../target'

describe('unit-d:Imports', () => {
it('should allow empty object', () => {
Expand All @@ -17,8 +17,15 @@ describe('unit-d:Imports', () => {
expectTypeOf<TestSubject>().toMatchTypeOf<JsonObject>()
})

it('should match Record<ImportsKey, ImportConditions | string>', () => {
it('should match [[subpath: ImportsSubpath]: Target]', () => {
expectTypeOf<TestSubject>()
.toMatchTypeOf<Record<ImportsKey, ImportConditions | string>>()
.toHaveProperty<ImportsSubpath>('#')
.toEqualTypeOf<Target>()
})

it('should match [[subpath: string]: Target]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty<string>('')
.toEqualTypeOf<Target>()
})
})
25 changes: 17 additions & 8 deletions src/__tests__/subpath-exports.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,41 @@
*/

import type { Optional } from '@flex-development/tutils'
import type Exports from '../exports'
import type ExportsSubpath from '../exports-subpath'
import type JsonObject from '../json-object'
import type TestSubject from '../subpath-exports'
import type Target from '../target'

describe('unit-d:SubpathExports', () => {
it('should allow empty object', () => {
assertType<TestSubject>({})
})

it('should extend JsonObject', () => {
it('should match JsonObject', () => {
expectTypeOf<TestSubject>().toMatchTypeOf<JsonObject>()
})

it('should match Record<`./${string}`, Exports>', () => {
expectTypeOf<TestSubject>().toMatchTypeOf<Record<`./${string}`, Exports>>()
it('should match [subpath: Exclude<ExportsSubpath, ".">]: Target]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty<Exclude<ExportsSubpath, '.'>>('./lib/*.mjs')
.toEqualTypeOf<Target>()
})

it('should match [[subpath: string]: Target]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty<string>('')
.toEqualTypeOf<Target>()
})

it('should match ["."?: Exports]', () => {
it('should match ["."?: Target]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('.')
.toEqualTypeOf<Optional<Exports>>()
.toEqualTypeOf<Optional<Target>>()
})

it('should match ["./package.json"?: Exports]', () => {
it('should match ["./package.json"?: Target]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('./package.json')
.toEqualTypeOf<Optional<Exports>>()
.toEqualTypeOf<Optional<Target>>()
})
})
19 changes: 19 additions & 0 deletions src/__tests__/target-list.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @file Unit Tests - TargetList
* @module pkg-types/tests/unit-d/TargetList
*/

import type ConditionalTargets from '../conditional-targets'
import type TestSubject from '../target-list'

describe('unit-d:TargetList', () => {
describe('TargetList[number]', () => {
it('should equal ConditionalTargets | TargetList | string | null', () => {
// Arrange
type Item = ConditionalTargets | TestSubject | string | null

// Expect
expectTypeOf<TestSubject[number]>().toEqualTypeOf<Item>()
})
})
})
26 changes: 26 additions & 0 deletions src/__tests__/target.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @file Unit Tests - Target
* @module pkg-types/tests/unit-d/Target
*/

import type ConditionalTargets from '../conditional-targets'
import type TestSubject from '../target'
import type TargetList from '../target-list'

describe('unit-d:Target', () => {
it('should extract ConditionalTargets', () => {
expectTypeOf<TestSubject>().extract<ConditionalTargets>().not.toBeNever()
})

it('should extract TargetList', () => {
expectTypeOf<TestSubject>().extract<TargetList>().not.toBeNever()
})

it('should extract string', () => {
expectTypeOf<TestSubject>().extract<string>().not.toBeNever()
})

it('should extract null', () => {
expectTypeOf<TestSubject>().extract<null>().not.toBeNever()
})
})
Loading

0 comments on commit 871f2a7

Please sign in to comment.