@cloudflare/autoconfig 0.0.0 → 0.1.2
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/chunk-6EUZQHAF.js +42 -0
- package/dist/dot-prop-6SRZBKHT.js +270 -0
- package/dist/index.d.ts +340 -0
- package/dist/index.js +52732 -0
- package/dist/metafile-esm.json +1 -0
- package/package.json +10 -5
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
+
}) : x)(function(x) {
|
|
11
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
+
});
|
|
14
|
+
var __esm = (fn, res) => function __init() {
|
|
15
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
16
|
+
};
|
|
17
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
18
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
23
|
+
};
|
|
24
|
+
var __copyProps = (to, from, except, desc) => {
|
|
25
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
26
|
+
for (let key of __getOwnPropNames(from))
|
|
27
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
28
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
29
|
+
}
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
33
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
34
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
35
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
36
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
37
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
|
+
mod
|
|
39
|
+
));
|
|
40
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
+
|
|
42
|
+
export { __commonJS, __esm, __export, __name, __require, __toCommonJS, __toESM };
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { __name } from './chunk-6EUZQHAF.js';
|
|
2
|
+
|
|
3
|
+
// ../../node_modules/.pnpm/dot-prop@9.0.0/node_modules/dot-prop/index.js
|
|
4
|
+
var isObject = /* @__PURE__ */ __name((value) => {
|
|
5
|
+
const type = typeof value;
|
|
6
|
+
return value !== null && (type === "object" || type === "function");
|
|
7
|
+
}, "isObject");
|
|
8
|
+
var isEmptyObject = /* @__PURE__ */ __name((value) => isObject(value) && Object.keys(value).length === 0, "isEmptyObject");
|
|
9
|
+
var disallowedKeys = /* @__PURE__ */ new Set([
|
|
10
|
+
"__proto__",
|
|
11
|
+
"prototype",
|
|
12
|
+
"constructor"
|
|
13
|
+
]);
|
|
14
|
+
var digits = new Set("0123456789");
|
|
15
|
+
function getPathSegments(path) {
|
|
16
|
+
const parts = [];
|
|
17
|
+
let currentSegment = "";
|
|
18
|
+
let currentPart = "start";
|
|
19
|
+
let isIgnoring = false;
|
|
20
|
+
for (const character of path) {
|
|
21
|
+
switch (character) {
|
|
22
|
+
case "\\": {
|
|
23
|
+
if (currentPart === "index") {
|
|
24
|
+
throw new Error("Invalid character in an index");
|
|
25
|
+
}
|
|
26
|
+
if (currentPart === "indexEnd") {
|
|
27
|
+
throw new Error("Invalid character after an index");
|
|
28
|
+
}
|
|
29
|
+
if (isIgnoring) {
|
|
30
|
+
currentSegment += character;
|
|
31
|
+
}
|
|
32
|
+
currentPart = "property";
|
|
33
|
+
isIgnoring = !isIgnoring;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
case ".": {
|
|
37
|
+
if (currentPart === "index") {
|
|
38
|
+
throw new Error("Invalid character in an index");
|
|
39
|
+
}
|
|
40
|
+
if (currentPart === "indexEnd") {
|
|
41
|
+
currentPart = "property";
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
if (isIgnoring) {
|
|
45
|
+
isIgnoring = false;
|
|
46
|
+
currentSegment += character;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
if (disallowedKeys.has(currentSegment)) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
parts.push(currentSegment);
|
|
53
|
+
currentSegment = "";
|
|
54
|
+
currentPart = "property";
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
case "[": {
|
|
58
|
+
if (currentPart === "index") {
|
|
59
|
+
throw new Error("Invalid character in an index");
|
|
60
|
+
}
|
|
61
|
+
if (currentPart === "indexEnd") {
|
|
62
|
+
currentPart = "index";
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
if (isIgnoring) {
|
|
66
|
+
isIgnoring = false;
|
|
67
|
+
currentSegment += character;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
if (currentPart === "property") {
|
|
71
|
+
if (disallowedKeys.has(currentSegment)) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
parts.push(currentSegment);
|
|
75
|
+
currentSegment = "";
|
|
76
|
+
}
|
|
77
|
+
currentPart = "index";
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case "]": {
|
|
81
|
+
if (currentPart === "index") {
|
|
82
|
+
parts.push(Number.parseInt(currentSegment, 10));
|
|
83
|
+
currentSegment = "";
|
|
84
|
+
currentPart = "indexEnd";
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
if (currentPart === "indexEnd") {
|
|
88
|
+
throw new Error("Invalid character after an index");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
default: {
|
|
92
|
+
if (currentPart === "index" && !digits.has(character)) {
|
|
93
|
+
throw new Error("Invalid character in an index");
|
|
94
|
+
}
|
|
95
|
+
if (currentPart === "indexEnd") {
|
|
96
|
+
throw new Error("Invalid character after an index");
|
|
97
|
+
}
|
|
98
|
+
if (currentPart === "start") {
|
|
99
|
+
currentPart = "property";
|
|
100
|
+
}
|
|
101
|
+
if (isIgnoring) {
|
|
102
|
+
isIgnoring = false;
|
|
103
|
+
currentSegment += "\\";
|
|
104
|
+
}
|
|
105
|
+
currentSegment += character;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (isIgnoring) {
|
|
110
|
+
currentSegment += "\\";
|
|
111
|
+
}
|
|
112
|
+
switch (currentPart) {
|
|
113
|
+
case "property": {
|
|
114
|
+
if (disallowedKeys.has(currentSegment)) {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
parts.push(currentSegment);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case "index": {
|
|
121
|
+
throw new Error("Index was not closed");
|
|
122
|
+
}
|
|
123
|
+
case "start": {
|
|
124
|
+
parts.push("");
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return parts;
|
|
129
|
+
}
|
|
130
|
+
__name(getPathSegments, "getPathSegments");
|
|
131
|
+
function isStringIndex(object, key) {
|
|
132
|
+
if (typeof key !== "number" && Array.isArray(object)) {
|
|
133
|
+
const index = Number.parseInt(key, 10);
|
|
134
|
+
return Number.isInteger(index) && object[index] === object[key];
|
|
135
|
+
}
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
__name(isStringIndex, "isStringIndex");
|
|
139
|
+
function assertNotStringIndex(object, key) {
|
|
140
|
+
if (isStringIndex(object, key)) {
|
|
141
|
+
throw new Error("Cannot use string index");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
__name(assertNotStringIndex, "assertNotStringIndex");
|
|
145
|
+
function getProperty(object, path, value) {
|
|
146
|
+
if (!isObject(object) || typeof path !== "string") {
|
|
147
|
+
return value === void 0 ? object : value;
|
|
148
|
+
}
|
|
149
|
+
const pathArray = getPathSegments(path);
|
|
150
|
+
if (pathArray.length === 0) {
|
|
151
|
+
return value;
|
|
152
|
+
}
|
|
153
|
+
for (let index = 0; index < pathArray.length; index++) {
|
|
154
|
+
const key = pathArray[index];
|
|
155
|
+
if (isStringIndex(object, key)) {
|
|
156
|
+
object = index === pathArray.length - 1 ? void 0 : null;
|
|
157
|
+
} else {
|
|
158
|
+
object = object[key];
|
|
159
|
+
}
|
|
160
|
+
if (object === void 0 || object === null) {
|
|
161
|
+
if (index !== pathArray.length - 1) {
|
|
162
|
+
return value;
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return object === void 0 ? value : object;
|
|
168
|
+
}
|
|
169
|
+
__name(getProperty, "getProperty");
|
|
170
|
+
function setProperty(object, path, value) {
|
|
171
|
+
if (!isObject(object) || typeof path !== "string") {
|
|
172
|
+
return object;
|
|
173
|
+
}
|
|
174
|
+
const root = object;
|
|
175
|
+
const pathArray = getPathSegments(path);
|
|
176
|
+
for (let index = 0; index < pathArray.length; index++) {
|
|
177
|
+
const key = pathArray[index];
|
|
178
|
+
assertNotStringIndex(object, key);
|
|
179
|
+
if (index === pathArray.length - 1) {
|
|
180
|
+
object[key] = value;
|
|
181
|
+
} else if (!isObject(object[key])) {
|
|
182
|
+
object[key] = typeof pathArray[index + 1] === "number" ? [] : {};
|
|
183
|
+
}
|
|
184
|
+
object = object[key];
|
|
185
|
+
}
|
|
186
|
+
return root;
|
|
187
|
+
}
|
|
188
|
+
__name(setProperty, "setProperty");
|
|
189
|
+
function deleteProperty(object, path) {
|
|
190
|
+
if (!isObject(object) || typeof path !== "string") {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
const pathArray = getPathSegments(path);
|
|
194
|
+
for (let index = 0; index < pathArray.length; index++) {
|
|
195
|
+
const key = pathArray[index];
|
|
196
|
+
assertNotStringIndex(object, key);
|
|
197
|
+
if (index === pathArray.length - 1) {
|
|
198
|
+
delete object[key];
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
object = object[key];
|
|
202
|
+
if (!isObject(object)) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
__name(deleteProperty, "deleteProperty");
|
|
208
|
+
function hasProperty(object, path) {
|
|
209
|
+
if (!isObject(object) || typeof path !== "string") {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
const pathArray = getPathSegments(path);
|
|
213
|
+
if (pathArray.length === 0) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
for (const key of pathArray) {
|
|
217
|
+
if (!isObject(object) || !(key in object) || isStringIndex(object, key)) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
object = object[key];
|
|
221
|
+
}
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
__name(hasProperty, "hasProperty");
|
|
225
|
+
function escapePath(path) {
|
|
226
|
+
if (typeof path !== "string") {
|
|
227
|
+
throw new TypeError("Expected a string");
|
|
228
|
+
}
|
|
229
|
+
return path.replaceAll(/[\\.[]/g, "\\$&");
|
|
230
|
+
}
|
|
231
|
+
__name(escapePath, "escapePath");
|
|
232
|
+
function entries(value) {
|
|
233
|
+
const result = Object.entries(value);
|
|
234
|
+
if (Array.isArray(value)) {
|
|
235
|
+
return result.map(([key, value2]) => [Number(key), value2]);
|
|
236
|
+
}
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
239
|
+
__name(entries, "entries");
|
|
240
|
+
function stringifyPath(pathSegments) {
|
|
241
|
+
let result = "";
|
|
242
|
+
for (let [index, segment] of entries(pathSegments)) {
|
|
243
|
+
if (typeof segment === "number") {
|
|
244
|
+
result += `[${segment}]`;
|
|
245
|
+
} else {
|
|
246
|
+
segment = escapePath(segment);
|
|
247
|
+
result += index === 0 ? segment : `.${segment}`;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return result;
|
|
251
|
+
}
|
|
252
|
+
__name(stringifyPath, "stringifyPath");
|
|
253
|
+
function* deepKeysIterator(object, currentPath = []) {
|
|
254
|
+
if (!isObject(object) || isEmptyObject(object)) {
|
|
255
|
+
if (currentPath.length > 0) {
|
|
256
|
+
yield stringifyPath(currentPath);
|
|
257
|
+
}
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
for (const [key, value] of entries(object)) {
|
|
261
|
+
yield* deepKeysIterator(value, [...currentPath, key]);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
__name(deepKeysIterator, "deepKeysIterator");
|
|
265
|
+
function deepKeys(object) {
|
|
266
|
+
return [...deepKeysIterator(object)];
|
|
267
|
+
}
|
|
268
|
+
__name(deepKeys, "deepKeys");
|
|
269
|
+
|
|
270
|
+
export { deepKeys, deleteProperty, escapePath, getProperty, hasProperty, setProperty };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { PackageManager, RawConfig, PackageJSON, Config, FatalError, TelemetryMessage, UserError } from '@cloudflare/workers-utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Logger interface for autoconfig output.
|
|
5
|
+
* Callers provide their own implementation (e.g., wrapping `console` or a custom logger).
|
|
6
|
+
*/
|
|
7
|
+
interface AutoConfigLogger {
|
|
8
|
+
/** Logs informational output. */
|
|
9
|
+
log(...args: unknown[]): void;
|
|
10
|
+
/** Logs an informational message. */
|
|
11
|
+
info(...args: unknown[]): void;
|
|
12
|
+
/** Logs a warning message. */
|
|
13
|
+
warn(...args: unknown[]): void;
|
|
14
|
+
/** Logs a debug-level message (may be suppressed in production). */
|
|
15
|
+
debug(...args: unknown[]): void;
|
|
16
|
+
/** Logs an error message. */
|
|
17
|
+
error(...args: unknown[]): void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Dialog interface for interactive prompts.
|
|
21
|
+
* Callers provide their own implementation (e.g., using `prompts`, `inquirer`, or a custom UI).
|
|
22
|
+
*/
|
|
23
|
+
interface AutoConfigDialogs {
|
|
24
|
+
/**
|
|
25
|
+
* Asks a yes/no confirmation question.
|
|
26
|
+
*
|
|
27
|
+
* @param text - The question to display
|
|
28
|
+
* @param options - Optional defaults and fallback behavior
|
|
29
|
+
* @returns `true` if confirmed, `false` otherwise
|
|
30
|
+
*/
|
|
31
|
+
confirm(text: string, options?: {
|
|
32
|
+
defaultValue?: boolean;
|
|
33
|
+
fallbackValue?: boolean;
|
|
34
|
+
}): Promise<boolean>;
|
|
35
|
+
/**
|
|
36
|
+
* Prompts the user for a text input.
|
|
37
|
+
*
|
|
38
|
+
* @param text - The prompt message
|
|
39
|
+
* @param options - Optional default value and validation function
|
|
40
|
+
* @returns The user-provided string
|
|
41
|
+
*/
|
|
42
|
+
prompt(text: string, options?: {
|
|
43
|
+
defaultValue?: string;
|
|
44
|
+
validate?: (value: string) => boolean | string | Promise<boolean | string>;
|
|
45
|
+
}): Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Presents a selection list to the user.
|
|
48
|
+
*
|
|
49
|
+
* @param text - The prompt message
|
|
50
|
+
* @param options - Available choices and optional default selection
|
|
51
|
+
* @returns The selected value
|
|
52
|
+
*/
|
|
53
|
+
select(text: string, options: {
|
|
54
|
+
choices: Array<{
|
|
55
|
+
title: string;
|
|
56
|
+
value: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
}>;
|
|
59
|
+
defaultOption?: number;
|
|
60
|
+
}): Promise<string>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Context object that provides external dependencies to the autoconfig system.
|
|
64
|
+
*
|
|
65
|
+
* Callers must provide implementations for `logger` and `dialogs`.
|
|
66
|
+
* All other fields are optional and allow callers to customize behavior
|
|
67
|
+
* (e.g., error reporting, command execution, CI detection).
|
|
68
|
+
*/
|
|
69
|
+
interface AutoConfigContext {
|
|
70
|
+
/** Logger used for all autoconfig output. */
|
|
71
|
+
logger: AutoConfigLogger;
|
|
72
|
+
/** Dialogs used for interactive prompts. */
|
|
73
|
+
dialogs: AutoConfigDialogs;
|
|
74
|
+
/**
|
|
75
|
+
* Runs a shell command in the given directory.
|
|
76
|
+
*
|
|
77
|
+
* @param command - The shell command string to execute
|
|
78
|
+
* @param cwd - The working directory for the command
|
|
79
|
+
* @param label - A short label for logging (e.g., "[build]")
|
|
80
|
+
* @returns A promise that resolves when the command completes
|
|
81
|
+
*/
|
|
82
|
+
runCommand: (command: string, cwd: string, label: string) => Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Returns `true` if running in a non-interactive or CI environment.
|
|
85
|
+
* Defaults to `() => false` if not provided.
|
|
86
|
+
*
|
|
87
|
+
* @returns Whether the current environment is non-interactive
|
|
88
|
+
*/
|
|
89
|
+
isNonInteractiveOrCI?: () => boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Returns a cache folder path used for detecting cached project state,
|
|
92
|
+
* or `undefined` if not available.
|
|
93
|
+
*
|
|
94
|
+
* @returns The cache folder path, or `undefined`
|
|
95
|
+
*/
|
|
96
|
+
getCacheFolder?: () => string | undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Checks whether a framework is supported by autoconfig.
|
|
101
|
+
*
|
|
102
|
+
* @param frameworkId The target framework's id
|
|
103
|
+
* @returns a boolean indicating wether the framework is supported
|
|
104
|
+
*/
|
|
105
|
+
declare function isFrameworkSupported(frameworkId: FrameworkInfo["id"]): boolean;
|
|
106
|
+
type FrameworkInfo = {
|
|
107
|
+
id: string;
|
|
108
|
+
name: string;
|
|
109
|
+
} & ({
|
|
110
|
+
supported: false;
|
|
111
|
+
} | {
|
|
112
|
+
supported: true;
|
|
113
|
+
class: typeof Framework;
|
|
114
|
+
frameworkPackageInfo: AutoConfigFrameworkPackageInfo;
|
|
115
|
+
});
|
|
116
|
+
/**
|
|
117
|
+
* AutoConfig information for a package that defines a framework.
|
|
118
|
+
*/
|
|
119
|
+
type AutoConfigFrameworkPackageInfo = {
|
|
120
|
+
/** The package name (e.g. "astro" for the Astro framework and "@solidjs/start" for the SolidStart framework) */
|
|
121
|
+
name: string;
|
|
122
|
+
/** The minimum version (if any) of the package/framework that autoconfig supports */
|
|
123
|
+
minimumVersion: string;
|
|
124
|
+
/** The latest major version of the package/framework that autoconfig supports */
|
|
125
|
+
maximumKnownMajorVersion: string;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
declare abstract class Framework {
|
|
129
|
+
#private;
|
|
130
|
+
readonly id: FrameworkInfo["id"];
|
|
131
|
+
readonly name: FrameworkInfo["name"];
|
|
132
|
+
get frameworkVersion(): string;
|
|
133
|
+
constructor(frameworkInfo: Pick<FrameworkInfo, "id" | "name">);
|
|
134
|
+
isConfigured(_projectPath: string): boolean;
|
|
135
|
+
abstract configure(options: ConfigurationOptions): Promise<ConfigurationResults> | ConfigurationResults;
|
|
136
|
+
configurationDescription?: string;
|
|
137
|
+
/**
|
|
138
|
+
* Validates the installed framework version against the supported range and
|
|
139
|
+
* stores it for later access via the `frameworkVersion` getter.
|
|
140
|
+
* Warns via the context logger if the version exceeds `maximumKnownMajorVersion`.
|
|
141
|
+
*
|
|
142
|
+
* @param projectPath - Path to the project root used to resolve the installed version.
|
|
143
|
+
* @param frameworkPackageInfo - Package metadata including name and version bounds.
|
|
144
|
+
* @param context - The autoconfig context providing logger and other dependencies.
|
|
145
|
+
* @throws {AssertionError} If the installed version cannot be determined.
|
|
146
|
+
* @throws {AutoConfigFrameworkConfigurationError} If the version is below `minimumVersion`.
|
|
147
|
+
*/
|
|
148
|
+
validateFrameworkVersion(projectPath: string, frameworkPackageInfo: AutoConfigFrameworkPackageInfo, context: AutoConfigContext): void;
|
|
149
|
+
}
|
|
150
|
+
type ConfigurationOptions = {
|
|
151
|
+
outputDir: string;
|
|
152
|
+
projectPath: string;
|
|
153
|
+
workerName: string;
|
|
154
|
+
dryRun: boolean;
|
|
155
|
+
packageManager: PackageManager;
|
|
156
|
+
isWorkspaceRoot: boolean;
|
|
157
|
+
context: AutoConfigContext;
|
|
158
|
+
};
|
|
159
|
+
type PackageJsonScriptsOverrides = {
|
|
160
|
+
preview?: string;
|
|
161
|
+
deploy?: string;
|
|
162
|
+
typegen?: string;
|
|
163
|
+
};
|
|
164
|
+
type ConfigurationResults = {
|
|
165
|
+
/** 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) */
|
|
166
|
+
wranglerConfig: RawConfig | null;
|
|
167
|
+
packageJsonScriptsOverrides?: PackageJsonScriptsOverrides;
|
|
168
|
+
buildCommandOverride?: string;
|
|
169
|
+
deployCommandOverride?: string;
|
|
170
|
+
versionCommandOverride?: string;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/** Makes the specified keys of T optional. */
|
|
174
|
+
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
175
|
+
type AutoConfigDetailsBase = {
|
|
176
|
+
/** The name of the worker */
|
|
177
|
+
workerName: string;
|
|
178
|
+
/** The path to the project (defaults to cwd) */
|
|
179
|
+
projectPath: string;
|
|
180
|
+
/** The content of the project's package.json file (if any) */
|
|
181
|
+
packageJson?: PackageJSON;
|
|
182
|
+
/** Whether the project is already configured (no autoconfig required) */
|
|
183
|
+
configured: boolean;
|
|
184
|
+
/** Details about the detected framework. It can be a JS framework or 'Static' if no actual JS framework is used. */
|
|
185
|
+
framework: Framework;
|
|
186
|
+
/** The build command used to build the project (if any) */
|
|
187
|
+
buildCommand?: string;
|
|
188
|
+
/** The output directory (if no framework is used, points to the raw asset files) */
|
|
189
|
+
outputDir: string;
|
|
190
|
+
/** The detected package manager for the project */
|
|
191
|
+
packageManager: PackageManager;
|
|
192
|
+
/** Whether the current path is at the root of a workspace */
|
|
193
|
+
isWorkspaceRoot?: boolean;
|
|
194
|
+
};
|
|
195
|
+
type AutoConfigDetailsForConfiguredProject = Optional<AutoConfigDetailsBase, "framework" | "outputDir"> & {
|
|
196
|
+
configured: true;
|
|
197
|
+
};
|
|
198
|
+
type AutoConfigDetailsForNonConfiguredProject = AutoConfigDetailsBase & {
|
|
199
|
+
configured: false;
|
|
200
|
+
};
|
|
201
|
+
type AutoConfigDetails = AutoConfigDetailsForConfiguredProject | AutoConfigDetailsForNonConfiguredProject;
|
|
202
|
+
type AutoConfigOptions = {
|
|
203
|
+
/** The autoconfig context providing logger, dialogs, and other dependencies. */
|
|
204
|
+
context: AutoConfigContext;
|
|
205
|
+
/** Whether to run autoconfig without actually applying any filesystem modification (default: false) */
|
|
206
|
+
dryRun?: boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Whether the build command should be run (default: true)
|
|
209
|
+
*
|
|
210
|
+
* Note: When `dryRun` is `true` the build command is never run.
|
|
211
|
+
*/
|
|
212
|
+
runBuild?: boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Whether the confirmation prompts should be skipped (default: false)
|
|
215
|
+
*
|
|
216
|
+
* Note: When `dryRun` is `true` the the confirmation prompts are always skipped.
|
|
217
|
+
*/
|
|
218
|
+
skipConfirmations?: boolean;
|
|
219
|
+
/**
|
|
220
|
+
* Whether to install Wrangler during autoconfig
|
|
221
|
+
*/
|
|
222
|
+
enableWranglerInstallation?: boolean;
|
|
223
|
+
};
|
|
224
|
+
type AutoConfigSummary = {
|
|
225
|
+
scripts: Record<string, string>;
|
|
226
|
+
wranglerInstall: boolean;
|
|
227
|
+
wranglerConfig?: RawConfig;
|
|
228
|
+
frameworkConfiguration?: string;
|
|
229
|
+
outputDir: string;
|
|
230
|
+
frameworkId?: string;
|
|
231
|
+
buildCommand?: string;
|
|
232
|
+
deployCommand?: string;
|
|
233
|
+
versionCommand?: string;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Detects project details needed for autoconfig: framework, package manager,
|
|
238
|
+
* output directory, worker name, and whether the project is already configured.
|
|
239
|
+
*
|
|
240
|
+
* @param options - Detection options including project path, wrangler config, and context.
|
|
241
|
+
* @returns The detected project details.
|
|
242
|
+
*/
|
|
243
|
+
declare function getDetailsForAutoConfig({ projectPath, wranglerConfig, context, }: {
|
|
244
|
+
/** The path to the project, defaults to cwd. */
|
|
245
|
+
projectPath?: string;
|
|
246
|
+
/** The parsed wrangler configuration for the project (if any). */
|
|
247
|
+
wranglerConfig?: Config;
|
|
248
|
+
/** The autoconfig context providing logger, dialogs, and other dependencies. */
|
|
249
|
+
context: AutoConfigContext;
|
|
250
|
+
}): Promise<AutoConfigDetails>;
|
|
251
|
+
/**
|
|
252
|
+
* Displays the detected autoconfig details to the user via the context logger.
|
|
253
|
+
*
|
|
254
|
+
* @param autoConfigDetails - The detected project details to display.
|
|
255
|
+
* @param context - The autoconfig context providing the logger.
|
|
256
|
+
* @param displayOptions - Optional display customization.
|
|
257
|
+
*/
|
|
258
|
+
declare function displayAutoConfigDetails(autoConfigDetails: AutoConfigDetails, context: AutoConfigContext, displayOptions?: {
|
|
259
|
+
heading?: string;
|
|
260
|
+
}): void;
|
|
261
|
+
/**
|
|
262
|
+
* Prompts the user to confirm or modify the detected autoconfig details.
|
|
263
|
+
*
|
|
264
|
+
* @param autoConfigDetails - The detected project details.
|
|
265
|
+
* @param context - The autoconfig context providing dialogs.
|
|
266
|
+
* @returns The (possibly updated) autoconfig details.
|
|
267
|
+
*/
|
|
268
|
+
declare function confirmAutoConfigDetails(autoConfigDetails: AutoConfigDetails, context: AutoConfigContext): Promise<AutoConfigDetails>;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Runs the full autoconfig flow: displays detected settings, confirms with the user,
|
|
272
|
+
* validates the framework version, runs framework configuration, writes wrangler config,
|
|
273
|
+
* updates package.json scripts, and optionally runs the build command.
|
|
274
|
+
*
|
|
275
|
+
* @param autoConfigDetails - The detected project details from `getDetailsForAutoConfig()`.
|
|
276
|
+
* @param autoConfigOptions - Options controlling dry-run, confirmations, build, and context.
|
|
277
|
+
* @returns A summary of all operations performed.
|
|
278
|
+
*/
|
|
279
|
+
declare function runAutoConfig(autoConfigDetails: AutoConfigDetails, autoConfigOptions: AutoConfigOptions): Promise<AutoConfigSummary>;
|
|
280
|
+
/**
|
|
281
|
+
* Builds a summary of all operations that autoconfig will (or did) perform,
|
|
282
|
+
* including package installation, package.json script updates, wrangler config
|
|
283
|
+
* creation, and framework-specific configuration.
|
|
284
|
+
*
|
|
285
|
+
* @param autoConfigDetails - The detected project details.
|
|
286
|
+
* @param wranglerConfigToWrite - The wrangler config object to write, or `null` if not applicable.
|
|
287
|
+
* @param projectCommands - The build, deploy, and version commands for the project.
|
|
288
|
+
* @param context - The autoconfig context providing logger and other dependencies.
|
|
289
|
+
* @param packageJsonScriptsOverrides - Optional overrides for package.json script entries.
|
|
290
|
+
* @returns A summary object describing all planned operations.
|
|
291
|
+
*/
|
|
292
|
+
declare function buildOperationsSummary(autoConfigDetails: AutoConfigDetailsForNonConfiguredProject & {
|
|
293
|
+
outputDir: NonNullable<AutoConfigDetails["outputDir"]>;
|
|
294
|
+
}, wranglerConfigToWrite: RawConfig | null, projectCommands: {
|
|
295
|
+
build?: string;
|
|
296
|
+
deploy: string;
|
|
297
|
+
version?: string;
|
|
298
|
+
}, context: AutoConfigContext, packageJsonScriptsOverrides?: PackageJsonScriptsOverrides): Promise<AutoConfigSummary>;
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Base class for errors where something in a autoconfig frameworks' configuration goes
|
|
302
|
+
* something wrong. These are not reported to Sentry.
|
|
303
|
+
*/
|
|
304
|
+
declare class AutoConfigFrameworkConfigurationError extends UserError {
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Error thrown when autoconfig detection fails.
|
|
308
|
+
* Carries detection metadata (`frameworkId`, `configured`) so that callers can
|
|
309
|
+
* extract it for telemetry without the autoconfig library needing to know about
|
|
310
|
+
* the telemetry system.
|
|
311
|
+
*/
|
|
312
|
+
declare class AutoConfigDetectionError extends FatalError {
|
|
313
|
+
/** The detected framework identifier (if detection got far enough to determine it). */
|
|
314
|
+
readonly frameworkId: string | undefined;
|
|
315
|
+
/** Whether the project was already configured at the time of the error. */
|
|
316
|
+
readonly configured: boolean;
|
|
317
|
+
/**
|
|
318
|
+
* @param message - The human-readable error message.
|
|
319
|
+
* @param options - Error options including telemetry message, optional code, and detection metadata.
|
|
320
|
+
*/
|
|
321
|
+
constructor(message: string, options: TelemetryMessage & {
|
|
322
|
+
code?: number;
|
|
323
|
+
frameworkId?: string;
|
|
324
|
+
configured: boolean;
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Gets the exact version of a package installed by a project (or undefined if the package is not installed)
|
|
330
|
+
|
|
331
|
+
* @param packageName the name of the target package
|
|
332
|
+
* @param projectPath the path of the project to check
|
|
333
|
+
* @param opts.stopAtProjectPath flag indicating whether the function should stop looking for the package at the project's path
|
|
334
|
+
* @returns the version of the package if the package is installed, undefined otherwise
|
|
335
|
+
*/
|
|
336
|
+
declare function getInstalledPackageVersion(packageName: string, projectPath: string, opts?: {
|
|
337
|
+
stopAtProjectPath?: boolean;
|
|
338
|
+
}): string | undefined;
|
|
339
|
+
|
|
340
|
+
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, getInstalledPackageVersion, isFrameworkSupported, runAutoConfig };
|