@shanzhai/change-tracking-helpers

Helpers for tracking changes to files during a Shanzhai build.

Usage no npm install needed!

<script type="module">
  import shanzhaiChangeTrackingHelpers from 'https://cdn.skypack.dev/@shanzhai/change-tracking-helpers';
</script>

README

@shanzhai/change-tracking-helpers Continuous Integration License FOSSA Status Renovate enabled npm npm type definitions

Helpers for tracking changes to files during a Shanzhai build.

Usage

This is a collection of helpers. Each requires its own explanation.

Generating Diffs

The generateDiff function compares two objects containing key-value pairs.

The differences between them are returned.

import { generateDiff } from "@shanzhai/change-tracking-helpers";

generateDiff({
  testRemoved: 123,
  testChanged: 456,
  testUnchanged: 789,
}, {
  testChanged: 456,
  testUnchanged: 789,
  testAdded: 101112,
});

This will return the following:

{
  added: [`testAdded`],
  changed: [`testChanged`],
  deleted: [`testDeleted`],
  unchanged: [`testUnchanged`],
};

Hashing files

The hashFile function resolves to the SHA-1 hash of a file.

As a reminder, SHA-1 is considered suitable for change tracking but not for protecting against malicious changes.

import { hashFile } from "@shanzhai/change-tracking-helpers";

await hashFile(`a/file/path`);

This will resolve to a string containing the hash in hexadecimal.

Filtering out common temporary or system files

The pathAccepted function determines whether a given string appears to be a temporary or system file or not.

import { pathAccepted } from "@shanzhai/change-tracking-helpers";

pathAccepted(`a/file/path`);

Some examples of paths which would not be accepted:

  • .a-dotfile
  • a/nested/.dotfile/path

Dependencies

This package has no runtime dependencies.

Peer Dependencies

This package has no runtime peer dependencies (it does not expect any other packages to be installed alongside itself).

License

FOSSA Status