serverless-plugin-warmup 6.0.0 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintignore CHANGED
@@ -1 +1,2 @@
1
- coverage
1
+ coverage
2
+ test_integration
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  Keep your lambdas warm during winter.
10
10
 
11
11
  **Requirements:**
12
- * Serverless *v1.12.x* or higher (Recommended *v1.33.x* or higher because of [this](https://github.com/juanjoDiaz/serverless-plugin-warmup/pull/69)).
12
+ * Serverless *v2.32.x* or higher
13
13
  * AWS provider
14
14
 
15
15
  ## How it works
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverless-plugin-warmup",
3
- "version": "6.0.0",
3
+ "version": "6.1.0",
4
4
  "description": "Keep your lambdas warm during winter.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -31,8 +31,8 @@
31
31
  "homepage": "https://github.com/juanjoDiaz/serverless-plugin-warmup",
32
32
  "dependencies": {},
33
33
  "devDependencies": {
34
- "eslint": "^7.32.0",
35
- "eslint-config-airbnb-base": "^14.2.1",
34
+ "eslint": "^8.5.0",
35
+ "eslint-config-airbnb-base": "^15.0.0",
36
36
  "eslint-plugin-import": "^2.24.2",
37
37
  "husky": "^7.0.2",
38
38
  "jest": "^27.2.0"
package/src/index.js CHANGED
@@ -116,7 +116,7 @@ class WarmUp {
116
116
 
117
117
  await Promise.all(foldersToClean.map(async (folderToClean) => {
118
118
  try {
119
- await fs.rmdir(
119
+ await fs.rm(
120
120
  path.join(this.serviceDir, folderToClean),
121
121
  { recursive: true },
122
122
  );
@@ -133,7 +133,7 @@ class WarmUp {
133
133
  foldersToClean.some((folder) => folder.startsWith('.warmup'))
134
134
  && (await fs.readdir(defaultDir)).length === 0
135
135
  ) {
136
- await fs.rmdir(defaultDir, { recursive: true });
136
+ await fs.rm(defaultDir, { recursive: true });
137
137
  }
138
138
  } catch (err) {
139
139
  if (err.code !== 'ENOENT') {
@@ -177,6 +177,12 @@ class WarmUp {
177
177
  return;
178
178
  }
179
179
 
180
+ // Avoid double processing due to the workaround for webpack/bundle plugins
181
+ // resetting the plugin and ignoring changes
182
+ if (this.serverless.service.functions[`warmUpPlugin${capitalize(warmerName)}`]) {
183
+ return;
184
+ }
185
+
180
186
  this.serverless.cli.log(`WarmUp: Creating warmer "${warmerName}" to warm up ${warmerConfig.functions.length} function${warmerConfig.functions.length === 1 ? '' : 's'}:`);
181
187
  warmerConfig.functions.forEach((func) => this.serverless.cli.log(` * ${func.name}`));
182
188
 
@@ -207,7 +213,7 @@ class WarmUp {
207
213
  return;
208
214
  }
209
215
 
210
- this.serverless.cli.log(`WarmUp: Prewarming up you functions using warmer "${warmerName}".`);
216
+ this.serverless.cli.log(`WarmUp: Prewarming up your functions using warmer "${warmerName}".`);
211
217
 
212
218
  try {
213
219
  const { SERVERLESS_ALIAS } = this.serverless.service.getFunction(`warmUpPlugin${capitalize(warmerName)}`).environment || {};
package/src/schema.js CHANGED
@@ -5,7 +5,7 @@ function extendServerlessSchema(serverless) {
5
5
  // Most of these are taken from
6
6
  // https://github.com/serverless/serverless/blob/master/lib/configSchema.js
7
7
  // https://github.com/serverless/serverless/blob/master/lib/plugins/aws/provider.js
8
- // https://github.com/serverless/serverless/blob/master/lib/plugins/aws/package/compile/events/schedule/index.js
8
+ // https://github.com/serverless/serverless/blob/master/lib/plugins/aws/package/compile/events/schedule.js
9
9
 
10
10
  const rateSyntax = '^rate\\((?:1 (?:minute|hour|day)|(?:1\\d+|[2-9]\\d*) (?:minute|hour|day)s)\\)$';
11
11
  const cronSyntax = '^cron\\(\\S+ \\S+ \\S+ \\S+ \\S+ \\S+\\)$';
@@ -27,59 +27,71 @@ function extendServerlessSchema(serverless) {
27
27
  type: 'array',
28
28
  items: {
29
29
  type: 'object',
30
- anyOf: [
31
- { type: 'string', pattern: scheduleSyntax },
32
- {
33
- type: 'object',
34
- properties: {
35
- rate: { type: 'string', pattern: scheduleSyntax },
36
- enabled: { type: 'boolean' },
37
- alias: { type: 'string' },
38
- name: {
39
- type: 'string', minLength: 1, maxLength: 64, pattern: '[\\.\\-_A-Za-z0-9]+',
30
+ properties: {
31
+ schedule: {
32
+ anyOf: [
33
+ { type: 'string', pattern: scheduleSyntax },
34
+ {
35
+ type: 'object',
36
+ properties: {
37
+ rate: {
38
+ type: 'array',
39
+ minItems: 1,
40
+ items: {
41
+ type: 'string',
42
+ pattern: scheduleSyntax,
43
+ },
44
+ },
45
+ enabled: { type: 'boolean' },
46
+ name: {
47
+ type: 'string', minLength: 1, maxLength: 64, pattern: '[\\.\\-_A-Za-z0-9]+',
48
+ },
49
+ description: { type: 'string', maxLength: 512 },
50
+ input: {
51
+ anyOf: [
52
+ { type: 'string', maxLength: 8192 },
53
+ {
54
+ type: 'object',
55
+ oneOf: [
56
+ {
57
+ properties: {
58
+ body: { type: 'string', maxLength: 8192 },
59
+ },
60
+ required: ['body'],
61
+ additionalProperties: false,
62
+ },
63
+ {
64
+ not: {
65
+ required: ['body'],
66
+ },
67
+ },
68
+ ],
69
+ },
70
+ ],
71
+ },
72
+ inputPath: { type: 'string', maxLength: 256 },
73
+ inputTransformer: {
74
+ type: 'object',
75
+ properties: {
76
+ inputTemplate: {
77
+ type: 'string',
78
+ minLength: 1,
79
+ maxLength: 8192,
80
+ },
81
+ inputPathsMap: { type: 'object' },
82
+ },
83
+ required: ['inputTemplate'],
84
+ additionalProperties: false,
85
+ },
86
+ },
87
+ required: ['rate'],
88
+ additionalProperties: false,
40
89
  },
41
- description: { type: 'string', maxLength: 512 },
42
- // input: {
43
- // anyOf: [
44
- // { type: 'string', maxLength: 8192 },
45
- // {
46
- // type: 'object',
47
- // oneOf: [
48
- // {
49
- // properties: {
50
- // body: { type: 'string', maxLength: 8192 },
51
- // },
52
- // required: ['body'],
53
- // additionalProperties: false,
54
- // },
55
- // {
56
- // not: {
57
- // required: ['body'],
58
- // },
59
- // },
60
- // ],
61
- // },
62
- // ],
63
- // },
64
- // inputPath: { type: 'string', maxLength: 256 },
65
- // inputTransformer: {
66
- // type: 'object',
67
- // properties: {
68
- // inputTemplate: {
69
- // type: 'string',
70
- // minLength: 1,
71
- // maxLength: 8192,
72
- // },
73
- // inputPathsMap: { type: 'object' },
74
- // },
75
- // required: ['inputTemplate'],
76
- // additionalProperties: false,
77
- // },
78
- },
79
- required: ['rate'],
80
- additionalProperties: false,
90
+ ],
81
91
  },
82
- ],
92
+ },
93
+ required: ['schedule'],
94
+ additionalProperties: false,
83
95
  },
84
96
  },
85
97
  package: {
@@ -123,10 +135,12 @@ function extendServerlessSchema(serverless) {
123
135
  serverless.configSchemaHandler.defineCustomProperties({
124
136
  properties: {
125
137
  warmup: {
126
- '.*': {
127
- type: 'object',
128
- properties: { ...globalConfigSchemaProperties, ...functionConfigSchemaProperties },
129
- additionalProperties: false,
138
+ patternProperties: {
139
+ '.*': {
140
+ type: 'object',
141
+ properties: { ...globalConfigSchemaProperties, ...functionConfigSchemaProperties },
142
+ additionalProperties: false,
143
+ },
130
144
  },
131
145
  },
132
146
  },
@@ -138,10 +152,12 @@ function extendServerlessSchema(serverless) {
138
152
  type: 'object',
139
153
  properties: {
140
154
  warmup: {
141
- '.*': {
142
- type: 'object',
143
- properties: { functionConfigSchemaProperties },
144
- additionalProperties: false,
155
+ patternProperties: {
156
+ '.*': {
157
+ type: 'object',
158
+ properties: { functionConfigSchemaProperties },
159
+ additionalProperties: false,
160
+ },
145
161
  },
146
162
  },
147
163
  },
package/src/warmer.js CHANGED
@@ -228,6 +228,7 @@ function addWarmUpFunctionToService(service, warmerName, warmerConfig) {
228
228
  ...(warmerConfig.role ? { role: warmerConfig.role } : {}),
229
229
  ...(warmerConfig.tags ? { tags: warmerConfig.tags } : {}),
230
230
  ...(warmerConfig.vpc ? { vpc: warmerConfig.vpc } : {}),
231
+ layers: [],
231
232
  };
232
233
  }
233
234