Skip to content
Open
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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ If you prefer to run off the fully compiled release version of your current code

> Note: Running any of the `build:` prefixed commands will not publish anything to npm. They simply populate the `dist/` directory with the compiled code. You can run these commands safely as often as you wish.

## Updating instrumentation log formatting

The script `prettier-ignore-log-lines.js` automatically adds `/* prettier-ignore */`
comments to long instrumentation log statements. Run it whenever you add or modify
logging counters so that Prettier doesn't wrap these lines:

```sh
node prettier-ignore-log-lines.js
```

Execute the command from the repository root (or pass a working directory containing
a `src/` folder). The script scans `src/**/*.ts` files and only updates lines that
match known instrumentation patterns and exceed the configured print width.

## Releasing

If you're a core developer on this project and need to cut a release, simply run:
Expand Down
50 changes: 50 additions & 0 deletions test/unit/scripts/prettier-ignore-log-lines.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import fs from 'fs'
import os from 'os'
import path from 'path'
import { spawnSync } from 'child_process'

const scriptPath = path.resolve(__dirname, '../../../prettier-ignore-log-lines.js')

function runScriptWithFile(content: string): string {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'prettier-test-'))
const srcDir = path.join(tmpDir, 'src')
fs.mkdirSync(srcDir)
const filePath = path.join(srcDir, 'file.ts')
fs.writeFileSync(filePath, content + '\n')
const result = spawnSync('node', [scriptPath], { cwd: tmpDir })
if (result.status !== 0) {
throw new Error(result.stderr.toString())
}
const output = fs.readFileSync(filePath, 'utf8')
fs.rmSync(tmpDir, { recursive: true, force: true })
return output.trimEnd()
}

describe('prettier-ignore-log-lines script', () => {
test('inserts comment for long instrumentation lines', () => {
const content = [
` nestedCountersInstance.countEvent('cat', '${'x'.repeat(150)}')`,
` nestedCountersInstance.countRareEvent('cat', '${'x'.repeat(150)}')`,
` stateManager.statemanager_fatal('fatal', '${'x'.repeat(150)}')`,
` if (logFlags.verbose) console.log('${'x'.repeat(150)}')`,
].join('\n')

const result = runScriptWithFile(content)
const lines = result.split(/\r?\n/)
for (const line of lines) {
expect(line.startsWith(' /* prettier-ignore */ ')).toBe(true)
}
})

test('keeps short and unrelated lines unchanged', () => {
const originalLines = [
` nestedCountersInstance.countEvent('cat', 'short')`,
` console.log('hello')`,
]
const result = runScriptWithFile(originalLines.join('\n'))
const lines = result.split(/\r?\n/)
lines.forEach((line, idx) => {
expect(line).toBe(originalLines[idx])
})
})
})
Loading