Skip to content

Commit

Permalink
fix: use require.resolve for generated js, fixes #459
Browse files Browse the repository at this point in the history
  • Loading branch information
weareoutman committed Oct 8, 2024
1 parent a37e86f commit 4728b28
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions docusaurus-search-local/src/server/utils/generate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ describe("generate", () => {
expect.stringMatching(
/^require\(".+\/|\\lunr-languages\/|\\lunr\.stemmer\.support\.js"\)\(lunr\);$/
),
'require("@easyops-cn/docusaurus-search-local/dist/client/shared/lunrLanguageZh").lunrLanguageZh(lunr);',
expect.stringMatching(
/^require\(".+\/lunrLanguageZh\.js"\)\.lunrLanguageZh\(lunr\);$/
),
'export const language = ["zh"];',
"export const removeDefaultStopWordFilter = false;",
"export const removeDefaultStemmer = false;",
Expand Down Expand Up @@ -129,7 +131,9 @@ describe("generate", () => {
expect.stringMatching(
/^require\(".+\/|\\lunr-languages\/|\\lunr\.stemmer\.support\.js"\)\(lunr\);$/
),
'require("@easyops-cn/docusaurus-search-local/dist/client/shared/lunrLanguageZh").lunrLanguageZh(lunr);',
expect.stringMatching(
/^require\(".+\/lunrLanguageZh\.js"\)\.lunrLanguageZh\(lunr\);$/
),
expect.stringMatching(
/^require\(".+\/|\\lunr-languages\/|\\lunr\.multi\.js"\)\(lunr\);$/
),
Expand Down Expand Up @@ -161,7 +165,9 @@ describe("generate", () => {
expect.stringMatching(
/^require\(".+\/|\\lunr-languages\/|\\lunr\.es\.js"\)\(lunr\);$/
),
'require("@easyops-cn/docusaurus-search-local/dist/client/shared/lunrLanguageZh").lunrLanguageZh(lunr);',
expect.stringMatching(
/^require\(".+\/lunrLanguageZh\.js"\)\.lunrLanguageZh\(lunr\);$/
),
expect.stringMatching(
/^require\(".+\/|\\lunr-languages\/|\\lunr\.multi\.js"\)\(lunr\);$/
),
Expand Down
6 changes: 5 additions & 1 deletion docusaurus-search-local/src/server/utils/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export function generate(config: ProcessedPluginOptions, dir: string): string {
}
if (language.includes("zh")) {
contents.push(
'require("@easyops-cn/docusaurus-search-local/dist/client/shared/lunrLanguageZh").lunrLanguageZh(lunr);'
`require(${JSON.stringify(
require.resolve(
"@easyops-cn/docusaurus-search-local/dist/client/shared/lunrLanguageZh"
)
)}).lunrLanguageZh(lunr);`
);
}
if (language.length > 1) {
Expand Down

0 comments on commit 4728b28

Please sign in to comment.