vike 0.4.160 → 0.4.161-commit-0e9c635
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/cli/bin.js +5 -0
- package/dist/cjs/node/client/router.js +4 -2
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +148 -0
- package/dist/cjs/node/plugin/plugins/buildConfig.js +61 -35
- package/dist/cjs/node/plugin/plugins/commonConfig.js +5 -13
- package/dist/cjs/node/plugin/plugins/config/stemUtils.js +1 -1
- package/dist/cjs/node/plugin/plugins/distFileNames.js +9 -1
- package/dist/cjs/node/plugin/plugins/envVars.js +6 -2
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +16 -4
- package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +1 -21
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +5 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +11 -91
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +28 -46
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +5 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +33 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +7 -7
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +21 -27
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +157 -111
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +0 -14
- package/dist/cjs/node/plugin/shared/rollupSourceMap.js +20 -0
- package/dist/cjs/node/plugin/utils.js +3 -2
- package/dist/cjs/node/prerender/runPrerender.js +13 -5
- package/dist/cjs/node/runtime/globalContext.js +15 -23
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/cjs/node/runtime/html/renderHtml.js +1 -1
- package/dist/cjs/node/runtime/html/stream.js +2 -2
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +39 -39
- package/dist/cjs/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -5
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +6 -7
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +23 -28
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +81 -43
- package/dist/cjs/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -23
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/node/shared/assertPluginManifest.js +1 -4
- package/dist/cjs/node/shared/assertV1Design.js +26 -0
- package/dist/cjs/node/shared/{getClientEntryFilePath.js → getClientEntry.js} +3 -3
- package/dist/cjs/node/shared/prependEntriesDir.js +13 -0
- package/dist/cjs/node/shared/utils.js +2 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
- package/dist/cjs/shared/route/executeGuardHook.js +3 -2
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/assertNodeVersion.js +2 -2
- package/dist/cjs/utils/{findUserPackageJsonPath.js → findFile.js} +11 -8
- package/dist/cjs/utils/isVersionOrAbove.js +29 -0
- package/dist/cjs/utils/nodeEnv.js +23 -1
- package/dist/cjs/utils/objectKeys.js +19 -3
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/sorter.js +62 -1
- package/dist/esm/client/client-routing-runtime/index.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/index.js +1 -1
- package/dist/esm/node/cli/bin.js +3 -1
- package/dist/esm/node/client/router.d.ts +2 -0
- package/dist/esm/node/client/router.js +3 -1
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +2 -2
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +13 -0
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +142 -0
- package/dist/esm/node/plugin/plugins/buildConfig.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/buildConfig.js +60 -34
- package/dist/esm/node/plugin/plugins/commonConfig.js +6 -14
- package/dist/esm/node/plugin/plugins/config/stemUtils.js +2 -2
- package/dist/esm/node/plugin/plugins/distFileNames.js +9 -1
- package/dist/esm/node/plugin/plugins/envVars.js +6 -2
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +17 -5
- package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.js +2 -19
- package/dist/esm/node/plugin/plugins/importBuild/index.d.ts +6 -1
- package/dist/esm/node/plugin/plugins/importBuild/index.js +5 -8
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +13 -93
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +39 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +29 -47
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +27 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.d.ts → transformFileImports.d.ts} +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +6 -6
- 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 +20 -26
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +155 -109
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +1 -15
- package/dist/esm/node/plugin/shared/rollupSourceMap.d.ts +14 -0
- package/dist/esm/node/plugin/shared/rollupSourceMap.js +17 -0
- package/dist/esm/node/plugin/utils.d.ts +3 -2
- package/dist/esm/node/plugin/utils.js +3 -2
- package/dist/esm/node/prerender/runPrerender.js +15 -7
- package/dist/esm/node/runtime/globalContext.d.ts +3 -10
- package/dist/esm/node/runtime/globalContext.js +15 -23
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/esm/node/runtime/html/renderHtml.js +1 -1
- package/dist/esm/node/runtime/html/stream.js +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.d.ts +6 -5
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +39 -39
- package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -5
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +6 -7
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +24 -29
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/esm/node/runtime/renderPage/logErrorHint.d.ts +8 -0
- package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +80 -42
- package/dist/esm/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -24
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/node/shared/ViteManifest.d.ts +1 -0
- package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -1
- package/dist/esm/node/shared/assertPluginManifest.js +2 -5
- package/dist/esm/node/shared/assertV1Design.d.ts +4 -0
- package/dist/esm/node/shared/assertV1Design.js +23 -0
- package/dist/esm/node/shared/getClientEntry.d.ts +3 -0
- package/dist/esm/node/shared/{getClientEntryFilePath.js → getClientEntry.js} +2 -2
- package/dist/esm/node/shared/prependEntriesDir.d.ts +2 -0
- package/dist/esm/node/shared/prependEntriesDir.js +10 -0
- package/dist/esm/node/shared/utils.d.ts +2 -0
- package/dist/esm/node/shared/utils.js +2 -0
- package/dist/esm/shared/page-configs/Config.d.ts +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +3 -3
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
- package/dist/esm/shared/route/executeGuardHook.js +3 -2
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -1
- package/dist/esm/utils/assertNodeVersion.js +2 -2
- package/dist/esm/utils/findFile.d.ts +3 -0
- package/dist/esm/utils/findFile.js +21 -0
- package/dist/esm/utils/getOutDirs.d.ts +1 -0
- package/dist/esm/utils/isVersionOrAbove.d.ts +2 -0
- package/dist/esm/utils/isVersionOrAbove.js +26 -0
- package/dist/esm/utils/nodeEnv.d.ts +4 -0
- package/dist/esm/utils/nodeEnv.js +19 -0
- package/dist/esm/utils/objectKeys.d.ts +10 -1
- package/dist/esm/utils/objectKeys.js +20 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/sorter.d.ts +59 -0
- package/dist/esm/utils/sorter.js +61 -0
- package/package.json +2 -2
- package/dist/cjs/node/plugin/shared/removeSourceMap.js +0 -12
- package/dist/cjs/utils/objectEntries.js +0 -8
- package/dist/esm/node/plugin/shared/removeSourceMap.d.ts +0 -7
- package/dist/esm/node/plugin/shared/removeSourceMap.js +0 -9
- package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.d.ts +0 -13
- package/dist/esm/node/shared/getClientEntryFilePath.d.ts +0 -3
- package/dist/esm/utils/findUserPackageJsonPath.d.ts +0 -2
- package/dist/esm/utils/findUserPackageJsonPath.js +0 -18
- package/dist/esm/utils/objectEntries.d.ts +0 -4
- package/dist/esm/utils/objectEntries.js +0 -5
- /package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.d.ts → loadFileAtConfigTime.d.ts} +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.d.ts +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export { resolveFilePathRelativeToUserRootDir };
|
|
2
|
+
export { resolveFilePathAbsoluteFilesystem };
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { assert, assertPosixPath } from '../../../../utils.js';
|
|
5
|
+
function resolveFilePathRelativeToUserRootDir(filePathRelativeToUserRootDir, userRootDir) {
|
|
6
|
+
assertPosixPath(filePathRelativeToUserRootDir);
|
|
7
|
+
assertPosixPath(userRootDir);
|
|
8
|
+
const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathRelativeToUserRootDir);
|
|
9
|
+
return getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem);
|
|
10
|
+
}
|
|
11
|
+
function resolveFilePathAbsoluteFilesystem(filePathAbsoluteFilesystem, userRootDir) {
|
|
12
|
+
assertPosixPath(filePathAbsoluteFilesystem);
|
|
13
|
+
assertPosixPath(userRootDir);
|
|
14
|
+
let filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem);
|
|
15
|
+
assert(!filePathRelativeToUserRootDir.startsWith('.') && !filePathRelativeToUserRootDir.startsWith('/'));
|
|
16
|
+
filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir;
|
|
17
|
+
return getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem);
|
|
18
|
+
}
|
|
19
|
+
function getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem) {
|
|
20
|
+
return {
|
|
21
|
+
filePathRelativeToUserRootDir,
|
|
22
|
+
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
23
|
+
filePathAbsoluteFilesystem,
|
|
24
|
+
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
25
|
+
importPathAbsolute: null
|
|
26
|
+
};
|
|
27
|
+
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { resolveImportPath };
|
|
|
3
3
|
export { assertImportPath };
|
|
4
4
|
export { clearFilesEnvMap };
|
|
5
5
|
import type { ConfigEnvInternal, DefinedAtFileFullInfo, FilePathResolved } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
6
|
-
import { type ImportData } from './
|
|
6
|
+
import { type ImportData } from './transformFileImports.js';
|
|
7
7
|
declare function resolveImport(configValue: unknown, importerFilePath: FilePathResolved, userRootDir: string, configEnv: ConfigEnvInternal, configName: string): null | (DefinedAtFileFullInfo & {
|
|
8
8
|
fileExportName: string;
|
|
9
9
|
});
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js
CHANGED
|
@@ -4,7 +4,7 @@ export { assertImportPath };
|
|
|
4
4
|
export { clearFilesEnvMap };
|
|
5
5
|
import pc from '@brillout/picocolors';
|
|
6
6
|
import { assert, assertPosixPath, assertUsage, deepEqual, requireResolve } from '../../../../utils.js';
|
|
7
|
-
import { parseImportData } from './
|
|
7
|
+
import { parseImportData } from './transformFileImports.js';
|
|
8
8
|
import path from 'path';
|
|
9
9
|
const filesEnvMap = new Map();
|
|
10
10
|
function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { transformFileImports };
|
|
2
2
|
export { parseImportData };
|
|
3
3
|
export { isImportData };
|
|
4
4
|
export type { FileImport };
|
|
@@ -8,7 +8,7 @@ type FileImport = {
|
|
|
8
8
|
importString: string;
|
|
9
9
|
importLocalName: string;
|
|
10
10
|
};
|
|
11
|
-
declare function
|
|
11
|
+
declare function transformFileImports(code: string, filePathToShowToUser2: string, skipWarnings?: true): {
|
|
12
12
|
noTransformation: true;
|
|
13
13
|
} | {
|
|
14
14
|
noTransformation: false;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { transformFileImports };
|
|
2
2
|
export { parseImportData };
|
|
3
3
|
export { isImportData };
|
|
4
4
|
// Playground: https://github.com/brillout/acorn-playground
|
|
@@ -7,8 +7,8 @@ export { isImportData };
|
|
|
7
7
|
import { parse } from 'acorn';
|
|
8
8
|
import { assert, assertUsage, assertWarning, styleFileRE } from '../../../../utils.js';
|
|
9
9
|
import pc from '@brillout/picocolors';
|
|
10
|
-
function
|
|
11
|
-
// For ./
|
|
10
|
+
function transformFileImports(code, filePathToShowToUser2,
|
|
11
|
+
// For ./transformFileImports.spec.ts
|
|
12
12
|
skipWarnings) {
|
|
13
13
|
const spliceOperations = [];
|
|
14
14
|
const fileImportsTransformed = [];
|
|
@@ -23,8 +23,8 @@ skipWarnings) {
|
|
|
23
23
|
return;
|
|
24
24
|
const importPath = node.source.value;
|
|
25
25
|
assert(typeof importPath === 'string');
|
|
26
|
-
// - This doesn't work. To make it work we would need to run esbuild twice: esbuild for TypeScript to JavaScript =>
|
|
27
|
-
// - Or we use an esbuild plugin to apply
|
|
26
|
+
// - This doesn't work. To make it work we would need to run esbuild twice: esbuild for TypeScript to JavaScript => transformFileImports() => esbuild for bundling.
|
|
27
|
+
// - Or we use an esbuild plugin to apply transformFileImports(). Maybe we can completely skip the need for acorn?
|
|
28
28
|
// - ?real breaks TypeScript, and TypeScript isn't working on supporting query params: https://github.com/microsoft/TypeScript/issues/10988#issuecomment-867135453
|
|
29
29
|
// - Import attributes would be the best.
|
|
30
30
|
// - But it only works with Node.js >=21: https://nodejs.org/api/esm.html#import-attributes
|
|
@@ -32,7 +32,7 @@ skipWarnings) {
|
|
|
32
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
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
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
|
|
35
|
+
// - Maybe we can use an esbuild plugin instead of acorn to apply transformFileImports()?
|
|
36
36
|
// - Using a magic comment `// @vike-real-import` is tricky:
|
|
37
37
|
// - Esbuild removes comments: https://github.com/evanw/esbuild/issues/1439#issuecomment-877656182
|
|
38
38
|
// - Using source maps to track these magic comments is brittle (source maps can easily break)
|
|
@@ -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, transformImports: boolean, userRootDir: string, doNotTranspile?: boolean): Promise<{
|
|
8
8
|
fileExports: Record<string, unknown>;
|
|
9
9
|
}>;
|
|
10
10
|
declare function getConfigBuildErrorFormatted(err: unknown): null | string;
|
|
@@ -8,13 +8,14 @@ import path from 'path';
|
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { import_ } from '@brillout/import';
|
|
10
10
|
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, unique, assertWarning, isObject, toPosixPath } from '../../../../utils.js';
|
|
11
|
-
import { isImportData,
|
|
11
|
+
import { isImportData, transformFileImports } from './transformFileImports.js';
|
|
12
12
|
import { vikeConfigDependencies } from '../getVikeConfig.js';
|
|
13
13
|
import 'source-map-support/register.js';
|
|
14
14
|
import { getConfigFileExport } from '../getConfigFileExport.js';
|
|
15
15
|
assertIsNotProductionRuntime();
|
|
16
|
-
async function transpileAndExecuteFile(filePath,
|
|
17
|
-
if (
|
|
16
|
+
async function transpileAndExecuteFile(filePath, transformImports, userRootDir, doNotTranspile = false) {
|
|
17
|
+
if (doNotTranspile) {
|
|
18
|
+
assert(!transformImports);
|
|
18
19
|
const fileExports = await executeFile(filePath.filePathAbsoluteFilesystem, filePath);
|
|
19
20
|
if (isHeaderFile(filePath.filePathAbsoluteFilesystem)) {
|
|
20
21
|
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
@@ -23,21 +24,20 @@ async function transpileAndExecuteFile(filePath, isValueFile, userRootDir, isCon
|
|
|
23
24
|
return { fileExports };
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
26
|
-
const { code, fileImportsTransformed } = await transpileFile(filePath,
|
|
27
|
-
const fileExports = await executeTranspiledFile(filePath, code, fileImportsTransformed
|
|
27
|
+
const { code, fileImportsTransformed } = await transpileFile(filePath, transformImports, userRootDir);
|
|
28
|
+
const fileExports = await executeTranspiledFile(filePath, code, fileImportsTransformed);
|
|
28
29
|
return { fileExports };
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
async function transpileFile(filePath,
|
|
32
|
+
async function transpileFile(filePath, transformImports, userRootDir) {
|
|
32
33
|
const { filePathAbsoluteFilesystem } = filePath;
|
|
33
34
|
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
34
35
|
assertPosixPath(filePathAbsoluteFilesystem);
|
|
35
36
|
vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
36
|
-
|
|
37
|
-
let code = await transpileWithEsbuild(filePath, userRootDir, importsAreTransformed, isValueFile);
|
|
37
|
+
let code = await transpileWithEsbuild(filePath, userRootDir, transformImports);
|
|
38
38
|
let fileImportsTransformed = null;
|
|
39
|
-
if (
|
|
40
|
-
const res =
|
|
39
|
+
if (transformImports) {
|
|
40
|
+
const res = transformFileImports_(code, filePath);
|
|
41
41
|
if (res) {
|
|
42
42
|
code = res.code;
|
|
43
43
|
fileImportsTransformed = res.fileImportsTransformed;
|
|
@@ -45,21 +45,16 @@ async function transpileFile(filePath, isValueFile, userRootDir) {
|
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
47
|
if (isHeaderFile(filePathAbsoluteFilesystem)) {
|
|
48
|
-
|
|
49
|
-
assertWarning(false, `${filePathToShowToUser2} is a JavaScript header file (.h.js), but JavaScript header files only apply to +config.h.js, see https://vike.dev/header-file`, { onlyOnce: true });
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
assert(false);
|
|
53
|
-
}
|
|
48
|
+
assertWarning(false, `${filePathToShowToUser2} is a JavaScript header file (.h.js), but JavaScript header files only apply to +config.h.js, see https://vike.dev/header-file`, { onlyOnce: true });
|
|
54
49
|
}
|
|
55
50
|
}
|
|
56
51
|
return { code, fileImportsTransformed };
|
|
57
52
|
}
|
|
58
|
-
function
|
|
53
|
+
function transformFileImports_(codeOriginal, filePath) {
|
|
59
54
|
const { filePathAbsoluteFilesystem } = filePath;
|
|
60
55
|
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
61
56
|
// Replace import statements with import strings
|
|
62
|
-
const res =
|
|
57
|
+
const res = transformFileImports(codeOriginal, filePathToShowToUser2);
|
|
63
58
|
if (res.noTransformation) {
|
|
64
59
|
return null;
|
|
65
60
|
}
|
|
@@ -72,8 +67,7 @@ function transformImports_(codeOriginal, filePath) {
|
|
|
72
67
|
}
|
|
73
68
|
return { code, fileImportsTransformed };
|
|
74
69
|
}
|
|
75
|
-
async function transpileWithEsbuild(filePath, userRootDir,
|
|
76
|
-
const isConfigFile = !isValueFile;
|
|
70
|
+
async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
77
71
|
const entryFilePath = filePath.filePathAbsoluteFilesystem;
|
|
78
72
|
const entryFileDir = path.posix.dirname(entryFilePath);
|
|
79
73
|
const options = {
|
|
@@ -94,12 +88,12 @@ async function transpileWithEsbuild(filePath, userRootDir, importsAreTransformed
|
|
|
94
88
|
// Esbuild still sometimes removes unused imports because of TypeScript: https://github.com/evanw/esbuild/issues/3034
|
|
95
89
|
treeShaking: false,
|
|
96
90
|
minify: false,
|
|
97
|
-
metafile:
|
|
91
|
+
metafile: !transformImports,
|
|
98
92
|
// We cannot bundle imports that are meant to be transformed
|
|
99
|
-
bundle: !
|
|
93
|
+
bundle: !transformImports
|
|
100
94
|
};
|
|
101
95
|
// Track dependencies
|
|
102
|
-
if (
|
|
96
|
+
if (!transformImports) {
|
|
103
97
|
options.packages = 'external';
|
|
104
98
|
options.plugins = [
|
|
105
99
|
{
|
|
@@ -134,7 +128,7 @@ async function transpileWithEsbuild(filePath, userRootDir, importsAreTransformed
|
|
|
134
128
|
throw err;
|
|
135
129
|
}
|
|
136
130
|
// Track dependencies
|
|
137
|
-
if (
|
|
131
|
+
if (!transformImports) {
|
|
138
132
|
assert(result.metafile);
|
|
139
133
|
Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
|
|
140
134
|
filePathRelative = toPosixPath(filePathRelative);
|
|
@@ -147,7 +141,7 @@ async function transpileWithEsbuild(filePath, userRootDir, importsAreTransformed
|
|
|
147
141
|
assert(typeof code === 'string');
|
|
148
142
|
return code;
|
|
149
143
|
}
|
|
150
|
-
async function executeTranspiledFile(filePath, code, fileImportsTransformed
|
|
144
|
+
async function executeTranspiledFile(filePath, code, fileImportsTransformed) {
|
|
151
145
|
const { filePathAbsoluteFilesystem, filePathRelativeToUserRootDir } = filePath;
|
|
152
146
|
// Alternative to using a temporary file: https://github.com/vitejs/vite/pull/13269
|
|
153
147
|
// - But seems to break source maps, so I don't think it's worth it
|
|
@@ -161,7 +155,7 @@ async function executeTranspiledFile(filePath, code, fileImportsTransformed, isV
|
|
|
161
155
|
finally {
|
|
162
156
|
clean();
|
|
163
157
|
}
|
|
164
|
-
if (fileImportsTransformed
|
|
158
|
+
if (fileImportsTransformed) {
|
|
165
159
|
assert(filePathRelativeToUserRootDir !== undefined);
|
|
166
160
|
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
167
161
|
assertImportsAreReExported(fileImportsTransformed, fileExports, filePathToShowToUser2);
|
|
@@ -2,11 +2,15 @@ export { getVikeConfig };
|
|
|
2
2
|
export { reloadVikeConfig };
|
|
3
3
|
export { vikeConfigDependencies };
|
|
4
4
|
export { isVikeConfigFile };
|
|
5
|
+
export { isV1Design };
|
|
6
|
+
export type { VikeConfig };
|
|
5
7
|
export type { InterfaceValueFile };
|
|
6
8
|
import type { PageConfigGlobalBuildTime, PageConfigBuildTime, FilePathResolved } from '../../../../../shared/page-configs/PageConfig.js';
|
|
7
9
|
import type { ExtensionResolved } from '../../../../../shared/ConfigVike.js';
|
|
10
|
+
import { type LocationId } from './getVikeConfig/filesystemRouting.js';
|
|
8
11
|
import type { ResolvedConfig } from 'vite';
|
|
9
12
|
type InterfaceFileCommons = {
|
|
13
|
+
locationId: LocationId;
|
|
10
14
|
filePath: FilePathResolved;
|
|
11
15
|
fileExportsByConfigName: Record<ConfigName, {
|
|
12
16
|
configValue?: unknown;
|
|
@@ -26,4 +30,5 @@ type VikeConfig = {
|
|
|
26
30
|
declare const vikeConfigDependencies: Set<string>;
|
|
27
31
|
declare function reloadVikeConfig(userRootDir: string, outDirRoot: string, extensions: ExtensionResolved[]): void;
|
|
28
32
|
declare function getVikeConfig(config: ResolvedConfig, isDev: boolean, tolerateInvalidConfig?: boolean, extensions?: ExtensionResolved[]): Promise<VikeConfig>;
|
|
33
|
+
declare function isV1Design(config: ResolvedConfig, isDev: boolean): Promise<boolean>;
|
|
29
34
|
declare function isVikeConfigFile(filePath: string): boolean;
|