vike 0.4.160 → 0.4.161
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 +42 -15
- 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/extractAssetsPlugin.js +7 -2
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +4 -7
- 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 +155 -111
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- package/dist/cjs/node/plugin/utils.js +3 -2
- package/dist/cjs/node/prerender/runPrerender.js +12 -5
- package/dist/cjs/node/runtime/globalContext.js +7 -4
- 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/executeOnRenderHtmlHook.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +39 -39
- 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/utils.js +1 -1
- 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 +43 -16
- 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/extractAssetsPlugin.js +8 -3
- package/dist/esm/node/plugin/plugins/importBuild/index.d.ts +6 -1
- package/dist/esm/node/plugin/plugins/importBuild/index.js +4 -7
- 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 +4 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +153 -109
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- 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 +13 -6
- package/dist/esm/node/runtime/globalContext.js +8 -5
- 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/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/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/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/shared/page-configs/Config.d.ts +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +2 -0
- 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 +1 -1
- package/dist/cjs/utils/objectEntries.js +0 -8
- package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.d.ts +0 -13
- 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
|
@@ -9,7 +9,7 @@ const utils_js_1 = require("../../../../utils.js");
|
|
|
9
9
|
const transpileAndExecuteFile_js_1 = require("./transpileAndExecuteFile.js");
|
|
10
10
|
const assertPlusFileExport_js_1 = require("../../../../../../shared/page-configs/assertPlusFileExport.js");
|
|
11
11
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
12
|
-
const
|
|
12
|
+
const transformFileImports_js_1 = require("./transformFileImports.js");
|
|
13
13
|
const getConfigFileExport_js_1 = require("../getConfigFileExport.js");
|
|
14
14
|
const resolveImportPath_js_1 = require("./resolveImportPath.js");
|
|
15
15
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
@@ -17,7 +17,7 @@ const resolveImportPath_js_1 = require("./resolveImportPath.js");
|
|
|
17
17
|
async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
18
18
|
const f = import_.filePathAbsoluteFilesystem;
|
|
19
19
|
if (!importedFilesLoaded[f]) {
|
|
20
|
-
importedFilesLoaded[f] = (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(import_,
|
|
20
|
+
importedFilesLoaded[f] = (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(import_, false, userRootDir).then((r) => r.fileExports);
|
|
21
21
|
}
|
|
22
22
|
const fileExports = await importedFilesLoaded[f];
|
|
23
23
|
const fileExport = fileExports[import_.fileExportName];
|
|
@@ -26,7 +26,7 @@ async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
|
26
26
|
exports.loadImportedFile = loadImportedFile;
|
|
27
27
|
// Load +{configName}.js
|
|
28
28
|
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
29
|
-
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(interfaceValueFile.filePath,
|
|
29
|
+
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(interfaceValueFile.filePath, false, userRootDir);
|
|
30
30
|
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
31
31
|
(0, assertPlusFileExport_js_1.assertPlusFileExport)(fileExports, filePathToShowToUser, configName);
|
|
32
32
|
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
@@ -39,7 +39,7 @@ exports.loadValueFile = loadValueFile;
|
|
|
39
39
|
async function loadConfigFile(configFilePath, userRootDir, visited, isConfigOfExtension) {
|
|
40
40
|
const { filePathAbsoluteFilesystem } = configFilePath;
|
|
41
41
|
assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem);
|
|
42
|
-
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(configFilePath,
|
|
42
|
+
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(configFilePath, !isConfigOfExtension, userRootDir, isConfigOfExtension);
|
|
43
43
|
const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [
|
|
44
44
|
...visited,
|
|
45
45
|
filePathAbsoluteFilesystem
|
|
@@ -121,7 +121,7 @@ function getExtendsImportData(configFileExports, configFilePath) {
|
|
|
121
121
|
(0, utils_js_1.assertUsage)(false, wrongUsage);
|
|
122
122
|
}
|
|
123
123
|
const extendsImportData = extendList.map((importDataSerialized) => {
|
|
124
|
-
const importData = (0,
|
|
124
|
+
const importData = (0, transformFileImports_js_1.parseImportData)(importDataSerialized);
|
|
125
125
|
(0, utils_js_1.assertUsage)(importData, wrongUsage);
|
|
126
126
|
return importData;
|
|
127
127
|
});
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveFilePathAbsoluteFilesystem = exports.resolveFilePathRelativeToUserRootDir = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const utils_js_1 = require("../../../../utils.js");
|
|
9
|
+
function resolveFilePathRelativeToUserRootDir(filePathRelativeToUserRootDir, userRootDir) {
|
|
10
|
+
(0, utils_js_1.assertPosixPath)(filePathRelativeToUserRootDir);
|
|
11
|
+
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
12
|
+
const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, filePathRelativeToUserRootDir);
|
|
13
|
+
return getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem);
|
|
14
|
+
}
|
|
15
|
+
exports.resolveFilePathRelativeToUserRootDir = resolveFilePathRelativeToUserRootDir;
|
|
16
|
+
function resolveFilePathAbsoluteFilesystem(filePathAbsoluteFilesystem, userRootDir) {
|
|
17
|
+
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
18
|
+
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
19
|
+
let filePathRelativeToUserRootDir = path_1.default.posix.relative(userRootDir, filePathAbsoluteFilesystem);
|
|
20
|
+
(0, utils_js_1.assert)(!filePathRelativeToUserRootDir.startsWith('.') && !filePathRelativeToUserRootDir.startsWith('/'));
|
|
21
|
+
filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir;
|
|
22
|
+
return getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem);
|
|
23
|
+
}
|
|
24
|
+
exports.resolveFilePathAbsoluteFilesystem = resolveFilePathAbsoluteFilesystem;
|
|
25
|
+
function getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem) {
|
|
26
|
+
return {
|
|
27
|
+
filePathRelativeToUserRootDir,
|
|
28
|
+
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
29
|
+
filePathAbsoluteFilesystem,
|
|
30
|
+
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
31
|
+
importPathAbsolute: null
|
|
32
|
+
};
|
|
33
|
+
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js
CHANGED
|
@@ -6,13 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.clearFilesEnvMap = exports.assertImportPath = exports.resolveImportPath = exports.resolveImport = void 0;
|
|
7
7
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
8
8
|
const utils_js_1 = require("../../../../utils.js");
|
|
9
|
-
const
|
|
9
|
+
const transformFileImports_js_1 = require("./transformFileImports.js");
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
11
|
const filesEnvMap = new Map();
|
|
12
12
|
function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
13
13
|
if (typeof configValue !== 'string')
|
|
14
14
|
return null;
|
|
15
|
-
const importData = (0,
|
|
15
|
+
const importData = (0, transformFileImports_js_1.parseImportData)(configValue);
|
|
16
16
|
if (!importData)
|
|
17
17
|
return null;
|
|
18
18
|
const { importPath, exportName } = importData;
|
|
@@ -3,15 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isImportData = exports.parseImportData = exports.
|
|
6
|
+
exports.isImportData = exports.parseImportData = exports.transformFileImports = void 0;
|
|
7
7
|
// Playground: https://github.com/brillout/acorn-playground
|
|
8
8
|
// Import attributes support: https://github.com/acornjs/acorn/issues/983
|
|
9
9
|
// - Isn't stage 4 yet: https://github.com/tc39/proposal-import-attributes
|
|
10
10
|
const acorn_1 = require("acorn");
|
|
11
11
|
const utils_js_1 = require("../../../../utils.js");
|
|
12
12
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
|
-
function
|
|
14
|
-
// For ./
|
|
13
|
+
function transformFileImports(code, filePathToShowToUser2,
|
|
14
|
+
// For ./transformFileImports.spec.ts
|
|
15
15
|
skipWarnings) {
|
|
16
16
|
const spliceOperations = [];
|
|
17
17
|
const fileImportsTransformed = [];
|
|
@@ -26,8 +26,8 @@ skipWarnings) {
|
|
|
26
26
|
return;
|
|
27
27
|
const importPath = node.source.value;
|
|
28
28
|
(0, utils_js_1.assert)(typeof importPath === 'string');
|
|
29
|
-
// - This doesn't work. To make it work we would need to run esbuild twice: esbuild for TypeScript to JavaScript =>
|
|
30
|
-
// - Or we use an esbuild plugin to apply
|
|
29
|
+
// - This doesn't work. To make it work we would need to run esbuild twice: esbuild for TypeScript to JavaScript => transformFileImports() => esbuild for bundling.
|
|
30
|
+
// - Or we use an esbuild plugin to apply transformFileImports(). Maybe we can completely skip the need for acorn?
|
|
31
31
|
// - ?real breaks TypeScript, and TypeScript isn't working on supporting query params: https://github.com/microsoft/TypeScript/issues/10988#issuecomment-867135453
|
|
32
32
|
// - Import attributes would be the best.
|
|
33
33
|
// - But it only works with Node.js >=21: https://nodejs.org/api/esm.html#import-attributes
|
|
@@ -35,7 +35,7 @@ skipWarnings) {
|
|
|
35
35
|
// - 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
|
|
36
36
|
// - Esbuid seems to support it: https://esbuild.github.io/plugins/#on-load-arguments:~:text=This%20contains%20a%20map%20of%20the%20import%20attributes%20that
|
|
37
37
|
// - acorn supports it over an acorn plugin: https://github.com/acornjs/acorn/issues/983
|
|
38
|
-
// - Maybe we can use an esbuild plugin instead of acorn to apply
|
|
38
|
+
// - Maybe we can use an esbuild plugin instead of acorn to apply transformFileImports()?
|
|
39
39
|
// - Using a magic comment `// @vike-real-import` is tricky:
|
|
40
40
|
// - Esbuild removes comments: https://github.com/evanw/esbuild/issues/1439#issuecomment-877656182
|
|
41
41
|
// - Using source maps to track these magic comments is brittle (source maps can easily break)
|
|
@@ -106,7 +106,7 @@ skipWarnings) {
|
|
|
106
106
|
const codeMod = spliceMany(code, spliceOperations);
|
|
107
107
|
return { code: codeMod, fileImportsTransformed, noTransformation: false };
|
|
108
108
|
}
|
|
109
|
-
exports.
|
|
109
|
+
exports.transformFileImports = transformFileImports;
|
|
110
110
|
function getImports(code) {
|
|
111
111
|
const { body } = (0, acorn_1.parse)(code, {
|
|
112
112
|
ecmaVersion: 'latest',
|
|
@@ -10,13 +10,14 @@ const path_1 = __importDefault(require("path"));
|
|
|
10
10
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
11
11
|
const import_1 = require("@brillout/import");
|
|
12
12
|
const utils_js_1 = require("../../../../utils.js");
|
|
13
|
-
const
|
|
13
|
+
const transformFileImports_js_1 = require("./transformFileImports.js");
|
|
14
14
|
const getVikeConfig_js_1 = require("../getVikeConfig.js");
|
|
15
15
|
require("source-map-support/register.js");
|
|
16
16
|
const getConfigFileExport_js_1 = require("../getConfigFileExport.js");
|
|
17
17
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
18
|
-
async function transpileAndExecuteFile(filePath,
|
|
19
|
-
if (
|
|
18
|
+
async function transpileAndExecuteFile(filePath, transformImports, userRootDir, doNotTranspile = false) {
|
|
19
|
+
if (doNotTranspile) {
|
|
20
|
+
(0, utils_js_1.assert)(!transformImports);
|
|
20
21
|
const fileExports = await executeFile(filePath.filePathAbsoluteFilesystem, filePath);
|
|
21
22
|
if (isHeaderFile(filePath.filePathAbsoluteFilesystem)) {
|
|
22
23
|
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
@@ -25,22 +26,21 @@ async function transpileAndExecuteFile(filePath, isValueFile, userRootDir, isCon
|
|
|
25
26
|
return { fileExports };
|
|
26
27
|
}
|
|
27
28
|
else {
|
|
28
|
-
const { code, fileImportsTransformed } = await transpileFile(filePath,
|
|
29
|
-
const fileExports = await executeTranspiledFile(filePath, code, fileImportsTransformed
|
|
29
|
+
const { code, fileImportsTransformed } = await transpileFile(filePath, transformImports, userRootDir);
|
|
30
|
+
const fileExports = await executeTranspiledFile(filePath, code, fileImportsTransformed);
|
|
30
31
|
return { fileExports };
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
exports.transpileAndExecuteFile = transpileAndExecuteFile;
|
|
34
|
-
async function transpileFile(filePath,
|
|
35
|
+
async function transpileFile(filePath, transformImports, userRootDir) {
|
|
35
36
|
const { filePathAbsoluteFilesystem } = filePath;
|
|
36
37
|
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
37
38
|
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
38
39
|
getVikeConfig_js_1.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
39
|
-
|
|
40
|
-
let code = await transpileWithEsbuild(filePath, userRootDir, importsAreTransformed, isValueFile);
|
|
40
|
+
let code = await transpileWithEsbuild(filePath, userRootDir, transformImports);
|
|
41
41
|
let fileImportsTransformed = null;
|
|
42
|
-
if (
|
|
43
|
-
const res =
|
|
42
|
+
if (transformImports) {
|
|
43
|
+
const res = transformFileImports_(code, filePath);
|
|
44
44
|
if (res) {
|
|
45
45
|
code = res.code;
|
|
46
46
|
fileImportsTransformed = res.fileImportsTransformed;
|
|
@@ -48,21 +48,16 @@ async function transpileFile(filePath, isValueFile, userRootDir) {
|
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
50
|
if (isHeaderFile(filePathAbsoluteFilesystem)) {
|
|
51
|
-
|
|
52
|
-
(0, utils_js_1.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 });
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
(0, utils_js_1.assert)(false);
|
|
56
|
-
}
|
|
51
|
+
(0, utils_js_1.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 });
|
|
57
52
|
}
|
|
58
53
|
}
|
|
59
54
|
return { code, fileImportsTransformed };
|
|
60
55
|
}
|
|
61
|
-
function
|
|
56
|
+
function transformFileImports_(codeOriginal, filePath) {
|
|
62
57
|
const { filePathAbsoluteFilesystem } = filePath;
|
|
63
58
|
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
64
59
|
// Replace import statements with import strings
|
|
65
|
-
const res = (0,
|
|
60
|
+
const res = (0, transformFileImports_js_1.transformFileImports)(codeOriginal, filePathToShowToUser2);
|
|
66
61
|
if (res.noTransformation) {
|
|
67
62
|
return null;
|
|
68
63
|
}
|
|
@@ -75,8 +70,7 @@ function transformImports_(codeOriginal, filePath) {
|
|
|
75
70
|
}
|
|
76
71
|
return { code, fileImportsTransformed };
|
|
77
72
|
}
|
|
78
|
-
async function transpileWithEsbuild(filePath, userRootDir,
|
|
79
|
-
const isConfigFile = !isValueFile;
|
|
73
|
+
async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
80
74
|
const entryFilePath = filePath.filePathAbsoluteFilesystem;
|
|
81
75
|
const entryFileDir = path_1.default.posix.dirname(entryFilePath);
|
|
82
76
|
const options = {
|
|
@@ -97,12 +91,12 @@ async function transpileWithEsbuild(filePath, userRootDir, importsAreTransformed
|
|
|
97
91
|
// Esbuild still sometimes removes unused imports because of TypeScript: https://github.com/evanw/esbuild/issues/3034
|
|
98
92
|
treeShaking: false,
|
|
99
93
|
minify: false,
|
|
100
|
-
metafile:
|
|
94
|
+
metafile: !transformImports,
|
|
101
95
|
// We cannot bundle imports that are meant to be transformed
|
|
102
|
-
bundle: !
|
|
96
|
+
bundle: !transformImports
|
|
103
97
|
};
|
|
104
98
|
// Track dependencies
|
|
105
|
-
if (
|
|
99
|
+
if (!transformImports) {
|
|
106
100
|
options.packages = 'external';
|
|
107
101
|
options.plugins = [
|
|
108
102
|
{
|
|
@@ -137,7 +131,7 @@ async function transpileWithEsbuild(filePath, userRootDir, importsAreTransformed
|
|
|
137
131
|
throw err;
|
|
138
132
|
}
|
|
139
133
|
// Track dependencies
|
|
140
|
-
if (
|
|
134
|
+
if (!transformImports) {
|
|
141
135
|
(0, utils_js_1.assert)(result.metafile);
|
|
142
136
|
Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
|
|
143
137
|
filePathRelative = (0, utils_js_1.toPosixPath)(filePathRelative);
|
|
@@ -150,7 +144,7 @@ async function transpileWithEsbuild(filePath, userRootDir, importsAreTransformed
|
|
|
150
144
|
(0, utils_js_1.assert)(typeof code === 'string');
|
|
151
145
|
return code;
|
|
152
146
|
}
|
|
153
|
-
async function executeTranspiledFile(filePath, code, fileImportsTransformed
|
|
147
|
+
async function executeTranspiledFile(filePath, code, fileImportsTransformed) {
|
|
154
148
|
const { filePathAbsoluteFilesystem, filePathRelativeToUserRootDir } = filePath;
|
|
155
149
|
// Alternative to using a temporary file: https://github.com/vitejs/vite/pull/13269
|
|
156
150
|
// - But seems to break source maps, so I don't think it's worth it
|
|
@@ -164,7 +158,7 @@ async function executeTranspiledFile(filePath, code, fileImportsTransformed, isV
|
|
|
164
158
|
finally {
|
|
165
159
|
clean();
|
|
166
160
|
}
|
|
167
|
-
if (fileImportsTransformed
|
|
161
|
+
if (fileImportsTransformed) {
|
|
168
162
|
(0, utils_js_1.assert)(filePathRelativeToUserRootDir !== undefined);
|
|
169
163
|
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
170
164
|
assertImportsAreReExported(fileImportsTransformed, fileExports, filePathToShowToUser2);
|
|
@@ -240,7 +234,7 @@ function assertImportsAreReExported(fileImportsTransformed, fileExports, filePat
|
|
|
240
234
|
Object.values(exportedStrings).forEach((exportVal) => {
|
|
241
235
|
if (typeof exportVal !== 'string')
|
|
242
236
|
return;
|
|
243
|
-
if (!(0,
|
|
237
|
+
if (!(0, transformFileImports_js_1.isImportData)(exportVal))
|
|
244
238
|
return;
|
|
245
239
|
const importString = exportVal;
|
|
246
240
|
fileImportsTransformed.forEach((fileImport) => {
|