From 769ca8ea9134f4bfe4f7e9c958904d20fb228dad Mon Sep 17 00:00:00 2001 From: Gengkun Date: Wed, 13 Mar 2024 21:16:52 +0800 Subject: [PATCH] chore: fix lint-staged prettier (#5935) * fix version * fix --- lint-staged.config.mjs | 4 +- package.json | 6 +-- packages/rspack-plugin-minify/src/index.js | 2 +- packages/rspack-test-tools/src/case/watch.ts | 4 +- .../rspack-test-tools/src/processor/multi.ts | 6 +-- .../rspack-test-tools/src/processor/normal.ts | 4 +- .../rspack-test-tools/src/runner/basic.ts | 5 +- .../src/runner/runner/basic.ts | 8 +-- packages/rspack/src/builtin-plugin/index.ts | 6 +-- packages/rspack/src/config/adapter.ts | 53 ++++++++++--------- packages/rspack/src/config/defaults.ts | 8 +-- packages/rspack/src/config/normalization.ts | 12 ++--- packages/rspack/src/lite-tapable/index.ts | 2 +- packages/rspack/src/rspack.ts | 6 ++- .../rspack/src/sharing/ConsumeSharedPlugin.ts | 10 ++-- .../src/stats/DefaultStatsFactoryPlugin.ts | 4 +- .../rspack/src/stats/statsFactoryUtils.ts | 4 +- packages/rspack/src/util/index.ts | 8 +-- pnpm-lock.yaml | 18 ++++--- 19 files changed, 90 insertions(+), 80 deletions(-) diff --git a/lint-staged.config.mjs b/lint-staged.config.mjs index 5c72595d300..876472e8fca 100644 --- a/lint-staged.config.mjs +++ b/lint-staged.config.mjs @@ -1,8 +1,6 @@ export default { "*.rs": "rustfmt --edition 2021", - "packages/**/*.{ts,js}": "prettier --write", - "x.mjs": "prettier --write", - "crates/rspack_plugin_runtime/**/*.{ts,js}": "prettier --write", + "*.{ts,js}": "pnpm run format:js", "*.toml": "npx @taplo/cli format", "*.{ts,js,mjs}": () => "pnpm run lint:js" } diff --git a/package.json b/package.json index fb03d5efb29..ef74f4e6bd3 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "build:viewer": "pnpm --filter \"@rspack/*\" build:viewer", "test:js": "pnpm -r run test", "format:rs": "pnpm --filter @rspack/core... build", - "format:js": "npx prettier 'packages/**/src/**/*.{ts,js}' 'crates/rspack_plugin_runtime/**/*.{ts,js}' --check --write", + "format:js": "./node_modules/prettier/bin/prettier.cjs 'packages/**/src/**/*.{ts,js}' 'crates/rspack_plugin_runtime/**/*.{ts,js}' 'x.mjs' --check --write", "format-ci:toml": "npx @taplo/cli format --check '.cargo/*.toml' './crates/**/Cargo.toml' './Cargo.toml'", "format:toml": "npx @taplo/cli format '.cargo/*.toml' './crates/**/Cargo.toml' './Cargo.toml'", "lint:js": "oxlint --deny-warnings -c .eslintrc.json", @@ -60,8 +60,8 @@ "lint-staged": "^15.0.0", "npm-run-all": "4.1.5", "oxlint": "0.2.10", - "prettier": "3.2", - "prettier-2": "npm:prettier@^2", + "prettier": "3.2.5", + "prettier-2": "npm:prettier@2.8.8", "rimraf": "3.0.2", "ts-jest": "29.1.2", "typescript": "5.0.2", diff --git a/packages/rspack-plugin-minify/src/index.js b/packages/rspack-plugin-minify/src/index.js index 3e51f58c061..c8250bef777 100644 --- a/packages/rspack-plugin-minify/src/index.js +++ b/packages/rspack-plugin-minify/src/index.js @@ -82,7 +82,7 @@ module.exports = class RspackMinifyPlugin { sourceAsString, map, true - ) + ) : new RawSource(result.code), { ...asset.info, diff --git a/packages/rspack-test-tools/src/case/watch.ts b/packages/rspack-test-tools/src/case/watch.ts index b5c5e2a9fe7..4c2c0bb1a11 100644 --- a/packages/rspack-test-tools/src/case/watch.ts +++ b/packages/rspack-test-tools/src/case/watch.ts @@ -57,13 +57,13 @@ const creator = new WatchCaseCreator({ stepName: run.name, tempDir: temp!, runable: true - }) + }) : new RspackWatchStepProcessor({ name, stepName: run.name, tempDir: temp!, runable: true - }) + }) ); } }); diff --git a/packages/rspack-test-tools/src/processor/multi.ts b/packages/rspack-test-tools/src/processor/multi.ts index 9aa614fce9e..34de601b226 100644 --- a/packages/rspack-test-tools/src/processor/multi.ts +++ b/packages/rspack-test-tools/src/processor/multi.ts @@ -56,8 +56,8 @@ export class MultiTaskProcessor const bundles = Array.isArray(curBundles) ? curBundles : curBundles - ? [curBundles] - : []; + ? [curBundles] + : []; const multiFileIndexMap: Record = context.getValue(_multiOptions.name, "multiFileIndexMap") || {}; @@ -91,7 +91,7 @@ export class MultiTaskProcessor ) ? readConfigFile( this._multiOptions.configFiles!.map(i => context.getSource(i)) - ) + ) : [{}]; for (let [index, options] of caseOptions.entries()) { diff --git a/packages/rspack-test-tools/src/processor/normal.ts b/packages/rspack-test-tools/src/processor/normal.ts index 4e4f890ec4f..c9dc00a415b 100644 --- a/packages/rspack-test-tools/src/processor/normal.ts +++ b/packages/rspack-test-tools/src/processor/normal.ts @@ -64,7 +64,7 @@ export class RspackNormalProcessor extends BasicTaskProcessor implements TRunnerFactory { - constructor(protected name: string, protected context: ITestContext) {} + constructor( + protected name: string, + protected context: ITestContext + ) {} create( file: string, diff --git a/packages/rspack-test-tools/src/runner/runner/basic.ts b/packages/rspack-test-tools/src/runner/runner/basic.ts index 98fa8455ade..e703fae8470 100644 --- a/packages/rspack-test-tools/src/runner/runner/basic.ts +++ b/packages/rspack-test-tools/src/runner/runner/basic.ts @@ -155,9 +155,11 @@ export class BasicRunner if (modules && modulePathStr in modules) { return modules[modulePathStr]; } else { - return require(modulePathStr.startsWith("node:") - ? modulePathStr.slice(5) - : modulePathStr); + return require( + modulePathStr.startsWith("node:") + ? modulePathStr.slice(5) + : modulePathStr + ); } }; } diff --git a/packages/rspack/src/builtin-plugin/index.ts b/packages/rspack/src/builtin-plugin/index.ts index 1c62865f1eb..77ee9c0f47c 100644 --- a/packages/rspack/src/builtin-plugin/index.ts +++ b/packages/rspack/src/builtin-plugin/index.ts @@ -69,8 +69,8 @@ function resolveTreeShaking( return treeShaking !== undefined ? treeShaking.toString() : production - ? "true" - : "false"; + ? "true" + : "false"; } export interface Builtins { @@ -97,7 +97,7 @@ export function deprecated_resolveBuiltins( ...builtins.css?.modules }, namedExports: builtins.css?.namedExports - } + } : undefined, treeShaking: resolveTreeShaking(builtins.treeShaking, production) }; diff --git a/packages/rspack/src/config/adapter.ts b/packages/rspack/src/config/adapter.ts index 2fdf38cccf0..dade608804f 100644 --- a/packages/rspack/src/config/adapter.ts +++ b/packages/rspack/src/config/adapter.ts @@ -174,7 +174,7 @@ function getRawResolve(resolve: Resolve): RawOptions["resolve"] { referencesType: references == "auto" ? "auto" : references ? "manual" : "disabled", references: references == "auto" ? undefined : references - } + } : undefined, byDependency: getRawResolveByDependency(resolve.byDependency) }; @@ -255,7 +255,7 @@ export function getRawLibrary(library: LibraryOptions): RawLibraryOptions { commonjs2: auxiliaryComment, amd: auxiliaryComment, root: auxiliaryComment - } + } : auxiliaryComment, libraryType: type, name: isNil(name) ? name : getRawLibraryName(name), @@ -398,7 +398,7 @@ const getRawModuleRule = ( k, getRawRuleSetCondition(v) ]) - ) + ) : undefined, resource: rule.resource ? getRawRuleSetCondition(rule.resource) : undefined, resourceQuery: rule.resourceQuery @@ -420,7 +420,7 @@ const getRawModuleRule = ( `${path}.use`, options ) - }, + }, type: rule.type, parser: rule.parser ? getRawParserOptions(rule.parser, rule.type ?? "javascript/auto") @@ -432,12 +432,12 @@ const getRawModuleRule = ( oneOf: rule.oneOf ? rule.oneOf.map((rule, index) => getRawModuleRule(rule, `${path}.oneOf[${index}]`, options) - ) + ) : undefined, rules: rule.rules ? rule.rules.map((rule, index) => getRawModuleRule(rule, `${path}.rules[${index}]`, options) - ) + ) : undefined, enforce: rule.enforce }; @@ -456,27 +456,30 @@ const getRawModuleRule = ( delete rawModuleRule.resourceQuery; delete rawModuleRule.resourceFragment; - rawModuleRule.rspackResource = getRawRuleSetCondition(function ( - resourceQueryFragment - ) { - const { path, query, fragment } = parseResource(resourceQueryFragment); + rawModuleRule.rspackResource = getRawRuleSetCondition( + function (resourceQueryFragment) { + const { path, query, fragment } = parseResource(resourceQueryFragment); - if (rule.test && !tryMatch(path, rule.test)) { - return false; - } else if (rule.resource && !tryMatch(path, rule.resource)) { - return false; - } + if (rule.test && !tryMatch(path, rule.test)) { + return false; + } else if (rule.resource && !tryMatch(path, rule.resource)) { + return false; + } - if (rule.resourceQuery && !tryMatch(query, rule.resourceQuery)) { - return false; - } + if (rule.resourceQuery && !tryMatch(query, rule.resourceQuery)) { + return false; + } - if (rule.resourceFragment && !tryMatch(fragment, rule.resourceFragment)) { - return false; - } + if ( + rule.resourceFragment && + !tryMatch(fragment, rule.resourceFragment) + ) { + return false; + } - return true; - }); + return true; + } + ); } return rawModuleRule; }; @@ -579,8 +582,8 @@ function getRawJavascriptParserOptions(parser: JavascriptParserOptions) { parser.url === false ? "false" : parser.url === "relative" - ? parser.url - : "true" + ? parser.url + : "true" }; } diff --git a/packages/rspack/src/config/defaults.ts b/packages/rspack/src/config/defaults.ts index 656055ad58a..bfdc38770c1 100644 --- a/packages/rspack/src/config/defaults.ts +++ b/packages/rspack/src/config/defaults.ts @@ -60,8 +60,8 @@ export const applyRspackOptionsDefaults = ( target === false ? false : typeof target === "string" - ? getTargetProperties(target, options.context!) - : getTargetsProperties(target, options.context!); + ? getTargetProperties(target, options.context!) + : getTargetsProperties(target, options.context!); const development = mode === "development"; const production = mode === "production" || !mode; @@ -114,8 +114,8 @@ export const applyRspackOptionsDefaults = ( return options.output.library ? options.output.library.type : options.output.module - ? "module" - : "var"; + ? "module" + : "var"; }); applyNodeDefaults(options.node, { targetProperties }); diff --git a/packages/rspack/src/config/normalization.ts b/packages/rspack/src/config/normalization.ts index 16634a1fd24..0920d94c20e 100644 --- a/packages/rspack/src/config/normalization.ts +++ b/packages/rspack/src/config/normalization.ts @@ -95,7 +95,7 @@ export const getNormalizedRspackOptions = ( return ignore.test(warning.message); }; } - }) + }) : undefined, name: config.name, dependencies: config.dependencies, @@ -115,10 +115,10 @@ export const getNormalizedRspackOptions = ( "type" in library ? library : libraryAsName || output.libraryTarget - ? ({ - name: libraryAsName - } as LibraryOptions) - : undefined; + ? ({ + name: libraryAsName + } as LibraryOptions) + : undefined; return { path: output.path, publicPath: output.publicPath, @@ -396,7 +396,7 @@ const keyedNestedConfig = ( obj ), {} as Record - ); + ); if (customKeys) { for (const key of Object.keys(customKeys)) { if (!(key in result)) { diff --git a/packages/rspack/src/lite-tapable/index.ts b/packages/rspack/src/lite-tapable/index.ts index 04f6edb6256..2993629a69c 100644 --- a/packages/rspack/src/lite-tapable/index.ts +++ b/packages/rspack/src/lite-tapable/index.ts @@ -3,7 +3,7 @@ type FixedSizeArray = T extends 0 : ReadonlyArray & { 0: U; length: T; - }; + }; type Measure = T extends 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ? T : never; diff --git a/packages/rspack/src/rspack.ts b/packages/rspack/src/rspack.ts index e80bdff1eb5..64d33f0ec51 100644 --- a/packages/rspack/src/rspack.ts +++ b/packages/rspack/src/rspack.ts @@ -147,8 +147,10 @@ function rspack( } else { const { compiler, watch } = create(); if (watch) { - util.deprecate(() => {}, - "A 'callback' argument needs to be provided to the 'rspack(options, callback)' function when the 'watch' option is set. There is no way to handle the 'watch' option without a callback.")(); + util.deprecate( + () => {}, + "A 'callback' argument needs to be provided to the 'rspack(options, callback)' function when the 'watch' option is set. There is no way to handle the 'watch' option without a callback." + )(); } return compiler; } diff --git a/packages/rspack/src/sharing/ConsumeSharedPlugin.ts b/packages/rspack/src/sharing/ConsumeSharedPlugin.ts index deac1620243..295580c1a26 100644 --- a/packages/rspack/src/sharing/ConsumeSharedPlugin.ts +++ b/packages/rspack/src/sharing/ConsumeSharedPlugin.ts @@ -48,7 +48,7 @@ export class ConsumeSharedPlugin extends RspackBuiltinPlugin { let result = item === key || !isRequiredVersion(item) ? // item is a request/key - { + { import: key, shareScope: options.shareScope || "default", shareKey: key, @@ -57,10 +57,10 @@ export class ConsumeSharedPlugin extends RspackBuiltinPlugin { strictVersion: false, singleton: false, eager: false - } + } : // key is a request/key - // item is a version - { + // item is a version + { import: key, shareScope: options.shareScope || "default", shareKey: key, @@ -69,7 +69,7 @@ export class ConsumeSharedPlugin extends RspackBuiltinPlugin { packageName: undefined, singleton: false, eager: false - }; + }; return result; }, (item, key) => ({ diff --git a/packages/rspack/src/stats/DefaultStatsFactoryPlugin.ts b/packages/rspack/src/stats/DefaultStatsFactoryPlugin.ts index ea705dc95db..e073bdfc7df 100644 --- a/packages/rspack/src/stats/DefaultStatsFactoryPlugin.ts +++ b/packages/rspack/src/stats/DefaultStatsFactoryPlugin.ts @@ -112,13 +112,13 @@ const ASSETS_GROUPERS: Record< [name]: !!key, filteredChildren: assets.length, ...assetGroup(children) - } + } : { type: "assets by status", [name]: !!key, children, ...assetGroup(children) - }; + }; } }); }; diff --git a/packages/rspack/src/stats/statsFactoryUtils.ts b/packages/rspack/src/stats/statsFactoryUtils.ts index 3a9cc7181fe..8629dbefcc7 100644 --- a/packages/rspack/src/stats/statsFactoryUtils.ts +++ b/packages/rspack/src/stats/statsFactoryUtils.ts @@ -309,8 +309,8 @@ const getItemSize = (item: Child) => { return !item.children ? 1 : item.filteredChildren - ? 2 + getTotalSize(item.children) - : 1 + getTotalSize(item.children); + ? 2 + getTotalSize(item.children) + : 1 + getTotalSize(item.children); }; export const spaceLimited = ( diff --git a/packages/rspack/src/util/index.ts b/packages/rspack/src/util/index.ts index 8659809b210..a7f60dfd726 100644 --- a/packages/rspack/src/util/index.ts +++ b/packages/rspack/src/util/index.ts @@ -77,10 +77,10 @@ export function concatErrorMsgAndStack(err: Error | JsStatsError): string { return isJsStatsError(err) ? err.formatted : err.stack - ? err.stack.startsWith(`${stackStartPrefix}${err.message}`) - ? `${err.stack}` - : `${err.message}\n${err.stack}` - : `${err.message}`; + ? err.stack.startsWith(`${stackStartPrefix}${err.message}`) + ? `${err.stack}` + : `${err.message}\n${err.stack}` + : `${err.message}`; } export function indent(str: string, prefix: string) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a5d8cb48c04..d92b8d13388 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -54,10 +54,10 @@ importers: specifier: 0.2.10 version: 0.2.10 prettier: - specifier: '3.2' - version: 3.2.4 + specifier: 3.2.5 + version: 3.2.5 prettier-2: - specifier: npm:prettier@^2 + specifier: npm:prettier@2.8.8 version: /prettier@2.8.8 rimraf: specifier: 3.0.2 @@ -4931,7 +4931,7 @@ packages: '@swc/helpers': optional: true dependencies: - '@swc/counter': 0.1.2 + '@swc/counter': 0.1.3 '@swc/types': 0.1.5 optionalDependencies: '@swc/core-darwin-arm64': 1.3.99 @@ -4944,12 +4944,8 @@ packages: '@swc/core-win32-ia32-msvc': 1.3.99 '@swc/core-win32-x64-msvc': 1.3.99 - /@swc/counter@0.1.2: - resolution: {integrity: sha512-9F4ys4C74eSTEUNndnER3VJ15oru2NumfQxS8geE+f3eB5xvfxpWyqE5XlVnxb/R14uoXi6SLbBwwiDSkv+XEw==} - /@swc/counter@0.1.3: resolution: {integrity: sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==} - dev: true /@swc/helpers@0.5.1: resolution: {integrity: sha512-sJ902EfIzn1Fa+qYmjdQqh8tPsoxyBz+8yBKC2HKUxyezKJFwPGOn7pv4WY6QuQW//ySQi5lJjA/ZT9sNWWNTg==} @@ -13433,6 +13429,12 @@ packages: hasBin: true dev: true + /prettier@3.2.5: + resolution: {integrity: sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==} + engines: {node: '>=14'} + hasBin: true + dev: true + /pretty-bytes@5.6.0: resolution: {integrity: sha512-FFw039TmrBqFK8ma/7OL3sDz/VytdtJr044/QUJtH0wK9lb9jLq9tJyIxUwtQJHwar2BqtiA4iCWSwo9JLkzFg==} engines: {node: '>=6'}