Skip to content

Commit 6748078

Browse files
committed
Implement microsoft#42994
1 parent fe5f523 commit 6748078

1 file changed

Lines changed: 71 additions & 66 deletions

File tree

src/vs/code/node/cliProcessMain.ts

Lines changed: 71 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ export function getIdAndVersion(id: string): [string, string | undefined] {
6262
}
6363

6464

65-
type Task = { (): Promise<void> };
66-
6765
class Main {
6866

6967
constructor(
@@ -82,7 +80,7 @@ class Main {
8280
} else if (argv['install-extension']) {
8381
const arg = argv['install-extension'];
8482
const args: string[] = typeof arg === 'string' ? [arg] : arg;
85-
await this.installExtension(args, argv['force']);
83+
await this.installExtensions(args, argv['force']);
8684

8785
} else if (argv['uninstall-extension']) {
8886
const arg = argv['uninstall-extension'];
@@ -100,77 +98,84 @@ class Main {
10098
extensions.forEach(e => console.log(getId(e.manifest, showVersions)));
10199
}
102100

103-
private installExtension(extensions: string[], force: boolean): Promise<any> {
104-
const vsixTasks: Task[] = extensions
105-
.filter(e => /\.vsix$/i.test(e))
106-
.map(id => () => {
107-
const extension = path.isAbsolute(id) ? id : path.join(process.cwd(), id);
108-
109-
return this.validate(extension, force)
110-
.then(valid => {
111-
if (valid) {
112-
return this.extensionManagementService.install(URI.file(extension)).then(() => {
113-
console.log(localize('successVsixInstall', "Extension '{0}' was successfully installed!", getBaseLabel(extension)));
114-
}, error => {
115-
if (isPromiseCanceledError(error)) {
116-
console.log(localize('cancelVsixInstall', "Cancelled installing Extension '{0}'.", getBaseLabel(extension)));
117-
return null;
118-
} else {
119-
return Promise.reject(error);
120-
}
121-
});
122-
}
123-
return null;
124-
});
125-
});
101+
private async installExtensions(extensions: string[], force: boolean): Promise<void> {
102+
let failed: string[] = [];
103+
for (const extension of extensions) {
104+
try {
105+
await this.installExtension(extension, force);
106+
} catch (err) {
107+
console.error(err.message || err.stack || err);
108+
failed.push(extension);
109+
}
110+
}
111+
return failed.length ? Promise.reject(localize('installation failed', "Failed Installing Extensions: {0}", failed.join(', '))) : Promise.resolve();
112+
}
126113

127-
const galleryTasks: Task[] = extensions
128-
.filter(e => !/\.vsix$/i.test(e))
129-
.map(e => () => {
130-
const [id, version] = getIdAndVersion(e);
131-
return this.extensionManagementService.getInstalled(LocalExtensionType.User)
132-
.then(installed => this.extensionGalleryService.getExtension({ id }, version)
133-
.then<IGalleryExtension>(null, err => {
134-
if (err.responseText) {
135-
try {
136-
const response = JSON.parse(err.responseText);
137-
return Promise.reject(response.message);
138-
} catch (e) {
139-
// noop
140-
}
141-
}
142-
return Promise.reject(err);
143-
})
144-
.then(extension => {
145-
if (!extension) {
146-
return Promise.reject(new Error(`${notFound(version ? `${id}@${version}` : id)}\n${useId}`));
114+
private installExtension(extension: string, force: boolean): Promise<any> {
115+
if (/\.vsix$/i.test(extension)) {
116+
extension = path.isAbsolute(extension) ? extension : path.join(process.cwd(), extension);
117+
118+
return this.validate(extension, force)
119+
.then(valid => {
120+
if (valid) {
121+
return this.extensionManagementService.install(URI.file(extension)).then(() => {
122+
console.log(localize('successVsixInstall', "Extension '{0}' was successfully installed!", getBaseLabel(extension)));
123+
}, error => {
124+
if (isPromiseCanceledError(error)) {
125+
console.log(localize('cancelVsixInstall', "Cancelled installing Extension '{0}'.", getBaseLabel(extension)));
126+
return null;
127+
} else {
128+
return Promise.reject(error);
147129
}
130+
});
131+
}
132+
return null;
133+
});
134+
}
148135

149-
const [installedExtension] = installed.filter(e => areSameExtensions({ id: getGalleryExtensionIdFromLocal(e) }, { id }));
150-
if (installedExtension) {
151-
if (extension.version !== installedExtension.manifest.version) {
152-
if (version || force) {
153-
console.log(localize('updateMessage', "Updating the Extension '{0}' to the version {1}", id, extension.version));
154-
return this.installFromGallery(id, extension);
155-
} else {
156-
console.log(localize('forceUpdate', "Extension '{0}' v{1} is already installed, but a newer version {2} is available in the marketplace. Use '--force' option to update to newer version.", id, installedExtension.manifest.version, extension.version));
157-
return Promise.resolve(null);
158-
}
159-
} else {
160-
console.log(localize('alreadyInstalled', "Extension '{0}' is already installed.", version ? `${id}@${version}` : id));
161-
return Promise.resolve(null);
162-
}
163-
} else {
164-
console.log(localize('foundExtension', "Found '{0}' in the marketplace.", id));
136+
const [id, version] = getIdAndVersion(extension);
137+
return this.extensionManagementService.getInstalled(LocalExtensionType.User)
138+
.then(installed => this.extensionGalleryService.getExtension({ id }, version)
139+
.then<IGalleryExtension>(null, err => {
140+
if (err.responseText) {
141+
try {
142+
const response = JSON.parse(err.responseText);
143+
return Promise.reject(response.message);
144+
} catch (e) {
145+
// noop
146+
}
147+
}
148+
return Promise.reject(err);
149+
})
150+
.then(extension => {
151+
if (!extension) {
152+
return Promise.reject(new Error(`${notFound(version ? `${id}@${version}` : id)}\n${useId}`));
153+
}
154+
155+
const [installedExtension] = installed.filter(e => areSameExtensions({ id: getGalleryExtensionIdFromLocal(e) }, { id }));
156+
if (installedExtension) {
157+
if (extension.version !== installedExtension.manifest.version) {
158+
if (version || force) {
159+
console.log(localize('updateMessage', "Updating the Extension '{0}' to the version {1}", id, extension.version));
165160
return this.installFromGallery(id, extension);
161+
} else {
162+
console.log(localize('forceUpdate', "Extension '{0}' v{1} is already installed, but a newer version {2} is available in the marketplace. Use '--force' option to update to newer version.", id, installedExtension.manifest.version, extension.version));
163+
return Promise.resolve(null);
166164
}
165+
} else {
166+
console.log(localize('alreadyInstalled', "Extension '{0}' is already installed.", version ? `${id}@${version}` : id));
167+
return Promise.resolve(null);
168+
}
169+
} else {
170+
console.log(localize('foundExtension', "Found '{0}' in the marketplace.", id));
171+
return this.installFromGallery(id, extension);
172+
}
167173

168-
}));
169-
});
170-
171-
return sequence([...vsixTasks, ...galleryTasks]);
174+
}));
172175
}
173176

177+
178+
174179
private async validate(vsix: string, force: boolean): Promise<boolean> {
175180
const manifest = await getManifest(vsix);
176181

0 commit comments

Comments
 (0)