mirror of https://github.com/opensumi/core
chore: make pre-commit great again (#115)
* chore: add prettier lint-staged * chore: update husky to v7 * chore: remove unused config * chore(prettier): 更新 printWidth * chore: add eslint * chore: update prettierrc
This commit is contained in:
parent
89129f7618
commit
1fa26c5db6
|
@ -0,0 +1,11 @@
|
|||
node_modules
|
||||
|
||||
**/tools/workspaces/**
|
||||
**/tools/extensions/**
|
||||
**/tools/**/vendor/
|
||||
tools/cli-engine/src/browser/worker-host.js
|
||||
|
||||
**/typings/**
|
||||
**/scripts/**
|
||||
packages/*/lib/**
|
||||
packages/*/dist/**
|
382
.eslintrc.js
382
.eslintrc.js
|
@ -1,241 +1,147 @@
|
|||
/*
|
||||
👋 Hi! This file was autogenerated by tslint-to-eslint-config.
|
||||
https://github.com/typescript-eslint/tslint-to-eslint-config
|
||||
|
||||
It represents the closest reasonable ESLint configuration to this
|
||||
project's original TSLint configuration.
|
||||
|
||||
We recommend eventually switching this configuration to extend from
|
||||
the recommended rulesets in typescript-eslint.
|
||||
https://github.com/typescript-eslint/tslint-to-eslint-config/blob/master/docs/FAQs.md
|
||||
|
||||
Happy linting! 💖
|
||||
*/
|
||||
module.exports = {
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"project": "tsconfig.json",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"eslint-plugin-jsdoc",
|
||||
"eslint-plugin-prefer-arrow",
|
||||
"eslint-plugin-import",
|
||||
"@typescript-eslint",
|
||||
"@typescript-eslint/tslint"
|
||||
env: {
|
||||
browser: true,
|
||||
es6: true,
|
||||
node: true,
|
||||
},
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint'],
|
||||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
|
||||
rules: {
|
||||
'@typescript-eslint/adjacent-overload-signatures': 'error',
|
||||
'@typescript-eslint/array-type': 'off',
|
||||
'@typescript-eslint/consistent-type-assertions': 'error',
|
||||
'@typescript-eslint/consistent-type-definitions': 'error',
|
||||
'@typescript-eslint/dot-notation': 'off',
|
||||
'@typescript-eslint/explicit-member-accessibility': [
|
||||
'off',
|
||||
{
|
||||
accessibility: 'explicit',
|
||||
},
|
||||
],
|
||||
"rules": {
|
||||
"@typescript-eslint/adjacent-overload-signatures": "error",
|
||||
"@typescript-eslint/array-type": "off",
|
||||
"@typescript-eslint/ban-types": [
|
||||
"error",
|
||||
{
|
||||
"types": {
|
||||
"Object": {
|
||||
"message": "Avoid using the `Object` type. Did you mean `object`?"
|
||||
},
|
||||
"Function": {
|
||||
"message": "Avoid using the `Function` type. Prefer a specific function type, like `() => void`."
|
||||
},
|
||||
"Boolean": {
|
||||
"message": "Avoid using the `Boolean` type. Did you mean `boolean`?"
|
||||
},
|
||||
"Number": {
|
||||
"message": "Avoid using the `Number` type. Did you mean `number`?"
|
||||
},
|
||||
"String": {
|
||||
"message": "Avoid using the `String` type. Did you mean `string`?"
|
||||
},
|
||||
"Symbol": {
|
||||
"message": "Avoid using the `Symbol` type. Did you mean `symbol`?"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/consistent-type-assertions": "error",
|
||||
"@typescript-eslint/consistent-type-definitions": "error",
|
||||
"@typescript-eslint/dot-notation": "off",
|
||||
"@typescript-eslint/explicit-member-accessibility": [
|
||||
"off",
|
||||
{
|
||||
"accessibility": "explicit"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/indent": [
|
||||
"error",
|
||||
4,
|
||||
{
|
||||
"FunctionDeclaration": {
|
||||
"parameters": "first"
|
||||
},
|
||||
"FunctionExpression": {
|
||||
"parameters": "first"
|
||||
}
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/member-delimiter-style": [
|
||||
"error",
|
||||
{
|
||||
"multiline": {
|
||||
"delimiter": "semi",
|
||||
"requireLast": true
|
||||
},
|
||||
"singleline": {
|
||||
"delimiter": "semi",
|
||||
"requireLast": false
|
||||
}
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/member-ordering": "off",
|
||||
"@typescript-eslint/naming-convention": "error",
|
||||
"@typescript-eslint/no-empty-function": "off",
|
||||
"@typescript-eslint/no-empty-interface": "error",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-misused-new": "error",
|
||||
"@typescript-eslint/no-namespace": "off",
|
||||
"@typescript-eslint/no-parameter-properties": "off",
|
||||
"@typescript-eslint/no-shadow": [
|
||||
"off",
|
||||
{
|
||||
"hoist": "all"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/no-unused-expressions": "off",
|
||||
"@typescript-eslint/no-use-before-define": "off",
|
||||
"@typescript-eslint/no-var-requires": "off",
|
||||
"@typescript-eslint/prefer-for-of": "error",
|
||||
"@typescript-eslint/prefer-function-type": "error",
|
||||
"@typescript-eslint/prefer-namespace-keyword": "error",
|
||||
"@typescript-eslint/quotes": [
|
||||
"error",
|
||||
"single",
|
||||
{
|
||||
"avoidEscape": true
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/semi": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"@typescript-eslint/triple-slash-reference": [
|
||||
"error",
|
||||
{
|
||||
"path": "always",
|
||||
"types": "prefer-import",
|
||||
"lib": "always"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/type-annotation-spacing": "error",
|
||||
"@typescript-eslint/unified-signatures": "error",
|
||||
"arrow-body-style": "error",
|
||||
"arrow-parens": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"brace-style": [
|
||||
"error",
|
||||
"1tbs"
|
||||
],
|
||||
"comma-dangle": [
|
||||
"error",
|
||||
"always-multiline"
|
||||
],
|
||||
"complexity": "off",
|
||||
"constructor-super": "error",
|
||||
"curly": "error",
|
||||
"eol-last": "error",
|
||||
"eqeqeq": [
|
||||
"error",
|
||||
"smart"
|
||||
],
|
||||
"guard-for-in": "error",
|
||||
"id-blacklist": [
|
||||
"error",
|
||||
"any",
|
||||
"Number",
|
||||
"number",
|
||||
"String",
|
||||
"string",
|
||||
"Boolean",
|
||||
"boolean",
|
||||
"Undefined",
|
||||
"undefined"
|
||||
],
|
||||
"id-match": "error",
|
||||
"import/order": "off",
|
||||
"jsdoc/check-alignment": "off",
|
||||
"jsdoc/check-indentation": "off",
|
||||
"jsdoc/newline-after-description": "off",
|
||||
"max-classes-per-file": "off",
|
||||
"max-len": "off",
|
||||
"new-parens": "error",
|
||||
"no-bitwise": "off",
|
||||
"no-caller": "error",
|
||||
"no-cond-assign": "off",
|
||||
"no-console": "off",
|
||||
"no-debugger": "error",
|
||||
"no-empty": "off",
|
||||
"no-eval": "off",
|
||||
"no-fallthrough": "off",
|
||||
"no-invalid-this": "off",
|
||||
"no-multiple-empty-lines": "error",
|
||||
"no-new-wrappers": "error",
|
||||
"no-throw-literal": "error",
|
||||
"no-trailing-spaces": "error",
|
||||
"no-undef-init": "error",
|
||||
"no-underscore-dangle": "error",
|
||||
"no-unsafe-finally": "error",
|
||||
"no-unused-labels": "error",
|
||||
"no-var": "error",
|
||||
"object-shorthand": "error",
|
||||
"one-var": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"prefer-arrow/prefer-arrow-functions": "off",
|
||||
"prefer-const": "error",
|
||||
"quote-props": "off",
|
||||
"radix": "error",
|
||||
"space-before-function-paren": [
|
||||
"error",
|
||||
{
|
||||
"anonymous": "never",
|
||||
"asyncArrow": "always",
|
||||
"named": "never"
|
||||
}
|
||||
],
|
||||
"spaced-comment": [
|
||||
"error",
|
||||
"always",
|
||||
{
|
||||
"markers": [
|
||||
"/"
|
||||
]
|
||||
}
|
||||
],
|
||||
"use-isnan": "error",
|
||||
"valid-typeof": "off",
|
||||
"@typescript-eslint/tslint/config": [
|
||||
"error",
|
||||
{
|
||||
"rules": {
|
||||
"import-spacing": true,
|
||||
"whitespace": [
|
||||
true,
|
||||
"check-branch",
|
||||
"check-decl",
|
||||
"check-operator",
|
||||
"check-separator",
|
||||
"check-type",
|
||||
"check-typecast"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
'@typescript-eslint/member-delimiter-style': [
|
||||
'error',
|
||||
{
|
||||
multiline: {
|
||||
delimiter: 'semi',
|
||||
requireLast: true,
|
||||
},
|
||||
singleline: {
|
||||
delimiter: 'semi',
|
||||
requireLast: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/member-ordering': 'off',
|
||||
'@typescript-eslint/naming-convention': 'off',
|
||||
'@typescript-eslint/no-empty-function': 'off',
|
||||
'@typescript-eslint/no-empty-interface': 'error',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-misused-new': 'error',
|
||||
'@typescript-eslint/no-namespace': 'off',
|
||||
'@typescript-eslint/no-parameter-properties': 'off',
|
||||
'@typescript-eslint/no-shadow': [
|
||||
'off',
|
||||
{
|
||||
hoist: 'all',
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/no-unused-expressions': 'off',
|
||||
'@typescript-eslint/no-use-before-define': 'off',
|
||||
'@typescript-eslint/no-var-requires': 'off',
|
||||
'@typescript-eslint/prefer-for-of': 'error',
|
||||
'@typescript-eslint/prefer-function-type': 'error',
|
||||
'@typescript-eslint/prefer-namespace-keyword': 'error',
|
||||
'@typescript-eslint/quotes': [
|
||||
'error',
|
||||
'single',
|
||||
{
|
||||
avoidEscape: true,
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/semi': ['error', 'always'],
|
||||
'@typescript-eslint/triple-slash-reference': [
|
||||
'error',
|
||||
{
|
||||
path: 'always',
|
||||
types: 'prefer-import',
|
||||
lib: 'always',
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/type-annotation-spacing': 'error',
|
||||
'@typescript-eslint/unified-signatures': 'error',
|
||||
'arrow-body-style': 'error',
|
||||
'arrow-parens': ['error', 'always'],
|
||||
'brace-style': ['error', '1tbs'],
|
||||
'comma-dangle': ['error', 'always-multiline'],
|
||||
complexity: 'off',
|
||||
'constructor-super': 'error',
|
||||
curly: 'error',
|
||||
'eol-last': 'error',
|
||||
eqeqeq: ['error', 'smart'],
|
||||
'guard-for-in': 'error',
|
||||
'id-blacklist': [
|
||||
'error',
|
||||
'any',
|
||||
'Number',
|
||||
'number',
|
||||
'String',
|
||||
'string',
|
||||
'Boolean',
|
||||
'boolean',
|
||||
'Undefined',
|
||||
'undefined',
|
||||
],
|
||||
'id-match': 'error',
|
||||
'import/order': 'off',
|
||||
'jsdoc/check-alignment': 'off',
|
||||
'jsdoc/check-indentation': 'off',
|
||||
'jsdoc/newline-after-description': 'off',
|
||||
'max-classes-per-file': 'off',
|
||||
'max-len': 'off',
|
||||
'new-parens': 'error',
|
||||
'no-bitwise': 'off',
|
||||
'no-caller': 'error',
|
||||
'no-cond-assign': 'off',
|
||||
'no-console': 'off',
|
||||
'no-debugger': 'error',
|
||||
// We strongly recommend that you do not use the no-undef lint rule on TypeScript projects.
|
||||
// The checks it provides are already provided by TypeScript without the need for configuration
|
||||
// TypeScript just does this significantly better.
|
||||
'no-undef': 'off',
|
||||
'no-empty': 'off',
|
||||
'no-eval': 'off',
|
||||
'no-fallthrough': 'off',
|
||||
'no-invalid-this': 'off',
|
||||
'no-multiple-empty-lines': 'error',
|
||||
'no-new-wrappers': 'error',
|
||||
'no-throw-literal': 'error',
|
||||
'no-trailing-spaces': 'error',
|
||||
'no-undef-init': 'error',
|
||||
'no-unsafe-finally': 'error',
|
||||
'no-unused-labels': 'error',
|
||||
'object-shorthand': 'error',
|
||||
'one-var': ['error', 'never'],
|
||||
'prefer-arrow/prefer-arrow-functions': 'off',
|
||||
'prefer-const': 'error',
|
||||
'quote-props': 'off',
|
||||
radix: 'error',
|
||||
'space-before-function-paren': [
|
||||
'error',
|
||||
{
|
||||
anonymous: 'never',
|
||||
asyncArrow: 'always',
|
||||
named: 'never',
|
||||
},
|
||||
],
|
||||
'spaced-comment': [
|
||||
'error',
|
||||
'always',
|
||||
{
|
||||
markers: ['/'],
|
||||
},
|
||||
],
|
||||
'use-isnan': 'error',
|
||||
'valid-typeof': 'off',
|
||||
},
|
||||
};
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npx commitlint --edit $1
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npm run clean:cache
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npm run clean:cache
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npx lint-staged
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npm run clean:cache
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"jsxSingleQuote": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all",
|
||||
"printWidth": 120,
|
||||
"proseWrap": "never",
|
||||
"endOfLine": "lf"
|
||||
}
|
|
@ -2,10 +2,7 @@ const { pathsToModuleNameMapper } = require('ts-jest');
|
|||
const tsconfig = require('./configs/ts/tsconfig.resolve.json');
|
||||
const os = require('os');
|
||||
|
||||
const tsModuleNameMapper = pathsToModuleNameMapper(
|
||||
tsconfig.compilerOptions.paths,
|
||||
{ prefix: '<rootDir>/configs/' },
|
||||
)
|
||||
const tsModuleNameMapper = pathsToModuleNameMapper(tsconfig.compilerOptions.paths, { prefix: '<rootDir>/configs/' });
|
||||
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
|
@ -13,21 +10,19 @@ module.exports = {
|
|||
testEnvironment: 'node',
|
||||
coverageProvider: process.env.JEST_COVERAGE_PROVIDER || 'babel',
|
||||
maxWorkers: process.env.SIGMA_MAX_PROCESSORS_LIMIT || os.cpus().length,
|
||||
setupFiles: [
|
||||
"./jest.setup.js"
|
||||
],
|
||||
setupFiles: ['./jest.setup.js'],
|
||||
collectCoverageFrom: [
|
||||
"packages/*/src/**/*.ts",
|
||||
"!packages/**/*.contribution.ts",
|
||||
'packages/*/src/**/*.ts',
|
||||
'!packages/**/*.contribution.ts',
|
||||
// 部分contribution文件为-contribution结尾
|
||||
"!packages/**/*-contribution.ts",
|
||||
"!packages/startup/**/*.ts",
|
||||
"!packages/core-electron-main/**/*.ts",
|
||||
"!packages/*/src/electron-main/**/*.ts",
|
||||
'!packages/**/*-contribution.ts',
|
||||
'!packages/startup/**/*.ts',
|
||||
'!packages/core-electron-main/**/*.ts',
|
||||
'!packages/*/src/electron-main/**/*.ts',
|
||||
],
|
||||
moduleNameMapper: {
|
||||
...tsModuleNameMapper,
|
||||
'.*\\.(css|less)$': '<rootDir>/tools/dev-tool/src/mock-exports.js'
|
||||
'.*\\.(css|less)$': '<rootDir>/tools/dev-tool/src/mock-exports.js',
|
||||
},
|
||||
testPathIgnorePatterns: [
|
||||
'/dist/',
|
||||
|
@ -47,9 +42,7 @@ module.exports = {
|
|||
// 后续统一至 @opensumi/ide-utils 模块
|
||||
'/packages/components/src/utils',
|
||||
],
|
||||
modulePathIgnorePatterns: [
|
||||
"<rootDir>/dist/",
|
||||
],
|
||||
modulePathIgnorePatterns: ['<rootDir>/dist/'],
|
||||
coveragePathIgnorePatterns: [
|
||||
'/dist/',
|
||||
'/node_modules/',
|
||||
|
@ -64,13 +57,13 @@ module.exports = {
|
|||
// 后续统一至 @opensumi/ide-utils 模块
|
||||
'/packages/components/src/utils',
|
||||
],
|
||||
testMatch: [ "**/__tests__/**/*.test.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)" ],
|
||||
testMatch: ['**/__tests__/**/*.test.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
|
||||
coverageThreshold: {
|
||||
global: {
|
||||
branches: 0,
|
||||
functions: 0,
|
||||
lines: 0,
|
||||
statements: 0
|
||||
}
|
||||
}
|
||||
statements: 0,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const { JSDOM } = require('jsdom');
|
||||
const { TextDecoder, TextEncoder } = require('util');
|
||||
|
||||
const jsdom = new JSDOM(`<div id="main"></div>`, {
|
||||
const jsdom = new JSDOM('<div id="main"></div>', {
|
||||
// https://github.com/jsdom/jsdom#basic-options
|
||||
// 禁用掉 resources: usable, 采用 jsdom 默认策略不加载 subresources
|
||||
// 避免测试用例加载 external subresource, 如 iconfont 的 css 挂掉
|
||||
|
@ -31,11 +31,11 @@ global.DOMParser = jsdom.window.DOMParser;
|
|||
global.HTMLDivElement = jsdom.window.HTMLDivElement;
|
||||
global.MutationObserver = jsdom.window.MutationObserver;
|
||||
global.KeyboardEvent = jsdom.window.KeyboardEvent;
|
||||
global.requestAnimationFrame = fn => setTimeout(fn, 16);
|
||||
jsdom.window.requestAnimationFrame = fn => setTimeout(fn, 16);
|
||||
jsdom.window.cancelAnimationFrame = () => { };
|
||||
global.document.queryCommandSupported = () => { };
|
||||
global.document.execCommand = () => { };
|
||||
global.requestAnimationFrame = (fn) => setTimeout(fn, 16);
|
||||
jsdom.window.requestAnimationFrame = (fn) => setTimeout(fn, 16);
|
||||
jsdom.window.cancelAnimationFrame = () => {};
|
||||
global.document.queryCommandSupported = () => {};
|
||||
global.document.execCommand = () => {};
|
||||
global.HTMLElement = jsdom.window.HTMLElement;
|
||||
global.self = global;
|
||||
global.TextEncoder = TextEncoder;
|
||||
|
@ -45,7 +45,7 @@ global.ElectronIpcRenderer = {
|
|||
send: () => {},
|
||||
removeListener: () => {},
|
||||
on: () => {},
|
||||
}
|
||||
};
|
||||
|
||||
class MockLocalStorage {
|
||||
constructor() {
|
||||
|
@ -76,7 +76,7 @@ process.env.IS_JEST_TEST = true;
|
|||
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
|
||||
Object.defineProperty(window, 'matchMedia', {
|
||||
writable: true,
|
||||
value: jest.fn().mockImplementation(query => ({
|
||||
value: jest.fn().mockImplementation((query) => ({
|
||||
matches: false,
|
||||
media: query,
|
||||
onchange: null,
|
||||
|
|
38
package.json
38
package.json
|
@ -1,11 +1,9 @@
|
|||
{
|
||||
"name": "@opensumi/ide",
|
||||
"version": "2.12.0",
|
||||
"resolution": {
|
||||
"webpack": "4.39.3"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"prepare": "husky install",
|
||||
"clean:cache": "rimraf .cache",
|
||||
"clean": "rimraf ./packages/*/lib",
|
||||
"check:dep": "ts-node ./scripts/depcheck",
|
||||
|
@ -34,7 +32,8 @@
|
|||
"update-disttag": "ts-node ./scripts/dist-tag",
|
||||
"lint": "tslint -c tslint.yml -p tsconfig.json -t stylish",
|
||||
"lint:fix": "npm run lint -- --fix",
|
||||
"lint-staged": "tslint -c tslint.staged.yml -p tsconfig.json -t stylish",
|
||||
"lint1": "eslint . --ext .js,.jsx,.ts,.tsx",
|
||||
"lint1:fix": "npm run lint1 -- --fix",
|
||||
"rebuild:node": "node ./scripts/rebuild-native.js",
|
||||
"test": "jest --forceExit",
|
||||
"test:module": "NODE_OPTIONS=--max_old_space_size=5120 node -r ts-node/register ./scripts/module-jest",
|
||||
|
@ -57,10 +56,10 @@
|
|||
"execa": "^1.0.0",
|
||||
"fs-extra": "^7.0.1",
|
||||
"glob": "^7.1.4",
|
||||
"husky": "^1.2.1",
|
||||
"husky": "^7.0.4",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"lerna": "^4.0.0",
|
||||
"lint-staged": "^12.0.2",
|
||||
"lint-staged": "^12.1.2",
|
||||
"lodash": "^4.17.11",
|
||||
"node-gyp": "^8.3.0",
|
||||
"ts-node": "8.0.2",
|
||||
|
@ -68,17 +67,12 @@
|
|||
"typescript": "^4.4.2",
|
||||
"webpack": "4.39.3"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "lint-staged",
|
||||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
||||
"post-checkout": "npm run clean:cache",
|
||||
"post-merge": "npm run clean:cache",
|
||||
"pre-rebase": "npm run clean:cache"
|
||||
}
|
||||
},
|
||||
"lint-staged": {
|
||||
"packages/**/*.(ts|tsx)": "tslint -c tslint.staged.yml -p tsconfig.json -t stylish"
|
||||
"*.{js,jsx,ts,tsx,md,html,css,less,json}": "prettier --write",
|
||||
"*.{js,jsx,ts,tsx}": "eslint --fix",
|
||||
"packages/**/*.(ts|tsx)": [
|
||||
"tslint -c tslint.staged.yml -p tsconfig.json -t stylish"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"commitizen": {
|
||||
|
@ -92,12 +86,13 @@
|
|||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@github.com:ide-framework/core.git"
|
||||
"url": "git@github.com:opensumi/core.git"
|
||||
},
|
||||
"resolutions": {
|
||||
"canvas": "2.6.1",
|
||||
"y18n": "4.0.0",
|
||||
"shelljs": "0.8.4"
|
||||
"shelljs": "0.8.4",
|
||||
"webpack": "4.39.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/classnames": "2.2.6",
|
||||
|
@ -120,12 +115,16 @@
|
|||
"@types/temp": "^0.8.34",
|
||||
"@types/write-pkg": "^4.0.0",
|
||||
"@types/ws": "^6.0.1",
|
||||
"@typescript-eslint/eslint-plugin": "^5.7.0",
|
||||
"@typescript-eslint/parser": "^5.7.0",
|
||||
"async-retry": "^1.3.1",
|
||||
"await-event": "^2.1.0",
|
||||
"chalk": "^3.0.0",
|
||||
"cross-env": "^6.0.3",
|
||||
"debug": "^4.3.2",
|
||||
"depcheck": "^1.4.2",
|
||||
"eslint": "^8.4.1",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"git-rev-sync": "^3.0.1",
|
||||
"got": "^11.8.3",
|
||||
"handlebars": "^4.7.3",
|
||||
|
@ -140,7 +139,7 @@
|
|||
"node-fetch": "^2.6.1",
|
||||
"offline-iconfont": "^1.1.0",
|
||||
"parse-github-url": "^1.0.2",
|
||||
"prettier": "^2.0.5",
|
||||
"prettier": "^2.5.1",
|
||||
"read-pkg": "^5.2.0",
|
||||
"regenerator-runtime": "^0.13.3",
|
||||
"rimraf": "^3.0.2",
|
||||
|
@ -150,6 +149,7 @@
|
|||
"strip-html-comments": "^1.0.0",
|
||||
"temp": "^0.9.0",
|
||||
"ts-jest": "^27.0.3",
|
||||
"tslint-config-prettier": "^1.18.0",
|
||||
"urllib": "^2.37.4",
|
||||
"uuid": "^8.3.2",
|
||||
"write-pkg": "^4.0.0",
|
||||
|
|
|
@ -9,7 +9,6 @@ export const MARKDOWN_EDITOR_COMPONENT_ID: string = 'MARKDOWN_EDITOR_COMPONENT_I
|
|||
|
||||
@Domain(BrowserEditorContribution)
|
||||
export class EmbeddedMarkdownEditorContribution implements BrowserEditorContribution {
|
||||
|
||||
@Autowired(IMarkdownService)
|
||||
markdownService: IMarkdownService;
|
||||
|
||||
|
@ -34,5 +33,4 @@ export class EmbeddedMarkdownEditorContribution implements BrowserEditorContribu
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
import { Injectable, Autowired, INJECTOR_TOKEN, Injector } from '@opensumi/di';
|
||||
import { Disposable, KeybindingRegistry, MonacoOverrideServiceRegistry, ServiceNames, ILogger } from '@opensumi/ide-core-browser';
|
||||
import {
|
||||
Disposable,
|
||||
KeybindingRegistry,
|
||||
MonacoOverrideServiceRegistry,
|
||||
ServiceNames,
|
||||
ILogger,
|
||||
} from '@opensumi/ide-core-browser';
|
||||
import { Deferred, Emitter as EventEmitter, Event } from '@opensumi/ide-core-common';
|
||||
import { IEditorConstructionOptions, isDiffEditor, MouseTargetType } from '@opensumi/monaco-editor-core/esm/vs/editor/browser/editorBrowser';
|
||||
import {
|
||||
IEditorConstructionOptions,
|
||||
isDiffEditor,
|
||||
MouseTargetType,
|
||||
} from '@opensumi/monaco-editor-core/esm/vs/editor/browser/editorBrowser';
|
||||
import { IDiffEditorConstructionOptions } from '@opensumi/monaco-editor-core/esm/vs/editor/browser/editorBrowser';
|
||||
import { SimpleKeybinding } from '@opensumi/monaco-editor-core/esm/vs/base/common/keyCodes';
|
||||
import { Range } from '@opensumi/monaco-editor-core/esm/vs/editor/editor.main';
|
||||
|
@ -14,7 +24,7 @@ import { monaco } from './monaco-api';
|
|||
import { MonacoResolvedKeybinding } from './monaco.resolved-keybinding';
|
||||
import { MonacoService } from '../common';
|
||||
|
||||
const SUMI_OVERFLOW_WIDGETS_CONTAINER_ID = 'sumi-overflow-widgets-container';
|
||||
const SUMI_OVERFLOW_WIDGETS_CONTAINER_ID = 'sumi-overflow-widgets-container';
|
||||
|
||||
@Injectable()
|
||||
export default class MonacoServiceImpl extends Disposable implements MonacoService {
|
||||
|
@ -45,8 +55,9 @@ export default class MonacoServiceImpl extends Disposable implements MonacoServi
|
|||
|
||||
get monacoBaseOptions() {
|
||||
return {
|
||||
// monaco 默认会将 overflowWidgets(如 hover) 放置在编辑器内部的 DOM 中
|
||||
// 但我们会在外部增加其他组件,可能会导致遮挡这些 Widget
|
||||
// Monaco 默认会将 overflowWidgets(如 hover) 放置在编辑器内部的 DOM 中
|
||||
// 但是 Monaco 在计算 overflowWidgets 的位置时是使用整个 body 的高度来计算定位的
|
||||
// 但我们会在顶部增加我们自己的业务组件,就会导致遮挡这些 overflowWidgets
|
||||
// 所以此处将 overflowWidget 放置在 body 下构造的一个专门的 container 中
|
||||
overflowWidgetsDomNode: document.getElementById(SUMI_OVERFLOW_WIDGETS_CONTAINER_ID)!,
|
||||
glyphMargin: true,
|
||||
|
@ -73,12 +84,16 @@ export default class MonacoServiceImpl extends Disposable implements MonacoServi
|
|||
public createCodeEditor(
|
||||
monacoContainer: HTMLElement,
|
||||
options?: IEditorConstructionOptions,
|
||||
overrides: {[key: string]: any} = {},
|
||||
overrides: { [key: string]: any } = {},
|
||||
): ICodeEditor {
|
||||
const editor = monaco.editor.create(monacoContainer, {
|
||||
...this.monacoBaseOptions,
|
||||
...options,
|
||||
}, { ...this.overrideServiceRegistry.all(), ...overrides });
|
||||
const editor = monaco.editor.create(
|
||||
monacoContainer,
|
||||
{
|
||||
...this.monacoBaseOptions,
|
||||
...options,
|
||||
},
|
||||
{ ...this.overrideServiceRegistry.all(), ...overrides },
|
||||
);
|
||||
this.overrideMonacoKeybindingService(editor);
|
||||
|
||||
this.addClickEventListener(editor);
|
||||
|
@ -86,23 +101,25 @@ export default class MonacoServiceImpl extends Disposable implements MonacoServi
|
|||
}
|
||||
|
||||
private doAddClickEventListener(editor: ICodeEditor) {
|
||||
this.addDispose(editor.onMouseDown((e) => {
|
||||
if (e.target.type === MouseTargetType.GUTTER_LINE_NUMBERS) {
|
||||
const lineNumber = e.target.position?.lineNumber || e.target.range?.startLineNumber;
|
||||
if (!lineNumber) {
|
||||
return;
|
||||
}
|
||||
this.addDispose(
|
||||
editor.onMouseDown((e) => {
|
||||
if (e.target.type === MouseTargetType.GUTTER_LINE_NUMBERS) {
|
||||
const lineNumber = e.target.position?.lineNumber || e.target.range?.startLineNumber;
|
||||
if (!lineNumber) {
|
||||
return;
|
||||
}
|
||||
|
||||
editor.setSelection(
|
||||
new Range(
|
||||
lineNumber,
|
||||
e.target.range?.startColumn || e.target.position?.column || 0,
|
||||
lineNumber + 1,
|
||||
e.target.range?.startColumn || e.target.position?.column || 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
}));
|
||||
editor.setSelection(
|
||||
new Range(
|
||||
lineNumber,
|
||||
e.target.range?.startColumn || e.target.position?.column || 0,
|
||||
lineNumber + 1,
|
||||
e.target.range?.startColumn || e.target.position?.column || 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
private addClickEventListener(editor: IDiffEditor | ICodeEditor) {
|
||||
|
@ -120,13 +137,17 @@ export default class MonacoServiceImpl extends Disposable implements MonacoServi
|
|||
public createDiffEditor(
|
||||
monacoContainer: HTMLElement,
|
||||
options?: IDiffEditorConstructionOptions,
|
||||
overrides: {[key: string]: any} = {},
|
||||
overrides: { [key: string]: any } = {},
|
||||
): IDiffEditor {
|
||||
const editor = monaco.editor.createDiffEditor(monacoContainer, {
|
||||
...this.monacoBaseOptions,
|
||||
ignoreTrimWhitespace: false,
|
||||
...options,
|
||||
} as any, { ...this.overrideServiceRegistry.all(), ...overrides });
|
||||
const editor = monaco.editor.createDiffEditor(
|
||||
monacoContainer,
|
||||
{
|
||||
...this.monacoBaseOptions,
|
||||
ignoreTrimWhitespace: false,
|
||||
...options,
|
||||
} as any,
|
||||
{ ...this.overrideServiceRegistry.all(), ...overrides },
|
||||
);
|
||||
this.overrideMonacoKeybindingService(editor);
|
||||
this.addClickEventListener(editor);
|
||||
return editor;
|
||||
|
@ -168,7 +189,9 @@ export default class MonacoServiceImpl extends Disposable implements MonacoServi
|
|||
if (!keybindingService) {
|
||||
return;
|
||||
}
|
||||
keybindingService.resolveKeybinding = (keybinding) => [new MonacoResolvedKeybinding(MonacoResolvedKeybinding.keySequence(keybinding), this.keybindingRegistry)];
|
||||
keybindingService.resolveKeybinding = (keybinding) => [
|
||||
new MonacoResolvedKeybinding(MonacoResolvedKeybinding.keySequence(keybinding), this.keybindingRegistry),
|
||||
];
|
||||
keybindingService.resolveKeyboardEvent = (keyboardEvent) => {
|
||||
const keybinding = new SimpleKeybinding(
|
||||
keyboardEvent.ctrlKey,
|
||||
|
@ -184,7 +207,7 @@ export default class MonacoServiceImpl extends Disposable implements MonacoServi
|
|||
public registerOverride(serviceName: ServiceNames, service: any) {
|
||||
this.logger.warn(
|
||||
true,
|
||||
`MonacoService#getOverride will be deprecated, please use MonacoOverrideServiceRegistry#getRegisteredService instead.`,
|
||||
'MonacoService#getOverride will be deprecated, please use MonacoOverrideServiceRegistry#getRegisteredService instead.',
|
||||
);
|
||||
this.overrideServiceRegistry.registerOverrideService(serviceName, service);
|
||||
}
|
||||
|
@ -192,7 +215,7 @@ export default class MonacoServiceImpl extends Disposable implements MonacoServi
|
|||
public getOverride(serviceName: ServiceNames) {
|
||||
this.logger.warn(
|
||||
true,
|
||||
`MonacoService#getOverride will be deprecated, please use MonacoOverrideServiceRegistry#getRegisteredService instead.`,
|
||||
'MonacoService#getOverride will be deprecated, please use MonacoOverrideServiceRegistry#getRegisteredService instead.',
|
||||
);
|
||||
return this.overrideServiceRegistry.getRegisteredService(serviceName);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
extends:
|
||||
- tslint:recommended
|
||||
- "tslint-config-prettier"
|
||||
|
||||
rules:
|
||||
only-arrow-functions: false
|
||||
|
@ -43,4 +44,3 @@ linterOptions:
|
|||
- '**/typings/**'
|
||||
- '**/typings-pending/**'
|
||||
- '**/scripts/**'
|
||||
|
||||
|
|
Loading…
Reference in New Issue