mirror of
https://github.com/hanzoai/insights-js.git
synced 2026-11-02 14:31:14 +00:00
* chore: move posthog-rrweb into the monorepo Imports the posthog-rrweb fork (currently published as v0.0.60) into packages/rrweb/ so that the rrweb packages release from this repo via the existing changesets pipeline. This collapses the current two-step publish flow (posthog-rrweb -> npm -> posthog-js) into a single monorepo release. Scope of the move: - Snapshot taken from posthog-rrweb@main; rrvideo, rrweb-player and web-extension are intentionally dropped because we do not consume them from posthog-js. - The seven packages we publish today continue to publish from this repo: @posthog/rrweb, @posthog/rrweb-types, @posthog/rrweb-utils, @posthog/rrdom, @posthog/rrweb-snapshot, @posthog/rrweb-record and @posthog/rrweb-plugin-console-record. - Internal-only packages (rrdom-nodejs, @posthog/rrweb-replay, @posthog/rrweb-all, @posthog/rrweb-packer, the experimental plugins) are listed under changesets ignore. - packages/browser now depends on @posthog/rrweb-record, @posthog/rrweb-plugin-console-record and @posthog/rrweb-types via workspace:* instead of pinned npm versions. Tooling/config updates: - pnpm-workspace.yaml gains packages/rrweb/* and packages/rrweb/plugins/* globs and a small catalog for vite, vite-plugin-dts and esbuild-plugin-umd-wrapper. - turbo.json picks up vite.config.* as build inputs and adds prepublish / check-types tasks used by the rrweb subpackages. - Root devDependencies hoist esbuild, esbuild-plugin-umd-wrapper and rollup-plugin-visualizer so vite builds resolve correctly. - .npmrc adds a few trust-policy-exclude entries for transitive deps brought in by the rrweb tree that lost provenance attestations. - release.yml extends the publish matrix to the seven publishable rrweb packages. - library-ci.yml adds an rrweb job (vitest + puppeteer under xvfb) that only runs when packages/rrweb/** changes. No runtime behavior changes are intended: the recorder bundle in packages/browser is byte-identical to main (verified locally), and the published rrweb packages get a single patch bump via the accompanying changeset. * stop using rrweb npm package and point imports to local rrweb * fix tests * fix tests * fix docker build * fix docker build * silence false positives * fix for tue's comment * pin package version * add minimal permissions to silence alert
105 lines
3.0 KiB
JavaScript
105 lines
3.0 KiB
JavaScript
import path from 'path';
|
|
import { defineConfig } from 'vite';
|
|
import dts from 'vite-plugin-dts';
|
|
import { copyFileSync } from 'node:fs';
|
|
import { build as esbuild } from 'esbuild';
|
|
import { umdWrapper } from 'esbuild-plugin-umd-wrapper';
|
|
import { resolve } from 'path';
|
|
|
|
// Plugin to generate UMD bundles using esbuild after vite build
|
|
function umdPlugin({ name, outDir }) {
|
|
return {
|
|
name: 'umd-plugin',
|
|
async writeBundle(outputOptions, bundle) {
|
|
for (const file of Object.values(bundle)) {
|
|
if (
|
|
file.type === 'asset' &&
|
|
file.fileName.endsWith('.cjs.map')
|
|
) {
|
|
const inputFilePath = resolve(
|
|
outputOptions.dir,
|
|
file.fileName,
|
|
).replace(/\.map$/, '');
|
|
const baseFileName = file.fileName.replace(/(\.cjs)(\.map)?$/, '');
|
|
const outputFilePath = resolve(outputOptions.dir, baseFileName);
|
|
|
|
// Determine library name based on filename
|
|
let libraryName = name;
|
|
if (baseFileName.includes('record')) {
|
|
libraryName = 'rrwebSnapshotRecord';
|
|
} else if (baseFileName.includes('replay')) {
|
|
libraryName = 'rrwebSnapshotReplay';
|
|
}
|
|
|
|
await esbuild({
|
|
entryPoints: [inputFilePath],
|
|
outfile: `${outputFilePath}.umd.cjs`,
|
|
minify: false,
|
|
sourcemap: true,
|
|
format: 'umd',
|
|
target: 'es2017',
|
|
treeShaking: true,
|
|
bundle: true,
|
|
plugins: [
|
|
umdWrapper({
|
|
libraryName: libraryName,
|
|
}),
|
|
],
|
|
});
|
|
|
|
await esbuild({
|
|
entryPoints: [inputFilePath],
|
|
outfile: `${outputFilePath}.umd.min.cjs`,
|
|
minify: true,
|
|
sourcemap: true,
|
|
format: 'umd',
|
|
target: 'es2017',
|
|
treeShaking: true,
|
|
bundle: true,
|
|
plugins: [
|
|
umdWrapper({
|
|
libraryName: libraryName,
|
|
}),
|
|
],
|
|
});
|
|
|
|
console.log(`${outDir}/${baseFileName}.umd.cjs`);
|
|
console.log(`${outDir}/${baseFileName}.umd.cjs.map`);
|
|
console.log(`${outDir}/${baseFileName}.umd.min.cjs`);
|
|
console.log(`${outDir}/${baseFileName}.umd.min.cjs.map`);
|
|
}
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
export default defineConfig({
|
|
build: {
|
|
lib: {
|
|
entry: {
|
|
'rrweb-snapshot': path.resolve(__dirname, 'src/index.ts'),
|
|
'record': path.resolve(__dirname, 'src/record.ts'),
|
|
'replay': path.resolve(__dirname, 'src/replay.ts'),
|
|
},
|
|
formats: ['es', 'cjs'],
|
|
},
|
|
outDir: 'dist',
|
|
sourcemap: true,
|
|
minify: false,
|
|
},
|
|
plugins: [
|
|
dts({
|
|
insertTypesEntry: true,
|
|
rollupTypes: true,
|
|
afterBuild: (emittedFiles) => {
|
|
const files = Array.from(emittedFiles.keys());
|
|
files.forEach((file) => {
|
|
const ctsFile = file.replace('.d.ts', '.d.cts');
|
|
copyFileSync(file, ctsFile);
|
|
});
|
|
},
|
|
}),
|
|
umdPlugin({ name: 'rrwebSnapshot', outDir: 'dist' }),
|
|
],
|
|
});
|