-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Type acquisition support for bower_components directory #14100
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,8 +99,11 @@ namespace ts.JsTyping { | |
const bowerJsonPath = combinePaths(searchDir, "bower.json"); | ||
getTypingNamesFromJson(bowerJsonPath, filesToWatch); | ||
|
||
const bowerComponentsPath = combinePaths(searchDir, "bower_components"); | ||
getTypingNamesFromPackagesFolder(bowerComponentsPath); | ||
|
||
const nodeModulesPath = combinePaths(searchDir, "node_modules"); | ||
getTypingNamesFromNodeModuleFolder(nodeModulesPath); | ||
getTypingNamesFromPackagesFolder(nodeModulesPath); | ||
} | ||
getTypingNamesFromSourceFileNames(fileNames); | ||
|
||
|
@@ -199,20 +202,24 @@ namespace ts.JsTyping { | |
} | ||
|
||
/** | ||
* Infer typing names from node_module folder | ||
* @param nodeModulesPath is the path to the "node_modules" folder | ||
* Infer typing names from packages folder (ex: node_module, bower_components) | ||
* @param packagesFolderPath is the path to the packages folder | ||
|
||
*/ | ||
function getTypingNamesFromNodeModuleFolder(nodeModulesPath: string) { | ||
function getTypingNamesFromPackagesFolder(packagesFolderPath: string) { | ||
filesToWatch.push(packagesFolderPath); | ||
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. should we watch the path after confirming it exists? 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. I kept this before the path existence check as we want to watch these paths even if they haven't been created yet. (ex: User creates an empty ASP.NET project, adds a js file then uses Manage Bower Packages to install jQuery.) |
||
|
||
// Todo: add support for ModuleResolutionHost too | ||
if (!host.directoryExists(nodeModulesPath)) { | ||
if (!host.directoryExists(packagesFolderPath)) { | ||
return; | ||
} | ||
|
||
const typingNames: string[] = []; | ||
const fileNames = host.readDirectory(nodeModulesPath, [".json"], /*excludes*/ undefined, /*includes*/ undefined, /*depth*/ 2); | ||
const fileNames = host.readDirectory(packagesFolderPath, [".json"], /*excludes*/ undefined, /*includes*/ undefined, /*depth*/ 2); | ||
for (const fileName of fileNames) { | ||
const normalizedFileName = normalizePath(fileName); | ||
if (getBaseFileName(normalizedFileName) !== "package.json") { | ||
const baseFileName = getBaseFileName(normalizedFileName); | ||
if (baseFileName !== "package.json" && baseFileName !== "bower.json") { | ||
continue; | ||
} | ||
const result = readConfigFile(normalizedFileName, (path: string) => host.readFile(path)); | ||
|
@@ -224,7 +231,7 @@ namespace ts.JsTyping { | |
// npm 3's package.json contains a "_requiredBy" field | ||
// we should include all the top level module names for npm 2, and only module names whose | ||
// "_requiredBy" field starts with "#" or equals "/" for npm 3. | ||
if (packageJson._requiredBy && | ||
if (baseFileName === "package.json" && packageJson._requiredBy && | ||
filter(packageJson._requiredBy, (r: string) => r[0] === "#" || r === "/").length === 0) { | ||
continue; | ||
} | ||
|
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.
Can you also check what paths are being watched?
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.
Good idea - will add this to the test