@rpcbase/vite 0.63.0 → 0.65.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 +2 -2
- package/package.json +2 -5
- package/posthogSourcemapsPlugin.js +71 -0
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
|
|
|
@@ -53,10 +54,8 @@ const resolveAliases = {
|
|
|
53
54
|
|
|
54
55
|
const integratedPackages = [
|
|
55
56
|
"@hookform/resolvers",
|
|
56
|
-
"@headlessui/react",
|
|
57
57
|
"axios",
|
|
58
58
|
"libphonenumber-js",
|
|
59
|
-
"maplibre-gl",
|
|
60
59
|
"posthog-js",
|
|
61
60
|
"posthog-node",
|
|
62
61
|
"react-hook-form"
|
|
@@ -88,6 +87,7 @@ const getBaseConfig = ({ command, mode, isSsrBuild, isPreview }) => {
|
|
|
88
87
|
inlinePattern: ["**/*.css"],
|
|
89
88
|
removeViteModuleLoader: false
|
|
90
89
|
}),
|
|
90
|
+
isProduction && posthogSourcemapsPlugin({ project: "dummy-test" }),
|
|
91
91
|
].filter(Boolean),
|
|
92
92
|
define: {
|
|
93
93
|
__vite_env__: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpcbase/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.65.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,17 +24,14 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@headlessui/react": "2.2.9",
|
|
28
27
|
"@hookform/resolvers": "5.2.2",
|
|
29
|
-
"@
|
|
28
|
+
"@posthog/cli": "0.5.7",
|
|
30
29
|
"@tailwindcss/vite": "4.1.16",
|
|
31
30
|
"@vitejs/plugin-react": "5.1.0",
|
|
32
|
-
"@vitejs/plugin-react-swc": "4.2.0",
|
|
33
31
|
"clsx": "2.1.1",
|
|
34
32
|
"glob": "11.0.3",
|
|
35
33
|
"libphonenumber-js": "1.12.24",
|
|
36
34
|
"lucide-react": "0.547.0",
|
|
37
|
-
"maplibre-gl": "5.9.0",
|
|
38
35
|
"nocache": "4.0.0",
|
|
39
36
|
"posthog-js": "1.280.1",
|
|
40
37
|
"posthog-node": "5.10.3",
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
const envId = process.env.POSTHOG_CLI_ENV_ID
|
|
52
|
+
const token = process.env.POSTHOG_CLI_TOKEN
|
|
53
|
+
if (!envId || !token) {
|
|
54
|
+
const orange = "\x1b[38;5;208m"
|
|
55
|
+
const reset = "\x1b[0m"
|
|
56
|
+
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}`)
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const injectArgs = ["sourcemap", "inject", "--directory", directory]
|
|
61
|
+
if (project) injectArgs.push("--project", project)
|
|
62
|
+
if (version) injectArgs.push("--version", version)
|
|
63
|
+
|
|
64
|
+
const uploadArgs = ["sourcemap", "upload", "--directory", directory]
|
|
65
|
+
if (deleteAfterUpload) uploadArgs.push("--delete-after")
|
|
66
|
+
|
|
67
|
+
await run(bin, [...globalArgs, ...injectArgs])
|
|
68
|
+
await run(bin, [...globalArgs, ...uploadArgs])
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|