Skip to content

Commit 0911478

Browse files
authored
Use EXTENSION_ROOT_DIR instead of __dirname (#3329)
* Use EXTENSION_DIR instead of __dirname
1 parent 5ada1e0 commit 0911478

9 files changed

Lines changed: 34 additions & 29 deletions

File tree

gulpfile.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,10 @@ const hygiene = (options, done) => {
386386
const { linter, configuration } = getLinter(options);
387387
const tsl = es.through(function (file) {
388388
const contents = file.contents.toString('utf8');
389-
// Don't print anything to the console, we'll do that.
390-
console.log('.');
389+
if (isCI) {
390+
// Don't print anything to the console, we'll do that.
391+
console.log('.');
392+
}
391393
// Yes this is a hack, but tslinter doesn't provide an option to prevent this.
392394
const oldWarn = console.warn;
393395
console.warn = () => { };

news/3 Code Health/3317.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use `EXTENSION_ROOT_DIR` instead of `__dirname` in preparation for bundling of extension.

src/client/common/application/applicationEnvironment.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
'use strict';
55

66
import { injectable } from 'inversify';
7-
import * as path from 'path';
87
import * as vscode from 'vscode';
9-
import { EXTENSION_ROOT_DIR } from '../constants';
108
import { IApplicationEnvironment } from './types';
119

1210
@injectable()
@@ -28,11 +26,11 @@ export class ApplicationEnvironment implements IApplicationEnvironment {
2826
}
2927
public get extensionName(): string {
3028
// tslint:disable-next-line:non-literal-require
31-
return require(path.join(EXTENSION_ROOT_DIR, 'package.json')).displayName;
29+
return this.packageJson.displayName;
3230
}
3331
// tslint:disable-next-line:no-any
3432
public get packageJson(): any {
35-
// tslint:disable-next-line:non-literal-require
36-
return require(path.join(EXTENSION_ROOT_DIR, 'package.json'));
33+
// tslint:disable-next-line:non-literal-require no-require-imports
34+
return require('../../../../package.json');
3735
}
3836
}

src/client/common/constants.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as path from 'path';
2-
31
export const PYTHON_LANGUAGE = 'python';
42
export const PYTHON = [
53
{ scheme: 'file', language: PYTHON_LANGUAGE },
@@ -86,4 +84,4 @@ export function isUnitTestExecution(): boolean {
8684
return process.env.VSC_PYTHON_UNIT_TEST === '1';
8785
}
8886

89-
export const EXTENSION_ROOT_DIR = path.join(__dirname, '..', '..', '..');
87+
export * from '../constants';

src/client/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
import * as path from 'path';
7+
export const EXTENSION_ROOT_DIR = path.join(__dirname, '..', '..');

src/client/datascience/codeCssGenerator.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import * as fm from 'file-matcher';
66
import * as fs from 'fs-extra';
77
import { inject, injectable } from 'inversify';
88
import * as path from 'path';
9-
109
import { IWorkspaceService } from '../common/application/types';
1110
import { ICurrentProcess, ILogger } from '../common/types';
11+
import { EXTENSION_ROOT_DIR } from '../constants';
1212
import { ICodeCssGenerator } from './types';
1313

1414
// This class generates css using the current theme in order to colorize code.
@@ -20,12 +20,12 @@ import { ICodeCssGenerator } from './types';
2020
@injectable()
2121
export class CodeCssGenerator implements ICodeCssGenerator {
2222
constructor(
23-
@inject(IWorkspaceService) private workspaceService : IWorkspaceService,
24-
@inject(ICurrentProcess) private currentProcess : ICurrentProcess,
25-
@inject(ILogger) private logger : ILogger) {
23+
@inject(IWorkspaceService) private workspaceService: IWorkspaceService,
24+
@inject(ICurrentProcess) private currentProcess: ICurrentProcess,
25+
@inject(ILogger) private logger: ILogger) {
2626
}
2727

28-
public generateThemeCss = async () : Promise<string> => {
28+
public generateThemeCss = async (): Promise<string> => {
2929
try {
3030
// First compute our current theme.
3131
const workbench = this.workspaceService.getConfiguration('workbench');
@@ -51,7 +51,7 @@ export class CodeCssGenerator implements ICodeCssGenerator {
5151
return '';
5252
}
5353

54-
private getScopeColor = (tokenColors: JSONArray, scope: string) : string => {
54+
private getScopeColor = (tokenColors: JSONArray, scope: string): string => {
5555
// Search through the scopes on the json object
5656
const match = tokenColors.findIndex(entry => {
5757
if (entry) {
@@ -81,7 +81,7 @@ export class CodeCssGenerator implements ICodeCssGenerator {
8181
}
8282

8383
// tslint:disable-next-line:max-func-body-length
84-
private generateCss = (tokenColors : JSONArray, fontFamily : string, fontSize: number) : string => {
84+
private generateCss = (tokenColors: JSONArray, fontFamily: string, fontSize: number): string => {
8585

8686
// There's a set of values that need to be found
8787
const comment = this.getScopeColor(tokenColors, 'comment');
@@ -233,11 +233,11 @@ export class CodeCssGenerator implements ICodeCssGenerator {
233233

234234
}
235235

236-
private mergeColors = (colors1 : JSONArray, colors2 : JSONArray) : JSONArray => {
236+
private mergeColors = (colors1: JSONArray, colors2: JSONArray): JSONArray => {
237237
return [...colors1, ...colors2];
238238
}
239239

240-
private readTokenColors = async (themeFile: string) : Promise<JSONArray> => {
240+
private readTokenColors = async (themeFile: string): Promise<JSONArray> => {
241241
const tokenContent = await fs.readFile(themeFile, 'utf8');
242242
const theme = JSON.parse(tokenContent) as JSONObject;
243243
const tokenColors = theme['tokenColors'] as JSONArray;
@@ -257,7 +257,7 @@ export class CodeCssGenerator implements ICodeCssGenerator {
257257
return [];
258258
}
259259

260-
private findTokenColors = async (theme : string) : Promise<JSONArray> => {
260+
private findTokenColors = async (theme: string): Promise<JSONArray> => {
261261
const currentExe = this.currentProcess.execPath;
262262
let currentPath = path.dirname(currentExe);
263263

@@ -271,11 +271,11 @@ export class CodeCssGenerator implements ICodeCssGenerator {
271271

272272
// Search through all of the json files for the theme name
273273
const escapedThemeName = theme.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
274-
const searchOptions : fm.FindOptions = {
274+
const searchOptions: fm.FindOptions = {
275275
path: extensionsPath,
276276
recursiveSearch: true,
277-
fileFilter : {
278-
fileNamePattern : '**/*.json',
277+
fileFilter: {
278+
fileNamePattern: '**/*.json',
279279
content: new RegExp(`id[',"]:\\s*[',"]${escapedThemeName}[',"]`)
280280
}
281281
};
@@ -316,7 +316,7 @@ export class CodeCssGenerator implements ICodeCssGenerator {
316316
}
317317

318318
// We should return a default. The vscode-light theme
319-
const defaultThemeFile = path.join(__dirname, 'defaultTheme.json');
319+
const defaultThemeFile = path.join(EXTENSION_ROOT_DIR, 'resources', 'defaultTheme.json');
320320
return this.readTokenColors(defaultThemeFile);
321321
}
322322
}

src/client/providers/renameProvider.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
import * as path from 'path';
21
import {
32
CancellationToken, OutputChannel,
43
Position, ProviderResult, RenameProvider,
54
TextDocument, window, workspace, WorkspaceEdit
65
} from 'vscode';
76
import { PythonSettings } from '../common/configSettings';
8-
import { STANDARD_OUTPUT_CHANNEL } from '../common/constants';
7+
import { EXTENSION_ROOT_DIR, STANDARD_OUTPUT_CHANNEL } from '../common/constants';
98
import { getWorkspaceEditsFromPatch } from '../common/editor';
109
import { IInstaller, IOutputChannel, Product } from '../common/types';
1110
import { IServiceContainer } from '../ioc/types';
1211
import { RefactorProxy } from '../refactor/proxy';
1312
import { captureTelemetry } from '../telemetry';
1413
import { REFACTOR_RENAME } from '../telemetry/constants';
1514

16-
const EXTENSION_DIR = path.join(__dirname, '..', '..', '..');
1715
type RenameResponse = {
1816
results: [{ diff: string }];
1917
};
@@ -54,7 +52,7 @@ export class PythonRenameProvider implements RenameProvider {
5452
const workspaceRoot = workspaceFolder ? workspaceFolder.uri.fsPath : __dirname;
5553
const pythonSettings = PythonSettings.getInstance(workspaceFolder ? workspaceFolder.uri : undefined);
5654

57-
const proxy = new RefactorProxy(EXTENSION_DIR, pythonSettings, workspaceRoot, this.serviceContainer);
55+
const proxy = new RefactorProxy(EXTENSION_ROOT_DIR, pythonSettings, workspaceRoot, this.serviceContainer);
5856
return proxy.rename<RenameResponse>(document, newName, document.uri.fsPath, range).then(response => {
5957
const fileDiffs = response.results.map(fileChanges => fileChanges.diff);
6058
return getWorkspaceEditsFromPatch(fileDiffs, workspaceRoot);

src/client/workspaceSymbols/generator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Disposable, OutputChannel, Uri, window } from 'vscode';
44
import { PythonSettings } from '../common/configSettings';
55
import { IProcessServiceFactory } from '../common/process/types';
66
import { IPythonSettings } from '../common/types';
7+
import { EXTENSION_ROOT_DIR } from '../constants';
78
import { captureTelemetry } from '../telemetry';
89
import { WORKSPACE_SYMBOLS_BUILD } from '../telemetry/constants';
910

@@ -20,7 +21,7 @@ export class Generator implements Disposable {
2021
constructor(public readonly workspaceFolder: Uri, private readonly output: OutputChannel,
2122
private readonly processServiceFactory: IProcessServiceFactory) {
2223
this.disposables = [];
23-
this.optionsFile = path.join(__dirname, '..', '..', '..', 'resources', 'ctagOptions');
24+
this.optionsFile = path.join(EXTENSION_ROOT_DIR, 'resources', 'ctagOptions');
2425
this.pythonSettings = PythonSettings.getInstance(workspaceFolder);
2526
}
2627

0 commit comments

Comments
 (0)