diff --git a/src/index.ts b/src/index.ts index e9b47706..ad41acde 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,11 @@ import * as fs from 'fs-extra' import * as _ from 'lodash' import * as globby from 'globby' -import { ServerlessOptions, ServerlessInstance, ServerlessFunction } from './types' +import { + ServerlessOptions, + ServerlessInstance, + ServerlessFunction +} from './types' import * as typescript from './typescript' import { watchFiles } from './watchFiles' @@ -14,7 +18,6 @@ const serverlessFolder = '.serverless' const buildFolder = '.build' export class TypeScriptPlugin { - private originalServicePath: string private isWatching: boolean @@ -47,7 +50,9 @@ export class TypeScriptPlugin { const emitedFiles = await this.compileTs() if (this.isWatching) { emitedFiles.forEach(filename => { - const module = require.resolve(path.resolve(this.originalServicePath, filename)) + const module = require.resolve( + path.resolve(this.originalServicePath, filename) + ) delete require.cache[module] }) } @@ -63,12 +68,20 @@ export class TypeScriptPlugin { get functions() { return this.options.function - ? { [this.options.function] : this.serverless.service.functions[this.options.function] } + ? { + [this.options.function]: this.serverless.service.functions[ + this.options.function + ] + } : this.serverless.service.functions } get rootFileNames() { - return typescript.extractFileNames(this.originalServicePath, this.serverless.service.provider.name, this.functions) + return typescript.extractFileNames( + this.originalServicePath, + this.serverless.service.provider.name, + this.functions + ) } prepare() { @@ -78,10 +91,13 @@ export class TypeScriptPlugin { const fn = functions[fnName] fn.package = fn.package || { exclude: [], - include: [], + include: [] } // Add plugin to excluded packages or an empty array if exclude is undefined - fn.package.exclude = _.uniq([...fn.package.exclude || [], 'node_modules/serverless-plugin-typescript']) + fn.package.exclude = _.uniq([ + ...(fn.package.exclude || []), + 'node_modules/serverless-plugin-typescript' + ]) } } @@ -119,7 +135,10 @@ export class TypeScriptPlugin { // Save original service path and functions this.originalServicePath = this.serverless.config.servicePath // Fake service path so that serverless will know what to zip - this.serverless.config.servicePath = path.join(this.originalServicePath, buildFolder) + this.serverless.config.servicePath = path.join( + this.originalServicePath, + buildFolder + ) } const tsconfig = typescript.getTypescriptConfig( @@ -142,7 +161,11 @@ export class TypeScriptPlugin { // Link or copy node_modules and package.json to .build so Serverless can // exlcude devDeps during packaging if (!fs.existsSync(outModulesPath)) { - await this.linkOrCopy(path.resolve('node_modules'), outModulesPath, 'junction') + await this.linkOrCopy( + path.resolve('node_modules'), + outModulesPath, + 'junction' + ) } if (!fs.existsSync(outPkgPath)) { @@ -150,7 +173,10 @@ export class TypeScriptPlugin { } // include any "extras" from the "include" section - if (this.serverless.service.package.include && this.serverless.service.package.include.length > 0) { + if ( + this.serverless.service.package.include && + this.serverless.service.package.include.length > 0 + ) { const files = await globby(this.serverless.service.package.include) for (const filename of files) { @@ -162,7 +188,10 @@ export class TypeScriptPlugin { } if (!fs.existsSync(destFileName)) { - fs.copySync(path.resolve(filename), path.resolve(path.join(buildFolder, filename))) + fs.copySync( + path.resolve(filename), + path.resolve(path.join(buildFolder, filename)) + ) } } } @@ -177,7 +206,7 @@ export class TypeScriptPlugin { if (this.options.function) { const fn = this.serverless.service.functions[this.options.function] const basename = path.basename(fn.package.artifact) - fn.package.artifact = path.join( + fn.package.artifact = path.join( this.originalServicePath, serverlessFolder, path.basename(fn.package.artifact) @@ -191,7 +220,9 @@ export class TypeScriptPlugin { this.serverless.service.functions[name].package.artifact = path.join( this.originalServicePath, serverlessFolder, - path.basename(this.serverless.service.functions[name].package.artifact) + path.basename( + this.serverless.service.functions[name].package.artifact + ) ) }) return @@ -233,13 +264,12 @@ export class TypeScriptPlugin { dstPath: string, type?: 'dir' | 'junction' | 'file' ): Promise { - return fs.symlink(srcPath, dstPath, type) - .catch(error => { - if (error.code === 'EPERM' && error.errno === -4048) { - return fs.copy(srcPath, dstPath) - } - throw error - }) + return fs.symlink(srcPath, dstPath, type).catch(error => { + if (error.code === 'EPERM' && error.errno === -4048) { + return fs.copy(srcPath, dstPath) + } + throw error + }) } }