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

Add a script to check of the usage of the correct lock files #44

Closed
mheob opened this issue Sep 16, 2022 · 0 comments · Fixed by #48
Closed

Add a script to check of the usage of the correct lock files #44

mheob opened this issue Sep 16, 2022 · 0 comments · Fixed by #48
Assignees
Labels
ci/cd Belongs to the CI/CD workflow

Comments

@mheob
Copy link
Owner

mheob commented Sep 16, 2022

It could be helpful to check if there are the correct package manager is used.
For that, a script like this could help:

import { existsSync } from 'node:fs';

const checkLockFiles = (): string[] => {
	const uesYarnLockFileMessage = 'Please remove it and use only "pnpm-lock.yaml".';
	const invalidFileMessage = (lockFile: string): string =>
		`Invalid occurrence of "${lockFile}" file. ${uesYarnLockFileMessage}`;

	const errors: string[] = [];

	const npmLockFile = 'package-lock.json';
	existsSync(npmLockFile) && errors.push(invalidFileMessage(npmLockFile));

	const yarnLockFile = 'yarn.lock';
	existsSync(yarnLockFile) && errors.push(invalidFileMessage(yarnLockFile));

	const pnpmLockFile = 'pnpm-lock.yaml';
	!existsSync(pnpmLockFile) &&
		errors.push('The "pnpm-lock.yaml" does not exist or cannot be read. Please run "pnpm i".');

	return errors;
};

const invalidLockFileErrors = checkLockFiles();

if (invalidLockFileErrors.length > 0) {
	for (const error of invalidLockFileErrors) console.log(error);
	process.exit(1);
}

process.exit(0);
@mheob mheob added the ci/cd Belongs to the CI/CD workflow label Sep 16, 2022
@mheob mheob self-assigned this Sep 17, 2022
@kodiakhq kodiakhq bot closed this as completed in 6adc64c Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/cd Belongs to the CI/CD workflow
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant