Skip to content

Commit 7e58afa

Browse files
committed
Bower_Components fix
1 parent 2fc634f commit 7e58afa

File tree

2 files changed

+60
-8
lines changed

2 files changed

+60
-8
lines changed

src/harness/unittests/typingsInstaller.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,53 @@ namespace ts.projectSystem {
692692
checkProjectActualFiles(p, [app.path, jqueryDTS.path]);
693693
});
694694

695-
it("configured projects discover from bower.josn", () => {
695+
it("configured projects discover from bower_components", () => {
696+
const app = {
697+
path: "/app.js",
698+
content: ""
699+
};
700+
const jsconfig = {
701+
path: "/jsconfig.json",
702+
content: JSON.stringify({})
703+
};
704+
const jquery = {
705+
path: "/bower_components/jquery/index.js",
706+
content: ""
707+
};
708+
const jqueryPackage = {
709+
path: "/bower_components/jquery/package.json",
710+
content: JSON.stringify({ name: "jquery" })
711+
};
712+
const jqueryDTS = {
713+
path: "/tmp/node_modules/@types/jquery/index.d.ts",
714+
content: ""
715+
};
716+
const host = createServerHost([app, jsconfig, jquery, jqueryPackage]);
717+
const installer = new (class extends Installer {
718+
constructor() {
719+
super(host, { globalTypingsCacheLocation: "/tmp", typesRegistry: createTypesRegistry("jquery") });
720+
}
721+
installWorker(_requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
722+
const installedTypings = ["@types/jquery"];
723+
const typingFiles = [jqueryDTS];
724+
executeCommand(this, host, installedTypings, typingFiles, cb);
725+
}
726+
})();
727+
728+
const projectService = createProjectService(host, { useSingleInferredProject: true, typingsInstaller: installer });
729+
projectService.openClientFile(app.path);
730+
731+
checkNumberOfProjects(projectService, { configuredProjects: 1 });
732+
const p = projectService.configuredProjects[0];
733+
checkProjectActualFiles(p, [app.path]);
734+
735+
installer.installAll(/*expectedCount*/ 1);
736+
737+
checkNumberOfProjects(projectService, { configuredProjects: 1 });
738+
checkProjectActualFiles(p, [app.path, jqueryDTS.path]);
739+
});
740+
741+
it("configured projects discover from bower.json", () => {
696742
const app = {
697743
path: "/app.js",
698744
content: ""
@@ -975,7 +1021,7 @@ namespace ts.projectSystem {
9751021
}
9761022
});
9771023

978-
it("should use cached locaitons", () => {
1024+
it("should use cached locations", () => {
9791025
const f = {
9801026
path: "/a/b/app.js",
9811027
content: ""

src/services/jsTyping.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@ namespace ts.JsTyping {
9999
const bowerJsonPath = combinePaths(searchDir, "bower.json");
100100
getTypingNamesFromJson(bowerJsonPath, filesToWatch);
101101

102+
const bowerComponentsPath = combinePaths(searchDir, "bower_components");
103+
getTypingNamesFromPackagesFolder(bowerComponentsPath);
104+
102105
const nodeModulesPath = combinePaths(searchDir, "node_modules");
103-
getTypingNamesFromNodeModuleFolder(nodeModulesPath);
106+
getTypingNamesFromPackagesFolder(nodeModulesPath);
104107
}
105108
getTypingNamesFromSourceFileNames(fileNames);
106109

@@ -199,17 +202,20 @@ namespace ts.JsTyping {
199202
}
200203

201204
/**
202-
* Infer typing names from node_module folder
203-
* @param nodeModulesPath is the path to the "node_modules" folder
205+
* Infer typing names from packages folder (ex: node_module, bower_components)
206+
* @param packagesFolderPath is the path to the packages folder
207+
204208
*/
205-
function getTypingNamesFromNodeModuleFolder(nodeModulesPath: string) {
209+
function getTypingNamesFromPackagesFolder(packagesFolderPath: string) {
210+
filesToWatch.push(packagesFolderPath);
211+
206212
// Todo: add support for ModuleResolutionHost too
207-
if (!host.directoryExists(nodeModulesPath)) {
213+
if (!host.directoryExists(packagesFolderPath)) {
208214
return;
209215
}
210216

211217
const typingNames: string[] = [];
212-
const fileNames = host.readDirectory(nodeModulesPath, [".json"], /*excludes*/ undefined, /*includes*/ undefined, /*depth*/ 2);
218+
const fileNames = host.readDirectory(packagesFolderPath, [".json"], /*excludes*/ undefined, /*includes*/ undefined, /*depth*/ 2);
213219
for (const fileName of fileNames) {
214220
const normalizedFileName = normalizePath(fileName);
215221
if (getBaseFileName(normalizedFileName) !== "package.json") {

0 commit comments

Comments
 (0)