Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: overall structure and reliability of the function #1296

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
implemented suggestion of reviewer and match with sonarcloud
thebedigupta committed Oct 14, 2024
commit e5c1fc7618315fb119852e7f16f5e58762c5141b
57 changes: 30 additions & 27 deletions apps/generator/lib/hooksRegistry.js
Original file line number Diff line number Diff line change
@@ -24,43 +24,46 @@
* @param {String} templateDir Directory where template is located.
* @param {String} hooksDir Directory where local hooks are located.
*/
function registerLocalHooks(hooks, templateDir, hooksDir) {
return new Promise((resolve, reject) => {
const localHooks = path.resolve(templateDir, hooksDir);
async function registerLocalHooks(hooks, templateDir, hooksDir) {
const localHooks = path.resolve(templateDir, hooksDir);

exists(localHooks).then(localHooksExist => {
if (!localHooksExist) return resolve(hooks);
try {
const localHooksExist = await exists(localHooks);
if (!localHooksExist) return hooks;

const walker = xfs.walk(localHooks, {
followLinks: false
});
return new Promise((resolve, reject) => {
const walker = xfs.walk(localHooks, {
followLinks: false
});

walker.on('file', async (root, stats, next) => {
try {
const filePath = path.resolve(templateDir, path.resolve(root, stats.name));
walker.on('file', async (root, stats, next) => {
try {
const filePath = path.resolve(templateDir, path.resolve(root, stats.name));

registerTypeScript(filePath);
await registerTypeScript(filePath);

delete require.cache[require.resolve(filePath)];
const mod = require(filePath);
delete require.cache[require.resolve(filePath)];
const mod = require(filePath);

addHook(hooks, mod);
addHook(hooks, mod);

next();
} catch (e) {
reject(e);
}
});
next();
} catch (e) {
reject(e);
}
});

walker.on('errors', (root, nodeStatsArray) => {
reject(nodeStatsArray);
});
walker.on('errors', (root, nodeStatsArray) => {
reject(nodeStatsArray);
});

walker.on('end', async () => {
resolve(hooks);
walker.on('end', () => {
resolve(hooks);
});
});
}).catch(reject);
});
} catch (error) {

Check failure on line 64 in apps/generator/lib/hooksRegistry.js

GitHub Actions / Test NodeJS PR - ubuntu-latest

Add logic to this catch clause or eliminate it and rethrow the exception automatically
throw error;
}
}

/**