vite-plugin-vercel 11.0.0-beta.11 → 11.0.0-beta.13

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/api.js CHANGED
@@ -1,3 +1,65 @@
1
- import { n as getVercelAPI, t as createAPI } from "./api-DR2y7JVQ.js";
1
+ import { t as assert } from "./assert-vtiLgQIb.js";
2
2
 
3
+ //#region src/api.ts
4
+ function createAPI(outfiles, pluginConfig) {
5
+ return {
6
+ getOutFiles() {
7
+ return outfiles;
8
+ },
9
+ get config() {
10
+ pluginConfig.config ??= {};
11
+ return pluginConfig.config;
12
+ },
13
+ get defaultMaxDuration() {
14
+ return pluginConfig.defaultMaxDuration;
15
+ },
16
+ set defaultMaxDuration(value) {
17
+ pluginConfig.defaultMaxDuration = value;
18
+ },
19
+ get expiration() {
20
+ return pluginConfig.expiration;
21
+ },
22
+ set expiration(value) {
23
+ pluginConfig.expiration = value;
24
+ },
25
+ get rewrites() {
26
+ pluginConfig.rewrites ??= [];
27
+ return pluginConfig.rewrites;
28
+ },
29
+ get headers() {
30
+ pluginConfig.headers ??= [];
31
+ return pluginConfig.headers;
32
+ },
33
+ get redirects() {
34
+ pluginConfig.redirects ??= [];
35
+ return pluginConfig.redirects;
36
+ },
37
+ get cleanUrls() {
38
+ return pluginConfig.cleanUrls;
39
+ },
40
+ set cleanUrls(value) {
41
+ pluginConfig.cleanUrls = value;
42
+ },
43
+ get trailingSlash() {
44
+ return pluginConfig.trailingSlash;
45
+ },
46
+ set trailingSlash(value) {
47
+ pluginConfig.trailingSlash = value;
48
+ },
49
+ get defaultSupportsResponseStreaming() {
50
+ return pluginConfig.defaultSupportsResponseStreaming;
51
+ },
52
+ set defaultSupportsResponseStreaming(value) {
53
+ pluginConfig.defaultSupportsResponseStreaming = value;
54
+ }
55
+ };
56
+ }
57
+ function getVercelAPI(pluginContextOrServer) {
58
+ const vpv = ("environment" in pluginContextOrServer ? pluginContextOrServer.environment.config : pluginContextOrServer.config).plugins.find((p) => p.name === "vite-plugin-vercel:api");
59
+ assert(vpv, "Could not find vite-plugin-vercel:api plugin");
60
+ assert(vpv.api, "Missing `api`. Make sure vite-plugin-vercel is up-to-date");
61
+ return vpv.api("environment" in pluginContextOrServer ? pluginContextOrServer : void 0);
62
+ }
63
+
64
+ //#endregion
3
65
  export { createAPI, getVercelAPI };
@@ -0,0 +1,8 @@
1
+ //#region src/utils/assert.ts
2
+ function assert(condition, errorMessage) {
3
+ if (condition) return;
4
+ throw new Error(`[vite-plugin-vercel] ${errorMessage}`);
5
+ }
6
+
7
+ //#endregion
8
+ export { assert as t };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as pathRelativeTo } from "./path-B4ThGm96.js";
1
+ import { t as pathRelativeTo } from "./path-DoLvGKnz.js";
2
2
  import path from "node:path";
3
3
  import { vercelEndpointExports } from "@vite-plugin-vercel/schemas";
4
4
  import { fromNextFs } from "convert-route/next-fs";
@@ -31,7 +31,7 @@ async function getVercelEntries(dir, { destination = dir, tryParseExports = true
31
31
  if (xports?.isr) entry.vercel.isr = xports.isr;
32
32
  if (xports?.headers) entry.vercel.headers = xports.headers;
33
33
  if (xports?.streaming) entry.vercel.streaming = xports.streaming;
34
- entry.pattern = entryToRou3(key);
34
+ entry.route = entryToRou3(key);
35
35
  if (key.includes("[...")) entry.vercel.enforce = "post";
36
36
  entryPoints.push(entry);
37
37
  }
package/dist/vite.js CHANGED
@@ -1,12 +1,13 @@
1
- import { t as pathRelativeTo$1 } from "./path-B4ThGm96.js";
2
- import { n as getVercelAPI, r as assert, t as createAPI } from "./api-DR2y7JVQ.js";
1
+ import { t as pathRelativeTo$1 } from "./path-DoLvGKnz.js";
2
+ import { t as assert } from "./assert-vtiLgQIb.js";
3
+ import { createAPI, getVercelAPI } from "./api.js";
3
4
  import { builtinModules } from "node:module";
4
5
  import path from "node:path";
5
6
  import { vercelOutputConfigSchema, vercelOutputPrerenderConfigSchema, vercelOutputVcConfigSchema } from "@vite-plugin-vercel/schemas";
6
7
  import { fromRou3 } from "convert-route/rou3";
7
8
  import { BuildEnvironment, createRunnableDevEnvironment, mergeConfig, normalizePath } from "vite";
8
9
  import { catchAll, devServer } from "@universal-deploy/store/vite";
9
- import { store } from "@universal-deploy/store";
10
+ import { addEntry, getAllEntries } from "@universal-deploy/store";
10
11
  import fs, { existsSync, readFileSync, writeFileSync } from "node:fs";
11
12
  import { copyFile, cp, rmdir, unlink } from "node:fs/promises";
12
13
  import { findRoot } from "@manypkg/find-root";
@@ -37,17 +38,17 @@ function getBuildEnvNames(pluginConfig) {
37
38
  */
38
39
  function dedupeRoutes() {
39
40
  const entriesToKeep = [];
40
- const entriesGroupedByModuleId = groupBy(store.entries, (e) => e.id);
41
+ const entriesGroupedByModuleId = groupBy(getAllEntries(), (e) => e.id);
41
42
  for (const entries of entriesGroupedByModuleId.values()) {
42
43
  let groupedEntry;
43
44
  for (const entry of entries) if (entry.vercel && Object.keys(entry.vercel).length > 0) {
44
- if (!Array.isArray(entry.pattern)) entry.pattern = [entry.pattern];
45
+ if (!Array.isArray(entry.route)) entry.route = [entry.route];
45
46
  entriesToKeep.push(entry);
46
47
  } else if (!groupedEntry) {
47
48
  groupedEntry = structuredClone(entry);
48
- if (!Array.isArray(groupedEntry.pattern)) groupedEntry.pattern = [groupedEntry.pattern];
49
+ if (!Array.isArray(groupedEntry.route)) groupedEntry.route = [groupedEntry.route];
49
50
  entriesToKeep.push(groupedEntry);
50
- } else groupedEntry.pattern.push(...[entry.pattern].flat());
51
+ } else groupedEntry.route.push(...[entry.route].flat());
51
52
  }
52
53
  return entriesToKeep;
53
54
  }
@@ -115,23 +116,23 @@ function removeExtension$1(subject) {
115
116
  //#endregion
116
117
  //#region src/utils/destination.ts
117
118
  function parseViteId(id) {
118
- const [path$1, query] = id.split("?");
119
+ const [path, query] = id.split("?");
119
120
  return {
120
- path: decodeURIComponent(path$1),
121
+ path: decodeURIComponent(path),
121
122
  query
122
123
  };
123
124
  }
124
- function extractBestPath({ path: path$1, query }) {
125
- if (!query) return path$1;
126
- return query.split("&").map(decodeURIComponent).find((p) => p.includes("/")) || path$1;
125
+ function extractBestPath({ path, query }) {
126
+ if (!query) return path;
127
+ return query.split("&").map(decodeURIComponent).find((p) => p.includes("/")) || path;
127
128
  }
128
- function shortenPath(path$1, maxSegments = 2) {
129
- return removeExtension$1(path$1.split(/[\\/]/).filter(Boolean).slice(-maxSegments).join("_"));
129
+ function shortenPath(path, maxSegments = 2) {
130
+ return removeExtension$1(path.split(/[\\/]/).filter(Boolean).slice(-maxSegments).join("_"));
130
131
  }
131
- function mapPath(path$1, maxSegments = 2) {
132
- const nodeModuleMatch = path$1.match(/node_modules[\\/](.+?)([\\/].*)?$/);
132
+ function mapPath(path, maxSegments = 2) {
133
+ const nodeModuleMatch = path.match(/node_modules[\\/](.+?)([\\/].*)?$/);
133
134
  if (nodeModuleMatch) return `${nodeModuleMatch[1].split(/[\\/]/)[0]}_${removeExtension$1(nodeModuleMatch[2]?.split(/[\\/]/).pop() || "index")}`;
134
- return shortenPath(path$1, maxSegments);
135
+ return shortenPath(path, maxSegments);
135
136
  }
136
137
  function hashString(str, length = 6) {
137
138
  let hash = 5381;
@@ -162,10 +163,10 @@ function apiPlugin(pluginConfig) {
162
163
  applyToEnvironment({ name }) {
163
164
  return name === envNames.edge || name === envNames.node;
164
165
  },
165
- writeBundle(_opts, bundle$2) {
166
+ writeBundle(_opts, bundle) {
166
167
  const root = this.environment.config.root ?? process.cwd();
167
168
  const entryMapByDestination = new Map(dedupeRoutes().map((e) => [entryDestination(root, e, ".func/index"), e]));
168
- for (const [key, value] of Object.entries(bundle$2)) if (value.type === "chunk" && entryMapByDestination.has(removeExtension$1(key))) outfiles.push({
169
+ for (const [key, value] of Object.entries(bundle)) if (value.type === "chunk" && entryMapByDestination.has(removeExtension$1(key))) outfiles.push({
169
170
  type: "chunk",
170
171
  root: this.environment.config.root,
171
172
  outdir: this.environment.config.build.outDir,
@@ -246,8 +247,8 @@ function basicBundlePlugin(pluginConfig) {
246
247
  name: "vite-plugin-vercel:bundle",
247
248
  enforce: "post",
248
249
  apply: "build",
249
- generateBundle(_opts, bundle$2) {
250
- for (const b of Object.values(bundle$2)) {
250
+ generateBundle(_opts, bundle) {
251
+ for (const b of Object.values(bundle)) {
251
252
  const outFile = joinAbsolute(this.environment, this.environment.config.build.outDir, b.fileName);
252
253
  if (b.type === "asset") {
253
254
  const originalFileNames = b.originalFileNames.map((relativePath) => path.resolve(this.environment.config.root, relativePath));
@@ -292,7 +293,7 @@ async function bundle$1(pluginContext, bundledAssets, outfile) {
292
293
  buildOptions.output = {
293
294
  format: "esm",
294
295
  legalComments: "none",
295
- inlineDynamicImports: true
296
+ codeSplitting: false
296
297
  };
297
298
  buildOptions.checks = { pluginTimings: false };
298
299
  buildOptions.input = [source];
@@ -312,13 +313,6 @@ async function bundle$1(pluginContext, bundledAssets, outfile) {
312
313
  } else {
313
314
  buildOptions.platform = "node";
314
315
  buildOptions.output.file = destination.replace(/\.js$/, ".mjs");
315
- buildOptions.output.banner = `import { createRequire as topLevelCreateRequire } from 'node:module';
316
- import { dirname as topLevelDirname } from 'node:path';
317
- import { fileURLToPath as topLevelFileURLToPath } from 'node:url';
318
- var require = topLevelCreateRequire(import.meta.url);
319
- var __filename = topLevelFileURLToPath(import.meta.url);
320
- var __dirname = topLevelDirname(__filename);
321
- `;
322
316
  }
323
317
  try {
324
318
  await build(buildOptions);
@@ -417,15 +411,15 @@ function nf3BundlePlugin(pluginConfig) {
417
411
  async writeBundle(_, output) {
418
412
  const isEdge = this.environment.name === envNames.edge;
419
413
  const config = this.environment.config;
420
- const outDir$1 = normalizePath(path.isAbsolute(config.build.outDir) ? config.build.outDir : path.join(config.root, config.build.outDir));
414
+ const outDir = normalizePath(path.isAbsolute(config.build.outDir) ? config.build.outDir : path.join(config.root, config.build.outDir));
421
415
  const entries = Object.entries(output).filter((e) => "isEntry" in e[1] && e[1].isEntry).map((e) => ({
422
416
  name: e[1].name,
423
417
  fileName: e[1].fileName,
424
- outPath: path.join(outDir$1, e[1].fileName)
418
+ outPath: path.join(outDir, e[1].fileName)
425
419
  }));
426
420
  if (entries.length === 0) return;
427
421
  const outPaths = entries.map((entry) => entry.outPath);
428
- const input = Object.fromEntries(outPaths.map((e) => [removeExtension(pathRelativeTo(e, outDir$1)), e]));
422
+ const input = Object.fromEntries(outPaths.map((e) => [removeExtension(pathRelativeTo(e, outDir)), e]));
429
423
  const limit = pLimit(Math.max(1, Math.ceil(cpus().length / 2)));
430
424
  const nonVitePlugins = this.environment.config.plugins.filter((p) => {
431
425
  return !p.name.startsWith("vite:") && p.name !== "alias" && p.name !== "commonjs" && p.name !== "nitro:externals";
@@ -434,12 +428,12 @@ function nf3BundlePlugin(pluginConfig) {
434
428
  return rest;
435
429
  });
436
430
  const localOutput = (await Promise.all(Object.values(input).map((entryPath) => limit(async () => {
437
- const outDir$2 = path.dirname(entryPath);
431
+ const outDir = path.dirname(entryPath);
438
432
  return { output: (await bundle({
439
433
  plugins: nonVitePlugins,
440
434
  isEdge,
441
435
  input: { index: entryPath },
442
- outDir: outDir$2,
436
+ outDir,
443
437
  externals: {
444
438
  conditions: this.environment.config.resolve.conditions,
445
439
  rootDir: this.environment.config.root,
@@ -452,7 +446,7 @@ function nf3BundlePlugin(pluginConfig) {
452
446
  }
453
447
  })).output.map((o) => ({
454
448
  ...o,
455
- fileName: path.join(outDir$2, o.fileName)
449
+ fileName: path.join(outDir, o.fileName)
456
450
  })) };
457
451
  })))).flatMap((r) => r.output);
458
452
  buildOutput = buildOutput ? [...buildOutput, ...localOutput] : localOutput;
@@ -551,7 +545,7 @@ function getVcConfig(pluginConfig, filename, options) {
551
545
 
552
546
  //#endregion
553
547
  //#region src/plugins/loader.ts
554
- const re_DUMMY = /* @__PURE__ */ new RegExp(`__DUMMY__$`);
548
+ const re_DUMMY = new RegExp(`__DUMMY__$`);
555
549
  const re_edge = /[?&]vercel_edge\b/;
556
550
  const re_node = /[?&]vercel_node\b/;
557
551
  function loaderPlugin(pluginConfig) {
@@ -661,7 +655,7 @@ export default def;`;
661
655
  source: JSON.stringify(vercelOutputPrerenderConfigSchema.parse(entry.vercel.isr), void 0, 2)
662
656
  });
663
657
  pluginConfig.rewrites ??= [];
664
- for (const ir of sortRoutes([entry.pattern].flat().map((p) => fromRou3(p)))) {
658
+ for (const ir of sortRoutes([entry.route].flat().map((p) => fromRou3(p)))) {
665
659
  const source = toPathToRegexpV6(ir);
666
660
  pluginConfig.rewrites.push({
667
661
  enforce: entry.vercel?.enforce,
@@ -787,7 +781,9 @@ function setupEnvs(pluginConfig) {
787
781
  handler() {
788
782
  if (!injected) {
789
783
  injected = true;
790
- if (pluginConfig.entries) store.entries.push(...pluginConfig.entries);
784
+ if (pluginConfig.entries) pluginConfig.entries.forEach((entry) => {
785
+ addEntry(entry);
786
+ });
791
787
  }
792
788
  const outDirOverride = pluginConfig.outDir ? { build: { outDir: pluginConfig.outDir } } : {};
793
789
  const environments = {};
@@ -842,8 +838,8 @@ function setupEnvs(pluginConfig) {
842
838
  },
843
839
  generateBundle: {
844
840
  order: "post",
845
- async handler(_opts, bundle$2) {
846
- cleanupDummy(bundle$2);
841
+ async handler(_opts, bundle) {
842
+ cleanupDummy(bundle);
847
843
  }
848
844
  },
849
845
  sharedDuringBuild: true
@@ -859,8 +855,8 @@ function setupEnvs(pluginConfig) {
859
855
  },
860
856
  generateBundle: {
861
857
  order: "post",
862
- async handler(_opts, bundle$2) {
863
- cleanupDummy(bundle$2);
858
+ async handler(_opts, bundle) {
859
+ cleanupDummy(bundle);
864
860
  this.emitFile({
865
861
  type: "asset",
866
862
  fileName: "config.json",
@@ -875,8 +871,8 @@ function setupEnvs(pluginConfig) {
875
871
  applyToEnvironment(env) {
876
872
  return env.name === envNames.client;
877
873
  },
878
- generateBundle: { async handler(_opts, bundle$2) {
879
- cleanupDummy(bundle$2);
874
+ generateBundle: { async handler(_opts, bundle) {
875
+ cleanupDummy(bundle);
880
876
  const topLevelConfig = this.environment.getTopLevelConfig();
881
877
  const clientEnv = topLevelConfig.environments.client;
882
878
  if (clientEnv) try {
@@ -924,9 +920,9 @@ function createVercelEnvironmentOptions(overrides) {
924
920
  function getDummyInput() {
925
921
  return { [DUMMY]: `${virtualEntry}:${DUMMY}` };
926
922
  }
927
- function cleanupDummy(bundle$2) {
928
- const dummy = Object.keys(bundle$2).find((key) => key.includes("_DUMMY_"));
929
- if (dummy) delete bundle$2[dummy];
923
+ function cleanupDummy(bundle) {
924
+ const dummy = Object.keys(bundle).find((key) => key.includes("_DUMMY_"));
925
+ if (dummy) delete bundle[dummy];
930
926
  }
931
927
 
932
928
  //#endregion
@@ -943,7 +939,6 @@ function vercel(pluginConfig = {}) {
943
939
  devServer()
944
940
  ];
945
941
  }
946
- var plugins_default = vercel;
947
942
 
948
943
  //#endregion
949
- export { plugins_default as default, vercel };
944
+ export { vercel as default, vercel };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vercel",
3
- "version": "11.0.0-beta.11",
3
+ "version": "11.0.0-beta.13",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -26,14 +26,14 @@
26
26
  "@types/node": "^22.19.3",
27
27
  "@universal-middleware/express": "^0.4.22",
28
28
  "@vercel/node": "^5.5.15",
29
- "tsdown": "^0.18.4",
29
+ "tsdown": "^0.20.3",
30
30
  "typescript": "^5.9.3",
31
31
  "vite": "^7.2.4",
32
32
  "vitest": "^4.0.16"
33
33
  },
34
34
  "dependencies": {
35
35
  "@manypkg/find-root": "^3.1.0",
36
- "@universal-deploy/store": "^0.0.6",
36
+ "@universal-deploy/store": "^0.0.8-beta.1",
37
37
  "@universal-middleware/core": "^0.4.13",
38
38
  "@universal-middleware/vercel": "^0.4.29",
39
39
  "@vercel/build-utils": "^13.2.3",
@@ -46,7 +46,7 @@
46
46
  "oxc-transform": "^0.108.0",
47
47
  "p-limit": "^7.2.0",
48
48
  "path-to-regexp": "^8.3.0",
49
- "rolldown": "^1.0.0-beta.58",
49
+ "rolldown": "^1.0.0-rc.4",
50
50
  "strip-ansi": "^7.1.2",
51
51
  "vite-plugin-wasm": "^3.5.0",
52
52
  "@vite-plugin-vercel/schemas": "^1.0.0"
@@ -1,70 +0,0 @@
1
- //#region src/utils/assert.ts
2
- function assert(condition, errorMessage) {
3
- if (condition) return;
4
- throw new Error(`[vite-plugin-vercel] ${errorMessage}`);
5
- }
6
-
7
- //#endregion
8
- //#region src/api.ts
9
- function createAPI(outfiles, pluginConfig) {
10
- return {
11
- getOutFiles() {
12
- return outfiles;
13
- },
14
- get config() {
15
- pluginConfig.config ??= {};
16
- return pluginConfig.config;
17
- },
18
- get defaultMaxDuration() {
19
- return pluginConfig.defaultMaxDuration;
20
- },
21
- set defaultMaxDuration(value) {
22
- pluginConfig.defaultMaxDuration = value;
23
- },
24
- get expiration() {
25
- return pluginConfig.expiration;
26
- },
27
- set expiration(value) {
28
- pluginConfig.expiration = value;
29
- },
30
- get rewrites() {
31
- pluginConfig.rewrites ??= [];
32
- return pluginConfig.rewrites;
33
- },
34
- get headers() {
35
- pluginConfig.headers ??= [];
36
- return pluginConfig.headers;
37
- },
38
- get redirects() {
39
- pluginConfig.redirects ??= [];
40
- return pluginConfig.redirects;
41
- },
42
- get cleanUrls() {
43
- return pluginConfig.cleanUrls;
44
- },
45
- set cleanUrls(value) {
46
- pluginConfig.cleanUrls = value;
47
- },
48
- get trailingSlash() {
49
- return pluginConfig.trailingSlash;
50
- },
51
- set trailingSlash(value) {
52
- pluginConfig.trailingSlash = value;
53
- },
54
- get defaultSupportsResponseStreaming() {
55
- return pluginConfig.defaultSupportsResponseStreaming;
56
- },
57
- set defaultSupportsResponseStreaming(value) {
58
- pluginConfig.defaultSupportsResponseStreaming = value;
59
- }
60
- };
61
- }
62
- function getVercelAPI(pluginContextOrServer) {
63
- const vpv = ("environment" in pluginContextOrServer ? pluginContextOrServer.environment.config : pluginContextOrServer.config).plugins.find((p) => p.name === "vite-plugin-vercel:api");
64
- assert(vpv, "Could not find vite-plugin-vercel:api plugin");
65
- assert(vpv.api, "Missing `api`. Make sure vite-plugin-vercel is up-to-date");
66
- return vpv.api("environment" in pluginContextOrServer ? pluginContextOrServer : void 0);
67
- }
68
-
69
- //#endregion
70
- export { getVercelAPI as n, assert as r, createAPI as t };
File without changes