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

Use @definitelytyped/types-registry for ATA #33791

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 36 additions & 18 deletions src/typingsInstaller/nodeTypingsInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ namespace ts.server.typingsInstaller {
}

const typesRegistryPackageName = "types-registry";
function getTypesRegistryFileLocation(globalTypingsCacheLocation: string): string {
return combinePaths(normalizeSlashes(globalTypingsCacheLocation), `node_modules/${typesRegistryPackageName}/index.json`);
const definitelyTypedTypesRegistryPackageName = "@definitelytyped/types-registry";
function getTypesRegistryFileLocation(globalTypingsCacheLocation: string, packageName: string): string {
return combinePaths(normalizeSlashes(globalTypingsCacheLocation), `node_modules/${packageName}/index.json`);
}

interface ExecSyncOptions {
Expand Down Expand Up @@ -105,28 +106,45 @@ namespace ts.server.typingsInstaller {
({ execSync: this.nodeExecSync } = require("child_process"));

this.ensurePackageDirectoryExists(globalTypingsCacheLocation);
const packageName = this.installTypesRegistry(globalTypingsCacheLocation);
this.typesRegistry = loadTypesRegistryFile(getTypesRegistryFileLocation(globalTypingsCacheLocation, packageName), this.installTypingHost, this.log);
}

try {
if (this.log.isEnabled()) {
this.log.writeLine(`Updating ${typesRegistryPackageName} npm package...`);
}
this.execSyncAndLog(`${this.npmPath} install --ignore-scripts ${typesRegistryPackageName}@${this.latestDistTag}`, { cwd: globalTypingsCacheLocation });
if (this.log.isEnabled()) {
this.log.writeLine(`Updated ${typesRegistryPackageName} npm package`);
private installTypesRegistry(globalTypingsCacheLocation: string) {
let result: typeof typesRegistryPackageName | typeof definitelyTypedTypesRegistryPackageName | "UPDATE FAILED" =
this.installTypesRegistryFromPackageName(definitelyTypedTypesRegistryPackageName, globalTypingsCacheLocation);
if (result === "UPDATE FAILED") {
result = this.installTypesRegistryFromPackageName(typesRegistryPackageName, globalTypingsCacheLocation);
if (result === "UPDATE FAILED") {
if (this.log.isEnabled()) {
this.log.writeLine(`Error updating ${typesRegistryPackageName} package`);
}
// store error info to report it later when it is known that server is already listening to events from typings installer
this.delayedInitializationError = {
kind: "event::initializationFailed",
message: result
};
return "types-registry";
}
}
catch (e) {
return result;
}

private installTypesRegistryFromPackageName(packageName: typeof typesRegistryPackageName | typeof definitelyTypedTypesRegistryPackageName, globalTypingsCacheLocation: string) {
if (this.log.isEnabled()) {
this.log.writeLine(`Updating ${packageName} npm package...`);
}
const registry = packageName === typesRegistryPackageName ? "" : "--registry=https://npm.pkg.github.com";
const failed = this.execSyncAndLog(`${this.npmPath} install ${registry} --ignore-scripts ${packageName}@${this.latestDistTag}`, { cwd: globalTypingsCacheLocation });
if (failed) {
return "UPDATE FAILED";
sandersn marked this conversation as resolved.
Show resolved Hide resolved
}
else {
if (this.log.isEnabled()) {
this.log.writeLine(`Error updating ${typesRegistryPackageName} package: ${(<Error>e).message}`);
this.log.writeLine(`Updated ${packageName} npm package`);
}
// store error info to report it later when it is known that server is already listening to events from typings installer
this.delayedInitializationError = {
kind: "event::initializationFailed",
message: (<Error>e).message
};
return packageName;
}

this.typesRegistry = loadTypesRegistryFile(getTypesRegistryFileLocation(globalTypingsCacheLocation), this.installTypingHost, this.log);
}

listen() {
Expand Down