Skip to content

Commit 778d011

Browse files
authored
Merge pull request #1959 from serverless-heaven/feat/serverless-v4
Add support for Serverless v4
2 parents 0189c33 + a3bc239 commit 778d011

File tree

20 files changed

+2742
-31
lines changed

20 files changed

+2742
-31
lines changed

.github/dependabot.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ updates:
1717
- dependency-name: glob
1818
versions:
1919
- '>= 9.0.0'
20+
# because tests aren't compatible
21+
- dependency-name: serverless
22+
versions:
23+
- '>= 4.0.0'
2024
- package-ecosystem: github-actions
2125
directory: '/'
2226
schedule:

.github/workflows/tests.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,39 @@ jobs:
132132

133133
- name: 'Run tests'
134134
run: 'npm run test'
135+
136+
serverless-v4:
137+
runs-on: ${{ matrix.os }}
138+
name: Node.js ${{ matrix.node }} on ${{ matrix.os }} with Serverless v4
139+
140+
strategy:
141+
matrix:
142+
os:
143+
- ubuntu-20.04
144+
node:
145+
- '20'
146+
147+
steps:
148+
- name: 'Checkout'
149+
uses: actions/checkout@v4
150+
with:
151+
fetch-depth: 2
152+
153+
- name: 'Install Node.js'
154+
uses: actions/setup-node@v4
155+
with:
156+
node-version: '${{ matrix.node }}'
157+
158+
- name: 'Install dependencies'
159+
run: npm ci
160+
161+
- name: 'Install Serverless v4'
162+
run: npm install serverless@4
163+
164+
- name: 'Run tests'
165+
run: npm run test tests/e2e/e2e.test.js
166+
env:
167+
AWS_DEFAULT_REGION: eu-west-1
168+
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}}
169+
AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY}}
170+
SERVERLESS_ACCESS_KEY: ${{secrets.SERVERLESS_ACCESS_KEY}}

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ plugins:
4949
- serverless-webpack
5050
```
5151
52+
## Serverless v4 requirement
53+
54+
If you are using Serverless v4 you must disable the default builtin ESBuild support in your `serverless.yml` (because it conflicts with `serverless-webpack`):
55+
56+
```yml
57+
build:
58+
esbuild: false
59+
```
60+
5261
## Configure
5362

5463
The configuration of the plugin is done by defining a `custom: webpack` object in your `serverless.yml` with your specific configuration. All settings are optional and will be set to reasonable defaults if missing.
@@ -184,8 +193,8 @@ module.exports = {
184193

185194
`serverless-webpack` generates Webpack entries from the `handler` value by default.
186195

187-
If your handler is different from the webpack entry, e.g. provided by a layer,
188-
you may override the generated entry at function level via the `entrypoint`
196+
If your handler is different from the webpack entry, e.g. provided by a layer,
197+
you may override the generated entry at function level via the `entrypoint`
189198
option in `serverless.yml`.
190199

191200
```yaml

examples/include-external-npm-packages-lock-file/_setup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
// That file is only used by the e2e tests
4+
35
const path = require('path');
46

57
module.exports = async (originalFixturePath, fixturePath, utils) => {

examples/include-external-npm-packages-with-yarn-workspaces/_setup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
// That file is only used by the e2e tests
4+
35
const path = require('path');
46

57
module.exports = async (originalFixturePath, fixturePath, utils) => {

examples/include-external-npm-packages/_setup.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
// That file is only used by the e2e tests
4+
35
const path = require('path');
46

57
module.exports = async (originalFixturePath, fixturePath, utils) => {
@@ -18,5 +20,6 @@ module.exports = async (originalFixturePath, fixturePath, utils) => {
1820
]);
1921

2022
const command = /^win/.test(process.platform) ? 'yarn.cmd' : 'yarn';
23+
2124
return utils.spawnProcess(command, ['install'], { cwd: __dirname });
2225
};

examples/serverless-v4/.babelrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"node": "20"
8+
}
9+
}
10+
]
11+
]
12+
}

examples/serverless-v4/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.webpack
3+
.webpackCache

examples/serverless-v4/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
You can try to invoke the function locally (be sure to `yarn install` before):
2+
3+
```
4+
yarn serverless invoke local --function=hello --path=./event.json
5+
```

examples/serverless-v4/_setup.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
// That file is only used by the e2e tests
4+
5+
const path = require('path');
6+
7+
module.exports = async (originalFixturePath, fixturePath, utils) => {
8+
const pluginPath = path.resolve(originalFixturePath, '..', '..');
9+
10+
const SLS_CONFIG_PATH = path.join(fixturePath, 'serverless.yml');
11+
const WEBPACK_CONFIG_PATH = path.join(fixturePath, 'webpack.config.js');
12+
const PACKAGE_JSON_PATH = path.join(fixturePath, 'package.json');
13+
const LOCK_PATH = path.join(fixturePath, 'yarn.lock');
14+
15+
await Promise.all([
16+
utils.replaceInFile(SLS_CONFIG_PATH, '- serverless-webpack', `- ${pluginPath}`),
17+
utils.replaceInFile(WEBPACK_CONFIG_PATH, "'serverless-webpack'", `'${pluginPath}'`),
18+
utils.replaceInFile(PACKAGE_JSON_PATH, 'file:../..', `file:${pluginPath}`),
19+
utils.replaceInFile(LOCK_PATH, 'file:../..', `file:${pluginPath}`)
20+
]);
21+
22+
const command = /^win/.test(process.platform) ? 'yarn.cmd' : 'yarn';
23+
24+
return utils.spawnProcess(command, ['install'], { cwd: __dirname });
25+
};

0 commit comments

Comments
 (0)