Skip to content

Commit 0ea36f1

Browse files
cspotcodebuehler
authored andcommitted
feat: windows support (#36)
Supporting the correct slashings in the pathes.
1 parent 43ecda4 commit 0ea36f1

File tree

7 files changed

+50
-7
lines changed

7 files changed

+50
-7
lines changed

.appveyor.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Test against the latest version of this Node.js version
2+
environment:
3+
nodejs_version: "8"
4+
5+
# Install scripts. (runs after repo cloning)
6+
install:
7+
# Get the latest stable version of Node.js or io.js
8+
- ps: Install-Product node $env:nodejs_version
9+
# install modules
10+
- npm install
11+
12+
# Post-install test scripts.
13+
test_script:
14+
# Output useful info for debugging.
15+
- node --version
16+
- npm --version
17+
# run tests
18+
- npm test
19+
20+
# Don't actually build.
21+
build: off

src/DeclarationIndex.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Namespace } from './resources/Namespace';
1212
import { Resource } from './resources/Resource';
1313
import { isExportableDeclaration } from './type-guards/TypescriptHeroGuards';
1414
import { TypescriptParser } from './TypescriptParser';
15-
import { normalizeFilename, normalizePathUri } from './utilities/PathHelpers';
15+
import { normalizeFilename, normalizePathUri, toPosix } from './utilities/PathHelpers';
1616

1717
/**
1818
* Returns the name of the node folder. Is used as the library name for indexing.
@@ -308,7 +308,7 @@ export class DeclarationIndex {
308308
break;
309309
}
310310
if (ex instanceof AllExport || ex instanceof NamedExport) {
311-
const exported = '/' + relative(this.rootPath, normalize(join(resource.parsedPath.dir, ex.from)));
311+
const exported = '/' + toPosix(relative(this.rootPath, normalize(join(resource.parsedPath.dir, ex.from))));
312312
exportsResource = exported === resourcePath;
313313
}
314314
}

src/utilities/PathHelpers.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,16 @@ export function normalizePathUri(uri: string): string {
2525
* @returns {string}
2626
*/
2727
export function normalizeFilename(filepath: string): string {
28-
return filepath.replace(/([.]d)?[.](t|j)sx?$/g, '');
28+
return toPosix(filepath.replace(/([.]d)?[.](t|j)sx?$/g, ''));
29+
}
30+
31+
/**
32+
* On Windows, replaces all backslash delimeters with forward slashes.
33+
* On other OSes, returns the path unmodified.
34+
*/
35+
export function toPosix(path: string): string {
36+
if (platform() === 'win32') {
37+
return path.replace(/\\/g, '/');
38+
}
39+
return path;
2940
}

test/declaration-index/DeclarationIndex.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import mockFs = require('mock-fs');
2-
import { join, resolve } from 'path';
2+
import { join, resolve } from '../testUtilities';
33

44
import { DeclarationIndex } from '../../src/DeclarationIndex';
55
import { ClassDeclaration } from '../../src/declarations';

test/declaration-index/specific-cases/body-parser/DeclarationIndex.body-parser.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join, resolve } from 'path';
1+
import { join, resolve } from '../../../testUtilities';
22

33
import { DeclarationIndex } from '../../../../src/DeclarationIndex';
44
import { TypescriptParser } from '../../../../src/TypescriptParser';

test/declaration-index/specific-cases/reindex-with-global-module/DeclarationIndex.reindex-with-global-module-export.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FileChanges } from '../../../../src';
2-
import { join, resolve } from 'path';
2+
import { join, resolve } from '../../../testUtilities';
33

44
import { DeclarationIndex } from '../../../../src/DeclarationIndex';
55
import { TypescriptParser } from '../../../../src/TypescriptParser';

test/testUtilities.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
import { resolve } from 'path';
1+
import * as Path from 'path';
2+
import { toPosix } from '../src/utilities/PathHelpers';
23

34
export function getWorkspaceFile(pathFromWorkspace: string): string {
45
return resolve(__dirname, '_workspace', pathFromWorkspace);
56
}
67

8+
// Like path.resolve, but always replaces backslashes with forward slashes on Windows.
9+
export function resolve(...paths: string[]): string {
10+
return toPosix(Path.resolve(...paths));
11+
}
12+
13+
// Like path.join, but always replaces backslashes with forward slashes on Windows.
14+
export function join(...paths: string[]): string {
15+
return toPosix(Path.join(...paths));
16+
}
17+
718
export const rootPath = resolve(__dirname, '_workspace');

0 commit comments

Comments
 (0)