-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement(core): warn on large file count in modules
This includes a new command and mechanism to suppress individual warnings. We can use that to emit more warnings of this nature, where the warning may or may not be relevant and could be annoying to see on every invocation.
- Loading branch information
Showing
12 changed files
with
257 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { Command, CommandParams } from "../base" | ||
import dedent from "dedent" | ||
import { StringParameter } from "../../cli/params" | ||
import { Warning } from "../../db/entities/warning" | ||
|
||
const hideWarningArgs = { | ||
key: new StringParameter({ | ||
help: "The key of the warning to hide (this will be shown along with relevant warning messages).", | ||
required: true, | ||
}), | ||
} | ||
|
||
type Args = typeof hideWarningArgs | ||
|
||
export class HideWarningCommand extends Command<Args, {}> { | ||
name = "hide-warning" | ||
help = "Hide a specific warning message." | ||
cliOnly = true | ||
|
||
noProject = true | ||
|
||
description = dedent` | ||
Hides the specified warning message. The command and key is generally provided along with displayed warning messages. | ||
` | ||
|
||
arguments = hideWarningArgs | ||
|
||
async action({ args }: CommandParams<Args, {}>) { | ||
await Warning.hide(args.key) | ||
|
||
return {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { Entity, Column, Index } from "typeorm" | ||
import { GardenEntity } from "../base-entity" | ||
import { LogEntry } from "../../logger/log-entry" | ||
import chalk from "chalk" | ||
|
||
/** | ||
* Provides a mechanism to emit warnings that the user can then hide, via the `garden util hide-warning` command. | ||
*/ | ||
@Entity() | ||
@Index(["key"], { unique: true }) | ||
export class Warning extends GardenEntity { | ||
@Column() | ||
key: string | ||
|
||
@Column() | ||
hidden: boolean | ||
|
||
static async emit({ key, log, message }: { key: string; log: LogEntry; message: string }) { | ||
const existing = await this.findOne({ where: { key } }) | ||
|
||
if (!existing || !existing.hidden) { | ||
log.warn( | ||
chalk.yellow(message + `\nRun ${chalk.underline(`garden util hide-warning ${key}`)} to disable this warning.`) | ||
) | ||
} | ||
} | ||
|
||
static async hide(key: string) { | ||
try { | ||
await this.createQueryBuilder().insert().values({ key, hidden: true }).execute() | ||
} catch {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { withDefaultGlobalOpts, getLogMessages, projectRootA } from "../../../../helpers" | ||
import { expect } from "chai" | ||
import { Warning } from "../../../../../src/db/entities/warning" | ||
import { getConnection } from "../../../../../src/db/connection" | ||
import { HideWarningCommand } from "../../../../../src/commands/util/hide-warning" | ||
import { makeDummyGarden } from "../../../../../src/cli/cli" | ||
import { randomString } from "../../../../../src/util/string" | ||
|
||
describe("HideWarningCommand", () => { | ||
it("should hide a warning message", async () => { | ||
const garden = await makeDummyGarden(projectRootA) | ||
const log = garden.log.placeholder() | ||
const cmd = new HideWarningCommand() | ||
const key = randomString(10) | ||
|
||
try { | ||
await cmd.action({ | ||
garden, | ||
args: { key }, | ||
opts: withDefaultGlobalOpts({}), | ||
log: garden.log, | ||
headerLog: garden.log, | ||
footerLog: garden.log, | ||
}) | ||
await Warning.emit({ | ||
key, | ||
log, | ||
message: "foo", | ||
}) | ||
expect(getLogMessages(log).length).to.equal(0) | ||
} finally { | ||
await getConnection().getRepository(Warning).createQueryBuilder().delete().where({ key }).execute() | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { expect } from "chai" | ||
import { randomString } from "../../../../../src/util/string" | ||
import { ensureConnected, getConnection } from "../../../../../src/db/connection" | ||
import { Warning } from "../../../../../src/db/entities/warning" | ||
import { getLogger } from "../../../../../src/logger/logger" | ||
import { getLogMessages } from "../../../../helpers" | ||
|
||
describe("Warning", () => { | ||
const key = randomString(10) | ||
|
||
before(async () => { | ||
await ensureConnected() | ||
}) | ||
|
||
afterEach(async () => { | ||
await getConnection().getRepository(Warning).createQueryBuilder().delete().where({ key }).execute() | ||
}) | ||
|
||
describe("hide", () => { | ||
it("should flag a warning key as hidden", async () => { | ||
await Warning.hide(key) | ||
const record = await Warning.findOneOrFail({ where: { key } }) | ||
expect(record.hidden).to.be.true | ||
}) | ||
|
||
it("should be a no-op if a key is already hidden", async () => { | ||
await Warning.hide(key) | ||
await Warning.hide(key) | ||
}) | ||
}) | ||
|
||
describe("emit", () => { | ||
it("should log a warning if the key has not been hidden", async () => { | ||
const log = getLogger().placeholder() | ||
const message = "Oh noes!" | ||
await Warning.emit({ key, log, message }) | ||
const logs = getLogMessages(log) | ||
expect(logs.length).to.equal(1) | ||
expect(logs[0]).to.equal(message + `\nRun garden util hide-warning ${key} to disable this warning.`) | ||
}) | ||
|
||
it("should not log a warning if the key has been hidden", async () => { | ||
const log = getLogger().placeholder() | ||
const message = "Oh noes!" | ||
await Warning.hide(key) | ||
await Warning.emit({ key, log, message }) | ||
const logs = getLogMessages(log) | ||
expect(logs.length).to.equal(0) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.