vike 0.4.260 → 0.4.261

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.
Files changed (65) hide show
  1. package/dist/client/runtime-client-routing/createPageContextClient.d.ts +10 -10
  2. package/dist/client/runtime-client-routing/getGlobalContextClientInternal.d.ts +10 -10
  3. package/dist/client/runtime-client-routing/getPageContext/removeBuiltInOverrides.d.ts +2 -2
  4. package/dist/client/runtime-client-routing/getPageContextFromHooks.d.ts +56 -56
  5. package/dist/client/runtime-client-routing/history.d.ts +1 -1
  6. package/dist/client/runtime-client-routing/renderPageClient.d.ts +49 -49
  7. package/dist/client/runtime-server-routing/createPageContextClient.d.ts +10 -10
  8. package/dist/client/runtime-server-routing/getGlobalContextClientInternal.d.ts +10 -10
  9. package/dist/client/shared/getGlobalContextClientInternalShared.d.ts +10 -10
  10. package/dist/node/api/resolveViteConfigUser.js +1 -1
  11. package/dist/node/api/startupLog.js +0 -1
  12. package/dist/node/cli/parseCli.js +1 -1
  13. package/dist/node/prerender/runPrerender.d.ts +22 -22
  14. package/dist/node/vite/plugins/pluginDev/autoAddVikeSkill.d.ts +3 -0
  15. package/dist/node/vite/plugins/pluginDev/autoAddVikeSkill.js +174 -0
  16. package/dist/node/vite/plugins/pluginDev.js +17 -0
  17. package/dist/node/vite/plugins/pluginVirtualFiles.js +1 -1
  18. package/dist/node/vite/shared/getMagicString.d.ts +1 -1
  19. package/dist/node/vite/shared/getMagicString.js +3 -0
  20. package/dist/node/vite/shared/loggerVite.js +3 -2
  21. package/dist/node/vite/shared/resolveVikeConfigInternal/assertExtensions.d.ts +1 -1
  22. package/dist/node/vite/shared/resolveVikeConfigInternal/{crawlPlusFilePaths.d.ts → crawlPlusFiles.d.ts} +2 -2
  23. package/dist/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +71 -0
  24. package/dist/node/vite/shared/resolveVikeConfigInternal/{getPlusFilesByLocationId.d.ts → getPlusFiles.d.ts} +2 -2
  25. package/dist/node/vite/shared/resolveVikeConfigInternal/{getPlusFilesByLocationId.js → getPlusFiles.js} +4 -5
  26. package/dist/node/vite/shared/resolveVikeConfigInternal/loadFileAtConfigTime.d.ts +1 -1
  27. package/dist/node/vite/shared/resolveVikeConfigInternal/metaBuiltIn.js +4 -0
  28. package/dist/node/vite/shared/resolveVikeConfigInternal.d.ts +2 -2
  29. package/dist/node/vite/shared/resolveVikeConfigInternal.js +5 -5
  30. package/dist/server/runtime/fetch.d.ts +1 -1
  31. package/dist/server/runtime/globalContext.d.ts +81 -81
  32. package/dist/server/runtime/renderPageServer/createPageContextServer.d.ts +22 -22
  33. package/dist/server/runtime/renderPageServer/execHookServer.d.ts +4 -3
  34. package/dist/server/runtime/renderPageServer/html/injectAssets/injectHtmlTags.js +3 -1
  35. package/dist/server/runtime/renderPageServer/loadPageConfigsLazyServerSide.d.ts +22 -22
  36. package/dist/server/runtime/renderPageServer/renderPageServerAfterRoute.d.ts +88 -88
  37. package/dist/server/runtime/renderPageServer.d.ts +22 -22
  38. package/dist/server/runtime/universal-middleware.d.ts +1 -1
  39. package/dist/shared-server-client/createGlobalContextShared.d.ts +20 -20
  40. package/dist/shared-server-client/getPageFiles/fileTypes.d.ts +1 -1
  41. package/dist/shared-server-client/hooks/execHook.d.ts +14 -5
  42. package/dist/shared-server-client/modifyUrlSameOrigin.js +1 -1
  43. package/dist/shared-server-client/page-configs/resolveVikeConfigPublic.d.ts +19 -19
  44. package/dist/shared-server-node/getFileSuffixes.d.ts +1 -1
  45. package/dist/types/Config.d.ts +21 -1
  46. package/dist/types/PageConfig.d.ts +1 -1
  47. package/dist/utils/PROJECT_VERSION.d.ts +1 -1
  48. package/dist/utils/PROJECT_VERSION.js +1 -1
  49. package/dist/utils/assertViteVersion.js +1 -1
  50. package/dist/utils/crawlFiles/ignorePatternsBuiltIn.d.ts +1 -0
  51. package/dist/{node/vite/shared/resolveVikeConfigInternal/crawlPlusFilePaths → utils/crawlFiles}/ignorePatternsBuiltIn.js +1 -1
  52. package/dist/utils/crawlFiles.d.ts +21 -0
  53. package/dist/utils/crawlFiles.js +195 -0
  54. package/dist/utils/genRandomId.d.ts +2 -0
  55. package/dist/utils/{getRandomId.js → genRandomId.js} +2 -2
  56. package/dist/{node/vite/shared → utils}/getEnvVarObject.d.ts +0 -1
  57. package/dist/{node/vite/shared → utils}/getEnvVarObject.js +4 -3
  58. package/dist/utils/getViteRPC.js +2 -2
  59. package/dist/utils/humanizeTime.d.ts +1 -1
  60. package/dist/utils/setTimeoutUnref.d.ts +2 -0
  61. package/dist/utils/setTimeoutUnref.js +11 -0
  62. package/package.json +11 -11
  63. package/dist/node/vite/shared/resolveVikeConfigInternal/crawlPlusFilePaths/ignorePatternsBuiltIn.d.ts +0 -2
  64. package/dist/node/vite/shared/resolveVikeConfigInternal/crawlPlusFilePaths.js +0 -259
  65. package/dist/utils/getRandomId.d.ts +0 -2
@@ -1,259 +0,0 @@
1
- export { crawlPlusFilePaths };
2
- export { isPlusFile };
3
- export { getPlusFileValueConfigName };
4
- import { assert, assertUsage, assertWarning } from '../../../../utils/assert.js';
5
- import { assertIsNotProductionRuntime } from '../../../../utils/assertSetup.js';
6
- import { isVersionMatch } from '../../../../utils/assertVersion.js';
7
- import { createDebug } from '../../../../utils/debug.js';
8
- import { deepEqual } from '../../../../utils/deepEqual.js';
9
- import { getGlobalObject } from '../../../../utils/getGlobalObject.js';
10
- import { hasProp } from '../../../../utils/hasProp.js';
11
- import { assertFilePathAbsoluteFilesystem } from '../../../../utils/isFilePathAbsoluteFilesystem.js';
12
- import { isNotNullish } from '../../../../utils/isNullish.js';
13
- import { scriptFileExtensionPattern, isScriptFile, scriptFileExtensionList } from '../../../../utils/isScriptFile.js';
14
- import { assertPosixPath } from '../../../../utils/path.js';
15
- import path from 'node:path';
16
- import { glob } from 'tinyglobby';
17
- import { exec } from 'node:child_process';
18
- import { promisify } from 'node:util';
19
- import { isTemporaryBuildFile } from './transpileAndExecuteFile.js';
20
- import { getEnvVarObject } from '../getEnvVarObject.js';
21
- import pc from '@brillout/picocolors';
22
- import picomatch from 'picomatch';
23
- import { ignorePatternsBuiltIn } from './crawlPlusFilePaths/ignorePatternsBuiltIn.js';
24
- import '../../assertEnvVite.js';
25
- const execA = promisify(exec);
26
- const debug = createDebug('vike:crawl');
27
- assertIsNotProductionRuntime();
28
- const globalObject = getGlobalObject('getVikeConfig/crawlPlusFilePaths.ts', {
29
- gitIsNotUsable: false,
30
- });
31
- // TODO/after-PR-merge rename crawlPlusFilePaths crawlPlusFiles
32
- async function crawlPlusFilePaths(userRootDir) {
33
- assertPosixPath(userRootDir);
34
- assertFilePathAbsoluteFilesystem(userRootDir);
35
- const userSettings = getUserSettings();
36
- const { ignorePatterns, ignoreMatchers } = getIgnore(userSettings);
37
- // Crawl
38
- const filesGit = userSettings.git !== false && (await gitLsFiles(userRootDir, ignorePatterns, ignoreMatchers));
39
- const filesGitNothingFound = !filesGit || filesGit.length === 0;
40
- const filesGlob = (filesGitNothingFound || debug.isActivated) && (await tinyglobby(userRootDir, ignorePatterns));
41
- let files = !filesGitNothingFound
42
- ? filesGit
43
- : // Fallback to tinyglobby for users that dynamically generate plus files. (Assuming that no plus file is found because of the user's .gitignore list.)
44
- filesGlob;
45
- assert(files);
46
- if (debug.isActivated && filesGit && filesGlob) {
47
- assertWarning(deepEqual(filesGlob.slice().sort(), filesGit.slice().sort()), "Git and glob results aren't matching.", { onlyOnce: false });
48
- }
49
- // Filter build files
50
- files = files.filter((filePath) => !isTemporaryBuildFile(filePath));
51
- // Normalize
52
- const plusFiles = files.map((filePath) => {
53
- // Both `$ git-ls files` and tinyglobby return posix paths
54
- assertPosixPath(filePath);
55
- assert(!filePath.startsWith(userRootDir));
56
- const filePathAbsoluteUserRootDir = path.posix.join('/', filePath);
57
- assert(isPlusFile(filePathAbsoluteUserRootDir));
58
- return { filePathAbsoluteUserRootDir };
59
- });
60
- return plusFiles;
61
- }
62
- // Same as tinyglobby() but using `$ git ls-files`
63
- async function gitLsFiles(userRootDir, ignorePatterns, ignoreMatchers) {
64
- if (globalObject.gitIsNotUsable)
65
- return null;
66
- // Preserve UTF-8 file paths.
67
- // https://github.com/vikejs/vike/issues/1658
68
- // https://stackoverflow.com/questions/22827239/how-to-make-git-properly-display-utf-8-encoded-pathnames-in-the-console-window/22828826#22828826
69
- // https://stackoverflow.com/questions/15884180/how-do-i-override-git-configuration-options-by-command-line-parameters/15884261#15884261
70
- const preserveUTF8 = '-c core.quotepath=off';
71
- const cmd = [
72
- 'git',
73
- preserveUTF8,
74
- 'ls-files',
75
- // Performance gain seems negligible: https://github.com/vikejs/vike/pull/1688#issuecomment-2166206648
76
- ...scriptFileExtensionList.map((ext) => `"**/+*.${ext}" "+*.${ext}"`),
77
- // Performance gain is non-negligible.
78
- // - https://github.com/vikejs/vike/pull/1688#issuecomment-2166206648
79
- // - When node_modules/ is untracked the performance gain could be significant?
80
- ...ignorePatterns.map((pattern) => `--exclude="${pattern}"`),
81
- // --others --exclude-standard => list untracked files (--others) while using .gitignore (--exclude-standard)
82
- // --cached => list tracked files
83
- '--others --exclude-standard --cached',
84
- ].join(' ');
85
- let filesAll;
86
- let filesDeleted;
87
- try {
88
- ;
89
- [filesAll, filesDeleted] = await Promise.all([
90
- // Main command
91
- runCmd1(cmd, userRootDir),
92
- // Get tracked but deleted files
93
- runCmd1('git ls-files --deleted', userRootDir),
94
- ]);
95
- }
96
- catch (err) {
97
- if (await isGitNotUsable(userRootDir)) {
98
- globalObject.gitIsNotUsable = true;
99
- return null;
100
- }
101
- throw err;
102
- }
103
- if (debug.isActivated) {
104
- debug('[git] userRootDir:', userRootDir);
105
- debug('[git] cmd:', cmd);
106
- debug('[git] result:', filesAll);
107
- debug('[git] filesDeleted:', filesDeleted);
108
- }
109
- const files = [];
110
- for (const filePath of filesAll) {
111
- // + file?
112
- if (!path.posix.basename(filePath).startsWith('+'))
113
- continue;
114
- // 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.)
115
- if (ignoreMatchers.some((m) => m(filePath)))
116
- continue;
117
- // JavaScript file?
118
- if (!isScriptFile(filePath))
119
- continue;
120
- // Deleted?
121
- if (filesDeleted.includes(filePath))
122
- continue;
123
- files.push(filePath);
124
- }
125
- return files;
126
- }
127
- // Same as gitLsFiles() but using tinyglobby
128
- async function tinyglobby(userRootDir, ignorePatterns) {
129
- const pattern = `**/+*.${scriptFileExtensionPattern}`;
130
- const options = {
131
- ignore: ignorePatterns,
132
- cwd: userRootDir,
133
- dot: false,
134
- };
135
- const files = await glob(pattern, options);
136
- // Make build deterministic, in order to get a stable generated hash for dist/client/assets/entries/entry-client-routing.${hash}.js
137
- // https://github.com/vikejs/vike/pull/1750
138
- files.sort();
139
- if (debug.isActivated) {
140
- debug('[glob] pattern:', pattern);
141
- debug('[glob] options:', options);
142
- debug('[glob] result:', files);
143
- }
144
- return files;
145
- }
146
- // Whether Git is installed and whether we can use it
147
- async function isGitNotUsable(userRootDir) {
148
- // Check Git version
149
- {
150
- const res = await runCmd2('git --version', userRootDir);
151
- if ('err' in res)
152
- return true;
153
- let { stdout, stderr } = res;
154
- assert(stderr === '');
155
- const prefix = 'git version ';
156
- assert(stdout.startsWith(prefix));
157
- const gitVersion = stdout.slice(prefix.length);
158
- // - Works with Git 2.43.1 but also (most certainly) with earlier versions.
159
- // - We didn't bother test which is the earliest version that works.
160
- // - Git 2.32.0 doesn't seem to work: https://github.com/vikejs/vike/discussions/1549
161
- // - Maybe it's because of StackBlitz: looking at the release notes, Git 2.32.0 should be working.
162
- if (!isVersionMatch(gitVersion, ['2.43.1']))
163
- return true;
164
- }
165
- // Is userRootDir inside a Git repository?
166
- {
167
- const res = await runCmd2('git rev-parse --is-inside-work-tree', userRootDir);
168
- if ('err' in res)
169
- return true;
170
- let { stdout, stderr } = res;
171
- assert(stderr === '');
172
- assert(stdout === 'true');
173
- return false;
174
- }
175
- }
176
- async function runCmd1(cmd, cwd) {
177
- const { stdout } = await execA(cmd, {
178
- cwd,
179
- // https://github.com/vikejs/vike/issues/1982
180
- maxBuffer: Infinity,
181
- });
182
- /* Not always true: https://github.com/vikejs/vike/issues/1440#issuecomment-1892831303
183
- assert(res.stderr === '')
184
- */
185
- return stdout.toString().split('\n').filter(Boolean);
186
- }
187
- async function runCmd2(cmd, cwd) {
188
- let res;
189
- try {
190
- res = await execA(cmd, { cwd });
191
- }
192
- catch (err) {
193
- return { err };
194
- }
195
- let { stdout, stderr } = res;
196
- stdout = stdout.toString().trim();
197
- stderr = stderr.toString().trim();
198
- return { stdout, stderr };
199
- }
200
- function getUserSettings() {
201
- const userSettings = getEnvVarObject('VIKE_CRAWL') ?? {};
202
- const wrongUsage = (settingName, settingType) => `Setting ${pc.cyan(settingName)} in VIKE_CRAWL should be a ${pc.cyan(settingType)}`;
203
- assertUsage(hasProp(userSettings, 'git', 'boolean') || hasProp(userSettings, 'git', 'undefined'), wrongUsage('git', 'boolean'));
204
- assertUsage(hasProp(userSettings, 'ignore', 'string[]') ||
205
- hasProp(userSettings, 'ignore', 'string') ||
206
- hasProp(userSettings, 'ignore', 'undefined'), wrongUsage('git', 'string or an array of strings'));
207
- assertUsage(hasProp(userSettings, 'ignoreBuiltIn', 'boolean') || hasProp(userSettings, 'ignoreBuiltIn', 'undefined'), wrongUsage('ignoreBuiltIn', 'boolean'));
208
- const settingNames = ['git', 'ignore', 'ignoreBuiltIn'];
209
- Object.keys(userSettings).forEach((name) => {
210
- assertUsage(settingNames.includes(name), `Unknown setting ${pc.bold(pc.red(name))} in VIKE_CRAWL`);
211
- });
212
- return userSettings;
213
- }
214
- function isPlusFile(filePath) {
215
- assertPosixPath(filePath);
216
- if (isTemporaryBuildFile(filePath))
217
- return false;
218
- const fileName = filePath.split('/').pop();
219
- return fileName.startsWith('+');
220
- }
221
- function getPlusFileValueConfigName(filePath) {
222
- if (!isPlusFile(filePath))
223
- return null;
224
- const fileName = path.posix.basename(filePath);
225
- // assertNoUnexpectedPlusSign(filePath, fileName)
226
- const basename = fileName.split('.')[0];
227
- assert(basename.startsWith('+'));
228
- const configName = basename.slice(1);
229
- assertUsage(configName !== '', `${filePath} Invalid filename ${fileName}`);
230
- return configName;
231
- }
232
- /* https://github.com/vikejs/vike/issues/1407
233
- function assertNoUnexpectedPlusSign(filePath: string, fileName: string) {
234
- const dirs = path.posix.dirname(filePath).split('/')
235
- dirs.forEach((dir, i) => {
236
- const dirPath = dirs.slice(0, i + 1).join('/')
237
- assertUsage(
238
- !dir.includes('+'),
239
- `Character '+' is a reserved character: remove '+' from the directory name ${dirPath}/`
240
- )
241
- })
242
- assertUsage(
243
- !fileName.slice(1).includes('+'),
244
- `Character '+' is only allowed at the beginning of filenames: make sure ${filePath} doesn't contain any '+' in its filename other than its first letter`
245
- )
246
- }
247
- */
248
- function getIgnore(userSettings) {
249
- const ignorePatternsSetByUser = [userSettings.ignore].flat().filter(isNotNullish);
250
- const { ignoreBuiltIn } = userSettings;
251
- const ignorePatterns = [...(ignoreBuiltIn === false ? [] : ignorePatternsBuiltIn), ...ignorePatternsSetByUser];
252
- const ignoreMatchers = ignorePatterns.map((p) => picomatch(p, {
253
- // We must pass the same settings than tinyglobby
254
- // https://github.com/SuperchupuDev/tinyglobby/blob/fcfb08a36c3b4d48d5488c21000c95a956d9797c/src/index.ts#L191-L194
255
- dot: false,
256
- nocase: false,
257
- }));
258
- return { ignorePatterns, ignoreMatchers };
259
- }
@@ -1,2 +0,0 @@
1
- export { getRandomId };
2
- declare function getRandomId(length?: number): string;