Skip to content

Commit

Permalink
Merge branch 'main' into use-environment-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
9aoy authored Aug 6, 2024
2 parents f34a8f6 + cba4e93 commit f9df472
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 15 deletions.
6 changes: 5 additions & 1 deletion packages/core/src/build.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import type { RsbuildInstance } from '@rsbuild/core';
import type { BuildOptions } from './cli/commands';
import { initRsbuild } from './config';
import type { RslibConfig } from './types/config';

export async function build(config: RslibConfig, options?: BuildOptions) {
export async function build(
config: RslibConfig,
options?: BuildOptions,
): Promise<RsbuildInstance> {
const rsbuildInstance = await initRsbuild(config);

await rsbuildInstance.build({
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const applyCommonOptions = (command: Command) => {
);
};

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

const buildCommand = program.command('build');
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 @@ -9,7 +9,7 @@ function initNodeEnv() {
}
}

export function prepareCli() {
export function prepareCli(): void {
initNodeEnv();

// Print a blank line to keep the greet log nice.
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'node:fs';
import path, { dirname, isAbsolute, join } from 'node:path';
import {
type RsbuildConfig,
type RsbuildInstance,
createRsbuild,
defineConfig as defineRsbuildConfig,
loadConfig as loadRsbuildConfig,
Expand Down Expand Up @@ -473,7 +474,9 @@ export async function composeCreateRsbuildConfig(
return composedRsbuildConfig;
}

export async function initRsbuild(rslibConfig: RslibConfig) {
export async function initRsbuild(
rslibConfig: RslibConfig,
): Promise<RsbuildInstance> {
const rsbuildConfigObject = await composeCreateRsbuildConfig(rslibConfig);
const environments: RsbuildConfig['environments'] = {};
const formatCount: Record<Format, number> = rsbuildConfigObject.reduce(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export * from './utils/helper';

export * from './types/config';

export const version = RSLIB_VERSION;
export const version: string = RSLIB_VERSION;
6 changes: 5 additions & 1 deletion packages/core/src/utils/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export const getDefaultExtension = (options: {
format: Format;
root: string;
autoExtension: boolean;
}) => {
}): {
jsExtension: string;
dtsExtension: string;
isModule?: boolean;
} => {
const { format, root, autoExtension } = options;

let jsExtension = '.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import color from 'picocolors';
* Node.js built-in modules.
* Copied from https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L12-L72
*/
export const nodeBuiltInModules = [
export const nodeBuiltInModules: Array<string | RegExp> = [
'assert',
'assert/strict',
'async_hooks',
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (process.env.DEBUG) {
logger.level = 'verbose';
}

export const isDebug = () => {
export const isDebug = (): boolean => {
if (!process.env.DEBUG) {
return false;
}
Expand All @@ -27,7 +27,7 @@ function getTime() {
return `${hours}:${minutes}:${seconds}`;
}

export const debug = (message: string | (() => string)) => {
export const debug = (message: string | (() => string)): void => {
if (isDebug()) {
const result = typeof message === 'string' ? message : message();
const time = color.gray(`${getTime()}`);
Expand Down
1 change: 1 addition & 0 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"rootDir": "src",
"declaration": true,
"declarationDir": "./dist-types",
"isolatedDeclarations": true,
"composite": true,
"module": "ESNext",
"moduleResolution": "Bundler",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-dts/src/apiExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type BundleOptions = {
tsconfigPath?: string;
};

export function bundleDts(options: BundleOptions) {
export function bundleDts(options: BundleOptions): void {
const {
cwd,
outDir,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-dts/src/dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as ts from 'typescript';
import { emitDts } from './tsc';
import { ensureTempDeclarationDir, loadTsconfig } from './utils';

export async function generateDts(data: DtsGenOptions) {
export async function generateDts(data: DtsGenOptions): Promise<void> {
const { options: pluginOptions, cwd, isWatch, name } = data;
logger.start(`Generating DTS... ${color.gray(`(${name})`)}`);
const { tsconfigPath, distPath, bundle, entryPath } = pluginOptions;
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 @@ -15,7 +15,7 @@ export function emitDts(
options: emitDtsOptions,
onComplete: (isSuccess: boolean) => void,
isWatch = false,
) {
): void {
const start = Date.now();
const getTimeCost = () => {
return `${Math.floor(Date.now() - start)}ms`;
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-dts/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function loadTsconfig(tsconfigPath: string): ts.ParsedCommandLine {
}

export const TEMP_FOLDER = '.rslib';
export const TEMP_DTS_DIR = `${TEMP_FOLDER}/declarations`;
export const TEMP_DTS_DIR: string = `${TEMP_FOLDER}/declarations`;

export function ensureTempDeclarationDir(cwd: string): string {
const dirPath = path.join(cwd, TEMP_DTS_DIR);
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-dts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"baseUrl": "./",
"rootDir": "src",
"declaration": true,
"isolatedDeclarations": true,
"composite": true,
"module": "ESNext",
"moduleResolution": "Bundler"
Expand Down
5 changes: 3 additions & 2 deletions scripts/tsconfig/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
"extends": "@tsconfig/strictest/tsconfig",
"compilerOptions": {
"exactOptionalPropertyTypes": false,
"target": "ES2019",
"target": "ES2021",
"lib": ["DOM", "ESNext"],
"allowJs": true,
"allowJs": false,
"checkJs": false,
"module": "ES2020",
"strict": true,
"isolatedModules": true,
Expand Down

0 comments on commit f9df472

Please sign in to comment.