@rpcbase/vite 0.64.0 → 0.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -13,6 +13,7 @@ import react from "@vitejs/plugin-react"
13
13
  import { createHtmlPlugin } from "vite-plugin-html"
14
14
  import { glob } from "glob"
15
15
 
16
+ import { posthogSourcemapsPlugin } from "./posthogSourcemapsPlugin.js"
16
17
 
17
18
  // const isCI = process.env.CI === "true"
18
19
 
@@ -86,6 +87,7 @@ const getBaseConfig = ({ command, mode, isSsrBuild, isPreview }) => {
86
87
  inlinePattern: ["**/*.css"],
87
88
  removeViteModuleLoader: false
88
89
  }),
90
+ isProduction && posthogSourcemapsPlugin({ project: "dummy-test" }),
89
91
  ].filter(Boolean),
90
92
  define: {
91
93
  __vite_env__: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/vite",
3
- "version": "0.64.0",
3
+ "version": "0.66.0",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "scripts": {
@@ -25,10 +25,9 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@hookform/resolvers": "5.2.2",
28
- "@swc/core": "1.13.21",
28
+ "@posthog/cli": "0.5.7",
29
29
  "@tailwindcss/vite": "4.1.16",
30
30
  "@vitejs/plugin-react": "5.1.0",
31
- "@vitejs/plugin-react-swc": "4.2.0",
32
31
  "clsx": "2.1.1",
33
32
  "glob": "11.0.3",
34
33
  "libphonenumber-js": "1.12.24",
@@ -0,0 +1,72 @@
1
+ import { spawn } from "node:child_process"
2
+ import path from "node:path"
3
+ import fs from "node:fs"
4
+ import { fileURLToPath } from "node:url"
5
+
6
+
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
8
+
9
+ function run(bin, args) {
10
+ return new Promise((resolve, reject) => {
11
+ const p = spawn(bin, args, { stdio: "inherit" })
12
+ p.on("close", code => code === 0 ? resolve() : reject(new Error(`posthog-cli exited ${code}`)))
13
+ })
14
+ }
15
+
16
+ function resolvePosthogCliBin() {
17
+ const binName = "posthog-cli"
18
+
19
+ const fromCwd = path.join(process.cwd(), "node_modules", ".bin", binName)
20
+ if (fs.existsSync(fromCwd)) return fromCwd
21
+
22
+ let dir = __dirname
23
+ while (true) {
24
+ const candidate = path.join(dir, "node_modules", ".bin", binName)
25
+ if (fs.existsSync(candidate)) return candidate
26
+
27
+ const parent = path.dirname(dir)
28
+ if (parent === dir) break
29
+ dir = parent
30
+ }
31
+
32
+ return binName
33
+ }
34
+
35
+ export function posthogSourcemapsPlugin(opts = {}) {
36
+ const {
37
+ directory = "build/dist",
38
+ project,
39
+ version,
40
+ host = process.env.RB_PUBLIC_POSTHOG_HOST || "https://eu.posthog.com",
41
+ deleteAfterUpload = true
42
+ } = opts
43
+
44
+ const bin = resolvePosthogCliBin()
45
+ const globalArgs = ["--host", host]
46
+
47
+ return {
48
+ name: "posthog-sourcemaps",
49
+ apply: "build",
50
+ closeBundle: async () => {
51
+ console.log("ENVV", process.env)
52
+ const envId = process.env.POSTHOG_CLI_ENV_ID
53
+ const token = process.env.POSTHOG_CLI_TOKEN
54
+ if (!envId || !token) {
55
+ const orange = "\x1b[38;5;208m"
56
+ const reset = "\x1b[0m"
57
+ console.warn(`${orange}posthog-sourcemaps: plugin is enabled but no env vars for auth configured (POSTHOG_CLI_ENV_ID/POSTHOG_CLI_TOKEN). Skipping without failing.${reset}`)
58
+ return
59
+ }
60
+
61
+ const injectArgs = ["sourcemap", "inject", "--directory", directory]
62
+ if (project) injectArgs.push("--project", project)
63
+ if (version) injectArgs.push("--version", version)
64
+
65
+ const uploadArgs = ["sourcemap", "upload", "--directory", directory]
66
+ if (deleteAfterUpload) uploadArgs.push("--delete-after")
67
+
68
+ await run(bin, [...globalArgs, ...injectArgs])
69
+ await run(bin, [...globalArgs, ...uploadArgs])
70
+ }
71
+ }
72
+ }