vike 0.4.221-commit-3310144 → 0.4.221
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/api/prepareViteApiCall.js +16 -18
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +10 -8
- package/dist/cjs/node/plugin/plugins/buildConfig.js +1 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +14 -27
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +5 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +3 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +4 -10
- package/dist/cjs/node/runtime-dev/createDevMiddleware.js +3 -3
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/debug.js +6 -9
- package/dist/esm/node/api/prepareViteApiCall.d.ts +2 -2
- package/dist/esm/node/api/prepareViteApiCall.js +16 -18
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +10 -8
- package/dist/esm/node/plugin/plugins/buildConfig.js +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +15 -28
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +1 -1
- 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 +3 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +5 -11
- package/dist/esm/node/runtime-dev/createDevMiddleware.js +3 -3
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +6 -9
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -49,18 +49,18 @@ const utils_js_1 = require("./utils.js");
|
|
|
49
49
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
50
50
|
const globalContext_js_1 = require("../runtime/globalContext.js");
|
|
51
51
|
const globalObject = (0, utils_js_1.getGlobalObject)('prepareViteApiCall.ts', {});
|
|
52
|
-
async function prepareViteApiCall(
|
|
52
|
+
async function prepareViteApiCall(viteConfig, operation) {
|
|
53
53
|
clear();
|
|
54
54
|
(0, context_js_1.setContextApiOperation)(operation);
|
|
55
|
-
return enhanceViteConfig(
|
|
55
|
+
return enhanceViteConfig(viteConfig, operation);
|
|
56
56
|
}
|
|
57
57
|
// For subsequent API calls, e.g. calling prerender() after build()
|
|
58
58
|
function clear() {
|
|
59
59
|
(0, context_js_1.clearContextApiOperation)();
|
|
60
60
|
(0, globalContext_js_1.clearGlobalContext)();
|
|
61
61
|
}
|
|
62
|
-
async function enhanceViteConfig(
|
|
63
|
-
const viteInfo = await getInfoFromVite(
|
|
62
|
+
async function enhanceViteConfig(viteConfig, operation) {
|
|
63
|
+
const viteInfo = await getInfoFromVite(viteConfig, operation);
|
|
64
64
|
await assertViteRoot2(viteInfo.root, viteInfo.viteConfigEnhanced, operation);
|
|
65
65
|
const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig2)(viteInfo.root, operation === 'dev', viteInfo.vikeVitePluginOptions);
|
|
66
66
|
const viteConfigEnhanced = addViteSettingsSetByVikeConfig(viteInfo.viteConfigEnhanced, vikeConfig);
|
|
@@ -76,7 +76,6 @@ function addViteSettingsSetByVikeConfig(viteConfigEnhanced, vikeConfig) {
|
|
|
76
76
|
viteConfigs.values.forEach((v) => {
|
|
77
77
|
(0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(v.value), `${v.definedAt} should be an object`);
|
|
78
78
|
viteConfigEnhanced = (0, vite_1.mergeConfig)(viteConfigEnhanced ?? {}, v.value);
|
|
79
|
-
(0, utils_js_1.assertUsage)(!findVikeVitePlugin(v.value), "Using the +vite setting to add Vike's Vite plugin is forbidden");
|
|
80
79
|
});
|
|
81
80
|
return viteConfigEnhanced;
|
|
82
81
|
}
|
|
@@ -86,14 +85,13 @@ async function getViteRoot(operation) {
|
|
|
86
85
|
(0, utils_js_1.assert)(globalObject.root);
|
|
87
86
|
return globalObject.root;
|
|
88
87
|
}
|
|
89
|
-
async function getInfoFromVite(
|
|
90
|
-
const
|
|
91
|
-
const root = normalizeViteRoot(
|
|
88
|
+
async function getInfoFromVite(viteConfig, operation) {
|
|
89
|
+
const viteConfigFromFile = await loadViteConfigFile(viteConfig, operation);
|
|
90
|
+
const root = normalizeViteRoot(viteConfigFromFile?.root ?? viteConfig?.root ?? process.cwd());
|
|
92
91
|
globalObject.root = root;
|
|
93
92
|
let vikeVitePluginOptions;
|
|
94
|
-
let viteConfigEnhanced =
|
|
95
|
-
|
|
96
|
-
const found = findVikeVitePlugin(viteConfigFromOptions) || findVikeVitePlugin(viteConfigFromUserViteFile);
|
|
93
|
+
let viteConfigEnhanced = viteConfig;
|
|
94
|
+
const found = findVikeVitePlugin([...(viteConfig?.plugins ?? []), ...(viteConfigFromFile?.plugins ?? [])]);
|
|
97
95
|
if (found) {
|
|
98
96
|
vikeVitePluginOptions = found.vikeVitePluginOptions;
|
|
99
97
|
}
|
|
@@ -102,20 +100,20 @@ async function getInfoFromVite(viteConfigFromOptions, operation) {
|
|
|
102
100
|
// Using a dynamic import because the script calling the Vike API may not live in the same place as vite.config.js, thus vike/plugin may resolved to two different node_modules/vike directories.
|
|
103
101
|
const { plugin: vikePlugin } = await Promise.resolve().then(() => __importStar(require('../plugin/index.js')));
|
|
104
102
|
viteConfigEnhanced = {
|
|
105
|
-
...
|
|
106
|
-
plugins: [...(
|
|
103
|
+
...viteConfig,
|
|
104
|
+
plugins: [...(viteConfig?.plugins ?? []), vikePlugin()]
|
|
107
105
|
};
|
|
108
|
-
const res = findVikeVitePlugin(viteConfigEnhanced);
|
|
106
|
+
const res = findVikeVitePlugin(viteConfigEnhanced.plugins);
|
|
109
107
|
(0, utils_js_1.assert)(res);
|
|
110
108
|
vikeVitePluginOptions = res.vikeVitePluginOptions;
|
|
111
109
|
}
|
|
112
110
|
(0, utils_js_1.assert)(vikeVitePluginOptions);
|
|
113
111
|
return { root, vikeVitePluginOptions, viteConfigEnhanced };
|
|
114
112
|
}
|
|
115
|
-
function findVikeVitePlugin(
|
|
113
|
+
function findVikeVitePlugin(plugins) {
|
|
116
114
|
let vikeVitePluginOptions;
|
|
117
115
|
let vikeVitePuginFound = false;
|
|
118
|
-
|
|
116
|
+
plugins.forEach((p) => {
|
|
119
117
|
if (p && '__vikeVitePluginOptions' in p) {
|
|
120
118
|
vikeVitePuginFound = true;
|
|
121
119
|
const options = p.__vikeVitePluginOptions;
|
|
@@ -128,8 +126,8 @@ function findVikeVitePlugin(viteConfig) {
|
|
|
128
126
|
return { vikeVitePluginOptions };
|
|
129
127
|
}
|
|
130
128
|
// Copied from https://github.com/vitejs/vite/blob/4f5845a3182fc950eb9cd76d7161698383113b18/packages/vite/src/node/config.ts#L961-L1005
|
|
131
|
-
async function loadViteConfigFile(
|
|
132
|
-
const [inlineConfig, command, defaultMode, _defaultNodeEnv, isPreview] = getResolveConfigArgs(
|
|
129
|
+
async function loadViteConfigFile(viteConfig, operation) {
|
|
130
|
+
const [inlineConfig, command, defaultMode, _defaultNodeEnv, isPreview] = getResolveConfigArgs(viteConfig, operation);
|
|
133
131
|
let config = inlineConfig;
|
|
134
132
|
let mode = inlineConfig.mode || defaultMode;
|
|
135
133
|
const configEnv = {
|
|
@@ -7,6 +7,7 @@ exports.fixServerAssets = fixServerAssets;
|
|
|
7
7
|
exports.fixServerAssets_isEnabled = fixServerAssets_isEnabled;
|
|
8
8
|
exports.fixServerAssets_assertCssCodeSplit = fixServerAssets_assertCssCodeSplit;
|
|
9
9
|
exports.fixServerAssets_assertCssTarget = fixServerAssets_assertCssTarget;
|
|
10
|
+
exports.fixServerAssets_assertCssTarget_populate = fixServerAssets_assertCssTarget_populate;
|
|
10
11
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
11
12
|
const fs_1 = __importDefault(require("fs"));
|
|
12
13
|
const path_1 = __importDefault(require("path"));
|
|
@@ -199,15 +200,17 @@ function fixServerAssets_assertCssCodeSplit(config) {
|
|
|
199
200
|
(0, utils_js_1.assertWarning)(config.build.cssCodeSplit, `${picocolors_1.default.cyan('build.cssCodeSplit')} shouldn't be set to ${picocolors_1.default.cyan('false')} (https://github.com/vikejs/vike/issues/1993)`, { onlyOnce: true });
|
|
200
201
|
}
|
|
201
202
|
const targets = [];
|
|
203
|
+
function fixServerAssets_assertCssTarget_populate(config) {
|
|
204
|
+
const isServerSide = (0, viteIsSSR_js_1.viteIsSSR)(config);
|
|
205
|
+
(0, utils_js_1.assert)(typeof isServerSide === 'boolean');
|
|
206
|
+
(0, utils_js_1.assert)(config.build.target !== undefined);
|
|
207
|
+
targets.push({ global: config.build.target, css: config.build.cssTarget, isServerSide });
|
|
208
|
+
}
|
|
202
209
|
async function fixServerAssets_assertCssTarget(config) {
|
|
203
210
|
if (!fixServerAssets_isEnabled())
|
|
204
211
|
return;
|
|
205
212
|
if (!(await (0, getVikeConfig_js_1.isV1Design)(config)))
|
|
206
213
|
return;
|
|
207
|
-
const isServerSide = (0, viteIsSSR_js_1.viteIsSSR)(config);
|
|
208
|
-
(0, utils_js_1.assert)(typeof isServerSide === 'boolean');
|
|
209
|
-
(0, utils_js_1.assert)(config.build.target !== undefined);
|
|
210
|
-
targets.push({ global: config.build.target, css: config.build.cssTarget, isServerSide });
|
|
211
214
|
const targetsServer = targets.filter((t) => t.isServerSide);
|
|
212
215
|
const targetsClient = targets.filter((t) => !t.isServerSide);
|
|
213
216
|
targetsClient.forEach((targetClient) => {
|
|
@@ -215,10 +218,9 @@ async function fixServerAssets_assertCssTarget(config) {
|
|
|
215
218
|
targetsServer.forEach((targetServer) => {
|
|
216
219
|
const targetCssResolvedServer = resolveCssTarget(targetServer);
|
|
217
220
|
(0, utils_js_1.assertWarning)((0, utils_js_1.isEqualStringList)(targetCssResolvedClient, targetCssResolvedServer), [
|
|
218
|
-
'The CSS browser target should be the same for both client and server
|
|
219
|
-
`Client: ${picocolors_1.default.cyan(JSON.stringify(targetCssResolvedClient))}`,
|
|
220
|
-
`Server: ${picocolors_1.default.cyan(JSON.stringify(targetCssResolvedServer))}
|
|
221
|
-
`Different targets lead to CSS duplication, see ${picocolors_1.default.underline('https://github.com/vikejs/vike/issues/1815#issuecomment-2507002979')} for more information.`
|
|
221
|
+
'The CSS browser target should be the same for both client-side and server-side (https://github.com/vikejs/vike/issues/1815#issuecomment-2507002979) but we got:',
|
|
222
|
+
`Client-side: ${picocolors_1.default.cyan(JSON.stringify(targetCssResolvedClient))}`,
|
|
223
|
+
`Server-side: ${picocolors_1.default.cyan(JSON.stringify(targetCssResolvedServer))}`
|
|
222
224
|
].join('\n'), {
|
|
223
225
|
showStackTrace: true,
|
|
224
226
|
onlyOnce: 'different-css-target'
|
|
@@ -54,6 +54,7 @@ function buildConfig() {
|
|
|
54
54
|
config.build.ssrEmitAssets = true;
|
|
55
55
|
// Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
|
|
56
56
|
config.build.cssMinify = 'esbuild';
|
|
57
|
+
(0, fixServerAssets_js_1.fixServerAssets_assertCssTarget_populate)(config);
|
|
57
58
|
(0, fixServerAssets_js_1.fixServerAssets_assertCssCodeSplit)(config);
|
|
58
59
|
}
|
|
59
60
|
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -12,7 +12,6 @@ const util_1 = require("util");
|
|
|
12
12
|
const transpileAndExecuteFile_js_1 = require("./transpileAndExecuteFile.js");
|
|
13
13
|
const getEnvVarObject_js_1 = require("../../../../shared/getEnvVarObject.js");
|
|
14
14
|
const execA = (0, util_1.promisify)(child_process_1.exec);
|
|
15
|
-
const debug = (0, utils_js_1.createDebugger)('vike:crawl');
|
|
16
15
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
17
16
|
(0, utils_js_1.assertIsSingleModuleInstance)('crawlPlusFiles.ts');
|
|
18
17
|
let gitIsNotUsable = false;
|
|
@@ -36,16 +35,17 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem) {
|
|
|
36
35
|
//
|
|
37
36
|
!outDirRelativeFromUserRootDir.startsWith('../')));
|
|
38
37
|
// Crawl
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
let files;
|
|
39
|
+
const res = !isGitCrawlDisabled() && (await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir));
|
|
40
|
+
if (res &&
|
|
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.)
|
|
42
|
+
res.length > 0) {
|
|
43
|
+
files = res;
|
|
44
|
+
// We cannot find files inside symlink directories with `$ git ls-files` => we use fast-glob
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
files = await fastGlob(userRootDir, outDirRelativeFromUserRootDir);
|
|
48
|
+
}
|
|
49
49
|
// Filter build files
|
|
50
50
|
files = files.filter((filePath) => !(0, transpileAndExecuteFile_js_1.isTemporaryBuildFile)(filePath));
|
|
51
51
|
// Normalize
|
|
@@ -74,7 +74,7 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
74
74
|
preserveUTF8,
|
|
75
75
|
'ls-files',
|
|
76
76
|
// Performance gain seems negligible: https://github.com/vikejs/vike/pull/1688#issuecomment-2166206648
|
|
77
|
-
...utils_js_1.scriptFileExtensionList.map((ext) => `"**/+*.${ext}"
|
|
77
|
+
...utils_js_1.scriptFileExtensionList.map((ext) => `"**/+*.${ext}"`),
|
|
78
78
|
// Performance gain is non-negligible.
|
|
79
79
|
// - https://github.com/vikejs/vike/pull/1688#issuecomment-2166206648
|
|
80
80
|
// - When node_modules/ is untracked the performance gain could be significant?
|
|
@@ -101,12 +101,6 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
101
101
|
}
|
|
102
102
|
throw err;
|
|
103
103
|
}
|
|
104
|
-
if (debug.isActivated) {
|
|
105
|
-
debug('[git] userRootDir:', userRootDir);
|
|
106
|
-
debug('[git] cmd:', cmd);
|
|
107
|
-
debug('[git] result:', filesAll);
|
|
108
|
-
debug('[git] filesDeleted:', filesDeleted);
|
|
109
|
-
}
|
|
110
104
|
const files = [];
|
|
111
105
|
for (const filePath of filesAll) {
|
|
112
106
|
// + file?
|
|
@@ -127,21 +121,14 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
127
121
|
}
|
|
128
122
|
// Same as gitLsFiles() but using fast-glob
|
|
129
123
|
async function fastGlob(userRootDir, outDirRelativeFromUserRootDir) {
|
|
130
|
-
const
|
|
131
|
-
const options = {
|
|
124
|
+
const files = await (0, fast_glob_1.default)(`**/+*.${utils_js_1.scriptFileExtensions}`, {
|
|
132
125
|
ignore: getIgnoreAsPatterns(outDirRelativeFromUserRootDir),
|
|
133
126
|
cwd: userRootDir,
|
|
134
127
|
dot: false
|
|
135
|
-
};
|
|
136
|
-
const files = await (0, fast_glob_1.default)(pattern, options);
|
|
128
|
+
});
|
|
137
129
|
// Make build deterministic, in order to get a stable generated hash for dist/client/assets/entries/entry-client-routing.${hash}.js
|
|
138
130
|
// https://github.com/vikejs/vike/pull/1750
|
|
139
131
|
files.sort();
|
|
140
|
-
if (debug.isActivated) {
|
|
141
|
-
debug('[glob] pattern:', pattern);
|
|
142
|
-
debug('[glob] options:', options);
|
|
143
|
-
debug('[glob] result:', files);
|
|
144
|
-
}
|
|
145
132
|
return files;
|
|
146
133
|
}
|
|
147
134
|
// Same as getIgnoreAsFilterFn() but as glob pattern
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.getFilesystemRouteDefinedBy = getFilesystemRouteDefinedBy;
|
|
|
8
8
|
exports.isInherited = isInherited;
|
|
9
9
|
exports.getLocationId = getLocationId;
|
|
10
10
|
exports.sortAfterInheritanceOrder = sortAfterInheritanceOrder;
|
|
11
|
+
exports.isGlobalLocation = isGlobalLocation;
|
|
11
12
|
exports.applyFilesystemRoutingRootEffect = applyFilesystemRoutingRootEffect;
|
|
12
13
|
exports.getLogicalPath = getLogicalPath;
|
|
13
14
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
@@ -44,6 +45,10 @@ function getLogicalPath(locationId, ignoredDirs, removeParenthesesDirs) {
|
|
|
44
45
|
assertIsPath(logicalPath);
|
|
45
46
|
return logicalPath;
|
|
46
47
|
}
|
|
48
|
+
/** Whether configs defined in `locationId` apply in every `locationIds` */
|
|
49
|
+
function isGlobalLocation(locationId, locationIds) {
|
|
50
|
+
return locationIds.every((locId) => isInherited(locationId, locId) || locationIsRendererDir(locId));
|
|
51
|
+
}
|
|
47
52
|
function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
48
53
|
assertLocationId(locationId1);
|
|
49
54
|
assertLocationId(locationId2);
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -56,7 +56,7 @@ async function loadValueFile(interfaceValueFile, configDefinitions, userRootDir,
|
|
|
56
56
|
async function loadConfigFile(configFilePath, userRootDir, visited, isExtensionConfig, esbuildCache) {
|
|
57
57
|
const { filePathAbsoluteFilesystem } = configFilePath;
|
|
58
58
|
assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem);
|
|
59
|
-
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(configFilePath, userRootDir, isExtensionConfig, esbuildCache);
|
|
59
|
+
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(configFilePath, userRootDir, isExtensionConfig ? 'is-extension-config' : true, esbuildCache);
|
|
60
60
|
const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [...visited, filePathAbsoluteFilesystem], esbuildCache);
|
|
61
61
|
const configFile = {
|
|
62
62
|
fileExports,
|
|
@@ -26,7 +26,7 @@ const debug = (0, utils_js_1.createDebugger)('vike:pointer-imports');
|
|
|
26
26
|
const debugEsbuildResolve = (0, utils_js_1.createDebugger)('vike:esbuild-resolve');
|
|
27
27
|
if (debugEsbuildResolve.isActivated)
|
|
28
28
|
debugEsbuildResolve('esbuild version', esbuild_1.version);
|
|
29
|
-
async function transpileAndExecuteFile(filePath, userRootDir,
|
|
29
|
+
async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile, esbuildCache) {
|
|
30
30
|
const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
|
|
31
31
|
const fileExtension = getFileExtension(filePathAbsoluteFilesystem);
|
|
32
32
|
if (esbuildCache[filePathAbsoluteFilesystem]) {
|
|
@@ -40,12 +40,12 @@ async function transpileAndExecuteFile(filePath, userRootDir, isExtensionConfig,
|
|
|
40
40
|
(0, utils_js_1.assertWarning)(false, `${picocolors_1.default.cyan('.h.js')} files are deprecated: simply renaming ${filePathToShowToUserResolved} to ${removeHeaderFileExtension(filePathToShowToUserResolved)} is usually enough, although you may occasionally need to use ${picocolors_1.default.cyan("with { type: 'pointer' }")} as explained at https://vike.dev/config#pointer-imports`, { onlyOnce: true });
|
|
41
41
|
}
|
|
42
42
|
let fileExports;
|
|
43
|
-
if (
|
|
43
|
+
if (isConfigFile === 'is-extension-config' && !isHeader && fileExtension.endsWith('js')) {
|
|
44
44
|
// This doesn't track dependencies => we should never use this for user land configs
|
|
45
45
|
fileExports = await executeFile(filePathAbsoluteFilesystem, filePath);
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
|
-
const transformImports = isHeader ? 'all' : true;
|
|
48
|
+
const transformImports = isConfigFile && (isHeader ? 'all' : true);
|
|
49
49
|
const code = await transpileFile(filePath, transformImports, userRootDir);
|
|
50
50
|
fileExports = await executeTranspiledFile(filePath, code);
|
|
51
51
|
}
|
|
@@ -338,7 +338,6 @@ function isTemporaryBuildFile(filePath) {
|
|
|
338
338
|
const fileName = path_1.default.posix.basename(filePath);
|
|
339
339
|
return /\.build-[a-z0-9]{12}\.mjs$/.test(fileName);
|
|
340
340
|
}
|
|
341
|
-
// TODO/next-major: remove
|
|
342
341
|
function isHeaderFile(filePath) {
|
|
343
342
|
(0, utils_js_1.assertPosixPath)(filePath);
|
|
344
343
|
const fileExtensions = getFileExtensions(filePath);
|
|
@@ -235,9 +235,10 @@ function assertPageConfigGlobal(pageConfigGlobal, plusFilesAll) {
|
|
|
235
235
|
});
|
|
236
236
|
}
|
|
237
237
|
function assertGlobalConfigLocation(configName, sources, plusFilesAll, configDefinitionsGlobal) {
|
|
238
|
+
const locationIdsAll = (0, utils_js_1.objectKeys)(plusFilesAll);
|
|
238
239
|
// Determine existing global +config.js files
|
|
239
240
|
const configFilePathsGlobal = [];
|
|
240
|
-
const plusFilesGlobal = Object.values((0, utils_js_1.objectFromEntries)((0, utils_js_1.objectEntries)(plusFilesAll).filter(([locationId]) => isGlobalLocation(locationId,
|
|
241
|
+
const plusFilesGlobal = Object.values((0, utils_js_1.objectFromEntries)((0, utils_js_1.objectEntries)(plusFilesAll).filter(([locationId]) => (0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIdsAll)))).flat();
|
|
241
242
|
plusFilesGlobal
|
|
242
243
|
.filter((i) => i.isConfigFile)
|
|
243
244
|
.forEach((plusFile) => {
|
|
@@ -256,7 +257,7 @@ function assertGlobalConfigLocation(configName, sources, plusFilesAll, configDef
|
|
|
256
257
|
if (!filePathAbsoluteUserRootDir)
|
|
257
258
|
return;
|
|
258
259
|
(0, utils_js_1.assert)(!plusFile.isExtensionConfig);
|
|
259
|
-
if (!isGlobalLocation(source.locationId,
|
|
260
|
+
if (!(0, filesystemRouting_js_1.isGlobalLocation)(source.locationId, locationIdsAll)) {
|
|
260
261
|
const configDef = configDefinitionsGlobal[configName];
|
|
261
262
|
(0, utils_js_1.assert)(configDef);
|
|
262
263
|
const isConditionallyGlobal = (0, utils_js_1.isCallable)(configDef.global);
|
|
@@ -359,7 +360,7 @@ function sortForGlobal(plusFilesAll) {
|
|
|
359
360
|
const locationIdsAll = (0, utils_js_1.objectKeys)(plusFilesAll);
|
|
360
361
|
const plusFilesAllSorted = Object.fromEntries((0, utils_js_1.objectEntries)(plusFilesAll)
|
|
361
362
|
.sort((0, utils_js_1.lowerFirst)(([locationId]) => locationId.split('/').length))
|
|
362
|
-
.sort((0, utils_js_1.makeFirst)(([locationId]) => isGlobalLocation(locationId,
|
|
363
|
+
.sort((0, utils_js_1.makeFirst)(([locationId]) => (0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIdsAll))));
|
|
363
364
|
return plusFilesAllSorted;
|
|
364
365
|
}
|
|
365
366
|
function resolveConfigValueSources(configName, configDef, plusFilesRelevant, userRootDir, isGlobal) {
|
|
@@ -931,10 +932,3 @@ function resolveConfigEnv(configEnv, filePath) {
|
|
|
931
932
|
}
|
|
932
933
|
return configEnvResolved;
|
|
933
934
|
}
|
|
934
|
-
/** Whether configs defined in `locationId` apply to every page */
|
|
935
|
-
function isGlobalLocation(locationId, plusFilesAll) {
|
|
936
|
-
const locationIdsPage = (0, utils_js_1.objectEntries)(plusFilesAll)
|
|
937
|
-
.filter(([_locationId, plusFiles]) => isDefiningPage(plusFiles))
|
|
938
|
-
.map(([locationId]) => locationId);
|
|
939
|
-
return locationIdsPage.every((locId) => (0, filesystemRouting_js_1.isInherited)(locationId, locId));
|
|
940
|
-
}
|
|
@@ -11,7 +11,7 @@ const globalContext_js_1 = require("../runtime/globalContext.js");
|
|
|
11
11
|
*/
|
|
12
12
|
async function createDevMiddleware(options = {}) {
|
|
13
13
|
(0, globalContext_js_1.setGlobalContext_isProduction)(false);
|
|
14
|
-
const
|
|
14
|
+
const viteConfig = {
|
|
15
15
|
...options.viteConfig,
|
|
16
16
|
server: {
|
|
17
17
|
...options.viteConfig?.server,
|
|
@@ -19,8 +19,8 @@ async function createDevMiddleware(options = {}) {
|
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
if (options.root)
|
|
22
|
-
|
|
23
|
-
const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(
|
|
22
|
+
viteConfig.root = options.root;
|
|
23
|
+
const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(viteConfig, 'dev');
|
|
24
24
|
const server = await (0, vite_1.createServer)(viteConfigEnhanced);
|
|
25
25
|
const devMiddleware = server.middlewares;
|
|
26
26
|
return { devMiddleware, viteServer: server, viteConfig: server.config };
|
package/dist/cjs/utils/debug.js
CHANGED
|
@@ -17,9 +17,7 @@ const isArray_js_1 = require("./isArray.js");
|
|
|
17
17
|
(0, assert_js_1.assert)(!(0, isBrowser_js_1.isBrowser)());
|
|
18
18
|
globalThis.__brillout_debug_createDebugger = createDebugger;
|
|
19
19
|
const flags = [
|
|
20
|
-
'vike:crawl',
|
|
21
20
|
'vike:error',
|
|
22
|
-
'vike:esbuild-resolve',
|
|
23
21
|
'vike:extractAssets',
|
|
24
22
|
'vike:extractExportNames',
|
|
25
23
|
'vike:glob',
|
|
@@ -32,9 +30,9 @@ const flags = [
|
|
|
32
30
|
'vike:routing',
|
|
33
31
|
'vike:setup',
|
|
34
32
|
'vike:stream',
|
|
35
|
-
'vike:virtual-files'
|
|
33
|
+
'vike:virtual-files',
|
|
34
|
+
'vike:esbuild-resolve'
|
|
36
35
|
];
|
|
37
|
-
const flagsSkipWildcard = ['vike:log'];
|
|
38
36
|
const flagRegex = /\bvike:[a-zA-Z-]+/g;
|
|
39
37
|
assertFlagsActivated();
|
|
40
38
|
function createDebugger(flag, optionsGlobal) {
|
|
@@ -79,8 +77,8 @@ function debug_(flag, options, ...msgs) {
|
|
|
79
77
|
function isDebugActivated(flag) {
|
|
80
78
|
(0, checkType_js_1.checkType)(flag);
|
|
81
79
|
(0, assert_js_1.assert)(flags.includes(flag));
|
|
82
|
-
const
|
|
83
|
-
const isActivated = flagsActivated.includes(flag)
|
|
80
|
+
const flagsActivated = getFlagsActivated();
|
|
81
|
+
const isActivated = flagsActivated.includes(flag);
|
|
84
82
|
return isActivated;
|
|
85
83
|
}
|
|
86
84
|
function formatMsg(info, options, padding, position) {
|
|
@@ -144,7 +142,7 @@ function replaceFunctionSerializer(_key, value) {
|
|
|
144
142
|
return value;
|
|
145
143
|
}
|
|
146
144
|
function assertFlagsActivated() {
|
|
147
|
-
const
|
|
145
|
+
const flagsActivated = getFlagsActivated();
|
|
148
146
|
flagsActivated.forEach((flag) => {
|
|
149
147
|
(0, assert_js_1.assertUsage)(flags.includes(flag), `Unknown DEBUG flag ${picocolors_1.default.cyan(flag)}. Valid flags:\n${flags.map((f) => ` ${picocolors_1.default.cyan(f)}`).join('\n')}`);
|
|
150
148
|
});
|
|
@@ -152,8 +150,7 @@ function assertFlagsActivated() {
|
|
|
152
150
|
function getFlagsActivated() {
|
|
153
151
|
const DEBUG = getDEBUG() ?? '';
|
|
154
152
|
const flagsActivated = DEBUG.match(flagRegex) ?? [];
|
|
155
|
-
|
|
156
|
-
return { flagsActivated, all };
|
|
153
|
+
return flagsActivated;
|
|
157
154
|
}
|
|
158
155
|
function getDEBUG() {
|
|
159
156
|
let DEBUG;
|
|
@@ -5,10 +5,10 @@ export { normalizeViteRoot };
|
|
|
5
5
|
import type { InlineConfig, ResolvedConfig } from 'vite';
|
|
6
6
|
import type { Operation } from './types.js';
|
|
7
7
|
import { type VikeConfigObject } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
|
|
8
|
-
declare function prepareViteApiCall(
|
|
8
|
+
declare function prepareViteApiCall(viteConfig: InlineConfig | undefined, operation: Operation): Promise<{
|
|
9
9
|
vikeConfig: VikeConfigObject;
|
|
10
10
|
viteConfigEnhanced: InlineConfig | undefined;
|
|
11
11
|
}>;
|
|
12
|
-
declare function getViteRoot(operation:
|
|
12
|
+
declare function getViteRoot(operation: 'build' | 'dev' | 'preview' | 'prerender'): Promise<string>;
|
|
13
13
|
declare function normalizeViteRoot(root: string): string;
|
|
14
14
|
declare function assertViteRoot(root: string, config: ResolvedConfig): void;
|
|
@@ -11,18 +11,18 @@ import { assert, assertUsage, getGlobalObject, isObject, toPosixPath } from './u
|
|
|
11
11
|
import pc from '@brillout/picocolors';
|
|
12
12
|
import { clearGlobalContext } from '../runtime/globalContext.js';
|
|
13
13
|
const globalObject = getGlobalObject('prepareViteApiCall.ts', {});
|
|
14
|
-
async function prepareViteApiCall(
|
|
14
|
+
async function prepareViteApiCall(viteConfig, operation) {
|
|
15
15
|
clear();
|
|
16
16
|
setContextApiOperation(operation);
|
|
17
|
-
return enhanceViteConfig(
|
|
17
|
+
return enhanceViteConfig(viteConfig, operation);
|
|
18
18
|
}
|
|
19
19
|
// For subsequent API calls, e.g. calling prerender() after build()
|
|
20
20
|
function clear() {
|
|
21
21
|
clearContextApiOperation();
|
|
22
22
|
clearGlobalContext();
|
|
23
23
|
}
|
|
24
|
-
async function enhanceViteConfig(
|
|
25
|
-
const viteInfo = await getInfoFromVite(
|
|
24
|
+
async function enhanceViteConfig(viteConfig, operation) {
|
|
25
|
+
const viteInfo = await getInfoFromVite(viteConfig, operation);
|
|
26
26
|
await assertViteRoot2(viteInfo.root, viteInfo.viteConfigEnhanced, operation);
|
|
27
27
|
const vikeConfig = await getVikeConfig2(viteInfo.root, operation === 'dev', viteInfo.vikeVitePluginOptions);
|
|
28
28
|
const viteConfigEnhanced = addViteSettingsSetByVikeConfig(viteInfo.viteConfigEnhanced, vikeConfig);
|
|
@@ -38,7 +38,6 @@ function addViteSettingsSetByVikeConfig(viteConfigEnhanced, vikeConfig) {
|
|
|
38
38
|
viteConfigs.values.forEach((v) => {
|
|
39
39
|
assertUsage(isObject(v.value), `${v.definedAt} should be an object`);
|
|
40
40
|
viteConfigEnhanced = mergeConfig(viteConfigEnhanced ?? {}, v.value);
|
|
41
|
-
assertUsage(!findVikeVitePlugin(v.value), "Using the +vite setting to add Vike's Vite plugin is forbidden");
|
|
42
41
|
});
|
|
43
42
|
return viteConfigEnhanced;
|
|
44
43
|
}
|
|
@@ -48,14 +47,13 @@ async function getViteRoot(operation) {
|
|
|
48
47
|
assert(globalObject.root);
|
|
49
48
|
return globalObject.root;
|
|
50
49
|
}
|
|
51
|
-
async function getInfoFromVite(
|
|
52
|
-
const
|
|
53
|
-
const root = normalizeViteRoot(
|
|
50
|
+
async function getInfoFromVite(viteConfig, operation) {
|
|
51
|
+
const viteConfigFromFile = await loadViteConfigFile(viteConfig, operation);
|
|
52
|
+
const root = normalizeViteRoot(viteConfigFromFile?.root ?? viteConfig?.root ?? process.cwd());
|
|
54
53
|
globalObject.root = root;
|
|
55
54
|
let vikeVitePluginOptions;
|
|
56
|
-
let viteConfigEnhanced =
|
|
57
|
-
|
|
58
|
-
const found = findVikeVitePlugin(viteConfigFromOptions) || findVikeVitePlugin(viteConfigFromUserViteFile);
|
|
55
|
+
let viteConfigEnhanced = viteConfig;
|
|
56
|
+
const found = findVikeVitePlugin([...(viteConfig?.plugins ?? []), ...(viteConfigFromFile?.plugins ?? [])]);
|
|
59
57
|
if (found) {
|
|
60
58
|
vikeVitePluginOptions = found.vikeVitePluginOptions;
|
|
61
59
|
}
|
|
@@ -64,20 +62,20 @@ async function getInfoFromVite(viteConfigFromOptions, operation) {
|
|
|
64
62
|
// Using a dynamic import because the script calling the Vike API may not live in the same place as vite.config.js, thus vike/plugin may resolved to two different node_modules/vike directories.
|
|
65
63
|
const { plugin: vikePlugin } = await import('../plugin/index.js');
|
|
66
64
|
viteConfigEnhanced = {
|
|
67
|
-
...
|
|
68
|
-
plugins: [...(
|
|
65
|
+
...viteConfig,
|
|
66
|
+
plugins: [...(viteConfig?.plugins ?? []), vikePlugin()]
|
|
69
67
|
};
|
|
70
|
-
const res = findVikeVitePlugin(viteConfigEnhanced);
|
|
68
|
+
const res = findVikeVitePlugin(viteConfigEnhanced.plugins);
|
|
71
69
|
assert(res);
|
|
72
70
|
vikeVitePluginOptions = res.vikeVitePluginOptions;
|
|
73
71
|
}
|
|
74
72
|
assert(vikeVitePluginOptions);
|
|
75
73
|
return { root, vikeVitePluginOptions, viteConfigEnhanced };
|
|
76
74
|
}
|
|
77
|
-
function findVikeVitePlugin(
|
|
75
|
+
function findVikeVitePlugin(plugins) {
|
|
78
76
|
let vikeVitePluginOptions;
|
|
79
77
|
let vikeVitePuginFound = false;
|
|
80
|
-
|
|
78
|
+
plugins.forEach((p) => {
|
|
81
79
|
if (p && '__vikeVitePluginOptions' in p) {
|
|
82
80
|
vikeVitePuginFound = true;
|
|
83
81
|
const options = p.__vikeVitePluginOptions;
|
|
@@ -90,8 +88,8 @@ function findVikeVitePlugin(viteConfig) {
|
|
|
90
88
|
return { vikeVitePluginOptions };
|
|
91
89
|
}
|
|
92
90
|
// Copied from https://github.com/vitejs/vite/blob/4f5845a3182fc950eb9cd76d7161698383113b18/packages/vite/src/node/config.ts#L961-L1005
|
|
93
|
-
async function loadViteConfigFile(
|
|
94
|
-
const [inlineConfig, command, defaultMode, _defaultNodeEnv, isPreview] = getResolveConfigArgs(
|
|
91
|
+
async function loadViteConfigFile(viteConfig, operation) {
|
|
92
|
+
const [inlineConfig, command, defaultMode, _defaultNodeEnv, isPreview] = getResolveConfigArgs(viteConfig, operation);
|
|
95
93
|
let config = inlineConfig;
|
|
96
94
|
let mode = inlineConfig.mode || defaultMode;
|
|
97
95
|
const configEnv = {
|
|
@@ -2,6 +2,7 @@ export { fixServerAssets };
|
|
|
2
2
|
export { fixServerAssets_isEnabled };
|
|
3
3
|
export { fixServerAssets_assertCssCodeSplit };
|
|
4
4
|
export { fixServerAssets_assertCssTarget };
|
|
5
|
+
export { fixServerAssets_assertCssTarget_populate };
|
|
5
6
|
import { ViteManifest } from '../../../shared/ViteManifest.js';
|
|
6
7
|
import { ResolvedConfig } from 'vite';
|
|
7
8
|
/**
|
|
@@ -17,4 +18,5 @@ declare function fixServerAssets(config: ResolvedConfig): Promise<{
|
|
|
17
18
|
serverManifestMod: ViteManifest;
|
|
18
19
|
}>;
|
|
19
20
|
declare function fixServerAssets_assertCssCodeSplit(config: ResolvedConfig): void;
|
|
21
|
+
declare function fixServerAssets_assertCssTarget_populate(config: ResolvedConfig): void;
|
|
20
22
|
declare function fixServerAssets_assertCssTarget(config: ResolvedConfig): Promise<void>;
|
|
@@ -2,6 +2,7 @@ export { fixServerAssets };
|
|
|
2
2
|
export { fixServerAssets_isEnabled };
|
|
3
3
|
export { fixServerAssets_assertCssCodeSplit };
|
|
4
4
|
export { fixServerAssets_assertCssTarget };
|
|
5
|
+
export { fixServerAssets_assertCssTarget_populate };
|
|
5
6
|
import fs from 'fs/promises';
|
|
6
7
|
import fs_sync from 'fs';
|
|
7
8
|
import path from 'path';
|
|
@@ -194,15 +195,17 @@ function fixServerAssets_assertCssCodeSplit(config) {
|
|
|
194
195
|
assertWarning(config.build.cssCodeSplit, `${pc.cyan('build.cssCodeSplit')} shouldn't be set to ${pc.cyan('false')} (https://github.com/vikejs/vike/issues/1993)`, { onlyOnce: true });
|
|
195
196
|
}
|
|
196
197
|
const targets = [];
|
|
198
|
+
function fixServerAssets_assertCssTarget_populate(config) {
|
|
199
|
+
const isServerSide = viteIsSSR(config);
|
|
200
|
+
assert(typeof isServerSide === 'boolean');
|
|
201
|
+
assert(config.build.target !== undefined);
|
|
202
|
+
targets.push({ global: config.build.target, css: config.build.cssTarget, isServerSide });
|
|
203
|
+
}
|
|
197
204
|
async function fixServerAssets_assertCssTarget(config) {
|
|
198
205
|
if (!fixServerAssets_isEnabled())
|
|
199
206
|
return;
|
|
200
207
|
if (!(await isV1Design(config)))
|
|
201
208
|
return;
|
|
202
|
-
const isServerSide = viteIsSSR(config);
|
|
203
|
-
assert(typeof isServerSide === 'boolean');
|
|
204
|
-
assert(config.build.target !== undefined);
|
|
205
|
-
targets.push({ global: config.build.target, css: config.build.cssTarget, isServerSide });
|
|
206
209
|
const targetsServer = targets.filter((t) => t.isServerSide);
|
|
207
210
|
const targetsClient = targets.filter((t) => !t.isServerSide);
|
|
208
211
|
targetsClient.forEach((targetClient) => {
|
|
@@ -210,10 +213,9 @@ async function fixServerAssets_assertCssTarget(config) {
|
|
|
210
213
|
targetsServer.forEach((targetServer) => {
|
|
211
214
|
const targetCssResolvedServer = resolveCssTarget(targetServer);
|
|
212
215
|
assertWarning(isEqualStringList(targetCssResolvedClient, targetCssResolvedServer), [
|
|
213
|
-
'The CSS browser target should be the same for both client and server
|
|
214
|
-
`Client: ${pc.cyan(JSON.stringify(targetCssResolvedClient))}`,
|
|
215
|
-
`Server: ${pc.cyan(JSON.stringify(targetCssResolvedServer))}
|
|
216
|
-
`Different targets lead to CSS duplication, see ${pc.underline('https://github.com/vikejs/vike/issues/1815#issuecomment-2507002979')} for more information.`
|
|
216
|
+
'The CSS browser target should be the same for both client-side and server-side (https://github.com/vikejs/vike/issues/1815#issuecomment-2507002979) but we got:',
|
|
217
|
+
`Client-side: ${pc.cyan(JSON.stringify(targetCssResolvedClient))}`,
|
|
218
|
+
`Server-side: ${pc.cyan(JSON.stringify(targetCssResolvedServer))}`
|
|
217
219
|
].join('\n'), {
|
|
218
220
|
showStackTrace: true,
|
|
219
221
|
onlyOnce: 'different-css-target'
|
|
@@ -10,7 +10,7 @@ import { extractAssetsAddQuery } from '../../shared/extractAssetsQuery.js';
|
|
|
10
10
|
import { createRequire } from 'module';
|
|
11
11
|
import fs from 'fs/promises';
|
|
12
12
|
import path from 'path';
|
|
13
|
-
import { fixServerAssets, fixServerAssets_assertCssCodeSplit, fixServerAssets_assertCssTarget, fixServerAssets_isEnabled } from './buildConfig/fixServerAssets.js';
|
|
13
|
+
import { fixServerAssets, fixServerAssets_assertCssCodeSplit, fixServerAssets_assertCssTarget, fixServerAssets_assertCssTarget_populate, fixServerAssets_isEnabled } from './buildConfig/fixServerAssets.js';
|
|
14
14
|
import { set_ASSETS_MANIFEST } from './buildEntry/index.js';
|
|
15
15
|
import { prependEntriesDir } from '../../shared/prependEntriesDir.js';
|
|
16
16
|
import { getFilePathResolved } from '../shared/getFilePath.js';
|
|
@@ -48,6 +48,7 @@ function buildConfig() {
|
|
|
48
48
|
config.build.ssrEmitAssets = true;
|
|
49
49
|
// Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
|
|
50
50
|
config.build.cssMinify = 'esbuild';
|
|
51
|
+
fixServerAssets_assertCssTarget_populate(config);
|
|
51
52
|
fixServerAssets_assertCssCodeSplit(config);
|
|
52
53
|
}
|
|
53
54
|
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { crawlPlusFiles };
|
|
2
|
-
import { assertPosixPath, assert, scriptFileExtensions, assertIsSingleModuleInstance, assertIsNotProductionRuntime, isVersionOrAbove, isScriptFile, scriptFileExtensionList
|
|
2
|
+
import { assertPosixPath, assert, scriptFileExtensions, assertIsSingleModuleInstance, assertIsNotProductionRuntime, isVersionOrAbove, isScriptFile, scriptFileExtensionList } from '../../../../utils.js';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import glob from 'fast-glob';
|
|
5
5
|
import { exec } from 'child_process';
|
|
@@ -7,7 +7,6 @@ import { promisify } from 'util';
|
|
|
7
7
|
import { isTemporaryBuildFile } from './transpileAndExecuteFile.js';
|
|
8
8
|
import { getEnvVarObject } from '../../../../shared/getEnvVarObject.js';
|
|
9
9
|
const execA = promisify(exec);
|
|
10
|
-
const debug = createDebugger('vike:crawl');
|
|
11
10
|
assertIsNotProductionRuntime();
|
|
12
11
|
assertIsSingleModuleInstance('crawlPlusFiles.ts');
|
|
13
12
|
let gitIsNotUsable = false;
|
|
@@ -31,16 +30,17 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem) {
|
|
|
31
30
|
//
|
|
32
31
|
!outDirRelativeFromUserRootDir.startsWith('../')));
|
|
33
32
|
// Crawl
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
let files;
|
|
34
|
+
const res = !isGitCrawlDisabled() && (await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir));
|
|
35
|
+
if (res &&
|
|
36
|
+
// 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.)
|
|
37
|
+
res.length > 0) {
|
|
38
|
+
files = res;
|
|
39
|
+
// We cannot find files inside symlink directories with `$ git ls-files` => we use fast-glob
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
files = await fastGlob(userRootDir, outDirRelativeFromUserRootDir);
|
|
43
|
+
}
|
|
44
44
|
// Filter build files
|
|
45
45
|
files = files.filter((filePath) => !isTemporaryBuildFile(filePath));
|
|
46
46
|
// Normalize
|
|
@@ -69,7 +69,7 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
69
69
|
preserveUTF8,
|
|
70
70
|
'ls-files',
|
|
71
71
|
// Performance gain seems negligible: https://github.com/vikejs/vike/pull/1688#issuecomment-2166206648
|
|
72
|
-
...scriptFileExtensionList.map((ext) => `"**/+*.${ext}"
|
|
72
|
+
...scriptFileExtensionList.map((ext) => `"**/+*.${ext}"`),
|
|
73
73
|
// Performance gain is non-negligible.
|
|
74
74
|
// - https://github.com/vikejs/vike/pull/1688#issuecomment-2166206648
|
|
75
75
|
// - When node_modules/ is untracked the performance gain could be significant?
|
|
@@ -96,12 +96,6 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
96
96
|
}
|
|
97
97
|
throw err;
|
|
98
98
|
}
|
|
99
|
-
if (debug.isActivated) {
|
|
100
|
-
debug('[git] userRootDir:', userRootDir);
|
|
101
|
-
debug('[git] cmd:', cmd);
|
|
102
|
-
debug('[git] result:', filesAll);
|
|
103
|
-
debug('[git] filesDeleted:', filesDeleted);
|
|
104
|
-
}
|
|
105
99
|
const files = [];
|
|
106
100
|
for (const filePath of filesAll) {
|
|
107
101
|
// + file?
|
|
@@ -122,21 +116,14 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
122
116
|
}
|
|
123
117
|
// Same as gitLsFiles() but using fast-glob
|
|
124
118
|
async function fastGlob(userRootDir, outDirRelativeFromUserRootDir) {
|
|
125
|
-
const
|
|
126
|
-
const options = {
|
|
119
|
+
const files = await glob(`**/+*.${scriptFileExtensions}`, {
|
|
127
120
|
ignore: getIgnoreAsPatterns(outDirRelativeFromUserRootDir),
|
|
128
121
|
cwd: userRootDir,
|
|
129
122
|
dot: false
|
|
130
|
-
};
|
|
131
|
-
const files = await glob(pattern, options);
|
|
123
|
+
});
|
|
132
124
|
// Make build deterministic, in order to get a stable generated hash for dist/client/assets/entries/entry-client-routing.${hash}.js
|
|
133
125
|
// https://github.com/vikejs/vike/pull/1750
|
|
134
126
|
files.sort();
|
|
135
|
-
if (debug.isActivated) {
|
|
136
|
-
debug('[glob] pattern:', pattern);
|
|
137
|
-
debug('[glob] options:', options);
|
|
138
|
-
debug('[glob] result:', files);
|
|
139
|
-
}
|
|
140
127
|
return files;
|
|
141
128
|
}
|
|
142
129
|
// Same as getIgnoreAsFilterFn() but as glob pattern
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { getFilesystemRouteDefinedBy };
|
|
|
3
3
|
export { isInherited };
|
|
4
4
|
export { getLocationId };
|
|
5
5
|
export { sortAfterInheritanceOrder };
|
|
6
|
+
export { isGlobalLocation };
|
|
6
7
|
export { applyFilesystemRoutingRootEffect };
|
|
7
8
|
export type { LocationId };
|
|
8
9
|
export { getLogicalPath };
|
|
@@ -45,6 +46,8 @@ declare function getFilesystemRouteString(locationId: LocationId): string;
|
|
|
45
46
|
* getLogicalPath('/pages/some-page', ['pages']) => '/some-page'
|
|
46
47
|
*/
|
|
47
48
|
declare function getLogicalPath(locationId: LocationId, ignoredDirs: string[], removeParenthesesDirs?: true): string;
|
|
49
|
+
/** Whether configs defined in `locationId` apply in every `locationIds` */
|
|
50
|
+
declare function isGlobalLocation(locationId: LocationId, locationIds: LocationId[]): boolean;
|
|
48
51
|
declare function sortAfterInheritanceOrder(locationId1: LocationId, locationId2: LocationId, locationIdPage: LocationId): -1 | 1 | 0;
|
|
49
52
|
/** Whether configs defined at `locationId1` also apply at `locationId2` */
|
|
50
53
|
declare function isInherited(locationId1: LocationId, locationId2: LocationId): boolean;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js
CHANGED
|
@@ -3,6 +3,7 @@ export { getFilesystemRouteDefinedBy };
|
|
|
3
3
|
export { isInherited };
|
|
4
4
|
export { getLocationId };
|
|
5
5
|
export { sortAfterInheritanceOrder };
|
|
6
|
+
export { isGlobalLocation };
|
|
6
7
|
export { applyFilesystemRoutingRootEffect };
|
|
7
8
|
// For ./filesystemRouting.spec.ts
|
|
8
9
|
export { getLogicalPath };
|
|
@@ -40,6 +41,10 @@ function getLogicalPath(locationId, ignoredDirs, removeParenthesesDirs) {
|
|
|
40
41
|
assertIsPath(logicalPath);
|
|
41
42
|
return logicalPath;
|
|
42
43
|
}
|
|
44
|
+
/** Whether configs defined in `locationId` apply in every `locationIds` */
|
|
45
|
+
function isGlobalLocation(locationId, locationIds) {
|
|
46
|
+
return locationIds.every((locId) => isInherited(locationId, locId) || locationIsRendererDir(locId));
|
|
47
|
+
}
|
|
43
48
|
function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
44
49
|
assertLocationId(locationId1);
|
|
45
50
|
assertLocationId(locationId2);
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -51,7 +51,7 @@ async function loadValueFile(interfaceValueFile, configDefinitions, userRootDir,
|
|
|
51
51
|
async function loadConfigFile(configFilePath, userRootDir, visited, isExtensionConfig, esbuildCache) {
|
|
52
52
|
const { filePathAbsoluteFilesystem } = configFilePath;
|
|
53
53
|
assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem);
|
|
54
|
-
const { fileExports } = await transpileAndExecuteFile(configFilePath, userRootDir, isExtensionConfig, esbuildCache);
|
|
54
|
+
const { fileExports } = await transpileAndExecuteFile(configFilePath, userRootDir, isExtensionConfig ? 'is-extension-config' : true, esbuildCache);
|
|
55
55
|
const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [...visited, filePathAbsoluteFilesystem], esbuildCache);
|
|
56
56
|
const configFile = {
|
|
57
57
|
fileExports,
|
|
@@ -10,7 +10,7 @@ type FileExports = {
|
|
|
10
10
|
};
|
|
11
11
|
type EsbuildCache = Record<string, // filePathAbsoluteFilesystem
|
|
12
12
|
Promise<FileExports>>;
|
|
13
|
-
declare function transpileAndExecuteFile(filePath: FilePathResolved, userRootDir: string,
|
|
13
|
+
declare function transpileAndExecuteFile(filePath: FilePathResolved, userRootDir: string, isConfigFile: boolean | 'is-extension-config', esbuildCache: EsbuildCache): Promise<FileExports>;
|
|
14
14
|
declare function getConfigBuildErrorFormatted(err: unknown): null | string;
|
|
15
15
|
declare function getConfigExecutionErrorIntroMsg(err: unknown): string | null;
|
|
16
16
|
declare function isTemporaryBuildFile(filePath: string): boolean;
|
|
@@ -21,7 +21,7 @@ const debug = createDebugger('vike:pointer-imports');
|
|
|
21
21
|
const debugEsbuildResolve = createDebugger('vike:esbuild-resolve');
|
|
22
22
|
if (debugEsbuildResolve.isActivated)
|
|
23
23
|
debugEsbuildResolve('esbuild version', version);
|
|
24
|
-
async function transpileAndExecuteFile(filePath, userRootDir,
|
|
24
|
+
async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile, esbuildCache) {
|
|
25
25
|
const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
|
|
26
26
|
const fileExtension = getFileExtension(filePathAbsoluteFilesystem);
|
|
27
27
|
if (esbuildCache[filePathAbsoluteFilesystem]) {
|
|
@@ -35,12 +35,12 @@ async function transpileAndExecuteFile(filePath, userRootDir, isExtensionConfig,
|
|
|
35
35
|
assertWarning(false, `${pc.cyan('.h.js')} files are deprecated: simply renaming ${filePathToShowToUserResolved} to ${removeHeaderFileExtension(filePathToShowToUserResolved)} is usually enough, although you may occasionally need to use ${pc.cyan("with { type: 'pointer' }")} as explained at https://vike.dev/config#pointer-imports`, { onlyOnce: true });
|
|
36
36
|
}
|
|
37
37
|
let fileExports;
|
|
38
|
-
if (
|
|
38
|
+
if (isConfigFile === 'is-extension-config' && !isHeader && fileExtension.endsWith('js')) {
|
|
39
39
|
// This doesn't track dependencies => we should never use this for user land configs
|
|
40
40
|
fileExports = await executeFile(filePathAbsoluteFilesystem, filePath);
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
|
-
const transformImports = isHeader ? 'all' : true;
|
|
43
|
+
const transformImports = isConfigFile && (isHeader ? 'all' : true);
|
|
44
44
|
const code = await transpileFile(filePath, transformImports, userRootDir);
|
|
45
45
|
fileExports = await executeTranspiledFile(filePath, code);
|
|
46
46
|
}
|
|
@@ -333,7 +333,6 @@ function isTemporaryBuildFile(filePath) {
|
|
|
333
333
|
const fileName = path.posix.basename(filePath);
|
|
334
334
|
return /\.build-[a-z0-9]{12}\.mjs$/.test(fileName);
|
|
335
335
|
}
|
|
336
|
-
// TODO/next-major: remove
|
|
337
336
|
function isHeaderFile(filePath) {
|
|
338
337
|
assertPosixPath(filePath);
|
|
339
338
|
const fileExtensions = getFileExtensions(filePath);
|
|
@@ -7,7 +7,7 @@ export { getConfVal };
|
|
|
7
7
|
export { getConfigDefinitionOptional };
|
|
8
8
|
import { assertPosixPath, assert, isObject, assertUsage, assertWarning, objectEntries, hasProp, includes, assertIsNotProductionRuntime, getMostSimilar, joinEnglish, assertKeys, objectKeys, objectFromEntries, unique, isCallable, makeFirst, lowerFirst } from '../../../utils.js';
|
|
9
9
|
import { configDefinitionsBuiltIn } from './getVikeConfig/configDefinitionsBuiltIn.js';
|
|
10
|
-
import { getLocationId, getFilesystemRouteString, getFilesystemRouteDefinedBy, isInherited, sortAfterInheritanceOrder, applyFilesystemRoutingRootEffect } from './getVikeConfig/filesystemRouting.js';
|
|
10
|
+
import { getLocationId, getFilesystemRouteString, getFilesystemRouteDefinedBy, isInherited, sortAfterInheritanceOrder, isGlobalLocation, applyFilesystemRoutingRootEffect } from './getVikeConfig/filesystemRouting.js';
|
|
11
11
|
import { isConfigInvalid, isConfigInvalid_set } from '../../../../runtime/renderPage/isConfigInvalid.js';
|
|
12
12
|
import { getViteDevServer } from '../../../../runtime/globalContext.js';
|
|
13
13
|
import { logConfigError, logConfigErrorRecover } from '../../../shared/loggerNotProd.js';
|
|
@@ -229,9 +229,10 @@ function assertPageConfigGlobal(pageConfigGlobal, plusFilesAll) {
|
|
|
229
229
|
});
|
|
230
230
|
}
|
|
231
231
|
function assertGlobalConfigLocation(configName, sources, plusFilesAll, configDefinitionsGlobal) {
|
|
232
|
+
const locationIdsAll = objectKeys(plusFilesAll);
|
|
232
233
|
// Determine existing global +config.js files
|
|
233
234
|
const configFilePathsGlobal = [];
|
|
234
|
-
const plusFilesGlobal = Object.values(objectFromEntries(objectEntries(plusFilesAll).filter(([locationId]) => isGlobalLocation(locationId,
|
|
235
|
+
const plusFilesGlobal = Object.values(objectFromEntries(objectEntries(plusFilesAll).filter(([locationId]) => isGlobalLocation(locationId, locationIdsAll)))).flat();
|
|
235
236
|
plusFilesGlobal
|
|
236
237
|
.filter((i) => i.isConfigFile)
|
|
237
238
|
.forEach((plusFile) => {
|
|
@@ -250,7 +251,7 @@ function assertGlobalConfigLocation(configName, sources, plusFilesAll, configDef
|
|
|
250
251
|
if (!filePathAbsoluteUserRootDir)
|
|
251
252
|
return;
|
|
252
253
|
assert(!plusFile.isExtensionConfig);
|
|
253
|
-
if (!isGlobalLocation(source.locationId,
|
|
254
|
+
if (!isGlobalLocation(source.locationId, locationIdsAll)) {
|
|
254
255
|
const configDef = configDefinitionsGlobal[configName];
|
|
255
256
|
assert(configDef);
|
|
256
257
|
const isConditionallyGlobal = isCallable(configDef.global);
|
|
@@ -353,7 +354,7 @@ function sortForGlobal(plusFilesAll) {
|
|
|
353
354
|
const locationIdsAll = objectKeys(plusFilesAll);
|
|
354
355
|
const plusFilesAllSorted = Object.fromEntries(objectEntries(plusFilesAll)
|
|
355
356
|
.sort(lowerFirst(([locationId]) => locationId.split('/').length))
|
|
356
|
-
.sort(makeFirst(([locationId]) => isGlobalLocation(locationId,
|
|
357
|
+
.sort(makeFirst(([locationId]) => isGlobalLocation(locationId, locationIdsAll))));
|
|
357
358
|
return plusFilesAllSorted;
|
|
358
359
|
}
|
|
359
360
|
function resolveConfigValueSources(configName, configDef, plusFilesRelevant, userRootDir, isGlobal) {
|
|
@@ -925,10 +926,3 @@ function resolveConfigEnv(configEnv, filePath) {
|
|
|
925
926
|
}
|
|
926
927
|
return configEnvResolved;
|
|
927
928
|
}
|
|
928
|
-
/** Whether configs defined in `locationId` apply to every page */
|
|
929
|
-
function isGlobalLocation(locationId, plusFilesAll) {
|
|
930
|
-
const locationIdsPage = objectEntries(plusFilesAll)
|
|
931
|
-
.filter(([_locationId, plusFiles]) => isDefiningPage(plusFiles))
|
|
932
|
-
.map(([locationId]) => locationId);
|
|
933
|
-
return locationIdsPage.every((locId) => isInherited(locationId, locId));
|
|
934
|
-
}
|
|
@@ -9,7 +9,7 @@ import { setGlobalContext_isProduction } from '../runtime/globalContext.js';
|
|
|
9
9
|
*/
|
|
10
10
|
async function createDevMiddleware(options = {}) {
|
|
11
11
|
setGlobalContext_isProduction(false);
|
|
12
|
-
const
|
|
12
|
+
const viteConfig = {
|
|
13
13
|
...options.viteConfig,
|
|
14
14
|
server: {
|
|
15
15
|
...options.viteConfig?.server,
|
|
@@ -17,8 +17,8 @@ async function createDevMiddleware(options = {}) {
|
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
if (options.root)
|
|
20
|
-
|
|
21
|
-
const { viteConfigEnhanced } = await prepareViteApiCall(
|
|
20
|
+
viteConfig.root = options.root;
|
|
21
|
+
const { viteConfigEnhanced } = await prepareViteApiCall(viteConfig, 'dev');
|
|
22
22
|
const server = await createServer(viteConfigEnhanced);
|
|
23
23
|
const devMiddleware = server.middlewares;
|
|
24
24
|
return { devMiddleware, viteServer: server, viteConfig: server.config };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.221
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.221";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.221
|
|
2
|
+
export const PROJECT_VERSION = '0.4.221';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { createDebugger };
|
|
2
2
|
export { isDebugActivated };
|
|
3
3
|
export type { Debug };
|
|
4
|
-
declare const flags: readonly ["vike:
|
|
4
|
+
declare const flags: readonly ["vike:error", "vike:extractAssets", "vike:extractExportNames", "vike:glob", "vike:globalContext", "vike:log", "vike:optimizeDeps", "vike:outDir", "vike:pageFiles", "vike:pointer-imports", "vike:routing", "vike:setup", "vike:stream", "vike:virtual-files", "vike:esbuild-resolve"];
|
|
5
5
|
type Flag = (typeof flags)[number];
|
|
6
6
|
type Debug = ReturnType<typeof createDebugger>;
|
|
7
7
|
type Options = {
|
package/dist/esm/utils/debug.js
CHANGED
|
@@ -12,9 +12,7 @@ import { isArray } from './isArray.js';
|
|
|
12
12
|
assert(!isBrowser());
|
|
13
13
|
globalThis.__brillout_debug_createDebugger = createDebugger;
|
|
14
14
|
const flags = [
|
|
15
|
-
'vike:crawl',
|
|
16
15
|
'vike:error',
|
|
17
|
-
'vike:esbuild-resolve',
|
|
18
16
|
'vike:extractAssets',
|
|
19
17
|
'vike:extractExportNames',
|
|
20
18
|
'vike:glob',
|
|
@@ -27,9 +25,9 @@ const flags = [
|
|
|
27
25
|
'vike:routing',
|
|
28
26
|
'vike:setup',
|
|
29
27
|
'vike:stream',
|
|
30
|
-
'vike:virtual-files'
|
|
28
|
+
'vike:virtual-files',
|
|
29
|
+
'vike:esbuild-resolve'
|
|
31
30
|
];
|
|
32
|
-
const flagsSkipWildcard = ['vike:log'];
|
|
33
31
|
const flagRegex = /\bvike:[a-zA-Z-]+/g;
|
|
34
32
|
assertFlagsActivated();
|
|
35
33
|
function createDebugger(flag, optionsGlobal) {
|
|
@@ -74,8 +72,8 @@ function debug_(flag, options, ...msgs) {
|
|
|
74
72
|
function isDebugActivated(flag) {
|
|
75
73
|
checkType(flag);
|
|
76
74
|
assert(flags.includes(flag));
|
|
77
|
-
const
|
|
78
|
-
const isActivated = flagsActivated.includes(flag)
|
|
75
|
+
const flagsActivated = getFlagsActivated();
|
|
76
|
+
const isActivated = flagsActivated.includes(flag);
|
|
79
77
|
return isActivated;
|
|
80
78
|
}
|
|
81
79
|
function formatMsg(info, options, padding, position) {
|
|
@@ -139,7 +137,7 @@ function replaceFunctionSerializer(_key, value) {
|
|
|
139
137
|
return value;
|
|
140
138
|
}
|
|
141
139
|
function assertFlagsActivated() {
|
|
142
|
-
const
|
|
140
|
+
const flagsActivated = getFlagsActivated();
|
|
143
141
|
flagsActivated.forEach((flag) => {
|
|
144
142
|
assertUsage(flags.includes(flag), `Unknown DEBUG flag ${pc.cyan(flag)}. Valid flags:\n${flags.map((f) => ` ${pc.cyan(f)}`).join('\n')}`);
|
|
145
143
|
});
|
|
@@ -147,8 +145,7 @@ function assertFlagsActivated() {
|
|
|
147
145
|
function getFlagsActivated() {
|
|
148
146
|
const DEBUG = getDEBUG() ?? '';
|
|
149
147
|
const flagsActivated = DEBUG.match(flagRegex) ?? [];
|
|
150
|
-
|
|
151
|
-
return { flagsActivated, all };
|
|
148
|
+
return flagsActivated;
|
|
152
149
|
}
|
|
153
150
|
function getDEBUG() {
|
|
154
151
|
let DEBUG;
|