Skip to content

Commit 237f6f2

Browse files
committed
fix(attw): improve attw execute, output package name
1 parent aaa30b3 commit 237f6f2

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/features/attw.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import child_process from 'node:child_process'
21
import { mkdtemp, readFile } from 'node:fs/promises'
32
import { tmpdir } from 'node:os'
43
import path from 'node:path'
54
import process from 'node:process'
6-
import { promisify } from 'node:util'
7-
import { blue, dim } from 'ansis'
5+
import { dim } from 'ansis'
86
import Debug from 'debug'
7+
import { exec } from 'tinyexec'
98
import { fsRemove } from '../utils/fs.ts'
109
import { importWithError } from '../utils/general.ts'
10+
import { prettyName } from '../utils/logger.ts'
1111
import type { ResolvedConfig } from '../config/index.ts'
1212
import type { CheckPackageOptions, Problem } from '@arethetypeswrong/core'
1313

1414
const debug = Debug('tsdown:attw')
15-
const exec = promisify(child_process.exec)
1615

1716
export interface AttwOptions extends CheckPackageOptions {
1817
/**
@@ -126,22 +125,14 @@ export async function attw(options: ResolvedConfig): Promise<void> {
126125

127126
const tempDir = await mkdtemp(path.join(tmpdir(), 'tsdown-attw-'))
128127

129-
let attwCore: typeof import('@arethetypeswrong/core')
130-
try {
131-
attwCore = await importWithError<typeof import('@arethetypeswrong/core')>(
132-
'@arethetypeswrong/core',
133-
)
134-
} catch {
135-
options.logger.error(
136-
`ATTW check requires ${blue`@arethetypeswrong/core`} to be installed.`,
137-
)
138-
return
139-
}
140-
128+
const attwCore = await importWithError<
129+
typeof import('@arethetypeswrong/core')
130+
>('@arethetypeswrong/core')
141131
try {
142132
const { stdout: tarballInfo } = await exec(
143-
`npm pack --json ----pack-destination ${tempDir}`,
144-
{ encoding: 'utf8', cwd: options.cwd },
133+
'npm',
134+
['pack', '--json', '--pack-destination', tempDir],
135+
{ nodeOptions: { cwd: options.cwd } },
145136
)
146137
const parsed = JSON.parse(tarballInfo)
147138
if (!Array.isArray(parsed) || !parsed[0]?.filename) {
@@ -170,10 +161,11 @@ export async function attw(options: ResolvedConfig): Promise<void> {
170161
throw new Error(problemMessage)
171162
}
172163

173-
options.logger.warn(problemMessage)
164+
options.logger.warn(prettyName(options.name), problemMessage)
174165
}
175166
} else {
176167
options.logger.success(
168+
prettyName(options.name),
177169
`No Are the types wrong problems found`,
178170
dim`(${Math.round(performance.now() - t)}ms)`,
179171
)

0 commit comments

Comments
 (0)