vike 0.4.214 → 0.4.216
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 +2 -2
- package/dist/cjs/node/api/build.js +14 -3
- package/dist/cjs/node/api/context.js +20 -0
- package/dist/cjs/node/api/dev.js +11 -3
- package/dist/cjs/node/api/onLoad.js +9 -0
- package/dist/cjs/node/api/{enhanceViteConfig.js → prepareViteApiCall.js} +11 -6
- package/dist/cjs/node/api/prerender.js +11 -3
- package/dist/cjs/node/api/preview.js +11 -3
- package/dist/cjs/node/api/utils.js +22 -0
- package/dist/cjs/node/cli/entry.js +8 -8
- package/dist/cjs/node/cli/onLoad.js +2 -0
- package/dist/cjs/node/plugin/index.js +2 -3
- package/dist/cjs/node/plugin/onLoad.js +2 -2
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +0 -3
- package/dist/cjs/node/plugin/plugins/buildConfig.js +6 -5
- package/dist/cjs/node/plugin/plugins/commonConfig/pluginName.js +1 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +23 -1
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +0 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +9 -19
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -7
- package/dist/cjs/node/plugin/plugins/previewConfig.js +0 -1
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +32 -17
- package/dist/cjs/node/prerender/runPrerender.js +5 -4
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +6 -6
- package/dist/cjs/node/runtime/index-common.js +3 -1
- package/dist/cjs/node/runtime/renderPage.js +4 -2
- package/dist/cjs/node/runtime/utils.js +1 -2
- package/dist/cjs/node/runtime-dev/createDevMiddleware.js +25 -0
- package/dist/cjs/node/runtime-dev/index.js +32 -0
- package/dist/cjs/shared/page-configs/getConfigValue.js +2 -31
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +4 -4
- package/dist/cjs/shared/page-configs/getConfigValueTyped.js +32 -0
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +2 -2
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +135 -0
- package/dist/cjs/utils/isDocker.js +2 -2
- package/dist/cjs/utils/requireResolve.js +2 -2
- package/dist/esm/__internal/index.js +2 -2
- package/dist/esm/node/api/build.d.ts +10 -3
- package/dist/esm/node/api/build.js +14 -3
- package/dist/esm/node/api/context.d.ts +5 -0
- package/dist/esm/node/api/context.js +19 -0
- package/dist/esm/node/api/dev.d.ts +11 -2
- package/dist/esm/node/api/dev.js +11 -3
- package/dist/esm/node/api/onLoad.d.ts +2 -0
- package/dist/esm/node/api/onLoad.js +7 -0
- package/dist/esm/node/api/prepareViteApiCall.d.ts +7 -0
- package/dist/esm/node/api/{enhanceViteConfig.js → prepareViteApiCall.js} +11 -6
- package/dist/esm/node/api/prerender.d.ts +9 -1
- package/dist/esm/node/api/prerender.js +11 -3
- package/dist/esm/node/api/preview.d.ts +11 -2
- package/dist/esm/node/api/preview.js +11 -3
- package/dist/esm/node/api/{APIOptions.d.ts → types.d.ts} +3 -1
- package/dist/esm/node/api/utils.d.ts +2 -0
- package/dist/esm/node/api/utils.js +6 -0
- package/dist/esm/node/cli/entry.js +8 -8
- package/dist/esm/node/cli/onLoad.js +2 -0
- package/dist/esm/node/cli/parseCli.d.ts +1 -1
- package/dist/esm/node/plugin/index.js +3 -4
- package/dist/esm/node/plugin/onLoad.js +1 -1
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +0 -3
- package/dist/esm/node/plugin/plugins/buildConfig.js +7 -6
- package/dist/esm/node/plugin/plugins/commonConfig/pluginName.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/commonConfig/pluginName.js +1 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +23 -1
- package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +10 -20
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -7
- package/dist/esm/node/plugin/plugins/previewConfig.js +1 -2
- package/dist/esm/node/plugin/plugins/setGlobalContext.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +34 -19
- package/dist/esm/node/prerender/runPrerender.d.ts +5 -3
- package/dist/esm/node/prerender/runPrerender.js +6 -5
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/globalContext.d.ts +2 -2
- package/dist/esm/node/runtime/globalContext.js +7 -7
- package/dist/esm/node/runtime/index-common.d.ts +1 -0
- package/dist/esm/node/runtime/index-common.js +1 -0
- package/dist/esm/node/runtime/renderPage.js +5 -3
- package/dist/esm/node/runtime/utils.d.ts +1 -2
- package/dist/esm/node/runtime/utils.js +1 -2
- package/dist/esm/node/runtime-dev/createDevMiddleware.d.ts +10 -0
- package/dist/esm/node/runtime-dev/createDevMiddleware.js +23 -0
- package/dist/esm/node/runtime-dev/index.d.ts +3 -0
- package/dist/esm/node/runtime-dev/index.js +6 -0
- package/dist/esm/shared/page-configs/getConfigValue.d.ts +2 -8
- package/dist/esm/shared/page-configs/getConfigValue.js +1 -27
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.d.ts +2 -3
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +2 -2
- package/dist/esm/shared/page-configs/getConfigValueTyped.d.ts +9 -0
- package/dist/esm/shared/page-configs/getConfigValueTyped.js +27 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSetup.d.ts +20 -0
- package/dist/esm/utils/assertSetup.js +130 -0
- package/dist/esm/utils/isDocker.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/requireResolve.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/utils/assertIsNotProductionRuntime.js +0 -62
- package/dist/cjs/utils/assertNodeEnv.js +0 -106
- package/dist/esm/node/api/enhanceViteConfig.d.ts +0 -6
- package/dist/esm/utils/assertIsNotProductionRuntime.d.ts +0 -12
- package/dist/esm/utils/assertIsNotProductionRuntime.js +0 -59
- package/dist/esm/utils/assertNodeEnv.d.ts +0 -10
- package/dist/esm/utils/assertNodeEnv.js +0 -103
- /package/dist/cjs/node/api/{APIOptions.js → types.js} +0 -0
- /package/dist/esm/node/api/{APIOptions.js → types.js} +0 -0
|
@@ -11,9 +11,9 @@ export { initGlobalContext_runPrerender };
|
|
|
11
11
|
export { initGlobalContext_getGlobalContextAsync };
|
|
12
12
|
export { setGlobalContext_viteDevServer };
|
|
13
13
|
export { setGlobalContext_viteConfig };
|
|
14
|
-
export {
|
|
14
|
+
export { setGlobalContext_isViteDev };
|
|
15
15
|
export { setGlobalContext_isPrerendering };
|
|
16
|
-
import { assert,
|
|
16
|
+
import { assert, onSetupRuntime, assertUsage, assertWarning, getGlobalObject, isPlainObject, objectAssign, objectKeys, genPromise } from './utils.js';
|
|
17
17
|
import { loadImportBuild } from './globalContext/loadImportBuild.js';
|
|
18
18
|
import { setPageFiles } from '../../shared/getPageFiles.js';
|
|
19
19
|
import { assertPluginManifest } from '../shared/assertPluginManifest.js';
|
|
@@ -89,8 +89,8 @@ function assertIsNotInitilizedYet() {
|
|
|
89
89
|
// In develpoment, globalObject.viteDevServer always needs to be awaited for before initializing globalObject.globalContext
|
|
90
90
|
assert(!globalObject.globalContext);
|
|
91
91
|
}
|
|
92
|
-
function
|
|
93
|
-
globalObject.
|
|
92
|
+
function setGlobalContext_isViteDev(isViteDev) {
|
|
93
|
+
globalObject.isViteDev = isViteDev;
|
|
94
94
|
}
|
|
95
95
|
function setGlobalContext_isPrerendering() {
|
|
96
96
|
globalObject.isPrerendering = true;
|
|
@@ -102,7 +102,7 @@ function getViteConfig() {
|
|
|
102
102
|
return globalObject.viteConfig ?? null;
|
|
103
103
|
}
|
|
104
104
|
async function initGlobalContext_renderPage() {
|
|
105
|
-
await initGlobalContext(!globalObject.
|
|
105
|
+
await initGlobalContext(!globalObject.isViteDev);
|
|
106
106
|
}
|
|
107
107
|
async function initGlobalContext_runPrerender() {
|
|
108
108
|
if (globalObject.initGlobalContext_runPrerender_alreadyCalled)
|
|
@@ -138,8 +138,8 @@ async function initGlobalContext(isProduction) {
|
|
|
138
138
|
assert(globalObject.globalContext.isPrerendering === (globalObject.isPrerendering ?? false));
|
|
139
139
|
return;
|
|
140
140
|
}
|
|
141
|
-
const { viteDevServer, viteConfig,
|
|
142
|
-
|
|
141
|
+
const { viteDevServer, viteConfig, isPrerendering } = globalObject;
|
|
142
|
+
onSetupRuntime();
|
|
143
143
|
if (!isProduction) {
|
|
144
144
|
assert(viteConfig);
|
|
145
145
|
assert(viteDevServer);
|
|
@@ -3,6 +3,7 @@ export { escapeInject, dangerouslySkipEscape } from './html/renderHtml.js';
|
|
|
3
3
|
export { pipeWebStream, pipeNodeStream, pipeStream, stampPipe } from './html/stream.js';
|
|
4
4
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
5
5
|
export { getGlobalContextSync, getGlobalContextAsync } from './globalContext.js';
|
|
6
|
+
export { createDevMiddleware } from '../runtime-dev/index.js';
|
|
6
7
|
export { injectAssets__public as _injectAssets } from './html/injectAssets/injectAssets__public.js';
|
|
7
8
|
export { createPageRenderer } from '../createPageRenderer.js';
|
|
8
9
|
import './page-files/setup.js';
|
|
@@ -3,6 +3,7 @@ export { escapeInject, dangerouslySkipEscape } from './html/renderHtml.js';
|
|
|
3
3
|
export { pipeWebStream, pipeNodeStream, pipeStream, stampPipe } from './html/stream.js';
|
|
4
4
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
5
5
|
export { getGlobalContextSync, getGlobalContextAsync } from './globalContext.js';
|
|
6
|
+
export { createDevMiddleware } from '../runtime-dev/index.js';
|
|
6
7
|
// TODO/v1-release: remove
|
|
7
8
|
export { injectAssets__public as _injectAssets } from './html/injectAssets/injectAssets__public.js';
|
|
8
9
|
// TODO/v1-release: remove
|
|
@@ -2,7 +2,7 @@ export { renderPage };
|
|
|
2
2
|
export { renderPage_addWrapper };
|
|
3
3
|
import { getRenderContext, getPageContextInitEnhanced, renderPageAlreadyRouted } from './renderPage/renderPageAlreadyRouted.js';
|
|
4
4
|
import { route } from '../../shared/route/index.js';
|
|
5
|
-
import { assert, hasProp, objectAssign, isUrl, parseUrl,
|
|
5
|
+
import { assert, hasProp, objectAssign, isUrl, parseUrl, onSetupRuntime, assertWarning, getGlobalObject, checkType, assertUsage, normalizeUrlPathname, removeBaseServer, modifyUrlPathname, prependBase, removeUrlOrigin, setUrlOrigin, createUrlFromComponents, isUri, getUrlPretty } from './utils.js';
|
|
6
6
|
import { assertNoInfiniteAbortLoop, getPageContextFromAllRewrites, isAbortError, logAbortErrorHandled } from '../../shared/route/abort.js';
|
|
7
7
|
import { getGlobalContext, initGlobalContext_renderPage } from './globalContext.js';
|
|
8
8
|
import { handlePageContextRequestUrl } from './renderPage/handlePageContextRequestUrl.js';
|
|
@@ -31,7 +31,7 @@ const renderPage_addWrapper = (wrapper) => {
|
|
|
31
31
|
async function renderPage(pageContextInit) {
|
|
32
32
|
assertArguments(...arguments);
|
|
33
33
|
assert(hasProp(pageContextInit, 'urlOriginal', 'string')); // assertUsage() already implemented at assertArguments()
|
|
34
|
-
|
|
34
|
+
onSetupRuntime();
|
|
35
35
|
assertIsUrl(pageContextInit.urlOriginal);
|
|
36
36
|
const urlPathnameWithBase = parseUrl(pageContextInit.urlOriginal, '/').pathname;
|
|
37
37
|
assertIsNotViteRequest(urlPathnameWithBase, pageContextInit.urlOriginal);
|
|
@@ -332,7 +332,9 @@ function assertIsUrl(urlOriginal) {
|
|
|
332
332
|
}
|
|
333
333
|
function assertIsNotViteRequest(urlPathname, urlOriginal) {
|
|
334
334
|
const isViteRequest = urlPathname.startsWith('/@vite/client') || urlPathname.startsWith('/@fs/') || urlPathname.startsWith('/__vite_ping');
|
|
335
|
-
|
|
335
|
+
if (!isViteRequest)
|
|
336
|
+
return;
|
|
337
|
+
assertUsage(false, `${pc.code('renderPage(pageContextInit)')} called with ${pc.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which is unexpected because the URL ${pc.bold(urlOriginal)} should have already been handled by the development middleware: make sure the ${pc.cyan('createDevMiddleware()')} middleware is executed *before* the ${pc.cyan('renderPage()')} middleware, see ${pc.underline('https://vike.dev/renderPage')}`);
|
|
336
338
|
}
|
|
337
339
|
function normalizeUrl(pageContextInit, httpRequestId) {
|
|
338
340
|
const { trailingSlash, disableUrlNormalization, baseServer } = getGlobalContext();
|
|
@@ -39,9 +39,8 @@ export * from '../../utils/objectKeys.js';
|
|
|
39
39
|
export * from '../../utils/objectEntries.js';
|
|
40
40
|
export * from '../../utils/objectFromEntries.js';
|
|
41
41
|
export * from '../../utils/getFileExtension.js';
|
|
42
|
-
export * from '../../utils/
|
|
42
|
+
export * from '../../utils/assertSetup.js';
|
|
43
43
|
export * from '../../utils/path-shim.js';
|
|
44
|
-
export * from '../../utils/assertNodeEnv.js';
|
|
45
44
|
export * from '../../utils/isHtml.js';
|
|
46
45
|
export * from '../../utils/warnIfErrorIsNotObject.js';
|
|
47
46
|
export * from '../../utils/stripAnsi.js';
|
|
@@ -43,9 +43,8 @@ export * from '../../utils/objectKeys.js';
|
|
|
43
43
|
export * from '../../utils/objectEntries.js';
|
|
44
44
|
export * from '../../utils/objectFromEntries.js';
|
|
45
45
|
export * from '../../utils/getFileExtension.js';
|
|
46
|
-
export * from '../../utils/
|
|
46
|
+
export * from '../../utils/assertSetup.js';
|
|
47
47
|
export * from '../../utils/path-shim.js';
|
|
48
|
-
export * from '../../utils/assertNodeEnv.js';
|
|
49
48
|
export * from '../../utils/isHtml.js';
|
|
50
49
|
export * from '../../utils/warnIfErrorIsNotObject.js';
|
|
51
50
|
export * from '../../utils/stripAnsi.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { createDevMiddleware };
|
|
2
|
+
import type { ResolvedConfig, Connect, ViteDevServer } from 'vite';
|
|
3
|
+
import type { APIOptions } from '../api/types.js';
|
|
4
|
+
declare function createDevMiddleware(options?: {
|
|
5
|
+
root?: string;
|
|
6
|
+
} & APIOptions): Promise<{
|
|
7
|
+
devMiddleware: Connect.Server;
|
|
8
|
+
viteServer: ViteDevServer;
|
|
9
|
+
viteConfig: ResolvedConfig;
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { createDevMiddleware };
|
|
2
|
+
import { createServer } from 'vite';
|
|
3
|
+
import { prepareViteApiCall } from '../api/prepareViteApiCall.js';
|
|
4
|
+
/*
|
|
5
|
+
* Create server middleware for development with HMR and lazy-transpiling.
|
|
6
|
+
*
|
|
7
|
+
* https://vike.dev/createDevMiddleware
|
|
8
|
+
*/
|
|
9
|
+
async function createDevMiddleware(options = {}) {
|
|
10
|
+
const viteConfig = {
|
|
11
|
+
...options.viteConfig,
|
|
12
|
+
server: {
|
|
13
|
+
...options.viteConfig?.server,
|
|
14
|
+
middlewareMode: options.viteConfig?.server?.middlewareMode ?? true
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
if (options.root)
|
|
18
|
+
viteConfig.root = options.root;
|
|
19
|
+
const { viteConfigEnhanced } = await prepareViteApiCall(viteConfig, 'dev');
|
|
20
|
+
const server = await createServer(viteConfigEnhanced);
|
|
21
|
+
const devMiddleware = server.middlewares;
|
|
22
|
+
return { devMiddleware, viteServer: server, viteConfig: server.config };
|
|
23
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createDevMiddleware_ as createDevMiddleware };
|
|
2
|
+
const createDevMiddleware_ = async (...args) => {
|
|
3
|
+
const p = './createDevMiddleware.js';
|
|
4
|
+
const { createDevMiddleware } = await import(/*webpackIgnore: true*/ /* @vite-ignore */ p);
|
|
5
|
+
return createDevMiddleware(...args);
|
|
6
|
+
};
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
export { getConfigValueRuntime };
|
|
2
|
-
export { getConfigValueTyped };
|
|
3
|
-
export type { TypeAsString };
|
|
4
2
|
import { type ResolveTypeAsString } from '../utils.js';
|
|
5
3
|
import type { PageConfigRuntime, ConfigValue } from './PageConfig.js';
|
|
6
4
|
import type { ConfigNameBuiltIn } from './Config.js';
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
declare function getConfigValueTyped<Type extends TypeAsString = undefined>(configValue: ConfigValue, configName: ConfigName, type?: Type): null | (ConfigValue & {
|
|
10
|
-
value: ResolveTypeAsString<Type>;
|
|
11
|
-
});
|
|
12
|
-
declare function getConfigValueRuntime<Type extends TypeAsString = undefined>(pageConfig: PageConfigRuntime, configName: ConfigName, type?: Type): null | (ConfigValue & {
|
|
5
|
+
import { type TypeAsString } from './getConfigValueTyped.js';
|
|
6
|
+
declare function getConfigValueRuntime<Type extends TypeAsString = undefined>(pageConfig: PageConfigRuntime, configName: ConfigNameBuiltIn, type?: Type): null | (ConfigValue & {
|
|
13
7
|
value: ResolveTypeAsString<Type>;
|
|
14
8
|
});
|
|
@@ -1,34 +1,8 @@
|
|
|
1
1
|
export { getConfigValueRuntime };
|
|
2
|
-
|
|
3
|
-
import { assert, assertUsage, getValuePrintable } from '../utils.js';
|
|
4
|
-
import pc from '@brillout/picocolors';
|
|
5
|
-
import { getConfigDefinedAtOptional } from './getConfigDefinedAt.js';
|
|
6
|
-
function getConfigValueTyped(configValue, configName, type) {
|
|
7
|
-
/* [NULL_HANDLING] Do we really need this? This doesn't seem to make sense, let's eventually (re)move this.
|
|
8
|
-
// Enable users to suppress global config values by setting the local config value to null
|
|
9
|
-
if (configValue.value === null) return null
|
|
10
|
-
*/
|
|
11
|
-
const { value, definedAtData } = configValue;
|
|
12
|
-
if (type)
|
|
13
|
-
assertConfigValueType(value, type, configName, definedAtData);
|
|
14
|
-
return configValue;
|
|
15
|
-
}
|
|
2
|
+
import { getConfigValueTyped } from './getConfigValueTyped.js';
|
|
16
3
|
function getConfigValueRuntime(pageConfig, configName, type) {
|
|
17
4
|
const configValue = pageConfig.configValues[configName];
|
|
18
5
|
if (!configValue)
|
|
19
6
|
return null;
|
|
20
7
|
return getConfigValueTyped(configValue, configName, type);
|
|
21
8
|
}
|
|
22
|
-
function assertConfigValueType(value, type, configName, definedAtData) {
|
|
23
|
-
assert(value !== null);
|
|
24
|
-
const typeActual = typeof value;
|
|
25
|
-
if (typeActual === type)
|
|
26
|
-
return;
|
|
27
|
-
const valuePrintable = getValuePrintable(value);
|
|
28
|
-
const problem = valuePrintable !== null
|
|
29
|
-
? `value ${pc.cyan(valuePrintable)}`
|
|
30
|
-
: `type ${pc.cyan(typeActual)}`;
|
|
31
|
-
const configDefinedAt = getConfigDefinedAtOptional('Config', configName, definedAtData);
|
|
32
|
-
const errMsg = `${configDefinedAt} has an invalid ${problem}: it should be a ${pc.cyan(type)} instead`;
|
|
33
|
-
assertUsage(false, errMsg);
|
|
34
|
-
}
|
|
@@ -2,8 +2,7 @@ export { getConfigValueBuildTime };
|
|
|
2
2
|
import { type ResolveTypeAsString } from '../utils.js';
|
|
3
3
|
import type { PageConfigBuildTime, ConfigValue } from './PageConfig.js';
|
|
4
4
|
import type { ConfigNameBuiltIn } from './Config.js';
|
|
5
|
-
import { type TypeAsString } from './
|
|
6
|
-
|
|
7
|
-
declare function getConfigValueBuildTime<Type extends TypeAsString = undefined>(pageConfig: PageConfigBuildTime, configName: ConfigName, type?: Type): null | (ConfigValue & {
|
|
5
|
+
import { type TypeAsString } from './getConfigValueTyped.js';
|
|
6
|
+
declare function getConfigValueBuildTime<Type extends TypeAsString = undefined>(pageConfig: PageConfigBuildTime, configName: ConfigNameBuiltIn, type?: Type): null | (ConfigValue & {
|
|
8
7
|
value: ResolveTypeAsString<Type>;
|
|
9
8
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { getConfigValueBuildTime };
|
|
2
2
|
import { assert } from '../utils.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { assertIsNotProductionRuntime } from '../../utils/assertSetup.js';
|
|
4
|
+
import { getConfigValueTyped } from './getConfigValueTyped.js';
|
|
5
5
|
assertIsNotProductionRuntime();
|
|
6
6
|
function getConfigValueBuildTime(pageConfig, configName, type) {
|
|
7
7
|
const configValue = getConfigValue(pageConfig, configName);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { getConfigValueTyped };
|
|
2
|
+
export type { TypeAsString };
|
|
3
|
+
import { type ResolveTypeAsString } from '../utils.js';
|
|
4
|
+
import type { ConfigValue } from './PageConfig.js';
|
|
5
|
+
import type { ConfigNameBuiltIn } from './Config.js';
|
|
6
|
+
type TypeAsString = 'string' | 'boolean' | undefined;
|
|
7
|
+
declare function getConfigValueTyped<Type extends TypeAsString = undefined>(configValue: ConfigValue, configName: ConfigNameBuiltIn, type?: Type): null | (ConfigValue & {
|
|
8
|
+
value: ResolveTypeAsString<Type>;
|
|
9
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export { getConfigValueTyped };
|
|
2
|
+
import { assert, assertUsage, getValuePrintable } from '../utils.js';
|
|
3
|
+
import pc from '@brillout/picocolors';
|
|
4
|
+
import { getConfigDefinedAtOptional } from './getConfigDefinedAt.js';
|
|
5
|
+
function getConfigValueTyped(configValue, configName, type) {
|
|
6
|
+
/* [NULL_HANDLING] Do we really need this? This doesn't seem to make sense, let's eventually (re)move this.
|
|
7
|
+
// Enable users to suppress global config values by setting the local config value to null
|
|
8
|
+
if (configValue.value === null) return null
|
|
9
|
+
*/
|
|
10
|
+
const { value, definedAtData } = configValue;
|
|
11
|
+
if (type)
|
|
12
|
+
assertConfigValueType(value, type, configName, definedAtData);
|
|
13
|
+
return configValue;
|
|
14
|
+
}
|
|
15
|
+
function assertConfigValueType(value, type, configName, definedAtData) {
|
|
16
|
+
assert(value !== null);
|
|
17
|
+
const typeActual = typeof value;
|
|
18
|
+
if (typeActual === type)
|
|
19
|
+
return;
|
|
20
|
+
const valuePrintable = getValuePrintable(value);
|
|
21
|
+
const problem = valuePrintable !== null
|
|
22
|
+
? `value ${pc.cyan(valuePrintable)}`
|
|
23
|
+
: `type ${pc.cyan(typeActual)}`;
|
|
24
|
+
const configDefinedAt = getConfigDefinedAtOptional('Config', configName, definedAtData);
|
|
25
|
+
const errMsg = `${configDefinedAt} has an invalid ${problem}: it should be a ${pc.cyan(type)} instead`;
|
|
26
|
+
assertUsage(false, errMsg);
|
|
27
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { serializeConfigValues };
|
|
2
|
-
import { assertIsNotProductionRuntime } from '../../../utils/
|
|
2
|
+
import { assertIsNotProductionRuntime } from '../../../utils/assertSetup.js';
|
|
3
3
|
import { assert, assertUsage, getPropAccessNotation } from '../../../node/plugin/utils.js';
|
|
4
4
|
import { addImportStatement } from '../../../node/plugin/plugins/importUserCode/addImportStatement.js';
|
|
5
5
|
import { parsePointerImportData } from '../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformPointerImports.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.216";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.
|
|
2
|
+
export const PROJECT_VERSION = '0.4.216';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { assertIsNotProductionRuntime };
|
|
2
|
+
export { onSetupRuntime };
|
|
3
|
+
export { onSetupBuild };
|
|
4
|
+
export { onSetupPrerender };
|
|
5
|
+
export { setNodeEnvProduction };
|
|
6
|
+
export { markSetup_viteDevServer };
|
|
7
|
+
export { markSetup_vitePreviewServer };
|
|
8
|
+
export { markSetup_vikeVitePlugin };
|
|
9
|
+
export { markSetup_isViteDev };
|
|
10
|
+
export { markSetup_isPrerendering };
|
|
11
|
+
declare function assertIsNotProductionRuntime(): void | undefined;
|
|
12
|
+
declare function onSetupRuntime(): void | undefined;
|
|
13
|
+
declare function onSetupBuild(): void;
|
|
14
|
+
declare function onSetupPrerender(): void;
|
|
15
|
+
declare function markSetup_viteDevServer(): void | undefined;
|
|
16
|
+
declare function markSetup_vitePreviewServer(): void | undefined;
|
|
17
|
+
declare function markSetup_vikeVitePlugin(): void;
|
|
18
|
+
declare function markSetup_isViteDev(isViteDev: boolean): void;
|
|
19
|
+
declare function markSetup_isPrerendering(): void;
|
|
20
|
+
declare function setNodeEnvProduction(): void | undefined;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export { assertIsNotProductionRuntime };
|
|
2
|
+
export { onSetupRuntime };
|
|
3
|
+
export { onSetupBuild };
|
|
4
|
+
export { onSetupPrerender };
|
|
5
|
+
export { setNodeEnvProduction };
|
|
6
|
+
export { markSetup_viteDevServer };
|
|
7
|
+
export { markSetup_vitePreviewServer };
|
|
8
|
+
export { markSetup_vikeVitePlugin };
|
|
9
|
+
export { markSetup_isViteDev };
|
|
10
|
+
export { markSetup_isPrerendering };
|
|
11
|
+
import { assert, assertUsage, assertWarning } from './assert.js';
|
|
12
|
+
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
13
|
+
import { createDebugger } from './debug.js';
|
|
14
|
+
import { getGlobalObject } from './getGlobalObject.js';
|
|
15
|
+
import { isVitest } from './isVitest.js';
|
|
16
|
+
import pc from '@brillout/picocolors';
|
|
17
|
+
assertIsNotBrowser();
|
|
18
|
+
const debug = createDebugger('vike:setup');
|
|
19
|
+
const setup = getGlobalObject('utils/assertIsNotProductionRuntime.ts', {});
|
|
20
|
+
// Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
|
|
21
|
+
function assertIsNotProductionRuntime() {
|
|
22
|
+
if (debug.isActivated)
|
|
23
|
+
debug('assertIsNotProductionRuntime()', new Error().stack);
|
|
24
|
+
setup.shouldNotBeProduction = true;
|
|
25
|
+
}
|
|
26
|
+
function onSetupRuntime() {
|
|
27
|
+
if (debug.isActivated)
|
|
28
|
+
debug('assertSetup()', new Error().stack);
|
|
29
|
+
if (isTest())
|
|
30
|
+
return;
|
|
31
|
+
if (!isViteLoaded()) {
|
|
32
|
+
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
33
|
+
assertWarning(!isNodeEnvDev(), `The ${getEnvDescription()}, which seems contradictory because the environment seems to be a production environment (Vite isn't loaded), see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
34
|
+
assertUsage(!setup.vikeVitePlugin, "Loading Vike's Vite plugin (the vike/plugin module) is prohibited in production.");
|
|
35
|
+
// This assert() one of the main goal of this file: it ensures assertIsNotProductionRuntime()
|
|
36
|
+
assert(!setup.shouldNotBeProduction);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
40
|
+
assertWarning(isNodeEnvDev() || setup.vitePreviewServer || setup.isPrerendering, `The ${getEnvDescription()}, but Vite is loaded which is prohibited in production, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
41
|
+
// These two assert() calls aren't that interesting
|
|
42
|
+
assert(setup.vikeVitePlugin);
|
|
43
|
+
assert(setup.shouldNotBeProduction);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Ensure NODE_ENV is 'production' when building.
|
|
47
|
+
// - Used by both Vue and React for bundling minified version:
|
|
48
|
+
// - Vue: https://github.com/vuejs/core/blob/f66a75ea75c8aece065b61e2126b4c5b2338aa6e/packages/vue/index.js
|
|
49
|
+
// - React: https://github.com/facebook/react/blob/01ab35a9a731dec69995fbd28f3ac7eaad11e183/packages/react/npm/index.js
|
|
50
|
+
// - Required for React: setting NODE_ENV to a value other than 'production' triggers an error: https://github.com/vikejs/vike/issues/1469#issuecomment-1969301797
|
|
51
|
+
// - Not required for Vue: when building the app, NODE_ENV can be set to a value other than 'production', e.g. 'development'.
|
|
52
|
+
function onSetupBuild() {
|
|
53
|
+
assertUsageNodeEnvIsNotDev('building');
|
|
54
|
+
/* Not needed: Vite already sets `process.env.NODE_ENV = 'production'`
|
|
55
|
+
setNodeEnvProduction()
|
|
56
|
+
*/
|
|
57
|
+
}
|
|
58
|
+
function onSetupPrerender() {
|
|
59
|
+
markSetup_isPrerendering();
|
|
60
|
+
if (getNodeEnvValue())
|
|
61
|
+
assertUsageNodeEnvIsNotDev('pre-rendering');
|
|
62
|
+
setNodeEnvProduction();
|
|
63
|
+
}
|
|
64
|
+
function isViteLoaded() {
|
|
65
|
+
// Do we need setup.viteDevServer or setup.vitePreviewServer ?
|
|
66
|
+
return setup.viteDevServer || setup.vitePreviewServer || setup.isViteDev !== undefined;
|
|
67
|
+
}
|
|
68
|
+
function isTest() {
|
|
69
|
+
return isVitest() || getNodeEnvValue() === 'test';
|
|
70
|
+
}
|
|
71
|
+
// Called by Vite hook configureServer()
|
|
72
|
+
function markSetup_viteDevServer() {
|
|
73
|
+
if (debug.isActivated)
|
|
74
|
+
debug('markSetup_viteDevServer()', new Error().stack);
|
|
75
|
+
setup.viteDevServer = true;
|
|
76
|
+
}
|
|
77
|
+
// Called by Vite hook configurePreviewServer()
|
|
78
|
+
function markSetup_vitePreviewServer() {
|
|
79
|
+
if (debug.isActivated)
|
|
80
|
+
debug('markSetup_vitePreviewServer()', new Error().stack);
|
|
81
|
+
setup.vitePreviewServer = true;
|
|
82
|
+
}
|
|
83
|
+
// Called by ../node/plugin/index.ts
|
|
84
|
+
function markSetup_vikeVitePlugin() {
|
|
85
|
+
if (debug.isActivated)
|
|
86
|
+
debug('markSetup_vikeVitePlugin()', new Error().stack);
|
|
87
|
+
setup.vikeVitePlugin = true;
|
|
88
|
+
}
|
|
89
|
+
// Whether Vite is loaded and whether it's in dev mode (the value returned by `isDevCheck()`)
|
|
90
|
+
function markSetup_isViteDev(isViteDev) {
|
|
91
|
+
if (debug.isActivated)
|
|
92
|
+
debug('markSetup_isViteDev()', new Error().stack);
|
|
93
|
+
setup.isViteDev = isViteDev;
|
|
94
|
+
}
|
|
95
|
+
// Called by ../node/prerender/runPrerender.ts
|
|
96
|
+
function markSetup_isPrerendering() {
|
|
97
|
+
if (debug.isActivated)
|
|
98
|
+
debug('markSetup_isPrerendering()', new Error().stack);
|
|
99
|
+
setup.isPrerendering = true;
|
|
100
|
+
}
|
|
101
|
+
function assertUsageNodeEnvIsNotDev(operation) {
|
|
102
|
+
if (!isNodeEnvDev())
|
|
103
|
+
return;
|
|
104
|
+
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
105
|
+
assertWarning(false, `The ${getEnvDescription()} which is forbidden upon ${operation}, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
106
|
+
}
|
|
107
|
+
function getEnvDescription() {
|
|
108
|
+
const nodeEnv = getNodeEnvValue();
|
|
109
|
+
const isDev = isNodeEnvDev();
|
|
110
|
+
const envType = `${(isDev ? 'development' : 'production')} environment`;
|
|
111
|
+
const nodeEnvDesc = `environment is set to be a ${pc.bold(envType)} by ${pc.cyan(`process.env.NODE_ENV===${JSON.stringify(nodeEnv)}`)}`;
|
|
112
|
+
return nodeEnvDesc;
|
|
113
|
+
}
|
|
114
|
+
function isNodeEnvDev() {
|
|
115
|
+
const nodeEnv = getNodeEnvValue();
|
|
116
|
+
// That's quite strict, let's see if some user complains
|
|
117
|
+
return !nodeEnv || ['development', 'dev'].includes(nodeEnv);
|
|
118
|
+
}
|
|
119
|
+
function getNodeEnvValue() {
|
|
120
|
+
if (typeof process === 'undefined')
|
|
121
|
+
return null;
|
|
122
|
+
return process.env.NODE_ENV?.toLowerCase();
|
|
123
|
+
}
|
|
124
|
+
function setNodeEnvProduction() {
|
|
125
|
+
// The statement `process.env['NODE_ENV'] = 'production'` chokes webpack v4
|
|
126
|
+
const proc = process;
|
|
127
|
+
const { env } = proc;
|
|
128
|
+
env.NODE_ENV = 'production';
|
|
129
|
+
assert(getNodeEnvValue() === 'production');
|
|
130
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { isDocker };
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
-
import { assertIsNotProductionRuntime } from './
|
|
3
|
+
import { assertIsNotProductionRuntime } from './assertSetup.js';
|
|
4
4
|
assertIsNotProductionRuntime();
|
|
5
5
|
function isDocker() {
|
|
6
6
|
return hasContainerEnv() || isDockerContainer();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { requireResolve };
|
|
2
2
|
import { assert } from './assert.js';
|
|
3
3
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
4
|
-
import { assertIsNotProductionRuntime } from './
|
|
4
|
+
import { assertIsNotProductionRuntime } from './assertSetup.js';
|
|
5
5
|
import { assertPosixPath, toPosixPath } from './filesystemPathHandling.js';
|
|
6
6
|
import { scriptFileExtensionList } from './isScriptFile.js';
|
|
7
7
|
import { createRequire } from 'module';
|
package/package.json
CHANGED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Mechanism to ensure code isn't loaded by production runtime
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.vikeVitePluginLoadedInProductionError = void 0;
|
|
5
|
-
exports.assertIsNotProductionRuntime = assertIsNotProductionRuntime;
|
|
6
|
-
exports.markEnvAsViteDev = markEnvAsViteDev;
|
|
7
|
-
exports.markEnvAsVitePreview = markEnvAsVitePreview;
|
|
8
|
-
exports.markEnvAsVikePluginLoaded = markEnvAsVikePluginLoaded;
|
|
9
|
-
exports.assertEnv = assertEnv;
|
|
10
|
-
const assert_js_1 = require("./assert.js");
|
|
11
|
-
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
12
|
-
const debug_js_1 = require("./debug.js");
|
|
13
|
-
const getGlobalObject_js_1 = require("./getGlobalObject.js");
|
|
14
|
-
const isVitest_js_1 = require("./isVitest.js");
|
|
15
|
-
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
16
|
-
const debug = (0, debug_js_1.createDebugger)('vike:setup');
|
|
17
|
-
const vikeVitePluginLoadedInProductionError = `Loading Vike's Vite plugin (the vike/plugin module) is prohibited in production.`;
|
|
18
|
-
exports.vikeVitePluginLoadedInProductionError = vikeVitePluginLoadedInProductionError;
|
|
19
|
-
const env = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertIsNotProductionRuntime.ts', {});
|
|
20
|
-
// Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
|
|
21
|
-
function assertIsNotProductionRuntime() {
|
|
22
|
-
if (debug.isActivated)
|
|
23
|
-
debug('assertIsNotProductionRuntime()', new Error().stack);
|
|
24
|
-
env.shouldNotBeProduction = true;
|
|
25
|
-
}
|
|
26
|
-
// Called by Vite hook configureServer()
|
|
27
|
-
function markEnvAsViteDev() {
|
|
28
|
-
if (debug.isActivated)
|
|
29
|
-
debug('markEnvAsViteDev()', new Error().stack);
|
|
30
|
-
env.isViteDev = true;
|
|
31
|
-
}
|
|
32
|
-
// Called by Vite hook configurePreviewServer()
|
|
33
|
-
function markEnvAsVitePreview() {
|
|
34
|
-
if (debug.isActivated)
|
|
35
|
-
debug('markEnvAsVitePreview()', new Error().stack);
|
|
36
|
-
env.isVitePreview = true;
|
|
37
|
-
}
|
|
38
|
-
// Called by ../node/plugin/index.ts
|
|
39
|
-
function markEnvAsVikePluginLoaded() {
|
|
40
|
-
if (debug.isActivated)
|
|
41
|
-
debug('markEnvAsVikePluginLoaded()', new Error().stack);
|
|
42
|
-
env.isVikePluginLoaded = true;
|
|
43
|
-
}
|
|
44
|
-
// Called by ../node/runtime/index.ts
|
|
45
|
-
function assertEnv() {
|
|
46
|
-
if (debug.isActivated)
|
|
47
|
-
debug('assertEnv()', new Error().stack);
|
|
48
|
-
if ((0, isVitest_js_1.isVitest)())
|
|
49
|
-
return;
|
|
50
|
-
const isProduction = !env.isViteDev && !env.isVitePreview;
|
|
51
|
-
if (isProduction) {
|
|
52
|
-
// Seems to be the only reliable way to assert that the user doesn't load Vike's Vite plugin in production. (The other assert() that uses process.env.NODE_ENV doesn't work if the user sets the process.env.NODE_ENV value later.)
|
|
53
|
-
(0, assert_js_1.assertUsage)(!env.isVikePluginLoaded, vikeVitePluginLoadedInProductionError);
|
|
54
|
-
// This assert() is the main goal of this file: it ensures assertIsNotProductionRuntime()
|
|
55
|
-
(0, assert_js_1.assert)(!env.shouldNotBeProduction);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
// This assert() is obious and boring
|
|
59
|
-
(0, assert_js_1.assert)(env.shouldNotBeProduction);
|
|
60
|
-
(0, assert_js_1.assert)(env.isVikePluginLoaded);
|
|
61
|
-
}
|
|
62
|
-
}
|