From 5427c1258fbdc9db5c89f30258d728c5c6daeb0e Mon Sep 17 00:00:00 2001 From: Drew Davis Date: Wed, 28 Oct 2026 23:42:48 +0100 Subject: [PATCH] chore: Make common-utils type checking faster --- packages/common-utils/package.json | 7 ++++--- packages/common-utils/src/core/handlebarsEnv.ts | 10 +++++----- packages/common-utils/tsconfig.build.json | 7 +++++++ packages/common-utils/tsup.config.ts | 11 ++--------- 4 files changed, 18 insertions(+), 17 deletions(-) create mode 100644 packages/common-utils/tsconfig.build.json diff --git a/packages/common-utils/package.json b/packages/common-utils/package.json index 4731a91a6f..0a4e25d705 100644 --- a/packages/common-utils/package.json +++ b/packages/common-utils/package.json @@ -47,9 +47,10 @@ }, "scripts": { "dev": "nodemon --on-change-only --watch ./src --ext ts --exec \"yarn dev:build\"", - "dev:build": "tsup && tsc --emitDeclarationOnly --declaration && tsc-alias", - "build": "tsup", - "ci:build": "tsup", + "dev:build": "yarn build", + "build": "tsup && yarn build:types", + "build:types": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json", + "ci:build": "yarn build", "lint": "npx eslint . --ext .ts --max-warnings 80", "lint:fix": "npx eslint . --ext .ts --fix", "ci:lint": "yarn lint && yarn tsc --noEmit", diff --git a/packages/common-utils/src/core/handlebarsEnv.ts b/packages/common-utils/src/core/handlebarsEnv.ts index 81076f3a35..fbf9d7f4e9 100644 --- a/packages/common-utils/src/core/handlebarsEnv.ts +++ b/packages/common-utils/src/core/handlebarsEnv.ts @@ -70,7 +70,7 @@ const KNOWN_HELPERS = { function parseAndCompile( template: string, strict: boolean, -): HandlebarsTemplateDelegate { +): Handlebars.TemplateDelegate { // hb.compile() defers parsing until the first render, which would push // syntax errors out to every render call. Parse up front and hand compile() // the AST instead, so a malformed template fails here, once. @@ -83,7 +83,7 @@ function parseAndCompile( } type CompileResult = - | { delegate: HandlebarsTemplateDelegate } + | { delegate: Handlebars.TemplateDelegate } | { error: unknown }; const strictCache = new Map(); @@ -93,7 +93,7 @@ function compileCached( cache: Map, template: string, strict: boolean, -): HandlebarsTemplateDelegate { +): Handlebars.TemplateDelegate { let result = cache.get(template); if (!result) { try { @@ -111,7 +111,7 @@ function compileCached( * Compile a template whose render throws if it references a key that isn't in * the context. */ -export function compileStrict(template: string): HandlebarsTemplateDelegate { +export function compileStrict(template: string): Handlebars.TemplateDelegate { return compileCached(strictCache, template, true); } @@ -119,7 +119,7 @@ export function compileStrict(template: string): HandlebarsTemplateDelegate { * Compile a template whose render leaves missing keys empty. Throws on invalid * syntax. */ -export function compileLenient(template: string): HandlebarsTemplateDelegate { +export function compileLenient(template: string): Handlebars.TemplateDelegate { return compileCached(lenientCache, template, false); } diff --git a/packages/common-utils/tsconfig.build.json b/packages/common-utils/tsconfig.build.json new file mode 100644 index 0000000000..bed5be0406 --- /dev/null +++ b/packages/common-utils/tsconfig.build.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "emitDeclarationOnly": true + }, + "exclude": ["node_modules", "src/**/__tests__/**", "src/**/*.test.ts"] +} diff --git a/packages/common-utils/tsup.config.ts b/packages/common-utils/tsup.config.ts index 3a4da0ce0e..b67e90beb2 100644 --- a/packages/common-utils/tsup.config.ts +++ b/packages/common-utils/tsup.config.ts @@ -3,15 +3,8 @@ import type { Options } from 'tsup'; export const tsup: Options = { splitting: true, clean: true, // clean up the dist folder - dts: { - // tsup's DTS bundler (rollup-plugin-dts) unconditionally injects the - // `baseUrl` compiler option, which TypeScript 6 reports as deprecated - // (TS5101). Acknowledge the deprecation so DTS generation succeeds until - // tsup stops forcing baseUrl. - compilerOptions: { - ignoreDeprecations: '6.0', - }, - }, // generate dts files + // Declarations come from (the more efficient) tsc + dts: false, format: ['cjs', 'esm'], // generate cjs and esm files minify: true, bundle: true,