a post-component library for building user-interfaces on the web.

scripts: migrate to typescript (#117)

tombl.dev 89b4e7c3 c4111968

verified
+30 -15
+3
.github/workflows/build.yml
··· 20 20 steps: 21 21 - uses: actions/checkout@v4 22 22 - uses: actions/configure-pages@v5 23 + - uses: actions/setup-node@v4 24 + with: 25 + node-version: 24 23 26 - run: npm ci 24 27 - run: npm run build --workspaces --if-present 25 28 - run: rm -rf node_modules
+3
.github/workflows/check.yml
··· 6 6 7 7 steps: 8 8 - uses: actions/checkout@v4 9 + - uses: actions/setup-node@v4 10 + with: 11 + node-version: 24 9 12 - run: npm install 10 13 - run: npm run build 11 14 - run: npm run check --workspaces
+3
.github/workflows/size.yml
··· 10 10 11 11 steps: 12 12 - uses: actions/checkout@v4 13 + - uses: actions/setup-node@v4 14 + with: 15 + node-version: 24 13 16 - uses: preactjs/compressed-size-action@v2 14 17 with: 15 18 compression: brotli
+2 -2
package.json
··· 8 8 }, 9 9 "scripts": { 10 10 "postinstall": "patch-package", 11 - "build": "node scripts/build.js", 12 - "build:watch": "node --watch scripts/build.js --watch", 11 + "build": "node scripts/build.ts", 12 + "build:watch": "node --watch scripts/build.ts --watch", 13 13 "format": "prettier --write . --cache", 14 14 "check": "tsc", 15 15 "test": "bun test --coverage --define __DEV__=true",
+12 -12
scripts/build.js scripts/build.ts
··· 1 1 import MagicString from 'magic-string' 2 + import assert from 'node:assert' 2 3 import { mkdir, readFile, rm, writeFile } from 'node:fs/promises' 3 4 import { parseArgs, styleText } from 'node:util' 4 5 import { brotliCompressSync, gzipSync } from 'node:zlib' ··· 19 20 await Promise.all([bundle_code(), write_package_json()]) 20 21 21 22 async function bundle_code() { 22 - /** @type {import('rolldown').Plugin} */ 23 - const strip_asserts_plugin = { 23 + const strip_asserts_plugin: rolldown.Plugin = { 24 24 name: 'strip-asserts', 25 25 transform(code, id, { moduleType }) { 26 26 if (id.includes('node_modules')) return 27 27 28 + assert(moduleType === 'js' || moduleType === 'ts') 28 29 const ast = this.parse(code, { lang: moduleType }) 29 30 const source = new MagicString(code, { filename: id }) 30 31 31 - walk(/** @type {import('@oxc-project/types').Node} */ (ast), null, { 32 + walk<import('@oxc-project/types').Node, null>(ast, null, { 32 33 CallExpression(node, { next }) { 33 34 if (node.callee.type === 'Identifier' && node.callee.name === 'assert') { 34 35 source.update(node.start, node.end, ';') ··· 45 46 46 47 const terser_name_cache = {} 47 48 48 - /** @type {import('rolldown').Plugin} */ 49 - const terser_plugin = { 49 + const terser_plugin: rolldown.Plugin = { 50 50 name: 'terser', 51 51 renderChunk(code) { 52 - return minify_sync(code, { 52 + const result = minify_sync(code, { 53 53 mangle: { properties: { regex: /^_/ } }, 54 54 nameCache: terser_name_cache, 55 55 sourceMap: true, 56 56 module: true, 57 57 }) 58 + assert(result.code) 59 + assert(typeof result.map === 'string') 60 + return { code: result.code, map: result.map } 58 61 }, 59 62 } 60 63 61 - /** @type {Record<string, number>} */ 62 - const old_sizes = {} 63 - /** @type {import('rolldown').Plugin} */ 64 - const print_size_plugin = { 64 + const old_sizes: Record<string, number> = {} 65 + const print_size_plugin: rolldown.Plugin = { 65 66 name: 'print-size', 66 67 generateBundle(_options, bundle) { 67 68 for (const [name, file] of Object.entries(bundle)) { ··· 91 92 }, 92 93 } 93 94 94 - /** @returns {import('rolldown').BuildOptions} */ 95 - function define_bundle(env) { 95 + function define_bundle(env): rolldown.BuildOptions { 96 96 const input = { 97 97 client: './src/client.ts', 98 98 server: './src/server.ts',
+7 -1
scripts/lex.js scripts/lex.ts
··· 7 7 .map(([name, value]) => [value, name]), 8 8 ) 9 9 10 + function tsa(...strings: string[]): TemplateStringsArray { 11 + return Object.assign(strings, { raw: strings }) 12 + } 13 + 10 14 for (const entry of process.argv.slice(2)) { 11 15 const statics = entry.split('$') 12 16 console.log(statics) 13 - for (const [char, state] of lexer.lex(statics)) { 17 + for (const [char, state] of lexer.lex(tsa(...statics))) { 14 18 console.log(JSON.stringify(char), names[state]) 15 19 } 16 20 } 21 + 22 + export {}