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