-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove posthog-node dependency
Posthog node has been replaced for a fetch call. Removing 3 (posthog + 2 transitive dependencies).
- Loading branch information
1 parent
1d62451
commit 5d906bd
Showing
16 changed files
with
223 additions
and
127 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@inlang/paraglide-js": minor | ||
--- | ||
|
||
refactor: remove posthog-node dependency | ||
|
||
Posthog node has been replaced for a fetch call. Removing 3 (posthog + 2 transitive dependencies). |
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 was deleted.
Oops, something went wrong.
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
2 changes: 2 additions & 0 deletions
2
packages/inlang-paraglide-js/src/services/env-variables/.gitignore
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,2 @@ | ||
index.ts | ||
index.js |
36 changes: 36 additions & 0 deletions
36
packages/inlang-paraglide-js/src/services/env-variables/createIndexFile.js
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,36 @@ | ||
/* eslint-disable no-undef */ | ||
/** | ||
* This script writes public environment variables | ||
* to an importable env file. | ||
* | ||
* - The SDK must bundle this file with the rest of the SDK | ||
* - This scripts avoids the need for a bundler | ||
* - Must be ran before building the SDK | ||
*/ | ||
|
||
import fs from "node:fs/promises"; | ||
import url from "node:url"; | ||
import path from "node:path"; | ||
|
||
const dirname = path.dirname(url.fileURLToPath(import.meta.url)); | ||
|
||
const packageJson = JSON.parse( | ||
await fs.readFile(path.resolve(dirname, "../../../package.json"), "utf-8") | ||
); | ||
|
||
await fs.writeFile( | ||
dirname + "/index.ts", | ||
` | ||
export const ENV_VARIABLES = { | ||
PARJS_APP_ID: "library.inlang.paraglideJs", | ||
PARJS_POSTHOG_TOKEN: ${ifDefined(process.env.PUBLIC_POSTHOG_TOKEN)}, | ||
PARJS_PACKAGE_VERSION: ${ifDefined(packageJson.version)}, | ||
} | ||
` | ||
); | ||
|
||
// console.log("✅ Created env variable index file."); | ||
|
||
function ifDefined(value) { | ||
return value ? `"${value}"` : undefined; | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/inlang-paraglide-js/src/services/env-variables/index.d.ts
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,22 @@ | ||
/** | ||
* Avoiding TypeScript errors before the `createIndexFile` script | ||
* is invoked by defining the type ahead of time. | ||
*/ | ||
|
||
/** | ||
* Env variables that are available at runtime. | ||
*/ | ||
export declare const ENV_VARIABLES: { | ||
/** | ||
* The inlang app id. | ||
*/ | ||
PARJS_APP_ID: string; | ||
PARJS_POSTHOG_TOKEN?: string; | ||
/** | ||
* The Package version from package.json | ||
* | ||
* This value is inlined by vite during build to avoid having to read the package.json | ||
* at runtime | ||
*/ | ||
PARJS_PACKAGE_VERSION: string; | ||
}; |
49 changes: 49 additions & 0 deletions
49
packages/inlang-paraglide-js/src/services/telemetry/capture.test.ts
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,49 @@ | ||
import { expect, test, vi } from "vitest"; | ||
import { capture } from "./capture.js"; | ||
import type { ENV_VARIABLES } from "../env-variables/index.js"; | ||
|
||
test("it should not capture if telemetry is off", async () => { | ||
// @ts-expect-error - global.fetch is not defined | ||
global.fetch = vi.fn(() => Promise.resolve()); | ||
|
||
vi.mock("../env-variables/index.js", async () => { | ||
return { | ||
ENV_VARIABLES: { | ||
PARJS_POSTHOG_TOKEN: "mock-defined", | ||
} satisfies Partial<typeof ENV_VARIABLES>, | ||
}; | ||
}); | ||
|
||
await capture("PARAGLIDE-JS compile executed", { | ||
projectId: "test", | ||
settings: { | ||
telemetry: "off", | ||
}, | ||
properties: {}, | ||
}); | ||
|
||
expect(global.fetch).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test("it should not capture if telemetry is NOT off", async () => { | ||
// @ts-expect-error - global.fetch is not defined | ||
global.fetch = vi.fn(() => Promise.resolve()); | ||
|
||
vi.mock("../env-variables/index.js", async () => { | ||
return { | ||
ENV_VARIABLES: { | ||
PARJS_POSTHOG_TOKEN: "mock-defined", | ||
} satisfies Partial<typeof ENV_VARIABLES>, | ||
}; | ||
}); | ||
|
||
await capture("PARAGLIDE-JS compile executed", { | ||
projectId: "test", | ||
settings: { | ||
telemetry: undefined, | ||
}, | ||
properties: {}, | ||
}); | ||
|
||
expect(global.fetch).toHaveBeenCalled(); | ||
}); |
Oops, something went wrong.