Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

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

32 changes: 28 additions & 4 deletions projects/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"dist/**/*.js"
],
"scripts": {
"dev": "pnpm run nve:install && pnpm dlx @modelcontextprotocol/inspector@0.21.2 node ./dist/index.js mcp",
"dev": "pnpm run nve:install && npx @modelcontextprotocol/inspector@0.21.2 node ./dist/index.js mcp",
Comment thread
coryrylan marked this conversation as resolved.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added npx here due to modelcontextprotocol/inspector#873

"ci": "wireit",
"build": "wireit",
"lint": "wireit",
Expand All @@ -47,22 +47,23 @@
"nve:uninstall:node": "pnpm uninstall --global @nvidia-elements/cli"
},
"dependencies": {
"@nvidia-elements/lint": "workspace:^",
"@inquirer/prompts": "8.4.2",
"@modelcontextprotocol/sdk": "1.29.0",
"@nvidia-elements/code": "workspace:*",
"@nvidia-elements/lint": "workspace:^",
"adm-zip": "0.5.17",
"archiver": "7.0.1",
"marked": "18.0.3",
"marked-terminal": "7.3.0",
"open": "11.0.0",
"ora": "9.4.0",
"publint": "catalog:",
"yargs": "18.0.0",
"open": "11.0.0",
"zod": "catalog:"
},
"devDependencies": {
"@internals/tools": "workspace:*",
"@internals/eslint": "workspace:*",
"@internals/tools": "workspace:*",
"@internals/vite": "workspace:*",
"@vitest/coverage-istanbul": "catalog:",
"@types/node": "catalog:",
Expand Down Expand Up @@ -117,6 +118,13 @@
"command": "NODE_ENV=production vite build",
"files": [
"../internals/tools/dist/**/*.js",
"../core/dist/bundles/index.js",
"../code/dist/bundles/index.js",
"../themes/dist/index.css",
"../themes/dist/dark.css",
"../themes/dist/high-contrast.css",
"../styles/dist/typography.css",
"../styles/dist/layout.css",
"src/**",
"!src/**/*.test.ts",
"package.json",
Expand All @@ -135,6 +143,22 @@
{
"script": "../internals/tools:build",
"cascade": false
},
{
"script": "../core:build",
"cascade": false
},
{
"script": "../code:build",
"cascade": false
},
{
"script": "../themes:build",
"cascade": false
},
{
"script": "../styles:build",
"cascade": false
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLI now relies on these builds since we create the mcp-app html files

}
]
},
Expand Down
37 changes: 36 additions & 1 deletion projects/cli/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ describe('index', () => {
input: ''
});
expect(result.status).toBe(1);
expect(result.stderr + result.stdout).toContain('Invalid values');
expect(result.stdout).toBe('');
expect(result.stderr).toContain('Invalid values');
});
});

Expand All @@ -116,4 +117,38 @@ describe('index', () => {
expect(combined).toContain('nve-bar');
});
});

describe('tool errors', () => {
it('should exit with error when exact api lookup has no matches', () => {
const result = spawnSync('node', ['dist/index.js', 'api.get', 'nve-badges'], {
timeout: 10000,
encoding: 'utf-8',
input: ''
});

expect(result.status).toBe(1);
expect(result.stdout).toBe('');
expect(result.stderr).toContain('No components or APIs found matching');
expect(result.stderr).toContain('nve-badges');
});
Comment thread
coryrylan marked this conversation as resolved.

it('should print structured error results when they are available', () => {
const result = spawnSync(
'node',
['dist/index.js', 'playground.create', '<nve-button nve-layout="column">hello</nve-button>'],
{
timeout: 10000,
encoding: 'utf-8',
input: '',
env: { ...process.env, CI: 'true', ELEMENTS_PLAYGROUND_BASE_URL: 'https://playground.example' }
}
);
const lintMessages = JSON.parse(result.stderr) as { message: string }[];

expect(result.status).toBe(1);
expect(result.stdout).toBe('');
expect(Array.isArray(lintMessages)).toBe(true);
expect(lintMessages[0]?.message).toContain('Unexpected use of restricted attribute "nve-layout"');
});
});
});
14 changes: 8 additions & 6 deletions projects/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const yargsInstance = yargs(hideBin(process.argv))
}

if (message !== null) {
console.log(colors.error(message));
console.error(colors.error(message));
}
process.exit(1);
});
Expand All @@ -45,6 +45,11 @@ yargsInstance.middleware(argv => {
}
});

async function exitWithToolError(result: unknown, message: string | undefined): Promise<never> {
console.error(result === undefined ? colors.error(message ?? 'unknown error') : await renderResult(result));
process.exit(1);
}

yargsInstance.command(
'$0',
'About and help',
Expand All @@ -57,8 +62,7 @@ yargsInstance.command(
await renderResult(result);
process.exit(0);
} else {
console.log(colors.error(message ?? 'unknown error'));
process.exit(1);
await exitWithToolError(result, message);
}
} else {
const greeting = colors.complete(`\x1b[?7l\n${JSON.parse(banner)}\n\n`);
Expand Down Expand Up @@ -102,7 +106,6 @@ tools
optionalArgs.forEach(key => builder.option(key, argOptions(properties[key]!)));
},
// main handler for the command
// eslint-disable-next-line max-statements
async args => {
const start = performance.now();
const { result, status, message } = await runAsyncTool(args, tool);
Expand All @@ -121,8 +124,7 @@ tools
await notifyIfUpdateAvailable(BUILD_SHA);
process.exit(0);
} else {
console.log(colors.error(message ?? 'unknown error'));
process.exit(1);
await exitWithToolError(result, message);
}
},
// middleware to get interactive arguments when missing
Expand Down
Loading