Skip to content

Commit 139b82b

Browse files
committed
fix: fix Uncaught ReferenceError: importScripts is not defined
1 parent 4376e13 commit 139b82b

File tree

13 files changed

+87
-373
lines changed

13 files changed

+87
-373
lines changed

docusaurus-search-local/src/client/theme/searchByWorker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface RemoteWorker {
1313
let remoteWorkerPromise: Promise<RemoteWorker> | undefined;
1414

1515
function getRemoteWorker() {
16-
if (!remoteWorkerPromise) {
16+
if (process.env.NODE_ENV === "production" && !remoteWorkerPromise) {
1717
remoteWorkerPromise = (async () => {
1818
const Remote = Comlink.wrap(
1919
new Worker(new URL("./worker.js", import.meta.url))

docusaurus-search-local/src/client/theme/worker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Comlink from "comlink";
22
import lunr from "lunr";
3-
import { searchIndexUrl, searchResultLimits } from "../utils/proxiedGenerated";
3+
import { searchIndexUrl, searchResultLimits, language } from "../utils/proxiedGeneratedConstants";
44
import { tokenize } from "../utils/tokenize";
55
import { smartQueries } from "../utils/smartQueries";
66
import {
@@ -13,7 +13,6 @@ import {
1313
} from "../../shared/interfaces";
1414
import { sortSearchResults } from "../utils/sortSearchResults";
1515
import { processTreeStatusOfSearchResults } from "../utils/processTreeStatusOfSearchResults";
16-
import { language } from "../utils/proxiedGenerated";
1716

1817
interface SerializedIndex {
1918
documents: SearchDocument[];

docusaurus-search-local/src/client/utils/SearchSourceFactory.spec.ts

Lines changed: 0 additions & 129 deletions
This file was deleted.

docusaurus-search-local/src/client/utils/SearchSourceFactory.ts

Lines changed: 0 additions & 84 deletions
This file was deleted.
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
export let language = ["en", "zh"];
2-
export let removeDefaultStopWordFilter = false;
3-
export let removeDefaultStemmer = false;
4-
export const searchIndexUrl = "search-index{dir}.json?_=abc";
5-
export const searchResultLimits = 8;
1+
export const removeDefaultStemmer = false;
62
export const searchResultContextMaxLength = 50;
73
export const explicitSearchResultPath = false;
84
export const docsPluginIdForPreferredVersion = undefined;
95
export const indexDocs = true;
10-
11-
export function __setLanguage(value: string[]): void {
12-
language = value;
13-
}
14-
15-
export function __setRemoveDefaultStopWordFilter(value: boolean): void {
16-
removeDefaultStopWordFilter = value;
17-
}
18-
19-
export function __setRemoveDefaultStemmer(value: boolean): void {
20-
removeDefaultStemmer = value;
21-
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export let language = ["en", "zh"];
2+
export let removeDefaultStopWordFilter = false;
3+
export const searchIndexUrl = "search-index{dir}.json?_=abc";
4+
export const searchResultLimits = 8;
5+
6+
export function __setLanguage(value: string[]): void {
7+
language = value;
8+
}
9+
10+
export function __setRemoveDefaultStopWordFilter(value: boolean): void {
11+
removeDefaultStopWordFilter = value;
12+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file is auto generated while building.
2+
export * from "@generated/@easyops-cn/docusaurus-search-local/default/generated-constants.js";

docusaurus-search-local/src/client/utils/smartQueries.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { smartQueries } from "./smartQueries";
33
import {
44
__setLanguage,
55
__setRemoveDefaultStopWordFilter,
6-
__setRemoveDefaultStemmer,
7-
} from "./proxiedGenerated";
6+
} from "./proxiedGeneratedConstants";
87
import { SmartQuery } from "../../shared/interfaces";
98

9+
jest.mock("./proxiedGeneratedConstants");
10+
1011
// eslint-disable-next-line @typescript-eslint/no-var-requires
1112
require("lunr-languages/lunr.stemmer.support")(lunr);
1213
// eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -16,8 +17,6 @@ require("lunr-languages/lunr.multi")(lunr);
1617

1718
(lunr as any).fake = {};
1819

19-
jest.mock("./proxiedGenerated");
20-
2120
const zhDictionary = ["研究生", "研究", "生命", "科学", "生命科学"];
2221

2322
interface TestQuery {
@@ -29,7 +28,6 @@ describe("smartQueries", () => {
2928
beforeEach(() => {
3029
__setLanguage(["en", "zh"]);
3130
__setRemoveDefaultStopWordFilter(false);
32-
__setRemoveDefaultStemmer(false);
3331
});
3432

3533
test.each<[string[], TestQuery[]]>([
@@ -238,7 +236,6 @@ describe("smartQueries with no stop words filter", () => {
238236
beforeEach(() => {
239237
__setLanguage(["en", "fake"]);
240238
__setRemoveDefaultStopWordFilter(true);
241-
__setRemoveDefaultStemmer(false);
242239
});
243240

244241
test.each<[string[], TestQuery[]]>([

docusaurus-search-local/src/client/utils/smartQueries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import lunr from "lunr";
22
import { SmartQuery, SmartTerm } from "../../shared/interfaces";
33
import { smartTerms } from "./smartTerms";
4-
import { language, removeDefaultStopWordFilter } from "./proxiedGenerated";
4+
import { language, removeDefaultStopWordFilter } from "./proxiedGeneratedConstants";
55

66
/**
77
* Get all possible queries for a list of tokens consists of words mixed English and Chinese,

docusaurus-search-local/src/declarations.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@ declare module "@easyops-cn/autocomplete.js" {
33
}
44

55
declare module "*/generated.js" {
6-
export const language: string[];
7-
export const removeDefaultStopWordFilter: string[];
86
export const removeDefaultStemmer: string[];
97
export class Mark {
108
constructor(root: HTMLElement);
119
mark: (terms: string[], options?: Record<string, unknown>) => void;
1210
unmark: () => void;
1311
}
14-
export const searchIndexUrl: string;
15-
export const searchResultLimits: number;
1612
export const searchResultContextMaxLength: number;
1713
export const explicitSearchResultPath: boolean;
1814
export const searchBarShortcut: boolean;
@@ -27,10 +23,16 @@ declare module "*/generated.js" {
2723
export const hideSearchBarWithNoSearchContext: boolean;
2824
export const useAllContextsWithNoSearchContext: boolean;
2925
export const forceIgnoreNoIndex: boolean;
26+
}
27+
28+
declare module "*/generated-constants.js" {
29+
export const removeDefaultStopWordFilter: string[];
30+
export const language: string[];
31+
export const searchIndexUrl: string;
32+
export const searchResultLimits: number;
3033
// These below are for mocking only.
3134
export const __setLanguage: (value: string[]) => void;
3235
export const __setRemoveDefaultStopWordFilter: (value: boolean) => void;
33-
export const __setRemoveDefaultStemmer: (value: boolean) => void;
3436
}
3537

3638
declare module "@docusaurus/Head";

0 commit comments

Comments
 (0)