Skip to content

Commit

Permalink
chore: use prettier3 to format code (#6181)
Browse files Browse the repository at this point in the history
chore: use prettier3!
  • Loading branch information
ahabhgk authored Apr 10, 2024
1 parent bbc8338 commit 958b557
Show file tree
Hide file tree
Showing 37 changed files with 168 additions and 155 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"build:viewer": "pnpm --filter \"@rspack/*\" build:viewer",
"test:js": "pnpm -r run test",
"format:rs": "pnpm --filter @rspack/core... build",
"format:js": "prettier \"packages/**/src/**/*.{ts,js}\" \"crates/rspack_plugin_runtime/**/*.{ts,js}\" \"x.mjs\" --check --write",
"format-ci:js": "prettier \"packages/**/src/**/*.{ts,js}\" \"crates/rspack_plugin_runtime/**/*.{ts,js}\" \"x.mjs\" --check",
"format:js": "pnpm run format-ci:js --write",
"format-ci:js": "node ./node_modules/prettier/bin/prettier.cjs \"packages/**/src/**/*.{ts,js}\" \"crates/rspack_plugin_runtime/**/*.{ts,js}\" \"x.mjs\" --check",
"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",
Expand Down Expand Up @@ -71,4 +71,4 @@
"why-is-node-running": "2.2.2"
},
"packageManager": "[email protected]"
}
}
6 changes: 3 additions & 3 deletions packages/rspack-cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export class BuildCommand implements RspackCommand {
children: compiler.compilers.map(compiler =>
compiler.options ? compiler.options.stats : undefined
)
}
}
: compiler.options
? compiler.options.stats
: undefined;
? compiler.options.stats
: undefined;
if (options.json && createJsonStringifyStream) {
const handleWriteError = (error: Error) => {
logger.error(error);
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-cli/src/commands/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async function getPreviewConfig(
directory: options.dir
? path.join(item.context ?? process.cwd(), options.dir)
: item.output?.path ??
path.join(item.context ?? process.cwd(), defaultRoot),
path.join(item.context ?? process.cwd(), defaultRoot),
publicPath: options.publicPath ?? "/"
},
port: options.port ?? 8080,
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-dev-server/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export function getRspackMemoryAssets(
// @ts-expect-error
const filename = path.startsWith(publicPath)
? // @ts-expect-error
path.slice(publicPath.length)
path.slice(publicPath.length)
: // @ts-expect-error
path.slice(1);
path.slice(1);
const buffer =
compiler.getAsset(filename) ??
(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-plugin-minify/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module.exports = class RspackMinifyPlugin {
sourceAsString,
map,
true
)
)
: new RawSource(result.code),
{
...asset.info,
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-test-tools/src/case/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ const creator = new BasicCaseCreator({
stepName: run.name,
tempDir: temp!,
runable: true
})
})
: new RspackWatchStepProcessor({
name,
stepName: run.name,
tempDir: temp!,
runable: true
})
})
);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ export class WebpackModulePlaceholderPlugin {
const webpackLibPath = which(compiler.constructor).path;
const Template = require(path.join(webpackLibPath, "Template.js"));
Template.renderRuntimeModules = createRenderRuntimeModulesFn(Template);
const JavascriptModulesPlugin = require(path.join(
webpackLibPath,
"javascript/JavascriptModulesPlugin.js"
));
const JavascriptModulesPlugin = require(
path.join(webpackLibPath, "javascript/JavascriptModulesPlugin.js")
);
compiler.hooks.compilation.tap("RuntimeDiffPlugin", compilation => {
const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
hooks.inlineInRuntimeBailout.tap(
Expand Down
6 changes: 3 additions & 3 deletions packages/rspack-test-tools/src/processor/multi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export class MultiTaskProcessor<T extends ECompilerType = ECompilerType.Rspack>
const bundles = Array.isArray(curBundles)
? curBundles
: curBundles
? [curBundles]
: [];
? [curBundles]
: [];

const multiFileIndexMap: Record<string, number[]> =
context.getValue(_multiOptions.name, "multiFileIndexMap") || {};
Expand Down Expand Up @@ -91,7 +91,7 @@ export class MultiTaskProcessor<T extends ECompilerType = ECompilerType.Rspack>
)
? readConfigFile(
this._multiOptions.configFiles!.map(i => context.getSource(i))
)
)
: [{}];

for (let [index, options] of caseOptions.entries()) {
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-test-tools/src/processor/normal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class RspackNormalProcessor extends BasicTaskProcessor<ECompilerType.Rspa
// emitOnErrors: true,
minimizer: [terserForTesting],
...testConfig.optimization
}
}
: {
removeAvailableModules: true,
removeEmptyChunks: true,
Expand All @@ -90,7 +90,7 @@ export class RspackNormalProcessor extends BasicTaskProcessor<ECompilerType.Rspa
chunkIds: "named",
minimizer: [terserForTesting],
...compilerOptions?.optimization
},
},
// CHANGE: rspack does not support `performance` yet.
// performance: {
// hints: false
Expand Down
5 changes: 4 additions & 1 deletion packages/rspack-test-tools/src/runner/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { EsmRunner } from "./runner/esm";
export class BasicRunnerFactory<T extends ECompilerType>
implements TRunnerFactory<T>
{
constructor(protected name: string, protected context: ITestContext) {}
constructor(
protected name: string,
protected context: ITestContext
) {}

create(
file: string,
Expand Down
8 changes: 5 additions & 3 deletions packages/rspack-test-tools/src/runner/runner/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ export class BasicRunner<T extends ECompilerType = ECompilerType.Rspack>
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
);
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack/src/Compilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
assetInfoUpdateOrFunction === undefined
? assetInfoUpdateOrFunction
: typeof assetInfoUpdateOrFunction === "function"
? jsAssetInfo => toJsAssetInfo(assetInfoUpdateOrFunction(jsAssetInfo))
: toJsAssetInfo(assetInfoUpdateOrFunction)
? jsAssetInfo => toJsAssetInfo(assetInfoUpdateOrFunction(jsAssetInfo))
: toJsAssetInfo(assetInfoUpdateOrFunction)
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/rspack/src/MultiStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export default class MultiStats {
...(typeof childOptions === "string"
? { preset: childOptions }
: childOptions && typeof childOptions === "object"
? childOptions
: undefined)
? childOptions
: undefined)
},
context
);
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack/src/builtin-plugin/HtmlRspackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export const HtmlRspackPlugin = create(
? "body"
: "head"
: configInject === false
? "false"
: configInject;
? "false"
: configInject;
return {
...c,
meta,
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack/src/builtin-plugin/css-extract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ export class CssExtractRspackPlugin {
typeof options.linkType === "undefined"
? JSON.stringify("text/css")
: options.linkType === false
? undefined
: JSON.stringify(options.linkType),
? undefined
: JSON.stringify(options.linkType),
attributes: options.attributes
? (Reflect.ownKeys(options.attributes)
.map(k => [
Expand Down
16 changes: 8 additions & 8 deletions packages/rspack/src/builtin-plugin/css-extract/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ function hotLoader(
context.loaderContext,
path.join(__dirname, "./hmr/hotModuleReplacement.js")
)})(module.id, ${JSON.stringify({
...context.options,
locals: !!context.locals
})});
...context.options,
locals: !!context.locals
})});
module.hot.dispose(cssReload);
${accept}
}
Expand Down Expand Up @@ -132,7 +132,7 @@ export const pitch: LoaderDefinition["pitch"] = function (request, _, data) {
: `${ABSOLUTE_PUBLIC_PATH}${publicPath.replace(
/\./g,
SINGLE_DOT_PATH_SEGMENT
)}`;
)}`;
} else {
publicPathForExtract = publicPath;
}
Expand Down Expand Up @@ -200,7 +200,7 @@ export const pitch: LoaderDefinition["pitch"] = function (request, _, data) {
sourceMap: sourceMap
? JSON.stringify(sourceMap)
: // eslint-disable-next-line no-undefined
undefined,
undefined,
filepath
};
})
Expand All @@ -224,10 +224,10 @@ export const pitch: LoaderDefinition["pitch"] = function (request, _, data) {
.join("")
: `\n${
esModule ? "export default" : "module.exports ="
} ${JSON.stringify(locals)};`
} ${JSON.stringify(locals)};`
: esModule
? `\nexport {};`
: "";
? `\nexport {};`
: "";

let resultSource = `// extracted by ${CssExtractRspackPlugin.pluginName}`;

Expand Down
4 changes: 2 additions & 2 deletions packages/rspack/src/builtin-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ function resolveTreeShaking(
return treeShaking !== undefined
? treeShaking.toString()
: production
? "true"
: "false";
? "true"
: "false";
}

export interface Builtins {
Expand Down
53 changes: 28 additions & 25 deletions packages/rspack/src/config/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function getRawResolve(resolve: Resolve): RawOptions["resolve"] {
referencesType:
references == "auto" ? "auto" : references ? "manual" : "disabled",
references: references == "auto" ? undefined : references
}
}
: undefined,
byDependency: getRawResolveByDependency(resolve.byDependency)
};
Expand Down Expand Up @@ -267,7 +267,7 @@ export function getRawLibrary(library: LibraryOptions): RawLibraryOptions {
commonjs2: auxiliaryComment,
amd: auxiliaryComment,
root: auxiliaryComment
}
}
: auxiliaryComment,
libraryType: type,
name: isNil(name) ? name : getRawLibraryName(name),
Expand Down Expand Up @@ -410,7 +410,7 @@ const getRawModuleRule = (
k,
getRawRuleSetCondition(v)
])
)
)
: undefined,
resource: rule.resource ? getRawRuleSetCondition(rule.resource) : undefined,
resourceQuery: rule.resourceQuery
Expand All @@ -432,7 +432,7 @@ const getRawModuleRule = (
`${path}.use`,
options
)
},
},
type: rule.type,
parser: rule.parser
? getRawParserOptions(rule.parser, rule.type ?? "javascript/auto")
Expand All @@ -444,12 +444,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
};
Expand All @@ -468,27 +468,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;
};
Expand Down Expand Up @@ -605,8 +608,8 @@ function getRawJavascriptParserOptions(parser: JavascriptParserOptions) {
parser.url === false
? "false"
: parser.url === "relative"
? parser.url
: "true"
? parser.url
: "true"
};
}

Expand Down
10 changes: 5 additions & 5 deletions packages/rspack/src/config/browserslistTargetHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ const load = (input, context) => {
const config = query
? query
: configPath
? browserslist.loadConfig({
config: configPath,
env
})
: browserslist.loadConfig({ path: context, env });
? browserslist.loadConfig({
config: configPath,
env
})
: browserslist.loadConfig({ path: context, env });

if (!config) return null;
return browserslist(config);
Expand Down
Loading

2 comments on commit 958b557

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ“ Benchmark detail: Open

task failure

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ“ Ran ecosystem CI: Open

suite result
modernjs, self-hosted, Linux, ci ❌ failure
_selftest, ubuntu-latest βœ… success
nx, ubuntu-latest βœ… success
rspress, ubuntu-latest βœ… success
rsbuild, ubuntu-latest βœ… success
compat, ubuntu-latest βœ… success
examples, ubuntu-latest βœ… success

Please sign in to comment.