Skip to content

Commit

Permalink
fix: add matchall polyfill to avoid build error
Browse files Browse the repository at this point in the history
  • Loading branch information
floydspace committed Feb 26, 2021
1 parent b88bfc8 commit 8079c1c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
7 changes: 3 additions & 4 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)]);
}, []);
};

Expand All @@ -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]));
};

Expand Down

0 comments on commit 8079c1c

Please sign in to comment.