Skip to content

Commit

Permalink
fix(eslint): update import type sort
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Sep 20, 2022
1 parent fc097b6 commit 06d2605
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 24 deletions.
20 changes: 19 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions packages/taro-webpack5-prebundle/src/h5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions packages/taro-webpack5-prebundle/src/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion packages/taro-webpack5-prebundle/src/mini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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[]
}
Expand Down
14 changes: 8 additions & 6 deletions packages/taro-webpack5-prebundle/src/prebundle/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
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'
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<IProjectBaseConfig['compiler'], string | undefined>['prebundle']

export interface IPrebundleConfig {
Expand Down Expand Up @@ -43,7 +45,7 @@ export default class BasePrebundle<T extends IPrebundleConfig = IPrebundleConfig

deps: CollectedDeps = new Map()
measure: ReturnType<typeof getMeasure>
webpackConfig: webpack.Configuration
webpackConfig: Configuration

constructor (protected config: T, protected option: IPrebundle) {
if (!option.enable) return
Expand Down Expand Up @@ -222,7 +224,7 @@ export default class BasePrebundle<T extends IPrebundleConfig = IPrebundleConfig
}])
}

getRemoteWebpackCompiler (standard: webpack.Configuration, custom: webpack.Configuration = {}) {
getRemoteWebpackCompiler (standard: Configuration, custom: Configuration = {}) {
/** NOTE: 删除 Host 应用影响打包 Remote 应用的配置 */
const inherit = { ...this.webpackConfig }
delete inherit.devServer
Expand Down
4 changes: 3 additions & 1 deletion packages/taro-webpack5-prebundle/src/utils/webpack.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { promoteRelativePath } from '@tarojs/helper'
import path from 'path'
import { Chunk, Compilation, sources } from 'webpack'
import { sources } from 'webpack'

import type { Chunk, Compilation } from 'webpack'

const { ConcatSource } = sources

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* MIT License http://www.opensource.org/licenses/mit-license.php
* Author Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy, Marais Rossouw @maraisr
*/
import webpack, { sources } from 'webpack'
import webpack, { RuntimeGlobals, sources, Template } from 'webpack'
import ContainerPlugin from 'webpack/lib/container/ContainerPlugin'

const { ConcatSource } = sources

const { Template, RuntimeGlobals } = webpack
const ContainerEntryModule = require('webpack/lib/container/ContainerEntryModule')

type Exposes = ConstructorParameters<typeof ContainerPlugin>[0]['exposes']
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Compilation['dependencyFactories']> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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 ||
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 06d2605

Please sign in to comment.