Skip to content

Feature/windows support #36

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

Merged
merged 2 commits into from
Oct 28, 2017
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
21 changes: 21 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Test against the latest version of this Node.js version
environment:
nodejs_version: "8"

# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
# install modules
- npm install

# Post-install test scripts.
test_script:
# Output useful info for debugging.
- node --version
- npm --version
# run tests
- npm test

# Don't actually build.
build: off
4 changes: 2 additions & 2 deletions src/DeclarationIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Namespace } from './resources/Namespace';
import { Resource } from './resources/Resource';
import { isExportableDeclaration } from './type-guards/TypescriptHeroGuards';
import { TypescriptParser } from './TypescriptParser';
import { normalizeFilename, normalizePathUri } from './utilities/PathHelpers';
import { normalizeFilename, normalizePathUri, toPosix } from './utilities/PathHelpers';

/**
* Returns the name of the node folder. Is used as the library name for indexing.
Expand Down Expand Up @@ -308,7 +308,7 @@ export class DeclarationIndex {
break;
}
if (ex instanceof AllExport || ex instanceof NamedExport) {
const exported = '/' + relative(this.rootPath, normalize(join(resource.parsedPath.dir, ex.from)));
const exported = '/' + toPosix(relative(this.rootPath, normalize(join(resource.parsedPath.dir, ex.from))));
exportsResource = exported === resourcePath;
}
}
Expand Down
13 changes: 12 additions & 1 deletion src/utilities/PathHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,16 @@ export function normalizePathUri(uri: string): string {
* @returns {string}
*/
export function normalizeFilename(filepath: string): string {
return filepath.replace(/([.]d)?[.](t|j)sx?$/g, '');
return toPosix(filepath.replace(/([.]d)?[.](t|j)sx?$/g, ''));
}

/**
* On Windows, replaces all backslash delimeters with forward slashes.
* On other OSes, returns the path unmodified.
*/
export function toPosix(path: string): string {
if (platform() === 'win32') {
return path.replace(/\\/g, '/');
}
return path;
}
2 changes: 1 addition & 1 deletion test/declaration-index/DeclarationIndex.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mockFs = require('mock-fs');
import { join, resolve } from 'path';
import { join, resolve } from '../testUtilities';

import { DeclarationIndex } from '../../src/DeclarationIndex';
import { ClassDeclaration } from '../../src/declarations';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join, resolve } from 'path';
import { join, resolve } from '../../../testUtilities';

import { DeclarationIndex } from '../../../../src/DeclarationIndex';
import { TypescriptParser } from '../../../../src/TypescriptParser';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FileChanges } from '../../../../src';
import { join, resolve } from 'path';
import { join, resolve } from '../../../testUtilities';

import { DeclarationIndex } from '../../../../src/DeclarationIndex';
import { TypescriptParser } from '../../../../src/TypescriptParser';
Expand Down
13 changes: 12 additions & 1 deletion test/testUtilities.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { resolve } from 'path';
import * as Path from 'path';
import { toPosix } from '../src/utilities/PathHelpers';

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

// Like path.resolve, but always replaces backslashes with forward slashes on Windows.
export function resolve(...paths: string[]): string {
return toPosix(Path.resolve(...paths));
}

// Like path.join, but always replaces backslashes with forward slashes on Windows.
export function join(...paths: string[]): string {
return toPosix(Path.join(...paths));
}

export const rootPath = resolve(__dirname, '_workspace');