Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Rstack is a unified JavaScript toolchain built around Rspack, with high performa
| [Rspress](https://github.com/web-infra-dev/rspress) | Static site generator |
| [Rsdoctor](https://github.com/web-infra-dev/rsdoctor) | Build analyzer |
| [Rstest](https://github.com/web-infra-dev/rstest) | Testing framework |
| [Rslint](https://github.com/web-infra-dev/rslint) | Linter |

## 🔗 Links

Expand Down
1 change: 1 addition & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Rstack 是一个围绕 Rspack 打造的 JavaScript 统一工具链,具有优
| [Rspress](https://github.com/web-infra-dev/rspress) | 静态站点生成器 |
| [Rsdoctor](https://github.com/web-infra-dev/rsdoctor) | 构建分析工具 |
| [Rstest](https://github.com/web-infra-dev/rstest) | 测试框架 |
| [Rslint](https://github.com/web-infra-dev/rslint) | 代码检查工具 |

## 🔗 链接

Expand Down
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.1.2/schema.json",
"$schema": "https://biomejs.dev/schemas/2.1.3/schema.json",
"assist": {
"actions": {
"source": {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"check-spell": "pnpx cspell && heading-case",
"format": "prettier . --write && biome check --write && heading-case --write",
"generate-release-pr": "zx scripts/generateReleasePr.mjs",
"lint": "biome check . --diagnostic-level=warn && prettier . --check && pnpm run check-spell",
"lint": "biome check . --diagnostic-level=warn && prettier . --check && pnpm run check-spell && pnpm lint:type",
"lint:type": "rslint",
"prebundle": "nx run-many -t prebundle",
"prepare": "pnpm run build && simple-git-hooks",
"sort-package-json": "npx sort-package-json \"packages/*/package.json\"",
Expand Down Expand Up @@ -42,6 +43,7 @@
"devDependencies": {
"@biomejs/biome": "^2.1.3",
"@changesets/cli": "^2.29.5",
"@rslint/core": "^0.1.5",
"@rstest/core": "0.1.1",
"@types/fs-extra": "^11.0.4",
"@types/node": "^22.17.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/cli/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ export function prepareCli(): void {
console.log();
}

logger.greet(` ${`Rslib v${RSLIB_VERSION}`}\n`);
logger.greet(` Rslib v${RSLIB_VERSION}\n`);
}
31 changes: 18 additions & 13 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ const composeExternalsWarnConfig = (
asyncFlag = false;
return;
}
return next();
next();
return;
}

callback(matched, shouldWarn);
Expand All @@ -227,7 +228,8 @@ const composeExternalsWarnConfig = (
do {
asyncFlag = true;
if (i >= externals.length) {
return callback(false);
callback(false);
return;
}
matchUserExternals(
externals[i++],
Expand Down Expand Up @@ -308,7 +310,7 @@ export const composeAutoExternalConfig = (options: {
const { bundle, format, pkgJson, userExternals } = options;

// If bundle is false, autoExternal will be disabled
if (bundle === false) {
if (!bundle) {
return {};
}

Expand Down Expand Up @@ -352,7 +354,7 @@ export const composeAutoExternalConfig = (options: {
)
.reduce<string[]>((prev, type) => {
if (externalOptions[type]) {
return pkgJson[type] ? prev.concat(Object.keys(pkgJson[type]!)) : prev;
return pkgJson[type] ? prev.concat(Object.keys(pkgJson[type])) : prev;
}
return prev;
}, [])
Expand Down Expand Up @@ -648,7 +650,7 @@ const composeFormatConfig = ({
},
};
case 'umd': {
if (bundle === false) {
if (!bundle) {
throw new Error(
'When using "umd" format, "bundle" must be set to "true". Since the default value for "bundle" is "true", so you can either explicitly set it to "true" or remove the field entirely.',
);
Expand Down Expand Up @@ -686,7 +688,7 @@ const composeFormatConfig = ({
return config;
}
case 'iife': {
if (bundle === false) {
if (!bundle) {
throw new Error(
'When using "iife" format, "bundle" must be set to "true". Since the default value for "bundle" is "true", so you can either explicitly set it to "true" or remove the field entirely.',
);
Expand Down Expand Up @@ -729,7 +731,7 @@ const composeFormatConfig = ({
return config;
}
case 'mf':
if (bundle === false) {
if (!bundle) {
throw new Error(
'When using "mf" format, "bundle" must be set to "true". Since the default value for "bundle" is "true", so you can either explicitly set it to "true" or remove the field entirely.',
);
Expand All @@ -743,7 +745,7 @@ const composeFormatConfig = ({
rspack: (config, { env }) => {
config.output = {
...config.output,
uniqueName: pkgJson.name as string,
uniqueName: pkgJson.name,
};

config.optimization = {
Expand Down Expand Up @@ -1086,7 +1088,7 @@ const composeEntryConfig = async (
} else {
// Non-existed file.
entryErrorReasons.push(
`Can't resolve the entry ${color.cyan(`"${entry}"`)} at the location ${color.cyan(`${entryAbsPath}`)}. Please ensure that the file exists.`,
`Can't resolve the entry ${color.cyan(`"${entry}"`)} at the location ${color.cyan(entryAbsPath)}. Please ensure that the file exists.`,
);
}
}
Expand Down Expand Up @@ -1253,12 +1255,13 @@ const composeBundlelessExternalConfig = (
async (data, callback) => {
const { request, getResolve, context, contextInfo } = data;
if (!request || !getResolve || !context || !contextInfo) {
return callback();
callback();
return;
}
const { issuer } = contextInfo;

if (!resolver) {
resolver = (await getResolve()) as RspackResolver;
resolver = getResolve() as RspackResolver;
}

async function redirectPath(
Expand Down Expand Up @@ -1327,7 +1330,8 @@ const composeBundlelessExternalConfig = (
}

if (redirectedPath === undefined) {
return callback(undefined, request);
callback(undefined, request);
return;
}

if (jsRedirectPath) {
Expand Down Expand Up @@ -1374,7 +1378,8 @@ const composeBundlelessExternalConfig = (
}
}

return callback(undefined, resolvedRequest);
callback(undefined, resolvedRequest);
return;
}

callback();
Expand Down
17 changes: 9 additions & 8 deletions packages/core/src/css/cssConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export async function cssExternalHandler(
// cssExtract: do not external @rsbuild/core/compiled/css-loader/noSourceMaps.js, sourceMaps.js, api.mjs etc.
// cssExtract would execute the result handled by css-loader with importModule, so we cannot external the "helper import" from css-loader
if (/compiled\/css-loader\//.test(request)) {
return callback();
callback();
return;
}

let resolvedRequest = request;
Expand All @@ -41,7 +42,8 @@ export async function cssExternalHandler(
if (!isCssFile(resolvedRequest)) {
// cssExtract: do not external assets module import
if (isCssFile(issuer)) {
return callback();
callback();
return;
}
return false;
}
Expand All @@ -51,15 +53,14 @@ export async function cssExternalHandler(
if (styleRedirectExtension) {
const isCssModulesRequest = isCssModulesFile(resolvedRequest, auto);
if (isCssModulesRequest) {
return callback(
undefined,
resolvedRequest.replace(/\.[^.]+$/, jsExtension),
);
callback(undefined, resolvedRequest.replace(/\.[^.]+$/, jsExtension));
return;
}
return callback(undefined, resolvedRequest.replace(/\.[^.]+$/, '.css'));
callback(undefined, resolvedRequest.replace(/\.[^.]+$/, '.css'));
return;
}

return callback(undefined, resolvedRequest);
callback(undefined, resolvedRequest);
}

const PLUGIN_NAME = 'rsbuild:lib-css';
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/css/libCssExtractLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const pitch: Rspack.LoaderDefinition['pitch'] = function (
const banner = options.banner;
const footer = options.footer;

let { publicPath } = this._compilation!.outputOptions;
let { publicPath } = this._compilation.outputOptions;

if (typeof options.publicPath === 'string') {
// eslint-disable-next-line prefer-destructuring
Expand Down Expand Up @@ -212,8 +212,7 @@ export const pitch: Rspack.LoaderDefinition['pitch'] = function (

const localsString = identifiers
.map(
([id, key]) =>
`\nvar ${id} = ${stringifyLocal(locals![key as string])};`,
([id, key]) => `\nvar ${id} = ${stringifyLocal(locals[key!])};`,
)
.join('');
const exportsString = `export { ${identifiers
Expand Down Expand Up @@ -282,7 +281,7 @@ export const pitch: Rspack.LoaderDefinition['pitch'] = function (
}
if (sourceMap) {
const sourceMapPath = `${distFilepath}.map`;
m.set(sourceMapPath, `${sourceMap}`);
m.set(sourceMapPath, sourceMap);
// Associate the source map with the CSS file
const sourceMappingURL = `/*# sourceMappingURL=${cssFilename}.map */`;
m.set(distFilepath, `${m.get(distFilepath)}\n${sourceMappingURL}`);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { logger } from './logger';
* Node.js built-in modules.
* Copied from https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L12-L72
*/
export const nodeBuiltInModules: Array<string | RegExp> = [
export const nodeBuiltInModules: (string | RegExp)[] = [
'assert',
'assert/strict',
'async_hooks',
Expand Down Expand Up @@ -140,7 +140,7 @@ export const isEmptyObject = (obj: object): boolean => {

export function pick<T, U extends keyof T>(
obj: T,
keys: ReadonlyArray<U>,
keys: readonly U[],
): Pick<T, U> {
return keys.reduce(
(ret, key) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ logger.override({
if (logger.level !== 'verbose') {
return;
}
const time = color.gray(`${getTime()}`);
const time = color.gray(getTime());
console.log(` ${color.green('rslib')} ${time} ${message}`, ...args);
},
});
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-dts/src/apiExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function bundleDts(options: BundleOptions): Promise<void> {
throw error;
}

const { Extractor, ExtractorConfig, ExtractorLogLevel } = apiExtractor!;
const { Extractor, ExtractorConfig, ExtractorLogLevel } = apiExtractor;
const {
name,
cwd,
Expand All @@ -53,7 +53,7 @@ export async function bundleDts(options: BundleOptions): Promise<void> {
relative(cwd, distPath),
`${entry.name}${dtsExtension}`,
);
const mainEntryPointFilePath = entry.path!.replace(/\?.*$/, '')!;
const mainEntryPointFilePath = entry.path!.replace(/\?.*$/, '');
const internalConfig = {
mainEntryPointFilePath,
bundledPackages,
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-dts/src/dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export async function generateDts(data: DtsGenOptions): Promise<void> {
: dtsEmitPath;

let dtsEntries: Required<DtsEntry>[] = [];
if (bundle === true) {
if (bundle) {
dtsEntries = dtsEntry
.map((entryObj) => {
const { name: entryName, path: entryPath } = entryObj;
Expand All @@ -204,7 +204,7 @@ export async function generateDts(data: DtsGenOptions): Promise<void> {
: join(cwd, entryPath);
const relativePath = relative(rootDir, dirname(entrySourcePath));
const newPath = join(
declarationDir!,
declarationDir,
relativePath,
basename(entrySourcePath),
).replace(
Expand All @@ -217,7 +217,7 @@ export async function generateDts(data: DtsGenOptions): Promise<void> {
}

const bundleDtsIfNeeded = async () => {
if (bundle === true) {
if (bundle) {
const { bundleDts } = await import('./apiExtractor');
await bundleDts({
name,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-dts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const pluginDts = (options: PluginDtsOptions = {}): RsbuildPlugin => ({
const cwd = api.context.rootPath;
const tsconfigPath = ts.findConfigFile(
cwd,
ts.sys.fileExists,
ts.sys.fileExists.bind(ts.sys),
config.source.tsconfigPath,
);

Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-dts/src/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const logPrefixTsc = color.dim('[tsc]');

const formatHost: ts.FormatDiagnosticsHost = {
getCanonicalFileName: (path) => path,
getCurrentDirectory: ts.sys.getCurrentDirectory,
getCurrentDirectory: ts.sys.getCurrentDirectory.bind(ts.sys),
getNewLine: () => ts.sys.newLine,
};

Expand Down
13 changes: 9 additions & 4 deletions packages/plugin-dts/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export const JS_EXTENSIONS_PATTERN: RegExp = new RegExp(
);

export function loadTsconfig(tsconfigPath: string): ts.ParsedCommandLine {
const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
const configFile = ts.readConfigFile(
tsconfigPath,
ts.sys.readFile.bind(ts.sys),
);
const configFileContent = ts.parseJsonConfigFileContent(
configFile.config,
ts.sys,
Expand Down Expand Up @@ -148,7 +151,7 @@ export function getFileLoc(
return `${color.cyan(diagnostic.file.fileName)}:${color.yellow(line + 1)}:${color.yellow(character + 1)}`;
}

return `${color.cyan(configPath)}`;
return color.cyan(configPath);
}

export const prettyTime = (seconds: number): string => {
Expand Down Expand Up @@ -561,7 +564,7 @@ export const globDtsFiles = async (
patterns: string[],
): Promise<string[]> => {
const dtsFiles = await Promise.all(
patterns.map((pattern) =>
patterns.map(async (pattern) =>
glob(convertPath(join(dir, pattern)), { absolute: true }),
),
);
Expand All @@ -573,7 +576,9 @@ export async function cleanDtsFiles(dir: string): Promise<void> {
const patterns = ['/**/*.d.ts', '/**/*.d.cts', '/**/*.d.mts'];
const allFiles = await globDtsFiles(dir, patterns);

await Promise.all(allFiles.map((file) => fsP.rm(file, { force: true })));
await Promise.all(
allFiles.map(async (file) => fsP.rm(file, { force: true })),
);
}

export async function cleanTsBuildInfoFile(
Expand Down
Loading
Loading