Skip to content

Commit

Permalink
fix: escape slash on windows (#24)
Browse files Browse the repository at this point in the history
* ci: add windows and macos to the matrix

* ci: remove SHELL

* fix: escape slash on windows

Fixes pnpm/pnpm#5420

* ci: reduce matrix size

* test: fix
  • Loading branch information
KSXGitHub authored Feb 2, 2024
1 parent accadf0 commit e2e1973
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
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

0 comments on commit e2e1973

Please sign in to comment.