diff --git a/README.md b/README.md index c5fdf925..dbcea723 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,9 @@ Serverless plugin for zero-config Typescript support ## Install ```sh -yarn add --dev serverless-plugin-typescript +yarn add --dev serverless-plugin-typescript typescript +# or +npm install -D serverless-plugin-typescript typescript ``` Add the following plugin to your `serverless.yml`: @@ -38,6 +40,7 @@ The default `tsconfig.json` file used by the plugin looks like this: "preserveConstEnums": true, "strictNullChecks": true, "sourceMap": true, + "allowJs": true, "target": "es5", "outDir": ".build", "moduleResolution": "node", diff --git a/example/package.json b/example/package.json index 8c0c8e77..d4945b34 100644 --- a/example/package.json +++ b/example/package.json @@ -6,6 +6,6 @@ "devDependencies": { "@types/lodash": "4.14.91", "@types/node": "^11.13.0", - "serverless-plugin-typescript": "1.1.5" + "serverless-plugin-typescript": "1.1.7" } } diff --git a/example/yarn.lock b/example/yarn.lock index 4b8e261a..6ea4949e 100644 --- a/example/yarn.lock +++ b/example/yarn.lock @@ -2,11 +2,54 @@ # yarn lockfile v1 +"@mrmlnc/readdir-enhanced@^2.2.1": + version "2.2.1" + resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde" + dependencies: + call-me-maybe "^1.0.1" + glob-to-regexp "^0.3.0" + +"@nodelib/fs.stat@^1.1.2": + version "1.1.3" + resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b" + +"@types/events@*": + version "3.0.0" + resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7" + +"@types/glob@^7.1.1": + version "7.1.1" + resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575" + dependencies: + "@types/events" "*" + "@types/minimatch" "*" + "@types/node" "*" + "@types/lodash@4.14.91": version "4.14.91" resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.91.tgz#794611b28056d16b5436059c6d800b39d573cd3a" -array-union@^1.0.1: +"@types/minimatch@*": + version "3.0.3" + resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" + +"@types/node@*", "@types/node@^11.13.0": + version "11.13.0" + resolved "https://registry.yarnpkg.com/@types/node/-/node-11.13.0.tgz#b0df8d6ef9b5001b2be3a94d909ce3c29a80f9e1" + +arr-diff@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-4.0.0.tgz#d6461074febfec71e7e15235761a329a5dc7c520" + +arr-flatten@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/arr-flatten/-/arr-flatten-1.1.0.tgz#36048bbff4e7b47e136644316c99669ea5ae91f1" + +arr-union@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/arr-union/-/arr-union-3.1.0.tgz#e39b09aea9def866a8f206e288af63919bae39c4" + +array-union@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/array-union/-/array-union-1.0.2.tgz#9a34410e4f4e3da23dea375be5be70f24778ec39" dependencies: @@ -16,14 +59,34 @@ array-uniq@^1.0.1: version "1.0.3" resolved "https://registry.yarnpkg.com/array-uniq/-/array-uniq-1.0.3.tgz#af6ac877a25cc7f74e058894753858dfdb24fdb6" -arrify@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d" +array-unique@^0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428" + +assign-symbols@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/assign-symbols/-/assign-symbols-1.0.0.tgz#59667f41fadd4f20ccbc2bb96b8d4f7f78ec0367" + +atob@^2.1.1: + version "2.1.2" + resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9" balanced-match@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" +base@^0.11.1: + version "0.11.2" + resolved "https://registry.yarnpkg.com/base/-/base-0.11.2.tgz#7bde5ced145b6d551a90db87f83c558b4eb48a8f" + dependencies: + cache-base "^1.0.1" + class-utils "^0.3.5" + component-emitter "^1.2.1" + define-property "^1.0.0" + isobject "^3.0.1" + mixin-deep "^1.2.0" + pascalcase "^0.1.1" + brace-expansion@^1.1.7: version "1.1.8" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.8.tgz#c07b211c7c952ec1f8efd51a77ef0d1d3990a292" @@ -31,20 +94,173 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" +braces@^2.3.1: + version "2.3.2" + resolved "https://registry.yarnpkg.com/braces/-/braces-2.3.2.tgz#5979fd3f14cd531565e5fa2df1abfff1dfaee729" + dependencies: + arr-flatten "^1.1.0" + array-unique "^0.3.2" + extend-shallow "^2.0.1" + fill-range "^4.0.0" + isobject "^3.0.1" + repeat-element "^1.1.2" + snapdragon "^0.8.1" + snapdragon-node "^2.0.1" + split-string "^3.0.2" + to-regex "^3.0.1" + +cache-base@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/cache-base/-/cache-base-1.0.1.tgz#0a7f46416831c8b662ee36fe4e7c59d76f666ab2" + dependencies: + collection-visit "^1.0.0" + component-emitter "^1.2.1" + get-value "^2.0.6" + has-value "^1.0.0" + isobject "^3.0.1" + set-value "^2.0.0" + to-object-path "^0.3.0" + union-value "^1.0.0" + unset-value "^1.0.0" + +call-me-maybe@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/call-me-maybe/-/call-me-maybe-1.0.1.tgz#26d208ea89e37b5cbde60250a15f031c16a4d66b" + +class-utils@^0.3.5: + version "0.3.6" + resolved "https://registry.yarnpkg.com/class-utils/-/class-utils-0.3.6.tgz#f93369ae8b9a7ce02fd41faad0ca83033190c463" + dependencies: + arr-union "^3.1.0" + define-property "^0.2.5" + isobject "^3.0.0" + static-extend "^0.1.1" + +collection-visit@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/collection-visit/-/collection-visit-1.0.0.tgz#4bc0373c164bc3291b4d368c829cf1a80a59dca0" + dependencies: + map-visit "^1.0.0" + object-visit "^1.0.0" + +component-emitter@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6" + concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" -dir-glob@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-2.0.0.tgz#0b205d2b6aef98238ca286598a8204d29d0a0034" +copy-descriptor@^0.1.0: + version "0.1.1" + resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d" + +debug@^2.2.0, debug@^2.3.3: + version "2.6.9" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" + dependencies: + ms "2.0.0" + +decode-uri-component@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545" + +define-property@^0.2.5: + version "0.2.5" + resolved "https://registry.yarnpkg.com/define-property/-/define-property-0.2.5.tgz#c35b1ef918ec3c990f9a5bc57be04aacec5c8116" + dependencies: + is-descriptor "^0.1.0" + +define-property@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/define-property/-/define-property-1.0.0.tgz#769ebaaf3f4a63aad3af9e8d304c9bbe79bfb0e6" + dependencies: + is-descriptor "^1.0.0" + +define-property@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/define-property/-/define-property-2.0.2.tgz#d459689e8d654ba77e02a817f8710d702cb16e9d" + dependencies: + is-descriptor "^1.0.2" + isobject "^3.0.1" + +dir-glob@^2.2.2: + version "2.2.2" + resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-2.2.2.tgz#fa09f0694153c8918b18ba0deafae94769fc50c4" dependencies: - arrify "^1.0.1" path-type "^3.0.0" -fs-extra@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-5.0.0.tgz#414d0110cdd06705734d055652c5411260c31abd" +expand-brackets@^2.1.4: + version "2.1.4" + resolved "https://registry.yarnpkg.com/expand-brackets/-/expand-brackets-2.1.4.tgz#b77735e315ce30f6b6eff0f83b04151a22449622" + dependencies: + debug "^2.3.3" + define-property "^0.2.5" + extend-shallow "^2.0.1" + posix-character-classes "^0.1.0" + regex-not "^1.0.0" + snapdragon "^0.8.1" + to-regex "^3.0.1" + +extend-shallow@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-2.0.1.tgz#51af7d614ad9a9f610ea1bafbb989d6b1c56890f" + dependencies: + is-extendable "^0.1.0" + +extend-shallow@^3.0.0, extend-shallow@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-3.0.2.tgz#26a71aaf073b39fb2127172746131c2704028db8" + dependencies: + assign-symbols "^1.0.0" + is-extendable "^1.0.1" + +extglob@^2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/extglob/-/extglob-2.0.4.tgz#ad00fe4dc612a9232e8718711dc5cb5ab0285543" + dependencies: + array-unique "^0.3.2" + define-property "^1.0.0" + expand-brackets "^2.1.4" + extend-shallow "^2.0.1" + fragment-cache "^0.2.1" + regex-not "^1.0.0" + snapdragon "^0.8.1" + to-regex "^3.0.1" + +fast-glob@^2.2.6: + version "2.2.6" + resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-2.2.6.tgz#a5d5b697ec8deda468d85a74035290a025a95295" + dependencies: + "@mrmlnc/readdir-enhanced" "^2.2.1" + "@nodelib/fs.stat" "^1.1.2" + glob-parent "^3.1.0" + is-glob "^4.0.0" + merge2 "^1.2.3" + micromatch "^3.1.10" + +fill-range@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-4.0.0.tgz#d544811d428f98eb06a63dc402d2403c328c38f7" + dependencies: + extend-shallow "^2.0.1" + is-number "^3.0.0" + repeat-string "^1.6.1" + to-regex-range "^2.1.0" + +for-in@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" + +fragment-cache@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/fragment-cache/-/fragment-cache-0.2.1.tgz#4290fad27f13e89be7f33799c6bc5a0abfff0d19" + dependencies: + map-cache "^0.2.2" + +fs-extra@^7.0.1: + version "7.0.1" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9" dependencies: graceful-fs "^4.1.2" jsonfile "^4.0.0" @@ -54,9 +270,24 @@ fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" -glob@^7.1.2: - version "7.1.2" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15" +get-value@^2.0.3, get-value@^2.0.6: + version "2.0.6" + resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28" + +glob-parent@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-3.1.0.tgz#9e6af6299d8d3bd2bd40430832bd113df906c5ae" + dependencies: + is-glob "^3.1.0" + path-dirname "^1.0.0" + +glob-to-regexp@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab" + +glob@^7.1.3: + version "7.1.3" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.3.tgz#3960832d3f1574108342dafd3a67b332c0969df1" dependencies: fs.realpath "^1.0.0" inflight "^1.0.4" @@ -65,24 +296,53 @@ glob@^7.1.2: once "^1.3.0" path-is-absolute "^1.0.0" -globby@^7.0.0: - version "7.1.1" - resolved "https://registry.yarnpkg.com/globby/-/globby-7.1.1.tgz#fb2ccff9401f8600945dfada97440cca972b8680" +globby@^9.2.0: + version "9.2.0" + resolved "https://registry.yarnpkg.com/globby/-/globby-9.2.0.tgz#fd029a706c703d29bdd170f4b6db3a3f7a7cb63d" dependencies: - array-union "^1.0.1" - dir-glob "^2.0.0" - glob "^7.1.2" - ignore "^3.3.5" - pify "^3.0.0" - slash "^1.0.0" + "@types/glob" "^7.1.1" + array-union "^1.0.2" + dir-glob "^2.2.2" + fast-glob "^2.2.6" + glob "^7.1.3" + ignore "^4.0.3" + pify "^4.0.1" + slash "^2.0.0" graceful-fs@^4.1.2, graceful-fs@^4.1.6: version "4.1.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" -ignore@^3.3.5: - version "3.3.7" - resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.7.tgz#612289bfb3c220e186a58118618d5be8c1bab021" +has-value@^0.3.1: + version "0.3.1" + resolved "https://registry.yarnpkg.com/has-value/-/has-value-0.3.1.tgz#7b1f58bada62ca827ec0a2078025654845995e1f" + dependencies: + get-value "^2.0.3" + has-values "^0.1.4" + isobject "^2.0.0" + +has-value@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/has-value/-/has-value-1.0.0.tgz#18b281da585b1c5c51def24c930ed29a0be6b177" + dependencies: + get-value "^2.0.6" + has-values "^1.0.0" + isobject "^3.0.0" + +has-values@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/has-values/-/has-values-0.1.4.tgz#6d61de95d91dfca9b9a02089ad384bff8f62b771" + +has-values@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/has-values/-/has-values-1.0.0.tgz#95b0b63fec2146619a6fe57fe75628d5a39efe4f" + dependencies: + is-number "^3.0.0" + kind-of "^4.0.0" + +ignore@^4.0.3: + version "4.0.6" + resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc" inflight@^1.0.4: version "1.0.6" @@ -95,28 +355,239 @@ inherits@2: version "2.0.3" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" +is-accessor-descriptor@^0.1.6: + version "0.1.6" + resolved "https://registry.yarnpkg.com/is-accessor-descriptor/-/is-accessor-descriptor-0.1.6.tgz#a9e12cb3ae8d876727eeef3843f8a0897b5c98d6" + dependencies: + kind-of "^3.0.2" + +is-accessor-descriptor@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-accessor-descriptor/-/is-accessor-descriptor-1.0.0.tgz#169c2f6d3df1f992618072365c9b0ea1f6878656" + dependencies: + kind-of "^6.0.0" + +is-buffer@^1.1.5: + version "1.1.6" + resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" + +is-data-descriptor@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz#0b5ee648388e2c860282e793f1856fec3f301b56" + dependencies: + kind-of "^3.0.2" + +is-data-descriptor@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-data-descriptor/-/is-data-descriptor-1.0.0.tgz#d84876321d0e7add03990406abbbbd36ba9268c7" + dependencies: + kind-of "^6.0.0" + +is-descriptor@^0.1.0: + version "0.1.6" + resolved "https://registry.yarnpkg.com/is-descriptor/-/is-descriptor-0.1.6.tgz#366d8240dde487ca51823b1ab9f07a10a78251ca" + dependencies: + is-accessor-descriptor "^0.1.6" + is-data-descriptor "^0.1.4" + kind-of "^5.0.0" + +is-descriptor@^1.0.0, is-descriptor@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/is-descriptor/-/is-descriptor-1.0.2.tgz#3b159746a66604b04f8c81524ba365c5f14d86ec" + dependencies: + is-accessor-descriptor "^1.0.0" + is-data-descriptor "^1.0.0" + kind-of "^6.0.2" + +is-extendable@^0.1.0, is-extendable@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/is-extendable/-/is-extendable-0.1.1.tgz#62b110e289a471418e3ec36a617d472e301dfc89" + +is-extendable@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-extendable/-/is-extendable-1.0.1.tgz#a7470f9e426733d81bd81e1155264e3a3507cab4" + dependencies: + is-plain-object "^2.0.4" + +is-extglob@^2.1.0, is-extglob@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2" + +is-glob@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-3.1.0.tgz#7ba5ae24217804ac70707b96922567486cc3e84a" + dependencies: + is-extglob "^2.1.0" + +is-glob@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.1.tgz#7567dbe9f2f5e2467bc77ab83c4a29482407a5dc" + dependencies: + is-extglob "^2.1.1" + +is-number@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/is-number/-/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195" + dependencies: + kind-of "^3.0.2" + +is-plain-object@^2.0.1, is-plain-object@^2.0.3, is-plain-object@^2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-2.0.4.tgz#2c163b3fafb1b606d9d17928f05c2a1c38e07677" + dependencies: + isobject "^3.0.1" + +is-windows@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" + +isarray@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" + +isobject@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/isobject/-/isobject-2.1.0.tgz#f065561096a3f1da2ef46272f815c840d87e0c89" + dependencies: + isarray "1.0.0" + +isobject@^3.0.0, isobject@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df" + jsonfile@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb" optionalDependencies: graceful-fs "^4.1.6" +kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0: + version "3.2.2" + resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64" + dependencies: + is-buffer "^1.1.5" + +kind-of@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-4.0.0.tgz#20813df3d712928b207378691a45066fae72dd57" + dependencies: + is-buffer "^1.1.5" + +kind-of@^5.0.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-5.1.0.tgz#729c91e2d857b7a419a1f9aa65685c4c33f5845d" + +kind-of@^6.0.0, kind-of@^6.0.2: + version "6.0.2" + resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.2.tgz#01146b36a6218e64e58f3a8d66de5d7fc6f6d051" + +lodash@^4.17.11: + version "4.17.11" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" + lodash@^4.17.4: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" +map-cache@^0.2.2: + version "0.2.2" + resolved "https://registry.yarnpkg.com/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf" + +map-visit@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/map-visit/-/map-visit-1.0.0.tgz#ecdca8f13144e660f1b5bd41f12f3479d98dfb8f" + dependencies: + object-visit "^1.0.0" + +merge2@^1.2.3: + version "1.2.3" + resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.2.3.tgz#7ee99dbd69bb6481689253f018488a1b902b0ed5" + +micromatch@^3.1.10: + version "3.1.10" + resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23" + dependencies: + arr-diff "^4.0.0" + array-unique "^0.3.2" + braces "^2.3.1" + define-property "^2.0.2" + extend-shallow "^3.0.2" + extglob "^2.0.4" + fragment-cache "^0.2.1" + kind-of "^6.0.2" + nanomatch "^1.2.9" + object.pick "^1.3.0" + regex-not "^1.0.0" + snapdragon "^0.8.1" + to-regex "^3.0.2" + minimatch@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" dependencies: brace-expansion "^1.1.7" +mixin-deep@^1.2.0: + version "1.3.1" + resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-1.3.1.tgz#a49e7268dce1a0d9698e45326c5626df3543d0fe" + dependencies: + for-in "^1.0.2" + is-extendable "^1.0.1" + +ms@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + +nanomatch@^1.2.9: + version "1.2.13" + resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119" + dependencies: + arr-diff "^4.0.0" + array-unique "^0.3.2" + define-property "^2.0.2" + extend-shallow "^3.0.2" + fragment-cache "^0.2.1" + is-windows "^1.0.2" + kind-of "^6.0.2" + object.pick "^1.3.0" + regex-not "^1.0.0" + snapdragon "^0.8.1" + to-regex "^3.0.1" + +object-copy@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/object-copy/-/object-copy-0.1.0.tgz#7e7d858b781bd7c991a41ba975ed3812754e998c" + dependencies: + copy-descriptor "^0.1.0" + define-property "^0.2.5" + kind-of "^3.0.3" + +object-visit@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/object-visit/-/object-visit-1.0.1.tgz#f79c4493af0c5377b59fe39d395e41042dd045bb" + dependencies: + isobject "^3.0.0" + +object.pick@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/object.pick/-/object.pick-1.3.0.tgz#87a10ac4c1694bd2e1cbf53591a66141fb5dd747" + dependencies: + isobject "^3.0.1" + once@^1.3.0: version "1.4.0" resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" dependencies: wrappy "1" +pascalcase@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14" + +path-dirname@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/path-dirname/-/path-dirname-1.0.2.tgz#cc33d24d525e099a5388c0336c6e32b9160609e0" + path-is-absolute@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" @@ -131,27 +602,181 @@ pify@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176" -serverless-plugin-typescript@1.1.5: - version "1.1.5" - resolved "https://registry.yarnpkg.com/serverless-plugin-typescript/-/serverless-plugin-typescript-1.1.5.tgz#a62ed1f04ea76875c72700b36b8bf95002a8d6a0" +pify@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/pify/-/pify-4.0.1.tgz#4b2cd25c50d598735c50292224fd8c6df41e3231" + +posix-character-classes@^0.1.0: + version "0.1.1" + resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab" + +regex-not@^1.0.0, regex-not@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/regex-not/-/regex-not-1.0.2.tgz#1f4ece27e00b0b65e0247a6810e6a85d83a5752c" dependencies: - fs-extra "^5.0.0" - globby "^7.0.0" - lodash "^4.17.4" - typescript "^2.2.2" + extend-shallow "^3.0.2" + safe-regex "^1.1.0" -slash@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55" +repeat-element@^1.1.2: + version "1.1.3" + resolved "https://registry.yarnpkg.com/repeat-element/-/repeat-element-1.1.3.tgz#782e0d825c0c5a3bb39731f84efee6b742e6b1ce" + +repeat-string@^1.6.1: + version "1.6.1" + resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-1.6.1.tgz#8dcae470e1c88abc2d600fff4a776286da75e637" + +resolve-url@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a" + +ret@~0.1.10: + version "0.1.15" + resolved "https://registry.yarnpkg.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc" + +safe-regex@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/safe-regex/-/safe-regex-1.1.0.tgz#40a3669f3b077d1e943d44629e157dd48023bf2e" + dependencies: + ret "~0.1.10" + +serverless-plugin-typescript@1.1.7: + version "1.1.7" + resolved "https://registry.yarnpkg.com/serverless-plugin-typescript/-/serverless-plugin-typescript-1.1.7.tgz#a26bee076bf9b091c3be0e0fef17de551bf58079" + dependencies: + fs-extra "^7.0.1" + globby "^9.2.0" + lodash "^4.17.11" + +set-value@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/set-value/-/set-value-0.4.3.tgz#7db08f9d3d22dc7f78e53af3c3bf4666ecdfccf1" + dependencies: + extend-shallow "^2.0.1" + is-extendable "^0.1.1" + is-plain-object "^2.0.1" + to-object-path "^0.3.0" + +set-value@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/set-value/-/set-value-2.0.0.tgz#71ae4a88f0feefbbf52d1ea604f3fb315ebb6274" + dependencies: + extend-shallow "^2.0.1" + is-extendable "^0.1.1" + is-plain-object "^2.0.3" + split-string "^3.0.1" + +slash@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/slash/-/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44" + +snapdragon-node@^2.0.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b" + dependencies: + define-property "^1.0.0" + isobject "^3.0.0" + snapdragon-util "^3.0.1" + +snapdragon-util@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/snapdragon-util/-/snapdragon-util-3.0.1.tgz#f956479486f2acd79700693f6f7b805e45ab56e2" + dependencies: + kind-of "^3.2.0" + +snapdragon@^0.8.1: + version "0.8.2" + resolved "https://registry.yarnpkg.com/snapdragon/-/snapdragon-0.8.2.tgz#64922e7c565b0e14204ba1aa7d6964278d25182d" + dependencies: + base "^0.11.1" + debug "^2.2.0" + define-property "^0.2.5" + extend-shallow "^2.0.1" + map-cache "^0.2.2" + source-map "^0.5.6" + source-map-resolve "^0.5.0" + use "^3.1.0" + +source-map-resolve@^0.5.0: + version "0.5.2" + resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.5.2.tgz#72e2cc34095543e43b2c62b2c4c10d4a9054f259" + dependencies: + atob "^2.1.1" + decode-uri-component "^0.2.0" + resolve-url "^0.2.1" + source-map-url "^0.4.0" + urix "^0.1.0" + +source-map-url@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3" + +source-map@^0.5.6: + version "0.5.7" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" + +split-string@^3.0.1, split-string@^3.0.2: + version "3.1.0" + resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2" + dependencies: + extend-shallow "^3.0.0" + +static-extend@^0.1.1: + version "0.1.2" + resolved "https://registry.yarnpkg.com/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6" + dependencies: + define-property "^0.2.5" + object-copy "^0.1.0" + +to-object-path@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/to-object-path/-/to-object-path-0.3.0.tgz#297588b7b0e7e0ac08e04e672f85c1f4999e17af" + dependencies: + kind-of "^3.0.2" + +to-regex-range@^2.1.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-2.1.1.tgz#7c80c17b9dfebe599e27367e0d4dd5590141db38" + dependencies: + is-number "^3.0.0" + repeat-string "^1.6.1" -typescript@^2.2.2: - version "2.3.0" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.3.0.tgz#2e63e09284392bc8158a2444c33e2093795c0418" +to-regex@^3.0.1, to-regex@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/to-regex/-/to-regex-3.0.2.tgz#13cfdd9b336552f30b51f33a8ae1b42a7a7599ce" + dependencies: + define-property "^2.0.2" + extend-shallow "^3.0.2" + regex-not "^1.0.2" + safe-regex "^1.1.0" + +union-value@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.0.tgz#5c71c34cb5bad5dcebe3ea0cd08207ba5aa1aea4" + dependencies: + arr-union "^3.1.0" + get-value "^2.0.6" + is-extendable "^0.1.1" + set-value "^0.4.3" universalify@^0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7" +unset-value@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559" + dependencies: + has-value "^0.3.1" + isobject "^3.0.0" + +urix@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72" + +use@^3.1.0: + version "3.1.1" + resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f" + wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" diff --git a/package.json b/package.json index c6de7b5e..0599b0ea 100644 --- a/package.json +++ b/package.json @@ -28,12 +28,13 @@ ], "devDependencies": { "@types/fs-extra": "5.0.5", - "@types/jest": "24.0.11", + "@types/jest": "24.0.12", "@types/lodash": "4.14.123", + "@types/node": "12.6.2", "jest": "24.5.0", - "mock-fs": "4.8.0", - "rimraf": "^2.6.3", - "ts-jest": "24.0.1", + "mock-fs": "4.9.0", + "rimraf": "2.6.3", + "ts-jest": "24.0.2", "tslint": "5.14.0", "typescript": "^3.4.1" }, diff --git a/src/Serverless.d.ts b/src/Serverless.d.ts new file mode 100644 index 00000000..ec7d7049 --- /dev/null +++ b/src/Serverless.d.ts @@ -0,0 +1,46 @@ +declare namespace Serverless { + interface Instance { + cli: { + log(str: string): void + } + + config: { + servicePath: string + } + + service: { + provider: { + name: string + } + functions: { + [key: string]: Serverless.Function + } + package: Serverless.Package + getAllFunctions(): string[] + } + + pluginManager: PluginManager + } + + interface Options { + function?: string + watch?: boolean + extraServicePath?: string + } + + interface Function { + handler: string + package: Serverless.Package + } + + interface Package { + include: string[] + exclude: string[] + artifact?: string + individually?: boolean + } + + interface PluginManager { + spawn(command: string): Promise + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 27e1769b..10fcb5e7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,50 +1,64 @@ import * as path from 'path' import * as fs from 'fs-extra' - import * as _ from 'lodash' import * as globby from 'globby' -import { ServerlessOptions, ServerlessInstance, ServerlessFunction } from './types' import * as typescript from './typescript' - import { watchFiles } from './watchFiles' -// Folders -const serverlessFolder = '.serverless' -const buildFolder = '.build' +const SERVERLESS_FOLDER = '.serverless' +const BUILD_FOLDER = '.build' export class TypeScriptPlugin { - private originalServicePath: string private isWatching: boolean - serverless: ServerlessInstance - options: ServerlessOptions - commands: { [key: string]: any } + serverless: Serverless.Instance + options: Serverless.Options hooks: { [key: string]: Function } - constructor(serverless: ServerlessInstance, options: ServerlessOptions) { + constructor(serverless: Serverless.Instance, options: Serverless.Options) { this.serverless = serverless this.options = options this.hooks = { 'before:run:run': async () => { await this.compileTs() + await this.copyExtras() + await this.copyDependencies() }, 'before:offline:start': async () => { await this.compileTs() + await this.copyExtras() + await this.copyDependencies() this.watchAll() }, 'before:offline:start:init': async () => { await this.compileTs() + await this.copyExtras() + await this.copyDependencies() this.watchAll() }, - 'before:package:createDeploymentArtifacts': this.compileTs.bind(this), - 'after:package:createDeploymentArtifacts': this.cleanup.bind(this), - 'before:deploy:function:packageFunction': this.compileTs.bind(this), - 'after:deploy:function:packageFunction': this.cleanup.bind(this), + 'before:package:createDeploymentArtifacts': async () => { + await this.compileTs() + await this.copyExtras() + await this.copyDependencies(true) + }, + 'after:package:createDeploymentArtifacts': async () => { + await this.cleanup() + }, + 'before:deploy:function:packageFunction': async () => { + await this.compileTs() + await this.copyExtras() + await this.copyDependencies(true) + }, + 'after:deploy:function:packageFunction': async () => { + await this.cleanup() + }, 'before:invoke:local:invoke': async () => { const emitedFiles = await this.compileTs() + await this.copyExtras() + await this.copyDependencies() if (this.isWatching) { emitedFiles.forEach(filename => { const module = require.resolve(path.resolve(this.originalServicePath, filename)) @@ -55,31 +69,42 @@ export class TypeScriptPlugin { 'after:invoke:local:invoke': () => { if (this.options.watch) { this.watchFunction() - this.serverless.cli.log('Waiting for changes ...') + this.serverless.cli.log('Waiting for changes...') } } } } get functions() { - return this.options.function - ? { [this.options.function] : this.serverless.service.functions[this.options.function] } - : this.serverless.service.functions + const { options } = this + const { service } = this.serverless + + if (options.function) { + return { + [options.function]: service.functions[this.options.function] + } + } + + return 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() { // exclude serverless-plugin-typescript - const functions = this.functions - for (const fnName in functions) { - const fn = functions[fnName] + for (const fnName in this.functions) { + const fn = this.functions[fnName] fn.package = fn.package || { exclude: [], 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']) } @@ -106,9 +131,7 @@ export class TypeScriptPlugin { this.serverless.cli.log(`Watching typescript files...`) this.isWatching = true - watchFiles(this.rootFileNames, this.originalServicePath, () => { - this.compileTs() - }) + watchFiles(this.rootFileNames, this.originalServicePath, this.compileTs) } async compileTs(): Promise { @@ -119,7 +142,7 @@ 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, BUILD_FOLDER) } const tsconfig = typescript.getTypescriptConfig( @@ -127,34 +150,23 @@ export class TypeScriptPlugin { this.isWatching ? null : this.serverless.cli ) - tsconfig.outDir = buildFolder + tsconfig.outDir = BUILD_FOLDER const emitedFiles = await typescript.run(this.rootFileNames, tsconfig) - await this.copyExtras() this.serverless.cli.log('Typescript compiled.') return emitedFiles } + /** Link or copy extras such as node_modules or package.include definitions */ async copyExtras() { - const outPkgPath = path.resolve(path.join(buildFolder, 'package.json')) - const outModulesPath = path.resolve(path.join(buildFolder, 'node_modules')) - - // 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') - } - - if (!fs.existsSync(outPkgPath)) { - await this.linkOrCopy(path.resolve('package.json'), outPkgPath, 'file') - } + const { service } = this.serverless // include any "extras" from the "include" section - if (this.serverless.service.package.include && this.serverless.service.package.include.length > 0) { - const files = await globby(this.serverless.service.package.include) + if (service.package.include && service.package.include.length > 0) { + const files = await globby(service.package.include) for (const filename of files) { - const destFileName = path.resolve(path.join(buildFolder, filename)) + const destFileName = path.resolve(path.join(BUILD_FOLDER, filename)) const dirname = path.dirname(destFileName) if (!fs.existsSync(dirname)) { @@ -162,45 +174,81 @@ 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(BUILD_FOLDER, filename))) } } } } + /** + * Copy the `node_modules` folder and `package.json` files to the output + * directory. + * @param isPackaging Provided if serverless is packaging the service for deployment + */ + async copyDependencies(isPackaging = false) { + const outPkgPath = path.resolve(path.join(BUILD_FOLDER, 'package.json')) + const outModulesPath = path.resolve(path.join(BUILD_FOLDER, 'node_modules')) + + // copy development dependencies during packaging + if (isPackaging) { + if (fs.existsSync(outModulesPath)) { + fs.unlinkSync(outModulesPath) + } + + fs.copySync( + path.resolve('node_modules'), + path.resolve(path.join(BUILD_FOLDER, 'node_modules')) + ) + } else { + if (!fs.existsSync(outModulesPath)) { + await this.linkOrCopy(path.resolve('node_modules'), outModulesPath, 'junction') + } + } + + // copy/link package.json + if (!fs.existsSync(outPkgPath)) { + await this.linkOrCopy(path.resolve('package.json'), outPkgPath, 'file') + } + } + + /** + * Move built code to the serverless folder, taking into account individual + * packaging preferences. + */ async moveArtifacts(): Promise { + const { service } = this.serverless + await fs.copy( - path.join(this.originalServicePath, buildFolder, serverlessFolder), - path.join(this.originalServicePath, serverlessFolder) + path.join(this.originalServicePath, BUILD_FOLDER, SERVERLESS_FOLDER), + path.join(this.originalServicePath, SERVERLESS_FOLDER) ) 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( + const fn = service.functions[this.options.function] + fn.package.artifact = path.join( this.originalServicePath, - serverlessFolder, + SERVERLESS_FOLDER, path.basename(fn.package.artifact) ) return } - if (this.serverless.service.package.individually) { - const functionNames = this.serverless.service.getAllFunctions() + if (service.package.individually) { + const functionNames = service.getAllFunctions() functionNames.forEach(name => { - this.serverless.service.functions[name].package.artifact = path.join( + service.functions[name].package.artifact = path.join( this.originalServicePath, - serverlessFolder, - path.basename(this.serverless.service.functions[name].package.artifact) + SERVERLESS_FOLDER, + path.basename(service.functions[name].package.artifact) ) }) return } - this.serverless.service.package.artifact = path.join( + service.package.artifact = path.join( this.originalServicePath, - serverlessFolder, - path.basename(this.serverless.service.package.artifact) + SERVERLESS_FOLDER, + path.basename(service.package.artifact) ) } @@ -209,18 +257,14 @@ export class TypeScriptPlugin { // Restore service path this.serverless.config.servicePath = this.originalServicePath // Remove temp build folder - fs.removeSync(path.join(this.originalServicePath, buildFolder)) + fs.removeSync(path.join(this.originalServicePath, BUILD_FOLDER)) } /** * Attempt to symlink a given path or directory and copy if it fails with an * `EPERM` error. */ - private async linkOrCopy( - srcPath: string, - dstPath: string, - type?: 'dir' | 'junction' | 'file' - ): Promise { + private async linkOrCopy(srcPath: string, dstPath: string, type?: fs.FsSymlinkType): Promise { return fs.symlink(srcPath, dstPath, type) .catch(error => { if (error.code === 'EPERM' && error.errno === -4048) { diff --git a/src/types.ts b/src/types.ts deleted file mode 100644 index 4ad23338..00000000 --- a/src/types.ts +++ /dev/null @@ -1,39 +0,0 @@ -export interface ServerlessInstance { - cli: { - log(str: string) - } - config: { - servicePath: string - } - service: { - provider: { - name: string - } - functions: { [key: string]: ServerlessFunction } - package: ServerlessPackage - getAllFunctions: () => string[] - } - pluginManager: PluginManager -} - -export interface ServerlessOptions { - function?: string - watch?: boolean - extraServicePath?: string -} - -export interface ServerlessFunction { - handler: string - package: ServerlessPackage -} - -export interface ServerlessPackage { - include: string[] - exclude: string[] - artifact?: string - individually?: boolean -} - -export interface PluginManager { - spawn(command: string): Promise -} diff --git a/src/typescript.ts b/src/typescript.ts index f18e59b4..22f7354a 100644 --- a/src/typescript.ts +++ b/src/typescript.ts @@ -1,7 +1,6 @@ import * as ts from 'typescript' import * as fs from 'fs-extra' import * as _ from 'lodash' -import { ServerlessFunction } from './types' import * as path from 'path' export function makeDefaultTypescriptConfig() { @@ -9,6 +8,7 @@ export function makeDefaultTypescriptConfig() { preserveConstEnums: true, strictNullChecks: true, sourceMap: true, + allowJs: true, target: ts.ScriptTarget.ES5, moduleResolution: ts.ModuleResolutionKind.NodeJs, lib: ['lib.es2015.d.ts'], @@ -18,8 +18,7 @@ export function makeDefaultTypescriptConfig() { return defaultTypescriptConfig } -export function extractFileNames(cwd: string, provider: string, functions?: { [key: string]: ServerlessFunction }): string[] { - +export function extractFileNames(cwd: string, provider: string, functions?: { [key: string]: Serverless.Function }): string[] { // The Google provider will use the entrypoint not from the definition of the // handler function, but instead from the package.json:main field, or via a // index.js file. This check reads the current package.json in the same way @@ -53,7 +52,21 @@ export function extractFileNames(cwd: string, provider: string, functions?: { [k const fnName = _.last(h.split('.')) const fnNameLastAppearanceIndex = h.lastIndexOf(fnName) // replace only last instance to allow the same name for file and handler - return h.substring(0, fnNameLastAppearanceIndex) + 'ts' + const fileName = h.substring(0, fnNameLastAppearanceIndex) + + // Check if the .ts files exists. If so return that to watch + if (fs.existsSync(path.join(cwd, fileName + 'ts'))) { + return fileName + 'ts' + } + + // Check if the .js files exists. If so return that to watch + if (fs.existsSync(path.join(cwd, fileName + 'js'))) { + return fileName + 'js' + } + + // Can't find the files. Watch will have an exception anyway. So throw one with error. + console.log(`Cannot locate handler - ${fileName} not found`) + throw new Error('Typescript compilation failed. Please ensure handlers exists with ext .ts or .js') }) } diff --git a/src/watchFiles.ts b/src/watchFiles.ts index 8b8322c5..a231534a 100644 --- a/src/watchFiles.ts +++ b/src/watchFiles.ts @@ -1,13 +1,7 @@ import * as typescript from './typescript' -import * as ts from 'typescript' import { watchFile, unwatchFile, Stats} from 'fs' -import { ServerlessOptions, ServerlessInstance, ServerlessFunction } from './types' -export function watchFiles( - rootFileNames: string[], - originalServicePath: string, - cb: () => void -) { +export function watchFiles(rootFileNames: string[], originalServicePath: string, cb: () => void) { const tsConfig = typescript.getTypescriptConfig(originalServicePath) let watchedFiles = typescript.getSourceFiles(rootFileNames, tsConfig) @@ -18,7 +12,7 @@ export function watchFiles( function watchCallback(curr: Stats, prev: Stats) { // Check timestamp if (+curr.mtime <= +prev.mtime) { - return + return } cb() diff --git a/tests/assets/hello.ts b/tests/assets/hello.ts new file mode 100644 index 00000000..e69de29b diff --git a/tests/assets/jsfile.js b/tests/assets/jsfile.js new file mode 100644 index 00000000..e69de29b diff --git a/tests/assets/world.ts b/tests/assets/world.ts new file mode 100644 index 00000000..e69de29b diff --git a/tests/typescript.extractFileName.test.ts b/tests/typescript.extractFileName.test.ts index 13ca2339..82fac1d8 100644 --- a/tests/typescript.extractFileName.test.ts +++ b/tests/typescript.extractFileName.test.ts @@ -1,24 +1,23 @@ import {extractFileNames} from '../src/typescript' -import {ServerlessFunction} from '../src/types' import * as path from 'path' -const functions: { [key: string]: ServerlessFunction } = { +const functions: { [key: string]: Serverless.Function } = { hello: { - handler: 'my-folder/hello.handler', + handler: 'tests/assets/hello.handler', package: { include: [], exclude: [] } }, world: { - handler: 'my-folder/my-subfolder/world.handler', + handler: 'tests/assets/world.handler', package: { include: [], exclude: [] } }, - create: { - handler: 'create.create', + js: { + handler: 'tests/assets/jsfile.create', package: { include: [], exclude: [] @@ -32,9 +31,9 @@ describe('extractFileName', () => { extractFileNames(process.cwd(), 'aws', functions), ).toEqual( [ - 'my-folder/hello.ts', - 'my-folder/my-subfolder/world.ts', - 'create.ts', + 'tests/assets/hello.ts', + 'tests/assets/world.ts', + 'tests/assets/jsfile.js', ], ) }) diff --git a/tslint.json b/tslint.json index 5c031f84..c5574c66 100644 --- a/tslint.json +++ b/tslint.json @@ -19,7 +19,8 @@ "ban-types": false, "interface-name": false, "forin": false, - "no-empty-interface": false + "no-empty-interface": false, + "no-namespace": [true, "allow-declarations"] }, "rulesDirectory": [] } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 4df663f3..735f988f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -353,10 +353,10 @@ resolved "https://registry.yarnpkg.com/@types/jest-diff/-/jest-diff-20.0.1.tgz#35cc15b9c4f30a18ef21852e255fdb02f6d59b89" integrity sha512-yALhelO3i0hqZwhjtcr6dYyaLoCHbAMshwtj6cGxTvHZAKXHsYGdff6E8EPw3xLKY0ELUTQ69Q1rQiJENnccMA== -"@types/jest@24.0.11": - version "24.0.11" - resolved "https://registry.yarnpkg.com/@types/jest/-/jest-24.0.11.tgz#1f099bea332c228ea6505a88159bfa86a5858340" - integrity sha512-2kLuPC5FDnWIDvaJBzsGTBQaBbnDweznicvK7UGYzlIJP4RJR2a4A/ByLUXEyEgag6jz8eHdlWExGDtH3EYUXQ== +"@types/jest@24.0.12": + version "24.0.12" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-24.0.12.tgz#0553dd0a5ac744e7dc4e8700da6d3baedbde3e8f" + integrity sha512-60sjqMhat7i7XntZckcSGV8iREJyXXI6yFHZkSZvCPUeOnEJ/VP1rU/WpEWQ56mvoh8NhC+sfKAuJRTyGtCOow== dependencies: "@types/jest-diff" "*" @@ -375,6 +375,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-11.12.2.tgz#d7f302e74b10e9801d52852137f652d9ee235da8" integrity sha512-c82MtnqWB/CqqK7/zit74Ob8H1dBdV7bK+BcErwtXbe0+nUGkgzq5NTDmRW/pAv2lFtmeNmW95b0zK2hxpeklg== +"@types/node@12.6.2": + version "12.6.2" + resolved "https://registry.yarnpkg.com/@types/node/-/node-12.6.2.tgz#a5ccec6abb6060d5f20d256fb03ed743e9774999" + integrity sha512-gojym4tX0FWeV2gsW4Xmzo5wxGjXGm550oVUII7f7G5o4BV6c7DBdiG1RRQd+y1bvqRyYtPfMK85UM95vsapqQ== + "@types/stack-utils@^1.0.1": version "1.0.1" resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e" @@ -2453,10 +2458,10 @@ mkdirp@0.x, mkdirp@^0.5.1: dependencies: minimist "0.0.8" -mock-fs@4.8.0: - version "4.8.0" - resolved "https://registry.yarnpkg.com/mock-fs/-/mock-fs-4.8.0.tgz#eb0784ceba4b34c91a924a5112eeb36e1b5a9e29" - integrity sha512-Gwj4KnJOW15YeTJKO5frFd/WDO5Mc0zxXqL9oHx3+e9rBqW8EVARqQHSaIXznUdljrD6pvbNGW2ZGXKPEfYJfw== +mock-fs@4.9.0: + version "4.9.0" + resolved "https://registry.yarnpkg.com/mock-fs/-/mock-fs-4.9.0.tgz#7fc0c2f82965050b2776f8eb4eb63ca53a92ff86" + integrity sha512-aUj0qIniTNxzGqAC61Bvro7YD37tIBnMw3wpClucUVgNBS7r6YQn/M4wuoH7SGteKz4SvC1OBeDsfpG0MYC+1Q== ms@2.0.0: version "2.0.0" @@ -2974,7 +2979,7 @@ ret@~0.1.10: resolved "https://registry.yarnpkg.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc" integrity sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg== -rimraf@^2.5.4, rimraf@^2.6.2, rimraf@^2.6.3: +rimraf@2.6.3, rimraf@^2.5.4, rimraf@^2.6.2: version "2.6.3" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab" integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA== @@ -3385,10 +3390,10 @@ trim-right@^1.0.1: resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003" integrity sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM= -ts-jest@24.0.1: - version "24.0.1" - resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-24.0.1.tgz#77258061cc354c3fa8616b8ac03baa0f8580f854" - integrity sha512-mgNZmYPuGBNgYpUzchI7vdSr6zATQI0TrSyzREnXHuPCvlW8T1DQ/fdscgx4ivS5vAMUGUaoxGdWIVHC5I8imw== +ts-jest@24.0.2: + version "24.0.2" + resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-24.0.2.tgz#8dde6cece97c31c03e80e474c749753ffd27194d" + integrity sha512-h6ZCZiA1EQgjczxq+uGLXQlNgeg02WWJBbeT8j6nyIBRQdglqbvzDoHahTEIiS6Eor6x8mK6PfZ7brQ9Q6tzHw== dependencies: bs-logger "0.x" buffer-from "1.x"