Skip to content

Commit 71ef4f6

Browse files
committed
Simplified conditions for return log instructions in API methods to rely on browser window to support ESM env
1 parent bcfa6f5 commit 71ef4f6

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

generate-pw/src/generate-pw.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,9 @@ function generatePassword(options = {}) {
8484

8585
// Log/return final result
8686
if (options.verbose && !fromGeneratePasswords) {
87-
console.info(
88-
'generatePassword() » Password generated!');
89-
if (typeof require == 'undefined' || !/cli(?:\.min)?\.js$/.test(require.main.filename)) console.info(
90-
'generatePassword() » Check returned string.');
87+
console.info('generatePassword() » Password generated!');
88+
if (typeof window != 'undefined')
89+
console.info('generatePassword() » Check returned string.');
9190
}
9291
return password;
9392
}
@@ -129,10 +128,11 @@ function generatePasswords(qty, options = {}) {
129128
for (let i = 0; i < qty; i++) passwords.push(generatePassword(options));
130129

131130
// Log/return final result
132-
if (options.verbose) console.info(
133-
`generatePasswords() » Password${ qty > 1 ? 's' : '' } generated!`);
134-
if (typeof require == 'undefined' || !/cli(?:\.min)?\.js$/.test(require.main.filename)) console.info(
135-
'generatePasswords() » Check returned array.');
131+
if (options.verbose) {
132+
console.info(`generatePasswords() » Password${ qty > 1 ? 's' : '' } generated!`);
133+
if (typeof window != 'undefined')
134+
console.info('generatePasswords() » Check returned array.');
135+
}
136136
return passwords;
137137
}
138138

geolocate/src/geolocate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async function geolocate(ips, options = {}) {
3737
let { status, org, as, query, ...filteredData } = await response.json(); // eslint-disable-line no-unused-vars
3838
filteredData = { ip, ...filteredData }; geoData.push(filteredData);
3939
}
40-
if (options.verbose && (typeof require == 'undefined' || !/cli(?:\.min)?\.js$/.test(require.main.filename)))
40+
if (options.verbose && typeof window != 'undefined')
4141
console.info('geolocate() » Success! Check returned array.');
4242
return geoData;
4343
} catch (err) { console.error('geolocate() » ERROR:', err.message); }

minify.js/node.js/src/minify.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,11 @@ function findJS(searchDir, options = {}) {
6363

6464
// Log/return final result
6565
if (!options.isRecursing && options.verbose) {
66-
console.info('findJS() » Search complete! '
67-
+ ( jsFiles.length == 0 ? 'No' : jsFiles.length )
68-
+ ` file${ jsFiles.length == 1 ? '' : 's' } found.`);
69-
if (findJS.caller.name != 'minify' && !process.argv.some(arg => arg.includes('gulp')) &&
70-
!/cli(?:\.min)?\.js$/.test(require.main.filename))
71-
console.info('findJS() » Check returned array.');
66+
console.info('findJS() » Search complete! '
67+
+ ( jsFiles.length == 0 ? 'No' : jsFiles.length )
68+
+ ` file${ jsFiles.length == 1 ? '' : 's' } found.`);
69+
if (findJS.caller.name != 'minify' && typeof window != 'undefined')
70+
console.info('findJS() » Check returned array.');
7271
}
7372
return options.isRecursing || jsFiles.length > 0 ? jsFiles : [];
7473
}
@@ -107,9 +106,8 @@ function minify(input, options = {}) {
107106
const minifyResult = uglifyJS.minify(fs.readFileSync(input, 'utf8'), minifyOptions);
108107
if (options.comment) minifyResult.code = prependComment(minifyResult.code, options.comment);
109108
if (minifyResult.error) console.error(`minify() » ERROR: ${minifyResult.error.message}`);
110-
else if (options.verbose && !process.argv.some(arg => arg.includes('gulp')) &&
111-
!/cli(?:\.min)?\.js$/.test(require.main.filename))
112-
console.info('minify() » Minification complete! Check returned object.');
109+
else if (typeof window != 'undefined')
110+
console.info('minify() » Minification complete! Check returned object.');
113111
return { code: minifyResult.code, srcPath: path.resolve(process.cwd(), input),
114112
error: minifyResult.error };
115113
} else { // dir path passed

scss-to-css/node.js/src/scss-to-css.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function findSCSS(searchDir, options = {}) {
6464
console.info('findSCSS() » Search complete! '
6565
+ ( scssFiles.length == 0 ? 'No' : scssFiles.length )
6666
+ ` file${ scssFiles.length == 1 ? '' : 's' } found.`);
67-
if (findSCSS.caller.name != 'compile' && !/cli(?:\.min)?\.js$/.test(require.main.filename))
67+
if (findSCSS.caller.name != 'compile' && typeof window != 'undefined')
6868
console.info('findSCSS() » Check returned array.');
6969
}
7070
return options.isRecursing || scssFiles.length > 0 ? scssFiles : [];
@@ -104,7 +104,7 @@ function compile(input, options = {}) {
104104
try { // to compile file passed
105105
const compileResult = sass.compile(input, compileOptions);
106106
if (options.comment) compileResult.css = prependComment(compileResult.css, options.comment);
107-
if (options.verbose && !/cli(?:\.min)?\.js$/.test(require.main.filename))
107+
if (options.verbose && typeof window != 'undefined')
108108
console.info('compile() » Compilation complete! Check returned object.');
109109
return { code: compileResult.css, srcMap: compileResult.sourceMap,
110110
srcPath: path.resolve(process.cwd(), input), error: undefined };

0 commit comments

Comments
 (0)