wrangler 0.0.0-e1c615f → 0.0.0-e22f9d7
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/package.json +3 -2
- package/pages/functions/buildWorker.ts +5 -0
- package/pages/functions/template-worker.ts +9 -2
- package/src/__tests__/dev.test.tsx +3 -2
- package/src/__tests__/kv.test.ts +24 -11
- package/src/__tests__/mock-cfetch.ts +4 -4
- package/src/api/form_data.ts +1 -1
- package/src/api/worker.ts +6 -6
- package/src/cfetch/internal.ts +4 -4
- package/src/config.ts +475 -119
- package/src/dev.tsx +107 -197
- package/src/index.tsx +50 -5
- package/src/inspect.ts +539 -0
- package/src/kv.tsx +18 -9
- package/src/pages.tsx +98 -35
- package/src/proxy.ts +275 -76
- package/src/publish.ts +40 -26
- package/src/sites.tsx +5 -1
- package/src/user.tsx +22 -17
- package/wrangler-dist/cli.js +30051 -29836
- package/wrangler-dist/cli.js.map +3 -3
- package/src/api/inspect.ts +0 -430
package/src/publish.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type { Config } from "./config";
|
|
|
11
11
|
import makeModuleCollector from "./module-collection";
|
|
12
12
|
import { syncAssets } from "./sites";
|
|
13
13
|
|
|
14
|
-
type CfScriptFormat =
|
|
14
|
+
type CfScriptFormat = undefined | "modules" | "service-worker";
|
|
15
15
|
|
|
16
16
|
type Props = {
|
|
17
17
|
config: Config;
|
|
@@ -19,13 +19,15 @@ type Props = {
|
|
|
19
19
|
script?: string;
|
|
20
20
|
name?: string;
|
|
21
21
|
env?: string;
|
|
22
|
+
compatibilityDate?: string;
|
|
23
|
+
compatibilityFlags?: string[];
|
|
22
24
|
public?: string;
|
|
23
25
|
site?: string;
|
|
24
26
|
triggers?: (string | number)[];
|
|
25
27
|
routes?: (string | number)[];
|
|
26
28
|
legacyEnv?: boolean;
|
|
27
|
-
jsxFactory:
|
|
28
|
-
jsxFragment:
|
|
29
|
+
jsxFactory: undefined | string;
|
|
30
|
+
jsxFragment: undefined | string;
|
|
29
31
|
};
|
|
30
32
|
|
|
31
33
|
function sleep(ms: number) {
|
|
@@ -48,6 +50,18 @@ export default async function publish(props: Props): Promise<void> {
|
|
|
48
50
|
__path__,
|
|
49
51
|
} = config;
|
|
50
52
|
|
|
53
|
+
const envRootObj =
|
|
54
|
+
props.env && config.env ? config.env[props.env] || {} : config;
|
|
55
|
+
|
|
56
|
+
assert(
|
|
57
|
+
envRootObj.compatibility_date || props.compatibilityDate,
|
|
58
|
+
"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."
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
if (accountId === undefined) {
|
|
62
|
+
throw new Error("No account_id provided.");
|
|
63
|
+
}
|
|
64
|
+
|
|
51
65
|
const triggers = props.triggers || config.triggers?.crons;
|
|
52
66
|
const routes = props.routes || config.routes;
|
|
53
67
|
|
|
@@ -120,18 +134,24 @@ export default async function publish(props: Props): Promise<void> {
|
|
|
120
134
|
...(jsxFragment && { jsxFragment }),
|
|
121
135
|
});
|
|
122
136
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
137
|
+
// result.metafile is defined because of the `metafile: true` option above.
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
139
|
+
const metafile = result.metafile!;
|
|
140
|
+
const expectedEntryPoint = props.public
|
|
141
|
+
? path.join(path.dirname(file), "static-asset-facade.js")
|
|
142
|
+
: file;
|
|
143
|
+
const outputEntry = Object.entries(metafile.outputs).find(
|
|
144
|
+
([, { entryPoint }]) => entryPoint === expectedEntryPoint
|
|
129
145
|
);
|
|
130
|
-
|
|
146
|
+
if (outputEntry === undefined) {
|
|
147
|
+
throw new Error(
|
|
148
|
+
`Cannot find entry-point "${expectedEntryPoint}" in generated bundle.`
|
|
149
|
+
);
|
|
150
|
+
}
|
|
131
151
|
const { format } = props;
|
|
132
152
|
const bundle = {
|
|
133
|
-
type:
|
|
134
|
-
exports:
|
|
153
|
+
type: outputEntry[1].exports.length > 0 ? "esm" : "commonjs",
|
|
154
|
+
exports: outputEntry[1].exports,
|
|
135
155
|
};
|
|
136
156
|
|
|
137
157
|
// TODO: instead of bundling the facade with the worker, we should just bundle the worker and expose it as a module.
|
|
@@ -148,13 +168,13 @@ export default async function publish(props: Props): Promise<void> {
|
|
|
148
168
|
return;
|
|
149
169
|
}
|
|
150
170
|
|
|
151
|
-
const content = await readFile(
|
|
171
|
+
const content = await readFile(outputEntry[0], { encoding: "utf-8" });
|
|
152
172
|
await destination.cleanup();
|
|
153
173
|
|
|
154
174
|
// if config.migrations
|
|
155
175
|
// get current migration tag
|
|
156
176
|
let migrations;
|
|
157
|
-
if (
|
|
177
|
+
if (config.migrations !== undefined) {
|
|
158
178
|
const scripts = await fetchResult<{ id: string; migration_tag: string }[]>(
|
|
159
179
|
`/accounts/${accountId}/workers/scripts`
|
|
160
180
|
);
|
|
@@ -190,17 +210,11 @@ export default async function publish(props: Props): Promise<void> {
|
|
|
190
210
|
}
|
|
191
211
|
}
|
|
192
212
|
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
props.public || props.site || props.config.site?.bucket,
|
|
199
|
-
false
|
|
200
|
-
)
|
|
201
|
-
: { manifest: undefined, namespace: undefined };
|
|
202
|
-
|
|
203
|
-
const envRootObj = props.env ? config.env[props.env] || {} : config;
|
|
213
|
+
const assetPath = props.public || props.site || props.config.site?.bucket; // TODO: allow both
|
|
214
|
+
const assets = assetPath
|
|
215
|
+
? await syncAssets(accountId, scriptName, assetPath, false)
|
|
216
|
+
: { manifest: undefined, namespace: undefined };
|
|
217
|
+
|
|
204
218
|
const bindings: CfWorkerInit["bindings"] = {
|
|
205
219
|
kv_namespaces: envRootObj.kv_namespaces?.concat(
|
|
206
220
|
assets.namespace
|
|
@@ -215,7 +229,7 @@ export default async function publish(props: Props): Promise<void> {
|
|
|
215
229
|
const worker: CfWorkerInit = {
|
|
216
230
|
name: scriptName,
|
|
217
231
|
main: {
|
|
218
|
-
name: path.basename(
|
|
232
|
+
name: path.basename(outputEntry[0]),
|
|
219
233
|
content: content,
|
|
220
234
|
type: bundle.type === "esm" ? "esm" : "commonjs",
|
|
221
235
|
},
|
package/src/sites.tsx
CHANGED
|
@@ -89,7 +89,11 @@ export async function syncAssets(
|
|
|
89
89
|
);
|
|
90
90
|
|
|
91
91
|
const manifest = {};
|
|
92
|
-
const upload
|
|
92
|
+
const upload: {
|
|
93
|
+
key: string;
|
|
94
|
+
value: string;
|
|
95
|
+
base64: boolean;
|
|
96
|
+
}[] = [];
|
|
93
97
|
// TODO: this can be more efficient by parallelising
|
|
94
98
|
for await (const file of getFilesInFolder(dirPath)) {
|
|
95
99
|
// TODO: "exclude:" config
|
package/src/user.tsx
CHANGED
|
@@ -206,7 +206,7 @@
|
|
|
206
206
|
*/
|
|
207
207
|
|
|
208
208
|
import React from "react";
|
|
209
|
-
import { render } from "ink";
|
|
209
|
+
import { render, Text } from "ink";
|
|
210
210
|
import Table from "ink-table";
|
|
211
211
|
import SelectInput from "ink-select-input";
|
|
212
212
|
import fetch from "node-fetch";
|
|
@@ -298,9 +298,9 @@ let initialised = false;
|
|
|
298
298
|
|
|
299
299
|
// we do this because we have some async stuff
|
|
300
300
|
// TODO: this should just happen in the top level
|
|
301
|
-
//
|
|
301
|
+
// and we should figure out how to do top level await
|
|
302
302
|
export async function initialise(): Promise<void> {
|
|
303
|
-
// get
|
|
303
|
+
// get refreshToken/accessToken from fs if exists
|
|
304
304
|
try {
|
|
305
305
|
// if CF_API_TOKEN available, use that
|
|
306
306
|
if (process.env.CF_API_TOKEN) {
|
|
@@ -350,7 +350,9 @@ export function getAPIToken(): string {
|
|
|
350
350
|
}
|
|
351
351
|
|
|
352
352
|
throwIfNotInitialised();
|
|
353
|
-
|
|
353
|
+
// `throwIfNotInitialised()` ensures that the accessToken is guaranteed to be defined.
|
|
354
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
355
|
+
return LocalState.accessToken!.value;
|
|
354
356
|
}
|
|
355
357
|
|
|
356
358
|
interface AccessContext {
|
|
@@ -971,14 +973,14 @@ export async function getAccountId() {
|
|
|
971
973
|
});
|
|
972
974
|
} catch (err) {
|
|
973
975
|
// probably offline
|
|
976
|
+
return;
|
|
974
977
|
}
|
|
975
|
-
|
|
976
|
-
let accountId: string;
|
|
977
|
-
|
|
978
|
-
const responseJSON: {
|
|
978
|
+
|
|
979
|
+
let accountId: string | undefined;
|
|
980
|
+
const responseJSON = (await response.json()) as {
|
|
979
981
|
success: boolean;
|
|
980
982
|
result: { id: string; account: { id: string; name: string } }[];
|
|
981
|
-
}
|
|
983
|
+
};
|
|
982
984
|
|
|
983
985
|
if (responseJSON.success === true) {
|
|
984
986
|
if (responseJSON.result.length === 1) {
|
|
@@ -1010,13 +1012,16 @@ export function ChooseAccount(props: {
|
|
|
1010
1012
|
onSelect: (item) => void;
|
|
1011
1013
|
}) {
|
|
1012
1014
|
return (
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1015
|
+
<>
|
|
1016
|
+
<Text bold>Select an account from below:</Text>
|
|
1017
|
+
<SelectInput
|
|
1018
|
+
items={props.accounts.map((item) => ({
|
|
1019
|
+
key: item.id,
|
|
1020
|
+
label: item.name,
|
|
1021
|
+
value: item,
|
|
1022
|
+
}))}
|
|
1023
|
+
onSelect={props.onSelect}
|
|
1024
|
+
/>
|
|
1025
|
+
</>
|
|
1021
1026
|
);
|
|
1022
1027
|
}
|