diff --git a/lib/index.js b/lib/index.js index 8cabbe0..91de932 100644 --- a/lib/index.js +++ b/lib/index.js @@ -243,9 +243,9 @@ const log = (args, shell) => { let lines = args.map(item => completionItem(item, shell)).map(item => { const { name: rawName, description: rawDescription } = item; - const name = shell === 'zsh' ? rawName?.replace(/:/g, '\\:') : rawName; + const name = shell === 'zsh' ? rawName?.replaceAll(':', '\\:') : rawName; const description = - shell === 'zsh' ? rawDescription?.replace(/:/g, '\\:') : rawDescription; + shell === 'zsh' ? rawDescription?.replaceAll(':', '\\:') : rawDescription; let str = name; if (shell === 'zsh' && description) { diff --git a/lib/installer.js b/lib/installer.js index 1c9ae5e..65fb4e7 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -247,10 +247,10 @@ const getCompletionScript = async ({ name, completer, shell }) => { const templatePath = scriptFromShell(shell); const templateContent = await readFile(templatePath, 'utf8'); const scriptContent = templateContent - .replace(/\{pkgname\}/g, name) - .replace(/{completer}/g, completer) + .replaceAll('{pkgname}', name) + .replaceAll('{completer}', completer) // on Bash on windows, we need to make sure to remove any \r - .replace(/\r?\n/g, '\n'); + .replaceAll(/\r?\n/g, '\n'); return scriptContent }; diff --git a/test/getCompletionScript.js b/test/getCompletionScript.js index c026b54..2691410 100644 --- a/test/getCompletionScript.js +++ b/test/getCompletionScript.js @@ -12,9 +12,9 @@ describe('getCompletionScript gets the right completion script for', () => { shell }); const expected = fs.readFileSync(require.resolve(`../lib/templates/completion.${COMPLETION_FILE_EXT[shell]}`), 'utf8') - .replace(/\{pkgname\}/g, 'foo') - .replace(/{completer}/g, 'foo-complete') - .replace(/\r?\n/g, '\n'); + .replaceAll('{pkgname}', 'foo') + .replaceAll('{completer}', 'foo-complete') + .replaceAll(/\r?\n/g, '\n'); assert.equal(received, expected); }); }