-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add quickfix and refactoring to install @types packages #19130
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
76b7be8
Add quickfix and refactoring to install @types packages
458a6de
Move `validatePackageName` to `jsTyping.ts`
ee9f892
Remove combinePaths overloads
7c22ad6
Respond to code review
b2d6b88
Update api baselines
8a273ed
Use native PromiseConstructor
d370ad3
Merge branch 'master' into install_types_fix_2
f6b0b01
Merge branch 'master' into install_types_fix_2
52cfe9e
Return false instead of undefined
dcb903c
Remove getProjectRootPath
ce79a84
Update api
b798d77
Merge branch 'master' into install_types_fix_2
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,7 +124,11 @@ namespace ts { | |
} | ||
} | ||
|
||
export function getEffectiveTypeRoots(options: CompilerOptions, host: { directoryExists?: (directoryName: string) => boolean, getCurrentDirectory?: () => string }): string[] | undefined { | ||
export interface GetEffectiveTypeRootsHost { | ||
directoryExists?: (directoryName: string) => boolean; | ||
getCurrentDirectory?: () => string; | ||
} | ||
export function getEffectiveTypeRoots(options: CompilerOptions, host: GetEffectiveTypeRootsHost): string[] | undefined { | ||
if (options.typeRoots) { | ||
return options.typeRoots; | ||
} | ||
|
@@ -985,7 +989,8 @@ namespace ts { | |
return withPackageId(packageId, pathAndExtension); | ||
} | ||
|
||
function getPackageName(moduleName: string): { packageName: string, rest: string } { | ||
/* @internal */ | ||
export function getPackageName(moduleName: string): { packageName: string, rest: string } { | ||
let idx = moduleName.indexOf(directorySeparator); | ||
if (moduleName[0] === "@") { | ||
idx = moduleName.indexOf(directorySeparator, idx + 1); | ||
|
@@ -1153,4 +1158,68 @@ namespace ts { | |
function toSearchResult<T>(value: T | undefined): SearchResult<T> { | ||
return value !== undefined ? { value } : undefined; | ||
} | ||
|
||
/* @internal */ | ||
export const enum PackageNameValidationResult { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These types shouldnt be in compiler .. They should be in Language service since they arent needed by compiler. |
||
Ok, | ||
ScopedPackagesNotSupported, | ||
EmptyName, | ||
NameTooLong, | ||
NameStartsWithDot, | ||
NameStartsWithUnderscore, | ||
NameContainsNonURISafeCharacters | ||
} | ||
|
||
const MaxPackageNameLength = 214; | ||
|
||
/** | ||
* Validates package name using rules defined at https://docs.npmjs.com/files/package.json | ||
*/ | ||
/* @internal */ | ||
export function validatePackageName(packageName: string): PackageNameValidationResult { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These functions too.. |
||
if (!packageName) { | ||
return PackageNameValidationResult.EmptyName; | ||
} | ||
if (packageName.length > MaxPackageNameLength) { | ||
return PackageNameValidationResult.NameTooLong; | ||
} | ||
if (packageName.charCodeAt(0) === CharacterCodes.dot) { | ||
return PackageNameValidationResult.NameStartsWithDot; | ||
} | ||
if (packageName.charCodeAt(0) === CharacterCodes._) { | ||
return PackageNameValidationResult.NameStartsWithUnderscore; | ||
} | ||
// check if name is scope package like: starts with @ and has one '/' in the middle | ||
// scoped packages are not currently supported | ||
// TODO: when support will be added we'll need to split and check both scope and package name | ||
if (/^@[^/]+\/[^/]+$/.test(packageName)) { | ||
return PackageNameValidationResult.ScopedPackagesNotSupported; | ||
} | ||
if (encodeURIComponent(packageName) !== packageName) { | ||
return PackageNameValidationResult.NameContainsNonURISafeCharacters; | ||
} | ||
return PackageNameValidationResult.Ok; | ||
} | ||
|
||
/* @internal */ | ||
export function renderPackageNameValidationFailure(result: PackageNameValidationResult, typing: string): string { | ||
switch (result) { | ||
case PackageNameValidationResult.EmptyName: | ||
return `Package name '${typing}' cannot be empty`; | ||
case PackageNameValidationResult.NameTooLong: | ||
return `Package name '${typing}' should be less than ${MaxPackageNameLength} characters`; | ||
case PackageNameValidationResult.NameStartsWithDot: | ||
return `Package name '${typing}' cannot start with '.'`; | ||
case PackageNameValidationResult.NameStartsWithUnderscore: | ||
return `Package name '${typing}' cannot start with '_'`; | ||
case PackageNameValidationResult.ScopedPackagesNotSupported: | ||
return `Package '${typing}' is scoped and currently is not supported`; | ||
case PackageNameValidationResult.NameContainsNonURISafeCharacters: | ||
return `Package name '${typing}' contains non URI safe characters`; | ||
case PackageNameValidationResult.Ok: | ||
throw Debug.fail(); // Shouldn't have called this. | ||
default: | ||
Debug.assertNever(result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not correct.. Path handle case sensitivity.. since path2 doesnt have Path as type you would never be sure if combined paths would be Path or just string (that needs to handle case sensitivity)