Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-pens-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'posthog-js': patch
---

Strip workspace:* references from lib/package.json after build
1 change: 1 addition & 0 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"start": "pnpm build-react && NODE_OPTIONS=\"--max-old-space-size=8192\" pnpm build-rollup -w",
"dev": "tsc -b && NODE_OPTIONS=\"--max-old-space-size=8192\" rollup -cw",
"build": "tsc -b && rollup -c",
"postbuild": "node scripts/strip-lib-package-json.js",
"package": "pnpm pack --out $PACKAGE_DEST/%s.tgz",
"lint": "eslint src && eslint playwright",
"lint:fix": "eslint src --fix && eslint playwright --fix",
Expand Down
19 changes: 19 additions & 0 deletions packages/browser/scripts/strip-lib-package-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// TypeScript copies package.json into lib/ (due to resolveJsonModule + the import in src/config.ts).
// The copy retains unresolved workspace:* references which break npm audit fix for consumers.
// This script strips dependencies and devDependencies from the build artifact.
// See: https://github.com/PostHog/posthog-js/issues/3290

const fs = require('fs')
const path = require('path')

const filePath = path.resolve(__dirname, '..', 'lib', 'package.json')

if (!fs.existsSync(filePath)) {
console.warn('warn: lib/package.json no longer exists — this postbuild script can be removed')
process.exit(0)
}

const pkg = JSON.parse(fs.readFileSync(filePath, 'utf8'))
delete pkg.dependencies
delete pkg.devDependencies
fs.writeFileSync(filePath, JSON.stringify(pkg, null, 4) + '\n')
Loading