@nightintelligence/cloudflare-workers-utils 0.35.0-patch3 → 0.35.0-patch4
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/dist/browser.mjs +2 -2
- package/dist/browser.mjs.map +1 -1
- package/dist/chunk-47QFQIPP.mjs +180 -0
- package/dist/chunk-47QFQIPP.mjs.map +1 -0
- package/dist/chunk-555CCIJE.mjs +75 -0
- package/dist/chunk-555CCIJE.mjs.map +1 -0
- package/dist/chunk-CGILA3WO.mjs +12 -0
- package/dist/{chunk-PAWJFY3S.mjs.map → chunk-CGILA3WO.mjs.map} +1 -1
- package/dist/chunk-FEHWZI5W.mjs +54 -0
- package/dist/chunk-FEHWZI5W.mjs.map +1 -0
- package/dist/chunk-KAEJMITB.mjs +64 -0
- package/dist/chunk-KAEJMITB.mjs.map +1 -0
- package/dist/chunk-T6I7NOR4.mjs +35 -0
- package/dist/chunk-T6I7NOR4.mjs.map +1 -0
- package/dist/chunk-VTOON473.mjs +237 -0
- package/dist/chunk-VTOON473.mjs.map +1 -0
- package/dist/chunk-W4SU7D4X.mjs +575 -0
- package/dist/chunk-W4SU7D4X.mjs.map +1 -0
- package/dist/chunk-YTEYGQOX.mjs +157 -0
- package/dist/chunk-YTEYGQOX.mjs.map +1 -0
- package/dist/chunk-Z7Q743IF.mjs +477 -0
- package/dist/chunk-Z7Q743IF.mjs.map +1 -0
- package/dist/chunk-ZZBYXY7A.mjs +44 -0
- package/dist/chunk-ZZBYXY7A.mjs.map +1 -0
- package/dist/compatibility-date.mjs +2 -42
- package/dist/compatibility-date.mjs.map +1 -1
- package/dist/compliance.mjs +6 -2
- package/dist/compliance.mjs.map +1 -1
- package/dist/docker-path.mjs +3 -11
- package/dist/docker-path.mjs.map +1 -1
- package/dist/errors.mjs +2 -61
- package/dist/errors.mjs.map +1 -1
- package/dist/fs-helpers.mjs +2 -33
- package/dist/fs-helpers.mjs.map +1 -1
- package/dist/global-wrangler-config-path.mjs +3 -28
- package/dist/global-wrangler-config-path.mjs.map +1 -1
- package/dist/index.mjs +9398 -54
- package/dist/index.mjs.map +1 -1
- package/dist/local-env.mjs +3 -3
- package/dist/local-env.mjs.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/prometheus-metrics.mjs +2 -51
- package/dist/prometheus-metrics.mjs.map +1 -1
- package/dist/test-helpers/index.mjs +307 -7
- package/dist/test-helpers/index.mjs.map +1 -1
- package/dist/zod-format.mjs +2 -235
- package/dist/zod-format.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-PAWJFY3S.mjs +0 -6
package/dist/browser.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { constructWranglerConfig } from './chunk-Z7Q743IF.mjs';
|
|
2
|
+
import './chunk-CGILA3WO.mjs';
|
|
3
3
|
//# sourceMappingURL=browser.mjs.map
|
|
4
4
|
//# sourceMappingURL=browser.mjs.map
|
package/dist/browser.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"browser.mjs"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"browser.mjs"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { getEnvironmentVariableFactory, getBooleanEnvironmentVariableFactory } from './chunk-555CCIJE.mjs';
|
|
2
|
+
import { UserError } from './chunk-KAEJMITB.mjs';
|
|
3
|
+
import { getGlobalConfigPath } from './chunk-YTEYGQOX.mjs';
|
|
4
|
+
import { __name } from './chunk-CGILA3WO.mjs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { dedent } from 'ts-dedent';
|
|
7
|
+
|
|
8
|
+
var getC3CommandFromEnv = getEnvironmentVariableFactory({
|
|
9
|
+
variableName: "WRANGLER_C3_COMMAND",
|
|
10
|
+
defaultValue: /* @__PURE__ */ __name(() => "create cloudflare", "defaultValue")
|
|
11
|
+
});
|
|
12
|
+
var getDoNotTrackFromEnv = getEnvironmentVariableFactory({
|
|
13
|
+
variableName: "DO_NOT_TRACK"
|
|
14
|
+
});
|
|
15
|
+
function isDoNotTrackEnabled() {
|
|
16
|
+
const value = getDoNotTrackFromEnv()?.toLowerCase();
|
|
17
|
+
return value === "1" || value === "true";
|
|
18
|
+
}
|
|
19
|
+
__name(isDoNotTrackEnabled, "isDoNotTrackEnabled");
|
|
20
|
+
var getWranglerSendMetricsVariableFromEnv = getBooleanEnvironmentVariableFactory({
|
|
21
|
+
variableName: "WRANGLER_SEND_METRICS"
|
|
22
|
+
});
|
|
23
|
+
function getWranglerSendMetricsFromEnv() {
|
|
24
|
+
if (isDoNotTrackEnabled()) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return getWranglerSendMetricsVariableFromEnv();
|
|
28
|
+
}
|
|
29
|
+
__name(getWranglerSendMetricsFromEnv, "getWranglerSendMetricsFromEnv");
|
|
30
|
+
var getNoSkillsUpdatePromptsFromEnv = getBooleanEnvironmentVariableFactory({
|
|
31
|
+
variableName: "WRANGLER_NO_SKILLS_UPDATE_PROMPTS"
|
|
32
|
+
});
|
|
33
|
+
var getWranglerSendErrorReportsFromEnv = getBooleanEnvironmentVariableFactory({
|
|
34
|
+
variableName: "WRANGLER_SEND_ERROR_REPORTS",
|
|
35
|
+
defaultValue: false
|
|
36
|
+
});
|
|
37
|
+
var getCloudflareApiEnvironmentFromEnv = getEnvironmentVariableFactory(
|
|
38
|
+
{
|
|
39
|
+
variableName: "WRANGLER_API_ENVIRONMENT",
|
|
40
|
+
defaultValue: /* @__PURE__ */ __name(() => "production", "defaultValue"),
|
|
41
|
+
choices: ["production", "staging"]
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
var COMPLIANCE_REGION_CONFIG_PUBLIC = {
|
|
45
|
+
compliance_region: "public"
|
|
46
|
+
};
|
|
47
|
+
var COMPLIANCE_REGION_CONFIG_UNKNOWN = {
|
|
48
|
+
compliance_region: void 0
|
|
49
|
+
};
|
|
50
|
+
var getCloudflareComplianceRegionFromEnv = getEnvironmentVariableFactory({
|
|
51
|
+
variableName: "CLOUDFLARE_COMPLIANCE_REGION",
|
|
52
|
+
choices: ["public", "fedramp_high"]
|
|
53
|
+
});
|
|
54
|
+
var getCloudflareComplianceRegion = /* @__PURE__ */ __name((complianceConfig) => {
|
|
55
|
+
const complianceRegionFromEnv = getCloudflareComplianceRegionFromEnv();
|
|
56
|
+
if (complianceRegionFromEnv !== void 0 && complianceConfig?.compliance_region !== void 0 && complianceRegionFromEnv !== complianceConfig.compliance_region) {
|
|
57
|
+
throw new UserError(
|
|
58
|
+
dedent`
|
|
59
|
+
The compliance region has been set to different values in two places:
|
|
60
|
+
- \`CLOUDFLARE_COMPLIANCE_REGION\` environment variable: \`${complianceRegionFromEnv}\`
|
|
61
|
+
- \`compliance_region\` configuration property: \`${complianceConfig.compliance_region}\`
|
|
62
|
+
`,
|
|
63
|
+
{ telemetryMessage: false }
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return complianceRegionFromEnv || complianceConfig?.compliance_region || "public";
|
|
67
|
+
}, "getCloudflareComplianceRegion");
|
|
68
|
+
var getCloudflareApiBaseUrlFromEnv = getEnvironmentVariableFactory({
|
|
69
|
+
variableName: "CLOUDFLARE_API_BASE_URL",
|
|
70
|
+
deprecatedName: "CF_API_BASE_URL"
|
|
71
|
+
});
|
|
72
|
+
var getCloudflareApiBaseUrl = /* @__PURE__ */ __name((complianceConfig) => getCloudflareApiBaseUrlFromEnv() ?? `https://api${getComplianceRegionSubdomain(complianceConfig)}${getStagingSubdomain()}.cloudflare.com/client/v4`, "getCloudflareApiBaseUrl");
|
|
73
|
+
function getComplianceRegionSubdomain(complianceConfig) {
|
|
74
|
+
return getCloudflareComplianceRegion(complianceConfig) === "fedramp_high" ? ".fed" : "";
|
|
75
|
+
}
|
|
76
|
+
__name(getComplianceRegionSubdomain, "getComplianceRegionSubdomain");
|
|
77
|
+
function getStagingSubdomain() {
|
|
78
|
+
return getCloudflareApiEnvironmentFromEnv() === "staging" ? ".staging" : "";
|
|
79
|
+
}
|
|
80
|
+
__name(getStagingSubdomain, "getStagingSubdomain");
|
|
81
|
+
var getSanitizeLogs = getBooleanEnvironmentVariableFactory({
|
|
82
|
+
variableName: "WRANGLER_LOG_SANITIZE",
|
|
83
|
+
defaultValue: true
|
|
84
|
+
});
|
|
85
|
+
var getOutputFileDirectoryFromEnv = getEnvironmentVariableFactory({
|
|
86
|
+
variableName: "WRANGLER_OUTPUT_FILE_DIRECTORY"
|
|
87
|
+
});
|
|
88
|
+
var getOutputFilePathFromEnv = getEnvironmentVariableFactory({
|
|
89
|
+
variableName: "WRANGLER_OUTPUT_FILE_PATH"
|
|
90
|
+
});
|
|
91
|
+
var getCIMatchTag = getEnvironmentVariableFactory({
|
|
92
|
+
variableName: "WRANGLER_CI_MATCH_TAG"
|
|
93
|
+
});
|
|
94
|
+
var getCIOverrideName = getEnvironmentVariableFactory({
|
|
95
|
+
variableName: "WRANGLER_CI_OVERRIDE_NAME"
|
|
96
|
+
});
|
|
97
|
+
var getCIOverrideNetworkModeHost = getEnvironmentVariableFactory({
|
|
98
|
+
variableName: "WRANGLER_CI_OVERRIDE_NETWORK_MODE_HOST"
|
|
99
|
+
});
|
|
100
|
+
var getCIGeneratePreviewAlias = getEnvironmentVariableFactory({
|
|
101
|
+
variableName: "WRANGLER_CI_GENERATE_PREVIEW_ALIAS",
|
|
102
|
+
defaultValue: /* @__PURE__ */ __name(() => "false", "defaultValue"),
|
|
103
|
+
choices: ["true", "false"]
|
|
104
|
+
});
|
|
105
|
+
var getWorkersCIBranchName = getEnvironmentVariableFactory({
|
|
106
|
+
variableName: "WORKERS_CI_BRANCH"
|
|
107
|
+
});
|
|
108
|
+
var getBuildConditionsFromEnv = getEnvironmentVariableFactory({
|
|
109
|
+
variableName: "WRANGLER_BUILD_CONDITIONS"
|
|
110
|
+
});
|
|
111
|
+
var getBuildPlatformFromEnv = getEnvironmentVariableFactory({
|
|
112
|
+
variableName: "WRANGLER_BUILD_PLATFORM"
|
|
113
|
+
});
|
|
114
|
+
var getRegistryPath = getEnvironmentVariableFactory({
|
|
115
|
+
variableName: "WRANGLER_REGISTRY_PATH",
|
|
116
|
+
defaultValue() {
|
|
117
|
+
return path.join(getGlobalConfigPath(), "registry");
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
var getD1ExtraLocationChoices = getEnvironmentVariableFactory({
|
|
121
|
+
variableName: "WRANGLER_D1_EXTRA_LOCATION_CHOICES"
|
|
122
|
+
});
|
|
123
|
+
var getSubdomainMixedStateCheckDisabled = getBooleanEnvironmentVariableFactory({
|
|
124
|
+
variableName: "WRANGLER_DISABLE_SUBDOMAIN_MIXED_STATE_CHECK",
|
|
125
|
+
defaultValue: false
|
|
126
|
+
});
|
|
127
|
+
var getCloudflareLoadDevVarsFromDotEnv = getBooleanEnvironmentVariableFactory({
|
|
128
|
+
variableName: "CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV",
|
|
129
|
+
defaultValue: true
|
|
130
|
+
});
|
|
131
|
+
var getCloudflareIncludeProcessEnvFromEnv = getBooleanEnvironmentVariableFactory({
|
|
132
|
+
variableName: "CLOUDFLARE_INCLUDE_PROCESS_ENV",
|
|
133
|
+
defaultValue: false
|
|
134
|
+
});
|
|
135
|
+
var getTraceHeader = getEnvironmentVariableFactory({
|
|
136
|
+
variableName: "WRANGLER_TRACE_ID"
|
|
137
|
+
});
|
|
138
|
+
var getDisableConfigWatching = getBooleanEnvironmentVariableFactory({
|
|
139
|
+
variableName: "WRANGLER_CI_DISABLE_CONFIG_WATCHING",
|
|
140
|
+
defaultValue: false
|
|
141
|
+
});
|
|
142
|
+
var getWranglerHideBanner = getBooleanEnvironmentVariableFactory({
|
|
143
|
+
variableName: "WRANGLER_HIDE_BANNER",
|
|
144
|
+
defaultValue: false
|
|
145
|
+
});
|
|
146
|
+
var getCloudflareEnv = getEnvironmentVariableFactory({
|
|
147
|
+
variableName: "CLOUDFLARE_ENV"
|
|
148
|
+
});
|
|
149
|
+
var getOpenNextDeployFromEnv = getEnvironmentVariableFactory({
|
|
150
|
+
variableName: "OPEN_NEXT_DEPLOY"
|
|
151
|
+
});
|
|
152
|
+
var getLocalExplorerEnabledFromEnv = getBooleanEnvironmentVariableFactory({
|
|
153
|
+
variableName: "X_LOCAL_EXPLORER",
|
|
154
|
+
defaultValue: true
|
|
155
|
+
});
|
|
156
|
+
var getLocalObservabilityEnabledFromEnv = getBooleanEnvironmentVariableFactory({
|
|
157
|
+
variableName: "X_LOCAL_OBSERVABILITY",
|
|
158
|
+
defaultValue: true
|
|
159
|
+
});
|
|
160
|
+
var getBrowserRenderingHeadfulFromEnv = getBooleanEnvironmentVariableFactory({
|
|
161
|
+
variableName: "X_BROWSER_HEADFUL",
|
|
162
|
+
defaultValue: false
|
|
163
|
+
});
|
|
164
|
+
var getCfFetchEnabledFromEnv = getBooleanEnvironmentVariableFactory({
|
|
165
|
+
variableName: "CLOUDFLARE_CF_FETCH_ENABLED",
|
|
166
|
+
defaultValue: true
|
|
167
|
+
});
|
|
168
|
+
var getCfFetchPathFromEnv = getEnvironmentVariableFactory({
|
|
169
|
+
variableName: "CLOUDFLARE_CF_FETCH_PATH"
|
|
170
|
+
});
|
|
171
|
+
var getWranglerCacheDirFromEnv = getEnvironmentVariableFactory({
|
|
172
|
+
variableName: "WRANGLER_CACHE_DIR"
|
|
173
|
+
});
|
|
174
|
+
var getCloudflaredPathFromEnv = getEnvironmentVariableFactory({
|
|
175
|
+
variableName: "CLOUDFLARED_PATH"
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
export { COMPLIANCE_REGION_CONFIG_PUBLIC, COMPLIANCE_REGION_CONFIG_UNKNOWN, getBrowserRenderingHeadfulFromEnv, getBuildConditionsFromEnv, getBuildPlatformFromEnv, getC3CommandFromEnv, getCIGeneratePreviewAlias, getCIMatchTag, getCIOverrideName, getCIOverrideNetworkModeHost, getCfFetchEnabledFromEnv, getCfFetchPathFromEnv, getCloudflareApiBaseUrl, getCloudflareApiEnvironmentFromEnv, getCloudflareComplianceRegion, getCloudflareEnv, getCloudflareIncludeProcessEnvFromEnv, getCloudflareLoadDevVarsFromDotEnv, getCloudflaredPathFromEnv, getComplianceRegionSubdomain, getD1ExtraLocationChoices, getDisableConfigWatching, getLocalExplorerEnabledFromEnv, getLocalObservabilityEnabledFromEnv, getNoSkillsUpdatePromptsFromEnv, getOpenNextDeployFromEnv, getOutputFileDirectoryFromEnv, getOutputFilePathFromEnv, getRegistryPath, getSanitizeLogs, getSubdomainMixedStateCheckDisabled, getTraceHeader, getWorkersCIBranchName, getWranglerCacheDirFromEnv, getWranglerHideBanner, getWranglerSendErrorReportsFromEnv, getWranglerSendMetricsFromEnv, isDoNotTrackEnabled };
|
|
179
|
+
//# sourceMappingURL=chunk-47QFQIPP.mjs.map
|
|
180
|
+
//# sourceMappingURL=chunk-47QFQIPP.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/environment-variables/misc-variables.ts"],"names":[],"mappings":";;;;;;;AAkCO,IAAM,sBAAsB,6BAAA,CAA8B;AAAA,EAChE,YAAA,EAAc,qBAAA;AAAA,EACd,YAAA,+BAAoB,mBAAA,EAAN,cAAA;AACf,CAAC;AAED,IAAM,uBAAuB,6BAAA,CAA8B;AAAA,EAC1D,YAAA,EAAc;AACf,CAAC,CAAA;AAGM,SAAS,mBAAA,GAA+B;AAC9C,EAAA,MAAM,KAAA,GAAQ,oBAAA,EAAqB,EAAG,WAAA,EAAY;AAClD,EAAA,OAAO,KAAA,KAAU,OAAO,KAAA,KAAU,MAAA;AACnC;AAHgB,MAAA,CAAA,mBAAA,EAAA,qBAAA,CAAA;AAKhB,IAAM,wCACL,oCAAA,CAAqC;AAAA,EACpC,YAAA,EAAc;AACf,CAAC,CAAA;AAMK,SAAS,6BAAA,GAAqD;AACpE,EAAA,IAAI,qBAAoB,EAAG;AAC1B,IAAA,OAAO,KAAA;AA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,sCACZ,oCAAA,CAAqC;AAAA,EACpC,YAAA,EAAc,uBAAA;AAAA,EACd,YAAA,EAAc;AACf,CAAC;AAgBK,IAAM,oCACZ,oCAAA,CAAqC;AAAA,EACpC,YAAA,EAAc,mBAAA;AAAA,EACd,YAAA,EAAc;AACf,CAAC;AAkBK,IAAM,2BAA2B,oCAAA,CAAqC;AAAA,EAC5E,YAAA,EAAc,6BAAA;AAAA,EACd,YAAA,EAAc;AACf,CAAC;AAcM,IAAM,wBAAwB,6BAAA,CAA8B;AAAA,EAClE,YAAA,EAAc;AACf,CAAC;AAOM,IAAM,6BAA6B,6BAAA,CAA8B;AAAA,EACvE,YAAA,EAAc;AACf,CAAC;AAQM,IAAM,4BAA4B,6BAAA,CAA8B;AAAA,EACtE,YAAA,EAAc;AACf,CAAC","file":"chunk-47QFQIPP.mjs","sourcesContent":["import path from \"node:path\";\nimport { dedent } from \"ts-dedent\";\nimport { UserError } from \"../errors\";\nimport { getGlobalConfigPath } from \"../global-wrangler-config-path\";\nimport {\n\tgetBooleanEnvironmentVariableFactory,\n\tgetEnvironmentVariableFactory,\n} from \"./factory\";\nimport type { Config } from \"../config\";\n\n/**\n * `WRANGLER_C3_COMMAND` can override the command used by `wrangler init` when delegating to C3.\n *\n * By default this will use `create cloudflare`.\n *\n * To run against the beta release of C3 use:\n *\n * ```sh\n * # Tell Wrangler to use the beta version of create-cloudflare\n * WRANGLER_C3_COMMAND=\"create cloudflare@beta\" npx wrangler init\n * ```\n *\n * To test the integration between wrangler and C3 locally, use:\n *\n * ```sh\n * # Ensure both Wrangler and C3 are built\n * npm run build\n * # Tell Wrangler to use the local version of create-cloudflare\n * WRANGLER_C3_COMMAND=\"exec ./packages/create-cloudflare\" npx wrangler init temp\n * ```\n *\n * Note that you cannot use `WRANGLER_C3_COMMAND=\"create cloudflare@2\"` if you are\n * running Wrangler from inside the monorepo as the bin paths get messed up.\n */\nexport const getC3CommandFromEnv = getEnvironmentVariableFactory({\n\tvariableName: \"WRANGLER_C3_COMMAND\",\n\tdefaultValue: () => \"create cloudflare\",\n});\n\nconst getDoNotTrackFromEnv = getEnvironmentVariableFactory({\n\tvariableName: \"DO_NOT_TRACK\",\n});\n\n/** Whether `DO_NOT_TRACK` is set to a supported telemetry opt-out value. */\nexport function isDoNotTrackEnabled(): boolean {\n\tconst value = getDoNotTrackFromEnv()?.toLowerCase();\n\treturn value === \"1\" || value === \"true\";\n}\n\nconst getWranglerSendMetricsVariableFromEnv =\n\tgetBooleanEnvironmentVariableFactory({\n\t\tvariableName: \"WRANGLER_SEND_METRICS\",\n\t});\n\n/**\n * `WRANGLER_SEND_METRICS` controls whether we attempt to send metrics information to Sparrow.\n * `DO_NOT_TRACK` takes precedence when it is set to an opt-out value.\n */\nexport function getWranglerSendMetricsFromEnv(): boolean | undefined {\n\tif (isDoNotTrackEnabled()) {\n\t\treturn false;\n\t}\n\n\treturn getWranglerSendMetricsVariableFromEnv();\n}\n\n/**\n * `WRANGLER_NO_SKILLS_UPDATE_PROMPTS` suppresses the prompt that offers to\n * update Cloudflare agent skills when they are out of date.\n *\n * Set to `\"true\"` to never be prompted for skills updates.\n */\nexport const getNoSkillsUpdatePromptsFromEnv =\n\tgetBooleanEnvironmentVariableFactory({\n\t\tvariableName: \"WRANGLER_NO_SKILLS_UPDATE_PROMPTS\",\n\t});\n\n/**\n * `WRANGLER_SEND_ERROR_REPORTS` controls whether we attempt to send error reports to Sentry.\n *\n * Defaults to `false` to avoid noisy false-positive reports. Users can opt in\n * by setting `WRANGLER_SEND_ERROR_REPORTS=true`.\n */\nexport const getWranglerSendErrorReportsFromEnv =\n\tgetBooleanEnvironmentVariableFactory({\n\t\tvariableName: \"WRANGLER_SEND_ERROR_REPORTS\",\n\t\tdefaultValue: false,\n\t});\n\n/**\n * Set `WRANGLER_API_ENVIRONMENT` environment variable to \"staging\" to tell Wrangler to hit the staging APIs rather than production.\n */\nexport const getCloudflareApiEnvironmentFromEnv = getEnvironmentVariableFactory(\n\t{\n\t\tvariableName: \"WRANGLER_API_ENVIRONMENT\",\n\t\tdefaultValue: () => \"production\" as const,\n\t\tchoices: [\"production\", \"staging\"] as const,\n\t}\n);\n\n/**\n * The compliance region to use for the API requests.\n */\nexport type ComplianceConfig = Partial<Pick<Config, \"compliance_region\">>;\n\n/** Used for commands that explicitly do not support compliance regions other than \"public\" */\nexport const COMPLIANCE_REGION_CONFIG_PUBLIC: ComplianceConfig = {\n\tcompliance_region: \"public\",\n};\n\n/**\n * Used for commands where there is no configuration available and\n * we rely upon the CLOUDFLARE_COMPLIANCE_REGION environment variable\n * to determine the compliance region.\n */\nexport const COMPLIANCE_REGION_CONFIG_UNKNOWN: ComplianceConfig = {\n\tcompliance_region: undefined,\n};\n\nconst getCloudflareComplianceRegionFromEnv = getEnvironmentVariableFactory({\n\tvariableName: \"CLOUDFLARE_COMPLIANCE_REGION\",\n\tchoices: [\"public\", \"fedramp_high\"] as const,\n});\n\n/**\n * Set `CLOUDFLARE_COMPLIANCE_REGION` environment variable to \"fedramp_high\"\n * or set the `compliance_region` property in the Wrangler configuration\n * to tell Wrangler to run in FedRAMP High compliance region mode, rather than \"public\" mode.\n */\nexport const getCloudflareComplianceRegion = (\n\tcomplianceConfig: ComplianceConfig\n) => {\n\tconst complianceRegionFromEnv = getCloudflareComplianceRegionFromEnv();\n\tif (\n\t\tcomplianceRegionFromEnv !== undefined &&\n\t\tcomplianceConfig?.compliance_region !== undefined &&\n\t\tcomplianceRegionFromEnv !== complianceConfig.compliance_region\n\t) {\n\t\tthrow new UserError(\n\t\t\tdedent`\n\t\t\tThe compliance region has been set to different values in two places:\n\t\t\t - \\`CLOUDFLARE_COMPLIANCE_REGION\\` environment variable: \\`${complianceRegionFromEnv}\\`\n\t\t\t - \\`compliance_region\\` configuration property: \\`${complianceConfig.compliance_region}\\`\n\t\t\t`,\n\t\t\t{ telemetryMessage: false }\n\t\t);\n\t}\n\treturn (\n\t\tcomplianceRegionFromEnv || complianceConfig?.compliance_region || \"public\"\n\t);\n};\n\nconst getCloudflareApiBaseUrlFromEnv = getEnvironmentVariableFactory({\n\tvariableName: \"CLOUDFLARE_API_BASE_URL\",\n\tdeprecatedName: \"CF_API_BASE_URL\",\n});\n\n/**\n * `CLOUDFLARE_API_BASE_URL` specifies the URL to the Cloudflare API.\n *\n * If this environment variable is not set, it will default to a URL computed from the\n * Cloudflare compliance region and the API environment.\n */\nexport const getCloudflareApiBaseUrl = (complianceConfig: ComplianceConfig) =>\n\tgetCloudflareApiBaseUrlFromEnv() ??\n\t`https://api${getComplianceRegionSubdomain(complianceConfig)}${getStagingSubdomain()}.cloudflare.com/client/v4`;\n\n/**\n * Compute the subdomain for the compliance region.\n */\nexport function getComplianceRegionSubdomain(\n\tcomplianceConfig: ComplianceConfig\n): string {\n\treturn getCloudflareComplianceRegion(complianceConfig) === \"fedramp_high\"\n\t\t? \".fed\"\n\t\t: \"\";\n}\n\n/**\n * Compute the subdomain for the staging environment.\n */\nfunction getStagingSubdomain(): string {\n\treturn getCloudflareApiEnvironmentFromEnv() === \"staging\" ? \".staging\" : \"\";\n}\n\n/**\n * `WRANGLER_LOG_SANITIZE` specifies whether we sanitize debug logs.\n *\n * By default we do, since debug logs could be added to GitHub issues and shouldn't include sensitive information.\n */\nexport const getSanitizeLogs = getBooleanEnvironmentVariableFactory({\n\tvariableName: \"WRANGLER_LOG_SANITIZE\",\n\tdefaultValue: true,\n});\n\n/**\n * `WRANGLER_OUTPUT_FILE_DIRECTORY` specifies a directory where we should write a file containing output data in ND-JSON format.\n *\n * If this is set a random file will be created in this directory, and certain Wrangler commands will write entries to this file.\n * This is overridden by the `WRANGLER_OUTPUT_FILE_PATH` environment variable.\n */\nexport const getOutputFileDirectoryFromEnv = getEnvironmentVariableFactory({\n\tvariableName: \"WRANGLER_OUTPUT_FILE_DIRECTORY\",\n});\n\n/**\n * `WRANGLER_OUTPUT_FILE_PATH` specifies a path to a file where we should write output data in ND-JSON format.\n *\n * If this is set certain Wrangler commands will write entries to this file.\n * This overrides the `WRANGLER_OUTPUT_FILE_DIRECTORY` environment variable.\n */\nexport const getOutputFilePathFromEnv = getEnvironmentVariableFactory({\n\tvariableName: \"WRANGLER_OUTPUT_FILE_PATH\",\n});\n\n/**\n * `WRANGLER_CI_MATCH_TAG` specifies a Worker tag\n *\n * If this is set, Wrangler will ensure the Worker being targeted has this tag\n */\nexport const getCIMatchTag = getEnvironmentVariableFactory({\n\tvariableName: \"WRANGLER_CI_MATCH_TAG\",\n});\n\n/**\n * `WRANGLER_CI_OVERRIDE_NAME` specifies a Worker name\n *\n * If this is set, Wrangler will override the Worker name with this one\n */\nexport const getCIOverrideName = getEnvironmentVariableFactory({\n\tvariableName: \"WRANGLER_CI_OVERRIDE_NAME\",\n});\n\n/**\n * `WRANGLER_CI_OVERRIDE_NETWORK_MODE_HOST` specifies whether --network=host should be set\n *\n * If this is set to true, Wrangler will use the --network=host flag when calling out to docker to build container images\n */\nexport const getCIOverrideNetworkModeHost = getEnvironmentVariableFactory({\n\tvariableName: \"WRANGLER_CI_OVERRIDE_NETWORK_MODE_HOST\",\n});\n\n/**\n * `WRANGLER_CI_GENERATE_PREVIEW_ALIAS` specifies whether to generate a preview alias during version upload\n *\n * If this is set to true, Wrangler will attempt to autogenerate the preview alias by using the branch\n * name. If the branch name is too long and an alias cannot be created, a warning will be printed to the console.\n */\nexport const getCIGeneratePreviewAlias = getEnvironmentVariableFactory({\n\tvariableName: \"WRANGLER_CI_GENERATE_PREVIEW_ALIAS\",\n\tdefaultValue: () => \"false\" as const,\n\tchoices: [\"true\", \"false\"] as const,\n});\n\n/**\n * `WORKERS_CI_BRANCH` is the branch name exposed by Workers CI\n *\n */\nexport const getWorkersCIBranchName = getEnvironmentVariableFactory({\n\tvariableName: \"WORKERS_CI_BRANCH\",\n});\n\n/**\n * `WRANGLER_BUILD_CONDITIONS` specifies the \"build conditions\" to use when importing packages at build time.\n *\n * See https://nodejs.org/api/packages.html#conditional-exports\n * and https://esbuild.github.io/api/#how-conditions-work.\n *\n * If this is set, Wrangler will configure esbuild to use this list of conditions.\n * The format is a string of comma separated conditions.\n */\nexport const getBuildConditionsFromEnv = getEnvironmentVariableFactory({\n\tvariableName: \"WRANGLER_BUILD_CONDITIONS\",\n});\n\n/**\n * `WRANGLER_BUILD_PLATFORM` specifies the \"build platform\" to use when importing packages at build time.\n *\n * See https://esbuild.github.io/api/#platform\n * and https://esbuild.github.io/api/#how-conditions-work.\n *\n * If this is set, Wrangler will configure esbuild to use this platform.\n */\nexport const getBuildPlatformFromEnv = getEnvironmentVariableFactory({\n\tvariableName: \"WRANGLER_BUILD_PLATFORM\",\n});\n\n/**\n * `WRANGLER_REGISTRY_PATH` specifies the file based dev registry folder\n */\nexport const getRegistryPath = getEnvironmentVariableFactory({\n\tvariableName: \"WRANGLER_REGISTRY_PATH\",\n\tdefaultValue() {\n\t\treturn path.join(getGlobalConfigPath(), \"registry\");\n\t},\n});\n\n/**\n * `WRANGLER_D1_EXTRA_LOCATION_CHOICES` is an internal variable to let D1 team target their testing environments.\n *\n * External accounts cannot access testing environments, so should not set this variable.\n */\nexport const getD1ExtraLocationChoices: () => string | undefined =\n\tgetEnvironmentVariableFactory({\n\t\tvariableName: \"WRANGLER_D1_EXTRA_LOCATION_CHOICES\",\n\t});\n\n/**\n * `WRANGLER_DOCKER_BIN` specifies the path to a docker binary.\n *\n * By default it's `docker`.\n */\nexport { getDockerPath } from \"../docker-path\";\n\nexport const getSubdomainMixedStateCheckDisabled =\n\tgetBooleanEnvironmentVariableFactory({\n\t\tvariableName: \"WRANGLER_DISABLE_SUBDOMAIN_MIXED_STATE_CHECK\",\n\t\tdefaultValue: false,\n\t});\n\n/**\n/**\n * `CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV` specifies whether to load vars for local dev from `.env` files.\n */\nexport const getCloudflareLoadDevVarsFromDotEnv =\n\tgetBooleanEnvironmentVariableFactory({\n\t\tvariableName: \"CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV\",\n\t\tdefaultValue: true,\n\t});\n\n/**\n * `CLOUDFLARE_INCLUDE_PROCESS_ENV` specifies whether to include the `process.env` in vars loaded from `.env` for local development.\n */\nexport const getCloudflareIncludeProcessEnvFromEnv =\n\tgetBooleanEnvironmentVariableFactory({\n\t\tvariableName: \"CLOUDFLARE_INCLUDE_PROCESS_ENV\",\n\t\tdefaultValue: false,\n\t});\n\nexport const getTraceHeader = getEnvironmentVariableFactory({\n\tvariableName: \"WRANGLER_TRACE_ID\",\n});\n\nexport const getDisableConfigWatching = getBooleanEnvironmentVariableFactory({\n\tvariableName: \"WRANGLER_CI_DISABLE_CONFIG_WATCHING\",\n\tdefaultValue: false,\n});\n\n/**\n * Hide the Wrangler version banner and command status (deprecated/experimental) warnings\n */\nexport const getWranglerHideBanner = getBooleanEnvironmentVariableFactory({\n\tvariableName: \"WRANGLER_HIDE_BANNER\",\n\tdefaultValue: false,\n});\n\n/**\n * `CLOUDFLARE_ENV` specifies the currently selected Wrangler/Cloudflare environment.\n */\nexport const getCloudflareEnv = getEnvironmentVariableFactory({\n\tvariableName: \"CLOUDFLARE_ENV\",\n});\n\n/**\n * `OPEN_NEXT_DEPLOY` is an environment variables that indicates that the current process is being\n * run by the open-next deploy command\n */\nexport const getOpenNextDeployFromEnv = getEnvironmentVariableFactory({\n\tvariableName: \"OPEN_NEXT_DEPLOY\",\n});\n\n/**\n * `X_LOCAL_EXPLORER` enables the local explorer UI at /cdn-cgi/local/explorer.\n */\nexport const getLocalExplorerEnabledFromEnv =\n\tgetBooleanEnvironmentVariableFactory({\n\t\tvariableName: \"X_LOCAL_EXPLORER\",\n\t\tdefaultValue: true,\n\t});\n\n/**\n * `X_LOCAL_OBSERVABILITY` turns on local-dev observability capture. Both\n * `wrangler dev` and the Vite plugin read it and pass it through as the one\n * `unsafeObservability` Miniflare option, which makes core attach the trace\n * collector to each user worker.\n *\n * Defaults to `true` so the Local Explorer's Observability tab captures traces\n * and logs out of the box. Set `X_LOCAL_OBSERVABILITY=false` to opt out — for\n * example if the extra per-worker services (collector + streaming tail) cause\n * trouble in a multi-process dev-registry setup.\n */\nexport const getLocalObservabilityEnabledFromEnv =\n\tgetBooleanEnvironmentVariableFactory({\n\t\tvariableName: \"X_LOCAL_OBSERVABILITY\",\n\t\tdefaultValue: true,\n\t});\n\n/**\n * `X_BROWSER_HEADFUL` opens the browser in headful (visible) mode when using the\n * Browser Run API in local development.\n *\n * Set to \"true\" to enable:\n *\n * ```sh\n * X_BROWSER_HEADFUL=true vite dev\n * ```\n *\n * Note: when using `@cloudflare/playwright`, two Chrome windows may appear — the initial blank\n * page and the one created by `browser.newPage()`. This is expected due to how Playwright handles\n * browser contexts via CDP.\n */\nexport const getBrowserRenderingHeadfulFromEnv =\n\tgetBooleanEnvironmentVariableFactory({\n\t\tvariableName: \"X_BROWSER_HEADFUL\",\n\t\tdefaultValue: false,\n\t});\n\n/**\n * `CLOUDFLARE_CF_FETCH_ENABLED` controls whether Miniflare fetches the `cf.json` file\n * containing request.cf properties from workers.cloudflare.com.\n *\n * - If set to \"false\", disables fetching and uses fallback data (no files created)\n * - If set to \"true\" or not set, uses the default behavior (fetches and caches cf.json)\n *\n * This is particularly useful for non-JavaScript projects that don't want\n * a node_modules directory created automatically.\n *\n * Example:\n * ```sh\n * # Disable cf fetching entirely\n * CLOUDFLARE_CF_FETCH_ENABLED=false npx wrangler dev\n * ```\n */\nexport const getCfFetchEnabledFromEnv = getBooleanEnvironmentVariableFactory({\n\tvariableName: \"CLOUDFLARE_CF_FETCH_ENABLED\",\n\tdefaultValue: true,\n});\n\n/**\n * `CLOUDFLARE_CF_FETCH_PATH` specifies a custom path for caching the cf.json file.\n *\n * - If set, uses the specified path instead of the default node_modules/.mf/cf.json\n * - If not set, uses the default location (node_modules/.mf/cf.json)\n *\n * Example:\n * ```sh\n * # Use a custom cache location\n * CLOUDFLARE_CF_FETCH_PATH=/tmp/cf-cache.json npx wrangler dev\n * ```\n */\nexport const getCfFetchPathFromEnv = getEnvironmentVariableFactory({\n\tvariableName: \"CLOUDFLARE_CF_FETCH_PATH\",\n});\n\n/**\n * `WRANGLER_CACHE_DIR` specifies a custom directory for Wrangler's cache files.\n * This overrides the default `node_modules/.cache/wrangler` location.\n * Useful for Yarn PnP or projects without node_modules.\n */\nexport const getWranglerCacheDirFromEnv = getEnvironmentVariableFactory({\n\tvariableName: \"WRANGLER_CACHE_DIR\",\n});\n\n/**\n * `CLOUDFLARED_PATH` specifies a custom path to a cloudflared binary.\n *\n * If set, Wrangler will use this cloudflared binary instead of downloading one.\n * The path must point to an existing executable file.\n */\nexport const getCloudflaredPathFromEnv = getEnvironmentVariableFactory({\n\tvariableName: \"CLOUDFLARED_PATH\",\n});\n"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { UserError } from './chunk-KAEJMITB.mjs';
|
|
2
|
+
import { __name } from './chunk-CGILA3WO.mjs';
|
|
3
|
+
|
|
4
|
+
// src/environment-variables/factory.ts
|
|
5
|
+
function getBooleanEnvironmentVariableFactory(options) {
|
|
6
|
+
return () => {
|
|
7
|
+
if (!(options.variableName in process.env) || process.env[options.variableName] === void 0) {
|
|
8
|
+
return typeof options.defaultValue === "function" ? options.defaultValue() : options.defaultValue;
|
|
9
|
+
}
|
|
10
|
+
switch (process.env[options.variableName]?.toLowerCase()) {
|
|
11
|
+
case "true":
|
|
12
|
+
return true;
|
|
13
|
+
case "false":
|
|
14
|
+
return false;
|
|
15
|
+
default:
|
|
16
|
+
throw new UserError(
|
|
17
|
+
`Expected ${options.variableName} to be "true" or "false", but got ${JSON.stringify(
|
|
18
|
+
process.env[options.variableName]
|
|
19
|
+
)}`,
|
|
20
|
+
{ telemetryMessage: false }
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
__name(getBooleanEnvironmentVariableFactory, "getBooleanEnvironmentVariableFactory");
|
|
26
|
+
function getEnvironmentVariableFactory({
|
|
27
|
+
variableName,
|
|
28
|
+
deprecatedName,
|
|
29
|
+
choices,
|
|
30
|
+
defaultValue
|
|
31
|
+
}) {
|
|
32
|
+
let hasWarned = false;
|
|
33
|
+
return () => {
|
|
34
|
+
if (variableName in process.env) {
|
|
35
|
+
return getProcessEnv(variableName, choices);
|
|
36
|
+
}
|
|
37
|
+
if (deprecatedName && deprecatedName in process.env) {
|
|
38
|
+
if (!hasWarned) {
|
|
39
|
+
hasWarned = true;
|
|
40
|
+
console.warn(
|
|
41
|
+
`Using "${deprecatedName}" environment variable. This is deprecated. Please use "${variableName}", instead.`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return getProcessEnv(deprecatedName, choices);
|
|
45
|
+
}
|
|
46
|
+
return defaultValue?.();
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
__name(getEnvironmentVariableFactory, "getEnvironmentVariableFactory");
|
|
50
|
+
function getProcessEnv(variableName, choices) {
|
|
51
|
+
assertOneOf(choices, process.env[variableName]);
|
|
52
|
+
return process.env[variableName];
|
|
53
|
+
}
|
|
54
|
+
__name(getProcessEnv, "getProcessEnv");
|
|
55
|
+
function assertOneOf(choices, value) {
|
|
56
|
+
if (Array.isArray(choices) && !choices.includes(value)) {
|
|
57
|
+
throw new UserError(
|
|
58
|
+
`Expected ${JSON.stringify(value)} to be one of ${JSON.stringify(choices)}`,
|
|
59
|
+
{ telemetryMessage: false }
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
__name(assertOneOf, "assertOneOf");
|
|
64
|
+
|
|
65
|
+
// src/docker-path.ts
|
|
66
|
+
var getDockerPath = getEnvironmentVariableFactory({
|
|
67
|
+
variableName: "WRANGLER_DOCKER_BIN",
|
|
68
|
+
defaultValue() {
|
|
69
|
+
return "docker";
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export { getBooleanEnvironmentVariableFactory, getDockerPath, getEnvironmentVariableFactory };
|
|
74
|
+
//# sourceMappingURL=chunk-555CCIJE.mjs.map
|
|
75
|
+
//# sourceMappingURL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wrangler for configuration and authentication.\n * Each variable is documented with its individual JSDoc comment below.\n */\ntype VariableNames =\n\t// ## Authentication & API Configuration\n\n\t/** Overrides the account ID for API requests. Can also be set in Wrangler config via `account_id` field. */\n\t| \"CLOUDFLARE_ACCOUNT_ID\"\n\t/** API token for authentication. Preferred over API key + email. */\n\t| \"CLOUDFLARE_API_TOKEN\"\n\t/** Legacy API key for authentication. Requires CLOUDFLARE_EMAIL. It is preferred to use `CLOUDFLARE_API_TOKEN`. */\n\t| \"CLOUDFLARE_API_KEY\"\n\t/** Email address for API key authentication. Used with `CLOUDFLARE_API_KEY`. It is preferred to use `CLOUDFLARE_API_TOKEN`. */\n\t| \"CLOUDFLARE_EMAIL\"\n\t/** Custom API base URL. Defaults to https://api.cloudflare.com/client/v4 */\n\t| \"CLOUDFLARE_API_BASE_URL\"\n\t/** Set to \"fedramp_high\" for FedRAMP High compliance region. This will update the API/AUTH URLs used to make requests to Cloudflare. */\n\t| \"CLOUDFLARE_COMPLIANCE_REGION\"\n\t/** API token for R2 SQL service. */\n\t| \"WRANGLER_R2_SQL_AUTH_TOKEN\"\n\n\t// ## Development & Local Testing\n\n\t/** Controls whether to fetch the cf.json file. Set to \"false\" or \"0\" to disable fetching and use fallback data. Defaults to \"true\". */\n\t| \"CLOUDFLARE_CF_FETCH_ENABLED\"\n\t/** Custom path for caching the cf.json file. Overrides the default node_modules/.mf/cf.json location. */\n\t| \"CLOUDFLARE_CF_FETCH_PATH\"\n\t/** Local database connection strings for Hyperdrive development. The * should be replaced with the Hyperdrive binding name in the Worker. */\n\t| `CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_${string}`\n\t/** Suppress Hyperdrive-related warnings during development. */\n\t| \"NO_HYPERDRIVE_WARNING\"\n\t/** Path to HTTPS private key file for running the local development server in HTTPS mode. Without this Wrangler will generate keys automatically. */\n\t| \"WRANGLER_HTTPS_KEY_PATH\"\n\t/** Path to HTTPS certificate file for running the local development server in HTTPS mode. Without this Wrangler will generate keys automatically. */\n\t| \"WRANGLER_HTTPS_CERT_PATH\"\n\t/** Load development variables from .env files (default: true). */\n\t| \"CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV\"\n\t/** Include process.env in development variables (default: false). */\n\t| \"CLOUDFLARE_INCLUDE_PROCESS_ENV\"\n\t/** Include a trace header in all API requests that Wrangler makes (for internal use only) */\n\t| \"WRANGLER_TRACE_ID\"\n\t/** Disable the check for mixed state of subdomain flags (`workers_dev`, `preview_urls`, etc.) (default: false). */\n\t| \"WRANGLER_DISABLE_SUBDOMAIN_MIXED_STATE_CHECK\"\n\n\t// ## Logging & Output\n\n\t/** Set log level: \"debug\", \"info\", \"log\", \"warn\", \"error\". */\n\t| \"WRANGLER_LOG\"\n\t/** Directory for debug log files. */\n\t| \"WRANGLER_LOG_PATH\"\n\t/** Sanitize sensitive data in debug logs (default: true). */\n\t| \"WRANGLER_LOG_SANITIZE\"\n\t/** Directory for ND-JSON output files. */\n\t| \"WRANGLER_OUTPUT_FILE_DIRECTORY\"\n\t/** Hide the Wrangler version banner */\n\t| \"WRANGLER_HIDE_BANNER\"\n\n\t// ## Build & Deployment Configuration\n\n\t/** Specific path for ND-JSON output file. */\n\t| \"WRANGLER_OUTPUT_FILE_PATH\"\n\t/** Comma-separated list of build conditions for esbuild. */\n\t| \"WRANGLER_BUILD_CONDITIONS\"\n\t/** Build platform for esbuild (e.g., \"node\", \"browser\"). */\n\t| \"WRANGLER_BUILD_PLATFORM\"\n\t/** Path to file-based dev registry folder. */\n\t| \"WRANGLER_REGISTRY_PATH\"\n\t/** Additional D1 location choices (internal use). */\n\t| \"WRANGLER_D1_EXTRA_LOCATION_CHOICES\"\n\t/** The Workers environment to target (equivalent to the `--env` CLI param) */\n\t| \"CLOUDFLARE_ENV\"\n\n\t// ## Directory Configuration\n\n\t/** Custom directory for Wrangler's cache files (overrides `node_modules/.cache/wrangler`). */\n\t| \"WRANGLER_CACHE_DIR\"\n\t/** Custom path to cloudflared binary (overrides automatic binary management). */\n\t| \"CLOUDFLARED_PATH\"\n\n\t// ## Advanced Configuration\n\n\t/** Set to \"staging\" to use staging APIs instead of production. */\n\t| \"WRANGLER_API_ENVIRONMENT\"\n\t/** Custom auth domain (usually auto-configured). */\n\t| \"WRANGLER_AUTH_DOMAIN\"\n\t/** Custom auth URL (usually auto-configured). */\n\t| \"WRANGLER_AUTH_URL\"\n\t/** Custom OAuth client ID (usually auto-configured). */\n\t| \"WRANGLER_CLIENT_ID\"\n\t/** Custom OAuth client ID for the `cf` CLI's OAuth app (usually auto-configured). */\n\t| \"CLOUDFLARE_CLIENT_ID\"\n\t/** Custom token URL (usually auto-configured). */\n\t| \"WRANGLER_TOKEN_URL\"\n\t/** Custom token revocation URL (usually auto-configured). */\n\t| \"WRANGLER_REVOKE_URL\"\n\t/** Direct authorization token for API requests. */\n\t| \"WRANGLER_CF_AUTHORIZATION_TOKEN\"\n\n\t// ## Cloudflare Access Service Token (for CI/non-interactive environments)\n\n\t/** Cloudflare Access Service Token Client ID. Used to authenticate with Access-protected domains in non-interactive environments (e.g. CI). */\n\t| \"CLOUDFLARE_ACCESS_CLIENT_ID\"\n\t/** Cloudflare Access Service Token Client Secret. Used with CLOUDFLARE_ACCESS_CLIENT_ID. */\n\t| \"CLOUDFLARE_ACCESS_CLIENT_SECRET\"\n\t/**\n\t * Store OAuth credentials in the OS keychain instead of a plaintext TOML\n\t * file. Overrides the persistent `keyring_enabled` preference written by\n\t * `wrangler login --use-keyring`.\n\t */\n\t| \"CLOUDFLARE_AUTH_USE_KEYRING\"\n\n\t// ## Experimental Feature Flags\n\n\t/** Enable the local explorer UI at /cdn-cgi/local/explorer (experimental, default: false). */\n\t| \"X_LOCAL_EXPLORER\"\n\t/** Enable local-dev observability capture (experimental, default: false). */\n\t| \"X_LOCAL_OBSERVABILITY\"\n\t/** Open the browser in headful (visible) mode when using the Browser Run API in local dev (default: false). */\n\t| \"X_BROWSER_HEADFUL\"\n\n\t// ## CI-specific Variables (Internal Use)\n\n\t/** Override command used by `wrangler init` (default: \"create cloudflare\"). */\n\t| \"WRANGLER_C3_COMMAND\"\n\t/** Enable/disable telemetry data collection. */\n\t| \"WRANGLER_SEND_METRICS\"\n\t/** Enable/disable error reporting to Sentry. */\n\t| \"WRANGLER_SEND_ERROR_REPORTS\"\n\t/** Suppress the prompt that offers to update Cloudflare agent skills. */\n\t| \"WRANGLER_NO_SKILLS_UPDATE_PROMPTS\"\n\t/** CI branch name (internal use). */\n\t| \"WORKERS_CI_BRANCH\"\n\t/** CI tag matching configuration (internal use). */\n\t| \"WRANGLER_CI_MATCH_TAG\"\n\t/** CI override name configuration (internal use). */\n\t| \"WRANGLER_CI_OVERRIDE_NAME\"\n\t/** CI network mode host override (internal use). */\n\t| \"WRANGLER_CI_OVERRIDE_NETWORK_MODE_HOST\"\n\t/** CI preview alias generation (internal use). */\n\t| \"WRANGLER_CI_GENERATE_PREVIEW_ALIAS\"\n\t/** Disable config watching in ConfigController. */\n\t| \"WRANGLER_CI_DISABLE_CONFIG_WATCHING\"\n\n\t/** Disable telemetry when set to an opt-out value. */\n\t| \"DO_NOT_TRACK\"\n\n\t// ## Docker Configuration\n\n\t/** Path to docker binary (default: \"docker\"). */\n\t| \"WRANGLER_DOCKER_BIN\"\n\t/** Docker host configuration (handled separately from environment variable factory). */\n\t| \"WRANGLER_DOCKER_HOST\"\n\t/** Docker host configuration (handled separately from environment variable factory). */\n\t| \"DOCKER_HOST\"\n\n\t/** Environment variable used to signal that the current process is being run by the open-next deploy command. */\n\t| \"OPEN_NEXT_DEPLOY\";\n\ntype DeprecatedNames =\n\t| \"CF_ACCOUNT_ID\"\n\t| \"CF_API_TOKEN\"\n\t| \"CF_API_KEY\"\n\t| \"CF_EMAIL\"\n\t| \"CF_API_BASE_URL\";\n\ntype ElementType<A> = A extends readonly (infer T)[] ? T : never;\n\n/**\n * Create a function used to access a boolean environment variable. It may return undefined if the variable is not set.\n *\n * This is not memoized to allow us to change the value at runtime, such as in testing.\n *\n * The environment variable must be either \"true\" or \"false\" (after lowercasing), otherwise it will throw an error.\n */\nexport function getBooleanEnvironmentVariableFactory(options: {\n\tvariableName: VariableNames;\n}): () => boolean | undefined;\nexport function getBooleanEnvironmentVariableFactory(options: {\n\tvariableName: VariableNames;\n\tdefaultValue: boolean | (() => boolean);\n}): () => boolean;\nexport function getBooleanEnvironmentVariableFactory(options: {\n\tvariableName: VariableNames;\n\tdefaultValue?: boolean | (() => boolean);\n}): () => boolean | undefined {\n\treturn () => {\n\t\tif (\n\t\t\t!(options.variableName in process.env) ||\n\t\t\tprocess.env[options.variableName] === undefined\n\t\t) {\n\t\t\treturn typeof options.defaultValue === \"function\"\n\t\t\t\t? options.defaultValue()\n\t\t\t\t: options.defaultValue;\n\t\t}\n\n\t\tswitch (process.env[options.variableName]?.toLowerCase()) {\n\t\t\tcase \"true\":\n\t\t\t\treturn true;\n\t\t\tcase \"false\":\n\t\t\t\treturn false;\n\t\t\tdefault:\n\t\t\t\tthrow new UserError(\n\t\t\t\t\t`Expected ${options.variableName} to be \"true\" or \"false\", but got ${JSON.stringify(\n\t\t\t\t\t\tprocess.env[options.variableName]\n\t\t\t\t\t)}`,\n\t\t\t\t\t{ telemetryMessage: false }\n\t\t\t\t);\n\t\t}\n\t};\n}\n\n/**\n * Create a function used to access an environment variable. It may return undefined if the variable is not set.\n *\n * This is not memoized to allow us to change the value at runtime, such as in testing.\n * A warning is shown if the client is using a deprecated version - but only once.\n * If a list of choices is provided, then the environment variable must be one of those given.\n */\nexport function getEnvironmentVariableFactory<\n\tChoices extends readonly string[],\n>(options: {\n\tvariableName: VariableNames;\n\tdeprecatedName?: DeprecatedNames;\n\tchoices?: Choices;\n}): () => ElementType<Choices> | undefined;\n/**\n * Create a function used to access an environment variable, with a default value if the variable is not set.\n *\n * This is not memoized to allow us to change the value at runtime, such as in testing.\n * A warning is shown if the client is using a deprecated version - but only once.\n * If a list of choices is provided, then the environment variable must be one of those given.\n */\nexport function getEnvironmentVariableFactory<\n\tChoices extends readonly string[],\n>(options: {\n\tvariableName: VariableNames;\n\tdeprecatedName?: DeprecatedNames;\n\tdefaultValue: () => ElementType<Choices>;\n\treadonly choices?: Choices;\n}): () => ElementType<Choices>;\n\nexport function getEnvironmentVariableFactory<\n\tChoices extends readonly string[],\n>({\n\tvariableName,\n\tdeprecatedName,\n\tchoices,\n\tdefaultValue,\n}: {\n\tvariableName: VariableNames;\n\tdeprecatedName?: DeprecatedNames;\n\tdefaultValue?: () => ElementType<Choices>;\n\treadonly choices?: Choices;\n}): () => ElementType<Choices> | undefined {\n\tlet hasWarned = false;\n\treturn () => {\n\t\tif (variableName in process.env) {\n\t\t\treturn getProcessEnv(variableName, choices);\n\t\t}\n\t\tif (deprecatedName && deprecatedName in process.env) {\n\t\t\tif (!hasWarned) {\n\t\t\t\thasWarned = true;\n\t\t\t\t// eslint-disable-next-line no-console -- ideally we'd use `logger.warn` here, but that creates a circular dependency that Vitest is unable to resolve\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Using \"${deprecatedName}\" environment variable. This is deprecated. Please use \"${variableName}\", instead.`\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn getProcessEnv(deprecatedName, choices);\n\t\t}\n\n\t\treturn defaultValue?.();\n\t};\n}\n\n/**\n * Get the value of an environment variable and check it is one of the choices.\n */\nfunction getProcessEnv<Choices extends readonly string[]>(\n\tvariableName: string,\n\tchoices: Choices | undefined\n): ElementType<Choices> | undefined {\n\tassertOneOf(choices, process.env[variableName]);\n\treturn process.env[variableName];\n}\n\n/**\n * Assert `value` is one of a list of `choices`.\n */\nfunction assertOneOf<Choices extends readonly string[]>(\n\tchoices: Choices | undefined,\n\tvalue: string | undefined\n): asserts value is ElementType<Choices> {\n\tif (Array.isArray(choices) && !choices.includes(value)) {\n\t\tthrow new UserError(\n\t\t\t`Expected ${JSON.stringify(value)} to be one of ${JSON.stringify(choices)}`,\n\t\t\t{ telemetryMessage: false }\n\t\t);\n\t}\n}\n","import { getEnvironmentVariableFactory } from \"./environment-variables/factory\";\n\n/**\n * Returns the configured path to the Docker binary.\n *\n * @returns The value of `WRANGLER_DOCKER_BIN`, or `docker` when unset.\n */\nexport const getDockerPath = getEnvironmentVariableFactory({\n\tvariableName: \"WRANGLER_DOCKER_BIN\",\n\tdefaultValue() {\n\t\treturn \"docker\";\n\t},\n});\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export { __name, __require };
|
|
11
|
+
//# sourceMappingURL=chunk-CGILA3WO.mjs.map
|
|
12
|
+
//# sourceMappingURL=chunk-CGILA3WO.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-CGILA3WO.mjs"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { __name } from './chunk-CGILA3WO.mjs';
|
|
2
|
+
|
|
3
|
+
// src/prometheus-metrics.ts
|
|
4
|
+
var MetricsRegistry = class {
|
|
5
|
+
static {
|
|
6
|
+
__name(this, "MetricsRegistry");
|
|
7
|
+
}
|
|
8
|
+
counters = [];
|
|
9
|
+
/**
|
|
10
|
+
* Create and register a new counter metric.
|
|
11
|
+
*
|
|
12
|
+
* @param name - The metric name (e.g. "service_request_total")
|
|
13
|
+
* @param help - A human-readable description of the metric
|
|
14
|
+
* @returns A Counter that can be incremented
|
|
15
|
+
*/
|
|
16
|
+
createCounter(name, help) {
|
|
17
|
+
const entry = { name, help, value: 0 };
|
|
18
|
+
this.counters.push(entry);
|
|
19
|
+
return {
|
|
20
|
+
inc: /* @__PURE__ */ __name(() => {
|
|
21
|
+
entry.value++;
|
|
22
|
+
}, "inc"),
|
|
23
|
+
add: /* @__PURE__ */ __name((amount) => {
|
|
24
|
+
if (amount < 0) {
|
|
25
|
+
throw new Error("Counter value cannot decrease");
|
|
26
|
+
}
|
|
27
|
+
entry.value += amount;
|
|
28
|
+
}, "add")
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Serialize all registered metrics in Prometheus text exposition format.
|
|
33
|
+
*
|
|
34
|
+
* @see https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format
|
|
35
|
+
*/
|
|
36
|
+
metrics() {
|
|
37
|
+
return this.counters.map((c) => {
|
|
38
|
+
let result = "";
|
|
39
|
+
if (c.help.length > 0) {
|
|
40
|
+
result += `# HELP ${c.name} ${c.help}
|
|
41
|
+
`;
|
|
42
|
+
}
|
|
43
|
+
result += `# TYPE ${c.name} counter
|
|
44
|
+
`;
|
|
45
|
+
result += `${c.name} ${c.value}
|
|
46
|
+
`;
|
|
47
|
+
return result;
|
|
48
|
+
}).join("");
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export { MetricsRegistry };
|
|
53
|
+
//# sourceMappingURL=chunk-FEHWZI5W.mjs.map
|
|
54
|
+
//# sourceMappingURL=chunk-FEHWZI5W.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/prometheus-metrics.ts"],"names":[],"mappings":";;;AAuCO,IAAM,kBAAN,MAAsB;AAAA,EAvC7B;AAuC6B,IAAA,MAAA,CAAA,IAAA,EAAA,iBAAA,CAAA;AAAA;AAAA,EACpB,WAA2B,EAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASpC,aAAA,CAAc,MAAc,IAAA,EAAuB;AAClD,IAAA,MAAM,KAAA,GAAsB,EAAE,IAAA,EAAM,IAAA,EAAM,OAAO,CAAA,EAAE;AACnD,IAAA,IAAA,CAAK,QAAA,CAAS,KAAK,KAAK,CAAA;AACxB,IAAA,OAAO;AAAA,MACN,qBAAK,MAAA,CAAA,MAAM;AACV,QAAA,KAAA,CAAM,KAAA,EAAA;AAAA,MACP,CAAA,EAFK,KAAA,CAAA;AAAA,MAGL,GAAA,0BAAM,MAAA,KAAmB;AACxB,QAAA,IAAI,SAAS,CAAA,EAAG;AACf,UAAA,MAAM,IAAI,MAAM,+BAA+B,CAAA;AAAA,QAChD;AACA,QAAA,KAAA,CAAM,KAAA,IAAS,MAAA;AAAA,MAChB,CAAA,EALK,KAAA;AAAA,KAMN;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAA,GAAkB;AACjB,IAAA,OAAO,IAAA,CAAK,QAAA,CACV,GAAA,CAAI,CAAC,CAAA,KAAM;AACX,MAAA,IAAI,MAAA,GAAS,EAAA;AACb,MAAA,IAAI,CAAA,CAAE,IAAA,CAAK,MAAA,GAAS,CAAA,EAAG;AACtB,QAAA,MAAA,IAAU,CAAA,OAAA,EAAU,CAAA,CAAE,IAAI,CAAA,CAAA,EAAI,EAAE,IAAI;AAAA,CAAA;AAAA,MACrC;AACA,MAAA,MAAA,IAAU,CAAA,OAAA,EAAU,EAAE,IAAI,CAAA;AAAA,CAAA;AAC1B,MAAA,MAAA,IAAU,CAAA,EAAG,CAAA,CAAE,IAAI,CAAA,CAAA,EAAI,EAAE,KAAK;AAAA,CAAA;AAC9B,MAAA,OAAO,MAAA;AAAA,IACR,CAAC,CAAA,CACA,IAAA,CAAK,EAAE,CAAA;AAAA,EACV;AACD","file":"chunk-FEHWZI5W.mjs","sourcesContent":["/**\n * Lightweight Prometheus metrics registry for push-based counter metrics.\n *\n * Designed for ephemeral per-request usage in Cloudflare Workers that push\n * metrics to a Prometheus push gateway. Replaces the deprecated `promjs` library.\n *\n * @example\n * ```ts\n * const metrics = new MetricsRegistry();\n * const reqCounter = metrics.createCounter(\n * \"service_request_total\",\n * \"Total requests\"\n * );\n * reqCounter.inc();\n *\n * // Push to Prometheus gateway\n * ctx.waitUntil(\n * fetch(prometheusUrl, {\n * method: \"POST\",\n * headers: { Authorization: `Bearer ${token}` },\n * body: metrics.metrics(),\n * })\n * );\n * ```\n */\n\nexport interface Counter {\n\t/** Increment the counter by 1. */\n\tinc(): void;\n\t/** Increment the counter by the given non-negative amount. */\n\tadd(amount: number): void;\n}\n\ninterface CounterEntry {\n\tname: string;\n\thelp: string;\n\tvalue: number;\n}\n\nexport class MetricsRegistry {\n\tprivate counters: CounterEntry[] = [];\n\n\t/**\n\t * Create and register a new counter metric.\n\t *\n\t * @param name - The metric name (e.g. \"service_request_total\")\n\t * @param help - A human-readable description of the metric\n\t * @returns A Counter that can be incremented\n\t */\n\tcreateCounter(name: string, help: string): Counter {\n\t\tconst entry: CounterEntry = { name, help, value: 0 };\n\t\tthis.counters.push(entry);\n\t\treturn {\n\t\t\tinc: () => {\n\t\t\t\tentry.value++;\n\t\t\t},\n\t\t\tadd: (amount: number) => {\n\t\t\t\tif (amount < 0) {\n\t\t\t\t\tthrow new Error(\"Counter value cannot decrease\");\n\t\t\t\t}\n\t\t\t\tentry.value += amount;\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Serialize all registered metrics in Prometheus text exposition format.\n\t *\n\t * @see https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format\n\t */\n\tmetrics(): string {\n\t\treturn this.counters\n\t\t\t.map((c) => {\n\t\t\t\tlet result = \"\";\n\t\t\t\tif (c.help.length > 0) {\n\t\t\t\t\tresult += `# HELP ${c.name} ${c.help}\\n`;\n\t\t\t\t}\n\t\t\t\tresult += `# TYPE ${c.name} counter\\n`;\n\t\t\t\tresult += `${c.name} ${c.value}\\n`;\n\t\t\t\treturn result;\n\t\t\t})\n\t\t\t.join(\"\");\n\t}\n}\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { __name } from './chunk-CGILA3WO.mjs';
|
|
2
|
+
|
|
3
|
+
// src/errors.ts
|
|
4
|
+
var UserError = class extends Error {
|
|
5
|
+
static {
|
|
6
|
+
__name(this, "UserError");
|
|
7
|
+
}
|
|
8
|
+
telemetryMessage;
|
|
9
|
+
constructor(message, options) {
|
|
10
|
+
super(message, options);
|
|
11
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
12
|
+
this.telemetryMessage = typeof options?.telemetryMessage === "string" ? options.telemetryMessage : options?.telemetryMessage ? message : void 0;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var DeprecationError = class extends UserError {
|
|
16
|
+
static {
|
|
17
|
+
__name(this, "DeprecationError");
|
|
18
|
+
}
|
|
19
|
+
constructor(message, options) {
|
|
20
|
+
super(`Deprecation:
|
|
21
|
+
${message}`, options);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var FatalError = class extends UserError {
|
|
25
|
+
static {
|
|
26
|
+
__name(this, "FatalError");
|
|
27
|
+
}
|
|
28
|
+
code;
|
|
29
|
+
constructor(message, options) {
|
|
30
|
+
super(message, options);
|
|
31
|
+
this.code = options.code;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var CommandLineArgsError = class extends UserError {
|
|
35
|
+
static {
|
|
36
|
+
__name(this, "CommandLineArgsError");
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var JsonFriendlyFatalError = class extends FatalError {
|
|
40
|
+
static {
|
|
41
|
+
__name(this, "JsonFriendlyFatalError");
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var MissingConfigError = class extends Error {
|
|
45
|
+
static {
|
|
46
|
+
__name(this, "MissingConfigError");
|
|
47
|
+
}
|
|
48
|
+
telemetryMessage;
|
|
49
|
+
constructor(key) {
|
|
50
|
+
super(`Missing config value for ${key}`);
|
|
51
|
+
this.telemetryMessage = `Missing config value for ${key}`;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
function createFatalError(message, isJson, options) {
|
|
55
|
+
if (isJson) {
|
|
56
|
+
return new JsonFriendlyFatalError(JSON.stringify(message), options);
|
|
57
|
+
}
|
|
58
|
+
return new FatalError(`${message}`, options);
|
|
59
|
+
}
|
|
60
|
+
__name(createFatalError, "createFatalError");
|
|
61
|
+
|
|
62
|
+
export { CommandLineArgsError, DeprecationError, FatalError, JsonFriendlyFatalError, MissingConfigError, UserError, createFatalError };
|
|
63
|
+
//# sourceMappingURL=chunk-KAEJMITB.mjs.map
|
|
64
|
+
//# sourceMappingURL=chunk-KAEJMITB.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts"],"names":[],"mappings":";;;AAoBO,IAAM,SAAA,GAAN,cAAwB,KAAA,CAAM;AAAA,EApBrC;AAoBqC,IAAA,MAAA,CAAA,IAAA,EAAA,WAAA,CAAA;AAAA;AAAA,EACpC,gBAAA;AAAA,EACA,WAAA,CAAY,SAAiB,OAAA,EAA2B;AACvD,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAGtB,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,GAAA,CAAA,MAAA,CAAW,SAAS,CAAA;AAChD,IAAA,IAAA,CAAK,gBAAA,GACJ,OAAO,OAAA,EAAS,gBAAA,KAAqB,WAClC,OAAA,CAAQ,gBAAA,GACR,OAAA,EAAS,gBAAA,GACR,OAAA,GACA,MAAA;AAAA,EACN;AACD;AAEO,IAAM,gBAAA,GAAN,cAA+B,SAAA,CAAU;AAAA,EApChD;AAoCgD,IAAA,MAAA,CAAA,IAAA,EAAA,kBAAA,CAAA;AAAA;AAAA,EAC/C,WAAA,CAAY,SAAiB,OAAA,EAA2B;AACvD,IAAA,KAAA,CAAM,CAAA;AAAA,EAAiB,OAAO,IAAI,OAAO,CAAA;AAAA,EAC1C;AACD;AAEO,IAAM,UAAA,GAAN,cAAyB,SAAA,CAAU;AAAA,EA1C1C;AA0C0C,IAAA,MAAA,CAAA,IAAA,EAAA,YAAA,CAAA;AAAA;AAAA,EAChC,IAAA;AAAA,EAET,WAAA,CAAY,SAAiB,OAAA,EAA4B;AACxD,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AACtB,IAAA,IAAA,CAAK,OAAO,OAAA,CAAQ,IAAA;AAAA,EACrB;AACD;AAEO,IAAM,oBAAA,GAAN,cAAmC,SAAA,CAAU;AAAA,EAnDpD;AAmDoD,IAAA,MAAA,CAAA,IAAA,EAAA,sBAAA,CAAA;AAAA;AAAC;AAY9C,IAAM,sBAAA,GAAN,cAAqC,UAAA,CAAW;AAAA,EA/DvD;AA+DuD,IAAA,MAAA,CAAA,IAAA,EAAA,wBAAA,CAAA;AAAA;AAAC;AAEjD,IAAM,kBAAA,GAAN,cAAiC,KAAA,CAAM;AAAA,EAjE9C;AAiE8C,IAAA,MAAA,CAAA,IAAA,EAAA,oBAAA,CAAA;AAAA;AAAA,EAC7C,gBAAA;AAAA,EACA,YAAY,GAAA,EAAa;AACxB,IAAA,KAAA,CAAM,CAAA,yBAAA,EAA4B,GAAG,CAAA,CAAE,CAAA;AACvC,IAAA,IAAA,CAAK,gBAAA,GAAmB,4BAA4B,GAAG,CAAA,CAAA;AAAA,EACxD;AACD;AAOO,SAAS,gBAAA,CACf,OAAA,EACA,MAAA,EACA,OAAA,EACQ;AACR,EAAA,IAAI,MAAA,EAAQ;AACX,IAAA,OAAO,IAAI,sBAAA,CAAuB,IAAA,CAAK,SAAA,CAAU,OAAO,GAAG,OAAO,CAAA;AAAA,EACnE;AAEA,EAAA,OAAO,IAAI,UAAA,CAAW,CAAA,EAAG,OAAO,IAAI,OAAO,CAAA;AAC5C;AAVgB,MAAA,CAAA,gBAAA,EAAA,kBAAA,CAAA","file":"chunk-KAEJMITB.mjs","sourcesContent":["/**\n * This is used to provide telemetry with a sanitised error\n * message that could not have any user-identifying information.\n * Set to `true` to duplicate `message`.\n * */\nexport type TelemetryMessage = {\n\ttelemetryMessage: string | boolean;\n};\n\ntype UserErrorOptions = ErrorOptions & TelemetryMessage;\n\ntype FatalErrorOptions = UserErrorOptions & {\n\tcode?: number;\n};\n/**\n * Base class for errors where the user has done something wrong. These are not\n * reported to Sentry. API errors are intentionally *not* `UserError`s, and are\n * reported to Sentry. This will help us understand which API errors need better\n * messaging.\n */\nexport class UserError extends Error {\n\ttelemetryMessage: string | undefined;\n\tconstructor(message: string, options: UserErrorOptions) {\n\t\tsuper(message, options);\n\t\t// Restore prototype chain:\n\t\t// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget\n\t\tObject.setPrototypeOf(this, new.target.prototype);\n\t\tthis.telemetryMessage =\n\t\t\ttypeof options?.telemetryMessage === \"string\"\n\t\t\t\t? options.telemetryMessage\n\t\t\t\t: options?.telemetryMessage\n\t\t\t\t\t? message\n\t\t\t\t\t: undefined;\n\t}\n}\n\nexport class DeprecationError extends UserError {\n\tconstructor(message: string, options: TelemetryMessage) {\n\t\tsuper(`Deprecation:\\n${message}`, options);\n\t}\n}\n\nexport class FatalError extends UserError {\n\treadonly code: number | undefined;\n\n\tconstructor(message: string, options: FatalErrorOptions) {\n\t\tsuper(message, options);\n\t\tthis.code = options.code;\n\t}\n}\n\nexport class CommandLineArgsError extends UserError {}\n\n/**\n * JsonFriendlyFatalError is used to output JSON when wrangler crashes, useful for --json mode.\n *\n * To use, pass stringify'd json into the constructor like so:\n * ```js\n * throw new JsonFriendlyFatalError(JSON.stringify({ error: messageToDisplay }), {\n * telemetryMessage: false,\n * });\n * ```\n */\nexport class JsonFriendlyFatalError extends FatalError {}\n\nexport class MissingConfigError extends Error {\n\ttelemetryMessage: string | undefined;\n\tconstructor(key: string) {\n\t\tsuper(`Missing config value for ${key}`);\n\t\tthis.telemetryMessage = `Missing config value for ${key}`;\n\t}\n}\n\n/**\n * Create either a FatalError or JsonFriendlyFatalError depending upon `isJson` parameter.\n *\n * If `isJson` is true, then the `message` is JSON stringified.\n */\nexport function createFatalError(\n\tmessage: unknown,\n\tisJson: boolean,\n\toptions: FatalErrorOptions\n): Error {\n\tif (isJson) {\n\t\treturn new JsonFriendlyFatalError(JSON.stringify(message), options);\n\t}\n\n\treturn new FatalError(`${message}`, options);\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { __name } from './chunk-CGILA3WO.mjs';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
|
|
4
|
+
function isDirectory(path) {
|
|
5
|
+
return fs.statSync(path, { throwIfNoEntry: false })?.isDirectory() ?? false;
|
|
6
|
+
}
|
|
7
|
+
__name(isDirectory, "isDirectory");
|
|
8
|
+
function removeDir(dirPath, { fireAndForget = false } = {}) {
|
|
9
|
+
const result = fs.promises.rm(dirPath, {
|
|
10
|
+
recursive: true,
|
|
11
|
+
force: true,
|
|
12
|
+
maxRetries: 5,
|
|
13
|
+
retryDelay: 100
|
|
14
|
+
});
|
|
15
|
+
if (fireAndForget) {
|
|
16
|
+
void result.catch(() => {
|
|
17
|
+
});
|
|
18
|
+
} else {
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
__name(removeDir, "removeDir");
|
|
23
|
+
function removeDirSync(dirPath) {
|
|
24
|
+
fs.rmSync(dirPath, {
|
|
25
|
+
recursive: true,
|
|
26
|
+
force: true,
|
|
27
|
+
maxRetries: 5,
|
|
28
|
+
retryDelay: 100
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
__name(removeDirSync, "removeDirSync");
|
|
32
|
+
|
|
33
|
+
export { isDirectory, removeDir, removeDirSync };
|
|
34
|
+
//# sourceMappingURL=chunk-T6I7NOR4.mjs.map
|
|
35
|
+
//# sourceMappingURL=chunk-T6I7NOR4.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/fs-helpers.ts"],"names":[],"mappings":";;;AAUO,SAAS,YAAY,IAAA,EAAc;AACzC,EAAA,OAAO,EAAA,CAAG,SAAS,IAAA,EAAM,EAAE,gBAAgB,KAAA,EAAO,CAAA,EAAG,WAAA,EAAY,IAAK,KAAA;AACvE;AAFgB,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA;AA4BT,SAAS,UACf,OAAA,EACA,EAAE,gBAAgB,KAAA,EAAM,GAAiC,EAAC,EACnC;AAOvB,EAAA,MAAM,MAAA,GAAS,EAAA,CAAG,QAAA,CAAS,EAAA,CAAG,OAAA,EAAS;AAAA,IACtC,SAAA,EAAW,IAAA;AAAA,IACX,KAAA,EAAO,IAAA;AAAA,IACP,UAAA,EAAY,CAAA;AAAA,IACZ,UAAA,EAAY;AAAA,GACZ,CAAA;AACD,EAAA,IAAI,aAAA,EAAe;AAElB,IAAA,KAAK,MAAA,CAAO,MAAM,MAAM;AAAA,IAAC,CAAC,CAAA;AAAA,EAC3B,CAAA,MAAO;AACN,IAAA,OAAO,MAAA;AAAA,EACR;AACD;AAtBgB,MAAA,CAAA,SAAA,EAAA,WAAA,CAAA;AAgCT,SAAS,cAAc,OAAA,EAAuB;AAEpD,EAAA,EAAA,CAAG,OAAO,OAAA,EAAS;AAAA,IAClB,SAAA,EAAW,IAAA;AAAA,IACX,KAAA,EAAO,IAAA;AAAA,IACP,UAAA,EAAY,CAAA;AAAA,IACZ,UAAA,EAAY;AAAA,GACZ,CAAA;AACF;AARgB,MAAA,CAAA,aAAA,EAAA,eAAA,CAAA","file":"chunk-T6I7NOR4.mjs","sourcesContent":["import fs from \"node:fs\";\n\n/**\n * Returns whether the given path is a directory\n *\n * Note: this function never throws; if the path does not exist or is inaccessible, it returns false.\n *\n * @param path The file system path to check\n * @returns `true` if the path is a directory, `false` otherwise\n */\nexport function isDirectory(path: string) {\n\treturn fs.statSync(path, { throwIfNoEntry: false })?.isDirectory() ?? false;\n}\n\n/**\n * Recursively remove a directory without waiting for completion or throwing any errors.\n *\n * @param dirPath The directory path to remove\n * @param options An object with a `fireAndForget` property set to `true`\n * @return `void` - the removal is fire-and-forget with errors suppressed\n */\nexport function removeDir(\n\tdirPath: string,\n\t{ fireAndForget }: { fireAndForget: true }\n): void;\n\n/**\n * Recursively remove a directory with retries for Windows compatibility.\n *\n * @param dirPath The directory path to remove\n * @param options An optional object with a `fireAndForget` property set to `false`, if defined\n * @return `Promise<void>` - resolves when the removal is complete, or rejects if the removal fails\n */\nexport function removeDir(\n\tdirPath: string,\n\toptions?: { fireAndForget?: false }\n): Promise<void>;\n\nexport function removeDir(\n\tdirPath: string,\n\t{ fireAndForget = false }: { fireAndForget?: boolean } = {}\n): Promise<void> | void {\n\t// On Windows, `workerd` (and other processes) may not release file handles\n\t// immediately after disposal, causing `EBUSY` errors. Node.js's built-in\n\t// `maxRetries` option handles `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`,\n\t// and `EPERM` errors with automatic backoff retries.\n\n\t// eslint-disable-next-line workers-sdk/no-direct-recursive-rm -- this is the helper itself\n\tconst result = fs.promises.rm(dirPath, {\n\t\trecursive: true,\n\t\tforce: true,\n\t\tmaxRetries: 5,\n\t\tretryDelay: 100,\n\t});\n\tif (fireAndForget) {\n\t\t// Don't wait for the promise, and silently swallow errors by handling if rejected\n\t\tvoid result.catch(() => {});\n\t} else {\n\t\treturn result;\n\t}\n}\n\n/**\n * Synchronously and recursively remove a directory, with retries for Windows compatibility.\n *\n * @see {@link removeDir} for the async version and rationale.\n *\n * @param dirPath The directory path to remove\n * @throws If the removal fails after retries, an error will be thrown\n */\nexport function removeDirSync(dirPath: string): void {\n\t// eslint-disable-next-line workers-sdk/no-direct-recursive-rm -- this is the helper itself\n\tfs.rmSync(dirPath, {\n\t\trecursive: true,\n\t\tforce: true,\n\t\tmaxRetries: 5,\n\t\tretryDelay: 100,\n\t});\n}\n"]}
|