wrangler 0.0.21 → 0.0.24
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/README.md +1 -1
- package/bin/wrangler.js +10 -1
- package/miniflare-dist/index.mjs +79 -0
- package/miniflare-dist/index.mjs.map +7 -0
- package/package.json +3 -4
- package/src/__tests__/configuration.test.ts +522 -300
- package/src/__tests__/dev.test.tsx +99 -3
- package/src/__tests__/guess-worker-format.test.ts +10 -0
- package/src/__tests__/index.test.ts +3 -11
- package/src/__tests__/kv.test.ts +16 -18
- package/src/__tests__/pages.test.ts +48 -10
- package/src/__tests__/publish.test.ts +1319 -421
- package/src/__tests__/r2.test.ts +4 -4
- package/src/__tests__/tail.test.ts +29 -4
- package/src/bundle.ts +15 -2
- package/src/config/README.md +6 -6
- package/src/config/config.ts +16 -77
- package/src/config/environment.ts +67 -1
- package/src/config/index.ts +13 -3
- package/src/config/validation-helpers.ts +105 -19
- package/src/config/validation.ts +272 -97
- package/src/dev/dev.tsx +72 -42
- package/src/dev/local.tsx +103 -118
- package/src/dev/use-esbuild.ts +4 -0
- package/src/entry.ts +84 -3
- package/src/index.tsx +137 -113
- package/src/intl-polyfill.d.ts +139 -0
- package/src/kv.ts +7 -27
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +37 -0
- package/src/module-collection.ts +58 -53
- package/src/pages.tsx +26 -10
- package/src/publish.ts +17 -21
- package/src/sites.tsx +59 -52
- package/src/tail/printing.ts +2 -2
- package/src/user.tsx +12 -3
- package/wrangler-dist/cli.js +836 -649
- package/wrangler-dist/cli.js.map +2 -2
- package/src/__tests__/dev2.test.tsx +0 -154
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TODO Remove once https://github.com/microsoft/TypeScript/pull/47254 lands
|
|
3
|
+
*/
|
|
4
|
+
declare namespace Intl {
|
|
5
|
+
interface DateTimeFormatOptions {
|
|
6
|
+
formatMatcher?: "basic" | "best fit" | "best fit" | undefined;
|
|
7
|
+
dateStyle?: "full" | "long" | "medium" | "short" | undefined;
|
|
8
|
+
timeStyle?: "full" | "long" | "medium" | "short" | undefined;
|
|
9
|
+
dayPeriod?: "narrow" | "short" | "long" | undefined;
|
|
10
|
+
fractionalSecondDigits?: 0 | 1 | 2 | 3 | undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface ResolvedDateTimeFormatOptions {
|
|
14
|
+
formatMatcher?: "basic" | "best fit" | "best fit";
|
|
15
|
+
dateStyle?: "full" | "long" | "medium" | "short";
|
|
16
|
+
timeStyle?: "full" | "long" | "medium" | "short";
|
|
17
|
+
hourCycle?: "h11" | "h12" | "h23" | "h24";
|
|
18
|
+
dayPeriod?: "narrow" | "short" | "long";
|
|
19
|
+
fractionalSecondDigits?: 0 | 1 | 2 | 3;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface NumberFormat {
|
|
23
|
+
formatRange(startDate: number | bigint, endDate: number | bigint): string;
|
|
24
|
+
formatRangeToParts(
|
|
25
|
+
startDate: number | bigint,
|
|
26
|
+
endDate: number | bigint
|
|
27
|
+
): NumberFormatPart[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The locale matching algorithm to use.
|
|
32
|
+
*
|
|
33
|
+
* [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation).
|
|
34
|
+
*/
|
|
35
|
+
type ListFormatLocaleMatcher = "lookup" | "best fit";
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The format of output message.
|
|
39
|
+
*
|
|
40
|
+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#parameters).
|
|
41
|
+
*/
|
|
42
|
+
type ListFormatType = "conjunction" | "disjunction" | "unit";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The length of the formatted message.
|
|
46
|
+
*
|
|
47
|
+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#parameters).
|
|
48
|
+
*/
|
|
49
|
+
type ListFormatStyle = "long" | "short" | "narrow";
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* An object with some or all properties of the `Intl.ListFormat` constructor `options` parameter.
|
|
53
|
+
*
|
|
54
|
+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#parameters).
|
|
55
|
+
*/
|
|
56
|
+
interface ListFormatOptions {
|
|
57
|
+
/** The locale matching algorithm to use. For information about this option, see [Intl page](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation). */
|
|
58
|
+
localeMatcher?: ListFormatLocaleMatcher;
|
|
59
|
+
/** The format of output message. */
|
|
60
|
+
type?: ListFormatType;
|
|
61
|
+
/** The length of the internationalized message. */
|
|
62
|
+
style?: ListFormatStyle;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface ListFormat {
|
|
66
|
+
/**
|
|
67
|
+
* Returns a string with a language-specific representation of the list.
|
|
68
|
+
*
|
|
69
|
+
* @param list - An iterable object, such as an [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).
|
|
70
|
+
*
|
|
71
|
+
* @throws `TypeError` if `list` includes something other than the possible values.
|
|
72
|
+
*
|
|
73
|
+
* @returns {string} A language-specific formatted string representing the elements of the list.
|
|
74
|
+
*
|
|
75
|
+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format).
|
|
76
|
+
*/
|
|
77
|
+
format(list: Iterable<string>): string;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Returns an Array of objects representing the different components that can be used to format a list of values in a locale-aware fashion.
|
|
81
|
+
*
|
|
82
|
+
* @param list - An iterable object, such as an [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array), to be formatted according to a locale.
|
|
83
|
+
*
|
|
84
|
+
* @throws `TypeError` if `list` includes something other than the possible values.
|
|
85
|
+
*
|
|
86
|
+
* @returns {{ type: "element" | "literal", value: string; }[]} An Array of components which contains the formatted parts from the list.
|
|
87
|
+
*
|
|
88
|
+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts).
|
|
89
|
+
*/
|
|
90
|
+
formatToParts(
|
|
91
|
+
list: Iterable<string>
|
|
92
|
+
): { type: "element" | "literal"; value: string }[];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const ListFormat: {
|
|
96
|
+
prototype: ListFormat;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Creates [Intl.ListFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat) objects that
|
|
100
|
+
* enable language-sensitive list formatting.
|
|
101
|
+
*
|
|
102
|
+
* @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
|
|
103
|
+
* For the general form and interpretation of the `locales` argument,
|
|
104
|
+
* see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
|
|
105
|
+
*
|
|
106
|
+
* @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#parameters)
|
|
107
|
+
* with some or all options of `ListFormatOptions`.
|
|
108
|
+
*
|
|
109
|
+
* @returns [Intl.ListFormatOptions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat) object.
|
|
110
|
+
*
|
|
111
|
+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat).
|
|
112
|
+
*/
|
|
113
|
+
new (
|
|
114
|
+
locales?: BCP47LanguageTag | BCP47LanguageTag[],
|
|
115
|
+
options?: ListFormatOptions
|
|
116
|
+
): ListFormat;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Returns an array containing those of the provided locales that are
|
|
120
|
+
* supported in list formatting without having to fall back to the runtime's default locale.
|
|
121
|
+
*
|
|
122
|
+
* @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
|
|
123
|
+
* For the general form and interpretation of the `locales` argument,
|
|
124
|
+
* see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
|
|
125
|
+
*
|
|
126
|
+
* @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf#parameters).
|
|
127
|
+
* with some or all possible options.
|
|
128
|
+
*
|
|
129
|
+
* @returns An array of strings representing a subset of the given locale tags that are supported in list
|
|
130
|
+
* formatting without having to fall back to the runtime's default locale.
|
|
131
|
+
*
|
|
132
|
+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf).
|
|
133
|
+
*/
|
|
134
|
+
supportedLocalesOf(
|
|
135
|
+
locales: BCP47LanguageTag | BCP47LanguageTag[],
|
|
136
|
+
options?: Pick<ListFormatOptions, "localeMatcher">
|
|
137
|
+
): BCP47LanguageTag[];
|
|
138
|
+
};
|
|
139
|
+
}
|
package/src/kv.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { URLSearchParams } from "node:url";
|
|
2
2
|
import { fetchListResult, fetchResult, fetchKVGetValue } from "./cfetch";
|
|
3
|
-
import type { Config
|
|
3
|
+
import type { Config } from "./config";
|
|
4
4
|
|
|
5
5
|
/** The largest number of kv items we can pass to the API in a single request. */
|
|
6
6
|
const API_MAX = 10000;
|
|
@@ -11,7 +11,6 @@ const BATCH_KEY_MAX = API_MAX / 2;
|
|
|
11
11
|
type KvArgs = {
|
|
12
12
|
binding?: string;
|
|
13
13
|
"namespace-id"?: string;
|
|
14
|
-
env?: string;
|
|
15
14
|
preview?: boolean;
|
|
16
15
|
};
|
|
17
16
|
|
|
@@ -217,8 +216,8 @@ export async function deleteBulkKeyValue(
|
|
|
217
216
|
}
|
|
218
217
|
|
|
219
218
|
export function getNamespaceId(
|
|
220
|
-
{ preview, binding, "namespace-id": namespaceId
|
|
221
|
-
|
|
219
|
+
{ preview, binding, "namespace-id": namespaceId }: KvArgs,
|
|
220
|
+
config: Config
|
|
222
221
|
): string {
|
|
223
222
|
// nice
|
|
224
223
|
if (namespaceId) {
|
|
@@ -228,45 +227,26 @@ export function getNamespaceId(
|
|
|
228
227
|
// begin pre-flight checks
|
|
229
228
|
|
|
230
229
|
// `--binding` is only valid if there's a wrangler configuration.
|
|
231
|
-
if (binding && !
|
|
230
|
+
if (binding && !config) {
|
|
232
231
|
throw new Error("--binding specified, but no config file was found.");
|
|
233
232
|
}
|
|
234
233
|
|
|
235
234
|
// there's no config. abort here
|
|
236
|
-
if (!
|
|
235
|
+
if (!config) {
|
|
237
236
|
throw new Error(
|
|
238
237
|
"Failed to find a config file.\n" +
|
|
239
238
|
"Either use --namespace-id to upload directly or create a configuration file with a binding."
|
|
240
239
|
);
|
|
241
240
|
}
|
|
242
241
|
|
|
243
|
-
// they want to use an environment, actually
|
|
244
|
-
if (env) {
|
|
245
|
-
if (!("env" in configOrEnv) || !configOrEnv.env[env]) {
|
|
246
|
-
throw new Error(
|
|
247
|
-
`Failed to find environment "${env}" in configuration file!`
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
return getNamespaceId(
|
|
251
|
-
{
|
|
252
|
-
binding,
|
|
253
|
-
"namespace-id": namespaceId,
|
|
254
|
-
preview,
|
|
255
|
-
},
|
|
256
|
-
configOrEnv.env[env]
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
242
|
// there's no KV namespaces
|
|
261
|
-
if (!
|
|
243
|
+
if (!config.kv_namespaces || config.kv_namespaces.length === 0) {
|
|
262
244
|
throw new Error(
|
|
263
245
|
"No KV Namespaces configured! Either use --namespace-id to upload directly or add a KV namespace to your wrangler config file."
|
|
264
246
|
);
|
|
265
247
|
}
|
|
266
248
|
|
|
267
|
-
const namespace =
|
|
268
|
-
(ns) => ns.binding === binding
|
|
269
|
-
);
|
|
249
|
+
const namespace = config.kv_namespaces.find((ns) => ns.binding === binding);
|
|
270
250
|
|
|
271
251
|
// we couldn't find a namespace with that binding
|
|
272
252
|
if (!namespace) {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Custom Miniflare CLI
|
|
2
|
+
|
|
3
|
+
This directory contains a simple wrapper around the programmatic Miniflare API,
|
|
4
|
+
which Wrangler spawns when running `wrangler dev` in local mode.
|
|
5
|
+
|
|
6
|
+
## Building
|
|
7
|
+
|
|
8
|
+
This CLI is built at the same time as Wrangler by running
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npm run -w wrangler build
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The output of the build is `miniflare-dist/index.mjs`.
|
|
15
|
+
|
|
16
|
+
## Running
|
|
17
|
+
|
|
18
|
+
The CLI expects a single command line argument which is the Miniflare options formatted as a string of JSON.
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
node --no-warnings ./packages/wrangler/miniflare-dist/index.mjs '{"watch": true, "script": ""}' --log VERBOSE
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The `--log` argument is optional and takes one of Miniflare's LogLevels: "NONE", "ERROR", "WARN", "INFO", "DEBUG", "VERBOSE".
|
|
25
|
+
It defaults to `INFO`.
|
|
26
|
+
|
|
27
|
+
## Debugging
|
|
28
|
+
|
|
29
|
+
Simply place a breakpoint in the code and run the above command in the VS Code "JavaScript Debug Terminal".
|
|
30
|
+
The code will stop at the breakpoint as expected.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type EnumKeys<Enum> = Exclude<keyof Enum, number>;
|
|
2
|
+
|
|
3
|
+
export const enumObject = <Enum extends Record<string, number | string>>(
|
|
4
|
+
e: Enum
|
|
5
|
+
) => {
|
|
6
|
+
const copy = { ...e } as { [K in EnumKeys<Enum>]: Enum[K] };
|
|
7
|
+
Object.values(e).forEach(
|
|
8
|
+
(value) => typeof value === "number" && delete copy[value]
|
|
9
|
+
);
|
|
10
|
+
return copy;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const enumKeys = <Enum extends Record<string, number | string>>(
|
|
14
|
+
e: Enum
|
|
15
|
+
) => {
|
|
16
|
+
return Object.keys(enumObject(e)) as EnumKeys<Enum>[];
|
|
17
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Log, LogLevel, Miniflare } from "miniflare";
|
|
2
|
+
import yargs from "yargs";
|
|
3
|
+
import { hideBin } from "yargs/helpers";
|
|
4
|
+
import { enumKeys } from "./enum-keys";
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
const args = await yargs(hideBin(process.argv))
|
|
8
|
+
.help(false)
|
|
9
|
+
.version(false)
|
|
10
|
+
.option("log", {
|
|
11
|
+
choices: enumKeys(LogLevel),
|
|
12
|
+
}).argv;
|
|
13
|
+
|
|
14
|
+
const logLevel = LogLevel[args.log ?? "INFO"];
|
|
15
|
+
const config = {
|
|
16
|
+
...JSON.parse((args._[0] as string) ?? "{}"),
|
|
17
|
+
log: new Log(logLevel),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
if (logLevel > LogLevel.INFO) {
|
|
21
|
+
console.log("OPTIONS:\n", JSON.stringify(config, null, 2));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const mf = new Miniflare(config);
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
// Start Miniflare development server
|
|
28
|
+
await mf.startServer();
|
|
29
|
+
} catch (e) {
|
|
30
|
+
mf.log.error(e as Error);
|
|
31
|
+
process.exitCode = 1;
|
|
32
|
+
// Unmount any mounted workers
|
|
33
|
+
await mf.dispose();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
await main();
|
package/src/module-collection.ts
CHANGED
|
@@ -117,62 +117,67 @@ export default function createModuleCollector(props: {
|
|
|
117
117
|
});
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
120
|
+
if (props.wrangler1xlegacyModuleReferences.fileNames.size > 0) {
|
|
121
|
+
build.onResolve(
|
|
122
|
+
{
|
|
123
|
+
filter: new RegExp(
|
|
124
|
+
"^(" +
|
|
125
|
+
[...props.wrangler1xlegacyModuleReferences.fileNames].join(
|
|
126
|
+
"|"
|
|
127
|
+
) +
|
|
128
|
+
")$"
|
|
129
|
+
),
|
|
130
|
+
},
|
|
131
|
+
async (args: esbuild.OnResolveArgs) => {
|
|
132
|
+
if (
|
|
133
|
+
args.kind !== "import-statement" &&
|
|
134
|
+
args.kind !== "require-call"
|
|
135
|
+
) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
// In the future, this will simply throw an error
|
|
139
|
+
console.warn(
|
|
140
|
+
`Deprecation warning: detected a legacy module import in "./${path.relative(
|
|
141
|
+
process.cwd(),
|
|
142
|
+
args.importer
|
|
143
|
+
)}". This will stop working in the future. Replace references to "${
|
|
144
|
+
args.path
|
|
145
|
+
}" with "./${args.path}";`
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
// take the file and massage it to a
|
|
149
|
+
// transportable/manageable format
|
|
150
|
+
const filePath = path.join(
|
|
151
|
+
props.wrangler1xlegacyModuleReferences.rootDirectory,
|
|
141
152
|
args.path
|
|
142
|
-
|
|
143
|
-
|
|
153
|
+
);
|
|
154
|
+
const fileContent = await readFile(filePath);
|
|
155
|
+
const fileHash = crypto
|
|
156
|
+
.createHash("sha1")
|
|
157
|
+
.update(fileContent)
|
|
158
|
+
.digest("hex");
|
|
159
|
+
const fileName = `./${fileHash}-${path.basename(args.path)}`;
|
|
144
160
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
// add the module to the array
|
|
162
|
-
modules.push({
|
|
163
|
-
name: fileName,
|
|
164
|
-
content: fileContent,
|
|
165
|
-
type: RuleTypeToModuleType[rule.type],
|
|
166
|
-
});
|
|
167
|
-
return {
|
|
168
|
-
path: fileName, // change the reference to the changed module
|
|
169
|
-
external: props.format === "modules", // mark it as external in the bundle
|
|
170
|
-
namespace: `wrangler-module-${rule.type}`, // just a tag, this isn't strictly necessary
|
|
171
|
-
watchFiles: [filePath], // we also add the file to esbuild's watch list
|
|
172
|
-
};
|
|
161
|
+
const { rule } =
|
|
162
|
+
rulesMatchers.find(({ regex }) => regex.test(fileName)) || {};
|
|
163
|
+
if (rule) {
|
|
164
|
+
// add the module to the array
|
|
165
|
+
modules.push({
|
|
166
|
+
name: fileName,
|
|
167
|
+
content: fileContent,
|
|
168
|
+
type: RuleTypeToModuleType[rule.type],
|
|
169
|
+
});
|
|
170
|
+
return {
|
|
171
|
+
path: fileName, // change the reference to the changed module
|
|
172
|
+
external: props.format === "modules", // mark it as external in the bundle
|
|
173
|
+
namespace: `wrangler-module-${rule.type}`, // just a tag, this isn't strictly necessary
|
|
174
|
+
watchFiles: [filePath], // we also add the file to esbuild's watch list
|
|
175
|
+
};
|
|
176
|
+
}
|
|
173
177
|
}
|
|
174
|
-
|
|
175
|
-
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
176
181
|
// ~ end legacy module specifier support ~
|
|
177
182
|
|
|
178
183
|
rules?.forEach((rule) => {
|
package/src/pages.tsx
CHANGED
|
@@ -22,11 +22,15 @@ import type { BuilderCallback } from "yargs";
|
|
|
22
22
|
// and also modifies some `stream/web` and `undici` prototypes, so we
|
|
23
23
|
// don't want to do this if pages commands aren't being called.
|
|
24
24
|
|
|
25
|
+
export const pagesBetaWarning =
|
|
26
|
+
"🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose";
|
|
27
|
+
|
|
25
28
|
const EXIT_CALLBACKS: (() => void)[] = [];
|
|
26
29
|
const EXIT = (message?: string, code?: number) => {
|
|
27
30
|
if (message) console.log(message);
|
|
28
31
|
if (code) process.exitCode = code;
|
|
29
32
|
EXIT_CALLBACKS.forEach((callback) => callback());
|
|
33
|
+
RUNNING_BUILDERS.forEach((builder) => builder.stop?.());
|
|
30
34
|
process.exit(code);
|
|
31
35
|
};
|
|
32
36
|
|
|
@@ -759,7 +763,8 @@ export const pages: BuilderCallback<unknown, unknown> = (yargs) => {
|
|
|
759
763
|
description: "Auto reload HTML pages when change is detected",
|
|
760
764
|
},
|
|
761
765
|
// TODO: Miniflare user options
|
|
762
|
-
})
|
|
766
|
+
})
|
|
767
|
+
.epilogue(pagesBetaWarning);
|
|
763
768
|
},
|
|
764
769
|
async ({
|
|
765
770
|
local,
|
|
@@ -773,6 +778,9 @@ export const pages: BuilderCallback<unknown, unknown> = (yargs) => {
|
|
|
773
778
|
"live-reload": liveReload,
|
|
774
779
|
_: [_pages, _dev, ...remaining],
|
|
775
780
|
}) => {
|
|
781
|
+
// Beta message for `wrangler pages <commands>` usage
|
|
782
|
+
console.log(pagesBetaWarning);
|
|
783
|
+
|
|
776
784
|
if (!local) {
|
|
777
785
|
console.error("Only local mode is supported at the moment.");
|
|
778
786
|
return;
|
|
@@ -805,13 +813,15 @@ export const pages: BuilderCallback<unknown, unknown> = (yargs) => {
|
|
|
805
813
|
|
|
806
814
|
console.log(`Compiling worker to "${scriptPath}"...`);
|
|
807
815
|
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
816
|
+
try {
|
|
817
|
+
await buildFunctions({
|
|
818
|
+
scriptPath,
|
|
819
|
+
functionsDirectory,
|
|
820
|
+
sourcemap: true,
|
|
821
|
+
watch: true,
|
|
822
|
+
onEnd: () => scriptReadyResolve(),
|
|
823
|
+
});
|
|
824
|
+
} catch {}
|
|
815
825
|
|
|
816
826
|
watch([functionsDirectory], {
|
|
817
827
|
persistent: true,
|
|
@@ -895,7 +905,9 @@ export const pages: BuilderCallback<unknown, unknown> = (yargs) => {
|
|
|
895
905
|
// User bindings
|
|
896
906
|
bindings: {
|
|
897
907
|
...Object.fromEntries(
|
|
898
|
-
bindings
|
|
908
|
+
bindings
|
|
909
|
+
.map((binding) => binding.toString().split("="))
|
|
910
|
+
.map(([key, ...values]) => [key, values.join("=")])
|
|
899
911
|
),
|
|
900
912
|
},
|
|
901
913
|
|
|
@@ -1014,7 +1026,8 @@ export const pages: BuilderCallback<unknown, unknown> = (yargs) => {
|
|
|
1014
1026
|
description:
|
|
1015
1027
|
"Watch for changes to the functions and automatically rebuild the Worker script",
|
|
1016
1028
|
},
|
|
1017
|
-
})
|
|
1029
|
+
})
|
|
1030
|
+
.epilogue(pagesBetaWarning),
|
|
1018
1031
|
async ({
|
|
1019
1032
|
directory,
|
|
1020
1033
|
"script-path": scriptPath,
|
|
@@ -1024,6 +1037,9 @@ export const pages: BuilderCallback<unknown, unknown> = (yargs) => {
|
|
|
1024
1037
|
fallbackService,
|
|
1025
1038
|
watch,
|
|
1026
1039
|
}) => {
|
|
1040
|
+
// Beta message for `wrangler pages <commands>` usage
|
|
1041
|
+
console.log(pagesBetaWarning);
|
|
1042
|
+
|
|
1027
1043
|
await buildFunctions({
|
|
1028
1044
|
scriptPath,
|
|
1029
1045
|
outputConfigPath,
|
package/src/publish.ts
CHANGED
|
@@ -27,6 +27,7 @@ type Props = {
|
|
|
27
27
|
legacyEnv: boolean | undefined;
|
|
28
28
|
jsxFactory: undefined | string;
|
|
29
29
|
jsxFragment: undefined | string;
|
|
30
|
+
tsconfig: undefined | string;
|
|
30
31
|
experimentalPublic: boolean;
|
|
31
32
|
};
|
|
32
33
|
|
|
@@ -38,25 +39,20 @@ export default async function publish(props: Props): Promise<void> {
|
|
|
38
39
|
// TODO: warn if git/hg has uncommitted changes
|
|
39
40
|
const { config, accountId } = props;
|
|
40
41
|
|
|
41
|
-
// TODO: should we automatically fallback to top level config if there is no matching environment??
|
|
42
|
-
const envRootObj = (props.env && config.env[props.env]) || config;
|
|
43
|
-
|
|
44
42
|
assert(
|
|
45
|
-
props.compatibilityDate ||
|
|
43
|
+
props.compatibilityDate || config.compatibility_date,
|
|
46
44
|
"A compatibility_date is required when publishing. Add one to your wrangler.toml file, or pass it in your terminal as --compatibility_date. See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information."
|
|
47
45
|
);
|
|
48
46
|
|
|
49
|
-
const triggers = props.triggers ||
|
|
47
|
+
const triggers = props.triggers || config.triggers?.crons;
|
|
50
48
|
const routes =
|
|
51
|
-
props.routes ??
|
|
52
|
-
envRootObj.routes ??
|
|
53
|
-
(envRootObj.route ? [envRootObj.route] : []) ??
|
|
54
|
-
[];
|
|
49
|
+
props.routes ?? config.routes ?? (config.route ? [config.route] : []) ?? [];
|
|
55
50
|
|
|
56
|
-
|
|
51
|
+
// deployToWorkersDev defaults to true only if there aren't any routes defined
|
|
52
|
+
const deployToWorkersDev = config.workers_dev ?? routes.length === 0;
|
|
57
53
|
|
|
58
|
-
const jsxFactory = props.jsxFactory ||
|
|
59
|
-
const jsxFragment = props.jsxFragment ||
|
|
54
|
+
const jsxFactory = props.jsxFactory || config.jsx_factory;
|
|
55
|
+
const jsxFragment = props.jsxFragment || config.jsx_fragment;
|
|
60
56
|
|
|
61
57
|
const scriptName = props.name;
|
|
62
58
|
assert(
|
|
@@ -102,6 +98,7 @@ export default async function publish(props: Props): Promise<void> {
|
|
|
102
98
|
jsxFactory,
|
|
103
99
|
jsxFragment,
|
|
104
100
|
rules: props.rules,
|
|
101
|
+
tsconfig: props.tsconfig ?? config.tsconfig,
|
|
105
102
|
}
|
|
106
103
|
);
|
|
107
104
|
|
|
@@ -160,12 +157,12 @@ export default async function publish(props: Props): Promise<void> {
|
|
|
160
157
|
);
|
|
161
158
|
|
|
162
159
|
const bindings: CfWorkerInit["bindings"] = {
|
|
163
|
-
kv_namespaces: (
|
|
160
|
+
kv_namespaces: (config.kv_namespaces || []).concat(
|
|
164
161
|
assets.namespace
|
|
165
162
|
? { binding: "__STATIC_CONTENT", id: assets.namespace }
|
|
166
163
|
: []
|
|
167
164
|
),
|
|
168
|
-
vars:
|
|
165
|
+
vars: config.vars,
|
|
169
166
|
wasm_modules: config.wasm_modules,
|
|
170
167
|
text_blobs: {
|
|
171
168
|
...config.text_blobs,
|
|
@@ -174,9 +171,9 @@ export default async function publish(props: Props): Promise<void> {
|
|
|
174
171
|
__STATIC_CONTENT_MANIFEST: "__STATIC_CONTENT_MANIFEST",
|
|
175
172
|
}),
|
|
176
173
|
},
|
|
177
|
-
durable_objects:
|
|
178
|
-
r2_buckets:
|
|
179
|
-
unsafe:
|
|
174
|
+
durable_objects: config.durable_objects,
|
|
175
|
+
r2_buckets: config.r2_buckets,
|
|
176
|
+
unsafe: config.unsafe?.bindings,
|
|
180
177
|
};
|
|
181
178
|
|
|
182
179
|
if (assets.manifest) {
|
|
@@ -197,11 +194,10 @@ export default async function publish(props: Props): Promise<void> {
|
|
|
197
194
|
bindings,
|
|
198
195
|
migrations,
|
|
199
196
|
modules,
|
|
200
|
-
compatibility_date:
|
|
201
|
-
props.compatibilityDate ?? envRootObj.compatibility_date,
|
|
197
|
+
compatibility_date: props.compatibilityDate ?? config.compatibility_date,
|
|
202
198
|
compatibility_flags:
|
|
203
|
-
props.compatibilityFlags ??
|
|
204
|
-
usage_model:
|
|
199
|
+
props.compatibilityFlags ?? config.compatibility_flags,
|
|
200
|
+
usage_model: config.usage_model,
|
|
205
201
|
};
|
|
206
202
|
|
|
207
203
|
const start = Date.now();
|