Skip to content

Commit df3d097

Browse files
committed
Fix CLI napi build for MCP tests
1 parent e163aeb commit df3d097

File tree

3 files changed

+35
-52
lines changed

3 files changed

+35
-52
lines changed

cli/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
},
5050
"scripts": {
5151
"build": "run-s build:deps build:napi bundle finalize:bundle generate:schema",
52-
"build:napi": "tsx ../scripts/copy-napi.ts",
52+
"build:napi": "run-s build:native build:napi:copy",
53+
"build:napi:copy": "tsx ../scripts/copy-napi.ts",
54+
"build:native": "napi build --platform --release --output-dir dist -- --features napi",
5355
"build:deps": "pnpm -F @truenine/logger -F @truenine/md-compiler -F @truenine/script-runtime run build",
5456
"build:deps:ts": "pnpm -F @truenine/logger -F @truenine/md-compiler -F @truenine/script-runtime run build:ts",
5557
"bundle": "tsx ../scripts/build-quiet.ts",

cli/test/native-binding/cleanup.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import type {DeletionError} from './desk-paths'
1212
import * as fs from 'node:fs'
1313
import * as path from 'node:path'
1414
import glob from 'fast-glob'
15-
import {buildDiagnostic, buildFileOperationDiagnostic, diagnosticLines} from '@/diagnostics'
1615
import {compactDeletionTargets} from '../../src/cleanup/delete-targets'
1716
import {planWorkspaceEmptyDirectoryCleanup} from '../../src/cleanup/empty-directories'
17+
import {buildDiagnostic, buildFileOperationDiagnostic, diagnosticLines} from '../../src/diagnostics'
1818
import {collectAllPluginOutputs} from '../../src/plugins/plugin-core'
1919
import {
2020
buildComparisonKeys,
@@ -231,8 +231,9 @@ async function collectCleanupTargets(
231231
return target.kind === 'file' ? 'direct' : 'recursive'
232232
}
233233

234-
for (const rule of collectProtectedInputSourceRules(cleanCtx.collectedOutputContext))
235-
{ addProtectRule(rule.path, rule.protectionMode, rule.reason, rule.source) }
234+
for (const rule of collectProtectedInputSourceRules(cleanCtx.collectedOutputContext)) {
235+
addProtectRule(rule.path, rule.protectionMode, rule.reason, rule.source)
236+
}
236237
if (cleanCtx.collectedOutputContext.aindexDir != null && cleanCtx.pluginOptions != null) {
237238
for (const rule of collectConfiguredAindexInputRules(cleanCtx.pluginOptions as Required<PluginOptions>, cleanCtx.collectedOutputContext.aindexDir, {
238239
workspaceDir: cleanCtx.collectedOutputContext.workspace.directory.path

cli/test/native-binding/desk-paths.ts

Lines changed: 28 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type {LoggerDiagnosticInput} from '../../src/plugins/plugin-core'
33
import * as fs from 'node:fs'
44
import path from 'node:path'
55
import process from 'node:process'
6-
import {buildFileOperationDiagnostic} from '@/diagnostics'
7-
import {resolveRuntimeEnvironment, resolveUserPath} from '@/runtime-environment'
6+
import {buildFileOperationDiagnostic} from '../../src/diagnostics'
7+
import {resolveRuntimeEnvironment, resolveUserPath} from '../../src/runtime-environment'
88

99
type PlatformFixedDir = 'win32' | 'darwin' | 'linux'
1010

@@ -41,8 +41,7 @@ export function deletePathSync(p: string): void {
4141
if (stat.isSymbolicLink()) {
4242
if (process.platform === 'win32') fs.rmSync(p, {recursive: true, force: true})
4343
else fs.unlinkSync(p)
44-
}
45-
else if (stat.isDirectory()) fs.rmSync(p, {recursive: true, force: true})
44+
} else if (stat.isDirectory()) fs.rmSync(p, {recursive: true, force: true})
4645
else fs.unlinkSync(p)
4746
}
4847

@@ -56,8 +55,7 @@ export function writeFileSync(filePath: string, data: string | Buffer, encoding:
5655
export function readFileSync(filePath: string, encoding: BufferEncoding = 'utf8'): string {
5756
try {
5857
return fs.readFileSync(filePath, encoding)
59-
}
60-
catch (error) {
58+
} catch (error) {
6159
const msg = error instanceof Error ? error.message : String(error)
6260
throw new Error(`Failed to read file "${filePath}": ${msg}`)
6361
}
@@ -98,8 +96,7 @@ async function deletePath(p: string): Promise<boolean> {
9896

9997
await fs.promises.unlink(p)
10098
return true
101-
}
102-
catch (error) {
99+
} catch (error) {
103100
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return false
104101
throw error
105102
}
@@ -109,19 +106,14 @@ async function deleteEmptyDirectory(p: string): Promise<boolean> {
109106
try {
110107
await fs.promises.rmdir(p)
111108
return true
112-
}
113-
catch (error) {
109+
} catch (error) {
114110
const {code} = error as NodeJS.ErrnoException
115111
if (code === 'ENOENT' || code === 'ENOTEMPTY') return false
116112
throw error
117113
}
118114
}
119115

120-
async function mapWithConcurrencyLimit<T, TResult>(
121-
items: readonly T[],
122-
concurrency: number,
123-
worker: (item: T) => Promise<TResult>
124-
): Promise<TResult[]> {
116+
async function mapWithConcurrencyLimit<T, TResult>(items: readonly T[], concurrency: number, worker: (item: T) => Promise<TResult>): Promise<TResult[]> {
125117
if (items.length === 0) return []
126118

127119
const results: TResult[] = []
@@ -147,20 +139,14 @@ async function mapWithConcurrencyLimit<T, TResult>(
147139
return results
148140
}
149141

150-
async function deletePaths(
151-
paths: readonly string[],
152-
options?: {readonly sortByDepthDescending?: boolean}
153-
): Promise<DeletionResult> {
154-
const sortedPaths = options?.sortByDepthDescending === true
155-
? [...paths].sort((a, b) => b.length - a.length || b.localeCompare(a))
156-
: [...paths]
142+
async function deletePaths(paths: readonly string[], options?: {readonly sortByDepthDescending?: boolean}): Promise<DeletionResult> {
143+
const sortedPaths = options?.sortByDepthDescending === true ? [...paths].sort((a, b) => b.length - a.length || b.localeCompare(a)) : [...paths]
157144

158145
const results = await mapWithConcurrencyLimit(sortedPaths, DELETE_CONCURRENCY, async currentPath => {
159146
try {
160147
const deleted = await deletePath(currentPath)
161148
return {path: currentPath, deleted}
162-
}
163-
catch (error) {
149+
} catch (error) {
164150
return {path: currentPath, error}
165151
}
166152
})
@@ -201,8 +187,7 @@ export async function deleteEmptyDirectories(dirs: readonly string[]): Promise<D
201187
try {
202188
const deleted = await deleteEmptyDirectory(currentPath)
203189
if (deleted) deletedPaths.push(currentPath)
204-
}
205-
catch (error) {
190+
} catch (error) {
206191
errors.push({path: currentPath, error})
207192
}
208193
}
@@ -214,14 +199,8 @@ export async function deleteEmptyDirectories(dirs: readonly string[]): Promise<D
214199
}
215200
}
216201

217-
export async function deleteTargets(targets: {
218-
readonly files?: readonly string[]
219-
readonly dirs?: readonly string[]
220-
}): Promise<DeleteTargetsResult> {
221-
const [fileResult, dirResult] = await Promise.all([
222-
deleteFiles(targets.files ?? []),
223-
deleteDirectories(targets.dirs ?? [])
224-
])
202+
export async function deleteTargets(targets: {readonly files?: readonly string[], readonly dirs?: readonly string[]}): Promise<DeleteTargetsResult> {
203+
const [fileResult, dirResult] = await Promise.all([deleteFiles(targets.files ?? []), deleteDirectories(targets.dirs ?? [])])
225204

226205
return {
227206
deletedFiles: fileResult.deletedPaths,
@@ -264,21 +243,22 @@ export function writeFileSafe(options: SafeWriteOptions): SafeWriteResult {
264243
writeFileSync(fullPath, content)
265244
logger.trace({action: 'write', type, path: fullPath})
266245
return {path: relativePath, success: true}
267-
}
268-
catch (error) {
246+
} catch (error) {
269247
const errMsg = error instanceof Error ? error.message : String(error)
270-
logger.error(buildFileOperationDiagnostic({
271-
code: 'OUTPUT_FILE_WRITE_FAILED',
272-
title: `Failed to write ${type} output`,
273-
operation: 'write',
274-
targetKind: `${type} output file`,
275-
path: fullPath,
276-
error: errMsg,
277-
details: {
278-
relativePath,
279-
type
280-
}
281-
}))
248+
logger.error(
249+
buildFileOperationDiagnostic({
250+
code: 'OUTPUT_FILE_WRITE_FAILED',
251+
title: `Failed to write ${type} output`,
252+
operation: 'write',
253+
targetKind: `${type} output file`,
254+
path: fullPath,
255+
error: errMsg,
256+
details: {
257+
relativePath,
258+
type
259+
}
260+
})
261+
)
282262
return {path: relativePath, success: false, error: error as Error}
283263
}
284264
}

0 commit comments

Comments
 (0)