Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3263fde

Browse filesBrowse files
authored
Merge pull request microsoft#11776 from Microsoft/vladima/port-11764
Ports PR microsoft#11764 into master
2 parents 46f7a0f + a477d1f commit 3263fde
Copy full SHA for 3263fde

3 files changed

+63-16Lines changed: 63 additions & 16 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/harness/unittests/typingsInstaller.ts‎

Copy file name to clipboardExpand all lines: src/harness/unittests/typingsInstaller.ts
+56-13Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ namespace ts.projectSystem {
569569
}
570570
executeRequest(requestKind: TI.RequestKind, _requestId: number, args: string[], _cwd: string, cb: TI.RequestCompletedAction): void {
571571
if (requestKind === TI.NpmInstallRequest) {
572-
let typingFiles: (FileOrFolder & { typings: string}) [] = [];
572+
let typingFiles: (FileOrFolder & { typings: string })[] = [];
573573
if (args.indexOf("@types/commander") >= 0) {
574574
typingFiles = [commander, jquery, lodash, cordova];
575575
}
@@ -591,7 +591,7 @@ namespace ts.projectSystem {
591591
projectFileName: projectFileName1,
592592
options: { allowJS: true, moduleResolution: ModuleResolutionKind.NodeJs },
593593
rootFiles: [toExternalFile(lodashJs.path), toExternalFile(commanderJs.path), toExternalFile(file3.path)],
594-
typingOptions: { include: ["jquery", "cordova" ] }
594+
typingOptions: { include: ["jquery", "cordova"] }
595595
});
596596

597597
installer.checkPendingCommands([TI.NpmViewRequest, TI.NpmViewRequest, TI.NpmViewRequest]);
@@ -626,7 +626,7 @@ namespace ts.projectSystem {
626626
installer.executePendingCommands();
627627

628628
checkProjectActualFiles(p1, [lodashJs.path, commanderJs.path, file3.path, commander.path, jquery.path, lodash.path, cordova.path]);
629-
checkProjectActualFiles(p2, [file3.path, grunt.path, gulp.path ]);
629+
checkProjectActualFiles(p2, [file3.path, grunt.path, gulp.path]);
630630
});
631631

632632
it("configured projects discover from node_modules", () => {
@@ -687,10 +687,10 @@ namespace ts.projectSystem {
687687
const bowerJson = {
688688
path: "/bower.json",
689689
content: JSON.stringify({
690-
"dependencies": {
691-
"jquery": "^3.1.0"
692-
}
693-
})
690+
"dependencies": {
691+
"jquery": "^3.1.0"
692+
}
693+
})
694694
};
695695
const jqueryDTS = {
696696
path: "/tmp/node_modules/@types/jquery/index.d.ts",
@@ -720,34 +720,77 @@ namespace ts.projectSystem {
720720
checkNumberOfProjects(projectService, { configuredProjects: 1 });
721721
checkProjectActualFiles(p, [app.path, jqueryDTS.path]);
722722
});
723+
724+
it("Malformed package.json should be watched", () => {
725+
const f = {
726+
path: "/a/b/app.js",
727+
content: "var x = require('commander')"
728+
};
729+
const brokenPackageJson = {
730+
path: "/a/b/package.json",
731+
content: `{ "dependencies": { "co } }`
732+
};
733+
const fixedPackageJson = {
734+
path: brokenPackageJson.path,
735+
content: `{ "dependencies": { "commander": "0.0.2" } }`
736+
};
737+
const cachePath = "/a/cache/";
738+
const commander = {
739+
path: cachePath + "node_modules/@types/commander/index.d.ts",
740+
content: "export let x: number"
741+
};
742+
const host = createServerHost([f, brokenPackageJson]);
743+
const installer = new (class extends Installer {
744+
constructor() {
745+
super(host, { globalTypingsCacheLocation: cachePath });
746+
}
747+
executeRequest(requestKind: TI.RequestKind, _requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
748+
const installedTypings = ["@types/commander"];
749+
const typingFiles = [commander];
750+
executeCommand(this, host, installedTypings, typingFiles, requestKind, cb);
751+
}
752+
})();
753+
const service = createProjectService(host, { typingsInstaller: installer });
754+
service.openClientFile(f.path);
755+
756+
installer.checkPendingCommands([]);
757+
758+
host.reloadFS([f, fixedPackageJson]);
759+
host.triggerFileWatcherCallback(fixedPackageJson.path, /*removed*/ false);
760+
// expected one view and one install request
761+
installer.installAll([TI.NpmViewRequest], [TI.NpmInstallRequest]);
762+
763+
service.checkNumberOfProjects({ inferredProjects: 1 });
764+
checkProjectActualFiles(service.inferredProjects[0], [f.path, commander.path]);
765+
});
723766
});
724767

725768
describe("Validate package name:", () => {
726-
it ("name cannot be too long", () => {
769+
it("name cannot be too long", () => {
727770
let packageName = "a";
728771
for (let i = 0; i < 8; i++) {
729772
packageName += packageName;
730773
}
731774
assert.equal(TI.validatePackageName(packageName), TI.PackageNameValidationResult.NameTooLong);
732775
});
733-
it ("name cannot start with dot", () => {
776+
it("name cannot start with dot", () => {
734777
assert.equal(TI.validatePackageName(".foo"), TI.PackageNameValidationResult.NameStartsWithDot);
735778
});
736-
it ("name cannot start with underscore", () => {
779+
it("name cannot start with underscore", () => {
737780
assert.equal(TI.validatePackageName("_foo"), TI.PackageNameValidationResult.NameStartsWithUnderscore);
738781
});
739-
it ("scoped packages not supported", () => {
782+
it("scoped packages not supported", () => {
740783
assert.equal(TI.validatePackageName("@scope/bar"), TI.PackageNameValidationResult.ScopedPackagesNotSupported);
741784
});
742-
it ("non URI safe characters are not supported", () => {
785+
it("non URI safe characters are not supported", () => {
743786
assert.equal(TI.validatePackageName(" scope "), TI.PackageNameValidationResult.NameContainsNonURISafeCharacters);
744787
assert.equal(TI.validatePackageName("; say ‘Hello from TypeScript!’ #"), TI.PackageNameValidationResult.NameContainsNonURISafeCharacters);
745788
assert.equal(TI.validatePackageName("a/b/c"), TI.PackageNameValidationResult.NameContainsNonURISafeCharacters);
746789
});
747790
});
748791

749792
describe("Invalid package names", () => {
750-
it ("should not be installed", () => {
793+
it("should not be installed", () => {
751794
const f1 = {
752795
path: "/a/b/app.js",
753796
content: "let x = 1"
Collapse file

‎src/server/typingsInstaller/typingsInstaller.ts‎

Copy file name to clipboardExpand all lines: src/server/typingsInstaller/typingsInstaller.ts
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,10 @@ namespace ts.server.typingsInstaller {
381381
if (this.log.isEnabled()) {
382382
this.log.writeLine(`Got FS notification for ${f}, handler is already invoked '${isInvoked}'`);
383383
}
384-
this.sendResponse({ projectName: projectName, kind: "invalidate" });
385-
isInvoked = true;
384+
if (!isInvoked) {
385+
this.sendResponse({ projectName: projectName, kind: "invalidate" });
386+
isInvoked = true;
387+
}
386388
});
387389
watchers.push(w);
388390
}
Collapse file

‎src/services/jsTyping.ts‎

Copy file name to clipboardExpand all lines: src/services/jsTyping.ts
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,12 @@ namespace ts.JsTyping {
135135
* Get the typing info from common package manager json files like package.json or bower.json
136136
*/
137137
function getTypingNamesFromJson(jsonPath: string, filesToWatch: string[]) {
138+
if (host.fileExists(jsonPath)) {
139+
filesToWatch.push(jsonPath);
140+
}
138141
const result = readConfigFile(jsonPath, (path: string) => host.readFile(path));
139142
if (result.config) {
140143
const jsonConfig: PackageJson = result.config;
141-
filesToWatch.push(jsonPath);
142144
if (jsonConfig.dependencies) {
143145
mergeTypings(getOwnKeys(jsonConfig.dependencies));
144146
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.