Skip to content

Commit

Permalink
fix: merge custom options with default options deeply
Browse files Browse the repository at this point in the history
Previously, the options were not merged deeply, so if anything was set
under e.g. watch, all of the default options under watch also had to be
specified to keep the defaults. This includes the pattern, so if you set
watch.ignore or watch.chokidar, you had to set watch.pattern otherwise
nothing would be watched.

Unfortunately, I had to cast the result to get the correct types here
because mergeDeepRight doesn't set the correct types for array
properties. See DefinitelyTyped/DefinitelyTyped#64424
  • Loading branch information
trygveaa authored and floydspace committed Feb 20, 2023
1 parent d27ff5d commit 1489525
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';
import fs from 'fs-extra';
import globby from 'globby';

import { concat, mergeRight } from 'ramda';
import { concat, mergeDeepRight } from 'ramda';
import type Serverless from 'serverless';
import type ServerlessPlugin from 'serverless/classes/Plugin';
import chokidar from 'chokidar';
Expand Down Expand Up @@ -296,16 +296,16 @@ class EsbuildServerlessPlugin implements ServerlessPlugin {
const resolvedOptions = {
...(target ? { target } : {}),
};
const withDefaultOptions = mergeRight(DEFAULT_BUILD_OPTIONS);
const withResolvedOptions = mergeRight(withDefaultOptions(resolvedOptions));
const withDefaultOptions = mergeDeepRight(DEFAULT_BUILD_OPTIONS);
const withResolvedOptions = mergeDeepRight(withDefaultOptions(resolvedOptions));

const configPath: string | undefined = this.serverless.service.custom?.esbuild?.config;

const config: ConfigFn | undefined = configPath ? require(path.join(this.serviceDirPath, configPath)) : undefined;

return withResolvedOptions<Configuration>(
config ? config(this.serverless) : this.serverless.service.custom?.esbuild ?? {}
);
) as Configuration;
}

get functionEntries() {
Expand Down

0 comments on commit 1489525

Please sign in to comment.