Merge remote-tracking branch 'origin/main' into deploy

This commit is contained in:
Alex Gleason committed 2025-10-18 16:15:35 -05:00
commit 2bb07a2e5a
5 files changed
+114 -147

No files matched your search

+10 -12
View File
@@ -32,11 +32,16 @@ async function bundle(
);
// Read package.json
const packageJsonText = await fs.readFile(
`${projectPath}/package.json`,
"utf8",
);
const packageJson = JSON.parse(packageJsonText);
let packageJson;
try {
const packageJsonText = await fs.readFile(
`${projectPath}/package.json`,
"utf8",
);
packageJson = JSON.parse(packageJsonText);
} catch {
packageJson = {};
}
// Try to read tsconfig.json
let tsconfig;
@@ -187,13 +192,6 @@ export async function buildProject(options: BuildProjectOptions): Promise<{
}> {
const { fs, projectPath, outputPath = `${projectPath}/dist` } = options;
// Check if we're in a valid project directory
try {
await fs.readFile(`${projectPath}/package.json`, "utf8");
} catch {
throw new Error(`❌ Could not find package.json at ${projectPath}. Make sure you're in a valid project directory.`);
}
// Check if index.html exists
try {
await fs.readFile(`${projectPath}/index.html`, "utf8");
+81 -3
View File
@@ -190,7 +190,7 @@ describe('CurlCommand', () => {
expect(result.stdout).toContain('100 12 100 12');
});
it('should be silent when -s flag is used', async () => {
it('should still output response body when -s flag is used', async () => {
const mockResponse = {
ok: true,
status: 200,
@@ -205,7 +205,7 @@ describe('CurlCommand', () => {
const result = await curlCommand.execute(['-s', 'https://example.com'], '/test');
expect(result.exitCode).toBe(0);
expect(result.stdout).toBe('');
expect(result.stdout).toBe('Hello World');
});
it('should handle HTTP error responses', async () => {
@@ -272,7 +272,9 @@ describe('CurlCommand', () => {
const result = await curlCommand.execute(['-si', 'https://example.com'], '/test');
expect(result.exitCode).toBe(0);
expect(result.stdout).toBe(''); // Silent mode
// Silent mode still shows response body and headers (when -i is used)
expect(result.stdout).toContain('HTTP/1.1 200 OK');
expect(result.stdout).toContain('Hello World');
});
it('should handle write-out format', async () => {
@@ -306,6 +308,82 @@ describe('CurlCommand', () => {
expect(result.stderr).toContain('Network error');
});
it('should suppress errors when -s is used alone', async () => {
const mockResponse = {
ok: false,
status: 404,
statusText: 'Not Found',
url: 'https://example.com/notfound',
text: vi.fn().mockResolvedValue('Page not found'),
headers: new Map(),
redirected: false,
};
mockFetch.mockResolvedValue(mockResponse);
const result = await curlCommand.execute(['-s', 'https://example.com/notfound'], '/test');
expect(result.exitCode).toBe(0);
expect(result.stdout).toBe('Page not found');
expect(result.stderr).toBe('');
});
it('should show errors when -sS is used together', async () => {
const mockResponse = {
ok: false,
status: 404,
statusText: 'Not Found',
url: 'https://example.com/notfound',
text: vi.fn().mockResolvedValue('Page not found'),
headers: new Map(),
redirected: false,
};
mockFetch.mockResolvedValue(mockResponse);
const result = await curlCommand.execute(['-sS', 'https://example.com/notfound'], '/test');
expect(result.exitCode).toBe(1);
expect(result.stderr).toContain('HTTP 404: Not Found');
expect(result.stderr).toContain('Page not found');
});
it('should show errors when -S is used with -s separately', async () => {
const mockResponse = {
ok: false,
status: 500,
statusText: 'Internal Server Error',
url: 'https://example.com/error',
text: vi.fn().mockResolvedValue('Server error'),
headers: new Map(),
redirected: false,
};
mockFetch.mockResolvedValue(mockResponse);
const result = await curlCommand.execute(['-s', '-S', 'https://example.com/error'], '/test');
expect(result.exitCode).toBe(1);
expect(result.stderr).toContain('HTTP 500: Internal Server Error');
expect(result.stderr).toContain('Server error');
});
it('should suppress network errors when -s is used alone', async () => {
mockFetch.mockRejectedValue(new Error('Network error'));
const result = await curlCommand.execute(['-s', 'https://example.com'], '/test');
expect(result.exitCode).toBe(0);
expect(result.stdout).toBe('');
expect(result.stderr).toBe('');
});
it('should show network errors when -sS is used together', async () => {
mockFetch.mockRejectedValue(new Error('Network error'));
const result = await curlCommand.execute(['-sS', 'https://example.com'], '/test');
expect(result.exitCode).toBe(1);
expect(result.stderr).toContain('Network error');
});
it('should handle timeout', async () => {
vi.useFakeTimers();
+21 -9
View File
@@ -16,6 +16,7 @@ interface CurlOptions {
includeHeaders: boolean;
followRedirects: boolean;
silent: boolean;
showError: boolean;
verbose: boolean;
userAgent?: string;
timeout?: number;
@@ -144,15 +145,16 @@ export class CurlCommand implements ShellCommand {
}
// Handle non-success status codes
if (!response.ok && !options.silent) {
if (!response.ok) {
const shouldShowError = !options.silent || options.showError;
const errorMsg = `HTTP ${response.status}: ${response.statusText}`;
if (options.output) {
// Still write to file even on error
await this.writeToFile(options.output, responseText, cwd);
return createErrorResult(errorMsg);
return shouldShowError ? createErrorResult(errorMsg) : createSuccessResult('');
} else {
output += responseText;
return createErrorResult(`${errorMsg}\n${output}`);
return shouldShowError ? createErrorResult(`${errorMsg}\n${output}`) : createSuccessResult(output);
}
}
@@ -171,20 +173,21 @@ export class CurlCommand implements ShellCommand {
// Handle write-out format
if (options.writeOut) {
const writeOutResult = this.formatWriteOut(options.writeOut, response, responseText);
if (options.silent) {
return createSuccessResult(writeOutResult);
} else {
output += '\n' + writeOutResult;
}
output += '\n' + writeOutResult;
}
return createSuccessResult(options.silent ? '' : output);
return createSuccessResult(output);
} catch (error) {
if (timeoutId) {
clearTimeout(timeoutId);
}
const shouldShowError = !options.silent || options.showError;
if (!shouldShowError) {
return createSuccessResult('');
}
if (error instanceof Error) {
if (error.name === 'AbortError') {
return createErrorResult(`${this.name}: operation timed out after ${options.timeout} seconds`);
@@ -213,6 +216,7 @@ export class CurlCommand implements ShellCommand {
includeHeaders: false,
followRedirects: true,
silent: false,
showError: false,
verbose: false,
maxRedirects: 50,
showProgress: true,
@@ -283,6 +287,11 @@ export class CurlCommand implements ShellCommand {
options.showProgress = false;
break;
case '-S':
case '--show-error':
options.showError = true;
break;
case '-v':
case '--verbose':
options.verbose = true;
@@ -333,6 +342,9 @@ export class CurlCommand implements ShellCommand {
options.silent = true;
options.showProgress = false;
break;
case '-S':
options.showError = true;
break;
case '-L':
options.followRedirects = true;
break;