vike 0.4.254 → 0.4.255-commit-05a7b95

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 (59) hide show
  1. package/dist/client/runtime-client-routing/createPageContextClient.d.ts +2 -24
  2. package/dist/client/runtime-client-routing/getGlobalContextClientInternal.d.ts +2 -24
  3. package/dist/client/runtime-client-routing/getPageContextFromHooks.d.ts +8 -96
  4. package/dist/client/runtime-client-routing/renderPageClient.d.ts +8 -96
  5. package/dist/client/runtime-server-routing/createPageContextClient.d.ts +2 -24
  6. package/dist/client/runtime-server-routing/getGlobalContextClientInternal.d.ts +2 -24
  7. package/dist/client/shared/getGlobalContextClientInternalShared.d.ts +2 -24
  8. package/dist/node/prerender/runPrerender.d.ts +9 -36
  9. package/dist/node/vite/index.js +2 -0
  10. package/dist/node/vite/plugins/build/pluginBuildConfig.js +2 -2
  11. package/dist/node/vite/plugins/pluginCommon/assertResolveAlias.js +2 -2
  12. package/dist/node/vite/plugins/pluginDev/optimizeDeps.js +2 -2
  13. package/dist/node/vite/plugins/pluginReplaceConstantsGlobalThis.js +2 -0
  14. package/dist/node/vite/plugins/pluginStripPointerImportAttribute.js +3 -3
  15. package/dist/node/vite/plugins/pluginUniversalDeploy/getDeployConfigs.d.ts +12 -0
  16. package/dist/node/vite/plugins/pluginUniversalDeploy/getDeployConfigs.js +73 -0
  17. package/dist/node/vite/plugins/pluginUniversalDeploy.d.ts +5 -0
  18. package/dist/node/vite/plugins/pluginUniversalDeploy.js +155 -0
  19. package/dist/node/vite/shared/addSsrMiddleware.js +1 -0
  20. package/dist/node/vite/shared/getClientEntrySrcDev.js +2 -2
  21. package/dist/node/vite/shared/getFilePath.js +3 -3
  22. package/dist/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +18 -0
  23. package/dist/node/vite/shared/resolveVikeConfigInternal/pointerImports.d.ts +0 -2
  24. package/dist/node/vite/shared/resolveVikeConfigInternal/pointerImports.js +16 -6
  25. package/dist/node/vite/shared/resolveVikeConfigInternal/resolvePointerImport.js +2 -2
  26. package/dist/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +16 -34
  27. package/dist/server/assertEnvServer.js +1 -1
  28. package/dist/server/runtime/fetch.d.ts +10 -0
  29. package/dist/server/runtime/fetch.js +5 -0
  30. package/dist/server/runtime/globalContext.d.ts +10 -120
  31. package/dist/server/runtime/renderPageServer/createHttpResponse.d.ts +5 -3
  32. package/dist/server/runtime/renderPageServer/createHttpResponse.js +13 -1
  33. package/dist/server/runtime/renderPageServer/createPageContextServer.d.ts +15 -39
  34. package/dist/server/runtime/renderPageServer/getPageAssets/getManifestEntry.js +2 -2
  35. package/dist/server/runtime/renderPageServer/getPageAssets/retrievePageAssetsProd.js +2 -2
  36. package/dist/server/runtime/renderPageServer/loadPageConfigsLazyServerSide.d.ts +9 -36
  37. package/dist/server/runtime/renderPageServer/renderPageServerAfterRoute.d.ts +36 -144
  38. package/dist/server/runtime/renderPageServer.d.ts +13 -39
  39. package/dist/server/runtime/renderPageServer.js +51 -3
  40. package/dist/server/runtime/universal-middleware.d.ts +9 -2
  41. package/dist/server/runtime/universal-middleware.js +9 -1
  42. package/dist/shared-server-client/createGlobalContextShared.d.ts +4 -48
  43. package/dist/shared-server-client/getPageFiles/fileTypes.js +1 -1
  44. package/dist/shared-server-client/page-configs/resolveVikeConfigPublic.d.ts +1 -0
  45. package/dist/types/Config.d.ts +28 -1
  46. package/dist/types/PageContext.d.ts +6 -0
  47. package/dist/utils/PROJECT_VERSION.d.ts +1 -1
  48. package/dist/utils/PROJECT_VERSION.js +1 -1
  49. package/dist/utils/asyncFlatten.d.ts +4 -0
  50. package/dist/utils/asyncFlatten.js +7 -0
  51. package/dist/utils/isImportPath.js +2 -2
  52. package/dist/utils/isScriptFile.d.ts +2 -0
  53. package/dist/utils/isScriptFile.js +4 -0
  54. package/dist/utils/parseNpmPackage.d.ts +8 -8
  55. package/dist/utils/parseNpmPackage.js +13 -13
  56. package/dist/utils/path.js +1 -1
  57. package/dist/utils/requireResolve.js +3 -3
  58. package/fetch.js +3 -0
  59. package/package.json +21 -4
@@ -1,7 +1,7 @@
1
1
  export { assertResolveAlias };
2
2
  import { assert, assertUsage, assertWarning } from '../../../../utils/assert.js';
3
3
  import { isArray } from '../../../../utils/isArray.js';
4
- import { isPathAliasRecommended } from '../../../../utils/parseNpmPackage.js';
4
+ import { isPathAliasRecommendation } from '../../../../utils/parseNpmPackage.js';
5
5
  import pc from '@brillout/picocolors';
6
6
  import '../../assertEnvVite.js';
7
7
  // Recommend users to avoid un-distinguishable path aliases.
@@ -62,7 +62,7 @@ function assertResolveAlias(config) {
62
62
  // - resolveOptimizeDeps()
63
63
  // - extractAssets
64
64
  // - in general: using un-distinguishable path aliases is asking for trouble
65
- if (!isPathAliasRecommended(find)) {
65
+ if (!isPathAliasRecommendation(find)) {
66
66
  if (find.startsWith('@')) {
67
67
  const msg = `${errPrefix} defines an invalid resolve.alias ${deprecation}: a path alias cannot start with ${pc.cyan('@')}, ${errSuffix1}`;
68
68
  assertWarning(false, msg, { onlyOnce: true });
@@ -5,7 +5,7 @@ import { assert } from '../../../../utils/assert.js';
5
5
  import { createDebug } from '../../../../utils/debug.js';
6
6
  import { isArray } from '../../../../utils/isArray.js';
7
7
  import { isFilePathAbsoluteFilesystem } from '../../../../utils/isFilePathAbsoluteFilesystem.js';
8
- import { assertIsImportPathNpmPackage, getNpmPackageName } from '../../../../utils/parseNpmPackage.js';
8
+ import { assertImportIsNpmPackage, getNpmPackageName } from '../../../../utils/parseNpmPackage.js';
9
9
  import { requireResolveOptional } from '../../../../utils/requireResolve.js';
10
10
  import { isVirtualFileId } from '../../../../utils/virtualFileId.js';
11
11
  import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
@@ -146,7 +146,7 @@ async function getPageDeps(config, pageConfigs) {
146
146
  // optimizeDeps.include expects npm packages
147
147
  assert(!e.startsWith('/'));
148
148
  // Shouldn't be a path alias, as path aliases would need to be added to optimizeDeps.entries instead of optimizeDeps.include
149
- assertIsImportPathNpmPackage(e);
149
+ assertImportIsNpmPackage(e);
150
150
  if (isExcluded(e, isForClientSide, definedAt))
151
151
  return;
152
152
  if (isForClientSide) {
@@ -39,9 +39,11 @@ function pluginReplaceConstantsGlobalThis() {
39
39
  },
40
40
  },
41
41
  configEnvironment: {
42
+ order: 'pre',
42
43
  handler(name, config) {
43
44
  const isClientSide = !isViteServerSide_configEnvironment(name, config);
44
45
  return {
46
+ consumer: isClientSide ? 'client' : 'server',
45
47
  define: {
46
48
  'globalThis.__VIKE__IS_CLIENT': JSON.stringify(isClientSide),
47
49
  },
@@ -1,8 +1,8 @@
1
1
  export { pluginStripPointerImportAttribute };
2
2
  import { getMagicString } from '../shared/getMagicString.js';
3
3
  import '../assertEnvVite.js';
4
- // Match `with { type: 'vike-pointer' }` (with optional whitespace variations)
5
- const runtimeAttrRE = /\bwith\s*\{\s*type\s*:\s*['"]vike-pointer['"]\s*\}/g;
4
+ // Match `with { type: 'vike:pointer' }` (with optional whitespace variations)
5
+ const runtimeAttrRE = /\bwith\s*\{\s*type\s*:\s*['"]vike:pointer['"]\s*\}/g;
6
6
  function pluginStripPointerImportAttribute() {
7
7
  return [
8
8
  {
@@ -10,7 +10,7 @@ function pluginStripPointerImportAttribute() {
10
10
  transform: {
11
11
  filter: {
12
12
  code: {
13
- include: 'vike-pointer',
13
+ include: 'vike:pointer',
14
14
  },
15
15
  },
16
16
  handler(code, id) {
@@ -0,0 +1,12 @@
1
+ export { getDeployConfigs };
2
+ import type { PageConfigPublicWithRoute } from '../../../../shared-server-client/page-configs/resolveVikeConfigPublic.js';
3
+ import '../../assertEnvVite.js';
4
+ declare function getDeployConfigs(pageId: string, page: PageConfigPublicWithRoute): {
5
+ route: string[];
6
+ vercel: {
7
+ isr: {
8
+ expiration: number;
9
+ } | undefined;
10
+ edge: boolean;
11
+ };
12
+ } | null;
@@ -0,0 +1,73 @@
1
+ import pc from '@brillout/picocolors';
2
+ export { getDeployConfigs };
3
+ import { fromVike, toRou3 } from 'convert-route';
4
+ import { assert, assertUsage, assertWarning } from '../../../../utils/assert.js';
5
+ import '../../assertEnvVite.js';
6
+ function getDeployConfigs(pageId, page) {
7
+ // Convert Vike's routes to rou3 format
8
+ const routeIr = typeof page.route === 'string' ? fromVike(page.route) : null;
9
+ // Vercel specific configs
10
+ const rawIsr = extractIsr(page.config);
11
+ let isr = assertIsr(rawIsr);
12
+ const edge = extractEdge(page.config);
13
+ const isrOrEdge = isr ? 'isr' : edge ? 'edge' : null;
14
+ if (typeof page.route === 'function' && isrOrEdge) {
15
+ assertWarning(false, `Page ${pageId}: ${pc.cyan(isrOrEdge)} is not supported when using route function. Remove ${pc.cyan(isrOrEdge)} config or use a route string if possible.`, { onlyOnce: true });
16
+ isr = null;
17
+ }
18
+ if (edge && rawIsr !== null && typeof rawIsr === 'object') {
19
+ assertUsage(false, `Page ${pageId}: ISR cannot be enabled for edge functions. Remove ${pc.cyan('isr')} config or set \`{ edge: false }\`.`);
20
+ }
21
+ if (isrOrEdge && routeIr) {
22
+ return {
23
+ route: [...new Set([...toRou3(routeIr), ...getPageContextRoute(routeIr)])],
24
+ vercel: {
25
+ isr: isr ? { expiration: isr } : undefined,
26
+ edge: Boolean(edge),
27
+ },
28
+ };
29
+ }
30
+ return null;
31
+ }
32
+ function extractIsr(exports) {
33
+ if (exports === null || typeof exports !== 'object')
34
+ return null;
35
+ if (!('isr' in exports))
36
+ return null;
37
+ const isr = exports.isr;
38
+ assertUsage(typeof isr === 'object' &&
39
+ typeof isr.expiration === 'number' &&
40
+ isr.expiration > 0, ' `{ expiration }` must be a positive number');
41
+ return isr;
42
+ }
43
+ function assertIsr(isr) {
44
+ if (isr === null || isr === undefined)
45
+ return null;
46
+ return isr.expiration;
47
+ }
48
+ function extractEdge(exports) {
49
+ if (exports === null || typeof exports !== 'object')
50
+ return null;
51
+ if (!('edge' in exports))
52
+ return null;
53
+ const edge = exports.edge;
54
+ assertUsage(typeof edge === 'boolean', ' `{ edge }` must be a boolean');
55
+ return edge;
56
+ }
57
+ function getPageContextRoute(routeIr) {
58
+ const lastSegment = routeIr.pathname.at(-1);
59
+ assert(lastSegment);
60
+ if (!lastSegment.catchAll) {
61
+ const pageContextIr = {
62
+ pathname: [
63
+ ...routeIr.pathname.slice(0, -1),
64
+ {
65
+ ...lastSegment,
66
+ value: `${lastSegment.value}.pageContext.json`,
67
+ },
68
+ ],
69
+ };
70
+ return toRou3(pageContextIr);
71
+ }
72
+ return [];
73
+ }
@@ -0,0 +1,5 @@
1
+ export { pluginUniversalDeploy };
2
+ import type { Plugin } from 'vite';
3
+ import type { VikeConfigInternal } from '../shared/resolveVikeConfigInternal.js';
4
+ import '../assertEnvVite.js';
5
+ declare function pluginUniversalDeploy(vikeConfig: VikeConfigInternal): Plugin[];
@@ -0,0 +1,155 @@
1
+ export { pluginUniversalDeploy };
2
+ import { addEntry } from '@universal-deploy/store';
3
+ import { node } from '@universal-deploy/node/vite';
4
+ import { catchAll, devServer } from '@universal-deploy/store/vite';
5
+ import { serverEntryVirtualId as vikeEntryId } from '@brillout/vite-plugin-server-entry/plugin';
6
+ import { getMagicString } from '../shared/getMagicString.js';
7
+ import { escapeRegex } from '../../../utils/escapeRegex.js';
8
+ import { getDeployConfigs } from './pluginUniversalDeploy/getDeployConfigs.js';
9
+ import { assert, assertUsage, assertWarning } from '../../../utils/assert.js';
10
+ import { asyncFlatten } from '../../../utils/asyncFlatten.js';
11
+ import '../assertEnvVite.js';
12
+ import pc from '@brillout/picocolors';
13
+ const virtualFileIdCatchAll = /^virtual:ud:catch-all$/;
14
+ function pluginUniversalDeploy(vikeConfig) {
15
+ if (hasVikeServerOrVikePhoton(vikeConfig))
16
+ return [];
17
+ let serverEntryId = virtualFileIdCatchAll;
18
+ let serverFilePath = null;
19
+ const serverConfig = vikeConfig.config.server;
20
+ if (serverConfig === false)
21
+ return [];
22
+ const serverPlusFile = vikeConfig._pageConfigGlobal.configValueSources.server?.[0];
23
+ if (serverPlusFile) {
24
+ assert('filePathAbsoluteFilesystem' in serverPlusFile.definedAt);
25
+ serverFilePath = serverPlusFile.definedAt.filePathAbsoluteFilesystem;
26
+ assert(serverFilePath);
27
+ serverEntryId = new RegExp(escapeRegex(serverFilePath));
28
+ }
29
+ if (serverConfig !== true && !serverFilePath)
30
+ return [];
31
+ const plugins = [
32
+ catchAll(),
33
+ devServer(),
34
+ // Enable node adapter only if +server is defined and no other deployment target has been found
35
+ ...node({ importer: 'vike' }).map((p) =>
36
+ // Disable node() plugin later when Vite's config() hook runs, because noDeploymentTargetFound() requires `config`
37
+ enablePluginIf((config) => noDeploymentTargetFound(config), p)),
38
+ {
39
+ name: 'vike:pluginUniversalDeploy:entries',
40
+ config() {
41
+ for (const [pageId, page] of Object.entries(vikeConfig.pages)) {
42
+ const deployConfigs = getDeployConfigs(pageId, page);
43
+ if (deployConfigs !== null) {
44
+ addEntry({
45
+ id: serverFilePath ?? 'vike/fetch',
46
+ ...deployConfigs,
47
+ });
48
+ }
49
+ }
50
+ // Default catch-all route
51
+ addEntry({
52
+ id: serverFilePath ?? 'vike/fetch',
53
+ route: '/**',
54
+ });
55
+ },
56
+ ...pluginOptions,
57
+ },
58
+ {
59
+ name: 'vike:pluginUniversalDeploy:serverEntry',
60
+ apply: 'build',
61
+ transform: {
62
+ order: 'post',
63
+ filter: {
64
+ id: {
65
+ include: [serverEntryId],
66
+ },
67
+ },
68
+ handler(code, id) {
69
+ const { magicString, getMagicStringResult } = getMagicString(code, id);
70
+ // Inject Vike virtual server entry
71
+ magicString.prepend(`import "${vikeEntryId}";\n`);
72
+ return getMagicStringResult();
73
+ },
74
+ },
75
+ ...pluginOptions,
76
+ },
77
+ ];
78
+ if (serverFilePath) {
79
+ plugins.push(
80
+ // If +server.js is defined, make virtual:ud:catch-all resolve to +server.js absolute path
81
+ {
82
+ name: 'vike:pluginUniversalDeploy:server',
83
+ resolveId: {
84
+ order: 'pre',
85
+ filter: {
86
+ id: virtualFileIdCatchAll,
87
+ },
88
+ handler() {
89
+ // Will resolve the entry from the users project root
90
+ return this.resolve(serverFilePath);
91
+ },
92
+ },
93
+ ...pluginOptions,
94
+ });
95
+ }
96
+ return plugins;
97
+ }
98
+ const pluginOptions = {
99
+ applyToEnvironment(env) {
100
+ return env.config.consumer === 'server';
101
+ },
102
+ sharedDuringBuild: true,
103
+ };
104
+ /**
105
+ * Enables a plugin based on a specified condition callback which will be executed in the `config` hook.
106
+ */
107
+ function enablePluginIf(condition, originalPlugin) {
108
+ const originalConfig = originalPlugin.config;
109
+ originalPlugin.config = {
110
+ order: originalConfig && 'order' in originalConfig ? originalConfig.order : 'pre',
111
+ async handler(c, e) {
112
+ const enabled = await condition.call(this, c, e);
113
+ if (!enabled) {
114
+ const keysToDelete = Object.keys(originalPlugin).filter((k) => k !== 'name');
115
+ originalPlugin.name += ':disabled';
116
+ for (const key of keysToDelete) {
117
+ // @ts-expect-error
118
+ delete originalPlugin[key];
119
+ }
120
+ }
121
+ else if (originalConfig) {
122
+ if (typeof originalConfig === 'function') {
123
+ return originalConfig.call(this, c, e);
124
+ }
125
+ return originalConfig.handler.call(this, c, e);
126
+ }
127
+ },
128
+ };
129
+ return originalPlugin;
130
+ }
131
+ // Disable a plugin if one of the following plugin is present
132
+ // - vite-plugin-vercel
133
+ // - @cloudflare/vite-plugin
134
+ async function noDeploymentTargetFound(c) {
135
+ const plugins = (await asyncFlatten((c.plugins ?? []))).filter((p) => Boolean(p));
136
+ assertUsage(!plugins.some((p) => p.name.startsWith('photon:target-loader:vercel')), 'Replace `@photonjs/vercel` by `vite-plugin-vercel@11`, see https://vike.dev/migration/universal-deploy');
137
+ assertUsage(!plugins.some((p) => p.name.startsWith('photon:target-loader:cloudflare')), 'Replace `@photonjs/cloudflare` by `@cloudflare/vite-plugin`, see https://vike.dev/migration/universal-deploy');
138
+ // vite-plugin-vercel
139
+ const vitePluginVercel = plugins.some((p) => p.name.match(/^vite-plugin-vercel:(?!.*:disabled$)/));
140
+ // @cloudflare/vite-plugin
141
+ const cloudflareVitePlugin = plugins.some((p) => p.name.match(/^vite-plugin-cloudflare:(?!.*:disabled$)/));
142
+ return !vitePluginVercel && !cloudflareVitePlugin;
143
+ }
144
+ function hasVikeServerOrVikePhoton(vikeConfig) {
145
+ const vikeExtendsNames = new Set(vikeConfig._extensions.map((plusFile) => ('fileExportsByConfigName' in plusFile ? plusFile.fileExportsByConfigName : {}).name));
146
+ const vikeServerOrVikePhoton = vikeExtendsNames.has('vike-server')
147
+ ? 'vike-server'
148
+ : vikeExtendsNames.has('vike-photon')
149
+ ? 'vike-photon'
150
+ : null;
151
+ if (vikeServerOrVikePhoton) {
152
+ assertWarning(false, `${pc.cyan(vikeServerOrVikePhoton)} is deprecated, see ${pc.underline('https://vike.dev/migration/universal-deploy')}`, { onlyOnce: true });
153
+ return true;
154
+ }
155
+ }
@@ -14,6 +14,7 @@ function addSsrMiddleware(middlewares, config, isPreview, isPrerenderingEnabled)
14
14
  const pageContextInit = {
15
15
  urlOriginal: url,
16
16
  headersOriginal: headers,
17
+ _reqDev: req,
17
18
  };
18
19
  Object.defineProperty(pageContextInit, 'userAgent', {
19
20
  get() {
@@ -1,6 +1,6 @@
1
1
  export { getClientEntrySrcDev };
2
2
  import { assertIsNotProductionRuntime } from '../../../utils/assertSetup.js';
3
- import { assertIsImportPathNpmPackage } from '../../../utils/parseNpmPackage.js';
3
+ import { assertImportIsNpmPackage } from '../../../utils/parseNpmPackage.js';
4
4
  import { toPosixPath, pathJoin } from '../../../utils/path.js';
5
5
  import { requireResolveNpmPackage, requireResolveDistFile } from '../../../utils/requireResolve.js';
6
6
  import { assert } from '../../../utils/assert.js';
@@ -32,7 +32,7 @@ function getClientEntrySrcDev(clientEntry, viteDevServer) {
32
32
  filePath = requireResolveDistFile(`dist/${clientEntry.replace('@@vike/dist/', '')}`);
33
33
  }
34
34
  else {
35
- assertIsImportPathNpmPackage(clientEntry);
35
+ assertImportIsNpmPackage(clientEntry);
36
36
  filePath = requireResolveNpmPackage({ importPathNpmPackage: clientEntry, userRootDir });
37
37
  }
38
38
  }
@@ -7,7 +7,7 @@ export { cleanFilePathUnknown };
7
7
  export { assertModuleId };
8
8
  import path from 'node:path';
9
9
  import { assertFilePathAbsoluteFilesystem } from '../../../utils/isFilePathAbsoluteFilesystem.js';
10
- import { assertIsImportPathNpmPackage } from '../../../utils/parseNpmPackage.js';
10
+ import { assertImportIsNpmPackage } from '../../../utils/parseNpmPackage.js';
11
11
  import { toPosixPath } from '../../../utils/path.js';
12
12
  import { assert } from '../../../utils/assert.js';
13
13
  import { assertPosixPath } from '../../../utils/path.js';
@@ -43,7 +43,7 @@ function getComputedProps(args) {
43
43
  const importPathAbsolute = args.importPathAbsolute ?? null;
44
44
  const { filePathAbsoluteUserRootDir } = args;
45
45
  if (importPathAbsolute)
46
- assertIsImportPathNpmPackage(importPathAbsolute);
46
+ assertImportIsNpmPackage(importPathAbsolute);
47
47
  return {
48
48
  importPathAbsolute,
49
49
  filePathAbsoluteUserRootDir,
@@ -57,7 +57,7 @@ function getComputedProps(args) {
57
57
  }
58
58
  function getComputedPropsImportPathAbsolute(args) {
59
59
  const { importPathAbsolute } = args;
60
- assertIsImportPathNpmPackage(importPathAbsolute);
60
+ assertImportIsNpmPackage(importPathAbsolute);
61
61
  return {
62
62
  filePathAbsoluteUserRootDir: null,
63
63
  importPathAbsolute,
@@ -4,6 +4,7 @@ import { getConfigDefinedAt, } from '../../../../shared-server-client/page-confi
4
4
  import { getConfigValueSourceRelevantAnyEnv, getConfigValueSourcesRelevant, isConfigSourceValueNull, } from '../../plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js';
5
5
  import { getFileSuffixes } from '../../../../shared-server-node/getFileSuffixes.js';
6
6
  import '../../assertEnvVite.js';
7
+ // TODO/after-PR-merge: rename_full configDefinitionsBuiltIn metaBuiltIn
7
8
  const configDefinitionsBuiltIn = {
8
9
  onRenderHtml: {
9
10
  env: { server: true },
@@ -225,6 +226,10 @@ const configDefinitionsBuiltIn = {
225
226
  eager: true,
226
227
  global: true,
227
228
  },
229
+ server: {
230
+ env: { server: true },
231
+ global: true,
232
+ },
228
233
  cli: {
229
234
  env: { config: true },
230
235
  global: true,
@@ -301,6 +306,19 @@ const configDefinitionsBuiltIn = {
301
306
  global: true,
302
307
  vite: true,
303
308
  },
309
+ license: {
310
+ env: { config: true },
311
+ global: true,
312
+ },
313
+ // -- Vercel --
314
+ isr: {
315
+ env: { server: true, config: true },
316
+ eager: true,
317
+ },
318
+ edge: {
319
+ env: { server: true, config: true },
320
+ eager: true,
321
+ },
304
322
  };
305
323
  function getConfigEnv(pageConfig, configName) {
306
324
  const source = getConfigValueSourceRelevantAnyEnv(configName, pageConfig);
@@ -1,6 +1,5 @@
1
1
  export { transformPointerImports };
2
2
  export { parsePointerImportData };
3
- export { isPointerImportData };
4
3
  export { assertPointerImportPath };
5
4
  export type { PointerImportData };
6
5
  import '../../assertEnvVite.js';
@@ -23,7 +22,6 @@ type PointerImportData = {
23
22
  importString: string;
24
23
  importStringWasGenerated: boolean;
25
24
  };
26
- declare function isPointerImportData(str: string): boolean;
27
25
  declare function parsePointerImportData(importString: string): null | PointerImportData;
28
26
  declare function assertPointerImportPath(importPath: string): boolean;
29
27
  declare module 'estree' {
@@ -1,6 +1,5 @@
1
1
  export { transformPointerImports };
2
2
  export { parsePointerImportData };
3
- export { isPointerImportData };
4
3
  export { assertPointerImportPath };
5
4
  // Playground: https://github.com/brillout/acorn-playground
6
5
  // Notes about `with { type: 'pointer' }`
@@ -30,6 +29,10 @@ function transformPointerImports(code, filePathToShowToUser2, pointerImports,
30
29
  // For ./transformPointerImports.spec.ts
31
30
  skipWarnings) {
32
31
  const spliceOperations = [];
32
+ // Collect all const declarations to prepend at the top, so that they are
33
+ // available before any code runs (import declarations are hoisted but const
34
+ // is not, so we must place them at the top to avoid TDZ errors).
35
+ const constDeclarations = [];
33
36
  // Performance trick
34
37
  if (!code.includes('import'))
35
38
  return null;
@@ -78,7 +81,7 @@ skipWarnings) {
78
81
  assertWarning(false, errMsg, { onlyOnce: true });
79
82
  }
80
83
  }
81
- let replacement = '';
84
+ let constDeclaration = '';
82
85
  node.specifiers.forEach((specifier) => {
83
86
  assert(specifier.type === 'ImportSpecifier' ||
84
87
  specifier.type === 'ImportDefaultSpecifier' ||
@@ -97,16 +100,23 @@ skipWarnings) {
97
100
  return importLocalName;
98
101
  })();
99
102
  const importString = serializePointerImportData({ importPath, exportName, importStringWasGenerated: true });
100
- replacement += `const ${importLocalName} = '${importString}';`;
103
+ constDeclaration += `const ${importLocalName} = '${importString}';`;
101
104
  });
105
+ if (constDeclaration)
106
+ constDeclarations.push(constDeclaration);
107
+ // Replace the import with blank lines to preserve source map line numbers.
102
108
  spliceOperations.push({
103
109
  start,
104
110
  end,
105
- replacement,
111
+ replacement: '\n'.repeat(importStatementCode.split('\n').length - 1),
106
112
  });
107
113
  });
108
- const codeMod = spliceMany(code, spliceOperations);
109
- return codeMod;
114
+ if (constDeclarations.length === 0 && spliceOperations.length === 0)
115
+ return null;
116
+ const codeWithImportsRemoved = spliceMany(code, spliceOperations);
117
+ if (constDeclarations.length === 0)
118
+ return codeWithImportsRemoved;
119
+ return constDeclarations.join('') + '\n' + codeWithImportsRemoved;
110
120
  }
111
121
  function getImports(code) {
112
122
  const result = parseSync(code, {
@@ -4,7 +4,7 @@ import pc from '@brillout/picocolors';
4
4
  import { assert, assertUsage } from '../../../../utils/assert.js';
5
5
  import { isFilePathAbsolute } from '../../../../utils/isFilePathAbsoluteFilesystem.js';
6
6
  import { isImportPathRelative } from '../../../../utils/isImportPath.js';
7
- import { isImportPathNpmPackageOrPathAlias } from '../../../../utils/parseNpmPackage.js';
7
+ import { isImportNpmPackageOrPathAlias } from '../../../../utils/parseNpmPackage.js';
8
8
  import { assertPosixPath } from '../../../../utils/path.js';
9
9
  import { requireResolveOptional } from '../../../../utils/requireResolve.js';
10
10
  import { assertPointerImportPath, parsePointerImportData } from './pointerImports.js';
@@ -50,7 +50,7 @@ function resolvePointerImportData(pointerImportData, importerFilePath, userRootD
50
50
  filePath = getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir });
51
51
  }
52
52
  else {
53
- assert(isImportPathNpmPackageOrPathAlias(importPath));
53
+ assert(isImportNpmPackageOrPathAlias(importPath));
54
54
  const importPathAbsolute = importPath;
55
55
  if (filePathAbsoluteFilesystem) {
56
56
  filePath = getFilePathResolved({
@@ -15,9 +15,9 @@ import { genPromise } from '../../../../utils/genPromise.js';
15
15
  import { assertFilePathAbsoluteFilesystem } from '../../../../utils/isFilePathAbsoluteFilesystem.js';
16
16
  import { isImportPathRelative } from '../../../../utils/isImportPath.js';
17
17
  import { isObject } from '../../../../utils/isObject.js';
18
- import { isPlainScriptFile } from '../../../../utils/isScriptFile.js';
18
+ import { isPlainJavaScriptFile, isPlainScriptFile } from '../../../../utils/isScriptFile.js';
19
19
  import { isVitest } from '../../../../utils/isVitest.js';
20
- import { assertIsImportPathNpmPackage, isImportPathNpmPackageOrPathAlias } from '../../../../utils/parseNpmPackage.js';
20
+ import { assertImportIsNpmPackage, isImportNpmPackageOrPathAlias } from '../../../../utils/parseNpmPackage.js';
21
21
  import { assertPosixPath, toPosixPath } from '../../../../utils/path.js';
22
22
  import { requireResolveOptionalDir } from '../../../../utils/requireResolve.js';
23
23
  import { transformPointerImports } from './pointerImports.js';
@@ -179,10 +179,10 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
179
179
  const importPathOriginal = args.path;
180
180
  // Esbuild resolves path aliases.
181
181
  // - Enabling us to use:
182
- // - assertIsImportPathNpmPackage()
183
- // - isImportPathNpmPackage(str, { cannotBePathAlias: true })
182
+ // - assertImportIsNpmPackage()
183
+ // - isImportNpmPackage(str, { cannotBePathAlias: true })
184
184
  assertFilePathAbsoluteFilesystem(importPathResolved);
185
- // Should be remove this? See comment below.
185
+ // Should we remove this? See comment below.
186
186
  const isVikeExtensionImport = (path.startsWith('vike-') && path.endsWith('/config')) || importPathResolved.endsWith('+config.js');
187
187
  const isPointerImport = transformImports === 'all' ||
188
188
  // .jsx, .vue, .svg, ... => obviously not config code => pointer import
@@ -193,32 +193,20 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
193
193
  // - vike@0.4.162 started soft-requiring Vike extensions to set the name config.
194
194
  // - In practice, it seems like it requires some (non-trivial?) refactoring.
195
195
  isVikeExtensionImport ||
196
- args.with?.['type'] === 'vike-pointer';
196
+ args.with?.['type'] === 'vike:pointer';
197
197
  assertPosixPath(importPathResolved);
198
- // `isNpmPkgImport` => `importPathOriginal` is most likely an npm package import, but it can also be a path alias that a) looks like an npm package import and b) resolves outside of `userRootDir`.
199
- const isNpmPkgImport = (() => {
200
- if (importPathResolved.includes('/node_modules/')) {
201
- // So far I can't think of a use case where this assertion would fail, but let's eventually remove it to avoid artificially restricting the user.
202
- assert(isImportPathNpmPackageOrPathAlias(importPathOriginal));
203
- return true;
204
- }
205
- // Linked npm packages
206
- if (
207
- // Assuming path aliases usually resolve inside `userRootDir`.
208
- // - This isn't always the case: https://github.com/vikejs/vike/issues/2326
209
- !importPathResolved.startsWith(userRootDir) &&
210
- // False positive if `importPathOriginal` is a path alias that a) looks like an npm package import and b) resolves outside of `userRootDir` => we then we wrongfully assume that `importPathOriginal` is an npm package import.
211
- isImportPathNpmPackageOrPathAlias(importPathOriginal)) {
212
- return true;
213
- }
214
- return false;
215
- })();
198
+ // False positive if `importPathOriginal` is a path alias that a) looks like an npm package import and b) resolves outside of `userRootDir` => we then we wrongfully assume that `importPathOriginal` is an npm package import.
199
+ // - For example: https://github.com/vikejs/vike/issues/2326
200
+ const isMostLikelyNpmPkgImport = isImportNpmPackageOrPathAlias(importPathOriginal) &&
201
+ (importPathResolved.includes('/node_modules/') ||
202
+ // Linked npm package
203
+ !importPathResolved.startsWith(userRootDir));
216
204
  const isExternal = isPointerImport ||
217
205
  // Performance: npm package imports can be externalized. (We could as well let esbuild transpile /node_modules/ code but it's useless as /node_modules/ code is already built. It would unnecessarily slow down transpilation.)
218
- isNpmPkgImport;
206
+ (isMostLikelyNpmPkgImport && isPlainJavaScriptFile(importPathResolved));
219
207
  if (!isExternal) {
220
208
  // User-land config code (i.e. not runtime code) => let esbuild transpile it
221
- assert(!isPointerImport && !isNpmPkgImport);
209
+ assert(!isPointerImport);
222
210
  if (debug.isActivated)
223
211
  debug('onResolve() [non-external]', { args, resolved, isPointerImport, isExternal });
224
212
  return resolved;
@@ -236,7 +224,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
236
224
  filePathAbsoluteFilesystem: importPathResolved,
237
225
  userRootDir,
238
226
  });
239
- if (filePathAbsoluteUserRootDir && !isNpmPkgImport) {
227
+ if (filePathAbsoluteUserRootDir && !isMostLikelyNpmPkgImport) {
240
228
  // `importPathOriginal` is most likely a path alias.
241
229
  // - We have to use esbuild's path alias resolution, because:
242
230
  // - Vike doesn't resolve path aliases at all.
@@ -246,19 +234,13 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
246
234
  }
247
235
  else {
248
236
  // `importPathOriginal` is most likely an npm package import.
249
- assertIsImportPathNpmPackage(importPathOriginal);
237
+ assertImportIsNpmPackage(importPathOriginal);
250
238
  // For improved error messages, let the resolution be handled by Vike or Node.js.
251
239
  importPathTranspiled = importPathOriginal;
252
240
  }
253
241
  }
254
242
  if (debug.isActivated)
255
243
  debug('onResolve() [external]', { args, resolved, importPathTranspiled, isPointerImport, isExternal });
256
- assert(isExternal);
257
- assert(
258
- // Import of runtime code => handled by Vike
259
- isPointerImport ||
260
- // Import of config code => loaded by Node.js at build-time
261
- isNpmPkgImport);
262
244
  pointerImports[importPathTranspiled] = isPointerImport;
263
245
  return { external: true, path: importPathTranspiled };
264
246
  });
@@ -20,7 +20,7 @@ function onLoad() {
20
20
  addEcosystemStamp();
21
21
  }
22
22
  // Used by:
23
- // - Telefunc (to detect the user's stack https://github.com/brillout/telefunc/blob/8288310e88e06a42b710d39c39fb502364ca6d30/telefunc/utils/isVikeApp.ts#L4)
23
+ // - Telefunc (to detect the user's stack https://github.com/telefunc/telefunc/blob/8288310e88e06a42b710d39c39fb502364ca6d30/telefunc/utils/isVikeApp.ts#L4)
24
24
  function addEcosystemStamp() {
25
25
  const g = globalThis;
26
26
  g._isVikeApp =
@@ -0,0 +1,10 @@
1
+ import '../assertEnvServer.js';
2
+ declare const _default: {
3
+ fetch: (<T extends string>(request: Request, context: Universal.Context, runtime: import("@universal-middleware/core").RuntimeAdapterTarget<T>) => Promise<Response>) & import("@universal-middleware/core").WithUniversalSymbols<{
4
+ name: string;
5
+ method: ("GET" | "HEAD" | "POST" | "PUT" | "OPTIONS" | "PATCH")[];
6
+ path: string;
7
+ immutable: true;
8
+ }>;
9
+ };
10
+ export default _default;
@@ -0,0 +1,5 @@
1
+ import '../assertEnvServer.js';
2
+ import vikeHandler from './universal-middleware.js';
3
+ export default {
4
+ fetch: vikeHandler,
5
+ };