@cloudflare/vite-plugin 1.20.1 → 1.20.3

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
@@ -15,7 +15,7 @@ import { URL as URL$1, fileURLToPath, pathToFileURL } from "node:url";
15
15
  import process2 from "node:process";
16
16
  import os from "node:os";
17
17
  import { defu } from "defu";
18
- import { getCloudflarePreset } from "@cloudflare/unenv-preset";
18
+ import { getCloudflarePreset, nonPrefixedNodeModules } from "@cloudflare/unenv-preset";
19
19
  import v8 from "node:v8";
20
20
  import { defineEnv } from "unenv";
21
21
  import * as fsp from "node:fs/promises";
@@ -1557,6 +1557,7 @@ function toMiniflareRequest(request$1) {
1557
1557
  signal: request$1.signal
1558
1558
  });
1559
1559
  }
1560
+ const isRolldown = "rolldownVersion" in vite;
1560
1561
 
1561
1562
  //#endregion
1562
1563
  //#region src/export-types.ts
@@ -6838,6 +6839,14 @@ function validateContainerApp(envName, topLevelName, configPath) {
6838
6839
  if (!isRequiredProperty(key, "public_key", "string")) diagnostics.errors.push(`${fieldPath}.public_key must be a string`);
6839
6840
  if (!key.public_key.toLowerCase().startsWith("ssh-ed25519")) diagnostics.errors.push(`${fieldPath}.public_key is a unsupported key type. Please provide a ED25519 public key.`);
6840
6841
  }
6842
+ if (validateOptionalProperty(diagnostics, field, "constraints", containerAppOptional.constraints, "object") && containerAppOptional.constraints) {
6843
+ const constraints = containerAppOptional.constraints;
6844
+ if ("tier" in constraints) {
6845
+ diagnostics.warnings.push(`"constraints.tier" has been deprecated in favor of "constraints.tiers". Please update your configuration to use "constraints.tiers" instead.`);
6846
+ if ("tiers" in constraints) diagnostics.errors.push(`${field}.constraints.tier and ${field}.constraints.tiers cannot both be set`);
6847
+ }
6848
+ validateOptionalTypedArray(diagnostics, `${field}.constraints.tiers`, constraints.tiers, "number");
6849
+ }
6841
6850
  if (typeof containerAppOptional.instance_type === "string") {
6842
6851
  validateOptionalProperty(diagnostics, field, "instance_type", containerAppOptional.instance_type, "string", ALLOWED_INSTANCE_TYPES);
6843
6852
  if (containerAppOptional.instance_type === "dev") diagnostics.warnings.push(`The "dev" instance_type has been renamed to "lite" and will be removed in a subsequent version. Please update your configuration to use "lite" instead.`);
@@ -14035,11 +14044,6 @@ function hasNodeJsCompat(workerConfig) {
14035
14044
  function hasNodeJsAls(workerConfig) {
14036
14045
  return workerConfig !== void 0 && getNodeCompat(workerConfig.compatibility_date, workerConfig.compatibility_flags ?? []).mode === "als";
14037
14046
  }
14038
- /**
14039
- * All the Node.js modules including their `node:...` aliases.
14040
- */
14041
- const nodeJsBuiltins = new Set([...builtinModules, ...builtinModules.map((m) => `node:${m}`)]);
14042
- const NODEJS_MODULES_RE = /* @__PURE__ */ new RegExp(`^(node:)?(${builtinModules.join("|")})$`);
14043
14047
  function isNodeAlsModule(modulePath) {
14044
14048
  return /^(?:node:)?async_hooks$/.test(modulePath);
14045
14049
  }
@@ -21420,13 +21424,24 @@ const defaultConditions = [
21420
21424
  "browser"
21421
21425
  ];
21422
21426
  const target = "es2024";
21427
+ const rollupOptions = {
21428
+ input: { [MAIN_ENTRY_NAME]: VIRTUAL_WORKER_ENTRY },
21429
+ preserveEntrySignatures: "strict"
21430
+ };
21431
+ const resolveExtensions = [
21432
+ ".mjs",
21433
+ ".js",
21434
+ ".mts",
21435
+ ".ts",
21436
+ ".jsx",
21437
+ ".tsx",
21438
+ ".json",
21439
+ ".cjs",
21440
+ ".cts",
21441
+ ".ctx"
21442
+ ];
21423
21443
  function createCloudflareEnvironmentOptions({ workerConfig, userConfig, mode, environmentName, isEntryWorker, hasNodeJsCompat: hasNodeJsCompat$1 }) {
21424
- const isRolldown = "rolldownVersion" in vite;
21425
21444
  const define$1 = getProcessEnvReplacements(hasNodeJsCompat$1, mode);
21426
- const rollupOptions = {
21427
- input: { [MAIN_ENTRY_NAME]: VIRTUAL_WORKER_ENTRY },
21428
- preserveEntrySignatures: "strict"
21429
- };
21430
21445
  return {
21431
21446
  resolve: {
21432
21447
  noExternal: true,
@@ -21449,7 +21464,8 @@ function createCloudflareEnvironmentOptions({ workerConfig, userConfig, mode, en
21449
21464
  ssr: true,
21450
21465
  ...isRolldown ? { rolldownOptions: {
21451
21466
  ...rollupOptions,
21452
- platform: "neutral"
21467
+ platform: "neutral",
21468
+ resolve: { extensions: resolveExtensions }
21453
21469
  } } : { rollupOptions }
21454
21470
  },
21455
21471
  optimizeDeps: {
@@ -21461,18 +21477,7 @@ function createCloudflareEnvironmentOptions({ workerConfig, userConfig, mode, en
21461
21477
  platform: "neutral",
21462
21478
  resolve: {
21463
21479
  conditionNames: [...defaultConditions, "development"],
21464
- extensions: [
21465
- ".mjs",
21466
- ".js",
21467
- ".mts",
21468
- ".ts",
21469
- ".jsx",
21470
- ".tsx",
21471
- ".json",
21472
- ".cjs",
21473
- ".cts",
21474
- ".ctx"
21475
- ]
21480
+ extensions: resolveExtensions
21476
21481
  },
21477
21482
  transform: {
21478
21483
  target,
@@ -21480,20 +21485,9 @@ function createCloudflareEnvironmentOptions({ workerConfig, userConfig, mode, en
21480
21485
  }
21481
21486
  } } : { esbuildOptions: {
21482
21487
  platform: "neutral",
21483
- target,
21484
21488
  conditions: [...defaultConditions, "development"],
21485
- resolveExtensions: [
21486
- ".mjs",
21487
- ".js",
21488
- ".mts",
21489
- ".ts",
21490
- ".jsx",
21491
- ".tsx",
21492
- ".json",
21493
- ".cjs",
21494
- ".cts",
21495
- ".ctx"
21496
- ],
21489
+ resolveExtensions,
21490
+ target,
21497
21491
  define: define$1
21498
21492
  } }
21499
21493
  },
@@ -23483,7 +23477,16 @@ const nodeJsCompatPlugin = createPlugin("nodejs-compat", (ctx) => {
23483
23477
  const nodeJsCompat = ctx.getNodeJsCompat(name);
23484
23478
  if (nodeJsCompat) return {
23485
23479
  resolve: { builtins: [...nodeJsCompat.externals] },
23486
- optimizeDeps: { exclude: [...nodeJsBuiltins] }
23480
+ optimizeDeps: { exclude: [
23481
+ ...nonPrefixedNodeModules,
23482
+ ...nonPrefixedNodeModules.map((module$2) => `node:${module$2}`),
23483
+ ...[
23484
+ "node:sea",
23485
+ "node:sqlite",
23486
+ "node:test",
23487
+ "node:test/reporters"
23488
+ ]
23489
+ ] }
23487
23490
  };
23488
23491
  },
23489
23492
  applyToEnvironment(environment) {
@@ -23540,7 +23543,7 @@ const nodeJsCompatWarningsPlugin = createPlugin("nodejs-compat-warnings", (ctx)
23540
23543
  if (workerConfig && !nodeJsCompat) {
23541
23544
  if (hasNodeJsAls(workerConfig) && isNodeAlsModule(source)) return;
23542
23545
  const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
23543
- if (nodeJsBuiltins.has(source)) {
23546
+ if (source.startsWith("node:") || nonPrefixedNodeModules.includes(source)) {
23544
23547
  nodeJsCompatWarnings?.registerImport(source, importer);
23545
23548
  return {
23546
23549
  id: source,
@@ -23554,7 +23557,7 @@ const nodeJsCompatWarningsPlugin = createPlugin("nodejs-compat-warnings", (ctx)
23554
23557
  configEnvironment(environmentName) {
23555
23558
  const workerConfig = ctx.getWorkerConfig(environmentName);
23556
23559
  const nodeJsCompat = ctx.getNodeJsCompat(environmentName);
23557
- if (workerConfig && !nodeJsCompat) return { optimizeDeps: { ..."rolldownVersion" in vite ? { rolldownOptions: { plugins: [{
23560
+ if (workerConfig && !nodeJsCompat) return { optimizeDeps: { ...isRolldown ? { rolldownOptions: { plugins: [{
23558
23561
  name: "vite-plugin-cloudflare:nodejs-compat-warnings-resolver",
23559
23562
  resolveId(source, importer) {
23560
23563
  return resolveId(environmentName, source, importer);
@@ -23562,7 +23565,7 @@ const nodeJsCompatWarningsPlugin = createPlugin("nodejs-compat-warnings", (ctx)
23562
23565
  }] } } : { esbuildOptions: { plugins: [{
23563
23566
  name: "vite-plugin-cloudflare:nodejs-compat-warnings-resolver",
23564
23567
  setup(build) {
23565
- build.onResolve({ filter: NODEJS_MODULES_RE }, ({ path, importer }) => {
23568
+ build.onResolve({ filter: /* @__PURE__ */ new RegExp(`^(${nonPrefixedNodeModules.join("|")}|node:.+)$`) }, ({ path, importer }) => {
23566
23569
  if (hasNodeJsAls(workerConfig) && isNodeAlsModule(path)) return;
23567
23570
  nodeJsCompatWarningsMap.get(workerConfig)?.registerImport(path, importer);
23568
23571
  return {
@@ -23580,6 +23583,9 @@ const nodeJsCompatWarningsPlugin = createPlugin("nodejs-compat-warnings", (ctx)
23580
23583
  if (workerConfig && !nodeJsCompat) nodeJsCompatWarningsMap.set(workerConfig, new NodeJsCompatWarnings(environmentName, resolvedViteConfig));
23581
23584
  }
23582
23585
  },
23586
+ applyToEnvironment(environment) {
23587
+ return ctx.getWorkerConfig(environment.name) !== void 0 && !ctx.getNodeJsCompat(environment.name);
23588
+ },
23583
23589
  async resolveId(source, importer) {
23584
23590
  return resolveId(this.environment.name, source, importer);
23585
23591
  }