Skip to content

Commit 6f69d1b

Browse files
author
Christoph Lühr
committed
fixed Windows issues
1 parent 96a2946 commit 6f69d1b

2 files changed

Lines changed: 41 additions & 9 deletions

File tree

src/update-ts-references.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,11 @@ const getReferencesFromDependencies = (
183183
.sort((refA, refB) => (refA.path > refB.path ? 1 : -1));
184184
};
185185

186-
const ensureLeadingDotSlash=(p)=> {
187-
if (!p || path.isAbsolute(p) || p.startsWith('./') || p.startsWith('../')) {
186+
const ensureLeadingDotSlash = (p) => {
187+
if (p == null || path.isAbsolute(p) || p.startsWith('.' + path.sep) || p.startsWith('..' + path.sep)) {
188188
return p;
189189
}
190-
191-
if (p.length === 0) {
192-
return '.'
193-
}
194-
195-
return './' + p;
190+
return p.length === 0 ? '.' : '.' + path.sep + p;
196191
}
197192

198193
const ensurePosixPathStyle = (reference) => ({
@@ -454,4 +449,4 @@ const execute = async ({
454449
return changesCount;
455450
};
456451

457-
module.exports = { execute, defaultOptions };
452+
module.exports = { execute, defaultOptions, ensureLeadingDotSlash };
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const path = require('path');
2+
const { ensureLeadingDotSlash } = require('../src/update-ts-references');
3+
4+
test('returns null as-is', () => {
5+
expect(ensureLeadingDotSlash(null)).toBe(null);
6+
});
7+
8+
test('returns undefined as-is', () => {
9+
expect(ensureLeadingDotSlash(undefined)).toBe(undefined);
10+
});
11+
12+
test('returns . for empty string', () => {
13+
expect(ensureLeadingDotSlash('')).toBe('.');
14+
});
15+
16+
test('returns absolute path as-is', () => {
17+
const p = path.resolve('/some/absolute/path');
18+
expect(ensureLeadingDotSlash(p)).toBe(p);
19+
});
20+
21+
test('returns path already starting with .' + path.sep + ' as-is', () => {
22+
const p = '.' + path.sep + 'foo';
23+
expect(ensureLeadingDotSlash(p)).toBe(p);
24+
});
25+
26+
test('returns path already starting with ..' + path.sep + ' as-is', () => {
27+
const p = '..' + path.sep + 'foo';
28+
expect(ensureLeadingDotSlash(p)).toBe(p);
29+
});
30+
31+
test('prepends .' + path.sep + ' to a plain relative path', () => {
32+
expect(ensureLeadingDotSlash('foo')).toBe('.' + path.sep + 'foo');
33+
});
34+
35+
test('prepends .' + path.sep + ' to a nested relative path', () => {
36+
expect(ensureLeadingDotSlash('foo' + path.sep + 'bar')).toBe('.' + path.sep + 'foo' + path.sep + 'bar');
37+
});

0 commit comments

Comments
 (0)