Skip to content

Commit

Permalink
fix(nginx): drop semicolon char
Browse files Browse the repository at this point in the history
  • Loading branch information
juanrgm committed Nov 27, 2023
1 parent 16dcdb4 commit 3d9e3ee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-cooks-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@anymodel/nginx": patch
---

Fix map directive
8 changes: 5 additions & 3 deletions packages/nginx/src/directives/AbstractDirective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export type Config<T> = Required<{
| null
| ((
value: NonNullable<T[K]>,
level: number
level: number,
settigs: { semicolon: boolean }
) => string | (string | AbstractContext<any, any>)[]);
}>;

Expand All @@ -19,8 +20,9 @@ export abstract class AbstractDirective<T> {
config?: Config<any>
) {
const configCb = config?.[key];
const settings = { semicolon: true };
if (configCb) {
value = configCb(value, level);
value = configCb(value, level, settings);
}

const values: any[] = [];
Expand All @@ -43,7 +45,7 @@ export abstract class AbstractDirective<T> {
if (v instanceof AbstractContext) {
return v.toString(level);
} else {
return `${padding}${key} ${v};`;
return `${padding}${key} ${v}${settings.semicolon ? `;` : ""}`;
}
})
.join("\n");
Expand Down
3 changes: 2 additions & 1 deletion packages/nginx/src/directives/HttpMapDirective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type HttpMapDirectiveSpec = {
export class HttpMapDirective extends AbstractDirective<HttpMapDirectiveSpec> {
static type = "httpMap" as const;
static config: Config<HttpMapDirectiveSpec> = {
map: (dir, level) =>
map: (dir, level, settings) =>
dir.map((item) => {
const pad = " ".repeat(level + 1);
const values = Object.entries(item.values)
Expand All @@ -34,6 +34,7 @@ export class HttpMapDirective extends AbstractDirective<HttpMapDirectiveSpec> {
return result;
}, [] as string[])
.join("\n");
settings.semicolon = false;
return `${item.source} ${item.variable} {\n${values}\n${pad}}`;
}),
map_hash_bucket_size: null,
Expand Down

0 comments on commit 3d9e3ee

Please sign in to comment.