Skip to content

Commit

Permalink
feat(init): add choose bundler prompt (#877)
Browse files Browse the repository at this point in the history
* feat(init): add choose bundler prompt

* chore: improve log

* chore: improve log

* chore: code review improvements

* fix: linter

* chore: changeset

* chore: update changeset

---------

Co-authored-by: Jakub Romańczyk <[email protected]>
  • Loading branch information
szymonrybczak and jbroma authored Jan 20, 2025
1 parent 2390ead commit 919ffb8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/real-ways-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack": minor
---

Add prompt for choosing the bundler in `repack-init`
1 change: 0 additions & 1 deletion packages/init/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const argv = yargs(hideBin(process.argv))
type: 'string',
choices: ['rspack', 'webpack'],
description: 'Specify the bundler to use',
default: 'rspack',
})
.option('custom-version', {
alias: 'c',
Expand Down
5 changes: 5 additions & 0 deletions packages/init/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import createBundlerConfig from './tasks/createBundlerConfig.js';
import ensureProjectExists from './tasks/ensureProjectExists.js';
import handleReactNativeConfig from './tasks/handleReactNativeConfig.js';
import modifyIOS from './tasks/modifyIOS.js';
import selectBundler from './tasks/selectBundler.js';

import logger, { enableVerboseLogging } from './utils/logger.js';

Expand Down Expand Up @@ -33,6 +34,10 @@ export default async function run({

checkReactNative(cwd);

if (!bundler) {
bundler = await selectBundler();
}

await addDependencies(bundler, cwd, packageManager, repackVersion);

await createBundlerConfig(bundler, cwd, templateType, entry);
Expand Down
25 changes: 25 additions & 0 deletions packages/init/src/tasks/selectBundler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { select } from '@inquirer/prompts';
import { isTruthyEnv } from '../utils/isTruthyEnv.js';
import logger from '../utils/logger.js';

export default async function selectBundler(): Promise<'rspack' | 'webpack'> {
if (isTruthyEnv(process.env.CI)) {
logger.info('Running in CI, using rspack. Use --bundler flag to override.');
return 'rspack';
}

return select({
message: 'Which bundler would you like to use?',
choices: [
{
name: 'Rspack (recommended)',
value: 'rspack',
},
{
name: 'Webpack',
value: 'webpack',
},
],
default: 'rspack',
});
}
3 changes: 3 additions & 0 deletions packages/init/src/utils/isTruthyEnv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const isTruthyEnv = (env: string | undefined) => {
return !!env && env !== 'false' && env !== '0';
};

0 comments on commit 919ffb8

Please sign in to comment.