|
1 | | -import child_process from 'node:child_process' |
2 | 1 | import { mkdtemp, readFile } from 'node:fs/promises' |
3 | 2 | import { tmpdir } from 'node:os' |
4 | 3 | import path from 'node:path' |
5 | 4 | import process from 'node:process' |
6 | | -import { promisify } from 'node:util' |
7 | | -import { blue, dim } from 'ansis' |
| 5 | +import { dim } from 'ansis' |
8 | 6 | import Debug from 'debug' |
| 7 | +import { exec } from 'tinyexec' |
9 | 8 | import { fsRemove } from '../utils/fs.ts' |
10 | 9 | import { importWithError } from '../utils/general.ts' |
| 10 | +import { prettyName } from '../utils/logger.ts' |
11 | 11 | import type { ResolvedConfig } from '../config/index.ts' |
12 | 12 | import type { CheckPackageOptions, Problem } from '@arethetypeswrong/core' |
13 | 13 |
|
14 | 14 | const debug = Debug('tsdown:attw') |
15 | | -const exec = promisify(child_process.exec) |
16 | 15 |
|
17 | 16 | export interface AttwOptions extends CheckPackageOptions { |
18 | 17 | /** |
@@ -126,22 +125,14 @@ export async function attw(options: ResolvedConfig): Promise<void> { |
126 | 125 |
|
127 | 126 | const tempDir = await mkdtemp(path.join(tmpdir(), 'tsdown-attw-')) |
128 | 127 |
|
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') |
141 | 131 | try { |
142 | 132 | 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 } }, |
145 | 136 | ) |
146 | 137 | const parsed = JSON.parse(tarballInfo) |
147 | 138 | if (!Array.isArray(parsed) || !parsed[0]?.filename) { |
@@ -170,10 +161,11 @@ export async function attw(options: ResolvedConfig): Promise<void> { |
170 | 161 | throw new Error(problemMessage) |
171 | 162 | } |
172 | 163 |
|
173 | | - options.logger.warn(problemMessage) |
| 164 | + options.logger.warn(prettyName(options.name), problemMessage) |
174 | 165 | } |
175 | 166 | } else { |
176 | 167 | options.logger.success( |
| 168 | + prettyName(options.name), |
177 | 169 | `No Are the types wrong problems found`, |
178 | 170 | dim`(${Math.round(performance.now() - t)}ms)`, |
179 | 171 | ) |
|
0 commit comments