Skip to content

Commit

Permalink
refactor(ts): ensure definitions are json-compatible
Browse files Browse the repository at this point in the history
- converts some interfaces to types to prevent re-opening
- https://www.typescriptlang.org/docs/handbook/advanced-types.html#interfaces-vs-type-aliases

Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Dec 3, 2022
1 parent 9a09e62 commit 63abb4a
Show file tree
Hide file tree
Showing 62 changed files with 701 additions and 569 deletions.
8 changes: 4 additions & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const config = {
overrides: [
...require('./.eslintrc.base.cjs').overrides,
{
files: ['./src/types/__tests__/types-versions.spec-d.ts'],
files: ['src/interfaces/dependency-map.ts', './src/types/imports.ts'],
rules: {
'sort-keys': 0
'@typescript-eslint/consistent-indexed-object-style': 0
}
},
{
files: ['./src/types/imports.ts'],
files: ['./src/types/__tests__/types-versions.spec-d.ts'],
rules: {
'@typescript-eslint/consistent-indexed-object-style': 0
'sort-keys': 0
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@commitlint/cli": "17.3.0",
"@commitlint/config-conventional": "17.3.0",
"@flex-development/mkbuild": "1.0.0-alpha.9",
"@flex-development/tutils": "6.0.0-alpha.3",
"@flex-development/tutils": "6.0.0-alpha.7",
"@graphql-eslint/eslint-plugin": "3.13.1",
"@types/chai": "4.3.4",
"@types/conventional-changelog": "3.1.1",
Expand Down Expand Up @@ -119,7 +119,7 @@
"yaml-eslint-parser": "1.1.0"
},
"peerDependencies": {
"@flex-development/tutils": ">=6.0.0-alpha.3"
"@flex-development/tutils": ">=6.0.0-alpha.7"
},
"resolutions": {
"@ardatan/sync-fetch": "larsgw/sync-fetch#head=worker_threads",
Expand Down
19 changes: 0 additions & 19 deletions src/interfaces/__tests__/bugs-object.spec-d.ts

This file was deleted.

48 changes: 48 additions & 0 deletions src/interfaces/__tests__/dependency-map.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @file Unit Tests - DependencyMap
* @module pkg-types/interfaces/tests/DependencyMap
*/

import type { DependencyMeta, PeerDependencyMeta } from '#src/types'
import type { JsonObject } from '@flex-development/tutils'
import type TestSubject from '../dependency-map'

describe('unit:interfaces/DependencyMap', () => {
type Union = DependencyMeta | PeerDependencyMeta | string | false

it('should allow empty object', () => {
assertType<TestSubject<Union>>({})
})

it('should be json object', () => {
expectTypeOf<TestSubject<Union>>().toMatchTypeOf<JsonObject>()
})

it('should return Record<string, DependencyMeta>', () => {
expectTypeOf<TestSubject<DependencyMeta>>().toMatchTypeOf<
Record<string, DependencyMeta>
>()
})

it('should return Record<string, PeerDependencyMeta>', () => {
expectTypeOf<TestSubject<PeerDependencyMeta>>().toMatchTypeOf<
Record<string, PeerDependencyMeta>
>()
})

it('should return Record<string, Record<string, string[]>>', () => {
expectTypeOf<TestSubject<Record<string, string[]>>>().toMatchTypeOf<
Record<string, Record<string, string[]>>
>()
})

it('should return Record<string, string>', () => {
expectTypeOf<TestSubject<string>>().toMatchTypeOf<Record<string, string>>()
})

it('should return Record<string, string | false>', () => {
expectTypeOf<TestSubject<string | false>>().toMatchTypeOf<
Record<string, string | false>
>()
})
})
16 changes: 0 additions & 16 deletions src/interfaces/__tests__/dependency-meta.spec-d.ts

This file was deleted.

45 changes: 5 additions & 40 deletions src/interfaces/__tests__/directories.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,19 @@
* @module pkg-types/interfaces/tests/Directories
*/

import type { JsonObject } from '@flex-development/tutils'
import type TestSubject from '../directories'

describe('unit:interfaces/Directories', () => {
it('should allow empty object', () => {
assertType<TestSubject>({})
})

it('should allow object that only has property "bin"', () => {
assertType<TestSubject>({ bin: './dist/bin' })
it('should be json object', () => {
expectTypeOf<TestSubject>().toMatchTypeOf<JsonObject>()
})

it('should allow object that only has property "doc"', () => {
assertType<TestSubject>({ doc: './dist/docs' })
})

it('should allow object that only has property "example"', () => {
assertType<TestSubject>({ example: './dist/docs/examples' })
})

it('should allow object that only has property "lib"', () => {
assertType<TestSubject>({ lib: './dist/lib' })
})

it('should allow object that only has property "man"', () => {
assertType<TestSubject>({ man: './dist/man' })
})

it('should allow object that only has property "src"', () => {
assertType<TestSubject>({ src: './src' })
})

it('should allow object that only has property "test"', () => {
assertType<TestSubject>({ test: './__tests__' })
})

it('should allow object with all properties', () => {
assertType<Required<TestSubject>>({
bin: './dist/bin',
doc: './dist/docs',
example: './dist/docs/examples',
lib: './dist/lib',
man: './dist/man',
src: './src',
test: './__tests__'
})
})

it('should allow object with unknown key', () => {
assertType<TestSubject>({ jars: 'java' })
it('should only have string values', () => {
expectTypeOf<TestSubject[string]>().toBeString()
})
})
18 changes: 0 additions & 18 deletions src/interfaces/__tests__/funding-info.spec-d.ts

This file was deleted.

27 changes: 0 additions & 27 deletions src/interfaces/__tests__/install-config.spec-d.ts

This file was deleted.

22 changes: 0 additions & 22 deletions src/interfaces/__tests__/license-object.spec-d.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/interfaces/__tests__/peer-dependency-meta.spec-d.ts

This file was deleted.

20 changes: 0 additions & 20 deletions src/interfaces/__tests__/person.spec-d.ts

This file was deleted.

62 changes: 32 additions & 30 deletions src/interfaces/__tests__/publish-config.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,58 @@
* @module pkg-types/interfaces/tests/PublishConfig
*/

import type { Access, Bin, Registry } from '#src/types'
import type { JsonObject } from '@flex-development/tutils'
import type TestSubject from '../publish-config'

describe('unit:interfaces/PublishConfig', () => {
it('should allow empty object', () => {
assertType<TestSubject>({})
})

it('should allow object that only has property "access"', () => {
assertType<TestSubject>({ access: 'public' })
assertType<TestSubject>({ access: 'restricted' })
it('should be json object', () => {
expectTypeOf<TestSubject>().toMatchTypeOf<JsonObject>()
})

it('should allow object that only has property "bin"', () => {
assertType<TestSubject>({ bin: './cli.mjs' })
assertType<TestSubject>({ bin: { mkbuild: './cli.mjs' } })
it('should have property [access?: Access]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('access')
.toEqualTypeOf<Access | undefined>()
})

it('should allow object that only has property "executableFiles"', () => {
assertType<TestSubject>({ executableFiles: ['./dist/shim.js'] })
it('should have property [bin?: Bin]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('bin')
.toEqualTypeOf<Bin | undefined>()
})

it('should allow object that only has property "main"', () => {
assertType<TestSubject>({ main: './index.cjs' })
it('should have property [executableFiles?: string[]]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('executableFiles')
.toEqualTypeOf<string[] | undefined>()
})

it('should allow object that only has property "module"', () => {
assertType<TestSubject>({ module: './index.mjs' })
it('should have property [main?: string]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('main')
.toEqualTypeOf<string | undefined>()
})

it('should allow object that only has property "registry"', () => {
assertType<TestSubject>({ registry: 'http://npm.pkg.github.com' })
it('should have property [module?: string]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('module')
.toEqualTypeOf<string | undefined>()
})

it('should allow object that only has property "tag"', () => {
assertType<TestSubject>({ tag: 'alpha' })
it('should have property [registry?: Registry]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('registry')
.toEqualTypeOf<Registry | undefined>()
})

it('should allow object with all properties', () => {
assertType<Required<TestSubject>>({
access: 'public',
bin: './cli.mjs',
executableFiles: ['./dist/shim.js'],
main: './index.cjs',
module: './index.mjs',
registry: 'http://npm.pkg.github.com',
tag: 'alpha'
})
})

it('should allow object with unknown key', () => {
assertType<TestSubject>({ key: 'value' })
it('should have property [tag?: string]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('tag')
.toEqualTypeOf<string | undefined>()
})
})
Loading

0 comments on commit 63abb4a

Please sign in to comment.