vike 0.4.161-commit-b829fee → 0.4.162-commit-49fe40c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/__internal/index.js +2 -2
- package/dist/cjs/node/plugin/index.js +0 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +1 -0
- package/dist/cjs/node/plugin/plugins/config/index.js +2 -7
- package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -8
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -18
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +2 -4
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +0 -19
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +8 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +1 -9
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +4 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js +35 -36
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +109 -104
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +36 -32
- package/dist/cjs/node/plugin/utils.js +0 -1
- package/dist/cjs/node/prerender/runPrerender.js +2 -2
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +1 -0
- package/dist/cjs/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +2 -3
- package/dist/cjs/node/runtime/utils.js +1 -2
- package/dist/cjs/node/shared/virtual-files/virtualFileImportUserCode.js +1 -0
- package/dist/cjs/shared/hooks/getHook.js +1 -1
- package/dist/cjs/shared/page-configs/helpers/getConfigValue.js +1 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +1 -1
- package/dist/cjs/shared/route/abort.js +1 -0
- package/dist/cjs/shared/route/resolvePrecedence.js +1 -0
- package/dist/cjs/utils/{nodeEnv.js → assertNodeEnv.js} +3 -0
- package/dist/cjs/utils/formatHintLog.js +1 -0
- package/dist/cjs/utils/hasProp.js +1 -0
- package/dist/cjs/utils/isScriptFile.js +15 -4
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/__internal/index.js +1 -1
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +20 -14
- package/dist/esm/client/shared/getPageContextProxyForUser.js +19 -2
- package/dist/esm/client/shared/loadUserFilesClientSide.js +1 -0
- package/dist/esm/node/plugin/index.js +0 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +1 -0
- package/dist/esm/node/plugin/plugins/config/index.js +2 -7
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -8
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -19
- package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -4
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +0 -19
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +8 -8
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +1 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.d.ts +1 -13
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js +35 -36
- 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 +111 -106
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +36 -32
- package/dist/esm/node/plugin/utils.d.ts +0 -1
- package/dist/esm/node/plugin/utils.js +0 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +3 -3
- package/dist/esm/node/prerender/runPrerender.js +2 -2
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +1 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +2 -3
- package/dist/esm/node/runtime/utils.d.ts +1 -2
- package/dist/esm/node/runtime/utils.js +1 -2
- package/dist/esm/node/shared/virtual-files/virtualFileImportUserCode.js +1 -0
- package/dist/esm/shared/ConfigVike.d.ts +0 -27
- package/dist/esm/shared/hooks/getHook.js +2 -2
- package/dist/esm/shared/page-configs/Config.d.ts +5 -0
- package/dist/esm/shared/page-configs/PageConfig.d.ts +1 -1
- package/dist/esm/shared/page-configs/helpers/getConfigValue.js +1 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +1 -1
- package/dist/esm/shared/route/abort.js +1 -0
- package/dist/esm/shared/route/resolvePrecedence.js +1 -0
- package/dist/esm/utils/{nodeEnv.js → assertNodeEnv.js} +3 -0
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/formatHintLog.js +1 -0
- package/dist/esm/utils/hasProp.js +1 -0
- package/dist/esm/utils/isScriptFile.d.ts +3 -1
- package/dist/esm/utils/isScriptFile.js +14 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +3 -2
- package/dist/cjs/node/plugin/plugins/config/findConfigVikeFromStemPackages.js +0 -27
- package/dist/cjs/node/plugin/plugins/config/resolveExtensions.js +0 -107
- package/dist/cjs/node/plugin/plugins/config/stemUtils.js +0 -85
- package/dist/cjs/node/plugin/plugins/extensionsAssets.js +0 -101
- package/dist/cjs/utils/getDependencyPackageJson.js +0 -91
- package/dist/cjs/utils/isStemPackageName.js +0 -14
- package/dist/esm/node/plugin/plugins/config/findConfigVikeFromStemPackages.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/config/findConfigVikeFromStemPackages.js +0 -24
- package/dist/esm/node/plugin/plugins/config/resolveExtensions.d.ts +0 -4
- package/dist/esm/node/plugin/plugins/config/resolveExtensions.js +0 -101
- package/dist/esm/node/plugin/plugins/config/stemUtils.d.ts +0 -8
- package/dist/esm/node/plugin/plugins/config/stemUtils.js +0 -79
- package/dist/esm/node/plugin/plugins/extensionsAssets.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/extensionsAssets.js +0 -95
- package/dist/esm/utils/getDependencyPackageJson.d.ts +0 -6
- package/dist/esm/utils/getDependencyPackageJson.js +0 -85
- package/dist/esm/utils/isStemPackageName.d.ts +0 -1
- package/dist/esm/utils/isStemPackageName.js +0 -10
- /package/dist/esm/utils/{nodeEnv.d.ts → assertNodeEnv.d.ts} +0 -0
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js
CHANGED
|
@@ -2,52 +2,55 @@ export { transformFileImports };
|
|
|
2
2
|
export { parseImportData };
|
|
3
3
|
export { isImportData };
|
|
4
4
|
// Playground: https://github.com/brillout/acorn-playground
|
|
5
|
-
//
|
|
6
|
-
//
|
|
5
|
+
// Notes about `with { type: 'pointer' }`
|
|
6
|
+
// - It works well with TypeScript: it doesn't complain upon `with { type: 'unknown-to-typescript' }` and go-to-definition & types are preserved: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#import-attributes
|
|
7
|
+
// - Acorn support for import attributes: https://github.com/acornjs/acorn/issues/983
|
|
8
|
+
// - Acorn plugin: https://github.com/acornjs/acorn/issues/983
|
|
9
|
+
// - Isn't stage 4 yet: https://github.com/tc39/proposal-import-attributes
|
|
10
|
+
// - Using a import path suffix such as `import { Layout } from './Layout?real` breaks TypeScript, and TypeScript isn't working on supporting query params: https://github.com/microsoft/TypeScript/issues/10988#issuecomment-867135453
|
|
11
|
+
// - Node.js >=21 supports import attribtues: https://nodejs.org/api/esm.html#import-attributes
|
|
12
|
+
// - Esbuid supports
|
|
13
|
+
// - Blocker: https://github.com/evanw/esbuild/issues/3646
|
|
14
|
+
// - Ugly hack to make it work: https://github.com/brillout/esbuild-playground/tree/experiment/import-attribute
|
|
15
|
+
// - Discussion with esbuild maintainer: https://github.com/evanw/esbuild/issues/3384
|
|
16
|
+
// - Using a magic comment `// @vike-real-import` is probably a bad idea:
|
|
17
|
+
// - Esbuild removes comments: https://github.com/evanw/esbuild/issues/1439#issuecomment-877656182
|
|
18
|
+
// - Using source maps to track these magic comments is brittle (source maps can easily break)
|
|
7
19
|
import { parse } from 'acorn';
|
|
8
20
|
import { assert, assertUsage, assertWarning, styleFileRE } from '../../../../utils.js';
|
|
9
21
|
import pc from '@brillout/picocolors';
|
|
10
|
-
|
|
22
|
+
// TODO: rename transformFileImports() => transformPointerImports()
|
|
23
|
+
function transformFileImports(code, filePathToShowToUser2, pointerImports,
|
|
11
24
|
// For ./transformFileImports.spec.ts
|
|
12
25
|
skipWarnings) {
|
|
13
26
|
const spliceOperations = [];
|
|
14
|
-
const fileImportsTransformed = [];
|
|
15
27
|
// Performance trick
|
|
16
28
|
if (!code.includes('import'))
|
|
17
|
-
return
|
|
29
|
+
return null;
|
|
18
30
|
const imports = getImports(code);
|
|
19
31
|
if (imports.length === 0)
|
|
20
|
-
return
|
|
32
|
+
return null;
|
|
21
33
|
imports.forEach((node) => {
|
|
22
34
|
if (node.type !== 'ImportDeclaration')
|
|
23
35
|
return;
|
|
24
36
|
const importPath = node.source.value;
|
|
25
37
|
assert(typeof importPath === 'string');
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// - It works well with TypeScript: it doesn't complain upon `with { type: 'unknown-to-typescript' }` and go-to-definition & types are preserved: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#import-attributes
|
|
33
|
-
// - Esbuid seems to support it: https://esbuild.github.io/plugins/#on-load-arguments:~:text=This%20contains%20a%20map%20of%20the%20import%20attributes%20that
|
|
34
|
-
// - acorn supports it over an acorn plugin: https://github.com/acornjs/acorn/issues/983
|
|
35
|
-
// - Maybe we can use an esbuild plugin instead of acorn to apply transformFileImports()?
|
|
36
|
-
// - Using a magic comment `// @vike-real-import` is tricky:
|
|
37
|
-
// - Esbuild removes comments: https://github.com/evanw/esbuild/issues/1439#issuecomment-877656182
|
|
38
|
-
// - Using source maps to track these magic comments is brittle (source maps can easily break)
|
|
39
|
-
if (importPath.endsWith('?real')) {
|
|
40
|
-
const { start, end } = node.source;
|
|
41
|
-
spliceOperations.push({
|
|
42
|
-
start,
|
|
43
|
-
end,
|
|
44
|
-
replacement: importPath.slice(0, -1 * '?real'.length)
|
|
45
|
-
});
|
|
46
|
-
return;
|
|
38
|
+
if (pointerImports !== 'all') {
|
|
39
|
+
assert(importPath in pointerImports);
|
|
40
|
+
const isPointerImport = pointerImports[importPath];
|
|
41
|
+
assert(isPointerImport === true || isPointerImport === false);
|
|
42
|
+
if (!isPointerImport)
|
|
43
|
+
return;
|
|
47
44
|
}
|
|
48
45
|
const { start, end } = node;
|
|
49
46
|
const importStatementCode = code.slice(start, end);
|
|
50
|
-
|
|
47
|
+
/* Pointer import without importing any value => doesn't make sense and doesn't have any effect.
|
|
48
|
+
```js
|
|
49
|
+
// Useless
|
|
50
|
+
import './some.css'
|
|
51
|
+
// Useless
|
|
52
|
+
import './Layout.jsx'
|
|
53
|
+
``` */
|
|
51
54
|
if (node.specifiers.length === 0) {
|
|
52
55
|
const isWarning = !styleFileRE.test(importPath);
|
|
53
56
|
let quote = indent(importStatementCode);
|
|
@@ -58,8 +61,9 @@ skipWarnings) {
|
|
|
58
61
|
quote = pc.bold(pc.red(quote));
|
|
59
62
|
}
|
|
60
63
|
const errMsg = [
|
|
61
|
-
`
|
|
62
|
-
quote
|
|
64
|
+
`The following import in ${filePathToShowToUser2} has no effect:`,
|
|
65
|
+
quote,
|
|
66
|
+
'See https://vike.dev/config#pointer-imports'
|
|
63
67
|
].join('\n');
|
|
64
68
|
if (!skipWarnings) {
|
|
65
69
|
if (!isWarning) {
|
|
@@ -88,11 +92,6 @@ skipWarnings) {
|
|
|
88
92
|
})();
|
|
89
93
|
const importString = serializeImportData({ importPath, exportName, importStringWasGenerated: true });
|
|
90
94
|
replacement += `const ${importLocalName} = '${importString}';`;
|
|
91
|
-
fileImportsTransformed.push({
|
|
92
|
-
importStatementCode,
|
|
93
|
-
importString,
|
|
94
|
-
importLocalName
|
|
95
|
-
});
|
|
96
95
|
});
|
|
97
96
|
spliceOperations.push({
|
|
98
97
|
start,
|
|
@@ -101,7 +100,7 @@ skipWarnings) {
|
|
|
101
100
|
});
|
|
102
101
|
});
|
|
103
102
|
const codeMod = spliceMany(code, spliceOperations);
|
|
104
|
-
return
|
|
103
|
+
return codeMod;
|
|
105
104
|
}
|
|
106
105
|
function getImports(code) {
|
|
107
106
|
const { body } = parse(code, {
|
|
@@ -4,7 +4,7 @@ export { getConfigExecutionErrorIntroMsg };
|
|
|
4
4
|
export { isTmpFile };
|
|
5
5
|
import 'source-map-support/register.js';
|
|
6
6
|
import type { FilePathResolved } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
7
|
-
declare function transpileAndExecuteFile(filePath: FilePathResolved,
|
|
7
|
+
declare function transpileAndExecuteFile(filePath: FilePathResolved, userRootDir: string, isConfigFile: boolean | 'is-extension-config'): Promise<{
|
|
8
8
|
fileExports: Record<string, unknown>;
|
|
9
9
|
}>;
|
|
10
10
|
declare function getConfigBuildErrorFormatted(err: unknown): null | string;
|
|
@@ -7,65 +7,58 @@ import fs from 'fs';
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { import_ } from '@brillout/import';
|
|
10
|
-
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert,
|
|
11
|
-
import {
|
|
10
|
+
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isJavaScriptFile, createDebugger } from '../../../../utils.js';
|
|
11
|
+
import { transformFileImports } from './transformFileImports.js';
|
|
12
12
|
import { vikeConfigDependencies } from '../getVikeConfig.js';
|
|
13
13
|
import 'source-map-support/register.js';
|
|
14
|
-
import { getConfigFileExport } from '../getConfigFileExport.js';
|
|
15
14
|
assertIsNotProductionRuntime();
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
const debug = createDebugger('vike:pointer-imports');
|
|
16
|
+
async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile) {
|
|
17
|
+
const { filePathAbsoluteFilesystem } = filePath;
|
|
18
|
+
const fileExtension = getFileExtension(filePathAbsoluteFilesystem);
|
|
19
|
+
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
20
|
+
assertUsage(isJavaScriptFile(filePathAbsoluteFilesystem), `${filePathToShowToUser2} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
|
|
21
|
+
const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
|
|
22
|
+
if (isHeader) {
|
|
23
|
+
assertWarning(false, `${pc.cyan('.h.js')} files are deprecated: simply renaming ${filePathToShowToUser2} to ${removeHeaderFileExtension(filePathToShowToUser2)} 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 });
|
|
24
|
+
}
|
|
25
|
+
if (isConfigFile === 'is-extension-config' && !isHeader && fileExtension.endsWith('js')) {
|
|
26
|
+
// This doesn't track dependencies => we should never use this for user land configs
|
|
27
|
+
const fileExports = await executeFile(filePathAbsoluteFilesystem, filePath);
|
|
24
28
|
return { fileExports };
|
|
25
29
|
}
|
|
26
30
|
else {
|
|
27
|
-
const
|
|
28
|
-
const
|
|
31
|
+
const transformImports = isConfigFile && (isHeader ? 'all' : true);
|
|
32
|
+
const code = await transpileFile(filePath, transformImports, userRootDir);
|
|
33
|
+
const fileExports = await executeTranspiledFile(filePath, code);
|
|
29
34
|
return { fileExports };
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
async function transpileFile(filePath, transformImports, userRootDir) {
|
|
33
|
-
const { filePathAbsoluteFilesystem } = filePath;
|
|
34
38
|
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
39
|
+
const { filePathAbsoluteFilesystem } = filePath;
|
|
35
40
|
assertPosixPath(filePathAbsoluteFilesystem);
|
|
36
41
|
vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
if (debug.isEnabled)
|
|
43
|
+
debug('transpile', filePathToShowToUser2);
|
|
44
|
+
let { code, pointerImports } = await transpileWithEsbuild(filePath, userRootDir, transformImports);
|
|
45
|
+
if (debug.isEnabled)
|
|
46
|
+
debug(`code, post esbuild (${filePathToShowToUser2})`, code);
|
|
47
|
+
let isImportTransformed = false;
|
|
39
48
|
if (transformImports) {
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
42
|
-
code =
|
|
43
|
-
|
|
49
|
+
const codeMod = transformFileImports(code, filePathToShowToUser2, pointerImports);
|
|
50
|
+
if (codeMod) {
|
|
51
|
+
code = codeMod;
|
|
52
|
+
isImportTransformed = true;
|
|
53
|
+
if (debug.isEnabled)
|
|
54
|
+
debug(`code, post transformImports() (${filePathToShowToUser2})`, code);
|
|
44
55
|
}
|
|
45
56
|
}
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
}
|
|
57
|
+
if (!isImportTransformed) {
|
|
58
|
+
if (debug.isEnabled)
|
|
59
|
+
debug(`code, no transformImports() (${filePathToShowToUser2})`);
|
|
50
60
|
}
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
function transformFileImports_(codeOriginal, filePath) {
|
|
54
|
-
const { filePathAbsoluteFilesystem } = filePath;
|
|
55
|
-
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
56
|
-
// Replace import statements with import strings
|
|
57
|
-
const res = transformFileImports(codeOriginal, filePathToShowToUser2);
|
|
58
|
-
if (res.noTransformation) {
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
const { code, fileImportsTransformed } = res;
|
|
62
|
-
if (!isHeaderFile(filePathAbsoluteFilesystem)) {
|
|
63
|
-
const filePathCorrect = appendHeaderFileExtension(filePathToShowToUser2);
|
|
64
|
-
assertWarning(false, `Rename ${filePathToShowToUser2} to ${filePathCorrect}, see https://vike.dev/header-file`, {
|
|
65
|
-
onlyOnce: true
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
return { code, fileImportsTransformed };
|
|
61
|
+
return code;
|
|
69
62
|
}
|
|
70
63
|
async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
71
64
|
const entryFilePath = filePath.filePathAbsoluteFilesystem;
|
|
@@ -88,14 +81,63 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
88
81
|
// Esbuild still sometimes removes unused imports because of TypeScript: https://github.com/evanw/esbuild/issues/3034
|
|
89
82
|
treeShaking: false,
|
|
90
83
|
minify: false,
|
|
91
|
-
metafile:
|
|
92
|
-
|
|
93
|
-
bundle: !transformImports
|
|
84
|
+
metafile: transformImports !== 'all',
|
|
85
|
+
bundle: transformImports !== 'all'
|
|
94
86
|
};
|
|
95
|
-
|
|
96
|
-
if (
|
|
87
|
+
let pointerImports;
|
|
88
|
+
if (transformImports === 'all') {
|
|
89
|
+
pointerImports = 'all';
|
|
97
90
|
options.packages = 'external';
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const pointerImports_ = (pointerImports = {});
|
|
98
94
|
options.plugins = [
|
|
95
|
+
// Determine what import should be externalized (and then transformed to a pointer/fake import)
|
|
96
|
+
{
|
|
97
|
+
name: 'vike:externalize-heuristic',
|
|
98
|
+
setup(build) {
|
|
99
|
+
// https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
100
|
+
const useEsbuildResolver = 'useEsbuildResolver';
|
|
101
|
+
// https://github.com/brillout/esbuild-playground
|
|
102
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
103
|
+
if (args.kind !== 'import-statement')
|
|
104
|
+
return;
|
|
105
|
+
if (args.pluginData?.[useEsbuildResolver])
|
|
106
|
+
return;
|
|
107
|
+
const isImportAbsolute = !args.path.startsWith('.');
|
|
108
|
+
const { path, ...opts } = args;
|
|
109
|
+
opts.pluginData = { [useEsbuildResolver]: true };
|
|
110
|
+
const resolved = await build.resolve(path, opts);
|
|
111
|
+
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
112
|
+
// - This is temporary, see comment below.
|
|
113
|
+
const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
|
|
114
|
+
const isPointerImport =
|
|
115
|
+
// .jsx, .vue, .svg, ... => obviously not config code
|
|
116
|
+
!isJavaScriptFile(resolved.path) ||
|
|
117
|
+
// Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a configas been set by the user or by a Vike extension).
|
|
118
|
+
// - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
|
|
119
|
+
// - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
|
|
120
|
+
isVikeExtensionConfigImport ||
|
|
121
|
+
// Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
|
|
122
|
+
// - For example if esbuild cannot resolve a path alias while Vite can.
|
|
123
|
+
// - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
|
|
124
|
+
resolved.errors.length > 0;
|
|
125
|
+
pointerImports_[args.path] = isPointerImport;
|
|
126
|
+
const isExternal = isPointerImport ||
|
|
127
|
+
// npm package imports that aren't pointer imports (e.g. Vite plugin import)
|
|
128
|
+
isImportAbsolute;
|
|
129
|
+
if (debug.isEnabled)
|
|
130
|
+
debug('onResolved()', { args, resolved, isPointerImport, isExternal });
|
|
131
|
+
if (isExternal) {
|
|
132
|
+
return { external: true, path: args.path };
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
return resolved;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
// Track dependencies
|
|
99
141
|
{
|
|
100
142
|
name: 'vike:dependency-tracker',
|
|
101
143
|
setup(b) {
|
|
@@ -128,7 +170,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
128
170
|
throw err;
|
|
129
171
|
}
|
|
130
172
|
// Track dependencies
|
|
131
|
-
if (
|
|
173
|
+
if (transformImports !== 'all') {
|
|
132
174
|
assert(result.metafile);
|
|
133
175
|
Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
|
|
134
176
|
filePathRelative = toPosixPath(filePathRelative);
|
|
@@ -139,10 +181,10 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
139
181
|
}
|
|
140
182
|
const code = result.outputFiles[0].text;
|
|
141
183
|
assert(typeof code === 'string');
|
|
142
|
-
return code;
|
|
184
|
+
return { code, pointerImports };
|
|
143
185
|
}
|
|
144
|
-
async function executeTranspiledFile(filePath, code
|
|
145
|
-
const { filePathAbsoluteFilesystem
|
|
186
|
+
async function executeTranspiledFile(filePath, code) {
|
|
187
|
+
const { filePathAbsoluteFilesystem } = filePath;
|
|
146
188
|
// Alternative to using a temporary file: https://github.com/vitejs/vite/pull/13269
|
|
147
189
|
// - But seems to break source maps, so I don't think it's worth it
|
|
148
190
|
const filePathTmp = getFilePathTmp(filePathAbsoluteFilesystem);
|
|
@@ -155,11 +197,6 @@ async function executeTranspiledFile(filePath, code, fileImportsTransformed) {
|
|
|
155
197
|
finally {
|
|
156
198
|
clean();
|
|
157
199
|
}
|
|
158
|
-
if (fileImportsTransformed) {
|
|
159
|
-
assert(filePathRelativeToUserRootDir !== undefined);
|
|
160
|
-
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
161
|
-
assertImportsAreReExported(fileImportsTransformed, fileExports, filePathToShowToUser2);
|
|
162
|
-
}
|
|
163
200
|
return fileExports;
|
|
164
201
|
}
|
|
165
202
|
async function executeFile(filePathToExecuteAbsoluteFilesystem, filePathSourceFile) {
|
|
@@ -222,59 +259,27 @@ function isTmpFile(filePath) {
|
|
|
222
259
|
const fileName = path.posix.basename(filePath);
|
|
223
260
|
return fileName.startsWith(tmpPrefix);
|
|
224
261
|
}
|
|
225
|
-
function assertImportsAreReExported(fileImportsTransformed, fileExports, filePathToShowToUser2) {
|
|
226
|
-
const fileExport = getConfigFileExport(fileExports, filePathToShowToUser2);
|
|
227
|
-
const exportedStrings = getExportedStrings(fileExport);
|
|
228
|
-
Object.values(exportedStrings).forEach((exportVal) => {
|
|
229
|
-
if (typeof exportVal !== 'string')
|
|
230
|
-
return;
|
|
231
|
-
if (!isImportData(exportVal))
|
|
232
|
-
return;
|
|
233
|
-
const importString = exportVal;
|
|
234
|
-
fileImportsTransformed.forEach((fileImport) => {
|
|
235
|
-
if (fileImport.importString === importString) {
|
|
236
|
-
fileImport.isReExported = true;
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
const fileImportsTransformedUnused = fileImportsTransformed.filter((fi) => !fi.isReExported);
|
|
241
|
-
if (fileImportsTransformedUnused.length === 0)
|
|
242
|
-
return;
|
|
243
|
-
const importStatements = unique(fileImportsTransformedUnused.map((fi) => fi.importStatementCode));
|
|
244
|
-
const importNamesUnused = fileImportsTransformedUnused.map((fi) => pc.cyan(fi.importLocalName)).join(', ');
|
|
245
|
-
const singular = fileImportsTransformedUnused.length === 1;
|
|
246
|
-
assertWarning(fileImportsTransformedUnused.length === 0, [
|
|
247
|
-
`${filePathToShowToUser2} imports the following:`,
|
|
248
|
-
...importStatements.map((s) => pc.cyan(` ${s}`)),
|
|
249
|
-
`But the import${singular ? '' : 's'} ${importNamesUnused} ${singular ? "isn't" : "aren't"} re-exported at ${pc.cyan('export default { ... }')} and therefore ${singular ? 'has' : 'have'} no effect, see explanation at https://vike.dev/header-file`
|
|
250
|
-
].join('\n'), { onlyOnce: true });
|
|
251
|
-
}
|
|
252
|
-
function getExportedStrings(obj) {
|
|
253
|
-
const exportedStrings = [];
|
|
254
|
-
Object.values(obj).forEach((val) => {
|
|
255
|
-
if (typeof val === 'string') {
|
|
256
|
-
exportedStrings.push(val);
|
|
257
|
-
}
|
|
258
|
-
else if (Array.isArray(val)) {
|
|
259
|
-
val.forEach((v) => {
|
|
260
|
-
if (typeof v === 'string') {
|
|
261
|
-
exportedStrings.push(v);
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
return exportedStrings;
|
|
267
|
-
}
|
|
268
262
|
function isHeaderFile(filePath) {
|
|
269
263
|
assertPosixPath(filePath);
|
|
270
|
-
const
|
|
271
|
-
return
|
|
264
|
+
const fileExtensions = getFileExtensions(filePath);
|
|
265
|
+
return fileExtensions.includes('h');
|
|
272
266
|
}
|
|
273
|
-
function
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
267
|
+
function getFileExtensions(filePath) {
|
|
268
|
+
const fileExtensions = path.posix.basename(filePath).split('.').slice(1);
|
|
269
|
+
return fileExtensions;
|
|
270
|
+
}
|
|
271
|
+
function getFileExtension(filePath) {
|
|
272
|
+
const fileExtensions = path.posix.basename(filePath).split('.').slice(1);
|
|
273
|
+
return fileExtensions.pop();
|
|
274
|
+
}
|
|
275
|
+
function removeHeaderFileExtension(filePath) {
|
|
276
|
+
assertPosixPath(filePath);
|
|
277
|
+
const fileName = path.posix.basename(filePath);
|
|
278
|
+
const fileNameParts = fileName.split('.');
|
|
279
|
+
const fileNamePartsMod = fileNameParts.filter((p) => p !== 'h');
|
|
280
|
+
assert(fileNamePartsMod.length < fileNameParts.length);
|
|
281
|
+
const fileNameMod = fileNamePartsMod.join('.');
|
|
282
|
+
return path.posix.join(path.posix.dirname(filePath), fileNameMod);
|
|
278
283
|
}
|
|
279
284
|
// Needed for the npm package 'source-map-support'. The Error.prepareStackTrace() hook of 'source-map-support' needs to be called before the file containing the source map is removed. The clean() call above removes the transpiled file from disk but it contains the inline source map.
|
|
280
285
|
function triggerPrepareStackTrace(err) {
|
|
@@ -6,7 +6,6 @@ export { isV1Design };
|
|
|
6
6
|
export type { VikeConfig };
|
|
7
7
|
export type { InterfaceValueFile };
|
|
8
8
|
import type { PageConfigGlobalBuildTime, PageConfigBuildTime, FilePathResolved } from '../../../../../shared/page-configs/PageConfig.js';
|
|
9
|
-
import type { ExtensionResolved } from '../../../../../shared/ConfigVike.js';
|
|
10
9
|
import { type LocationId } from './getVikeConfig/filesystemRouting.js';
|
|
11
10
|
import type { ResolvedConfig } from 'vite';
|
|
12
11
|
type InterfaceFileCommons = {
|
|
@@ -28,7 +27,7 @@ type VikeConfig = {
|
|
|
28
27
|
globalVikeConfig: Record<string, unknown>;
|
|
29
28
|
};
|
|
30
29
|
declare const vikeConfigDependencies: Set<string>;
|
|
31
|
-
declare function reloadVikeConfig(userRootDir: string, outDirRoot: string
|
|
32
|
-
declare function getVikeConfig(config: ResolvedConfig, isDev: boolean, tolerateInvalidConfig?: boolean
|
|
30
|
+
declare function reloadVikeConfig(userRootDir: string, outDirRoot: string): void;
|
|
31
|
+
declare function getVikeConfig(config: ResolvedConfig, isDev: boolean, tolerateInvalidConfig?: boolean): Promise<VikeConfig>;
|
|
33
32
|
declare function isV1Design(config: ResolvedConfig, isDev: boolean): Promise<boolean>;
|
|
34
33
|
declare function isVikeConfigFile(filePath: string): boolean;
|
|
@@ -14,7 +14,6 @@ import { logConfigError, logConfigErrorRecover } from '../../../shared/loggerNot
|
|
|
14
14
|
import { removeSuperfluousViteLog_enable, removeSuperfluousViteLog_disable } from '../../../shared/loggerVite/removeSuperfluousViteLog.js';
|
|
15
15
|
import pc from '@brillout/picocolors';
|
|
16
16
|
import { getConfigDefinedAtString } from '../../../../../shared/page-configs/helpers.js';
|
|
17
|
-
import { getConfigVike } from '../../../../shared/getConfigVike.js';
|
|
18
17
|
import { assertConfigValueIsSerializable } from './getConfigValuesSerialized.js';
|
|
19
18
|
import { crawlPlusFiles } from './getVikeConfig/crawlPlusFiles.js';
|
|
20
19
|
import { getConfigFileExport } from './getConfigFileExport.js';
|
|
@@ -26,10 +25,10 @@ let devServerIsCorrupt = false;
|
|
|
26
25
|
let wasConfigInvalid = null;
|
|
27
26
|
let vikeConfigPromise = null;
|
|
28
27
|
const vikeConfigDependencies = new Set();
|
|
29
|
-
function reloadVikeConfig(userRootDir, outDirRoot
|
|
28
|
+
function reloadVikeConfig(userRootDir, outDirRoot) {
|
|
30
29
|
vikeConfigDependencies.clear();
|
|
31
30
|
clearFilesEnvMap();
|
|
32
|
-
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, true,
|
|
31
|
+
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, true, true);
|
|
33
32
|
handleReloadSideEffects();
|
|
34
33
|
}
|
|
35
34
|
async function handleReloadSideEffects() {
|
|
@@ -63,11 +62,11 @@ async function handleReloadSideEffects() {
|
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
|
-
async function getVikeConfig(config, isDev, tolerateInvalidConfig = false
|
|
65
|
+
async function getVikeConfig(config, isDev, tolerateInvalidConfig = false) {
|
|
67
66
|
const { outDirRoot } = getOutDirs(config);
|
|
68
67
|
const userRootDir = config.root;
|
|
69
68
|
if (!vikeConfigPromise) {
|
|
70
|
-
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
|
|
69
|
+
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, tolerateInvalidConfig);
|
|
71
70
|
}
|
|
72
71
|
return await vikeConfigPromise;
|
|
73
72
|
}
|
|
@@ -77,8 +76,8 @@ async function isV1Design(config, isDev) {
|
|
|
77
76
|
const isV1Design = pageConfigs.length > 0;
|
|
78
77
|
return isV1Design;
|
|
79
78
|
}
|
|
80
|
-
async function loadInterfaceFiles(userRootDir, outDirRoot, isDev
|
|
81
|
-
const plusFiles = await findPlusFiles(userRootDir, outDirRoot, isDev
|
|
79
|
+
async function loadInterfaceFiles(userRootDir, outDirRoot, isDev) {
|
|
80
|
+
const plusFiles = await findPlusFiles(userRootDir, outDirRoot, isDev);
|
|
82
81
|
const configFiles = [];
|
|
83
82
|
const valueFiles = [];
|
|
84
83
|
plusFiles.forEach((f) => {
|
|
@@ -104,14 +103,14 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
104
103
|
extendsConfigs.forEach((extendsConfig) => {
|
|
105
104
|
/* We purposely use the same locationId because the Vike extension's config should only apply to where it's being extended from, for example:
|
|
106
105
|
```js
|
|
107
|
-
// /pages/admin/+config.
|
|
106
|
+
// /pages/admin/+config.js
|
|
108
107
|
|
|
109
108
|
import vikeVue from 'vike-vue/config'
|
|
110
109
|
// Should only apply to /pages/admin/**
|
|
111
110
|
export default { extends: [vikeVue] }
|
|
112
111
|
```
|
|
113
112
|
```js
|
|
114
|
-
// /pages/marketing/+config.
|
|
113
|
+
// /pages/marketing/+config.js
|
|
115
114
|
|
|
116
115
|
import vikeReact from 'vike-react/config'
|
|
117
116
|
// Should only apply to /pages/marketing/**
|
|
@@ -119,6 +118,28 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
119
118
|
```
|
|
120
119
|
*/
|
|
121
120
|
const interfaceFile = getInterfaceFileFromConfigFile(extendsConfig, true, locationId);
|
|
121
|
+
{
|
|
122
|
+
const alreadyMigrated = [
|
|
123
|
+
'vike-react',
|
|
124
|
+
'vike-react-query',
|
|
125
|
+
'vike-react-zustand',
|
|
126
|
+
'vike-vue',
|
|
127
|
+
'vike-pinia',
|
|
128
|
+
'vike-solid'
|
|
129
|
+
];
|
|
130
|
+
const extensionName = extendsConfig.filePath.importPathAbsolute.split('/')[0];
|
|
131
|
+
const warnMsg = alreadyMigrated.includes(extensionName)
|
|
132
|
+
? `You're using a deprecated version of the Vike extension ${extensionName}, update ${extensionName} to its latest version.`
|
|
133
|
+
: `The config of the Vike extension ${extensionName} should set a ${pc.cyan('name')} value`;
|
|
134
|
+
const isNameDefined = interfaceFile.fileExportsByConfigName.name?.configValue;
|
|
135
|
+
if (alreadyMigrated) {
|
|
136
|
+
// Eventually always make it a assertUsage()
|
|
137
|
+
assertWarning(isNameDefined, warnMsg, { onlyOnce: true });
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
assertUsage(isNameDefined, warnMsg);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
122
143
|
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
123
144
|
});
|
|
124
145
|
}),
|
|
@@ -186,12 +207,12 @@ function assertAllConfigsAreKnown(interfaceFilesByLocationId) {
|
|
|
186
207
|
});
|
|
187
208
|
});
|
|
188
209
|
}
|
|
189
|
-
async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
|
|
210
|
+
async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, tolerateInvalidConfig) {
|
|
190
211
|
let hasError = false;
|
|
191
212
|
let ret;
|
|
192
213
|
let err;
|
|
193
214
|
try {
|
|
194
|
-
ret = await loadVikeConfig(userRootDir, outDirRoot, isDev
|
|
215
|
+
ret = await loadVikeConfig(userRootDir, outDirRoot, isDev);
|
|
195
216
|
}
|
|
196
217
|
catch (err_) {
|
|
197
218
|
hasError = true;
|
|
@@ -227,8 +248,8 @@ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
|
|
|
227
248
|
}
|
|
228
249
|
}
|
|
229
250
|
}
|
|
230
|
-
async function loadVikeConfig(userRootDir, outDirRoot, isDev
|
|
231
|
-
const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev
|
|
251
|
+
async function loadVikeConfig(userRootDir, outDirRoot, isDev) {
|
|
252
|
+
const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev);
|
|
232
253
|
const importedFilesLoaded = {};
|
|
233
254
|
const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
|
|
234
255
|
const pageConfigs = await Promise.all(objectEntries(interfaceFilesByLocationId)
|
|
@@ -403,7 +424,7 @@ async function resolveConfigValueSources(configName, configDef, interfaceFilesRe
|
|
|
403
424
|
// Make this value:
|
|
404
425
|
// /pages/some-page/+{configName}.js > `export default`
|
|
405
426
|
// override that value:
|
|
406
|
-
// /pages/some-page/+config.
|
|
427
|
+
// /pages/some-page/+config.js > `export default { someConfig }`
|
|
407
428
|
const interfaceFileWinner = interfaceValueFile ?? interfaceConfigFile;
|
|
408
429
|
if (interfaceFileWinner) {
|
|
409
430
|
const interfaceFilesOverriden = [...interfaceValueFiles, ...interfaceConfigFiles].filter((f) => f !== interfaceFileWinner);
|
|
@@ -711,26 +732,9 @@ function getComputed(configValueSources, configDefinitions) {
|
|
|
711
732
|
});
|
|
712
733
|
return configValuesComputed;
|
|
713
734
|
}
|
|
714
|
-
async function findPlusFiles(userRootDir, outDirRoot, isDev
|
|
735
|
+
async function findPlusFiles(userRootDir, outDirRoot, isDev) {
|
|
715
736
|
const files = await crawlPlusFiles(userRootDir, outDirRoot, isDev);
|
|
716
737
|
const plusFiles = files.map(({ filePathRelativeToUserRootDir }) => resolveFilePathRelativeToUserRootDir(filePathRelativeToUserRootDir, userRootDir));
|
|
717
|
-
// TODO/v1-release: remove
|
|
718
|
-
extensions.forEach((extension) => {
|
|
719
|
-
extension.pageConfigsDistFiles?.forEach((pageConfigDistFile) => {
|
|
720
|
-
if (!pageConfigDistFile.importPath.includes('+'))
|
|
721
|
-
return;
|
|
722
|
-
assert(pageConfigDistFile.importPath.includes('+'));
|
|
723
|
-
assert(path.posix.basename(pageConfigDistFile.importPath).startsWith('+'));
|
|
724
|
-
const { importPath, filePath } = pageConfigDistFile;
|
|
725
|
-
plusFiles.push({
|
|
726
|
-
filePathRelativeToUserRootDir: null,
|
|
727
|
-
filePathAbsoluteVite: importPath,
|
|
728
|
-
filePathAbsoluteFilesystem: filePath,
|
|
729
|
-
filePathToShowToUser: importPath,
|
|
730
|
-
importPathAbsolute: importPath
|
|
731
|
-
});
|
|
732
|
-
});
|
|
733
|
-
});
|
|
734
738
|
return plusFiles;
|
|
735
739
|
}
|
|
736
740
|
function getConfigName(filePath) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export * from '../runtime/utils.js';
|
|
2
2
|
export * from '../../utils/viteIsSSR.js';
|
|
3
3
|
export * from '../../utils/getFilePathAbsolute.js';
|
|
4
|
-
export * from '../../utils/getDependencyPackageJson.js';
|
|
5
4
|
export * from '../../utils/requireResolve.js';
|
|
6
5
|
export * from '../../utils/arrayIncludes.js';
|
|
7
6
|
export * from '../../utils/isDev.js';
|
|
@@ -7,7 +7,6 @@ export * from '../runtime/utils.js';
|
|
|
7
7
|
// Utils only needed by `plugin/*`
|
|
8
8
|
export * from '../../utils/viteIsSSR.js';
|
|
9
9
|
export * from '../../utils/getFilePathAbsolute.js';
|
|
10
|
-
export * from '../../utils/getDependencyPackageJson.js';
|
|
11
10
|
export * from '../../utils/requireResolve.js';
|
|
12
11
|
export * from '../../utils/arrayIncludes.js';
|
|
13
12
|
export * from '../../utils/isDev.js';
|
|
@@ -36,11 +36,11 @@ type PrerenderOptions = {
|
|
|
36
36
|
root?: string;
|
|
37
37
|
/** @deprecated Define `prerender({ viteConfig: { configFile }})` instead. */
|
|
38
38
|
configFile?: string;
|
|
39
|
-
/** @deprecated Define `partial` in vite.config.js instead, see https://vike.dev/prerender
|
|
39
|
+
/** @deprecated Define `partial` in vite.config.js instead, see https://vike.dev/prerender */
|
|
40
40
|
partial?: boolean;
|
|
41
|
-
/** @deprecated Define `noExtraDir` in vite.config.js instead, see https://vike.dev/prerender
|
|
41
|
+
/** @deprecated Define `noExtraDir` in vite.config.js instead, see https://vike.dev/prerender */
|
|
42
42
|
noExtraDir?: boolean;
|
|
43
|
-
/** @deprecated Define `parallel` in vite.config.js instead, see https://vike.dev/prerender
|
|
43
|
+
/** @deprecated Define `parallel` in vite.config.js instead, see https://vike.dev/prerender */
|
|
44
44
|
parallel?: number;
|
|
45
45
|
/** @deprecated */
|
|
46
46
|
outDir?: string;
|
|
@@ -530,7 +530,7 @@ function warnMissingPages(prerenderedPageContexts, doNotPrerenderList, renderCon
|
|
|
530
530
|
.filter((pageId) => !isErrorPage(pageId, renderContext.pageConfigs))
|
|
531
531
|
.forEach((pageId) => {
|
|
532
532
|
const pageAt = isV1 ? pageId : `\`${pageId}.page.*\``;
|
|
533
|
-
assertWarning(partial, `Cannot pre-render page ${pageAt} because it has a non-static route, while no ${hookName}() hook returned any URL matching the page's route. You need to use a ${hookName}() hook (https://vike.dev/${hookName}) providing a list of URLs for ${pageAt} that should be pre-rendered. If you don't want to pre-render ${pageAt} then use the option prerender.partial (https://vike.dev/prerender
|
|
533
|
+
assertWarning(partial, `Cannot pre-render page ${pageAt} because it has a non-static route, while no ${hookName}() hook returned any URL matching the page's route. You need to use a ${hookName}() hook (https://vike.dev/${hookName}) providing a list of URLs for ${pageAt} that should be pre-rendered. If you don't want to pre-render ${pageAt} then use the option prerender.partial (https://vike.dev/prerender#partial) to suppress this warning.`, { onlyOnce: true });
|
|
534
534
|
});
|
|
535
535
|
}
|
|
536
536
|
async function prerender404(prerenderedPageContexts, renderContext, prerenderContext, onComplete) {
|
|
@@ -646,7 +646,7 @@ function checkOutdatedOptions(options) {
|
|
|
646
646
|
assertUsage(options.root === undefined, 'Option `prerender({ root })` deprecated: set `prerender({ viteConfig: { root }})` instead.', { showStackTrace: true });
|
|
647
647
|
assertUsage(options.configFile === undefined, 'Option `prerender({ configFile })` deprecated: set `prerender({ viteConfig: { configFile }})` instead.', { showStackTrace: true });
|
|
648
648
|
['noExtraDir', 'partial', 'parallel'].forEach((prop) => {
|
|
649
|
-
assertUsage(options[prop] === undefined, `[prerender()] Option ${pc.cyan(prop)} is deprecated. Define ${pc.cyan(prop)} in vite.config.js instead. See https://vike.dev/prerender
|
|
649
|
+
assertUsage(options[prop] === undefined, `[prerender()] Option ${pc.cyan(prop)} is deprecated. Define ${pc.cyan(prop)} in vite.config.js instead. See https://vike.dev/prerender`, { showStackTrace: true });
|
|
650
650
|
});
|
|
651
651
|
['base', 'outDir'].forEach((prop) => {
|
|
652
652
|
assertWarning(options[prop] === undefined, `[prerender()] Option ${pc.cyan(prop)} is outdated and has no effect (vike now automatically determines ${pc.cyan(prop)})`, {
|