-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(webpack): compile JS with webpack - EUBFR-7 (#4)
* chore(webpack): compile JS with webpack - EUBFR-7 * Dynamic path * Add tests * Add integration test * Use yarn workspaces * Try to fix yarn version * Try to fix yarn version (pt 2) * Force pull * Custom node image * Update doc * Update dependencies * Even more complex example * Remove dead code
- Loading branch information
1 parent
ec633bb
commit f10bf01
Showing
21 changed files
with
2,829 additions
and
384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
--- | ||
root: true | ||
extends: | ||
- 'airbnb-base' | ||
- 'prettier' | ||
- airbnb-base | ||
- prettier | ||
- plugin:jest/recommended | ||
plugins: | ||
- 'prettier' | ||
- jest | ||
- prettier | ||
rules: | ||
'prettier/prettier': | ||
- 'error' | ||
prettier/prettier: | ||
- error | ||
- | ||
'trailingComma': 'es5' | ||
'singleQuote': true | ||
trailingComma: es5 | ||
singleQuote: true | ||
env: | ||
node: true | ||
jest/globals: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.serverless | ||
.webpack | ||
node_modules | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
singleQuote: true | ||
trailingComma: es5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
FROM buildpack-deps:jessie | ||
|
||
RUN groupadd --gid 1000 node \ | ||
&& useradd --uid 1000 --gid node --shell /bin/bash --create-home node | ||
|
||
# gpg keys listed at https://github.com/nodejs/node#release-team | ||
RUN set -ex \ | ||
&& for key in \ | ||
9554F04D7259F04124DE6B476D5A82AC7E37093B \ | ||
94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \ | ||
FD3A5288F042B6850C66B31F09FE44734EB7990E \ | ||
71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \ | ||
DD8F2338BAE7501E3DD5AC78C273792F7D83545D \ | ||
B9AE9905FFD7803F25714661B63B535A4C206CA9 \ | ||
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \ | ||
56730D5401028683275BD23C23EFEFE93C4CFFFE \ | ||
; do \ | ||
gpg --keyserver pgp.mit.edu --recv-keys "$key" || \ | ||
gpg --keyserver keyserver.pgp.com --recv-keys "$key" || \ | ||
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key" ; \ | ||
done | ||
|
||
ENV NPM_CONFIG_LOGLEVEL info | ||
ENV NODE_VERSION 8.4.0 | ||
|
||
RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \ | ||
&& case "${dpkgArch##*-}" in \ | ||
amd64) ARCH='x64';; \ | ||
ppc64el) ARCH='ppc64le';; \ | ||
s390x) ARCH='s390x';; \ | ||
arm64) ARCH='arm64';; \ | ||
armhf) ARCH='armv7l';; \ | ||
*) echo "unsupported architecture"; exit 1 ;; \ | ||
esac \ | ||
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \ | ||
&& curl -SLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \ | ||
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \ | ||
&& grep " node-v$NODE_VERSION-linux-$ARCH.tar.xz\$" SHASUMS256.txt | sha256sum -c - \ | ||
&& tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 \ | ||
&& rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \ | ||
&& ln -s /usr/local/bin/node /usr/local/bin/nodejs | ||
|
||
ENV YARN_VERSION 1.0.1 | ||
|
||
RUN set -ex \ | ||
&& for key in \ | ||
6A010C5166006599AA17F08146C2130DFD2497F5 \ | ||
; do \ | ||
gpg --keyserver pgp.mit.edu --recv-keys "$key" || \ | ||
gpg --keyserver keyserver.pgp.com --recv-keys "$key" || \ | ||
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key" ; \ | ||
done \ | ||
&& curl -fSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \ | ||
&& curl -fSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \ | ||
&& gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \ | ||
&& mkdir -p /opt/yarn \ | ||
&& tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/yarn --strip-components=1 \ | ||
&& ln -s /opt/yarn/bin/yarn /usr/local/bin/yarn \ | ||
&& ln -s /opt/yarn/bin/yarn /usr/local/bin/yarnpkg \ | ||
&& rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz | ||
|
||
CMD [ "node" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"plugins": ["transform-runtime"], | ||
"presets": ["es2015", "stage-3"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"private": true, | ||
"name": "example01", | ||
"version": "0.0.1", | ||
"scripts": { | ||
"test:integration": | ||
"serverless offline start --exec \"jest --testPathPattern=integration\"", | ||
"test:unit": "jest --testPathPattern=unit", | ||
"offline": "serverless offline start" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "6.26.0", | ||
"babel-loader": "7.1.2", | ||
"babel-plugin-transform-runtime": "6.23.0", | ||
"babel-preset-es2015": "6.24.1", | ||
"babel-preset-stage-3": "6.24.1", | ||
"jest": "21.0.2", | ||
"serverless": "1.21.1", | ||
"serverless-offline": "3.15.3", | ||
"serverless-webpack": "3.0.0", | ||
"webpack": "3.5.6", | ||
"webpack-node-externals": "1.6.0" | ||
}, | ||
"dependencies": { | ||
"babel-runtime": "6.26.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
service: example01 | ||
|
||
plugins: | ||
- serverless-webpack | ||
- serverless-offline | ||
|
||
custom: | ||
serverless-offline: | ||
port: 4000 | ||
# Enable auto-packing of external modules | ||
webpackIncludeModules: true | ||
|
||
provider: | ||
name: aws | ||
runtime: nodejs6.10 | ||
|
||
functions: | ||
hello-custom: | ||
handler: src/handler.hello | ||
events: # All events associated with this function | ||
- http: | ||
path: hello/{name} | ||
method: get | ||
request: | ||
parameters: | ||
paths: | ||
name: true | ||
hello-world: | ||
handler: src/handler.hello | ||
events: # All events associated with this function | ||
- http: | ||
path: hello | ||
method: get |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default stringToFormat => `-- ${stringToFormat} --`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* eslint-disable import/prefer-default-export, no-console */ | ||
import getMessage from './message'; | ||
|
||
export const hello = (event, context, callback) => { | ||
// Contains incoming request data (e.g., query params, headers and more) | ||
// console.log(event); | ||
|
||
const { name } = event.pathParameters || { name: 'World' }; | ||
|
||
const response = { | ||
statusCode: 200, | ||
headers: { | ||
'x-custom-header': 'My Header Value', | ||
}, | ||
body: JSON.stringify({ message: getMessage(name) }), | ||
}; | ||
|
||
callback(null, response); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import format from './formatter'; | ||
|
||
export default name => format(`Hello ${name}!`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const http = require('http'); | ||
|
||
function request(url) { | ||
return new Promise(resolve => { | ||
http.get(url, response => { | ||
let data = ''; | ||
response.on('data', _data => { | ||
data += _data; | ||
}); | ||
response.on('end', () => resolve(data)); | ||
}); | ||
}); | ||
} | ||
|
||
it('works with promises', () => { | ||
expect.assertions(1); | ||
|
||
const name = 'test'; | ||
|
||
return request(`http://localhost:4000/hello/${name}`).then(data => | ||
expect(JSON.parse(data)).toEqual({ message: `-- Hello ${name}! --` }) | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import getMessage from '../../src/message'; | ||
|
||
test(`getMessage('World') to return 'Hello World!'`, () => { | ||
expect(getMessage('World')).toBe('-- Hello World! --'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
const slsw = require('serverless-webpack'); | ||
const nodeExternals = require('webpack-node-externals'); | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
entry: slsw.lib.entries, | ||
target: 'node', | ||
externals: [nodeExternals()], | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.js$/, | ||
loaders: ['babel-loader'], | ||
include: __dirname, | ||
exclude: /node_modules/, | ||
}, | ||
], | ||
}, | ||
output: { | ||
libraryTarget: 'commonjs', | ||
path: path.join(__dirname, '.webpack'), | ||
filename: '[name].js', | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.