vike 0.4.218-commit-ea8bb27 → 0.4.218-commit-8ebd8ee
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/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +33 -16
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSetup.js +33 -16
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -33,16 +33,19 @@ function onSetupRuntime() {
|
|
|
33
33
|
debug('assertSetup()', new Error().stack);
|
|
34
34
|
if (isTest())
|
|
35
35
|
return;
|
|
36
|
+
assertNodeEnvIsNotUndefinedString();
|
|
36
37
|
if (!isViteLoaded()) {
|
|
37
38
|
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
38
|
-
(0, assert_js_1.assertWarning)(!isNodeEnvDev(), `The ${getEnvDescription()}, which
|
|
39
|
+
(0, assert_js_1.assertWarning)(!isNodeEnvDev(), `The ${getEnvDescription()}, which is contradictory because the environment seems to be a production environment (Vite isn't loaded), see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
39
40
|
(0, assert_js_1.assertUsage)(!setup.vikeVitePlugin, "Loading Vike's Vite plugin (the vike/plugin module) is prohibited in production.");
|
|
40
41
|
// This assert() one of the main goal of this file: it ensures assertIsNotProductionRuntime()
|
|
41
42
|
(0, assert_js_1.assert)(!setup.shouldNotBeProduction);
|
|
42
43
|
}
|
|
43
44
|
else {
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
if (!setup.vitePreviewServer && !setup.isPrerendering) {
|
|
46
|
+
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
47
|
+
(0, assert_js_1.assertWarning)(isNodeEnvDev(), `The ${getEnvDescription()}, but Vite is loaded which is prohibited in production, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
48
|
+
}
|
|
46
49
|
// These two assert() calls aren't that interesting
|
|
47
50
|
(0, assert_js_1.assert)(setup.vikeVitePlugin);
|
|
48
51
|
(0, assert_js_1.assert)(setup.shouldNotBeProduction);
|
|
@@ -62,7 +65,7 @@ function onSetupBuild() {
|
|
|
62
65
|
}
|
|
63
66
|
function onSetupPrerender() {
|
|
64
67
|
markSetup_isPrerendering();
|
|
65
|
-
if (
|
|
68
|
+
if (getNodeEnv())
|
|
66
69
|
assertUsageNodeEnvIsNotDev('pre-rendering');
|
|
67
70
|
setNodeEnvProduction();
|
|
68
71
|
}
|
|
@@ -71,7 +74,7 @@ function isViteLoaded() {
|
|
|
71
74
|
return setup.viteDevServer || setup.vitePreviewServer || setup.isViteDev !== undefined;
|
|
72
75
|
}
|
|
73
76
|
function isTest() {
|
|
74
|
-
return (0, isVitest_js_1.isVitest)() ||
|
|
77
|
+
return (0, isVitest_js_1.isVitest)() || isNodeEnv('test');
|
|
75
78
|
}
|
|
76
79
|
// Called by Vite hook configureServer()
|
|
77
80
|
function markSetup_viteDevServer() {
|
|
@@ -110,26 +113,40 @@ function assertUsageNodeEnvIsNotDev(operation) {
|
|
|
110
113
|
(0, assert_js_1.assertWarning)(false, `The ${getEnvDescription()} which is forbidden upon ${operation}, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
111
114
|
}
|
|
112
115
|
function getEnvDescription() {
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
const envType = `${(isDev ? 'development' : 'production')} environment`;
|
|
116
|
-
const nodeEnvDesc = `environment is set to be a ${picocolors_1.default.bold(envType)} by ${picocolors_1.default.cyan(`process.env.NODE_ENV===${JSON.stringify(nodeEnv)}`)}`;
|
|
116
|
+
const envType = `${(isNodeEnvDev() ? 'development' : 'production')} environment`;
|
|
117
|
+
const nodeEnvDesc = `environment is set to be a ${picocolors_1.default.bold(envType)} by ${picocolors_1.default.cyan(`process.env.NODE_ENV===${JSON.stringify(getNodeEnv())}`)}`;
|
|
117
118
|
return nodeEnvDesc;
|
|
118
119
|
}
|
|
120
|
+
// For example, Wrangler bug replaces `process.env.NODE_ENV` with `"undefined"`
|
|
121
|
+
// https://github.com/cloudflare/workers-sdk/issues/7886
|
|
122
|
+
function assertNodeEnvIsNotUndefinedString() {
|
|
123
|
+
const nodeEnv = getNodeEnv();
|
|
124
|
+
(0, assert_js_1.assertWarning)(nodeEnv === 'undefined', `${picocolors_1.default.cyan('process.env.NODE_ENV=="undefined"')} which is unexpected: ${picocolors_1.default.cyan('process.env.NODE_ENV')} can be the value ${picocolors_1.default.cyan('undefined')} (in development) but it shouldn't be the string ${picocolors_1.default.cyan('"undefined"')} ${picocolors_1.default.underline('https://vike.dev/NODE_ENV')}`, { onlyOnce: true });
|
|
125
|
+
}
|
|
119
126
|
function isNodeEnvDev() {
|
|
120
|
-
const nodeEnv =
|
|
127
|
+
const nodeEnv = getNodeEnv();
|
|
121
128
|
// That's quite strict, let's see if some user complains
|
|
122
|
-
return
|
|
129
|
+
return nodeEnv === undefined || isNodeEnv(['development', 'dev', '']);
|
|
130
|
+
}
|
|
131
|
+
function isNodeEnv(value) {
|
|
132
|
+
const values = Array.isArray(value) ? value : [value];
|
|
133
|
+
const nodeEnv = getNodeEnv();
|
|
134
|
+
return nodeEnv !== undefined && values.includes(nodeEnv.toLowerCase());
|
|
123
135
|
}
|
|
124
|
-
function
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
136
|
+
function getNodeEnv() {
|
|
137
|
+
let val;
|
|
138
|
+
try {
|
|
139
|
+
val = process.env.NODE_ENV;
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
return val;
|
|
128
145
|
}
|
|
129
146
|
function setNodeEnvProduction() {
|
|
130
147
|
// The statement `process.env['NODE_ENV'] = 'production'` chokes webpack v4
|
|
131
148
|
const proc = process;
|
|
132
149
|
const { env } = proc;
|
|
133
150
|
env.NODE_ENV = 'production';
|
|
134
|
-
(0, assert_js_1.assert)(
|
|
151
|
+
(0, assert_js_1.assert)(isNodeEnv('production'));
|
|
135
152
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.218-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.218-commit-8ebd8ee";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.218-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.218-commit-8ebd8ee';
|
|
@@ -28,16 +28,19 @@ function onSetupRuntime() {
|
|
|
28
28
|
debug('assertSetup()', new Error().stack);
|
|
29
29
|
if (isTest())
|
|
30
30
|
return;
|
|
31
|
+
assertNodeEnvIsNotUndefinedString();
|
|
31
32
|
if (!isViteLoaded()) {
|
|
32
33
|
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
33
|
-
assertWarning(!isNodeEnvDev(), `The ${getEnvDescription()}, which
|
|
34
|
+
assertWarning(!isNodeEnvDev(), `The ${getEnvDescription()}, which is contradictory because the environment seems to be a production environment (Vite isn't loaded), see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
34
35
|
assertUsage(!setup.vikeVitePlugin, "Loading Vike's Vite plugin (the vike/plugin module) is prohibited in production.");
|
|
35
36
|
// This assert() one of the main goal of this file: it ensures assertIsNotProductionRuntime()
|
|
36
37
|
assert(!setup.shouldNotBeProduction);
|
|
37
38
|
}
|
|
38
39
|
else {
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
if (!setup.vitePreviewServer && !setup.isPrerendering) {
|
|
41
|
+
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
42
|
+
assertWarning(isNodeEnvDev(), `The ${getEnvDescription()}, but Vite is loaded which is prohibited in production, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
43
|
+
}
|
|
41
44
|
// These two assert() calls aren't that interesting
|
|
42
45
|
assert(setup.vikeVitePlugin);
|
|
43
46
|
assert(setup.shouldNotBeProduction);
|
|
@@ -57,7 +60,7 @@ function onSetupBuild() {
|
|
|
57
60
|
}
|
|
58
61
|
function onSetupPrerender() {
|
|
59
62
|
markSetup_isPrerendering();
|
|
60
|
-
if (
|
|
63
|
+
if (getNodeEnv())
|
|
61
64
|
assertUsageNodeEnvIsNotDev('pre-rendering');
|
|
62
65
|
setNodeEnvProduction();
|
|
63
66
|
}
|
|
@@ -66,7 +69,7 @@ function isViteLoaded() {
|
|
|
66
69
|
return setup.viteDevServer || setup.vitePreviewServer || setup.isViteDev !== undefined;
|
|
67
70
|
}
|
|
68
71
|
function isTest() {
|
|
69
|
-
return isVitest() ||
|
|
72
|
+
return isVitest() || isNodeEnv('test');
|
|
70
73
|
}
|
|
71
74
|
// Called by Vite hook configureServer()
|
|
72
75
|
function markSetup_viteDevServer() {
|
|
@@ -105,26 +108,40 @@ function assertUsageNodeEnvIsNotDev(operation) {
|
|
|
105
108
|
assertWarning(false, `The ${getEnvDescription()} which is forbidden upon ${operation}, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
106
109
|
}
|
|
107
110
|
function getEnvDescription() {
|
|
108
|
-
const
|
|
109
|
-
const
|
|
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)}`)}`;
|
|
111
|
+
const envType = `${(isNodeEnvDev() ? 'development' : 'production')} environment`;
|
|
112
|
+
const nodeEnvDesc = `environment is set to be a ${pc.bold(envType)} by ${pc.cyan(`process.env.NODE_ENV===${JSON.stringify(getNodeEnv())}`)}`;
|
|
112
113
|
return nodeEnvDesc;
|
|
113
114
|
}
|
|
115
|
+
// For example, Wrangler bug replaces `process.env.NODE_ENV` with `"undefined"`
|
|
116
|
+
// https://github.com/cloudflare/workers-sdk/issues/7886
|
|
117
|
+
function assertNodeEnvIsNotUndefinedString() {
|
|
118
|
+
const nodeEnv = getNodeEnv();
|
|
119
|
+
assertWarning(nodeEnv === 'undefined', `${pc.cyan('process.env.NODE_ENV=="undefined"')} which is unexpected: ${pc.cyan('process.env.NODE_ENV')} can be the value ${pc.cyan('undefined')} (in development) but it shouldn't be the string ${pc.cyan('"undefined"')} ${pc.underline('https://vike.dev/NODE_ENV')}`, { onlyOnce: true });
|
|
120
|
+
}
|
|
114
121
|
function isNodeEnvDev() {
|
|
115
|
-
const nodeEnv =
|
|
122
|
+
const nodeEnv = getNodeEnv();
|
|
116
123
|
// That's quite strict, let's see if some user complains
|
|
117
|
-
return
|
|
124
|
+
return nodeEnv === undefined || isNodeEnv(['development', 'dev', '']);
|
|
125
|
+
}
|
|
126
|
+
function isNodeEnv(value) {
|
|
127
|
+
const values = Array.isArray(value) ? value : [value];
|
|
128
|
+
const nodeEnv = getNodeEnv();
|
|
129
|
+
return nodeEnv !== undefined && values.includes(nodeEnv.toLowerCase());
|
|
118
130
|
}
|
|
119
|
-
function
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
131
|
+
function getNodeEnv() {
|
|
132
|
+
let val;
|
|
133
|
+
try {
|
|
134
|
+
val = process.env.NODE_ENV;
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
return val;
|
|
123
140
|
}
|
|
124
141
|
function setNodeEnvProduction() {
|
|
125
142
|
// The statement `process.env['NODE_ENV'] = 'production'` chokes webpack v4
|
|
126
143
|
const proc = process;
|
|
127
144
|
const { env } = proc;
|
|
128
145
|
env.NODE_ENV = 'production';
|
|
129
|
-
assert(
|
|
146
|
+
assert(isNodeEnv('production'));
|
|
130
147
|
}
|