Skip to content

Commit

Permalink
Bug/fix rpc bundle (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsotimus authored Feb 2, 2024
1 parent c8c8c73 commit 64d9c09
Show file tree
Hide file tree
Showing 22 changed files with 68 additions and 60 deletions.
2 changes: 1 addition & 1 deletion apps/example-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"eslint-plugin-react-refresh": "^0.4.5",
"typescript": "^5.2.2",
"vite": "^5.0.8",
"vite-plugin-posthog": "*",
"vite-plugin-posthog": "2.0.4",
"react-posthog-consent": "*"
}
}
6 changes: 3 additions & 3 deletions apps/example-react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
useVitePostHog,
useFeatureFlagEnabled,
} from "vite-plugin-posthog/react";
// import { useConsent } from "react-posthog-consent/vite";
import { useConsent } from "react-posthog-consent/vite";

function App() {
const [count, setCount] = useState(0);
const posthog = useVitePostHog();
const showWelcomeMessage = useFeatureFlagEnabled("welcome-msg");
// const { reset } = useConsent();
const { handleReset } = useConsent();

const handleClick = () => {
posthog?.capture("count incremented");
Expand Down Expand Up @@ -40,7 +40,7 @@ function App() {
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
<button onClick={() => console.log("reset")}>Custom Reset</button>
<button onClick={handleReset}>Custom Reset</button>
<button onClick={() => posthog?.reset()}>Reset</button>
</>
);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/react-posthog-consent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"import": "./dist/vite/index.js"
}
},
"types": "src/core/types.d.ts",
"typings": "src/core/types.d.ts",
"types": "src/core/index.d.ts",
"typings": "src/core/index.d.ts",
"files": [
"dist",
"package.json",
Expand Down
65 changes: 35 additions & 30 deletions packages/react-posthog-consent/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,52 @@ import cjs from "@rollup/plugin-commonjs";

const config = defineConfig([
{
input: "src/core/index.ts",
input: {
"core/index": "src/core/index.ts",
"vite/index": "src/vite/index.ts",
},
output: {
dir: "dist/core",
dir: "dist",
format: "es",
},
plugins: [
typescript({
outDir: "dist/core",
include: [
"src/core/**/*",
"src/shared/**/*",
"src/utils/**/*",
"src/types.ts",
],
outDir: "dist",
include: ["src/**/*"],
declaration: true,
}),
nodeResolve(),
cjs(),
],
external: ["react", "react-dom", "posthog-js", "vite-plugin-posthog"],
},
{
input: "src/vite/index.ts",
output: {
dir: "dist/vite",
format: "es",
},
plugins: [
typescript({
outDir: "dist/vite",
include: [
"src/vite/**/*",
"src/shared/**/*",
"src/utils/**/*",
"src/types.ts",
],
}),
cjs(),
nodeResolve(),
external: [
"react",
"react-dom",
"posthog-js",
"vite-plugin-posthog",
"react/jsx-runtime",
],
external: ["react", "react-dom", "vite-plugin-posthog"],
},
// {
// input: "src/vite/index.ts",
// output: {
// dir: "dist/vite",
// format: "es",
// },
// plugins: [
// typescript({
// outDir: "dist/vite",
// include: [
// "src/vite/**/*",
// "src/shared/**/*",
// "src/utils/**/*",
// "src/types.ts",
// ],
// }),
// cjs(),
// nodeResolve(),
// ],
// external: ["react", "react-dom", "vite-plugin-posthog"],
// },
]);

export default config;
4 changes: 2 additions & 2 deletions packages/react-posthog-consent/src/core/ConsentProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, {
import {
ReactNode,
PropsWithChildren,
createContext,
useEffect,
useState,
} from "react";
import { ConsentConfig, ConsentContextType } from "../types";
import { ConsentConfig, ConsentContextType } from "../shared/types";
import { usePostHogConsent } from "./usePostHogConsent";

export const ConsentContext = createContext<ConsentContextType>({
Expand Down
2 changes: 1 addition & 1 deletion packages/react-posthog-consent/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { PostHog } from "../types";
export * from "../shared/types";
export * from "./ConsentProvider";
export * from "./usePostHogConsent";
export * from "./useConsent";
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getCookie } from "../shared/getCookie";
import { rejectConsent } from "../shared/rejectConsent";
import { triggerOptIn } from "../shared/triggerOptIn";
import { triggerReset } from "../shared/triggerReset";
import { ConsentConfig } from "../types";
import { ConsentConfig } from "../shared/types";

export const usePostHogConsent = (config: ConsentConfig) => {
const posthog = usePostHog();
Expand Down
5 changes: 3 additions & 2 deletions packages/react-posthog-consent/src/shared/acceptConsent.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ConsentConfig, PostHog } from "../types";
import { getCookiePrefix } from "../utils/getCookiePrefix";
import { ConsentConfig, PostHog } from "./types";
import { getCookiePrefix } from "./utils/getCookiePrefix";
import { configureCookies } from "./configureCookies";

export const acceptConsent = (
posthog: PostHog | null,
config: ConsentConfig
) => {
// TODO: COnfigure Opt-in capturing
posthog?.opt_in_capturing();
const cookies = configureCookies(config);
cookies.set(`${getCookiePrefix(config.cookiePrefix)}_consent`, {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-posthog-consent/src/shared/checkHasConsent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ConsentConfig } from "../types";
import { getCookiePrefix } from "../utils/getCookiePrefix";
import { ConsentConfig } from "./types";
import { getCookiePrefix } from "./utils/getCookiePrefix";
import { configureCookies } from "./configureCookies";

export const checkHasConsent = (config: ConsentConfig) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-posthog-consent/src/shared/configureCookies.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Cookies from "universal-cookie";
import { ConsentConfig } from "../types";
import { addDays } from "../utils/addDays";
import { ConsentConfig } from "./types";
import { addDays } from "./utils/addDays";

export const configureCookies = (config: ConsentConfig) => {
const requestedDate = addDays(config.cookie_expiration || 30);
Expand Down
4 changes: 2 additions & 2 deletions packages/react-posthog-consent/src/shared/getCookie.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ConsentConfig, CookiePayload } from "../types";
import { getCookiePrefix } from "../utils/getCookiePrefix";
import { ConsentConfig, CookiePayload } from "./types";
import { getCookiePrefix } from "./utils/getCookiePrefix";
import { configureCookies } from "./configureCookies";

export const getCookie = (config: ConsentConfig) => {
Expand Down
8 changes: 4 additions & 4 deletions packages/react-posthog-consent/src/shared/rejectConsent.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ConsentConfig } from "../types";
import { getCookiePrefix } from "../utils/getCookiePrefix";
import { ConsentConfig } from "./types";
import { getCookiePrefix } from "./utils/getCookiePrefix";
import { configureCookies } from "./configureCookies";

export const rejectConsent = (config: ConsentConfig) => {
//TODO: Add in Posthog Opt out, just incase
const cookies = configureCookies(config);

cookies.set(`${getCookiePrefix(config.cookiePrefix)}_consent`, {
status: true,
status: false,
timestamp: Date.now(),
});
};
3 changes: 2 additions & 1 deletion packages/react-posthog-consent/src/shared/triggerOptIn.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ConsentConfig, PostHog } from "../types";
import { ConsentConfig, PostHog } from "./types";

export const triggerOptIn = (
posthog: PostHog | null,
config: ConsentConfig
) => {
//TODO: Re-trigger opt-in capturing, with days left
posthog?.opt_in_capturing();
if (config.enable_session_recording) {
posthog?.startSessionRecording();
Expand Down
2 changes: 1 addition & 1 deletion packages/react-posthog-consent/src/shared/triggerReset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConsentConfig, PostHog } from "../types";
import { ConsentConfig, PostHog } from "./types";
import { checkHasConsent } from "./checkHasConsent";

export const triggerReset = (
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions packages/react-posthog-consent/src/vite/ConsentProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, {
import {
ReactNode,
PropsWithChildren,
createContext,
useEffect,
useState,
} from "react";
import { ConsentConfig, ConsentContextType } from "../types";
import { ConsentConfig, ConsentContextType } from "../shared/types";
import { usePostHogConsent } from "./usePostHogConsent";

export const ConsentContext = createContext<ConsentContextType>({
Expand Down
1 change: 1 addition & 0 deletions packages/react-posthog-consent/src/vite/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./usePostHogConsent";
export * from "./ConsentProvider";
export * from "./useConsent";
export * from "../shared/types";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useVitePostHog } from "vite-plugin-posthog/react";
import { ConsentConfig } from "../types";
import { ConsentConfig } from "../shared/types";
import { acceptConsent } from "../shared/acceptConsent";
import { checkHasConsent } from "../shared/checkHasConsent";
import { getCookie } from "../shared/getCookie";
Expand Down
2 changes: 1 addition & 1 deletion packages/react-posthog-consent/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"jsx": "react",
"jsx": "react-jsx",
"module": "ESNext",
"target": "esnext",
"moduleResolution": "Bundler",
Expand Down

0 comments on commit 64d9c09

Please sign in to comment.