Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix CHOICES_SEARCH_KMP not being set was breaking e2e tests
  • Loading branch information
Xon committed Mar 14, 2025
commit 3361a7119d968c2ba7a6a128e0eb0a3e08d7cad3
4 changes: 2 additions & 2 deletions public/types/src/scripts/interfaces/build-flags.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export declare const canUseDom: boolean;
export declare const searchFuse: string | undefined;
export declare const searchKMP: string | undefined;
export declare const searchKMP: boolean;
/**
* These are not directly used, as an exported object (even as const) will prevent tree-shake away code paths
*/
export declare const BuildFlags: {
readonly searchFuse: string | undefined;
readonly searchKMP: string | undefined;
readonly searchKMP: boolean;
readonly canUseDom: boolean;
};
11 changes: 11 additions & 0 deletions public/types/src/scripts/search/kmp.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Options } from '../interfaces';
import { Searcher, SearchResult } from '../interfaces/search';
export declare class SearchByKMP<T extends object> implements Searcher<T> {
_fields: string[];
_haystack: T[];
constructor(config: Options);
index(data: T[]): void;
reset(): void;
isEmptyIndex(): boolean;
search(_needle: string): SearchResult<T>[];
}
1 change: 1 addition & 0 deletions scripts/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const pckg = require('../package.json');

const buildFeatures = {
CHOICES_SEARCH_FUSE: "full", // "basic" / "null"
CHOICES_SEARCH_KMP: "0", // "1"
CHOICES_CAN_USE_DOM: "1", // "0"
}

Expand Down
2 changes: 1 addition & 1 deletion src/scripts/interfaces/build-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const canUseDom: boolean =
: !!(typeof document !== 'undefined' && document.createElement);

export const searchFuse: string | undefined = process.env.CHOICES_SEARCH_FUSE;
export const searchKMP: string | undefined = process.env.CHOICES_SEARCH_KMP;
export const searchKMP: boolean = process.env.CHOICES_SEARCH_KMP === '1';

/**
* These are not directly used, as an exported object (even as const) will prevent tree-shake away code paths
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SearchByKMP } from './kmp';
import { searchFuse, searchKMP } from '../interfaces/build-flags';

export function getSearcher<T extends object>(config: Options): Searcher<T> {
if (searchFuse) {
if (searchFuse && !searchKMP) {
return new SearchByFuse<T>(config);
}
if (searchKMP) {
Expand Down
Loading