diff --git a/package.json b/package.json index 1a6ac3d7..bd9eb330 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "esbuild": ">=0.8", "fs-extra": "^9.0.1", "globby": "^11.0.1", - "ramda": "^0.27.0" + "ramda": "^0.27.0", + "string.prototype.matchall": "^4.0.4" } } diff --git a/src/helper.ts b/src/helper.ts index 8185c5eb..58359bef 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -2,6 +2,7 @@ import * as fs from 'fs-extra'; import * as path from 'path'; import { uniq } from 'ramda'; import * as Serverless from 'serverless'; +import * as matchAll from 'string.prototype.matchall'; export function extractFileNames( cwd: string, @@ -66,8 +67,7 @@ export const flatDep = (deps: any, filter?: string[]) => { if (!deps) return []; return Object.entries(deps).reduce((acc, [depName, details]) => { if (filter && !filter.includes(depName)) return acc; - // @ts-ignore - return uniq([...acc, depName, ...flatDep(details.dependencies)]); + return uniq([...acc, depName, ...flatDep((details as any).dependencies)]); }, []); }; @@ -77,8 +77,7 @@ export const flatDep = (deps: any, filter?: string[]) => { */ export const getDepsFromBundle = (bundlePath: string) => { const bundleContent = fs.readFileSync(bundlePath, 'utf8'); - // @ts-ignore - const requireMatch = bundleContent.matchAll(/require\("(.*?)"\)/gim); + const requireMatch = matchAll(bundleContent, /require\("(.*?)"\)/gim); return uniq(Array.from(requireMatch).map(match => match[1])); };