vike 0.4.161 → 0.4.162-commit-8995471
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/__internal/index.js +2 -2
- package/dist/cjs/node/plugin/index.js +0 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +41 -37
- package/dist/cjs/node/plugin/plugins/config/index.js +2 -7
- package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -8
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -18
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +2 -4
- package/dist/cjs/node/plugin/plugins/envVars.js +6 -2
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +10 -22
- package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +1 -21
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +29 -95
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +8 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +1 -9
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +4 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js +35 -36
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +109 -104
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +39 -33
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +0 -14
- package/dist/cjs/node/plugin/shared/rollupSourceMap.js +20 -0
- package/dist/cjs/node/plugin/utils.js +0 -1
- package/dist/cjs/node/prerender/runPrerender.js +3 -2
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +8 -19
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +1 -0
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +2 -8
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +6 -7
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +23 -28
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -23
- package/dist/cjs/node/runtime/utils.js +1 -2
- package/dist/cjs/node/shared/assertPluginManifest.js +1 -4
- package/dist/cjs/node/shared/assertV1Design.js +26 -0
- package/dist/cjs/node/shared/{getClientEntryFilePath.js → getClientEntry.js} +3 -3
- package/dist/cjs/node/shared/prependEntriesDir.js +13 -0
- package/dist/cjs/node/shared/utils.js +2 -0
- package/dist/cjs/node/shared/virtual-files/virtualFileImportUserCode.js +1 -0
- package/dist/cjs/shared/hooks/getHook.js +1 -1
- package/dist/cjs/shared/page-configs/helpers/getConfigValue.js +1 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +1 -1
- package/dist/cjs/shared/route/abort.js +1 -0
- package/dist/cjs/shared/route/resolvePrecedence.js +1 -0
- package/dist/cjs/utils/{nodeEnv.js → assertNodeEnv.js} +3 -0
- package/dist/cjs/utils/formatHintLog.js +1 -0
- package/dist/cjs/utils/hasProp.js +1 -0
- package/dist/cjs/utils/isScriptFile.js +15 -4
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/__internal/index.js +1 -1
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +20 -14
- package/dist/esm/client/shared/getPageContextProxyForUser.js +19 -2
- package/dist/esm/client/shared/loadUserFilesClientSide.js +1 -0
- package/dist/esm/node/plugin/index.js +0 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +40 -36
- package/dist/esm/node/plugin/plugins/config/index.js +2 -7
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -8
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -19
- package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -4
- package/dist/esm/node/plugin/plugins/envVars.js +6 -2
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +11 -23
- package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.js +2 -19
- package/dist/esm/node/plugin/plugins/importBuild/index.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +31 -97
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +8 -8
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +1 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +1 -1
- 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 +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.d.ts +1 -13
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js +35 -36
- 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 +111 -106
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +39 -33
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +1 -15
- package/dist/esm/node/plugin/shared/rollupSourceMap.d.ts +14 -0
- package/dist/esm/node/plugin/shared/rollupSourceMap.js +17 -0
- package/dist/esm/node/plugin/utils.d.ts +0 -1
- package/dist/esm/node/plugin/utils.js +0 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +3 -3
- package/dist/esm/node/prerender/runPrerender.js +4 -3
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/globalContext.d.ts +3 -10
- package/dist/esm/node/runtime/globalContext.js +7 -18
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +1 -0
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +2 -8
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +6 -7
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +24 -29
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -24
- package/dist/esm/node/runtime/utils.d.ts +1 -2
- package/dist/esm/node/runtime/utils.js +1 -2
- package/dist/esm/node/shared/ViteManifest.d.ts +1 -0
- package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -1
- package/dist/esm/node/shared/assertPluginManifest.js +2 -5
- package/dist/esm/node/shared/assertV1Design.d.ts +4 -0
- package/dist/esm/node/shared/assertV1Design.js +23 -0
- package/dist/esm/node/shared/getClientEntry.d.ts +3 -0
- package/dist/esm/node/shared/{getClientEntryFilePath.js → getClientEntry.js} +2 -2
- package/dist/esm/node/shared/prependEntriesDir.d.ts +2 -0
- package/dist/esm/node/shared/prependEntriesDir.js +10 -0
- package/dist/esm/node/shared/utils.d.ts +2 -0
- package/dist/esm/node/shared/utils.js +2 -0
- package/dist/esm/node/shared/virtual-files/virtualFileImportUserCode.js +1 -0
- package/dist/esm/shared/ConfigVike.d.ts +0 -27
- package/dist/esm/shared/hooks/getHook.js +2 -2
- package/dist/esm/shared/page-configs/Config.d.ts +5 -0
- package/dist/esm/shared/page-configs/PageConfig.d.ts +2 -4
- package/dist/esm/shared/page-configs/helpers/getConfigValue.js +1 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +1 -1
- package/dist/esm/shared/route/abort.js +1 -0
- package/dist/esm/shared/route/resolvePrecedence.js +1 -0
- package/dist/esm/utils/{nodeEnv.js → assertNodeEnv.js} +3 -0
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/formatHintLog.js +1 -0
- package/dist/esm/utils/hasProp.js +1 -0
- package/dist/esm/utils/isScriptFile.d.ts +3 -1
- package/dist/esm/utils/isScriptFile.js +14 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +4 -3
- package/dist/cjs/node/plugin/plugins/config/findConfigVikeFromStemPackages.js +0 -27
- package/dist/cjs/node/plugin/plugins/config/resolveExtensions.js +0 -107
- package/dist/cjs/node/plugin/plugins/config/stemUtils.js +0 -85
- package/dist/cjs/node/plugin/plugins/extensionsAssets.js +0 -101
- package/dist/cjs/node/plugin/shared/removeSourceMap.js +0 -12
- package/dist/cjs/utils/getDependencyPackageJson.js +0 -91
- package/dist/cjs/utils/isStemPackageName.js +0 -14
- package/dist/esm/node/plugin/plugins/config/findConfigVikeFromStemPackages.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/config/findConfigVikeFromStemPackages.js +0 -24
- package/dist/esm/node/plugin/plugins/config/resolveExtensions.d.ts +0 -4
- package/dist/esm/node/plugin/plugins/config/resolveExtensions.js +0 -101
- package/dist/esm/node/plugin/plugins/config/stemUtils.d.ts +0 -8
- package/dist/esm/node/plugin/plugins/config/stemUtils.js +0 -79
- package/dist/esm/node/plugin/plugins/extensionsAssets.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/extensionsAssets.js +0 -95
- package/dist/esm/node/plugin/shared/removeSourceMap.d.ts +0 -7
- package/dist/esm/node/plugin/shared/removeSourceMap.js +0 -9
- package/dist/esm/node/shared/getClientEntryFilePath.d.ts +0 -3
- package/dist/esm/utils/getDependencyPackageJson.d.ts +0 -6
- package/dist/esm/utils/getDependencyPackageJson.js +0 -85
- package/dist/esm/utils/isStemPackageName.d.ts +0 -1
- package/dist/esm/utils/isStemPackageName.js +0 -10
- /package/dist/esm/utils/{nodeEnv.d.ts → assertNodeEnv.d.ts} +0 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export { getVirtualFileImportUserCode };
|
|
2
|
-
import { assert, assertPosixPath, viteIsSSR_options,
|
|
2
|
+
import { assert, assertPosixPath, viteIsSSR_options, scriptFileExtensions, debugGlob, getOutDirs, isVersionOrAbove, assertWarning } from '../../utils.js';
|
|
3
3
|
import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
4
|
-
import {
|
|
4
|
+
import { version as viteVersion } from 'vite';
|
|
5
|
+
import { fileTypes } from '../../../../shared/getPageFiles/fileTypes.js';
|
|
5
6
|
import path from 'path';
|
|
6
7
|
import { getVirtualFilePageConfigs } from './v1-design/getVirtualFilePageConfigs.js';
|
|
7
|
-
import {
|
|
8
|
+
import { isV1Design as isV1Design_ } from './v1-design/getVikeConfig.js';
|
|
8
9
|
async function getVirtualFileImportUserCode(id, options, configVike, config, isDev) {
|
|
9
10
|
const idParsed = isVirtualFileIdImportUserCode(id);
|
|
10
11
|
assert(idParsed);
|
|
@@ -21,53 +22,13 @@ async function getCode(config, configVike, isForClientSide, isClientRouting, isP
|
|
|
21
22
|
assert(isDev === !isBuild);
|
|
22
23
|
let content = '';
|
|
23
24
|
{
|
|
24
|
-
const globRoots = getGlobRoots(config
|
|
25
|
+
const globRoots = getGlobRoots(config);
|
|
25
26
|
debugGlob('Glob roots: ', globRoots);
|
|
26
27
|
content += await generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, configVike, isPrerendering, config, isDev, id);
|
|
27
28
|
}
|
|
28
|
-
{
|
|
29
|
-
const extensionsImportPaths = configVike.extensions
|
|
30
|
-
.map(({ pageConfigsDistFiles }) => pageConfigsDistFiles)
|
|
31
|
-
.flat()
|
|
32
|
-
.filter(isNotNullish)
|
|
33
|
-
.map(({ importPath }) => importPath);
|
|
34
|
-
content += generateExtensionImports(extensionsImportPaths, isForClientSide, isBuild, isClientRouting, isPrerendering);
|
|
35
|
-
}
|
|
36
29
|
debugGlob(`Glob imports for ${isForClientSide ? 'client' : 'server'}:\n`, content);
|
|
37
30
|
return content;
|
|
38
31
|
}
|
|
39
|
-
function generateExtensionImports(extensionsImportPaths, isForClientSide, isBuild, isClientRouting, isPrerendering) {
|
|
40
|
-
let fileContent = '\n\n';
|
|
41
|
-
extensionsImportPaths
|
|
42
|
-
.filter((importPath) => {
|
|
43
|
-
assert(
|
|
44
|
-
// V1 design
|
|
45
|
-
importPath.includes('+') ||
|
|
46
|
-
// V0.4 design
|
|
47
|
-
importPath.includes('.page.'));
|
|
48
|
-
return !importPath.includes('+');
|
|
49
|
-
})
|
|
50
|
-
.forEach((importPath) => {
|
|
51
|
-
const fileType = determineFileType(importPath);
|
|
52
|
-
const { includeImport, includeExportNames } = determineInjection({
|
|
53
|
-
fileType,
|
|
54
|
-
isForClientSide,
|
|
55
|
-
isClientRouting,
|
|
56
|
-
isPrerendering,
|
|
57
|
-
isBuild
|
|
58
|
-
});
|
|
59
|
-
if (includeImport) {
|
|
60
|
-
fileContent += addImport(importPath, fileType, false, isBuild);
|
|
61
|
-
}
|
|
62
|
-
if (includeExportNames) {
|
|
63
|
-
fileContent += addImport(importPath, fileType, true, isBuild);
|
|
64
|
-
}
|
|
65
|
-
if (!includeImport && !includeExportNames && !isForClientSide) {
|
|
66
|
-
fileContent += `pageFilesList.push("${importPath}");` + '\n';
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
return fileContent;
|
|
70
|
-
}
|
|
71
32
|
function determineInjection({ fileType, isForClientSide, isClientRouting, isPrerendering, isBuild }) {
|
|
72
33
|
if (!isForClientSide) {
|
|
73
34
|
return {
|
|
@@ -93,42 +54,6 @@ function determineInjection({ fileType, isForClientSide, isClientRouting, isPrer
|
|
|
93
54
|
}
|
|
94
55
|
}
|
|
95
56
|
}
|
|
96
|
-
function addImport(importPath, fileType, exportNames, isBuild) {
|
|
97
|
-
const pageFilesVar = (() => {
|
|
98
|
-
if (exportNames) {
|
|
99
|
-
if (isBuild) {
|
|
100
|
-
return 'pageFilesExportNamesEager';
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
return 'pageFilesExportNamesLazy';
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
if (fileType === '.page.route') {
|
|
108
|
-
return 'pageFilesEager';
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
return 'pageFilesLazy';
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
})();
|
|
115
|
-
const query = !exportNames ? '' : '?extractExportNames';
|
|
116
|
-
let fileContent = '';
|
|
117
|
-
const mapVar = `${pageFilesVar}['${fileType}']`;
|
|
118
|
-
fileContent += `${mapVar} = ${mapVar} ?? {};\n`;
|
|
119
|
-
const value = (() => {
|
|
120
|
-
if (!pageFilesVar.endsWith('Eager')) {
|
|
121
|
-
return `() => import('${importPath}${query}')`;
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
const { importName, importStatement } = generateEagerImport(`${importPath}${query}`);
|
|
125
|
-
fileContent += importStatement + '\n';
|
|
126
|
-
return importName;
|
|
127
|
-
}
|
|
128
|
-
})();
|
|
129
|
-
fileContent += `${mapVar}['${importPath}'] = ${value};\n`;
|
|
130
|
-
return fileContent;
|
|
131
|
-
}
|
|
132
57
|
async function generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, configVike, isPrerendering, config, isDev, id) {
|
|
133
58
|
let fileContent = `// Generatead by node/plugin/plugins/virtualFiles/index.ts
|
|
134
59
|
|
|
@@ -143,6 +68,8 @@ export const isGeneratedFile = true;
|
|
|
143
68
|
${await getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, config)}
|
|
144
69
|
|
|
145
70
|
`;
|
|
71
|
+
// We still use import.meta.glob() when using th V1 design in order to not break the V1 design deprecation warning
|
|
72
|
+
const isV1Design = await isV1Design_(config, isDev);
|
|
146
73
|
fileTypes
|
|
147
74
|
.filter((fileType) => fileType !== '.css')
|
|
148
75
|
.forEach((fileType) => {
|
|
@@ -155,18 +82,18 @@ ${await getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, c
|
|
|
155
82
|
isBuild
|
|
156
83
|
});
|
|
157
84
|
if (includeImport) {
|
|
158
|
-
fileContent += getGlobs(globRoots, isBuild, fileType);
|
|
85
|
+
fileContent += getGlobs(globRoots, isBuild, fileType, null, isV1Design);
|
|
159
86
|
}
|
|
160
87
|
if (includeExportNames) {
|
|
161
|
-
fileContent += getGlobs(globRoots, isBuild, fileType, 'extractExportNames');
|
|
88
|
+
fileContent += getGlobs(globRoots, isBuild, fileType, 'extractExportNames', isV1Design);
|
|
162
89
|
}
|
|
163
90
|
});
|
|
164
91
|
if (configVike.includeAssetsImportedByServer && isForClientSide) {
|
|
165
|
-
fileContent += getGlobs(globRoots, isBuild, '.page.server', 'extractAssets');
|
|
92
|
+
fileContent += getGlobs(globRoots, isBuild, '.page.server', 'extractAssets', isV1Design);
|
|
166
93
|
}
|
|
167
94
|
return fileContent;
|
|
168
95
|
}
|
|
169
|
-
function getGlobs(globRoots, isBuild, fileType, query) {
|
|
96
|
+
function getGlobs(globRoots, isBuild, fileType, query, isV1Design) {
|
|
170
97
|
const isEager = isBuild && (query === 'extractExportNames' || fileType === '.page.route');
|
|
171
98
|
let pageFilesVar;
|
|
172
99
|
if (query === 'extractExportNames') {
|
|
@@ -206,10 +133,26 @@ function getGlobs(globRoots, isBuild, fileType, query) {
|
|
|
206
133
|
varNameLocals.push(varNameLocal);
|
|
207
134
|
const globIncludePath = `'${getGlobPath(globRoot.includeDir, fileType)}'`;
|
|
208
135
|
const globExcludePath = globRoot.excludeDir ? `'!${getGlobPath(globRoot.excludeDir, fileType)}'` : null;
|
|
209
|
-
const globOptions =
|
|
210
|
-
|
|
136
|
+
const globOptions = { eager: isEager };
|
|
137
|
+
if (query) {
|
|
138
|
+
const isNewViteInterface = isVersionOrAbove(viteVersion, '5.1.0');
|
|
139
|
+
if (isNewViteInterface &&
|
|
140
|
+
// When used for the old design, the new syntax breaks Vike's CI (surprinsigly so). I couldn't reproduce locally (I didn't dig much).
|
|
141
|
+
isV1Design) {
|
|
142
|
+
globOptions.query = `?${query}`;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
globOptions.as = query;
|
|
146
|
+
const msg = [
|
|
147
|
+
"Update to the new V1 design to get rid of Vite's warning:",
|
|
148
|
+
'The glob option "as" has been deprecated in favour of "query".',
|
|
149
|
+
'See https://vike.dev/migration/v1-design for how to migrate.'
|
|
150
|
+
].join(' ');
|
|
151
|
+
assertWarning(!isNewViteInterface, msg, { onlyOnce: true });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
211
154
|
const globPaths = globExcludePath ? `[${globIncludePath}, ${globExcludePath}]` : `[${globIncludePath}]`;
|
|
212
|
-
const globLine = `const ${varNameLocal} = import.meta.glob(${globPaths}, ${globOptions});`;
|
|
155
|
+
const globLine = `const ${varNameLocal} = import.meta.glob(${globPaths}, ${JSON.stringify(globOptions)});`;
|
|
213
156
|
return globLine;
|
|
214
157
|
}),
|
|
215
158
|
`const ${varName} = {${varNameLocals.map((varNameLocal) => `...${varNameLocal}`).join(',')}};`,
|
|
@@ -217,22 +160,13 @@ function getGlobs(globRoots, isBuild, fileType, query) {
|
|
|
217
160
|
''
|
|
218
161
|
].join('\n');
|
|
219
162
|
}
|
|
220
|
-
function getGlobRoots(config
|
|
163
|
+
function getGlobRoots(config) {
|
|
221
164
|
const globRoots = [
|
|
222
165
|
{
|
|
223
166
|
includeDir: '/',
|
|
224
167
|
excludeDir: path.posix.relative(config.root, getOutDirs(config).outDirRoot)
|
|
225
168
|
}
|
|
226
169
|
];
|
|
227
|
-
configVike.extensions
|
|
228
|
-
.map(({ pageConfigsSrcDir }) => pageConfigsSrcDir)
|
|
229
|
-
.filter(isNotNullish)
|
|
230
|
-
.forEach((pageConfigsSrcDir) => {
|
|
231
|
-
const globRoot = {
|
|
232
|
-
includeDir: path.posix.relative(config.root, pageConfigsSrcDir)
|
|
233
|
-
};
|
|
234
|
-
globRoots.push(globRoot);
|
|
235
|
-
});
|
|
236
170
|
return globRoots;
|
|
237
171
|
}
|
|
238
172
|
function getGlobPath(globRootDir, fileType) {
|
|
@@ -33,7 +33,7 @@ function importUserCode() {
|
|
|
33
33
|
},
|
|
34
34
|
handleHotUpdate(ctx) {
|
|
35
35
|
try {
|
|
36
|
-
return handleHotUpdate(ctx, config
|
|
36
|
+
return handleHotUpdate(ctx, config);
|
|
37
37
|
}
|
|
38
38
|
catch (err) {
|
|
39
39
|
// Vite swallows errors thrown by handleHotUpdate()
|
|
@@ -57,11 +57,11 @@ function importUserCode() {
|
|
|
57
57
|
},
|
|
58
58
|
configureServer(server) {
|
|
59
59
|
isDev1_onConfigureServer();
|
|
60
|
-
handleFileAddRemove(server, config
|
|
60
|
+
handleFileAddRemove(server, config);
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
-
function handleFileAddRemove(server, config
|
|
64
|
+
function handleFileAddRemove(server, config) {
|
|
65
65
|
server.watcher.prependListener('add', (f) => listener(f, false));
|
|
66
66
|
server.watcher.prependListener('unlink', (f) => listener(f, true));
|
|
67
67
|
return;
|
|
@@ -73,11 +73,11 @@ function handleFileAddRemove(server, config, configVike) {
|
|
|
73
73
|
virtualModules.forEach((mod) => {
|
|
74
74
|
server.moduleGraph.invalidateModule(mod);
|
|
75
75
|
});
|
|
76
|
-
reloadConfig(file, config,
|
|
76
|
+
reloadConfig(file, config, isRemove ? 'removed' : 'created');
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
function handleHotUpdate(ctx, config
|
|
80
|
+
function handleHotUpdate(ctx, config) {
|
|
81
81
|
const { file, server } = ctx;
|
|
82
82
|
assertPosixPath(file);
|
|
83
83
|
vikeConfigDependencies.forEach((f) => assertPosixPath(f));
|
|
@@ -108,7 +108,7 @@ function handleHotUpdate(ctx, config, configVike) {
|
|
|
108
108
|
/* Tailwind breaks this assertion, see https://github.com/vikejs/vike/discussions/1330#discussioncomment-7787238
|
|
109
109
|
assert(!isViteModule)
|
|
110
110
|
*/
|
|
111
|
-
reloadConfig(file, config,
|
|
111
|
+
reloadConfig(file, config, 'modified');
|
|
112
112
|
const virtualModules = getVirtualModules(server);
|
|
113
113
|
return virtualModules;
|
|
114
114
|
}
|
|
@@ -116,13 +116,13 @@ function handleHotUpdate(ctx, config, configVike) {
|
|
|
116
116
|
function isVikeConfigModule(filePathAbsoluteFilesystem) {
|
|
117
117
|
return vikeConfigDependencies.has(filePathAbsoluteFilesystem);
|
|
118
118
|
}
|
|
119
|
-
function reloadConfig(filePath, config,
|
|
119
|
+
function reloadConfig(filePath, config, op) {
|
|
120
120
|
{
|
|
121
121
|
const filePathToShowToUser = pc.dim(getFilePathRelativeToUserRootDir(filePath, config.root, true));
|
|
122
122
|
const msg = `${op} ${filePathToShowToUser}`;
|
|
123
123
|
logConfigInfo(msg, 'info');
|
|
124
124
|
}
|
|
125
|
-
reloadVikeConfig(config.root, getOutDirs(config).outDirRoot
|
|
125
|
+
reloadVikeConfig(config.root, getOutDirs(config).outDirRoot);
|
|
126
126
|
}
|
|
127
127
|
function getVirtualModules(server) {
|
|
128
128
|
const virtualModules = Array.from(server.moduleGraph.urlToModuleMap.keys())
|
|
@@ -60,15 +60,7 @@ function getConfigValueSerialized(value, configName, definedAt) {
|
|
|
60
60
|
*/
|
|
61
61
|
const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser({ definedAt });
|
|
62
62
|
assert(configValueFilePathToShowToUser);
|
|
63
|
-
assertUsage(false,
|
|
64
|
-
`The code of ${pc.cyan(configName)} cannot live inside ${configValueFilePathToShowToUser},`,
|
|
65
|
-
'see https://vike.dev/header-file#runtime-code'
|
|
66
|
-
/* I guess showing this is more confusing than adding value.
|
|
67
|
-
`(technically speaking: the value of ${pc.cyan(
|
|
68
|
-
configName
|
|
69
|
-
)} isn't serializable (${serializationErrMsg}) and it's therefore runtime code that needs to be imported).`
|
|
70
|
-
//*/
|
|
71
|
-
].join(' '));
|
|
63
|
+
assertUsage(false, `${pc.cyan(configName)} defined by ${configValueFilePathToShowToUser} must be defined over a so-called "pointer import", see https://vike.dev/config#pointer-imports`);
|
|
72
64
|
}
|
|
73
65
|
configValueSerialized = JSON.stringify(configValueSerialized);
|
|
74
66
|
return configValueSerialized;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts
CHANGED
|
@@ -13,18 +13,18 @@ export { getLogicalPath };
|
|
|
13
13
|
* Each config value is assigned with a `locationId` value. That's the source-of-truth for determining inheritance between config values.
|
|
14
14
|
*
|
|
15
15
|
* For Vike extensions, `locationId` is different than the config value's `definedAt`, for example the `onRenderHtml()` hook of `vike-react`:
|
|
16
|
-
* - `locationId === '/pages'` (the directory of `/pages/+config.
|
|
16
|
+
* - `locationId === '/pages'` (the directory of `/pages/+config.js` which extends `vike-react`)
|
|
17
17
|
* - `definedAt.filePathAbsoluteFilesystem === '/home/rom/code/my-vike-app/node_modules/vike-react/dist/renderer/onRenderHtml.js'` (the file where the value is defined)
|
|
18
18
|
*
|
|
19
19
|
* This is an important distinction because the Vike extension's config should only apply to where it's being extended from, for example:
|
|
20
20
|
* ```js
|
|
21
|
-
* // /pages/admin/+config.
|
|
21
|
+
* // /pages/admin/+config.js
|
|
22
22
|
* import vikeVue from 'vike-vue/config'
|
|
23
23
|
* // Should only apply to /pages/admin/**
|
|
24
24
|
* export default { extends: [vikeVue] }
|
|
25
25
|
* ```
|
|
26
26
|
* ```js
|
|
27
|
-
* // /pages/marketing/+config.
|
|
27
|
+
* // /pages/marketing/+config.js
|
|
28
28
|
* import vikeReact from 'vike-react/config'
|
|
29
29
|
* // Should only apply to /pages/marketing/**
|
|
30
30
|
* export default { extends: [vikeReact] }
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js
CHANGED
|
@@ -15,7 +15,7 @@ import { assert, assertPosixPath, higherFirst } from '../../../../utils.js';
|
|
|
15
15
|
* 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/**`).
|
|
16
16
|
*/
|
|
17
17
|
function getLocationId(
|
|
18
|
-
// We always determine `locationId` from a real user-land file: the `locationId` for Vike extensions is the `locationId` of the the user's `+config.
|
|
18
|
+
// We always determine `locationId` from a real user-land file: the `locationId` for Vike extensions is the `locationId` of the the user's `+config.js` that extends the Vike extension.
|
|
19
19
|
filePathRelativeToUserRootDir) {
|
|
20
20
|
assertPosixPath(filePathRelativeToUserRootDir);
|
|
21
21
|
assert(filePathRelativeToUserRootDir.startsWith('/'));
|
|
@@ -15,7 +15,7 @@ declare function loadImportedFile(import_: FilePathResolved & {
|
|
|
15
15
|
fileExportName: string;
|
|
16
16
|
}, userRootDir: string, importedFilesLoaded: ImportedFilesLoaded): Promise<unknown>;
|
|
17
17
|
declare function loadValueFile(interfaceValueFile: InterfaceValueFile, configName: string, userRootDir: string): Promise<void>;
|
|
18
|
-
declare function loadConfigFile(configFilePath: FilePathResolved, userRootDir: string, visited: string[],
|
|
18
|
+
declare function loadConfigFile(configFilePath: FilePathResolved, userRootDir: string, visited: string[], isExtensionConfig: boolean): Promise<{
|
|
19
19
|
configFile: ConfigFile;
|
|
20
20
|
extendsConfigs: ConfigFile[];
|
|
21
21
|
}>;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -14,7 +14,7 @@ assertIsNotProductionRuntime();
|
|
|
14
14
|
async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
15
15
|
const f = import_.filePathAbsoluteFilesystem;
|
|
16
16
|
if (!importedFilesLoaded[f]) {
|
|
17
|
-
importedFilesLoaded[f] = transpileAndExecuteFile(import_,
|
|
17
|
+
importedFilesLoaded[f] = transpileAndExecuteFile(import_, userRootDir, false).then((r) => r.fileExports);
|
|
18
18
|
}
|
|
19
19
|
const fileExports = await importedFilesLoaded[f];
|
|
20
20
|
const fileExport = fileExports[import_.fileExportName];
|
|
@@ -22,7 +22,7 @@ async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
|
22
22
|
}
|
|
23
23
|
// Load +{configName}.js
|
|
24
24
|
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
25
|
-
const { fileExports } = await transpileAndExecuteFile(interfaceValueFile.filePath,
|
|
25
|
+
const { fileExports } = await transpileAndExecuteFile(interfaceValueFile.filePath, userRootDir, false);
|
|
26
26
|
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
27
27
|
assertPlusFileExport(fileExports, filePathToShowToUser, configName);
|
|
28
28
|
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
@@ -31,10 +31,10 @@ async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
// Load +config.js, including all its extends fake imports
|
|
34
|
-
async function loadConfigFile(configFilePath, userRootDir, visited,
|
|
34
|
+
async function loadConfigFile(configFilePath, userRootDir, visited, isExtensionConfig) {
|
|
35
35
|
const { filePathAbsoluteFilesystem } = configFilePath;
|
|
36
36
|
assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem);
|
|
37
|
-
const { fileExports } = await transpileAndExecuteFile(configFilePath,
|
|
37
|
+
const { fileExports } = await transpileAndExecuteFile(configFilePath, userRootDir, isExtensionConfig ? 'is-extension-config' : true);
|
|
38
38
|
const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [
|
|
39
39
|
...visited,
|
|
40
40
|
filePathAbsoluteFilesystem
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js
CHANGED
|
@@ -115,7 +115,7 @@ function assertFileEnv(filePathForEnvCheck, configEnv, configName) {
|
|
|
115
115
|
assertUsage(false, [
|
|
116
116
|
`${filePathForEnvCheck} defines the value of configs living in different environments:`,
|
|
117
117
|
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${pc.cyan(c.configName)} which value lives in environment ${pc.cyan(JSON.stringify(c.configEnv))}`),
|
|
118
|
-
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/
|
|
118
|
+
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/config#pointer-imports'
|
|
119
119
|
].join('\n'));
|
|
120
120
|
}
|
|
121
121
|
}
|
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
export { transformFileImports };
|
|
2
2
|
export { parseImportData };
|
|
3
3
|
export { isImportData };
|
|
4
|
-
export type { FileImport };
|
|
5
4
|
export type { ImportData };
|
|
6
|
-
|
|
7
|
-
importStatementCode: string;
|
|
8
|
-
importString: string;
|
|
9
|
-
importLocalName: string;
|
|
10
|
-
};
|
|
11
|
-
declare function transformFileImports(code: string, filePathToShowToUser2: string, skipWarnings?: true): {
|
|
12
|
-
noTransformation: true;
|
|
13
|
-
} | {
|
|
14
|
-
noTransformation: false;
|
|
15
|
-
code: string;
|
|
16
|
-
fileImportsTransformed: FileImport[];
|
|
17
|
-
};
|
|
5
|
+
declare function transformFileImports(code: string, filePathToShowToUser2: string, pointerImports: 'all' | Record<string, boolean>, skipWarnings?: true): string | null;
|
|
18
6
|
/**
|
|
19
7
|
* Data Structure holding info about import statement:
|
|
20
8
|
* `import { someExport as someImport } from './some-file'`
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js
CHANGED
|
@@ -2,52 +2,55 @@ export { transformFileImports };
|
|
|
2
2
|
export { parseImportData };
|
|
3
3
|
export { isImportData };
|
|
4
4
|
// Playground: https://github.com/brillout/acorn-playground
|
|
5
|
-
//
|
|
6
|
-
//
|
|
5
|
+
// Notes about `with { type: 'pointer' }`
|
|
6
|
+
// - It works well with TypeScript: it doesn't complain upon `with { type: 'unknown-to-typescript' }` and go-to-definition & types are preserved: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#import-attributes
|
|
7
|
+
// - Acorn support for import attributes: https://github.com/acornjs/acorn/issues/983
|
|
8
|
+
// - Acorn plugin: https://github.com/acornjs/acorn/issues/983
|
|
9
|
+
// - Isn't stage 4 yet: https://github.com/tc39/proposal-import-attributes
|
|
10
|
+
// - Using a import path suffix such as `import { Layout } from './Layout?real` breaks TypeScript, and TypeScript isn't working on supporting query params: https://github.com/microsoft/TypeScript/issues/10988#issuecomment-867135453
|
|
11
|
+
// - Node.js >=21 supports import attribtues: https://nodejs.org/api/esm.html#import-attributes
|
|
12
|
+
// - Esbuid supports
|
|
13
|
+
// - Blocker: https://github.com/evanw/esbuild/issues/3646
|
|
14
|
+
// - Ugly hack to make it work: https://github.com/brillout/esbuild-playground/tree/experiment/import-attribute
|
|
15
|
+
// - Discussion with esbuild maintainer: https://github.com/evanw/esbuild/issues/3384
|
|
16
|
+
// - Using a magic comment `// @vike-real-import` is probably a bad idea:
|
|
17
|
+
// - Esbuild removes comments: https://github.com/evanw/esbuild/issues/1439#issuecomment-877656182
|
|
18
|
+
// - Using source maps to track these magic comments is brittle (source maps can easily break)
|
|
7
19
|
import { parse } from 'acorn';
|
|
8
20
|
import { assert, assertUsage, assertWarning, styleFileRE } from '../../../../utils.js';
|
|
9
21
|
import pc from '@brillout/picocolors';
|
|
10
|
-
|
|
22
|
+
// TODO: rename transformFileImports() => transformPointerImports()
|
|
23
|
+
function transformFileImports(code, filePathToShowToUser2, pointerImports,
|
|
11
24
|
// For ./transformFileImports.spec.ts
|
|
12
25
|
skipWarnings) {
|
|
13
26
|
const spliceOperations = [];
|
|
14
|
-
const fileImportsTransformed = [];
|
|
15
27
|
// Performance trick
|
|
16
28
|
if (!code.includes('import'))
|
|
17
|
-
return
|
|
29
|
+
return null;
|
|
18
30
|
const imports = getImports(code);
|
|
19
31
|
if (imports.length === 0)
|
|
20
|
-
return
|
|
32
|
+
return null;
|
|
21
33
|
imports.forEach((node) => {
|
|
22
34
|
if (node.type !== 'ImportDeclaration')
|
|
23
35
|
return;
|
|
24
36
|
const importPath = node.source.value;
|
|
25
37
|
assert(typeof importPath === 'string');
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// - It works well with TypeScript: it doesn't complain upon `with { type: 'unknown-to-typescript' }` and go-to-definition & types are preserved: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#import-attributes
|
|
33
|
-
// - Esbuid seems to support it: https://esbuild.github.io/plugins/#on-load-arguments:~:text=This%20contains%20a%20map%20of%20the%20import%20attributes%20that
|
|
34
|
-
// - acorn supports it over an acorn plugin: https://github.com/acornjs/acorn/issues/983
|
|
35
|
-
// - Maybe we can use an esbuild plugin instead of acorn to apply transformFileImports()?
|
|
36
|
-
// - Using a magic comment `// @vike-real-import` is tricky:
|
|
37
|
-
// - Esbuild removes comments: https://github.com/evanw/esbuild/issues/1439#issuecomment-877656182
|
|
38
|
-
// - Using source maps to track these magic comments is brittle (source maps can easily break)
|
|
39
|
-
if (importPath.endsWith('?real')) {
|
|
40
|
-
const { start, end } = node.source;
|
|
41
|
-
spliceOperations.push({
|
|
42
|
-
start,
|
|
43
|
-
end,
|
|
44
|
-
replacement: importPath.slice(0, -1 * '?real'.length)
|
|
45
|
-
});
|
|
46
|
-
return;
|
|
38
|
+
if (pointerImports !== 'all') {
|
|
39
|
+
assert(importPath in pointerImports);
|
|
40
|
+
const isPointerImport = pointerImports[importPath];
|
|
41
|
+
assert(isPointerImport === true || isPointerImport === false);
|
|
42
|
+
if (!isPointerImport)
|
|
43
|
+
return;
|
|
47
44
|
}
|
|
48
45
|
const { start, end } = node;
|
|
49
46
|
const importStatementCode = code.slice(start, end);
|
|
50
|
-
|
|
47
|
+
/* Pointer import without importing any value => doesn't make sense and doesn't have any effect.
|
|
48
|
+
```js
|
|
49
|
+
// Useless
|
|
50
|
+
import './some.css'
|
|
51
|
+
// Useless
|
|
52
|
+
import './Layout.jsx'
|
|
53
|
+
``` */
|
|
51
54
|
if (node.specifiers.length === 0) {
|
|
52
55
|
const isWarning = !styleFileRE.test(importPath);
|
|
53
56
|
let quote = indent(importStatementCode);
|
|
@@ -58,8 +61,9 @@ skipWarnings) {
|
|
|
58
61
|
quote = pc.bold(pc.red(quote));
|
|
59
62
|
}
|
|
60
63
|
const errMsg = [
|
|
61
|
-
`
|
|
62
|
-
quote
|
|
64
|
+
`The following import in ${filePathToShowToUser2} has no effect:`,
|
|
65
|
+
quote,
|
|
66
|
+
'See https://vike.dev/config#pointer-imports'
|
|
63
67
|
].join('\n');
|
|
64
68
|
if (!skipWarnings) {
|
|
65
69
|
if (!isWarning) {
|
|
@@ -88,11 +92,6 @@ skipWarnings) {
|
|
|
88
92
|
})();
|
|
89
93
|
const importString = serializeImportData({ importPath, exportName, importStringWasGenerated: true });
|
|
90
94
|
replacement += `const ${importLocalName} = '${importString}';`;
|
|
91
|
-
fileImportsTransformed.push({
|
|
92
|
-
importStatementCode,
|
|
93
|
-
importString,
|
|
94
|
-
importLocalName
|
|
95
|
-
});
|
|
96
95
|
});
|
|
97
96
|
spliceOperations.push({
|
|
98
97
|
start,
|
|
@@ -101,7 +100,7 @@ skipWarnings) {
|
|
|
101
100
|
});
|
|
102
101
|
});
|
|
103
102
|
const codeMod = spliceMany(code, spliceOperations);
|
|
104
|
-
return
|
|
103
|
+
return codeMod;
|
|
105
104
|
}
|
|
106
105
|
function getImports(code) {
|
|
107
106
|
const { body } = parse(code, {
|
|
@@ -4,7 +4,7 @@ export { getConfigExecutionErrorIntroMsg };
|
|
|
4
4
|
export { isTmpFile };
|
|
5
5
|
import 'source-map-support/register.js';
|
|
6
6
|
import type { FilePathResolved } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
7
|
-
declare function transpileAndExecuteFile(filePath: FilePathResolved,
|
|
7
|
+
declare function transpileAndExecuteFile(filePath: FilePathResolved, userRootDir: string, isConfigFile: boolean | 'is-extension-config'): Promise<{
|
|
8
8
|
fileExports: Record<string, unknown>;
|
|
9
9
|
}>;
|
|
10
10
|
declare function getConfigBuildErrorFormatted(err: unknown): null | string;
|