macos_exclude_node_module_stores
This script will exclude all node_modules
and .pnpm-store
directories in the given directory ($PWD
if not given) and its subdirectories from Time Machine backups and prevent their Spotlight indexing.
Copy the script into your Node.js project and add it as a preinstall life cycle script to your package.json
For this to work, you should not ignore pre- or post-scripts:
Alternatively, you can use this script as a custom script in your package.json
And execute it manually:
|
Usage
$ scripts/nodejs/macos_exclude_node_module_stores.sh
$ scripts/nodejs/macos_exclude_node_module_stores.sh /tmp/example_project
$ xattr -r /tmp/example_workspace
$ tree --noreport -a /tmp/example_workspace
/tmp/example_workspace
├── project1
│ └── node_modules
└── project2
└── frontend
├── .pnpm-store
└── node_modules
$ scripts/nodejs/macos_exclude_node_module_stores.sh /tmp/example_workspace
$ xattr -r /tmp/example_workspace (1)
/tmp/example_workspace/project1/node_modules: com.apple.metadata:com_apple_backup_excludeItem
/tmp/example_workspace/project2/frontend/.pnpm-store: com.apple.metadata:com_apple_backup_excludeItem
/tmp/example_workspace/project2/frontend/node_modules: com.apple.metadata:com_apple_backup_excludeItem
$ tree --noreport -a /tmp/example_workspace
/tmp/example_workspace
├── project1
│ └── node_modules
│ └── .metadata_never_index (2)
└── project2
└── frontend
├── .pnpm-store
│ └── .metadata_never_index (2)
└── node_modules
└── .metadata_never_index (2)
1 | node_modules and .pnpm-store directories are not backed up by Time Machine |
2 | Spotlight indexing prevented |