wrangler
Advanced tools
Comparing version 0.0.0-beta.6 to 0.0.0-bf67bf2
{ | ||
"name": "wrangler", | ||
"version": "0.0.0-beta.6", | ||
"version": "0.0.0-bf67bf2", | ||
"author": "wrangler@cloudflare.com", | ||
@@ -39,7 +39,9 @@ "description": "Command-line interface for all things Cloudflare Workers", | ||
"dependencies": { | ||
"@cloudflare/pages-functions-compiler": "0.3.5", | ||
"esbuild": "0.13.12", | ||
"@cloudflare/pages-functions-compiler": "0.3.7", | ||
"esbuild": "0.14.1", | ||
"miniflare": "2.0.0-rc.2", | ||
"semiver": "^1.1.0", | ||
"serve": "^13.0.2" | ||
"serve": "^13.0.2", | ||
"@esbuild-plugins/node-globals-polyfill": "^0.1.1", | ||
"@esbuild-plugins/node-modules-polyfill": "^0.1.2" | ||
}, | ||
@@ -53,9 +55,9 @@ "optionalDependencies": { | ||
"@types/express": "^4.17.13", | ||
"@types/react": "^17.0.34", | ||
"@types/react": "^17.0.37", | ||
"@types/signal-exit": "^3.0.1", | ||
"@types/ws": "^8.2.0", | ||
"@types/yargs": "^17.0.5", | ||
"@types/ws": "^8.2.1", | ||
"@types/yargs": "^17.0.7", | ||
"clipboardy": "^3.0.0", | ||
"command-exists": "^1.2.9", | ||
"execa": "^5.1.1", | ||
"execa": "^6.0.0", | ||
"express": "^4.17.1", | ||
@@ -68,5 +70,5 @@ "finalhandler": "^1.1.2", | ||
"ink": "^3.2.0", | ||
"ink-select-input": "^4.2.0", | ||
"ink-select-input": "^4.2.1", | ||
"ink-table": "^3.0.0", | ||
"ink-text-input": "^4.0.1", | ||
"ink-text-input": "^4.0.2", | ||
"node-fetch": "^3.1.0", | ||
@@ -77,6 +79,6 @@ "open": "^8.4.0", | ||
"serve-static": "^1.14.1", | ||
"signal-exit": "^3.0.5", | ||
"signal-exit": "^3.0.6", | ||
"tmp-promise": "^3.0.3", | ||
"ws": "^8.2.3", | ||
"yargs": "^17.2.1" | ||
"ws": "^8.3.0", | ||
"yargs": "^17.3.0" | ||
}, | ||
@@ -105,3 +107,3 @@ "files": [ | ||
"transformIgnorePatterns": [ | ||
"node_modules/(?!node-fetch|fetch-blob|find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|data-uri-to-buffer|formdata-polyfill)" | ||
"node_modules/(?!node-fetch|fetch-blob|find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|data-uri-to-buffer|formdata-polyfill|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream)" | ||
], | ||
@@ -120,2 +122,2 @@ "moduleNameMapper": { | ||
} | ||
} | ||
} |
@@ -113,3 +113,3 @@ import * as fs from "node:fs"; | ||
await w('kv:namespace create "UnitTestNamespace"'); | ||
await w("kv:namespace create UnitTestNamespace"); | ||
expect( | ||
@@ -116,0 +116,0 @@ KVNamespaces.find((ns) => ns.title === `worker-UnitTestNamespace`) |
@@ -6,4 +6,2 @@ import type { | ||
CfModule, | ||
CfKvNamespace, | ||
CfCryptoKey, | ||
} from "./worker.js"; | ||
@@ -31,8 +29,22 @@ import { FormData, Blob } from "formdata-node"; | ||
const { namespaceId } = variable as CfKvNamespace; | ||
if (namespaceId) { | ||
return { name, type: "kv_namespace", namespace_id: namespaceId }; | ||
if ("namespaceId" in variable) { | ||
return { | ||
name, | ||
type: "kv_namespace", | ||
namespace_id: variable.namespaceId, | ||
}; | ||
} | ||
const { format, algorithm, usages, data } = variable as CfCryptoKey; | ||
if ("class_name" in variable) { | ||
return { | ||
name, | ||
type: "durable_object_namespace", | ||
class_name: variable.class_name, | ||
...(variable.script_name && { | ||
script_name: variable.script_name, | ||
}), | ||
}; | ||
} | ||
const { format, algorithm, usages, data } = variable; | ||
if (format) { | ||
@@ -89,3 +101,11 @@ let key_base64; | ||
const formData = new FormData(); | ||
const { main, modules, variables, usage_model, compatibility_date } = worker; | ||
const { | ||
main, | ||
modules, | ||
variables, | ||
migrations, | ||
usage_model, | ||
compatibility_date, | ||
compatibility_flags, | ||
} = worker; | ||
const { name, type: mainType } = main; | ||
@@ -99,8 +119,12 @@ | ||
const singleton = mainType === "commonjs"; | ||
const metadata = { | ||
main_module: singleton ? undefined : name, | ||
body_part: singleton ? name : undefined, | ||
bindings, | ||
}; | ||
const metadata = | ||
mainType !== "commonjs" | ||
? { | ||
main_module: name, | ||
bindings, | ||
} | ||
: { | ||
body_part: name, | ||
bindings, | ||
}; | ||
if (compatibility_date) { | ||
@@ -110,2 +134,6 @@ // @ts-expect-error - we should type metadata | ||
} | ||
if (compatibility_flags) { | ||
// @ts-expect-error - we should type metadata | ||
metadata.compatibility_flags = compatibility_flags; | ||
} | ||
if (usage_model) { | ||
@@ -115,5 +143,10 @@ // @ts-expect-error - we should type metadata | ||
} | ||
if (migrations) { | ||
// @ts-expect-error - we should type metadata | ||
metadata.migrations = migrations; | ||
} | ||
formData.set("metadata", JSON.stringify(metadata)); | ||
if (singleton && modules && modules.length > 0) { | ||
if (mainType === "commonjs" && modules && modules.length > 0) { | ||
throw new TypeError( | ||
@@ -120,0 +153,0 @@ "More than one module can only be specified when type = 'esm'" |
@@ -75,2 +75,17 @@ import type { CfPreviewToken } from "./preview"; | ||
export interface CfDurableObject { | ||
class_name: string; | ||
script_name?: string; | ||
} | ||
interface CfDOMigrations { | ||
old_tag?: string; | ||
new_tag: string; | ||
steps: { | ||
new_classes?: string[]; | ||
renamed_classes?: string[]; | ||
deleted_classes?: string[]; | ||
}[]; | ||
} | ||
/** | ||
@@ -103,3 +118,3 @@ * A `WebCrypto` key. | ||
*/ | ||
export type CfVariable = string | CfKvNamespace | CfCryptoKey; | ||
export type CfVariable = string | CfKvNamespace | CfCryptoKey | CfDurableObject; | ||
@@ -122,4 +137,6 @@ /** | ||
variables?: { [name: string]: CfVariable }; | ||
compatibility_date?: string; | ||
usage_model?: void | "bundled" | "unbound"; | ||
migrations: void | CfDOMigrations; | ||
compatibility_date: string | void; | ||
compatibility_flags: void | string[]; | ||
usage_model: void | "bundled" | "unbound"; | ||
} | ||
@@ -126,0 +143,0 @@ |
// we're going to manually write both the type definition AND | ||
// the validator for the config, so that we can give better error messages | ||
type DOMigration = { | ||
tag: string; | ||
new_classes?: string[]; | ||
renamed_classes?: string[]; | ||
deleted_classes?: string[]; | ||
}; | ||
type Project = "webpack" | "javascript" | "rust"; | ||
@@ -31,2 +38,8 @@ | ||
type DurableObject = { | ||
name: string; | ||
class_name: string; | ||
script_name?: string; | ||
}; | ||
type Build = { | ||
@@ -63,2 +76,4 @@ command?: string; | ||
workers_dev?: boolean; // inherited | ||
compatibility_date?: string; // inherited | ||
compatibility_flags?: string[]; // inherited | ||
zone_id?: string; // inherited | ||
@@ -69,7 +84,11 @@ routes?: string[]; // inherited | ||
site?: Site; | ||
jsxFactory?: string; // inherited | ||
jsxFragment?: string; // inherited | ||
jsx_factory?: string; // inherited | ||
jsx_fragment?: string; // inherited | ||
polyfill_node?: boolean; //inherited | ||
// we should use typescript to parse cron patterns | ||
triggers?: { crons: Cron[] }; // inherited | ||
vars?: Vars; | ||
durable_objects?: { bindings: DurableObject[] }; | ||
kv_namespaces?: KVNamespace[]; | ||
usage_model?: UsageModel; // inherited | ||
}; | ||
@@ -82,2 +101,4 @@ | ||
type?: Project; // top level | ||
compatibility_date?: string; // inherited | ||
compatibility_flags?: string[]; // inherited | ||
// -- there's some mutually exclusive logic for this next block, | ||
@@ -92,5 +113,8 @@ // but I didn't bother for now | ||
webpack_config?: string; // inherited | ||
jsxFactory?: string; // inherited | ||
jsxFragment?: string; // inherited | ||
jsx_factory?: string; // inherited | ||
jsx_fragment?: string; // inherited | ||
polyfill_node?: boolean; //inherited | ||
vars?: Vars; | ||
migrations?: DOMigration[]; | ||
durable_objects?: { bindings: DurableObject[] }; | ||
kv_namespaces?: KVNamespace[]; | ||
@@ -104,3 +128,3 @@ site?: Site; // inherited | ||
build?: Build; | ||
env?: { [envName: string]: Env }; | ||
env?: { [envName: string]: void | Env }; | ||
}; |
@@ -11,2 +11,4 @@ import type { CfWorkerInit } from "./api/worker"; | ||
import { syncAssets } from "./sites"; | ||
import NodeModulesPolyfills from "@esbuild-plugins/node-modules-polyfill"; | ||
import NodeGlobalsPolyfills from "@esbuild-plugins/node-globals-polyfill"; | ||
@@ -28,2 +30,3 @@ type CfScriptFormat = void | "modules" | "service-worker"; | ||
jsxFragment: void | string; | ||
polyfillNode: void | boolean; | ||
}; | ||
@@ -54,4 +57,4 @@ | ||
const jsxFactory = props.jsxFactory || config.jsxFactory; | ||
const jsxFragment = props.jsxFragment || config.jsxFragment; | ||
const jsxFactory = props.jsxFactory || config.jsx_factory; | ||
const jsxFragment = props.jsxFragment || config.jsx_fragment; | ||
@@ -94,2 +97,7 @@ assert(config.account_id, "missing account id"); | ||
bundle: true, | ||
define: { | ||
...((props.polyfillNode ?? config.polyfill_node) && { | ||
global: "globalThis", | ||
}), | ||
}, | ||
nodePaths: props.public ? [path.join(__dirname, "../vendor")] : undefined, | ||
@@ -99,2 +107,6 @@ outdir: destination.path, | ||
format: "esm", | ||
plugins: | ||
props.polyfillNode ?? config.polyfill_node | ||
? [NodeGlobalsPolyfills({ buffer: true }), NodeModulesPolyfills()] | ||
: undefined, | ||
sourcemap: true, | ||
@@ -139,2 +151,42 @@ metafile: true, | ||
destination.cleanup(); | ||
// if config.migrations | ||
// get current migration tag | ||
let migrations; | ||
if ("migrations" in config) { | ||
const scripts = await cfetch<{ id: string; migration_tag: string }[]>( | ||
`/accounts/${accountId}/workers/scripts` | ||
); | ||
const script = scripts.find((script) => script.id === scriptName); | ||
if (script?.migration_tag) { | ||
// was already published once | ||
const foundIndex = config.migrations.findIndex( | ||
(migration) => migration.tag === script.migration_tag | ||
); | ||
if (foundIndex === -1) { | ||
console.warn( | ||
`The published script ${scriptName} has a migration tag "${script.migration_tag}, which was not found in wrangler.toml. You may have already delated it. Applying all available migrations to the script...` | ||
); | ||
migrations = { | ||
old_tag: script.migration_tag, | ||
new_tag: config.migrations[config.migrations.length - 1].tag, | ||
steps: config.migrations.map(({ tag: _tag, ...rest }) => rest), | ||
}; | ||
} else { | ||
migrations = { | ||
old_tag: script.migration_tag, | ||
new_tag: config.migrations[config.migrations.length - 1].tag, | ||
steps: config.migrations | ||
.slice(foundIndex + 1) | ||
.map(({ tag: _tag, ...rest }) => rest), | ||
}; | ||
} | ||
} else { | ||
migrations = { | ||
new_tag: config.migrations[config.migrations.length - 1].tag, | ||
steps: config.migrations.map(({ tag: _tag, ...rest }) => rest), | ||
}; | ||
} | ||
} | ||
const assets = | ||
@@ -150,3 +202,3 @@ props.public || props.site || props.config.site?.bucket // TODO: allow both | ||
const envRootObj = props.env ? config[`env.${props.env}`] : config; | ||
const envRootObj = props.env ? config.env[props.env] || {} : config; | ||
@@ -157,6 +209,3 @@ const worker: CfWorkerInit = { | ||
content: content, | ||
type: | ||
(bundle.type === "esm" ? "modules" : "service-worker") === "modules" | ||
? "esm" | ||
: "commonjs", | ||
type: bundle.type === "esm" ? "esm" : "commonjs", | ||
}, | ||
@@ -166,3 +215,3 @@ variables: { | ||
...(envRootObj?.kv_namespaces || []).reduce( | ||
(obj, { binding, preview_id, id }) => { | ||
(obj, { binding, preview_id: _preview_id, id }) => { | ||
return { ...obj, [binding]: { namespaceId: id } }; | ||
@@ -172,2 +221,11 @@ }, | ||
), | ||
...(envRootObj?.durable_objects?.bindings || []).reduce( | ||
(obj, { name, class_name, script_name }) => { | ||
return { | ||
...obj, | ||
[name]: { class_name, ...(script_name && { script_name }) }, | ||
}; | ||
}, | ||
{} | ||
), | ||
...(assets.namespace | ||
@@ -177,2 +235,3 @@ ? { __STATIC_CONTENT: { namespaceId: assets.namespace } } | ||
}, | ||
...(migrations && { migrations }), | ||
modules: assets.manifest | ||
@@ -185,2 +244,5 @@ ? [].concat({ | ||
: [], | ||
compatibility_date: config.compatibility_date, | ||
compatibility_flags: config.compatibility_flags, | ||
usage_model: config.usage_model, | ||
}; | ||
@@ -187,0 +249,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12762417
8814
1
8
+ Added@cloudflare/pages-functions-compiler@0.3.7(transitive)
+ Added@esbuild-plugins/node-globals-polyfill@0.1.1(transitive)
+ Added@esbuild-plugins/node-modules-polyfill@0.1.4(transitive)
+ Addedesbuild@0.14.1(transitive)
+ Addedesbuild-android-arm64@0.14.1(transitive)
+ Addedesbuild-darwin-64@0.14.1(transitive)
+ Addedesbuild-darwin-arm64@0.14.1(transitive)
+ Addedesbuild-freebsd-64@0.14.1(transitive)
+ Addedesbuild-freebsd-arm64@0.14.1(transitive)
+ Addedesbuild-linux-32@0.14.1(transitive)
+ Addedesbuild-linux-64@0.14.1(transitive)
+ Addedesbuild-linux-arm@0.14.1(transitive)
+ Addedesbuild-linux-arm64@0.14.1(transitive)
+ Addedesbuild-linux-mips64le@0.14.1(transitive)
+ Addedesbuild-linux-ppc64le@0.14.1(transitive)
+ Addedesbuild-netbsd-64@0.14.1(transitive)
+ Addedesbuild-openbsd-64@0.14.1(transitive)
+ Addedesbuild-sunos-64@0.14.1(transitive)
+ Addedesbuild-windows-32@0.14.1(transitive)
+ Addedesbuild-windows-64@0.14.1(transitive)
+ Addedesbuild-windows-arm64@0.14.1(transitive)
+ Addedescape-string-regexp@4.0.0(transitive)
+ Addedestree-walker@0.6.1(transitive)
+ Addedmagic-string@0.25.9(transitive)
+ Addedrollup-plugin-inject@3.0.2(transitive)
+ Addedrollup-plugin-node-polyfills@0.2.1(transitive)
+ Addedrollup-pluginutils@2.8.2(transitive)
+ Addedsourcemap-codec@1.4.8(transitive)
- Removed@cloudflare/pages-functions-compiler@0.3.5(transitive)
- Removedesbuild@0.13.12(transitive)
- Removedesbuild-android-arm64@0.13.12(transitive)
- Removedesbuild-darwin-64@0.13.12(transitive)
- Removedesbuild-darwin-arm64@0.13.12(transitive)
- Removedesbuild-freebsd-64@0.13.12(transitive)
- Removedesbuild-freebsd-arm64@0.13.12(transitive)
- Removedesbuild-linux-32@0.13.12(transitive)
- Removedesbuild-linux-64@0.13.12(transitive)
- Removedesbuild-linux-arm@0.13.12(transitive)
- Removedesbuild-linux-arm64@0.13.12(transitive)
- Removedesbuild-linux-mips64le@0.13.12(transitive)
- Removedesbuild-linux-ppc64le@0.13.12(transitive)
- Removedesbuild-netbsd-64@0.13.12(transitive)
- Removedesbuild-openbsd-64@0.13.12(transitive)
- Removedesbuild-sunos-64@0.13.12(transitive)
- Removedesbuild-windows-32@0.13.12(transitive)
- Removedesbuild-windows-64@0.13.12(transitive)
- Removedesbuild-windows-arm64@0.13.12(transitive)
Updatedesbuild@0.14.1