@cloudflare/vite-plugin 1.30.0 → 1.30.2

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/index.mjs CHANGED
@@ -1893,7 +1893,14 @@ const formatInvalidRoutes = (invalidRules) => {
1893
1893
  };
1894
1894
 
1895
1895
  //#endregion
1896
- //#region ../workers-utils/dist/chunk-LDFBMPMW.mjs
1896
+ //#region ../workers-utils/dist/chunk-OZQVB3L3.mjs
1897
+ var INHERIT_SYMBOL = Symbol.for("inherit_binding");
1898
+ var SERVICE_TAG_PREFIX = "cf:service=";
1899
+ var ENVIRONMENT_TAG_PREFIX = "cf:environment=";
1900
+ var PATH_TO_DEPLOY_CONFIG = ".wrangler/deploy/config.json";
1901
+
1902
+ //#endregion
1903
+ //#region ../workers-utils/dist/chunk-DCOBXSFB.mjs
1897
1904
  var __create = Object.create;
1898
1905
  var __defProp = Object.defineProperty;
1899
1906
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1931,13 +1938,9 @@ var __toESM = (mod, isNodeMode, target$1) => (target$1 = mod != null ? __create(
1931
1938
  value: mod,
1932
1939
  enumerable: true
1933
1940
  }) : target$1, mod));
1934
- var INHERIT_SYMBOL = Symbol.for("inherit_binding");
1935
- var SERVICE_TAG_PREFIX = "cf:service=";
1936
- var ENVIRONMENT_TAG_PREFIX = "cf:environment=";
1937
- var PATH_TO_DEPLOY_CONFIG = ".wrangler/deploy/config.json";
1938
1941
 
1939
1942
  //#endregion
1940
- //#region ../workers-utils/dist/chunk-BOOBEZKI.mjs
1943
+ //#region ../workers-utils/dist/chunk-GMX45GYB.mjs
1941
1944
  function getLocalWorkerdCompatibilityDate({ projectPath = process.cwd() } = {}) {
1942
1945
  try {
1943
1946
  const miniflareEntry = module$1.createRequire(path3.join(projectPath, "package.json")).resolve("miniflare");
@@ -2116,6 +2119,18 @@ function mapWorkerMetadataBindings(bindings) {
2116
2119
  index_name: binding.index_name
2117
2120
  }];
2118
2121
  break;
2122
+ case "ai_search_namespace":
2123
+ configObj.ai_search_namespaces = [...configObj.ai_search_namespaces ?? [], {
2124
+ binding: binding.name,
2125
+ namespace: binding.namespace
2126
+ }];
2127
+ break;
2128
+ case "ai_search":
2129
+ configObj.ai_search = [...configObj.ai_search ?? [], {
2130
+ binding: binding.name,
2131
+ instance_name: binding.instance_name
2132
+ }];
2133
+ break;
2119
2134
  case "hyperdrive":
2120
2135
  configObj.hyperdrive = [...configObj.hyperdrive ?? [], {
2121
2136
  binding: binding.name,
@@ -2237,7 +2252,57 @@ function constructWranglerConfig(workerOrWorkers) {
2237
2252
  __name(constructWranglerConfig, "constructWranglerConfig");
2238
2253
 
2239
2254
  //#endregion
2240
- //#region ../workers-utils/dist/chunk-NNMRVG4F.mjs
2255
+ //#region ../workers-utils/dist/chunk-O4YGOZSW.mjs
2256
+ var MetricsRegistry = class {
2257
+ static {
2258
+ __name(this, "MetricsRegistry");
2259
+ }
2260
+ counters = [];
2261
+ /**
2262
+ * Create and register a new counter metric.
2263
+ *
2264
+ * @param name - The metric name (e.g. "service_request_total")
2265
+ * @param help - A human-readable description of the metric
2266
+ * @returns A Counter that can be incremented
2267
+ */
2268
+ createCounter(name, help) {
2269
+ const entry = {
2270
+ name,
2271
+ help,
2272
+ value: 0
2273
+ };
2274
+ this.counters.push(entry);
2275
+ return {
2276
+ inc: /* @__PURE__ */ __name(() => {
2277
+ entry.value++;
2278
+ }, "inc"),
2279
+ add: /* @__PURE__ */ __name((amount) => {
2280
+ if (amount < 0) throw new Error("Counter value cannot decrease");
2281
+ entry.value += amount;
2282
+ }, "add")
2283
+ };
2284
+ }
2285
+ /**
2286
+ * Serialize all registered metrics in Prometheus text exposition format.
2287
+ *
2288
+ * @see https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format
2289
+ */
2290
+ metrics() {
2291
+ return this.counters.map((c) => {
2292
+ let result = "";
2293
+ if (c.help.length > 0) result += `# HELP ${c.name} ${c.help}
2294
+ `;
2295
+ result += `# TYPE ${c.name} counter
2296
+ `;
2297
+ result += `${c.name} ${c.value}
2298
+ `;
2299
+ return result;
2300
+ }).join("");
2301
+ }
2302
+ };
2303
+
2304
+ //#endregion
2305
+ //#region ../workers-utils/dist/chunk-A4F3D336.mjs
2241
2306
  var UserError = class extends Error {
2242
2307
  static {
2243
2308
  __name(this, "UserError");
@@ -4239,6 +4304,9 @@ var APIError = class extends ParseError {
4239
4304
  this.name = this.constructor.name;
4240
4305
  this.#status = status;
4241
4306
  }
4307
+ get status() {
4308
+ return this.#status;
4309
+ }
4242
4310
  isGatewayError() {
4243
4311
  if (this.#status !== void 0) return [524].includes(this.#status);
4244
4312
  return false;
@@ -5222,6 +5290,8 @@ var defaultWranglerConfig = {
5222
5290
  r2_buckets: [],
5223
5291
  d1_databases: [],
5224
5292
  vectorize: [],
5293
+ ai_search_namespaces: [],
5294
+ ai_search: [],
5225
5295
  hyperdrive: [],
5226
5296
  workflows: [],
5227
5297
  secrets_store_secrets: [],
@@ -9002,6 +9072,8 @@ var Diagnostics = class {
9002
9072
  errors = [];
9003
9073
  warnings = [];
9004
9074
  children = [];
9075
+ /** Set to true when an unexpected/unknown field is encountered during validation. */
9076
+ hasUnexpectedFields = false;
9005
9077
  /**
9006
9078
  * Merge the given `diagnostics` into this as a child.
9007
9079
  */
@@ -9013,6 +9085,11 @@ var Diagnostics = class {
9013
9085
  if (this.errors.length > 0) return true;
9014
9086
  else return this.children.some((child) => child.hasErrors());
9015
9087
  }
9088
+ /** Does this or any of its children have unexpected fields. */
9089
+ hasUnexpectedFieldsInTree() {
9090
+ if (this.hasUnexpectedFields) return true;
9091
+ else return this.children.some((child) => child.hasUnexpectedFieldsInTree());
9092
+ }
9016
9093
  /** Render the errors of this and all its children. */
9017
9094
  renderErrors() {
9018
9095
  return this.render("errors");
@@ -9205,6 +9282,7 @@ var validateAdditionalProperties = /* @__PURE__ */ __name((diagnostics, fieldPat
9205
9282
  if (restPropSet.size > 0) {
9206
9283
  const fields = Array.from(restPropSet.keys()).map((field) => `"${field}"`);
9207
9284
  diagnostics.warnings.push(`Unexpected fields found in ${fieldPath} field: ${fields}`);
9285
+ diagnostics.hasUnexpectedFields = true;
9208
9286
  return false;
9209
9287
  }
9210
9288
  return true;
@@ -9249,6 +9327,8 @@ var friendlyBindingNames = {
9249
9327
  queues: "Queue",
9250
9328
  d1_databases: "D1 Database",
9251
9329
  vectorize: "Vectorize Index",
9330
+ ai_search_namespaces: "AI Search Namespace",
9331
+ ai_search: "AI Search Instance",
9252
9332
  hyperdrive: "Hyperdrive Config",
9253
9333
  r2_buckets: "R2 Bucket",
9254
9334
  logfwdr: "logfwdr",
@@ -9295,6 +9375,8 @@ var bindingTypeFriendlyNames = {
9295
9375
  r2_bucket: "R2 Bucket",
9296
9376
  d1: "D1 Database",
9297
9377
  vectorize: "Vectorize Index",
9378
+ ai_search_namespace: "AI Search Namespace",
9379
+ ai_search: "AI Search Instance",
9298
9380
  hyperdrive: "Hyperdrive Config",
9299
9381
  service: "Worker",
9300
9382
  fetcher: "Service Binding",
@@ -9758,6 +9840,8 @@ function normalizeAndValidateEnvironment(diagnostics, configPath, rawEnv, isDisp
9758
9840
  r2_buckets: notInheritable(diagnostics, topLevelEnv, rawConfig, rawEnv, envName, "r2_buckets", validateBindingArray(envName, validateR2Binding), []),
9759
9841
  d1_databases: notInheritable(diagnostics, topLevelEnv, rawConfig, rawEnv, envName, "d1_databases", validateBindingArray(envName, validateD1Binding), []),
9760
9842
  vectorize: notInheritable(diagnostics, topLevelEnv, rawConfig, rawEnv, envName, "vectorize", validateBindingArray(envName, validateVectorizeBinding), []),
9843
+ ai_search_namespaces: notInheritable(diagnostics, topLevelEnv, rawConfig, rawEnv, envName, "ai_search_namespaces", validateBindingArray(envName, validateAISearchNamespaceBinding), []),
9844
+ ai_search: notInheritable(diagnostics, topLevelEnv, rawConfig, rawEnv, envName, "ai_search", validateBindingArray(envName, validateAISearchBinding), []),
9761
9845
  hyperdrive: notInheritable(diagnostics, topLevelEnv, rawConfig, rawEnv, envName, "hyperdrive", validateBindingArray(envName, validateHyperdriveBinding), []),
9762
9846
  services: notInheritable(diagnostics, topLevelEnv, rawConfig, rawEnv, envName, "services", validateBindingArray(envName, validateServiceBinding), []),
9763
9847
  analytics_engine_datasets: notInheritable(diagnostics, topLevelEnv, rawConfig, rawEnv, envName, "analytics_engine_datasets", validateBindingArray(envName, validateAnalyticsEngineBinding), []),
@@ -10194,6 +10278,8 @@ var validateUnsafeBinding = /* @__PURE__ */ __name((diagnostics, field, value) =
10194
10278
  "text_blob",
10195
10279
  "browser",
10196
10280
  "ai",
10281
+ "ai_search_namespace",
10282
+ "ai_search",
10197
10283
  "kv_namespace",
10198
10284
  "durable_object_namespace",
10199
10285
  "d1_database",
@@ -10623,6 +10709,50 @@ var validateVectorizeBinding = /* @__PURE__ */ __name((diagnostics, field, value
10623
10709
  ]);
10624
10710
  return isValid2;
10625
10711
  }, "validateVectorizeBinding");
10712
+ var validateAISearchNamespaceBinding = /* @__PURE__ */ __name((diagnostics, field, value) => {
10713
+ if (typeof value !== "object" || value === null) {
10714
+ diagnostics.errors.push(`"ai_search_namespaces" bindings should be objects, but got ${JSON.stringify(value)}`);
10715
+ return false;
10716
+ }
10717
+ let isValid2 = true;
10718
+ if (!isRequiredProperty(value, "binding", "string")) {
10719
+ diagnostics.errors.push(`"${field}" bindings should have a string "binding" field but got ${JSON.stringify(value)}.`);
10720
+ isValid2 = false;
10721
+ }
10722
+ if (!isRequiredProperty(value, "namespace", "string")) {
10723
+ diagnostics.errors.push(`"${field}" bindings must have a "namespace" field but got ${JSON.stringify(value)}.`);
10724
+ isValid2 = false;
10725
+ }
10726
+ if (!isRemoteValid(value, field, diagnostics)) isValid2 = false;
10727
+ validateAdditionalProperties(diagnostics, field, Object.keys(value), [
10728
+ "binding",
10729
+ "namespace",
10730
+ "remote"
10731
+ ]);
10732
+ return isValid2;
10733
+ }, "validateAISearchNamespaceBinding");
10734
+ var validateAISearchBinding = /* @__PURE__ */ __name((diagnostics, field, value) => {
10735
+ if (typeof value !== "object" || value === null) {
10736
+ diagnostics.errors.push(`"ai_search" bindings should be objects, but got ${JSON.stringify(value)}`);
10737
+ return false;
10738
+ }
10739
+ let isValid2 = true;
10740
+ if (!isRequiredProperty(value, "binding", "string")) {
10741
+ diagnostics.errors.push(`"${field}" bindings should have a string "binding" field but got ${JSON.stringify(value)}.`);
10742
+ isValid2 = false;
10743
+ }
10744
+ if (!isRequiredProperty(value, "instance_name", "string")) {
10745
+ diagnostics.errors.push(`"${field}" bindings must have an "instance_name" field but got ${JSON.stringify(value)}.`);
10746
+ isValid2 = false;
10747
+ }
10748
+ if (!isRemoteValid(value, field, diagnostics)) isValid2 = false;
10749
+ validateAdditionalProperties(diagnostics, field, Object.keys(value), [
10750
+ "binding",
10751
+ "instance_name",
10752
+ "remote"
10753
+ ]);
10754
+ return isValid2;
10755
+ }, "validateAISearchBinding");
10626
10756
  var validateHyperdriveBinding = /* @__PURE__ */ __name((diagnostics, field, value) => {
10627
10757
  if (typeof value !== "object" || value === null) {
10628
10758
  diagnostics.errors.push(`"hyperdrive" bindings should be objects, but got ${JSON.stringify(value)}`);
@@ -10838,6 +10968,10 @@ var validateConsumer = /* @__PURE__ */ __name((diagnostics, field, value, _confi
10838
10968
  "retry_delay"
10839
10969
  ])) isValid2 = false;
10840
10970
  if (!isRequiredProperty(value, "queue", "string")) diagnostics.errors.push(`"${field}" should have a string "queue" field but got ${JSON.stringify(value)}.`);
10971
+ if ("type" in value && value.type !== void 0 && value.type !== "worker") {
10972
+ diagnostics.errors.push(`"${field}.type" has an invalid value "${value.type}". Only "worker" consumers can be configured in your Wrangler configuration.`);
10973
+ isValid2 = false;
10974
+ }
10841
10975
  for (const optionalOpt of [
10842
10976
  {
10843
10977
  key: "type",
@@ -19266,14 +19400,15 @@ const additionalModulesPlugin = createPlugin("additional-modules", (ctx) => {
19266
19400
  resolveId: {
19267
19401
  filter: { id: moduleRuleFilters },
19268
19402
  async handler(source, importer, options) {
19269
- const additionalModuleType = matchAdditionalModule(source);
19270
- if (!additionalModuleType) return;
19271
- const resolved = await this.resolve(cleanUrl(source), importer, options);
19272
- if (!resolved) throw new Error(`Import "${source}" not found. Does the file exist?`);
19273
- additionalModulePaths.add(resolved.id);
19403
+ const resolved = await this.resolve(source, importer, options);
19404
+ if (!resolved) return;
19405
+ const additionalModuleType = matchAdditionalModule(resolved.id);
19406
+ if (!additionalModuleType) return resolved;
19407
+ const filePath = cleanUrl(resolved.id);
19408
+ additionalModulePaths.add(filePath);
19274
19409
  return {
19275
19410
  external: true,
19276
- id: createModuleReference(additionalModuleType, resolved.id)
19411
+ id: createModuleReference(additionalModuleType, filePath)
19277
19412
  };
19278
19413
  }
19279
19414
  },
@@ -19338,7 +19473,8 @@ const moduleRules = [
19338
19473
  pattern: /\.(txt|html|sql)$/
19339
19474
  }
19340
19475
  ];
19341
- const moduleRuleFilters = moduleRules.map((rule) => rule.pattern);
19476
+ const subpathImportRE = /^#/;
19477
+ const moduleRuleFilters = [...moduleRules.map((rule) => rule.pattern), subpathImportRE];
19342
19478
  function matchAdditionalModule(source) {
19343
19479
  for (const rule of moduleRules) if (rule.pattern.test(source)) return rule.type;
19344
19480
  return null;
@@ -26195,6 +26331,7 @@ let ImageRegistryNotFoundError;
26195
26331
  let ImageRegistryPermissions = /* @__PURE__ */ function(ImageRegistryPermissions$1) {
26196
26332
  ImageRegistryPermissions$1["PULL"] = "pull";
26197
26333
  ImageRegistryPermissions$1["PUSH"] = "push";
26334
+ ImageRegistryPermissions$1["LIBRARY_PUSH"] = "library_push";
26198
26335
  return ImageRegistryPermissions$1;
26199
26336
  }({});
26200
26337
 
@@ -26484,7 +26621,8 @@ function dockerBuild(dockerPath, options) {
26484
26621
  "inherit",
26485
26622
  "inherit"
26486
26623
  ],
26487
- detached: true
26624
+ detached: process.platform !== "win32",
26625
+ windowsHide: true
26488
26626
  });
26489
26627
  if (child.stdin !== null) {
26490
26628
  child.stdin.write(options.dockerfile);
@@ -26506,7 +26644,8 @@ function dockerBuild(dockerPath, options) {
26506
26644
  return {
26507
26645
  abort: () => {
26508
26646
  child.unref();
26509
- if (child.pid !== void 0) process.kill(-child.pid);
26647
+ if (child.pid !== void 0) if (process.platform === "win32") child.kill();
26648
+ else process.kill(-child.pid);
26510
26649
  },
26511
26650
  ready
26512
26651
  };
@@ -26614,7 +26753,8 @@ const runDockerCmd = (dockerPath, args, stdio) => {
26614
26753
  });
26615
26754
  const child = spawn(dockerPath, args, {
26616
26755
  stdio: stdio ?? "inherit",
26617
- detached: true
26756
+ detached: process.platform !== "win32",
26757
+ windowsHide: true
26618
26758
  });
26619
26759
  let errorHandled = false;
26620
26760
  child.on("close", (code) => {
@@ -26634,7 +26774,8 @@ const runDockerCmd = (dockerPath, args, stdio) => {
26634
26774
  abort: () => {
26635
26775
  aborted = true;
26636
26776
  child.unref();
26637
- if (child.pid !== void 0) process.kill(-child.pid);
26777
+ if (child.pid !== void 0) if (process.platform === "win32") child.kill();
26778
+ else process.kill(-child.pid);
26638
26779
  },
26639
26780
  ready,
26640
26781
  then: async (onResolve, onReject) => ready.then(onResolve).catch(onReject)