vike 0.4.222-commit-5513d32 → 0.4.222-commit-ce4e16e
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/node/plugin/plugins/envVars.js +2 -17
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +2 -2
- package/dist/cjs/node/plugin/shared/viteIsSSR.js +19 -10
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/node/plugin/plugins/envVars.js +2 -17
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +3 -3
- package/dist/esm/node/plugin/shared/viteIsSSR.d.ts +7 -4
- package/dist/esm/node/plugin/shared/viteIsSSR.js +20 -11
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ const utils_js_1 = require("../utils.js");
|
|
|
6
6
|
const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
|
|
7
7
|
const getFilePath_js_1 = require("../shared/getFilePath.js");
|
|
8
8
|
const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
9
|
+
const viteIsSSR_js_1 = require("../shared/viteIsSSR.js");
|
|
9
10
|
// TODO/enventually: (after we implemented vike.config.js)
|
|
10
11
|
// - Make import.meta.env work inside +config.js
|
|
11
12
|
// - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
|
|
@@ -38,7 +39,7 @@ function envVarsPlugin() {
|
|
|
38
39
|
if (!code.includes('import.meta.env.'))
|
|
39
40
|
return;
|
|
40
41
|
const isBuild = config.command === 'build';
|
|
41
|
-
const isClientSide =
|
|
42
|
+
const isClientSide = !(0, viteIsSSR_js_1.viteIsSSR_safe)(config, options);
|
|
42
43
|
Object.entries(envsAll)
|
|
43
44
|
.filter(([key]) => {
|
|
44
45
|
// Already handled by Vite
|
|
@@ -84,19 +85,3 @@ function envVarsPlugin() {
|
|
|
84
85
|
function applyEnvVar(envStatementRegEx, envVal, code) {
|
|
85
86
|
return code.replace(envStatementRegEx, JSON.stringify(envVal));
|
|
86
87
|
}
|
|
87
|
-
function getIsClientSide(config, options) {
|
|
88
|
-
const isBuild = config.command === 'build';
|
|
89
|
-
if (isBuild) {
|
|
90
|
-
(0, utils_js_1.assert)(typeof config.build.ssr === 'boolean');
|
|
91
|
-
const isServerSide = config.build.ssr;
|
|
92
|
-
if (options !== undefined) {
|
|
93
|
-
(0, utils_js_1.assert)(options.ssr === isServerSide);
|
|
94
|
-
}
|
|
95
|
-
return !isServerSide;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
(0, utils_js_1.assert)(typeof options?.ssr === 'boolean');
|
|
99
|
-
const isServerSide = options.ssr;
|
|
100
|
-
return !isServerSide;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
@@ -48,7 +48,7 @@ function extractAssetsPlugin() {
|
|
|
48
48
|
}
|
|
49
49
|
// TODO/now: add meta.default
|
|
50
50
|
(0, utils_js_1.assert)(vikeConfig.global.config.includeAssetsImportedByServer ?? true);
|
|
51
|
-
(0, utils_js_1.assert)(!(0, viteIsSSR_js_1.
|
|
51
|
+
(0, utils_js_1.assert)(!(0, viteIsSSR_js_1.viteIsSSR_safe)(config, options));
|
|
52
52
|
const importStatements = await (0, parseEsModule_js_1.getImportStatements)(src);
|
|
53
53
|
const moduleNames = getImportedModules(importStatements);
|
|
54
54
|
const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
|
|
@@ -65,7 +65,7 @@ function extractAssetsPlugin() {
|
|
|
65
65
|
// - Vite's `vite:resolve` plugin; https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
|
|
66
66
|
enforce: 'pre',
|
|
67
67
|
async resolveId(source, importer, options) {
|
|
68
|
-
if ((0, viteIsSSR_js_1.
|
|
68
|
+
if ((0, viteIsSSR_js_1.viteIsSSR_safe)(config, options)) {
|
|
69
69
|
// When building for the server, there should never be a `?extractAssets` query
|
|
70
70
|
(0, utils_js_1.assert)(!extractAssetsRE.test(source));
|
|
71
71
|
(0, utils_js_1.assert)(importer === undefined || !extractAssetsRE.test(importer));
|
|
@@ -2,21 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.viteIsSSR = viteIsSSR;
|
|
4
4
|
exports.viteIsSSR_options = viteIsSSR_options;
|
|
5
|
+
exports.viteIsSSR_safe = viteIsSSR_safe;
|
|
5
6
|
const assert_js_1 = require("../../../utils/assert.js");
|
|
6
|
-
const isObject_js_1 = require("../../../utils/isObject.js");
|
|
7
7
|
function viteIsSSR(config) {
|
|
8
8
|
return !!config?.build?.ssr;
|
|
9
9
|
}
|
|
10
|
-
// https://github.com/vitejs/vite/discussions/5109#discussioncomment-1450726
|
|
11
10
|
function viteIsSSR_options(options) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
return !!options?.ssr;
|
|
12
|
+
}
|
|
13
|
+
// Vite is quite messy about setting `ssr: boolean`, thus we use an extra safe implemention for security purposes.
|
|
14
|
+
// It's used for .client.js and .server.js guarantee thus we use agressive assert() calls for added safety.
|
|
15
|
+
function viteIsSSR_safe(config, options) {
|
|
16
|
+
if (config.command === 'build') {
|
|
17
|
+
(0, assert_js_1.assert)(typeof config.build.ssr === 'boolean');
|
|
18
|
+
const val = config.build.ssr;
|
|
19
|
+
if (options?.ssr !== undefined)
|
|
20
|
+
(0, assert_js_1.assert)(val === options.ssr);
|
|
21
|
+
return val;
|
|
17
22
|
}
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
else {
|
|
24
|
+
(0, assert_js_1.assert)(typeof options?.ssr === 'boolean');
|
|
25
|
+
const val = options.ssr;
|
|
26
|
+
/* This assert() fails (which is very unexpected).
|
|
27
|
+
if (typeof config.build.ssr === 'boolean') assert(val === config.build.ssr)
|
|
28
|
+
//*/
|
|
29
|
+
return val;
|
|
20
30
|
}
|
|
21
|
-
(0, assert_js_1.assert)(false);
|
|
22
31
|
}
|
|
@@ -4,6 +4,7 @@ import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, isArr
|
|
|
4
4
|
import { sourceMapPassthrough } from '../shared/rollupSourceMap.js';
|
|
5
5
|
import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
|
|
6
6
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
7
|
+
import { viteIsSSR_safe } from '../shared/viteIsSSR.js';
|
|
7
8
|
// TODO/enventually: (after we implemented vike.config.js)
|
|
8
9
|
// - Make import.meta.env work inside +config.js
|
|
9
10
|
// - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
|
|
@@ -36,7 +37,7 @@ function envVarsPlugin() {
|
|
|
36
37
|
if (!code.includes('import.meta.env.'))
|
|
37
38
|
return;
|
|
38
39
|
const isBuild = config.command === 'build';
|
|
39
|
-
const isClientSide =
|
|
40
|
+
const isClientSide = !viteIsSSR_safe(config, options);
|
|
40
41
|
Object.entries(envsAll)
|
|
41
42
|
.filter(([key]) => {
|
|
42
43
|
// Already handled by Vite
|
|
@@ -82,19 +83,3 @@ function envVarsPlugin() {
|
|
|
82
83
|
function applyEnvVar(envStatementRegEx, envVal, code) {
|
|
83
84
|
return code.replace(envStatementRegEx, JSON.stringify(envVal));
|
|
84
85
|
}
|
|
85
|
-
function getIsClientSide(config, options) {
|
|
86
|
-
const isBuild = config.command === 'build';
|
|
87
|
-
if (isBuild) {
|
|
88
|
-
assert(typeof config.build.ssr === 'boolean');
|
|
89
|
-
const isServerSide = config.build.ssr;
|
|
90
|
-
if (options !== undefined) {
|
|
91
|
-
assert(options.ssr === isServerSide);
|
|
92
|
-
}
|
|
93
|
-
return !isServerSide;
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
assert(typeof options?.ssr === 'boolean');
|
|
97
|
-
const isServerSide = options.ssr;
|
|
98
|
-
return !isServerSide;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
@@ -17,7 +17,7 @@ import { fixServerAssets_isEnabled } from './buildConfig/fixServerAssets.js';
|
|
|
17
17
|
import { getVikeConfig, isV1Design } from './importUserCode/v1-design/getVikeConfig.js';
|
|
18
18
|
import { assertV1Design } from '../../shared/assertV1Design.js';
|
|
19
19
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
20
|
-
import {
|
|
20
|
+
import { viteIsSSR_safe } from '../shared/viteIsSSR.js';
|
|
21
21
|
const extractAssetsRE = /(\?|&)extractAssets(?:&|$)/;
|
|
22
22
|
const rawRE = /(\?|&)raw(?:&|$)/;
|
|
23
23
|
const urlRE = /(\?|&)url(?:&|$)/;
|
|
@@ -46,7 +46,7 @@ function extractAssetsPlugin() {
|
|
|
46
46
|
}
|
|
47
47
|
// TODO/now: add meta.default
|
|
48
48
|
assert(vikeConfig.global.config.includeAssetsImportedByServer ?? true);
|
|
49
|
-
assert(!
|
|
49
|
+
assert(!viteIsSSR_safe(config, options));
|
|
50
50
|
const importStatements = await getImportStatements(src);
|
|
51
51
|
const moduleNames = getImportedModules(importStatements);
|
|
52
52
|
const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
|
|
@@ -63,7 +63,7 @@ function extractAssetsPlugin() {
|
|
|
63
63
|
// - Vite's `vite:resolve` plugin; https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
|
|
64
64
|
enforce: 'pre',
|
|
65
65
|
async resolveId(source, importer, options) {
|
|
66
|
-
if (
|
|
66
|
+
if (viteIsSSR_safe(config, options)) {
|
|
67
67
|
// When building for the server, there should never be a `?extractAssets` query
|
|
68
68
|
assert(!extractAssetsRE.test(source));
|
|
69
69
|
assert(importer === undefined || !extractAssetsRE.test(importer));
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import type { ResolvedConfig, UserConfig } from 'vite';
|
|
2
1
|
export { viteIsSSR };
|
|
3
2
|
export { viteIsSSR_options };
|
|
3
|
+
export { viteIsSSR_safe };
|
|
4
|
+
import type { ResolvedConfig, UserConfig } from 'vite';
|
|
4
5
|
declare function viteIsSSR(config: ResolvedConfig | UserConfig): boolean;
|
|
5
|
-
|
|
6
|
+
declare function viteIsSSR_options(options: {
|
|
7
|
+
ssr?: boolean;
|
|
8
|
+
} | undefined): boolean;
|
|
9
|
+
declare function viteIsSSR_safe(config: ResolvedConfig, options: {
|
|
6
10
|
ssr?: boolean;
|
|
7
|
-
};
|
|
8
|
-
declare function viteIsSSR_options(options: Options): boolean;
|
|
11
|
+
} | undefined): boolean;
|
|
@@ -1,20 +1,29 @@
|
|
|
1
|
-
import { assert } from '../../../utils/assert.js';
|
|
2
|
-
import { isObject } from '../../../utils/isObject.js';
|
|
3
1
|
export { viteIsSSR };
|
|
4
2
|
export { viteIsSSR_options };
|
|
3
|
+
export { viteIsSSR_safe };
|
|
4
|
+
import { assert } from '../../../utils/assert.js';
|
|
5
5
|
function viteIsSSR(config) {
|
|
6
6
|
return !!config?.build?.ssr;
|
|
7
7
|
}
|
|
8
|
-
// https://github.com/vitejs/vite/discussions/5109#discussioncomment-1450726
|
|
9
8
|
function viteIsSSR_options(options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
return !!options?.ssr;
|
|
10
|
+
}
|
|
11
|
+
// Vite is quite messy about setting `ssr: boolean`, thus we use an extra safe implemention for security purposes.
|
|
12
|
+
// It's used for .client.js and .server.js guarantee thus we use agressive assert() calls for added safety.
|
|
13
|
+
function viteIsSSR_safe(config, options) {
|
|
14
|
+
if (config.command === 'build') {
|
|
15
|
+
assert(typeof config.build.ssr === 'boolean');
|
|
16
|
+
const val = config.build.ssr;
|
|
17
|
+
if (options?.ssr !== undefined)
|
|
18
|
+
assert(val === options.ssr);
|
|
19
|
+
return val;
|
|
15
20
|
}
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
else {
|
|
22
|
+
assert(typeof options?.ssr === 'boolean');
|
|
23
|
+
const val = options.ssr;
|
|
24
|
+
/* This assert() fails (which is very unexpected).
|
|
25
|
+
if (typeof config.build.ssr === 'boolean') assert(val === config.build.ssr)
|
|
26
|
+
//*/
|
|
27
|
+
return val;
|
|
18
28
|
}
|
|
19
|
-
assert(false);
|
|
20
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.222-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.222-commit-ce4e16e";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.222-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.222-commit-ce4e16e';
|