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

fourTheorem / slic-watch / 25389622734

05 May 2026 04:43PM UTC coverage: 97.404% (-0.3%) from 97.662%
25389622734

Pull #128

github

web-flow
Merge 0b1db15b0 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%)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© 2026 Coveralls, Inc