-
Notifications
You must be signed in to change notification settings - Fork 885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CCI] Fix type errors in i18n #3629
Changes from 2 commits
00d016c
cdda27b
cc6494b
8b22e9b
5b68cf6
efbcbdb
f9fef23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,9 +41,14 @@ import { | |
mergeConfigs, | ||
} from './i18n/tasks'; | ||
|
||
const skipOnNoTranslations = ({ config }: { config: I18nConfig }) => | ||
!config.translations.length && 'No translations found.'; | ||
export interface ListrContext { | ||
config?: I18nConfig; | ||
reporter: ErrorReporter; | ||
messages: Map<string, { message: string }>; | ||
} | ||
|
||
const skipOnNoTranslations = (context: ListrContext) => | ||
!context.config?.translations?.length && 'No translations found.'; | ||
run( | ||
async ({ | ||
flags: { | ||
|
@@ -105,16 +110,17 @@ run( | |
{ | ||
title: 'Validating Default Messages', | ||
skip: skipOnNoTranslations, | ||
task: ({ config }) => | ||
new Listr(extractDefaultMessages(config, srcPaths), { exitOnError: true }), | ||
task: ({ config }) => { | ||
return new Listr(extractDefaultMessages(config!, srcPaths), { exitOnError: true }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are already handling for a missing config value in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can skipOnNoTranslations do a throw error if there is no config? So as not to create more checks. Although these functions will be used anyway and there is no other way to check if the config is in one place |
||
}, | ||
}, | ||
{ | ||
title: 'Compatibility Checks', | ||
skip: skipOnNoTranslations, | ||
task: ({ config }) => | ||
task: ({ config }) => { | ||
Nicksqain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
new Listr( | ||
checkCompatibility( | ||
config, | ||
config!, | ||
Nicksqain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
ignoreMalformed: !!ignoreMalformed, | ||
ignoreIncompatible: !!ignoreIncompatible, | ||
|
@@ -125,7 +131,8 @@ run( | |
log | ||
), | ||
{ exitOnError: true } | ||
), | ||
); | ||
}, | ||
}, | ||
], | ||
{ | ||
|
@@ -138,7 +145,7 @@ run( | |
const reporter = new ErrorReporter(); | ||
const messages: Map<string, { message: string }> = new Map(); | ||
await list.run({ messages, reporter }); | ||
} catch (error) { | ||
} catch (error: ErrorReporter | Error) { | ||
process.exitCode = 1; | ||
if (error instanceof ErrorReporter) { | ||
error.errors.forEach((e: string | Error) => log.error(e)); | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -35,7 +35,7 @@ import { resolve } from 'path'; | |||||
import { createFailError, run } from '@osd/dev-utils'; | ||||||
import { ErrorReporter, serializeToJson, serializeToJson5, writeFileAsync } from './i18n'; | ||||||
import { extractDefaultMessages, mergeConfigs } from './i18n/tasks'; | ||||||
|
||||||
import { ListrContext } from './run_i18n_check'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This can come from a common source instead of another file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not know how you import :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ./i18n/tasks. Right? |
||||||
run( | ||||||
async ({ | ||||||
flags: { | ||||||
|
@@ -59,19 +59,19 @@ run( | |||||
} | ||||||
const srcPaths = Array().concat(path || ['./src', './packages']); | ||||||
|
||||||
const list = new Listr([ | ||||||
const list = new Listr<ListrContext>([ | ||||||
{ | ||||||
title: 'Merging .i18nrc.json files', | ||||||
task: () => new Listr(mergeConfigs(includeConfig), { exitOnError: true }), | ||||||
}, | ||||||
{ | ||||||
title: 'Extracting Default Messages', | ||||||
task: ({ config }) => | ||||||
new Listr(extractDefaultMessages(config, srcPaths), { exitOnError: true }), | ||||||
new Listr(extractDefaultMessages(config!, srcPaths), { exitOnError: true }), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
update |
||||||
}, | ||||||
{ | ||||||
title: 'Writing to file', | ||||||
enabled: (ctx) => outputDir && ctx.messages.size, | ||||||
enabled: (ctx) => Boolean(outputDir && ctx.messages.size), | ||||||
task: async (ctx) => { | ||||||
const sortedMessages = [...ctx.messages].sort(([key1], [key2]) => | ||||||
key1.localeCompare(key2) | ||||||
|
@@ -90,7 +90,7 @@ run( | |||||
const reporter = new ErrorReporter(); | ||||||
const messages: Map<string, { message: string }> = new Map(); | ||||||
await list.run({ messages, reporter }); | ||||||
} catch (error) { | ||||||
} catch (error: ErrorReporter | Error) { | ||||||
process.exitCode = 1; | ||||||
if (error instanceof ErrorReporter) { | ||||||
error.errors.forEach((e: string | Error) => log.error(e)); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ import Listr from 'listr'; | |
import { createFailError, run } from '@osd/dev-utils'; | ||
import { ErrorReporter, integrateLocaleFiles } from './i18n'; | ||
import { extractDefaultMessages, mergeConfigs } from './i18n/tasks'; | ||
import { ListrContext } from './run_i18n_check'; | ||
|
||
run( | ||
async ({ | ||
|
@@ -90,30 +91,32 @@ run( | |
|
||
const srcPaths = Array().concat(path || ['./src', './packages']); | ||
|
||
const list = new Listr([ | ||
const list = new Listr<ListrContext>([ | ||
{ | ||
title: 'Merging .i18nrc.json files', | ||
task: () => new Listr(mergeConfigs(includeConfig), { exitOnError: true }), | ||
}, | ||
{ | ||
title: 'Extracting Default Messages', | ||
task: ({ config }) => | ||
new Listr(extractDefaultMessages(config, srcPaths), { exitOnError: true }), | ||
new Listr(extractDefaultMessages(config!, srcPaths), { exitOnError: true }), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, you dont need this change |
||
}, | ||
{ | ||
title: 'Integrating Locale File', | ||
task: async ({ messages, config }) => { | ||
await integrateLocaleFiles(messages, { | ||
sourceFileName: source, | ||
targetFileName: target, | ||
dryRun, | ||
ignoreIncompatible, | ||
ignoreUnused, | ||
ignoreMissing, | ||
ignoreMalformed, | ||
config, | ||
log, | ||
}); | ||
if (config) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like you pattern of throwing an error if config is missing instead of this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you missed this change. The reason i like throwing an error is because it makes it clear why the task failed. The config should never be empty, but if it is, based on this change this task will complete silently, but the other tasks like |
||
await integrateLocaleFiles(messages, { | ||
sourceFileName: source, | ||
targetFileName: target, | ||
dryRun, | ||
ignoreIncompatible, | ||
ignoreUnused, | ||
ignoreMissing, | ||
ignoreMalformed, | ||
config, | ||
log, | ||
}); | ||
} | ||
}, | ||
}, | ||
]); | ||
|
@@ -123,7 +126,7 @@ run( | |
const messages: Map<string, { message: string }> = new Map(); | ||
await list.run({ messages, reporter }); | ||
process.exitCode = 0; | ||
} catch (error) { | ||
} catch (error: ErrorReporter | Error) { | ||
process.exitCode = 1; | ||
if (error instanceof ErrorReporter) { | ||
error.errors.forEach((e: string | Error) => log.error(e)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this nesting required? Cant you simply change the if condition to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure if the error would be instance of parser.SyntaxError, so I left it so to get your opinion. I'll change it if it's right