Introduces a new bruno.json configuration property named 'ignore' allowing to specify which files or folders should be ignored in the collection. (#1514)

Also makes sure the behavior of legacy collections is not altered.

Fixes issue #1496
This commit is contained in:
fredjeck 2024-02-04 22:34:54 +01:00 committed by GitHub
parent 09e7ea0d4d
commit cb95b5f36a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 10 deletions

View File

@ -33,6 +33,10 @@ const Info = ({ collection }) => {
<td className="py-2 px-2 text-right">Location&nbsp;:</td>
<td className="py-2 px-2 break-all">{collection.pathname}</td>
</tr>
<tr className="">
<td className="py-2 px-2 text-right">Ignored files&nbsp;:</td>
<td className="py-2 px-2 break-all">{collection.brunoConfig.ignore.map((x) => `'${x}'`).join(', ')}</td>
</tr>
<tr className="">
<td className="py-2 px-2 text-right">Environments&nbsp;:</td>
<td className="py-2 px-2">{collection.environments?.length || 0}</td>

View File

@ -62,8 +62,13 @@ const openCollection = async (win, watcher, collectionPath, options = {}) => {
const brunoConfig = await getCollectionConfigFile(collectionPath);
const uid = generateUidBasedOnHash(collectionPath);
if (!brunoConfig.ignore || brunoConfig.ignore.length === 0) {
// Forces default behavior for legacy collections
brunoConfig.ignore = ['node_modules', '.git'];
}
win.webContents.send('main:collection-opened', collectionPath, uid, brunoConfig);
ipcMain.emit('main:collection-opened', win, collectionPath, uid);
ipcMain.emit('main:collection-opened', win, collectionPath, uid, brunoConfig);
} catch (err) {
if (!options.dontSendDisplayErrors) {
win.webContents.send('main:display-error', {

View File

@ -403,17 +403,18 @@ class Watcher {
this.watchers = {};
}
addWatcher(win, watchPath, collectionUid) {
addWatcher(win, watchPath, collectionUid, brunoConfig) {
if (this.watchers[watchPath]) {
this.watchers[watchPath].close();
}
const ignores = brunoConfig?.ignore || [];
const self = this;
setTimeout(() => {
const watcher = chokidar.watch(watchPath, {
ignoreInitial: false,
usePolling: watchPath.startsWith("\\\\") ? true : false,
ignored: (path) => ['node_modules', '.git'].some((s) => path.includes(s)),
usePolling: watchPath.startsWith('\\\\') ? true : false,
ignored: (path) => ignores.some((s) => path.includes(s)),
persistent: true,
ignorePermissionErrors: true,
awaitWriteFinish: {

View File

@ -70,13 +70,14 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
const brunoConfig = {
version: '1',
name: collectionName,
type: 'collection'
type: 'collection',
ignore: ['node_modules', '.git']
};
const content = await stringifyJson(brunoConfig);
await writeFile(path.join(dirPath, 'bruno.json'), content);
mainWindow.webContents.send('main:collection-opened', dirPath, uid, brunoConfig);
ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid);
ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid, brunoConfig);
} catch (error) {
return Promise.reject(error);
}
@ -449,13 +450,14 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
const brunoConfig = {
version: '1',
name: collectionName,
type: 'collection'
type: 'collection',
ignore: ['node_modules', '.git']
};
const content = await stringifyJson(brunoConfig);
await writeFile(path.join(collectionPath, 'bruno.json'), content);
mainWindow.webContents.send('main:collection-opened', collectionPath, uid, brunoConfig);
ipcMain.emit('main:collection-opened', mainWindow, collectionPath, uid);
ipcMain.emit('main:collection-opened', mainWindow, collectionPath, uid, brunoConfig);
lastOpenedCollections.add(collectionPath);
@ -612,8 +614,8 @@ const registerMainEventHandlers = (mainWindow, watcher, lastOpenedCollections) =
shell.openExternal(docsURL);
});
ipcMain.on('main:collection-opened', (win, pathname, uid) => {
watcher.addWatcher(win, pathname, uid);
ipcMain.on('main:collection-opened', (win, pathname, uid, brunoConfig) => {
watcher.addWatcher(win, pathname, uid, brunoConfig);
lastOpenedCollections.add(pathname);
});