vike 0.4.168 → 0.4.169
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/plugin/plugins/buildConfig.js +10 -2
- package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +1 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +19 -16
- package/dist/cjs/node/plugin/plugins/distFileNames.js +7 -1
- package/dist/cjs/node/plugin/plugins/envVars.js +1 -5
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +7 -7
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +14 -11
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +7 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +11 -14
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +129 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js +8 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +52 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +81 -106
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -2
- package/dist/cjs/node/plugin/shared/getFilePath.js +50 -49
- package/dist/cjs/node/plugin/utils.js +2 -2
- package/dist/cjs/node/prerender/runPrerender.js +6 -5
- package/dist/cjs/node/prerender/utils.js +2 -1
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +1 -0
- package/dist/cjs/node/runtime/index-common.js +14 -3
- package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +2 -1
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +25 -14
- package/dist/cjs/node/runtime/renderPage/log404/index.js +2 -2
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +1 -1
- package/dist/cjs/node/runtime/utils.js +2 -1
- package/dist/cjs/node/shared/assertV1Design.js +1 -1
- package/dist/cjs/node/shared/getClientEntry.js +2 -2
- package/dist/cjs/node/shared/prependEntriesDir.js +1 -0
- package/dist/cjs/node/shared/utils.js +0 -1
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +3 -3
- package/dist/cjs/shared/getPageFiles/getExports.js +8 -15
- package/dist/cjs/shared/getPageFiles.js +3 -6
- package/dist/cjs/shared/hooks/getHook.js +7 -6
- package/dist/cjs/shared/page-configs/getConfigDefinedAt.js +48 -0
- package/dist/cjs/shared/page-configs/{helpers/getConfigValue.js → getConfigValue.js} +6 -8
- package/dist/cjs/shared/page-configs/helpers.js +6 -11
- package/dist/cjs/shared/page-configs/serialize/assertPageConfigsSerialized.js +1 -1
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +2 -1
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesSerialized.js +11 -6
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +4 -3
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +3 -3
- package/dist/cjs/shared/route/index.js +2 -2
- package/dist/cjs/shared/route/loadPageRoutes.js +12 -10
- package/dist/cjs/shared/route/resolveRouteFunction.js +8 -9
- package/dist/cjs/shared/route/resolveRouteString.js +5 -16
- package/dist/cjs/shared/route/utils.js +0 -1
- package/dist/cjs/shared/utils.js +1 -0
- package/dist/cjs/utils/assertPathFilesystemAbsolute.js +39 -0
- package/dist/cjs/utils/createErrorWithCleanStackTrace.js +1 -7
- package/dist/cjs/utils/debug.js +2 -1
- package/dist/cjs/utils/findFile.js +2 -1
- package/dist/cjs/utils/hasProp.js +9 -5
- package/dist/cjs/utils/injectRollupInputs.js +2 -1
- package/dist/cjs/utils/isArray.js +8 -0
- package/dist/cjs/utils/isArrayOfStrings.js +8 -0
- package/dist/cjs/utils/isDev.js +12 -4
- package/dist/cjs/utils/isNpmPackage.js +1 -1
- package/dist/cjs/utils/isObjectOfStrings.js +8 -0
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +3 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +2 -1
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -0
- package/dist/esm/client/shared/getPageContextSerializedInHtml.d.ts +1 -0
- package/dist/esm/client/shared/getPageContextSerializedInHtml.js +1 -0
- package/dist/esm/client/shared/loadUserFilesClientSide.js +3 -7
- package/dist/esm/node/plugin/plugins/buildConfig.js +9 -1
- package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +2 -2
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +20 -17
- package/dist/esm/node/plugin/plugins/distFileNames.js +8 -2
- package/dist/esm/node/plugin/plugins/envVars.js +2 -6
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +9 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +14 -11
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +4 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +7 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +12 -15
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.d.ts +12 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +123 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.d.ts +8 -8
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js +7 -7
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +53 -13
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +81 -106
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/esm/node/plugin/shared/getFilePath.d.ts +11 -5
- package/dist/esm/node/plugin/shared/getFilePath.js +49 -48
- package/dist/esm/node/plugin/utils.d.ts +2 -2
- package/dist/esm/node/plugin/utils.js +2 -2
- package/dist/esm/node/prerender/runPrerender.js +6 -5
- package/dist/esm/node/prerender/utils.d.ts +2 -1
- package/dist/esm/node/prerender/utils.js +2 -1
- package/dist/esm/node/runtime/html/serializePageContextClientSide.d.ts +1 -0
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +1 -0
- package/dist/esm/node/runtime/index-common.d.ts +0 -4
- package/dist/esm/node/runtime/index-common.js +14 -3
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +2 -1
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +4 -4
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +27 -16
- package/dist/esm/node/runtime/renderPage/log404/index.js +2 -2
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -7
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +16 -16
- package/dist/esm/node/runtime/utils.d.ts +2 -1
- package/dist/esm/node/runtime/utils.js +2 -1
- package/dist/esm/node/shared/assertV1Design.js +1 -1
- package/dist/esm/node/shared/getClientEntry.js +1 -1
- package/dist/esm/node/shared/prependEntriesDir.js +1 -0
- package/dist/esm/node/shared/utils.d.ts +0 -1
- package/dist/esm/node/shared/utils.js +0 -1
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +1 -1
- package/dist/esm/shared/getPageFiles/getExports.d.ts +4 -5
- package/dist/esm/shared/getPageFiles/getExports.js +9 -16
- package/dist/esm/shared/getPageFiles.d.ts +1 -2
- package/dist/esm/shared/getPageFiles.js +1 -3
- package/dist/esm/shared/hooks/getHook.js +6 -5
- package/dist/esm/shared/page-configs/Config.d.ts +2 -2
- package/dist/esm/shared/page-configs/FilePath.d.ts +32 -22
- package/dist/esm/shared/page-configs/PageConfig.d.ts +27 -15
- package/dist/esm/shared/page-configs/getConfigDefinedAt.d.ts +11 -0
- package/dist/esm/shared/page-configs/getConfigDefinedAt.js +42 -0
- package/dist/esm/shared/page-configs/{helpers/getConfigValue.d.ts → getConfigValue.d.ts} +2 -2
- package/dist/esm/shared/page-configs/{helpers/getConfigValue.js → getConfigValue.js} +6 -8
- package/dist/esm/shared/page-configs/helpers.d.ts +3 -9
- package/dist/esm/shared/page-configs/helpers.js +6 -8
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +7 -4
- package/dist/esm/shared/page-configs/serialize/assertPageConfigsSerialized.js +2 -2
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +2 -1
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.js +12 -7
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +5 -4
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +3 -3
- package/dist/esm/shared/route/index.js +2 -2
- package/dist/esm/shared/route/loadPageRoutes.d.ts +3 -3
- package/dist/esm/shared/route/loadPageRoutes.js +10 -8
- package/dist/esm/shared/route/resolveRouteFunction.d.ts +1 -1
- package/dist/esm/shared/route/resolveRouteFunction.js +9 -10
- package/dist/esm/shared/route/resolveRouteString.d.ts +0 -2
- package/dist/esm/shared/route/resolveRouteString.js +5 -16
- package/dist/esm/shared/route/utils.d.ts +0 -1
- package/dist/esm/shared/route/utils.js +0 -1
- package/dist/esm/shared/utils.d.ts +1 -0
- package/dist/esm/shared/utils.js +1 -0
- package/dist/esm/utils/assertPathFilesystemAbsolute.d.ts +6 -0
- package/dist/esm/utils/assertPathFilesystemAbsolute.js +33 -0
- package/dist/esm/utils/createErrorWithCleanStackTrace.js +1 -7
- package/dist/esm/utils/debug.js +2 -1
- package/dist/esm/utils/findFile.js +2 -1
- package/dist/esm/utils/hasProp.d.ts +1 -0
- package/dist/esm/utils/hasProp.js +9 -5
- package/dist/esm/utils/injectRollupInputs.js +2 -1
- package/dist/esm/utils/isArray.d.ts +1 -0
- package/dist/esm/utils/isArray.js +4 -0
- package/dist/esm/utils/isArrayOfStrings.d.ts +2 -0
- package/dist/esm/utils/isArrayOfStrings.js +5 -0
- package/dist/esm/utils/isDev.d.ts +3 -0
- package/dist/esm/utils/isDev.js +11 -3
- package/dist/esm/utils/isNpmPackage.js +1 -1
- package/dist/esm/utils/isObjectOfStrings.d.ts +2 -0
- package/dist/esm/utils/isObjectOfStrings.js +5 -0
- 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/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +0 -136
- package/dist/cjs/shared/page-configs/helpers/getConfigDefinedAtString.js +0 -43
- package/dist/cjs/utils/assertPathIsFilesystemAbsolute.js +0 -21
- package/dist/cjs/utils/isStringRecord.js +0 -7
- package/dist/cjs/utils/mergeCumulativeValues.js +0 -21
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +0 -13
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +0 -130
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.d.ts +0 -7
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.js +0 -37
- package/dist/esm/utils/assertPathIsFilesystemAbsolute.d.ts +0 -3
- package/dist/esm/utils/assertPathIsFilesystemAbsolute.js +0 -15
- package/dist/esm/utils/isStringRecord.d.ts +0 -1
- package/dist/esm/utils/isStringRecord.js +0 -3
- package/dist/esm/utils/mergeCumulativeValues.d.ts +0 -2
- package/dist/esm/utils/mergeCumulativeValues.js +0 -18
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.manifestTempFile = exports.analyzeClientEntries = exports.assertRollupInput = exports.buildConfig = void 0;
|
|
7
7
|
const utils_js_1 = require("../utils.js");
|
|
8
8
|
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
9
|
-
const
|
|
9
|
+
const getConfigValue_js_1 = require("../../../shared/page-configs/getConfigValue.js");
|
|
10
10
|
const findPageFiles_js_1 = require("../shared/findPageFiles.js");
|
|
11
11
|
const getConfigVike_js_1 = require("../../shared/getConfigVike.js");
|
|
12
12
|
const virtualFilePageConfigValuesAll_js_1 = require("../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
|
|
@@ -156,7 +156,7 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
156
156
|
let clientEntries = {};
|
|
157
157
|
let clientEntryList = [];
|
|
158
158
|
pageConfigs.forEach((pageConfig) => {
|
|
159
|
-
const configValue = (0,
|
|
159
|
+
const configValue = (0, getConfigValue_js_1.getConfigValue)(pageConfig, 'clientRouting', 'boolean');
|
|
160
160
|
if (configValue?.value) {
|
|
161
161
|
hasClientRouting = true;
|
|
162
162
|
}
|
|
@@ -232,7 +232,15 @@ function getEntryFromPageConfig(pageConfig, isForClientSide) {
|
|
|
232
232
|
let { pageId } = pageConfig;
|
|
233
233
|
const entryTarget = (0, virtualFilePageConfigValuesAll_js_1.getVirtualFileIdPageConfigValuesAll)(pageId, isForClientSide);
|
|
234
234
|
let entryName = pageId;
|
|
235
|
+
// Avoid:
|
|
236
|
+
// ```
|
|
237
|
+
// dist/client/assets/entries/.Dp9wM6PK.js
|
|
238
|
+
// dist/server/entries/.mjs
|
|
239
|
+
// ```
|
|
240
|
+
if (entryName === '/')
|
|
241
|
+
entryName = 'root';
|
|
235
242
|
entryName = (0, prependEntriesDir_js_1.prependEntriesDir)(entryName);
|
|
243
|
+
(0, utils_js_1.assert)(!entryName.endsWith('/'));
|
|
236
244
|
return { entryName, entryTarget };
|
|
237
245
|
}
|
|
238
246
|
function resolve(filePath) {
|
|
@@ -80,7 +80,7 @@ function assertResolveAlias(config) {
|
|
|
80
80
|
exports.assertResolveAlias = assertResolveAlias;
|
|
81
81
|
function getAliases(config) {
|
|
82
82
|
const { alias } = config.resolve;
|
|
83
|
-
if (!
|
|
83
|
+
if (!(0, utils_js_1.isArray)(alias)) {
|
|
84
84
|
return [alias];
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
@@ -35,28 +35,32 @@ exports.determineOptimizeDeps = determineOptimizeDeps;
|
|
|
35
35
|
async function getPageDeps(config, pageConfigs, isDev) {
|
|
36
36
|
let entries = [];
|
|
37
37
|
let include = [];
|
|
38
|
+
const addEntry = (e) => {
|
|
39
|
+
(0, utils_js_1.assert)(e);
|
|
40
|
+
entries.push(e);
|
|
41
|
+
};
|
|
42
|
+
const addInclude = (e) => {
|
|
43
|
+
(0, utils_js_1.assert)(e);
|
|
44
|
+
// Shouldn't be a path alias, as path aliases would need to be added to config.optimizeDeps.entries instead of config.optimizeDeps.include
|
|
45
|
+
(0, utils_js_1.assertIsNpmPackageImport)(e);
|
|
46
|
+
include.push(e);
|
|
47
|
+
};
|
|
38
48
|
// V1 design
|
|
39
49
|
{
|
|
40
50
|
pageConfigs.forEach((pageConfig) => {
|
|
41
51
|
(0, getConfigValueSourcesNotOverriden_js_1.getConfigValueSourcesNotOverriden)(pageConfig).forEach((configValueSource) => {
|
|
42
52
|
if (!configValueSource.valueIsImportedAtRuntime)
|
|
43
53
|
return;
|
|
44
|
-
const {
|
|
54
|
+
const { definedAtFilePath, configEnv } = configValueSource;
|
|
45
55
|
if (!configEnv.client)
|
|
46
56
|
return;
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
(
|
|
50
|
-
// Surprisingly Vite expects entries to be absolute paths
|
|
51
|
-
entries.push(filePathAbsoluteFilesystem);
|
|
57
|
+
if (definedAtFilePath.filePathAbsoluteUserRootDir !== null) {
|
|
58
|
+
// Vite expects entries to be filesystem absolute paths (surprisingly so).
|
|
59
|
+
addEntry(definedAtFilePath.filePathAbsoluteFilesystem);
|
|
52
60
|
}
|
|
53
61
|
else {
|
|
54
|
-
// Adding
|
|
55
|
-
|
|
56
|
-
(0, utils_js_1.assert)(importPathAbsolute); // Help TS
|
|
57
|
-
// Shouldn't be a path alias, as path aliases would need to be added to config.optimizeDeps.entries instead of config.optimizeDeps.include
|
|
58
|
-
(0, utils_js_1.assertIsNpmPackageImport)(importPathAbsolute);
|
|
59
|
-
include.push(importPathAbsolute);
|
|
62
|
+
// Adding definedAtFilePath.filePathAbsoluteFilesystem doesn't work for npm packages, I guess because of Vite's config.server.fs.allow
|
|
63
|
+
addInclude(definedAtFilePath.importPathAbsolute);
|
|
60
64
|
}
|
|
61
65
|
});
|
|
62
66
|
});
|
|
@@ -68,8 +72,7 @@ async function getPageDeps(config, pageConfigs, isDev) {
|
|
|
68
72
|
pageFiles.forEach((filePathAbsoluteUserRootDir) => {
|
|
69
73
|
const entry = (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteUserRootDir, userRootDir });
|
|
70
74
|
const { filePathAbsoluteFilesystem } = entry;
|
|
71
|
-
(
|
|
72
|
-
entries.push(filePathAbsoluteFilesystem);
|
|
75
|
+
addEntry(filePathAbsoluteFilesystem);
|
|
73
76
|
});
|
|
74
77
|
}
|
|
75
78
|
entries = (0, utils_js_1.unique)(entries);
|
|
@@ -86,7 +89,7 @@ function getVirtualFiles(config, pageConfigs) {
|
|
|
86
89
|
return entriesVirtualFiles;
|
|
87
90
|
}
|
|
88
91
|
function normalizeEntries(entries) {
|
|
89
|
-
if (
|
|
92
|
+
if ((0, utils_js_1.isArray)(entries))
|
|
90
93
|
return entries;
|
|
91
94
|
if (typeof entries === 'string')
|
|
92
95
|
return [entries];
|
|
@@ -95,7 +98,7 @@ function normalizeEntries(entries) {
|
|
|
95
98
|
(0, utils_js_1.assert)(false);
|
|
96
99
|
}
|
|
97
100
|
function normalizeInclude(include) {
|
|
98
|
-
if (
|
|
101
|
+
if ((0, utils_js_1.isArray)(include))
|
|
99
102
|
return include;
|
|
100
103
|
if (include === undefined)
|
|
101
104
|
return [];
|
|
@@ -116,6 +116,12 @@ function clean(name, removePathSep, fixGlob) {
|
|
|
116
116
|
}
|
|
117
117
|
name = removeLeadingUnderscoreInFilename(name);
|
|
118
118
|
name = removeUnderscoreDoublets(name);
|
|
119
|
+
// Avoid:
|
|
120
|
+
// ```
|
|
121
|
+
// dist/client/assets/entries/.Dp9wM6PK.js
|
|
122
|
+
// dist/server/entries/.mjs
|
|
123
|
+
// ```
|
|
124
|
+
(0, utils_js_1.assert)(!name.endsWith('/'));
|
|
119
125
|
return name;
|
|
120
126
|
}
|
|
121
127
|
function fixExtractAssetsQuery(name) {
|
|
@@ -165,7 +171,7 @@ function getRollupOutputs(config) {
|
|
|
165
171
|
(_a = config.build).rollupOptions ?? (_a.rollupOptions = {});
|
|
166
172
|
(_b = config.build.rollupOptions).output ?? (_b.output = {});
|
|
167
173
|
const { output } = config.build.rollupOptions;
|
|
168
|
-
if (!
|
|
174
|
+
if (!(0, utils_js_1.isArray)(output)) {
|
|
169
175
|
return [output];
|
|
170
176
|
}
|
|
171
177
|
return output;
|
|
@@ -30,11 +30,7 @@ function envVarsPlugin() {
|
|
|
30
30
|
Object.entries(envsAll)
|
|
31
31
|
.filter(([key]) => {
|
|
32
32
|
// Already handled by Vite
|
|
33
|
-
const envPrefix = !config.envPrefix
|
|
34
|
-
? []
|
|
35
|
-
: Array.isArray(config.envPrefix)
|
|
36
|
-
? config.envPrefix
|
|
37
|
-
: [config.envPrefix];
|
|
33
|
+
const envPrefix = !config.envPrefix ? [] : (0, utils_js_1.isArray)(config.envPrefix) ? config.envPrefix : [config.envPrefix];
|
|
38
34
|
return !envPrefix.some((prefix) => key.startsWith(prefix));
|
|
39
35
|
})
|
|
40
36
|
.forEach(([envName, envVal]) => {
|
|
@@ -189,7 +189,7 @@ function analyzeImport(importStatement) {
|
|
|
189
189
|
if (rawRE.test(moduleName)) {
|
|
190
190
|
return { moduleName, skip: true };
|
|
191
191
|
}
|
|
192
|
-
/* We
|
|
192
|
+
/* We shouldn't do this because of aliased imports
|
|
193
193
|
if (!moduleName.startsWith('.')) {
|
|
194
194
|
return { moduleName, skip: true }
|
|
195
195
|
}
|
|
@@ -18,9 +18,11 @@ const getFilePath_js_1 = require("../../shared/getFilePath.js");
|
|
|
18
18
|
function importUserCode() {
|
|
19
19
|
let config;
|
|
20
20
|
let configVike;
|
|
21
|
+
let isDev_;
|
|
21
22
|
return {
|
|
22
23
|
name: 'vike:importUserCode',
|
|
23
|
-
config() {
|
|
24
|
+
config(_, env) {
|
|
25
|
+
isDev_ = (0, utils_js_1.isDev3)(env);
|
|
24
26
|
return {
|
|
25
27
|
experimental: {
|
|
26
28
|
// TODO/v1-release: remove
|
|
@@ -48,7 +50,7 @@ function importUserCode() {
|
|
|
48
50
|
}
|
|
49
51
|
},
|
|
50
52
|
async load(id, options) {
|
|
51
|
-
const isDev = (0, utils_js_1.isDev1)();
|
|
53
|
+
const isDev = isDev_ !== null ? isDev_ : (0, utils_js_1.isDev1)();
|
|
52
54
|
if (!(0, utils_js_1.isVirtualFileId)(id))
|
|
53
55
|
return undefined;
|
|
54
56
|
id = (0, utils_js_1.getVirtualFileId)(id);
|
|
@@ -62,7 +64,8 @@ function importUserCode() {
|
|
|
62
64
|
}
|
|
63
65
|
},
|
|
64
66
|
configureServer(server) {
|
|
65
|
-
(
|
|
67
|
+
if (isDev_ === null)
|
|
68
|
+
(0, utils_js_1.isDev1_onConfigureServer)();
|
|
66
69
|
handleFileAddRemove(server, config);
|
|
67
70
|
}
|
|
68
71
|
};
|
|
@@ -125,10 +128,7 @@ function isVikeConfigModule(filePathAbsoluteFilesystem) {
|
|
|
125
128
|
}
|
|
126
129
|
function reloadConfig(filePath, config, op) {
|
|
127
130
|
{
|
|
128
|
-
const
|
|
129
|
-
filePathAbsoluteFilesystem: filePath,
|
|
130
|
-
userRootDir: config.root
|
|
131
|
-
});
|
|
131
|
+
const filePathToShowToUserResolved = (0, getFilePath_js_1.getModuleFilePath)(filePath, config);
|
|
132
132
|
const msg = `${op} ${picocolors_1.default.dim(filePathToShowToUserResolved)}`;
|
|
133
133
|
(0, loggerNotProd_js_1.logConfigInfo)(msg, 'info');
|
|
134
134
|
}
|
|
@@ -13,7 +13,7 @@ const getConfigValueSourcesNotOverriden_js_1 = require("../../../shared/getConfi
|
|
|
13
13
|
function getConfigValuesSerialized(pageConfig, isEnvMatch) {
|
|
14
14
|
const lines = [];
|
|
15
15
|
Object.entries(pageConfig.configValuesComputed).forEach(([configName, configValuesComputed]) => {
|
|
16
|
-
const {
|
|
16
|
+
const { configEnv } = configValuesComputed;
|
|
17
17
|
if (!isEnvMatch(configEnv))
|
|
18
18
|
return;
|
|
19
19
|
// configValeSources has higher precedence
|
|
@@ -21,9 +21,11 @@ function getConfigValuesSerialized(pageConfig, isEnvMatch) {
|
|
|
21
21
|
return;
|
|
22
22
|
const configValue = pageConfig.configValues[configName];
|
|
23
23
|
(0, utils_js_1.assert)(configValue);
|
|
24
|
-
const {
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const { value, ...common } = configValue;
|
|
25
|
+
(0, utils_js_1.assert)(value === configValuesComputed.value);
|
|
26
|
+
const valueSerialized = getConfigValueSerialized(value, configName, configValue.definedAtData);
|
|
27
|
+
const configValueSerialized = { valueSerialized, ...common };
|
|
28
|
+
(0, serializeConfigValue_js_1.serializeConfigValue)(lines, configName, configValueSerialized);
|
|
27
29
|
});
|
|
28
30
|
(0, getConfigValueSourcesNotOverriden_js_1.getConfigValueSourcesNotOverriden)(pageConfig).forEach((configValueSource) => {
|
|
29
31
|
const { configName, configEnv } = configValueSource;
|
|
@@ -33,20 +35,21 @@ function getConfigValuesSerialized(pageConfig, isEnvMatch) {
|
|
|
33
35
|
if (!isEnvMatch(configEnv, configValueSource)) {
|
|
34
36
|
return;
|
|
35
37
|
}
|
|
36
|
-
const { value,
|
|
37
|
-
const valueSerialized = getConfigValueSerialized(value, configName,
|
|
38
|
-
|
|
38
|
+
const { value, ...common } = configValue;
|
|
39
|
+
const valueSerialized = getConfigValueSerialized(value, configName, configValue.definedAtData);
|
|
40
|
+
const configValueSerialized = { valueSerialized, ...common };
|
|
41
|
+
(0, serializeConfigValue_js_1.serializeConfigValue)(lines, configName, configValueSerialized);
|
|
39
42
|
});
|
|
40
43
|
const code = lines.join('\n');
|
|
41
44
|
return code;
|
|
42
45
|
}
|
|
43
46
|
exports.getConfigValuesSerialized = getConfigValuesSerialized;
|
|
44
|
-
function assertConfigValueIsSerializable(value, configName,
|
|
47
|
+
function assertConfigValueIsSerializable(value, configName, definedAtData) {
|
|
45
48
|
// Contains asserts
|
|
46
|
-
getConfigValueSerialized(value, configName,
|
|
49
|
+
getConfigValueSerialized(value, configName, definedAtData);
|
|
47
50
|
}
|
|
48
51
|
exports.assertConfigValueIsSerializable = assertConfigValueIsSerializable;
|
|
49
|
-
function getConfigValueSerialized(value, configName,
|
|
52
|
+
function getConfigValueSerialized(value, configName, definedAtData) {
|
|
50
53
|
const valueName = `config${(0, utils_js_1.getPropAccessNotation)(configName)}`;
|
|
51
54
|
let configValueSerialized;
|
|
52
55
|
try {
|
|
@@ -64,7 +67,7 @@ function getConfigValueSerialized(value, configName, definedAt) {
|
|
|
64
67
|
serializationErrMsg = 'see serialization error printed above'
|
|
65
68
|
}
|
|
66
69
|
*/
|
|
67
|
-
const configValueFilePathToShowToUser = (0, helpers_js_1.getConfigValueFilePathToShowToUser)(
|
|
70
|
+
const configValueFilePathToShowToUser = (0, helpers_js_1.getConfigValueFilePathToShowToUser)(definedAtData);
|
|
68
71
|
(0, utils_js_1.assert)(configValueFilePathToShowToUser);
|
|
69
72
|
(0, utils_js_1.assertUsage)(false, `${picocolors_1.default.cyan(configName)} defined by ${configValueFilePathToShowToUser} must be defined over a so-called "pointer import", see https://vike.dev/config#pointer-imports`);
|
|
70
73
|
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -23,7 +23,13 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
23
23
|
// config.outDir is outside of config.root => it's going to be ignored anyways
|
|
24
24
|
outDirRelativeFromUserRootDir = null;
|
|
25
25
|
}
|
|
26
|
-
(0, utils_js_1.assert)(outDirRelativeFromUserRootDir === null ||
|
|
26
|
+
(0, utils_js_1.assert)(outDirRelativeFromUserRootDir === null ||
|
|
27
|
+
/* Not true if outDirRelativeFromUserRootDir starts with a hidden directory (i.e. a directory with a name that starts with `.`)
|
|
28
|
+
!outDirRelativeFromUserRootDir.startsWith('.') &&
|
|
29
|
+
*/
|
|
30
|
+
(!outDirRelativeFromUserRootDir.startsWith('./') &&
|
|
31
|
+
//
|
|
32
|
+
!outDirRelativeFromUserRootDir.startsWith('../')));
|
|
27
33
|
const timeBefore = new Date().getTime();
|
|
28
34
|
let files = [];
|
|
29
35
|
const res = await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir);
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -11,8 +11,7 @@ const assertPlusFileExport_js_1 = require("../../../../../../shared/page-configs
|
|
|
11
11
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
12
12
|
const transformFileImports_js_1 = require("./transformFileImports.js");
|
|
13
13
|
const getConfigFileExport_js_1 = require("../getConfigFileExport.js");
|
|
14
|
-
const
|
|
15
|
-
const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
|
|
14
|
+
const resolvePointerImport_js_1 = require("./resolvePointerImport.js");
|
|
16
15
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
17
16
|
// Load fake import
|
|
18
17
|
async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
@@ -62,13 +61,11 @@ function assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem) {
|
|
|
62
61
|
(0, utils_js_1.assertUsage)(idx === -1, `Infinite extends loop ${[...loop, filePathAbsoluteFilesystem].join('>')}`);
|
|
63
62
|
}
|
|
64
63
|
async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir, visited) {
|
|
65
|
-
const
|
|
64
|
+
const extendsPointerImportData = getExtendsPointerImportData(configFileExports, configFilePath);
|
|
66
65
|
const extendsConfigFiles = [];
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
(0, resolveImportPath_js_1.assertImportPath)(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
71
|
-
const filePath = (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteFilesystem, userRootDir, importPathAbsolute });
|
|
66
|
+
extendsPointerImportData.map((pointerImportData) => {
|
|
67
|
+
const filePath = (0, resolvePointerImport_js_1.resolvePointerImport)(pointerImportData, configFilePath, userRootDir);
|
|
68
|
+
(0, utils_js_1.assert)(filePath.filePathAbsoluteFilesystem);
|
|
72
69
|
extendsConfigFiles.push(filePath);
|
|
73
70
|
});
|
|
74
71
|
const extendsConfigs = [];
|
|
@@ -80,7 +77,7 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
80
77
|
const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
|
|
81
78
|
return { extendsConfigs, extendsFilePaths };
|
|
82
79
|
}
|
|
83
|
-
function
|
|
80
|
+
function getExtendsPointerImportData(configFileExports, configFilePath) {
|
|
84
81
|
const { filePathToShowToUser } = configFilePath;
|
|
85
82
|
const configFileExport = (0, getConfigFileExport_js_1.getConfigFileExport)(configFileExports, filePathToShowToUser);
|
|
86
83
|
const wrongUsage = `${filePathToShowToUser} sets the config ${picocolors_1.default.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
|
|
@@ -97,10 +94,10 @@ function getExtendsImportData(configFileExports, configFilePath) {
|
|
|
97
94
|
else {
|
|
98
95
|
(0, utils_js_1.assertUsage)(false, wrongUsage);
|
|
99
96
|
}
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
(0, utils_js_1.assertUsage)(
|
|
103
|
-
return
|
|
97
|
+
const extendsPointerImportData = extendList.map((importString) => {
|
|
98
|
+
const pointerImportData = (0, transformFileImports_js_1.parsePointerImportData)(importString);
|
|
99
|
+
(0, utils_js_1.assertUsage)(pointerImportData, wrongUsage);
|
|
100
|
+
return pointerImportData;
|
|
104
101
|
});
|
|
105
|
-
return
|
|
102
|
+
return extendsPointerImportData;
|
|
106
103
|
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
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.clearFilesEnvMap = exports.resolvePointerImport = exports.resolvePointerImportOfConfig = void 0;
|
|
7
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
8
|
+
const utils_js_1 = require("../../../../utils.js");
|
|
9
|
+
const transformFileImports_js_1 = require("./transformFileImports.js");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
|
|
12
|
+
const filesEnvMap = new Map();
|
|
13
|
+
function resolvePointerImportOfConfig(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
14
|
+
if (typeof configValue !== 'string')
|
|
15
|
+
return null;
|
|
16
|
+
const pointerImportData = (0, transformFileImports_js_1.parsePointerImportData)(configValue);
|
|
17
|
+
if (!pointerImportData)
|
|
18
|
+
return null;
|
|
19
|
+
const { importPath, exportName } = pointerImportData;
|
|
20
|
+
const filePath = resolvePointerImport(pointerImportData, importerFilePath, userRootDir);
|
|
21
|
+
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
22
|
+
assertFileEnv(filePath.filePathAbsoluteFilesystem, importPath, configEnv, configName);
|
|
23
|
+
return {
|
|
24
|
+
...filePath,
|
|
25
|
+
fileExportName: exportName,
|
|
26
|
+
fileExportPathToShowToUser
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
exports.resolvePointerImportOfConfig = resolvePointerImportOfConfig;
|
|
30
|
+
function resolvePointerImport(pointerImportData, importerFilePath, userRootDir) {
|
|
31
|
+
const { importPath } = pointerImportData;
|
|
32
|
+
const filePathAbsoluteFilesystem = resolveImportPathWithNode(pointerImportData, importerFilePath);
|
|
33
|
+
let filePath;
|
|
34
|
+
// - importPath is one of the following. (See `transpileAndExecuteFile()`.)
|
|
35
|
+
// - A relative import path
|
|
36
|
+
// - A filesystem absolute path
|
|
37
|
+
// - An npm package import
|
|
38
|
+
// - importPath cannot be a path alias (since esbuild resolves path aliases, see transpileAndExecuteFile.ts)
|
|
39
|
+
(0, utils_js_1.assertPosixPath)(importPath);
|
|
40
|
+
if (importPath.startsWith('.') || (0, utils_js_1.isPathFilesystemAbsolute)(importPath)) {
|
|
41
|
+
if (importPath.startsWith('.')) {
|
|
42
|
+
(0, utils_js_1.assert)(importPath.startsWith('./') || importPath.startsWith('../'));
|
|
43
|
+
}
|
|
44
|
+
assertImportPath(filePathAbsoluteFilesystem, pointerImportData, importerFilePath);
|
|
45
|
+
const filePathAbsoluteUserRootDir = (0, getFilePath_js_1.getFilePathAbsoluteUserRootDir)({ filePathAbsoluteFilesystem, userRootDir });
|
|
46
|
+
// This assert() is guarenteed, see assertUsage() in the onResolve() esbuild hook in transpileAndExecuteFile.ts
|
|
47
|
+
(0, utils_js_1.assert)(filePathAbsoluteUserRootDir);
|
|
48
|
+
// Imports are included in virtual files, thus the relative path of imports need to resolved.
|
|
49
|
+
// ```
|
|
50
|
+
// [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
|
|
51
|
+
// ```
|
|
52
|
+
filePath = (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteUserRootDir, userRootDir });
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const importPathAbsolute = importPath;
|
|
56
|
+
// importPath cannot be a path alias (since esbuild resolves path aliases, see transpileAndExecuteFile.ts)
|
|
57
|
+
(0, utils_js_1.assertIsNpmPackageImport)(importPathAbsolute);
|
|
58
|
+
if (filePathAbsoluteFilesystem) {
|
|
59
|
+
filePath = (0, getFilePath_js_1.getFilePathResolved)({
|
|
60
|
+
userRootDir,
|
|
61
|
+
filePathAbsoluteFilesystem,
|
|
62
|
+
importPathAbsolute
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
filePath = (0, getFilePath_js_1.getFilePathUnresolved)({
|
|
67
|
+
importPathAbsolute
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return filePath;
|
|
72
|
+
}
|
|
73
|
+
exports.resolvePointerImport = resolvePointerImport;
|
|
74
|
+
function resolveImportPathWithNode(pointerImportData, importerFilePath) {
|
|
75
|
+
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|
|
76
|
+
(0, utils_js_1.assertPosixPath)(importerFilePathAbsolute);
|
|
77
|
+
const cwd = path_1.default.posix.dirname(importerFilePathAbsolute);
|
|
78
|
+
// We can't use import.meta.resolve() as of Junary 2023 (and probably for a lot longer)
|
|
79
|
+
// https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment137174954_62272600:~:text=But%20the%20argument%20parent%20(aka%20cwd)%20still%20requires%20a%20flag
|
|
80
|
+
// filePathAbsoluteFilesystem is expected to be null when pointerImportData.importPath is a Vite path alias
|
|
81
|
+
const filePathAbsoluteFilesystem = (0, utils_js_1.requireResolve)(pointerImportData.importPath, cwd);
|
|
82
|
+
return filePathAbsoluteFilesystem;
|
|
83
|
+
}
|
|
84
|
+
function assertImportPath(filePathAbsoluteFilesystem, pointerImportData, importerFilePath) {
|
|
85
|
+
const { importPath: importPath, importStringWasGenerated, importString } = pointerImportData;
|
|
86
|
+
const { filePathToShowToUser } = importerFilePath;
|
|
87
|
+
if (!filePathAbsoluteFilesystem) {
|
|
88
|
+
const importPathString = picocolors_1.default.cyan(`'${importPath}'`);
|
|
89
|
+
const errIntro = importStringWasGenerated
|
|
90
|
+
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
91
|
+
: `The import ${picocolors_1.default.cyan(importString)} defined in ${filePathToShowToUser}`;
|
|
92
|
+
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
93
|
+
if (importPath.startsWith('.')) {
|
|
94
|
+
(0, utils_js_1.assert)(importPath.startsWith('./') || importPath.startsWith('../'));
|
|
95
|
+
(0, utils_js_1.assertUsage)(false, `${errIntro2} point to an existing file?`);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
(0, utils_js_1.assertUsage)(false, `${errIntro2} exist?`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function assertFileEnv(filePathAbsoluteFilesystem, importPath, configEnv, configName) {
|
|
103
|
+
let key;
|
|
104
|
+
if (filePathAbsoluteFilesystem) {
|
|
105
|
+
key = filePathAbsoluteFilesystem;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
(0, utils_js_1.assertIsNpmPackageImport)(importPath);
|
|
109
|
+
key = importPath;
|
|
110
|
+
}
|
|
111
|
+
(0, utils_js_1.assertPosixPath)(key);
|
|
112
|
+
if (!filesEnvMap.has(key)) {
|
|
113
|
+
filesEnvMap.set(key, []);
|
|
114
|
+
}
|
|
115
|
+
const fileEnv = filesEnvMap.get(key);
|
|
116
|
+
fileEnv.push({ configEnv, configName });
|
|
117
|
+
const configDifferentEnv = fileEnv.filter((c) => !(0, utils_js_1.deepEqual)(c.configEnv, configEnv))[0];
|
|
118
|
+
if (configDifferentEnv) {
|
|
119
|
+
(0, utils_js_1.assertUsage)(false, [
|
|
120
|
+
`${key} defines the value of configs living in different environments:`,
|
|
121
|
+
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${picocolors_1.default.cyan(c.configName)} which value lives in environment ${picocolors_1.default.cyan(JSON.stringify(c.configEnv))}`),
|
|
122
|
+
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/config#pointer-imports'
|
|
123
|
+
].join('\n'));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function clearFilesEnvMap() {
|
|
127
|
+
filesEnvMap.clear();
|
|
128
|
+
}
|
|
129
|
+
exports.clearFilesEnvMap = clearFilesEnvMap;
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.
|
|
6
|
+
exports.isPointerImportData = exports.parsePointerImportData = exports.transformFileImports = void 0;
|
|
7
7
|
// Playground: https://github.com/brillout/acorn-playground
|
|
8
8
|
// Notes about `with { type: 'pointer' }`
|
|
9
9
|
// - 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
|
|
@@ -93,7 +93,7 @@ skipWarnings) {
|
|
|
93
93
|
}
|
|
94
94
|
return importLocalName;
|
|
95
95
|
})();
|
|
96
|
-
const importString =
|
|
96
|
+
const importString = serializePointerImportData({ importPath, exportName, importStringWasGenerated: true });
|
|
97
97
|
replacement += `const ${importLocalName} = '${importString}';`;
|
|
98
98
|
});
|
|
99
99
|
spliceOperations.push({
|
|
@@ -122,17 +122,17 @@ function getImports(code) {
|
|
|
122
122
|
const import_ = 'import';
|
|
123
123
|
const SEP = ':';
|
|
124
124
|
const zeroWidthSpace = '\u200b';
|
|
125
|
-
function
|
|
125
|
+
function serializePointerImportData({ importPath, exportName, importStringWasGenerated }) {
|
|
126
126
|
const tag = importStringWasGenerated ? zeroWidthSpace : '';
|
|
127
127
|
// `import:${importPath}:${importPath}`
|
|
128
128
|
return `${tag}${import_}${SEP}${importPath}${SEP}${exportName}`;
|
|
129
129
|
}
|
|
130
|
-
function
|
|
130
|
+
function isPointerImportData(str) {
|
|
131
131
|
return str.startsWith(import_ + SEP) || str.startsWith(zeroWidthSpace + import_ + SEP);
|
|
132
132
|
}
|
|
133
|
-
exports.
|
|
134
|
-
function
|
|
135
|
-
if (!
|
|
133
|
+
exports.isPointerImportData = isPointerImportData;
|
|
134
|
+
function parsePointerImportData(importString) {
|
|
135
|
+
if (!isPointerImportData(importString)) {
|
|
136
136
|
return null;
|
|
137
137
|
}
|
|
138
138
|
let importStringWasGenerated = false;
|
|
@@ -152,7 +152,7 @@ function parseImportData(importString) {
|
|
|
152
152
|
const importPath = parts.slice(0, -1).join(SEP);
|
|
153
153
|
return { importPath, exportName, importStringWasGenerated, importString };
|
|
154
154
|
}
|
|
155
|
-
exports.
|
|
155
|
+
exports.parsePointerImportData = parsePointerImportData;
|
|
156
156
|
function spliceMany(str, operations) {
|
|
157
157
|
let strMod = '';
|
|
158
158
|
let endPrev;
|
|
@@ -13,6 +13,7 @@ const utils_js_1 = require("../../../../utils.js");
|
|
|
13
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
|
+
const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
|
|
16
17
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
17
18
|
const debug = (0, utils_js_1.createDebugger)('vike:pointer-imports');
|
|
18
19
|
async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile) {
|
|
@@ -114,13 +115,21 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
114
115
|
return resolved;
|
|
115
116
|
}
|
|
116
117
|
(0, utils_js_1.assert)(resolved.path);
|
|
117
|
-
|
|
118
|
+
const importPathResolved = (0, utils_js_1.toPosixPath)(resolved.path);
|
|
119
|
+
const importPathOriginal = args.path;
|
|
120
|
+
// Esbuild resolves path aliases.
|
|
121
|
+
// - Enabling us to use:
|
|
122
|
+
// ```js
|
|
123
|
+
// isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
124
|
+
// assertIsNpmPackageImport()
|
|
125
|
+
// ```
|
|
126
|
+
(0, utils_js_1.assertPathFilesystemAbsolute)(importPathResolved);
|
|
118
127
|
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
119
128
|
// - This is temporary, see comment below.
|
|
120
|
-
const isVikeExtensionConfigImport =
|
|
129
|
+
const isVikeExtensionConfigImport = importPathResolved.endsWith('+config.js');
|
|
121
130
|
const isPointerImport = transformImports === 'all' ||
|
|
122
131
|
// .jsx, .vue, .svg, ... => obviously not config code
|
|
123
|
-
!(0, utils_js_1.isJavaScriptFile)(
|
|
132
|
+
!(0, utils_js_1.isJavaScriptFile)(importPathResolved) ||
|
|
124
133
|
// 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).
|
|
125
134
|
// - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
|
|
126
135
|
// - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
|
|
@@ -129,21 +138,52 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
129
138
|
// - For example if esbuild cannot resolve a path alias while Vite can.
|
|
130
139
|
// - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
|
|
131
140
|
resolved.errors.length > 0;
|
|
132
|
-
|
|
133
|
-
(0, utils_js_1.assertPosixPath)(resolved.path);
|
|
141
|
+
(0, utils_js_1.assertPosixPath)(importPathResolved);
|
|
134
142
|
const isExternal = isPointerImport ||
|
|
135
143
|
// Performance: npm package imports that aren't pointer imports can be externalized. For example, if Vike eventually adds support for setting Vite configs in the vike.config.js file, then the user may import a Vite plugin in his vike.config.js file. (We could as well let esbuild always transpile /node_modules/ code but it would be useless and would unnecessarily slow down transpilation.)
|
|
136
|
-
|
|
144
|
+
importPathResolved.includes('/node_modules/');
|
|
145
|
+
const filePathAbsoluteUserRootDir = (0, getFilePath_js_1.getFilePathAbsoluteUserRootDir)({
|
|
146
|
+
filePathAbsoluteFilesystem: importPathResolved,
|
|
147
|
+
userRootDir
|
|
148
|
+
});
|
|
149
|
+
let importPathTranspiled;
|
|
150
|
+
(0, utils_js_1.assertPosixPath)(importPathOriginal);
|
|
151
|
+
if (importPathOriginal.startsWith('./') || importPathOriginal.startsWith('../')) {
|
|
152
|
+
// - We need this assertUsage() because we didn't find a way (yet?) to use filesystem absolute import paths in virtual files.
|
|
153
|
+
// - Alternatively, we can again try one of the following for generating the imports of virtual files. (Last time we tried none of it worked.)
|
|
154
|
+
// - ~~~js
|
|
155
|
+
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
156
|
+
// filePath = `/@fs${filePathAbsoluteFilesystem}`
|
|
157
|
+
// ~~~
|
|
158
|
+
// - ~~~js
|
|
159
|
+
// assert(filePathAbsoluteUserRootDir.startsWith('../'))
|
|
160
|
+
// filePathAbsoluteUserRootDir = '/' + filePathAbsoluteUserRootDir
|
|
161
|
+
// ~~~
|
|
162
|
+
(0, utils_js_1.assertUsage)(filePathAbsoluteUserRootDir, `Import ${picocolors_1.default.cyan(importPathOriginal)} resolves to ${importPathResolved} outside of ${userRootDir} which is forbidden: make sure your relative import paths resolve inside ${userRootDir}, or import from an npm package.`);
|
|
163
|
+
importPathTranspiled = importPathResolved;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
// importPathOriginal is either:
|
|
167
|
+
// - Npm package import
|
|
168
|
+
// - Path alias
|
|
169
|
+
if (filePathAbsoluteUserRootDir) {
|
|
170
|
+
// importPathOriginal is most likely a path alias. (Is it even possible for an npm package import to resolved inside `userRootDir`?)
|
|
171
|
+
importPathTranspiled = importPathResolved;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
// importPathOriginal is an npm package import. (Assuming path aliases always resolve inside `userRootDir`.)
|
|
175
|
+
(0, utils_js_1.assertIsNpmPackageImport)(importPathOriginal);
|
|
176
|
+
importPathTranspiled = importPathOriginal;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
137
179
|
if (debug.isActivated)
|
|
138
|
-
debug('onResolved()', { args, resolved, isPointerImport, isExternal });
|
|
139
|
-
|
|
140
|
-
// isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
141
|
-
// assertIsNpmPackageImport()
|
|
142
|
-
(0, utils_js_1.assertPathIsFilesystemAbsolute)(resolved.path);
|
|
180
|
+
debug('onResolved()', { args, resolved, importPathTranspiled, isPointerImport, isExternal });
|
|
181
|
+
pointerImports[importPathTranspiled] = isPointerImport;
|
|
143
182
|
if (isExternal) {
|
|
144
|
-
return { external: true, path:
|
|
183
|
+
return { external: true, path: importPathTranspiled };
|
|
145
184
|
}
|
|
146
185
|
else {
|
|
186
|
+
resolved.path = importPathTranspiled;
|
|
147
187
|
return resolved;
|
|
148
188
|
}
|
|
149
189
|
});
|