@cloudflare/autoconfig 0.2.9 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ import { fileURLToPath } from 'node:url';
17
17
  import os from 'node:os';
18
18
  import tty from 'node:tty';
19
19
  import { maybeAppendWranglerToGitIgnore, maybeAppendWranglerToGitIgnoreLikeFile } from '@cloudflare/cli-shared-helpers/gitignore';
20
+ import { InputWorkerSchema, convertToWranglerConfig } from '@cloudflare/config';
20
21
 
21
22
  // ../../node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.mjs
22
23
  var tslib_es6_exports = {};
@@ -43684,7 +43685,9 @@ var Framework = class {
43684
43685
  this.id = frameworkInfo.id;
43685
43686
  this.name = frameworkInfo.name;
43686
43687
  }
43687
- isConfigured(_projectPath) {
43688
+ isConfigured(_projectPath, {
43689
+ target: _target = "cf"
43690
+ } = {}) {
43688
43691
  return false;
43689
43692
  }
43690
43693
  configurationDescription;
@@ -43742,13 +43745,14 @@ var Analog = class extends Framework {
43742
43745
  await updateViteConfig(projectPath);
43743
43746
  }
43744
43747
  return {
43745
- wranglerConfig: {
43746
- main: "./dist/analog/server/index.mjs",
43747
- assets: {
43748
- binding: "ASSETS",
43749
- directory: "./dist/analog/public"
43748
+ buildTool: "wrangler",
43749
+ workerConfig: {
43750
+ entrypoint: "./dist/analog/server/index.mjs",
43751
+ env: {
43752
+ ASSETS: { type: "assets" }
43750
43753
  }
43751
- }
43754
+ },
43755
+ buildConfig: { assetsDirectory: "./dist/analog/public" }
43752
43756
  };
43753
43757
  }
43754
43758
  };
@@ -43867,22 +43871,21 @@ var Angular = class extends Framework {
43867
43871
  await installAdditionalDependencies(packageManager, isWorkspaceRoot);
43868
43872
  }
43869
43873
  return {
43870
- wranglerConfig: {
43871
- main: "./dist/server/server.mjs",
43872
- assets: {
43873
- binding: "ASSETS",
43874
- directory: `${outputDir}browser`
43874
+ buildTool: "wrangler",
43875
+ workerConfig: {
43876
+ entrypoint: "./dist/server/server.mjs",
43877
+ env: {
43878
+ ASSETS: { type: "assets" }
43875
43879
  }
43876
- }
43880
+ },
43881
+ buildConfig: { assetsDirectory: `${outputDir}browser` }
43877
43882
  };
43878
43883
  } else {
43879
43884
  this.configurationDescription = "Configuring Angular SPA project (assets only)";
43880
43885
  return {
43881
- wranglerConfig: {
43882
- assets: {
43883
- directory: outputDir
43884
- }
43885
- }
43886
+ buildTool: "wrangler",
43887
+ workerConfig: {},
43888
+ buildConfig: { assetsDirectory: outputDir }
43886
43889
  };
43887
43890
  }
43888
43891
  }
@@ -43984,18 +43987,19 @@ var Astro = class extends Framework {
43984
43987
  }
43985
43988
  if (semiver_default(astroVersion, "6.0.0") < 0) {
43986
43989
  return {
43987
- wranglerConfig: {
43988
- main: `${outputDir}/_worker.js/index.js`,
43989
- compatibility_flags: ["global_fetch_strictly_public"],
43990
- assets: {
43991
- binding: "ASSETS",
43992
- directory: outputDir
43990
+ buildTool: "wrangler",
43991
+ workerConfig: {
43992
+ entrypoint: `${outputDir}/_worker.js/index.js`,
43993
+ compatibilityFlags: ["global_fetch_strictly_public"],
43994
+ env: {
43995
+ ASSETS: { type: "assets" }
43993
43996
  }
43994
- }
43997
+ },
43998
+ buildConfig: { assetsDirectory: outputDir }
43995
43999
  };
43996
44000
  }
43997
44001
  return {
43998
- wranglerConfig: null
44002
+ workerConfig: null
43999
44003
  };
44000
44004
  }
44001
44005
  configurationDescription = 'Configuring project for Astro with "astro add cloudflare"';
@@ -44162,7 +44166,7 @@ var NextJs = class extends Framework {
44162
44166
  }
44163
44167
  return {
44164
44168
  // `@opennextjs/cloudflare migrate` creates the wrangler config file
44165
- wranglerConfig: {},
44169
+ workerConfig: {},
44166
44170
  packageJsonScriptsOverrides: {
44167
44171
  preview: "opennextjs-cloudflare build && opennextjs-cloudflare preview",
44168
44172
  deploy: "opennextjs-cloudflare build && opennextjs-cloudflare deploy"
@@ -44234,16 +44238,17 @@ var Nuxt = class extends Framework {
44234
44238
  updateNuxtConfig(projectPath);
44235
44239
  }
44236
44240
  return {
44237
- wranglerConfig: {
44238
- main: "./.output/server/index.mjs",
44239
- assets: {
44240
- binding: "ASSETS",
44241
- directory: "./.output/public/"
44241
+ buildTool: "wrangler",
44242
+ workerConfig: {
44243
+ entrypoint: "./.output/server/index.mjs",
44244
+ env: {
44245
+ ASSETS: { type: "assets" }
44242
44246
  },
44243
44247
  observability: {
44244
44248
  enabled: true
44245
44249
  }
44246
- }
44250
+ },
44251
+ buildConfig: { assetsDirectory: "./.output/public/" }
44247
44252
  };
44248
44253
  }
44249
44254
  configurationDescription = "Configuring project for Nuxt";
@@ -44279,14 +44284,15 @@ var Qwik = class extends Framework {
44279
44284
  addBindingsProxy(projectPath);
44280
44285
  }
44281
44286
  return {
44282
- wranglerConfig: {
44283
- main: "./dist/_worker.js",
44284
- compatibility_flags: ["global_fetch_strictly_public"],
44285
- assets: {
44286
- binding: "ASSET",
44287
- directory: "./dist"
44287
+ buildTool: "wrangler",
44288
+ workerConfig: {
44289
+ entrypoint: "./dist/_worker.js",
44290
+ compatibilityFlags: ["global_fetch_strictly_public"],
44291
+ env: {
44292
+ ASSET: { type: "assets" }
44288
44293
  }
44289
44294
  },
44295
+ buildConfig: { assetsDirectory: "./dist" },
44290
44296
  packageJsonScriptsOverrides: {
44291
44297
  preview: `${packageManager.type} run build && wrangler dev`,
44292
44298
  deploy: `${packageManager.type} run build && wrangler deploy`
@@ -44926,8 +44932,9 @@ var ReactRouter = class extends Framework {
44926
44932
  }
44927
44933
  }
44928
44934
  return {
44929
- wranglerConfig: {
44930
- main: "./workers/app.ts"
44935
+ buildTool: "vite",
44936
+ workerConfig: {
44937
+ entrypoint: "./workers/app.ts"
44931
44938
  }
44932
44939
  };
44933
44940
  }
@@ -44951,13 +44958,14 @@ var SolidStart = class extends Framework {
44951
44958
  }
44952
44959
  }
44953
44960
  return {
44954
- wranglerConfig: {
44955
- main: "./.output/server/index.mjs",
44956
- assets: {
44957
- binding: "ASSETS",
44958
- directory: "./.output/public"
44961
+ buildTool: "wrangler",
44962
+ workerConfig: {
44963
+ entrypoint: "./.output/server/index.mjs",
44964
+ env: {
44965
+ ASSETS: { type: "assets" }
44959
44966
  }
44960
- }
44967
+ },
44968
+ buildConfig: { assetsDirectory: "./.output/public" }
44961
44969
  };
44962
44970
  }
44963
44971
  };
@@ -45030,11 +45038,9 @@ var Static = class extends Framework {
45030
45038
  }
45031
45039
  configure({ outputDir }) {
45032
45040
  return {
45033
- wranglerConfig: {
45034
- assets: {
45035
- directory: outputDir
45036
- }
45037
- }
45041
+ buildTool: "wrangler",
45042
+ workerConfig: {},
45043
+ buildConfig: { assetsDirectory: outputDir }
45038
45044
  };
45039
45045
  }
45040
45046
  };
@@ -45076,13 +45082,14 @@ var SvelteKit = class extends Framework {
45076
45082
  });
45077
45083
  }
45078
45084
  return {
45079
- wranglerConfig: {
45080
- main: ".svelte-kit/cloudflare/_worker.js",
45081
- assets: {
45082
- binding: "ASSETS",
45083
- directory: ".svelte-kit/cloudflare"
45085
+ buildTool: "wrangler",
45086
+ workerConfig: {
45087
+ entrypoint: ".svelte-kit/cloudflare/_worker.js",
45088
+ env: {
45089
+ ASSETS: { type: "assets" }
45084
45090
  }
45085
- }
45091
+ },
45092
+ buildConfig: { assetsDirectory: ".svelte-kit/cloudflare" }
45086
45093
  };
45087
45094
  }
45088
45095
  configurationDescription = 'Configuring project for SvelteKit with "sv add"';
@@ -45108,8 +45115,9 @@ var TanstackStart = class extends Framework {
45108
45115
  transformViteConfig(projectPath, { viteEnvironmentName: "ssr" });
45109
45116
  }
45110
45117
  return {
45111
- wranglerConfig: {
45112
- main: "@tanstack/react-start/server-entry"
45118
+ buildTool: "vite",
45119
+ workerConfig: {
45120
+ entrypoint: "@tanstack/react-start/server-entry"
45113
45121
  }
45114
45122
  };
45115
45123
  }
@@ -45155,8 +45163,9 @@ var Vike = class extends Framework {
45155
45163
  addVikePhotonToConfigFile(projectPath);
45156
45164
  }
45157
45165
  return {
45158
- wranglerConfig: {
45159
- main: "virtual:photon:cloudflare:server-entry"
45166
+ buildTool: "vite",
45167
+ workerConfig: {
45168
+ entrypoint: "virtual:photon:cloudflare:server-entry"
45160
45169
  },
45161
45170
  packageJsonScriptsOverrides: {
45162
45171
  preview: "vike build && vike preview",
@@ -45295,7 +45304,10 @@ var Vite = class extends Framework {
45295
45304
  static {
45296
45305
  __name(this, "Vite");
45297
45306
  }
45298
- isConfigured(projectPath) {
45307
+ isConfigured(projectPath, { target = "cf" } = {}) {
45308
+ if (target !== "wrangler") {
45309
+ return false;
45310
+ }
45299
45311
  if (!hasViteConfig(projectPath)) {
45300
45312
  return false;
45301
45313
  }
@@ -45320,9 +45332,10 @@ var Vite = class extends Framework {
45320
45332
  }
45321
45333
  }
45322
45334
  return {
45323
- wranglerConfig: {
45335
+ buildTool: "vite",
45336
+ workerConfig: {
45324
45337
  assets: {
45325
- not_found_handling: "single-page-application"
45338
+ notFoundHandling: "single-page-application"
45326
45339
  }
45327
45340
  }
45328
45341
  };
@@ -45370,14 +45383,17 @@ var Waku = class extends Framework {
45370
45383
  await updateWakuConfig(projectPath);
45371
45384
  }
45372
45385
  return {
45373
- wranglerConfig: {
45374
- main: "./src/waku.server",
45386
+ buildTool: "wrangler",
45387
+ workerConfig: {
45388
+ entrypoint: "./src/waku.server",
45375
45389
  assets: {
45376
- binding: "ASSETS",
45377
- directory: "./dist/public",
45378
- html_handling: "drop-trailing-slash"
45390
+ htmlHandling: "drop-trailing-slash"
45391
+ },
45392
+ env: {
45393
+ ASSETS: { type: "assets" }
45379
45394
  }
45380
- }
45395
+ },
45396
+ buildConfig: { assetsDirectory: "./dist/public" }
45381
45397
  };
45382
45398
  }
45383
45399
  };
@@ -45727,7 +45743,7 @@ var NoOpFramework = class extends Framework {
45727
45743
  }
45728
45744
  async configure() {
45729
45745
  return {
45730
- wranglerConfig: {}
45746
+ workerConfig: {}
45731
45747
  };
45732
45748
  }
45733
45749
  };
@@ -52037,6 +52053,11 @@ async function detectFramework(projectPath, context, wranglerConfig) {
52037
52053
  buildSettings,
52038
52054
  context
52039
52055
  );
52056
+ if (maybeDetectedFramework) {
52057
+ maybeDetectedFramework.devCommand = project.frameworks.get(maybeDetectedFramework.baseDirectory ?? "")?.find(
52058
+ ({ id }) => id === maybeDetectedFramework.framework.id
52059
+ )?.dev?.command;
52060
+ }
52040
52061
  if (await isPagesProject(
52041
52062
  projectPath,
52042
52063
  context,
@@ -52203,6 +52224,7 @@ function maybeFindDetectedFramework(settings, context) {
52203
52224
  __name(maybeFindDetectedFramework, "maybeFindDetectedFramework");
52204
52225
 
52205
52226
  // src/details/index.ts
52227
+ var CLOUDFLARE_CONFIG_FILE = "cloudflare.config.ts";
52206
52228
  function assertNonConfigured(details) {
52207
52229
  assert3(
52208
52230
  details.configured === false,
@@ -52239,15 +52261,15 @@ __name(findAssetsDir, "findAssetsDir");
52239
52261
  async function getDetailsForAutoConfig({
52240
52262
  projectPath = process.cwd(),
52241
52263
  wranglerConfig,
52264
+ target = "cf",
52242
52265
  context
52243
52266
  }) {
52244
52267
  const { logger } = context;
52245
52268
  logger.debug(`Running autoconfig detection in ${projectPath}...`);
52246
- if (
52247
- // If a real Wrangler config has been found the project is already configured for Workers
52248
- wranglerConfig?.configPath && // Unless `pages_build_output_dir` is set, since that indicates that the project is a Pages one instead
52249
- !wranglerConfig.pages_build_output_dir
52250
- ) {
52269
+ const hasCloudflareConfig = target === "cf" && existsSync(resolve(projectPath, CLOUDFLARE_CONFIG_FILE));
52270
+ if (target === "wrangler" && // If a real Wrangler config has been found the project is already configured for Workers
52271
+ wranglerConfig?.configPath && // Unless `pages_build_output_dir` is set, since that indicates that the project is a Pages one instead
52272
+ !wranglerConfig.pages_build_output_dir) {
52251
52273
  return {
52252
52274
  configured: true,
52253
52275
  projectPath,
@@ -52268,19 +52290,18 @@ async function getDetailsForAutoConfig({
52268
52290
  } catch {
52269
52291
  logger.debug("No package.json found when running autoconfig");
52270
52292
  }
52271
- const configured = framework.isConfigured(projectPath) ?? false;
52293
+ const configured = hasCloudflareConfig || framework.isConfigured(projectPath, { target });
52272
52294
  const outputDir = detectedFramework?.dist ?? await findAssetsDir(projectPath);
52273
52295
  const baseDetails = {
52274
52296
  projectPath,
52275
52297
  framework,
52276
52298
  packageJson,
52277
52299
  packageManager,
52278
- ...detectedFramework ? {
52279
- buildCommand: getProjectBuildCommand(
52280
- detectedFramework,
52281
- packageManager
52282
- )
52283
- } : {},
52300
+ devCommand: getProjectCommand(detectedFramework.devCommand, packageManager),
52301
+ buildCommand: getProjectCommand(
52302
+ detectedFramework.buildCommand,
52303
+ packageManager
52304
+ ),
52284
52305
  workerName: getWorkerName(packageJson?.name, projectPath)
52285
52306
  };
52286
52307
  if (configured) {
@@ -52306,19 +52327,19 @@ async function getDetailsForAutoConfig({
52306
52327
  };
52307
52328
  }
52308
52329
  __name(getDetailsForAutoConfig, "getDetailsForAutoConfig");
52309
- function getProjectBuildCommand(detectedFramework, packageManager) {
52310
- if (!detectedFramework.buildCommand) {
52330
+ function getProjectCommand(command, packageManager) {
52331
+ if (!command) {
52311
52332
  return void 0;
52312
52333
  }
52313
52334
  const { type, dlx, npx } = packageManager;
52314
52335
  for (const packageManagerCommandPrefix of [type, dlx.join(" "), npx]) {
52315
- if (detectedFramework.buildCommand.startsWith(packageManagerCommandPrefix)) {
52316
- return detectedFramework.buildCommand;
52336
+ if (command.startsWith(packageManagerCommandPrefix)) {
52337
+ return command;
52317
52338
  }
52318
52339
  }
52319
- return `${npx} ${detectedFramework.buildCommand}`;
52340
+ return `${npx} ${command}`;
52320
52341
  }
52321
- __name(getProjectBuildCommand, "getProjectBuildCommand");
52342
+ __name(getProjectCommand, "getProjectCommand");
52322
52343
  function displayAutoConfigDetails(autoConfigDetails, context, displayOptions) {
52323
52344
  const { logger } = context;
52324
52345
  logger.log("");
@@ -52411,11 +52432,12 @@ async function confirmAutoConfigDetails(autoConfigDetails, context) {
52411
52432
  __name(confirmAutoConfigDetails, "confirmAutoConfigDetails");
52412
52433
  async function runAutoConfig(autoConfigDetails, autoConfigOptions) {
52413
52434
  const { context } = autoConfigOptions;
52435
+ const target = autoConfigOptions.target ?? "cf";
52414
52436
  const { logger } = context;
52415
52437
  const dryRun = autoConfigOptions.dryRun === true;
52416
52438
  const runBuild = !dryRun && (autoConfigOptions.runBuild ?? true);
52417
52439
  const skipConfirmations = dryRun || autoConfigOptions.skipConfirmations === true;
52418
- const enableWranglerInstallation = autoConfigOptions.enableWranglerInstallation ?? true;
52440
+ const enableTargetCliInstallation = autoConfigOptions.enableTargetCliInstallation ?? true;
52419
52441
  assertNonConfigured(autoConfigDetails);
52420
52442
  displayAutoConfigDetails(autoConfigDetails, context);
52421
52443
  const updatedAutoConfigDetails = skipConfirmations ? autoConfigDetails : await confirmAutoConfigDetails(autoConfigDetails, context);
@@ -52442,10 +52464,9 @@ async function runAutoConfig(autoConfigDetails, autoConfigOptions) {
52442
52464
  "The Output Directory is unexpectedly missing"
52443
52465
  );
52444
52466
  const compatibilityDate = DEFAULT_COMPAT_DATE;
52445
- const wranglerConfig = {
52446
- $schema: "node_modules/wrangler/config-schema.json",
52467
+ const defaultWorkerConfig = {
52447
52468
  name: autoConfigDetails.workerName,
52448
- compatibility_date: compatibilityDate,
52469
+ compatibilityDate,
52449
52470
  observability: {
52450
52471
  enabled: true
52451
52472
  }
@@ -52463,6 +52484,7 @@ async function runAutoConfig(autoConfigDetails, autoConfigOptions) {
52463
52484
  );
52464
52485
  }
52465
52486
  const dryRunConfigurationResults = await autoConfigDetails.framework.configure({
52487
+ target,
52466
52488
  outputDir: autoConfigDetails.outputDir,
52467
52489
  projectPath: autoConfigDetails.projectPath,
52468
52490
  workerName: autoConfigDetails.workerName,
@@ -52471,18 +52493,32 @@ async function runAutoConfig(autoConfigDetails, autoConfigOptions) {
52471
52493
  packageManager,
52472
52494
  context
52473
52495
  });
52496
+ const dryRunWorkerConfig = mergeWorkerConfig(
52497
+ defaultWorkerConfig,
52498
+ dryRunConfigurationResults.workerConfig
52499
+ );
52500
+ if (target === "cf" && dryRunConfigurationResults.buildTool === "wrangler" && dryRunConfigurationResults.buildConfig && existsSync(resolve(autoConfigDetails.projectPath, "wrangler.config.ts"))) {
52501
+ throw new FatalError(
52502
+ "Cannot generate wrangler.config.ts because the file already exists. Remove or rename the existing file, then run autoconfig again.",
52503
+ { telemetryMessage: "autoconfig wrangler config conflict" }
52504
+ );
52505
+ }
52474
52506
  const { npx } = packageManager;
52507
+ let buildCommand = dryRunConfigurationResults.buildCommandOverride ?? autoConfigDetails.buildCommand;
52508
+ if (target === "cf" && autoConfigDetails.packageJson?.scripts?.build !== void 0) {
52509
+ buildCommand = `${packageManager.type} run build`;
52510
+ }
52475
52511
  const autoConfigSummary = await buildOperationsSummary(
52476
52512
  { ...autoConfigDetails, outputDir: autoConfigDetails.outputDir },
52477
- dryRunConfigurationResults.wranglerConfig === null ? null : ensureNodejsCompatIsEnabled({
52478
- ...wranglerConfig,
52479
- ...dryRunConfigurationResults.wranglerConfig
52480
- }),
52513
+ dryRunWorkerConfig,
52514
+ dryRunConfigurationResults,
52481
52515
  {
52482
- build: dryRunConfigurationResults.buildCommandOverride ?? autoConfigDetails.buildCommand,
52483
- deploy: dryRunConfigurationResults.deployCommandOverride ?? `${npx} wrangler deploy`,
52484
- version: dryRunConfigurationResults?.versionCommandOverride ?? `${npx} wrangler versions upload`
52516
+ build: buildCommand,
52517
+ deploy: dryRunConfigurationResults.deployCommandOverride ?? `${npx} ${target} deploy`,
52518
+ version: dryRunConfigurationResults.versionCommandOverride ?? `${npx} ${target} versions upload`
52485
52519
  },
52520
+ enableTargetCliInstallation,
52521
+ target,
52486
52522
  context,
52487
52523
  dryRunConfigurationResults.packageJsonScriptsOverrides
52488
52524
  );
@@ -52502,10 +52538,21 @@ async function runAutoConfig(autoConfigDetails, autoConfigOptions) {
52502
52538
  `Running autoconfig with:
52503
52539
  ${JSON.stringify(autoConfigDetails, null, 2)}...`
52504
52540
  );
52505
- if (autoConfigSummary.wranglerInstall && enableWranglerInstallation) {
52541
+ if (autoConfigDetails.packageJson && enableTargetCliInstallation) {
52542
+ if (target === "cf") {
52543
+ await installPackages(packageManager.type, ["cf@latest"], {
52544
+ dev: true,
52545
+ isWorkspaceRoot
52546
+ });
52547
+ } else {
52548
+ await installWrangler(packageManager.type, isWorkspaceRoot);
52549
+ }
52550
+ }
52551
+ if (autoConfigDetails.packageJson && target === "cf" && dryRunConfigurationResults.buildTool === "wrangler") {
52506
52552
  await installWrangler(packageManager.type, isWorkspaceRoot);
52507
52553
  }
52508
52554
  const configurationResults = await autoConfigDetails.framework.configure({
52555
+ target,
52509
52556
  outputDir: autoConfigDetails.outputDir,
52510
52557
  projectPath: autoConfigDetails.projectPath,
52511
52558
  workerName: autoConfigDetails.workerName,
@@ -52514,6 +52561,10 @@ ${JSON.stringify(autoConfigDetails, null, 2)}...`
52514
52561
  packageManager,
52515
52562
  context
52516
52563
  });
52564
+ const workerConfig = mergeWorkerConfig(
52565
+ defaultWorkerConfig,
52566
+ configurationResults.workerConfig
52567
+ );
52517
52568
  if (autoConfigDetails.packageJson) {
52518
52569
  const packageJsonPath = resolve(
52519
52570
  autoConfigDetails.projectPath,
@@ -52537,11 +52588,25 @@ ${JSON.stringify(autoConfigDetails, null, 2)}...`
52537
52588
  ) + "\n"
52538
52589
  );
52539
52590
  }
52540
- if (configurationResults.wranglerConfig !== null) {
52541
- await saveWranglerJsonc(autoConfigDetails.projectPath, {
52542
- ...wranglerConfig,
52543
- ...configurationResults.wranglerConfig
52544
- });
52591
+ if (target === "wrangler") {
52592
+ const wranglerConfig = getWranglerConfig(
52593
+ workerConfig,
52594
+ configurationResults
52595
+ );
52596
+ if (wranglerConfig !== null) {
52597
+ await saveWranglerJsonc(autoConfigDetails.projectPath, wranglerConfig);
52598
+ }
52599
+ }
52600
+ if (target === "cf") {
52601
+ if (workerConfig !== null) {
52602
+ await saveCloudflareConfig(autoConfigDetails.projectPath, workerConfig);
52603
+ }
52604
+ if (configurationResults.buildTool === "wrangler" && configurationResults.buildConfig) {
52605
+ await saveWranglerConfigTs(
52606
+ autoConfigDetails.projectPath,
52607
+ configurationResults.buildConfig
52608
+ );
52609
+ }
52545
52610
  }
52546
52611
  maybeAppendWranglerToGitIgnore(autoConfigDetails.projectPath);
52547
52612
  if (autoConfigDetails.outputDir === autoConfigDetails.projectPath) {
@@ -52549,7 +52614,6 @@ ${JSON.stringify(autoConfigDetails, null, 2)}...`
52549
52614
  `${autoConfigDetails.projectPath}/.assetsignore`
52550
52615
  );
52551
52616
  }
52552
- const buildCommand = configurationResults.buildCommandOverride ?? autoConfigDetails.buildCommand;
52553
52617
  if (buildCommand && runBuild) {
52554
52618
  await context.runCommand(
52555
52619
  buildCommand,
@@ -52560,6 +52624,32 @@ ${JSON.stringify(autoConfigDetails, null, 2)}...`
52560
52624
  return autoConfigSummary;
52561
52625
  }
52562
52626
  __name(runAutoConfig, "runAutoConfig");
52627
+ function mergeWorkerConfig(defaultWorkerConfig, workerConfig) {
52628
+ return workerConfig === null ? null : { ...defaultWorkerConfig, ...workerConfig };
52629
+ }
52630
+ __name(mergeWorkerConfig, "mergeWorkerConfig");
52631
+ function getWranglerConfig(workerConfig, configurationResults) {
52632
+ if (workerConfig === null) {
52633
+ return null;
52634
+ }
52635
+ const parsedWorkerConfig = InputWorkerSchema.parse({
52636
+ type: "worker",
52637
+ ...workerConfig
52638
+ });
52639
+ const convertedWranglerConfig = convertToWranglerConfig(parsedWorkerConfig);
52640
+ const wranglerConfig = ensureNodejsCompatIsEnabled({
52641
+ $schema: "node_modules/wrangler/config-schema.json",
52642
+ ...convertedWranglerConfig,
52643
+ ...configurationResults.buildConfig?.assetsDirectory ? {
52644
+ assets: {
52645
+ ...convertedWranglerConfig.assets,
52646
+ directory: configurationResults.buildConfig.assetsDirectory
52647
+ }
52648
+ } : {}
52649
+ });
52650
+ return wranglerConfig;
52651
+ }
52652
+ __name(getWranglerConfig, "getWranglerConfig");
52563
52653
  function ensureNodejsCompatIsEnabled(wranglerConfig) {
52564
52654
  const flags = (wranglerConfig.compatibility_flags ?? []).filter(
52565
52655
  (flag) => !flag.startsWith("nodejs_")
@@ -52594,39 +52684,88 @@ async function saveWranglerJsonc(projectPath, wranglerConfig) {
52594
52684
  );
52595
52685
  }
52596
52686
  __name(saveWranglerJsonc, "saveWranglerJsonc");
52597
- async function buildOperationsSummary(autoConfigDetails, wranglerConfigToWrite, projectCommands, context, packageJsonScriptsOverrides) {
52687
+ async function saveCloudflareConfig(projectPath, workerConfig) {
52688
+ await writeFile(
52689
+ resolve(projectPath, "cloudflare.config.ts"),
52690
+ renderCloudflareConfig(workerConfig)
52691
+ );
52692
+ }
52693
+ __name(saveCloudflareConfig, "saveCloudflareConfig");
52694
+ async function saveWranglerConfigTs(projectPath, buildConfig) {
52695
+ await writeFile(
52696
+ resolve(projectPath, "wrangler.config.ts"),
52697
+ renderWranglerConfigTs(buildConfig)
52698
+ );
52699
+ }
52700
+ __name(saveWranglerConfigTs, "saveWranglerConfigTs");
52701
+ function renderCloudflareConfig(workerConfig) {
52702
+ return `import { defineWorker } from "cf/config";
52703
+
52704
+ export default defineWorker(${JSON.stringify(workerConfig, null, 2)});
52705
+ `;
52706
+ }
52707
+ __name(renderCloudflareConfig, "renderCloudflareConfig");
52708
+ function renderWranglerConfigTs(buildConfig) {
52709
+ return `import { defineWranglerConfig } from "wrangler/experimental-config";
52710
+
52711
+ export default defineWranglerConfig(${JSON.stringify(buildConfig, null, 2)});
52712
+ `;
52713
+ }
52714
+ __name(renderWranglerConfigTs, "renderWranglerConfigTs");
52715
+ function indentFileContent(content) {
52716
+ return " " + content.trimEnd().replace(/\n/g, "\n ");
52717
+ }
52718
+ __name(indentFileContent, "indentFileContent");
52719
+ async function buildOperationsSummary(autoConfigDetails, workerConfig, configurationResults, projectCommands, enableTargetCliInstallation, target, context, packageJsonScriptsOverrides) {
52598
52720
  const { logger } = context;
52599
52721
  logger.log("");
52722
+ const wranglerConfig = target === "wrangler" ? getWranglerConfig(workerConfig, configurationResults) : null;
52600
52723
  const summary = {
52601
- wranglerInstall: false,
52602
52724
  scripts: {},
52603
- ...wranglerConfigToWrite !== null ? {
52604
- wranglerConfig: wranglerConfigToWrite
52605
- } : {},
52725
+ ...target === "wrangler" ? { wranglerConfig: wranglerConfig ?? void 0 } : {
52726
+ workerConfig: workerConfig ?? void 0,
52727
+ buildConfig: configurationResults.buildConfig
52728
+ },
52606
52729
  outputDir: autoConfigDetails.outputDir,
52607
52730
  frameworkId: autoConfigDetails.framework.id,
52608
52731
  buildCommand: projectCommands.build,
52609
52732
  deployCommand: projectCommands.deploy,
52610
52733
  versionCommand: projectCommands.version
52611
52734
  };
52735
+ const packagesToInstall = /* @__PURE__ */ new Set();
52612
52736
  if (autoConfigDetails.packageJson) {
52613
- summary.wranglerInstall = true;
52737
+ if (enableTargetCliInstallation) {
52738
+ packagesToInstall.add(target);
52739
+ }
52740
+ if (configurationResults.buildTool === "vite") {
52741
+ packagesToInstall.add("@cloudflare/vite-plugin");
52742
+ } else if (target === "cf" && configurationResults.buildTool === "wrangler") {
52743
+ packagesToInstall.add("wrangler");
52744
+ }
52745
+ }
52746
+ if (packagesToInstall.size > 0) {
52614
52747
  logger.log("\u{1F4E6} Install packages:");
52615
- logger.log(` - wrangler (devDependency)`);
52748
+ for (const packageName of packagesToInstall) {
52749
+ logger.log(` - ${packageName} (devDependency)`);
52750
+ }
52616
52751
  logger.log("");
52752
+ }
52753
+ if (autoConfigDetails.packageJson) {
52754
+ const scriptOverrides = target === "wrangler" ? packageJsonScriptsOverrides : void 0;
52755
+ const buildCommandPrefix = autoConfigDetails.buildCommand ? `${autoConfigDetails.buildCommand} && ` : "";
52617
52756
  summary.scripts = {
52618
- deploy: packageJsonScriptsOverrides?.deploy ?? (autoConfigDetails.buildCommand ? `${autoConfigDetails.buildCommand} && wrangler deploy` : `wrangler deploy`),
52619
- preview: packageJsonScriptsOverrides?.preview ?? (autoConfigDetails.buildCommand ? `${autoConfigDetails.buildCommand} && wrangler dev` : `wrangler dev`)
52757
+ deploy: scriptOverrides?.deploy ?? `${buildCommandPrefix}${target} deploy${target === "cf" && autoConfigDetails.buildCommand ? " --no-build" : ""}`,
52758
+ preview: scriptOverrides?.preview ?? `${target === "wrangler" ? buildCommandPrefix : ""}${target} dev`
52620
52759
  };
52621
52760
  const containsServerSideCode = (
52622
52761
  // If there is an entrypoint then we know that there is server side code
52623
- !!wranglerConfigToWrite?.main
52762
+ !!workerConfig?.entrypoint
52624
52763
  );
52625
52764
  if (
52626
52765
  // If there is no server side code, then there is no need to add the cf-typegen script
52627
52766
  containsServerSideCode && usesTypescript(autoConfigDetails.projectPath) && !("cf-typegen" in (autoConfigDetails.packageJson.scripts ?? {}))
52628
52767
  ) {
52629
- summary.scripts["cf-typegen"] = packageJsonScriptsOverrides?.typegen ?? "wrangler types";
52768
+ summary.scripts["cf-typegen"] = scriptOverrides?.typegen ?? `${target} types`;
52630
52769
  }
52631
52770
  logger.log("\u{1F4DD} Update package.json scripts:");
52632
52771
  for (const [name, script] of Object.entries(summary.scripts)) {
@@ -52634,7 +52773,21 @@ async function buildOperationsSummary(autoConfigDetails, wranglerConfigToWrite,
52634
52773
  }
52635
52774
  logger.log("");
52636
52775
  }
52637
- if (wranglerConfigToWrite) {
52776
+ if (target === "cf" && workerConfig) {
52777
+ logger.log("\u{1F4C4} Create cloudflare.config.ts:");
52778
+ logger.log(indentFileContent(renderCloudflareConfig(workerConfig)));
52779
+ logger.log("");
52780
+ }
52781
+ if (target === "cf" && configurationResults.buildTool === "wrangler" && configurationResults.buildConfig) {
52782
+ logger.log("\u{1F4C4} Create wrangler.config.ts:");
52783
+ logger.log(
52784
+ indentFileContent(
52785
+ renderWranglerConfigTs(configurationResults.buildConfig)
52786
+ )
52787
+ );
52788
+ logger.log("");
52789
+ }
52790
+ if (target === "wrangler" && wranglerConfig) {
52638
52791
  const wranglerConfigPath = resolve(
52639
52792
  autoConfigDetails.projectPath,
52640
52793
  "wrangler.jsonc"
@@ -52644,11 +52797,13 @@ async function buildOperationsSummary(autoConfigDetails, wranglerConfigToWrite,
52644
52797
  configExists ? "\u{1F4C4} Update wrangler.jsonc:" : "\u{1F4C4} Create wrangler.jsonc:"
52645
52798
  );
52646
52799
  logger.log(
52647
- " " + JSON.stringify(wranglerConfigToWrite, null, 2).replace(/\n/g, "\n ")
52800
+ " " + JSON.stringify(wranglerConfig, null, 2).replace(/\n/g, "\n ")
52648
52801
  );
52649
52802
  logger.log("");
52650
52803
  }
52651
- if (autoConfigDetails.framework && !(autoConfigDetails.framework instanceof Static) && !autoConfigDetails.framework.isConfigured(autoConfigDetails.projectPath)) {
52804
+ if (autoConfigDetails.framework && !(autoConfigDetails.framework instanceof Static) && !autoConfigDetails.framework.isConfigured(autoConfigDetails.projectPath, {
52805
+ target
52806
+ })) {
52652
52807
  summary.frameworkConfiguration = autoConfigDetails.framework.configurationDescription ?? `Configuring project for ${autoConfigDetails.framework.name}`;
52653
52808
  logger.log(`\u{1F6E0}\uFE0F ${summary.frameworkConfiguration}`);
52654
52809
  logger.log("");