From ebc7305873b4cec536e3172c642d951493b5889e Mon Sep 17 00:00:00 2001 From: Noemi <45180344+unflxw@users.noreply.github.com> Date: Tue, 23 Apr 2024 10:39:27 +0200 Subject: [PATCH 1/2] Use `isomorphic-unfetch@4.0.0` specifically An issue with `unfetch@5`, depended on by `isomorphic-unfetch@4.0.2`, breaks bundling with tools such as `esbuild` and `webpack`: https://github.com/developit/unfetch/pull/164 --- packages/core/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/package.json b/packages/core/package.json index 4c9b4232..97cb378f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -26,7 +26,7 @@ }, "dependencies": { "@appsignal/types": "=3.0.1", - "isomorphic-unfetch": "^4.0.0", + "isomorphic-unfetch": "=4.0.0", "tslib": "^2.3.0" } } From 6ae655af7ae04c75ce88893f7551a9c77420402a Mon Sep 17 00:00:00 2001 From: Noemi <45180344+unflxw@users.noreply.github.com> Date: Tue, 23 Apr 2024 10:57:38 +0200 Subject: [PATCH 2/2] Move `isomorphic-unfetch` dependency `isomorphic-unfetch` is only used in `@appsignal/core` to perform a push API validation request. This request is only ever performed by the CLI package. Move the push API validation request function to `@appsignal/cli` alongside with the dependency on `isomorphic-unfetch`, and remove `@appsignal/cli`'s dependency on `@appsignal/core`. --- .../remove-dependency-on---appsignal-core-.md | 6 +++++ packages/cli/package.json | 2 +- packages/cli/src/installers/node/index.ts | 2 +- packages/cli/src/utils.ts | 22 +++++++++++++++++++ ...move-dependency-on--isomorphic-unfetch-.md | 7 ++++++ packages/core/package.json | 1 - packages/core/src/index.ts | 1 - packages/core/src/utils/push-api.ts | 22 ------------------- 8 files changed, 37 insertions(+), 26 deletions(-) create mode 100644 packages/cli/.changesets/remove-dependency-on---appsignal-core-.md create mode 100644 packages/core/.changesets/remove-dependency-on--isomorphic-unfetch-.md delete mode 100644 packages/core/src/utils/push-api.ts diff --git a/packages/cli/.changesets/remove-dependency-on---appsignal-core-.md b/packages/cli/.changesets/remove-dependency-on---appsignal-core-.md new file mode 100644 index 00000000..8ed954ca --- /dev/null +++ b/packages/cli/.changesets/remove-dependency-on---appsignal-core-.md @@ -0,0 +1,6 @@ +--- +bump: "patch" +type: "remove" +--- + +Remove dependency on `@appsignal/core`. diff --git a/packages/cli/package.json b/packages/cli/package.json index 91f6eb31..d2970881 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -20,7 +20,7 @@ "access": "public" }, "dependencies": { - "@appsignal/core": "=1.1.21", + "isomorphic-unfetch": "=4.0.0", "chalk": "^4.1.0", "commander": "^6.2.1", "inquirer": "^7.3.3" diff --git a/packages/cli/src/installers/node/index.ts b/packages/cli/src/installers/node/index.ts index 85294f23..036933fa 100644 --- a/packages/cli/src/installers/node/index.ts +++ b/packages/cli/src/installers/node/index.ts @@ -2,7 +2,7 @@ import { existsSync } from "fs" import { spawnSync } from "child_process" import chalk from "chalk" import inquirer from "inquirer" -import { validatePushApiKey } from "@appsignal/core" +import { validatePushApiKey } from "../../utils" import * as fs from "fs" import * as path from "path" diff --git a/packages/cli/src/utils.ts b/packages/cli/src/utils.ts index 85cbc9a4..bfd5812b 100644 --- a/packages/cli/src/utils.ts +++ b/packages/cli/src/utils.ts @@ -1,5 +1,6 @@ import { existsSync } from "fs" import { dirname } from "path" +import fetch from "isomorphic-unfetch" // Returns the filesystem location at which the root of the // `@appsignal/nodejs` package was found. @@ -46,3 +47,24 @@ export function checkForAppsignalPackage(): string { process.exit(1) } + +export async function validatePushApiKey({ + endpoint = "https://push.appsignal.com", + apiKey +}: { + endpoint?: string + apiKey: string +}) { + const { status } = await fetch(`${endpoint}/1/auth?api_key=${apiKey}`) + + switch (status) { + case 200: + return true + case 401: + return false + default: + throw new Error( + `Invalid ${status} response from server when authenticating` + ) + } +} diff --git a/packages/core/.changesets/remove-dependency-on--isomorphic-unfetch-.md b/packages/core/.changesets/remove-dependency-on--isomorphic-unfetch-.md new file mode 100644 index 00000000..8c58d8c1 --- /dev/null +++ b/packages/core/.changesets/remove-dependency-on--isomorphic-unfetch-.md @@ -0,0 +1,7 @@ +--- +bump: "patch" +type: "remove" +--- + +Remove dependency on `isomorphic-unfetch`. This fixes an issue where +`isomorphic-unfetch` fails to bundle properly with `esbuild` or `webpack`. diff --git a/packages/core/package.json b/packages/core/package.json index 97cb378f..970a7b7a 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -26,7 +26,6 @@ }, "dependencies": { "@appsignal/types": "=3.0.1", - "isomorphic-unfetch": "=4.0.0", "tslib": "^2.3.0" } } diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 50d53781..83087b4e 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -5,7 +5,6 @@ export * from "./utils/error" export * from "./utils/url" export * from "./utils/async" export * from "./utils/environment" -export * from "./utils/push-api" // Classes export { Serializable } from "./serializable" diff --git a/packages/core/src/utils/push-api.ts b/packages/core/src/utils/push-api.ts deleted file mode 100644 index aab51f8e..00000000 --- a/packages/core/src/utils/push-api.ts +++ /dev/null @@ -1,22 +0,0 @@ -import fetch from "isomorphic-unfetch" - -export async function validatePushApiKey({ - endpoint = "https://push.appsignal.com", - apiKey -}: { - endpoint?: string - apiKey: string -}) { - const { status } = await fetch(`${endpoint}/1/auth?api_key=${apiKey}`) - - switch (status) { - case 200: - return true - case 401: - return false - default: - throw new Error( - `Invalid ${status} response from server when authenticating` - ) - } -}