@nightintelligence/cloudflare-workers-utils 0.35.0-patch2 → 0.35.0-patch3

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.
Files changed (53) hide show
  1. package/dist/browser.mjs +2 -2
  2. package/dist/browser.mjs.map +1 -1
  3. package/dist/chunk-PAWJFY3S.mjs +6 -0
  4. package/dist/{chunk-6LYDFTTF.mjs.map → chunk-PAWJFY3S.mjs.map} +1 -1
  5. package/dist/compatibility-date.mjs +42 -2
  6. package/dist/compatibility-date.mjs.map +1 -1
  7. package/dist/compliance.mjs +2 -7
  8. package/dist/compliance.mjs.map +1 -1
  9. package/dist/docker-path.mjs +11 -3
  10. package/dist/docker-path.mjs.map +1 -1
  11. package/dist/errors.mjs +61 -2
  12. package/dist/errors.mjs.map +1 -1
  13. package/dist/fs-helpers.mjs +33 -2
  14. package/dist/fs-helpers.mjs.map +1 -1
  15. package/dist/global-wrangler-config-path.mjs +28 -3
  16. package/dist/global-wrangler-config-path.mjs.map +1 -1
  17. package/dist/index.mjs +54 -26124
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/local-env.mjs +5 -80
  20. package/dist/local-env.mjs.map +1 -1
  21. package/dist/metafile-esm.json +1 -1
  22. package/dist/prometheus-metrics.mjs +51 -2
  23. package/dist/prometheus-metrics.mjs.map +1 -1
  24. package/dist/test-helpers/index.mjs +7 -308
  25. package/dist/test-helpers/index.mjs.map +1 -1
  26. package/dist/zod-format.mjs +235 -2
  27. package/dist/zod-format.mjs.map +1 -1
  28. package/package.json +1 -1
  29. package/dist/chunk-3D4BXUZX.mjs +0 -54
  30. package/dist/chunk-3D4BXUZX.mjs.map +0 -1
  31. package/dist/chunk-4RE36JUD.mjs +0 -3160
  32. package/dist/chunk-4RE36JUD.mjs.map +0 -1
  33. package/dist/chunk-6LYDFTTF.mjs +0 -40
  34. package/dist/chunk-CPLEE7LH.mjs +0 -64
  35. package/dist/chunk-CPLEE7LH.mjs.map +0 -1
  36. package/dist/chunk-G5FCNCLK.mjs +0 -47
  37. package/dist/chunk-G5FCNCLK.mjs.map +0 -1
  38. package/dist/chunk-IGC3TZGH.mjs +0 -157
  39. package/dist/chunk-IGC3TZGH.mjs.map +0 -1
  40. package/dist/chunk-NXPJWJ2B.mjs +0 -180
  41. package/dist/chunk-NXPJWJ2B.mjs.map +0 -1
  42. package/dist/chunk-OPAKTV2K.mjs +0 -75
  43. package/dist/chunk-OPAKTV2K.mjs.map +0 -1
  44. package/dist/chunk-VKFVZ67V.mjs +0 -35
  45. package/dist/chunk-VKFVZ67V.mjs.map +0 -1
  46. package/dist/chunk-W7DIL5J2.mjs +0 -267
  47. package/dist/chunk-W7DIL5J2.mjs.map +0 -1
  48. package/dist/chunk-ZLUHKBEC.mjs +0 -44
  49. package/dist/chunk-ZLUHKBEC.mjs.map +0 -1
  50. package/dist/chunk-ZQ2EZEOC.mjs +0 -477
  51. package/dist/chunk-ZQ2EZEOC.mjs.map +0 -1
  52. package/dist/open-OYMIZX6T.mjs +0 -609
  53. package/dist/open-OYMIZX6T.mjs.map +0 -1
package/dist/browser.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { constructWranglerConfig } from './chunk-ZQ2EZEOC.mjs';
2
- import './chunk-6LYDFTTF.mjs';
1
+ import './chunk-PAWJFY3S.mjs';
2
+ export { constructWranglerConfig } from './construct-wrangler-config';
3
3
  //# sourceMappingURL=browser.mjs.map
4
4
  //# sourceMappingURL=browser.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"browser.mjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"browser.mjs","sourcesContent":[]}
@@ -0,0 +1,6 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ export { __name };
5
+ //# sourceMappingURL=chunk-PAWJFY3S.mjs.map
6
+ //# sourceMappingURL=chunk-PAWJFY3S.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-6LYDFTTF.mjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-PAWJFY3S.mjs"}
@@ -1,4 +1,44 @@
1
- export { NODEJS_COMPAT_DEFAULT_ON_DATE, NODEJS_COMPAT_V2_SWITCH_OVER_DATE, getTodaysCompatDate, isCompatDate, isNodejsCompatDefaultOn, resolveNodejsCompat, stripRedundantNodejsCompatFlags } from './chunk-ZLUHKBEC.mjs';
2
- import './chunk-6LYDFTTF.mjs';
1
+ import { __name } from './chunk-PAWJFY3S.mjs';
2
+ import assert from 'node:assert';
3
+
4
+ function isCompatDate(str) {
5
+ return /^\d{4}-\d{2}-\d{2}$/.test(str);
6
+ }
7
+ __name(isCompatDate, "isCompatDate");
8
+ function formatCompatibilityDate(date) {
9
+ const compatDate = date.toISOString().slice(0, 10);
10
+ assert(isCompatDate(compatDate));
11
+ return compatDate;
12
+ }
13
+ __name(formatCompatibilityDate, "formatCompatibilityDate");
14
+ function getTodaysCompatDate() {
15
+ return formatCompatibilityDate(/* @__PURE__ */ new Date());
16
+ }
17
+ __name(getTodaysCompatDate, "getTodaysCompatDate");
18
+ const NODEJS_COMPAT_DEFAULT_ON_DATE = "2026-08-04";
19
+ function isNodejsCompatDefaultOn(compatibilityDate) {
20
+ return compatibilityDate !== void 0 && compatibilityDate >= NODEJS_COMPAT_DEFAULT_ON_DATE;
21
+ }
22
+ __name(isNodejsCompatDefaultOn, "isNodejsCompatDefaultOn");
23
+ const NODEJS_COMPAT_V2_SWITCH_OVER_DATE = "2024-09-23";
24
+ function resolveNodejsCompat(compatibilityDate, compatibilityFlags) {
25
+ const isDefaultOn = isNodejsCompatDefaultOn(compatibilityDate);
26
+ const isNodejsCompatEnabled = compatibilityFlags.includes("nodejs_compat") || isDefaultOn && !compatibilityFlags.includes("no_nodejs_compat");
27
+ const isNodejsCompatV2Enabled = compatibilityFlags.includes("nodejs_compat_v2") || !compatibilityFlags.includes("no_nodejs_compat_v2") && (isDefaultOn || isNodejsCompatEnabled && compatibilityDate >= NODEJS_COMPAT_V2_SWITCH_OVER_DATE);
28
+ return { isNodejsCompatEnabled, isNodejsCompatV2Enabled };
29
+ }
30
+ __name(resolveNodejsCompat, "resolveNodejsCompat");
31
+ function stripRedundantNodejsCompatFlags(compatibilityDate, compatibilityFlags) {
32
+ if (!isNodejsCompatDefaultOn(compatibilityDate)) {
33
+ return compatibilityFlags;
34
+ }
35
+ const redundantFlags = ["nodejs_compat", "nodejs_compat_v2"].filter(
36
+ (flag) => !compatibilityFlags.includes(`no_${flag}`)
37
+ );
38
+ return compatibilityFlags.filter((flag) => !redundantFlags.includes(flag));
39
+ }
40
+ __name(stripRedundantNodejsCompatFlags, "stripRedundantNodejsCompatFlags");
41
+
42
+ export { NODEJS_COMPAT_DEFAULT_ON_DATE, NODEJS_COMPAT_V2_SWITCH_OVER_DATE, getTodaysCompatDate, isCompatDate, isNodejsCompatDefaultOn, resolveNodejsCompat, stripRedundantNodejsCompatFlags };
3
43
  //# sourceMappingURL=compatibility-date.mjs.map
4
44
  //# sourceMappingURL=compatibility-date.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"compatibility-date.mjs"}
1
+ {"version":3,"sources":["../src/compatibility-date.ts"],"names":[],"mappings":";;;AAiBO,SAAS,aAAa,GAAA,EAAgC;AAC5D,EAAA,OAAO,qBAAA,CAAsB,KAAK,GAAG,CAAA;AACtC;AAFgB,MAAA,CAAA,YAAA,EAAA,cAAA,CAAA;AAUhB,SAAS,wBAAwB,IAAA,EAAwB;AACxD,EAAA,MAAM,aAAa,IAAA,CAAK,WAAA,EAAY,CAAE,KAAA,CAAM,GAAG,EAAE,CAAA;AACjD,EAAA,MAAA,CAAO,YAAA,CAAa,UAAU,CAAC,CAAA;AAC/B,EAAA,OAAO,UAAA;AACR;AAJS,MAAA,CAAA,uBAAA,EAAA,yBAAA,CAAA;AASF,SAAS,mBAAA,GAAkC;AACjD,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1E;AAbgB,MAAA,CAAA,+BAAA,EAAA,iCAAA,CAAA","file":"compatibility-date.mjs","sourcesContent":["import assert from \"node:assert\";\n\ntype YYYY = `${number}${number}${number}${number}`;\ntype MM = `${number}${number}`;\ntype DD = `${number}${number}`;\n\n/**\n * Represents a valid compatibility date, a string such as `2025-09-27`\n */\nexport type CompatDate = `${YYYY}-${MM}-${DD}`;\n\n/**\n * Discern whether a string represents a compatibility date (`YYYY-MM-DD`)\n *\n * @param str The target string\n * @returns true if the string represents a compatibility date, false otherwise\n */\nexport function isCompatDate(str: string): str is CompatDate {\n\treturn /^\\d{4}-\\d{2}-\\d{2}$/.test(str);\n}\n\n/**\n * Returns the date formatted as a compatibility date\n *\n * @param date The target date to convert\n * @returns The date as a CompatDate string (a string following the format `YYYY-MM-DD`)\n */\nfunction formatCompatibilityDate(date: Date): CompatDate {\n\tconst compatDate = date.toISOString().slice(0, 10);\n\tassert(isCompatDate(compatDate));\n\treturn compatDate;\n}\n\n/**\n * Returns today's date as a compatibility date string (`YYYY-MM-DD`).\n */\nexport function getTodaysCompatDate(): CompatDate {\n\treturn formatCompatibilityDate(new Date());\n}\n\n/**\n * The compatibility date on which the `nodejs_compat` and `nodejs_compat_v2`\n * compatibility flags became enabled by default in workerd.\n *\n * From this date onwards, specifying either flag explicitly is a validation\n * error (\"The compatibility flag nodejs_compat became the default as of\n * 2026-08-04 so does not need to be specified anymore\"), so tooling must not\n * add them to configurations using such a compatibility date.\n *\n * @see https://github.com/cloudflare/workerd/blob/main/src/workerd/io/compatibility-date.capnp\n */\nexport const NODEJS_COMPAT_DEFAULT_ON_DATE = \"2026-08-04\";\n\n/**\n * Whether workerd enables Node.js compatibility by default for the given\n * compatibility date, i.e. without the `nodejs_compat` flag being specified.\n *\n * @param compatibilityDate The compatibility date to check\n * @returns true if the date is on or after {@link NODEJS_COMPAT_DEFAULT_ON_DATE}\n */\nexport function isNodejsCompatDefaultOn(\n\tcompatibilityDate: string | undefined\n): boolean {\n\treturn (\n\t\tcompatibilityDate !== undefined &&\n\t\tcompatibilityDate >= NODEJS_COMPAT_DEFAULT_ON_DATE\n\t);\n}\n\n/**\n * The compatibility date on which `nodejs_compat` started implying\n * `nodejs_compat_v2`.\n */\nexport const NODEJS_COMPAT_V2_SWITCH_OVER_DATE = \"2024-09-23\";\n\n/**\n * Resolves whether workerd will enable the `nodejs_compat` and\n * `nodejs_compat_v2` features, mirroring how workerd itself resolves them from\n * the compatibility date and flags:\n * - Both are enabled by default from {@link NODEJS_COMPAT_DEFAULT_ON_DATE}\n * onwards, and each must be turned off separately from that date, with\n * `no_nodejs_compat` and `no_nodejs_compat_v2` respectively.\n * - Before that date, `nodejs_compat` implies `nodejs_compat_v2` from\n * {@link NODEJS_COMPAT_V2_SWITCH_OVER_DATE} onwards.\n *\n * @param compatibilityDate The compatibility date\n * @param compatibilityFlags The compatibility flags\n */\nexport function resolveNodejsCompat(\n\tcompatibilityDate: string,\n\tcompatibilityFlags: string[]\n): { isNodejsCompatEnabled: boolean; isNodejsCompatV2Enabled: boolean } {\n\tconst isDefaultOn = isNodejsCompatDefaultOn(compatibilityDate);\n\n\tconst isNodejsCompatEnabled =\n\t\tcompatibilityFlags.includes(\"nodejs_compat\") ||\n\t\t(isDefaultOn && !compatibilityFlags.includes(\"no_nodejs_compat\"));\n\n\tconst isNodejsCompatV2Enabled =\n\t\tcompatibilityFlags.includes(\"nodejs_compat_v2\") ||\n\t\t(!compatibilityFlags.includes(\"no_nodejs_compat_v2\") &&\n\t\t\t(isDefaultOn ||\n\t\t\t\t(isNodejsCompatEnabled &&\n\t\t\t\t\tcompatibilityDate >= NODEJS_COMPAT_V2_SWITCH_OVER_DATE)));\n\n\treturn { isNodejsCompatEnabled, isNodejsCompatV2Enabled };\n}\n\n// TODO: remove when workerd no longer errors\n/**\n * Removes the `nodejs_compat` and `nodejs_compat_v2` flags from a list of\n * compatibility flags when the compatibility date already enables them.\n *\n * workerd rejects a compatibility flag that its compatibility date enables by\n * default, so from {@link NODEJS_COMPAT_DEFAULT_ON_DATE} onwards specifying\n * either flag stops a Worker from starting up. Removing them is a no-op for\n * such a date, so tooling can accept the redundant flags rather than failing.\n *\n * A flag is kept when its matching opt-out is specified too, since workerd\n * reports those as contradictory and the enable flag wins there - dropping it\n * would silently switch Node.js compatibility off instead.\n *\n * @param compatibilityDate The compatibility date\n * @param compatibilityFlags The compatibility flags\n * @returns The flags, without the ones the date makes redundant\n */\nexport function stripRedundantNodejsCompatFlags(\n\tcompatibilityDate: string | undefined,\n\tcompatibilityFlags: string[]\n): string[] {\n\tif (!isNodejsCompatDefaultOn(compatibilityDate)) {\n\t\treturn compatibilityFlags;\n\t}\n\n\tconst redundantFlags = [\"nodejs_compat\", \"nodejs_compat_v2\"].filter(\n\t\t(flag) => !compatibilityFlags.includes(`no_${flag}`)\n\t);\n\n\treturn compatibilityFlags.filter((flag) => !redundantFlags.includes(flag));\n}\n"]}
@@ -1,9 +1,4 @@
1
- export { COMPLIANCE_REGION_CONFIG_PUBLIC, COMPLIANCE_REGION_CONFIG_UNKNOWN, getCloudflareApiBaseUrl, getCloudflareComplianceRegion, getComplianceRegionSubdomain } from './chunk-NXPJWJ2B.mjs';
2
- import './chunk-G5FCNCLK.mjs';
3
- import './chunk-OPAKTV2K.mjs';
4
- import './chunk-CPLEE7LH.mjs';
5
- import './chunk-IGC3TZGH.mjs';
6
- import './chunk-VKFVZ67V.mjs';
7
- import './chunk-6LYDFTTF.mjs';
1
+ import './chunk-PAWJFY3S.mjs';
2
+ export { COMPLIANCE_REGION_CONFIG_PUBLIC, COMPLIANCE_REGION_CONFIG_UNKNOWN, getCloudflareApiBaseUrl, getCloudflareComplianceRegion, getComplianceRegionSubdomain } from './environment-variables/misc-variables';
8
3
  //# sourceMappingURL=compliance.mjs.map
9
4
  //# sourceMappingURL=compliance.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"compliance.mjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"compliance.mjs","sourcesContent":[]}
@@ -1,5 +1,13 @@
1
- export { getDockerPath } from './chunk-OPAKTV2K.mjs';
2
- import './chunk-CPLEE7LH.mjs';
3
- import './chunk-6LYDFTTF.mjs';
1
+ import './chunk-PAWJFY3S.mjs';
2
+ import { getEnvironmentVariableFactory } from './environment-variables/factory';
3
+
4
+ const getDockerPath = getEnvironmentVariableFactory({
5
+ variableName: "WRANGLER_DOCKER_BIN",
6
+ defaultValue() {
7
+ return "docker";
8
+ }
9
+ });
10
+
11
+ export { getDockerPath };
4
12
  //# sourceMappingURL=docker-path.mjs.map
5
13
  //# sourceMappingURL=docker-path.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"docker-path.mjs"}
1
+ {"version":3,"sources":["../src/docker-path.ts"],"names":[],"mappings":";;;AAOO,MAAM,gBAAgB,6BAAA,CAA8B;AAAA,EAC1D,YAAA,EAAc,qBAAA;AAAA,EACd,YAAA,GAAe;AACd,IAAA,OAAO,QAAA;AAAA,EACR;AACD,CAAC","file":"docker-path.mjs","sourcesContent":["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"]}
package/dist/errors.mjs CHANGED
@@ -1,4 +1,63 @@
1
- export { CommandLineArgsError, DeprecationError, FatalError, JsonFriendlyFatalError, MissingConfigError, UserError, createFatalError } from './chunk-CPLEE7LH.mjs';
2
- import './chunk-6LYDFTTF.mjs';
1
+ import { __name } from './chunk-PAWJFY3S.mjs';
2
+
3
+ class UserError extends Error {
4
+ static {
5
+ __name(this, "UserError");
6
+ }
7
+ telemetryMessage;
8
+ constructor(message, options) {
9
+ super(message, options);
10
+ Object.setPrototypeOf(this, new.target.prototype);
11
+ this.telemetryMessage = typeof options?.telemetryMessage === "string" ? options.telemetryMessage : options?.telemetryMessage ? message : void 0;
12
+ }
13
+ }
14
+ class DeprecationError extends UserError {
15
+ static {
16
+ __name(this, "DeprecationError");
17
+ }
18
+ constructor(message, options) {
19
+ super(`Deprecation:
20
+ ${message}`, options);
21
+ }
22
+ }
23
+ class FatalError extends UserError {
24
+ static {
25
+ __name(this, "FatalError");
26
+ }
27
+ code;
28
+ constructor(message, options) {
29
+ super(message, options);
30
+ this.code = options.code;
31
+ }
32
+ }
33
+ class CommandLineArgsError extends UserError {
34
+ static {
35
+ __name(this, "CommandLineArgsError");
36
+ }
37
+ }
38
+ class JsonFriendlyFatalError extends FatalError {
39
+ static {
40
+ __name(this, "JsonFriendlyFatalError");
41
+ }
42
+ }
43
+ class MissingConfigError extends Error {
44
+ static {
45
+ __name(this, "MissingConfigError");
46
+ }
47
+ telemetryMessage;
48
+ constructor(key) {
49
+ super(`Missing config value for ${key}`);
50
+ this.telemetryMessage = `Missing config value for ${key}`;
51
+ }
52
+ }
53
+ function createFatalError(message, isJson, options) {
54
+ if (isJson) {
55
+ return new JsonFriendlyFatalError(JSON.stringify(message), options);
56
+ }
57
+ return new FatalError(`${message}`, options);
58
+ }
59
+ __name(createFatalError, "createFatalError");
60
+
61
+ export { CommandLineArgsError, DeprecationError, FatalError, JsonFriendlyFatalError, MissingConfigError, UserError, createFatalError };
3
62
  //# sourceMappingURL=errors.mjs.map
4
63
  //# sourceMappingURL=errors.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"errors.mjs"}
1
+ {"version":3,"sources":["../src/errors.ts"],"names":[],"mappings":";;AAoBO,MAAM,kBAAkB,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,OA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AAA,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":"errors.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"]}
@@ -1,4 +1,35 @@
1
- export { isDirectory, removeDir, removeDirSync } from './chunk-VKFVZ67V.mjs';
2
- import './chunk-6LYDFTTF.mjs';
1
+ import { __name } from './chunk-PAWJFY3S.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 };
3
34
  //# sourceMappingURL=fs-helpers.mjs.map
4
35
  //# sourceMappingURL=fs-helpers.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"fs-helpers.mjs"}
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":"fs-helpers.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"]}
@@ -1,5 +1,30 @@
1
- export { getGlobalConfigPath, getGlobalWranglerCachePath } from './chunk-IGC3TZGH.mjs';
2
- import './chunk-VKFVZ67V.mjs';
3
- import './chunk-6LYDFTTF.mjs';
1
+ import { __name } from './chunk-PAWJFY3S.mjs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { isDirectory } from './fs-helpers';
5
+ import { xdgAppPaths } from './xdg-app-paths';
6
+
7
+ function getGlobalConfigPath({
8
+ appName = "wrangler",
9
+ leadingDot = true,
10
+ useLegacyHomeDir = true
11
+ } = {}) {
12
+ const dirName = `${leadingDot ? "." : ""}${appName}`;
13
+ const configDir = xdgAppPaths(dirName).config();
14
+ if (useLegacyHomeDir) {
15
+ const legacyConfigDir = path.join(os.homedir(), dirName);
16
+ if (isDirectory(legacyConfigDir)) {
17
+ return legacyConfigDir;
18
+ }
19
+ }
20
+ return configDir;
21
+ }
22
+ __name(getGlobalConfigPath, "getGlobalConfigPath");
23
+ function getGlobalWranglerCachePath() {
24
+ return xdgAppPaths(".wrangler").cache();
25
+ }
26
+ __name(getGlobalWranglerCachePath, "getGlobalWranglerCachePath");
27
+
28
+ export { getGlobalConfigPath, getGlobalWranglerCachePath };
4
29
  //# sourceMappingURL=global-wrangler-config-path.mjs.map
5
30
  //# sourceMappingURL=global-wrangler-config-path.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"global-wrangler-config-path.mjs"}
1
+ {"version":3,"sources":["../src/global-wrangler-config-path.ts"],"names":[],"mappings":";;;;;;AA+BO,SAAS,mBAAA,CAAoB;AAAA,EACnC,OAAA,GAAU,UAAA;AAAA,EACV,UAAA,GAAa,IAAA;AAAA,EACb,gBAAA,GAAmB;AACpB,CAAA,GAAgC,EAAC,EAAG;AAEnC,EAAA,MAAM,UAAU,CAAA,EAAG,UAAA,GAAa,GAAA,GAAM,EAAE,GAAG,OAAO,CAAA,CAAA;AAClD,EAAA,MAAM,SAAA,GAAY,WAAA,CAAY,OAAO,CAAA,CAAE,MAAA,EAAO;AAE9C,EAAA,IAAI,gBAAA,EAAkB;AACrB,IAAA,MAAM,kBAAkB,IAAA,CAAK,IAAA,CAAK,EAAA,CAAG,OAAA,IAAW,OAAO,CAAA;AAGvD,IAAA,IAAI,WAAA,CAAY,eAAe,CAAA,EAAG;AACjC,MAAA,OAAO,eAAA;AAAA,IACR;AAAA,EACD;AAEA,EAAA,OAAO,SAAA;AACR;AAnBgB,MAAA,CAAA,mBAAA,EAAA,qBAAA,CAAA;AA2BT,SAAS,0BAAA,GAA6B;AAC5C,EAAA,OAAO,WAAA,CAAY,WAAW,CAAA,CAAE,KAAA,EAAM;AACvC;AAFgB,MAAA,CAAA,0BAAA,EAAA,4BAAA,CAAA","file":"global-wrangler-config-path.mjs","sourcesContent":["import os from \"node:os\";\nimport path from \"node:path\";\nimport { isDirectory } from \"./fs-helpers\";\nimport { xdgAppPaths } from \"./xdg-app-paths\";\n\nexport interface GetGlobalConfigPathOptions {\n\t/**\n\t * The application namespace. Defaults to `\"wrangler\"`.\n\t */\n\tappName?: string;\n\t/**\n\t * Whether to prepend a `.` to `appName` when resolving the XDG path and the\n\t * legacy `$HOME` directory. Defaults to `true` to match wrangler's\n\t * historical behaviour (`.wrangler`).\n\t */\n\tleadingDot?: boolean;\n\t/**\n\t * When `true` (the default, matching wrangler's historical behaviour), a\n\t * pre-existing `~/.<appName>` directory takes precedence over the XDG path.\n\t * Pass `false` to always use the XDG-compliant path.\n\t */\n\tuseLegacyHomeDir?: boolean;\n}\n\n/**\n * Resolve the global config directory for a Cloudflare CLI.\n *\n * Defaults to wrangler's directory (`.wrangler`) so existing callers are\n * unaffected, but accepts an `appName` so other first-party CLIs (e.g. `cf`)\n * can reuse the same XDG-compliant resolution under their own namespace.\n */\nexport function getGlobalConfigPath({\n\tappName = \"wrangler\",\n\tleadingDot = true,\n\tuseLegacyHomeDir = true,\n}: GetGlobalConfigPathOptions = {}) {\n\t//TODO: We should implement a custom path --global-config and/or the WRANGLER_HOME type environment variable\n\tconst dirName = `${leadingDot ? \".\" : \"\"}${appName}`;\n\tconst configDir = xdgAppPaths(dirName).config(); // New XDG compliant config path\n\n\tif (useLegacyHomeDir) {\n\t\tconst legacyConfigDir = path.join(os.homedir(), dirName); // Legacy config in user's home directory\n\t\t// Check for the legacy directory in $HOME; if it is not there then use the\n\t\t// XDG compliant path.\n\t\tif (isDirectory(legacyConfigDir)) {\n\t\t\treturn legacyConfigDir;\n\t\t}\n\t}\n\n\treturn configDir;\n}\n\n/**\n * Resolve the XDG-compliant global cache directory for wrangler (`.wrangler`).\n *\n * Unlike {@link getGlobalConfigPath}, this never falls back to a legacy\n * `~/.wrangler` directory.\n */\nexport function getGlobalWranglerCachePath() {\n\treturn xdgAppPaths(\".wrangler\").cache();\n}\n"]}