wrangler 2.0.5 → 2.0.8
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 +16 -4
- package/package.json +6 -4
- package/pages/functions/buildPlugin.ts +13 -0
- package/pages/functions/buildWorker.ts +13 -0
- package/src/__tests__/configuration.test.ts +335 -86
- package/src/__tests__/dev.test.tsx +166 -15
- package/src/__tests__/helpers/mock-dialogs.ts +41 -1
- package/src/__tests__/index.test.ts +30 -16
- package/src/__tests__/init.test.ts +249 -131
- package/src/__tests__/kv.test.ts +101 -101
- package/src/__tests__/package-manager.test.ts +154 -7
- package/src/__tests__/pages.test.ts +369 -39
- package/src/__tests__/parse.test.ts +5 -1
- package/src/__tests__/publish.test.ts +556 -84
- package/src/__tests__/r2.test.ts +47 -24
- package/src/__tests__/secret.test.ts +39 -4
- package/src/abort.d.ts +3 -0
- package/src/bundle.ts +32 -1
- package/src/cfetch/index.ts +21 -4
- package/src/cfetch/internal.ts +14 -9
- package/src/config/environment.ts +40 -14
- package/src/config/index.ts +162 -0
- package/src/config/validation.ts +179 -64
- package/src/create-worker-preview.ts +17 -7
- package/src/create-worker-upload-form.ts +22 -8
- package/src/dev/dev.tsx +2 -4
- package/src/dev/local.tsx +6 -0
- package/src/dev/remote.tsx +15 -1
- package/src/dialogs.tsx +48 -0
- package/src/durable.ts +102 -0
- package/src/index.tsx +314 -144
- package/src/inspect.ts +39 -0
- package/src/kv.ts +77 -13
- package/src/open-in-browser.ts +5 -12
- package/src/package-manager.ts +50 -3
- package/src/pages.tsx +210 -65
- package/src/parse.ts +21 -4
- package/src/proxy.ts +38 -22
- package/src/publish.ts +227 -113
- package/src/sites.tsx +11 -9
- package/src/worker.ts +8 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.ts +16 -1
- package/wrangler-dist/cli.js +35466 -22362
package/src/durable.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { fetchResult } from "./cfetch";
|
|
3
|
+
import { logger } from "./logger";
|
|
4
|
+
import type { Config } from "./config";
|
|
5
|
+
import type { CfWorkerInit } from "./worker";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* For a given Worker + migrations config, figure out which migrations
|
|
9
|
+
* to upload based on the current migration tag of the deployed Worker.
|
|
10
|
+
*/
|
|
11
|
+
export async function getMigrationsToUpload(
|
|
12
|
+
scriptName: string,
|
|
13
|
+
props: {
|
|
14
|
+
accountId: string | undefined;
|
|
15
|
+
config: Config;
|
|
16
|
+
legacyEnv: boolean | undefined;
|
|
17
|
+
env: string | undefined;
|
|
18
|
+
}
|
|
19
|
+
): Promise<CfWorkerInit["migrations"]> {
|
|
20
|
+
const { config, accountId } = props;
|
|
21
|
+
|
|
22
|
+
assert(accountId, "Missing accountId");
|
|
23
|
+
// if config.migrations
|
|
24
|
+
let migrations;
|
|
25
|
+
if (config.migrations.length > 0) {
|
|
26
|
+
// get current migration tag
|
|
27
|
+
type ScriptData = { id: string; migration_tag?: string };
|
|
28
|
+
let script: ScriptData | undefined;
|
|
29
|
+
if (!props.legacyEnv) {
|
|
30
|
+
try {
|
|
31
|
+
if (props.env) {
|
|
32
|
+
const scriptData = await fetchResult<{
|
|
33
|
+
script: ScriptData;
|
|
34
|
+
}>(
|
|
35
|
+
`/accounts/${accountId}/workers/services/${scriptName}/environments/${props.env}`
|
|
36
|
+
);
|
|
37
|
+
script = scriptData.script;
|
|
38
|
+
} else {
|
|
39
|
+
const scriptData = await fetchResult<{
|
|
40
|
+
default_environment: {
|
|
41
|
+
script: ScriptData;
|
|
42
|
+
};
|
|
43
|
+
}>(`/accounts/${accountId}/workers/services/${scriptName}`);
|
|
44
|
+
script = scriptData.default_environment.script;
|
|
45
|
+
}
|
|
46
|
+
} catch (err) {
|
|
47
|
+
if (
|
|
48
|
+
![
|
|
49
|
+
10090, // corresponds to workers.api.error.service_not_found, so the script wasn't previously published at all
|
|
50
|
+
10092, // workers.api.error.environment_not_found, so the script wasn't published to this environment yet
|
|
51
|
+
].includes((err as { code: number }).code)
|
|
52
|
+
) {
|
|
53
|
+
throw err;
|
|
54
|
+
}
|
|
55
|
+
// else it's a 404, no script found, and we can proceed
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
const scripts = await fetchResult<ScriptData[]>(
|
|
59
|
+
`/accounts/${accountId}/workers/scripts`
|
|
60
|
+
);
|
|
61
|
+
script = scripts.find(({ id }) => id === scriptName);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (script?.migration_tag) {
|
|
65
|
+
// was already published once
|
|
66
|
+
const scriptMigrationTag = script.migration_tag;
|
|
67
|
+
const foundIndex = config.migrations.findIndex(
|
|
68
|
+
(migration) => migration.tag === scriptMigrationTag
|
|
69
|
+
);
|
|
70
|
+
if (foundIndex === -1) {
|
|
71
|
+
logger.warn(
|
|
72
|
+
`The published script ${scriptName} has a migration tag "${script.migration_tag}, which was not found in wrangler.toml. You may have already deleted it. Applying all available migrations to the script...`
|
|
73
|
+
);
|
|
74
|
+
migrations = {
|
|
75
|
+
old_tag: script.migration_tag,
|
|
76
|
+
new_tag: config.migrations[config.migrations.length - 1].tag,
|
|
77
|
+
steps: config.migrations.map(({ tag: _tag, ...rest }) => rest),
|
|
78
|
+
};
|
|
79
|
+
} else {
|
|
80
|
+
if (foundIndex !== config.migrations.length - 1) {
|
|
81
|
+
// there are new migrations to send up
|
|
82
|
+
migrations = {
|
|
83
|
+
old_tag: script.migration_tag,
|
|
84
|
+
new_tag: config.migrations[config.migrations.length - 1].tag,
|
|
85
|
+
steps: config.migrations
|
|
86
|
+
.slice(foundIndex + 1)
|
|
87
|
+
.map(({ tag: _tag, ...rest }) => rest),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// else, we're up to date, no migrations to send
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
// first time publishing durable objects to this script,
|
|
94
|
+
// so we send all the migrations
|
|
95
|
+
migrations = {
|
|
96
|
+
new_tag: config.migrations[config.migrations.length - 1].tag,
|
|
97
|
+
steps: config.migrations.map(({ tag: _tag, ...rest }) => rest),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return migrations;
|
|
102
|
+
}
|