Skip to content

Commit

Permalink
fix: remove compress unused option
Browse files Browse the repository at this point in the history
  • Loading branch information
SoaresMG committed Aug 8, 2024
1 parent 90d0c48 commit e3b3d66
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-buses-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nuxt-mock-server": patch
---

fix: remove compress unused option
2 changes: 0 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export interface ModuleOptions {
enabled?: boolean;
pathMatch?: string;
mockDir?: string;
compress?: boolean;
devtools?: boolean;
}

Expand All @@ -35,7 +34,6 @@ export default defineNuxtModule<ModuleOptions>({
enabled: false,
pathMatch: "^\\/api\\/.*$",
mockDir: "mocks",
compress: false,
devtools: true,
},
async setup(options, nuxt) {
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/server/formatters/auto-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ export class AutoFormatter implements BaseFormatter {
protected formatters: Record<FormatterDataType, BaseFormatter>;
private defaultFormatter: JsonFormatter;

constructor(outputDir: string, compressionEnabled: boolean, onError: OnErrorCallback) {
this.defaultFormatter = new JsonFormatter(outputDir, compressionEnabled, onError);
const textFormatter = new TextFormatter(outputDir, compressionEnabled, onError);
constructor(outputDir: string, onError: OnErrorCallback) {
this.defaultFormatter = new JsonFormatter(outputDir, onError);
const textFormatter = new TextFormatter(outputDir, onError);

this.formatters = {
"application/json": this.defaultFormatter,
"application/xml": textFormatter,
"text/plain": textFormatter,
"text/html": textFormatter,
"application/octet-stream": new StreamFormatter(outputDir, compressionEnabled, onError),
"application/octet-stream": new StreamFormatter(outputDir, onError),
};
}

Expand Down
4 changes: 1 addition & 3 deletions src/runtime/server/formatters/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ export type OnErrorCallback = (err: Error) => void;

export abstract class Formatter implements BaseFormatter {
protected outputDir: string;
protected compressionEnabled: boolean;
onError: OnErrorCallback;

constructor(outputDir: string, compressionEnabled: boolean, onError: OnErrorCallback) {
constructor(outputDir: string, onError: OnErrorCallback) {
this.outputDir = outputDir;
this.compressionEnabled = compressionEnabled;
this.onError = onError;
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/server/plugins/mock-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default defineNitroPlugin((nitro) => {

const routeRegExp = new RegExp(mockServer.pathMatch);

const formatter = new AutoFormatter(mockServer.mockDir, !!mockServer.compress, consola.error);
const formatter = new AutoFormatter(mockServer.mockDir, consola.error);

nitro.hooks.hook("request", defineErrorHandler(async (event) => {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/server/routes/__mock-server__/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default defineEventHandler(async () => {
return;
}

const formatter = new AutoFormatter(mockServer.mockDir, !!mockServer.compress, consola.error);
const formatter = new AutoFormatter(mockServer.mockDir, consola.error);
const mockFiles = await fs.readdir(mockServer.mockDir);
return (await Promise.all(mockFiles.map(file => formatter.getEntry(file)))).filter(notUndefinedOrNull);
});

0 comments on commit e3b3d66

Please sign in to comment.