Skip to content

Commit 764a561

Browse files
committed
fix(helpers): make deep props optional
1 parent 3bd5df6 commit 764a561

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/index.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'graceful-fs'
22
import { join } from 'path'
3-
import { PackageJson, TsConfigJson } from 'type-fest'
3+
import { PackageJson, PartialDeep, TsConfigJson } from 'type-fest'
44
import { JsonRoot, loadJsonFile } from './loadJsonFile'
55

66
type MaybePromise<T> = T | Promise<T>
@@ -128,22 +128,18 @@ export const modifyJsonFile: ModifyJsonFileGenericFunction = async (path, modify
128128

129129
// todo: use read-pkg / write-pkg for normalization
130130

131-
type TEST = 'HAYA'
132-
133-
/** Use {@linkcode TEST instead} */
134-
const d = 5
135-
136131
/**
137132
* Almost the same is sindresorhus/write-pkg, but with proper typing support and setters for properties
138133
*/
139-
export const modifyPackageJsonFile: ModifyJsonFileFunction<PackageJson, true> = (path, modify, options = {}) => {
134+
// TODO remove workaround once my pr is merged
135+
export const modifyPackageJsonFile: ModifyJsonFileFunction<PartialDeep<PackageJson>, true> = (path, modify, options = {}) => {
140136
if (typeof path === 'object') {
141137
path = join(path.dir, 'package.json')
142138
}
143139
return modifyJsonFile(path, modify, { removeJsonc: true, ...options })
144140
}
145141

146-
export const modifyTsConfigJsonFile: ModifyJsonFileFunction<TsConfigJson, true> = (path, modify, options = {}) => {
142+
export const modifyTsConfigJsonFile: ModifyJsonFileFunction<PartialDeep<TsConfigJson>, true> = (path, modify, options = {}) => {
147143
if (typeof path === 'object') {
148144
path = join(path.dir, 'tsconfig.json')
149145
}

test-d/index.test-d.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expectType } from 'tsd'
22

33
// TODO-high map to build/ only on script run somehow
44
import { modifyJsonFile, modifyPackageJsonFile } from 'modify-json-file'
5+
import { PackageJson, PartialDeep } from 'type-fest';
56

67
modifyJsonFile('path.json', {
78
value: 5,
@@ -23,7 +24,7 @@ modifyJsonFile<number>('path.json', n => {
2324
return n + 5
2425
})
2526

26-
modifyPackageJsonFile('someDirWithPackageJson', {
27+
modifyPackageJsonFile('', {
2728
name: name => `@supertf/${name}`,
2829
dependencies: {
2930
string: 'string',
@@ -34,6 +35,18 @@ modifyPackageJsonFile('someDirWithPackageJson', {
3435
},
3536
files: undefined,
3637
// removing react-scripts from devDependencies
37-
// TODO
38-
// devDependencies: deps => ({ ...deps, 'react-script': undefined }),
38+
devDependencies: deps => ({ ...deps, 'react-script': undefined }),
3939
})
40+
41+
const b: PartialDeep<PackageJson> = {
42+
// typesVersions: {
43+
// ">=4": {
44+
// "*": undefined
45+
// }
46+
// }
47+
scripts: {
48+
install: undefined
49+
}
50+
}
51+
52+
modifyPackageJsonFile({ dir: '.' }, old => ({ files: undefined }))

0 commit comments

Comments
 (0)