({
fix,
packages,
}: {
fix: boolean
packages: Package[]
})
| 259 | } |
| 260 | |
| 261 | async function checkLibraryContents({ |
| 262 | fix, |
| 263 | packages, |
| 264 | }: { |
| 265 | fix: boolean |
| 266 | packages: Package[] |
| 267 | }): Promise<boolean> { |
| 268 | let errorCount = 0 |
| 269 | |
| 270 | for (const { packageJson, name, path } of packages) { |
| 271 | if (packageJson.private) continue |
| 272 | |
| 273 | const sourceFilePath = join(path, 'src', 'index.ts') |
| 274 | const sourceFileContents = await readFileIfExists(sourceFilePath) |
| 275 | if (!sourceFileContents) { |
| 276 | nicelog(['⏩ ', kleur.blue(`${name}: `), 'skipped (no src/index.ts)'].join('')) |
| 277 | continue |
| 278 | } |
| 279 | |
| 280 | const search = [ |
| 281 | 'registerTldrawLibraryVersion(', |
| 282 | '\t(globalThis as any).TLDRAW_LIBRARY_NAME,', |
| 283 | '\t(globalThis as any).TLDRAW_LIBRARY_VERSION,', |
| 284 | '\t(globalThis as any).TLDRAW_LIBRARY_MODULES', |
| 285 | ')', |
| 286 | ].join('\n') |
| 287 | |
| 288 | if (sourceFileContents.includes(search)) { |
| 289 | nicelog(['✅ ', kleur.green(name)].join('')) |
| 290 | continue |
| 291 | } |
| 292 | |
| 293 | errorCount++ |
| 294 | if (fix) { |
| 295 | const newSourceFileContents = [ |
| 296 | "import {registerTldrawLibraryVersion} from '@tldraw/utils'", |
| 297 | sourceFileContents, |
| 298 | '', |
| 299 | 'registerTldrawLibraryVersion(', |
| 300 | '(globalThis as any).TLDRAW_LIBRARY_NAME,', |
| 301 | '(globalThis as any).TLDRAW_LIBRARY_VERSION,', |
| 302 | '(globalThis as any).TLDRAW_LIBRARY_NAME', |
| 303 | ')', |
| 304 | ].join('\n') |
| 305 | |
| 306 | await writeCodeFile(null, 'typescript', sourceFilePath, newSourceFileContents) |
| 307 | nicelog( |
| 308 | [ |
| 309 | '⚠️ ', |
| 310 | kleur.yellow(`${name}: `), |
| 311 | 'added call to ', |
| 312 | kleur.blue('registerTldrawLibraryVersion'), |
| 313 | ].join('') |
| 314 | ) |
| 315 | } else { |
| 316 | nicelog( |
| 317 | [ |
| 318 | '❌ ', |
no test coverage detected
searching dependent graphs…