Skip to content

Commit

Permalink
removed the async keyword from the Promise executor is the direct app…
Browse files Browse the repository at this point in the history
…roach

sorry for over complementing things you are right this was the straight-forward approach for solving this issue
  • Loading branch information
thebedigupta authored Oct 9, 2024
1 parent ad5669e commit 0579c0a
Showing 1 changed file with 33 additions and 39 deletions.
72 changes: 33 additions & 39 deletions apps/generator/lib/hooksRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,54 +19,48 @@ module.exports.registerHooks = async (hooks, templateConfig, templateDir, hooksD

/**
* Loads the local template hooks from default location.
* This function walks through the hooks directory and registers each hook file it finds.
* @private
* @param {Object} hooks Object that stores information about all available hook functions grouped by the type of the hook.
* @param {String} templateDir Directory where template is located.
* @param {String} hooksDir Directory where local hooks are located.
* @returns {Promise<Object>} - A promise that resolves to the updated hooks object.
*/
function registerLocalHooks(hooks, templateDir, hooksDir) {
async function registerLocalHooks(hooks, templateDir, hooksDir) {
const localHooks = path.resolve(templateDir, hooksDir);

if (!await exists(localHooks)) return hooks;

return new Promise((resolve, reject) => {
const localHooks = path.resolve(templateDir, hooksDir);

exists(localHooks)
.then(exists => {
if (!exists) {
resolve(hooks);
return;
}

const walker = xfs.walk(localHooks, { followLinks: false });

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

registerTypeScript(filePath);

delete require.cache[require.resolve(filePath)];

try {
const mod = require(filePath);
addHook(hooks, mod);
next();
} catch (e) {
next(e);
}
});

walker.on('errors', (root, nodeStatsArray) => {
reject(new Error(`Error walking directory: ${nodeStatsArray}`));
});

walker.on('end', () => {
resolve(hooks);
});
})
.catch(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));

registerTypeScript(filePath);

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

addHook(hooks, mod);

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

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

walker.on('end', () => {
resolve(hooks);
});
});
}

/**
* Loads the template hooks provided in template config.
* @private
Expand Down

0 comments on commit 0579c0a

Please sign in to comment.