vike 0.4.165 → 0.4.166-commit-6a8acaa
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/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +6 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +78 -63
- package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +14 -1
- package/dist/cjs/node/plugin/plugins/config/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +18 -23
- package/dist/cjs/node/plugin/plugins/envVars.js +3 -2
- package/dist/cjs/node/plugin/plugins/fileEnv.js +6 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +6 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +53 -24
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +10 -25
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +32 -35
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +18 -26
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +26 -21
- package/dist/cjs/node/plugin/shared/getFilePath.js +142 -0
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +3 -8
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +2 -1
- package/dist/cjs/node/plugin/utils.js +1 -1
- package/dist/cjs/node/prerender/runPrerender.js +6 -7
- package/dist/cjs/node/prerender/utils.js +2 -1
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
- package/dist/cjs/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
- package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +3 -3
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +31 -33
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +9 -8
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +6 -12
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +5 -0
- package/dist/cjs/node/runtime/renderPage.js +34 -21
- package/dist/cjs/node/runtime/utils.js +0 -1
- package/dist/cjs/shared/page-configs/FilePath.js +2 -0
- package/dist/cjs/shared/route/abort.js +2 -1
- package/dist/cjs/shared/route/executeGuardHook.js +2 -1
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +2 -1
- package/dist/cjs/shared/route/utils.js +0 -1
- package/dist/cjs/utils/assert.js +2 -0
- package/dist/cjs/utils/assertPathIsFilesystemAbsolute.js +1 -0
- package/dist/cjs/utils/assertSingleInstance.js +6 -5
- package/dist/cjs/utils/assertVersion.js +4 -1
- package/dist/cjs/utils/getGlobalObject.js +21 -6
- package/dist/cjs/utils/isNpmPackage.js +11 -5
- package/dist/cjs/utils/parseUrl.js +8 -1
- package/dist/cjs/utils/projectInfo.js +1 -4
- package/dist/esm/client/client-routing-runtime/history.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/history.js +5 -5
- package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +1 -1
- package/dist/esm/node/plugin/index.js +1 -1
- package/dist/esm/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +6 -2
- package/dist/esm/node/plugin/plugins/buildConfig.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/buildConfig.js +79 -64
- package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +14 -1
- package/dist/esm/node/plugin/plugins/config/index.js +1 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +19 -24
- package/dist/esm/node/plugin/plugins/envVars.js +4 -3
- package/dist/esm/node/plugin/plugins/fileEnv.js +7 -4
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +7 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
- 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 +54 -25
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +11 -26
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +32 -35
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +18 -26
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +26 -21
- package/dist/esm/node/plugin/shared/getFilePath.d.ts +21 -0
- package/dist/esm/node/plugin/shared/getFilePath.js +136 -0
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +4 -9
- package/dist/esm/node/plugin/shared/loggerNotProd.js +2 -1
- package/dist/esm/node/plugin/utils.d.ts +1 -1
- package/dist/esm/node/plugin/utils.js +1 -1
- package/dist/esm/node/prerender/runPrerender.js +2 -3
- package/dist/esm/node/prerender/utils.d.ts +2 -1
- package/dist/esm/node/prerender/utils.js +2 -1
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
- package/dist/esm/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +32 -34
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +9 -8
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +7 -13
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +2 -0
- package/dist/esm/node/runtime/renderPage.js +34 -21
- package/dist/esm/node/runtime/utils.d.ts +0 -1
- package/dist/esm/node/runtime/utils.js +0 -1
- package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +1 -1
- package/dist/esm/shared/page-configs/FilePath.d.ts +64 -0
- package/dist/esm/shared/page-configs/FilePath.js +1 -0
- package/dist/esm/shared/page-configs/PageConfig.d.ts +1 -42
- package/dist/esm/shared/route/abort.js +2 -1
- package/dist/esm/shared/route/executeGuardHook.js +2 -1
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +2 -1
- package/dist/esm/shared/route/utils.d.ts +0 -1
- package/dist/esm/shared/route/utils.js +0 -1
- package/dist/esm/utils/assert.js +2 -0
- package/dist/esm/utils/assertPathIsFilesystemAbsolute.js +1 -0
- package/dist/esm/utils/assertSingleInstance.d.ts +2 -2
- package/dist/esm/utils/assertSingleInstance.js +5 -4
- package/dist/esm/utils/assertVersion.js +4 -1
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/getGlobalObject.d.ts +6 -1
- package/dist/esm/utils/getGlobalObject.js +22 -6
- package/dist/esm/utils/isNpmPackage.d.ts +5 -7
- package/dist/esm/utils/isNpmPackage.js +15 -4
- package/dist/esm/utils/parseUrl.js +8 -1
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -4
- package/package.json +26 -14
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -33
- package/dist/cjs/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -19
- package/dist/cjs/utils/getFilePathAbsolute.js +0 -70
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +0 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -27
- package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.d.ts +0 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -16
- package/dist/esm/utils/getFilePathAbsolute.d.ts +0 -5
- package/dist/esm/utils/getFilePathAbsolute.js +0 -64
|
@@ -18,7 +18,7 @@ function onBrowserHistoryNavigation() {
|
|
|
18
18
|
window.addEventListener('popstate', async () => {
|
|
19
19
|
const currentState = getState();
|
|
20
20
|
const scrollTarget = currentState.historyState.scrollPosition || 'scroll-to-top-or-hash';
|
|
21
|
-
const isUserLandPushStateNavigation = currentState.historyState.
|
|
21
|
+
const isUserLandPushStateNavigation = currentState.historyState.triggeredBy === 'user';
|
|
22
22
|
const isHashNavigation = currentState.urlWithoutHash === globalObject.previousState.urlWithoutHash;
|
|
23
23
|
const isBackwardNavigation = !currentState.historyState.timestamp || !globalObject.previousState.historyState.timestamp
|
|
24
24
|
? null
|
|
@@ -8,7 +8,7 @@ function baseUrls(configVike) {
|
|
|
8
8
|
return {
|
|
9
9
|
name: 'vike:baseUrls',
|
|
10
10
|
enforce: 'post',
|
|
11
|
-
config
|
|
11
|
+
async config(config) {
|
|
12
12
|
const bases = resolveBaseFromUserConfig(config, configVike);
|
|
13
13
|
baseServer = bases.baseServer;
|
|
14
14
|
baseAssets = bases.baseAssets;
|
|
@@ -43,10 +43,14 @@ async function copyAssets(filesToCopy, config) {
|
|
|
43
43
|
return;
|
|
44
44
|
assert(existsSync(assetsDirServer));
|
|
45
45
|
const concurrencyLimit = pLimit(10);
|
|
46
|
-
await Promise.all(filesToCopy.map((file) => concurrencyLimit(() =>
|
|
46
|
+
await Promise.all(filesToCopy.map((file) => concurrencyLimit(() =>
|
|
47
|
+
// TODO: move instead of copying
|
|
48
|
+
fs.cp(path.posix.join(outDirServer, file), path.posix.join(outDirClient, file), {
|
|
47
49
|
recursive: true
|
|
48
50
|
}))));
|
|
49
|
-
|
|
51
|
+
/* We cannot do that because, with some edge case Rollup settings (outputing JavaScript chunks and static assets to the same directoy), this removes JavaScript chunks, see https://github.com/vikejs/vike/issues/1154#issuecomment-1975762404
|
|
52
|
+
await fs.rm(assetsDirServer, { recursive: true })
|
|
53
|
+
*/
|
|
50
54
|
}
|
|
51
55
|
// Add serverManifest resources to clientManifest
|
|
52
56
|
function addServerAssets(clientManifest, serverManifest) {
|
|
@@ -5,7 +5,7 @@ export { manifestTempFile };
|
|
|
5
5
|
import type { ResolvedConfig, Plugin } from 'vite';
|
|
6
6
|
import type { PageConfigBuildTime } from '../../../shared/page-configs/PageConfig.js';
|
|
7
7
|
declare const manifestTempFile = "_temp_manifest.json";
|
|
8
|
-
declare function buildConfig(): Plugin;
|
|
8
|
+
declare function buildConfig(): Plugin[];
|
|
9
9
|
declare function analyzeClientEntries(pageConfigs: PageConfigBuildTime[], config: ResolvedConfig): {
|
|
10
10
|
hasClientRouting: boolean;
|
|
11
11
|
hasServerRouting: boolean;
|
|
@@ -2,7 +2,7 @@ export { buildConfig };
|
|
|
2
2
|
export { assertRollupInput };
|
|
3
3
|
export { analyzeClientEntries };
|
|
4
4
|
export { manifestTempFile };
|
|
5
|
-
import { assert, resolveOutDir, viteIsSSR,
|
|
5
|
+
import { assert, resolveOutDir, viteIsSSR, addOnBeforeLogHook, removeFileExtention, unique, assertUsage, injectRollupInputs, normalizeRollupInput, getOutDirs, assertNodeEnv_build, assertIsNpmPackageImport } from '../utils.js';
|
|
6
6
|
import { getVikeConfig, isV1Design } from './importUserCode/v1-design/getVikeConfig.js';
|
|
7
7
|
import { getConfigValue } from '../../../shared/page-configs/helpers.js';
|
|
8
8
|
import { findPageFiles } from '../shared/findPageFiles.js';
|
|
@@ -16,6 +16,7 @@ import path from 'path';
|
|
|
16
16
|
import { fixServerAssets, fixServerAssets_isEnabled } from './buildConfig/fixServerAssets.js';
|
|
17
17
|
import { set_constant_ASSETS_MAP } from './importBuild/index.js';
|
|
18
18
|
import { prependEntriesDir } from '../../shared/prependEntriesDir.js';
|
|
19
|
+
import { getFilePathResolved } from '../shared/getFilePath.js';
|
|
19
20
|
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
20
21
|
const importMetaUrl = import.meta.url;
|
|
21
22
|
const require_ = createRequire(importMetaUrl);
|
|
@@ -25,71 +26,81 @@ function buildConfig() {
|
|
|
25
26
|
let isSsrBuild;
|
|
26
27
|
let outDirs;
|
|
27
28
|
let config;
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
29
|
+
return [
|
|
30
|
+
{
|
|
31
|
+
name: 'vike:buildConfig:configResolved',
|
|
32
|
+
apply: 'build',
|
|
33
|
+
enforce: 'post',
|
|
34
|
+
configResolved: {
|
|
35
|
+
order: 'post',
|
|
36
|
+
async handler(config_) {
|
|
37
|
+
config = config_;
|
|
38
|
+
assertNodeEnv_build();
|
|
39
|
+
assertRollupInput(config);
|
|
40
|
+
const entries = await getEntries(config);
|
|
41
|
+
assert(Object.keys(entries).length > 0);
|
|
42
|
+
config.build.rollupOptions.input = injectRollupInputs(entries, config);
|
|
43
|
+
addLogHook();
|
|
44
|
+
outDirs = getOutDirs(config);
|
|
45
|
+
{
|
|
46
|
+
isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config, false));
|
|
47
|
+
if (isServerAssetsFixEnabled) {
|
|
48
|
+
// https://github.com/vikejs/vike/issues/1339
|
|
49
|
+
config.build.ssrEmitAssets = true;
|
|
50
|
+
// Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
|
|
51
|
+
config.build.cssMinify = 'esbuild';
|
|
52
|
+
}
|
|
50
53
|
}
|
|
51
54
|
}
|
|
55
|
+
},
|
|
56
|
+
config(config) {
|
|
57
|
+
assertNodeEnv_build();
|
|
58
|
+
isSsrBuild = viteIsSSR(config);
|
|
59
|
+
return {
|
|
60
|
+
build: {
|
|
61
|
+
outDir: resolveOutDir(config),
|
|
62
|
+
manifest: manifestTempFile,
|
|
63
|
+
copyPublicDir: !isSsrBuild
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
buildStart() {
|
|
68
|
+
assertNodeEnv_build();
|
|
52
69
|
}
|
|
53
70
|
},
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
await fs.
|
|
81
|
-
|
|
82
|
-
else {
|
|
83
|
-
const clientManifestMod = await fixServerAssets(config);
|
|
84
|
-
await fs.writeFile(assetsJsonFilePath, JSON.stringify(clientManifestMod, null, 2), 'utf-8');
|
|
71
|
+
{
|
|
72
|
+
name: 'vike:buildConfig:writeBundle',
|
|
73
|
+
apply: 'build',
|
|
74
|
+
// Make sure other writeBundle() hooks are called after this writeBundle() hook.
|
|
75
|
+
// - set_constant_ASSETS_MAP() needs to be called before dist/server/ code is executed.
|
|
76
|
+
// - For example, the writeBundle() hook of vite-plugin-vercel needs to be called after this writeBundle() hook, otherwise: https://github.com/vikejs/vike/issues/1527
|
|
77
|
+
enforce: 'pre',
|
|
78
|
+
writeBundle: {
|
|
79
|
+
order: 'pre',
|
|
80
|
+
sequential: true,
|
|
81
|
+
async handler(options, bundle) {
|
|
82
|
+
if (isSsrBuild) {
|
|
83
|
+
// Ideally we'd move dist/_temp_manifest.json to dist/server/client-assets.json instead of dist/assets.json
|
|
84
|
+
// - But we can't because there is no guarentee whether dist/server/ is generated before or after dist/client/ (generating dist/server/ after dist/client/ erases dist/server/client-assets.json)
|
|
85
|
+
// - We'll able to do so once we replace `$ vite build` with `$ vike build`
|
|
86
|
+
const assetsJsonFilePath = path.posix.join(outDirs.outDirRoot, 'assets.json');
|
|
87
|
+
const clientManifestFilePath = path.posix.join(outDirs.outDirClient, manifestTempFile);
|
|
88
|
+
const serverManifestFilePath = path.posix.join(outDirs.outDirServer, manifestTempFile);
|
|
89
|
+
if (!isServerAssetsFixEnabled) {
|
|
90
|
+
await fs.copyFile(clientManifestFilePath, assetsJsonFilePath);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const clientManifestMod = await fixServerAssets(config);
|
|
94
|
+
await fs.writeFile(assetsJsonFilePath, JSON.stringify(clientManifestMod, null, 2), 'utf-8');
|
|
95
|
+
}
|
|
96
|
+
await fs.rm(clientManifestFilePath);
|
|
97
|
+
await fs.rm(serverManifestFilePath);
|
|
98
|
+
await set_constant_ASSETS_MAP(options, bundle);
|
|
85
99
|
}
|
|
86
|
-
await fs.rm(clientManifestFilePath);
|
|
87
|
-
await fs.rm(serverManifestFilePath);
|
|
88
|
-
await set_constant_ASSETS_MAP(options, bundle);
|
|
89
100
|
}
|
|
90
101
|
}
|
|
91
102
|
}
|
|
92
|
-
|
|
103
|
+
];
|
|
93
104
|
}
|
|
94
105
|
async function getEntries(config) {
|
|
95
106
|
const configVike = await getConfigVike(config);
|
|
@@ -190,18 +201,22 @@ async function getPageFileEntries(config, includeAssetsImportedByServer) {
|
|
|
190
201
|
return pageFileEntries;
|
|
191
202
|
}
|
|
192
203
|
function getEntryFromClientEntry(clientEntry, config, addExtractAssetsQuery) {
|
|
193
|
-
if (
|
|
204
|
+
if (!clientEntry.startsWith('/')) {
|
|
205
|
+
assertIsNpmPackageImport(clientEntry);
|
|
194
206
|
const entryTarget = clientEntry;
|
|
195
207
|
const entryName = prependEntriesDir(clientEntry);
|
|
196
208
|
return { entryName, entryTarget };
|
|
197
209
|
}
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
210
|
+
const filePathAbsoluteUserRootDir = clientEntry;
|
|
211
|
+
assert(filePathAbsoluteUserRootDir.startsWith('/'));
|
|
212
|
+
const filePath = getFilePathResolved({
|
|
213
|
+
filePathAbsoluteUserRootDir,
|
|
214
|
+
userRootDir: config.root
|
|
215
|
+
});
|
|
216
|
+
let entryTarget = filePath.filePathAbsoluteFilesystem;
|
|
202
217
|
if (addExtractAssetsQuery)
|
|
203
218
|
entryTarget = extractAssetsAddQuery(entryTarget);
|
|
204
|
-
let entryName =
|
|
219
|
+
let entryName = filePathAbsoluteUserRootDir;
|
|
205
220
|
if (addExtractAssetsQuery)
|
|
206
221
|
entryName = extractAssetsAddQuery(entryName);
|
|
207
222
|
entryName = removeFileExtention(entryName);
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
export { assertResolveAlias };
|
|
2
2
|
import { assert, assertUsage, assertWarning, isValidPathAlias } from '../../utils.js';
|
|
3
3
|
import pc from '@brillout/picocolors';
|
|
4
|
-
//
|
|
4
|
+
// Recommend users to avoid un-distinguishable path aliases.
|
|
5
|
+
// There are a lot of libraries that don't or cannot follow that recommendation, for example:
|
|
6
|
+
// - Nx
|
|
7
|
+
// - Not sure why, but Nx seems to add a path alias for each monorepo package
|
|
8
|
+
// - https://github.com/vikejs/vike/discussions/1134
|
|
9
|
+
// - MUI
|
|
10
|
+
// - https://mui.com/material-ui/guides/minimizing-bundle-size/#how-to-use-custom-bundles
|
|
11
|
+
// - https://github.com/vikejs/vike/discussions/1549#discussioncomment-8789002
|
|
12
|
+
// - @preact/preset-vite
|
|
13
|
+
// - Aliases react imports
|
|
14
|
+
// - @vitejs/plugin-vue2
|
|
15
|
+
// - https://github.com/vikejs/vike/issues/1329
|
|
5
16
|
function assertResolveAlias(config) {
|
|
17
|
+
// TODO: re-implement warning https://github.com/vikejs/vike/issues/1567
|
|
18
|
+
return;
|
|
6
19
|
const aliases = getAliases(config);
|
|
7
20
|
const errPrefix = config.configFile || 'Your Vite configuration';
|
|
8
21
|
const errSuffix1 = 'see https://vike.dev/path-aliases#vite';
|
|
@@ -20,7 +20,7 @@ async function getConfigVikPromise(vikeConfig, config) {
|
|
|
20
20
|
const fromPluginOptions = (vikeConfig ?? {});
|
|
21
21
|
const fromViteConfig = (config.vike ?? {});
|
|
22
22
|
const configs = [fromPluginOptions, fromViteConfig];
|
|
23
|
-
const { globalVikeConfig: fromPlusConfigFile } = await getVikeConfig(config, isDev2(config)
|
|
23
|
+
const { globalVikeConfig: fromPlusConfigFile } = await getVikeConfig(config, isDev2(config));
|
|
24
24
|
configs.push(fromPlusConfigFile);
|
|
25
25
|
assertVikeConfig(fromPlusConfigFile, ({ prop, errMsg }) => {
|
|
26
26
|
// TODO: add config file path ?
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export { determineOptimizeDeps };
|
|
2
2
|
import { findPageFiles } from '../../shared/findPageFiles.js';
|
|
3
|
-
import { assert,
|
|
3
|
+
import { assert, assertIsNpmPackageImport, createDebugger, unique } from '../../utils.js';
|
|
4
4
|
import { getVikeConfig } from '../importUserCode/v1-design/getVikeConfig.js';
|
|
5
5
|
import { getConfigValueSourcesNotOverriden } from '../../shared/getConfigValueSourcesNotOverriden.js';
|
|
6
6
|
import { analyzeClientEntries } from '../buildConfig.js';
|
|
7
7
|
import { virtualFileIdImportUserCodeClientCR, virtualFileIdImportUserCodeClientSR } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
8
|
+
import { getFilePathResolved } from '../../shared/getFilePath.js';
|
|
9
|
+
const debug = createDebugger('vike:optimizeDeps');
|
|
8
10
|
async function determineOptimizeDeps(config, isDev) {
|
|
9
11
|
const { pageConfigs } = await getVikeConfig(config, isDev);
|
|
10
12
|
const { entries, include } = await getPageDeps(config, pageConfigs, isDev);
|
|
@@ -21,7 +23,11 @@ async function determineOptimizeDeps(config, isDev) {
|
|
|
21
23
|
*/
|
|
22
24
|
config.optimizeDeps.include = [...include, ...normalizeInclude(config.optimizeDeps.include)];
|
|
23
25
|
config.optimizeDeps.entries = [...entries, ...normalizeEntries(config.optimizeDeps.entries)];
|
|
24
|
-
|
|
26
|
+
if (debug.isEnabled)
|
|
27
|
+
debug('config.optimizeDeps', {
|
|
28
|
+
'config.optimizeDeps.entries': config.optimizeDeps.entries,
|
|
29
|
+
'config.optimizeDeps.include': config.optimizeDeps.include
|
|
30
|
+
});
|
|
25
31
|
}
|
|
26
32
|
async function getPageDeps(config, pageConfigs, isDev) {
|
|
27
33
|
let entries = [];
|
|
@@ -35,7 +41,7 @@ async function getPageDeps(config, pageConfigs, isDev) {
|
|
|
35
41
|
const { definedAt, configEnv } = configValueSource;
|
|
36
42
|
if (!configEnv.client)
|
|
37
43
|
return;
|
|
38
|
-
if (definedAt.
|
|
44
|
+
if (definedAt.filePathAbsoluteUserRootDir !== null) {
|
|
39
45
|
const { filePathAbsoluteFilesystem } = definedAt;
|
|
40
46
|
assert(filePathAbsoluteFilesystem);
|
|
41
47
|
// Surprisingly Vite expects entries to be absolute paths
|
|
@@ -44,24 +50,10 @@ async function getPageDeps(config, pageConfigs, isDev) {
|
|
|
44
50
|
else {
|
|
45
51
|
// Adding definedAt.filePathAbsoluteFilesystem doesn't work for npm packages, I guess because of Vite's config.server.fs.allow
|
|
46
52
|
const { importPathAbsolute } = definedAt;
|
|
47
|
-
assert(importPathAbsolute);
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (isNpmPackageImport(importPathAbsolute)) {
|
|
52
|
-
// isNpmPackageImport() returns false for a path alias like #root/renderer/onRenderClient
|
|
53
|
-
assert(!importPathAbsolute.startsWith('#'));
|
|
54
|
-
include.push(importPathAbsolute);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
/* Path aliases, e.g.:
|
|
58
|
-
* ```js
|
|
59
|
-
* // /renderer/+config.js
|
|
60
|
-
* import onRenderClient from '#root/renderer/onRenderClient'
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
entries.push(importPathAbsolute);
|
|
64
|
-
}
|
|
53
|
+
assert(importPathAbsolute); // Help TS
|
|
54
|
+
// Shouldn't be a path alias, as path aliases would need to be added to config.optimizeDeps.entries instead of config.optimizeDeps.include
|
|
55
|
+
assertIsNpmPackageImport(importPathAbsolute);
|
|
56
|
+
include.push(importPathAbsolute);
|
|
65
57
|
}
|
|
66
58
|
});
|
|
67
59
|
});
|
|
@@ -69,9 +61,12 @@ async function getPageDeps(config, pageConfigs, isDev) {
|
|
|
69
61
|
// V0.4 design
|
|
70
62
|
{
|
|
71
63
|
const pageFiles = await findPageFiles(config, ['.page', '.page.client'], isDev);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
64
|
+
const userRootDir = config.root;
|
|
65
|
+
pageFiles.forEach((filePathAbsoluteUserRootDir) => {
|
|
66
|
+
const entry = getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir });
|
|
67
|
+
const { filePathAbsoluteFilesystem } = entry;
|
|
68
|
+
assert(filePathAbsoluteFilesystem);
|
|
69
|
+
entries.push(filePathAbsoluteFilesystem);
|
|
75
70
|
});
|
|
76
71
|
}
|
|
77
72
|
entries = unique(entries);
|
|
@@ -2,8 +2,9 @@ export { envVarsPlugin };
|
|
|
2
2
|
// For ./envVars.spec.ts
|
|
3
3
|
export { applyEnvVar };
|
|
4
4
|
import { loadEnv } from 'vite';
|
|
5
|
-
import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex,
|
|
5
|
+
import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, lowerFirst } from '../utils.js';
|
|
6
6
|
import { sourceMapPassthrough } from '../shared/rollupSourceMap.js';
|
|
7
|
+
import { getModuleFilePath } from '../shared/getFilePath.js';
|
|
7
8
|
function envVarsPlugin() {
|
|
8
9
|
let envsAll;
|
|
9
10
|
let config;
|
|
@@ -45,10 +46,10 @@ function envVarsPlugin() {
|
|
|
45
46
|
if (isPrivate && isClientSide) {
|
|
46
47
|
if (!code.includes(envStatement))
|
|
47
48
|
return;
|
|
48
|
-
const
|
|
49
|
+
const modulePath = getModuleFilePath(id, config);
|
|
49
50
|
const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
|
|
50
51
|
const keyPublic = `${publicPrefix}${envName}`;
|
|
51
|
-
const errMsg = `${envStatement} is used in client-side file ${
|
|
52
|
+
const errMsg = `${envStatement} is used in client-side file ${modulePath} which means that the environment variable ${envName} will be included in client-side bundles and, therefore, ${envName} will be publicly exposed which can be a security leak${errMsgAddendum}. Use ${envStatement} only in server-side files, or rename ${envName} to ${keyPublic}, see https://vike.dev/env`;
|
|
52
53
|
if (isBuild) {
|
|
53
54
|
assertUsage(false, errMsg);
|
|
54
55
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { fileEnv };
|
|
2
|
-
import { assert, assertUsage, assertWarning, capitalizeFirstLetter
|
|
2
|
+
import { assert, assertUsage, assertWarning, capitalizeFirstLetter } 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
|
+
import { getModuleFilePath } from '../shared/getFilePath.js';
|
|
6
7
|
function fileEnv() {
|
|
7
8
|
let config;
|
|
8
9
|
let isDev = false;
|
|
@@ -39,11 +40,13 @@ function fileEnv() {
|
|
|
39
40
|
// resolved is null when import path is erroneous and doesn't actually point to a file
|
|
40
41
|
if (!resolved)
|
|
41
42
|
return;
|
|
42
|
-
const
|
|
43
|
+
const moduleId = resolved.id;
|
|
44
|
+
const modulePath = moduleId.split('?')[0];
|
|
43
45
|
// `.server.js` and `.client.js` should only apply to user files
|
|
44
46
|
if (modulePath.includes('/node_modules/'))
|
|
45
47
|
return;
|
|
46
48
|
// TODO/v1-release: remove
|
|
49
|
+
// - I don't remember exactly, but I think I've added `TODO/v1-release: remove` because I vaguely remember that we can remove this after we remove the 0.4 design.
|
|
47
50
|
if (modulePath.endsWith('.css'))
|
|
48
51
|
return;
|
|
49
52
|
const isServerSide = options?.ssr;
|
|
@@ -55,7 +58,7 @@ function fileEnv() {
|
|
|
55
58
|
return;
|
|
56
59
|
// Show error message
|
|
57
60
|
let errMsg;
|
|
58
|
-
let modulePathPretty =
|
|
61
|
+
let modulePathPretty = getModuleFilePath(moduleId, config);
|
|
59
62
|
modulePathPretty = modulePathPretty.replaceAll(suffix, pc.bold(suffix));
|
|
60
63
|
errMsg = `${capitalizeFirstLetter(envExpect)}-only module ${modulePathPretty} (https://vike.dev/file-env) imported on the ${envActual}-side`;
|
|
61
64
|
if (importer &&
|
|
@@ -63,7 +66,7 @@ function fileEnv() {
|
|
|
63
66
|
!importer.includes('virtual:vike:') &&
|
|
64
67
|
// I don't know why and who sets importer to '<stdin>' (I guess Vite?)
|
|
65
68
|
importer !== '<stdin>') {
|
|
66
|
-
const importerPath =
|
|
69
|
+
const importerPath = getModuleFilePath(importer, config);
|
|
67
70
|
errMsg += ` by ${importerPath}`;
|
|
68
71
|
}
|
|
69
72
|
if (isDev) {
|
|
@@ -3,12 +3,13 @@ import { normalizePath } from 'vite';
|
|
|
3
3
|
import { getConfigVike } from '../../../shared/getConfigVike.js';
|
|
4
4
|
import { getVirtualFilePageConfigValuesAll } from './v1-design/getVirtualFilePageConfigValuesAll.js';
|
|
5
5
|
import { getVirtualFileImportUserCode } from './getVirtualFileImportUserCode.js';
|
|
6
|
-
import { assert, assertPosixPath,
|
|
6
|
+
import { assert, assertPosixPath, getOutDirs, getVirtualFileId, isDev1, isDev1_onConfigureServer, isVirtualFileId, resolveVirtualFileId } from '../../utils.js';
|
|
7
7
|
import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
8
8
|
import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
9
9
|
import { vikeConfigDependencies, reloadVikeConfig, isVikeConfigFile } from './v1-design/getVikeConfig.js';
|
|
10
10
|
import pc from '@brillout/picocolors';
|
|
11
11
|
import { logConfigInfo, clearLogs } from '../../shared/loggerNotProd.js';
|
|
12
|
+
import { getFilePathResolved } from '../../shared/getFilePath.js';
|
|
12
13
|
function importUserCode() {
|
|
13
14
|
let config;
|
|
14
15
|
let configVike;
|
|
@@ -118,8 +119,11 @@ function isVikeConfigModule(filePathAbsoluteFilesystem) {
|
|
|
118
119
|
}
|
|
119
120
|
function reloadConfig(filePath, config, op) {
|
|
120
121
|
{
|
|
121
|
-
const
|
|
122
|
-
|
|
122
|
+
const { filePathToShowToUserResolved } = getFilePathResolved({
|
|
123
|
+
filePathAbsoluteFilesystem: filePath,
|
|
124
|
+
userRootDir: config.root
|
|
125
|
+
});
|
|
126
|
+
const msg = `${op} ${pc.dim(filePathToShowToUserResolved)}`;
|
|
123
127
|
logConfigInfo(msg, 'info');
|
|
124
128
|
}
|
|
125
129
|
reloadVikeConfig(config.root, getOutDirs(config).outDirRoot);
|
|
@@ -58,5 +58,5 @@ type ConfigDefinitionInternal = Omit<ConfigDefinition, 'env'> & {
|
|
|
58
58
|
type ConfigDefinitions = Record<string, ConfigDefinitionInternal>;
|
|
59
59
|
type ConfigDefinitionsBuiltIn = Record<ConfigNameBuiltIn, ConfigDefinitionInternal>;
|
|
60
60
|
declare const configDefinitionsBuiltIn: ConfigDefinitionsBuiltIn;
|
|
61
|
-
type ConfigNameGlobal = 'onPrerenderStart' | 'onBeforeRoute' | 'prerender' | '
|
|
61
|
+
type ConfigNameGlobal = 'onPrerenderStart' | 'onBeforeRoute' | 'prerender' | 'disableAutoFullBuild' | 'includeAssetsImportedByServer' | 'baseAssets' | 'baseServer' | 'redirects' | 'trailingSlash' | 'disableUrlNormalization';
|
|
62
62
|
declare const configDefinitionsBuiltInGlobal: Record<ConfigNameGlobal, ConfigDefinitionInternal>;
|
|
@@ -103,7 +103,6 @@ const configDefinitionsBuiltInGlobal = {
|
|
|
103
103
|
prerender: {
|
|
104
104
|
env: { config: true }
|
|
105
105
|
},
|
|
106
|
-
extensions: { env: { config: true } },
|
|
107
106
|
disableAutoFullBuild: { env: { config: true } },
|
|
108
107
|
includeAssetsImportedByServer: { env: { config: true } },
|
|
109
108
|
baseAssets: { env: { config: true } },
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export { crawlPlusFiles };
|
|
2
|
-
import { assertPosixPath, assert, toPosixPath, assertWarning, scriptFileExtensionList, scriptFileExtensions,
|
|
2
|
+
import { assertPosixPath, assert, toPosixPath, assertWarning, scriptFileExtensionList, scriptFileExtensions, humanizeTime, assertIsSingleModuleInstance, assertIsNotProductionRuntime, isVersionOrAbove } from '../../../../utils.js';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import glob from 'fast-glob';
|
|
5
5
|
import { exec } from 'child_process';
|
|
6
6
|
import { promisify } from 'util';
|
|
7
7
|
import pc from '@brillout/picocolors';
|
|
8
8
|
const execA = promisify(exec);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
assertIsNotProductionRuntime();
|
|
10
|
+
assertIsSingleModuleInstance('crawlPlusFiles.ts');
|
|
11
|
+
let gitIsNotUsable = false;
|
|
12
12
|
async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
13
13
|
assertPosixPath(userRootDir);
|
|
14
14
|
assertPosixPath(outDirAbsoluteFilesystem);
|
|
@@ -43,14 +43,14 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
43
43
|
const plusFiles = files.map((p) => {
|
|
44
44
|
p = toPosixPath(p);
|
|
45
45
|
assert(!p.startsWith(userRootDir));
|
|
46
|
-
const
|
|
47
|
-
return {
|
|
46
|
+
const filePathAbsoluteUserRootDir = path.posix.join('/', p);
|
|
47
|
+
return { filePathAbsoluteUserRootDir };
|
|
48
48
|
});
|
|
49
49
|
return plusFiles;
|
|
50
50
|
}
|
|
51
51
|
// Same as fastGlob() but using `$ git ls-files`
|
|
52
52
|
async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
53
|
-
if (
|
|
53
|
+
if (gitIsNotUsable)
|
|
54
54
|
return null;
|
|
55
55
|
const ignoreAsPatterns = getIgnoreAsPatterns(outDirRelativeFromUserRootDir);
|
|
56
56
|
const ignoreAsFilterFn = getIgnoreAsFilterFn(outDirRelativeFromUserRootDir);
|
|
@@ -68,14 +68,14 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
68
68
|
;
|
|
69
69
|
[files, filesDeleted] = await Promise.all([
|
|
70
70
|
// Main command
|
|
71
|
-
|
|
71
|
+
runCmd1(cmd, userRootDir),
|
|
72
72
|
// Get tracked by deleted files
|
|
73
|
-
|
|
73
|
+
runCmd1('git ls-files --deleted', userRootDir)
|
|
74
74
|
]);
|
|
75
75
|
}
|
|
76
76
|
catch (err) {
|
|
77
|
-
if (await
|
|
78
|
-
|
|
77
|
+
if (await isGitNotUsable(userRootDir)) {
|
|
78
|
+
gitIsNotUsable = true;
|
|
79
79
|
return null;
|
|
80
80
|
}
|
|
81
81
|
throw err;
|
|
@@ -119,24 +119,53 @@ function getIgnoreAsFilterFn(outDirRelativeFromUserRootDir) {
|
|
|
119
119
|
!file.includes('.telefunc.') &&
|
|
120
120
|
(outDirRelativeFromUserRootDir === null || !file.startsWith(`${outDirRelativeFromUserRootDir}/`));
|
|
121
121
|
}
|
|
122
|
-
// Whether Git is installed and whether
|
|
123
|
-
async function
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
res = await
|
|
122
|
+
// Whether Git is installed and whether we can use it
|
|
123
|
+
async function isGitNotUsable(userRootDir) {
|
|
124
|
+
// Check Git version
|
|
125
|
+
{
|
|
126
|
+
const res = await runCmd2('git --version', userRootDir);
|
|
127
|
+
if ('err' in res)
|
|
128
|
+
return true;
|
|
129
|
+
let { stdout, stderr } = res;
|
|
130
|
+
assert(stderr === '');
|
|
131
|
+
const prefix = 'git version ';
|
|
132
|
+
assert(stdout.startsWith(prefix));
|
|
133
|
+
const gitVersion = stdout.slice(prefix.length);
|
|
134
|
+
// - Works with Git 2.43.1 but also (most certainly) with earlier versions.
|
|
135
|
+
// - We didn't bother test which is the earliest verision that works.
|
|
136
|
+
// - Git 2.32.0 doesn't seem to work: https://github.com/vikejs/vike/discussions/1549
|
|
137
|
+
// - Maybe it's because of StackBlitz: looking at the release notes, Git 2.32.0 should be working.
|
|
138
|
+
if (!isVersionOrAbove(gitVersion, '2.43.1'))
|
|
139
|
+
return true;
|
|
127
140
|
}
|
|
128
|
-
|
|
129
|
-
|
|
141
|
+
// Is userRootDir inside a Git repository?
|
|
142
|
+
{
|
|
143
|
+
const res = await runCmd2('git rev-parse --is-inside-work-tree', userRootDir);
|
|
144
|
+
if ('err' in res)
|
|
145
|
+
return true;
|
|
146
|
+
let { stdout, stderr } = res;
|
|
147
|
+
assert(stderr === '');
|
|
148
|
+
assert(stdout === 'true');
|
|
149
|
+
return false;
|
|
130
150
|
}
|
|
131
|
-
const { stdout, stderr } = res;
|
|
132
|
-
assert(stderr.toString().trim() === '');
|
|
133
|
-
assert(stdout.toString().trim() === 'true');
|
|
134
|
-
return false;
|
|
135
151
|
}
|
|
136
|
-
async function
|
|
137
|
-
const
|
|
152
|
+
async function runCmd1(cmd, cwd) {
|
|
153
|
+
const { stdout } = await execA(cmd, { cwd });
|
|
138
154
|
/* Not always true: https://github.com/vikejs/vike/issues/1440#issuecomment-1892831303
|
|
139
155
|
assert(res.stderr === '')
|
|
140
156
|
*/
|
|
141
|
-
return
|
|
157
|
+
return stdout.toString().split('\n').filter(Boolean);
|
|
158
|
+
}
|
|
159
|
+
async function runCmd2(cmd, cwd) {
|
|
160
|
+
let res;
|
|
161
|
+
try {
|
|
162
|
+
res = await execA(cmd, { cwd });
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
return { err };
|
|
166
|
+
}
|
|
167
|
+
let { stdout, stderr } = res;
|
|
168
|
+
stdout = stdout.toString().trim();
|
|
169
|
+
stderr = stderr.toString().trim();
|
|
170
|
+
return { stdout, stderr };
|
|
142
171
|
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ type LocationId = string & {
|
|
|
39
39
|
*
|
|
40
40
|
* The value `locationId` is always a user-land path, because Filesystem Routing/Inheritance only applies to the user-land (Vike never uses Filesystem Routing/Inheritance for `node_modules/**`).
|
|
41
41
|
*/
|
|
42
|
-
declare function getLocationId(
|
|
42
|
+
declare function getLocationId(filePathAbsoluteUserRootDir: string): LocationId;
|
|
43
43
|
/** Filesystem Routing: get the URL */
|
|
44
44
|
declare function getFilesystemRouteString(locationId: LocationId): string;
|
|
45
45
|
/**
|