Skip to content

Commit c064d8f

Browse files
committed
refactor(exportfunctions): improve style and structure of code as well as cleanup some comments
1 parent 16c1e2d commit c064d8f

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

src/export-functions.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable no-console, no-continue, no-unused-vars */
1+
/* eslint-disable no-continue, no-unused-vars */
22
import camelCase from 'camelcase';
33
import glob from 'glob';
44
import set from 'lodash.set';
@@ -187,32 +187,31 @@ export function exportFunctions({
187187
// eslint-disable-next-line no-restricted-syntax
188188
for (const file of files) {
189189
const absPath = resolve(cwd, file);
190-
const standardRelativePath = absPath.substr(cwd.length + 1); /* ? */
191-
const funcName = funcNameFromRelPath(standardRelativePath); /* ? */
192-
if (isDeployment() || funcNameMatchesInstance(funcName)) {
193-
if (!isDeployment()) log.timeEnd(moduleSearchMsg);
194-
if (absPath.slice(0, -2) === __filename.slice(0, -2)) continue; // Prevent exporting self
195-
196-
if (exportPathMode) {
197-
set(exports, funcName.replace(/-/g, '.'), standardRelativePath);
198-
continue;
199-
}
200-
if (!isDeployment()) log.time(coldModuleMsg);
201-
let funcTrigger: any;
202-
try {
203-
// eslint-disable-next-line no-eval
204-
const mod = eval('require')(absPath); // This is to preserve require call in webpack
205-
funcTrigger = extractTrigger(mod, getFunctionInstance());
206-
} catch (err) {
207-
console.error(err);
208-
continue;
209-
}
210-
if (!isDeployment()) log.timeEnd(coldModuleMsg);
211-
if (!funcTrigger) continue;
212-
const propPath = funcName.replace(/-/g, '.'); /* ? */
213-
set(exports, propPath, funcTrigger);
190+
const normalizedRelativePath = absPath.slice(cwd.length + 1); // * This step normalises glob match search string
191+
const funcName = funcNameFromRelPath(normalizedRelativePath); /* ? */
192+
if (!isDeployment() && !funcNameMatchesInstance(funcName)) continue;
193+
if (!isDeployment()) log.timeEnd(moduleSearchMsg);
194+
if (absPath.slice(0, -2) === __filename.slice(0, -2)) continue; // Prevent exporting self
195+
196+
if (exportPathMode) {
197+
set(exports, funcName.split('-'), normalizedRelativePath);
198+
continue;
214199
}
215-
} // End loop
200+
if (!isDeployment()) log.time(coldModuleMsg);
201+
let funcTrigger: any;
202+
try {
203+
// eslint-disable-next-line no-eval
204+
const mod = eval('require')(absPath); // This is to preserve require call in webpack
205+
funcTrigger = extractTrigger(mod, getFunctionInstance());
206+
} catch (err) {
207+
console.warn(err);
208+
continue;
209+
}
210+
if (!isDeployment()) log.timeEnd(coldModuleMsg);
211+
if (!funcTrigger) continue;
212+
const propPath = funcName.split('-');
213+
set(exports, propPath, funcTrigger);
214+
}
216215

217216
if (isDeployment()) log.timeEnd(deployMsg);
218217
return exports;

0 commit comments

Comments
 (0)