Skip to content

Commit e0f97a0

Browse files
committed
use yarn to create deployment artifact
1 parent a87a3bd commit e0f97a0

File tree

5 files changed

+39
-22
lines changed

5 files changed

+39
-22
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ build/Release
3737

3838
# Dependency directories
3939
node_modules/
40+
prod_node_modules/
4041
jspm_packages/
4142

4243
# TypeScript v1 declaration files

packages/sls-random/serverless.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ plugins:
44
- serverless-plugin-scripts
55

66
package:
7-
exclude:
8-
- ./**
9-
- '!dist/**'
10-
- '!node_modules/**'
7+
artifact: dist/artifact.zip
118

129
provider:
1310
name: aws
@@ -31,11 +28,11 @@ provider:
3128
custom:
3229
scripts:
3330
hooks:
34-
'before:deploy:createDeploymentArtifacts': yarn run build
31+
'before:deploy:createDeploymentArtifacts': yarn run build && ../../scripts/sls-package.sh
3532

3633
functions:
3734

3835
fetchRandomNumber:
39-
handler: dist/index.fetchRandomNumber
36+
handler: index.fetchRandomNumber
4037
events:
4138
- http: GET number

scripts/sls-package.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#! /bin/sh
2+
3+
# this is assumed to run from a sls-package, e.g. at packages/sls-random
4+
# see https://github.com/yarnpkg/yarn/issues/6293#issuecomment-414779476
5+
cwd=$PWD
6+
7+
# install production deps for the entire workspace
8+
cd ../..
9+
yarn install --production
10+
cd $cwd
11+
12+
# dupe node_modules
13+
mkdir -p dist
14+
rm -fr dist/node_modules
15+
cp -RL node_modules dist/node_modules
16+
17+
# cleanup .bin
18+
rm -rf dist/node_modules/.bin
19+
20+
# back to development
21+
cd ../../
22+
yarn install
23+
cd $cwd
24+
25+
# prepare artifact
26+
cd dist
27+
zip -r artifact.zip *
28+
cd ..

tsconfig.settings.json

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,16 @@
22
"compilerOptions": {
33
"module": "commonjs",
44
"target": "es6",
5-
"lib": [
6-
"es6"
7-
],
5+
"lib": ["es6"],
86
"moduleResolution": "node",
97

108
"rootDir": "./",
119
"baseUrl": "packages/",
1210
"paths": {
1311
"@org/*": ["./*/src"]
1412
},
15-
"typeRoots": [
16-
"./node_modules/@types",
17-
"./packages/types"
18-
],
19-
13+
"typeRoots": ["./node_modules/@types", "./packages/types"],
14+
2015
"composite": true,
2116
"declaration": true,
2217
"declarationMap": true,
@@ -34,9 +29,5 @@
3429
"resolveJsonModule": true,
3530
"esModuleInterop": true
3631
},
37-
"exclude": [
38-
"**/dist",
39-
"**/node_modules",
40-
"**/test"
41-
]
42-
}
32+
"exclude": ["**/dist", "**/node_modules", "**/prod_node_modules", "**/test"]
33+
}

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,8 +795,8 @@ aws-lambda@^0.1.2:
795795
dotenv "^0.4.0"
796796

797797
aws-sdk@^*, aws-sdk@^2.228.0:
798-
version "2.297.0"
799-
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.297.0.tgz#2fe085076f6fd488285ef7cfaf883fdaa47acee9"
798+
version "2.298.0"
799+
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.298.0.tgz#53259d06ca3bcde69d11f3b24b1c05088939c67f"
800800
dependencies:
801801
buffer "4.9.1"
802802
events "1.1.1"

0 commit comments

Comments
 (0)