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

change writeHash to use a default parameter instead of bind (#17) #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kinland
Copy link

@kinland kinland commented Oct 19, 2023

This PR allows you to write a custom hash. This is primarily a workaround for #16

With these changes, I can now do something like

/** @type {import('package-changed/types')} */
const { isPackageChanged } = require('package-changed');

/** @type {import('child_process')} */
const { execSync } = require('node:child_process');

(async () => {
    const { oldHash, hash: rootHash, writeHash } = await isPackageChanged({ noHashFile: true });
    const { hash: nextjsHash } = await isPackageChanged({ noHashFile: true, cwd: './nextjs' });

    const newHash = `${rootHash}${nextjsHash}`;

    if (newHash !== oldHash) {
        console.log("Package changed. Running 'rm -f .eslintcache && pnpm install'.");
        // dependencies in a package.json have changed since last run
        execSync('rm -f .eslintcache');
        execSync('pnpm install');

        writeHash(newHash);
    }
})();

@thdk
Copy link
Owner

thdk commented Oct 22, 2023

Hi, thanks for your effort. I like your approach as it keeps the library simple without requiring too much knowledge of package managers logic.

However, I think we can add a helper function to the library writeHash(hash: string): void which could also be used internally when calling the writeHash(): void function returned from isPackageChanged.

So your example usage would become:

/** @type {import('package-changed/types')} */
const { isPackageChanged, writeHash } = require('package-changed');

/** @type {import('child_process')} */
const { execSync } = require('node:child_process');

(async () => {
    const { oldHash, hash: rootHash } = await isPackageChanged({ noHashFile: true });
    const { hash: nextjsHash } = await isPackageChanged({ noHashFile: true, cwd: './nextjs' });

    const newHash = `${rootHash}${nextjsHash}`;

    if (newHash !== oldHash) {
        console.log("Package changed. Running 'rm -f .eslintcache && pnpm install'.");
        // dependencies in a package.json have changed since last run
        execSync('rm -f .eslintcache');
        execSync('pnpm install');

        writeHash(newHash);
    }
})();

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

Successfully merging this pull request may close these issues.

2 participants