vike 0.4.168-commit-ce94f5c → 0.4.168-commit-42406a9
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/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/loadFileAtConfigTime.js +11 -14
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{resolveImportPath.js → resolvePointerImport.js} +58 -44
- 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 +44 -48
- 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/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/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 +43 -47
- 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 +1 -1
- 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 -109
- 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
|
@@ -2,7 +2,7 @@ export { distFileNames };
|
|
|
2
2
|
// Attempt to preserve file structure of `.page.js` files:
|
|
3
3
|
// - https://github.com/vikejs/vike/commit/11a4c49e5403aa7c37c8020c462b499425b41854
|
|
4
4
|
// - Blocker: https://github.com/rollup/rollup/issues/4724
|
|
5
|
-
import { assertPosixPath, assert, assertUsage } from '../utils.js';
|
|
5
|
+
import { assertPosixPath, assert, assertUsage, isArray } from '../utils.js';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { getAssetsDir } from '../shared/getAssetsDir.js';
|
|
8
8
|
function distFileNames() {
|
|
@@ -110,6 +110,12 @@ function clean(name, removePathSep, fixGlob) {
|
|
|
110
110
|
}
|
|
111
111
|
name = removeLeadingUnderscoreInFilename(name);
|
|
112
112
|
name = removeUnderscoreDoublets(name);
|
|
113
|
+
// Avoid:
|
|
114
|
+
// ```
|
|
115
|
+
// dist/client/assets/entries/.Dp9wM6PK.js
|
|
116
|
+
// dist/server/entries/.mjs
|
|
117
|
+
// ```
|
|
118
|
+
assert(!name.endsWith('/'));
|
|
113
119
|
return name;
|
|
114
120
|
}
|
|
115
121
|
function fixExtractAssetsQuery(name) {
|
|
@@ -159,7 +165,7 @@ function getRollupOutputs(config) {
|
|
|
159
165
|
(_a = config.build).rollupOptions ?? (_a.rollupOptions = {});
|
|
160
166
|
(_b = config.build.rollupOptions).output ?? (_b.output = {});
|
|
161
167
|
const { output } = config.build.rollupOptions;
|
|
162
|
-
if (!
|
|
168
|
+
if (!isArray(output)) {
|
|
163
169
|
return [output];
|
|
164
170
|
}
|
|
165
171
|
return output;
|
|
@@ -2,7 +2,7 @@ export { envVarsPlugin };
|
|
|
2
2
|
// For ./envVars.spec.ts
|
|
3
3
|
export { applyEnvVar };
|
|
4
4
|
import { loadEnv } from 'vite';
|
|
5
|
-
import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, lowerFirst } from '../utils.js';
|
|
5
|
+
import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, isArray, lowerFirst } from '../utils.js';
|
|
6
6
|
import { sourceMapPassthrough } from '../shared/rollupSourceMap.js';
|
|
7
7
|
import { getModuleFilePath } from '../shared/getFilePath.js';
|
|
8
8
|
function envVarsPlugin() {
|
|
@@ -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 ? [] : isArray(config.envPrefix) ? config.envPrefix : [config.envPrefix];
|
|
38
34
|
return !envPrefix.some((prefix) => key.startsWith(prefix));
|
|
39
35
|
})
|
|
40
36
|
.forEach(([envName, envVal]) => {
|
|
@@ -3,19 +3,21 @@ import { normalizePath } from 'vite';
|
|
|
3
3
|
import { getConfigVike } from '../../../shared/getConfigVike.js';
|
|
4
4
|
import { getVirtualFilePageConfigValuesAll } from './v1-design/getVirtualFilePageConfigValuesAll.js';
|
|
5
5
|
import { getVirtualFileImportUserCode } from './getVirtualFileImportUserCode.js';
|
|
6
|
-
import { assert, assertPosixPath, getOutDirs, getVirtualFileId, isDev1, isDev1_onConfigureServer, isVirtualFileId, resolveVirtualFileId } from '../../utils.js';
|
|
6
|
+
import { assert, assertPosixPath, getOutDirs, getVirtualFileId, isDev1, isDev1_onConfigureServer, isDev3, isVirtualFileId, resolveVirtualFileId } from '../../utils.js';
|
|
7
7
|
import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
8
8
|
import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
9
9
|
import { vikeConfigDependencies, reloadVikeConfig, isVikeConfigFile } from './v1-design/getVikeConfig.js';
|
|
10
10
|
import pc from '@brillout/picocolors';
|
|
11
11
|
import { logConfigInfo, clearLogs } from '../../shared/loggerNotProd.js';
|
|
12
|
-
import {
|
|
12
|
+
import { getModuleFilePath } from '../../shared/getFilePath.js';
|
|
13
13
|
function importUserCode() {
|
|
14
14
|
let config;
|
|
15
15
|
let configVike;
|
|
16
|
+
let isDev_;
|
|
16
17
|
return {
|
|
17
18
|
name: 'vike:importUserCode',
|
|
18
|
-
config() {
|
|
19
|
+
config(_, env) {
|
|
20
|
+
isDev_ = isDev3(env);
|
|
19
21
|
return {
|
|
20
22
|
experimental: {
|
|
21
23
|
// TODO/v1-release: remove
|
|
@@ -43,7 +45,7 @@ function importUserCode() {
|
|
|
43
45
|
}
|
|
44
46
|
},
|
|
45
47
|
async load(id, options) {
|
|
46
|
-
const isDev = isDev1();
|
|
48
|
+
const isDev = isDev_ !== null ? isDev_ : isDev1();
|
|
47
49
|
if (!isVirtualFileId(id))
|
|
48
50
|
return undefined;
|
|
49
51
|
id = getVirtualFileId(id);
|
|
@@ -57,7 +59,8 @@ function importUserCode() {
|
|
|
57
59
|
}
|
|
58
60
|
},
|
|
59
61
|
configureServer(server) {
|
|
60
|
-
|
|
62
|
+
if (isDev_ === null)
|
|
63
|
+
isDev1_onConfigureServer();
|
|
61
64
|
handleFileAddRemove(server, config);
|
|
62
65
|
}
|
|
63
66
|
};
|
|
@@ -119,10 +122,7 @@ function isVikeConfigModule(filePathAbsoluteFilesystem) {
|
|
|
119
122
|
}
|
|
120
123
|
function reloadConfig(filePath, config, op) {
|
|
121
124
|
{
|
|
122
|
-
const
|
|
123
|
-
filePathAbsoluteFilesystem: filePath,
|
|
124
|
-
userRootDir: config.root
|
|
125
|
-
});
|
|
125
|
+
const filePathToShowToUserResolved = getModuleFilePath(filePath, config);
|
|
126
126
|
const msg = `${op} ${pc.dim(filePathToShowToUserResolved)}`;
|
|
127
127
|
logConfigInfo(msg, 'info');
|
|
128
128
|
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getConfigValuesSerialized };
|
|
2
2
|
export { assertConfigValueIsSerializable };
|
|
3
|
-
import type { ConfigEnvInternal, ConfigValueSource,
|
|
3
|
+
import type { ConfigEnvInternal, ConfigValueSource, DefinedAtData, PageConfigBuildTime } from '../../../../../shared/page-configs/PageConfig.js';
|
|
4
4
|
declare function getConfigValuesSerialized(pageConfig: PageConfigBuildTime, isEnvMatch: (configEnv: ConfigEnvInternal, configValueSource?: ConfigValueSource) => boolean): string;
|
|
5
|
-
declare function assertConfigValueIsSerializable(value: unknown, configName: string,
|
|
5
|
+
declare function assertConfigValueIsSerializable(value: unknown, configName: string, definedAtData: DefinedAtData): void;
|
|
@@ -9,7 +9,7 @@ import { getConfigValueSourcesNotOverriden } from '../../../shared/getConfigValu
|
|
|
9
9
|
function getConfigValuesSerialized(pageConfig, isEnvMatch) {
|
|
10
10
|
const lines = [];
|
|
11
11
|
Object.entries(pageConfig.configValuesComputed).forEach(([configName, configValuesComputed]) => {
|
|
12
|
-
const {
|
|
12
|
+
const { configEnv } = configValuesComputed;
|
|
13
13
|
if (!isEnvMatch(configEnv))
|
|
14
14
|
return;
|
|
15
15
|
// configValeSources has higher precedence
|
|
@@ -17,9 +17,11 @@ function getConfigValuesSerialized(pageConfig, isEnvMatch) {
|
|
|
17
17
|
return;
|
|
18
18
|
const configValue = pageConfig.configValues[configName];
|
|
19
19
|
assert(configValue);
|
|
20
|
-
const {
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const { value, ...common } = configValue;
|
|
21
|
+
assert(value === configValuesComputed.value);
|
|
22
|
+
const valueSerialized = getConfigValueSerialized(value, configName, configValue.definedAtData);
|
|
23
|
+
const configValueSerialized = { valueSerialized, ...common };
|
|
24
|
+
serializeConfigValue(lines, configName, configValueSerialized);
|
|
23
25
|
});
|
|
24
26
|
getConfigValueSourcesNotOverriden(pageConfig).forEach((configValueSource) => {
|
|
25
27
|
const { configName, configEnv } = configValueSource;
|
|
@@ -29,18 +31,19 @@ function getConfigValuesSerialized(pageConfig, isEnvMatch) {
|
|
|
29
31
|
if (!isEnvMatch(configEnv, configValueSource)) {
|
|
30
32
|
return;
|
|
31
33
|
}
|
|
32
|
-
const { value,
|
|
33
|
-
const valueSerialized = getConfigValueSerialized(value, configName,
|
|
34
|
-
|
|
34
|
+
const { value, ...common } = configValue;
|
|
35
|
+
const valueSerialized = getConfigValueSerialized(value, configName, configValue.definedAtData);
|
|
36
|
+
const configValueSerialized = { valueSerialized, ...common };
|
|
37
|
+
serializeConfigValue(lines, configName, configValueSerialized);
|
|
35
38
|
});
|
|
36
39
|
const code = lines.join('\n');
|
|
37
40
|
return code;
|
|
38
41
|
}
|
|
39
|
-
function assertConfigValueIsSerializable(value, configName,
|
|
42
|
+
function assertConfigValueIsSerializable(value, configName, definedAtData) {
|
|
40
43
|
// Contains asserts
|
|
41
|
-
getConfigValueSerialized(value, configName,
|
|
44
|
+
getConfigValueSerialized(value, configName, definedAtData);
|
|
42
45
|
}
|
|
43
|
-
function getConfigValueSerialized(value, configName,
|
|
46
|
+
function getConfigValueSerialized(value, configName, definedAtData) {
|
|
44
47
|
const valueName = `config${getPropAccessNotation(configName)}`;
|
|
45
48
|
let configValueSerialized;
|
|
46
49
|
try {
|
|
@@ -58,7 +61,7 @@ function getConfigValueSerialized(value, configName, definedAt) {
|
|
|
58
61
|
serializationErrMsg = 'see serialization error printed above'
|
|
59
62
|
}
|
|
60
63
|
*/
|
|
61
|
-
const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser(
|
|
64
|
+
const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser(definedAtData);
|
|
62
65
|
assert(configValueFilePathToShowToUser);
|
|
63
66
|
assertUsage(false, `${pc.cyan(configName)} defined by ${configValueFilePathToShowToUser} must be defined over a so-called "pointer import", see https://vike.dev/config#pointer-imports`);
|
|
64
67
|
}
|
|
@@ -5,8 +5,9 @@ export type { ConfigDefinitions };
|
|
|
5
5
|
export type { ConfigDefinitionInternal };
|
|
6
6
|
export type { ConfigNameGlobal };
|
|
7
7
|
export type { ConfigEffect };
|
|
8
|
-
import type { ConfigEnvInternal, ConfigEnv, ConfigValueSources,
|
|
8
|
+
import type { ConfigEnvInternal, ConfigEnv, ConfigValueSources, DefinedAtFilePath } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
9
9
|
import type { Config, ConfigNameBuiltIn } from '../../../../../../shared/page-configs/Config.js';
|
|
10
|
+
import type { ConfigDefinedAt } from '../../../../../../shared/page-configs/getConfigDefinedAt.js';
|
|
10
11
|
/** The meta definition of a config.
|
|
11
12
|
*
|
|
12
13
|
* https://vike.dev/meta
|
|
@@ -46,13 +47,13 @@ type ConfigEffect = (config: {
|
|
|
46
47
|
*
|
|
47
48
|
* https://vike.dev/meta
|
|
48
49
|
*/
|
|
49
|
-
configDefinedAt:
|
|
50
|
+
configDefinedAt: ConfigDefinedAt;
|
|
50
51
|
}) => Config | undefined;
|
|
51
52
|
/** For Vike internal use */
|
|
52
53
|
type ConfigDefinitionInternal = Omit<ConfigDefinition, 'env'> & {
|
|
53
54
|
_computed?: (configValueSources: ConfigValueSources) => unknown;
|
|
54
55
|
_valueIsFilePath?: true;
|
|
55
|
-
|
|
56
|
+
_userEffectDefinedAtFilePath?: DefinedAtFilePath;
|
|
56
57
|
env: ConfigEnvInternal;
|
|
57
58
|
};
|
|
58
59
|
type ConfigDefinitions = Record<string, ConfigDefinitionInternal>;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts
CHANGED
|
@@ -12,9 +12,9 @@ export { getLogicalPath };
|
|
|
12
12
|
*
|
|
13
13
|
* Each config value is assigned with a `locationId` value. That's the source-of-truth for determining inheritance between config values.
|
|
14
14
|
*
|
|
15
|
-
* For Vike extensions, `locationId` is different than the config value's `
|
|
15
|
+
* For Vike extensions, `locationId` is different than the config value's `definedAtFilePath`, for example the `onRenderHtml()` hook of `vike-react`:
|
|
16
16
|
* - `locationId === '/pages'` (the directory of `/pages/+config.js` which extends `vike-react`)
|
|
17
|
-
* - `
|
|
17
|
+
* - `definedAtFilePath.filePathAbsoluteFilesystem === '/home/rom/code/my-vike-app/node_modules/vike-react/dist/renderer/onRenderHtml.js'` (the file where the value is defined)
|
|
18
18
|
*
|
|
19
19
|
* This is an important distinction because the Vike extension's config should only apply to where it's being extended from, for example:
|
|
20
20
|
* ```js
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -6,10 +6,9 @@ import { assert, assertUsage, hasProp, assertIsNotProductionRuntime } from '../.
|
|
|
6
6
|
import { transpileAndExecuteFile } from './transpileAndExecuteFile.js';
|
|
7
7
|
import { assertPlusFileExport } from '../../../../../../shared/page-configs/assertPlusFileExport.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
|
-
import {
|
|
9
|
+
import { parsePointerImportData } from './transformFileImports.js';
|
|
10
10
|
import { getConfigFileExport } from '../getConfigFileExport.js';
|
|
11
|
-
import {
|
|
12
|
-
import { getFilePathResolved } from '../../../../shared/getFilePath.js';
|
|
11
|
+
import { resolvePointerImport } from './resolvePointerImport.js';
|
|
13
12
|
assertIsNotProductionRuntime();
|
|
14
13
|
// Load fake import
|
|
15
14
|
async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
@@ -56,13 +55,11 @@ function assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem) {
|
|
|
56
55
|
assertUsage(idx === -1, `Infinite extends loop ${[...loop, filePathAbsoluteFilesystem].join('>')}`);
|
|
57
56
|
}
|
|
58
57
|
async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir, visited) {
|
|
59
|
-
const
|
|
58
|
+
const extendsPointerImportData = getExtendsPointerImportData(configFileExports, configFilePath);
|
|
60
59
|
const extendsConfigFiles = [];
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
assertImportPath(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
65
|
-
const filePath = getFilePathResolved({ filePathAbsoluteFilesystem, userRootDir, importPathAbsolute });
|
|
60
|
+
extendsPointerImportData.map((pointerImportData) => {
|
|
61
|
+
const filePath = resolvePointerImport(pointerImportData, configFilePath, userRootDir);
|
|
62
|
+
assert(filePath.filePathAbsoluteFilesystem);
|
|
66
63
|
extendsConfigFiles.push(filePath);
|
|
67
64
|
});
|
|
68
65
|
const extendsConfigs = [];
|
|
@@ -74,7 +71,7 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
74
71
|
const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
|
|
75
72
|
return { extendsConfigs, extendsFilePaths };
|
|
76
73
|
}
|
|
77
|
-
function
|
|
74
|
+
function getExtendsPointerImportData(configFileExports, configFilePath) {
|
|
78
75
|
const { filePathToShowToUser } = configFilePath;
|
|
79
76
|
const configFileExport = getConfigFileExport(configFileExports, filePathToShowToUser);
|
|
80
77
|
const wrongUsage = `${filePathToShowToUser} sets the config ${pc.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
|
|
@@ -91,10 +88,10 @@ function getExtendsImportData(configFileExports, configFilePath) {
|
|
|
91
88
|
else {
|
|
92
89
|
assertUsage(false, wrongUsage);
|
|
93
90
|
}
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
assertUsage(
|
|
97
|
-
return
|
|
91
|
+
const extendsPointerImportData = extendList.map((importString) => {
|
|
92
|
+
const pointerImportData = parsePointerImportData(importString);
|
|
93
|
+
assertUsage(pointerImportData, wrongUsage);
|
|
94
|
+
return pointerImportData;
|
|
98
95
|
});
|
|
99
|
-
return
|
|
96
|
+
return extendsPointerImportData;
|
|
100
97
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { resolvePointerImportOfConfig };
|
|
2
|
+
export { resolvePointerImport };
|
|
3
|
+
export { clearFilesEnvMap };
|
|
4
|
+
import type { ConfigEnvInternal, DefinedAtFilePath } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
5
|
+
import { type PointerImportData } from './transformFileImports.js';
|
|
6
|
+
import type { FilePath, FilePathResolved } from '../../../../../../shared/page-configs/FilePath.js';
|
|
7
|
+
type PointerImportResolved = DefinedAtFilePath & {
|
|
8
|
+
fileExportName: string;
|
|
9
|
+
};
|
|
10
|
+
declare function resolvePointerImportOfConfig(configValue: unknown, importerFilePath: FilePathResolved, userRootDir: string, configEnv: ConfigEnvInternal, configName: string): null | PointerImportResolved;
|
|
11
|
+
declare function resolvePointerImport(pointerImportData: PointerImportData, importerFilePath: FilePathResolved, userRootDir: string): FilePath;
|
|
12
|
+
declare function clearFilesEnvMap(): void;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export { resolvePointerImportOfConfig };
|
|
2
|
+
export { resolvePointerImport };
|
|
3
|
+
export { clearFilesEnvMap };
|
|
4
|
+
import pc from '@brillout/picocolors';
|
|
5
|
+
import { assert, assertIsNpmPackageImport, assertPosixPath, assertUsage, deepEqual, isPathFilesystemAbsolute, requireResolve } from '../../../../utils.js';
|
|
6
|
+
import { parsePointerImportData } from './transformFileImports.js';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { getFilePathAbsoluteUserRootDir, getFilePathResolved, getFilePathUnresolved } from '../../../../shared/getFilePath.js';
|
|
9
|
+
const filesEnvMap = new Map();
|
|
10
|
+
function resolvePointerImportOfConfig(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
11
|
+
if (typeof configValue !== 'string')
|
|
12
|
+
return null;
|
|
13
|
+
const pointerImportData = parsePointerImportData(configValue);
|
|
14
|
+
if (!pointerImportData)
|
|
15
|
+
return null;
|
|
16
|
+
const { importPath, exportName } = pointerImportData;
|
|
17
|
+
const filePath = resolvePointerImport(pointerImportData, importerFilePath, userRootDir);
|
|
18
|
+
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
19
|
+
assertFileEnv(filePath.filePathAbsoluteFilesystem, importPath, configEnv, configName);
|
|
20
|
+
return {
|
|
21
|
+
...filePath,
|
|
22
|
+
fileExportName: exportName,
|
|
23
|
+
fileExportPathToShowToUser
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function resolvePointerImport(pointerImportData, importerFilePath, userRootDir) {
|
|
27
|
+
const { importPath } = pointerImportData;
|
|
28
|
+
const filePathAbsoluteFilesystem = resolveImportPathWithNode(pointerImportData, importerFilePath);
|
|
29
|
+
let filePath;
|
|
30
|
+
// - importPath is one of the following. (See `transpileAndExecuteFile()`.)
|
|
31
|
+
// - A relative import path
|
|
32
|
+
// - A filesystem absolute path
|
|
33
|
+
// - An npm package import
|
|
34
|
+
// - importPath cannot be a path alias (since esbuild resolves path aliases, see transpileAndExecuteFile.ts)
|
|
35
|
+
assertPosixPath(importPath);
|
|
36
|
+
if (importPath.startsWith('.') || isPathFilesystemAbsolute(importPath)) {
|
|
37
|
+
if (importPath.startsWith('.')) {
|
|
38
|
+
assert(importPath.startsWith('./') || importPath.startsWith('../'));
|
|
39
|
+
}
|
|
40
|
+
assertImportPath(filePathAbsoluteFilesystem, pointerImportData, importerFilePath);
|
|
41
|
+
const filePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir });
|
|
42
|
+
// This assert() is guarenteed, see assertUsage() in the onResolve() esbuild hook in transpileAndExecuteFile.ts
|
|
43
|
+
assert(filePathAbsoluteUserRootDir);
|
|
44
|
+
// Imports are included in virtual files, thus the relative path of imports need to resolved.
|
|
45
|
+
// ```
|
|
46
|
+
// [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
|
|
47
|
+
// ```
|
|
48
|
+
filePath = getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir });
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const importPathAbsolute = importPath;
|
|
52
|
+
// importPath cannot be a path alias (since esbuild resolves path aliases, see transpileAndExecuteFile.ts)
|
|
53
|
+
assertIsNpmPackageImport(importPathAbsolute);
|
|
54
|
+
if (filePathAbsoluteFilesystem) {
|
|
55
|
+
filePath = getFilePathResolved({
|
|
56
|
+
userRootDir,
|
|
57
|
+
filePathAbsoluteFilesystem,
|
|
58
|
+
importPathAbsolute
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
filePath = getFilePathUnresolved({
|
|
63
|
+
importPathAbsolute
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return filePath;
|
|
68
|
+
}
|
|
69
|
+
function resolveImportPathWithNode(pointerImportData, importerFilePath) {
|
|
70
|
+
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|
|
71
|
+
assertPosixPath(importerFilePathAbsolute);
|
|
72
|
+
const cwd = path.posix.dirname(importerFilePathAbsolute);
|
|
73
|
+
// We can't use import.meta.resolve() as of Junary 2023 (and probably for a lot longer)
|
|
74
|
+
// 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
|
|
75
|
+
// filePathAbsoluteFilesystem is expected to be null when pointerImportData.importPath is a Vite path alias
|
|
76
|
+
const filePathAbsoluteFilesystem = requireResolve(pointerImportData.importPath, cwd);
|
|
77
|
+
return filePathAbsoluteFilesystem;
|
|
78
|
+
}
|
|
79
|
+
function assertImportPath(filePathAbsoluteFilesystem, pointerImportData, importerFilePath) {
|
|
80
|
+
const { importPath: importPath, importStringWasGenerated, importString } = pointerImportData;
|
|
81
|
+
const { filePathToShowToUser } = importerFilePath;
|
|
82
|
+
if (!filePathAbsoluteFilesystem) {
|
|
83
|
+
const importPathString = pc.cyan(`'${importPath}'`);
|
|
84
|
+
const errIntro = importStringWasGenerated
|
|
85
|
+
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
86
|
+
: `The import ${pc.cyan(importString)} defined in ${filePathToShowToUser}`;
|
|
87
|
+
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
88
|
+
if (importPath.startsWith('.')) {
|
|
89
|
+
assert(importPath.startsWith('./') || importPath.startsWith('../'));
|
|
90
|
+
assertUsage(false, `${errIntro2} point to an existing file?`);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
assertUsage(false, `${errIntro2} exist?`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function assertFileEnv(filePathAbsoluteFilesystem, importPath, configEnv, configName) {
|
|
98
|
+
let key;
|
|
99
|
+
if (filePathAbsoluteFilesystem) {
|
|
100
|
+
key = filePathAbsoluteFilesystem;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
assertIsNpmPackageImport(importPath);
|
|
104
|
+
key = importPath;
|
|
105
|
+
}
|
|
106
|
+
assertPosixPath(key);
|
|
107
|
+
if (!filesEnvMap.has(key)) {
|
|
108
|
+
filesEnvMap.set(key, []);
|
|
109
|
+
}
|
|
110
|
+
const fileEnv = filesEnvMap.get(key);
|
|
111
|
+
fileEnv.push({ configEnv, configName });
|
|
112
|
+
const configDifferentEnv = fileEnv.filter((c) => !deepEqual(c.configEnv, configEnv))[0];
|
|
113
|
+
if (configDifferentEnv) {
|
|
114
|
+
assertUsage(false, [
|
|
115
|
+
`${key} defines the value of configs living in different environments:`,
|
|
116
|
+
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${pc.cyan(c.configName)} which value lives in environment ${pc.cyan(JSON.stringify(c.configEnv))}`),
|
|
117
|
+
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/config#pointer-imports'
|
|
118
|
+
].join('\n'));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function clearFilesEnvMap() {
|
|
122
|
+
filesEnvMap.clear();
|
|
123
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export { transformFileImports };
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export type {
|
|
2
|
+
export { parsePointerImportData };
|
|
3
|
+
export { isPointerImportData };
|
|
4
|
+
export type { PointerImportData };
|
|
5
5
|
declare function transformFileImports(code: string, filePathToShowToUser2: string, pointerImports: Record<string, boolean> | 'all', skipWarnings?: true): string | null;
|
|
6
6
|
/**
|
|
7
|
-
* Data Structure
|
|
7
|
+
* Data Structure for [pointer imports](https://vike.dev/config#pointer-imports):
|
|
8
8
|
* `import { someExport as someImport } from './some-file'`
|
|
9
9
|
* <=>
|
|
10
|
-
* `
|
|
10
|
+
* `pointerImportData === {`
|
|
11
11
|
* `importPath: './some-file',`
|
|
12
12
|
* `exportName: 'someExport',`
|
|
13
13
|
* `importString: 'import:./some-file:someExport',`
|
|
@@ -15,14 +15,14 @@ declare function transformFileImports(code: string, filePathToShowToUser2: strin
|
|
|
15
15
|
* `}`
|
|
16
16
|
* We discard the import name `someImport` because we don't need it.
|
|
17
17
|
*/
|
|
18
|
-
type
|
|
18
|
+
type PointerImportData = {
|
|
19
19
|
importPath: string;
|
|
20
20
|
exportName: string;
|
|
21
21
|
importString: string;
|
|
22
22
|
importStringWasGenerated: boolean;
|
|
23
23
|
};
|
|
24
|
-
declare function
|
|
25
|
-
declare function
|
|
24
|
+
declare function isPointerImportData(str: string): boolean;
|
|
25
|
+
declare function parsePointerImportData(importString: string): null | PointerImportData;
|
|
26
26
|
declare module 'estree' {
|
|
27
27
|
interface BaseNodeWithoutComments {
|
|
28
28
|
start: number;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { transformFileImports };
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
2
|
+
export { parsePointerImportData };
|
|
3
|
+
export { isPointerImportData };
|
|
4
4
|
// Playground: https://github.com/brillout/acorn-playground
|
|
5
5
|
// Notes about `with { type: 'pointer' }`
|
|
6
6
|
// - It works well with TypeScript: it doesn't complain upon `with { type: 'unknown-to-typescript' }` and go-to-definition & types are preserved: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#import-attributes
|
|
@@ -90,7 +90,7 @@ skipWarnings) {
|
|
|
90
90
|
}
|
|
91
91
|
return importLocalName;
|
|
92
92
|
})();
|
|
93
|
-
const importString =
|
|
93
|
+
const importString = serializePointerImportData({ importPath, exportName, importStringWasGenerated: true });
|
|
94
94
|
replacement += `const ${importLocalName} = '${importString}';`;
|
|
95
95
|
});
|
|
96
96
|
spliceOperations.push({
|
|
@@ -118,16 +118,16 @@ function getImports(code) {
|
|
|
118
118
|
const import_ = 'import';
|
|
119
119
|
const SEP = ':';
|
|
120
120
|
const zeroWidthSpace = '\u200b';
|
|
121
|
-
function
|
|
121
|
+
function serializePointerImportData({ importPath, exportName, importStringWasGenerated }) {
|
|
122
122
|
const tag = importStringWasGenerated ? zeroWidthSpace : '';
|
|
123
123
|
// `import:${importPath}:${importPath}`
|
|
124
124
|
return `${tag}${import_}${SEP}${importPath}${SEP}${exportName}`;
|
|
125
125
|
}
|
|
126
|
-
function
|
|
126
|
+
function isPointerImportData(str) {
|
|
127
127
|
return str.startsWith(import_ + SEP) || str.startsWith(zeroWidthSpace + import_ + SEP);
|
|
128
128
|
}
|
|
129
|
-
function
|
|
130
|
-
if (!
|
|
129
|
+
function parsePointerImportData(importString) {
|
|
130
|
+
if (!isPointerImportData(importString)) {
|
|
131
131
|
return null;
|
|
132
132
|
}
|
|
133
133
|
let importStringWasGenerated = false;
|
|
@@ -7,10 +7,11 @@ import fs from 'fs';
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { import_ } from '@brillout/import';
|
|
10
|
-
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isJavaScriptFile, createDebugger,
|
|
10
|
+
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isJavaScriptFile, createDebugger, assertPathFilesystemAbsolute, assertIsNpmPackageImport } from '../../../../utils.js';
|
|
11
11
|
import { transformFileImports } from './transformFileImports.js';
|
|
12
12
|
import { vikeConfigDependencies } from '../getVikeConfig.js';
|
|
13
13
|
import 'source-map-support/register.js';
|
|
14
|
+
import { getFilePathAbsoluteUserRootDir } from '../../../../shared/getFilePath.js';
|
|
14
15
|
assertIsNotProductionRuntime();
|
|
15
16
|
const debug = createDebugger('vike:pointer-imports');
|
|
16
17
|
async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile) {
|
|
@@ -111,13 +112,21 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
111
112
|
return resolved;
|
|
112
113
|
}
|
|
113
114
|
assert(resolved.path);
|
|
114
|
-
|
|
115
|
+
const importPathResolved = toPosixPath(resolved.path);
|
|
116
|
+
const importPathOriginal = args.path;
|
|
117
|
+
// Esbuild resolves path aliases.
|
|
118
|
+
// - Enabling us to use:
|
|
119
|
+
// ```js
|
|
120
|
+
// isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
121
|
+
// assertIsNpmPackageImport()
|
|
122
|
+
// ```
|
|
123
|
+
assertPathFilesystemAbsolute(importPathResolved);
|
|
115
124
|
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
116
125
|
// - This is temporary, see comment below.
|
|
117
|
-
const isVikeExtensionConfigImport =
|
|
126
|
+
const isVikeExtensionConfigImport = importPathResolved.endsWith('+config.js');
|
|
118
127
|
const isPointerImport = transformImports === 'all' ||
|
|
119
128
|
// .jsx, .vue, .svg, ... => obviously not config code
|
|
120
|
-
!isJavaScriptFile(
|
|
129
|
+
!isJavaScriptFile(importPathResolved) ||
|
|
121
130
|
// 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).
|
|
122
131
|
// - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
|
|
123
132
|
// - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
|
|
@@ -126,21 +135,52 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
126
135
|
// - For example if esbuild cannot resolve a path alias while Vite can.
|
|
127
136
|
// - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
|
|
128
137
|
resolved.errors.length > 0;
|
|
129
|
-
|
|
130
|
-
assertPosixPath(resolved.path);
|
|
138
|
+
assertPosixPath(importPathResolved);
|
|
131
139
|
const isExternal = isPointerImport ||
|
|
132
140
|
// 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.)
|
|
133
|
-
|
|
141
|
+
importPathResolved.includes('/node_modules/');
|
|
142
|
+
const filePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir({
|
|
143
|
+
filePathAbsoluteFilesystem: importPathResolved,
|
|
144
|
+
userRootDir
|
|
145
|
+
});
|
|
146
|
+
let importPathTranspiled;
|
|
147
|
+
assertPosixPath(importPathOriginal);
|
|
148
|
+
if (importPathOriginal.startsWith('./') || importPathOriginal.startsWith('../')) {
|
|
149
|
+
// - We need this assertUsage() because we didn't find a way (yet?) to use filesystem absolute import paths in virtual files.
|
|
150
|
+
// - Alternatively, we can again try one of the following for generating the imports of virtual files. (Last time we tried none of it worked.)
|
|
151
|
+
// - ~~~js
|
|
152
|
+
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
153
|
+
// filePath = `/@fs${filePathAbsoluteFilesystem}`
|
|
154
|
+
// ~~~
|
|
155
|
+
// - ~~~js
|
|
156
|
+
// assert(filePathAbsoluteUserRootDir.startsWith('../'))
|
|
157
|
+
// filePathAbsoluteUserRootDir = '/' + filePathAbsoluteUserRootDir
|
|
158
|
+
// ~~~
|
|
159
|
+
assertUsage(filePathAbsoluteUserRootDir, `Import ${pc.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.`);
|
|
160
|
+
importPathTranspiled = importPathResolved;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
// importPathOriginal is either:
|
|
164
|
+
// - Npm package import
|
|
165
|
+
// - Path alias
|
|
166
|
+
if (filePathAbsoluteUserRootDir) {
|
|
167
|
+
// importPathOriginal is most likely a path alias. (Is it even possible for an npm package import to resolved inside `userRootDir`?)
|
|
168
|
+
importPathTranspiled = importPathResolved;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
// importPathOriginal is an npm package import. (Assuming path aliases always resolve inside `userRootDir`.)
|
|
172
|
+
assertIsNpmPackageImport(importPathOriginal);
|
|
173
|
+
importPathTranspiled = importPathOriginal;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
134
176
|
if (debug.isActivated)
|
|
135
|
-
debug('onResolved()', { args, resolved, isPointerImport, isExternal });
|
|
136
|
-
|
|
137
|
-
// isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
138
|
-
// assertIsNpmPackageImport()
|
|
139
|
-
assertPathIsFilesystemAbsolute(resolved.path);
|
|
177
|
+
debug('onResolved()', { args, resolved, importPathTranspiled, isPointerImport, isExternal });
|
|
178
|
+
pointerImports[importPathTranspiled] = isPointerImport;
|
|
140
179
|
if (isExternal) {
|
|
141
|
-
return { external: true, path:
|
|
180
|
+
return { external: true, path: importPathTranspiled };
|
|
142
181
|
}
|
|
143
182
|
else {
|
|
183
|
+
resolved.path = importPathTranspiled;
|
|
144
184
|
return resolved;
|
|
145
185
|
}
|
|
146
186
|
});
|