vike 0.4.160 → 0.4.161-commit-ba539a4
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/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/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 +8 -7
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +15 -19
- 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/node/shared/{getClientEntryFilePath.js → getClientEntry.js} +3 -3
- package/dist/cjs/node/shared/prependEntriesDir.js +13 -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/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/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.js +8 -7
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +16 -20
- 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/node/shared/ViteManifest.d.ts +1 -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/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 +2 -2
- package/dist/cjs/utils/objectEntries.js +0 -8
- 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/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js
CHANGED
|
@@ -3,34 +3,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getLogicalPath = exports.applyFilesystemRoutingRootEffect = exports.isGlobalLocation = exports.sortAfterInheritanceOrder = exports.getLocationId = exports.isInherited = exports.getFilesystemRouteDefinedBy = exports.getFilesystemRouteString = void 0;
|
|
4
4
|
const utils_js_1 = require("../../../../utils.js");
|
|
5
5
|
/**
|
|
6
|
-
* getLocationId('/pages/some-page/+Page.js') => '/pages/some-page'
|
|
7
|
-
* getLocationId('/
|
|
8
|
-
*
|
|
6
|
+
* `getLocationId('/pages/some-page/+Page.js')` => `'/pages/some-page'`
|
|
7
|
+
* `getLocationId('/renderer/+config.js')` => `'/renderer'`
|
|
8
|
+
*
|
|
9
|
+
* The value `locationId` is always a user-land path, because Filesystem Routing/Inheritance only applies to the user-land (Vike never uses Filesystem Routing/Inheritance for `node_modules/**`).
|
|
9
10
|
*/
|
|
10
|
-
function getLocationId(
|
|
11
|
-
|
|
11
|
+
function getLocationId(
|
|
12
|
+
// We always determine `locationId` from a real user-land file: the `locationId` for Vike extensions is the `locationId` of the the user's `+config.h.js` that extends the Vike extension.
|
|
13
|
+
filePathRelativeToUserRootDir) {
|
|
14
|
+
(0, utils_js_1.assertPosixPath)(filePathRelativeToUserRootDir);
|
|
15
|
+
(0, utils_js_1.assert)(filePathRelativeToUserRootDir.startsWith('/'));
|
|
16
|
+
const locationId = removeFilename(filePathRelativeToUserRootDir);
|
|
12
17
|
assertLocationId(locationId);
|
|
13
18
|
return locationId;
|
|
14
19
|
}
|
|
15
20
|
exports.getLocationId = getLocationId;
|
|
16
|
-
/**
|
|
21
|
+
/** Filesystem Routing: get the URL */
|
|
17
22
|
function getFilesystemRouteString(locationId) {
|
|
18
23
|
return getLogicalPath(locationId, ['renderer', 'pages', 'src', 'index']);
|
|
19
24
|
}
|
|
20
25
|
exports.getFilesystemRouteString = getFilesystemRouteString;
|
|
21
|
-
/**
|
|
22
|
-
function getInheritanceRoot(
|
|
23
|
-
return getLogicalPath(
|
|
26
|
+
/** Filesystem Inheritance: get the apply root */
|
|
27
|
+
function getInheritanceRoot(locationId) {
|
|
28
|
+
return getLogicalPath(locationId, ['renderer']);
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
31
|
* getLogicalPath('/pages/some-page', ['pages']) => '/some-page'
|
|
27
|
-
* getLogicalPath('some-npm-pkg/renderer', ['renderer']) => '/'
|
|
28
32
|
*/
|
|
29
|
-
function getLogicalPath(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return someDir;
|
|
33
|
+
function getLogicalPath(locationId, removeDirs) {
|
|
34
|
+
let logicalPath = removeDirectories(locationId, removeDirs);
|
|
35
|
+
assertIsPath(logicalPath);
|
|
36
|
+
return logicalPath;
|
|
34
37
|
}
|
|
35
38
|
exports.getLogicalPath = getLogicalPath;
|
|
36
39
|
/** Whether configs defined in `locationId` apply in every `locationIds` */
|
|
@@ -39,6 +42,10 @@ function isGlobalLocation(locationId, locationIds) {
|
|
|
39
42
|
}
|
|
40
43
|
exports.isGlobalLocation = isGlobalLocation;
|
|
41
44
|
function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
45
|
+
assertLocationId(locationId1);
|
|
46
|
+
assertLocationId(locationId2);
|
|
47
|
+
if (locationId1 === locationId2)
|
|
48
|
+
return 0;
|
|
42
49
|
const inheritanceRoot1 = getInheritanceRoot(locationId1);
|
|
43
50
|
const inheritanceRoot2 = getInheritanceRoot(locationId2);
|
|
44
51
|
const inheritanceRootPage = getInheritanceRoot(locationIdPage);
|
|
@@ -54,15 +61,10 @@ function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
|
54
61
|
(0, utils_js_1.assert)(inheritanceRoot1.length !== inheritanceRoot2.length);
|
|
55
62
|
return (0, utils_js_1.higherFirst)((inheritanceRoot) => inheritanceRoot.length)(inheritanceRoot1, inheritanceRoot2);
|
|
56
63
|
}
|
|
57
|
-
// Should be true since we aggregate interface files by locationId
|
|
58
|
-
(0, utils_js_1.assert)(locationId1 !== locationId2);
|
|
59
64
|
// locationId1 first, i.e. `indexOf(locationId1) < indexOf(locationId2)`
|
|
60
65
|
const locationId1First = -1;
|
|
61
66
|
// locationId2 first, i.e. `indexOf(locationId2) < indexOf(locationId1)`
|
|
62
67
|
const locationId2First = 1;
|
|
63
|
-
if (locationIsNpmPackage(locationId1) !== locationIsNpmPackage(locationId2)) {
|
|
64
|
-
return locationIsNpmPackage(locationId1) ? locationId2First : locationId1First;
|
|
65
|
-
}
|
|
66
68
|
if (locationIsRendererDir(locationId1) !== locationIsRendererDir(locationId2)) {
|
|
67
69
|
return locationIsRendererDir(locationId1) ? locationId2First : locationId1First;
|
|
68
70
|
}
|
|
@@ -74,9 +76,6 @@ function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
|
74
76
|
return locationId1 > locationId2 ? locationId1First : locationId2First;
|
|
75
77
|
}
|
|
76
78
|
exports.sortAfterInheritanceOrder = sortAfterInheritanceOrder;
|
|
77
|
-
function locationIsNpmPackage(locationId) {
|
|
78
|
-
return !locationId.startsWith('/');
|
|
79
|
-
}
|
|
80
79
|
function locationIsRendererDir(locationId) {
|
|
81
80
|
return locationId.split('/').includes('renderer');
|
|
82
81
|
}
|
|
@@ -87,19 +86,6 @@ function isInherited(locationId1, locationId2) {
|
|
|
87
86
|
return startsWith(inheritanceRoot2, inheritanceRoot1);
|
|
88
87
|
}
|
|
89
88
|
exports.isInherited = isInherited;
|
|
90
|
-
function removeNpmPackageName(somePath) {
|
|
91
|
-
if (!(0, utils_js_1.isNpmPackageImport)(somePath)) {
|
|
92
|
-
(0, utils_js_1.assert)(somePath.startsWith('/'));
|
|
93
|
-
return somePath;
|
|
94
|
-
}
|
|
95
|
-
const importPath = (0, utils_js_1.getNpmPackageImportPath)(somePath);
|
|
96
|
-
if (!importPath)
|
|
97
|
-
return '/';
|
|
98
|
-
(0, utils_js_1.assertPosixPath)(importPath);
|
|
99
|
-
(0, utils_js_1.assert)(!importPath.startsWith('/'));
|
|
100
|
-
somePath = '/' + importPath;
|
|
101
|
-
return somePath;
|
|
102
|
-
}
|
|
103
89
|
function removeDirectories(somePath, removeDirs) {
|
|
104
90
|
(0, utils_js_1.assertPosixPath)(somePath);
|
|
105
91
|
somePath = somePath
|
|
@@ -110,17 +96,13 @@ function removeDirectories(somePath, removeDirs) {
|
|
|
110
96
|
somePath = '/';
|
|
111
97
|
return somePath;
|
|
112
98
|
}
|
|
113
|
-
function removeFilename(
|
|
114
|
-
|
|
115
|
-
(0, utils_js_1.assert)(filePathAbsoluteVite.startsWith('/') || (0, utils_js_1.isNpmPackageImport)(filePathAbsoluteVite));
|
|
99
|
+
function removeFilename(filePathRelativeToUserRootDir) {
|
|
100
|
+
const filePathParts = filePathRelativeToUserRootDir.split('/');
|
|
116
101
|
{
|
|
117
|
-
const filename =
|
|
118
|
-
|
|
119
|
-
(0, utils_js_1.assert)(optional);
|
|
120
|
-
return filePathAbsoluteVite;
|
|
121
|
-
}
|
|
102
|
+
const filename = filePathParts.slice(-1)[0];
|
|
103
|
+
(0, utils_js_1.assert)(filename.includes('.'));
|
|
122
104
|
}
|
|
123
|
-
let locationId =
|
|
105
|
+
let locationId = filePathParts.slice(0, -1).join('/');
|
|
124
106
|
if (locationId === '')
|
|
125
107
|
locationId = '/';
|
|
126
108
|
assertLocationId(locationId);
|
|
@@ -144,7 +126,7 @@ function applyFilesystemRoutingRootEffect(routeFilesystem, filesystemRoutingRoot
|
|
|
144
126
|
}
|
|
145
127
|
exports.applyFilesystemRoutingRootEffect = applyFilesystemRoutingRootEffect;
|
|
146
128
|
function assertLocationId(locationId) {
|
|
147
|
-
(0, utils_js_1.assert)(locationId.startsWith('/')
|
|
129
|
+
(0, utils_js_1.assert)(locationId.startsWith('/'));
|
|
148
130
|
(0, utils_js_1.assert)(!locationId.endsWith('/') || locationId === '/');
|
|
149
131
|
}
|
|
150
132
|
function assertIsPath(logicalPath) {
|
|
@@ -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) => {
|