|
6 | 6 | * and may be running at the same time. It is laid out as the published package is, `dist/` beside `assets/` and |
7 | 7 | * `skills/`, which the compiled code reads from its own directory's parent. |
8 | 8 | */ |
9 | | -import { execFile } from 'node:child_process'; |
10 | 9 | import fs from 'node:fs'; |
11 | 10 | import path from 'node:path'; |
12 | 11 | import { fileURLToPath } from 'node:url'; |
13 | | -import { promisify } from 'node:util'; |
| 12 | +import { buildForTests } from '../src/cli-spec/build'; |
14 | 13 |
|
15 | 14 | export const packageDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); |
16 | 15 | const copyDir = path.join(packageDir, 'node_modules', '.cache', 'cli-e2e'); |
17 | 16 | export const buildDir = path.join(copyDir, 'dist'); |
18 | 17 | export const cliPath = path.join(buildDir, 'cli.js'); |
19 | 18 |
|
20 | | -/** |
21 | | - * TypeScript's `bin/tsc`, from the nearest `node_modules/typescript` at or above `dir`. (The global |
22 | | - * setup runs where `import.meta.resolve` isn't available, and TypeScript 7 exports no `bin/tsc`.) |
23 | | - */ |
24 | | -function findTsc(dir: string): string { |
25 | | - const tsc = path.join(dir, 'node_modules', 'typescript', 'bin', 'tsc'); |
26 | | - if (fs.existsSync(tsc)) { |
27 | | - return tsc; |
28 | | - } |
29 | | - const parent = path.dirname(dir); |
30 | | - if (parent === dir) { |
31 | | - throw new Error('typescript is not installed'); |
32 | | - } |
33 | | - return findTsc(parent); |
34 | | -} |
35 | | - |
36 | 19 | export async function buildCli(): Promise<void> { |
37 | | - const tsc = findTsc(packageDir); |
38 | 20 | fs.rmSync(copyDir, { recursive: true, force: true }); |
39 | 21 | for (const dir of ['assets', 'skills']) { |
40 | 22 | fs.cpSync(path.join(packageDir, dir), path.join(copyDir, dir), { recursive: true }); |
41 | 23 | } |
42 | | - await promisify(execFile)( |
43 | | - process.execPath, |
44 | | - [ |
45 | | - tsc, |
46 | | - '-p', |
47 | | - path.join(packageDir, 'tsconfig.build.json'), |
48 | | - '--outDir', |
49 | | - buildDir, |
50 | | - // A build the tests only run: no source maps, which would name sources outside the |
51 | | - // build's folder, and no declarations. |
52 | | - '--sourceMap', |
53 | | - 'false', |
54 | | - '--declaration', |
55 | | - 'false', |
56 | | - ], |
57 | | - { cwd: packageDir }, |
58 | | - ); |
| 24 | + await buildForTests(buildDir); |
59 | 25 | } |
0 commit comments