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: package argument #15

Open
FFdhorkin opened this issue Jul 19, 2023 · 2 comments
Open

Suggestion: package argument #15

FFdhorkin opened this issue Jul 19, 2023 · 2 comments

Comments

@FFdhorkin
Copy link

FFdhorkin commented Jul 19, 2023

I've got an expensive command that I only want to run when a specific dependency's version changes. While I can manually log the hash to a file, it would be preferable to be able to include this within the packagehash from package-changed.

My imagined usage would go something like this:

const {
  isChanged,
  monitoredPackagesChanged, // Record<packageName, isChanged for that package>
  writeHash,
} = await isPackageChanged({
  hashFilename: '.packagehash',
  monitorPackages: ['foo']
});

if (isChanged) {
  // do some stuff always
  ...

  if (monitoredPackagesChanged.foo) {
    // do the expensive thing here
  }
  writeHash();
}

I imagine that would necessitate turning the packagehash file into a JSON object

@thdk
Copy link
Owner

thdk commented Jul 21, 2023

Thanks for the suggestion. Would you be up for submitting a PR for this?

I would though prefer to use the following:

--only, -O only include the dependencies of which the name matches given regex in calculated hash

So if you want to run some command when a single package changed.

npx package-changed --only some-dependency --run 'echo "some-dependency was updated"

If you still need to know when any package changed you have to run the package-changed command twice with different arguments and using a different hash file.

@FFdhorkin
Copy link
Author

FFdhorkin commented Jul 21, 2023

Tentatively, I'm up for submitting a PR for this, but it will depend on me finding the time.

Regarding the --only: would you be OK with me changing the packagehash file to a JSON object? I'd prefer not to create a bunch of separate files. Even when added to .gitignore in projects, that's just extra clutter.

People using package-changed without the new functionality would end up with a file like

{ "package.json": "c425579fe880e10f9c84caf2b3aa0b58" }

Whereas people who had only been monitoring some-dependency might have

{ "some-dependency": "9c84caf2b3aa0b58c425579fe880e10f" }

And someone doing both:

{ 
    "package.json": "c425579fe880e10f9c84caf2b3aa0b58",
    "some-dependency": "9c84caf2b3aa0b58c425579fe880e10f"
}

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