Skip to content

Commit cba4e93

Browse files
authored
perf: enable TypeScript isolatedDeclarations (#64)
1 parent 9ccc01d commit cba4e93

File tree

15 files changed

+29
-15
lines changed

15 files changed

+29
-15
lines changed

packages/core/src/build.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import type { RsbuildInstance } from '@rsbuild/core';
12
import type { BuildOptions } from './cli/commands';
23
import { initRsbuild } from './config';
34
import type { RslibConfig } from './types/config';
45

5-
export async function build(config: RslibConfig, options?: BuildOptions) {
6+
export async function build(
7+
config: RslibConfig,
8+
options?: BuildOptions,
9+
): Promise<RsbuildInstance> {
610
const rsbuildInstance = await initRsbuild(config);
711

812
await rsbuildInstance.build({

packages/core/src/cli/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const applyCommonOptions = (command: Command) => {
3131
);
3232
};
3333

34-
export function runCli() {
34+
export function runCli(): void {
3535
program.name('rslib').usage('<command> [options]').version(RSLIB_VERSION);
3636

3737
const buildCommand = program.command('build');

packages/core/src/cli/prepare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function initNodeEnv() {
99
}
1010
}
1111

12-
export function prepareCli() {
12+
export function prepareCli(): void {
1313
initNodeEnv();
1414

1515
// Print a blank line to keep the greet log nice.

packages/core/src/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from 'node:fs';
22
import path, { dirname, isAbsolute, join } from 'node:path';
33
import {
44
type RsbuildConfig,
5+
type RsbuildInstance,
56
createRsbuild,
67
defineConfig as defineRsbuildConfig,
78
loadConfig as loadRsbuildConfig,
@@ -473,7 +474,9 @@ export async function composeCreateRsbuildConfig(
473474
return composedRsbuildConfig;
474475
}
475476

476-
export async function initRsbuild(rslibConfig: RslibConfig) {
477+
export async function initRsbuild(
478+
rslibConfig: RslibConfig,
479+
): Promise<RsbuildInstance> {
477480
const rsbuildConfigObject = await composeCreateRsbuildConfig(rslibConfig);
478481
const environments: RsbuildConfig['environments'] = {};
479482
const formatCount: Record<Format, number> = rsbuildConfigObject.reduce(

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export * from './utils/helper';
88

99
export * from './types/config';
1010

11-
export const version = RSLIB_VERSION;
11+
export const version: string = RSLIB_VERSION;

packages/core/src/utils/extension.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ export const getDefaultExtension = (options: {
77
format: Format;
88
root: string;
99
autoExtension: boolean;
10-
}) => {
10+
}): {
11+
jsExtension: string;
12+
dtsExtension: string;
13+
isModule?: boolean;
14+
} => {
1115
const { format, root, autoExtension } = options;
1216

1317
let jsExtension = '.js';

packages/core/src/utils/helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import color from 'picocolors';
55
* Node.js built-in modules.
66
* Copied from https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L12-L72
77
*/
8-
export const nodeBuiltInModules = [
8+
export const nodeBuiltInModules: Array<string | RegExp> = [
99
'assert',
1010
'assert/strict',
1111
'async_hooks',

packages/core/src/utils/logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if (process.env.DEBUG) {
66
logger.level = 'verbose';
77
}
88

9-
export const isDebug = () => {
9+
export const isDebug = (): boolean => {
1010
if (!process.env.DEBUG) {
1111
return false;
1212
}
@@ -27,7 +27,7 @@ function getTime() {
2727
return `${hours}:${minutes}:${seconds}`;
2828
}
2929

30-
export const debug = (message: string | (() => string)) => {
30+
export const debug = (message: string | (() => string)): void => {
3131
if (isDebug()) {
3232
const result = typeof message === 'string' ? message : message();
3333
const time = color.gray(`${getTime()}`);

packages/core/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"rootDir": "src",
77
"declaration": true,
88
"declarationDir": "./dist-types",
9+
"isolatedDeclarations": true,
910
"composite": true,
1011
"module": "ESNext",
1112
"moduleResolution": "Bundler",

packages/plugin-dts/src/apiExtractor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type BundleOptions = {
1313
tsconfigPath?: string;
1414
};
1515

16-
export function bundleDts(options: BundleOptions) {
16+
export function bundleDts(options: BundleOptions): void {
1717
const {
1818
cwd,
1919
outDir,

0 commit comments

Comments
 (0)