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

[suggestion] writeHash should use default parameter instead of bind #17

Open
kinland opened this issue Oct 19, 2023 · 0 comments
Open

Comments

@kinland
Copy link

kinland commented Oct 19, 2023

The original writeHash method takes an optional string for the hash.

However, the method that gets returned is writeHash.bind(null, result.hash)

As a result, as a workaround for #16 , I'm unable to write a custom hash.

My suggestion is to move the writeHash method to just below the const result = and change it to

    const writeHash = (hash: string | undefined = result.hash) =>
        hash && fs.writeFileSync(packageHashPath, hash, {});

This would allow me to use a concatenated hash for multiple files, like so:

/** @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);
    }
})();

I will open a PR for this shortly.

kinland added a commit to kinland/package-changed that referenced this issue Oct 19, 2023
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

1 participant