Skip to content

Commit

Permalink
Merge pull request #113 from LiangCY/feat/upgrade-ts
Browse files Browse the repository at this point in the history
upgrade typescript
  • Loading branch information
ascoders authored Feb 9, 2021
2 parents 86a3e08 + abdd0f2 commit 152175f
Show file tree
Hide file tree
Showing 18 changed files with 632 additions and 299 deletions.
8 changes: 6 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"no-underscore-dangle": 2,
"eol-last": 2,
"no-useless-rename": 2,
"no-undef": 0,
"class-methods-use-this": 0,
"prefer-destructuring": 0,
"no-unused-vars": 0,
Expand All @@ -91,15 +92,18 @@
"import/prefer-default-export": 0,
"import/no-dynamic-require": 2,
"@typescript-eslint/no-var-requires": 2,
"no-use-before-define": [
"no-use-before-define": 0,
"@typescript-eslint/no-use-before-define": [
"error",
{
"functions": false
}
],
"@typescript-eslint/no-use-before-define": 0,
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/interface-name-prefix": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"no-shadow": 0,
"@typescript-eslint/no-shadow": 2,
"no-invalid-this": 0,
"babel/no-invalid-this": 2,
"no-await-in-loop": "off",
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
<a name="4.3.0"></a>
# [4.3.0](https://github.com/prijs/pri/compare/4.2.12...4.3.0) (2021-02-09)


### Bug Fixes

* circular detect exclude ([7995320](https://github.com/prijs/pri/commit/7995320))
* eslint no-shadow ([4d0368c](https://github.com/prijs/pri/commit/4d0368c))
* type ([f67ca43](https://github.com/prijs/pri/commit/f67ca43))


### Features

* increase ts checker memory limit ([4922c52](https://github.com/prijs/pri/commit/4922c52))
* support mode in webpack-dev-server ([ab8d718](https://github.com/prijs/pri/commit/ab8d718))
* update typescript and eslint ([39a49ee](https://github.com/prijs/pri/commit/39a49ee))



<a name="4.2.12"></a>
## [4.2.12](https://github.com/prijs/pri/compare/4.2.11...4.2.12) (2021-02-03)

Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pri",
"version": "4.2.13",
"version": "4.3.0",
"types": "src/node/index.ts",
"main": "built/node/index.js",
"scripts": {
Expand Down Expand Up @@ -43,7 +43,7 @@
"@babel/plugin-transform-runtime": "7.7.5",
"@babel/preset-env": "7.7.5",
"@babel/preset-react": "7.7.4",
"@babel/preset-typescript": "7.9.0",
"@babel/preset-typescript": "7.12.7",
"@babel/runtime": "7.7.5",
"@commitlint/cli": "^8.2.0",
"@commitlint/lint": "^8.2.0",
Expand Down Expand Up @@ -72,8 +72,8 @@
"@types/webpack-dev-server": "3.9.0",
"@types/webpack-serve": "2.0.1",
"@types/yargs": "13.0.3",
"@typescript-eslint/eslint-plugin": "2.26.0",
"@typescript-eslint/parser": "2.26.0",
"@typescript-eslint/eslint-plugin": "4.12.0",
"@typescript-eslint/parser": "4.12.0",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "25.1.0",
"babel-loader": "8.0.6",
Expand All @@ -87,14 +87,14 @@
"css-loader": "3.2.1",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "6.8.0",
"eslint": "7.18.0",
"eslint-config-airbnb-base": "14.1.0",
"eslint-config-prettier": "6.10.1",
"eslint-config-prettier": "7.2.0",
"eslint-import-resolver-webpack": "0.12.1",
"eslint-plugin-babel": "5.3.0",
"eslint-plugin-import": "2.20.2",
"eslint-plugin-react": "7.19.0",
"eslint-plugin-react-hooks": "3.0.0",
"eslint-plugin-babel": "5.3.1",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-react": "7.22.0",
"eslint-plugin-react-hooks": "4.2.0",
"file-loader": "5.0.2",
"fork-ts-checker-webpack-plugin": "5.2.0",
"fs-extra": "8.1.0",
Expand Down Expand Up @@ -146,7 +146,7 @@
"socket.io-client": "2.3.0",
"speed-measure-webpack-plugin": "1.3.3",
"style-loader": "1.1.3",
"typescript": "3.8.2",
"typescript": "4.1.3",
"update-notifier": "3.0.1",
"url-join": "4.0.1",
"url-loader": "3.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const commandBundle = async (opts: IOpts = {}) => {
await bundleDlls({ dllOutPath, dllFileName, dllMainfestName });

runWebpackDevServer({
mode: 'development',
mode: opts.mode ?? 'development',
outFileName: pri.sourceConfig.bundleFileName,
devServerPort: freePort,
publicPath: `https://localhost:${freePort}`,
Expand Down
1 change: 1 addition & 0 deletions src/built-in-plugins/command-bundle/plugin/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export interface IOpts {
skipLint?: boolean;
dev?: boolean;
publicPath?: string;
mode?: 'development' | 'production';
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import { LayoutComponent } from './pages/layout';
import { ApplicationContext, ApplicationReducer } from './stores';
import { IPlugin } from './define';

export default (plugins?: IPlugin[]) => {
ReactDOM.render(<Root plugins={plugins} />, document.getElementById('root'));
};

const Root = React.memo((props: { plugins: IPlugin[] }) => {
const [state, dispatch] = React.useReducer(ApplicationReducer, {
plugins: [],
Expand All @@ -28,3 +24,7 @@ const Root = React.memo((props: { plugins: IPlugin[] }) => {
</ApplicationContext.Provider>
);
});

export default (plugins?: IPlugin[]) => {
ReactDOM.render(<Root plugins={plugins} />, document.getElementById('root'));
};
6 changes: 3 additions & 3 deletions src/built-in-plugins/command-dev/plugin/project-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const projectDev = async (options: any) => {
if (options && options.debugDashboard) {
await debugDashboard();
} else {
await debugProject();
await debugProject(options);
}
};

Expand Down Expand Up @@ -62,7 +62,7 @@ async function debugDashboard() {
});
}

async function debugProject() {
async function debugProject(options?: any) {
const freePort = pri.sourceConfig.devPort || (await portfinder.getPortPromise());
const dashboardServerPort = await portfinder.getPortPromise({ port: freePort + 1 });
const dashboardClientPort = await portfinder.getPortPromise({ port: freePort + 2 });
Expand Down Expand Up @@ -142,7 +142,7 @@ async function debugProject() {

// Serve project
await runWebpackDevServer({
mode: 'development',
mode: options?.mode ?? 'development',
autoOpenBrowser: true,
hot: pri.sourceConfig.hotReload,
publicPath: globalState.sourceConfig.publicPath,
Expand Down
8 changes: 0 additions & 8 deletions src/built-in-plugins/command-docs/plugin/dev-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ import { prettierConfig } from '../../../utils/prettier-config';
import { tempPath, docsPath } from '../../../utils/structor-config';
import { runWebpackDevServer } from '../../../utils/webpack-dev-server';

interface IResult {
projectAnalyseDocs: {
docs: {
file: path.ParsedPath;
}[];
};
}

export async function devDocs() {
const docsEntryPath = path.join(pri.projectRootPath, tempPath.dir, 'docs-entry.tsx');
prepare(docsEntryPath);
Expand Down
10 changes: 5 additions & 5 deletions src/built-in-plugins/command-publish/plugin/run-publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { commandBundle } from '../../command-bundle/plugin/command-bundle';
import { isWorkingTreeClean, getCurrentBranchName } from '../../../utils/git-operate';
import { logFatal, logInfo, spinner, logText } from '../../../utils/log';
import { getMonoAndNpmDepsOnce, DepMap } from '../../../utils/packages';
import { ProjectConfig, PackageInfo } from '../../../utils/define';
import { ProjectConfig } from '../../../utils/define';
import { isOwner } from '../../../utils/npm';
import { README_FILE } from '../../../utils/constants';

Expand Down Expand Up @@ -63,7 +63,7 @@ export const publish = async (options: PublishOption) => {
]);
}

// eslint-disable-next-line no-unused-expressions
// eslint-disable-next-line babel/no-unused-expressions
!options.commitOnly && (await buildDeclaration());

if (includeAllPrompt.includeAll) {
Expand All @@ -74,7 +74,7 @@ export const publish = async (options: PublishOption) => {
}
}
} else {
// eslint-disable-next-line no-unused-expressions
// eslint-disable-next-line babel/no-unused-expressions
!options.commitOnly && (await buildDeclaration());
}
if (selectedPkgJson?.name) {
Expand All @@ -83,7 +83,7 @@ export const publish = async (options: PublishOption) => {
await publishByPackageName(currentSelectedSourceType, options, depMap, isDevelopBranch, currentBranchName);

await fs.remove(path.join(pri.projectRootPath, tempPath.dir, declarationPath.dir));
// eslint-disable-next-line no-unused-expressions
// eslint-disable-next-line babel/no-unused-expressions
!options.publishOnly && (await exec(`git push origin ${currentBranchName}`));
}
break;
Expand All @@ -92,7 +92,7 @@ export const publish = async (options: PublishOption) => {
default:
// Not sure what to do, so keep empty.
}
// eslint-disable-next-line no-unused-expressions
// eslint-disable-next-line babel/no-unused-expressions
options.exitAfterPublish && process.exit(0);
};

Expand Down
2 changes: 2 additions & 0 deletions src/built-in-plugins/ensure-project-files/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ function ensureTsconfig() {
lib: ['dom', 'es5', 'es6', 'es7', 'scripthost', 'es2018.promise'],
emitDecoratorMetadata: true,
preserveConstEnums: true,
isolatedModules: true,
noEmit: true,
paths: {
[`${PRI_PACKAGE_NAME}/*`]: [PRI_PACKAGE_NAME, path.join(tempTypesPath.dir, '*')],
...(pri.sourceConfig.type === 'project' && { 'src/*': ['src/*'] }),
Expand Down
2 changes: 1 addition & 1 deletion src/node/create-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function createCli(opts?: { pluginIncludeRoots: string[] }) {

registerYargs(yargs, commandRegisterMap);

// eslint-disable-next-line no-unused-expressions
// eslint-disable-next-line babel/no-unused-expressions
yargs.alias('help', 'h').alias('version', 'v').argv;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/utils/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class ProjectInfo {
*/
interface ICircularDetectConfig {
enable?: boolean;
exclude?: RegExp;
exclude?: string;
}

/**
Expand Down
10 changes: 3 additions & 7 deletions src/utils/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ import { typeChecker } from './type-checker';

export const eslintParam = "'./?(src|packages|docs|tests)/**/*.?(ts|tsx)'";

interface Options {
lintAll?: boolean;
needFix?: boolean;
showBreakError?: boolean;
typeCheck?: boolean;
}

class DefaultOptions {
lintAll = false;

Expand All @@ -33,7 +26,9 @@ export async function lint(options?: Partial<DefaultOptions>) {
// 通过 child_process 运行 pri,stdio 设置 pipe 模式时, 标准输出是异步的, 导致输出被截断,
// 此处判断在 pipe 模式设置成同步输出
if (!process.stdout.isTTY) {
// eslint-disable-next-line no-underscore-dangle
(process.stdout as any)?._handle?.setBlocking(true);
// eslint-disable-next-line no-underscore-dangle
(process.stderr as any)?._handle?.setBlocking(true);
}
const { CLIEngine } = await import('eslint');
Expand Down Expand Up @@ -61,6 +56,7 @@ export async function lint(options?: Partial<DefaultOptions>) {
lintFiles = glob.sync(lintFilesPattern);
lintFilesPattern = `"${lintFilesPattern}"`;
} else {
// eslint-disable-next-line max-len
lintFilesPattern = `${globalState.projectRootPath}/${packagesPath.dir}/${globalState.selectedSourceType}/**/*.{ts,tsx}`;
lintFiles = glob.sync(lintFilesPattern);
lintFilesPattern = `"${lintFilesPattern}"`;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function logSuccess(message: string) {
signale.success(message);
}

export async function spinner<T>(message: string, fn: (error: (message?: string) => void) => T): Promise<T> {
export async function spinner<T>(message: string, fn: (error: (msg?: string) => void) => T): Promise<T> {
const oraSpinner = ora(colors.green(message)).start();

let errorMessage: string = null;
Expand Down
1 change: 0 additions & 1 deletion src/utils/type-checker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { execSync } from 'child_process';
import * as process from 'process';
import { pri } from '../node';
import { logFatal, logInfo, logSuccess } from './log';

export function typeChecker() {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface IHtmlTemplateArgs {
appendBody?: string;
}

export type IOptions<T = {}> = {
export type IOptions<T = unknown> = {
mode: 'development' | 'production';
entryPath: string | string[] | IEntryPath;
htmlTemplatePath?: string;
Expand Down
3 changes: 2 additions & 1 deletion src/utils/webpack-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ export const runWebpackDevServer = async (opts: IOptions<IExtraOptions>) => {

// If set open in project config, perform a circular dependency check
if (globalState.projectConfig.circularDetect?.enable) {
const exclude = globalState.projectConfig.circularDetect?.exclude;
webpackConfig.plugins.push(
new CircularDependencyPlugin({
exclude: globalState.projectConfig.circularDetect?.exclude ?? /node_modules/,
exclude: exclude ? new RegExp(exclude) : /node_modules/,
cwd: process.cwd(),
}),
);
Expand Down
Loading

0 comments on commit 152175f

Please sign in to comment.