Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: escape slash on windows #24

Merged
merged 5 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ jobs:
strategy:
fail-fast: false
matrix:
node:
- '18'
- '20'
- '21'
platform:
- ubuntu-latest
include:
- node: '18'
platform: ubuntu-latest
- node: '20'
platform: ubuntu-latest
- node: '21'
platform: ubuntu-latest
- node: '20'
platform: windows-latest
- node: '20'
platform: macos-latest

name: '${{matrix.platform}} / Node.js ${{ matrix.node }}'
runs-on: ${{matrix.platform}}
Expand All @@ -31,7 +36,7 @@ jobs:
- name: pnpm install
run: pnpm install
- name: run tests
run: SHELL=/bin/bash pnpm test
run: pnpm test

typecheck:
name: Type Check
Expand Down
4 changes: 4 additions & 0 deletions lib/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const locationFromShell = shell => {
* @param {SupportedShell} shell - Shell to base the check on
*/
const sourceLineForShell = (scriptname, shell) => {
// Windows naturally uses `\` as path separator, which would be misinterpreted by the
// shell interpreters.
scriptname = scriptname.replaceAll('\\', '/');

if (shell === 'fish') {
return `[ -f ${scriptname} ]; and . ${scriptname}; or true`;
}
Expand Down
4 changes: 2 additions & 2 deletions test/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('installer', () => {
assert.ok(/uninstall by removing these lines/.test(filecontent));
assert.ok(
filecontent.match(
`. ${path.join(COMPLETION_DIR, 'bash/__tabtab.bash')}`
`. ${path.join(COMPLETION_DIR, 'bash/__tabtab.bash').replaceAll('\\', '/')}`
)
);
})
Expand All @@ -100,7 +100,7 @@ describe('installer', () => {
.then(filecontent => {
assert.ok(/tabtab source for foo/.test(filecontent));
assert.ok(
filecontent.match(`. ${path.join(COMPLETION_DIR, 'bash/foo.bash')}`)
filecontent.match(`. ${path.join(COMPLETION_DIR, 'bash/foo.bash').replaceAll('\\', '/')}`)
);
}));

Expand Down
2 changes: 1 addition & 1 deletion test/tabtab-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('tabtab.install()', () => {
);
assert.ok(/tabtab source for foo/.test(filecontent));
assert.ok(
filecontent.match(`. ${path.join(COMPLETION_DIR, 'bash/foo.bash')}`)
filecontent.match(`. ${path.join(COMPLETION_DIR, 'bash/foo.bash').replaceAll('\\', '/')}`)
);
});

Expand Down
Loading