From 5e362b13c52b9518261824752855386e0562a546 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Thu, 2 Jan 2020 12:47:19 -0800 Subject: [PATCH 1/3] Remove ts code from build scripts --- build/ci/postInstall.js | 21 ++-- build/ci/postInstall.ts | 56 ---------- build/constants.js | 4 +- build/constants.ts | 14 --- build/contributedFiles.json | 3 +- build/tsconfig.json | 29 ----- build/tslint-rules/baseRuleWalker.js | 8 +- build/tslint-rules/baseRuleWalker.ts | 22 ---- .../messagesMustBeLocalizedRule.js | 27 ++--- .../messagesMustBeLocalizedRule.ts | 72 ------------- build/util.js | 9 +- build/util.ts | 23 ---- build/webpack/common.js | 28 ++--- build/webpack/common.ts | 64 ----------- .../loaders/externalizeDependencies.js | 9 +- .../loaders/externalizeDependencies.ts | 22 ---- build/webpack/loaders/fixNodeFetch.js | 8 +- build/webpack/loaders/jsonloader.js | 9 +- build/webpack/loaders/remarkLoader.js | 6 +- build/webpack/plugins/less-plugin-base64.js | 29 +++-- build/webpack/webpack.debugadapter.config.js | 27 ++--- build/webpack/webpack.debugadapter.config.ts | 69 ------------ build/webpack/webpack.extension.config.js | 32 +++--- build/webpack/webpack.extension.config.ts | 101 ------------------ .../webpack.extension.dependencies.config.js | 33 +++--- .../webpack.extension.dependencies.config.ts | 71 ------------ 26 files changed, 113 insertions(+), 683 deletions(-) delete mode 100644 build/ci/postInstall.ts delete mode 100644 build/constants.ts delete mode 100644 build/tsconfig.json delete mode 100644 build/tslint-rules/baseRuleWalker.ts delete mode 100644 build/tslint-rules/messagesMustBeLocalizedRule.ts delete mode 100644 build/util.ts delete mode 100644 build/webpack/common.ts delete mode 100644 build/webpack/loaders/externalizeDependencies.ts delete mode 100644 build/webpack/webpack.debugadapter.config.ts delete mode 100644 build/webpack/webpack.extension.config.ts delete mode 100644 build/webpack/webpack.extension.dependencies.config.ts diff --git a/build/ci/postInstall.js b/build/ci/postInstall.js index 3198674c4668..db4deae4545e 100644 --- a/build/ci/postInstall.js +++ b/build/ci/postInstall.js @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. 'use strict'; -exports.__esModule = true; -var colors = require("colors/safe"); -var fs = require("fs"); -var path = require("path"); -var constants_1 = require("../constants"); + +var colors = require('colors/safe'); +var fs = require('fs'); +var path = require('path'); +var constants_1 = require('../constants'); /** * In order to compile the extension in strict mode, one of the dependencies (@jupyterlab) has some files that * just won't compile in strict mode. @@ -22,21 +22,20 @@ function fixJupyterLabDTSFiles() { var fileContents = fs.readFileSync(filePath, { encoding: 'utf8' }); if (fileContents.indexOf('[key: string]: ISchema | undefined;') > 0) { // tslint:disable-next-line:no-console - console.log(colors.blue(relativePath + " file already updated (by Python VSC)")); + console.log(colors.blue(relativePath + ' file already updated (by Python VSC)')); return; } if (fileContents.indexOf('[key: string]: ISchema;') > 0) { var replacedText = fileContents.replace('[key: string]: ISchema;', '[key: string]: ISchema | undefined;'); if (fileContents === replacedText) { - throw new Error('Fix for JupyterLabl file \'settingregistry.d.ts\' failed (pvsc post install script)'); + throw new Error("Fix for JupyterLabl file 'settingregistry.d.ts' failed (pvsc post install script)"); } fs.writeFileSync(filePath, replacedText); // tslint:disable-next-line:no-console - console.log(colors.green(relativePath + " file updated (by Python VSC)")); - } - else { + console.log(colors.green(relativePath + ' file updated (by Python VSC)')); + } else { // tslint:disable-next-line:no-console - console.log(colors.red(relativePath + " file does not need updating.")); + console.log(colors.red(relativePath + ' file does not need updating.')); } } fixJupyterLabDTSFiles(); diff --git a/build/ci/postInstall.ts b/build/ci/postInstall.ts deleted file mode 100644 index d21a7f256cfe..000000000000 --- a/build/ci/postInstall.ts +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -'use strict'; - -import * as colors from 'colors/safe'; -import * as fs from 'fs'; -import * as path from 'path'; -import { ExtensionRootDir } from '../constants'; - -/** - * In order to compile the extension in strict mode, one of the dependencies (@jupyterlab) has some files that - * just won't compile in strict mode. - * Unfortunately we cannot fix it by overriding their type definitions - * Note: that has been done for a few of the JupyterLabl files (see typings/index.d.ts). - * The solution is to modify the type definition file after `npm install`. - */ -function fixJupyterLabDTSFiles() { - const relativePath = path.join( - 'node_modules', - '@jupyterlab', - 'services', - 'node_modules', - '@jupyterlab', - 'coreutils', - 'lib', - 'settingregistry.d.ts' - ); - const filePath = path.join( - ExtensionRootDir, relativePath - ); - if (!fs.existsSync(filePath)) { - throw new Error(`Type Definition file from JupyterLab not found '${filePath}' (pvsc post install script)`); - } - - const fileContents = fs.readFileSync(filePath, { encoding: 'utf8' }); - if (fileContents.indexOf('[key: string]: ISchema | undefined;') > 0) { - // tslint:disable-next-line:no-console - console.log(colors.blue(`${relativePath} file already updated (by Python VSC)`)); - return; - } - if (fileContents.indexOf('[key: string]: ISchema;') > 0) { - const replacedText = fileContents.replace('[key: string]: ISchema;', '[key: string]: ISchema | undefined;'); - if (fileContents === replacedText) { - throw new Error('Fix for JupyterLabl file \'settingregistry.d.ts\' failed (pvsc post install script)'); - } - fs.writeFileSync(filePath, replacedText); - // tslint:disable-next-line:no-console - console.log(colors.green(`${relativePath} file updated (by Python VSC)`)); - } else { - // tslint:disable-next-line:no-console - console.log(colors.red(`${relativePath} file does not need updating.`)); - } -} - -fixJupyterLabDTSFiles(); diff --git a/build/constants.js b/build/constants.js index 9d59ed9388e6..60109ea4ce0e 100644 --- a/build/constants.js +++ b/build/constants.js @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. 'use strict'; -Object.defineProperty(exports, "__esModule", { value: true }); -const util = require("./util"); + +const util = require('./util'); exports.ExtensionRootDir = util.ExtensionRootDir; // This is a list of files that existed before MS got the extension. exports.existingFiles = util.getListOfFiles('existingFiles.json'); diff --git a/build/constants.ts b/build/constants.ts deleted file mode 100644 index 7fa818e562dc..000000000000 --- a/build/constants.ts +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -'use strict'; - -import * as util from './util'; - -export const ExtensionRootDir = util.ExtensionRootDir; - -// This is a list of files that existed before MS got the extension. -export const existingFiles: string[] = util.getListOfFiles('existingFiles.json'); -export const contributedFiles: string[] = util.getListOfFiles('contributedFiles.json'); -export const isWindows = /^win/.test(process.platform); -export const isCI = process.env.TRAVIS === 'true' || process.env.TF_BUILD !== undefined; diff --git a/build/contributedFiles.json b/build/contributedFiles.json index 0d4f101c7a37..fe51488c7066 100644 --- a/build/contributedFiles.json +++ b/build/contributedFiles.json @@ -1,2 +1 @@ -[ -] +[] diff --git a/build/tsconfig.json b/build/tsconfig.json deleted file mode 100644 index 45ed1ed7a6ef..000000000000 --- a/build/tsconfig.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "target": "es6", - "outDir": ".", - "lib": [ - "es6" - ], - "allowJs": true, - "checkJs": true, - "sourceMap": false, - "rootDir": ".", - "removeComments": false, - "experimentalDecorators": true, - "noImplicitThis": false, - "noUnusedLocals": true, - "noUnusedParameters": false, - "strict": true - }, - "include": [ - "**/*.ts" - ], - "exclude": [ - "node_modules", - ".vscode-test", - ".vscode test", - "src" - ] -} diff --git a/build/tslint-rules/baseRuleWalker.js b/build/tslint-rules/baseRuleWalker.js index 3e563c8d8f44..b8ce93d4179d 100644 --- a/build/tslint-rules/baseRuleWalker.js +++ b/build/tslint-rules/baseRuleWalker.js @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. 'use strict'; -Object.defineProperty(exports, "__esModule", { value: true }); -const path = require("path"); -const Lint = require("tslint"); -const util = require("../util"); + +const path = require('path'); +const Lint = require('tslint'); +const util = require('../util'); class BaseRuleWalker extends Lint.RuleWalker { shouldIgnoreCurrentFile(node, filesToIgnore) { const sourceFile = node.getSourceFile(); diff --git a/build/tslint-rules/baseRuleWalker.ts b/build/tslint-rules/baseRuleWalker.ts deleted file mode 100644 index e1e7dff0e44b..000000000000 --- a/build/tslint-rules/baseRuleWalker.ts +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -'use strict'; - -import * as path from 'path'; -import * as Lint from 'tslint'; -import * as ts from 'typescript'; -import * as util from '../util'; - -export class BaseRuleWalker extends Lint.RuleWalker { - protected shouldIgnoreCurrentFile(node: ts.Node, filesToIgnore: string[]): boolean { - const sourceFile = node.getSourceFile(); - if (sourceFile && sourceFile.fileName) { - const filename = path.resolve(util.ExtensionRootDir, sourceFile.fileName); - if (filesToIgnore.indexOf(filename.replace(/\//g, path.sep)) >= 0) { - return true; - } - } - return false; - } -} diff --git a/build/tslint-rules/messagesMustBeLocalizedRule.js b/build/tslint-rules/messagesMustBeLocalizedRule.js index fcd38774ad37..76c892de9653 100644 --- a/build/tslint-rules/messagesMustBeLocalizedRule.js +++ b/build/tslint-rules/messagesMustBeLocalizedRule.js @@ -1,32 +1,35 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. 'use strict'; -Object.defineProperty(exports, "__esModule", { value: true }); -const path = require("path"); -const Lint = require("tslint"); -const ts = require("typescript"); -const util = require("../util"); -const baseRuleWalker_1 = require("./baseRuleWalker"); + +const path = require('path'); +const Lint = require('tslint'); +const ts = require('typescript'); +const util = require('../util'); +const baseRuleWalker = require('./baseRuleWalker'); const methodNames = [ // From IApplicationShell (vscode.window): - 'showErrorMessage', 'showInformationMessage', - 'showWarningMessage', 'setStatusBarMessage', + 'showErrorMessage', + 'showInformationMessage', + 'showWarningMessage', + 'setStatusBarMessage', // From IOutputChannel (vscode.OutputChannel): - 'appendLine', 'appendLine' + 'appendLine', + 'appendLine' ]; // tslint:ignore-next-line:no-suspicious-comments // TODO: Ideally we would not ignore any files. const ignoredFiles = util.getListOfFiles('unlocalizedFiles.json'); const ignoredPrefix = path.normalize('src/test'); const failureMessage = 'Messages must be localized in the Python Extension (use src/client/common/utils/localize.ts)'; -class NoStringLiteralsInMessages extends baseRuleWalker_1.BaseRuleWalker { +class NoStringLiteralsInMessages extends baseRuleWalker.BaseRuleWalker { visitCallExpression(node) { if (!this.shouldIgnoreNode(node)) { node.arguments .filter(arg => ts.isStringLiteral(arg) || ts.isTemplateLiteral(arg)) .forEach(arg => { - this.addFailureAtNode(arg, failureMessage); - }); + this.addFailureAtNode(arg, failureMessage); + }); } super.visitCallExpression(node); } diff --git a/build/tslint-rules/messagesMustBeLocalizedRule.ts b/build/tslint-rules/messagesMustBeLocalizedRule.ts deleted file mode 100644 index cdd94678faa0..000000000000 --- a/build/tslint-rules/messagesMustBeLocalizedRule.ts +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -'use strict'; - -import * as path from 'path'; -import * as Lint from 'tslint'; -import * as ts from 'typescript'; -import * as util from '../util'; -import { BaseRuleWalker } from './baseRuleWalker'; - -const methodNames = [ - // From IApplicationShell (vscode.window): - 'showErrorMessage', 'showInformationMessage', - 'showWarningMessage', 'setStatusBarMessage', - // From IOutputChannel (vscode.OutputChannel): - 'appendLine', 'appendLine' -]; -// tslint:ignore-next-line:no-suspicious-comments -// TODO: Ideally we would not ignore any files. -const ignoredFiles = util.getListOfFiles('unlocalizedFiles.json'); -const ignoredPrefix = path.normalize('src/test'); - -const failureMessage = 'Messages must be localized in the Python Extension (use src/client/common/utils/localize.ts)'; - -class NoStringLiteralsInMessages extends BaseRuleWalker { - protected visitCallExpression(node: ts.CallExpression): void { - if (!this.shouldIgnoreNode(node)) { - node.arguments - .filter(arg => ts.isStringLiteral(arg) || ts.isTemplateLiteral(arg)) - .forEach(arg => { - this.addFailureAtNode(arg, failureMessage); - }); - } - super.visitCallExpression(node); - } - protected shouldIgnoreCurrentFile(node: ts.Node) { - //console.log(''); - //console.log(node.getSourceFile().fileName); - //console.log(ignoredFiles); - if (super.shouldIgnoreCurrentFile(node, ignoredFiles)) { - return true; - } - const sourceFile = node.getSourceFile(); - if (sourceFile && sourceFile.fileName) { - if (sourceFile.fileName.startsWith(ignoredPrefix)) { - return true; - } - } - return false; - } - private shouldIgnoreNode(node: ts.CallExpression) { - if (this.shouldIgnoreCurrentFile(node)) { - return true; - } - if (!ts.isPropertyAccessExpression(node.expression)) { - return true; - } - const prop = node.expression as ts.PropertyAccessExpression; - if (methodNames.indexOf(prop.name.text) < 0) { - return true; - } - return false; - } -} - -export class Rule extends Lint.Rules.AbstractRule { - public static FAILURE_STRING = failureMessage; - public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - return this.applyWithWalker(new NoStringLiteralsInMessages(sourceFile, this.getOptions())); - } -} diff --git a/build/util.js b/build/util.js index c6a55d6c2035..8a5ce3daf7d5 100644 --- a/build/util.js +++ b/build/util.js @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. 'use strict'; -Object.defineProperty(exports, "__esModule", { value: true }); -const fs = require("fs"); -const path = require("path"); + +const fs = require('fs'); +const path = require('path'); exports.ExtensionRootDir = path.dirname(__dirname); function getListOfFiles(filename) { filename = path.normalize(filename); @@ -12,8 +12,7 @@ function getListOfFiles(filename) { } const data = fs.readFileSync(filename).toString(); const files = JSON.parse(data); - return files - .map(file => { + return files.map(file => { return path.join(exports.ExtensionRootDir, file.replace(/\//g, path.sep)); }); } diff --git a/build/util.ts b/build/util.ts deleted file mode 100644 index 30178318c7e5..000000000000 --- a/build/util.ts +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -'use strict'; - -import * as fs from 'fs'; -import * as path from 'path'; - -export const ExtensionRootDir = path.dirname(__dirname); - -export function getListOfFiles(filename: string): string[] { - filename = path.normalize(filename); - if (!path.isAbsolute(filename)) { - filename = path.join(__dirname, filename); - } - - const data = fs.readFileSync(filename).toString(); - const files = JSON.parse(data) as string[]; - return files - .map(file => { - return path.join(ExtensionRootDir, file.replace(/\//g, path.sep)); - }); -} diff --git a/build/webpack/common.js b/build/webpack/common.js index 7c1ef55f7396..0201ad7e9c66 100644 --- a/build/webpack/common.js +++ b/build/webpack/common.js @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. 'use strict'; -Object.defineProperty(exports, "__esModule", { value: true }); -const glob = require("glob"); -const path = require("path"); -const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer"); -const constants_1 = require("../constants"); + +const glob = require('glob'); +const path = require('path'); +const webpack_bundle_analyzer = require('webpack-bundle-analyzer'); +const constants = require('../constants'); exports.nodeModulesToExternalize = [ 'unicode/category/Lu', 'unicode/category/Ll', @@ -37,22 +37,22 @@ exports.nodeModulesToExternalize = [ 'koa-compress', 'koa-logger' ]; -exports.nodeModulesToReplacePaths = [ - ...exports.nodeModulesToExternalize -]; +exports.nodeModulesToReplacePaths = [...exports.nodeModulesToExternalize]; function getDefaultPlugins(name) { const plugins = []; - if (!constants_1.isCI) { - plugins.push(new webpack_bundle_analyzer_1.BundleAnalyzerPlugin({ - analyzerMode: 'static', - reportFilename: `${name}.analyzer.html` - })); + if (!constants.isCI) { + plugins.push( + new webpack_bundle_analyzer.BundleAnalyzerPlugin({ + analyzerMode: 'static', + reportFilename: `${name}.analyzer.html` + }) + ); } return plugins; } exports.getDefaultPlugins = getDefaultPlugins; function getListOfExistingModulesInOutDir() { - const outDir = path.join(constants_1.ExtensionRootDir, 'out', 'client'); + const outDir = path.join(constants.ExtensionRootDir, 'out', 'client'); const files = glob.sync('**/*.js', { sync: true, cwd: outDir }); return files.map(filePath => `./${filePath.slice(0, -3)}`); } diff --git a/build/webpack/common.ts b/build/webpack/common.ts deleted file mode 100644 index c44bd94559e4..000000000000 --- a/build/webpack/common.ts +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -'use strict'; - -import * as glob from 'glob'; -import * as path from 'path'; -import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; -import { ExtensionRootDir, isCI } from '../constants'; - -export const nodeModulesToExternalize = [ - 'unicode/category/Lu', - 'unicode/category/Ll', - 'unicode/category/Lt', - 'unicode/category/Lo', - 'unicode/category/Lm', - 'unicode/category/Nl', - 'unicode/category/Mn', - 'unicode/category/Mc', - 'unicode/category/Nd', - 'unicode/category/Pc', - '@jupyterlab/services', - 'azure-storage', - 'request', - 'request-progress', - 'source-map-support', - 'diff-match-patch', - 'sudo-prompt', - 'node-stream-zip', - 'xml2js', - 'vsls/vscode', - 'pdfkit', - 'crypto-js', - 'fontkit', - 'linebreak', - 'png-js', - '@koa/cors', - 'koa', - 'koa-compress', - 'koa-logger' -]; - -export const nodeModulesToReplacePaths = [ - ...nodeModulesToExternalize -]; - -export function getDefaultPlugins(name: 'extension' | 'debugger' | 'dependencies' | 'datascience-ui') { - const plugins = []; - if (!isCI) { - plugins.push( - new BundleAnalyzerPlugin({ - analyzerMode: 'static', - reportFilename: `${name}.analyzer.html` - }) - ); - } - return plugins; -} - -export function getListOfExistingModulesInOutDir() { - const outDir = path.join(ExtensionRootDir, 'out', 'client'); - const files = glob.sync('**/*.js', { sync: true, cwd: outDir }); - return files.map(filePath => `./${filePath.slice(0, -3)}`); -} diff --git a/build/webpack/loaders/externalizeDependencies.js b/build/webpack/loaders/externalizeDependencies.js index 7c3ccc8ef5d1..654da53163ea 100644 --- a/build/webpack/loaders/externalizeDependencies.js +++ b/build/webpack/loaders/externalizeDependencies.js @@ -1,8 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -'use strict'; -Object.defineProperty(exports, "__esModule", { value: true }); -const common_1 = require("../common"); + +const common = require('../common'); function replaceModule(contents, moduleName, quotes) { const stringToSearch = `${quotes}${moduleName}${quotes}`; const stringToReplaceWith = `${quotes}./node_modules/${moduleName}${quotes}`; @@ -10,10 +9,10 @@ function replaceModule(contents, moduleName, quotes) { } // tslint:disable:no-default-export no-invalid-this function default_1(source) { - common_1.nodeModulesToReplacePaths.forEach(moduleName => { + common.nodeModulesToReplacePaths.forEach(moduleName => { if (source.indexOf(moduleName) > 0) { source = replaceModule(source, moduleName, '"'); - source = replaceModule(source, moduleName, '\''); + source = replaceModule(source, moduleName, "'"); } }); return source; diff --git a/build/webpack/loaders/externalizeDependencies.ts b/build/webpack/loaders/externalizeDependencies.ts deleted file mode 100644 index 403088403ec2..000000000000 --- a/build/webpack/loaders/externalizeDependencies.ts +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -'use strict'; - -import { nodeModulesToReplacePaths } from '../common'; - -function replaceModule(contents: string, moduleName: string, quotes: '"' | '\''): string { - const stringToSearch = `${quotes}${moduleName}${quotes}`; - const stringToReplaceWith = `${quotes}./node_modules/${moduleName}${quotes}`; - return contents.replace(new RegExp(stringToSearch, 'gm'), stringToReplaceWith); -} -// tslint:disable:no-default-export no-invalid-this -export default function (source: string) { - nodeModulesToReplacePaths.forEach(moduleName => { - if (source.indexOf(moduleName) > 0) { - source = replaceModule(source, moduleName, '"'); - source = replaceModule(source, moduleName, '\''); - } - }); - return source; -} diff --git a/build/webpack/loaders/fixNodeFetch.js b/build/webpack/loaders/fixNodeFetch.js index a42d79942170..c6bc95b6833c 100644 --- a/build/webpack/loaders/fixNodeFetch.js +++ b/build/webpack/loaders/fixNodeFetch.js @@ -6,7 +6,7 @@ const path = require('path'); const constants = require('../../constants'); -const nodeFetchIndexFile = path.join(constants.ExtensionRootDir, 'node_modules', '@jupyterlab','services','node_modules','node-fetch','lib','index.js'); +const nodeFetchIndexFile = path.join(constants.ExtensionRootDir, 'node_modules', '@jupyterlab', 'services', 'node_modules', 'node-fetch', 'lib', 'index.js'); // On windows replace `\` with `\\`, else we get an error in webpack (Module parse failed: Octal literal in strict mode). const nodeFetchFile = constants.isWindows ? nodeFetchIndexFile.replace(/\\/g, '\\\\') : nodeFetchIndexFile; @@ -19,9 +19,9 @@ const nodeFetchFile = constants.isWindows ? nodeFetchIndexFile.replace(/\\/g, '\ * @param {string} source * @returns */ -exports.default = function (source) { - if (source.indexOf('require(\'node-fetch\')') > 0) { +exports.default = function(source) { + if (source.indexOf("require('node-fetch')") > 0) { source = source.replace(/require\('node-fetch'\)/g, `require('${nodeFetchFile}')`); } return source; -} +}; diff --git a/build/webpack/loaders/jsonloader.js b/build/webpack/loaders/jsonloader.js index a5c8927a7d3a..b9bbcce75400 100644 --- a/build/webpack/loaders/jsonloader.js +++ b/build/webpack/loaders/jsonloader.js @@ -1,8 +1,7 @@ // For some reason this has to be in commonjs format module.exports = function(source) { - - // Just inline the source and fix up defaults so that they don't - // mess up the logic in the setOptions.js file - return `module.exports = ${source}\nmodule.exports.default = false`; -} + // Just inline the source and fix up defaults so that they don't + // mess up the logic in the setOptions.js file + return `module.exports = ${source}\nmodule.exports.default = false`; +}; diff --git a/build/webpack/loaders/remarkLoader.js b/build/webpack/loaders/remarkLoader.js index 8dde61d300ea..b9bbcce75400 100644 --- a/build/webpack/loaders/remarkLoader.js +++ b/build/webpack/loaders/remarkLoader.js @@ -1,9 +1,7 @@ // For some reason this has to be in commonjs format module.exports = function(source) { - // Just inline the source and fix up defaults so that they don't // mess up the logic in the setOptions.js file - return `module.exports = ${source}\nmodule.exports.default = false`; - - } + return `module.exports = ${source}\nmodule.exports.default = false`; +}; diff --git a/build/webpack/plugins/less-plugin-base64.js b/build/webpack/plugins/less-plugin-base64.js index c05d9a2b5b71..b7ecff56020f 100644 --- a/build/webpack/plugins/less-plugin-base64.js +++ b/build/webpack/plugins/less-plugin-base64.js @@ -4,8 +4,8 @@ const less = require('less'); class Base64MimeTypeNode { constructor() { - this.value = "image/svg+xml;base64"; - this.type = "Base64MimeTypeNode"; + this.value = 'image/svg+xml;base64'; + this.type = 'Base64MimeTypeNode'; } eval(context) { @@ -14,7 +14,6 @@ class Base64MimeTypeNode { } class Base64Visitor { - constructor() { this.visitor = new less.visitors.Visitor(this); @@ -33,29 +32,27 @@ class Base64Visitor { visitUrl(URLNode, visitArgs) { // Return two new nodes in the call. One that has the mime type and other with the node. The data-uri // evaluator will transform this into a base64 string - return new less.tree.Call("data-uri", [new Base64MimeTypeNode(), URLNode.value], URLNode.index || 0, URLNode.currentFileInfo); + return new less.tree.Call('data-uri', [new Base64MimeTypeNode(), URLNode.value], URLNode.index || 0, URLNode.currentFileInfo); } - } /* -* This was originally used to perform less on uris and turn them into base64 encoded so they can be loaded into -* a webpack html. There's one caveat though. Less and webpack don't play well together. It runs the less at the root dir. -* This means in order to use this in a less file, you need to qualify the urls as if they come from the root dir. -* Example: -* url("./foo.svg") -* becomes -* url("./src/datascience-ui/history-react/images/foo.svg") -*/ + * This was originally used to perform less on uris and turn them into base64 encoded so they can be loaded into + * a webpack html. There's one caveat though. Less and webpack don't play well together. It runs the less at the root dir. + * This means in order to use this in a less file, you need to qualify the urls as if they come from the root dir. + * Example: + * url("./foo.svg") + * becomes + * url("./src/datascience-ui/history-react/images/foo.svg") + */ class Base64Plugin { - constructor() { - } + constructor() {} install(less, pluginManager) { pluginManager.addVisitor(new Base64Visitor()); } printUsage() { - console.log('Base64 Plugin. Add to your webpack.config.js as a plugin to convert URLs to base64 inline') + console.log('Base64 Plugin. Add to your webpack.config.js as a plugin to convert URLs to base64 inline'); } } diff --git a/build/webpack/webpack.debugadapter.config.js b/build/webpack/webpack.debugadapter.config.js index 4544d1725ace..c26664f843dc 100644 --- a/build/webpack/webpack.debugadapter.config.js +++ b/build/webpack/webpack.debugadapter.config.js @@ -1,13 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. 'use strict'; -Object.defineProperty(exports, "__esModule", { value: true }); -const path = require("path"); -const tsconfig_paths_webpack_plugin_1 = require("tsconfig-paths-webpack-plugin"); -const constants_1 = require("../constants"); -const common_1 = require("./common"); + +const path = require('path'); +const tsconfig_paths_webpack_plugin = require('tsconfig-paths-webpack-plugin'); +const constants = require('../constants'); +const common = require('./common'); // tslint:disable-next-line:no-var-requires no-require-imports -const configFileName = path.join(constants_1.ExtensionRootDir, 'tsconfig.extension.json'); +const configFileName = path.join(constants.ExtensionRootDir, 'tsconfig.extension.json'); const config = { mode: 'production', target: 'node', @@ -40,22 +40,15 @@ const config = { } ] }, - externals: [ - 'vscode', - 'commonjs' - ], - plugins: [ - ...common_1.getDefaultPlugins('debugger') - ], + externals: ['vscode', 'commonjs'], + plugins: [...common.getDefaultPlugins('debugger')], resolve: { extensions: ['.ts', '.js'], - plugins: [ - new tsconfig_paths_webpack_plugin_1.TsconfigPathsPlugin({ configFile: configFileName }) - ] + plugins: [new tsconfig_paths_webpack_plugin.TsconfigPathsPlugin({ configFile: configFileName })] }, output: { filename: '[name].js', - path: path.resolve(constants_1.ExtensionRootDir, 'out', 'client'), + path: path.resolve(constants.ExtensionRootDir, 'out', 'client'), libraryTarget: 'commonjs2', devtoolModuleFilenameTemplate: '../../[resource-path]' } diff --git a/build/webpack/webpack.debugadapter.config.ts b/build/webpack/webpack.debugadapter.config.ts deleted file mode 100644 index 2805fb98adae..000000000000 --- a/build/webpack/webpack.debugadapter.config.ts +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -'use strict'; - -import * as path from 'path'; -import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin'; -import { Configuration } from 'webpack'; -import { ExtensionRootDir } from '../constants'; -import { getDefaultPlugins } from './common'; - -// tslint:disable-next-line:no-var-requires no-require-imports -const configFileName = path.join(ExtensionRootDir, 'tsconfig.extension.json'); - -const config: Configuration = { - mode: 'production', - target: 'node', - entry: { - 'debugger/debugAdapter/main': './src/client/debugger/debugAdapter/main.ts' - }, - devtool: 'source-map', - node: { - __dirname: false - }, - module: { - rules: [ - { - // JupyterServices imports node-fetch. - test: /@jupyterlab[\\\/]services[\\\/].*js$/, - use: [ - { - loader: path.join(__dirname, 'loaders', 'fixNodeFetch.js') - } - ] - }, - { - test: /\.ts$/, - exclude: /node_modules/, - use: [ - { - loader: 'ts-loader' - } - ] - } - ] - }, - externals: [ - 'vscode', - 'commonjs' - ], - plugins: [ - ...getDefaultPlugins('debugger') - ], - resolve: { - extensions: ['.ts', '.js'], - plugins: [ - new TsconfigPathsPlugin({ configFile: configFileName }) - ] - }, - output: { - filename: '[name].js', - path: path.resolve(ExtensionRootDir, 'out', 'client'), - libraryTarget: 'commonjs2', - devtoolModuleFilenameTemplate: '../../[resource-path]' - } -}; - -// tslint:disable-next-line:no-default-export -export default config; diff --git a/build/webpack/webpack.extension.config.js b/build/webpack/webpack.extension.config.js index 4cb8ccb06241..e35dfe609e73 100644 --- a/build/webpack/webpack.extension.config.js +++ b/build/webpack/webpack.extension.config.js @@ -1,16 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. 'use strict'; -Object.defineProperty(exports, "__esModule", { value: true }); -const path = require("path"); -const tsconfig_paths_webpack_plugin_1 = require("tsconfig-paths-webpack-plugin"); -const constants_1 = require("../constants"); -const common_1 = require("./common"); + +const path = require('path'); +const tsconfig_paths_webpack_plugin = require('tsconfig-paths-webpack-plugin'); +const constants = require('../constants'); +const common = require('./common'); // tslint:disable-next-line:no-var-requires no-require-imports -const configFileName = path.join(constants_1.ExtensionRootDir, 'tsconfig.extension.json'); +const configFileName = path.join(constants.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). -const existingModulesInOutDir = common_1.getListOfExistingModulesInOutDir(); +const existingModulesInOutDir = common.getListOfExistingModulesInOutDir(); // tslint:disable-next-line:no-var-requires no-require-imports const FileManagerPlugin = require('filemanager-webpack-plugin'); const config = { @@ -56,13 +56,9 @@ const config = { { enforce: 'post', test: /linebreak[\/\\]src[\/\\]linebreaker.js/, loader: 'transform-loader?brfs' } ] }, - externals: [ - 'vscode', - 'commonjs', - ...existingModulesInOutDir - ], + externals: ['vscode', 'commonjs', ...existingModulesInOutDir], plugins: [ - ...common_1.getDefaultPlugins('extension'), + ...common.getDefaultPlugins('extension'), // Copy pdfkit bits after extension builds. webpack can't handle pdfkit. new FileManagerPlugin({ onEnd: [ @@ -77,20 +73,18 @@ const config = { }) ], resolve: { - alias:{ + alias: { // Pointing pdfkit to a dummy js file so webpack doesn't fall over. // Since pdfkit has been externalized (it gets updated with the valid code by copying the pdfkit files // into the right destination). - 'pdfkit':path.resolve(__dirname, 'pdfkit.js') + pdfkit: path.resolve(__dirname, 'pdfkit.js') }, extensions: ['.ts', '.js'], - plugins: [ - new tsconfig_paths_webpack_plugin_1.TsconfigPathsPlugin({ configFile: configFileName }) - ] + plugins: [new tsconfig_paths_webpack_plugin.TsconfigPathsPlugin({ configFile: configFileName })] }, output: { filename: '[name].js', - path: path.resolve(constants_1.ExtensionRootDir, 'out', 'client'), + path: path.resolve(constants.ExtensionRootDir, 'out', 'client'), libraryTarget: 'commonjs2', devtoolModuleFilenameTemplate: '../../[resource-path]' } diff --git a/build/webpack/webpack.extension.config.ts b/build/webpack/webpack.extension.config.ts deleted file mode 100644 index 57b358940cd8..000000000000 --- a/build/webpack/webpack.extension.config.ts +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -'use strict'; - -import * as path from 'path'; -import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin'; -import { Configuration } from 'webpack'; -import { ExtensionRootDir } from '../constants'; -import { getDefaultPlugins, getListOfExistingModulesInOutDir } from './common'; - -// tslint:disable-next-line:no-var-requires no-require-imports -const configFileName = path.join(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). -const existingModulesInOutDir = getListOfExistingModulesInOutDir(); - -// tslint:disable-next-line:no-var-requires no-require-imports -const FileManagerPlugin = require('filemanager-webpack-plugin'); - -const config: Configuration = { - mode: 'production', - target: 'node', - entry: { - extension: './src/client/extension.ts' - }, - devtool: 'source-map', - node: { - __dirname: false - }, - module: { - rules: [ - { - // JupyterServices imports node-fetch. - test: /@jupyterlab[\\\/]services[\\\/].*js$/, - use: [ - { - loader: path.join(__dirname, 'loaders', 'fixNodeFetch.js') - } - ] - }, - { - test: /\.ts$/, - use: [ - { - loader: path.join(__dirname, 'loaders', 'externalizeDependencies.js') - } - ] - }, - { - test: /\.ts$/, - exclude: /node_modules/, - use: [ - { - loader: 'ts-loader' - } - ] - }, - {enforce: 'post', test: /unicode-properties[\/\\]index.js$/, loader: 'transform-loader?brfs'}, - {enforce: 'post', test: /fontkit[\/\\]index.js$/, loader: 'transform-loader?brfs'}, - {enforce: 'post', test: /pdfkit[\\\/]js[\\\/].*js$/, loader: 'transform-loader?brfs'}, - {enforce: 'post', test: /linebreak[\/\\]src[\/\\]linebreaker.js/, loader: 'transform-loader?brfs'} - ] - }, - externals: [ - 'vscode', - 'commonjs', - ...existingModulesInOutDir - ], - plugins: [ - ...getDefaultPlugins('extension'), - // Copy pdfkit bits after extension builds. webpack can't handle pdfkit. - new FileManagerPlugin({ - onEnd: [ - { - copy: [ - { source: './node_modules/fontkit/*.trie', destination: './out/client/node_modules' }, - { source: './node_modules/pdfkit/js/data/*.*', destination: './out/client/node_modules/data' }, - { source: './node_modules/pdfkit/js/pdfkit.js', destination: './out/client/node_modules/' } - ] - } - ] - }) - ], - resolve: { - extensions: ['.ts', '.js'], - plugins: [ - new TsconfigPathsPlugin({ configFile: configFileName }) - ] - }, - output: { - filename: '[name].js', - path: path.resolve(ExtensionRootDir, 'out', 'client'), - libraryTarget: 'commonjs2', - devtoolModuleFilenameTemplate: '../../[resource-path]' - } -}; - -// tslint:disable-next-line:no-default-export -export default config; diff --git a/build/webpack/webpack.extension.dependencies.config.js b/build/webpack/webpack.extension.dependencies.config.js index 47b5101d2195..6ff5b38dd7a4 100644 --- a/build/webpack/webpack.extension.dependencies.config.js +++ b/build/webpack/webpack.extension.dependencies.config.js @@ -1,14 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. 'use strict'; -Object.defineProperty(exports, "__esModule", { value: true }); + // tslint:disable-next-line: no-require-imports -const copyWebpackPlugin = require("copy-webpack-plugin"); -const path = require("path"); -const constants_1 = require("../constants"); -const common_1 = require("./common"); +const copyWebpackPlugin = require('copy-webpack-plugin'); +const path = require('path'); +const constants = require('../constants'); +const common = require('./common'); const entryItems = {}; -common_1.nodeModulesToExternalize.forEach(moduleName => { +common.nodeModulesToExternalize.forEach(moduleName => { entryItems[`node_modules/${moduleName}`] = `./node_modules/${moduleName}`; }); const config = { @@ -35,34 +35,27 @@ const config = { { enforce: 'post', test: /linebreak[\/\\]src[\/\\]linebreaker.js/, loader: 'transform-loader?brfs' } ] }, - externals: [ - 'vscode', - 'commonjs' - ], + externals: ['vscode', 'commonjs'], plugins: [ - ...common_1.getDefaultPlugins('dependencies'), + ...common.getDefaultPlugins('dependencies'), // vsls requires our package.json to be next to node_modules. It's how they // 'find' the calling extension. - new copyWebpackPlugin([ - { from: './package.json', to: '.' } - ]), + new copyWebpackPlugin([{ from: './package.json', to: '.' }]), // onigasm requires our onigasm.wasm to be in node_modules - new copyWebpackPlugin([ - { from: './node_modules/onigasm/lib/onigasm.wasm', to: './node_modules/onigasm/lib/onigasm.wasm' } - ]) + new copyWebpackPlugin([{ from: './node_modules/onigasm/lib/onigasm.wasm', to: './node_modules/onigasm/lib/onigasm.wasm' }]) ], resolve: { - alias:{ + alias: { // Pointing pdfkit to a dummy js file so webpack doesn't fall over. // Since pdfkit has been externalized (it gets updated with the valid code by copying the pdfkit files // into the right destination). - 'pdfkit':path.resolve(__dirname, 'pdfkit.js') + pdfkit: path.resolve(__dirname, 'pdfkit.js') }, extensions: ['.js'] }, output: { filename: '[name].js', - path: path.resolve(constants_1.ExtensionRootDir, 'out', 'client'), + path: path.resolve(constants.ExtensionRootDir, 'out', 'client'), libraryTarget: 'commonjs2', devtoolModuleFilenameTemplate: '../../[resource-path]' } diff --git a/build/webpack/webpack.extension.dependencies.config.ts b/build/webpack/webpack.extension.dependencies.config.ts deleted file mode 100644 index bb5b3db31154..000000000000 --- a/build/webpack/webpack.extension.dependencies.config.ts +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -'use strict'; - -// tslint:disable-next-line: no-require-imports -import copyWebpackPlugin = require('copy-webpack-plugin'); -import * as path from 'path'; -import * as webpack from 'webpack'; -import { ExtensionRootDir } from '../constants'; -import { getDefaultPlugins, nodeModulesToExternalize } from './common'; - -const entryItems: Record = {}; -nodeModulesToExternalize.forEach(moduleName => { - entryItems[`node_modules/${moduleName}`] = `./node_modules/${moduleName}`; -}); - -const config: webpack.Configuration = { - mode: 'production', - target: 'node', - entry: entryItems, - devtool: 'source-map', - node: { - __dirname: false - }, - module: { - rules: [ - { - // JupyterServices imports node-fetch. - test: /@jupyterlab[\\\/]services[\\\/].*js$/, - use: [ - { - loader: path.join(__dirname, 'loaders', 'fixNodeFetch.js') - } - ] - }, - {enforce: 'post', test: /unicode-properties[\/\\]index.js$/, loader: 'transform-loader?brfs'}, - {enforce: 'post', test: /fontkit[\/\\]index.js$/, loader: 'transform-loader?brfs'}, - {enforce: 'post', test: /pdfkit[\\\/]js[\\\/].*js$/, loader: 'transform-loader?brfs'}, - {enforce: 'post', test: /linebreak[\/\\]src[\/\\]linebreaker.js/, loader: 'transform-loader?brfs'} - ] - }, - externals: [ - 'vscode', - 'commonjs' - ], - plugins: [ - ...getDefaultPlugins('dependencies'), - // vsls requires our package.json to be next to node_modules. It's how they - // 'find' the calling extension. - new copyWebpackPlugin([ - { from: './package.json', to: '.' } - ]), - // onigasm requires our onigasm.wasm to be in node_modules - new copyWebpackPlugin([ - { from: './node_modules/onigasm/lib/onigasm.wasm', to: './node_modules/onigasm/lib/onigasm.wasm' } - ]) - ], - resolve: { - extensions: ['.js'] - }, - output: { - filename: '[name].js', - path: path.resolve(ExtensionRootDir, 'out', 'client'), - libraryTarget: 'commonjs2', - devtoolModuleFilenameTemplate: '../../[resource-path]' - } -}; - -// tslint:disable-next-line:no-default-export -export default config; From fbb71d23001c6ecb0a867ef02942c17f41ae3b39 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Thu, 2 Jan 2020 12:50:21 -0800 Subject: [PATCH 2/3] News entry --- news/3 Code Health/5674.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/3 Code Health/5674.md diff --git a/news/3 Code Health/5674.md b/news/3 Code Health/5674.md new file mode 100644 index 000000000000..0db2b9d68ef5 --- /dev/null +++ b/news/3 Code Health/5674.md @@ -0,0 +1 @@ +Use `vanillajs` for build scripts (instead of `typescript`, avoids the step of having to trasnpile). From fd9d72525dda23526951b483f7b996ff8a0acc3a Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Thu, 2 Jan 2020 12:53:19 -0800 Subject: [PATCH 3/3] Verify format of js code --- build/ci/templates/jobs/build_compile.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/ci/templates/jobs/build_compile.yml b/build/ci/templates/jobs/build_compile.yml index 214afa27c035..a8f08666a20d 100644 --- a/build/ci/templates/jobs/build_compile.yml +++ b/build/ci/templates/jobs/build_compile.yml @@ -32,3 +32,7 @@ jobs: - bash: npx prettier "src/**/*.ts*" --check displayName: "Code Format" workingDirectory: $(Build.SourcesDirectory) + + - bash: npx prettier "build/**/*.js" --check + displayName: "Code Format" + workingDirectory: $(Build.SourcesDirectory)