diff --git a/.changeset/quick-avocados-fetch.md b/.changeset/quick-avocados-fetch.md new file mode 100644 index 00000000000..f01f2b8f0c8 --- /dev/null +++ b/.changeset/quick-avocados-fetch.md @@ -0,0 +1,5 @@ +--- +"create-fuels": patch +--- + +fix: passing arguments with NPM diff --git a/apps/docs/src/guide/creating-a-fuel-dapp/options.md b/apps/docs/src/guide/creating-a-fuel-dapp/options.md index e4deea28b5e..9d2f7932250 100644 --- a/apps/docs/src/guide/creating-a-fuel-dapp/options.md +++ b/apps/docs/src/guide/creating-a-fuel-dapp/options.md @@ -14,7 +14,7 @@ pnpm create fuels@{{fuels}} [project-name] [options] ``` ```sh-vue [npm] -npm create fuels@{{fuels}} [project-name] [options] +npm create fuels@{{fuels}} -- [project-name] [options] ``` ```sh-vue [bun] diff --git a/packages/create-fuels/src/bin.ts b/packages/create-fuels/src/bin.ts index 89ef73cf72b..495ef63f4a8 100644 --- a/packages/create-fuels/src/bin.ts +++ b/packages/create-fuels/src/bin.ts @@ -6,7 +6,6 @@ import { runScaffoldCli, setupProgram } from './cli'; runScaffoldCli({ program: setupProgram(), args: process.argv, - shouldInstallDeps: true, }) .then(() => process.exit(0)) .catch((e) => { diff --git a/packages/create-fuels/src/cli.ts b/packages/create-fuels/src/cli.ts index 4d05f54c286..ca3b524b10c 100644 --- a/packages/create-fuels/src/cli.ts +++ b/packages/create-fuels/src/cli.ts @@ -39,11 +39,9 @@ function writeEnvFile(envFilePath: string) { export const runScaffoldCli = async ({ program, args = process.argv, - shouldInstallDeps = false, }: { program: Command; args: string[]; - shouldInstallDeps?: boolean; }) => { program.parse(args); @@ -120,18 +118,17 @@ export const runScaffoldCli = async ({ fileCopySpinner.succeed('Copied template files!'); - const installDepsSpinner = ora({ - text: 'Installing dependencies..', - color: 'green', - }).start(); + if (opts['no-install'] === false) { + const installDepsSpinner = ora({ + text: 'Installing dependencies..', + color: 'green', + }).start(); - if (shouldInstallDeps) { process.chdir(projectPath); execSync(packageManager.install, { stdio: verboseEnabled ? 'inherit' : 'pipe' }); + installDepsSpinner.succeed('Installed dependencies!'); } - installDepsSpinner.succeed('Installed dependencies!'); - log(); log(); log(chalk.green(`⚡️ Success! Created a fullstack Fuel dapp at ${projectPath}`)); diff --git a/packages/create-fuels/src/lib/setupProgram.ts b/packages/create-fuels/src/lib/setupProgram.ts index c47e64cb63d..b244b7d1b6a 100644 --- a/packages/create-fuels/src/lib/setupProgram.ts +++ b/packages/create-fuels/src/lib/setupProgram.ts @@ -10,6 +10,7 @@ export interface ProgramOptions { npm?: boolean; bun?: boolean; verbose?: boolean; + 'no-install'?: boolean; } export const setupProgram = () => { @@ -20,6 +21,7 @@ export const setupProgram = () => { .option('--npm', 'Use npm to install dependencies') .option('--bun', 'Use bun to install dependencies') .option('--verbose', 'Enable verbose logging') + .option('--no-install', `Do not install dependencies after scaffolding`, false) .addHelpCommand() .showHelpAfterError(true); return program; diff --git a/packages/create-fuels/test/cli.test.ts b/packages/create-fuels/test/cli.test.ts index 88775a972dc..ae358f8817c 100644 --- a/packages/create-fuels/test/cli.test.ts +++ b/packages/create-fuels/test/cli.test.ts @@ -42,7 +42,6 @@ describe('CLI', () => { await runScaffoldCli({ program: setupProgram(), args, - shouldInstallDeps: false, }); let originalTemplateFiles = await getAllFiles(paths.template); @@ -59,7 +58,6 @@ describe('CLI', () => { await runScaffoldCli({ program: setupProgram(), args, - shouldInstallDeps: false, }); const packageJsonPath = join(paths.root, 'package.json'); @@ -82,7 +80,6 @@ describe('CLI', () => { await runScaffoldCli({ program: setupProgram(), args, - shouldInstallDeps: false, }).catch((e) => { expect(e).toBeInstanceOf(Error); }); diff --git a/packages/create-fuels/test/e2e.test.ts b/packages/create-fuels/test/e2e.test.ts index 9c66b0479e6..a2350ac7dfa 100644 --- a/packages/create-fuels/test/e2e.test.ts +++ b/packages/create-fuels/test/e2e.test.ts @@ -15,10 +15,11 @@ import { const { log } = console; -const PUBLISHED_NPM_VERSION = process.env.PUBLISHED_NPM_VERSION; -const packageManagerCreateCommands: [PackageManager, string, string[]][] = [ - ['pnpm', 'pnpm --ignore-workspace create fuels', []], - ['bun', 'bunx --bun create-fuels', ['/bun.lockb']], +const PUBLISHED_NPM_VERSION = process.env.PUBLISHED_NPM_VERSION ?? 'next'; +const packageManagerCreateCommands: [PackageManager, string][] = [ + ['pnpm', 'pnpm --ignore-workspace create fuels'], + ['bun', 'bunx --bun create-fuels'], + ['npm', 'npm create fuels'], ]; /** @@ -45,14 +46,14 @@ describe('`create fuels` package integrity', () => { it.each(packageManagerCreateCommands)( `should perform 'create fuels' using '%s'`, - async (packageManager, createCommand, additionalFiles) => { + async (packageManager, createCommand) => { if (shouldSkip) { return; } const args = generateArgs(paths.root, packageManager).join(' '); const expectedTemplateFiles = await getAllFiles(paths.sourceTemplate).then((files) => - filterOriginalTemplateFiles(files).filter(filterForcBuildFiles).concat(additionalFiles) + filterOriginalTemplateFiles(files).filter(filterForcBuildFiles) ); const { error: createFuelsError } = await safeExec(() => diff --git a/packages/create-fuels/test/utils/generateArgs.ts b/packages/create-fuels/test/utils/generateArgs.ts index f6ac54cf344..614e2068c8a 100644 --- a/packages/create-fuels/test/utils/generateArgs.ts +++ b/packages/create-fuels/test/utils/generateArgs.ts @@ -1,9 +1,13 @@ export const generateArgs = (projectName?: string, packageManager: string = 'pnpm'): string[] => { const args = []; + if (packageManager === 'npm') { + args.push('--'); + } if (projectName) { args.push(projectName); } args.push(`--${packageManager}`); + args.push(`--no-install`); return args; };