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

prevent overwriting custom commands #1439

Open
adiletbaimyrza opened this issue May 10, 2024 · 2 comments
Open

prevent overwriting custom commands #1439

adiletbaimyrza opened this issue May 10, 2024 · 2 comments

Comments

@adiletbaimyrza
Copy link

Hello, my team is working on a project and at some point we decided to integrate husky. The thing is that our project is not located in the same directory as .git file. I managed to change prepare script from
"scripts": { ..., "prepare": "husky" },
to
"scripts": { ..., "prepare": "cd .. && husky frontend/.husky && cd frontend && npx husky init" },

and I created .husky/pre-commit file with cd frontend npx lint-staged

when running npm install it overwrites package.json and .husky/pre-commit files to default values. I created a fork of the husky repository and added a few lines to prevent overwriting those files. Like so:

// create a prepare script only if it doesn't exist
if (!o.scripts.prepare) {
	;(o.scripts ||= {}).prepare = 'husky'
	w(n, JSON.stringify(o, 0, /\t/.test(s) ? '\t' : 2) + '\n')
}

p.stdout.write(i())
try { f.mkdirSync('.husky') } catch {}

// create a pre-commit file with test command only if it doesn't exist
if (!e('.husky/pre-commit')) {
	w('.husky/pre-commit', process.env.npm_config_user_agent.split('/')[0] + ' test\n');
}

it works well in our project. What do you think about adding those lines to the bin.mjs?

@typicode
Copy link
Owner

Hi, husky init needs to be called only once in a project and shouldn't be added to scripts

@adiletbaimyrza
Copy link
Author

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants