vike 0.4.165 → 0.4.166
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 +68 -58
- package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +12 -0
- package/dist/cjs/node/plugin/plugins/config/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -2
- package/dist/cjs/node/plugin/plugins/envVars.js +1 -1
- package/dist/cjs/node/plugin/plugins/fileEnv.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -1
- 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 +5 -24
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +15 -22
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -20
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +21 -20
- package/dist/cjs/node/plugin/shared/getFilePath.js +88 -0
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +1 -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/getPageAssets/getManifestEntry.js +26 -24
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +5 -0
- package/dist/cjs/node/runtime/renderPage.js +34 -21
- package/dist/cjs/shared/page-configs/FilePath.js +2 -0
- package/dist/cjs/utils/assert.js +2 -0
- package/dist/cjs/utils/assertSingleInstance.js +6 -5
- package/dist/cjs/utils/assertVersion.js +4 -1
- package/dist/cjs/utils/getFilePathAbsolute.js +11 -11
- package/dist/cjs/utils/getGlobalObject.js +21 -6
- package/dist/cjs/utils/isNpmPackage.js +1 -4
- 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 +69 -59
- package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +12 -0
- package/dist/esm/node/plugin/plugins/config/index.js +1 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +3 -3
- package/dist/esm/node/plugin/plugins/envVars.js +2 -2
- package/dist/esm/node/plugin/plugins/fileEnv.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -2
- 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 +6 -25
- 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 +15 -22
- 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 +11 -20
- 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 +21 -20
- package/dist/esm/node/plugin/shared/getFilePath.d.ts +20 -0
- package/dist/esm/node/plugin/shared/getFilePath.js +82 -0
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +2 -2
- 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/getPageAssets/getManifestEntry.js +26 -24
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +2 -0
- package/dist/esm/node/runtime/renderPage.js +34 -21
- package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +1 -1
- package/dist/esm/shared/page-configs/FilePath.d.ts +52 -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/utils/assert.js +2 -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/getFilePathAbsolute.d.ts +4 -4
- package/dist/esm/utils/getFilePathAbsolute.js +10 -10
- package/dist/esm/utils/getGlobalObject.d.ts +6 -1
- package/dist/esm/utils/getGlobalObject.js +22 -6
- package/dist/esm/utils/isNpmPackage.d.ts +0 -6
- package/dist/esm/utils/isNpmPackage.js +5 -3
- 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/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
|
@@ -38,7 +38,7 @@ function plugin(vikeConfig) {
|
|
|
38
38
|
...(0, commonConfig_js_1.commonConfig)(),
|
|
39
39
|
(0, index_js_2.importUserCode)(),
|
|
40
40
|
...(0, index_js_1.devConfig)(),
|
|
41
|
-
(0, buildConfig_js_1.buildConfig)(),
|
|
41
|
+
...(0, buildConfig_js_1.buildConfig)(),
|
|
42
42
|
(0, previewConfig_js_1.previewConfig)(),
|
|
43
43
|
...(0, autoFullBuild_js_1.autoFullBuild)(),
|
|
44
44
|
(0, packageJsonFile_js_1.packageJsonFile)(),
|
|
@@ -10,7 +10,7 @@ function baseUrls(configVike) {
|
|
|
10
10
|
return {
|
|
11
11
|
name: 'vike:baseUrls',
|
|
12
12
|
enforce: 'post',
|
|
13
|
-
config
|
|
13
|
+
async config(config) {
|
|
14
14
|
const bases = (0, resolveBase_js_1.resolveBaseFromUserConfig)(config, configVike);
|
|
15
15
|
baseServer = bases.baseServer;
|
|
16
16
|
baseAssets = bases.baseAssets;
|
|
@@ -49,10 +49,14 @@ async function copyAssets(filesToCopy, config) {
|
|
|
49
49
|
return;
|
|
50
50
|
(0, utils_js_1.assert)((0, fs_1.existsSync)(assetsDirServer));
|
|
51
51
|
const concurrencyLimit = (0, utils_js_1.pLimit)(10);
|
|
52
|
-
await Promise.all(filesToCopy.map((file) => concurrencyLimit(() =>
|
|
52
|
+
await Promise.all(filesToCopy.map((file) => concurrencyLimit(() =>
|
|
53
|
+
// TODO: move instead of copying
|
|
54
|
+
promises_1.default.cp(path_1.default.posix.join(outDirServer, file), path_1.default.posix.join(outDirClient, file), {
|
|
53
55
|
recursive: true
|
|
54
56
|
}))));
|
|
55
|
-
|
|
57
|
+
/* 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
|
|
58
|
+
await fs.rm(assetsDirServer, { recursive: true })
|
|
59
|
+
*/
|
|
56
60
|
}
|
|
57
61
|
// Add serverManifest resources to clientManifest
|
|
58
62
|
function addServerAssets(clientManifest, serverManifest) {
|
|
@@ -28,71 +28,81 @@ function buildConfig() {
|
|
|
28
28
|
let isSsrBuild;
|
|
29
29
|
let outDirs;
|
|
30
30
|
let config;
|
|
31
|
-
return
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
31
|
+
return [
|
|
32
|
+
{
|
|
33
|
+
name: 'vike:buildConfig:configResolved',
|
|
34
|
+
apply: 'build',
|
|
35
|
+
enforce: 'post',
|
|
36
|
+
configResolved: {
|
|
37
|
+
order: 'post',
|
|
38
|
+
async handler(config_) {
|
|
39
|
+
config = config_;
|
|
40
|
+
(0, utils_js_1.assertNodeEnv_build)();
|
|
41
|
+
assertRollupInput(config);
|
|
42
|
+
const entries = await getEntries(config);
|
|
43
|
+
(0, utils_js_1.assert)(Object.keys(entries).length > 0);
|
|
44
|
+
config.build.rollupOptions.input = (0, utils_js_1.injectRollupInputs)(entries, config);
|
|
45
|
+
addLogHook();
|
|
46
|
+
outDirs = (0, utils_js_1.getOutDirs)(config);
|
|
47
|
+
{
|
|
48
|
+
isServerAssetsFixEnabled = (0, fixServerAssets_js_1.fixServerAssets_isEnabled)() && (await (0, getVikeConfig_js_1.isV1Design)(config, false));
|
|
49
|
+
if (isServerAssetsFixEnabled) {
|
|
50
|
+
// https://github.com/vikejs/vike/issues/1339
|
|
51
|
+
config.build.ssrEmitAssets = true;
|
|
52
|
+
// Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
|
|
53
|
+
config.build.cssMinify = 'esbuild';
|
|
54
|
+
}
|
|
53
55
|
}
|
|
54
56
|
}
|
|
57
|
+
},
|
|
58
|
+
config(config) {
|
|
59
|
+
(0, utils_js_1.assertNodeEnv_build)();
|
|
60
|
+
isSsrBuild = (0, utils_js_1.viteIsSSR)(config);
|
|
61
|
+
return {
|
|
62
|
+
build: {
|
|
63
|
+
outDir: (0, utils_js_1.resolveOutDir)(config),
|
|
64
|
+
manifest: manifestTempFile,
|
|
65
|
+
copyPublicDir: !isSsrBuild
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
buildStart() {
|
|
70
|
+
(0, utils_js_1.assertNodeEnv_build)();
|
|
55
71
|
}
|
|
56
72
|
},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
await promises_1.default.
|
|
84
|
-
|
|
85
|
-
else {
|
|
86
|
-
const clientManifestMod = await (0, fixServerAssets_js_1.fixServerAssets)(config);
|
|
87
|
-
await promises_1.default.writeFile(assetsJsonFilePath, JSON.stringify(clientManifestMod, null, 2), 'utf-8');
|
|
73
|
+
{
|
|
74
|
+
name: 'vike:buildConfig:writeBundle',
|
|
75
|
+
apply: 'build',
|
|
76
|
+
// Make sure other writeBundle() hooks are called after this writeBundle() hook.
|
|
77
|
+
// - set_constant_ASSETS_MAP() needs to be called before dist/server/ code is executed.
|
|
78
|
+
// - 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
|
|
79
|
+
enforce: 'pre',
|
|
80
|
+
writeBundle: {
|
|
81
|
+
order: 'pre',
|
|
82
|
+
sequential: true,
|
|
83
|
+
async handler(options, bundle) {
|
|
84
|
+
if (isSsrBuild) {
|
|
85
|
+
// Ideally we'd move dist/_temp_manifest.json to dist/server/client-assets.json instead of dist/assets.json
|
|
86
|
+
// - 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)
|
|
87
|
+
// - We'll able to do so once we replace `$ vite build` with `$ vike build`
|
|
88
|
+
const assetsJsonFilePath = path_1.default.posix.join(outDirs.outDirRoot, 'assets.json');
|
|
89
|
+
const clientManifestFilePath = path_1.default.posix.join(outDirs.outDirClient, manifestTempFile);
|
|
90
|
+
const serverManifestFilePath = path_1.default.posix.join(outDirs.outDirServer, manifestTempFile);
|
|
91
|
+
if (!isServerAssetsFixEnabled) {
|
|
92
|
+
await promises_1.default.copyFile(clientManifestFilePath, assetsJsonFilePath);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const clientManifestMod = await (0, fixServerAssets_js_1.fixServerAssets)(config);
|
|
96
|
+
await promises_1.default.writeFile(assetsJsonFilePath, JSON.stringify(clientManifestMod, null, 2), 'utf-8');
|
|
97
|
+
}
|
|
98
|
+
await promises_1.default.rm(clientManifestFilePath);
|
|
99
|
+
await promises_1.default.rm(serverManifestFilePath);
|
|
100
|
+
await (0, index_js_1.set_constant_ASSETS_MAP)(options, bundle);
|
|
88
101
|
}
|
|
89
|
-
await promises_1.default.rm(clientManifestFilePath);
|
|
90
|
-
await promises_1.default.rm(serverManifestFilePath);
|
|
91
|
-
await (0, index_js_1.set_constant_ASSETS_MAP)(options, bundle);
|
|
92
102
|
}
|
|
93
103
|
}
|
|
94
104
|
}
|
|
95
|
-
|
|
105
|
+
];
|
|
96
106
|
}
|
|
97
107
|
exports.buildConfig = buildConfig;
|
|
98
108
|
async function getEntries(config) {
|
|
@@ -203,7 +213,7 @@ function getEntryFromClientEntry(clientEntry, config, addExtractAssetsQuery) {
|
|
|
203
213
|
const filePath = clientEntry;
|
|
204
214
|
(0, utils_js_1.assertPosixPath)(filePath);
|
|
205
215
|
(0, utils_js_1.assert)(filePath.startsWith('/'));
|
|
206
|
-
let entryTarget = (0, utils_js_1.
|
|
216
|
+
let entryTarget = (0, utils_js_1.getFilePathAbsoluteFilesystem)(filePath, config);
|
|
207
217
|
if (addExtractAssetsQuery)
|
|
208
218
|
entryTarget = (0, extractAssetsQuery_js_1.extractAssetsAddQuery)(entryTarget);
|
|
209
219
|
let entryName = filePath;
|
|
@@ -6,6 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.assertResolveAlias = void 0;
|
|
7
7
|
const utils_js_1 = require("../../utils.js");
|
|
8
8
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
|
+
// Recommend users to avoid un-distinguishable path aliases.
|
|
10
|
+
// There are a lot of libraries that don't or cannot follow that recommendation, for example:
|
|
11
|
+
// - Nx
|
|
12
|
+
// - Not sure why, but Nx seems to add a path alias for each monorepo package
|
|
13
|
+
// - https://github.com/vikejs/vike/discussions/1134
|
|
14
|
+
// - MUI
|
|
15
|
+
// - https://mui.com/material-ui/guides/minimizing-bundle-size/#how-to-use-custom-bundles
|
|
16
|
+
// - https://github.com/vikejs/vike/discussions/1549#discussioncomment-8789002
|
|
17
|
+
// - @preact/preset-vite
|
|
18
|
+
// - Aliases react imports
|
|
19
|
+
// - @vitejs/plugin-vue2
|
|
20
|
+
// - https://github.com/vikejs/vike/issues/1329
|
|
9
21
|
// TODO/v1-release: replace assertWarning() with assertUsage()
|
|
10
22
|
function assertResolveAlias(config) {
|
|
11
23
|
const aliases = getAliases(config);
|
|
@@ -26,7 +26,7 @@ async function getConfigVikPromise(vikeConfig, config) {
|
|
|
26
26
|
const fromPluginOptions = (vikeConfig ?? {});
|
|
27
27
|
const fromViteConfig = (config.vike ?? {});
|
|
28
28
|
const configs = [fromPluginOptions, fromViteConfig];
|
|
29
|
-
const { globalVikeConfig: fromPlusConfigFile } = await (0, getVikeConfig_js_1.getVikeConfig)(config, (0, utils_js_1.isDev2)(config)
|
|
29
|
+
const { globalVikeConfig: fromPlusConfigFile } = await (0, getVikeConfig_js_1.getVikeConfig)(config, (0, utils_js_1.isDev2)(config));
|
|
30
30
|
configs.push(fromPlusConfigFile);
|
|
31
31
|
(0, assertVikeConfig_js_1.assertVikeConfig)(fromPlusConfigFile, ({ prop, errMsg }) => {
|
|
32
32
|
// TODO: add config file path ?
|
|
@@ -38,7 +38,7 @@ async function getPageDeps(config, pageConfigs, isDev) {
|
|
|
38
38
|
const { definedAt, configEnv } = configValueSource;
|
|
39
39
|
if (!configEnv.client)
|
|
40
40
|
return;
|
|
41
|
-
if (definedAt.
|
|
41
|
+
if (definedAt.filePathAbsoluteUserRootDir !== null) {
|
|
42
42
|
const { filePathAbsoluteFilesystem } = definedAt;
|
|
43
43
|
(0, utils_js_1.assert)(filePathAbsoluteFilesystem);
|
|
44
44
|
// Surprisingly Vite expects entries to be absolute paths
|
|
@@ -73,7 +73,7 @@ async function getPageDeps(config, pageConfigs, isDev) {
|
|
|
73
73
|
{
|
|
74
74
|
const pageFiles = await (0, findPageFiles_js_1.findPageFiles)(config, ['.page', '.page.client'], isDev);
|
|
75
75
|
pageFiles.forEach((filePath) => {
|
|
76
|
-
const entry = (0, utils_js_1.
|
|
76
|
+
const entry = (0, utils_js_1.getFilePathAbsoluteFilesystem)(filePath, config);
|
|
77
77
|
entries.push(entry);
|
|
78
78
|
});
|
|
79
79
|
}
|
|
@@ -45,7 +45,7 @@ function envVarsPlugin() {
|
|
|
45
45
|
if (isPrivate && isClientSide) {
|
|
46
46
|
if (!code.includes(envStatement))
|
|
47
47
|
return;
|
|
48
|
-
const filePathToShowToUser = (0, utils_js_1.
|
|
48
|
+
const filePathToShowToUser = (0, utils_js_1.getFilePathAbsoluteUserRootDir)(id, config.root);
|
|
49
49
|
const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
|
|
50
50
|
const keyPublic = `${publicPrefix}${envName}`;
|
|
51
51
|
const errMsg = `${envStatement} is used in client-side file ${filePathToShowToUser} 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`;
|
|
@@ -60,7 +60,7 @@ function fileEnv() {
|
|
|
60
60
|
return;
|
|
61
61
|
// Show error message
|
|
62
62
|
let errMsg;
|
|
63
|
-
let modulePathPretty = (0, utils_js_1.
|
|
63
|
+
let modulePathPretty = (0, utils_js_1.getFilePathAbsoluteUserRootDir)(modulePath, config.root);
|
|
64
64
|
modulePathPretty = modulePathPretty.replaceAll(suffix, picocolors_1.default.bold(suffix));
|
|
65
65
|
errMsg = `${(0, utils_js_1.capitalizeFirstLetter)(envExpect)}-only module ${modulePathPretty} (https://vike.dev/file-env) imported on the ${envActual}-side`;
|
|
66
66
|
if (importer &&
|
|
@@ -68,7 +68,7 @@ function fileEnv() {
|
|
|
68
68
|
!importer.includes('virtual:vike:') &&
|
|
69
69
|
// I don't know why and who sets importer to '<stdin>' (I guess Vite?)
|
|
70
70
|
importer !== '<stdin>') {
|
|
71
|
-
const importerPath = (0, utils_js_1.
|
|
71
|
+
const importerPath = (0, utils_js_1.getFilePathAbsoluteUserRootDir)(importer.split('?')[0], config.root);
|
|
72
72
|
errMsg += ` by ${importerPath}`;
|
|
73
73
|
}
|
|
74
74
|
if (isDev) {
|
|
@@ -124,7 +124,7 @@ function isVikeConfigModule(filePathAbsoluteFilesystem) {
|
|
|
124
124
|
}
|
|
125
125
|
function reloadConfig(filePath, config, op) {
|
|
126
126
|
{
|
|
127
|
-
const filePathToShowToUser = picocolors_1.default.dim((0, utils_js_1.
|
|
127
|
+
const filePathToShowToUser = picocolors_1.default.dim((0, utils_js_1.getFilePathAbsoluteUserRootDir)(filePath, config.root, true));
|
|
128
128
|
const msg = `${op} ${filePathToShowToUser}`;
|
|
129
129
|
(0, loggerNotProd_js_1.logConfigInfo)(msg, 'info');
|
|
130
130
|
}
|
|
@@ -105,7 +105,6 @@ const configDefinitionsBuiltInGlobal = {
|
|
|
105
105
|
prerender: {
|
|
106
106
|
env: { config: true }
|
|
107
107
|
},
|
|
108
|
-
extensions: { env: { config: true } },
|
|
109
108
|
disableAutoFullBuild: { env: { config: true } },
|
|
110
109
|
includeAssetsImportedByServer: { env: { config: true } },
|
|
111
110
|
baseAssets: { env: { config: true } },
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -11,9 +11,9 @@ const child_process_1 = require("child_process");
|
|
|
11
11
|
const util_1 = require("util");
|
|
12
12
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
13
|
const execA = (0, util_1.promisify)(child_process_1.exec);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
15
|
+
(0, utils_js_1.assertIsSingleModuleInstance)('crawlPlusFiles.ts');
|
|
16
|
+
let gitIsNotUsable = false;
|
|
17
17
|
async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
18
18
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
19
19
|
(0, utils_js_1.assertPosixPath)(outDirAbsoluteFilesystem);
|
|
@@ -48,15 +48,15 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
48
48
|
const plusFiles = files.map((p) => {
|
|
49
49
|
p = (0, utils_js_1.toPosixPath)(p);
|
|
50
50
|
(0, utils_js_1.assert)(!p.startsWith(userRootDir));
|
|
51
|
-
const
|
|
52
|
-
return {
|
|
51
|
+
const filePathAbsoluteUserRootDir = path_1.default.posix.join('/', p);
|
|
52
|
+
return { filePathAbsoluteUserRootDir };
|
|
53
53
|
});
|
|
54
54
|
return plusFiles;
|
|
55
55
|
}
|
|
56
56
|
exports.crawlPlusFiles = crawlPlusFiles;
|
|
57
57
|
// Same as fastGlob() but using `$ git ls-files`
|
|
58
58
|
async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
59
|
-
if (
|
|
59
|
+
if (gitIsNotUsable)
|
|
60
60
|
return null;
|
|
61
61
|
const ignoreAsPatterns = getIgnoreAsPatterns(outDirRelativeFromUserRootDir);
|
|
62
62
|
const ignoreAsFilterFn = getIgnoreAsFilterFn(outDirRelativeFromUserRootDir);
|
|
@@ -74,14 +74,14 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
74
74
|
;
|
|
75
75
|
[files, filesDeleted] = await Promise.all([
|
|
76
76
|
// Main command
|
|
77
|
-
|
|
77
|
+
runCmd1(cmd, userRootDir),
|
|
78
78
|
// Get tracked by deleted files
|
|
79
|
-
|
|
79
|
+
runCmd1('git ls-files --deleted', userRootDir)
|
|
80
80
|
]);
|
|
81
81
|
}
|
|
82
82
|
catch (err) {
|
|
83
|
-
if (await
|
|
84
|
-
|
|
83
|
+
if (await isGitNotUsable(userRootDir)) {
|
|
84
|
+
gitIsNotUsable = true;
|
|
85
85
|
return null;
|
|
86
86
|
}
|
|
87
87
|
throw err;
|
|
@@ -125,24 +125,53 @@ function getIgnoreAsFilterFn(outDirRelativeFromUserRootDir) {
|
|
|
125
125
|
!file.includes('.telefunc.') &&
|
|
126
126
|
(outDirRelativeFromUserRootDir === null || !file.startsWith(`${outDirRelativeFromUserRootDir}/`));
|
|
127
127
|
}
|
|
128
|
-
// Whether Git is installed and whether
|
|
129
|
-
async function
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
res = await
|
|
128
|
+
// Whether Git is installed and whether we can use it
|
|
129
|
+
async function isGitNotUsable(userRootDir) {
|
|
130
|
+
// Check Git version
|
|
131
|
+
{
|
|
132
|
+
const res = await runCmd2('git --version', userRootDir);
|
|
133
|
+
if ('err' in res)
|
|
134
|
+
return true;
|
|
135
|
+
let { stdout, stderr } = res;
|
|
136
|
+
(0, utils_js_1.assert)(stderr === '');
|
|
137
|
+
const prefix = 'git version ';
|
|
138
|
+
(0, utils_js_1.assert)(stdout.startsWith(prefix));
|
|
139
|
+
const gitVersion = stdout.slice(prefix.length);
|
|
140
|
+
// - Works with Git 2.43.1 but also (most certainly) with earlier versions.
|
|
141
|
+
// - We didn't bother test which is the earliest verision that works.
|
|
142
|
+
// - Git 2.32.0 doesn't seem to work: https://github.com/vikejs/vike/discussions/1549
|
|
143
|
+
// - Maybe it's because of StackBlitz: looking at the release notes, Git 2.32.0 should be working.
|
|
144
|
+
if (!(0, utils_js_1.isVersionOrAbove)(gitVersion, '2.43.1'))
|
|
145
|
+
return true;
|
|
133
146
|
}
|
|
134
|
-
|
|
135
|
-
|
|
147
|
+
// Is userRootDir inside a Git repository?
|
|
148
|
+
{
|
|
149
|
+
const res = await runCmd2('git rev-parse --is-inside-work-tree', userRootDir);
|
|
150
|
+
if ('err' in res)
|
|
151
|
+
return true;
|
|
152
|
+
let { stdout, stderr } = res;
|
|
153
|
+
(0, utils_js_1.assert)(stderr === '');
|
|
154
|
+
(0, utils_js_1.assert)(stdout === 'true');
|
|
155
|
+
return false;
|
|
136
156
|
}
|
|
137
|
-
const { stdout, stderr } = res;
|
|
138
|
-
(0, utils_js_1.assert)(stderr.toString().trim() === '');
|
|
139
|
-
(0, utils_js_1.assert)(stdout.toString().trim() === 'true');
|
|
140
|
-
return false;
|
|
141
157
|
}
|
|
142
|
-
async function
|
|
143
|
-
const
|
|
158
|
+
async function runCmd1(cmd, cwd) {
|
|
159
|
+
const { stdout } = await execA(cmd, { cwd });
|
|
144
160
|
/* Not always true: https://github.com/vikejs/vike/issues/1440#issuecomment-1892831303
|
|
145
161
|
assert(res.stderr === '')
|
|
146
162
|
*/
|
|
147
|
-
return
|
|
163
|
+
return stdout.toString().split('\n').filter(Boolean);
|
|
164
|
+
}
|
|
165
|
+
async function runCmd2(cmd, cwd) {
|
|
166
|
+
let res;
|
|
167
|
+
try {
|
|
168
|
+
res = await execA(cmd, { cwd });
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
return { err };
|
|
172
|
+
}
|
|
173
|
+
let { stdout, stderr } = res;
|
|
174
|
+
stdout = stdout.toString().trim();
|
|
175
|
+
stderr = stderr.toString().trim();
|
|
176
|
+
return { stdout, stderr };
|
|
148
177
|
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js
CHANGED
|
@@ -10,10 +10,10 @@ const utils_js_1 = require("../../../../utils.js");
|
|
|
10
10
|
*/
|
|
11
11
|
function getLocationId(
|
|
12
12
|
// 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.
|
|
13
|
-
|
|
14
|
-
(0, utils_js_1.assertPosixPath)(
|
|
15
|
-
(0, utils_js_1.assert)(
|
|
16
|
-
const locationId = removeFilename(
|
|
13
|
+
filePathAbsoluteUserRootDir) {
|
|
14
|
+
(0, utils_js_1.assertPosixPath)(filePathAbsoluteUserRootDir);
|
|
15
|
+
(0, utils_js_1.assert)(filePathAbsoluteUserRootDir.startsWith('/'));
|
|
16
|
+
const locationId = removeFilename(filePathAbsoluteUserRootDir);
|
|
17
17
|
assertLocationId(locationId);
|
|
18
18
|
return locationId;
|
|
19
19
|
}
|
|
@@ -96,8 +96,8 @@ function removeDirectories(somePath, removeDirs) {
|
|
|
96
96
|
somePath = '/';
|
|
97
97
|
return somePath;
|
|
98
98
|
}
|
|
99
|
-
function removeFilename(
|
|
100
|
-
const filePathParts =
|
|
99
|
+
function removeFilename(filePathAbsoluteUserRootDir) {
|
|
100
|
+
const filePathParts = filePathAbsoluteUserRootDir.split('/');
|
|
101
101
|
{
|
|
102
102
|
const filename = filePathParts.slice(-1)[0];
|
|
103
103
|
(0, utils_js_1.assert)(filename.includes('.'));
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -12,6 +12,7 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
12
12
|
const transformFileImports_js_1 = require("./transformFileImports.js");
|
|
13
13
|
const getConfigFileExport_js_1 = require("../getConfigFileExport.js");
|
|
14
14
|
const resolveImportPath_js_1 = require("./resolveImportPath.js");
|
|
15
|
+
const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
|
|
15
16
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
16
17
|
// Load fake import
|
|
17
18
|
async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
@@ -64,21 +65,12 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
64
65
|
const extendsImportData = getExtendsImportData(configFileExports, configFilePath);
|
|
65
66
|
const extendsConfigFiles = [];
|
|
66
67
|
extendsImportData.map((importData) => {
|
|
67
|
-
const { importPath:
|
|
68
|
+
const { importPath: importPathAbsolute } = importData;
|
|
68
69
|
const filePathAbsoluteFilesystem = (0, resolveImportPath_js_1.resolveImportPath)(importData, configFilePath);
|
|
69
70
|
(0, resolveImportPath_js_1.assertImportPath)(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
70
|
-
warnUserLandExtension(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir);
|
|
74
|
-
const filePathAbsoluteVite = filePathRelativeToUserRootDir ?? importPath;
|
|
75
|
-
extendsConfigFiles.push({
|
|
76
|
-
filePathAbsoluteFilesystem,
|
|
77
|
-
filePathAbsoluteVite,
|
|
78
|
-
filePathRelativeToUserRootDir,
|
|
79
|
-
filePathToShowToUser: filePathAbsoluteVite,
|
|
80
|
-
importPathAbsolute: importPath
|
|
81
|
-
});
|
|
71
|
+
warnUserLandExtension(importPathAbsolute, configFilePath);
|
|
72
|
+
const filePath = (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteFilesystem, userRootDir, importPathAbsolute });
|
|
73
|
+
extendsConfigFiles.push(filePath);
|
|
82
74
|
});
|
|
83
75
|
const extendsConfigs = [];
|
|
84
76
|
await Promise.all(extendsConfigFiles.map(async (configFilePath) => {
|
|
@@ -89,17 +81,6 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
89
81
|
const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
|
|
90
82
|
return { extendsConfigs, extendsFilePaths };
|
|
91
83
|
}
|
|
92
|
-
function determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir) {
|
|
93
|
-
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
94
|
-
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
95
|
-
if (!filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
let filePathRelativeToUserRootDir = filePathAbsoluteFilesystem.slice(userRootDir.length);
|
|
99
|
-
if (!filePathRelativeToUserRootDir.startsWith('/'))
|
|
100
|
-
filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir;
|
|
101
|
-
return filePathRelativeToUserRootDir;
|
|
102
|
-
}
|
|
103
84
|
function warnUserLandExtension(importPath, configFilePath) {
|
|
104
85
|
(0, utils_js_1.assertWarning)((0, utils_js_1.isNpmPackageImport)(importPath), `${configFilePath.filePathToShowToUser} uses ${picocolors_1.default.cyan('extends')} to inherit from ${picocolors_1.default.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this.`, { onlyOnce: true });
|
|
105
86
|
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js
CHANGED
|
@@ -8,6 +8,7 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
8
8
|
const utils_js_1 = require("../../../../utils.js");
|
|
9
9
|
const transformFileImports_js_1 = require("./transformFileImports.js");
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
|
|
11
12
|
const filesEnvMap = new Map();
|
|
12
13
|
function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
13
14
|
if (typeof configValue !== 'string')
|
|
@@ -25,14 +26,8 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
|
|
|
25
26
|
// [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
|
|
26
27
|
// ```
|
|
27
28
|
assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath);
|
|
28
|
-
const
|
|
29
|
-
const filePath = {
|
|
30
|
-
filePathAbsoluteFilesystem,
|
|
31
|
-
filePathRelativeToUserRootDir,
|
|
32
|
-
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
33
|
-
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
34
|
-
importPathAbsolute: null
|
|
35
|
-
};
|
|
29
|
+
const filePathAbsoluteUserRootDir = resolveImportPath_absoluteUserRootDir(filePathAbsoluteFilesystem, importData, importerFilePath, userRootDir);
|
|
30
|
+
const filePath = (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteUserRootDir, userRootDir, importPathAbsolute: null });
|
|
36
31
|
return {
|
|
37
32
|
...filePath,
|
|
38
33
|
fileExportName: exportName,
|
|
@@ -43,13 +38,11 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
|
|
|
43
38
|
// importPath can be:
|
|
44
39
|
// - an npm package import
|
|
45
40
|
// - a path alias
|
|
46
|
-
const filePath = {
|
|
41
|
+
const filePath = (0, getFilePath_js_1.getFilePathUnresolved)({
|
|
47
42
|
filePathAbsoluteFilesystem,
|
|
48
|
-
|
|
49
|
-
filePathAbsoluteVite: importPath,
|
|
50
|
-
filePathToShowToUser: importPath,
|
|
43
|
+
filePathAbsoluteUserRootDir: null,
|
|
51
44
|
importPathAbsolute: importPath
|
|
52
|
-
};
|
|
45
|
+
});
|
|
53
46
|
return {
|
|
54
47
|
...filePath,
|
|
55
48
|
fileExportName: exportName,
|
|
@@ -58,11 +51,11 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
|
|
|
58
51
|
}
|
|
59
52
|
}
|
|
60
53
|
exports.resolveImport = resolveImport;
|
|
61
|
-
function
|
|
54
|
+
function resolveImportPath_absoluteUserRootDir(filePathAbsoluteFilesystem, importData, configFilePath, userRootDir) {
|
|
62
55
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
63
|
-
let
|
|
56
|
+
let filePathAbsoluteUserRootDir;
|
|
64
57
|
if (filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
65
|
-
|
|
58
|
+
filePathAbsoluteUserRootDir = getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, userRootDir);
|
|
66
59
|
}
|
|
67
60
|
else {
|
|
68
61
|
(0, utils_js_1.assertUsage)(false, `${configFilePath.filePathToShowToUser} imports from a relative path ${picocolors_1.default.cyan(importData.importPath)} outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
|
|
@@ -71,14 +64,14 @@ function resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, imp
|
|
|
71
64
|
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
72
65
|
// filePath = `/@fs${filePathAbsoluteFilesystem}`
|
|
73
66
|
// /*/
|
|
74
|
-
//
|
|
75
|
-
// assert(
|
|
76
|
-
//
|
|
67
|
+
// filePathAbsoluteUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem)
|
|
68
|
+
// assert(filePathAbsoluteUserRootDir.startsWith('../'))
|
|
69
|
+
// filePathAbsoluteUserRootDir = '/' + filePathAbsoluteUserRootDir
|
|
77
70
|
// //*/
|
|
78
71
|
}
|
|
79
|
-
(0, utils_js_1.assertPosixPath)(
|
|
80
|
-
(0, utils_js_1.assert)(
|
|
81
|
-
return
|
|
72
|
+
(0, utils_js_1.assertPosixPath)(filePathAbsoluteUserRootDir);
|
|
73
|
+
(0, utils_js_1.assert)(filePathAbsoluteUserRootDir.startsWith('/'));
|
|
74
|
+
return filePathAbsoluteUserRootDir;
|
|
82
75
|
}
|
|
83
76
|
function resolveImportPath(importData, importerFilePath) {
|
|
84
77
|
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|