Skip to content

Commit

Permalink
chore: Switch from esbuild to tsc for libs
Browse files Browse the repository at this point in the history
  • Loading branch information
jahands committed Feb 13, 2025
1 parent da0535f commit 204f849
Show file tree
Hide file tree
Showing 28 changed files with 70 additions and 129 deletions.
7 changes: 7 additions & 0 deletions .changeset/tame-berries-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'workers-tagged-logger': minor
'http-codex': minor
'@jahands/cli-tools': minor
---

chore: Switch from esbuild to tsc
11 changes: 5 additions & 6 deletions packages/cli-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,24 @@
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.mjs"
"default": "./dist/index.js"
}
}
},
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",
"main": "./dist/index.js",
"module": "./dist/index.js",
"files": [
"dist"
],
"scripts": {
"build": "bun ./scripts/build.ts",
"build": "runx build tsc ./src/index.ts",
"check:lint": "run-eslint-workers",
"check:types": "run-tsc",
"check:types": "runx check --exports",
"test": "run-vitest"
},
"devDependencies": {
"@repo/tools": "workspace:*",
"@repo/typescript-config": "workspace:*",
"esbuild": "0.24.2",
"vitest": "2.1.1"
},
"peerDependencies": {
Expand Down
24 changes: 0 additions & 24 deletions packages/cli-tools/scripts/build-types.ts

This file was deleted.

31 changes: 0 additions & 31 deletions packages/cli-tools/scripts/build.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/cli-tools/scripts/entrypoints.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/cli-tools/src/args.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command, program } from '@commander-js/extra-typings'
import { beforeAll, beforeEach, describe, expect, it } from 'vitest'
import { z } from 'zod'

import { parseArg } from './args'
import { parseArg } from './args.js'

const exitErrors: Error[] = []
beforeAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-tools/src/cmd.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'

import { cmdExists } from './cmd'
import { cmdExists } from './cmd.js'

describe('cmdExists()', async () => {
it('returns true when command exists', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-tools/src/env.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { program } from '@commander-js/extra-typings'
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'

import { getEnv } from './env'
import { getEnv } from './env.js'

const exitErrors: Error[] = []
beforeAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-tools/src/env.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cliError } from './errors'
import { cliError } from './errors.js'

/**
* Get an env var, throwing an error if it's not set
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-tools/src/errors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command, program } from '@commander-js/extra-typings'
import { beforeAll, beforeEach, describe, expect, it } from 'vitest'

import { cliError } from './errors'
import { cliError } from './errors.js'

const exitErrors: Error[] = []
beforeAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-tools/src/fs.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'

import { isNotFoundError } from './fs'
import { isNotFoundError } from './fs.js'

describe('isNotFoundError()', () => {
it('returns false if not a not-found error', () => {
Expand Down
14 changes: 7 additions & 7 deletions packages/cli-tools/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './args'
export * from './cmd'
export * from './env'
export * from './errors'
export * from './fs'
export * from './proc'
export * from './promise'
export * from './args.js'
export * from './cmd.js'
export * from './env.js'
export * from './errors.js'
export * from './fs.js'
export * from './proc.js'
export * from './promise.js'
23 changes: 3 additions & 20 deletions packages/cli-tools/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

/* Linting */
"skipLibCheck": true,
"strict": true,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true
}
"extends": "@repo/typescript-config/lib-emit.json",
"include": ["**/*.ts"],
"exclude": ["node_modules", "dist", "tsconfig.json"]
}
5 changes: 2 additions & 3 deletions packages/http-codex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@
"dist"
],
"scripts": {
"build": "runx build tsc",
"check:exports": "runx check -e",
"build": "runx build tsc ./src/index.ts ./src/status.ts",
"check:lint": "run-eslint-workers",
"check:types": "run-s build check:exports",
"check:types": "runx check --exports",
"test": "run-vitest"
},
"devDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions packages/tools/src/cmd/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ buildCmd
buildCmd
.command('tsc')
.description('Build a library with tsc')
.argument('<entrypoint...>', 'Entrypoint(s) for the program')
.option('-r, --root-dir <string>', 'Root dir for tsc to use (overrides tsconfig.json)', 'src')
.action(async ({ rootDir }) => {
.action(async (entrypoints, { rootDir }) => {
await $`rm -rf ./dist` // Make sure we don't have any previous artifacts

// Read the parent config so that we don't get
Expand All @@ -44,7 +45,7 @@ buildCmd
rootDir: rootDir,
} satisfies ts.CompilerOptions

ts.createProgram(['./src/index.ts', './src/status.ts'], config).emit()
ts.createProgram(entrypoints, config).emit()
})

function getCompilerOptionsJSONFollowExtends(filename: string): { [key: string]: unknown } {
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-config/lib.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./base.json",
"extends": "@repo/typescript-config/base.json",
"compilerOptions": {
"module": "es2022",
"target": "es2022",
Expand Down
7 changes: 7 additions & 0 deletions packages/typescript-config/workers-lib-emit-node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@repo/typescript-config/lib-emit.json",
"compilerOptions": {
"types": ["@cloudflare/workers-types/2023-07-01", "@types/node"]
}
}
7 changes: 7 additions & 0 deletions packages/typescript-config/workers-lib-emit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@repo/typescript-config/lib-emit.json",
"compilerOptions": {
"types": ["@cloudflare/workers-types/2023-07-01"]
}
}
2 changes: 1 addition & 1 deletion packages/typescript-config/workers-lib-node.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./workers.json",
"extends": "@repo/typescript-config/workers.json",
"compilerOptions": {
"types": ["@cloudflare/workers-types/2023-07-01", "@types/node"]
}
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-config/workers-lib.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./workers.json",
"extends": "@repo/typescript-config/workers.json",
"compilerOptions": {
"types": ["@cloudflare/workers-types/2023-07-01"]
}
Expand Down
16 changes: 8 additions & 8 deletions packages/workers-tagged-logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@
"type": "module",
"exports": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"node": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"module": "./dist/index.mjs",
"types": "./dist/index.d.mts",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "pkgroll --clean-dist",
"build": "runx build tsc ./src/index.ts",
"check:lint": "run-eslint-workers",
"check:types": "run-tsc",
"check:types": "runx check --exports",
"test": "run-vitest"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/workers-tagged-logger/src/hono.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Hono } from 'hono'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'

import { useWorkersLogger } from './hono'
import { setupTest } from './logger.spec'
import { useWorkersLogger } from './hono.js'
import { setupTest } from './logger.spec.js'

beforeEach(() => {
vi.useFakeTimers()
Expand Down
4 changes: 2 additions & 2 deletions packages/workers-tagged-logger/src/hono.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { z } from 'zod'

import { withLogTags, WorkersLogger } from './logger'
import { withLogTags, WorkersLogger } from './logger.js'

import type { Context as HonoContext, Handler as HonoHandler, Next as HonoNext } from 'hono'
import type { LogTags } from './logger'
import type { LogTags } from './logger.js'

export type LoggerHonoBindings = z.infer<typeof LoggerHonoBindings>
export const LoggerHonoBindings = z.object({ ENVIRONMENT: z.string().min(1).optional() })
Expand Down
6 changes: 3 additions & 3 deletions packages/workers-tagged-logger/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { WorkersLogger, withLogTags, ConsoleLog, LogTags } from './logger'
export type { WorkersLoggerOptions } from './logger'
export { useWorkersLogger, LoggerHonoBindings } from './hono'
export { WorkersLogger, withLogTags, ConsoleLog, LogTags } from './logger.js'
export type { WorkersLoggerOptions } from './logger.js'
export { useWorkersLogger, LoggerHonoBindings } from './hono.js'
4 changes: 2 additions & 2 deletions packages/workers-tagged-logger/src/logger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
stringifyMessages,
withLogTags,
WorkersLogger,
} from './logger'
} from './logger.js'

import type { LogTags, WorkersLoggerOptions } from './logger'
import type { LogTags, WorkersLoggerOptions } from './logger.js'

type ParsedConsoleLog = z.infer<typeof ParsedConsoleLog>
const ParsedConsoleLog = ConsoleLog.merge(
Expand Down
2 changes: 1 addition & 1 deletion packages/workers-tagged-logger/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@repo/typescript-config/workers-lib-node.json",
"extends": "@repo/typescript-config/workers-lib-emit.json",
"include": ["**/*.ts"],
"exclude": ["node_modules", "dist", "tsconfig.json"]
}
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"outputLogs": "new-only"
},
"check:types": {
"dependsOn": ["^build", "^check:types"],
"dependsOn": ["^build", "build", "^check:types"],
"outputLogs": "new-only"
},
"check:lint": {
Expand All @@ -56,7 +56,7 @@
"outputLogs": "new-only"
},
"test:ci": {
"dependsOn": ["build", "^build"],
"dependsOn": ["^build", "build"],
"outputLogs": "new-only"
},
"//#build": {
Expand Down

0 comments on commit 204f849

Please sign in to comment.