vike 0.4.227-commit-68a216b → 0.4.227-commit-e36b916
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/build/pluginModuleBanner.js +24 -4
- package/dist/cjs/node/plugin/plugins/envVars.js +22 -13
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +1 -2
- package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +1 -2
- package/dist/cjs/node/plugin/plugins/fileEnv.js +1 -2
- package/dist/cjs/node/plugin/utils.js +1 -0
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/isScriptFile.js +4 -4
- package/dist/cjs/utils/parseUrl.js +4 -4
- package/dist/cjs/{node/plugin/shared → utils}/rollupSourceMap.js +4 -4
- package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.js +21 -4
- package/dist/esm/node/plugin/plugins/envVars.js +19 -13
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +2 -3
- package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +2 -3
- package/dist/esm/node/plugin/plugins/fileEnv.js +2 -3
- package/dist/esm/node/plugin/utils.d.ts +1 -0
- package/dist/esm/node/plugin/utils.js +1 -0
- package/dist/esm/shared/route/executeOnBeforeRouteHook.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/isScriptFile.js +4 -4
- package/dist/esm/utils/parseUrl.js +4 -4
- package/dist/esm/{node/plugin/shared → utils}/rollupSourceMap.d.ts +4 -4
- package/dist/esm/{node/plugin/shared → utils}/rollupSourceMap.js +4 -4
- package/package.json +2 -1
|
@@ -1,31 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.pluginModuleBanner = pluginModuleBanner;
|
|
7
|
+
const magic_string_1 = __importDefault(require("magic-string"));
|
|
4
8
|
const utils_js_1 = require("../../utils.js");
|
|
5
9
|
const virtual_files_js_1 = require("../../../shared/virtual-files.js");
|
|
6
10
|
const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
|
|
7
|
-
const rollupSourceMap_js_1 = require("../../shared/rollupSourceMap.js");
|
|
8
11
|
// Rollup's banner feature doesn't work with Vite: https://github.com/vitejs/vite/issues/8412
|
|
9
12
|
// But, anyways, we want to prepend the banner at the beginning of each module, not at the beginning of each file (I believe that's what Rollup's banner feature does).
|
|
10
13
|
const vikeModuleBannerPlaceholder = 'vikeModuleBannerPlaceholder';
|
|
11
14
|
function pluginModuleBanner() {
|
|
12
15
|
let config;
|
|
16
|
+
let disabled = false;
|
|
13
17
|
return {
|
|
14
18
|
name: 'vike:pluginModuleBanner',
|
|
15
19
|
enforce: 'post',
|
|
16
20
|
apply: 'build',
|
|
17
21
|
configResolved(config_) {
|
|
18
22
|
config = config_;
|
|
23
|
+
if (config.build.minify && config.build.minify !== 'esbuild') {
|
|
24
|
+
// Doesn't work upon `config.build.minify === 'terser'`
|
|
25
|
+
// https://github.com/vikejs/vike/issues/2315
|
|
26
|
+
disabled = true;
|
|
27
|
+
}
|
|
19
28
|
},
|
|
20
29
|
generateBundle: {
|
|
21
30
|
order: 'post',
|
|
22
31
|
handler(_options, bundle) {
|
|
32
|
+
if (disabled)
|
|
33
|
+
return;
|
|
23
34
|
for (const module of Object.values(bundle)) {
|
|
24
35
|
if (module.type === 'chunk') {
|
|
25
36
|
if ((0, isViteServerBuild_js_1.isViteServerBuild)(config)) {
|
|
26
37
|
const codeOld = module.code;
|
|
27
38
|
const codeNew = codeOld.replace(/vikeModuleBannerPlaceholder\("([^"]*)"\);/g, '/* $1 [vike:pluginModuleBanner] */');
|
|
28
|
-
|
|
39
|
+
if (codeNew.includes(vikeModuleBannerPlaceholder)) {
|
|
40
|
+
console.log('codeNew', codeNew);
|
|
41
|
+
(0, utils_js_1.assert)(false);
|
|
42
|
+
}
|
|
29
43
|
module.code = codeNew;
|
|
30
44
|
}
|
|
31
45
|
else {
|
|
@@ -38,6 +52,8 @@ function pluginModuleBanner() {
|
|
|
38
52
|
transform: {
|
|
39
53
|
order: 'post',
|
|
40
54
|
handler(code, id, options) {
|
|
55
|
+
if (disabled)
|
|
56
|
+
return;
|
|
41
57
|
if (!(0, isViteServerBuild_js_1.isViteServerBuild_safe)(config, options))
|
|
42
58
|
return;
|
|
43
59
|
if (id.startsWith('\0'))
|
|
@@ -45,9 +61,13 @@ function pluginModuleBanner() {
|
|
|
45
61
|
id = (0, virtual_files_js_1.removeVirtualIdTag)(id);
|
|
46
62
|
if (id.startsWith(config.root))
|
|
47
63
|
id = id.slice(config.root.length + 1);
|
|
64
|
+
const s = new magic_string_1.default(code);
|
|
48
65
|
// No need to insert a new line; Rollup formats the code and will insert a new line.
|
|
49
|
-
|
|
50
|
-
return
|
|
66
|
+
s.prepend(`${vikeModuleBannerPlaceholder}(${JSON.stringify(id)}); `);
|
|
67
|
+
return {
|
|
68
|
+
code: s.toString(),
|
|
69
|
+
map: s.generateMap({ hires: true, source: id })
|
|
70
|
+
};
|
|
51
71
|
}
|
|
52
72
|
}
|
|
53
73
|
};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.envVarsPlugin = envVarsPlugin;
|
|
7
|
+
const magic_string_1 = __importDefault(require("magic-string"));
|
|
4
8
|
const vite_1 = require("vite");
|
|
5
9
|
const utils_js_1 = require("../utils.js");
|
|
6
|
-
const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
|
|
7
10
|
const getFilePath_js_1 = require("../shared/getFilePath.js");
|
|
8
11
|
const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
9
12
|
const isViteServerBuild_js_1 = require("../shared/isViteServerBuild.js");
|
|
@@ -12,7 +15,7 @@ const isViteServerBuild_js_1 = require("../shared/isViteServerBuild.js");
|
|
|
12
15
|
// - 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
|
|
13
16
|
// - Or stop using Vite's `mode` implemention and have Vike implement its own `mode` feature? (So that the only dependencies are `$ vike build --mode staging` and `$ MODE=staging vike build`.)
|
|
14
17
|
const PUBLIC_ENV_PREFIX = 'PUBLIC_ENV__';
|
|
15
|
-
const
|
|
18
|
+
const PUBLIC_ENV_ALLOWLIST = [
|
|
16
19
|
// https://github.com/vikejs/vike/issues/1724
|
|
17
20
|
'STORYBOOK'
|
|
18
21
|
];
|
|
@@ -40,6 +43,7 @@ function envVarsPlugin() {
|
|
|
40
43
|
return;
|
|
41
44
|
const isBuild = config.command === 'build';
|
|
42
45
|
const isClientSide = !(0, isViteServerBuild_js_1.isViteServerBuild_safe)(config, options);
|
|
46
|
+
const s = new magic_string_1.default(code);
|
|
43
47
|
Object.entries(envsAll)
|
|
44
48
|
.filter(([key]) => {
|
|
45
49
|
// Already handled by Vite
|
|
@@ -48,12 +52,12 @@ function envVarsPlugin() {
|
|
|
48
52
|
})
|
|
49
53
|
.forEach(([envName, envVal]) => {
|
|
50
54
|
const envStatement = `import.meta.env.${envName}`;
|
|
51
|
-
const
|
|
55
|
+
const envStatementRegExStr = (0, utils_js_1.escapeRegex)(envStatement) + '\\b';
|
|
52
56
|
// Security check
|
|
53
57
|
{
|
|
54
|
-
const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !
|
|
58
|
+
const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_ALLOWLIST.includes(envName);
|
|
55
59
|
if (isPrivate && isClientSide) {
|
|
56
|
-
if (!
|
|
60
|
+
if (!new RegExp(envStatementRegExStr).test(code))
|
|
57
61
|
return;
|
|
58
62
|
const modulePath = (0, getFilePath_js_1.getModuleFilePathAbsolute)(id, config);
|
|
59
63
|
const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
|
|
@@ -72,16 +76,21 @@ function envVarsPlugin() {
|
|
|
72
76
|
(0, utils_js_1.assert)(!(isPrivate && isClientSide) || !isBuild);
|
|
73
77
|
}
|
|
74
78
|
// Apply
|
|
75
|
-
|
|
79
|
+
applyEnvVar(s, envStatementRegExStr, envVal);
|
|
76
80
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
if (!s.hasChanged())
|
|
82
|
+
return null;
|
|
83
|
+
return {
|
|
84
|
+
code: s.toString(),
|
|
85
|
+
map: s.generateMap({ hires: true, source: id })
|
|
86
|
+
};
|
|
82
87
|
}
|
|
83
88
|
};
|
|
84
89
|
}
|
|
85
|
-
function applyEnvVar(
|
|
86
|
-
|
|
90
|
+
function applyEnvVar(s, envStatementRegExStr, envVal) {
|
|
91
|
+
const envStatementRegEx = new RegExp(envStatementRegExStr, 'g');
|
|
92
|
+
let match;
|
|
93
|
+
while ((match = envStatementRegEx.exec(s.original))) {
|
|
94
|
+
s.overwrite(match.index, match.index + match[0].length, JSON.stringify(envVal));
|
|
95
|
+
}
|
|
87
96
|
}
|
|
@@ -12,7 +12,6 @@ const virtual_files_js_1 = require("../../shared/virtual-files.js");
|
|
|
12
12
|
const extractAssetsQuery_js_1 = require("../../shared/extractAssetsQuery.js");
|
|
13
13
|
const isAsset_js_1 = require("../shared/isAsset.js");
|
|
14
14
|
const parseEsModule_js_1 = require("../shared/parseEsModule.js");
|
|
15
|
-
const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
|
|
16
15
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
17
16
|
const handleAssetsManifest_js_1 = require("./build/handleAssetsManifest.js");
|
|
18
17
|
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
@@ -53,7 +52,7 @@ function extractAssetsPlugin() {
|
|
|
53
52
|
const moduleNames = getImportedModules(importStatements);
|
|
54
53
|
const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
|
|
55
54
|
debugTransformResult(id, code, importStatements);
|
|
56
|
-
return (0,
|
|
55
|
+
return (0, utils_js_1.rollupSourceMapRemove)(code);
|
|
57
56
|
}
|
|
58
57
|
},
|
|
59
58
|
// This plugin appends `?extractAssets` to module IDs
|
|
@@ -5,7 +5,6 @@ exports.extractExportNamesPlugin = extractExportNamesPlugin;
|
|
|
5
5
|
exports.isUsingClientRouter = isUsingClientRouter;
|
|
6
6
|
const utils_js_1 = require("../utils.js");
|
|
7
7
|
const parseEsModule_js_1 = require("../shared/parseEsModule.js");
|
|
8
|
-
const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
|
|
9
8
|
const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
10
9
|
const isViteServerBuild_js_1 = require("../shared/isViteServerBuild.js");
|
|
11
10
|
const extractExportNamesRE = /(\?|&)extractExportNames(?:&|$)/;
|
|
@@ -42,7 +41,7 @@ async function getExtractExportNamesCode(src, isClientSide, isProduction, id) {
|
|
|
42
41
|
globalObject.usesClientRouter = true;
|
|
43
42
|
}
|
|
44
43
|
const code = getCode(exportNames, wildcardReExports, isClientSide, isProduction, id);
|
|
45
|
-
return (0,
|
|
44
|
+
return (0, utils_js_1.rollupSourceMapRemove)(code);
|
|
46
45
|
}
|
|
47
46
|
function getCode(exportNames, wildcardReExports, isClientSide, isProduction, id) {
|
|
48
47
|
let code = '';
|
|
@@ -9,7 +9,6 @@ const extractAssetsPlugin_js_1 = require("./extractAssetsPlugin.js");
|
|
|
9
9
|
const extractExportNamesPlugin_js_1 = require("./extractExportNamesPlugin.js");
|
|
10
10
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
11
11
|
const getFilePath_js_1 = require("../shared/getFilePath.js");
|
|
12
|
-
const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
|
|
13
12
|
const parseEsModule_js_1 = require("../shared/parseEsModule.js");
|
|
14
13
|
const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
15
14
|
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
@@ -54,7 +53,7 @@ function fileEnv() {
|
|
|
54
53
|
const errMsg = getErrorMessage(id, isServerSide, importers, false, true);
|
|
55
54
|
// We have to inject empty exports to avoid Rollup complaining about missing exports, see https://gist.github.com/brillout/5ea45776e65bd65100a52ecd7bfda3ff
|
|
56
55
|
const { exportNames } = await (0, parseEsModule_js_1.getExportNames)(code);
|
|
57
|
-
return (0,
|
|
56
|
+
return (0, utils_js_1.rollupSourceMapRemove)([
|
|
58
57
|
`throw new Error(${JSON.stringify(errMsg)});`,
|
|
59
58
|
...exportNames.map((name) => name === 'default' ? 'export default undefined;' : `export const ${name} = undefined;`)
|
|
60
59
|
].join('\n'));
|
|
@@ -45,3 +45,4 @@ __exportStar(require("../../utils/PROJECT_VERSION.js"), exports);
|
|
|
45
45
|
__exportStar(require("../../utils/isEqualStringList.js"), exports);
|
|
46
46
|
__exportStar(require("../../utils/isDocker.js"), exports);
|
|
47
47
|
__exportStar(require("../../utils/isVitest.js"), exports);
|
|
48
|
+
__exportStar(require("../../utils/rollupSourceMap.js"), exports);
|
|
@@ -72,7 +72,7 @@ async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
|
|
|
72
72
|
if ((0, utils_js_1.hasProp)(hookReturn.pageContext, 'urlLogical')) {
|
|
73
73
|
(0, utils_js_1.assertUsageUrlPathnameAbsolute)(
|
|
74
74
|
// We skip validation and type-cast instead of assertUsage() in order to save client-side KBs
|
|
75
|
-
hookReturn.pageContext.urlLogical, `${errPrefix} returned ${picocolors_1.default.cyan('{ pageContext: { urlLogical } }')}
|
|
75
|
+
hookReturn.pageContext.urlLogical, `${errPrefix} returned ${picocolors_1.default.cyan('{ pageContext: { urlLogical } }')} and ${picocolors_1.default.cyan('urlLogical')}`);
|
|
76
76
|
}
|
|
77
77
|
(0, assertPageContextProvidedByUser_js_1.assertPageContextProvidedByUser)(hookReturn.pageContext, {
|
|
78
78
|
hookFilePath: onBeforeRouteHook.hookFilePath,
|
|
@@ -8,12 +8,12 @@ const assert_js_1 = require("./assert.js");
|
|
|
8
8
|
// We can't use a RegExp:
|
|
9
9
|
// - Needs to work with Micromatch: https://github.com/micromatch/micromatch because:
|
|
10
10
|
// - Vite's `import.meta.glob()` uses Micromatch
|
|
11
|
-
// - We need this to be a
|
|
11
|
+
// - We need this to be a allowlist because:
|
|
12
12
|
// - A pattern `*([a-zA-Z0-9]` doesn't work.
|
|
13
13
|
// - Because of ReScript: `.res` are ReScript source files which need to be ignored. (The ReScript compiler generates `.js` files alongside `.res` files.)
|
|
14
|
-
// -
|
|
15
|
-
// - We cannot implement a
|
|
16
|
-
// - A post `import.meta.glob()`
|
|
14
|
+
// - Block listing doesn't work.
|
|
15
|
+
// - We cannot implement a blocklist with a glob pattern.
|
|
16
|
+
// - A post `import.meta.glob()` blocklist filtering doesn't work because Vite would still process the files (e.g. including them in the bundle).
|
|
17
17
|
// prettier-ignore
|
|
18
18
|
// biome-ignore format:
|
|
19
19
|
const extJavaScript = [
|
|
@@ -186,14 +186,14 @@ function parseProtocol(uri) {
|
|
|
186
186
|
return { protocol, uriWithoutProtocol };
|
|
187
187
|
}
|
|
188
188
|
function isUrlProtocol(protocol) {
|
|
189
|
-
// Is there an
|
|
190
|
-
// - If the
|
|
191
|
-
const
|
|
189
|
+
// Is there an alternative to having a blocklist?
|
|
190
|
+
// - If the blocklist becomes too big, maybe use a allowlist instead ['tauri://', 'file://', 'capacitor://', 'http://', 'https://']
|
|
191
|
+
const blocklist = [
|
|
192
192
|
// https://docs.ipfs.tech/how-to/address-ipfs-on-web
|
|
193
193
|
'ipfs://',
|
|
194
194
|
'ipns://'
|
|
195
195
|
];
|
|
196
|
-
if (
|
|
196
|
+
if (blocklist.includes(protocol))
|
|
197
197
|
return false;
|
|
198
198
|
return protocol.endsWith('://');
|
|
199
199
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.rollupSourceMapRemove = rollupSourceMapRemove;
|
|
4
|
+
exports.rollupSourceMapPassthrough = rollupSourceMapPassthrough;
|
|
5
5
|
// https://rollupjs.org/guide/en/#source-code-transformations
|
|
6
6
|
/** Remove entire source mapping, to save KBs. */
|
|
7
|
-
function
|
|
7
|
+
function rollupSourceMapRemove(code) {
|
|
8
8
|
return {
|
|
9
9
|
code,
|
|
10
10
|
map: { mappings: '' }
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
/** Don't provide any source map, pass through current source map instead. */
|
|
14
|
-
function
|
|
14
|
+
function rollupSourceMapPassthrough(code) {
|
|
15
15
|
return {
|
|
16
16
|
code,
|
|
17
17
|
map: null
|
|
@@ -1,29 +1,40 @@
|
|
|
1
1
|
export { pluginModuleBanner };
|
|
2
|
+
import MagicString from 'magic-string';
|
|
2
3
|
import { assert } from '../../utils.js';
|
|
3
4
|
import { removeVirtualIdTag } from '../../../shared/virtual-files.js';
|
|
4
5
|
import { isViteServerBuild, isViteServerBuild_safe } from '../../shared/isViteServerBuild.js';
|
|
5
|
-
import { sourceMapPassthrough } from '../../shared/rollupSourceMap.js';
|
|
6
6
|
// Rollup's banner feature doesn't work with Vite: https://github.com/vitejs/vite/issues/8412
|
|
7
7
|
// But, anyways, we want to prepend the banner at the beginning of each module, not at the beginning of each file (I believe that's what Rollup's banner feature does).
|
|
8
8
|
const vikeModuleBannerPlaceholder = 'vikeModuleBannerPlaceholder';
|
|
9
9
|
function pluginModuleBanner() {
|
|
10
10
|
let config;
|
|
11
|
+
let disabled = false;
|
|
11
12
|
return {
|
|
12
13
|
name: 'vike:pluginModuleBanner',
|
|
13
14
|
enforce: 'post',
|
|
14
15
|
apply: 'build',
|
|
15
16
|
configResolved(config_) {
|
|
16
17
|
config = config_;
|
|
18
|
+
if (config.build.minify && config.build.minify !== 'esbuild') {
|
|
19
|
+
// Doesn't work upon `config.build.minify === 'terser'`
|
|
20
|
+
// https://github.com/vikejs/vike/issues/2315
|
|
21
|
+
disabled = true;
|
|
22
|
+
}
|
|
17
23
|
},
|
|
18
24
|
generateBundle: {
|
|
19
25
|
order: 'post',
|
|
20
26
|
handler(_options, bundle) {
|
|
27
|
+
if (disabled)
|
|
28
|
+
return;
|
|
21
29
|
for (const module of Object.values(bundle)) {
|
|
22
30
|
if (module.type === 'chunk') {
|
|
23
31
|
if (isViteServerBuild(config)) {
|
|
24
32
|
const codeOld = module.code;
|
|
25
33
|
const codeNew = codeOld.replace(/vikeModuleBannerPlaceholder\("([^"]*)"\);/g, '/* $1 [vike:pluginModuleBanner] */');
|
|
26
|
-
|
|
34
|
+
if (codeNew.includes(vikeModuleBannerPlaceholder)) {
|
|
35
|
+
console.log('codeNew', codeNew);
|
|
36
|
+
assert(false);
|
|
37
|
+
}
|
|
27
38
|
module.code = codeNew;
|
|
28
39
|
}
|
|
29
40
|
else {
|
|
@@ -36,6 +47,8 @@ function pluginModuleBanner() {
|
|
|
36
47
|
transform: {
|
|
37
48
|
order: 'post',
|
|
38
49
|
handler(code, id, options) {
|
|
50
|
+
if (disabled)
|
|
51
|
+
return;
|
|
39
52
|
if (!isViteServerBuild_safe(config, options))
|
|
40
53
|
return;
|
|
41
54
|
if (id.startsWith('\0'))
|
|
@@ -43,9 +56,13 @@ function pluginModuleBanner() {
|
|
|
43
56
|
id = removeVirtualIdTag(id);
|
|
44
57
|
if (id.startsWith(config.root))
|
|
45
58
|
id = id.slice(config.root.length + 1);
|
|
59
|
+
const s = new MagicString(code);
|
|
46
60
|
// No need to insert a new line; Rollup formats the code and will insert a new line.
|
|
47
|
-
|
|
48
|
-
return
|
|
61
|
+
s.prepend(`${vikeModuleBannerPlaceholder}(${JSON.stringify(id)}); `);
|
|
62
|
+
return {
|
|
63
|
+
code: s.toString(),
|
|
64
|
+
map: s.generateMap({ hires: true, source: id })
|
|
65
|
+
};
|
|
49
66
|
}
|
|
50
67
|
}
|
|
51
68
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { envVarsPlugin };
|
|
2
|
+
import MagicString from 'magic-string';
|
|
2
3
|
import { loadEnv } from 'vite';
|
|
3
4
|
import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, isArray, lowerFirst } from '../utils.js';
|
|
4
|
-
import { sourceMapPassthrough } from '../shared/rollupSourceMap.js';
|
|
5
5
|
import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
|
|
6
6
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
7
7
|
import { isViteServerBuild_safe } from '../shared/isViteServerBuild.js';
|
|
@@ -10,7 +10,7 @@ import { isViteServerBuild_safe } from '../shared/isViteServerBuild.js';
|
|
|
10
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
|
|
11
11
|
// - Or stop using Vite's `mode` implemention and have Vike implement its own `mode` feature? (So that the only dependencies are `$ vike build --mode staging` and `$ MODE=staging vike build`.)
|
|
12
12
|
const PUBLIC_ENV_PREFIX = 'PUBLIC_ENV__';
|
|
13
|
-
const
|
|
13
|
+
const PUBLIC_ENV_ALLOWLIST = [
|
|
14
14
|
// https://github.com/vikejs/vike/issues/1724
|
|
15
15
|
'STORYBOOK'
|
|
16
16
|
];
|
|
@@ -38,6 +38,7 @@ function envVarsPlugin() {
|
|
|
38
38
|
return;
|
|
39
39
|
const isBuild = config.command === 'build';
|
|
40
40
|
const isClientSide = !isViteServerBuild_safe(config, options);
|
|
41
|
+
const s = new MagicString(code);
|
|
41
42
|
Object.entries(envsAll)
|
|
42
43
|
.filter(([key]) => {
|
|
43
44
|
// Already handled by Vite
|
|
@@ -46,12 +47,12 @@ function envVarsPlugin() {
|
|
|
46
47
|
})
|
|
47
48
|
.forEach(([envName, envVal]) => {
|
|
48
49
|
const envStatement = `import.meta.env.${envName}`;
|
|
49
|
-
const
|
|
50
|
+
const envStatementRegExStr = escapeRegex(envStatement) + '\\b';
|
|
50
51
|
// Security check
|
|
51
52
|
{
|
|
52
|
-
const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !
|
|
53
|
+
const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_ALLOWLIST.includes(envName);
|
|
53
54
|
if (isPrivate && isClientSide) {
|
|
54
|
-
if (!
|
|
55
|
+
if (!new RegExp(envStatementRegExStr).test(code))
|
|
55
56
|
return;
|
|
56
57
|
const modulePath = getModuleFilePathAbsolute(id, config);
|
|
57
58
|
const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
|
|
@@ -70,16 +71,21 @@ function envVarsPlugin() {
|
|
|
70
71
|
assert(!(isPrivate && isClientSide) || !isBuild);
|
|
71
72
|
}
|
|
72
73
|
// Apply
|
|
73
|
-
|
|
74
|
+
applyEnvVar(s, envStatementRegExStr, envVal);
|
|
74
75
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
if (!s.hasChanged())
|
|
77
|
+
return null;
|
|
78
|
+
return {
|
|
79
|
+
code: s.toString(),
|
|
80
|
+
map: s.generateMap({ hires: true, source: id })
|
|
81
|
+
};
|
|
80
82
|
}
|
|
81
83
|
};
|
|
82
84
|
}
|
|
83
|
-
function applyEnvVar(
|
|
84
|
-
|
|
85
|
+
function applyEnvVar(s, envStatementRegExStr, envVal) {
|
|
86
|
+
const envStatementRegEx = new RegExp(envStatementRegExStr, 'g');
|
|
87
|
+
let match;
|
|
88
|
+
while ((match = envStatementRegEx.exec(s.original))) {
|
|
89
|
+
s.overwrite(match.index, match.index + match[0].length, JSON.stringify(envVal));
|
|
90
|
+
}
|
|
85
91
|
}
|
|
@@ -6,12 +6,11 @@
|
|
|
6
6
|
// - This appraoch supports import path aliases `vite.config.js#resolve.alias` https://vitejs.dev/config/#resolve-alias
|
|
7
7
|
export { extractAssetsPlugin };
|
|
8
8
|
export { extractAssetsRE };
|
|
9
|
-
import { assert, assertPosixPath, styleFileRE, createDebugger, isScriptFile, assertUsage } from '../utils.js';
|
|
9
|
+
import { assert, assertPosixPath, styleFileRE, createDebugger, isScriptFile, assertUsage, rollupSourceMapRemove } from '../utils.js';
|
|
10
10
|
import { resolveVirtualFileId, isVirtualFileId, getVirtualFileId } from '../../shared/virtual-files.js';
|
|
11
11
|
import { extractAssetsAddQuery } from '../../shared/extractAssetsQuery.js';
|
|
12
12
|
import { isAsset } from '../shared/isAsset.js';
|
|
13
13
|
import { getImportStatements } from '../shared/parseEsModule.js';
|
|
14
|
-
import { sourceMapRemove } from '../shared/rollupSourceMap.js';
|
|
15
14
|
import pc from '@brillout/picocolors';
|
|
16
15
|
import { handleAssetsManifest_isFixEnabled } from './build/handleAssetsManifest.js';
|
|
17
16
|
import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
|
|
@@ -51,7 +50,7 @@ function extractAssetsPlugin() {
|
|
|
51
50
|
const moduleNames = getImportedModules(importStatements);
|
|
52
51
|
const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
|
|
53
52
|
debugTransformResult(id, code, importStatements);
|
|
54
|
-
return
|
|
53
|
+
return rollupSourceMapRemove(code);
|
|
55
54
|
}
|
|
56
55
|
},
|
|
57
56
|
// This plugin appends `?extractAssets` to module IDs
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export { extractExportNamesPlugin };
|
|
2
2
|
export { isUsingClientRouter };
|
|
3
3
|
export { extractExportNamesRE };
|
|
4
|
-
import { assert, getFileExtension, createDebugger, getGlobalObject, assertUsage } from '../utils.js';
|
|
4
|
+
import { assert, getFileExtension, createDebugger, getGlobalObject, assertUsage, rollupSourceMapRemove } from '../utils.js';
|
|
5
5
|
import { getExportNames } from '../shared/parseEsModule.js';
|
|
6
|
-
import { sourceMapRemove } from '../shared/rollupSourceMap.js';
|
|
7
6
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
8
7
|
import { isViteServerBuild_options } from '../shared/isViteServerBuild.js';
|
|
9
8
|
const extractExportNamesRE = /(\?|&)extractExportNames(?:&|$)/;
|
|
@@ -39,7 +38,7 @@ async function getExtractExportNamesCode(src, isClientSide, isProduction, id) {
|
|
|
39
38
|
globalObject.usesClientRouter = true;
|
|
40
39
|
}
|
|
41
40
|
const code = getCode(exportNames, wildcardReExports, isClientSide, isProduction, id);
|
|
42
|
-
return
|
|
41
|
+
return rollupSourceMapRemove(code);
|
|
43
42
|
}
|
|
44
43
|
function getCode(exportNames, wildcardReExports, isClientSide, isProduction, id) {
|
|
45
44
|
let code = '';
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
export { fileEnv };
|
|
2
|
-
import { assert, assertUsage, assertWarning, capitalizeFirstLetter, joinEnglish } from '../utils.js';
|
|
2
|
+
import { assert, assertUsage, assertWarning, capitalizeFirstLetter, joinEnglish, rollupSourceMapRemove } from '../utils.js';
|
|
3
3
|
import { extractAssetsRE } from './extractAssetsPlugin.js';
|
|
4
4
|
import { extractExportNamesRE } from './extractExportNamesPlugin.js';
|
|
5
5
|
import pc from '@brillout/picocolors';
|
|
6
6
|
import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
|
|
7
|
-
import { sourceMapRemove } from '../shared/rollupSourceMap.js';
|
|
8
7
|
import { getExportNames } from '../shared/parseEsModule.js';
|
|
9
8
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
10
9
|
import { isV1Design } from './importUserCode/v1-design/getVikeConfig.js';
|
|
@@ -49,7 +48,7 @@ function fileEnv() {
|
|
|
49
48
|
const errMsg = getErrorMessage(id, isServerSide, importers, false, true);
|
|
50
49
|
// We have to inject empty exports to avoid Rollup complaining about missing exports, see https://gist.github.com/brillout/5ea45776e65bd65100a52ecd7bfda3ff
|
|
51
50
|
const { exportNames } = await getExportNames(code);
|
|
52
|
-
return
|
|
51
|
+
return rollupSourceMapRemove([
|
|
53
52
|
`throw new Error(${JSON.stringify(errMsg)});`,
|
|
54
53
|
...exportNames.map((name) => name === 'default' ? 'export default undefined;' : `export const ${name} = undefined;`)
|
|
55
54
|
].join('\n'));
|
|
@@ -67,7 +67,7 @@ async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
|
|
|
67
67
|
if (hasProp(hookReturn.pageContext, 'urlLogical')) {
|
|
68
68
|
assertUsageUrlPathnameAbsolute(
|
|
69
69
|
// We skip validation and type-cast instead of assertUsage() in order to save client-side KBs
|
|
70
|
-
hookReturn.pageContext.urlLogical, `${errPrefix} returned ${pc.cyan('{ pageContext: { urlLogical } }')}
|
|
70
|
+
hookReturn.pageContext.urlLogical, `${errPrefix} returned ${pc.cyan('{ pageContext: { urlLogical } }')} and ${pc.cyan('urlLogical')}`);
|
|
71
71
|
}
|
|
72
72
|
assertPageContextProvidedByUser(hookReturn.pageContext, {
|
|
73
73
|
hookFilePath: onBeforeRouteHook.hookFilePath,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.227-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.227-commit-e36b916";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.227-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.227-commit-e36b916';
|
|
@@ -7,12 +7,12 @@ import { assert } from './assert.js';
|
|
|
7
7
|
// We can't use a RegExp:
|
|
8
8
|
// - Needs to work with Micromatch: https://github.com/micromatch/micromatch because:
|
|
9
9
|
// - Vite's `import.meta.glob()` uses Micromatch
|
|
10
|
-
// - We need this to be a
|
|
10
|
+
// - We need this to be a allowlist because:
|
|
11
11
|
// - A pattern `*([a-zA-Z0-9]` doesn't work.
|
|
12
12
|
// - Because of ReScript: `.res` are ReScript source files which need to be ignored. (The ReScript compiler generates `.js` files alongside `.res` files.)
|
|
13
|
-
// -
|
|
14
|
-
// - We cannot implement a
|
|
15
|
-
// - A post `import.meta.glob()`
|
|
13
|
+
// - Block listing doesn't work.
|
|
14
|
+
// - We cannot implement a blocklist with a glob pattern.
|
|
15
|
+
// - A post `import.meta.glob()` blocklist filtering doesn't work because Vite would still process the files (e.g. including them in the bundle).
|
|
16
16
|
// prettier-ignore
|
|
17
17
|
// biome-ignore format:
|
|
18
18
|
const extJavaScript = [
|
|
@@ -182,14 +182,14 @@ function parseProtocol(uri) {
|
|
|
182
182
|
return { protocol, uriWithoutProtocol };
|
|
183
183
|
}
|
|
184
184
|
function isUrlProtocol(protocol) {
|
|
185
|
-
// Is there an
|
|
186
|
-
// - If the
|
|
187
|
-
const
|
|
185
|
+
// Is there an alternative to having a blocklist?
|
|
186
|
+
// - If the blocklist becomes too big, maybe use a allowlist instead ['tauri://', 'file://', 'capacitor://', 'http://', 'https://']
|
|
187
|
+
const blocklist = [
|
|
188
188
|
// https://docs.ipfs.tech/how-to/address-ipfs-on-web
|
|
189
189
|
'ipfs://',
|
|
190
190
|
'ipns://'
|
|
191
191
|
];
|
|
192
|
-
if (
|
|
192
|
+
if (blocklist.includes(protocol))
|
|
193
193
|
return false;
|
|
194
194
|
return protocol.endsWith('://');
|
|
195
195
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { rollupSourceMapRemove };
|
|
2
|
+
export { rollupSourceMapPassthrough };
|
|
3
3
|
/** Remove entire source mapping, to save KBs. */
|
|
4
|
-
declare function
|
|
4
|
+
declare function rollupSourceMapRemove(code: string): {
|
|
5
5
|
code: string;
|
|
6
6
|
map: {
|
|
7
7
|
mappings: '';
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
10
|
/** Don't provide any source map, pass through current source map instead. */
|
|
11
|
-
declare function
|
|
11
|
+
declare function rollupSourceMapPassthrough(code: string): {
|
|
12
12
|
code: string;
|
|
13
13
|
map: null;
|
|
14
14
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { rollupSourceMapRemove };
|
|
2
|
+
export { rollupSourceMapPassthrough };
|
|
3
3
|
// https://rollupjs.org/guide/en/#source-code-transformations
|
|
4
4
|
/** Remove entire source mapping, to save KBs. */
|
|
5
|
-
function
|
|
5
|
+
function rollupSourceMapRemove(code) {
|
|
6
6
|
return {
|
|
7
7
|
code,
|
|
8
8
|
map: { mappings: '' }
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
11
|
/** Don't provide any source map, pass through current source map instead. */
|
|
12
|
-
function
|
|
12
|
+
function rollupSourceMapPassthrough(code) {
|
|
13
13
|
return {
|
|
14
14
|
code,
|
|
15
15
|
map: null
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.227-commit-
|
|
3
|
+
"version": "0.4.227-commit-e36b916",
|
|
4
4
|
"repository": "https://github.com/vikejs/vike",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": {
|
|
@@ -129,6 +129,7 @@
|
|
|
129
129
|
"es-module-lexer": "^1.0.0",
|
|
130
130
|
"esbuild": "^0.19.0 || ^0.20.0 || ^0.21.0 || ^0.22.0 || ^0.23.0 || ^0.24.0",
|
|
131
131
|
"json5": "^2.0.0",
|
|
132
|
+
"magic-string": "^0.30.17",
|
|
132
133
|
"picomatch": "^4.0.2",
|
|
133
134
|
"semver": "^7.0.0",
|
|
134
135
|
"sirv": "^3.0.1",
|