Skip to content

Commit

Permalink
chore: move runCLI from internal helpers to index export
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Nov 15, 2024
1 parent cbd597b commit b859ef2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
12 changes: 2 additions & 10 deletions packages/core/bin/rsbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,8 @@ if (enableCompileCache) {
}

async function main() {
const { __internalHelper, logger } = await import('../dist/index.js');
const { runCli, prepareCli } = __internalHelper;

prepareCli();

try {
runCli();
} catch (err) {
logger.error(err);
}
const { runCLI } = await import('../dist/index.js');
runCLI();
}

main();
2 changes: 1 addition & 1 deletion packages/core/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default defineConfig({
externals,
},
lib: [
// Node / ESM
// Node / ESM / index
{
format: 'esm',
syntax: 'es2021',
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 @@ -63,7 +63,7 @@ const applyServerOptions = (command: Command) => {
.option('--host <host>', 'specify the host that the server listens to');
};

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

const devCommand = program.command('dev');
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { logger } from '../logger';
import { setupCommands } from './commands';
import { prepareCli } from './prepare';

export async function runCLI(): Promise<void> {
prepareCli();

try {
setupCommands();
} catch (err) {
logger.error('Failed to start Rsbuild CLI.');
logger.error(err);
}
}
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as __internalHelper from './internal';
export { loadEnv } from './loadEnv';
export { createRsbuild } from './createRsbuild';
export { loadConfig, defineConfig } from './config';
export { runCLI } from './cli';

// Rsbuild version
export const version: string = RSBUILD_VERSION;
Expand Down
3 changes: 0 additions & 3 deletions packages/core/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
* Some internal methods of Rsbuild.
* Please do not use them in your Rsbuild project or plugins.
*/

export { runCli } from './cli/commands';
export { prepareCli } from './cli/prepare';
export { setHTMLPlugin } from './pluginHelper';

0 comments on commit b859ef2

Please sign in to comment.