diff --git a/.eslintrc.js b/.eslintrc.js index 9487f423..2891b5c9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -7,21 +7,21 @@ module.exports = { env: { node: true, browser: true, - es6: true, + es2020: true, }, parserOptions: { sourceType: 'module', - ecmaVersion: 2018, + parser: '@typescript-eslint/parser', }, ignorePatterns: [ '.eslintrc.js', 'lint-staged.config.js', ], - plugins: ['security', 'no-unsanitized', 'eslint-plugin-header', 'import'], + plugins: ['@typescript-eslint', 'security', 'no-unsanitized', 'eslint-plugin-header', 'import'], extends: [ 'eslint:recommended', 'plugin:security/recommended', 'plugin:no-unsanitized/DOM', 'airbnb-base', 'plugin:import/errors', 'plugin:import/warnings', - 'plugin:import/typescript', + 'plugin:import/typescript', 'plugin:@typescript-eslint/recommended', 'airbnb-typescript/base', ], rules: { 'header/header': [2, 'line', [{ @@ -51,5 +51,21 @@ module.exports = { 'security/detect-object-injection': 0, // the rule is relevant for user input data on the node.js environment 'import/order': ['error', {'groups': ['builtin', 'external', 'internal']}], 'import/prefer-default-export': 0, // works incorrect with interfaces + + '@typescript-eslint/no-explicit-any': 0, + '@typescript-eslint/indent': ['error', 4], + '@typescript-eslint/lines-between-class-members': 0, + '@typescript-eslint/explicit-function-return-type': ['warn', { allowExpressions: true }], + '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/ban-types': [ + 'error', + { + types: { + '{}': false, // TODO: try to fix with Record + object: false, // TODO: try to fix with Record + Function: false, // TODO: try to fix somehow + }, + }, + ], }, }; diff --git a/cvat-canvas/.eslintrc.js b/cvat-canvas/.eslintrc.js index b7235422..ab68a033 100644 --- a/cvat-canvas/.eslintrc.js +++ b/cvat-canvas/.eslintrc.js @@ -2,12 +2,7 @@ // // SPDX-License-Identifier: MIT -const globalConfig = require('../.eslintrc.js'); - module.exports = { - env: { - node: true, - }, ignorePatterns: [ '.eslintrc.js', 'webpack.config.js', @@ -15,31 +10,7 @@ module.exports = { 'dist/**', ], parserOptions: { - parser: '@typescript-eslint/parser', - ecmaVersion: 6, project: './tsconfig.json', tsconfigRootDir: __dirname, }, - plugins: ['@typescript-eslint'], - extends: ['plugin:@typescript-eslint/recommended', 'airbnb-typescript/base'], - rules: { - ...globalConfig.rules, - - '@typescript-eslint/no-explicit-any': 0, - '@typescript-eslint/indent': ['error', 4], - '@typescript-eslint/lines-between-class-members': 0, - '@typescript-eslint/no-explicit-any': [0], - '@typescript-eslint/explicit-function-return-type': ['warn', { allowExpressions: true }], - '@typescript-eslint/explicit-module-boundary-types': 'off', - '@typescript-eslint/ban-types': [ - 'error', - { - types: { - '{}': false, // TODO: try to fix with Record - object: false, // TODO: try to fix with Record - Function: false, // TODO: try to fix somehow - }, - }, - ], - }, }; diff --git a/cvat-canvas3d/.eslintrc.js b/cvat-canvas3d/.eslintrc.js index aebc7229..144b2c30 100644 --- a/cvat-canvas3d/.eslintrc.js +++ b/cvat-canvas3d/.eslintrc.js @@ -2,15 +2,8 @@ // // SPDX-License-Identifier: MIT -const globalConfig = require('../.eslintrc.js'); - module.exports = { - env: { - node: true, - }, parserOptions: { - parser: '@typescript-eslint/parser', - ecmaVersion: 6, project: './tsconfig.json', tsconfigRootDir: __dirname, }, @@ -20,26 +13,4 @@ module.exports = { 'node_modules/**', 'dist/**', ], - plugins: ['@typescript-eslint'], - extends: ['plugin:@typescript-eslint/recommended', 'airbnb-typescript/base'], - rules: { - ...globalConfig.rules, - - '@typescript-eslint/no-explicit-any': 0, - '@typescript-eslint/indent': ['error', 4], - '@typescript-eslint/lines-between-class-members': 0, - '@typescript-eslint/no-explicit-any': [0], - '@typescript-eslint/explicit-function-return-type': ['warn', { allowExpressions: true }], - '@typescript-eslint/explicit-module-boundary-types': 'off', - '@typescript-eslint/ban-types': [ - 'error', - { - types: { - '{}': false, // TODO: try to fix with Record - object: false, // TODO: try to fix with Record - Function: false, // TODO: try to fix somehow - }, - }, - ], - }, }; diff --git a/cvat-core/.eslintrc.js b/cvat-core/.eslintrc.js index 76c8aea4..1a036f8d 100644 --- a/cvat-core/.eslintrc.js +++ b/cvat-core/.eslintrc.js @@ -4,9 +4,6 @@ module.exports = { env: { - node: true, - browser: true, - es6: true, 'jest/globals': true, }, ignorePatterns: [ @@ -19,9 +16,8 @@ module.exports = { 'dist/**', ], parserOptions: { - parser: 'babel-eslint', - sourceType: 'module', - ecmaVersion: 2018, + project: './tsconfig.json', + tsconfigRootDir: __dirname, }, plugins: ['jest'], rules: { @@ -29,5 +25,5 @@ module.exports = { 'jest/no-focused-tests': 'error', 'jest/no-identical-title': 'error', 'jest/prefer-to-have-length': 'warn', - } + } }; diff --git a/cvat-core/package.json b/cvat-core/package.json index fddf989d..fbc8a269 100644 --- a/cvat-core/package.json +++ b/cvat-core/package.json @@ -2,12 +2,14 @@ "name": "cvat-core", "version": "5.1.0", "description": "Part of Computer Vision Tool which presents an interface for client-side integration", - "main": "babel.config.js", + "main": "src/api.ts", "scripts": { "build": "webpack", "test": "jest --config=jest.config.js --coverage", "docs": "jsdoc --readme README.md src/*.js -p -c jsdoc.config.js -d docs", - "coveralls": "cat ./reports/coverage/lcov.info | coveralls" + "coveralls": "cat ./reports/coverage/lcov.info | coveralls", + "type-check": "tsc --noEmit", + "type-check:watch": "npm run type-check -- --watch" }, "author": "Intel", "license": "MIT", @@ -26,7 +28,7 @@ "dependencies": { "axios": "^0.21.4", "browser-or-node": "^1.2.1", - "cvat-data": "../cvat-data", + "cvat-data": "file:../cvat-data", "detect-browser": "^5.2.1", "error-stack-parser": "^2.0.2", "form-data": "^2.5.0", diff --git a/cvat-core/src/annotation-formats.js b/cvat-core/src/annotation-formats.ts similarity index 100% rename from cvat-core/src/annotation-formats.js rename to cvat-core/src/annotation-formats.ts diff --git a/cvat-core/src/annotations-collection.js b/cvat-core/src/annotations-collection.ts similarity index 100% rename from cvat-core/src/annotations-collection.js rename to cvat-core/src/annotations-collection.ts diff --git a/cvat-core/src/annotations-filter.js b/cvat-core/src/annotations-filter.ts similarity index 100% rename from cvat-core/src/annotations-filter.js rename to cvat-core/src/annotations-filter.ts diff --git a/cvat-core/src/annotations-history.js b/cvat-core/src/annotations-history.ts similarity index 100% rename from cvat-core/src/annotations-history.js rename to cvat-core/src/annotations-history.ts diff --git a/cvat-core/src/annotations-objects.js b/cvat-core/src/annotations-objects.ts similarity index 100% rename from cvat-core/src/annotations-objects.js rename to cvat-core/src/annotations-objects.ts diff --git a/cvat-core/src/annotations-saver.js b/cvat-core/src/annotations-saver.ts similarity index 100% rename from cvat-core/src/annotations-saver.js rename to cvat-core/src/annotations-saver.ts diff --git a/cvat-core/src/annotations.js b/cvat-core/src/annotations.ts similarity index 100% rename from cvat-core/src/annotations.js rename to cvat-core/src/annotations.ts diff --git a/cvat-core/src/api-implementation.js b/cvat-core/src/api-implementation.ts similarity index 100% rename from cvat-core/src/api-implementation.js rename to cvat-core/src/api-implementation.ts diff --git a/cvat-core/src/api.js b/cvat-core/src/api.ts similarity index 100% rename from cvat-core/src/api.js rename to cvat-core/src/api.ts diff --git a/cvat-core/src/cloud-storage.js b/cvat-core/src/cloud-storage.ts similarity index 100% rename from cvat-core/src/cloud-storage.js rename to cvat-core/src/cloud-storage.ts diff --git a/cvat-core/src/comment.js b/cvat-core/src/comment.ts similarity index 100% rename from cvat-core/src/comment.js rename to cvat-core/src/comment.ts diff --git a/cvat-core/src/common.js b/cvat-core/src/common.ts similarity index 100% rename from cvat-core/src/common.js rename to cvat-core/src/common.ts diff --git a/cvat-core/src/config.js b/cvat-core/src/config.ts similarity index 100% rename from cvat-core/src/config.js rename to cvat-core/src/config.ts diff --git a/cvat-core/src/enums.js b/cvat-core/src/enums.ts similarity index 100% rename from cvat-core/src/enums.js rename to cvat-core/src/enums.ts diff --git a/cvat-core/src/exceptions.js b/cvat-core/src/exceptions.ts similarity index 100% rename from cvat-core/src/exceptions.js rename to cvat-core/src/exceptions.ts diff --git a/cvat-core/src/frames.js b/cvat-core/src/frames.ts similarity index 100% rename from cvat-core/src/frames.js rename to cvat-core/src/frames.ts diff --git a/cvat-core/src/issue.js b/cvat-core/src/issue.ts similarity index 100% rename from cvat-core/src/issue.js rename to cvat-core/src/issue.ts diff --git a/cvat-core/src/labels.js b/cvat-core/src/labels.ts similarity index 100% rename from cvat-core/src/labels.js rename to cvat-core/src/labels.ts diff --git a/cvat-core/src/lambda-manager.js b/cvat-core/src/lambda-manager.ts similarity index 100% rename from cvat-core/src/lambda-manager.js rename to cvat-core/src/lambda-manager.ts diff --git a/cvat-core/src/log.js b/cvat-core/src/log.ts similarity index 100% rename from cvat-core/src/log.js rename to cvat-core/src/log.ts diff --git a/cvat-core/src/logger-storage.js b/cvat-core/src/logger-storage.ts similarity index 100% rename from cvat-core/src/logger-storage.js rename to cvat-core/src/logger-storage.ts diff --git a/cvat-core/src/ml-model.js b/cvat-core/src/ml-model.ts similarity index 100% rename from cvat-core/src/ml-model.js rename to cvat-core/src/ml-model.ts diff --git a/cvat-core/src/object-state.js b/cvat-core/src/object-state.ts similarity index 100% rename from cvat-core/src/object-state.js rename to cvat-core/src/object-state.ts diff --git a/cvat-core/src/organization.js b/cvat-core/src/organization.ts similarity index 100% rename from cvat-core/src/organization.js rename to cvat-core/src/organization.ts diff --git a/cvat-core/src/plugins.js b/cvat-core/src/plugins.ts similarity index 100% rename from cvat-core/src/plugins.js rename to cvat-core/src/plugins.ts diff --git a/cvat-core/src/project-implementation.js b/cvat-core/src/project-implementation.ts similarity index 100% rename from cvat-core/src/project-implementation.js rename to cvat-core/src/project-implementation.ts diff --git a/cvat-core/src/project.js b/cvat-core/src/project.ts similarity index 100% rename from cvat-core/src/project.js rename to cvat-core/src/project.ts diff --git a/cvat-core/src/server-proxy.js b/cvat-core/src/server-proxy.ts similarity index 100% rename from cvat-core/src/server-proxy.js rename to cvat-core/src/server-proxy.ts diff --git a/cvat-core/src/session.js b/cvat-core/src/session.ts similarity index 100% rename from cvat-core/src/session.js rename to cvat-core/src/session.ts diff --git a/cvat-core/src/statistics.js b/cvat-core/src/statistics.ts similarity index 100% rename from cvat-core/src/statistics.js rename to cvat-core/src/statistics.ts diff --git a/cvat-core/src/user.js b/cvat-core/src/user.ts similarity index 100% rename from cvat-core/src/user.js rename to cvat-core/src/user.ts diff --git a/cvat-core/tsconfig.json b/cvat-core/tsconfig.json new file mode 100644 index 00000000..036d7e73 --- /dev/null +++ b/cvat-core/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "es2020", + "allowJs": true, + "module": "commonjs", + "moduleResolution": "node", + "esModuleInterop": true, + "isolatedModules": true, + "noEmit": true, + "baseUrl": "src", + }, + "include": ["src/*.ts"] +} diff --git a/cvat-core/webpack.config.js b/cvat-core/webpack.config.js index d98d1936..24098cf8 100644 --- a/cvat-core/webpack.config.js +++ b/cvat-core/webpack.config.js @@ -12,17 +12,31 @@ const nodeConfig = { target: 'node', mode: 'development', devtool: 'source-map', - entry: './src/api.js', + entry: './src/api.ts', output: { path: path.resolve(__dirname, 'dist'), filename: 'cvat-core.node.js', libraryTarget: 'commonjs', }, + resolve: { + extensions: ['.ts', '.js'], + }, module: { rules: [ { - test: /.js?$/, + test: /.ts?$/, exclude: /node_modules/, + use: { + loader: 'babel-loader', + options: { + plugins: [ + '@babel/plugin-proposal-class-properties', + '@babel/plugin-proposal-optional-chaining', + ], + presets: ['@babel/preset-env', '@babel/typescript'], + sourceType: 'unambiguous', + }, + }, }, ], }, @@ -36,7 +50,7 @@ const webConfig = { mode: 'production', devtool: 'source-map', entry: { - 'cvat-core': './src/api.js', + 'cvat-core': './src/api.ts', }, output: { path: path.resolve(__dirname, 'dist'), @@ -44,15 +58,22 @@ const webConfig = { library: 'cvat', libraryTarget: 'window', }, + resolve: { + extensions: ['.ts', '.js'], + }, module: { rules: [ { - test: /.js?$/, + test: /.ts?$/, exclude: /node_modules/, use: { loader: 'babel-loader', options: { - presets: ['@babel/preset-env'], + plugins: [ + '@babel/plugin-proposal-class-properties', + '@babel/plugin-proposal-optional-chaining', + ], + presets: ['@babel/preset-env', '@babel/typescript'], sourceType: 'unambiguous', }, }, diff --git a/cvat-data/.eslintrc.js b/cvat-data/.eslintrc.js index 1a8f6be0..3aa39c7d 100644 --- a/cvat-data/.eslintrc.js +++ b/cvat-data/.eslintrc.js @@ -3,10 +3,16 @@ // SPDX-License-Identifier: MIT module.exports = { + ignorePatterns: [ + '.eslintrc.js', + 'webpack.config.js', + 'src/3rdparty/**', + 'node_modules/**', + 'dist/**', + ], parserOptions: { - parser: 'babel-eslint', - sourceType: 'module', - ecmaVersion: 2018, + project: './tsconfig.json', + tsconfigRootDir: __dirname, }, - ignorePatterns: ['.eslintrc.js', 'webpack.config.js', 'src/3rdparty/**', 'node_modules/**', 'dist/**'], + plugins: ['jest'], }; diff --git a/cvat-data/package.json b/cvat-data/package.json index eae7762a..77f4d53f 100644 --- a/cvat-data/package.json +++ b/cvat-data/package.json @@ -2,11 +2,13 @@ "name": "cvat-data", "version": "1.0.2", "description": "", - "main": "src/js/cvat-data.js", + "main": "src/ts/cvat-data.ts", "scripts": { - "patch": "cd src/js && patch --dry-run --forward -p0 < 3rdparty_patch.diff >> /dev/null && patch -p0 < 3rdparty_patch.diff; true", + "patch": "cd src/ts && patch --dry-run --forward -p0 < 3rdparty_patch.diff >> /dev/null && patch -p0 < 3rdparty_patch.diff; true", "build": "npm run patch; webpack --config ./webpack.config.js", - "server": "npm run patch; nodemon --watch config --exec 'webpack-dev-server --config ./webpack.config.js --mode=development --open'" + "server": "npm run patch; nodemon --watch config --exec 'webpack-dev-server --config ./webpack.config.js --mode=development --open'", + "type-check": "tsc --noEmit", + "type-check:watch": "npm run type-check -- --watch" }, "author": "Intel", "license": "MIT", diff --git a/cvat-data/src/js/3rdparty/Decoder.js b/cvat-data/src/ts/3rdparty/Decoder.js similarity index 100% rename from cvat-data/src/js/3rdparty/Decoder.js rename to cvat-data/src/ts/3rdparty/Decoder.js diff --git a/cvat-data/src/js/3rdparty/Decoder.worker.js b/cvat-data/src/ts/3rdparty/Decoder.worker.js similarity index 100% rename from cvat-data/src/js/3rdparty/Decoder.worker.js rename to cvat-data/src/ts/3rdparty/Decoder.worker.js diff --git a/cvat-data/src/js/3rdparty/README.md b/cvat-data/src/ts/3rdparty/README.md similarity index 100% rename from cvat-data/src/js/3rdparty/README.md rename to cvat-data/src/ts/3rdparty/README.md diff --git a/cvat-data/src/js/3rdparty/avc.wasm b/cvat-data/src/ts/3rdparty/avc.wasm similarity index 100% rename from cvat-data/src/js/3rdparty/avc.wasm rename to cvat-data/src/ts/3rdparty/avc.wasm diff --git a/cvat-data/src/js/3rdparty/mp4.js b/cvat-data/src/ts/3rdparty/mp4.js similarity index 100% rename from cvat-data/src/js/3rdparty/mp4.js rename to cvat-data/src/ts/3rdparty/mp4.js diff --git a/cvat-data/src/js/3rdparty_patch.diff b/cvat-data/src/ts/3rdparty_patch.diff similarity index 100% rename from cvat-data/src/js/3rdparty_patch.diff rename to cvat-data/src/ts/3rdparty_patch.diff diff --git a/cvat-data/src/js/cvat-data.js b/cvat-data/src/ts/cvat-data.ts similarity index 100% rename from cvat-data/src/js/cvat-data.js rename to cvat-data/src/ts/cvat-data.ts diff --git a/cvat-data/src/js/unzip_imgs.worker.js b/cvat-data/src/ts/unzip_imgs.worker.js similarity index 100% rename from cvat-data/src/js/unzip_imgs.worker.js rename to cvat-data/src/ts/unzip_imgs.worker.js diff --git a/cvat-data/tsconfig.json b/cvat-data/tsconfig.json new file mode 100644 index 00000000..036d7e73 --- /dev/null +++ b/cvat-data/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "es2020", + "allowJs": true, + "module": "commonjs", + "moduleResolution": "node", + "esModuleInterop": true, + "isolatedModules": true, + "noEmit": true, + "baseUrl": "src", + }, + "include": ["src/*.ts"] +} diff --git a/cvat-data/webpack.config.js b/cvat-data/webpack.config.js index 386e17e5..71f8663f 100644 --- a/cvat-data/webpack.config.js +++ b/cvat-data/webpack.config.js @@ -13,7 +13,7 @@ const cvatData = { target: 'web', mode: 'production', entry: { - 'cvat-data': './src/js/cvat-data.js', + 'cvat-data': './src/js/cvat-data.ts', }, output: { path: path.resolve(__dirname, 'dist'), @@ -21,15 +21,22 @@ const cvatData = { library: 'cvatData', libraryTarget: 'window', }, + resolve: { + extensions: ['.ts', '.js'], + }, module: { rules: [ { - test: /.js?$/, + test: /.ts?$/, exclude: /node_modules/, use: { loader: 'babel-loader', options: { - presets: ['@babel/preset-env'], + plugins: [ + '@babel/plugin-proposal-class-properties', + '@babel/plugin-proposal-optional-chaining', + ], + presets: ['@babel/preset-env', '@babel/typescript'], sourceType: 'unambiguous', }, }, diff --git a/cvat-ui/.eslintrc.js b/cvat-ui/.eslintrc.js index 6d8abb27..01fb3aea 100644 --- a/cvat-ui/.eslintrc.js +++ b/cvat-ui/.eslintrc.js @@ -5,12 +5,7 @@ const globalConfig = require('../.eslintrc.js'); module.exports = { - env: { - node: true, - }, parserOptions: { - parser: '@typescript-eslint/parser', - ecmaVersion: 6, project: './tsconfig.json', tsconfigRootDir: __dirname, }, @@ -20,27 +15,9 @@ module.exports = { 'node_modules/**', 'dist/**', ], - plugins: ['@typescript-eslint'], - extends: ['plugin:@typescript-eslint/recommended', 'airbnb-typescript'], + extends: ['airbnb-typescript'], rules: { - ...globalConfig.rules, - - '@typescript-eslint/no-explicit-any': 0, - '@typescript-eslint/indent': ['error', 4], - '@typescript-eslint/lines-between-class-members': 0, - '@typescript-eslint/no-explicit-any': [0], - '@typescript-eslint/explicit-function-return-type': ['warn', { allowExpressions: true }], - '@typescript-eslint/explicit-module-boundary-types': 'off', - '@typescript-eslint/ban-types': [ - 'error', - { - types: { - '{}': false, // TODO: try to fix with Record - object: false, // TODO: try to fix with Record - Function: false, // TODO: try to fix somehow - }, - }, - ], + ...globalConfig.rules, // need to import rules again because they've been redefined by "airbnb-typescript" 'react/no-did-update-set-state': 0, // https://github.com/airbnb/javascript/issues/1875 'react/require-default-props': 'off', @@ -52,11 +29,4 @@ module.exports = { 'react/jsx-props-no-spreading': 0, 'jsx-quotes': ['error', 'prefer-single'], }, - // settings: { - // 'import/resolver': { - // node: { - // paths: ['src', `${__dirname}/src`], - // }, - // }, - // }, }; diff --git a/cvat-ui/webpack.config.js b/cvat-ui/webpack.config.js index f2686ecd..9c8b9485 100644 --- a/cvat-ui/webpack.config.js +++ b/cvat-ui/webpack.config.js @@ -146,7 +146,7 @@ module.exports = (env) => ({ new CopyPlugin({ patterns: [ { - from: '../cvat-data/src/js/3rdparty/avc.wasm', + from: '../cvat-data/src/ts/3rdparty/avc.wasm', to: 'assets/3rdparty/', }, ],