Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: simplify deps #1102

Merged
merged 7 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"@types/socket.io-client": "^1.4.32",
"@types/temp": "^0.9.1",
"@types/ws": "^6.0.1",
"@types/yargs": "^16",
"@types/yargs": "^17.0.10",
"@typescript-eslint/eslint-plugin": "^5.12.1",
"@typescript-eslint/parser": "^5.12.1",
"async-retry": "^1.3.1",
Expand Down Expand Up @@ -135,7 +135,7 @@
"simple-git": "^3.3.0",
"temp": "^0.9.4",
"ts-jest": "^28.0.0",
"yargs": "^16.1.0",
"yargs": "^17.5.0",
"yauzl": "^2.10.0"
}
}
3 changes: 0 additions & 3 deletions packages/core-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,15 @@
"@vscode/codicons": "0.0.27",
"ajv": "^6.10.0",
"classnames": "2.2.6",
"clsx": "^1.0.4",
"font-awesome": "^4.7.0",
"fuzzy": "^0.1.3",
"jsonc-parser": "^2.1.0",
"keycode": "^2.2.0",
"lodash": "^4.17.15",
"lzutf8": "^0.5.5",
"marked": "4.0.10",
"mobx": "^5.9.4",
"mobx-react-lite": "^1.3.1",
"onigasm": "2.2.2",
"p-series": "^2.1.0",
"rc-menu": "^9.3.2",
"react": "^16.8.6",
"react-autosize-textarea": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ export * from './credential';
export * from './crypto';
export * from './markdown';
export * from './settings';
export * from '@opensumi/ide-utils';
export * from './utils';
5 changes: 5 additions & 0 deletions packages/core-common/src/node/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { argv as _argv } from 'yargs';

const argv = _argv as { [x: string]: unknown; _: (string | number)[]; $0: string };

export { argv };
1 change: 1 addition & 0 deletions packages/core-common/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@opensumi/ide-utils';
2 changes: 1 addition & 1 deletion packages/core-electron-main/src/bootstrap/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { app, BrowserWindow, BrowserWindowConstructorOptions } from 'electron';
import { argv } from 'yargs';

import { Injector, ConstructorOf } from '@opensumi/di';
import {
Expand All @@ -12,6 +11,7 @@ import {
asExtensionCandidate,
} from '@opensumi/ide-core-common';
import { IElectronMainLifeCycleService } from '@opensumi/ide-core-common/lib/electron';
import { argv } from '@opensumi/ide-core-common/lib/node/cli';

import { ElectronMainModule } from '../electron-main-module';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pSeries = require('p-series');

import { Injectable, Autowired, INJECTOR_TOKEN, Injector } from '@opensumi/di';
import {
DecorationsManager,
Expand All @@ -8,7 +6,7 @@ import {
WatchEvent,
TreeNodeEvent,
} from '@opensumi/ide-components';
import { Emitter, Deferred, Event, DisposableCollection, path } from '@opensumi/ide-core-browser';
import { Emitter, Deferred, Event, DisposableCollection, path, pSeries } from '@opensumi/ide-core-browser';

import { DebugVariable, ExpressionContainer, ExpressionNode } from '../tree/debug-tree-node.define';
import styles from '../view/variables/debug-variables.module.less';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pSeries from 'p-series';

import { Injectable, Autowired, INJECTOR_TOKEN, Injector } from '@opensumi/di';
import {
DecorationsManager,
Expand All @@ -19,6 +17,7 @@ import {
DisposableCollection,
IClipboardService,
path,
pSeries,
} from '@opensumi/ide-core-browser';
import { AbstractContextMenuService, MenuId, ICtxMenuRenderer } from '@opensumi/ide-core-browser/lib/menu/next';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pSeries from 'p-series';

import { Injectable, Autowired, INJECTOR_TOKEN, Injector } from '@opensumi/di';
import {
TreeModel,
Expand All @@ -26,6 +24,7 @@ import {
IContextKey,
IReporterService,
path,
pSeries,
} from '@opensumi/ide-core-browser';
import { AbstractContextMenuService, MenuId, ICtxMenuRenderer } from '@opensumi/ide-core-browser/lib/menu/next';

Expand Down
2 changes: 1 addition & 1 deletion packages/file-tree-next/src/browser/file-tree.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import throttle from 'lodash/throttle';
import pSeries from 'p-series';

import { Injectable, Autowired } from '@opensumi/di';
import { Tree, ITree, ITreeNodeOrCompositeTreeNode, TreeNodeType } from '@opensumi/ide-components';
Expand All @@ -18,6 +17,7 @@ import {
ILogger,
path,
Throttler,
pSeries,
} from '@opensumi/ide-core-browser';
import { CorePreferences } from '@opensumi/ide-core-browser/lib/core-preferences';
import { LabelService } from '@opensumi/ide-core-browser/lib/services';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pSeries = require('p-series');

import { Injectable, Autowired, INJECTOR_TOKEN, Injector } from '@opensumi/di';
import {
DecorationsManager,
Expand All @@ -20,6 +18,7 @@ import {
Deferred,
Event,
path,
pSeries,
} from '@opensumi/ide-core-browser';
import { AbstractContextMenuService, MenuId, ICtxMenuRenderer } from '@opensumi/ide-core-browser/lib/menu/next';
import { LabelService } from '@opensumi/ide-core-browser/lib/services';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pSeries from 'p-series';

import { Injectable, Autowired, INJECTOR_TOKEN, Injector } from '@opensumi/di';
import { DecorationsManager, Decoration, IRecycleTreeHandle, TreeNodeType, WatchEvent } from '@opensumi/ide-components';
import {
Expand All @@ -16,6 +14,7 @@ import {
Disposable,
ThrottledDelayer,
path,
pSeries,
} from '@opensumi/ide-core-browser';
import { WorkbenchEditorService } from '@opensumi/ide-editor/lib/browser';
import {
Expand Down
4 changes: 2 additions & 2 deletions packages/remote-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ Examples:
`,
)
.help()
.string('_').argv;
.string('_').argv as { [x: string]: unknown; _: (string | number)[]; $0: string };

if (argv._[0] !== undefined) {
openPathOrUrl(argv._[0]);
openPathOrUrl(argv._[0].toString());
} else {
// eslint-disable-next-line no-console
console.error(red('The path or url is not defined.'));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { observable } from 'mobx';
import pSeries from 'p-series';

import { Autowired, Injectable, Injector, INJECTOR_TOKEN } from '@opensumi/di';
import { Decoration, DecorationsManager, IRecycleTreeHandle, TreeNodeType, WatchEvent } from '@opensumi/ide-components';
Expand All @@ -9,6 +8,7 @@ import {
PreferenceService,
EDITOR_COMMANDS,
ILogger,
pSeries,
} from '@opensumi/ide-core-browser';
import { path, Deferred, DisposableCollection, Emitter, Event, URI } from '@opensumi/ide-core-browser';
import { ICtxMenuRenderer } from '@opensumi/ide-core-browser/lib/menu/next/renderer/ctxmenu/base';
Expand Down
2 changes: 1 addition & 1 deletion packages/startup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"compression": "^1.7.4",
"cross-env": "^7.0.3",
"css-loader": "^2.1.1",
"electron": "^13.6.9",
"electron": "^18.3.0",
"file-loader": "^3.0.1",
"friendly-errors-webpack-plugin": "^1.7.0",
"html-webpack-plugin": "^3.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export * from './marshalling';
export * from './os';
export * from './platform';
export * from './progress';
export * from './promise-util';
export * from './promises';
export * from './sequence';
export * from './types';
export * from './uint';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ export class Deferred<T> {
this.reject = reject;
});
}

export async function pSeries<T>(tasks: Iterable<() => Promise<T> | T>): Promise<T[]> {
const results = [] as T[];

for (const task of tasks) {
results.push(await task());
}

return results;
}
30 changes: 15 additions & 15 deletions scripts/depcheck.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@

import { join, resolve, relative } from 'path';
import depcheck from 'depcheck';
import chalk from 'chalk';
import { readdirSync, existsSync } from 'fs-extra';
import { argv } from 'yargs';
import { argv } from '../packages/core-common/src/node/cli';

const packagesDir = join(__dirname, '../packages');

const options = {
ignoreBinPackage: false, // ignore the packages with bin entry
skipMissing: false, // skip calculation of missing dependencies
ignoreDirs: [
'bower_components',
'node_modules',
'lib',
],
ignoreDirs: ['bower_components', 'node_modules', 'lib'],
ignoreMatches: [
'@opensumi/ide-core-browser',
'@opensumi/ide-core-common',
Expand Down Expand Up @@ -44,11 +39,14 @@ const options = {
],
};

function check(rootDir: string, config = {
unusedDependency: true,
unusedDevDependency: true,
missing: true,
}) {
function check(
rootDir: string,
config = {
unusedDependency: true,
unusedDevDependency: true,
missing: true,
},
) {
return new Promise<void>((resolve) => {
const cwd = process.cwd();
depcheck(rootDir, options, (unused) => {
Expand Down Expand Up @@ -127,10 +125,12 @@ async function bootAll() {
runTaskWithPackages(targetPacks);
}

const targetModule = (argv as any).module as string;

// 指定模块加载
if (argv.module) {
console.log(`单模块模式依赖检查: ${argv.module}`);
const moduleName = (argv.module as string).replace(/@ali\//, '');
if (targetModule) {
console.log(`单模块模式依赖检查: ${targetModule}`);
const moduleName = targetModule.replace(/@ali\//, '');
runTaskWithPackages([moduleName]);
} else {
console.log('项目级别依赖检查');
Expand Down
22 changes: 5 additions & 17 deletions scripts/run-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import { join } from 'path';
import yargs from 'yargs';

import { shell } from 'execa';
import { command } from 'execa';
import { readdirSync, writeJSONSync, mkdirSync, readJSONSync, pathExistsSync, removeSync } from 'fs-extra';
import { pSeries } from '../packages/utils/src/promises';

const argv = yargs.argv;

Expand Down Expand Up @@ -53,20 +54,6 @@ if (argv.noCache) {
successCheckPoint.clean();
}

/*
* serial executes Promises sequentially.
* @param {funcs} An array of funcs that return promises.
* @example
* const urls = ['/url1', '/url2', '/url3']
* serial(urls.map(url => () => $.ajax(url)))
* .then(console.log.bind(console))
*/
const serial = (funcs) =>
funcs.reduce(
(promise, func) => promise.then((result) => func().then(Array.prototype.concat.bind(result))),
Promise.resolve([]),
);

const skipList = ((argv as any).skipList ?? '').split(',') || ([] as string[]);
const testResult = {};

Expand Down Expand Up @@ -99,9 +86,10 @@ const funcs = packagesDirNames.map((target) => {
}

console.log('cmd:', cmd, 'env:', env);
const runResult = await shell(cmd, {
const runResult = await command(cmd, {
reject: false,
stdio: 'inherit',
shell: true,
env,
});
const info = {
Expand All @@ -126,6 +114,6 @@ const funcs = packagesDirNames.map((target) => {
};
});

serial(funcs).then(() => {
pSeries(funcs).then(() => {
writeJSONSync(join(cacheDir, 'tests.json'), testResult);
});
3 changes: 2 additions & 1 deletion scripts/start.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { startFromFolder } from './fn/module';
import { argv } from 'yargs';
import { argv } from '../packages/core-common/src/node/cli';

const folderName = (argv.folder as string) || 'packages/startup';
const scriptName = (argv.script as string) || 'start';

Expand Down
4 changes: 2 additions & 2 deletions tools/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^5.0.3",
"css-loader": "^2.1.1",
"electron": "^18.0.0",
"electron": "^18.3.0",
"electron-builder": "^23.0.3",
"file-loader": "^3.0.1",
"friendly-errors-webpack-plugin": "^1.7.0",
Expand All @@ -73,6 +73,6 @@
"typescript": "4.6.4",
"webpack": "^4.39.3",
"webpack-cli": "^3.3.1",
"yargs": "^13.2.4"
"yargs": "^17.5.0"
}
}
6 changes: 2 additions & 4 deletions tools/electron/scripts/rebuild-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ if (target === 'electron') {
version = argv.electronVersion || require('electron/package.json').version;
console.log('rebuilding native for electron version ' + version);
commands = [
os.platform() === 'win32'
? 'set HOME=~/.electron-gyp'
: 'HOME=~/.electron-gyp',
os.platform() === 'win32' ? 'set HOME=~/.electron-gyp' : 'HOME=~/.electron-gyp',
'node-gyp',
'rebuild',
'--openssl_fips=X',
Expand Down Expand Up @@ -62,7 +60,7 @@ function getBuildCacheDir(modulePath, type, version, arch) {
require('os').tmpdir(),
'kaitian_build_cache',
`${type}-${version}-${arch}`,
info.name + '-' + info.version
info.name + '-' + info.version,
);
}

Expand Down