Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(harper.js): config now persists across calls
Elijah Potterd49cbe8006d6
diff --git a/packages/.prettierignore b/packages/.prettierignoreindex 01439aeea..b92d7fa41 100644--- a/packages/.prettierignore+++ b/packages/.prettierignore@@ -14,3 +14,4 @@ main.jspnpm-lock.yamlpackage-lock.jsonyarn.lock+distdiff --git a/packages/harper.js/src/Linter.test.ts b/packages/harper.js/src/Linter.test.tsindex dc17f90f5..595e1f1d1 100644--- a/packages/harper.js/src/Linter.test.ts+++ b/packages/harper.js/src/Linter.test.ts@@ -77,6 +77,23 @@ for (const [linterName, Linter] of Object.entries(linters)) {const lintConfig = await linter.getLintConfig();expect(lintConfig).toHaveProperty('repeated_words');});++ test(`${linterName} can both get and set its configuration`, async () => {+ const linter = new Linter();++ let lintConfig = await linter.getLintConfig();++ for (const key of Object.keys(lintConfig)) {+ lintConfig[key] = true;+ }++ await linter.setLintConfig(lintConfig);+ lintConfig = await linter.getLintConfig();++ for (const key of Object.keys(lintConfig)) {+ expect(lintConfig[key]).toBe(true);+ }+ });}test('Linters have the same config format', async () => {diff --git a/packages/harper.js/src/LocalLinter.ts b/packages/harper.js/src/LocalLinter.tsindex 36b4ca097..be8ff879c 100644--- a/packages/harper.js/src/LocalLinter.ts+++ b/packages/harper.js/src/LocalLinter.ts@@ -9,9 +9,11 @@ export default class LocalLinter implements Linter {/** Initialize the WebAssembly and construct the inner Linter. */private async initialize(): Promise<void> {- const wasm = await loadWasm();- wasm.setup();- this.inner = wasm.Linter.new();+ if (!this.inner) {+ const wasm = await loadWasm();+ wasm.setup();+ this.inner = wasm.Linter.new();+ }}async setup(): Promise<void> {diff --git a/packages/harper.js/src/loadWasm.ts b/packages/harper.js/src/loadWasm.tsindex a6bfe56e3..2459bb351 100644--- a/packages/harper.js/src/loadWasm.ts+++ b/packages/harper.js/src/loadWasm.ts@@ -20,7 +20,7 @@ export function setWasmUri(uri: string) {export default async function loadWasm() {const wasm = await import('wasm');// @ts-ignore- await wasm.default(getWasmUri());+ await wasm.default({ module_or_path: getWasmUri() });return wasm;}