From 06d26052da585690bc9ee48a3cfa50460d63e400 Mon Sep 17 00:00:00 2001 From: Zakary Date: Tue, 20 Sep 2022 16:13:51 +0800 Subject: [PATCH] fix(eslint): update import type sort --- .eslintrc.js | 20 ++++++++++++++++++- packages/taro-webpack5-prebundle/src/h5.ts | 5 +++-- packages/taro-webpack5-prebundle/src/index.ts | 9 +++++---- packages/taro-webpack5-prebundle/src/mini.ts | 4 +++- .../src/prebundle/index.ts | 14 +++++++------ .../src/utils/webpack.ts | 4 +++- .../src/webpack/TaroContainerEntryModule.ts | 3 +-- .../TaroContainerEntryModuleFactory.ts | 4 ++-- .../src/webpack/TaroContainerPlugin.ts | 3 ++- .../src/webpack/TaroModuleFederationPlugin.ts | 6 +++--- .../src/webpack/TaroRemoteRuntimeModule.ts | 4 +++- 11 files changed, 52 insertions(+), 24 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 26aaef57d1ae..694dbff8cdf4 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -50,7 +50,25 @@ module.exports = { 'react/no-find-dom-node': 0, quotes: [2, 'single', { avoidEscape: true, allowTemplateLiterals: true }], semi: [2, 'never'], - 'simple-import-sort/imports': 2, + 'simple-import-sort/imports': [2, { + groups: [ + // Side effect imports. + ['^\\u0000'], + // Node.js builtins prefixed with `node:`. + ['^node:'], + // Packages. + // Things that start with a letter (or digit or underscore), or `@` followed by a letter. + ['^@?\\w'], + // Absolute imports and other imports such as Vue-style `@/foo`. + // Anything not matched in another group. + ['^'], + // Relative imports. + // Anything that starts with a dot. + ['^\\.'], + // Types Group + ['^node:.*\\u0000$', '^@?\\w.*\\u0000$', '(?<=\\u0000)$', '^\\..*\\u0000$'], + ] + }], 'simple-import-sort/exports': 2, 'space-before-function-paren': [2, 'always'], 'standard/no-callback-literal': 0 diff --git a/packages/taro-webpack5-prebundle/src/h5.ts b/packages/taro-webpack5-prebundle/src/h5.ts index 7b227c139950..9bb184cd3739 100644 --- a/packages/taro-webpack5-prebundle/src/h5.ts +++ b/packages/taro-webpack5-prebundle/src/h5.ts @@ -26,11 +26,9 @@ import { chalk } from '@tarojs/helper' import fs from 'fs-extra' import path from 'path' import { performance } from 'perf_hooks' -import { Configuration, Stats } from 'webpack' import webpackDevServer from 'webpack-dev-server' import VirtualModulesPlugin from 'webpack-virtual-modules' -import type { IPrebundle } from './prebundle' import BasePrebundle, { IPrebundleConfig } from './prebundle' import { flattenId, @@ -40,6 +38,9 @@ import { import { assetsRE, MF_NAME } from './utils/constant' import TaroModuleFederationPlugin from './webpack/TaroModuleFederationPlugin' +import type { Configuration, Stats } from 'webpack' +import type { IPrebundle } from './prebundle' + export const VirtualModule = new VirtualModulesPlugin() export interface IH5PrebundleConfig extends IPrebundleConfig { diff --git a/packages/taro-webpack5-prebundle/src/index.ts b/packages/taro-webpack5-prebundle/src/index.ts index 366a0a64446f..421a36cdf01e 100644 --- a/packages/taro-webpack5-prebundle/src/index.ts +++ b/packages/taro-webpack5-prebundle/src/index.ts @@ -1,11 +1,12 @@ -import { EntryObject } from 'webpack' -import Chain from 'webpack-chain' import webpackDevServer from 'webpack-dev-server' -import { IH5PrebundleConfig } from './h5' -import { IMiniPrebundleConfig } from './mini' import BasePrebundle, { IPrebundle } from './prebundle' +import type { EntryObject } from 'webpack' +import type Chain from 'webpack-chain' +import type { IH5PrebundleConfig } from './h5' +import type { IMiniPrebundleConfig } from './mini' + export * from './prebundle' export interface IPrebundleParam { diff --git a/packages/taro-webpack5-prebundle/src/mini.ts b/packages/taro-webpack5-prebundle/src/mini.ts index 0377278bfe9c..a0888f3e17ce 100644 --- a/packages/taro-webpack5-prebundle/src/mini.ts +++ b/packages/taro-webpack5-prebundle/src/mini.ts @@ -25,7 +25,7 @@ import fs from 'fs-extra' import path from 'path' import { performance } from 'perf_hooks' -import { ProvidePlugin, Stats } from 'webpack' +import { ProvidePlugin } from 'webpack' import BasePrebundle, { IPrebundleConfig } from './prebundle' import { bundle } from './prebundle/bundle' @@ -37,6 +37,8 @@ import { import { MF_NAME } from './utils/constant' import TaroModuleFederationPlugin from './webpack/TaroModuleFederationPlugin' +import type { Stats } from 'webpack' + export interface IMiniPrebundleConfig extends IPrebundleConfig { runtimePath?: string | string[] } diff --git a/packages/taro-webpack5-prebundle/src/prebundle/index.ts b/packages/taro-webpack5-prebundle/src/prebundle/index.ts index 8fc879335e0e..83808a0bcc0f 100644 --- a/packages/taro-webpack5-prebundle/src/prebundle/index.ts +++ b/packages/taro-webpack5-prebundle/src/prebundle/index.ts @@ -1,11 +1,8 @@ -import { Config } from '@swc/core' import { chalk, fs, readConfig, recursiveMerge, resolveMainFilePath, terminalLink } from '@tarojs/helper' -import { IProjectBaseConfig } from '@tarojs/taro/types/compile' import { Message } from 'esbuild' import path from 'path' import { performance } from 'perf_hooks' -import webpack, { EntryObject } from 'webpack' -import Chain from 'webpack-chain' +import webpack from 'webpack' import { commitMeta, createResolve, getBundleHash, getCacheDir, getMeasure, Metadata, sortDeps } from '../utils' import { CollectedDeps, MF_NAME } from '../utils/constant' @@ -13,6 +10,11 @@ import TaroModuleFederationPlugin from '../webpack/TaroModuleFederationPlugin' import { bundle } from './bundle' import { scanImports } from './scanImports' +import type { Config } from '@swc/core' +import type { IProjectBaseConfig } from '@tarojs/taro/types/compile' +import type { Configuration, EntryObject } from 'webpack' +import type Chain from 'webpack-chain' + export type IPrebundle = Exclude['prebundle'] export interface IPrebundleConfig { @@ -43,7 +45,7 @@ export default class BasePrebundle - webpackConfig: webpack.Configuration + webpackConfig: Configuration constructor (protected config: T, protected option: IPrebundle) { if (!option.enable) return @@ -222,7 +224,7 @@ export default class BasePrebundle[0]['exposes'] diff --git a/packages/taro-webpack5-prebundle/src/webpack/TaroContainerEntryModuleFactory.ts b/packages/taro-webpack5-prebundle/src/webpack/TaroContainerEntryModuleFactory.ts index 5e7d1eb39e22..c0f5514a604f 100644 --- a/packages/taro-webpack5-prebundle/src/webpack/TaroContainerEntryModuleFactory.ts +++ b/packages/taro-webpack5-prebundle/src/webpack/TaroContainerEntryModuleFactory.ts @@ -1,7 +1,7 @@ -import { Compilation } from 'webpack' - import TaroContainerEntryModule from './TaroContainerEntryModule' +import type { Compilation } from 'webpack' + const ContainerEntryModuleFactory = require('webpack/lib/container/ContainerEntryModuleFactory') export default class TaroContainerEntryModuleFactory extends ContainerEntryModuleFactory implements MapValue { diff --git a/packages/taro-webpack5-prebundle/src/webpack/TaroContainerPlugin.ts b/packages/taro-webpack5-prebundle/src/webpack/TaroContainerPlugin.ts index fa8d32614ff4..c457782fac48 100644 --- a/packages/taro-webpack5-prebundle/src/webpack/TaroContainerPlugin.ts +++ b/packages/taro-webpack5-prebundle/src/webpack/TaroContainerPlugin.ts @@ -3,11 +3,12 @@ * MIT License http://www.opensource.org/licenses/mit-license.php * Author Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy, Marais Rossouw @maraisr */ -import { Compiler } from 'webpack' import ContainerPlugin from 'webpack/lib/container/ContainerPlugin' import TaroContainerEntryModuleFactory from './TaroContainerEntryModuleFactory' +import type { Compiler } from 'webpack' + const ContainerEntryDependency = require('webpack/lib/container/ContainerEntryDependency') const PLUGIN_NAME = 'TaroContainerPlugin' diff --git a/packages/taro-webpack5-prebundle/src/webpack/TaroModuleFederationPlugin.ts b/packages/taro-webpack5-prebundle/src/webpack/TaroModuleFederationPlugin.ts index 57faddfb1250..282d6399d434 100644 --- a/packages/taro-webpack5-prebundle/src/webpack/TaroModuleFederationPlugin.ts +++ b/packages/taro-webpack5-prebundle/src/webpack/TaroModuleFederationPlugin.ts @@ -4,16 +4,15 @@ * Author Tobias Koppers @sokra and Zackary Jackson @ScriptedAlchemy */ import _ from 'lodash' -import { Compiler, sharing } from 'webpack' import ModuleFederationPlugin from 'webpack/lib/container/ModuleFederationPlugin' import isValidExternalsType from 'webpack/schemas/plugins/container/ExternalsType.check.js' -import type { ContainerReferencePluginOptions, ModuleFederationPluginOptions } from 'webpack/types' import { CollectedDeps } from '../utils/constant' import TaroContainerPlugin from './TaroContainerPlugin' import TaroContainerReferencePlugin from './TaroContainerReferencePlugin' -const { SharePlugin } = sharing +import type { Compiler } from 'webpack' +import type { ContainerReferencePluginOptions, ModuleFederationPluginOptions } from 'webpack/types' const PLUGIN_NAME = 'TaroModuleFederationPlugin' @@ -41,6 +40,7 @@ export default class TaroModuleFederationPlugin extends ModuleFederationPlugin { /** Apply the plugin */ apply (compiler: Compiler) { + const { SharePlugin } = compiler.webpack.sharing const { _options: options } = this const library = options.library || { type: 'var', name: options.name } const remoteType = options.remoteType || diff --git a/packages/taro-webpack5-prebundle/src/webpack/TaroRemoteRuntimeModule.ts b/packages/taro-webpack5-prebundle/src/webpack/TaroRemoteRuntimeModule.ts index fc92941f0dd2..8ae5c29e599f 100644 --- a/packages/taro-webpack5-prebundle/src/webpack/TaroRemoteRuntimeModule.ts +++ b/packages/taro-webpack5-prebundle/src/webpack/TaroRemoteRuntimeModule.ts @@ -1,4 +1,6 @@ -import { ChunkGraph, Compilation, RuntimeGlobals, RuntimeModule, Template } from 'webpack' +import { RuntimeGlobals, RuntimeModule, Template } from 'webpack' + +import type { ChunkGraph, Compilation } from 'webpack' import type RemoteModule from 'webpack/lib/container/RemoteModule' export default class TaroRemoteRuntimeModule extends RuntimeModule {