Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
The tree-sync npm package is designed to synchronize directories, ensuring that the contents of one directory match another. It is particularly useful for build systems and deployment scripts where maintaining consistent directory structures is crucial.
Synchronize Directories
This feature allows you to synchronize the contents of a source directory with a destination directory. The code sample demonstrates how to use TreeSync to ensure that the destination directory matches the source directory.
const TreeSync = require('tree-sync');
const sourceDir = 'path/to/source';
const destDir = 'path/to/destination';
const tree = new TreeSync(sourceDir, destDir);
tree.sync();
Custom Filter Function
This feature allows you to provide a custom filter function to exclude certain files or directories from being synchronized. The code sample shows how to exclude files with a .tmp extension from the synchronization process.
const TreeSync = require('tree-sync');
const sourceDir = 'path/to/source';
const destDir = 'path/to/destination';
const tree = new TreeSync(sourceDir, destDir);
tree.sync({ filter: (relativePath) => !relativePath.endsWith('.tmp') });
Dry Run Mode
This feature allows you to perform a dry run to see what changes would be made without actually applying them. The code sample demonstrates how to use the dry run mode to preview the synchronization changes.
const TreeSync = require('tree-sync');
const sourceDir = 'path/to/source';
const destDir = 'path/to/destination';
const tree = new TreeSync(sourceDir, destDir);
tree.sync({ dryRun: true });
rsync is a widely-used utility for keeping directories in sync. It is highly efficient and supports a variety of options for file transfer and synchronization. Unlike tree-sync, rsync is a command-line tool and not a Node.js package, but it can be used in Node.js scripts via child processes.
fs-extra is a Node.js package that extends the native fs module with additional methods for file and directory manipulation. While it does not provide a direct synchronization feature like tree-sync, it offers methods like copy and move that can be used to achieve similar results.
chokidar is a Node.js package for watching file and directory changes. It can be used to trigger synchronization actions when changes are detected. While it does not perform synchronization itself, it can be combined with other tools to achieve directory synchronization.
A module for repeated efficient synchronizing two directories.
// input/a/{a.js,b.js}
// output/
var tree = new TreeSync('input', 'output');
tree.sync();
// output is now contains copies of everything that is in input
fs.unlink('/input/a/b.js');
// input / output have diverged
tree.sync();
// difference is calculated and efficient patch to update `output` is created and applied
Under the hood, this library uses walk-sync to traverse files and folders. You may optionally pass in options to selectively include or ignore files and directories. These whitelisted properties (ignore
and globs
) will be passed to walk-sync.
// Assume the following folder structure...
// input/
// foo/
// foo.js
// bar.js
// bar/
// foo-bar.js
var tree = new TreeSync('input', 'output', {
ignore: ['**/b']
});
tree.sync();
// We now expect output to contain foo/, but not bar/.
// Any changes made to bar/ won't be synced to output, and the contents of bar/ won't be traversed.
// Assume the following folder structure...
// input/
// foo/
// foo.js
// bar.js
// bar/
// foo-bar.js
var tree = new TreeSync('input', 'output', {
globs: ['foo', 'foo/bar.js']
});
tree.sync();
// We now expect output to contain foo/bar.js, but nothing else.
// Be careful when using this property! You'll need to make sure that if you're including a file, it's parent
// path is also included, or you'll get an error when tree-sync tries to copy the file over.
FAQs
A module for repeated efficient synchronizing two directories.
We found that tree-sync demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.