wrangler 2.0.0 → 2.0.1
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 +3 -1
- package/package.json +3 -3
- package/src/__tests__/parse.test.ts +4 -0
- package/src/pages.tsx +42 -33
- package/src/parse.ts +3 -1
- package/src/proxy.ts +4 -9
- package/wrangler-dist/cli.js +34 -28
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
## ⛅️ wrangler
|
|
2
2
|
|
|
3
|
+
> This package is for wrangler v2.x, released first in May 2022. If you're looking for v1.x of the `@cloudflare/wrangler` package, visit https://www.npmjs.com/package/@cloudflare/wrangler / https://github.com/cloudflare/wrangler.
|
|
4
|
+
|
|
3
5
|
`wrangler` is a command line tool for building [Cloudflare Workers](https://workers.cloudflare.com/).
|
|
4
6
|
|
|
5
7
|
## Quick Start
|
|
@@ -22,7 +24,7 @@ npx wrangler init my-worker
|
|
|
22
24
|
# try it out
|
|
23
25
|
cd my-worker && npm run start
|
|
24
26
|
# and then publish it
|
|
25
|
-
|
|
27
|
+
npm run publish
|
|
26
28
|
```
|
|
27
29
|
|
|
28
30
|
## Installation:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"author": "wrangler@cloudflare.com",
|
|
5
5
|
"description": "Command-line interface for all things Cloudflare Workers",
|
|
6
6
|
"bin": {
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT OR Apache-2.0",
|
|
11
11
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/cloudflare/
|
|
12
|
+
"url": "https://github.com/cloudflare/wrangler2/issues"
|
|
13
13
|
},
|
|
14
|
-
"homepage": "https://github.com/cloudflare/
|
|
14
|
+
"homepage": "https://github.com/cloudflare/wrangler2#readme",
|
|
15
15
|
"keywords": [
|
|
16
16
|
"wrangler",
|
|
17
17
|
"cloudflare",
|
package/src/pages.tsx
CHANGED
|
@@ -82,6 +82,8 @@ const PAGES_CONFIG_CACHE_FILENAME = "pages.json";
|
|
|
82
82
|
export const pagesBetaWarning =
|
|
83
83
|
"🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose";
|
|
84
84
|
|
|
85
|
+
const isInPagesCI = !!process.env.CF_PAGES;
|
|
86
|
+
|
|
85
87
|
const CLEANUP_CALLBACKS: (() => void)[] = [];
|
|
86
88
|
const CLEANUP = () => {
|
|
87
89
|
CLEANUP_CALLBACKS.forEach((callback) => callback());
|
|
@@ -851,40 +853,45 @@ const createDeployment: CommandModule<
|
|
|
851
853
|
|
|
852
854
|
const isInteractive = process.stdin.isTTY;
|
|
853
855
|
if (!projectName && isInteractive) {
|
|
854
|
-
const
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
856
|
+
const projects = (await listProjects({ accountId })).filter(
|
|
857
|
+
(project) => !project.source
|
|
858
|
+
);
|
|
859
|
+
|
|
860
|
+
let existingOrNew: "existing" | "new" = "new";
|
|
861
|
+
|
|
862
|
+
if (projects.length > 0) {
|
|
863
|
+
existingOrNew = await new Promise<"new" | "existing">((resolve) => {
|
|
864
|
+
const { unmount } = render(
|
|
865
|
+
<>
|
|
866
|
+
<Text>
|
|
867
|
+
No project selected. Would you like to create one or use an
|
|
868
|
+
existing project?
|
|
869
|
+
</Text>
|
|
870
|
+
<SelectInput
|
|
871
|
+
items={[
|
|
872
|
+
{
|
|
873
|
+
key: "new",
|
|
874
|
+
label: "Create a new project",
|
|
875
|
+
value: "new",
|
|
876
|
+
},
|
|
877
|
+
{
|
|
878
|
+
key: "existing",
|
|
879
|
+
label: "Use an existing project",
|
|
880
|
+
value: "existing",
|
|
881
|
+
},
|
|
882
|
+
]}
|
|
883
|
+
onSelect={async (selected) => {
|
|
884
|
+
resolve(selected.value as "new" | "existing");
|
|
885
|
+
unmount();
|
|
886
|
+
}}
|
|
887
|
+
/>
|
|
888
|
+
</>
|
|
889
|
+
);
|
|
890
|
+
});
|
|
891
|
+
}
|
|
882
892
|
|
|
883
893
|
switch (existingOrNew) {
|
|
884
894
|
case "existing": {
|
|
885
|
-
const projects = (await listProjects({ accountId })).filter(
|
|
886
|
-
(project) => !project.source
|
|
887
|
-
);
|
|
888
895
|
projectName = await new Promise((resolve) => {
|
|
889
896
|
const { unmount } = render(
|
|
890
897
|
<>
|
|
@@ -1581,8 +1588,10 @@ export const pages: BuilderCallback<unknown, unknown> = (yargs) => {
|
|
|
1581
1588
|
watch,
|
|
1582
1589
|
plugin,
|
|
1583
1590
|
}) => {
|
|
1584
|
-
|
|
1585
|
-
|
|
1591
|
+
if (!isInPagesCI) {
|
|
1592
|
+
// Beta message for `wrangler pages <commands>` usage
|
|
1593
|
+
logger.log(pagesBetaWarning);
|
|
1594
|
+
}
|
|
1586
1595
|
|
|
1587
1596
|
await buildFunctions({
|
|
1588
1597
|
outfile,
|
package/src/parse.ts
CHANGED
|
@@ -77,7 +77,9 @@ type TomlError = Error & {
|
|
|
77
77
|
*/
|
|
78
78
|
export function parseTOML(input: string, file?: string): TOML.JsonMap | never {
|
|
79
79
|
try {
|
|
80
|
-
|
|
80
|
+
// Normalize CRLF to LF to avoid hitting https://github.com/iarna/iarna-toml/issues/33.
|
|
81
|
+
const normalizedInput = input.replace(/\r\n$/g, "\n");
|
|
82
|
+
return TOML.parse(normalizedInput);
|
|
81
83
|
} catch (err) {
|
|
82
84
|
const { name, message, line, col } = err as TomlError;
|
|
83
85
|
if (name !== TOML_ERROR_NAME) {
|
package/src/proxy.ts
CHANGED
|
@@ -210,6 +210,10 @@ export function usePreviewServer({
|
|
|
210
210
|
const request = message.pipe(remote.request(headers));
|
|
211
211
|
request.on("response", (responseHeaders) => {
|
|
212
212
|
const status = responseHeaders[":status"] ?? 500;
|
|
213
|
+
|
|
214
|
+
// log all requests to terminal
|
|
215
|
+
logger.log(new Date().toLocaleTimeString(), method, url, status);
|
|
216
|
+
|
|
213
217
|
rewriteRemoteHostToLocalHostInHeaders(
|
|
214
218
|
responseHeaders,
|
|
215
219
|
previewToken.host,
|
|
@@ -349,15 +353,6 @@ async function createProxyServer(
|
|
|
349
353
|
: createHttpServer();
|
|
350
354
|
|
|
351
355
|
return server
|
|
352
|
-
.on("request", function (req, res) {
|
|
353
|
-
// log all requests
|
|
354
|
-
logger.log(
|
|
355
|
-
new Date().toLocaleTimeString(),
|
|
356
|
-
req.method,
|
|
357
|
-
req.url,
|
|
358
|
-
res.statusCode
|
|
359
|
-
);
|
|
360
|
-
})
|
|
361
356
|
.on("upgrade", (req) => {
|
|
362
357
|
// log all websocket connections
|
|
363
358
|
logger.log(
|
package/wrangler-dist/cli.js
CHANGED
|
@@ -104810,7 +104810,7 @@ var yargs_default = Yargs;
|
|
|
104810
104810
|
|
|
104811
104811
|
// package.json
|
|
104812
104812
|
var name = "wrangler";
|
|
104813
|
-
var version = "2.0.
|
|
104813
|
+
var version = "2.0.1";
|
|
104814
104814
|
var author = "wrangler@cloudflare.com";
|
|
104815
104815
|
var description = "Command-line interface for all things Cloudflare Workers";
|
|
104816
104816
|
var bin = {
|
|
@@ -104819,9 +104819,9 @@ var bin = {
|
|
|
104819
104819
|
};
|
|
104820
104820
|
var license = "MIT OR Apache-2.0";
|
|
104821
104821
|
var bugs = {
|
|
104822
|
-
url: "https://github.com/cloudflare/
|
|
104822
|
+
url: "https://github.com/cloudflare/wrangler2/issues"
|
|
104823
104823
|
};
|
|
104824
|
-
var homepage = "https://github.com/cloudflare/
|
|
104824
|
+
var homepage = "https://github.com/cloudflare/wrangler2#readme";
|
|
104825
104825
|
var keywords = [
|
|
104826
104826
|
"wrangler",
|
|
104827
104827
|
"cloudflare",
|
|
@@ -105017,7 +105017,8 @@ var TOML_ERROR_NAME = "TomlError";
|
|
|
105017
105017
|
var TOML_ERROR_SUFFIX = " at row ";
|
|
105018
105018
|
function parseTOML(input, file) {
|
|
105019
105019
|
try {
|
|
105020
|
-
|
|
105020
|
+
const normalizedInput = input.replace(/\r\n$/g, "\n");
|
|
105021
|
+
return import_toml.default.parse(normalizedInput);
|
|
105021
105022
|
} catch (err2) {
|
|
105022
105023
|
const { name: name2, message, line, col } = err2;
|
|
105023
105024
|
if (name2 !== TOML_ERROR_NAME) {
|
|
@@ -107438,6 +107439,7 @@ function usePreviewServer({
|
|
|
107438
107439
|
const request = message.pipe(remote.request(headers));
|
|
107439
107440
|
request.on("response", (responseHeaders) => {
|
|
107440
107441
|
const status = responseHeaders[":status"] ?? 500;
|
|
107442
|
+
logger.log(new Date().toLocaleTimeString(), method, url3, status);
|
|
107441
107443
|
rewriteRemoteHostToLocalHostInHeaders(responseHeaders, previewToken.host, port, localProtocol);
|
|
107442
107444
|
for (const name2 of Object.keys(responseHeaders)) {
|
|
107443
107445
|
if (name2.startsWith(":")) {
|
|
@@ -107522,9 +107524,7 @@ var HTTP1_HEADERS = /* @__PURE__ */ new Set([
|
|
|
107522
107524
|
]);
|
|
107523
107525
|
async function createProxyServer(localProtocol) {
|
|
107524
107526
|
const server = localProtocol === "https" ? (0, import_node_https.createServer)(await getHttpsOptions()) : (0, import_node_http2.createServer)();
|
|
107525
|
-
return server.on("
|
|
107526
|
-
logger.log(new Date().toLocaleTimeString(), req.method, req.url, res.statusCode);
|
|
107527
|
-
}).on("upgrade", (req) => {
|
|
107527
|
+
return server.on("upgrade", (req) => {
|
|
107528
107528
|
logger.log(new Date().toLocaleTimeString(), req.method, req.url, 101, "(WebSocket)");
|
|
107529
107529
|
}).on("error", (err2) => {
|
|
107530
107530
|
logger.error(new Date().toLocaleTimeString(), err2);
|
|
@@ -109952,6 +109952,7 @@ var getRequestContextCheckOptions = async () => {
|
|
|
109952
109952
|
// src/pages.tsx
|
|
109953
109953
|
var PAGES_CONFIG_CACHE_FILENAME = "pages.json";
|
|
109954
109954
|
var pagesBetaWarning = "\u{1F6A7} 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose";
|
|
109955
|
+
var isInPagesCI = !!process.env.CF_PAGES;
|
|
109955
109956
|
var CLEANUP_CALLBACKS = [];
|
|
109956
109957
|
var CLEANUP = () => {
|
|
109957
109958
|
CLEANUP_CALLBACKS.forEach((callback) => callback());
|
|
@@ -110460,29 +110461,32 @@ var createDeployment = {
|
|
|
110460
110461
|
projectName ??= config.project_name;
|
|
110461
110462
|
const isInteractive = process.stdin.isTTY;
|
|
110462
110463
|
if (!projectName && isInteractive) {
|
|
110463
|
-
const
|
|
110464
|
-
|
|
110465
|
-
|
|
110466
|
-
|
|
110467
|
-
|
|
110468
|
-
|
|
110469
|
-
|
|
110470
|
-
|
|
110471
|
-
|
|
110472
|
-
|
|
110473
|
-
|
|
110474
|
-
|
|
110464
|
+
const projects = (await listProjects({ accountId })).filter((project) => !project.source);
|
|
110465
|
+
let existingOrNew = "new";
|
|
110466
|
+
if (projects.length > 0) {
|
|
110467
|
+
existingOrNew = await new Promise((resolve11) => {
|
|
110468
|
+
const { unmount: unmount2 } = (0, import_ink5.render)(/* @__PURE__ */ import_react9.default.createElement(import_react9.default.Fragment, null, /* @__PURE__ */ import_react9.default.createElement(import_ink5.Text, null, "No project selected. Would you like to create one or use an existing project?"), /* @__PURE__ */ import_react9.default.createElement(import_ink_select_input2.default, {
|
|
110469
|
+
items: [
|
|
110470
|
+
{
|
|
110471
|
+
key: "new",
|
|
110472
|
+
label: "Create a new project",
|
|
110473
|
+
value: "new"
|
|
110474
|
+
},
|
|
110475
|
+
{
|
|
110476
|
+
key: "existing",
|
|
110477
|
+
label: "Use an existing project",
|
|
110478
|
+
value: "existing"
|
|
110479
|
+
}
|
|
110480
|
+
],
|
|
110481
|
+
onSelect: async (selected) => {
|
|
110482
|
+
resolve11(selected.value);
|
|
110483
|
+
unmount2();
|
|
110475
110484
|
}
|
|
110476
|
-
|
|
110477
|
-
|
|
110478
|
-
|
|
110479
|
-
unmount2();
|
|
110480
|
-
}
|
|
110481
|
-
})));
|
|
110482
|
-
});
|
|
110485
|
+
})));
|
|
110486
|
+
});
|
|
110487
|
+
}
|
|
110483
110488
|
switch (existingOrNew) {
|
|
110484
110489
|
case "existing": {
|
|
110485
|
-
const projects = (await listProjects({ accountId })).filter((project) => !project.source);
|
|
110486
110490
|
projectName = await new Promise((resolve11) => {
|
|
110487
110491
|
const { unmount: unmount2 } = (0, import_ink5.render)(/* @__PURE__ */ import_react9.default.createElement(import_react9.default.Fragment, null, /* @__PURE__ */ import_react9.default.createElement(import_ink5.Text, null, "Select a project:"), /* @__PURE__ */ import_react9.default.createElement(import_ink_select_input2.default, {
|
|
110488
110492
|
items: projects.map((project) => ({
|
|
@@ -110960,7 +110964,9 @@ var pages = (yargs) => {
|
|
|
110960
110964
|
watch: watch3,
|
|
110961
110965
|
plugin
|
|
110962
110966
|
}) => {
|
|
110963
|
-
|
|
110967
|
+
if (!isInPagesCI) {
|
|
110968
|
+
logger.log(pagesBetaWarning);
|
|
110969
|
+
}
|
|
110964
110970
|
await buildFunctions({
|
|
110965
110971
|
outfile,
|
|
110966
110972
|
outputConfigPath,
|