Skip to content

Commit

Permalink
Clean up tsconfigs (#12107)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Tyriar authored Nov 21, 2022
1 parent 20701ef commit f4f7109
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 98 deletions.
6 changes: 3 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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'
},
Expand Down
2 changes: 1 addition & 1 deletion build/webpack/webpack.extension.node.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions build/webpack/webpack.extension.web.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -40,7 +40,7 @@ const config = {
{
loader: 'ts-loader',
options: {
configFile: 'tsconfig.extension.web.json'
configFile: 'src/tsconfig.extension.web.json'
}
}
]
Expand Down
12 changes: 11 additions & 1 deletion src/kernels/telemetry/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '' }
];
Expand Down
16 changes: 8 additions & 8 deletions src/telemetryGenerator.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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()!;
Expand Down
18 changes: 18 additions & 0 deletions src/tsconfig.extension.node.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
33 changes: 33 additions & 0 deletions src/tsconfig.extension.web.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
3 changes: 3 additions & 0 deletions src/webviews/webview-side/react-common/postOffice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -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
}
}
27 changes: 0 additions & 27 deletions tsconfig.extension.node.json

This file was deleted.

23 changes: 0 additions & 23 deletions tsconfig.extension.web.json

This file was deleted.

52 changes: 19 additions & 33 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}

0 comments on commit f4f7109

Please sign in to comment.