|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +/** |
| 4 | + * Runs after a full build to assert that Uint8Array was not generated with a type parameter |
| 5 | + * by TypeScript, which is only compatible with TypeScript 5.7. |
| 6 | + */ |
| 7 | + |
| 8 | +const walk = require("../utils/walk"); |
| 9 | +const fs = require("node:fs"); |
| 10 | +const path = require("node:path"); |
| 11 | + |
| 12 | +const root = path.join(__dirname, "..", ".."); |
| 13 | + |
| 14 | +const clients = path.join(root, "clients"); |
| 15 | +const lib = path.join(root, "lib"); |
| 16 | +const packages = path.join(root, "packages"); |
| 17 | +const private = path.join(root, "private"); |
| 18 | + |
| 19 | +(async () => { |
| 20 | + const errors = []; |
| 21 | + for (const group of [clients, lib, packages, private]) { |
| 22 | + for (const folder of fs.readdirSync(group)) { |
| 23 | + const packagePath = path.join(group, folder); |
| 24 | + const distTypes = path.join(packagePath, "dist-types"); |
| 25 | + if (fs.existsSync(distTypes)) { |
| 26 | + for await (const file of walk(distTypes)) { |
| 27 | + const contents = fs.readFileSync(file, "utf-8"); |
| 28 | + if (contents.includes("Uint8Array<")) { |
| 29 | + errors.push(file); |
| 30 | + } |
| 31 | + } |
| 32 | + } |
| 33 | + } |
| 34 | + } |
| 35 | + if (errors.length > 0) { |
| 36 | + throw new Error( |
| 37 | + `The following files used Uint8Array in a generic way, only compatible with TypeScript 5.7:\n\t${errors.join( |
| 38 | + "\n\t" |
| 39 | + )}` |
| 40 | + ); |
| 41 | + } else { |
| 42 | + console.log(`✅ No Uint8Arrays with type parameters.`); |
| 43 | + } |
| 44 | +})(); |
0 commit comments