Skip to content

Commit 1524cee

Browse files
committed
refactor!: api
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent 8193e02 commit 1524cee

161 files changed

Lines changed: 3098 additions & 2581 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ mkbuild
1919
nvmrc
2020
pathe
2121
pkgs
22+
pnpx
2223
preid
2324
shfmt
2425
unstub

README.md

Lines changed: 69 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -41,111 +41,77 @@ yarn add @flex-development/pkg-types
4141

4242
## Use
4343

44-
```typescript
45-
import type { PackageJson } from '@flex-development/pkg-types'
46-
import fs from 'node:fs'
47-
import path from 'node:path'
48-
49-
/**
50-
* Enables or disables [`type`][1] in `package.json`.
51-
*
52-
* [1]: https://nodejs.org/api/packages.html#type
53-
*
54-
* @example
55-
* toggle()
56-
* @example
57-
* toggle('off')
58-
* @example
59-
* toggle('on')
60-
*
61-
* @param {'off' | 'on'} [command] - Toggle command
62-
* @return {void} Nothing when complete
63-
*/
64-
function toggle(command?: 'off' | 'on'): void {
65-
// see: https://yarnpkg.com/advanced/lifecycle-scripts#environment-variables
66-
const { npm_package_json = 'package.json' } = process.env
67-
68-
/**
69-
* Absolute path to `package.json`.
70-
*
71-
* @const {string} pkgfile
72-
*/
73-
const pkgfile: string = path.resolve(npm_package_json)
74-
75-
/**
76-
* `package.json` data.
77-
*
78-
* @var {PackageJson} pkg
79-
*/
80-
let pkg: PackageJson = JSON.parse(fs.readFileSync(pkgfile, 'utf8'))
81-
82-
// toggle package type
83-
pkg = Object.keys(pkg).reduce<PackageJson>((acc, key) => {
84-
const [, type, prefix = ''] = /^((#?)type)$/.exec(key) ?? []
85-
86-
if (type) {
87-
key = command
88-
? `${command === 'off' ? '#' : ''}type`
89-
: prefix
90-
? type.replace(new RegExp('^' + prefix), '')
91-
: '#' + type
92-
93-
acc[key] = pkg[type]!
94-
} else {
95-
acc[key] = pkg[key]!
96-
}
97-
98-
return acc
99-
}, {})
100-
101-
// rewrite package.json
102-
return void fs.writeFileSync(pkgfile, JSON.stringify(pkg, null, 2) + '\n')
103-
}
104-
105-
export default toggle
44+
```ts
45+
import type {
46+
Condition,
47+
ConditionMap,
48+
ExportConditions,
49+
Exports,
50+
ExportsKey,
51+
ExportsList,
52+
ExportsObject,
53+
ImportConditions,
54+
Imports,
55+
ImportsKey,
56+
PackageJson,
57+
PackageType,
58+
SubpathExports
59+
} from '@flex-development/pkg-types'
10660
```
10761

108-
Need this functionality? See [`toggle-pkg-type`][toggle-pkg-type] \:blush:
109-
11062
## API
11163

112-
### Interfaces
113-
114-
- [`DependencyMap`](src/interfaces/dependency-map.ts)
115-
- [`Directories`](src/interfaces/directories.ts)
116-
- [`PackageJson`](src/interfaces/package-json.ts)
117-
- [`PublishConfig`](src/interfaces/publish-config.ts)
118-
- [`Scripts`](src/interfaces/scripts.ts)
119-
120-
### Types
121-
122-
- [`Access`](src/types/access.ts)
123-
- [`Bin`](src/types/bin.ts)
124-
- [`Browser`](src/types/browser.ts)
125-
- [`Bugs`](src/types/bugs.ts)
126-
- [`CPU`](src/types/cpu.ts)
127-
- [`DependencyMeta`](src/types/dependency-meta.ts)
128-
- [`Engine`](src/types/engine.ts)
129-
- [`Engines`](src/types/engines.ts)
130-
- [`ExportCondition`](src/types/export-condition.ts)
131-
- [`ExportConditions`](src/types/export-conditions.ts)
132-
- [`Exports`](src/types/exports.ts)
133-
- [`FundingInfo`](src/types/funding-info.ts)
134-
- [`FundingType`](src/types/funding-type.ts)
135-
- [`HoistingLimits`](src/types/hoisiting-limits.ts)
136-
- [`ImportsKey`](src/types/imports-key.ts)
137-
- [`Imports`](src/types/imports.ts)
138-
- [`InstallConfig`](src/types/install-config.ts)
139-
- [`LicenseObject`](src/types/license-object.ts)
140-
- [`OS`](src/types/os.ts)
141-
- [`PeerDependencyMeta`](src/types/peer-dependency-meta.ts)
142-
- [`Person`](src/types/person.ts)
143-
- [`Registry`](src/types/registry.ts)
144-
- [`Repository`](src/types/repository.ts)
145-
- [`SemanticVersion`](src/types/semantic-version.ts)
146-
- [`Type`](src/types/type.ts)
147-
- [`TypesVersions`](src/types/types-versions.ts)
148-
- [`WorkspacesConfig`](src/types/workspaces-config.ts)
64+
- [`Access`](./src/access.ts)
65+
- [`Bin`](./src/bin.ts)
66+
- [`BinObject`](./src/bin-object.ts)
67+
- [`Browser`](./src/browser.ts)
68+
- [`BrowserObject`](./src/browser-object.ts)
69+
- [`Bugs`](./src/bugs.ts)
70+
- [`Condition`](./src/condition.ts)
71+
- [`ConditionMap`](./src/condition-map.ts)
72+
- [`Config`](./src/config.ts)
73+
- [`CPU`](./src/cpu.ts)
74+
- [`CPUMap`](./src/cpu-map.ts)
75+
- [`Dependencies`](./src/dependencies.ts)
76+
- [`DevDependencies`](./src/dev-dependencies.ts)
77+
- [`Directories`](./src/directories.ts)
78+
- [`Engine`](./src/engine.ts)
79+
- [`EngineMap`](./src/engine-map.ts)
80+
- [`Engines`](./src/engines.ts)
81+
- [`ExportConditions`](./src/export-conditions.ts)
82+
- [`Exports`](./src/exports.ts)
83+
- [`ExportsKey`](./src/exports-key.ts)
84+
- [`ExportsList`](./src/exports-list.ts)
85+
- [`ExportsObject`](./src/exports-object.ts)
86+
- [`ImportConditions`](./src/import-conditions.ts)
87+
- [`Imports`](./src/imports.ts)
88+
- [`ImportsKey`](./src/imports-key.ts)
89+
- [`JsonArray`](./src/json-array.ts)
90+
- [`JsonObject`](./src/json-object.ts)
91+
- [`JsonPrimitive`](./src/json-primitive.ts)
92+
- [`JsonValue`](./src/json-value.ts)
93+
- [`LicenseInfo`](./src/license-info.ts)
94+
- [`OptionalDependencies`](./src/optional-dependencies.ts)
95+
- [`OS`](./src/os.ts)
96+
- [`OSMap`](./src/os-map.ts)
97+
- [`PackageJson`](./src/package-json.ts)
98+
- [`PackageManager`](./src/package-manager.ts)
99+
- [`PackageManagerMap`](./src/package-manager-map.ts)
100+
- [`PackageType`](./src/package-type.ts)
101+
- [`PeerDependencies`](./src/peer-dependencies.ts)
102+
- [`PeerDependenciesMeta`](./src/peer-dependencies-meta.ts)
103+
- [`PeerDependencyMetadata`](./src/peer-dependency-metadata.ts)
104+
- [`People`](./src/people.ts)
105+
- [`Person`](./src/person.ts)
106+
- [`PublishConfig`](./src/publish-config.ts)
107+
- [`RepositoryInfo`](./src/repository-info.ts)
108+
- [`RepositoryType`](./src/repository-type.ts)
109+
- [`RepositoryTypeMap`](./src/repository-type-map.ts)
110+
- [`Scripts`](./src/scripts.ts)
111+
- [`SemanticVersion`](./src/semantic-version.ts)
112+
- [`SubpathExports`](./src/subpath-exports.ts)
113+
- [`TypesVersions`](./src/types-versions.ts)
114+
- [`WorkspacesConfig`](./src/workspaces-config.ts)
149115

150116
## Related
151117

@@ -155,7 +121,8 @@ Need this functionality? See [`toggle-pkg-type`][toggle-pkg-type] \:blush:
155121

156122
See [`CONTRIBUTING.md`](CONTRIBUTING.md).
157123

158-
[toggle-pkg-type]: https://github.com/flex-development/toggle-pkg-type
124+
This project has a [code of conduct](./CODE_OF_CONDUCT.md). By interacting with this repository, organization, or
125+
community you agree to abide by its terms.
159126

160127
[tsconfig-types]: https://github.com/flex-development/tsconfig-types
161128

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"type": "module",
3333
"files": [
3434
"CHANGELOG.md",
35+
"LICENSE.md",
36+
"README.md",
3537
"dist"
3638
],
3739
"exports": {
@@ -195,9 +197,6 @@
195197
"vitest": "2.0.5",
196198
"yaml-eslint-parser": "1.2.3"
197199
},
198-
"peerDependencies": {
199-
"@flex-development/tutils": ">=6.0.0-alpha.7"
200-
},
201200
"packageManager": "yarn@4.4.0",
202201
"sideEffects": false
203202
}
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
/**
22
* @file Unit Tests - Access
3-
* @module pkg-types/types/tests/Access
3+
* @module pkg-types/tests/unit-d/Access
44
*/
55

6-
import type { JsonValue } from '@flex-development/tutils'
76
import type TestSubject from '../access'
87

9-
describe('unit:types/Access', () => {
10-
it('should be json value', () => {
11-
expectTypeOf<TestSubject>().toMatchTypeOf<JsonValue>()
12-
})
13-
8+
describe('unit-d:Access', () => {
149
it('should extract "public"', () => {
1510
expectTypeOf<TestSubject>().extract<'public'>().toBeString()
1611
})

src/__tests__/bin-object.spec-d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @file Unit Tests - BinObject
3+
* @module pkg-types/tests/unit-d/BinObject
4+
*/
5+
6+
import type TestSubject from '../bin-object'
7+
8+
describe('unit-d:BinObject', () => {
9+
it('should allow empty object', () => {
10+
assertType<TestSubject>({})
11+
})
12+
13+
it('should match Record<string, string>', () => {
14+
expectTypeOf<TestSubject>().toMatchTypeOf<Record<string, string>>()
15+
})
16+
})

src/__tests__/bin.spec-d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @file Unit Tests - Bin
3+
* @module pkg-types/tests/unit-d/Bin
4+
*/
5+
6+
import type TestSubject from '../bin'
7+
import type BinObject from '../bin-object'
8+
9+
describe('unit-d:Bin', () => {
10+
it('should extract BinObject', () => {
11+
expectTypeOf<TestSubject>().extract<BinObject>().not.toBeNever()
12+
})
13+
14+
it('should extract string', () => {
15+
expectTypeOf<TestSubject>().extract<string>().not.toBeNever()
16+
})
17+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @file Unit Tests - BrowserObject
3+
* @module pkg-types/tests/unit-d/BrowserObject
4+
*/
5+
6+
import type TestSubject from '../browser-object'
7+
8+
describe('unit-d:BrowserObject', () => {
9+
it('should match Record<string, string | false>', () => {
10+
expectTypeOf<TestSubject>().toMatchTypeOf<Record<string, string | false>>()
11+
})
12+
})

src/__tests__/browser.spec-d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @file Unit Tests - Browser
3+
* @module pkg-types/tests/unit-d/Browser
4+
*/
5+
6+
import type TestSubject from '../browser'
7+
import type BrowserObject from '../browser-object'
8+
9+
describe('unit-d:Browser', () => {
10+
it('should extract BrowserObject', () => {
11+
expectTypeOf<TestSubject>().extract<BrowserObject>().not.toBeNever()
12+
})
13+
14+
it('should extract string', () => {
15+
expectTypeOf<TestSubject>().extract<string>().not.toBeNever()
16+
})
17+
})

src/__tests__/bugs.spec-d.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @file Unit Tests - Bugs
3+
* @module pkg-types/tests/unit-d/Bugs
4+
*/
5+
6+
import type { Nilable } from '@flex-development/tutils'
7+
import type TestSubject from '../bugs'
8+
import type JsonObject from '../json-object'
9+
10+
describe('unit-d:Bugs', () => {
11+
it('should allow empty object', () => {
12+
assertType<TestSubject>({})
13+
})
14+
15+
it('should extend JsonObject', () => {
16+
expectTypeOf<TestSubject>().toMatchTypeOf<JsonObject>()
17+
})
18+
19+
it('should match [email?: string | null]', () => {
20+
expectTypeOf<TestSubject>()
21+
.toHaveProperty('email')
22+
.toEqualTypeOf<Nilable<string>>()
23+
})
24+
25+
it('should match [url?: string]', () => {
26+
expectTypeOf<TestSubject>()
27+
.toHaveProperty('url')
28+
.toEqualTypeOf<Nilable<string>>()
29+
})
30+
})

0 commit comments

Comments
 (0)