Skip to content

Commit 92ee0d1

Browse files
committed
🍎 ⏪ remove legacy cli check
fixes microsoft#22366
1 parent 6b1ae53 commit 92ee0d1

1 file changed

Lines changed: 20 additions & 123 deletions

File tree

src/vs/workbench/parts/cli/electron-browser/cli.contribution.ts

Lines changed: 20 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@
55

66
import * as nls from 'vs/nls';
77
import * as path from 'path';
8-
import * as os from 'os';
98
import * as cp from 'child_process';
109
import * as pfs from 'vs/base/node/pfs';
1110
import { nfcall } from 'vs/base/common/async';
1211
import { TPromise } from 'vs/base/common/winjs.base';
1312
import URI from 'vs/base/common/uri';
1413
import { Action } from 'vs/base/common/actions';
1514
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry';
16-
import { IWorkbenchContributionsRegistry, IWorkbenchContribution, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
1715
import { Registry } from 'vs/platform/platform';
1816
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
1917
import { IMessageService, Severity } from 'vs/platform/message/common/message';
2018
import { IEditorService } from 'vs/platform/editor/common/editor';
21-
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2219
import product from 'vs/platform/node/product';
2320

2421
interface ILegacyUse {
@@ -30,10 +27,6 @@ function ignore<T>(code: string, value: T = null): (err: any) => TPromise<T> {
3027
return err => err.code === code ? TPromise.as<T>(value) : TPromise.wrapError<T>(err);
3128
}
3229

33-
function readOrEmpty(name: string): TPromise<string> {
34-
return pfs.readFile(name, 'utf8').then(null, ignore('ENOENT', ''));
35-
}
36-
3730
const root = URI.parse(require.toUrl('')).fsPath;
3831
const source = path.resolve(root, '..', 'bin', 'code');
3932

@@ -67,61 +60,28 @@ class InstallAction extends Action {
6760
return undefined;
6861
}
6962

70-
return this.checkLegacy()
71-
.then(uses => {
72-
if (uses.length > 0) {
73-
const { file, lineNumber } = uses[0];
74-
const message = nls.localize(
75-
'exists',
76-
"Please remove the alias referencing '{0}' in '{1}' (line {2}) and retry this action.",
77-
product.darwinBundleIdentifier,
78-
file,
79-
lineNumber
80-
);
81-
82-
const resource = URI.file(file);
83-
const input = { resource };
84-
const actions = [
85-
new Action('inlineEdit', nls.localize('editFile', "Edit '{0}'", file), '', true, () => {
86-
return this.editorService.openEditor(input).then(() => {
87-
const message = nls.localize('again', "Please remove the '{0}' alias from '{1}' before continuing.", product.applicationName, file);
88-
const actions = [
89-
new Action('continue', nls.localize('continue', "Continue"), '', true, () => this.run()),
90-
new Action('cancel', nls.localize('cancel', "Cancel"))
91-
];
92-
93-
this.messageService.show(Severity.Info, { message, actions });
94-
});
95-
})
96-
];
97-
98-
this.messageService.show(Severity.Warning, { message, actions });
63+
return this.isInstalled()
64+
.then(isInstalled => {
65+
if (!isAvailable || isInstalled) {
9966
return TPromise.as(null);
100-
}
101-
102-
return this.isInstalled()
103-
.then(isInstalled => {
104-
if (!isAvailable || isInstalled) {
105-
return TPromise.as(null);
106-
} else {
107-
const createSymlink = () => {
108-
return pfs.unlink(this.target)
109-
.then(null, ignore('ENOENT'))
110-
.then(() => pfs.symlink(source, this.target));
111-
};
112-
113-
return createSymlink().then(null, err => {
114-
if (err.code === 'EACCES' || err.code === 'ENOENT') {
115-
return this.createBinFolder()
116-
.then(() => createSymlink());
117-
}
118-
119-
return TPromise.wrapError(err);
120-
});
67+
} else {
68+
const createSymlink = () => {
69+
return pfs.unlink(this.target)
70+
.then(null, ignore('ENOENT'))
71+
.then(() => pfs.symlink(source, this.target));
72+
};
73+
74+
return createSymlink().then(null, err => {
75+
if (err.code === 'EACCES' || err.code === 'ENOENT') {
76+
return this.createBinFolder()
77+
.then(() => createSymlink());
12178
}
122-
})
123-
.then(() => this.messageService.show(Severity.Info, nls.localize('successIn', "Shell command '{0}' successfully installed in PATH.", product.applicationName)));
124-
});
79+
80+
return TPromise.wrapError(err);
81+
});
82+
}
83+
})
84+
.then<void>(() => this.messageService.show(Severity.Info, nls.localize('successIn', "Shell command '{0}' successfully installed in PATH.", product.applicationName)));
12585
});
12686
}
12787

@@ -152,32 +112,6 @@ class InstallAction extends Action {
152112
this.messageService.show(Severity.Info, { message, actions });
153113
});
154114
}
155-
156-
checkLegacy(): TPromise<ILegacyUse[]> {
157-
const files = [
158-
path.join(os.homedir(), '.bash_profile'),
159-
path.join(os.homedir(), '.bashrc'),
160-
path.join(os.homedir(), '.zshrc')
161-
];
162-
163-
return TPromise.join(files.map(f => readOrEmpty(f))).then(result => {
164-
return result.reduce((result, contents, index) => {
165-
const file = files[index];
166-
const lines = contents.split(/\r?\n/);
167-
168-
lines.some((line, index) => {
169-
if (line.indexOf(product.darwinBundleIdentifier) > -1 && !/^\s*#/.test(line)) {
170-
result.push({ file, lineNumber: index + 1 });
171-
return true;
172-
}
173-
174-
return false;
175-
});
176-
177-
return result;
178-
}, [] as ILegacyUse[]);
179-
});
180-
}
181115
}
182116

183117
class UninstallAction extends Action {
@@ -212,47 +146,10 @@ class UninstallAction extends Action {
212146
}
213147
}
214148

215-
class DarwinCLIHelper implements IWorkbenchContribution {
216-
217-
constructor(
218-
@IInstantiationService instantiationService: IInstantiationService,
219-
@IMessageService messageService: IMessageService
220-
) {
221-
const installAction = instantiationService.createInstance(InstallAction, InstallAction.ID, InstallAction.LABEL);
222-
223-
isAvailable().done(isAvailable => {
224-
if (!isAvailable) {
225-
return;
226-
}
227-
228-
return installAction.checkLegacy().done(files => {
229-
if (files.length > 0) {
230-
const message = nls.localize('update', "Code needs to change the '{0}' shell command. Would you like to do this now?", product.applicationName);
231-
const now = new Action('changeNow', nls.localize('changeNow', "Change Now"), '', true, () => installAction.run());
232-
const later = new Action('later', nls.localize('later', "Later"), '', true, () => {
233-
messageService.show(Severity.Info, nls.localize('laterInfo', "Remember you can always run the '{0}' action from the Command Palette.", installAction.label));
234-
return null;
235-
});
236-
const actions = [now, later];
237-
238-
messageService.show(Severity.Info, { message, actions });
239-
}
240-
});
241-
});
242-
}
243-
244-
getId(): string {
245-
return 'darwin.cli';
246-
}
247-
}
248-
249149
if (process.platform === 'darwin') {
250150
const category = nls.localize('shellCommand', "Shell Command");
251151

252152
const workbenchActionsRegistry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
253153
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(InstallAction, InstallAction.ID, InstallAction.LABEL), 'Shell Command: Install \'code\' command in PATH', category);
254154
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(UninstallAction, UninstallAction.ID, UninstallAction.LABEL), 'Shell Command: Uninstall \'code\' command from PATH', category);
255-
256-
const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
257-
workbenchRegistry.registerWorkbenchContribution(DarwinCLIHelper);
258155
}

0 commit comments

Comments
 (0)