Skip to content

Commit 371f0fc

Browse files
author
彦熹
committed
PullRequest: 46 feat/refactor-code-service
1 parent 2d34eee commit 371f0fc

72 files changed

Lines changed: 2387 additions & 2283 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

jest.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ module.exports = {
1111
watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'],
1212
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
1313
moduleNameMapper: {
14-
'^@alipay/alex-(.*?)$': '<rootDir>/packages/$1/src',
15-
'@alipay/alex': '<rootDir>/packages/alex/src',
14+
'^@alipay/alex-(?!browserfs)(.*?)$': '<rootDir>/packages/$1/src',
15+
'^@alipay/alex$': '<rootDir>/packages/alex/src',
16+
'\\.(css|less)$': '<rootDir>/mocks/styleMock.js',
1617
},
1718
rootDir: __dirname,
1819
testMatch: ['<rootDir>/packages/**/__tests__/**/*@(test|spec).[jt]s?(x)'],
1920
testPathIgnorePatterns: ['/node_modules/'],
21+
setupFiles: ['./jest.setup.js'],
2022
};

jest.setup.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const { JSDOM } = require('jsdom');
2+
const { TextDecoder, TextEncoder } = require('util');
3+
4+
const jsdom = new JSDOM(`<div id="main"></div>`, {
5+
// https://github.com/jsdom/jsdom#basic-options
6+
// 禁用掉 resources: usable, 采用 jsdom 默认策略不加载 subresources
7+
// 避免测试用例加载 external subresource, 如 iconfont 的 css 挂掉
8+
// resources: 'usable',
9+
runScripts: 'dangerously',
10+
url: 'http://localhost/?id=1',
11+
});
12+
global.document = jsdom.window.document;
13+
let text = '';
14+
global.navigator = Object.assign(jsdom.window.navigator, {
15+
clipboard: {
16+
writeText(value) {
17+
text = value;
18+
},
19+
readText() {
20+
return text;
21+
},
22+
},
23+
});
24+
global.Element = jsdom.window.Element;
25+
global.HTMLDivElement = jsdom.window.HTMLDivElement;
26+
global.fetch = jsdom.window.fetch;
27+
global.location = jsdom.window.location;
28+
global.getComputedStyle = jsdom.window.getComputedStyle;
29+
global.window = jsdom.window;
30+
global.DOMParser = jsdom.window.DOMParser;
31+
global.HTMLDivElement = jsdom.window.HTMLDivElement;
32+
global.MutationObserver = jsdom.window.MutationObserver;
33+
global.requestAnimationFrame = (fn) => setTimeout(fn, 16);
34+
jsdom.window.requestAnimationFrame = (fn) => setTimeout(fn, 16);
35+
jsdom.window.cancelAnimationFrame = () => {};
36+
global.document.queryCommandSupported = () => {};
37+
global.document.execCommand = () => {};
38+
global.HTMLElement = jsdom.window.HTMLElement;
39+
global.self = global;
40+
global.TextEncoder = TextEncoder;
41+
global.TextDecoder = TextDecoder;
42+
43+
class MockLocalStorage {
44+
constructor() {
45+
this.store = {};
46+
}
47+
48+
clear() {
49+
this.store = {};
50+
}
51+
52+
getItem(key) {
53+
return this.store[key] || null;
54+
}
55+
56+
setItem(key, value) {
57+
this.store[key] = value.toString();
58+
}
59+
60+
removeItem(key) {
61+
delete this.store[key];
62+
}
63+
}
64+
65+
global.localStorage = new MockLocalStorage();

mocks/styleMock.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"husky": "^4.3.0",
6969
"inquirer": "^7.3.3",
7070
"jest": "^26.6.3",
71+
"jsdom": "^16.5.3",
7172
"json5": "^2.2.0",
7273
"lint-staged": "^10.5.1",
7374
"minimist": "^1.2.5",

packages/alex/src/api/createApp.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
import { BoxPanel, SplitPanel } from '@ali/ide-core-browser/lib/components';
1919
import '@ali/ide-core-browser/lib/style/index.less';
2020
import * as os from 'os';
21+
import { IPluginConfig } from '@alipay/alex-plugin';
22+
import { deletionLogPath } from '@alipay/alex-browserfs/lib/backend/OverlayFS';
2123

2224
import '../core/extension.patch';
2325
import { disposeMode } from '../core/patch';
@@ -47,7 +49,7 @@ const getDefaultAppConfig = (): IAppOpts => ({
4749
'files.exclude': {
4850
...FILES_DEFAULTS.filesExclude,
4951
// browserfs OverlayFS 用来记录删除的文件
50-
'**/.deletedFiles.log': true,
52+
[`**${deletionLogPath}`]: true,
5153
},
5254
},
5355
layoutConfig: getDefaultLayoutConfig(),
@@ -116,6 +118,11 @@ export function createApp({ appConfig, runtimeConfig }: IConfig): IAppInstance {
116118
useValue: runtimeConfig,
117119
});
118120

121+
app.injector.addProviders({
122+
token: IPluginConfig,
123+
useValue: customConfig.plugins,
124+
});
125+
119126
if (runtimeConfig.reporter) {
120127
app.injector.addProviders({
121128
token: IReporter,

packages/alex/src/api/createEditor.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { IThemeService } from '@ali/ide-theme/lib/common';
1919
import '@ali/ide-core-browser/lib/style/index.less';
2020
import * as os from 'os';
2121
import { IPluginConfig } from '@alipay/alex-plugin';
22+
import { deletionLogPath } from '@alipay/alex-browserfs/lib/backend/OverlayFS';
2223

2324
import { disposeMode } from '../core/patch';
2425
import { getModules } from '../core/editor/modules';
@@ -44,7 +45,7 @@ const getDefaultAppConfig = (): IAppOpts => ({
4445
'files.exclude': {
4546
...FILES_DEFAULTS.filesExclude,
4647
// browserfs OverlayFS 用来记录删除的文件
47-
'**/.deletedFiles.log': true,
48+
[`**${deletionLogPath}`]: true,
4849
},
4950
},
5051
layoutConfig: getEditorLayoutConfig(),

packages/alex/src/core/editor/editor.module.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,6 @@ class EditorSpecialContribution
264264
wrapped: memSystem,
265265
folder: `/${md5(this.appConfig.workspaceDir)}`,
266266
});
267-
await new Promise<void>((resolve, reject) => {
268-
(folderSystem as InstanceType<typeof FolderAdapter>).initialize((err) => {
269-
if (err) {
270-
reject(err);
271-
} else {
272-
resolve();
273-
}
274-
});
275-
});
276267
const overlayFileSystem = await createFileSystem(OverlayFS, {
277268
readable: editorSystem,
278269
writable: folderSystem,

packages/alex/src/core/extensions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const IDETheme: IExtensionBasicMetadata = {
3333
extension: {
3434
publisher: 'kaitian',
3535
name: 'ide-dark-theme',
36-
version: '2.2.0',
36+
version: '2.3.2',
3737
},
3838
packageJSON: {
3939
name: 'ide-dark-theme',

packages/alex/src/core/modules.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { WorkspaceEditModule } from '@ali/ide-workspace-edit/lib/browser';
4545
*/
4646

4747
import { ClientModule, ServerModuleCollection } from '@alipay/alex-core';
48+
import { PluginModule } from '@alipay/alex-plugin';
4849

4950
// TODO: 部分模块需要注意顺序,否则会报错,待框架侧调整修复
5051
export const modules: ModuleConstructor[] = [
@@ -97,5 +98,6 @@ export const modules: ModuleConstructor[] = [
9798

9899
// Alex
99100
ClientModule,
101+
PluginModule,
100102
...ServerModuleCollection,
101103
];

packages/code-api/src/antcode/antcode.module.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)