vike 0.4.248 → 0.4.249-commit-55681da
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/bin.js +3 -0
- package/dist/client/runtime-client-routing/getPageContext.js +0 -2
- package/dist/client/runtime-client-routing/getPageContextFromHooks.d.ts +8 -8
- package/dist/client/runtime-client-routing/renderPageClient.d.ts +4 -4
- package/dist/node/api/utils.d.ts +2 -2
- package/dist/node/api/utils.js +2 -2
- package/dist/node/vite/plugins/build/pluginBuildConfig.js +2 -2
- package/dist/node/vite/plugins/pluginVirtualFiles.js +71 -113
- package/dist/node/vite/shared/loggerDev.d.ts +3 -0
- package/dist/node/vite/shared/loggerDev.js +29 -13
- package/dist/node/vite/shared/loggerVite.js +3 -3
- package/dist/node/vite/shared/resolveVikeConfigInternal/assertExtensions.d.ts +1 -1
- package/dist/node/vite/shared/resolveVikeConfigInternal/{crawlPlusFiles.d.ts → crawlPlusFilePaths.d.ts} +2 -2
- package/dist/node/vite/shared/resolveVikeConfigInternal/{crawlPlusFiles.js → crawlPlusFilePaths.js} +4 -4
- package/dist/node/vite/shared/resolveVikeConfigInternal/{getPlusFilesAll.d.ts → getPlusFilesByLocationId.d.ts} +8 -6
- package/dist/node/vite/shared/resolveVikeConfigInternal/{getPlusFilesAll.js → getPlusFilesByLocationId.js} +47 -59
- package/dist/node/vite/shared/resolveVikeConfigInternal/loadFileAtConfigTime.d.ts +1 -1
- package/dist/node/vite/shared/resolveVikeConfigInternal.d.ts +1 -1
- package/dist/node/vite/shared/resolveVikeConfigInternal.js +66 -64
- package/dist/server/runtime/asyncHook.d.ts +2 -2
- package/dist/server/runtime/asyncHook.js +2 -2
- package/dist/server/runtime/renderPageServer/html/stream.js +12 -13
- package/dist/server/utils.d.ts +2 -2
- package/dist/server/utils.js +2 -2
- package/dist/types/Config.d.ts +3 -2
- package/dist/types/PageConfig.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.js +1 -1
- package/dist/utils/assert.d.ts +7 -4
- package/dist/utils/assert.js +65 -50
- package/dist/utils/colorsClient.d.ts +6 -0
- package/dist/utils/colorsClient.js +16 -0
- package/dist/utils/{colors.js → colorsServer.js} +2 -0
- package/dist/utils/formatHintLog.js +1 -1
- package/dist/utils/getBetterError.js +11 -7
- package/dist/utils/shallowClone.d.ts +2 -0
- package/dist/utils/shallowClone.js +11 -0
- package/dist/utils/trimWithAnsi.js +1 -1
- package/package.json +6 -6
- package/dist/utils/colorVike.d.ts +0 -2
- package/dist/utils/colorVike.js +0 -5
- package/node/cli/bin.js +0 -3
- /package/dist/node/vite/shared/resolveVikeConfigInternal/{crawlPlusFiles → crawlPlusFilePaths}/ignorePatternsBuiltIn.d.ts +0 -0
- /package/dist/node/vite/shared/resolveVikeConfigInternal/{crawlPlusFiles → crawlPlusFilePaths}/ignorePatternsBuiltIn.js +0 -0
- /package/dist/utils/{colors.d.ts → colorsServer.d.ts} +0 -0
package/bin.js
ADDED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export { getPageContext };
|
|
2
2
|
export { providePageContext };
|
|
3
3
|
// TO-DO/eventually: create new setting `+asyncHook: true` that sets the default value of the `asyncHook` parameter below to `true`
|
|
4
|
-
// TODO/next-release: update vike-{react,vue,solid} usage
|
|
5
|
-
// TODO/next-release: contact Da-Jin about `window.history.state?.vike` https://vike.dev/navigate#history-pushstate
|
|
6
4
|
import { getPageContext_sync, providePageContext } from '../../shared-server-client/hooks/execHook.js';
|
|
7
5
|
import { getPageContextClient } from './renderPageClient.js';
|
|
8
6
|
function getPageContext({ asyncHook } = {}) {
|
|
@@ -136,7 +136,7 @@ declare function getPageContextFromHooksClient_firstRender(pageContext: PageCont
|
|
|
136
136
|
url: string;
|
|
137
137
|
pageExports: Record<string, unknown>;
|
|
138
138
|
isBaseMissing?: true;
|
|
139
|
-
}, "
|
|
139
|
+
}, "pageExports" | "exports" | "pageId" | "config" | "Page" | "data" | "routeParams" | "source" | "sources" | "from" | "configEntries" | "exportsAll" | "abortReason"> & {
|
|
140
140
|
isClientSide: true;
|
|
141
141
|
isPrerendering: false;
|
|
142
142
|
} & {
|
|
@@ -152,7 +152,7 @@ declare function getPageContextFromHooksClient_firstRender(pageContext: PageCont
|
|
|
152
152
|
urlParsed: import("./utils.js").UrlPublic;
|
|
153
153
|
urlPathname: string;
|
|
154
154
|
url: string;
|
|
155
|
-
},
|
|
155
|
+
}, "pageContextsAborted" | "previousPageContext" | ("globalContext" | "Page" | "data")> & {
|
|
156
156
|
previousPageContext: {
|
|
157
157
|
pageId: string;
|
|
158
158
|
} | null;
|
|
@@ -204,7 +204,7 @@ declare function getPageContextFromHooksClient_firstRender(pageContext: PageCont
|
|
|
204
204
|
url: string;
|
|
205
205
|
pageExports: Record<string, unknown>;
|
|
206
206
|
isBaseMissing?: true;
|
|
207
|
-
}, "
|
|
207
|
+
}, "pageExports" | "exports" | "pageId" | "config" | "Page" | "data" | "routeParams" | "source" | "sources" | "from" | "configEntries" | "exportsAll" | "abortReason"> & {
|
|
208
208
|
isClientSide: true;
|
|
209
209
|
isPrerendering: false;
|
|
210
210
|
} & {
|
|
@@ -220,7 +220,7 @@ declare function getPageContextFromHooksClient_firstRender(pageContext: PageCont
|
|
|
220
220
|
urlParsed: import("./utils.js").UrlPublic;
|
|
221
221
|
urlPathname: string;
|
|
222
222
|
url: string;
|
|
223
|
-
},
|
|
223
|
+
}, "pageContextsAborted" | "previousPageContext" | ("globalContext" | "Page" | "data")> & {
|
|
224
224
|
previousPageContext: {
|
|
225
225
|
pageId: string;
|
|
226
226
|
} | null;
|
|
@@ -362,7 +362,7 @@ declare function getPageContextFromHooksClient(pageContext: {
|
|
|
362
362
|
url: string;
|
|
363
363
|
pageExports: Record<string, unknown>;
|
|
364
364
|
isBaseMissing?: true;
|
|
365
|
-
}, "
|
|
365
|
+
}, "pageExports" | "exports" | "pageId" | "config" | "Page" | "data" | "routeParams" | "source" | "sources" | "from" | "configEntries" | "exportsAll" | "abortReason"> & {
|
|
366
366
|
isClientSide: true;
|
|
367
367
|
isPrerendering: false;
|
|
368
368
|
} & {
|
|
@@ -378,7 +378,7 @@ declare function getPageContextFromHooksClient(pageContext: {
|
|
|
378
378
|
urlParsed: import("./utils.js").UrlPublic;
|
|
379
379
|
urlPathname: string;
|
|
380
380
|
url: string;
|
|
381
|
-
},
|
|
381
|
+
}, "pageContextsAborted" | "previousPageContext" | ("globalContext" | "Page" | "data")> & {
|
|
382
382
|
previousPageContext: {
|
|
383
383
|
pageId: string;
|
|
384
384
|
} | null;
|
|
@@ -428,7 +428,7 @@ declare function getPageContextFromHooksClient(pageContext: {
|
|
|
428
428
|
url: string;
|
|
429
429
|
pageExports: Record<string, unknown>;
|
|
430
430
|
isBaseMissing?: true;
|
|
431
|
-
}, "
|
|
431
|
+
}, "pageExports" | "exports" | "pageId" | "config" | "Page" | "data" | "routeParams" | "source" | "sources" | "from" | "configEntries" | "exportsAll" | "abortReason"> & {
|
|
432
432
|
isClientSide: true;
|
|
433
433
|
isPrerendering: false;
|
|
434
434
|
} & {
|
|
@@ -444,7 +444,7 @@ declare function getPageContextFromHooksClient(pageContext: {
|
|
|
444
444
|
urlParsed: import("./utils.js").UrlPublic;
|
|
445
445
|
urlPathname: string;
|
|
446
446
|
url: string;
|
|
447
|
-
},
|
|
447
|
+
}, "pageContextsAborted" | "previousPageContext" | ("globalContext" | "Page" | "data")> & {
|
|
448
448
|
previousPageContext: {
|
|
449
449
|
pageId: string;
|
|
450
450
|
} | null;
|
|
@@ -149,7 +149,7 @@ declare function renderPageClient(renderArgs: RenderArgs): Promise<({
|
|
|
149
149
|
url: string;
|
|
150
150
|
pageExports: Record<string, unknown>;
|
|
151
151
|
isBaseMissing?: true;
|
|
152
|
-
}, "
|
|
152
|
+
}, "pageExports" | "exports" | "pageId" | "config" | "Page" | "data" | "routeParams" | "source" | "sources" | "from" | "configEntries" | "exportsAll" | "abortReason"> & {
|
|
153
153
|
isClientSide: true;
|
|
154
154
|
isPrerendering: false;
|
|
155
155
|
} & {
|
|
@@ -165,7 +165,7 @@ declare function renderPageClient(renderArgs: RenderArgs): Promise<({
|
|
|
165
165
|
urlParsed: import("./utils.js").UrlPublic;
|
|
166
166
|
urlPathname: string;
|
|
167
167
|
url: string;
|
|
168
|
-
},
|
|
168
|
+
}, "pageContextsAborted" | "previousPageContext" | ("globalContext" | "Page" | "data")> & {
|
|
169
169
|
previousPageContext: {
|
|
170
170
|
pageId: string;
|
|
171
171
|
} | null;
|
|
@@ -300,7 +300,7 @@ declare function getPageContextBegin(isForErrorPage: boolean, { urlOriginal, isB
|
|
|
300
300
|
url: string;
|
|
301
301
|
pageExports: Record<string, unknown>;
|
|
302
302
|
isBaseMissing?: true;
|
|
303
|
-
}, "
|
|
303
|
+
}, "pageExports" | "exports" | "pageId" | "config" | "Page" | "data" | "routeParams" | "source" | "sources" | "from" | "configEntries" | "exportsAll" | "abortReason"> & {
|
|
304
304
|
isClientSide: true;
|
|
305
305
|
isPrerendering: false;
|
|
306
306
|
} & {
|
|
@@ -316,7 +316,7 @@ declare function getPageContextBegin(isForErrorPage: boolean, { urlOriginal, isB
|
|
|
316
316
|
urlParsed: import("./utils.js").UrlPublic;
|
|
317
317
|
urlPathname: string;
|
|
318
318
|
url: string;
|
|
319
|
-
},
|
|
319
|
+
}, "pageContextsAborted" | "previousPageContext" | ("globalContext" | "Page" | "data")> & {
|
|
320
320
|
previousPageContext: {
|
|
321
321
|
pageId: string;
|
|
322
322
|
} | null;
|
package/dist/node/api/utils.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ export * from '../../utils/assertVersion.js';
|
|
|
6
6
|
export * from '../../utils/pick.js';
|
|
7
7
|
export * from '../../utils/assertSetup.js';
|
|
8
8
|
export * from '../../utils/isCallable.js';
|
|
9
|
-
export * from '../../utils/
|
|
10
|
-
export * from '../../utils/
|
|
9
|
+
export * from '../../utils/colorsServer.js';
|
|
10
|
+
export * from '../../utils/colorsClient.js';
|
|
11
11
|
export * from '../../utils/PROJECT_VERSION.js';
|
package/dist/node/api/utils.js
CHANGED
|
@@ -10,6 +10,6 @@ export * from '../../utils/assertVersion.js';
|
|
|
10
10
|
export * from '../../utils/pick.js';
|
|
11
11
|
export * from '../../utils/assertSetup.js';
|
|
12
12
|
export * from '../../utils/isCallable.js';
|
|
13
|
-
export * from '../../utils/
|
|
14
|
-
export * from '../../utils/
|
|
13
|
+
export * from '../../utils/colorsServer.js';
|
|
14
|
+
export * from '../../utils/colorsClient.js';
|
|
15
15
|
export * from '../../utils/PROJECT_VERSION.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { pluginBuildConfig };
|
|
2
2
|
export { assertRollupInput };
|
|
3
3
|
export { analyzeClientEntries };
|
|
4
|
-
import { assert,
|
|
4
|
+
import { assert, setAssertOnBeforeLog, removeFileExtension, unique, assertUsage, injectRollupInputs, normalizeRollupInput, onSetupBuild, assertIsImportPathNpmPackage, requireResolveDistFile, } from '../../utils.js';
|
|
5
5
|
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
6
6
|
import { findPageFiles } from '../../shared/findPageFiles.js';
|
|
7
7
|
import { generateVirtualFileId } from '../../../../shared-server-node/virtualFileId.js';
|
|
@@ -203,7 +203,7 @@ function addLogHook() {
|
|
|
203
203
|
'rendering chunks (',
|
|
204
204
|
'computing gzip size ('
|
|
205
205
|
];
|
|
206
|
-
|
|
206
|
+
setAssertOnBeforeLog(() => {
|
|
207
207
|
// Using viteTransientLogs is very conservative as clearing the current line is low risk. (We can assume that important messages, such as errors, include a trailing new line. Usually, only transient messages have no trailing new lines.)
|
|
208
208
|
if (viteTransientLogs.some((s) => lastLog?.startsWith(s))) {
|
|
209
209
|
process.stdout.clearLine(0);
|
|
@@ -9,7 +9,7 @@ import pc from '@brillout/picocolors';
|
|
|
9
9
|
import { logConfigInfo } from '../shared/loggerDev.js';
|
|
10
10
|
import { getFilePathToShowToUserModule } from '../shared/getFilePath.js';
|
|
11
11
|
import { updateUserFiles } from '../../../server/runtime/globalContext.js';
|
|
12
|
-
import { isPlusFile } from '../shared/resolveVikeConfigInternal/
|
|
12
|
+
import { isPlusFile } from '../shared/resolveVikeConfigInternal/crawlPlusFilePaths.js';
|
|
13
13
|
import { isTemporaryBuildFile } from '../shared/resolveVikeConfigInternal/transpileAndExecuteFile.js';
|
|
14
14
|
import { debugFileChange, getVikeConfigError } from '../../../shared-server-node/getVikeConfigError.js';
|
|
15
15
|
const filterRolldown = {
|
|
@@ -38,11 +38,12 @@ function pluginVirtualFiles() {
|
|
|
38
38
|
return addVirtualFileIdPrefix(id);
|
|
39
39
|
},
|
|
40
40
|
},
|
|
41
|
+
// Vite calls handleHotUpdate() whenever *any file* is modified — including files that aren't in Vite's module graph such as +config.js
|
|
41
42
|
handleHotUpdate: {
|
|
42
43
|
async handler(ctx) {
|
|
43
44
|
debugFileChange('handleHotUpdate()', ctx.file);
|
|
44
45
|
try {
|
|
45
|
-
return await
|
|
46
|
+
return await onFileModified(ctx, config);
|
|
46
47
|
}
|
|
47
48
|
catch (err) {
|
|
48
49
|
// Vite swallows errors thrown by handleHotUpdate()
|
|
@@ -73,106 +74,89 @@ function pluginVirtualFiles() {
|
|
|
73
74
|
},
|
|
74
75
|
configureServer: {
|
|
75
76
|
handler(server) {
|
|
76
|
-
|
|
77
|
+
server.watcher.prependListener('add', (file) => onFileCreatedOrRemoved(file, false, server, config));
|
|
78
|
+
server.watcher.prependListener('unlink', (file) => onFileCreatedOrRemoved(file, true, server, config));
|
|
77
79
|
},
|
|
78
80
|
},
|
|
79
81
|
},
|
|
80
82
|
];
|
|
81
83
|
}
|
|
82
|
-
function
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
84
|
+
async function onFileModified(ctx, config) {
|
|
85
|
+
const { file, server } = ctx;
|
|
86
|
+
const isAppFile = await isAppDependency(ctx.file, ctx.server.moduleGraph);
|
|
87
|
+
debugFileChange(isAppFile);
|
|
88
|
+
if (!isAppFile)
|
|
89
|
+
return;
|
|
90
|
+
const reloadVikeConfig = () => reloadConfig(file, config, 'modified', server);
|
|
91
|
+
if (isAppFile.isRuntimeDependency) {
|
|
92
|
+
// Ensure we invalidate `file` *before* server.ssrLoadModule() in updateUserFiles()
|
|
93
|
+
// Vite also invalidates it, but *after* handleHotUpdate() and thus after server.ssrLoadModule()
|
|
94
|
+
ctx.modules.forEach((mod) => server.moduleGraph.invalidateModule(mod));
|
|
95
|
+
// Re-running ssrLoadModule() is cheap (Vite uses a cache) => eagerly calling updateUserFiles() makes sense.
|
|
96
|
+
// - Even for SPA apps that don't have (m)any server files? Ideally, we should set `isRuntimeDependency: true` only for server modules (let's do it once Vite has a clear separate per-environment module graphs).
|
|
97
|
+
await updateUserFiles();
|
|
98
|
+
}
|
|
99
|
+
if (isAppFile.isConfigDependency) {
|
|
100
|
+
/* Tailwind breaks this assertion, see https://github.com/vikejs/vike/discussions/1330#discussioncomment-7787238
|
|
101
|
+
const isViteModule = ctx.modules.length > 0
|
|
102
|
+
assert(!isViteModule)
|
|
103
|
+
*/
|
|
104
|
+
reloadVikeConfig();
|
|
105
|
+
// Trigger a full page reload. (Because files such as +config.js can potentially modify Vike's virtual files.)
|
|
106
|
+
const vikeVirtualFiles = getVikeVirtualFiles(server);
|
|
107
|
+
return vikeVirtualFiles;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async function onFileCreatedOrRemoved(file, isRemove, server, config) {
|
|
111
|
+
file = normalizePath(file);
|
|
112
|
+
if (isTemporaryBuildFile(file))
|
|
113
|
+
return;
|
|
114
|
+
const operation = isRemove ? 'removed' : 'created';
|
|
115
|
+
debugFileChange('server.watcher', file, operation);
|
|
116
|
+
const { moduleGraph } = server;
|
|
117
|
+
const isAppFile = await isAppDependency(file, moduleGraph);
|
|
118
|
+
const reloadVikeConfig = () => reloadConfig(file, config, operation, server);
|
|
119
|
+
if (
|
|
120
|
+
// Vike config (non-runtime) code
|
|
121
|
+
isAppFile?.isConfigDependency ||
|
|
122
|
+
// New + file => not tracked yet by Vike (`vikeConfigObject._vikeConfigDependencies`) nor Vite (`moduleGraph`)
|
|
123
|
+
isPlusFile(file) ||
|
|
124
|
+
// Trick: when fixing the path of a relative import => we don't know whether `file` is the imported file => we take a leap of faith when the conditions below are met.
|
|
125
|
+
// - Reloading Vike's config is cheap => eagerly reloading it makes sense when it's in an erroneous state.
|
|
111
126
|
// - Not sure how reliable that trick is.
|
|
112
|
-
// - Reloading Vike's config is cheap and file creation/removal is rare => the trick is worth it.
|
|
113
127
|
// - Reproduction:
|
|
114
128
|
// ```bash
|
|
115
|
-
// rm
|
|
129
|
+
// rm someImportedFile.js && sleep 2 && git checkout someImportedFile.js
|
|
116
130
|
// ```
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
131
|
+
(isScriptFile(file) && getVikeConfigError())) {
|
|
132
|
+
reloadVikeConfig();
|
|
121
133
|
}
|
|
122
134
|
}
|
|
123
|
-
function
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
// Vite calls its hook handleHotUpdate() whenever *any file* is modified — including files that aren't in Vite's module graph such as `pages/+config.js`
|
|
130
|
-
async function handleHotUpdate(ctx, config) {
|
|
131
|
-
const { file, server } = ctx;
|
|
132
|
-
const isVikeConfigDep = await isVikeConfigDependency(ctx.file, ctx.server.moduleGraph);
|
|
133
|
-
debugFileChange(isVikeConfigDep);
|
|
134
|
-
if (isVikeConfigDep) {
|
|
135
|
-
if (!isVikeConfigDep.isProcessedByVite) {
|
|
136
|
-
/* Tailwind breaks this assertion, see https://github.com/vikejs/vike/discussions/1330#discussioncomment-7787238
|
|
137
|
-
const isViteModule = ctx.modules.length > 0
|
|
138
|
-
assert(!isViteModule)
|
|
139
|
-
*/
|
|
140
|
-
reloadConfig(file, config, 'modified', server);
|
|
141
|
-
// Files such as `pages/+config.js` can potentially modify Vike's virtual files.
|
|
142
|
-
// Triggers a full page reload
|
|
143
|
-
const vikeVirtualFiles = getVikeVirtualFiles(server);
|
|
144
|
-
return vikeVirtualFiles;
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
// Ensure we invalidate `file` *before* server.ssrLoadModule() in updateUserFiles()
|
|
148
|
-
// Vite also invalidates it, but *after* handleHotUpdate() and thus after server.ssrLoadModule()
|
|
149
|
-
ctx.modules.forEach((mod) => server.moduleGraph.invalidateModule(mod));
|
|
150
|
-
await updateUserFiles();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
async function isVikeConfigDependency(filePathAbsoluteFilesystem, moduleGraph) {
|
|
155
|
-
// Non-runtime Vike config files such as `pages/+config.js` which aren't processed by Vite.
|
|
135
|
+
async function isAppDependency(filePathAbsoluteFilesystem, moduleGraph) {
|
|
136
|
+
const isAppFile = {};
|
|
137
|
+
// =============================
|
|
138
|
+
// { isConfigDependency: false }
|
|
139
|
+
// =============================
|
|
140
|
+
// Vike config (non-runtime) files such as +config.js which aren't processed by Vite.
|
|
156
141
|
// - They're missing in Vite's module graph.
|
|
157
142
|
// - Potentially modifies Vike's virtual files.
|
|
158
|
-
// - Same for all `pages/+config.js` dependencies.
|
|
143
|
+
// - Same for all `pages/+config.js` transitive dependencies.
|
|
159
144
|
assertPosixPath(filePathAbsoluteFilesystem);
|
|
160
145
|
const vikeConfigObject = await getVikeConfigInternalOptional();
|
|
161
146
|
if (vikeConfigObject) {
|
|
162
147
|
const { _vikeConfigDependencies: vikeConfigDependencies } = vikeConfigObject;
|
|
163
148
|
vikeConfigDependencies.forEach((f) => assertPosixPath(f));
|
|
164
|
-
|
|
165
|
-
return { isProcessedByVite: false };
|
|
149
|
+
isAppFile.isConfigDependency = vikeConfigDependencies.has(filePathAbsoluteFilesystem);
|
|
166
150
|
}
|
|
167
|
-
//
|
|
151
|
+
// =============================
|
|
152
|
+
// { isRuntimeDependency: true }
|
|
153
|
+
// =============================
|
|
154
|
+
// Vike runtime files such as +data.js which are processed by Vite.
|
|
168
155
|
// - They're included in Vite's module graph.
|
|
169
156
|
// - They never modify Vike's virtual files.
|
|
170
|
-
// - Same for all `+data.js` dependencies.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (isPlusValueFileDependency)
|
|
174
|
-
return { isProcessedByVite: true };
|
|
175
|
-
return null;
|
|
157
|
+
// - Same for all `+data.js` transitive dependencies.
|
|
158
|
+
isAppFile.isRuntimeDependency = existsInViteModuleGraph(filePathAbsoluteFilesystem, moduleGraph);
|
|
159
|
+
return isAppFile;
|
|
176
160
|
}
|
|
177
161
|
function reloadConfig(filePath, config, operation, server) {
|
|
178
162
|
// Ensure server.ssrLoadModule() loads fresh Vike virtual files (`reloadConfig()` > `updateUserFiles()` > `server.ssrLoadModule()`)
|
|
@@ -185,6 +169,12 @@ function reloadConfig(filePath, config, operation, server) {
|
|
|
185
169
|
reloadVikeConfig();
|
|
186
170
|
updateUserFiles();
|
|
187
171
|
}
|
|
172
|
+
function invalidateVikeVirtualFiles(server) {
|
|
173
|
+
const vikeVirtualFiles = getVikeVirtualFiles(server);
|
|
174
|
+
vikeVirtualFiles.forEach((mod) => {
|
|
175
|
+
server.moduleGraph.invalidateModule(mod);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
188
178
|
function getVikeVirtualFiles(server) {
|
|
189
179
|
const vikeVirtualFiles = Array.from(server.moduleGraph.urlToModuleMap.keys())
|
|
190
180
|
.filter((url) => parseVirtualFileId(url))
|
|
@@ -195,38 +185,6 @@ function getVikeVirtualFiles(server) {
|
|
|
195
185
|
});
|
|
196
186
|
return vikeVirtualFiles;
|
|
197
187
|
}
|
|
198
|
-
// Get all transitive importers (including the module itself)
|
|
199
|
-
function getImporters(file, moduleGraph) {
|
|
200
|
-
const importers = new Set();
|
|
201
|
-
const mods = moduleGraph.getModulesByFile(file);
|
|
202
|
-
if (!mods)
|
|
203
|
-
return importers;
|
|
204
|
-
for (const mod of mods) {
|
|
205
|
-
getModuleImporters(mod).forEach((importer) => {
|
|
206
|
-
if (importer)
|
|
207
|
-
importers.add(importer);
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
return importers;
|
|
211
|
-
}
|
|
212
|
-
function getModuleImporters(mod, seen = new Set()) {
|
|
213
|
-
if (seen.has(mod))
|
|
214
|
-
return new Set();
|
|
215
|
-
seen.add(mod);
|
|
216
|
-
const importers = new Set();
|
|
217
|
-
if (mod.id)
|
|
218
|
-
importers.add(mod);
|
|
219
|
-
// Traverse through the importers (modules that import this module)
|
|
220
|
-
for (const importer of mod.importers) {
|
|
221
|
-
if (importer.id)
|
|
222
|
-
importers.add(importer);
|
|
223
|
-
getModuleImporters(importer, seen).forEach((importerTransitive) => {
|
|
224
|
-
if (importerTransitive)
|
|
225
|
-
importers.add(importerTransitive);
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
return importers;
|
|
229
|
-
}
|
|
230
188
|
function existsInViteModuleGraph(file, moduleGraph) {
|
|
231
189
|
return !!moduleGraph.getModulesByFile(file);
|
|
232
190
|
}
|
|
@@ -2,8 +2,11 @@ export { logVite };
|
|
|
2
2
|
export { logConfigInfo };
|
|
3
3
|
export { logErrorServerDev };
|
|
4
4
|
export type { LogType };
|
|
5
|
+
export type { AddTagsDev };
|
|
5
6
|
import { type PageContext_logRuntime } from '../../../server/runtime/loggerRuntime.js';
|
|
6
7
|
type LogType = 'info' | 'warn' | 'error' | 'error-resolve';
|
|
7
8
|
declare function logConfigInfo(msg: string, logType: LogType): void;
|
|
8
9
|
declare function logVite(msg: string, logType: LogType, requestId: number | null, prependViteTag: boolean): void;
|
|
9
10
|
declare function logErrorServerDev(err: unknown, pageContext: PageContext_logRuntime, errorComesFromVite?: boolean): void;
|
|
11
|
+
type AddTagsDev = typeof addTagsDev;
|
|
12
|
+
declare function addTagsDev<TagVike extends string, TagType extends string>(tagVike: TagVike, tagType: TagType): `1:37:00 PM ${TagVike}[request(n)]${TagType}`;
|
|
@@ -12,7 +12,7 @@ export { logErrorServerDev };
|
|
|
12
12
|
import { isAbortError } from '../../../shared-server-client/route/abort.js';
|
|
13
13
|
import { getViteConfig } from '../../../server/runtime/globalContext.js';
|
|
14
14
|
import { assertPageContext_logRuntime, setLogRuntimeDev, } from '../../../server/runtime/loggerRuntime.js';
|
|
15
|
-
import {
|
|
15
|
+
import { setAssertOnBeforeErr, assert, assertIsNotProductionRuntime, colorVike, colorVite, formatHintLog, hasGreen, hasProp, hasRed, hasYellow, isDebugError, stripAnsi, colorError, colorWarning, setAssertAddTagsDev, } from '../utils.js';
|
|
16
16
|
import { isErrorWithCodeSnippet, getPrettyErrorWithCodeSnippet } from './loggerDev/errorWithCodeSnippet.js';
|
|
17
17
|
import { getConfigExecutionErrorIntroMsg, getConfigBuildErrorFormatted, } from './resolveVikeConfigInternal/transpileAndExecuteFile.js';
|
|
18
18
|
import pc from '@brillout/picocolors';
|
|
@@ -20,13 +20,14 @@ import { isUserHookError } from '../../../shared-server-client/hooks/execHook.js
|
|
|
20
20
|
import { getViteDevServer } from '../../../server/runtime/globalContext.js';
|
|
21
21
|
import { logErrorServer } from '../../../server/runtime/logErrorServer.js';
|
|
22
22
|
import { getBetterError } from '../../../utils/getBetterError.js';
|
|
23
|
-
import {
|
|
23
|
+
import { getRequestId_withAsyncHook } from '../../../server/runtime/asyncHook.js';
|
|
24
24
|
assertIsNotProductionRuntime();
|
|
25
25
|
setLogRuntimeDev(logErrorServerDev, logRuntimeInfoDev);
|
|
26
|
-
|
|
26
|
+
setAssertOnBeforeErr((err) => {
|
|
27
27
|
// We must directly apply vite.ssrFixStacktrace() to `assertWarning(..., { showStackTrace: true })` because warnings aren't caught by the try-catch of renderPageServer()
|
|
28
|
-
|
|
28
|
+
applyViteSourceMap(err);
|
|
29
29
|
});
|
|
30
|
+
setAssertAddTagsDev(addTagsDev);
|
|
30
31
|
// Note shown to user when Vike completely modifies the error message (which is somewhat risky)
|
|
31
32
|
const errorDebugNote = pc.dim(formatHintLog("Error isn't helpful? See https://vike.dev/debug#verbose-errors"));
|
|
32
33
|
function logRuntimeInfoDev(msg, pageContext, logType) {
|
|
@@ -44,7 +45,7 @@ function logVite(msg, logType, requestId, prependViteTag) {
|
|
|
44
45
|
}
|
|
45
46
|
function logErrorServerDev(err, pageContext, errorComesFromVite = false) {
|
|
46
47
|
assertPageContext_logRuntime(pageContext);
|
|
47
|
-
|
|
48
|
+
applyViteSourceMap(err);
|
|
48
49
|
// Skip `throw render()` / `throw redirect()`
|
|
49
50
|
if (isAbortError(err) && !isDebugError()) {
|
|
50
51
|
return;
|
|
@@ -96,7 +97,7 @@ function logErrorServerDev(err, pageContext, errorComesFromVite = false) {
|
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
if (tagSource) {
|
|
99
|
-
const errIntro =
|
|
100
|
+
const errIntro = colorError(`[Error] ${errorComesFromVite ? 'Transpilation error' : 'An error was thrown'}:`);
|
|
100
101
|
const prepend = `${getTagsError(errIntro, tagSource)}${errIntro}\n`;
|
|
101
102
|
const errBetter = getBetterError(err, { message: { prepend } });
|
|
102
103
|
logErr(errBetter);
|
|
@@ -128,7 +129,7 @@ function logDev(msg, logType, tagSource, tagTool, doNotAddTags) {
|
|
|
128
129
|
assert(false);
|
|
129
130
|
}
|
|
130
131
|
function getTagSource(requestId = null) {
|
|
131
|
-
const requestIdFromStore =
|
|
132
|
+
const requestIdFromStore = getRequestId_withAsyncHook();
|
|
132
133
|
if (requestIdFromStore !== null) {
|
|
133
134
|
if (requestId === null) {
|
|
134
135
|
requestId = requestIdFromStore;
|
|
@@ -143,7 +144,7 @@ function getTagSource(requestId = null) {
|
|
|
143
144
|
const tagSource = `request-${requestId}`;
|
|
144
145
|
return tagSource;
|
|
145
146
|
}
|
|
146
|
-
function
|
|
147
|
+
function applyViteSourceMap(thing) {
|
|
147
148
|
if (isDebugError())
|
|
148
149
|
return;
|
|
149
150
|
if (!hasProp(thing, 'stack'))
|
|
@@ -160,20 +161,35 @@ function getTagsError(msg, tagSource) {
|
|
|
160
161
|
function getTags(msg, tagTool, tagSource, logType) {
|
|
161
162
|
const tagToolColored = (() => {
|
|
162
163
|
if (logType === 'error' && !hasRed(msg))
|
|
163
|
-
return
|
|
164
|
+
return colorError(tagTool);
|
|
164
165
|
if (logType === 'error-resolve' && !hasGreen(msg))
|
|
165
166
|
return pc.bold(pc.green(tagTool));
|
|
166
167
|
if (logType === 'warn' && !hasYellow(msg))
|
|
167
|
-
return
|
|
168
|
+
return colorWarning(tagTool);
|
|
168
169
|
if (tagTool === '[vite]')
|
|
169
170
|
return colorVite(tagTool);
|
|
170
171
|
if (tagTool === '[vike]')
|
|
171
172
|
return colorVike(tagTool);
|
|
172
173
|
assert(false);
|
|
173
174
|
})();
|
|
174
|
-
const timestamp =
|
|
175
|
+
const timestamp = getTagTimestamp();
|
|
175
176
|
const whitespace = (/\s|\[/.test(stripAnsi(msg)[0]) ? '' : ' ');
|
|
176
|
-
const
|
|
177
|
-
const tags = `${timestamp} ${tagToolColored}${
|
|
177
|
+
const tagSourceOuter = getTagSourceOuter(tagSource);
|
|
178
|
+
const tags = `${timestamp} ${tagToolColored}${tagSourceOuter}${whitespace}`;
|
|
178
179
|
return tags;
|
|
179
180
|
}
|
|
181
|
+
function getTagTimestamp() {
|
|
182
|
+
const timestamp = pc.dim(new Date().toLocaleTimeString());
|
|
183
|
+
return timestamp;
|
|
184
|
+
}
|
|
185
|
+
function getTagSourceOuter(tagSource) {
|
|
186
|
+
const tagSourceOuter = (!tagSource ? '' : pc.dim(`[${tagSource}]`));
|
|
187
|
+
return tagSourceOuter;
|
|
188
|
+
}
|
|
189
|
+
function addTagsDev(tagVike, tagType) {
|
|
190
|
+
const timestamp = getTagTimestamp();
|
|
191
|
+
const tagSource = getTagSource();
|
|
192
|
+
const tagSourceOuter = getTagSourceOuter(tagSource);
|
|
193
|
+
const tagsDev = `${timestamp} ${tagVike}${tagSourceOuter}${tagType}`;
|
|
194
|
+
return tagsDev;
|
|
195
|
+
}
|
|
@@ -5,7 +5,7 @@ export { swallowViteLogForceOptimization_disable };
|
|
|
5
5
|
export { swallowViteLogConnected };
|
|
6
6
|
export { swallowViteLogConnected_clean };
|
|
7
7
|
import { assert, getGlobalObject, isDebugError, removeEmptyLines, trimWithAnsi, trimWithAnsiTrailOnly, } from '../utils.js';
|
|
8
|
-
import {
|
|
8
|
+
import { getRequestId_withAsyncHook } from '../../../server/runtime/asyncHook.js';
|
|
9
9
|
import { logErrorServerDev, logVite } from './loggerDev.js';
|
|
10
10
|
const globalObject = getGlobalObject('vite/shared/loggerDev.ts', {
|
|
11
11
|
processStartupLog_isCompact: null,
|
|
@@ -43,7 +43,7 @@ function intercept(loggerType, config) {
|
|
|
43
43
|
// - It doesn't format error code snippets.
|
|
44
44
|
// - It only shows error.message which means that crucial information such as error.id isn't shown to the user.
|
|
45
45
|
logErrorServerDev(options.error, null, true);
|
|
46
|
-
// We swallow Vite's message:
|
|
46
|
+
// We swallow Vite's message: it doesn't seem to add any value.
|
|
47
47
|
// - It can even be confusing, such as the following:
|
|
48
48
|
// ```
|
|
49
49
|
// Error when evaluating SSR module virtual:vike:page-entry:server:/pages/abort: failed to import "/pages/abort/+Page.mdx"
|
|
@@ -51,7 +51,7 @@ function intercept(loggerType, config) {
|
|
|
51
51
|
assert(!isDebugError());
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
|
-
const requestId =
|
|
54
|
+
const requestId = getRequestId_withAsyncHook();
|
|
55
55
|
// Vite's default logger preprends the "[vite]" tag if and only if options.timestamp is true
|
|
56
56
|
const prependViteTag = options.timestamp || typeof requestId === 'number';
|
|
57
57
|
// If it's an actual error => options.error is set => it's handled with logErrorServerDev() above
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { assertExtensionsConventions };
|
|
2
2
|
export { assertExtensionsRequire };
|
|
3
|
-
import type { PlusFile } from './
|
|
3
|
+
import type { PlusFile } from './getPlusFilesByLocationId.js';
|
|
4
4
|
declare function assertExtensionsConventions(plusFile: PlusFile): void;
|
|
5
5
|
declare function assertExtensionsRequire(plusFiles: PlusFile[]): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { crawlPlusFilePaths };
|
|
2
2
|
export { isPlusFile };
|
|
3
3
|
export { getPlusFileValueConfigName };
|
|
4
|
-
declare function
|
|
4
|
+
declare function crawlPlusFilePaths(userRootDir: string): Promise<{
|
|
5
5
|
filePathAbsoluteUserRootDir: string;
|
|
6
6
|
}[]>;
|
|
7
7
|
declare function isPlusFile(filePath: string): boolean;
|
package/dist/node/vite/shared/resolveVikeConfigInternal/{crawlPlusFiles.js → crawlPlusFilePaths.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { crawlPlusFilePaths };
|
|
2
2
|
export { isPlusFile };
|
|
3
3
|
export { getPlusFileValueConfigName };
|
|
4
4
|
import { assertPosixPath, assert, scriptFileExtensionPattern, assertIsNotProductionRuntime, isVersionMatch, isScriptFile, scriptFileExtensionList, createDebug, deepEqual, assertUsage, assertFilePathAbsoluteFilesystem, assertWarning, hasProp, isNotNullish, getGlobalObject, } from '../../utils.js';
|
|
@@ -10,14 +10,14 @@ import { isTemporaryBuildFile } from './transpileAndExecuteFile.js';
|
|
|
10
10
|
import { getEnvVarObject } from '../getEnvVarObject.js';
|
|
11
11
|
import pc from '@brillout/picocolors';
|
|
12
12
|
import picomatch from 'picomatch';
|
|
13
|
-
import { ignorePatternsBuiltIn } from './
|
|
13
|
+
import { ignorePatternsBuiltIn } from './crawlPlusFilePaths/ignorePatternsBuiltIn.js';
|
|
14
14
|
const execA = promisify(exec);
|
|
15
15
|
const debug = createDebug('vike:crawl');
|
|
16
16
|
assertIsNotProductionRuntime();
|
|
17
|
-
const globalObject = getGlobalObject('getVikeConfig/
|
|
17
|
+
const globalObject = getGlobalObject('getVikeConfig/crawlPlusFilePaths.ts', {
|
|
18
18
|
gitIsNotUsable: false,
|
|
19
19
|
});
|
|
20
|
-
async function
|
|
20
|
+
async function crawlPlusFilePaths(userRootDir) {
|
|
21
21
|
assertPosixPath(userRootDir);
|
|
22
22
|
assertFilePathAbsoluteFilesystem(userRootDir);
|
|
23
23
|
const userSettings = getUserSettings();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { getPlusFilesByLocationId };
|
|
2
2
|
export type { PlusFileValue };
|
|
3
3
|
export type { PlusFile };
|
|
4
4
|
export type { PlusFilesByLocationId };
|
|
@@ -7,21 +7,23 @@ import { type EsbuildCache } from './transpileAndExecuteFile.js';
|
|
|
7
7
|
import { PointerImportLoaded } from './loadFileAtConfigTime.js';
|
|
8
8
|
import type { FilePathResolved } from '../../../../types/FilePath.js';
|
|
9
9
|
type PlusFile = PlusFileConfig | PlusFileValue;
|
|
10
|
-
type
|
|
10
|
+
type PlusFileCommon = {
|
|
11
11
|
locationId: LocationId;
|
|
12
12
|
filePath: FilePathResolved;
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
/** +config.js */
|
|
15
|
+
type PlusFileConfig = PlusFileCommon & {
|
|
15
16
|
isConfigFile: true;
|
|
16
17
|
fileExportsByConfigName: Record<string, // configName
|
|
17
18
|
unknown>;
|
|
18
19
|
pointerImportsByConfigName: Record<string, // configName
|
|
19
|
-
PointerImportLoaded>;
|
|
20
|
+
PointerImportLoaded[]>;
|
|
20
21
|
isExtensionConfig: boolean;
|
|
21
22
|
extendsFilePaths: string[];
|
|
22
23
|
isNotLoaded?: undefined;
|
|
23
24
|
};
|
|
24
|
-
|
|
25
|
+
/** +{configName}.js */
|
|
26
|
+
type PlusFileValue = PlusFileCommon & {
|
|
25
27
|
isConfigFile: false;
|
|
26
28
|
configName: string;
|
|
27
29
|
} & ({
|
|
@@ -34,4 +36,4 @@ type PlusFileValue = PlusFileCommons & {
|
|
|
34
36
|
isExtensionConfig?: undefined;
|
|
35
37
|
};
|
|
36
38
|
type PlusFilesByLocationId = Record<LocationId, PlusFile[]>;
|
|
37
|
-
declare function
|
|
39
|
+
declare function getPlusFilesByLocationId(userRootDir: string, esbuildCache: EsbuildCache): Promise<PlusFilesByLocationId>;
|