@cloudflare/autoconfig 0.2.8 → 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.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { PackageManager, RawConfig, PackageJSON, Config, FatalError, TelemetryMessage, UserError } from '@cloudflare/workers-utils';
1
+ import { WorkerConfigInput } from '@cloudflare/config';
2
+ import { PackageManager, PackageJSON, RawConfig, Config, FatalError, TelemetryMessage, UserError } from '@cloudflare/workers-utils';
2
3
  export { getInstalledPackageVersion } from '@cloudflare/workers-utils';
3
4
 
4
5
  /**
@@ -17,6 +18,7 @@ interface AutoConfigLogger {
17
18
  /** Logs an error message. */
18
19
  error(...args: unknown[]): void;
19
20
  }
21
+ type AutoConfigTarget = "cf" | "wrangler";
20
22
  /**
21
23
  * Dialog interface for interactive prompts.
22
24
  * Callers provide their own implementation (e.g., using `prompts`, `inquirer`, or a custom UI).
@@ -132,7 +134,9 @@ declare abstract class Framework {
132
134
  readonly name: FrameworkInfo["name"];
133
135
  get frameworkVersion(): string;
134
136
  constructor(frameworkInfo: Pick<FrameworkInfo, "id" | "name">);
135
- isConfigured(_projectPath: string): boolean;
137
+ isConfigured(_projectPath: string, { target: _target, }?: {
138
+ target?: AutoConfigTarget;
139
+ }): boolean;
136
140
  abstract configure(options: ConfigurationOptions): Promise<ConfigurationResults> | ConfigurationResults;
137
141
  configurationDescription?: string;
138
142
  /**
@@ -149,6 +153,7 @@ declare abstract class Framework {
149
153
  validateFrameworkVersion(projectPath: string, frameworkPackageInfo: AutoConfigFrameworkPackageInfo, context: AutoConfigContext): void;
150
154
  }
151
155
  type ConfigurationOptions = {
156
+ target: AutoConfigTarget;
152
157
  outputDir: string;
153
158
  projectPath: string;
154
159
  workerName: string;
@@ -162,9 +167,16 @@ type PackageJsonScriptsOverrides = {
162
167
  deploy?: string;
163
168
  typegen?: string;
164
169
  };
170
+ type BuildConfig = {
171
+ assetsDirectory?: string;
172
+ };
165
173
  type ConfigurationResults = {
166
- /** The wrangler configuration that the framework's `configure()` hook should generate. `null` if autoconfig should not create the wrangler file (in case an external tool already does that) */
167
- wranglerConfig: RawConfig | null;
174
+ /** The tool that cf should delegate build and development commands to. */
175
+ buildTool?: "vite" | "wrangler";
176
+ /** Worker configuration generated by the framework. `null` if an external tool generates it. */
177
+ workerConfig: Partial<WorkerConfigInput> | null;
178
+ /** Build configuration that complements the Worker configuration. */
179
+ buildConfig?: BuildConfig;
168
180
  packageJsonScriptsOverrides?: PackageJsonScriptsOverrides;
169
181
  buildCommandOverride?: string;
170
182
  deployCommandOverride?: string;
@@ -184,6 +196,8 @@ type AutoConfigDetailsBase = {
184
196
  configured: boolean;
185
197
  /** Details about the detected framework. It can be a JS framework or 'Static' if no actual JS framework is used. */
186
198
  framework: Framework;
199
+ /** The dev command used to run the project locally (if any) */
200
+ devCommand?: string;
187
201
  /** The build command used to build the project (if any) */
188
202
  buildCommand?: string;
189
203
  /** The output directory (if no framework is used, points to the raw asset files) */
@@ -201,6 +215,8 @@ type AutoConfigDetailsForNonConfiguredProject = AutoConfigDetailsBase & {
201
215
  };
202
216
  type AutoConfigDetails = AutoConfigDetailsForConfiguredProject | AutoConfigDetailsForNonConfiguredProject;
203
217
  type AutoConfigOptions = {
218
+ /** The configuration target, defaults to cf. */
219
+ target?: AutoConfigTarget;
204
220
  /** The autoconfig context providing logger, dialogs, and other dependencies. */
205
221
  context: AutoConfigContext;
206
222
  /** Whether to run autoconfig without actually applying any filesystem modification (default: false) */
@@ -218,13 +234,14 @@ type AutoConfigOptions = {
218
234
  */
219
235
  skipConfirmations?: boolean;
220
236
  /**
221
- * Whether to install Wrangler during autoconfig
237
+ * Whether to install the selected target CLI during autoconfig.
222
238
  */
223
- enableWranglerInstallation?: boolean;
239
+ enableTargetCliInstallation?: boolean;
224
240
  };
225
241
  type AutoConfigSummary = {
226
242
  scripts: Record<string, string>;
227
- wranglerInstall: boolean;
243
+ workerConfig?: WorkerConfigInput;
244
+ buildConfig?: BuildConfig;
228
245
  wranglerConfig?: RawConfig;
229
246
  frameworkConfiguration?: string;
230
247
  outputDir: string;
@@ -236,16 +253,21 @@ type AutoConfigSummary = {
236
253
 
237
254
  /**
238
255
  * Detects project details needed for autoconfig: framework, package manager,
239
- * output directory, worker name, and whether the project is already configured.
256
+ * output directory, worker name, commands, and whether the project is already configured.
257
+ * By default, the project is considered configured when `cloudflare.config.ts`
258
+ * exists. Passing `target: "wrangler"` opts into Wrangler configuration
259
+ * detection instead.
240
260
  *
241
261
  * @param options - Detection options including project path, wrangler config, and context.
242
262
  * @returns The detected project details.
243
263
  */
244
- declare function getDetailsForAutoConfig({ projectPath, wranglerConfig, context, }: {
264
+ declare function getDetailsForAutoConfig({ projectPath, wranglerConfig, target, context, }: {
245
265
  /** The path to the project, defaults to cwd. */
246
266
  projectPath?: string;
247
267
  /** The parsed wrangler configuration for the project (if any). */
248
268
  wranglerConfig?: Config;
269
+ /** The configuration target, defaults to cf. */
270
+ target?: AutoConfigTarget;
249
271
  /** The autoconfig context providing logger, dialogs, and other dependencies. */
250
272
  context: AutoConfigContext;
251
273
  }): Promise<AutoConfigDetails>;
@@ -270,7 +292,7 @@ declare function confirmAutoConfigDetails(autoConfigDetails: AutoConfigDetails,
270
292
 
271
293
  /**
272
294
  * Runs the full autoconfig flow: displays detected settings, confirms with the user,
273
- * validates the framework version, runs framework configuration, writes wrangler config,
295
+ * validates the framework version, runs framework configuration, writes configuration,
274
296
  * updates package.json scripts, and optionally runs the build command.
275
297
  *
276
298
  * @param autoConfigDetails - The detected project details from `getDetailsForAutoConfig()`.
@@ -280,23 +302,26 @@ declare function confirmAutoConfigDetails(autoConfigDetails: AutoConfigDetails,
280
302
  declare function runAutoConfig(autoConfigDetails: AutoConfigDetails, autoConfigOptions: AutoConfigOptions): Promise<AutoConfigSummary>;
281
303
  /**
282
304
  * Builds a summary of all operations that autoconfig will (or did) perform,
283
- * including package installation, package.json script updates, wrangler config
305
+ * including package installation, package.json script updates, configuration
284
306
  * creation, and framework-specific configuration.
285
307
  *
286
308
  * @param autoConfigDetails - The detected project details.
287
- * @param wranglerConfigToWrite - The wrangler config object to write, or `null` if not applicable.
309
+ * @param workerConfig - The resolved Worker configuration.
310
+ * @param configurationResults - The framework configuration results.
288
311
  * @param projectCommands - The build, deploy, and version commands for the project.
312
+ * @param enableTargetCliInstallation - Whether to install the selected target CLI package.
313
+ * @param target - The configuration target.
289
314
  * @param context - The autoconfig context providing logger and other dependencies.
290
315
  * @param packageJsonScriptsOverrides - Optional overrides for package.json script entries.
291
316
  * @returns A summary object describing all planned operations.
292
317
  */
293
318
  declare function buildOperationsSummary(autoConfigDetails: AutoConfigDetailsForNonConfiguredProject & {
294
319
  outputDir: NonNullable<AutoConfigDetails["outputDir"]>;
295
- }, wranglerConfigToWrite: RawConfig | null, projectCommands: {
320
+ }, workerConfig: WorkerConfigInput | null, configurationResults: ConfigurationResults, projectCommands: {
296
321
  build?: string;
297
322
  deploy: string;
298
323
  version?: string;
299
- }, context: AutoConfigContext, packageJsonScriptsOverrides?: PackageJsonScriptsOverrides): Promise<AutoConfigSummary>;
324
+ }, enableTargetCliInstallation: boolean, target: AutoConfigTarget, context: AutoConfigContext, packageJsonScriptsOverrides?: PackageJsonScriptsOverrides): Promise<AutoConfigSummary>;
300
325
 
301
326
  /**
302
327
  * Base class for errors where something in a autoconfig frameworks' configuration goes
@@ -326,4 +351,4 @@ declare class AutoConfigDetectionError extends FatalError {
326
351
  });
327
352
  }
328
353
 
329
- export { type AutoConfigContext, type AutoConfigDetails, type AutoConfigDetailsForConfiguredProject, type AutoConfigDetailsForNonConfiguredProject, AutoConfigDetectionError, type AutoConfigDialogs, AutoConfigFrameworkConfigurationError, type AutoConfigFrameworkPackageInfo, type AutoConfigLogger, type AutoConfigOptions, type AutoConfigSummary, type ConfigurationOptions, type ConfigurationResults, Framework, type FrameworkInfo, type PackageJsonScriptsOverrides, buildOperationsSummary, confirmAutoConfigDetails, displayAutoConfigDetails, getDetailsForAutoConfig, isFrameworkSupported, runAutoConfig };
354
+ export { type AutoConfigContext, type AutoConfigDetails, type AutoConfigDetailsForConfiguredProject, type AutoConfigDetailsForNonConfiguredProject, AutoConfigDetectionError, type AutoConfigDialogs, AutoConfigFrameworkConfigurationError, type AutoConfigFrameworkPackageInfo, type AutoConfigLogger, type AutoConfigOptions, type AutoConfigSummary, type AutoConfigTarget, type BuildConfig, type ConfigurationOptions, type ConfigurationResults, Framework, type FrameworkInfo, type PackageJsonScriptsOverrides, buildOperationsSummary, confirmAutoConfigDetails, displayAutoConfigDetails, getDetailsForAutoConfig, isFrameworkSupported, runAutoConfig };