Skip to content

Commit a1b23fb

Browse files
authored
fix: change the return value of the diff API to an object (#181)
1 parent 06061a6 commit a1b23fb

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/commands/diff.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const handler = async (args: Arguments<DiffOptions>): Promise<unknown> =>
6464
provider, conf, normalize, target, locale, targetPaths, filenameMatch
6565
})
6666

67-
if (ret) {
67+
if (Object.keys(ret).length) {
6868
return Promise.reject(new DiffError('There are differences!'))
6969
}
7070
return Promise.resolve()

src/utils.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import {
1818
NamespaceDictionary,
1919
PushableOptions,
2020
DiffOptions,
21-
PushOptions
21+
PushOptions,
22+
diffInfo
2223
} from '../types'
2324

2425
// import modules
@@ -33,7 +34,7 @@ import deepmerge from 'deepmerge'
3334
import { promisify } from 'util'
3435
import type { Ignore } from 'ignore'
3536
import querystring from 'query-string'
36-
const { diffString } = require('json-diff') // NOTE: not provided type definition ...
37+
const jsonDiff = require('json-diff') // NOTE: not provided type definition ...
3738

3839
import { debug as Debug } from 'debug'
3940
const debug = Debug('vue-i18n-locale-message:utils')
@@ -450,7 +451,7 @@ export function returnIgnoreInstance (ig: Ignore, ignoreFiles: string[]): void {
450451
})
451452
}
452453

453-
export async function isDifferent (options: DiffOptions): Promise<boolean> {
454+
export async function isDifferent (options: DiffOptions): Promise<diffInfo> {
454455
const format = 'json'
455456
const ProviderFactory = loadProvider(options.provider)
456457

@@ -472,13 +473,14 @@ export async function isDifferent (options: DiffOptions): Promise<boolean> {
472473
const locales = Object.keys(localeMessages) as Locale[]
473474
const serviceMessages = await provider.pull({ locales, dryRun: false, normalize: options.normalize, format })
474475

475-
const ret = diffString(serviceMessages, localeMessages)
476+
const ret = jsonDiff.diffString(serviceMessages, localeMessages)
476477
console.log(ret)
477478

478479
if (ret) {
479-
return Promise.resolve(true)
480+
const diffObj = jsonDiff.diff(serviceMessages, localeMessages)
481+
return Promise.resolve(diffObj)
480482
} else {
481-
return Promise.resolve(false)
483+
return Promise.resolve({})
482484
}
483485
}
484486

types/index.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,12 @@ export type DiffOptions = {
224224
normalize?: string
225225
} & PushableOptions
226226

227-
declare function diff (options: DiffOptions): Promise<boolean>
227+
export type diffInfo = {
228+
__old?: any
229+
__new?: any
230+
}
231+
232+
declare function diff (options: DiffOptions): Promise<diffInfo>
228233

229234
/**
230235
* Provider factory function

0 commit comments

Comments
 (0)