Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build/webpack/webpack.debugadapter.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const tsconfig_paths_webpack_plugin_1 = require("tsconfig-paths-webpack-plugin");
const webpack_1 = require("webpack");
const constants_1 = require("../constants");
const common_1 = require("./common");
// tslint:disable-next-line:no-var-requires no-require-imports
Expand Down
2 changes: 1 addition & 1 deletion build/webpack/webpack.debugadapter.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as path from 'path';
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
import { Configuration, ContextReplacementPlugin } from 'webpack';
import { Configuration } from 'webpack';
import { ExtensionRootDir } from '../constants';
import { getDefaultPlugins } from './common';

Expand Down
11 changes: 1 addition & 10 deletions build/webpack/webpack.extension.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const tsconfig_paths_webpack_plugin_1 = require("tsconfig-paths-webpack-plugin");
const webpack_1 = require("webpack");
const constants_1 = require("../constants");
const common_1 = require("./common");
// tslint:disable-next-line:no-var-requires no-require-imports
const WrapperPlugin = require('wrapper-webpack-plugin');
// tslint:disable-next-line:no-var-requires no-require-imports
const configFileName = path.join(constants_1.ExtensionRootDir, 'tsconfig.extension.json');
// Some modules will be pre-genearted and stored in out/.. dir and they'll be referenced via NormalModuleReplacementPlugin
// We need to ensure they do not get bundled into the output (as they are large).
Expand Down Expand Up @@ -60,13 +57,7 @@ const config = {
...existingModulesInOutDir
],
plugins: [
...common_1.getDefaultPlugins('extension'),
new WrapperPlugin({
test: /\extension.js$/,
// Import source map warning file only if source map is enabled.
// Minimize importing external files.
header: '(function(){if (require(\'vscode\').workspace.getConfiguration(\'python.diagnostics\', undefined).get(\'sourceMapsEnabled\', false)) {require(\'./sourceMapSupport\').default(require(\'vscode\'));}})();'
})
...common_1.getDefaultPlugins('extension')
],
resolve: {
extensions: ['.ts', '.js'],
Expand Down
13 changes: 2 additions & 11 deletions build/webpack/webpack.extension.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@

import * as path from 'path';
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
import { Configuration, ContextReplacementPlugin } from 'webpack';
import { Configuration } from 'webpack';
import { ExtensionRootDir } from '../constants';
import { getDefaultPlugins, getListOfExistingModulesInOutDir } from './common';

// tslint:disable-next-line:no-var-requires no-require-imports
const WrapperPlugin = require('wrapper-webpack-plugin');

// tslint:disable-next-line:no-var-requires no-require-imports
const configFileName = path.join(ExtensionRootDir, 'tsconfig.extension.json');

Expand Down Expand Up @@ -65,13 +62,7 @@ const config: Configuration = {
...existingModulesInOutDir
],
plugins: [
...getDefaultPlugins('extension'),
new WrapperPlugin({
test: /\extension.js$/,
// Import source map warning file only if source map is enabled.
// Minimize importing external files.
header: '(function(){if (require(\'vscode\').workspace.getConfiguration(\'python.diagnostics\', undefined).get(\'sourceMapsEnabled\', false)) {require(\'./sourceMapSupport\').default(require(\'vscode\'));}})();'
})
...getDefaultPlugins('extension')
],
resolve: {
extensions: ['.ts', '.js'],
Expand Down
59 changes: 0 additions & 59 deletions build/webpack/webpack.extension.sourceMaps.config.js

This file was deleted.

65 changes: 0 additions & 65 deletions build/webpack/webpack.extension.sourceMaps.config.ts

This file was deleted.

11 changes: 10 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,16 @@ function getAllowedWarningsForWebPack(buildConfig) {
throw new Error('Unknown WebPack Configuration');
}
}
gulp.task('prePublishBundle', gulp.series('checkNativeDependencies', 'check-datascience-dependencies', 'compile', 'clean:cleanExceptTests', 'webpack'));
gulp.task('renameSourceMaps', async () => {
// By default souce maps will be disabled in the extenion.
// Users will need to use the command `python.enableSourceMapSupport` to enable source maps.
const extensionSourceMap = path.join(__dirname, 'out', 'client', 'extension.js.map');
const debuggerSourceMap = path.join(__dirname, 'out', 'client', 'debugger', 'debugAdapter', 'main.js.map');
await fs.rename(extensionSourceMap, `${extensionSourceMap}.disabled`);
await fs.rename(debuggerSourceMap, `${debuggerSourceMap}.disabled`);
});

gulp.task('prePublishBundle', gulp.series('checkNativeDependencies', 'check-datascience-dependencies', 'compile', 'clean:cleanExceptTests', 'webpack', 'renameSourceMaps'));
gulp.task('prePublishNonBundle', gulp.series('checkNativeDependencies', 'check-datascience-dependencies', 'compile', 'compile-webviews'));

const installPythonLibArgs = ['-m', 'pip', '--disable-pip-version-check', 'install',
Expand Down
1 change: 1 addition & 0 deletions news/2 Fixes/3905.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changes to how source maps are enabled and disabled in the extension.
9 changes: 0 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1990,7 +1990,6 @@
"retyped-diff-match-patch-tsd-ambient": "^1.0.0-0",
"rewiremock": "^3.13.0",
"shortid": "^2.2.8",
"source-map-support": "^0.5.9",
"style-loader": "^0.23.1",
"styled-jsx": "^3.1.0",
"svg-inline-loader": "^0.8.0",
Expand All @@ -2015,7 +2014,6 @@
"webpack-fix-default-import-plugin": "^1.0.3",
"webpack-merge": "^4.1.4",
"webpack-node-externals": "^1.7.2",
"wrapper-webpack-plugin": "^2.0.0",
"yargs": "^12.0.2"
},
"__metadata": {
Expand Down
8 changes: 7 additions & 1 deletion src/client/extension.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
'use strict';
// tslint:disable:no-var-requires no-require-imports

// This line should always be right on top.
// tslint:disable-next-line:no-any
if ((Reflect as any).metadata === undefined) {
// tslint:disable-next-line:no-require-imports no-var-requires
require('reflect-metadata');
}

// Initialize source maps (this must never be moved up nor further down).
import {initialize } from './sourceMapSupport';
initialize(require('vscode'));

const durations: { [key: string]: number } = {};
import { StopWatch } from './common/utils/stopWatch';
// Do not move this line of code (used to measure extension load times).
Expand Down
43 changes: 37 additions & 6 deletions src/client/sourceMapSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@

'use strict';

import * as fs from 'fs';
import * as path from 'path';
import { promisify } from 'util';
import { WorkspaceConfiguration } from 'vscode';
import './common/extensions';
import { EXTENSION_ROOT_DIR } from './constants';

type VSCode = typeof import('vscode');

// tslint:disable:no-require-imports
Expand All @@ -18,7 +24,7 @@ export class SourceMapSupport {
if (!this.enabled) {
return;
}
this.initializeSourceMaps();
await this.enableSourceMaps(true);
const localize = require('./common/utils/localize') as typeof import('./common/utils/localize');
const disable = localize.Diagnostics.disableSourceMaps();
const selection = await this.vscode.window.showWarningMessage(localize.Diagnostics.warnSourceMaps(), disable);
Expand All @@ -30,14 +36,39 @@ export class SourceMapSupport {
return this.config.get<boolean>(setting, false);
}
public async disable(): Promise<void> {
await this.config.update(setting, false, this.vscode.ConfigurationTarget.Global);
if (this.enabled) {
await this.config.update(setting, false, this.vscode.ConfigurationTarget.Global);
}
await this.enableSourceMaps(false);
}
protected async enableSourceMaps(enable: boolean) {
const extensionSourceFile = path.join(EXTENSION_ROOT_DIR, 'out', 'client', 'extension.js');
const debuggerSourceFile = path.join(EXTENSION_ROOT_DIR, 'out', 'client', 'debugger', 'debugAdapter', 'main.js');
await Promise.all([this.enableSourceMap(enable, extensionSourceFile), this.enableSourceMap(enable, debuggerSourceFile)]);
}
protected async enableSourceMap(enable: boolean, sourceFile: string) {
const sourceMapFile = `${sourceFile}.map`;
const disabledSourceMapFile = `${sourceFile}.map.disabled`;
if (enable) {
await this.rename(disabledSourceMapFile, sourceMapFile);
} else {
await this.rename(sourceMapFile, disabledSourceMapFile);
}
}
protected initializeSourceMaps() {
require('./node_modules/source-map-support').install();
protected async rename(sourceFile: string, targetFile: string) {
const fsExists = promisify(fs.exists);
const fsRename = promisify(fs.rename);
if (await fsExists(targetFile)) {
return;
}
await fsRename(sourceFile, targetFile);
}
}
// tslint:disable-next-line:no-default-export
export default function initialize(vscode: VSCode) {
export function initialize(vscode: VSCode = require('vscode')) {
if (!vscode.workspace.getConfiguration('python.diagnostics', undefined).get('sourceMapsEnabled', false)) {
new SourceMapSupport(vscode).disable().ignoreErrors();
return;
}
new SourceMapSupport(vscode).initialize().catch(ex => {
console.error('Failed to initialize source map support in extension');
});
Expand Down
Loading