• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fourTheorem / slic-watch / 25176032713

30 Apr 2026 04:06PM UTC coverage: 97.404% (-0.3%) from 97.662%
25176032713

Pull #128

github

web-flow
Merge bf037c7fb into 14bfabd12
Pull Request #128: Improve typings and update dependencies

264 of 301 branches covered (87.71%)

Branch coverage included in aggregate %.

217 of 228 new or added lines in 8 files covered. (95.18%)

3451 of 3513 relevant lines covered (98.24%)

164.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.19
/serverless-plugin/serverless-plugin.ts
1
import { merge } from 'lodash'
3✔
2
import type Serverless from 'serverless'
3✔
3
import type Hooks from 'serverless-hooks-plugin'
3✔
4
import { type Template } from 'cloudform-types'
3✔
5
import type Resource from 'cloudform-types/types/resource'
3✔
6
import { addAlarms, addDashboard, pluginConfigSchema, functionConfigSchema } from '../core/index'
3✔
7
import { resolveSlicWatchConfig, type ResolvedConfiguration, type SlicWatchConfig } from '../core/inputs/general-config'
3✔
8
import { setLogger } from '../core/logging'
3✔
9

3✔
10
export class ServerlessPluginError extends Error {
3✔
11
  constructor (message: string) {
3✔
NEW
12
    super(message)
×
NEW
13
    this.name = 'ServerlessError'
×
NEW
14
  }
×
15
}
3✔
16

3✔
17
interface ServerlessPluginUtils {
3✔
18
  log: Record<string, unknown> // The Serverless Framework's logger which may be used by plugins to create output
3✔
19
}
3✔
20

3✔
21
interface ServerlessFunctionConfig {
3✔
22
  slicWatch?: SlicWatchConfig
3✔
23
}
3✔
24

3✔
25
class ServerlessPlugin {
3✔
26
  serverless: Serverless
3✔
27
  hooks: Hooks
3✔
28

3✔
29
  /**
3✔
30
     * Plugin constructor according to the Serverless Framework plugin signature
3✔
31
     *
3✔
32
     * @param {*} serverless The Serverless instance
3✔
33
     */
3✔
34
  constructor (serverless: Serverless, _cliOptions: Record<string, unknown>, pluginUtils: ServerlessPluginUtils) {
3✔
35
    this.serverless = serverless
9✔
36

9✔
37
    if (serverless.service.provider.name !== 'aws') {
9!
NEW
38
      throw new ServerlessPluginError('SLIC Watch only supports AWS')
×
39
    }
×
40

9✔
41
    // Serverless framework provides the logger we must use to output updates and errors
9✔
42
    setLogger(pluginUtils.log)
9✔
43

9✔
44
    if (serverless.configSchemaHandler != null) {
9!
45
      serverless.configSchemaHandler.defineCustomProperties(pluginConfigSchema)
×
46
      serverless.configSchemaHandler.defineFunctionProperties('aws', functionConfigSchema)
×
47
    }
×
48

9✔
49
    // Use the latest possible hook to ensure that `Resources` are included in the compiled Template
9✔
50
    this.hooks = { 'after:aws:package:finalize:mergeCustomProviderResources': this.createSlicWatchResources.bind(this) }
9✔
51
  }
9✔
52

3✔
53
  /**
3✔
54
   * Modify the CloudFormation template before the package is finalized
3✔
55
   */
3✔
56
  createSlicWatchResources () {
3✔
57
    const slicWatchConfig: SlicWatchConfig = this.serverless.service.custom?.slicWatch ?? {}
9!
58

9✔
59
    let config: ResolvedConfiguration
9✔
60
    try {
9✔
61
      config = resolveSlicWatchConfig(slicWatchConfig)
9✔
62
    } catch (err) {
9!
NEW
63
      throw new ServerlessPluginError((err as Error).message)
×
64
    }
×
65

9✔
66
    if (config.enabled) {
9✔
67
      const awsProvider = this.serverless.getProvider('aws')
9✔
68

9✔
69
      const compiledTemplate = this.serverless.service.provider.compiledCloudFormationTemplate as Template
9✔
70
      const templateResources = (compiledTemplate.Resources ?? {}) as Record<string, Resource>
9!
71
      compiledTemplate.Resources = templateResources
9✔
72
      const additionalResources = this.serverless.service.resources as Partial<Template> | undefined
9✔
73

9✔
74
      // Each Lambda Function declared in serverless.yml may have a slicWatch configuration
9✔
75
      // to set configuration overrides for the specific function. We transform those into
9✔
76
      // CloudFormation Metadata on the generate AWS::Lambda::Function resource
9✔
77
      const allFunctions = this.serverless.service.getAllFunctions() as string[]
9✔
78
      this.serverless.cli.log(`Setting SLIC Watch configuration for ${allFunctions}`)
9✔
79

9✔
80
      for (const funcName of allFunctions) {
9✔
81
        const func = this.serverless.service.getFunction(funcName) as ServerlessFunctionConfig
33✔
82
        const funcConfig = func.slicWatch ?? {}
33✔
83
        const functionLogicalId = awsProvider.naming.getLambdaLogicalId(funcName)
33✔
84
        const functionResource = templateResources[functionLogicalId]
33✔
85
        if (functionResource != null) {
33✔
86
          functionResource.Metadata = {
33✔
87
            ...(functionResource.Metadata ?? {}),
33!
88
            slicWatch: funcConfig
33✔
89
          }
33✔
90
        }
33✔
91
      }
33✔
92

9✔
93
      if (additionalResources != null) {
9!
NEW
94
        merge(compiledTemplate, additionalResources)
×
NEW
95
      }
×
96
      addDashboard(config.dashboard, compiledTemplate)
9✔
97
      addAlarms(config.alarms, config.alarmActionsConfig, compiledTemplate)
9✔
98
    }
9✔
99
  }
9✔
100
}
3✔
101

3✔
102
export default ServerlessPlugin
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc