vike 0.4.168 → 0.4.170
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 +53 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +82 -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 +54 -13
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +82 -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
|
@@ -3,7 +3,7 @@ export { reloadVikeConfig };
|
|
|
3
3
|
export { vikeConfigDependencies };
|
|
4
4
|
export { isVikeConfigFile };
|
|
5
5
|
export { isV1Design };
|
|
6
|
-
import { assertPosixPath, assert, isObject, assertUsage, assertWarning, objectEntries, hasProp, arrayIncludes, assertIsNotProductionRuntime, getMostSimilar, joinEnglish, lowerFirst,
|
|
6
|
+
import { assertPosixPath, assert, isObject, assertUsage, assertWarning, objectEntries, hasProp, arrayIncludes, assertIsNotProductionRuntime, getMostSimilar, joinEnglish, lowerFirst, getOutDirs, assertKeys, objectKeys, objectFromEntries, makeFirst, isNpmPackageImport, reverse } from '../../../utils.js';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { configDefinitionsBuiltIn, configDefinitionsBuiltInGlobal } from './getVikeConfig/configDefinitionsBuiltIn.js';
|
|
9
9
|
import { getLocationId, getFilesystemRouteString, getFilesystemRouteDefinedBy, isInherited, sortAfterInheritanceOrder, isGlobalLocation, applyFilesystemRoutingRootEffect } from './getVikeConfig/filesystemRouting.js';
|
|
@@ -13,12 +13,12 @@ import { getViteDevServer } from '../../../../runtime/globalContext.js';
|
|
|
13
13
|
import { logConfigError, logConfigErrorRecover } from '../../../shared/loggerNotProd.js';
|
|
14
14
|
import { removeSuperfluousViteLog_enable, removeSuperfluousViteLog_disable } from '../../../shared/loggerVite/removeSuperfluousViteLog.js';
|
|
15
15
|
import pc from '@brillout/picocolors';
|
|
16
|
-
import {
|
|
16
|
+
import { getConfigDefinedAt } from '../../../../../shared/page-configs/getConfigDefinedAt.js';
|
|
17
17
|
import { assertConfigValueIsSerializable } from './getConfigValuesSerialized.js';
|
|
18
18
|
import { crawlPlusFiles } from './getVikeConfig/crawlPlusFiles.js';
|
|
19
19
|
import { getConfigFileExport } from './getConfigFileExport.js';
|
|
20
20
|
import { loadConfigFile, loadImportedFile, loadValueFile } from './getVikeConfig/loadFileAtConfigTime.js';
|
|
21
|
-
import { clearFilesEnvMap,
|
|
21
|
+
import { clearFilesEnvMap, resolvePointerImportOfConfig } from './getVikeConfig/resolvePointerImport.js';
|
|
22
22
|
import { getFilePathResolved } from '../../../shared/getFilePath.js';
|
|
23
23
|
assertIsNotProductionRuntime();
|
|
24
24
|
let devServerIsCorrupt = false;
|
|
@@ -127,6 +127,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev) {
|
|
|
127
127
|
'vike-pinia',
|
|
128
128
|
'vike-solid'
|
|
129
129
|
];
|
|
130
|
+
assert(extendsConfig.filePath.importPathAbsolute);
|
|
130
131
|
const extensionName = extendsConfig.filePath.importPathAbsolute.split('/')[0];
|
|
131
132
|
const warnMsg = alreadyMigrated.includes(extensionName)
|
|
132
133
|
? `You're using a deprecated version of the Vike extension ${extensionName}, update ${extensionName} to its latest version.`
|
|
@@ -265,6 +266,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev) {
|
|
|
265
266
|
if (isGlobalConfig(configName))
|
|
266
267
|
return;
|
|
267
268
|
const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
269
|
+
configDef.env = deriveConfigEnvFromFileName(configDef.env, interfaceFile.filePath.fileName);
|
|
268
270
|
if (!isConfigEnv(configDef, configName))
|
|
269
271
|
return;
|
|
270
272
|
const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
|
|
@@ -301,6 +303,22 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev) {
|
|
|
301
303
|
assertPageConfigs(pageConfigs);
|
|
302
304
|
return { pageConfigs, pageConfigGlobal, globalVikeConfig };
|
|
303
305
|
}
|
|
306
|
+
function deriveConfigEnvFromFileName(env, fileName) {
|
|
307
|
+
env = { ...env };
|
|
308
|
+
if (fileName.includes('.server.')) {
|
|
309
|
+
env.server = true;
|
|
310
|
+
env.client = false;
|
|
311
|
+
}
|
|
312
|
+
else if (fileName.includes('.client.')) {
|
|
313
|
+
env.client = true;
|
|
314
|
+
env.server = false;
|
|
315
|
+
}
|
|
316
|
+
else if (fileName.includes('.shared.')) {
|
|
317
|
+
env.server = true;
|
|
318
|
+
env.client = true;
|
|
319
|
+
}
|
|
320
|
+
return env;
|
|
321
|
+
}
|
|
304
322
|
function assertPageConfigs(pageConfigs) {
|
|
305
323
|
pageConfigs.forEach((pageConfig) => {
|
|
306
324
|
assertOnBeforeRenderEnv(pageConfig);
|
|
@@ -387,7 +405,7 @@ async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importe
|
|
|
387
405
|
assert('value' in configValueSource);
|
|
388
406
|
if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
|
|
389
407
|
return;
|
|
390
|
-
const { filePathToShowToUser } = configValueSource.
|
|
408
|
+
const { filePathToShowToUser } = configValueSource.definedAtFilePath;
|
|
391
409
|
assertWarning(false, `Being able to define config ${pc.cyan(configName)} in ${filePathToShowToUser} is experimental and will likely be removed. Define the config ${pc.cyan(configName)} in Vike's Vite plugin options instead.`, { onlyOnce: true });
|
|
392
410
|
globalVikeConfig[configName] = configValueSource.value;
|
|
393
411
|
}
|
|
@@ -481,26 +499,26 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
481
499
|
assert(conf);
|
|
482
500
|
const configEnv = configDef.env;
|
|
483
501
|
const { locationId } = interfaceFile;
|
|
484
|
-
const
|
|
502
|
+
const definedAtFilePath_ = {
|
|
485
503
|
...interfaceFile.filePath,
|
|
486
504
|
fileExportPathToShowToUser: ['default', configName]
|
|
487
505
|
};
|
|
488
506
|
// +client.js
|
|
489
507
|
if (configDef._valueIsFilePath) {
|
|
490
|
-
let
|
|
508
|
+
let definedAtFilePath;
|
|
491
509
|
let valueFilePath;
|
|
492
510
|
if (interfaceFile.isConfigFile) {
|
|
493
511
|
const { configValue } = conf;
|
|
494
|
-
const
|
|
495
|
-
const configDefinedAt =
|
|
496
|
-
assertUsage(
|
|
497
|
-
valueFilePath =
|
|
498
|
-
|
|
512
|
+
const pointerImport = resolvePointerImportOfConfig(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
513
|
+
const configDefinedAt = getConfigDefinedAt('Config', configName, definedAtFilePath_);
|
|
514
|
+
assertUsage(pointerImport, `${configDefinedAt} should be an import`);
|
|
515
|
+
valueFilePath = pointerImport.filePathAbsoluteVite;
|
|
516
|
+
definedAtFilePath = pointerImport;
|
|
499
517
|
}
|
|
500
518
|
else {
|
|
501
519
|
assert(interfaceFile.isValueFile);
|
|
502
520
|
valueFilePath = interfaceFile.filePath.filePathAbsoluteVite;
|
|
503
|
-
|
|
521
|
+
definedAtFilePath = {
|
|
504
522
|
...interfaceFile.filePath,
|
|
505
523
|
fileExportPathToShowToUser: []
|
|
506
524
|
};
|
|
@@ -512,7 +530,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
512
530
|
configEnv,
|
|
513
531
|
valueIsImportedAtRuntime: true,
|
|
514
532
|
valueIsDefinedByValueFile: false,
|
|
515
|
-
|
|
533
|
+
definedAtFilePath
|
|
516
534
|
};
|
|
517
535
|
return configValueSource;
|
|
518
536
|
}
|
|
@@ -520,28 +538,26 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
520
538
|
if (interfaceFile.isConfigFile) {
|
|
521
539
|
assert('configValue' in conf);
|
|
522
540
|
const { configValue } = conf;
|
|
523
|
-
//
|
|
524
|
-
const
|
|
525
|
-
if (
|
|
541
|
+
// Pointer import
|
|
542
|
+
const pointerImport = resolvePointerImportOfConfig(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
543
|
+
if (pointerImport) {
|
|
526
544
|
const configValueSource = {
|
|
527
545
|
locationId,
|
|
528
546
|
configEnv,
|
|
529
547
|
valueIsImportedAtRuntime: true,
|
|
530
548
|
valueIsDefinedByValueFile: false,
|
|
531
|
-
|
|
549
|
+
definedAtFilePath: pointerImport
|
|
532
550
|
};
|
|
533
551
|
// Load fake import
|
|
534
552
|
if (isConfigEnv(configDef, configName) &&
|
|
535
553
|
// The value of `extends` was already loaded and already used: we don't need the value of `extends` anymore
|
|
536
554
|
configName !== 'extends') {
|
|
537
|
-
if (
|
|
538
|
-
|
|
539
|
-
assert(hasProp(import_, 'filePathToShowToUserResolved', 'string')); // Help TS
|
|
540
|
-
const fileExport = await loadImportedFile(import_, userRootDir, importedFilesLoaded);
|
|
555
|
+
if (pointerImport.filePathAbsoluteFilesystem) {
|
|
556
|
+
const fileExport = await loadImportedFile(pointerImport, userRootDir, importedFilesLoaded);
|
|
541
557
|
configValueSource.value = fileExport;
|
|
542
558
|
}
|
|
543
559
|
else {
|
|
544
|
-
const configDefinedAt =
|
|
560
|
+
const configDefinedAt = getConfigDefinedAt('Config', configName, configValueSource.definedAtFilePath);
|
|
545
561
|
assertUsage(!configDef.cumulative, `${configDefinedAt} cannot be defined over an aliased import`);
|
|
546
562
|
}
|
|
547
563
|
}
|
|
@@ -554,7 +570,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
554
570
|
configEnv,
|
|
555
571
|
valueIsImportedAtRuntime: false,
|
|
556
572
|
valueIsDefinedByValueFile: false,
|
|
557
|
-
|
|
573
|
+
definedAtFilePath: definedAtFilePath_
|
|
558
574
|
};
|
|
559
575
|
return configValueSource;
|
|
560
576
|
}
|
|
@@ -567,7 +583,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
567
583
|
configEnv,
|
|
568
584
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
569
585
|
valueIsDefinedByValueFile: true,
|
|
570
|
-
|
|
586
|
+
definedAtFilePath: {
|
|
571
587
|
...interfaceFile.filePath,
|
|
572
588
|
fileExportPathToShowToUser: configName === interfaceFile.configName
|
|
573
589
|
? []
|
|
@@ -605,12 +621,12 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
605
621
|
return;
|
|
606
622
|
const meta = configMeta.configValue;
|
|
607
623
|
assertMetaValue(meta, `Config ${pc.cyan('meta')} defined at ${interfaceFile.filePath.filePathToShowToUser}`);
|
|
608
|
-
// Set configDef.
|
|
624
|
+
// Set configDef._userEffectDefinedAtFilePath
|
|
609
625
|
Object.entries(meta).forEach(([configName, configDef]) => {
|
|
610
626
|
if (!configDef.effect)
|
|
611
627
|
return;
|
|
612
628
|
assert(interfaceFile.isConfigFile);
|
|
613
|
-
configDef.
|
|
629
|
+
configDef._userEffectDefinedAtFilePath = {
|
|
614
630
|
...interfaceFile.filePath,
|
|
615
631
|
fileExportPathToShowToUser: ['default', 'meta', configName, 'effect']
|
|
616
632
|
};
|
|
@@ -627,24 +643,24 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
627
643
|
const configDefinitions = configDefinitionsMerged;
|
|
628
644
|
return configDefinitions;
|
|
629
645
|
}
|
|
630
|
-
function assertMetaValue(metaVal,
|
|
646
|
+
function assertMetaValue(metaVal, metaConfigDefinedAt) {
|
|
631
647
|
if (!isObject(metaVal)) {
|
|
632
|
-
assert(
|
|
633
|
-
assertUsage(false, `${
|
|
648
|
+
assert(metaConfigDefinedAt); // We expect internal effects to return a valid meta value
|
|
649
|
+
assertUsage(false, `${metaConfigDefinedAt} has an invalid type ${pc.cyan(typeof metaVal)}: it should be an object instead.`);
|
|
634
650
|
}
|
|
635
651
|
objectEntries(metaVal).forEach(([configName, def]) => {
|
|
636
652
|
if (!isObject(def)) {
|
|
637
|
-
assert(
|
|
638
|
-
assertUsage(false, `${
|
|
653
|
+
assert(metaConfigDefinedAt); // We expect internal effects to return a valid meta value
|
|
654
|
+
assertUsage(false, `${metaConfigDefinedAt} sets ${pc.cyan(`meta.${configName}`)} to a value with an invalid type ${pc.cyan(typeof def)}: it should be an object instead.`);
|
|
639
655
|
}
|
|
640
656
|
// env
|
|
641
657
|
let configEnv;
|
|
642
658
|
{
|
|
643
|
-
assert(
|
|
659
|
+
assert(metaConfigDefinedAt); // We expect internal effects to return a valid meta value
|
|
644
660
|
if (!('env' in def)) {
|
|
645
|
-
assertUsage(false, `${
|
|
661
|
+
assertUsage(false, `${metaConfigDefinedAt} doesn't set ${pc.cyan(`meta.${configName}.env`)} but it's required.`);
|
|
646
662
|
}
|
|
647
|
-
configEnv = getConfigEnvValue(def.env, `${
|
|
663
|
+
configEnv = getConfigEnvValue(def.env, `${metaConfigDefinedAt} sets ${pc.cyan(`meta.${configName}.env`)} to`);
|
|
648
664
|
// Overwrite deprecated value with valid value
|
|
649
665
|
// TODO/v1-release: remove once support for the deprecated values is removed
|
|
650
666
|
if (typeof def.env === 'string')
|
|
@@ -653,12 +669,12 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
|
653
669
|
// effect
|
|
654
670
|
if ('effect' in def) {
|
|
655
671
|
if (!hasProp(def, 'effect', 'function')) {
|
|
656
|
-
assert(
|
|
657
|
-
assertUsage(false, `${
|
|
672
|
+
assert(metaConfigDefinedAt); // We expect internal effects to return a valid meta value
|
|
673
|
+
assertUsage(false, `${metaConfigDefinedAt} sets ${pc.cyan(`meta.${configName}.effect`)} to an invalid type ${pc.cyan(typeof def.effect)}: it should be a function instead`);
|
|
658
674
|
}
|
|
659
675
|
if (!configEnv.config) {
|
|
660
|
-
assert(
|
|
661
|
-
assertUsage(false, `${
|
|
676
|
+
assert(metaConfigDefinedAt); // We expect internal effects to return a valid meta value
|
|
677
|
+
assertUsage(false, `${metaConfigDefinedAt} sets ${pc.cyan(`meta.${configName}.effect`)} but it's only supported if meta.${configName}.env has ${pc.cyan('{ config: true }')} (but it's ${pc.cyan(JSON.stringify(configEnv))} instead)`);
|
|
662
678
|
}
|
|
663
679
|
}
|
|
664
680
|
});
|
|
@@ -680,7 +696,7 @@ function applyEffectsAll(configValueSources, configDefinitions) {
|
|
|
680
696
|
// Call effect
|
|
681
697
|
const configModFromEffect = configDef.effect({
|
|
682
698
|
configValue: source.value,
|
|
683
|
-
configDefinedAt:
|
|
699
|
+
configDefinedAt: getConfigDefinedAt('Config', configName, source.definedAtFilePath)
|
|
684
700
|
});
|
|
685
701
|
if (!configModFromEffect)
|
|
686
702
|
return;
|
|
@@ -692,16 +708,14 @@ function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
|
|
|
692
708
|
const notSupported = `Effects currently only supports modifying the the ${pc.cyan('env')} of a config.`;
|
|
693
709
|
objectEntries(configModFromEffect).forEach(([configName, configValue]) => {
|
|
694
710
|
if (configName === 'meta') {
|
|
695
|
-
let
|
|
696
|
-
if (configDefEffect.
|
|
697
|
-
|
|
698
|
-
definedAt: configDefEffect._userEffectDefinedAt
|
|
699
|
-
});
|
|
711
|
+
let configDefinedAt;
|
|
712
|
+
if (configDefEffect._userEffectDefinedAtFilePath) {
|
|
713
|
+
configDefinedAt = getConfigDefinedAt('Config', configName, configDefEffect._userEffectDefinedAtFilePath);
|
|
700
714
|
}
|
|
701
715
|
else {
|
|
702
|
-
|
|
716
|
+
configDefinedAt = null;
|
|
703
717
|
}
|
|
704
|
-
assertMetaValue(configValue,
|
|
718
|
+
assertMetaValue(configValue, configDefinedAt);
|
|
705
719
|
objectEntries(configValue).forEach(([configTargetName, configTargetDef]) => {
|
|
706
720
|
{
|
|
707
721
|
const keys = Object.keys(configTargetDef);
|
|
@@ -719,7 +733,7 @@ function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
|
|
|
719
733
|
else {
|
|
720
734
|
assertUsage(false, notSupported);
|
|
721
735
|
// If we do end implementing being able to set the value of a config:
|
|
722
|
-
// - For setting
|
|
736
|
+
// - For setting definedAtFile: we could take the definedAtFile of the effect config while appending '(effect)' to definedAtFile.fileExportPathToShowToUser
|
|
723
737
|
}
|
|
724
738
|
});
|
|
725
739
|
}
|
|
@@ -827,11 +841,11 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
827
841
|
if (configFilesystemRoutingRoot) {
|
|
828
842
|
const routingRoot = getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName);
|
|
829
843
|
if (routingRoot) {
|
|
830
|
-
const { filesystemRoutingRootEffect /*,
|
|
844
|
+
const { filesystemRoutingRootEffect /*, filesystemRoutingRootConfigDefinedAt*/ } = routingRoot;
|
|
831
845
|
const debugInfo = { locationId, routeFilesystem: filesystemRouteString, configFilesystemRoutingRoot };
|
|
832
846
|
assert(filesystemRouteString.startsWith(filesystemRoutingRootEffect.before), debugInfo);
|
|
833
847
|
filesystemRouteString = applyFilesystemRoutingRootEffect(filesystemRouteString, filesystemRoutingRootEffect);
|
|
834
|
-
// filesystemRouteDefinedBy = `${filesystemRouteDefinedBy} (with ${
|
|
848
|
+
// filesystemRouteDefinedBy = `${filesystemRouteDefinedBy} (with ${filesystemRoutingRootConfigDefinedAt})`
|
|
835
849
|
}
|
|
836
850
|
}
|
|
837
851
|
assert(filesystemRouteString.startsWith('/'));
|
|
@@ -846,15 +860,15 @@ function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName)
|
|
|
846
860
|
// Eagerly loaded since it's config-only
|
|
847
861
|
assert('value' in configFilesystemRoutingRoot);
|
|
848
862
|
const { value } = configFilesystemRoutingRoot;
|
|
849
|
-
const configDefinedAt =
|
|
863
|
+
const configDefinedAt = getConfigDefinedAt('Config', configName, configFilesystemRoutingRoot.definedAtFilePath);
|
|
850
864
|
assertUsage(typeof value === 'string', `${configDefinedAt} should be a string`);
|
|
851
865
|
assertUsage(value.startsWith('/'), `${configDefinedAt} is ${pc.cyan(value)} but it should start with a leading slash ${pc.cyan('/')}`);
|
|
852
|
-
const { filePathAbsoluteUserRootDir } = configFilesystemRoutingRoot.
|
|
866
|
+
const { filePathAbsoluteUserRootDir } = configFilesystemRoutingRoot.definedAtFilePath;
|
|
853
867
|
assert(filePathAbsoluteUserRootDir);
|
|
854
868
|
const before = getFilesystemRouteString(getLocationId(filePathAbsoluteUserRootDir));
|
|
855
869
|
const after = value;
|
|
856
870
|
const filesystemRoutingRootEffect = { before, after };
|
|
857
|
-
return { filesystemRoutingRootEffect,
|
|
871
|
+
return { filesystemRoutingRootEffect, filesystemRoutingRootConfigDefinedAt: configDefinedAt };
|
|
858
872
|
}
|
|
859
873
|
function determineIsErrorPage(routeFilesystem) {
|
|
860
874
|
assertPosixPath(routeFilesystem);
|
|
@@ -867,8 +881,9 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
867
881
|
const configValues = {};
|
|
868
882
|
Object.entries(configValuesComputed).forEach(([configName, configValueComputed]) => {
|
|
869
883
|
configValues[configName] = {
|
|
884
|
+
type: 'computed',
|
|
870
885
|
value: configValueComputed.value,
|
|
871
|
-
|
|
886
|
+
definedAtData: null
|
|
872
887
|
};
|
|
873
888
|
});
|
|
874
889
|
Object.entries(configValueSources).forEach(([configName, sources]) => {
|
|
@@ -878,18 +893,20 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
878
893
|
const configValueSource = sources[0];
|
|
879
894
|
if ('value' in configValueSource) {
|
|
880
895
|
configValues[configName] = {
|
|
896
|
+
type: 'classic',
|
|
881
897
|
value: configValueSource.value,
|
|
882
|
-
|
|
898
|
+
definedAtData: getDefinedAtFile(configValueSource)
|
|
883
899
|
};
|
|
884
900
|
}
|
|
885
901
|
}
|
|
886
902
|
else {
|
|
887
903
|
const value = mergeCumulative(configName, sources);
|
|
904
|
+
const definedAtData = sources.map((source) => getDefinedAtFile(source));
|
|
905
|
+
assert(value.length === definedAtData.length);
|
|
888
906
|
configValues[configName] = {
|
|
907
|
+
type: 'cumulative',
|
|
889
908
|
value,
|
|
890
|
-
|
|
891
|
-
files: sources.map((source) => getDefinedAtFile(source))
|
|
892
|
-
}
|
|
909
|
+
definedAtData
|
|
893
910
|
};
|
|
894
911
|
}
|
|
895
912
|
});
|
|
@@ -897,62 +914,21 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
897
914
|
}
|
|
898
915
|
function getDefinedAtFile(configValueSource) {
|
|
899
916
|
return {
|
|
900
|
-
filePathToShowToUser: configValueSource.
|
|
901
|
-
fileExportPathToShowToUser: configValueSource.
|
|
917
|
+
filePathToShowToUser: configValueSource.definedAtFilePath.filePathToShowToUser,
|
|
918
|
+
fileExportPathToShowToUser: configValueSource.definedAtFilePath.fileExportPathToShowToUser
|
|
902
919
|
};
|
|
903
920
|
}
|
|
904
|
-
function getDefinedAt(configValueSource) {
|
|
905
|
-
return getDefinedAtFile(configValueSource);
|
|
906
|
-
}
|
|
907
921
|
function mergeCumulative(configName, configValueSources) {
|
|
908
|
-
const
|
|
909
|
-
const valuesSet = [];
|
|
910
|
-
let configValueSourcePrevious = null;
|
|
922
|
+
const configValues = [];
|
|
911
923
|
configValueSources.forEach((configValueSource) => {
|
|
912
|
-
const configDefinedAt = getConfigDefinedAtString('Config', configName, configValueSource);
|
|
913
924
|
// We could, in principle, also support cumulative for values that aren't loaded at config-time but it isn't completely trivial to implement.
|
|
914
925
|
assert('value' in configValueSource);
|
|
915
926
|
// Make sure configValueSource.value is serializable
|
|
916
|
-
assertConfigValueIsSerializable(configValueSource.value, configName,
|
|
917
|
-
const assertNoMixing = (isSet) => {
|
|
918
|
-
const vals1 = isSet ? valuesSet : valuesArr;
|
|
919
|
-
const t1 = isSet ? 'a Set' : 'an array';
|
|
920
|
-
const vals2 = !isSet ? valuesSet : valuesArr;
|
|
921
|
-
const t2 = !isSet ? 'a Set' : 'an array';
|
|
922
|
-
assert(vals1.length > 0);
|
|
923
|
-
if (vals2.length === 0)
|
|
924
|
-
return;
|
|
925
|
-
assert(configValueSourcePrevious);
|
|
926
|
-
const configPreviousDefinedAt = getConfigDefinedAtString('Config', configName, configValueSourcePrevious);
|
|
927
|
-
assertUsage(false, `${configDefinedAt} sets ${t1} but another ${configPreviousDefinedAt} sets ${t2} which is forbidden: the values must be all arrays or all sets (you cannot mix).`);
|
|
928
|
-
};
|
|
927
|
+
assertConfigValueIsSerializable(configValueSource.value, configName, getDefinedAtFile(configValueSource));
|
|
929
928
|
const { value } = configValueSource;
|
|
930
|
-
|
|
931
|
-
valuesArr.push(value);
|
|
932
|
-
assertNoMixing(false);
|
|
933
|
-
}
|
|
934
|
-
else if (value instanceof Set) {
|
|
935
|
-
valuesSet.push(value);
|
|
936
|
-
assertNoMixing(true);
|
|
937
|
-
}
|
|
938
|
-
else {
|
|
939
|
-
assertUsage(false, `${configDefinedAt} must be an array or a Set`);
|
|
940
|
-
}
|
|
941
|
-
configValueSourcePrevious = configValueSource;
|
|
929
|
+
configValues.push(value);
|
|
942
930
|
});
|
|
943
|
-
|
|
944
|
-
assert(valuesSet.length === 0);
|
|
945
|
-
const result = mergeCumulativeValues(valuesArr);
|
|
946
|
-
assert(result !== null);
|
|
947
|
-
return result;
|
|
948
|
-
}
|
|
949
|
-
if (valuesSet.length > 0) {
|
|
950
|
-
assert(valuesArr.length === 0);
|
|
951
|
-
const result = mergeCumulativeValues(valuesSet);
|
|
952
|
-
assert(result !== null);
|
|
953
|
-
return result;
|
|
954
|
-
}
|
|
955
|
-
assert(false);
|
|
931
|
+
return configValues;
|
|
956
932
|
}
|
|
957
933
|
function getConfigEnvValue(val, errMsgIntro) {
|
|
958
934
|
const errInvalidValue = `${errMsgIntro} an invalid value ${pc.cyan(JSON.stringify(val))}`;
|
|
@@ -1022,10 +998,10 @@ function assertConfigExists(configName, configNamesRelevant, filePathToShowToUse
|
|
|
1022
998
|
function sortConfigValueSources(configValueSources, locationIdPage) {
|
|
1023
999
|
return Object.fromEntries(Object.entries(configValueSources)
|
|
1024
1000
|
// Make order deterministic (no other purpose)
|
|
1025
|
-
.sort(([, [source1]], [, [source2]]) => source1.
|
|
1001
|
+
.sort(([, [source1]], [, [source2]]) => source1.definedAtFilePath.filePathAbsoluteVite < source2.definedAtFilePath.filePathAbsoluteVite ? -1 : 1)
|
|
1026
1002
|
// Sort after whether the config value was defined by an npm package
|
|
1027
1003
|
.sort(makeFirst(([, [source]]) => {
|
|
1028
|
-
const { importPathAbsolute } = source.
|
|
1004
|
+
const { importPathAbsolute } = source.definedAtFilePath;
|
|
1029
1005
|
return (!!importPathAbsolute &&
|
|
1030
1006
|
isNpmPackageImport(importPathAbsolute, {
|
|
1031
1007
|
// Vike config files don't support path aliases. (If they do one day, then Vike will/should be able to resolve path aliases.)
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -4,7 +4,7 @@ import { getVirtualFileIdPageConfigValuesAll, isVirtualFileIdPageConfigValuesAll
|
|
|
4
4
|
import { getVikeConfig } from './getVikeConfig.js';
|
|
5
5
|
import { extractAssetsAddQuery } from '../../../../shared/extractAssetsQuery.js';
|
|
6
6
|
import { debug } from './debug.js';
|
|
7
|
-
import { getConfigValue } from '../../../../../shared/page-configs/
|
|
7
|
+
import { getConfigValue } from '../../../../../shared/page-configs/getConfigValue.js';
|
|
8
8
|
import { getConfigValueSourcesNotOverriden } from '../../../shared/getConfigValueSourcesNotOverriden.js';
|
|
9
9
|
import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
|
|
10
10
|
import { serializeConfigValueImported } from '../../../../../shared/page-configs/serialize/serializeConfigValue.js';
|
|
@@ -3,19 +3,25 @@ export { getFilePathUnresolved };
|
|
|
3
3
|
export { getModuleFilePath };
|
|
4
4
|
export { getFilePathToShowToUserFromUnkown };
|
|
5
5
|
export { cleanFilePathUnkown };
|
|
6
|
-
|
|
6
|
+
export { getFilePathAbsoluteUserRootDir };
|
|
7
|
+
import type { FilePathResolved, FilePathUnresolved } from '../../../shared/page-configs/FilePath.js';
|
|
7
8
|
import type { ResolvedConfig } from 'vite';
|
|
8
|
-
declare function getFilePathUnresolved({ importPathAbsolute }: {
|
|
9
|
-
importPathAbsolute: string;
|
|
10
|
-
}): FilePath;
|
|
11
9
|
declare function getFilePathResolved(args: {
|
|
12
10
|
userRootDir: string;
|
|
13
|
-
importPathAbsolute?: string;
|
|
14
11
|
} & ({
|
|
15
12
|
filePathAbsoluteFilesystem: string;
|
|
13
|
+
importPathAbsolute: string;
|
|
16
14
|
} | {
|
|
17
15
|
filePathAbsoluteUserRootDir: string;
|
|
16
|
+
importPathAbsolute?: string;
|
|
18
17
|
})): FilePathResolved;
|
|
18
|
+
declare function getFilePathUnresolved(args: {
|
|
19
|
+
importPathAbsolute: string;
|
|
20
|
+
}): FilePathUnresolved;
|
|
21
|
+
declare function getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir }: {
|
|
22
|
+
filePathAbsoluteFilesystem: string;
|
|
23
|
+
userRootDir: string;
|
|
24
|
+
}): string | null;
|
|
19
25
|
declare function getModuleFilePath(moduleId: string, config: ResolvedConfig): string;
|
|
20
26
|
declare function getFilePathToShowToUserFromUnkown(filePathUnkown: string, userRootDir: string): string;
|
|
21
27
|
declare function cleanFilePathUnkown(filePathUnknown: string): string;
|
|
@@ -3,14 +3,11 @@ export { getFilePathUnresolved };
|
|
|
3
3
|
export { getModuleFilePath };
|
|
4
4
|
export { getFilePathToShowToUserFromUnkown };
|
|
5
5
|
export { cleanFilePathUnkown };
|
|
6
|
+
export { getFilePathAbsoluteUserRootDir };
|
|
6
7
|
import path from 'path';
|
|
7
|
-
import { assert,
|
|
8
|
-
function getFilePathUnresolved({ importPathAbsolute }) {
|
|
9
|
-
return getFilePath({ importPathAbsolute, filePathAbsoluteUserRootDir: null });
|
|
10
|
-
}
|
|
8
|
+
import { assert, assertIsNpmPackageImport, assertPathFilesystemAbsolute, assertPosixPath, toPosixPath } from '../utils.js';
|
|
11
9
|
function getFilePathResolved(args) {
|
|
12
10
|
const { userRootDir } = args;
|
|
13
|
-
const importPathAbsolute = args.importPathAbsolute ?? null;
|
|
14
11
|
let filePathAbsoluteFilesystem;
|
|
15
12
|
let filePathAbsoluteUserRootDir;
|
|
16
13
|
if ('filePathAbsoluteFilesystem' in args) {
|
|
@@ -21,73 +18,77 @@ function getFilePathResolved(args) {
|
|
|
21
18
|
filePathAbsoluteUserRootDir = args.filePathAbsoluteUserRootDir;
|
|
22
19
|
filePathAbsoluteFilesystem = getFilePathAbsoluteUserFilesystem({ filePathAbsoluteUserRootDir, userRootDir });
|
|
23
20
|
}
|
|
24
|
-
let filePath;
|
|
25
|
-
const common = {
|
|
26
|
-
filePathAbsoluteUserRootDir,
|
|
27
|
-
importPathAbsolute,
|
|
28
|
-
userRootDir
|
|
29
|
-
};
|
|
30
|
-
if (importPathAbsolute) {
|
|
31
|
-
filePath = getFilePath({
|
|
32
|
-
...common,
|
|
33
|
-
importPathAbsolute
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
assert(filePathAbsoluteUserRootDir);
|
|
38
|
-
filePath = getFilePath({
|
|
39
|
-
...common,
|
|
40
|
-
filePathAbsoluteUserRootDir
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
21
|
assert(filePathAbsoluteFilesystem);
|
|
44
|
-
|
|
22
|
+
assertPathFilesystemAbsolute(filePathAbsoluteFilesystem);
|
|
45
23
|
const filePathToShowToUserResolved = filePathAbsoluteUserRootDir || filePathAbsoluteFilesystem;
|
|
46
24
|
assert(filePathToShowToUserResolved);
|
|
25
|
+
assertPosixPath(filePathAbsoluteFilesystem);
|
|
26
|
+
const fileName = path.posix.basename(filePathAbsoluteFilesystem);
|
|
47
27
|
const filePathResolved = {
|
|
48
|
-
...
|
|
28
|
+
...getComputedProps(args),
|
|
49
29
|
filePathAbsoluteFilesystem,
|
|
50
|
-
filePathToShowToUserResolved
|
|
30
|
+
filePathToShowToUserResolved,
|
|
31
|
+
fileName
|
|
51
32
|
};
|
|
52
33
|
return filePathResolved;
|
|
53
34
|
}
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
35
|
+
function getComputedProps(args) {
|
|
36
|
+
if ('filePathAbsoluteUserRootDir' in args) {
|
|
37
|
+
const importPathAbsolute = args.importPathAbsolute ?? null;
|
|
38
|
+
const { filePathAbsoluteUserRootDir } = args;
|
|
39
|
+
if (importPathAbsolute)
|
|
40
|
+
assertIsNpmPackageImport(importPathAbsolute);
|
|
41
|
+
return {
|
|
42
|
+
importPathAbsolute,
|
|
43
|
+
filePathAbsoluteUserRootDir,
|
|
44
|
+
filePathAbsoluteVite: filePathAbsoluteUserRootDir,
|
|
45
|
+
filePathToShowToUser: filePathAbsoluteUserRootDir
|
|
46
|
+
};
|
|
58
47
|
}
|
|
59
48
|
else {
|
|
60
|
-
|
|
61
|
-
filePathAbsoluteVite = args.importPathAbsolute;
|
|
49
|
+
return getComputedPropsImportPathAbsolute(args);
|
|
62
50
|
}
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
}
|
|
52
|
+
function getComputedPropsImportPathAbsolute(args) {
|
|
53
|
+
const { importPathAbsolute } = args;
|
|
54
|
+
assertIsNpmPackageImport(importPathAbsolute);
|
|
55
|
+
return {
|
|
56
|
+
filePathAbsoluteUserRootDir: null,
|
|
57
|
+
importPathAbsolute,
|
|
58
|
+
filePathAbsoluteVite: importPathAbsolute,
|
|
59
|
+
filePathToShowToUser: importPathAbsolute
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function getFilePathUnresolved(args) {
|
|
65
63
|
return {
|
|
66
|
-
...args,
|
|
67
|
-
filePathAbsoluteFilesystem: null
|
|
68
|
-
filePathAbsoluteVite,
|
|
69
|
-
filePathToShowToUser
|
|
64
|
+
...getComputedPropsImportPathAbsolute(args),
|
|
65
|
+
filePathAbsoluteFilesystem: null
|
|
70
66
|
};
|
|
71
67
|
}
|
|
72
68
|
function getFilePathAbsoluteUserFilesystem({ filePathAbsoluteUserRootDir, userRootDir }) {
|
|
73
69
|
assertPosixPath(filePathAbsoluteUserRootDir);
|
|
74
70
|
assertPosixPath(userRootDir);
|
|
75
|
-
|
|
71
|
+
assertPathFilesystemAbsolute(userRootDir);
|
|
76
72
|
const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathAbsoluteUserRootDir);
|
|
77
|
-
|
|
73
|
+
assertPathFilesystemAbsolute(userRootDir);
|
|
78
74
|
return filePathAbsoluteFilesystem;
|
|
79
75
|
}
|
|
80
76
|
function getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir }) {
|
|
81
77
|
assertPosixPath(filePathAbsoluteFilesystem);
|
|
82
78
|
assertPosixPath(userRootDir);
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
assertPathFilesystemAbsolute(filePathAbsoluteFilesystem);
|
|
80
|
+
assertPathFilesystemAbsolute(userRootDir);
|
|
85
81
|
const filePathRelative = path.posix.relative(userRootDir, filePathAbsoluteFilesystem);
|
|
86
82
|
if (!filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
87
83
|
assert(filePathRelative.startsWith('../'));
|
|
88
84
|
return null;
|
|
89
85
|
}
|
|
90
|
-
assert(!filePathRelative.startsWith('
|
|
86
|
+
assert(!filePathRelative.startsWith('/') &&
|
|
87
|
+
/* Not true if filePathRelative starts with a hidden directory (i.e. a directory with a name that starts with `.`)
|
|
88
|
+
!filePathRelative.startsWith('.') &&
|
|
89
|
+
*/
|
|
90
|
+
!filePathRelative.startsWith('./') &&
|
|
91
|
+
!filePathRelative.startsWith('../'));
|
|
91
92
|
const filePathAbsoluteUserRootDir = `/${filePathRelative}`;
|
|
92
93
|
assert(filePathAbsoluteUserRootDir === getFilePathAbsoluteUserRootDir2(filePathAbsoluteFilesystem, userRootDir));
|
|
93
94
|
return filePathAbsoluteUserRootDir;
|
|
@@ -97,15 +98,15 @@ function getModuleFilePath(moduleId, config) {
|
|
|
97
98
|
assertPosixPath(moduleId);
|
|
98
99
|
assertPosixPath(userRootDir);
|
|
99
100
|
const filePathAbsoluteFilesystem = cleanModuleId(moduleId);
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
return
|
|
101
|
+
assertPathFilesystemAbsolute(filePathAbsoluteFilesystem);
|
|
102
|
+
const filePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir });
|
|
103
|
+
return filePathAbsoluteUserRootDir || filePathAbsoluteFilesystem;
|
|
103
104
|
}
|
|
104
105
|
function getFilePathToShowToUserFromUnkown(
|
|
105
106
|
// We don't have any guarentee about filePath, e.g. about whether is filePathAbsoluteFilesystem or filePathAbsoluteUserRootDir
|
|
106
107
|
filePathUnkown, userRootDir) {
|
|
107
108
|
assertPosixPath(userRootDir);
|
|
108
|
-
|
|
109
|
+
assertPathFilesystemAbsolute(userRootDir);
|
|
109
110
|
filePathUnkown = cleanFilePathUnkown(filePathUnkown);
|
|
110
111
|
if (!filePathUnkown.startsWith(userRootDir)) {
|
|
111
112
|
return filePathUnkown;
|
|
@@ -12,11 +12,11 @@ export * from '../../utils/trimWithAnsi.js';
|
|
|
12
12
|
export * from '../../utils/removeEmptyLines.js';
|
|
13
13
|
export * from '../../utils/findFile.js';
|
|
14
14
|
export * from '../../utils/getPropAccessNotation.js';
|
|
15
|
-
export * from '../../utils/mergeCumulativeValues.js';
|
|
16
15
|
export * from '../../utils/deepEqual.js';
|
|
17
16
|
export * from '../../utils/assertKeys.js';
|
|
18
17
|
export * from '../../utils/injectRollupInputs.js';
|
|
19
18
|
export * from '../../utils/humanizeTime.js';
|
|
20
19
|
export * from '../../utils/pLimit.js';
|
|
21
20
|
export * from '../../utils/assertVersion.js';
|
|
22
|
-
export * from '../../utils/
|
|
21
|
+
export * from '../../utils/assertPathFilesystemAbsolute.js';
|
|
22
|
+
export * from '../../utils/isArray.js';
|
|
@@ -18,11 +18,11 @@ export * from '../../utils/trimWithAnsi.js';
|
|
|
18
18
|
export * from '../../utils/removeEmptyLines.js';
|
|
19
19
|
export * from '../../utils/findFile.js';
|
|
20
20
|
export * from '../../utils/getPropAccessNotation.js';
|
|
21
|
-
export * from '../../utils/mergeCumulativeValues.js';
|
|
22
21
|
export * from '../../utils/deepEqual.js';
|
|
23
22
|
export * from '../../utils/assertKeys.js';
|
|
24
23
|
export * from '../../utils/injectRollupInputs.js';
|
|
25
24
|
export * from '../../utils/humanizeTime.js';
|
|
26
25
|
export * from '../../utils/pLimit.js';
|
|
27
26
|
export * from '../../utils/assertVersion.js';
|
|
28
|
-
export * from '../../utils/
|
|
27
|
+
export * from '../../utils/assertPathFilesystemAbsolute.js';
|
|
28
|
+
export * from '../../utils/isArray.js';
|