fix(api): do not report the same deprecation warning more than once (#5774)
A quick fix for suppressing duplicate deprecation warnings.master
parent
3d7970a673
commit
a9fd8e2cf4
|
@ -46,6 +46,8 @@ class FlagSchema extends vnopts.ChoiceSchema {
|
|||
}
|
||||
}
|
||||
|
||||
let hasDeprecationWarned;
|
||||
|
||||
function normalizeOptions(
|
||||
options,
|
||||
optionInfos,
|
||||
|
@ -60,7 +62,25 @@ function normalizeOptions(
|
|||
|
||||
const descriptor = isCLI ? cliDescriptor : vnopts.apiDescriptor;
|
||||
const schemas = optionInfosToSchemas(optionInfos, { isCLI });
|
||||
return vnopts.normalize(options, schemas, { logger, unknown, descriptor });
|
||||
const normalizer = new vnopts.Normalizer(schemas, {
|
||||
logger,
|
||||
unknown,
|
||||
descriptor
|
||||
});
|
||||
|
||||
const shouldSuppressDuplicateDeprecationWarnings = logger !== false;
|
||||
|
||||
if (shouldSuppressDuplicateDeprecationWarnings && hasDeprecationWarned) {
|
||||
normalizer._hasDeprecationWarned = hasDeprecationWarned;
|
||||
}
|
||||
|
||||
const normalized = normalizer.normalize(options);
|
||||
|
||||
if (shouldSuppressDuplicateDeprecationWarnings) {
|
||||
hasDeprecationWarned = normalizer._hasDeprecationWarned;
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
function optionInfosToSchemas(optionInfos, { isCLI }) {
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`API format with deprecated parser (babylon) should work 1`] = `
|
||||
"{ parser: \\"babylon\\" } is deprecated; we now treat it as { parser: \\"babel\\" }.
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`API format with deprecated parser (postcss) should work 1`] = `
|
||||
"{ parser: \\"postcss\\" } is deprecated; we now treat it as { parser: \\"css\\" }.
|
||||
"
|
||||
|
|
|
@ -25,9 +25,13 @@ test("API format with deprecated parser (postcss) should work", () => {
|
|||
expect(warnings).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("API format with deprecated parser (babylon) should work", () => {
|
||||
expect(() =>
|
||||
prettier.format("hello_world( )", { parser: "babylon" })
|
||||
).not.toThrowError();
|
||||
expect(warnings).toMatchSnapshot();
|
||||
test("API format with deprecated parser (babylon) should work and do not report the same deprecation warning more than once", () => {
|
||||
expect(() => {
|
||||
prettier.format("hello_world( )", { parser: "babylon" });
|
||||
prettier.format("hello_world( )", { parser: "babylon" });
|
||||
}).not.toThrowError();
|
||||
expect(warnings).toMatchInlineSnapshot(`
|
||||
"{ parser: \\"babylon\\" } is deprecated; we now treat it as { parser: \\"babel\\" }.
|
||||
"
|
||||
`);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue