vike 0.4.168-commit-7678a7d → 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 +2 -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 +1 -1
- package/dist/cjs/node/plugin/plugins/envVars.js +1 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -4
- 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/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/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 +1 -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 +2 -2
- package/dist/esm/node/plugin/plugins/envVars.js +2 -6
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -5
- 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/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/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
|
@@ -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;
|
|
@@ -265,6 +265,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev) {
|
|
|
265
265
|
if (isGlobalConfig(configName))
|
|
266
266
|
return;
|
|
267
267
|
const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
268
|
+
configDef.env = deriveConfigEnvFromFileName(configDef.env, interfaceFile.filePath.fileName);
|
|
268
269
|
if (!isConfigEnv(configDef, configName))
|
|
269
270
|
return;
|
|
270
271
|
const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
|
|
@@ -301,6 +302,22 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev) {
|
|
|
301
302
|
assertPageConfigs(pageConfigs);
|
|
302
303
|
return { pageConfigs, pageConfigGlobal, globalVikeConfig };
|
|
303
304
|
}
|
|
305
|
+
function deriveConfigEnvFromFileName(env, fileName) {
|
|
306
|
+
env = { ...env };
|
|
307
|
+
if (fileName.includes('.server.')) {
|
|
308
|
+
env.server = true;
|
|
309
|
+
env.client = false;
|
|
310
|
+
}
|
|
311
|
+
else if (fileName.includes('.client.')) {
|
|
312
|
+
env.client = true;
|
|
313
|
+
env.server = false;
|
|
314
|
+
}
|
|
315
|
+
else if (fileName.includes('.shared.')) {
|
|
316
|
+
env.server = true;
|
|
317
|
+
env.client = true;
|
|
318
|
+
}
|
|
319
|
+
return env;
|
|
320
|
+
}
|
|
304
321
|
function assertPageConfigs(pageConfigs) {
|
|
305
322
|
pageConfigs.forEach((pageConfig) => {
|
|
306
323
|
assertOnBeforeRenderEnv(pageConfig);
|
|
@@ -387,7 +404,7 @@ async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importe
|
|
|
387
404
|
assert('value' in configValueSource);
|
|
388
405
|
if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
|
|
389
406
|
return;
|
|
390
|
-
const { filePathToShowToUser } = configValueSource.
|
|
407
|
+
const { filePathToShowToUser } = configValueSource.definedAtFilePath;
|
|
391
408
|
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
409
|
globalVikeConfig[configName] = configValueSource.value;
|
|
393
410
|
}
|
|
@@ -481,26 +498,26 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
481
498
|
assert(conf);
|
|
482
499
|
const configEnv = configDef.env;
|
|
483
500
|
const { locationId } = interfaceFile;
|
|
484
|
-
const
|
|
501
|
+
const definedAtFilePath_ = {
|
|
485
502
|
...interfaceFile.filePath,
|
|
486
503
|
fileExportPathToShowToUser: ['default', configName]
|
|
487
504
|
};
|
|
488
505
|
// +client.js
|
|
489
506
|
if (configDef._valueIsFilePath) {
|
|
490
|
-
let
|
|
507
|
+
let definedAtFilePath;
|
|
491
508
|
let valueFilePath;
|
|
492
509
|
if (interfaceFile.isConfigFile) {
|
|
493
510
|
const { configValue } = conf;
|
|
494
|
-
const
|
|
495
|
-
const configDefinedAt =
|
|
496
|
-
assertUsage(
|
|
497
|
-
valueFilePath =
|
|
498
|
-
|
|
511
|
+
const pointerImport = resolvePointerImportOfConfig(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
512
|
+
const configDefinedAt = getConfigDefinedAt('Config', configName, definedAtFilePath_);
|
|
513
|
+
assertUsage(pointerImport, `${configDefinedAt} should be an import`);
|
|
514
|
+
valueFilePath = pointerImport.filePathAbsoluteVite;
|
|
515
|
+
definedAtFilePath = pointerImport;
|
|
499
516
|
}
|
|
500
517
|
else {
|
|
501
518
|
assert(interfaceFile.isValueFile);
|
|
502
519
|
valueFilePath = interfaceFile.filePath.filePathAbsoluteVite;
|
|
503
|
-
|
|
520
|
+
definedAtFilePath = {
|
|
504
521
|
...interfaceFile.filePath,
|
|
505
522
|
fileExportPathToShowToUser: []
|
|
506
523
|
};
|
|
@@ -512,7 +529,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
512
529
|
configEnv,
|
|
513
530
|
valueIsImportedAtRuntime: true,
|
|
514
531
|
valueIsDefinedByValueFile: false,
|
|
515
|
-
|
|
532
|
+
definedAtFilePath
|
|
516
533
|
};
|
|
517
534
|
return configValueSource;
|
|
518
535
|
}
|
|
@@ -520,28 +537,26 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
520
537
|
if (interfaceFile.isConfigFile) {
|
|
521
538
|
assert('configValue' in conf);
|
|
522
539
|
const { configValue } = conf;
|
|
523
|
-
//
|
|
524
|
-
const
|
|
525
|
-
if (
|
|
540
|
+
// Pointer import
|
|
541
|
+
const pointerImport = resolvePointerImportOfConfig(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
542
|
+
if (pointerImport) {
|
|
526
543
|
const configValueSource = {
|
|
527
544
|
locationId,
|
|
528
545
|
configEnv,
|
|
529
546
|
valueIsImportedAtRuntime: true,
|
|
530
547
|
valueIsDefinedByValueFile: false,
|
|
531
|
-
|
|
548
|
+
definedAtFilePath: pointerImport
|
|
532
549
|
};
|
|
533
550
|
// Load fake import
|
|
534
551
|
if (isConfigEnv(configDef, configName) &&
|
|
535
552
|
// The value of `extends` was already loaded and already used: we don't need the value of `extends` anymore
|
|
536
553
|
configName !== 'extends') {
|
|
537
|
-
if (
|
|
538
|
-
|
|
539
|
-
assert(hasProp(import_, 'filePathToShowToUserResolved', 'string')); // Help TS
|
|
540
|
-
const fileExport = await loadImportedFile(import_, userRootDir, importedFilesLoaded);
|
|
554
|
+
if (pointerImport.filePathAbsoluteFilesystem) {
|
|
555
|
+
const fileExport = await loadImportedFile(pointerImport, userRootDir, importedFilesLoaded);
|
|
541
556
|
configValueSource.value = fileExport;
|
|
542
557
|
}
|
|
543
558
|
else {
|
|
544
|
-
const configDefinedAt =
|
|
559
|
+
const configDefinedAt = getConfigDefinedAt('Config', configName, configValueSource.definedAtFilePath);
|
|
545
560
|
assertUsage(!configDef.cumulative, `${configDefinedAt} cannot be defined over an aliased import`);
|
|
546
561
|
}
|
|
547
562
|
}
|
|
@@ -554,7 +569,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
554
569
|
configEnv,
|
|
555
570
|
valueIsImportedAtRuntime: false,
|
|
556
571
|
valueIsDefinedByValueFile: false,
|
|
557
|
-
|
|
572
|
+
definedAtFilePath: definedAtFilePath_
|
|
558
573
|
};
|
|
559
574
|
return configValueSource;
|
|
560
575
|
}
|
|
@@ -567,7 +582,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
567
582
|
configEnv,
|
|
568
583
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
569
584
|
valueIsDefinedByValueFile: true,
|
|
570
|
-
|
|
585
|
+
definedAtFilePath: {
|
|
571
586
|
...interfaceFile.filePath,
|
|
572
587
|
fileExportPathToShowToUser: configName === interfaceFile.configName
|
|
573
588
|
? []
|
|
@@ -605,12 +620,12 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
605
620
|
return;
|
|
606
621
|
const meta = configMeta.configValue;
|
|
607
622
|
assertMetaValue(meta, `Config ${pc.cyan('meta')} defined at ${interfaceFile.filePath.filePathToShowToUser}`);
|
|
608
|
-
// Set configDef.
|
|
623
|
+
// Set configDef._userEffectDefinedAtFilePath
|
|
609
624
|
Object.entries(meta).forEach(([configName, configDef]) => {
|
|
610
625
|
if (!configDef.effect)
|
|
611
626
|
return;
|
|
612
627
|
assert(interfaceFile.isConfigFile);
|
|
613
|
-
configDef.
|
|
628
|
+
configDef._userEffectDefinedAtFilePath = {
|
|
614
629
|
...interfaceFile.filePath,
|
|
615
630
|
fileExportPathToShowToUser: ['default', 'meta', configName, 'effect']
|
|
616
631
|
};
|
|
@@ -627,24 +642,24 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
627
642
|
const configDefinitions = configDefinitionsMerged;
|
|
628
643
|
return configDefinitions;
|
|
629
644
|
}
|
|
630
|
-
function assertMetaValue(metaVal,
|
|
645
|
+
function assertMetaValue(metaVal, metaConfigDefinedAt) {
|
|
631
646
|
if (!isObject(metaVal)) {
|
|
632
|
-
assert(
|
|
633
|
-
assertUsage(false, `${
|
|
647
|
+
assert(metaConfigDefinedAt); // We expect internal effects to return a valid meta value
|
|
648
|
+
assertUsage(false, `${metaConfigDefinedAt} has an invalid type ${pc.cyan(typeof metaVal)}: it should be an object instead.`);
|
|
634
649
|
}
|
|
635
650
|
objectEntries(metaVal).forEach(([configName, def]) => {
|
|
636
651
|
if (!isObject(def)) {
|
|
637
|
-
assert(
|
|
638
|
-
assertUsage(false, `${
|
|
652
|
+
assert(metaConfigDefinedAt); // We expect internal effects to return a valid meta value
|
|
653
|
+
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
654
|
}
|
|
640
655
|
// env
|
|
641
656
|
let configEnv;
|
|
642
657
|
{
|
|
643
|
-
assert(
|
|
658
|
+
assert(metaConfigDefinedAt); // We expect internal effects to return a valid meta value
|
|
644
659
|
if (!('env' in def)) {
|
|
645
|
-
assertUsage(false, `${
|
|
660
|
+
assertUsage(false, `${metaConfigDefinedAt} doesn't set ${pc.cyan(`meta.${configName}.env`)} but it's required.`);
|
|
646
661
|
}
|
|
647
|
-
configEnv = getConfigEnvValue(def.env, `${
|
|
662
|
+
configEnv = getConfigEnvValue(def.env, `${metaConfigDefinedAt} sets ${pc.cyan(`meta.${configName}.env`)} to`);
|
|
648
663
|
// Overwrite deprecated value with valid value
|
|
649
664
|
// TODO/v1-release: remove once support for the deprecated values is removed
|
|
650
665
|
if (typeof def.env === 'string')
|
|
@@ -653,12 +668,12 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
|
653
668
|
// effect
|
|
654
669
|
if ('effect' in def) {
|
|
655
670
|
if (!hasProp(def, 'effect', 'function')) {
|
|
656
|
-
assert(
|
|
657
|
-
assertUsage(false, `${
|
|
671
|
+
assert(metaConfigDefinedAt); // We expect internal effects to return a valid meta value
|
|
672
|
+
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
673
|
}
|
|
659
674
|
if (!configEnv.config) {
|
|
660
|
-
assert(
|
|
661
|
-
assertUsage(false, `${
|
|
675
|
+
assert(metaConfigDefinedAt); // We expect internal effects to return a valid meta value
|
|
676
|
+
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
677
|
}
|
|
663
678
|
}
|
|
664
679
|
});
|
|
@@ -680,7 +695,7 @@ function applyEffectsAll(configValueSources, configDefinitions) {
|
|
|
680
695
|
// Call effect
|
|
681
696
|
const configModFromEffect = configDef.effect({
|
|
682
697
|
configValue: source.value,
|
|
683
|
-
configDefinedAt:
|
|
698
|
+
configDefinedAt: getConfigDefinedAt('Config', configName, source.definedAtFilePath)
|
|
684
699
|
});
|
|
685
700
|
if (!configModFromEffect)
|
|
686
701
|
return;
|
|
@@ -692,16 +707,14 @@ function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
|
|
|
692
707
|
const notSupported = `Effects currently only supports modifying the the ${pc.cyan('env')} of a config.`;
|
|
693
708
|
objectEntries(configModFromEffect).forEach(([configName, configValue]) => {
|
|
694
709
|
if (configName === 'meta') {
|
|
695
|
-
let
|
|
696
|
-
if (configDefEffect.
|
|
697
|
-
|
|
698
|
-
definedAt: configDefEffect._userEffectDefinedAt
|
|
699
|
-
});
|
|
710
|
+
let configDefinedAt;
|
|
711
|
+
if (configDefEffect._userEffectDefinedAtFilePath) {
|
|
712
|
+
configDefinedAt = getConfigDefinedAt('Config', configName, configDefEffect._userEffectDefinedAtFilePath);
|
|
700
713
|
}
|
|
701
714
|
else {
|
|
702
|
-
|
|
715
|
+
configDefinedAt = null;
|
|
703
716
|
}
|
|
704
|
-
assertMetaValue(configValue,
|
|
717
|
+
assertMetaValue(configValue, configDefinedAt);
|
|
705
718
|
objectEntries(configValue).forEach(([configTargetName, configTargetDef]) => {
|
|
706
719
|
{
|
|
707
720
|
const keys = Object.keys(configTargetDef);
|
|
@@ -719,7 +732,7 @@ function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
|
|
|
719
732
|
else {
|
|
720
733
|
assertUsage(false, notSupported);
|
|
721
734
|
// If we do end implementing being able to set the value of a config:
|
|
722
|
-
// - For setting
|
|
735
|
+
// - For setting definedAtFile: we could take the definedAtFile of the effect config while appending '(effect)' to definedAtFile.fileExportPathToShowToUser
|
|
723
736
|
}
|
|
724
737
|
});
|
|
725
738
|
}
|
|
@@ -827,11 +840,11 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
827
840
|
if (configFilesystemRoutingRoot) {
|
|
828
841
|
const routingRoot = getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName);
|
|
829
842
|
if (routingRoot) {
|
|
830
|
-
const { filesystemRoutingRootEffect /*,
|
|
843
|
+
const { filesystemRoutingRootEffect /*, filesystemRoutingRootConfigDefinedAt*/ } = routingRoot;
|
|
831
844
|
const debugInfo = { locationId, routeFilesystem: filesystemRouteString, configFilesystemRoutingRoot };
|
|
832
845
|
assert(filesystemRouteString.startsWith(filesystemRoutingRootEffect.before), debugInfo);
|
|
833
846
|
filesystemRouteString = applyFilesystemRoutingRootEffect(filesystemRouteString, filesystemRoutingRootEffect);
|
|
834
|
-
// filesystemRouteDefinedBy = `${filesystemRouteDefinedBy} (with ${
|
|
847
|
+
// filesystemRouteDefinedBy = `${filesystemRouteDefinedBy} (with ${filesystemRoutingRootConfigDefinedAt})`
|
|
835
848
|
}
|
|
836
849
|
}
|
|
837
850
|
assert(filesystemRouteString.startsWith('/'));
|
|
@@ -846,15 +859,15 @@ function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName)
|
|
|
846
859
|
// Eagerly loaded since it's config-only
|
|
847
860
|
assert('value' in configFilesystemRoutingRoot);
|
|
848
861
|
const { value } = configFilesystemRoutingRoot;
|
|
849
|
-
const configDefinedAt =
|
|
862
|
+
const configDefinedAt = getConfigDefinedAt('Config', configName, configFilesystemRoutingRoot.definedAtFilePath);
|
|
850
863
|
assertUsage(typeof value === 'string', `${configDefinedAt} should be a string`);
|
|
851
864
|
assertUsage(value.startsWith('/'), `${configDefinedAt} is ${pc.cyan(value)} but it should start with a leading slash ${pc.cyan('/')}`);
|
|
852
|
-
const { filePathAbsoluteUserRootDir } = configFilesystemRoutingRoot.
|
|
865
|
+
const { filePathAbsoluteUserRootDir } = configFilesystemRoutingRoot.definedAtFilePath;
|
|
853
866
|
assert(filePathAbsoluteUserRootDir);
|
|
854
867
|
const before = getFilesystemRouteString(getLocationId(filePathAbsoluteUserRootDir));
|
|
855
868
|
const after = value;
|
|
856
869
|
const filesystemRoutingRootEffect = { before, after };
|
|
857
|
-
return { filesystemRoutingRootEffect,
|
|
870
|
+
return { filesystemRoutingRootEffect, filesystemRoutingRootConfigDefinedAt: configDefinedAt };
|
|
858
871
|
}
|
|
859
872
|
function determineIsErrorPage(routeFilesystem) {
|
|
860
873
|
assertPosixPath(routeFilesystem);
|
|
@@ -867,8 +880,9 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
867
880
|
const configValues = {};
|
|
868
881
|
Object.entries(configValuesComputed).forEach(([configName, configValueComputed]) => {
|
|
869
882
|
configValues[configName] = {
|
|
883
|
+
type: 'computed',
|
|
870
884
|
value: configValueComputed.value,
|
|
871
|
-
|
|
885
|
+
definedAtData: null
|
|
872
886
|
};
|
|
873
887
|
});
|
|
874
888
|
Object.entries(configValueSources).forEach(([configName, sources]) => {
|
|
@@ -878,18 +892,20 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
878
892
|
const configValueSource = sources[0];
|
|
879
893
|
if ('value' in configValueSource) {
|
|
880
894
|
configValues[configName] = {
|
|
895
|
+
type: 'classic',
|
|
881
896
|
value: configValueSource.value,
|
|
882
|
-
|
|
897
|
+
definedAtData: getDefinedAtFile(configValueSource)
|
|
883
898
|
};
|
|
884
899
|
}
|
|
885
900
|
}
|
|
886
901
|
else {
|
|
887
902
|
const value = mergeCumulative(configName, sources);
|
|
903
|
+
const definedAtData = sources.map((source) => getDefinedAtFile(source));
|
|
904
|
+
assert(value.length === definedAtData.length);
|
|
888
905
|
configValues[configName] = {
|
|
906
|
+
type: 'cumulative',
|
|
889
907
|
value,
|
|
890
|
-
|
|
891
|
-
files: sources.map((source) => getDefinedAtFile(source))
|
|
892
|
-
}
|
|
908
|
+
definedAtData
|
|
893
909
|
};
|
|
894
910
|
}
|
|
895
911
|
});
|
|
@@ -897,62 +913,21 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
897
913
|
}
|
|
898
914
|
function getDefinedAtFile(configValueSource) {
|
|
899
915
|
return {
|
|
900
|
-
filePathToShowToUser: configValueSource.
|
|
901
|
-
fileExportPathToShowToUser: configValueSource.
|
|
916
|
+
filePathToShowToUser: configValueSource.definedAtFilePath.filePathToShowToUser,
|
|
917
|
+
fileExportPathToShowToUser: configValueSource.definedAtFilePath.fileExportPathToShowToUser
|
|
902
918
|
};
|
|
903
919
|
}
|
|
904
|
-
function getDefinedAt(configValueSource) {
|
|
905
|
-
return getDefinedAtFile(configValueSource);
|
|
906
|
-
}
|
|
907
920
|
function mergeCumulative(configName, configValueSources) {
|
|
908
|
-
const
|
|
909
|
-
const valuesSet = [];
|
|
910
|
-
let configValueSourcePrevious = null;
|
|
921
|
+
const configValues = [];
|
|
911
922
|
configValueSources.forEach((configValueSource) => {
|
|
912
|
-
const configDefinedAt = getConfigDefinedAtString('Config', configName, configValueSource);
|
|
913
923
|
// 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
924
|
assert('value' in configValueSource);
|
|
915
925
|
// 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
|
-
};
|
|
926
|
+
assertConfigValueIsSerializable(configValueSource.value, configName, getDefinedAtFile(configValueSource));
|
|
929
927
|
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;
|
|
928
|
+
configValues.push(value);
|
|
942
929
|
});
|
|
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);
|
|
930
|
+
return configValues;
|
|
956
931
|
}
|
|
957
932
|
function getConfigEnvValue(val, errMsgIntro) {
|
|
958
933
|
const errInvalidValue = `${errMsgIntro} an invalid value ${pc.cyan(JSON.stringify(val))}`;
|
|
@@ -1022,10 +997,10 @@ function assertConfigExists(configName, configNamesRelevant, filePathToShowToUse
|
|
|
1022
997
|
function sortConfigValueSources(configValueSources, locationIdPage) {
|
|
1023
998
|
return Object.fromEntries(Object.entries(configValueSources)
|
|
1024
999
|
// Make order deterministic (no other purpose)
|
|
1025
|
-
.sort(([, [source1]], [, [source2]]) => source1.
|
|
1000
|
+
.sort(([, [source1]], [, [source2]]) => source1.definedAtFilePath.filePathAbsoluteVite < source2.definedAtFilePath.filePathAbsoluteVite ? -1 : 1)
|
|
1026
1001
|
// Sort after whether the config value was defined by an npm package
|
|
1027
1002
|
.sort(makeFirst(([, [source]]) => {
|
|
1028
|
-
const { importPathAbsolute } = source.
|
|
1003
|
+
const { importPathAbsolute } = source.definedAtFilePath;
|
|
1029
1004
|
return (!!importPathAbsolute &&
|
|
1030
1005
|
isNpmPackageImport(importPathAbsolute, {
|
|
1031
1006
|
// 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,67 +18,66 @@ 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('../'));
|
|
@@ -102,15 +98,15 @@ function getModuleFilePath(moduleId, config) {
|
|
|
102
98
|
assertPosixPath(moduleId);
|
|
103
99
|
assertPosixPath(userRootDir);
|
|
104
100
|
const filePathAbsoluteFilesystem = cleanModuleId(moduleId);
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
return
|
|
101
|
+
assertPathFilesystemAbsolute(filePathAbsoluteFilesystem);
|
|
102
|
+
const filePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir });
|
|
103
|
+
return filePathAbsoluteUserRootDir || filePathAbsoluteFilesystem;
|
|
108
104
|
}
|
|
109
105
|
function getFilePathToShowToUserFromUnkown(
|
|
110
106
|
// We don't have any guarentee about filePath, e.g. about whether is filePathAbsoluteFilesystem or filePathAbsoluteUserRootDir
|
|
111
107
|
filePathUnkown, userRootDir) {
|
|
112
108
|
assertPosixPath(userRootDir);
|
|
113
|
-
|
|
109
|
+
assertPathFilesystemAbsolute(userRootDir);
|
|
114
110
|
filePathUnkown = cleanFilePathUnkown(filePathUnkown);
|
|
115
111
|
if (!filePathUnkown.startsWith(userRootDir)) {
|
|
116
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';
|