From f4f7109055425c4d7860e4e46252f64678b2d253 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Mon, 21 Nov 2022 15:12:56 -0800 Subject: [PATCH] Clean up tsconfigs (#12107) * Explicitly state computeHash type * Remove msrCrypto in favor of native APIs msrCrypto is a polyfill for the native APIs which are well supported in browser and node currently. The module also recommends using native APIs when they are available. Fixes #12023 Part of #11996 * Fix compile issue in webTestReporter.js * Mark node:crypto as an external * Introduce a tsconfig.base.json * Move extension tsconfigs into src and extend base * Simplify tsconfig excludes * require reflect-metadata in smoke tests earlier * Fix types in helper.ts when allowJs is removed * Remove allowJs! * Remove unneeded cast --- .eslintrc.js | 6 +-- .../webpack/webpack.extension.node.config.js | 2 +- build/webpack/webpack.extension.web.config.js | 4 +- src/kernels/telemetry/helper.ts | 12 ++++- src/telemetryGenerator.node.ts | 16 +++--- src/tsconfig.extension.node.json | 18 +++++++ src/tsconfig.extension.web.json | 33 ++++++++++++ .../webview-side/react-common/postOffice.ts | 3 ++ tsconfig.base.json | 30 +++++++++++ tsconfig.extension.node.json | 27 ---------- tsconfig.extension.web.json | 23 -------- tsconfig.json | 52 +++++++------------ 12 files changed, 128 insertions(+), 98 deletions(-) create mode 100644 src/tsconfig.extension.node.json create mode 100644 src/tsconfig.extension.web.json create mode 100644 tsconfig.base.json delete mode 100644 tsconfig.extension.node.json delete mode 100644 tsconfig.extension.web.json diff --git a/.eslintrc.js b/.eslintrc.js index 888c84572db..351edb25c8c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -7,7 +7,7 @@ module.exports = { extends: ['prettier', 'prettier/@typescript-eslint'], ignorePatterns: [ '*.js', - 'vscode.d.ts', + 'vscode.*.d.ts', '**/*.test.ts', 'types', // TODO: Does this file need to be linted? @@ -18,8 +18,8 @@ module.exports = { project: [ 'tsconfig.json', 'tsconfig.datascience-ui.json', - 'tsconfig.extension.node.json', - 'tsconfig.extension.web.json' + 'src/tsconfig.extension.node.json', + 'src/tsconfig.extension.web.json' ], sourceType: 'module' }, diff --git a/build/webpack/webpack.extension.node.config.js b/build/webpack/webpack.extension.node.config.js index f4f35e5b544..70c94339365 100644 --- a/build/webpack/webpack.extension.node.config.js +++ b/build/webpack/webpack.extension.node.config.js @@ -10,7 +10,7 @@ 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.ExtensionRootDir, 'tsconfig.extension.node.json'); +const configFileName = path.join(constants.ExtensionRootDir, 'src/tsconfig.extension.node.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.getListOfExistingModulesInOutDir(); diff --git a/build/webpack/webpack.extension.web.config.js b/build/webpack/webpack.extension.web.config.js index 1bdd7145eec..dd7fa8b2ffe 100644 --- a/build/webpack/webpack.extension.web.config.js +++ b/build/webpack/webpack.extension.web.config.js @@ -21,7 +21,7 @@ const testEntry = { const entry = process.env.VSC_TEST_BUNDLE === 'true' ? testEntry : devEntry; // tslint:disable-next-line:no-var-requires no-require-imports -const configFileName = path.join(constants.ExtensionRootDir, 'tsconfig.extension.web.json'); +const configFileName = path.join(constants.ExtensionRootDir, 'src/tsconfig.extension.web.json'); const config = { mode: process.env.VSC_TEST_BUNDLE ? 'development' : 'none', target: 'webworker', @@ -40,7 +40,7 @@ const config = { { loader: 'ts-loader', options: { - configFile: 'tsconfig.extension.web.json' + configFile: 'src/tsconfig.extension.web.json' } } ] diff --git a/src/kernels/telemetry/helper.ts b/src/kernels/telemetry/helper.ts index 159a891e77f..0691d6131e5 100644 --- a/src/kernels/telemetry/helper.ts +++ b/src/kernels/telemetry/helper.ts @@ -58,7 +58,17 @@ export async function trackKernelResourceInformation( { resourceType: getResourceType(resource), resourceHash: resource ? await getTelemetrySafeHashedString(resource.toString()) : undefined, - kernelSessionId: await getTelemetrySafeHashedString(Date.now().toString()) + kernelSessionId: await getTelemetrySafeHashedString(Date.now().toString()), + capturedEnvVars: undefined, + userExecutedCell: undefined, + disableUI: undefined, + kernelLanguage: undefined, + kernelId: undefined, + isUsingActiveInterpreter: undefined, + pythonEnvironmentType: undefined, + pythonEnvironmentPath: undefined, + pythonEnvironmentVersion: undefined, + kernelConnectionType: undefined }, { previouslySelectedKernelConnectionId: '' } ]; diff --git a/src/telemetryGenerator.node.ts b/src/telemetryGenerator.node.ts index b30215c0030..20053a3bba2 100644 --- a/src/telemetryGenerator.node.ts +++ b/src/telemetryGenerator.node.ts @@ -611,12 +611,15 @@ function isNodeExported(node: ts.Node): boolean { ); } +function getTsCompilerOptionsJson(): any { + const tsconfigPath = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'tsconfig.json'); + const jsonContent = ts.parseConfigFileTextToJson(tsconfigPath, fs.readFileSync(tsconfigPath, 'utf8')); + return ts.convertCompilerOptionsFromJson(jsonContent.config.compilerOptions, ''); +} + /** Generate documentation for all classes in a set of .ts files */ function generateDocumentationForCommonTypes(fileNames: string[]): void { - const configFile = ts.convertCompilerOptionsFromJson( - JSON.parse(fs.readFileSync(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'tsconfig.json'), 'utf8')), - '' - ); + const configFile = getTsCompilerOptionsJson(); const program = ts.createProgram(fileNames, configFile.options); const typeChecker = program!.getTypeChecker(); @@ -653,10 +656,7 @@ function generateDocumentationForCommonTypes(fileNames: string[]): void { } function generateDocumentation(fileNames: string[]): void { - const configFile = ts.convertCompilerOptionsFromJson( - JSON.parse(fs.readFileSync(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'tsconfig.json'), 'utf8')), - '' - ); + const configFile = getTsCompilerOptionsJson(); const host = new TypeScriptLanguageServiceHost(fileNames, configFile.options); const languageService = ts.createLanguageService(host, undefined, ts.LanguageServiceMode.Semantic); const program = languageService.getProgram()!; diff --git a/src/tsconfig.extension.node.json b/src/tsconfig.extension.node.json new file mode 100644 index 00000000000..372cfee0dab --- /dev/null +++ b/src/tsconfig.extension.node.json @@ -0,0 +1,18 @@ +{ + "extends": "../tsconfig.base.json", + "compilerOptions": { + "baseUrl": "..", + "rootDir": ".", + "outDir": "out", + + // Types + "lib": ["es6", "es2018", "ES2019", "ES2020"], + }, + "include": [ + "./**/*" + ], + "exclude": [ + "webviews/webview-side", + "**/*.web.ts" + ] +} diff --git a/src/tsconfig.extension.web.json b/src/tsconfig.extension.web.json new file mode 100644 index 00000000000..8e1dc9133f0 --- /dev/null +++ b/src/tsconfig.extension.web.json @@ -0,0 +1,33 @@ +{ + "extends": "../tsconfig.base.json", + "compilerOptions": { + "baseUrl": "..", + "rootDir": ".", + "outDir": "out", + + // Types + "paths": { + "*": ["types/*"] + }, + "typeRoots": [ + "./node_modules/@types", + ], + "types": [ + // "vscode-notebook-renderer", + "webpack-env" + ], + "lib": ["es6", "es2018", "dom", "ES2019", "ES2020"] + }, + "include": [ + "./**/*", + + // Include all types outside the type roots manually + "../types/slickgrid", + "../vscode.*" + ], + "exclude": [ + "test/datascience/extensionapi", + "*.node.ts", + "**/*.node.ts" + ] +} diff --git a/src/webviews/webview-side/react-common/postOffice.ts b/src/webviews/webview-side/react-common/postOffice.ts index 29e06015138..b538c1f168f 100644 --- a/src/webviews/webview-side/react-common/postOffice.ts +++ b/src/webviews/webview-side/react-common/postOffice.ts @@ -32,6 +32,9 @@ interface IMessageApi { dispose(): void; } +declare var onDidReceiveKernelMessage: KernelMessagingApi['onDidReceiveKernelMessage']; +declare var postKernelMessage: KernelMessagingApi['postKernelMessage']; + // This special function talks to vscode from a web panel export declare function acquireVsCodeApi(): IVsCodeApi; // Provides support for messaging when using the vscode webview messaging api diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 00000000000..4512bd5c3ae --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,30 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es2020", + "jsx": "react", + + // Types + "lib": [], + "types": [], + + // Features/output + "sourceMap": true, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "removeComments": true, + "resolveJsonModule": true, + + // Strictness + "strict": true, + "noImplicitAny": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitOverride": true, + "noFallthroughCasesInSwitch": true, + "useUnknownInCatchVariables": false, + "strictPropertyInitialization": false + } +} diff --git a/tsconfig.extension.node.json b/tsconfig.extension.node.json deleted file mode 100644 index 437a2a4cdcb..00000000000 --- a/tsconfig.extension.node.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - "baseUrl": ".", - "module": "commonjs", - "target": "es2020", - "outDir": "out", - "lib": ["es6", "es2018", "ES2019", "ES2020"], - "jsx": "react", - "sourceMap": true, - "rootDir": "src", - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "useUnknownInCatchVariables": false, - "noImplicitThis": false - }, - "exclude": [ - "node_modules", - ".vscode-test", - ".vscode test", - "src/webviews/webview-side", - "build", - "src/test", - "src/*.web.ts", - "src/**/*.web.ts", - "gulpfile.js" - ] -} diff --git a/tsconfig.extension.web.json b/tsconfig.extension.web.json deleted file mode 100644 index d38644b4081..00000000000 --- a/tsconfig.extension.web.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "paths": { - "*": ["types/*"] - } - }, - "exclude": [ - "node_modules", - ".vscode-test", - ".vscode test", - "src/test/datascience/extensionapi", - "build", - "out", - "tmp", - ".nyc_output", - ".git", - "src/*.node.ts", - "src/**/*.node.ts", - ".vscode-test-web", - "gulpfile.js" - ] -} diff --git a/tsconfig.json b/tsconfig.json index d21f405dc70..37e566c19ed 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,50 +1,36 @@ { + "extends": "./tsconfig.base.json", "compilerOptions": { "baseUrl": ".", + "rootDir": "src", + "outDir": "out", + + // Types "paths": { "*": ["types/*"] }, - "module": "commonjs", - "target": "es2020", - "outDir": "out", + "typeRoots": [ + "./node_modules/@types", + ], + "types": [ + "webpack-env" + ], "lib": ["es6", "es2018", "dom", "ES2019", "ES2020"], - "jsx": "react", - "sourceMap": true, - "rootDir": "src", - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "strict": true, - "noImplicitAny": true, - "noImplicitThis": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noImplicitOverride": true, - "noFallthroughCasesInSwitch": true, - "resolveJsonModule": true, - "removeComments": true, - "useUnknownInCatchVariables": false, - "strictPropertyInitialization": false, - "esModuleInterop": true, - "allowJs": true, - "types": ["@types/vscode-notebook-renderer/preload", "webpack-env"] }, + "include": [ + "./src/**/*", + + // Include all types outside the type roots manually + "./types/slickgrid", + "./vscode.*" + ], "exclude": [ - "node_modules", - ".vscode-test", - ".vscode test", "src/server/node_modules", "src/node_modules", "src/server/src/typings", "src/typings", "src/ipywidgets", "src/smoke", - "src/test/datascience/extensionapi", - "build", - "out", - "ipywidgets", - "tmp", - ".nyc_output", - ".git", - "gulpfile.js" + "src/test/datascience/extensionapi" ] }