Skip to content

Commit

Permalink
More filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jun 25, 2023
1 parent dffac6a commit ad0f5d7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
1 change: 0 additions & 1 deletion cli/run/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export default async function runRollup(command: Record<string, any>): Promise<v

if (isWatchEnabled(command.watch)) {
await loadFsEvents();
// TODO Lukas filter in watch mode
const { watch } = await import('./watch-cli');
await watch(command);
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/getLogFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const testFilter = (log: RollupLog, key: string, parts: string[]): boolean => {
if (!(key in log)) {
return false;
}
let value = String(log[key as keyof RollupLog]);
const rawValue = log[key as keyof RollupLog];
let value = typeof rawValue === 'object' ? JSON.stringify(rawValue) : String(rawValue);
if (!value.startsWith(parts[0])) {
return false;
}
Expand Down
23 changes: 22 additions & 1 deletion test/misc/get-log-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,26 @@ describe.only('getLogFilter', () => {
assert.equal(filter({ code: 'SECOND', plugin: 'my-plugin' }), false);
});

// TODO Lukas handle edge cases: non-string-values (number, object), empty string, no colon, extra colon on right side, unexpected &
it('handles numbers and objects', () => {
const filter = getLogFilter(['foo:1', 'bar:*2*', 'baz:{"a":1}', 'baz:{"b":1,*}']);
assert.equal(filter({ foo: 1 }), true, 'foo:1');
assert.equal(filter({ foo: 10 }), false, 'foo:10');
assert.equal(filter({ bar: 123 }), true, 'bar:123');
assert.equal(filter({ bar: 13 }), false, 'bar:13');
assert.equal(filter({ baz: { a: 1 } }), true, 'baz:{"a":1}');
assert.equal(filter({ baz: { a: 1, b: 2 } }), false, 'baz:{"a":1,"b":2}');
assert.equal(filter({ baz: { b: 1, c: 2 } }), true, 'baz:{"b":1,"c":2}');
});

// it('handles edge case filters', () => {
// const filter = getLogFilter([
// ':A', // property is "empty string"
// 'a:', // value is "empty string"
// '', // property and value are "empty string"
// 'code:A&', // property and value are "empty string",
// 'foo:bar:baz' // second colon is treated literally
// ]);
// });

// TODO Lukas filter in watch mode, nested properties, handle edge cases: empty string, no colon, extra colon on right side, unexpected &
});

0 comments on commit ad0f5d7

Please sign in to comment.