vike 0.4.228-commit-0e9e0f2 → 0.4.228-commit-1bb55f1
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/cjs/__internal/index.js +1 -1
- package/dist/cjs/client/client-routing-runtime/globalContext.js +4 -4
- package/dist/cjs/client/server-routing-runtime/globalContext.js +4 -4
- package/dist/cjs/client/shared/{createGetGlobalContext.js → createGetGlobalContextClient.js} +23 -3
- package/dist/cjs/client/shared/utils.js +1 -0
- package/dist/cjs/node/plugin/plugins/commonConfig.js +5 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +0 -1
- package/dist/cjs/node/prerender/runPrerender.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +6 -5
- package/dist/cjs/node/runtime/index-deprecated.js +9 -38
- package/dist/cjs/node/runtime/index.js +56 -2
- package/dist/cjs/node/runtime/renderPage.js +1 -1
- package/dist/cjs/shared/createGlobalContextShared.js +3 -0
- package/dist/cjs/shared/route/loadPageRoutes.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/__internal/index.js +2 -2
- package/dist/esm/client/client-routing-runtime/createPageContext.js +2 -2
- package/dist/esm/client/client-routing-runtime/globalContext.d.ts +3 -3
- package/dist/esm/client/client-routing-runtime/globalContext.js +3 -3
- package/dist/esm/client/index.d.ts +1 -0
- package/dist/esm/client/index.js +4 -0
- package/dist/esm/client/node.js +1 -3
- package/dist/esm/client/server-routing-runtime/createPageContextClientSide.js +2 -2
- package/dist/esm/client/server-routing-runtime/globalContext.d.ts +4 -3
- package/dist/esm/client/server-routing-runtime/globalContext.js +3 -3
- package/dist/esm/client/shared/{createGetGlobalContext.d.ts → createGetGlobalContextClient.d.ts} +6 -2
- package/dist/esm/client/shared/{createGetGlobalContext.js → createGetGlobalContextClient.js} +27 -5
- package/dist/esm/client/shared/utils.d.ts +1 -0
- package/dist/esm/client/shared/utils.js +1 -0
- package/dist/esm/node/plugin/plugins/commonConfig.js +5 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +0 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +2 -2
- package/dist/esm/node/prerender/runPrerender.js +2 -2
- package/dist/esm/node/runtime/globalContext.d.ts +7 -6
- package/dist/esm/node/runtime/globalContext.js +7 -6
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.d.ts +2 -2
- package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -2
- package/dist/esm/node/runtime/index-deprecated.d.ts +1 -16
- package/dist/esm/node/runtime/index-deprecated.js +9 -36
- package/dist/esm/node/runtime/index.d.ts +23 -1
- package/dist/esm/node/runtime/index.js +38 -3
- package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage.js +2 -2
- package/dist/esm/shared/createGlobalContextShared.d.ts +2 -0
- package/dist/esm/shared/createGlobalContextShared.js +2 -0
- package/dist/esm/shared/route/loadPageRoutes.js +1 -1
- package/dist/esm/shared/types.d.ts +29 -12
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/package.json +10 -9
- package/dist/cjs/node/runtime/index-common.js +0 -27
- package/dist/esm/node/runtime/index-common.d.ts +0 -8
- package/dist/esm/node/runtime/index-common.js +0 -10
|
@@ -17,7 +17,7 @@ const assertSetup_js_1 = require("../utils/assertSetup.js");
|
|
|
17
17
|
async function getPagesAndRoutes() {
|
|
18
18
|
(0, assertSetup_js_1.setNodeEnvProduction)();
|
|
19
19
|
await (0, globalContext_js_2.initGlobalContext_getPagesAndRoutes)();
|
|
20
|
-
const { globalContext } = await (0, globalContext_js_2.
|
|
20
|
+
const { globalContext } = await (0, globalContext_js_2.getGlobalContextServerInternal)();
|
|
21
21
|
const {
|
|
22
22
|
//
|
|
23
23
|
_pageRoutes: pageRoutes, _pageFilesAll: pageFilesAll, _pageConfigs: pageConfigs, _allPageIds: allPageIds } = globalContext;
|
|
@@ -33,13 +33,13 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
37
|
-
const
|
|
36
|
+
exports.getGlobalContextClientInternal = void 0;
|
|
37
|
+
const createGetGlobalContextClient_js_1 = require("../shared/createGetGlobalContextClient.js");
|
|
38
38
|
const loadPageRoutes_js_1 = require("../../shared/route/loadPageRoutes.js");
|
|
39
39
|
// @ts-ignore
|
|
40
40
|
const virtualFileExports = __importStar(require("virtual:vike:importUserCode:client:client-routing"));
|
|
41
|
-
const
|
|
42
|
-
exports.
|
|
41
|
+
const getGlobalContextClientInternal = (0, createGetGlobalContextClient_js_1.createGetGlobalContextClient)(virtualFileExports, true, addGlobalContext);
|
|
42
|
+
exports.getGlobalContextClientInternal = getGlobalContextClientInternal;
|
|
43
43
|
async function addGlobalContext(globalContext) {
|
|
44
44
|
const { pageRoutes, onBeforeRouteHook } = await (0, loadPageRoutes_js_1.loadPageRoutes)(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
|
|
45
45
|
return {
|
|
@@ -33,9 +33,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
37
|
-
const
|
|
36
|
+
exports.getGlobalContextClientInternal = void 0;
|
|
37
|
+
const createGetGlobalContextClient_js_1 = require("../shared/createGetGlobalContextClient.js");
|
|
38
38
|
// @ts-ignore
|
|
39
39
|
const virtualFileExports = __importStar(require("virtual:vike:importUserCode:client:server-routing"));
|
|
40
|
-
const
|
|
41
|
-
exports.
|
|
40
|
+
const getGlobalContextClientInternal = (0, createGetGlobalContextClient_js_1.createGetGlobalContextClient)(virtualFileExports, false);
|
|
41
|
+
exports.getGlobalContextClientInternal = getGlobalContextClientInternal;
|
package/dist/cjs/client/shared/{createGetGlobalContext.js → createGetGlobalContextClient.js}
RENAMED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getGlobalContext = getGlobalContext;
|
|
4
|
+
exports.getGlobalContextSync = getGlobalContextSync;
|
|
5
|
+
exports.createGetGlobalContextClient = createGetGlobalContextClient;
|
|
4
6
|
const createGlobalContextShared_js_1 = require("../../shared/createGlobalContextShared.js");
|
|
5
7
|
const getJsonSerializedInHtml_js_1 = require("./getJsonSerializedInHtml.js");
|
|
6
8
|
const utils_js_1 = require("./utils.js");
|
|
7
|
-
const globalObject = (0, utils_js_1.getGlobalObject)('
|
|
8
|
-
|
|
9
|
+
const globalObject = (0, utils_js_1.getGlobalObject)('createGetGlobalContextClient.ts', (() => {
|
|
10
|
+
const { promise: globalContextPromise, resolve: globalContextPromiseResolve } = (0, utils_js_1.genPromise)();
|
|
11
|
+
return {
|
|
12
|
+
globalContextPromise,
|
|
13
|
+
globalContextPromiseResolve
|
|
14
|
+
};
|
|
15
|
+
})());
|
|
16
|
+
function createGetGlobalContextClient(virtualFileExports, isClientRouting, addGlobalContext) {
|
|
9
17
|
(0, utils_js_1.assert)(globalObject.isClientRouting === undefined || globalObject.isClientRouting === isClientRouting);
|
|
10
18
|
globalObject.isClientRouting = isClientRouting;
|
|
11
19
|
// Eagerly call onCreateGlobalContext() hook
|
|
@@ -32,7 +40,19 @@ function createGetGlobalContext(virtualFileExports, isClientRouting, addGlobalCo
|
|
|
32
40
|
(0, utils_js_1.objectAssign)(globalContextAddendum, await addGlobalContext?.(globalContext));
|
|
33
41
|
return globalContextAddendum;
|
|
34
42
|
});
|
|
43
|
+
(0, utils_js_1.assert)(globalObject.globalContext);
|
|
44
|
+
globalObject.globalContextPromiseResolve(globalObject.globalContext);
|
|
35
45
|
// Return
|
|
36
46
|
return globalContext;
|
|
37
47
|
}
|
|
38
48
|
}
|
|
49
|
+
// The type is never used: it's the type of the server-side getGlobalContext() that is used.
|
|
50
|
+
async function getGlobalContext() {
|
|
51
|
+
const globalContext = await globalObject.globalContextPromise;
|
|
52
|
+
return globalContext;
|
|
53
|
+
}
|
|
54
|
+
function getGlobalContextSync() {
|
|
55
|
+
const { globalContext } = globalObject;
|
|
56
|
+
(0, utils_js_1.assertUsage)(globalContext, createGlobalContextShared_js_1.getGlobalContextSyncErrMsg);
|
|
57
|
+
return globalContext;
|
|
58
|
+
}
|
|
@@ -19,3 +19,4 @@ __exportStar(require("../../utils/parseUrl.js"), exports);
|
|
|
19
19
|
__exportStar(require("../../utils/getGlobalObject.js"), exports);
|
|
20
20
|
__exportStar(require("../../utils/objectAssign.js"), exports);
|
|
21
21
|
__exportStar(require("../../utils/hasProp.js"), exports);
|
|
22
|
+
__exportStar(require("../../utils/genPromise.js"), exports);
|
|
@@ -158,14 +158,17 @@ function assertSingleInstance(config) {
|
|
|
158
158
|
function assertVikeCliOrApi(config) {
|
|
159
159
|
if ((0, context_js_1.isVikeCliOrApi)())
|
|
160
160
|
return;
|
|
161
|
-
if ((0, utils_js_1.isVitest)())
|
|
162
|
-
return;
|
|
163
161
|
if ((0, isViteCliCall_js_1.isViteCliCall)()) {
|
|
162
|
+
(0, utils_js_1.assert)(!(0, utils_js_1.isVitest)());
|
|
164
163
|
(0, utils_js_1.assertWarning)(false, `Vite's CLI is deprecated ${picocolors_1.default.underline('https://vike.dev/migration/cli')}`, {
|
|
165
164
|
onlyOnce: true
|
|
166
165
|
});
|
|
167
166
|
return;
|
|
168
167
|
}
|
|
168
|
+
if ((0, utils_js_1.isVitest)()) {
|
|
169
|
+
(0, utils_js_1.assertWarning)(false, `Unexpected Vitest setup: you seem to be using Vitest together with Vike's Vite plugin but without using Vike's JavaScript API which is unexpected, see ${picocolors_1.default.underline('https://vike.dev/vitest')}`, { onlyOnce: true });
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
169
172
|
if (config.server.middlewareMode) {
|
|
170
173
|
(0, utils_js_1.assertWarning)(false, `${picocolors_1.default.cyan('vite.createServer()')} is deprecated ${picocolors_1.default.underline('https://vike.dev/migration/cli#api')}`, {
|
|
171
174
|
onlyOnce: true
|
|
@@ -212,7 +212,6 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
212
212
|
// - Vike doesn't resolve path aliases at all.
|
|
213
213
|
// - Node.js doesn't support `tsconfig.js#compilerOptions.paths`.
|
|
214
214
|
// - Esbuild path alias resolution seems reliable, e.g. it supports `tsconfig.js#compilerOptions.paths`.
|
|
215
|
-
(0, utils_js_1.assert)(!(0, utils_js_1.isImportPathNpmPackageOrPathAlias)(importPathOriginal));
|
|
216
215
|
importPathTranspiled = importPathResolved;
|
|
217
216
|
}
|
|
218
217
|
else {
|
|
@@ -132,7 +132,7 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
132
132
|
}
|
|
133
133
|
const concurrencyLimit = (0, utils_js_1.pLimit)(parallel === false || parallel === 0 ? 1 : parallel === true || parallel === undefined ? (0, os_1.cpus)().length : parallel);
|
|
134
134
|
await (0, globalContext_js_1.initGlobalContext_runPrerender)();
|
|
135
|
-
const { globalContext, globalContext_public } = await (0, globalContext_js_1.
|
|
135
|
+
const { globalContext, globalContext_public } = await (0, globalContext_js_1.getGlobalContextServerInternal)();
|
|
136
136
|
globalContext._pageFilesAll.forEach(assertExportNames);
|
|
137
137
|
const prerenderContext = {
|
|
138
138
|
pageContexts: [],
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getGlobalContext = getGlobalContext;
|
|
7
7
|
exports.getGlobalContextSync = getGlobalContextSync;
|
|
8
8
|
exports.getGlobalContextAsync = getGlobalContextAsync;
|
|
9
|
-
exports.
|
|
9
|
+
exports.getGlobalContextServerInternal = getGlobalContextServerInternal;
|
|
10
10
|
exports.getViteDevServer = getViteDevServer;
|
|
11
11
|
exports.getViteConfig = getViteConfig;
|
|
12
12
|
exports.initGlobalContext_renderPage = initGlobalContext_renderPage;
|
|
@@ -41,8 +41,8 @@ const globalObject = (0, utils_js_1.getGlobalObject)('runtime/globalContext.ts',
|
|
|
41
41
|
// Trick to break down TypeScript circular dependency
|
|
42
42
|
// https://chat.deepseek.com/a/chat/s/d7e9f90a-c7f3-4108-9cd5-4ad6caed3539
|
|
43
43
|
const globalObjectTyped = globalObject;
|
|
44
|
-
async function
|
|
45
|
-
//
|
|
44
|
+
async function getGlobalContextServerInternal() {
|
|
45
|
+
// getGlobalContextServerInternal() should always be called after initGlobalContext()
|
|
46
46
|
(0, utils_js_1.assert)(globalObject.isInitialized);
|
|
47
47
|
assertGlobalContextIsDefined();
|
|
48
48
|
if (globalObject.isProduction !== true)
|
|
@@ -64,6 +64,7 @@ function assertGlobalContextIsDefined() {
|
|
|
64
64
|
(0, utils_js_1.assert)(globalObject.globalContext);
|
|
65
65
|
(0, utils_js_1.assert)(globalObject.globalContext_public);
|
|
66
66
|
}
|
|
67
|
+
// We purposely return GlobalContext instead of GlobalContextServer because `import { getGlobalContext } from 'vike'` can resolve to the client-side implementation.
|
|
67
68
|
/**
|
|
68
69
|
* Get runtime information about your app.
|
|
69
70
|
*
|
|
@@ -105,9 +106,9 @@ async function getGlobalContextAsync(isProduction) {
|
|
|
105
106
|
function getGlobalContextSync() {
|
|
106
107
|
debug('getGlobalContextSync()');
|
|
107
108
|
const { globalContext_public } = globalObjectTyped;
|
|
108
|
-
(0, utils_js_1.assertUsage)(globalContext_public,
|
|
109
|
+
(0, utils_js_1.assertUsage)(globalContext_public, createGlobalContextShared_js_1.getGlobalContextSyncErrMsg);
|
|
109
110
|
(0, utils_js_1.assertWarning)(false,
|
|
110
|
-
// We discourage users from using it because
|
|
111
|
+
// We discourage users from using it because `pageContext.globalContext` is safer: I ain't sure but there could be race conditions when using `getGlobalContextSync()` inside React/Vue components upon HMR.
|
|
111
112
|
// We're lying about "is going to be deprecated in the next major release": let's keep it and see if users need it (so far I can't see a use case for it).
|
|
112
113
|
'getGlobalContextSync() is going to be deprecated in the next major release, see https://vike.dev/getGlobalContext', { onlyOnce: true });
|
|
113
114
|
return globalContext_public;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// TODO/v1-release: replace this with:
|
|
3
|
-
// assertUsage(false, "`import { something } from 'vike'` doesn't exist: instead import from 'vike/server', 'vike/client', 'vike/plugin', ...")
|
|
4
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
3
|
if (k2 === undefined) k2 = k;
|
|
6
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -19,44 +17,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
19
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
18
|
};
|
|
21
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
(0, assert_js_1.assertUsage)(!(0, isBrowser_js_1.isBrowser)(), "It's forbidden to `import { something } from 'vike'` on the client-side: the module 'vike' is a server-only module.", { showStackTrace: true });
|
|
26
|
-
__exportStar(require("./index-common.js"), exports);
|
|
27
|
-
__exportStar(require("../../types/index-dreprecated.js"), exports);
|
|
20
|
+
// TODO/soon: point package.json#exports['./server'] to this file.
|
|
21
|
+
// - Write migration guide, see comment below.
|
|
22
|
+
__exportStar(require("./index.js"), exports);
|
|
28
23
|
const utils_js_1 = require("./utils.js");
|
|
29
24
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
30
|
-
const abort_js_1 = require("../../shared/route/abort.js");
|
|
31
|
-
/** @deprecated
|
|
32
|
-
* Replace:
|
|
33
|
-
* ```
|
|
34
|
-
* import { RenderErrorPage } from 'vike'
|
|
35
|
-
* ```
|
|
36
|
-
* With:
|
|
37
|
-
* ```
|
|
38
|
-
* import { render } from 'vike/abort'
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* See https://vike.dev/render
|
|
42
|
-
*/
|
|
43
|
-
const RenderErrorPage = (...args) => {
|
|
44
|
-
(0, utils_js_1.assertWarning)(false, [
|
|
45
|
-
'Replace:',
|
|
46
|
-
picocolors_1.default.red(" import { RenderErrorPage } from 'vike'"),
|
|
47
|
-
'With:',
|
|
48
|
-
picocolors_1.default.green(" import { render } from 'vike/abort'"),
|
|
49
|
-
'See https://vike.dev/render'
|
|
50
|
-
].join('\n'), { onlyOnce: true, showStackTrace: true });
|
|
51
|
-
return (0, abort_js_1.RenderErrorPage)(...args);
|
|
52
|
-
};
|
|
53
|
-
exports.RenderErrorPage = RenderErrorPage;
|
|
54
25
|
(0, utils_js_1.assertWarning)(false, [
|
|
55
|
-
'You have
|
|
56
|
-
picocolors_1.default.red(" import { something } from 'vike'"),
|
|
26
|
+
'You have outdated imports:',
|
|
27
|
+
picocolors_1.default.bold(picocolors_1.default.red(" import { something } from 'vike/server'")),
|
|
57
28
|
'Replace them with:',
|
|
58
|
-
picocolors_1.default.green(" import { something } from 'vike
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
29
|
+
picocolors_1.default.bold(picocolors_1.default.green(" import { something } from 'vike'"))
|
|
30
|
+
/* Add migration guide, with migration scritps such as `$ rename vike/server vike`
|
|
31
|
+
`See ${pc.underline('https://vike.dev/migration/0.4.xxx')}`
|
|
32
|
+
*/
|
|
62
33
|
].join('\n'), { showStackTrace: true, onlyOnce: true });
|
|
@@ -13,8 +13,62 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
16
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.RenderErrorPage = exports.createPageRenderer = exports._injectAssets = exports.createDevMiddleware = exports.getGlobalContextAsync = exports.getGlobalContextSync = exports.getGlobalContext = exports.version = exports.stampPipe = exports.pipeStream = exports.pipeNodeStream = exports.pipeWebStream = exports.dangerouslySkipEscape = exports.escapeInject = exports.renderPage = void 0;
|
|
17
21
|
const isBrowser_js_1 = require("../../utils/isBrowser.js");
|
|
18
22
|
const assert_js_1 = require("../../utils/assert.js");
|
|
19
|
-
(0, assert_js_1.
|
|
20
|
-
|
|
23
|
+
(0, assert_js_1.assert)(!(0, isBrowser_js_1.isBrowser)());
|
|
24
|
+
var renderPage_js_1 = require("./renderPage.js");
|
|
25
|
+
Object.defineProperty(exports, "renderPage", { enumerable: true, get: function () { return renderPage_js_1.renderPage; } });
|
|
26
|
+
var renderHtml_js_1 = require("./html/renderHtml.js");
|
|
27
|
+
Object.defineProperty(exports, "escapeInject", { enumerable: true, get: function () { return renderHtml_js_1.escapeInject; } });
|
|
28
|
+
Object.defineProperty(exports, "dangerouslySkipEscape", { enumerable: true, get: function () { return renderHtml_js_1.dangerouslySkipEscape; } });
|
|
29
|
+
var stream_js_1 = require("./html/stream.js");
|
|
30
|
+
Object.defineProperty(exports, "pipeWebStream", { enumerable: true, get: function () { return stream_js_1.pipeWebStream; } });
|
|
31
|
+
Object.defineProperty(exports, "pipeNodeStream", { enumerable: true, get: function () { return stream_js_1.pipeNodeStream; } });
|
|
32
|
+
Object.defineProperty(exports, "pipeStream", { enumerable: true, get: function () { return stream_js_1.pipeStream; } });
|
|
33
|
+
Object.defineProperty(exports, "stampPipe", { enumerable: true, get: function () { return stream_js_1.stampPipe; } });
|
|
34
|
+
var utils_js_1 = require("./utils.js");
|
|
35
|
+
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return utils_js_1.PROJECT_VERSION; } });
|
|
36
|
+
var globalContext_js_1 = require("./globalContext.js");
|
|
37
|
+
Object.defineProperty(exports, "getGlobalContext", { enumerable: true, get: function () { return globalContext_js_1.getGlobalContext; } });
|
|
38
|
+
Object.defineProperty(exports, "getGlobalContextSync", { enumerable: true, get: function () { return globalContext_js_1.getGlobalContextSync; } });
|
|
39
|
+
Object.defineProperty(exports, "getGlobalContextAsync", { enumerable: true, get: function () { return globalContext_js_1.getGlobalContextAsync; } });
|
|
40
|
+
var index_js_1 = require("../runtime-dev/index.js");
|
|
41
|
+
Object.defineProperty(exports, "createDevMiddleware", { enumerable: true, get: function () { return index_js_1.createDevMiddleware; } });
|
|
42
|
+
// TODO/v1-release: remove
|
|
43
|
+
// Deprecated exports
|
|
44
|
+
__exportStar(require("../../types/index-dreprecated.js"), exports);
|
|
45
|
+
var injectAssets__public_js_1 = require("./html/injectAssets/injectAssets__public.js");
|
|
46
|
+
Object.defineProperty(exports, "_injectAssets", { enumerable: true, get: function () { return injectAssets__public_js_1.injectAssets__public; } });
|
|
47
|
+
var createPageRenderer_js_1 = require("../createPageRenderer.js");
|
|
48
|
+
Object.defineProperty(exports, "createPageRenderer", { enumerable: true, get: function () { return createPageRenderer_js_1.createPageRenderer; } });
|
|
49
|
+
const utils_js_2 = require("./utils.js");
|
|
50
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
51
|
+
const abort_js_1 = require("../../shared/route/abort.js");
|
|
52
|
+
/** @deprecated
|
|
53
|
+
* Replace:
|
|
54
|
+
* ```
|
|
55
|
+
* import { RenderErrorPage } from 'vike'
|
|
56
|
+
* ```
|
|
57
|
+
* With:
|
|
58
|
+
* ```
|
|
59
|
+
* import { render } from 'vike/abort'
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* See https://vike.dev/render
|
|
63
|
+
*/
|
|
64
|
+
const RenderErrorPage = (...args) => {
|
|
65
|
+
(0, utils_js_2.assertWarning)(false, [
|
|
66
|
+
'Replace:',
|
|
67
|
+
picocolors_1.default.red(" import { RenderErrorPage } from 'vike'"),
|
|
68
|
+
'With:',
|
|
69
|
+
picocolors_1.default.green(" import { render } from 'vike/abort'"),
|
|
70
|
+
'See https://vike.dev/render'
|
|
71
|
+
].join('\n'), { onlyOnce: true, showStackTrace: true });
|
|
72
|
+
return (0, abort_js_1.RenderErrorPage)(...args);
|
|
73
|
+
};
|
|
74
|
+
exports.RenderErrorPage = RenderErrorPage;
|
|
@@ -81,7 +81,7 @@ async function renderPagePrepare(pageContextInit, httpRequestId) {
|
|
|
81
81
|
else {
|
|
82
82
|
// `globalContext` now contains the entire Vike config and getVikeConfig() isn't called anymore for this request.
|
|
83
83
|
}
|
|
84
|
-
const { globalContext, globalContext_public } = await (0, globalContext_js_1.
|
|
84
|
+
const { globalContext, globalContext_public } = await (0, globalContext_js_1.getGlobalContextServerInternal)();
|
|
85
85
|
const pageContextBegin = await getPageContextBegin(pageContextInit, globalContext, globalContext_public, httpRequestId);
|
|
86
86
|
// Check Base URL
|
|
87
87
|
{
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGlobalContextSyncErrMsg = void 0;
|
|
3
4
|
exports.createGlobalContextShared = createGlobalContextShared;
|
|
5
|
+
const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.";
|
|
6
|
+
exports.getGlobalContextSyncErrMsg = getGlobalContextSyncErrMsg;
|
|
4
7
|
const getPageConfigsRuntime_js_1 = require("./getPageConfigsRuntime.js");
|
|
5
8
|
const executeHookGeneric_js_1 = require("./hooks/executeHookGeneric.js");
|
|
6
9
|
const utils_js_1 = require("./utils.js");
|
|
@@ -10,7 +10,7 @@ const getConfigDefinedAt_js_1 = require("../page-configs/getConfigDefinedAt.js")
|
|
|
10
10
|
const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
|
|
11
11
|
const getHook_js_1 = require("../hooks/getHook.js");
|
|
12
12
|
async function loadPageRoutes(
|
|
13
|
-
// Remove all arguments and use
|
|
13
|
+
// Remove all arguments and use GlobalContextServerInternal instead?
|
|
14
14
|
pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds) {
|
|
15
15
|
// TODO/next-major: remove & make this function sync
|
|
16
16
|
await Promise.all(pageFilesAll.filter((p) => p.fileType === '.page.route').map((p) => p.loadFile?.()));
|
|
@@ -3,7 +3,7 @@ export { setGlobalContext_buildEntry } from '../node/runtime/globalContext.js';
|
|
|
3
3
|
// Needed by vite-plugin-vercel
|
|
4
4
|
export { route, getPagesAndRoutes };
|
|
5
5
|
import { route as routeInternal } from '../shared/route/index.js';
|
|
6
|
-
import {
|
|
6
|
+
import { getGlobalContextServerInternal, initGlobalContext_getPagesAndRoutes } from '../node/runtime/globalContext.js';
|
|
7
7
|
import { setNodeEnvProduction } from '../utils/assertSetup.js';
|
|
8
8
|
/**
|
|
9
9
|
* Used by {@link https://github.com/magne4000/vite-plugin-vercel|vite-plugin-vercel} to compute some rewrite rules and extract { isr } configs.
|
|
@@ -13,7 +13,7 @@ import { setNodeEnvProduction } from '../utils/assertSetup.js';
|
|
|
13
13
|
async function getPagesAndRoutes() {
|
|
14
14
|
setNodeEnvProduction();
|
|
15
15
|
await initGlobalContext_getPagesAndRoutes();
|
|
16
|
-
const { globalContext } = await
|
|
16
|
+
const { globalContext } = await getGlobalContextServerInternal();
|
|
17
17
|
const {
|
|
18
18
|
//
|
|
19
19
|
_pageRoutes: pageRoutes, _pageFilesAll: pageFilesAll, _pageConfigs: pageConfigs, _allPageIds: allPageIds } = globalContext;
|
|
@@ -2,10 +2,10 @@ export { createPageContextClientSide };
|
|
|
2
2
|
import { createPageContextShared } from '../../shared/createPageContextShared.js';
|
|
3
3
|
import { getPageContextUrlComputed } from '../../shared/getPageContextUrlComputed.js';
|
|
4
4
|
import { getBaseServer } from './getBaseServer.js';
|
|
5
|
-
import {
|
|
5
|
+
import { getGlobalContextClientInternal } from './globalContext.js';
|
|
6
6
|
import { assert, augmentType, isBaseServer, objectAssign } from './utils.js';
|
|
7
7
|
async function createPageContextClientSide(urlOriginal) {
|
|
8
|
-
const globalContext = await
|
|
8
|
+
const globalContext = await getGlobalContextClientInternal();
|
|
9
9
|
const baseServer = getBaseServer();
|
|
10
10
|
assert(isBaseServer(baseServer));
|
|
11
11
|
const pageContextCreated = {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { getGlobalContextClientInternal };
|
|
2
2
|
export type { GlobalContextClient };
|
|
3
3
|
import type { GlobalContextSharedPublic } from '../../shared/createGlobalContextShared.js';
|
|
4
4
|
type GlobalContextClient = GlobalContextSharedPublic & Pick<GlobalContextClientInternal, 'isClientSide'> & Vike.GlobalContext & Vike.GlobalContextClient & {};
|
|
5
|
-
type GlobalContextClientInternal = Awaited<ReturnType<typeof
|
|
6
|
-
declare const
|
|
5
|
+
type GlobalContextClientInternal = Awaited<ReturnType<typeof getGlobalContextClientInternal>>;
|
|
6
|
+
declare const getGlobalContextClientInternal: () => Promise<{
|
|
7
7
|
isGlobalContext: true;
|
|
8
8
|
_virtualFileExports: unknown;
|
|
9
9
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import {
|
|
1
|
+
export { getGlobalContextClientInternal };
|
|
2
|
+
import { createGetGlobalContextClient } from '../shared/createGetGlobalContextClient.js';
|
|
3
3
|
import { loadPageRoutes } from '../../shared/route/loadPageRoutes.js';
|
|
4
4
|
// @ts-ignore
|
|
5
5
|
import * as virtualFileExports from 'virtual:vike:importUserCode:client:client-routing';
|
|
6
|
-
const
|
|
6
|
+
const getGlobalContextClientInternal = createGetGlobalContextClient(virtualFileExports, true, addGlobalContext);
|
|
7
7
|
async function addGlobalContext(globalContext) {
|
|
8
8
|
const { pageRoutes, onBeforeRouteHook } = await loadPageRoutes(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
|
|
9
9
|
return {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getGlobalContext, getGlobalContext as getGlobalContextAsync, getGlobalContextSync } from './shared/createGetGlobalContextClient.js';
|
package/dist/esm/client/node.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { assertUsage } from './server-routing-runtime/utils.js';
|
|
2
2
|
assertUsage(false, [
|
|
3
|
-
'
|
|
3
|
+
'Server imports are forbidden on the client-side:',
|
|
4
4
|
" import { something } from 'vike/server'",
|
|
5
|
-
// TODO/v1-release: remove this line (also remove s above in `s/Following imports/Following import/`)
|
|
6
|
-
" import { something } from 'vike'",
|
|
7
5
|
'Did you mean the following instead?',
|
|
8
6
|
" import { something } from 'vike/client/router'"
|
|
9
7
|
].join('\n'), { showStackTrace: true });
|
|
@@ -4,10 +4,10 @@ import { getPageContextSerializedInHtml } from '../shared/getJsonSerializedInHtm
|
|
|
4
4
|
import { loadUserFilesClientSide } from '../shared/loadUserFilesClientSide.js';
|
|
5
5
|
import { getCurrentUrl } from '../shared/getCurrentUrl.js';
|
|
6
6
|
import { createPageContextShared } from '../../shared/createPageContextShared.js';
|
|
7
|
-
import {
|
|
7
|
+
import { getGlobalContextClientInternal } from './globalContext.js';
|
|
8
8
|
const urlFirst = getCurrentUrl({ withoutHash: true });
|
|
9
9
|
async function createPageContextClientSide() {
|
|
10
|
-
const globalContext = await
|
|
10
|
+
const globalContext = await getGlobalContextClientInternal();
|
|
11
11
|
const pageContextCreated = {
|
|
12
12
|
/* Don't spread globalContext for now? Or never spread it as it leads to confusion? The convenience isn't worth the added confusion?
|
|
13
13
|
...globalContext, // least precedence
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { getGlobalContextClientInternal };
|
|
2
2
|
export type { GlobalContextClientWithServerRouting };
|
|
3
3
|
import type { GlobalContextSharedPublic } from '../../shared/createGlobalContextShared.js';
|
|
4
|
-
type GlobalContextClientWithServerRouting = GlobalContextSharedPublic & Vike.GlobalContext & Vike.GlobalContextClient & {};
|
|
5
|
-
|
|
4
|
+
type GlobalContextClientWithServerRouting = GlobalContextSharedPublic & Pick<GlobalContextClientInternal, 'isClientSide'> & Vike.GlobalContext & Vike.GlobalContextClient & {};
|
|
5
|
+
type GlobalContextClientInternal = Awaited<ReturnType<typeof getGlobalContextClientInternal>>;
|
|
6
|
+
declare const getGlobalContextClientInternal: () => Promise<{
|
|
6
7
|
isGlobalContext: true;
|
|
7
8
|
_virtualFileExports: unknown;
|
|
8
9
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import {
|
|
1
|
+
export { getGlobalContextClientInternal };
|
|
2
|
+
import { createGetGlobalContextClient } from '../shared/createGetGlobalContextClient.js';
|
|
3
3
|
// @ts-ignore
|
|
4
4
|
import * as virtualFileExports from 'virtual:vike:importUserCode:client:server-routing';
|
|
5
|
-
const
|
|
5
|
+
const getGlobalContextClientInternal = createGetGlobalContextClient(virtualFileExports, false);
|
package/dist/esm/client/shared/{createGetGlobalContext.d.ts → createGetGlobalContextClient.d.ts}
RENAMED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { getGlobalContext };
|
|
2
|
+
export { getGlobalContextSync };
|
|
3
|
+
export { createGetGlobalContextClient };
|
|
2
4
|
import { type GlobalContextShared } from '../../shared/createGlobalContextShared.js';
|
|
3
|
-
declare function
|
|
5
|
+
declare function createGetGlobalContextClient<GlobalContextAddendum extends object>(virtualFileExports: unknown, isClientRouting: boolean, addGlobalContext?: (globalContext: GlobalContextShared) => Promise<GlobalContextAddendum>): () => Promise<{
|
|
4
6
|
isGlobalContext: true;
|
|
5
7
|
_virtualFileExports: unknown;
|
|
6
8
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
@@ -17,3 +19,5 @@ declare function createGetGlobalContext<GlobalContextAddendum extends object>(vi
|
|
|
17
19
|
*/
|
|
18
20
|
isClientSide: true;
|
|
19
21
|
} & Awaited<GlobalContextAddendum>>>;
|
|
22
|
+
declare function getGlobalContext(): Promise<never>;
|
|
23
|
+
declare function getGlobalContextSync(): never;
|
package/dist/esm/client/shared/{createGetGlobalContext.js → createGetGlobalContextClient.js}
RENAMED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// Public usage
|
|
2
|
+
export { getGlobalContext };
|
|
3
|
+
export { getGlobalContextSync };
|
|
4
|
+
// Internal usage
|
|
5
|
+
export { createGetGlobalContextClient };
|
|
6
|
+
import { createGlobalContextShared, getGlobalContextSyncErrMsg } from '../../shared/createGlobalContextShared.js';
|
|
3
7
|
import { getGlobalContextSerializedInHtml } from './getJsonSerializedInHtml.js';
|
|
4
|
-
import { assert, getGlobalObject, objectAssign } from './utils.js';
|
|
5
|
-
const globalObject = getGlobalObject('
|
|
6
|
-
|
|
8
|
+
import { assert, assertUsage, genPromise, getGlobalObject, objectAssign } from './utils.js';
|
|
9
|
+
const globalObject = getGlobalObject('createGetGlobalContextClient.ts', (() => {
|
|
10
|
+
const { promise: globalContextPromise, resolve: globalContextPromiseResolve } = genPromise();
|
|
11
|
+
return {
|
|
12
|
+
globalContextPromise,
|
|
13
|
+
globalContextPromiseResolve
|
|
14
|
+
};
|
|
15
|
+
})());
|
|
16
|
+
function createGetGlobalContextClient(virtualFileExports, isClientRouting, addGlobalContext) {
|
|
7
17
|
assert(globalObject.isClientRouting === undefined || globalObject.isClientRouting === isClientRouting);
|
|
8
18
|
globalObject.isClientRouting = isClientRouting;
|
|
9
19
|
// Eagerly call onCreateGlobalContext() hook
|
|
@@ -30,7 +40,19 @@ function createGetGlobalContext(virtualFileExports, isClientRouting, addGlobalCo
|
|
|
30
40
|
objectAssign(globalContextAddendum, await addGlobalContext?.(globalContext));
|
|
31
41
|
return globalContextAddendum;
|
|
32
42
|
});
|
|
43
|
+
assert(globalObject.globalContext);
|
|
44
|
+
globalObject.globalContextPromiseResolve(globalObject.globalContext);
|
|
33
45
|
// Return
|
|
34
46
|
return globalContext;
|
|
35
47
|
}
|
|
36
48
|
}
|
|
49
|
+
// The type is never used: it's the type of the server-side getGlobalContext() that is used.
|
|
50
|
+
async function getGlobalContext() {
|
|
51
|
+
const globalContext = await globalObject.globalContextPromise;
|
|
52
|
+
return globalContext;
|
|
53
|
+
}
|
|
54
|
+
function getGlobalContextSync() {
|
|
55
|
+
const { globalContext } = globalObject;
|
|
56
|
+
assertUsage(globalContext, getGlobalContextSyncErrMsg);
|
|
57
|
+
return globalContext;
|
|
58
|
+
}
|
|
@@ -153,14 +153,17 @@ function assertSingleInstance(config) {
|
|
|
153
153
|
function assertVikeCliOrApi(config) {
|
|
154
154
|
if (isVikeCliOrApi())
|
|
155
155
|
return;
|
|
156
|
-
if (isVitest())
|
|
157
|
-
return;
|
|
158
156
|
if (isViteCliCall()) {
|
|
157
|
+
assert(!isVitest());
|
|
159
158
|
assertWarning(false, `Vite's CLI is deprecated ${pc.underline('https://vike.dev/migration/cli')}`, {
|
|
160
159
|
onlyOnce: true
|
|
161
160
|
});
|
|
162
161
|
return;
|
|
163
162
|
}
|
|
163
|
+
if (isVitest()) {
|
|
164
|
+
assertWarning(false, `Unexpected Vitest setup: you seem to be using Vitest together with Vike's Vite plugin but without using Vike's JavaScript API which is unexpected, see ${pc.underline('https://vike.dev/vitest')}`, { onlyOnce: true });
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
164
167
|
if (config.server.middlewareMode) {
|
|
165
168
|
assertWarning(false, `${pc.cyan('vite.createServer()')} is deprecated ${pc.underline('https://vike.dev/migration/cli#api')}`, {
|
|
166
169
|
onlyOnce: true
|
|
@@ -207,7 +207,6 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
207
207
|
// - Vike doesn't resolve path aliases at all.
|
|
208
208
|
// - Node.js doesn't support `tsconfig.js#compilerOptions.paths`.
|
|
209
209
|
// - Esbuild path alias resolution seems reliable, e.g. it supports `tsconfig.js#compilerOptions.paths`.
|
|
210
|
-
assert(!isImportPathNpmPackageOrPathAlias(importPathOriginal));
|
|
211
210
|
importPathTranspiled = importPathResolved;
|
|
212
211
|
}
|
|
213
212
|
else {
|
|
@@ -5,7 +5,7 @@ export { runPrerender_forceExit };
|
|
|
5
5
|
export type { PrerenderOptions };
|
|
6
6
|
export type { PrerenderContextPublic };
|
|
7
7
|
import type { PageFile } from '../../shared/getPageFiles.js';
|
|
8
|
-
import { type
|
|
8
|
+
import { type GlobalContextServerInternal, type GlobalContextServer } from '../runtime/globalContext.js';
|
|
9
9
|
import type { InlineConfig, ResolvedConfig } from 'vite';
|
|
10
10
|
import type { APIOptions } from '../api/types.js';
|
|
11
11
|
type ProvidedByHook = null | {
|
|
@@ -66,7 +66,7 @@ declare function runPrerenderFromCLIPrerenderCommand(): Promise<void>;
|
|
|
66
66
|
declare function runPrerenderFromAutoRun(viteConfig: InlineConfig | undefined): Promise<{
|
|
67
67
|
forceExit: boolean;
|
|
68
68
|
}>;
|
|
69
|
-
declare function createPageContextPrerendering(urlOriginal: string, prerenderContext: PrerenderContext, globalContext:
|
|
69
|
+
declare function createPageContextPrerendering(urlOriginal: string, prerenderContext: PrerenderContext, globalContext: GlobalContextServerInternal, globalContext_public: GlobalContextServer, is404: boolean, pageId: string | undefined, providedByHook: ProvidedByHook): Promise<((({
|
|
70
70
|
isClientSide: boolean;
|
|
71
71
|
isPrerendering: boolean;
|
|
72
72
|
} & Pick<import("../../shared/types.js").PageContextBuiltInServerInternal, "urlOriginal" | "headersOriginal"> & {
|
|
@@ -9,7 +9,7 @@ import { prerenderPage } from '../runtime/renderPage/renderPageAlreadyRouted.js'
|
|
|
9
9
|
import { createPageContextServerSide } from '../runtime/renderPage/createPageContextServerSide.js';
|
|
10
10
|
import pc from '@brillout/picocolors';
|
|
11
11
|
import { cpus } from 'os';
|
|
12
|
-
import {
|
|
12
|
+
import { getGlobalContextServerInternal, initGlobalContext_runPrerender, setGlobalContext_isPrerendering } from '../runtime/globalContext.js';
|
|
13
13
|
import { resolveConfig } from 'vite';
|
|
14
14
|
import { getPageFilesServerSide } from '../../shared/getPageFiles.js';
|
|
15
15
|
import { getPageContextRequestUrl } from '../../shared/getPageContextRequestUrl.js';
|
|
@@ -94,7 +94,7 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
94
94
|
}
|
|
95
95
|
const concurrencyLimit = pLimit(parallel === false || parallel === 0 ? 1 : parallel === true || parallel === undefined ? cpus().length : parallel);
|
|
96
96
|
await initGlobalContext_runPrerender();
|
|
97
|
-
const { globalContext, globalContext_public } = await
|
|
97
|
+
const { globalContext, globalContext_public } = await getGlobalContextServerInternal();
|
|
98
98
|
globalContext._pageFilesAll.forEach(assertExportNames);
|
|
99
99
|
const prerenderContext = {
|
|
100
100
|
pageContexts: [],
|