diff --git a/.changesets/report-client-file-presence-in-diagnose-result.md b/.changesets/report-client-file-presence-in-diagnose-result.md new file mode 100644 index 00000000..8f7b17fe --- /dev/null +++ b/.changesets/report-client-file-presence-in-diagnose-result.md @@ -0,0 +1,6 @@ +--- +bump: "patch" +type: "add" +--- + +The diagnose CLI command now reports on the presence of the `appsignal.cjs` file. diff --git a/src/__tests__/config.test.ts b/src/__tests__/config.test.ts index e6aeb3ee..07b63cc6 100644 --- a/src/__tests__/config.test.ts +++ b/src/__tests__/config.test.ts @@ -216,6 +216,42 @@ describe("Configuration", () => { }) }) + describe("clientFilePath", () => { + describe("when the client file exists in the root path", () => { + it("returns the path to the client file", () => { + jest.spyOn(fs, "existsSync").mockImplementation(givenPath => { + return givenPath === path.join(process.cwd(), "appsignal.cjs") + }) + config = new Configuration({ name, pushApiKey }) + + expect(config.clientFilePath).toEqual( + path.join(process.cwd(), "appsignal.cjs") + ) + }) + }) + + describe("when the client file exists in the src path", () => { + it("returns the path to the client file", () => { + jest.spyOn(fs, "existsSync").mockImplementation(givenPath => { + return givenPath === path.join(process.cwd(), "src", "appsignal.cjs") + }) + config = new Configuration({ name, pushApiKey }) + + expect(config.clientFilePath).toEqual( + path.join(process.cwd(), "src", "appsignal.cjs") + ) + }) + }) + + describe("when the client file does not exist", () => { + it("returns undefined", () => { + config = new Configuration({ name, pushApiKey }) + + expect(config.clientFilePath).toBeUndefined() + }) + }) + }) + describe("private environment variables", () => { beforeEach(() => { new Configuration({}) diff --git a/src/cli/diagnose.ts b/src/cli/diagnose.ts index bcbc7ca4..f2735c1e 100644 --- a/src/cli/diagnose.ts +++ b/src/cli/diagnose.ts @@ -181,6 +181,13 @@ export class Diagnose { this.print_newline() + console.log(` AppSignal client file`) + console.log( + ` Path: ${format_value(data["paths"]["appsignal.cjs"]["path"])}` + ) + + this.print_newline() + console.log(` AppSignal log`) console.log( ` Path: ${format_value(data["paths"]["appsignal.log"]["path"])}` diff --git a/src/config.ts b/src/config.ts index 5a74836e..d0e9c966 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,6 @@ import path from "path" import os from "os" +import fs from "fs" import { VERSION } from "./version" import { isWritable } from "./utils" @@ -74,6 +75,18 @@ export class Configuration { } } + public get clientFilePath(): string | undefined { + const filename = "appsignal.cjs" + + if (fs.existsSync(path.join(process.cwd(), filename))) { + return path.join(process.cwd(), filename) + } else if (fs.existsSync(path.join(process.cwd(), "src", filename))) { + return path.join(process.cwd(), "src", filename) + } else { + return undefined + } + } + /** * Returns default OS tmp dir. Uses OS package for Windows. Linux and macOS * have `/tmp` hardcoded as a default diff --git a/src/diagnose.ts b/src/diagnose.ts index eba25220..ec805b59 100644 --- a/src/diagnose.ts +++ b/src/diagnose.ts @@ -147,7 +147,6 @@ export class DiagnoseTool { private getPathsData() { const paths: { [key: string]: FileMetadata } = {} - const logFilePath = this.#config.logFilePath const pathsToCheck = { @@ -157,6 +156,9 @@ export class DiagnoseTool { log_dir_path: { path: logFilePath ? path.dirname(logFilePath) : "" }, + "appsignal.cjs": { + path: this.#config.clientFilePath || "" + }, "appsignal.log": { path: logFilePath || "", content: logFilePath diff --git a/test/integration/diagnose b/test/integration/diagnose index d0c79e53..d67ba380 160000 --- a/test/integration/diagnose +++ b/test/integration/diagnose @@ -1 +1 @@ -Subproject commit d0c79e53a5e944220886e8b65612e4d520237976 +Subproject commit d67ba3804a38e99baadb75198e252804b1563dd3