vike 0.4.215 → 0.4.217-commit-99ea561
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/api/build.js +10 -3
- package/dist/cjs/node/api/context.js +8 -6
- package/dist/cjs/node/api/dev.js +7 -2
- package/dist/cjs/node/api/{prepareApiCall.js → prepareViteApiCall.js} +16 -6
- package/dist/cjs/node/api/prerender.js +7 -2
- package/dist/cjs/node/api/preview.js +7 -2
- package/dist/cjs/node/api/utils.js +1 -0
- package/dist/cjs/node/plugin/index.js +7 -10
- package/dist/cjs/node/plugin/onLoad.js +2 -2
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +15 -12
- package/dist/cjs/node/plugin/plugins/baseUrls.js +17 -12
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +1 -1
- package/dist/cjs/node/plugin/plugins/buildConfig.js +10 -10
- package/dist/cjs/node/plugin/plugins/commonConfig.js +35 -4
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -4
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +4 -7
- package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +2 -2
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +8 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +8 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +9 -13
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +23 -106
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +128 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +42 -28
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -1
- package/dist/cjs/node/plugin/plugins/previewConfig.js +4 -4
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +35 -17
- package/dist/cjs/node/prerender/runPrerender.js +5 -7
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +21 -13
- package/dist/cjs/node/runtime/index-common.js +3 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -1
- package/dist/cjs/node/runtime/renderPage.js +4 -2
- package/dist/cjs/node/runtime/utils.js +1 -2
- package/dist/cjs/node/runtime-dev/createDevMiddleware.js +25 -0
- package/dist/cjs/node/runtime-dev/index.js +32 -0
- package/dist/cjs/node/shared/resolveBase.js +41 -0
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +2 -2
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +135 -0
- package/dist/cjs/utils/isDocker.js +2 -2
- package/dist/cjs/utils/requireResolve.js +2 -2
- package/dist/esm/__internal/index.js +2 -2
- package/dist/esm/node/api/build.d.ts +5 -0
- package/dist/esm/node/api/build.js +10 -3
- package/dist/esm/node/api/context.js +9 -7
- package/dist/esm/node/api/dev.d.ts +5 -0
- package/dist/esm/node/api/dev.js +7 -2
- package/dist/esm/node/api/prepareViteApiCall.d.ts +7 -0
- package/dist/esm/node/api/{prepareApiCall.js → prepareViteApiCall.js} +16 -6
- package/dist/esm/node/api/prerender.d.ts +5 -0
- package/dist/esm/node/api/prerender.js +7 -2
- package/dist/esm/node/api/preview.d.ts +5 -0
- package/dist/esm/node/api/preview.js +7 -2
- package/dist/esm/node/api/utils.d.ts +1 -0
- package/dist/esm/node/api/utils.js +1 -0
- package/dist/esm/node/cli/parseCli.d.ts +1 -1
- package/dist/esm/node/plugin/index.d.ts +3 -3
- package/dist/esm/node/plugin/index.js +6 -9
- package/dist/esm/node/plugin/onLoad.js +1 -1
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +15 -12
- package/dist/esm/node/plugin/plugins/baseUrls.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/baseUrls.js +17 -12
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +1 -1
- package/dist/esm/node/plugin/plugins/buildConfig.js +11 -11
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +7 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +36 -5
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -5
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +4 -7
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.d.ts +3 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.js +2 -2
- package/dist/esm/node/plugin/plugins/importBuild/index.js +8 -6
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +8 -8
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +11 -15
- 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 +23 -106
- package/dist/esm/{shared/ConfigVike.d.ts → node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.d.ts} +14 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +123 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +8 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +43 -29
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -1
- package/dist/esm/node/plugin/plugins/previewConfig.js +5 -5
- package/dist/esm/node/plugin/plugins/setGlobalContext.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +37 -19
- package/dist/esm/node/plugin/shared/getEnvVarObject.d.ts +1 -1
- package/dist/esm/node/prerender/runPrerender.js +6 -8
- 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 +8 -4
- package/dist/esm/node/runtime/globalContext.js +22 -14
- package/dist/esm/node/runtime/index-common.d.ts +1 -0
- package/dist/esm/node/runtime/index-common.js +1 -0
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -1
- package/dist/esm/node/runtime/renderPage.js +5 -3
- package/dist/esm/node/runtime/utils.d.ts +1 -2
- package/dist/esm/node/runtime/utils.js +1 -2
- package/dist/esm/node/runtime-dev/createDevMiddleware.d.ts +10 -0
- package/dist/esm/node/runtime-dev/createDevMiddleware.js +23 -0
- package/dist/esm/node/runtime-dev/index.d.ts +3 -0
- package/dist/esm/node/runtime-dev/index.js +6 -0
- package/dist/esm/node/shared/resolveBase.d.ts +11 -0
- package/dist/esm/node/shared/resolveBase.js +36 -0
- package/dist/esm/shared/page-configs/Config.d.ts +2 -2
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +1 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSetup.d.ts +20 -0
- package/dist/esm/utils/assertSetup.js +130 -0
- package/dist/esm/utils/isDocker.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/requireResolve.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/node/plugin/plugins/config/assertVikeConfig.js +0 -75
- package/dist/cjs/node/plugin/plugins/config/index.js +0 -81
- package/dist/cjs/node/plugin/plugins/config/pickFirst.js +0 -6
- package/dist/cjs/node/plugin/plugins/config/resolveBase.js +0 -47
- package/dist/cjs/node/shared/getConfigVike.js +0 -10
- package/dist/cjs/shared/ConfigVike.js +0 -2
- package/dist/cjs/utils/assertIsNotProductionRuntime.js +0 -62
- package/dist/cjs/utils/assertNodeEnv.js +0 -106
- package/dist/esm/node/api/prepareApiCall.d.ts +0 -7
- package/dist/esm/node/plugin/plugins/config/assertVikeConfig.d.ts +0 -7
- package/dist/esm/node/plugin/plugins/config/assertVikeConfig.js +0 -73
- package/dist/esm/node/plugin/plugins/config/index.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/config/index.js +0 -76
- package/dist/esm/node/plugin/plugins/config/pickFirst.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/config/pickFirst.js +0 -3
- package/dist/esm/node/plugin/plugins/config/resolveBase.d.ts +0 -10
- package/dist/esm/node/plugin/plugins/config/resolveBase.js +0 -42
- package/dist/esm/node/shared/getConfigVike.d.ts +0 -4
- package/dist/esm/node/shared/getConfigVike.js +0 -8
- package/dist/esm/shared/ConfigVike.js +0 -1
- package/dist/esm/utils/assertIsNotProductionRuntime.d.ts +0 -12
- package/dist/esm/utils/assertIsNotProductionRuntime.js +0 -59
- package/dist/esm/utils/assertNodeEnv.d.ts +0 -10
- package/dist/esm/utils/assertNodeEnv.js +0 -103
|
@@ -9,37 +9,39 @@ const plugin_1 = require("@brillout/vite-plugin-server-entry/plugin");
|
|
|
9
9
|
const utils_js_1 = require("../../utils.js");
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
11
|
const module_1 = require("module");
|
|
12
|
-
const getConfigVike_js_1 = require("../../../shared/getConfigVike.js");
|
|
13
12
|
const getVikeManifest_js_1 = require("./getVikeManifest.js");
|
|
14
13
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
15
14
|
const virtualFileImportUserCode_js_1 = require("../../../shared/virtual-files/virtualFileImportUserCode.js");
|
|
15
|
+
const getVikeConfig_js_1 = require("../importUserCode/v1-design/getVikeConfig.js");
|
|
16
16
|
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
17
17
|
const importMetaUrl = `file://${__filename}`;
|
|
18
18
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
19
19
|
const ASSETS_MAP = '__VITE_ASSETS_MAP__';
|
|
20
20
|
function importBuild() {
|
|
21
21
|
let config;
|
|
22
|
-
let
|
|
22
|
+
let vikeConfigGlobal;
|
|
23
23
|
return [
|
|
24
24
|
{
|
|
25
25
|
name: 'vike:importBuild:config',
|
|
26
26
|
enforce: 'post',
|
|
27
27
|
async configResolved(config_) {
|
|
28
28
|
config = config_;
|
|
29
|
-
|
|
29
|
+
const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config);
|
|
30
|
+
vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
|
|
30
31
|
}
|
|
31
32
|
},
|
|
32
33
|
...(0, plugin_1.serverProductionEntryPlugin)({
|
|
33
34
|
getServerProductionEntry: () => {
|
|
34
|
-
return getServerProductionEntryCode(config,
|
|
35
|
+
return getServerProductionEntryCode(config, vikeConfigGlobal);
|
|
35
36
|
},
|
|
36
37
|
libraryName: 'Vike'
|
|
37
38
|
})
|
|
38
39
|
];
|
|
39
40
|
}
|
|
40
|
-
function getServerProductionEntryCode(config,
|
|
41
|
+
function getServerProductionEntryCode(config, vikeConfigGlobal) {
|
|
41
42
|
const importPath = getImportPath(config);
|
|
42
|
-
const vikeManifest = (0, getVikeManifest_js_1.getVikeManifest)(
|
|
43
|
+
const vikeManifest = (0, getVikeManifest_js_1.getVikeManifest)(vikeConfigGlobal, config);
|
|
44
|
+
// Let's eventually simplify and move everything to a single virtual module
|
|
43
45
|
const importerCode = [
|
|
44
46
|
` import { setImportBuildGetters } from '${importPath}';`,
|
|
45
47
|
` import * as pageFiles from '${virtualFileImportUserCode_js_1.virtualFileIdImportUserCodeServer}';`,
|
|
@@ -11,16 +11,16 @@ const fileTypes_js_1 = require("../../../../shared/getPageFiles/fileTypes.js");
|
|
|
11
11
|
const path_1 = __importDefault(require("path"));
|
|
12
12
|
const getVirtualFilePageConfigs_js_1 = require("./v1-design/getVirtualFilePageConfigs.js");
|
|
13
13
|
const getVikeConfig_js_1 = require("./v1-design/getVikeConfig.js");
|
|
14
|
-
async function getVirtualFileImportUserCode(id, options,
|
|
14
|
+
async function getVirtualFileImportUserCode(id, options, vikeConfigGlobal, config, isDev) {
|
|
15
15
|
const idParsed = (0, virtualFileImportUserCode_js_1.isVirtualFileIdImportUserCode)(id);
|
|
16
16
|
(0, utils_js_1.assert)(idParsed);
|
|
17
17
|
const { isForClientSide, isClientRouting } = idParsed;
|
|
18
18
|
(0, utils_js_1.assert)(isForClientSide === !(0, utils_js_1.viteIsSSR_options)(options));
|
|
19
|
-
const isPrerendering = !!
|
|
20
|
-
const code = await getCode(config,
|
|
19
|
+
const isPrerendering = !!vikeConfigGlobal.prerender;
|
|
20
|
+
const code = await getCode(config, vikeConfigGlobal, isForClientSide, isClientRouting, isPrerendering, isDev, id);
|
|
21
21
|
return code;
|
|
22
22
|
}
|
|
23
|
-
async function getCode(config,
|
|
23
|
+
async function getCode(config, vikeConfigGlobal, isForClientSide, isClientRouting, isPrerendering, isDev, id) {
|
|
24
24
|
const { command } = config;
|
|
25
25
|
(0, utils_js_1.assert)(command === 'serve' || command === 'build');
|
|
26
26
|
const isBuild = command === 'build';
|
|
@@ -29,7 +29,7 @@ async function getCode(config, configVike, isForClientSide, isClientRouting, isP
|
|
|
29
29
|
{
|
|
30
30
|
const globRoots = getGlobRoots(config);
|
|
31
31
|
(0, utils_js_1.debugGlob)('Glob roots: ', globRoots);
|
|
32
|
-
content += await generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting,
|
|
32
|
+
content += await generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfigGlobal, isPrerendering, config, isDev, id);
|
|
33
33
|
}
|
|
34
34
|
(0, utils_js_1.debugGlob)(`Glob imports for ${isForClientSide ? 'client' : 'server'}:\n`, content);
|
|
35
35
|
return content;
|
|
@@ -59,7 +59,7 @@ function determineInjection({ fileType, isForClientSide, isClientRouting, isPrer
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
async function generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting,
|
|
62
|
+
async function generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfigGlobal, isPrerendering, config, isDev, id) {
|
|
63
63
|
let fileContent = `// Generated by https://github.com/vikejs/vike/blob/main/vike/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.ts
|
|
64
64
|
|
|
65
65
|
export const pageFilesLazy = {};
|
|
@@ -73,7 +73,7 @@ ${await (0, getVirtualFilePageConfigs_js_1.getVirtualFilePageConfigs)(isForClien
|
|
|
73
73
|
|
|
74
74
|
`;
|
|
75
75
|
// We still use import.meta.glob() when using th V1 design in order to not break the V1 design deprecation warning
|
|
76
|
-
const isV1Design = await (0, getVikeConfig_js_1.isV1Design)(config
|
|
76
|
+
const isV1Design = await (0, getVikeConfig_js_1.isV1Design)(config);
|
|
77
77
|
fileTypes_js_1.fileTypes
|
|
78
78
|
.filter((fileType) => fileType !== '.css')
|
|
79
79
|
.forEach((fileType) => {
|
|
@@ -91,7 +91,7 @@ ${await (0, getVirtualFilePageConfigs_js_1.getVirtualFilePageConfigs)(isForClien
|
|
|
91
91
|
fileContent += getGlobs(globRoots, isBuild, fileType, 'extractExportNames', isV1Design);
|
|
92
92
|
}
|
|
93
93
|
});
|
|
94
|
-
if (
|
|
94
|
+
if (vikeConfigGlobal.includeAssetsImportedByServer && isForClientSide) {
|
|
95
95
|
fileContent += getGlobs(globRoots, isBuild, '.page.server', 'extractAssets', isV1Design);
|
|
96
96
|
}
|
|
97
97
|
return fileContent;
|
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.importUserCode = importUserCode;
|
|
7
7
|
const vite_1 = require("vite");
|
|
8
|
-
const getConfigVike_js_1 = require("../../../shared/getConfigVike.js");
|
|
9
8
|
const getVirtualFilePageConfigValuesAll_js_1 = require("./v1-design/getVirtualFilePageConfigValuesAll.js");
|
|
10
9
|
const getVirtualFileImportUserCode_js_1 = require("./getVirtualFileImportUserCode.js");
|
|
11
10
|
const utils_js_1 = require("../../utils.js");
|
|
@@ -18,20 +17,16 @@ const loggerNotProd_js_1 = require("../../shared/loggerNotProd.js");
|
|
|
18
17
|
const getFilePath_js_1 = require("../../shared/getFilePath.js");
|
|
19
18
|
function importUserCode() {
|
|
20
19
|
let config;
|
|
21
|
-
let
|
|
22
|
-
let isDev;
|
|
20
|
+
let vikeConfigGlobal;
|
|
23
21
|
return {
|
|
24
22
|
name: 'vike:importUserCode',
|
|
25
|
-
config(_, env) {
|
|
26
|
-
isDev = (0, utils_js_1.isDevCheck)(env);
|
|
27
|
-
},
|
|
28
23
|
async configResolved(config_) {
|
|
29
|
-
|
|
24
|
+
const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config_);
|
|
25
|
+
vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
|
|
30
26
|
config = config_;
|
|
31
27
|
// TODO/v1-release: remove
|
|
32
28
|
{
|
|
33
|
-
(0,
|
|
34
|
-
const isV1 = await (0, getVikeConfig_js_1.isV1Design)(config, isDev);
|
|
29
|
+
const isV1 = await (0, getVikeConfig_js_1.isV1Design)(config);
|
|
35
30
|
if (!isV1)
|
|
36
31
|
config.experimental.importGlobRestoreExtension = true;
|
|
37
32
|
}
|
|
@@ -55,13 +50,14 @@ function importUserCode() {
|
|
|
55
50
|
if (!(0, virtual_files_js_1.isVirtualFileId)(id))
|
|
56
51
|
return undefined;
|
|
57
52
|
id = (0, virtual_files_js_1.getVirtualFileId)(id);
|
|
53
|
+
const isDev = config._isDev;
|
|
58
54
|
(0, utils_js_1.assert)(typeof isDev === 'boolean');
|
|
59
55
|
if ((0, virtualFilePageConfigValuesAll_js_1.isVirtualFileIdPageConfigValuesAll)(id)) {
|
|
60
56
|
const code = await (0, getVirtualFilePageConfigValuesAll_js_1.getVirtualFilePageConfigValuesAll)(id, isDev, config);
|
|
61
57
|
return code;
|
|
62
58
|
}
|
|
63
59
|
if ((0, virtualFileImportUserCode_js_1.isVirtualFileIdImportUserCode)(id)) {
|
|
64
|
-
const code = await (0, getVirtualFileImportUserCode_js_1.getVirtualFileImportUserCode)(id, options,
|
|
60
|
+
const code = await (0, getVirtualFileImportUserCode_js_1.getVirtualFileImportUserCode)(id, options, vikeConfigGlobal, config, isDev);
|
|
65
61
|
return code;
|
|
66
62
|
}
|
|
67
63
|
},
|
|
@@ -88,8 +84,6 @@ function handleFileAddRemove(server, config) {
|
|
|
88
84
|
}
|
|
89
85
|
function handleHotUpdate(ctx, config) {
|
|
90
86
|
const { file, server } = ctx;
|
|
91
|
-
(0, utils_js_1.assertPosixPath)(file);
|
|
92
|
-
getVikeConfig_js_1.vikeConfigDependencies.forEach((f) => (0, utils_js_1.assertPosixPath)(f));
|
|
93
87
|
const isVikeConfig = isVikeConfigModule(file);
|
|
94
88
|
const isViteModule = ctx.modules.length > 0;
|
|
95
89
|
/* Should we show this?
|
|
@@ -119,6 +113,8 @@ function handleHotUpdate(ctx, config) {
|
|
|
119
113
|
}
|
|
120
114
|
}
|
|
121
115
|
function isVikeConfigModule(filePathAbsoluteFilesystem) {
|
|
116
|
+
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
117
|
+
getVikeConfig_js_1.vikeConfigDependencies.forEach((f) => (0, utils_js_1.assertPosixPath)(f));
|
|
122
118
|
return getVikeConfig_js_1.vikeConfigDependencies.has(filePathAbsoluteFilesystem);
|
|
123
119
|
}
|
|
124
120
|
function reloadConfig(filePath, config, op) {
|
|
@@ -127,7 +123,7 @@ function reloadConfig(filePath, config, op) {
|
|
|
127
123
|
const msg = `${op} ${picocolors_1.default.dim(filePathToShowToUserResolved)}`;
|
|
128
124
|
(0, loggerNotProd_js_1.logConfigInfo)(msg, 'info');
|
|
129
125
|
}
|
|
130
|
-
(0, getVikeConfig_js_1.reloadVikeConfig)(config
|
|
126
|
+
(0, getVikeConfig_js_1.reloadVikeConfig)(config);
|
|
131
127
|
}
|
|
132
128
|
function getVirtualModules(server) {
|
|
133
129
|
const virtualModules = Array.from(server.moduleGraph.urlToModuleMap.keys())
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -6,24 +6,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.crawlPlusFiles = crawlPlusFiles;
|
|
7
7
|
const utils_js_1 = require("../../../../utils.js");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
10
9
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
11
10
|
const child_process_1 = require("child_process");
|
|
12
11
|
const util_1 = require("util");
|
|
13
12
|
const transpileAndExecuteFile_js_1 = require("./transpileAndExecuteFile.js");
|
|
13
|
+
const getEnvVarObject_js_1 = require("../../../../shared/getEnvVarObject.js");
|
|
14
14
|
const execA = (0, util_1.promisify)(child_process_1.exec);
|
|
15
|
-
const TOO_MANY_UNTRACKED_FILES = 5;
|
|
16
15
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
17
16
|
(0, utils_js_1.assertIsSingleModuleInstance)('crawlPlusFiles.ts');
|
|
18
17
|
let gitIsNotUsable = false;
|
|
19
|
-
async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem
|
|
18
|
+
async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem) {
|
|
20
19
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
//*/
|
|
21
|
+
const outDirRelativeFromUserRootDir = null;
|
|
22
|
+
/*/
|
|
23
|
+
assertPosixPath(outDirAbsoluteFilesystem)
|
|
24
|
+
let outDirRelativeFromUserRootDir: string | null = path.posix.relative(userRootDir, outDirAbsoluteFilesystem)
|
|
23
25
|
if (outDirRelativeFromUserRootDir.startsWith('../')) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
// config.outDir is outside of config.root => it's going to be ignored anyways
|
|
27
|
+
outDirRelativeFromUserRootDir = null
|
|
26
28
|
}
|
|
29
|
+
//*/
|
|
27
30
|
(0, utils_js_1.assert)(outDirRelativeFromUserRootDir === null ||
|
|
28
31
|
/* Not true if outDirRelativeFromUserRootDir starts with a hidden directory (i.e. a directory with a name that starts with `.`)
|
|
29
32
|
!outDirRelativeFromUserRootDir.startsWith('.') &&
|
|
@@ -32,14 +35,13 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, crawlWithGi
|
|
|
32
35
|
//
|
|
33
36
|
!outDirRelativeFromUserRootDir.startsWith('../')));
|
|
34
37
|
// Crawl
|
|
35
|
-
let files
|
|
36
|
-
const res =
|
|
38
|
+
let files;
|
|
39
|
+
const res = !isGitCrawlDisabled() && (await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir));
|
|
37
40
|
if (res &&
|
|
38
41
|
// Fallback to fast-glob for users that dynamically generate plus files. (Assuming that no plus file is found because of the user's .gitignore list.)
|
|
39
|
-
res.
|
|
40
|
-
files = res
|
|
42
|
+
res.length > 0) {
|
|
43
|
+
files = res;
|
|
41
44
|
// We cannot find files inside symlink directories with `$ git ls-files` => we use fast-glob
|
|
42
|
-
files.push(...(await crawlSymlinkDirs(res.symlinkDirs, userRootDir, outDirRelativeFromUserRootDir)));
|
|
43
45
|
}
|
|
44
46
|
else {
|
|
45
47
|
files = await fastGlob(userRootDir, outDirRelativeFromUserRootDir);
|
|
@@ -81,14 +83,13 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
81
83
|
...ignoreAsPatterns.map((pattern) => `--exclude="${pattern}"`),
|
|
82
84
|
// --others --exclude-standard => list untracked files (--others) while using .gitignore (--exclude-standard)
|
|
83
85
|
// --cached => list tracked files
|
|
84
|
-
|
|
85
|
-
'--others --exclude-standard --cached --stage'
|
|
86
|
+
'--others --exclude-standard --cached'
|
|
86
87
|
].join(' ');
|
|
87
|
-
let
|
|
88
|
+
let filesAll;
|
|
88
89
|
let filesDeleted;
|
|
89
90
|
try {
|
|
90
91
|
;
|
|
91
|
-
[
|
|
92
|
+
[filesAll, filesDeleted] = await Promise.all([
|
|
92
93
|
// Main command
|
|
93
94
|
runCmd1(cmd, userRootDir),
|
|
94
95
|
// Get tracked but deleted files
|
|
@@ -102,31 +103,14 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
102
103
|
}
|
|
103
104
|
throw err;
|
|
104
105
|
}
|
|
105
|
-
const filePaths = resultLines.map(parseGitLsResultLine);
|
|
106
|
-
// If there are too many files without mode we fallback to fast-glob
|
|
107
|
-
if (filePaths.filter((f) => !f.mode).length > TOO_MANY_UNTRACKED_FILES)
|
|
108
|
-
return null;
|
|
109
|
-
const symlinkDirs = [];
|
|
110
106
|
const files = [];
|
|
111
|
-
for (const
|
|
107
|
+
for (const filePath of filesAll) {
|
|
112
108
|
// Deleted?
|
|
113
109
|
if (filesDeleted.includes(filePath))
|
|
114
110
|
continue;
|
|
115
111
|
// We have to repeat the same exclusion logic here because the option --exclude of `$ git ls-files` only applies to untracked files. (We use --exclude only to speed up the `$ git ls-files` command.)
|
|
116
112
|
if (!ignoreAsFilterFn(filePath))
|
|
117
113
|
continue;
|
|
118
|
-
// Symlink directory?
|
|
119
|
-
{
|
|
120
|
-
const isSymlinkDir = await isSymlinkDirectory(mode, filePath, userRootDir);
|
|
121
|
-
if (isSymlinkDir) {
|
|
122
|
-
symlinkDirs.push(filePath);
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
// Skip deleted files and non-symlink directories
|
|
126
|
-
if (isSymlinkDir === null) {
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
114
|
// + file?
|
|
131
115
|
if (!path_1.default.posix.basename(filePath).startsWith('+'))
|
|
132
116
|
continue;
|
|
@@ -135,7 +119,7 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
135
119
|
continue;
|
|
136
120
|
files.push(filePath);
|
|
137
121
|
}
|
|
138
|
-
return
|
|
122
|
+
return files;
|
|
139
123
|
}
|
|
140
124
|
// Same as gitLsFiles() but using fast-glob
|
|
141
125
|
async function fastGlob(userRootDir, outDirRelativeFromUserRootDir) {
|
|
@@ -205,77 +189,6 @@ async function isGitNotUsable(userRootDir) {
|
|
|
205
189
|
return false;
|
|
206
190
|
}
|
|
207
191
|
}
|
|
208
|
-
async function crawlSymlinkDirs(symlinkDirs, userRootDir, outDirRelativeFromUserRootDir) {
|
|
209
|
-
const filesInSymlinkDirs = (await Promise.all(symlinkDirs.map(async (symlinkDir) => (await fastGlob(path_1.default.posix.join(userRootDir, symlinkDir), outDirRelativeFromUserRootDir)).map((filePath) => path_1.default.posix.join(symlinkDir, filePath))))).flat();
|
|
210
|
-
return filesInSymlinkDirs;
|
|
211
|
-
}
|
|
212
|
-
// Parse:
|
|
213
|
-
// ```
|
|
214
|
-
// some/not/tracked/path
|
|
215
|
-
// 100644 f6928073402b241b468b199893ff6f4aed0b7195 0\tpages/index/+Page.tsx
|
|
216
|
-
// ```
|
|
217
|
-
function parseGitLsResultLine(resultLine) {
|
|
218
|
-
const [part1, part2, ...rest] = resultLine.split('\t');
|
|
219
|
-
(0, utils_js_1.assert)(part1);
|
|
220
|
-
(0, utils_js_1.assert)(rest.length === 0);
|
|
221
|
-
// Git doesn't provide the mode for untracked paths.
|
|
222
|
-
// `resultLine` is:
|
|
223
|
-
// ```
|
|
224
|
-
// some/not/tracked/path
|
|
225
|
-
// ```
|
|
226
|
-
if (part2 === undefined) {
|
|
227
|
-
return { filePath: part1, mode: null };
|
|
228
|
-
}
|
|
229
|
-
(0, utils_js_1.assert)(part2);
|
|
230
|
-
// `resultLine` is:
|
|
231
|
-
// ```
|
|
232
|
-
// 100644 f6928073402b241b468b199893ff6f4aed0b7195 0\tpages/index/+Page.tsx
|
|
233
|
-
// ```
|
|
234
|
-
const [mode, _, __, ...rest2] = part1.split(' ');
|
|
235
|
-
(0, utils_js_1.assert)(mode && _ && __ && rest2.length === 0);
|
|
236
|
-
return { filePath: part2, mode };
|
|
237
|
-
}
|
|
238
|
-
async function isSymlinkDirectory(mode, filePath, userRootDir) {
|
|
239
|
-
const filePathAbsolute = path_1.default.posix.join(userRootDir, filePath);
|
|
240
|
-
let stats = null;
|
|
241
|
-
let isSymlink = false;
|
|
242
|
-
if (mode === '120000') {
|
|
243
|
-
isSymlink = true;
|
|
244
|
-
}
|
|
245
|
-
else if (mode === null) {
|
|
246
|
-
// `$ git ls-files` doesn't provide the mode when Git doesn't track the path
|
|
247
|
-
stats = await getFileStats(filePathAbsolute);
|
|
248
|
-
if (stats === null)
|
|
249
|
-
return null;
|
|
250
|
-
isSymlink = stats.isSymbolicLink();
|
|
251
|
-
if (!isSymlink && stats.isDirectory())
|
|
252
|
-
return null;
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
(0, utils_js_1.assert)(mode);
|
|
256
|
-
}
|
|
257
|
-
if (!isSymlink)
|
|
258
|
-
return false;
|
|
259
|
-
if (!stats)
|
|
260
|
-
stats = await getFileStats(filePathAbsolute);
|
|
261
|
-
if (stats === null)
|
|
262
|
-
return null;
|
|
263
|
-
const isDirectory = stats.isDirectory();
|
|
264
|
-
return isDirectory;
|
|
265
|
-
}
|
|
266
|
-
async function getFileStats(filePathAbsolute) {
|
|
267
|
-
let stats;
|
|
268
|
-
try {
|
|
269
|
-
stats = await promises_1.default.lstat(filePathAbsolute);
|
|
270
|
-
}
|
|
271
|
-
catch (err) {
|
|
272
|
-
// File was deleted, usually a temporary file such as +config.js.build-j95xb988fpln.mjs
|
|
273
|
-
// ENOENT: no such file or directory
|
|
274
|
-
(0, utils_js_1.assert)(err.code === 'ENOENT');
|
|
275
|
-
return null;
|
|
276
|
-
}
|
|
277
|
-
return stats;
|
|
278
|
-
}
|
|
279
192
|
async function runCmd1(cmd, cwd) {
|
|
280
193
|
const { stdout } = await execA(cmd, {
|
|
281
194
|
cwd,
|
|
@@ -300,3 +213,7 @@ async function runCmd2(cmd, cwd) {
|
|
|
300
213
|
stderr = stderr.toString().trim();
|
|
301
214
|
return { stdout, stderr };
|
|
302
215
|
}
|
|
216
|
+
function isGitCrawlDisabled() {
|
|
217
|
+
const crawSettings = (0, getEnvVarObject_js_1.getEnvVarObject)('VIKE_CRAWL');
|
|
218
|
+
return crawSettings?.git === false;
|
|
219
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveVikeConfigGlobal = resolveVikeConfigGlobal;
|
|
7
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
8
|
+
const utils_js_1 = require("../../../../utils.js");
|
|
9
|
+
function resolveVikeConfigGlobal(vikeVitePluginOptions, pageConfigGlobalValues) {
|
|
10
|
+
// TODO/v1-release: remove
|
|
11
|
+
assertVikeConfigGlobal(vikeVitePluginOptions, ({ prop, errMsg }) => `vite.config.js > vike option ${prop} ${errMsg}`);
|
|
12
|
+
const configs = [vikeVitePluginOptions];
|
|
13
|
+
assertVikeConfigGlobal(pageConfigGlobalValues, ({ prop, errMsg }) => {
|
|
14
|
+
// Can we add the config file path ?
|
|
15
|
+
return `config ${picocolors_1.default.cyan(prop)} ${errMsg}`;
|
|
16
|
+
});
|
|
17
|
+
configs.push(pageConfigGlobalValues);
|
|
18
|
+
const vikeConfigGlobal = {
|
|
19
|
+
disableAutoFullBuild: pickFirst(configs.map((c) => c.disableAutoFullBuild)) ?? null,
|
|
20
|
+
prerender: resolvePrerenderOptions(configs),
|
|
21
|
+
includeAssetsImportedByServer: pickFirst(configs.map((c) => c.includeAssetsImportedByServer)) ?? true,
|
|
22
|
+
baseServer: pickFirst(configs.map((c) => c.baseServer)) ?? null,
|
|
23
|
+
baseAssets: pickFirst(configs.map((c) => c.baseAssets)) ?? null,
|
|
24
|
+
redirects: merge(configs.map((c) => c.redirects)) ?? {},
|
|
25
|
+
disableUrlNormalization: pickFirst(configs.map((c) => c.disableUrlNormalization)) ?? false,
|
|
26
|
+
trailingSlash: pickFirst(configs.map((c) => c.trailingSlash)) ?? false,
|
|
27
|
+
crawl: {
|
|
28
|
+
git: vikeVitePluginOptions.crawl?.git ?? null
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return vikeConfigGlobal;
|
|
32
|
+
}
|
|
33
|
+
function resolvePrerenderOptions(configs) {
|
|
34
|
+
if (!configs.some((c) => c.prerender)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const configsPrerender = configs.map((c) => c.prerender).filter(isObject2);
|
|
38
|
+
return {
|
|
39
|
+
partial: pickFirst(configsPrerender.map((c) => c.partial)) ?? false,
|
|
40
|
+
noExtraDir: pickFirst(configsPrerender.map((c) => c.noExtraDir)) ?? false,
|
|
41
|
+
parallel: pickFirst(configsPrerender.map((c) => c.parallel)) ?? true,
|
|
42
|
+
disableAutoRun: pickFirst(configsPrerender.map((c) => c.disableAutoRun)) ?? false
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function isObject2(p) {
|
|
46
|
+
return typeof p === 'object';
|
|
47
|
+
}
|
|
48
|
+
function merge(objs) {
|
|
49
|
+
const obj = {};
|
|
50
|
+
objs.forEach((e) => {
|
|
51
|
+
Object.assign(obj, e);
|
|
52
|
+
});
|
|
53
|
+
return obj;
|
|
54
|
+
}
|
|
55
|
+
function pickFirst(arr) {
|
|
56
|
+
return arr.filter((v) => v !== undefined)[0];
|
|
57
|
+
}
|
|
58
|
+
function assertVikeConfigGlobal(vikeConfigGlobal, wrongUsageMsg) {
|
|
59
|
+
const wrongUsageError = check(vikeConfigGlobal);
|
|
60
|
+
if (wrongUsageError) {
|
|
61
|
+
(0, utils_js_1.assertUsage)(false, wrongUsageMsg(wrongUsageError));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function check(vikeConfigGlobal) {
|
|
65
|
+
(0, utils_js_1.assert)((0, utils_js_1.isObject)(vikeConfigGlobal));
|
|
66
|
+
{
|
|
67
|
+
const prop = 'disableUrlNormalization';
|
|
68
|
+
if (!(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'boolean') && !(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'undefined'))
|
|
69
|
+
return { prop, errMsg: 'should be a boolean' };
|
|
70
|
+
}
|
|
71
|
+
{
|
|
72
|
+
const prop = 'trailingSlash';
|
|
73
|
+
if (!(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'boolean') && !(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'undefined'))
|
|
74
|
+
return { prop, errMsg: 'should be a boolean' };
|
|
75
|
+
}
|
|
76
|
+
{
|
|
77
|
+
const prop = 'redirects';
|
|
78
|
+
const { redirects } = vikeConfigGlobal;
|
|
79
|
+
if (!(redirects === undefined ||
|
|
80
|
+
((0, utils_js_1.isObject)(redirects) && Object.values(redirects).every((v) => typeof v === 'string'))))
|
|
81
|
+
return { prop, errMsg: 'should be an object of strings' };
|
|
82
|
+
}
|
|
83
|
+
{
|
|
84
|
+
const prop = 'disableAutoFullBuild';
|
|
85
|
+
if (!(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'boolean') &&
|
|
86
|
+
!(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'undefined') &&
|
|
87
|
+
!(vikeConfigGlobal[prop] === 'prerender'))
|
|
88
|
+
return { prop, errMsg: "should be a boolean or 'prerender'" };
|
|
89
|
+
}
|
|
90
|
+
{
|
|
91
|
+
const prop = 'includeAssetsImportedByServer';
|
|
92
|
+
if (!(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'boolean') && !(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'undefined'))
|
|
93
|
+
return { prop, errMsg: 'should be a boolean' };
|
|
94
|
+
}
|
|
95
|
+
{
|
|
96
|
+
const prop = 'prerender';
|
|
97
|
+
if (!(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'object') &&
|
|
98
|
+
!(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'boolean') &&
|
|
99
|
+
!(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'undefined'))
|
|
100
|
+
return { prop, errMsg: 'should be an object or a boolean' };
|
|
101
|
+
}
|
|
102
|
+
const configVikePrerender = vikeConfigGlobal.prerender;
|
|
103
|
+
if (typeof configVikePrerender === 'object') {
|
|
104
|
+
{
|
|
105
|
+
const p = 'partial';
|
|
106
|
+
if (!(0, utils_js_1.hasProp)(configVikePrerender, p, 'boolean') && !(0, utils_js_1.hasProp)(configVikePrerender, p, 'undefined'))
|
|
107
|
+
return { prop: `prerender.${p}`, errMsg: 'should be a boolean' };
|
|
108
|
+
}
|
|
109
|
+
{
|
|
110
|
+
const p = 'noExtraDir';
|
|
111
|
+
if (!(0, utils_js_1.hasProp)(configVikePrerender, p, 'boolean') && !(0, utils_js_1.hasProp)(configVikePrerender, p, 'undefined'))
|
|
112
|
+
return { prop: `prerender.${p}`, errMsg: 'should be a boolean' };
|
|
113
|
+
}
|
|
114
|
+
{
|
|
115
|
+
const p = 'disableAutoRun';
|
|
116
|
+
if (!(0, utils_js_1.hasProp)(configVikePrerender, p, 'boolean') && !(0, utils_js_1.hasProp)(configVikePrerender, p, 'undefined'))
|
|
117
|
+
return { prop: `prerender.${p}`, errMsg: 'should be a boolean' };
|
|
118
|
+
}
|
|
119
|
+
{
|
|
120
|
+
const p = 'parallel';
|
|
121
|
+
if (!(0, utils_js_1.hasProp)(configVikePrerender, p, 'boolean') &&
|
|
122
|
+
!(0, utils_js_1.hasProp)(configVikePrerender, p, 'number') &&
|
|
123
|
+
!(0, utils_js_1.hasProp)(configVikePrerender, p, 'undefined'))
|
|
124
|
+
return { prop: `prerender.${p}`, errMsg: 'should be a boolean or a number' };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|