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

Package declaration file for commonjs packages #3159

Closed
wants to merge 13 commits into from
Closed
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
31 changes: 31 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,37 @@ module ts {
type: "boolean",
description: Diagnostics.Generates_corresponding_d_ts_file,
},
{
name: "packageName",
type: "string",
experimental: true,
description: Diagnostics.Specifies_the_name_of_the_package,
paramType: Diagnostics.NAME
},
{
name: "packageMain",
type: "string",
isFilePath: true,
experimental: true,
description: Diagnostics.Specifies_the_main_module_for_the_package,
paramType: Diagnostics.FILE
},
{
name: "packageDeclaration",
type: "string",
isFilePath: true,
experimental: true,
description: Diagnostics.Specifies_the_output_path_for_the_package_declaration,
paramType: Diagnostics.FILE
},
{
name: "packageDir",
type: "string",
isFilePath: true,
experimental: true,
description: Diagnostics.Specifies_the_root_directory_of_the_package,
paramType: Diagnostics.DIRECTORY
},
{
name: "diagnostics",
type: "boolean",
Expand Down
38 changes: 38 additions & 0 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ module ts {
EqualTo = 0,
GreaterThan = 1
}

export const enum StringComparison {
Ordinal = 0,
IgnoreCase = 1,
CurrentCultureIgnoreCase = 2
}

export interface StringSet extends Map<any> { }

Expand Down Expand Up @@ -485,6 +491,38 @@ module ts {

return normalized;
}

export function compareStrings(x: string, y: string, comparison?: StringComparison): Comparison {
if (x === y) return Comparison.EqualTo;
if (x === undefined) return Comparison.LessThan;
if (y === undefined) return Comparison.GreaterThan;
if (comparison === StringComparison.CurrentCultureIgnoreCase) {
x = x.toLocaleLowerCase();
y = y.toLocaleLowerCase();
}
else if (comparison === StringComparison.IgnoreCase) {
x = x.toLowerCase();
y = y.toLowerCase();
}

return x === y ? Comparison.EqualTo : x < y ? Comparison.LessThan : Comparison.GreaterThan;
}

export function comparePaths(path1: string, path2: string, currentDirectory: string, ignoreCase?: boolean): Comparison {
let pathComponents1 = getNormalizedPathComponents(path1, currentDirectory);
let pathComponents2 = getNormalizedPathComponents(path2, currentDirectory);
let sharedLength = Math.min(pathComponents1.length, pathComponents2.length);
for (let i = 0; i < sharedLength; i++) {
let component1 = pathComponents1[i];
let component2 = pathComponents2[i];
let result = compareStrings(component1, component2, ignoreCase ? StringComparison.IgnoreCase : StringComparison.Ordinal);
if (result !== Comparison.EqualTo) {
return result;
}
}

return compareValues(pathComponents1.length, pathComponents2.length);
}

export function normalizePath(path: string): string {
path = normalizeSlashes(path);
Expand Down
Loading