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: 4 additions & 1 deletion packages/rrweb/record/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
"scripts": {
"dev": "vite build --watch",
"build": "pnpm turbo run prepublish",
"build:declarations": "rolldown -c rolldown.dts.config.mts",
"test": "vitest run",
"test:watch": "vitest watch",
"check-types": "tsc -noEmit",
"prepublish": "tsc -noEmit && vite build",
"prepublish": "tsc -noEmit && vite build && pnpm build:declarations",
"lint": "oxlint src"
},
"repository": {
Expand Down Expand Up @@ -41,6 +42,8 @@
],
"devDependencies": {
"puppeteer": "^23.11.1",
"rolldown": "catalog:",
"rolldown-plugin-dts": "catalog:",
"vite": "catalog:",
"vite-plugin-dts": "catalog:",
"vitest": "^1.4.0",
Expand Down
32 changes: 32 additions & 0 deletions packages/rrweb/record/rolldown.dts.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { copyFileSync } from 'node:fs';
import path from 'node:path';
import { defineConfig, type Plugin } from 'rolldown';
import { dts } from 'rolldown-plugin-dts';

function copyDeclarationsForCommonJs(): Plugin {
return {
name: 'copy-declarations-for-commonjs',
writeBundle(outputOptions) {
if (!outputOptions.dir) return;

const declarationPath = path.resolve(outputOptions.dir, 'index.d.ts');
copyFileSync(declarationPath, declarationPath.replace(/\.d\.ts$/, '.d.cts'));
},
};
}

export default defineConfig({
input: 'src/index.ts',
external: ['@posthog/rrweb'],
output: {
dir: 'dist',
format: 'es',
},
plugins: [
...dts({
emitDtsOnly: true,
generator: 'oxc',
}),
copyDeclarationsForCommonJs(),
],
});
22 changes: 22 additions & 0 deletions packages/rrweb/record/test/build-output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,26 @@ describe('build output', () => {
expect(bundle).not.toContain('sourceMappingURL=image-bitmap-data-url-worker-')
expect(bundle).toContain('sourceMappingURL=rrweb-record.js.map')
})

it('emits matching ESM and CommonJS declarations', () => {
const esmDeclarations = readFileSync(resolve(__dirname, '../dist/index.d.ts'), 'utf8')
const commonJsDeclarations = readFileSync(resolve(__dirname, '../dist/index.d.cts'), 'utf8')

const expectedExports = [
'DeferredStylesheetStats',
'MutationCost',
'SnapshotCost',
'getDeferredStylesheetStats',
'getDiscardedDurationSamples',
'getLastSnapshotCost',
'getMutationCost',
'record',
'resetMaxDepthState',
'resetSnapshotCostState',
'wasMaxDepthReached',
]

expect(commonJsDeclarations).toBe(esmDeclarations)
expectedExports.forEach((exportName) => expect(esmDeclarations).toContain(exportName))
})
})
3 changes: 2 additions & 1 deletion packages/rrweb/record/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
],
"compilerOptions": {
"rootDir": "src",
"tsBuildInfoFile": "./tsconfig.tsbuildinfo"
"tsBuildInfoFile": "./tsconfig.tsbuildinfo",
"isolatedDeclarations": true
},
"references": [
{
Expand Down
1 change: 1 addition & 0 deletions packages/rrweb/record/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const workspacePackages: Record<string, string> = {
};

export default config(path.resolve(__dirname, 'src/index.ts'), 'rrweb', {
generateDeclarations: process.argv.includes('--watch'),
plugins: [
{
name: 'resolve-workspace-sources',
Expand Down
Loading