Skip to content

Commit 852b598

Browse files
Use babel-register. Closes #179. Closes #178
1 parent b04028b commit 852b598

File tree

10 files changed

+64
-41
lines changed

10 files changed

+64
-41
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/*
2+
lib/*

.eslintrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"env": {
3+
"node": true
4+
},
5+
"extends": [
6+
"standard",
7+
"plugin:import/errors",
8+
"plugin:import/warnings"
9+
]
10+
}

package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"compile": "babel -d lib/ src/",
88
"test": "ava",
9-
"lint": "standard",
9+
"lint": "eslint ./",
1010
"prepublish": "npm run compile",
1111
"pub": "np"
1212
},
@@ -38,6 +38,7 @@
3838
"dependencies": {
3939
"archiver": "^1.0.0",
4040
"aws-sdk": "^2.4.13",
41+
"babel-register": "^6.22.0",
4142
"bluebird": "^3.4.7",
4243
"chalk": "^1.1.3",
4344
"cliui": "^3.2.0",
@@ -62,8 +63,12 @@
6263
"babel-plugin-transform-object-rest-spread": "^6.20.2",
6364
"babel-preset-env": "^1.1.8",
6465
"babel-register": "^6.18.0",
66+
"eslint": "^3.14.1",
67+
"eslint-config-standard": "^6.2.1",
68+
"eslint-plugin-import": "^2.2.0",
69+
"eslint-plugin-promise": "^3.4.0",
70+
"eslint-plugin-standard": "^2.0.1",
6571
"np": "^2.12.0",
66-
"standard": "^8.6.0",
6772
"testdouble": "^1.10.1"
6873
},
6974
"babel": {

src/generate-endpoint/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as load from '../util/load'
77

88
const integration = 'x-amazon-apigateway-integration'
99

10-
module.exports = function (opts) {
10+
export default function (opts) {
1111
let accountId = opts.accountId
1212
let path = opts.path
1313
let method = opts.method

src/run/index.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { requireProject } from '../util/require-project'
1+
import requireProject from '../util/require-project'
22
import * as load from '../util/load'
33
import build from '../util/build-functions'
44
import Promise from 'bluebird'
55
import chalk from 'chalk'
66
import AWS from 'aws-sdk'
77
import mergeWith from 'lodash.mergewith'
8-
import requireUnbuilt from '../util/require-unbuilt'
98

109
import cliui from 'cliui'
1110
const ui = cliui({ width: 80 })
@@ -54,12 +53,11 @@ function runFunction (opts) {
5453

5554
const context = {}
5655

57-
if (performBuild) {
58-
await build(name, env)
59-
}
56+
performBuild ? await build(name, env) : require('babel-register')
6057

6158
const funcPath = `${performBuild ? 'dist' : 'functions'}/${name}/${fileName}.js`
62-
const func = (performBuild ? requireProject(funcPath) : await requireUnbuilt(funcPath))[handler]
59+
60+
const func = requireProject(funcPath)[handler]
6361

6462
if (typeof func !== 'function') {
6563
return Promise.reject(new Error(`Handler function provided is not a function. Please verify that there exists a handler function exported as ${handler} in dist/${name}/${fileName}.js`))

src/util/require-project.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import path from 'path'
22

3-
export function requireProject (relativePath) {
3+
export default function (relativePath) {
44
return require(projectPath(relativePath))
55
}
66

7-
export function projectPath (relativePath) {
7+
function projectPath (relativePath) {
88
return path.join(process.cwd(), relativePath)
99
}

src/util/require-unbuilt.js

-18
This file was deleted.

test/run/index-all.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ td.when(load.funcs('*')).thenReturn(funcNames)
1313
td.when(load.lambdaConfig(), { ignoreExtraArgs: true }).thenReturn(config)
1414
td.when(load.events(), { ignoreExtraArgs: true }).thenReturn(events)
1515

16-
const projectUtils = td.replace('../../src/util/require-project')
17-
td.when(projectUtils.requireProject(td.matchers.contains('events'))).thenReturn({})
18-
19-
const requireUnbuilt = td.replace('../../src/util/require-unbuilt')
20-
td.when(requireUnbuilt(td.matchers.anything())).thenResolve(lambdaFunc)
16+
const requireProject = td.replace('../../src/util/require-project')
17+
td.when(requireProject(td.matchers.contains('events'))).thenReturn({})
18+
td.when(requireProject(td.matchers.contains(`functions`))).thenReturn(lambdaFunc)
2119

2220
test.before(() => {
2321
return require('../../src/run/index')({ pattern: '*', build: false })
@@ -26,4 +24,3 @@ test.before(() => {
2624
test('Calls the functions', () => {
2725
td.verify(lambdaFunc[handler](), { times: funcNames.length, ignoreExtraArgs: true })
2826
})
29-

test/run/index-build.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import test from 'ava'
2+
import td from '../helpers/testdouble'
3+
4+
const funcName = 'foo'
5+
const handler = 'handler'
6+
const config = { Handler: `index.${handler}` }
7+
const events = [{}]
8+
const lambdaFunc = td.object([handler])
9+
td.when(lambdaFunc[handler](td.matchers.anything(), td.matchers.isA(Object))).thenCallback(null, 'bar')
10+
11+
const load = td.replace('../../src/util/load')
12+
td.when(load.funcs(funcName)).thenReturn([funcName])
13+
td.when(load.lambdaConfig(funcName)).thenReturn(config)
14+
td.when(load.events(funcName, td.matchers.anything())).thenReturn(events)
15+
16+
const build = td.replace('../../src/util/build-functions')
17+
td.when(build(funcName, td.matchers.anything())).thenResolve({})
18+
19+
const requireProject = td.replace('../../src/util/require-project')
20+
td.when(requireProject(td.matchers.contains(`dist/${funcName}`))).thenReturn(lambdaFunc)
21+
22+
test.before(async () => {
23+
return await require('../../src/run/index')({ pattern: funcName, build: true })
24+
})
25+
26+
test('Calls the function', () => {
27+
td.verify(lambdaFunc[handler](), { ignoreExtraArgs: true })
28+
})
29+
30+
test('Loads event', () => {
31+
td.verify(requireProject(td.matchers.contains('events')))
32+
})

test/run/index.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ td.when(load.funcs(funcName)).thenReturn([funcName])
1313
td.when(load.lambdaConfig(funcName)).thenReturn(config)
1414
td.when(load.events(funcName, td.matchers.anything())).thenReturn(events)
1515

16-
const projectUtils = td.replace('../../src/util/require-project')
17-
18-
const requireUnbuilt = td.replace('../../src/util/require-unbuilt')
19-
td.when(requireUnbuilt(td.matchers.contains(funcName))).thenResolve(lambdaFunc)
16+
const requireProject = td.replace('../../src/util/require-project')
17+
td.when(requireProject(td.matchers.contains(`functions/${funcName}`))).thenReturn(lambdaFunc)
2018

2119
test.before(async () => {
2220
return await require('../../src/run/index')({ pattern: funcName, build: false })
@@ -27,6 +25,5 @@ test('Calls the function', () => {
2725
})
2826

2927
test('Loads event', () => {
30-
td.verify(projectUtils.requireProject(td.matchers.contains('events')))
28+
td.verify(requireProject(td.matchers.contains('events')))
3129
})
32-

0 commit comments

Comments
 (0)