Skip to content

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

Description

@kinland

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions