Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
],
"scripts": {
"prepublish": "npm run build",
"precommit": "npm run test",
"build": "rm -rf dist && tsc",
"test": "npm run lint",
"pretest": "npm run lint",
"test": "jest",
"lint": "tslint -c tslint.json 'src/**/*.ts'"
},
"repository": {
Expand All @@ -25,13 +27,28 @@
],
"devDependencies": {
"@types/fs-extra": "2.0.0",
"@types/jest": "^19.2.4",
"@types/lodash": "^4.14.62",
"jest": "^20.0.4",
"mock-fs": "^4.3.0",
"ts-jest": "^20.0.6",
"tslint": "^5.1.0"
},
"dependencies": {
"fs-p": "2.0.0",
"globby": "^6.1.0",
"lodash": "^4.17.4",
"typescript": "^2.2.2"
},
"jest": {
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
]
}
}
26 changes: 15 additions & 11 deletions src/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ import * as _ from 'lodash'
import { ServerlessFunction } from './types'
import * as path from 'path'

export function makeDefaultTypescriptConfig() {
const defaultTypescriptConfig: ts.CompilerOptions = {
preserveConstEnums: true,
strictNullChecks: true,
sourceMap: true,
target: ts.ScriptTarget.ES5,
moduleResolution: ts.ModuleResolutionKind.NodeJs,
lib: ['lib.es2015.d.ts'],
rootDir: './',
}

return defaultTypescriptConfig
}

export function extractFileNames(functions: { [key: string]: ServerlessFunction }): string[] {
return _.values(functions)
.map(fn => fn.handler)
Expand Down Expand Up @@ -59,15 +73,5 @@ export function getTypescriptConfig(cwd: string): ts.CompilerOptions {
return configParseResult.options
}

const defaultTypescriptConfig: ts.CompilerOptions = {
preserveConstEnums: true,
strictNullChecks: true,
sourceMap: true,
target: ts.ScriptTarget.ES5,
moduleResolution: ts.ModuleResolutionKind.NodeJs,
lib: ['lib.es2015.d.ts'],
rootDir: './',
}

return defaultTypescriptConfig
return makeDefaultTypescriptConfig()
}
41 changes: 41 additions & 0 deletions tests/typescript.extractFileName.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {extractFileNames} from '../src/typescript'
import {ServerlessFunction} from '../src/types'

const functions: { [key: string]: ServerlessFunction } = {
hello: {
handler: 'my-folder/hello.handler',
package: {
include: [],
exclude: []
}
},
world: {
handler: 'my-folder/my-subfolder/world.handler',
package: {
include: [],
exclude: []
}
},
create: {
handler: 'create.create',
package: {
include: [],
exclude: []
}
},
}

describe('extractFileName', () => {
it('get function filenames from serverless service', () => {
expect(
extractFileNames(functions),
).toEqual(
[
'my-folder/hello.ts',
'my-folder/my-subfolder/world.ts',
'create.ts',
],
)
})
})

11 changes: 11 additions & 0 deletions tests/typescript.getTypescriptConfig.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {getTypescriptConfig, makeDefaultTypescriptConfig} from '../src/typescript'

describe('getTypescriptConfig', () => {
it(`returns default typescript configuration if the one provided doesn't exist`, () => {
expect(
getTypescriptConfig('/ciaone/my-folder'),
).toEqual(
makeDefaultTypescriptConfig()
)
})
})
Loading