Skip to content

Commit d19f510

Browse files
committed
fix(core): createFileAsync() types of param data
nodejs v14 not accepts `number` BREAKING CHANGES: narrow from `any`
1 parent 094c961 commit d19f510

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/core/src/lib/utils.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,12 @@ export async function createDirAsync(path: string): Promise<string> {
148148
*
149149
* @requires string - created file path
150150
*/
151-
export async function createFileAsync(file: string, data: any, options?: WriteFileOptions): Promise<string> {
151+
export async function createFileAsync(
152+
file: string,
153+
data: string | NodeJS.ArrayBufferView | number | Record<PropertyKey, unknown>,
154+
options?: WriteFileOptions,
155+
): Promise<string> {
156+
152157
const dir = dirname(file)
153158

154159
/* istanbul ignore next */
@@ -170,6 +175,9 @@ export async function createFileAsync(file: string, data: any, options?: WriteFi
170175
else if (typeof data === 'object') {
171176
await writeFileAsync(path, JSON.stringify(data))
172177
}
178+
else if (typeof data === 'number') {
179+
await writeFileAsync(path, data.toString(), opts)
180+
}
173181
else {
174182
await writeFileAsync(path, data, opts)
175183
}

packages/core/test/10.isFileExists.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe(filename, () => {
4141
const fnName = 'fileExist'
4242

4343
it(`Should ${fnName}() works`, async () => {
44-
const random = Math.random()
44+
const random = Math.random().toString()
4545
const randomPath = `${tmpDir}/${pathPrefix}-${random}`
4646
const file = `${randomPath}/test`
4747

0 commit comments

Comments
 (0)