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
|
@@ -14,12 +14,12 @@ const globalContext_js_1 = require("../../../../runtime/globalContext.js");
|
|
|
14
14
|
const loggerNotProd_js_1 = require("../../../shared/loggerNotProd.js");
|
|
15
15
|
const removeSuperfluousViteLog_js_1 = require("../../../shared/loggerVite/removeSuperfluousViteLog.js");
|
|
16
16
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
17
|
-
const
|
|
17
|
+
const getConfigDefinedAt_js_1 = require("../../../../../shared/page-configs/getConfigDefinedAt.js");
|
|
18
18
|
const getConfigValuesSerialized_js_1 = require("./getConfigValuesSerialized.js");
|
|
19
19
|
const crawlPlusFiles_js_1 = require("./getVikeConfig/crawlPlusFiles.js");
|
|
20
20
|
const getConfigFileExport_js_1 = require("./getConfigFileExport.js");
|
|
21
21
|
const loadFileAtConfigTime_js_1 = require("./getVikeConfig/loadFileAtConfigTime.js");
|
|
22
|
-
const
|
|
22
|
+
const resolvePointerImport_js_1 = require("./getVikeConfig/resolvePointerImport.js");
|
|
23
23
|
const getFilePath_js_1 = require("../../../shared/getFilePath.js");
|
|
24
24
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
25
25
|
let devServerIsCorrupt = false;
|
|
@@ -29,7 +29,7 @@ const vikeConfigDependencies = new Set();
|
|
|
29
29
|
exports.vikeConfigDependencies = vikeConfigDependencies;
|
|
30
30
|
function reloadVikeConfig(userRootDir, outDirRoot) {
|
|
31
31
|
vikeConfigDependencies.clear();
|
|
32
|
-
(0,
|
|
32
|
+
(0, resolvePointerImport_js_1.clearFilesEnvMap)();
|
|
33
33
|
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, true, true);
|
|
34
34
|
handleReloadSideEffects();
|
|
35
35
|
}
|
|
@@ -132,6 +132,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev) {
|
|
|
132
132
|
'vike-pinia',
|
|
133
133
|
'vike-solid'
|
|
134
134
|
];
|
|
135
|
+
(0, utils_js_1.assert)(extendsConfig.filePath.importPathAbsolute);
|
|
135
136
|
const extensionName = extendsConfig.filePath.importPathAbsolute.split('/')[0];
|
|
136
137
|
const warnMsg = alreadyMigrated.includes(extensionName)
|
|
137
138
|
? `You're using a deprecated version of the Vike extension ${extensionName}, update ${extensionName} to its latest version.`
|
|
@@ -270,6 +271,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev) {
|
|
|
270
271
|
if (isGlobalConfig(configName))
|
|
271
272
|
return;
|
|
272
273
|
const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
274
|
+
configDef.env = deriveConfigEnvFromFileName(configDef.env, interfaceFile.filePath.fileName);
|
|
273
275
|
if (!isConfigEnv(configDef, configName))
|
|
274
276
|
return;
|
|
275
277
|
const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
|
|
@@ -306,6 +308,22 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev) {
|
|
|
306
308
|
assertPageConfigs(pageConfigs);
|
|
307
309
|
return { pageConfigs, pageConfigGlobal, globalVikeConfig };
|
|
308
310
|
}
|
|
311
|
+
function deriveConfigEnvFromFileName(env, fileName) {
|
|
312
|
+
env = { ...env };
|
|
313
|
+
if (fileName.includes('.server.')) {
|
|
314
|
+
env.server = true;
|
|
315
|
+
env.client = false;
|
|
316
|
+
}
|
|
317
|
+
else if (fileName.includes('.client.')) {
|
|
318
|
+
env.client = true;
|
|
319
|
+
env.server = false;
|
|
320
|
+
}
|
|
321
|
+
else if (fileName.includes('.shared.')) {
|
|
322
|
+
env.server = true;
|
|
323
|
+
env.client = true;
|
|
324
|
+
}
|
|
325
|
+
return env;
|
|
326
|
+
}
|
|
309
327
|
function assertPageConfigs(pageConfigs) {
|
|
310
328
|
pageConfigs.forEach((pageConfig) => {
|
|
311
329
|
assertOnBeforeRenderEnv(pageConfig);
|
|
@@ -392,7 +410,7 @@ async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importe
|
|
|
392
410
|
(0, utils_js_1.assert)('value' in configValueSource);
|
|
393
411
|
if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
|
|
394
412
|
return;
|
|
395
|
-
const { filePathToShowToUser } = configValueSource.
|
|
413
|
+
const { filePathToShowToUser } = configValueSource.definedAtFilePath;
|
|
396
414
|
(0, utils_js_1.assertWarning)(false, `Being able to define config ${picocolors_1.default.cyan(configName)} in ${filePathToShowToUser} is experimental and will likely be removed. Define the config ${picocolors_1.default.cyan(configName)} in Vike's Vite plugin options instead.`, { onlyOnce: true });
|
|
397
415
|
globalVikeConfig[configName] = configValueSource.value;
|
|
398
416
|
}
|
|
@@ -486,26 +504,26 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
486
504
|
(0, utils_js_1.assert)(conf);
|
|
487
505
|
const configEnv = configDef.env;
|
|
488
506
|
const { locationId } = interfaceFile;
|
|
489
|
-
const
|
|
507
|
+
const definedAtFilePath_ = {
|
|
490
508
|
...interfaceFile.filePath,
|
|
491
509
|
fileExportPathToShowToUser: ['default', configName]
|
|
492
510
|
};
|
|
493
511
|
// +client.js
|
|
494
512
|
if (configDef._valueIsFilePath) {
|
|
495
|
-
let
|
|
513
|
+
let definedAtFilePath;
|
|
496
514
|
let valueFilePath;
|
|
497
515
|
if (interfaceFile.isConfigFile) {
|
|
498
516
|
const { configValue } = conf;
|
|
499
|
-
const
|
|
500
|
-
const configDefinedAt = (0,
|
|
501
|
-
(0, utils_js_1.assertUsage)(
|
|
502
|
-
valueFilePath =
|
|
503
|
-
|
|
517
|
+
const pointerImport = (0, resolvePointerImport_js_1.resolvePointerImportOfConfig)(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
518
|
+
const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configName, definedAtFilePath_);
|
|
519
|
+
(0, utils_js_1.assertUsage)(pointerImport, `${configDefinedAt} should be an import`);
|
|
520
|
+
valueFilePath = pointerImport.filePathAbsoluteVite;
|
|
521
|
+
definedAtFilePath = pointerImport;
|
|
504
522
|
}
|
|
505
523
|
else {
|
|
506
524
|
(0, utils_js_1.assert)(interfaceFile.isValueFile);
|
|
507
525
|
valueFilePath = interfaceFile.filePath.filePathAbsoluteVite;
|
|
508
|
-
|
|
526
|
+
definedAtFilePath = {
|
|
509
527
|
...interfaceFile.filePath,
|
|
510
528
|
fileExportPathToShowToUser: []
|
|
511
529
|
};
|
|
@@ -517,7 +535,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
517
535
|
configEnv,
|
|
518
536
|
valueIsImportedAtRuntime: true,
|
|
519
537
|
valueIsDefinedByValueFile: false,
|
|
520
|
-
|
|
538
|
+
definedAtFilePath
|
|
521
539
|
};
|
|
522
540
|
return configValueSource;
|
|
523
541
|
}
|
|
@@ -525,28 +543,26 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
525
543
|
if (interfaceFile.isConfigFile) {
|
|
526
544
|
(0, utils_js_1.assert)('configValue' in conf);
|
|
527
545
|
const { configValue } = conf;
|
|
528
|
-
//
|
|
529
|
-
const
|
|
530
|
-
if (
|
|
546
|
+
// Pointer import
|
|
547
|
+
const pointerImport = (0, resolvePointerImport_js_1.resolvePointerImportOfConfig)(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
548
|
+
if (pointerImport) {
|
|
531
549
|
const configValueSource = {
|
|
532
550
|
locationId,
|
|
533
551
|
configEnv,
|
|
534
552
|
valueIsImportedAtRuntime: true,
|
|
535
553
|
valueIsDefinedByValueFile: false,
|
|
536
|
-
|
|
554
|
+
definedAtFilePath: pointerImport
|
|
537
555
|
};
|
|
538
556
|
// Load fake import
|
|
539
557
|
if (isConfigEnv(configDef, configName) &&
|
|
540
558
|
// The value of `extends` was already loaded and already used: we don't need the value of `extends` anymore
|
|
541
559
|
configName !== 'extends') {
|
|
542
|
-
if (
|
|
543
|
-
|
|
544
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(import_, 'filePathToShowToUserResolved', 'string')); // Help TS
|
|
545
|
-
const fileExport = await (0, loadFileAtConfigTime_js_1.loadImportedFile)(import_, userRootDir, importedFilesLoaded);
|
|
560
|
+
if (pointerImport.filePathAbsoluteFilesystem) {
|
|
561
|
+
const fileExport = await (0, loadFileAtConfigTime_js_1.loadImportedFile)(pointerImport, userRootDir, importedFilesLoaded);
|
|
546
562
|
configValueSource.value = fileExport;
|
|
547
563
|
}
|
|
548
564
|
else {
|
|
549
|
-
const configDefinedAt = (0,
|
|
565
|
+
const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configName, configValueSource.definedAtFilePath);
|
|
550
566
|
(0, utils_js_1.assertUsage)(!configDef.cumulative, `${configDefinedAt} cannot be defined over an aliased import`);
|
|
551
567
|
}
|
|
552
568
|
}
|
|
@@ -559,7 +575,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
559
575
|
configEnv,
|
|
560
576
|
valueIsImportedAtRuntime: false,
|
|
561
577
|
valueIsDefinedByValueFile: false,
|
|
562
|
-
|
|
578
|
+
definedAtFilePath: definedAtFilePath_
|
|
563
579
|
};
|
|
564
580
|
return configValueSource;
|
|
565
581
|
}
|
|
@@ -572,7 +588,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
572
588
|
configEnv,
|
|
573
589
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
574
590
|
valueIsDefinedByValueFile: true,
|
|
575
|
-
|
|
591
|
+
definedAtFilePath: {
|
|
576
592
|
...interfaceFile.filePath,
|
|
577
593
|
fileExportPathToShowToUser: configName === interfaceFile.configName
|
|
578
594
|
? []
|
|
@@ -610,12 +626,12 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
610
626
|
return;
|
|
611
627
|
const meta = configMeta.configValue;
|
|
612
628
|
assertMetaValue(meta, `Config ${picocolors_1.default.cyan('meta')} defined at ${interfaceFile.filePath.filePathToShowToUser}`);
|
|
613
|
-
// Set configDef.
|
|
629
|
+
// Set configDef._userEffectDefinedAtFilePath
|
|
614
630
|
Object.entries(meta).forEach(([configName, configDef]) => {
|
|
615
631
|
if (!configDef.effect)
|
|
616
632
|
return;
|
|
617
633
|
(0, utils_js_1.assert)(interfaceFile.isConfigFile);
|
|
618
|
-
configDef.
|
|
634
|
+
configDef._userEffectDefinedAtFilePath = {
|
|
619
635
|
...interfaceFile.filePath,
|
|
620
636
|
fileExportPathToShowToUser: ['default', 'meta', configName, 'effect']
|
|
621
637
|
};
|
|
@@ -632,24 +648,24 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
632
648
|
const configDefinitions = configDefinitionsMerged;
|
|
633
649
|
return configDefinitions;
|
|
634
650
|
}
|
|
635
|
-
function assertMetaValue(metaVal,
|
|
651
|
+
function assertMetaValue(metaVal, metaConfigDefinedAt) {
|
|
636
652
|
if (!(0, utils_js_1.isObject)(metaVal)) {
|
|
637
|
-
(0, utils_js_1.assert)(
|
|
638
|
-
(0, utils_js_1.assertUsage)(false, `${
|
|
653
|
+
(0, utils_js_1.assert)(metaConfigDefinedAt); // We expect internal effects to return a valid meta value
|
|
654
|
+
(0, utils_js_1.assertUsage)(false, `${metaConfigDefinedAt} has an invalid type ${picocolors_1.default.cyan(typeof metaVal)}: it should be an object instead.`);
|
|
639
655
|
}
|
|
640
656
|
(0, utils_js_1.objectEntries)(metaVal).forEach(([configName, def]) => {
|
|
641
657
|
if (!(0, utils_js_1.isObject)(def)) {
|
|
642
|
-
(0, utils_js_1.assert)(
|
|
643
|
-
(0, utils_js_1.assertUsage)(false, `${
|
|
658
|
+
(0, utils_js_1.assert)(metaConfigDefinedAt); // We expect internal effects to return a valid meta value
|
|
659
|
+
(0, utils_js_1.assertUsage)(false, `${metaConfigDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}`)} to a value with an invalid type ${picocolors_1.default.cyan(typeof def)}: it should be an object instead.`);
|
|
644
660
|
}
|
|
645
661
|
// env
|
|
646
662
|
let configEnv;
|
|
647
663
|
{
|
|
648
|
-
(0, utils_js_1.assert)(
|
|
664
|
+
(0, utils_js_1.assert)(metaConfigDefinedAt); // We expect internal effects to return a valid meta value
|
|
649
665
|
if (!('env' in def)) {
|
|
650
|
-
(0, utils_js_1.assertUsage)(false, `${
|
|
666
|
+
(0, utils_js_1.assertUsage)(false, `${metaConfigDefinedAt} doesn't set ${picocolors_1.default.cyan(`meta.${configName}.env`)} but it's required.`);
|
|
651
667
|
}
|
|
652
|
-
configEnv = getConfigEnvValue(def.env, `${
|
|
668
|
+
configEnv = getConfigEnvValue(def.env, `${metaConfigDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.env`)} to`);
|
|
653
669
|
// Overwrite deprecated value with valid value
|
|
654
670
|
// TODO/v1-release: remove once support for the deprecated values is removed
|
|
655
671
|
if (typeof def.env === 'string')
|
|
@@ -658,12 +674,12 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
|
658
674
|
// effect
|
|
659
675
|
if ('effect' in def) {
|
|
660
676
|
if (!(0, utils_js_1.hasProp)(def, 'effect', 'function')) {
|
|
661
|
-
(0, utils_js_1.assert)(
|
|
662
|
-
(0, utils_js_1.assertUsage)(false, `${
|
|
677
|
+
(0, utils_js_1.assert)(metaConfigDefinedAt); // We expect internal effects to return a valid meta value
|
|
678
|
+
(0, utils_js_1.assertUsage)(false, `${metaConfigDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.effect`)} to an invalid type ${picocolors_1.default.cyan(typeof def.effect)}: it should be a function instead`);
|
|
663
679
|
}
|
|
664
680
|
if (!configEnv.config) {
|
|
665
|
-
(0, utils_js_1.assert)(
|
|
666
|
-
(0, utils_js_1.assertUsage)(false, `${
|
|
681
|
+
(0, utils_js_1.assert)(metaConfigDefinedAt); // We expect internal effects to return a valid meta value
|
|
682
|
+
(0, utils_js_1.assertUsage)(false, `${metaConfigDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.effect`)} but it's only supported if meta.${configName}.env has ${picocolors_1.default.cyan('{ config: true }')} (but it's ${picocolors_1.default.cyan(JSON.stringify(configEnv))} instead)`);
|
|
667
683
|
}
|
|
668
684
|
}
|
|
669
685
|
});
|
|
@@ -685,7 +701,7 @@ function applyEffectsAll(configValueSources, configDefinitions) {
|
|
|
685
701
|
// Call effect
|
|
686
702
|
const configModFromEffect = configDef.effect({
|
|
687
703
|
configValue: source.value,
|
|
688
|
-
configDefinedAt: (0,
|
|
704
|
+
configDefinedAt: (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configName, source.definedAtFilePath)
|
|
689
705
|
});
|
|
690
706
|
if (!configModFromEffect)
|
|
691
707
|
return;
|
|
@@ -697,16 +713,14 @@ function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
|
|
|
697
713
|
const notSupported = `Effects currently only supports modifying the the ${picocolors_1.default.cyan('env')} of a config.`;
|
|
698
714
|
(0, utils_js_1.objectEntries)(configModFromEffect).forEach(([configName, configValue]) => {
|
|
699
715
|
if (configName === 'meta') {
|
|
700
|
-
let
|
|
701
|
-
if (configDefEffect.
|
|
702
|
-
|
|
703
|
-
definedAt: configDefEffect._userEffectDefinedAt
|
|
704
|
-
});
|
|
716
|
+
let configDefinedAt;
|
|
717
|
+
if (configDefEffect._userEffectDefinedAtFilePath) {
|
|
718
|
+
configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configName, configDefEffect._userEffectDefinedAtFilePath);
|
|
705
719
|
}
|
|
706
720
|
else {
|
|
707
|
-
|
|
721
|
+
configDefinedAt = null;
|
|
708
722
|
}
|
|
709
|
-
assertMetaValue(configValue,
|
|
723
|
+
assertMetaValue(configValue, configDefinedAt);
|
|
710
724
|
(0, utils_js_1.objectEntries)(configValue).forEach(([configTargetName, configTargetDef]) => {
|
|
711
725
|
{
|
|
712
726
|
const keys = Object.keys(configTargetDef);
|
|
@@ -724,7 +738,7 @@ function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
|
|
|
724
738
|
else {
|
|
725
739
|
(0, utils_js_1.assertUsage)(false, notSupported);
|
|
726
740
|
// If we do end implementing being able to set the value of a config:
|
|
727
|
-
// - For setting
|
|
741
|
+
// - For setting definedAtFile: we could take the definedAtFile of the effect config while appending '(effect)' to definedAtFile.fileExportPathToShowToUser
|
|
728
742
|
}
|
|
729
743
|
});
|
|
730
744
|
}
|
|
@@ -832,11 +846,11 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
832
846
|
if (configFilesystemRoutingRoot) {
|
|
833
847
|
const routingRoot = getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName);
|
|
834
848
|
if (routingRoot) {
|
|
835
|
-
const { filesystemRoutingRootEffect /*,
|
|
849
|
+
const { filesystemRoutingRootEffect /*, filesystemRoutingRootConfigDefinedAt*/ } = routingRoot;
|
|
836
850
|
const debugInfo = { locationId, routeFilesystem: filesystemRouteString, configFilesystemRoutingRoot };
|
|
837
851
|
(0, utils_js_1.assert)(filesystemRouteString.startsWith(filesystemRoutingRootEffect.before), debugInfo);
|
|
838
852
|
filesystemRouteString = (0, filesystemRouting_js_1.applyFilesystemRoutingRootEffect)(filesystemRouteString, filesystemRoutingRootEffect);
|
|
839
|
-
// filesystemRouteDefinedBy = `${filesystemRouteDefinedBy} (with ${
|
|
853
|
+
// filesystemRouteDefinedBy = `${filesystemRouteDefinedBy} (with ${filesystemRoutingRootConfigDefinedAt})`
|
|
840
854
|
}
|
|
841
855
|
}
|
|
842
856
|
(0, utils_js_1.assert)(filesystemRouteString.startsWith('/'));
|
|
@@ -851,15 +865,15 @@ function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName)
|
|
|
851
865
|
// Eagerly loaded since it's config-only
|
|
852
866
|
(0, utils_js_1.assert)('value' in configFilesystemRoutingRoot);
|
|
853
867
|
const { value } = configFilesystemRoutingRoot;
|
|
854
|
-
const configDefinedAt = (0,
|
|
868
|
+
const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configName, configFilesystemRoutingRoot.definedAtFilePath);
|
|
855
869
|
(0, utils_js_1.assertUsage)(typeof value === 'string', `${configDefinedAt} should be a string`);
|
|
856
870
|
(0, utils_js_1.assertUsage)(value.startsWith('/'), `${configDefinedAt} is ${picocolors_1.default.cyan(value)} but it should start with a leading slash ${picocolors_1.default.cyan('/')}`);
|
|
857
|
-
const { filePathAbsoluteUserRootDir } = configFilesystemRoutingRoot.
|
|
871
|
+
const { filePathAbsoluteUserRootDir } = configFilesystemRoutingRoot.definedAtFilePath;
|
|
858
872
|
(0, utils_js_1.assert)(filePathAbsoluteUserRootDir);
|
|
859
873
|
const before = (0, filesystemRouting_js_1.getFilesystemRouteString)((0, filesystemRouting_js_1.getLocationId)(filePathAbsoluteUserRootDir));
|
|
860
874
|
const after = value;
|
|
861
875
|
const filesystemRoutingRootEffect = { before, after };
|
|
862
|
-
return { filesystemRoutingRootEffect,
|
|
876
|
+
return { filesystemRoutingRootEffect, filesystemRoutingRootConfigDefinedAt: configDefinedAt };
|
|
863
877
|
}
|
|
864
878
|
function determineIsErrorPage(routeFilesystem) {
|
|
865
879
|
(0, utils_js_1.assertPosixPath)(routeFilesystem);
|
|
@@ -873,8 +887,9 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
873
887
|
const configValues = {};
|
|
874
888
|
Object.entries(configValuesComputed).forEach(([configName, configValueComputed]) => {
|
|
875
889
|
configValues[configName] = {
|
|
890
|
+
type: 'computed',
|
|
876
891
|
value: configValueComputed.value,
|
|
877
|
-
|
|
892
|
+
definedAtData: null
|
|
878
893
|
};
|
|
879
894
|
});
|
|
880
895
|
Object.entries(configValueSources).forEach(([configName, sources]) => {
|
|
@@ -884,18 +899,20 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
884
899
|
const configValueSource = sources[0];
|
|
885
900
|
if ('value' in configValueSource) {
|
|
886
901
|
configValues[configName] = {
|
|
902
|
+
type: 'classic',
|
|
887
903
|
value: configValueSource.value,
|
|
888
|
-
|
|
904
|
+
definedAtData: getDefinedAtFile(configValueSource)
|
|
889
905
|
};
|
|
890
906
|
}
|
|
891
907
|
}
|
|
892
908
|
else {
|
|
893
909
|
const value = mergeCumulative(configName, sources);
|
|
910
|
+
const definedAtData = sources.map((source) => getDefinedAtFile(source));
|
|
911
|
+
(0, utils_js_1.assert)(value.length === definedAtData.length);
|
|
894
912
|
configValues[configName] = {
|
|
913
|
+
type: 'cumulative',
|
|
895
914
|
value,
|
|
896
|
-
|
|
897
|
-
files: sources.map((source) => getDefinedAtFile(source))
|
|
898
|
-
}
|
|
915
|
+
definedAtData
|
|
899
916
|
};
|
|
900
917
|
}
|
|
901
918
|
});
|
|
@@ -903,62 +920,21 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
903
920
|
}
|
|
904
921
|
function getDefinedAtFile(configValueSource) {
|
|
905
922
|
return {
|
|
906
|
-
filePathToShowToUser: configValueSource.
|
|
907
|
-
fileExportPathToShowToUser: configValueSource.
|
|
923
|
+
filePathToShowToUser: configValueSource.definedAtFilePath.filePathToShowToUser,
|
|
924
|
+
fileExportPathToShowToUser: configValueSource.definedAtFilePath.fileExportPathToShowToUser
|
|
908
925
|
};
|
|
909
926
|
}
|
|
910
|
-
function getDefinedAt(configValueSource) {
|
|
911
|
-
return getDefinedAtFile(configValueSource);
|
|
912
|
-
}
|
|
913
927
|
function mergeCumulative(configName, configValueSources) {
|
|
914
|
-
const
|
|
915
|
-
const valuesSet = [];
|
|
916
|
-
let configValueSourcePrevious = null;
|
|
928
|
+
const configValues = [];
|
|
917
929
|
configValueSources.forEach((configValueSource) => {
|
|
918
|
-
const configDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configValueSource);
|
|
919
930
|
// We could, in principle, also support cumulative for values that aren't loaded at config-time but it isn't completely trivial to implement.
|
|
920
931
|
(0, utils_js_1.assert)('value' in configValueSource);
|
|
921
932
|
// Make sure configValueSource.value is serializable
|
|
922
|
-
(0, getConfigValuesSerialized_js_1.assertConfigValueIsSerializable)(configValueSource.value, configName,
|
|
923
|
-
const assertNoMixing = (isSet) => {
|
|
924
|
-
const vals1 = isSet ? valuesSet : valuesArr;
|
|
925
|
-
const t1 = isSet ? 'a Set' : 'an array';
|
|
926
|
-
const vals2 = !isSet ? valuesSet : valuesArr;
|
|
927
|
-
const t2 = !isSet ? 'a Set' : 'an array';
|
|
928
|
-
(0, utils_js_1.assert)(vals1.length > 0);
|
|
929
|
-
if (vals2.length === 0)
|
|
930
|
-
return;
|
|
931
|
-
(0, utils_js_1.assert)(configValueSourcePrevious);
|
|
932
|
-
const configPreviousDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configValueSourcePrevious);
|
|
933
|
-
(0, utils_js_1.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).`);
|
|
934
|
-
};
|
|
933
|
+
(0, getConfigValuesSerialized_js_1.assertConfigValueIsSerializable)(configValueSource.value, configName, getDefinedAtFile(configValueSource));
|
|
935
934
|
const { value } = configValueSource;
|
|
936
|
-
|
|
937
|
-
valuesArr.push(value);
|
|
938
|
-
assertNoMixing(false);
|
|
939
|
-
}
|
|
940
|
-
else if (value instanceof Set) {
|
|
941
|
-
valuesSet.push(value);
|
|
942
|
-
assertNoMixing(true);
|
|
943
|
-
}
|
|
944
|
-
else {
|
|
945
|
-
(0, utils_js_1.assertUsage)(false, `${configDefinedAt} must be an array or a Set`);
|
|
946
|
-
}
|
|
947
|
-
configValueSourcePrevious = configValueSource;
|
|
935
|
+
configValues.push(value);
|
|
948
936
|
});
|
|
949
|
-
|
|
950
|
-
(0, utils_js_1.assert)(valuesSet.length === 0);
|
|
951
|
-
const result = (0, utils_js_1.mergeCumulativeValues)(valuesArr);
|
|
952
|
-
(0, utils_js_1.assert)(result !== null);
|
|
953
|
-
return result;
|
|
954
|
-
}
|
|
955
|
-
if (valuesSet.length > 0) {
|
|
956
|
-
(0, utils_js_1.assert)(valuesArr.length === 0);
|
|
957
|
-
const result = (0, utils_js_1.mergeCumulativeValues)(valuesSet);
|
|
958
|
-
(0, utils_js_1.assert)(result !== null);
|
|
959
|
-
return result;
|
|
960
|
-
}
|
|
961
|
-
(0, utils_js_1.assert)(false);
|
|
937
|
+
return configValues;
|
|
962
938
|
}
|
|
963
939
|
function getConfigEnvValue(val, errMsgIntro) {
|
|
964
940
|
const errInvalidValue = `${errMsgIntro} an invalid value ${picocolors_1.default.cyan(JSON.stringify(val))}`;
|
|
@@ -1028,10 +1004,10 @@ function assertConfigExists(configName, configNamesRelevant, filePathToShowToUse
|
|
|
1028
1004
|
function sortConfigValueSources(configValueSources, locationIdPage) {
|
|
1029
1005
|
return Object.fromEntries(Object.entries(configValueSources)
|
|
1030
1006
|
// Make order deterministic (no other purpose)
|
|
1031
|
-
.sort(([, [source1]], [, [source2]]) => source1.
|
|
1007
|
+
.sort(([, [source1]], [, [source2]]) => source1.definedAtFilePath.filePathAbsoluteVite < source2.definedAtFilePath.filePathAbsoluteVite ? -1 : 1)
|
|
1032
1008
|
// Sort after whether the config value was defined by an npm package
|
|
1033
1009
|
.sort((0, utils_js_1.makeFirst)(([, [source]]) => {
|
|
1034
|
-
const { importPathAbsolute } = source.
|
|
1010
|
+
const { importPathAbsolute } = source.definedAtFilePath;
|
|
1035
1011
|
return (!!importPathAbsolute &&
|
|
1036
1012
|
(0, utils_js_1.isNpmPackageImport)(importPathAbsolute, {
|
|
1037
1013
|
// 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/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -6,7 +6,7 @@ const virtualFilePageConfigValuesAll_js_1 = require("../../../../shared/virtual-
|
|
|
6
6
|
const getVikeConfig_js_1 = require("./getVikeConfig.js");
|
|
7
7
|
const extractAssetsQuery_js_1 = require("../../../../shared/extractAssetsQuery.js");
|
|
8
8
|
const debug_js_1 = require("./debug.js");
|
|
9
|
-
const
|
|
9
|
+
const getConfigValue_js_1 = require("../../../../../shared/page-configs/getConfigValue.js");
|
|
10
10
|
const getConfigValueSourcesNotOverriden_js_1 = require("../../../shared/getConfigValueSourcesNotOverriden.js");
|
|
11
11
|
const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
12
12
|
const serializeConfigValue_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValue.js");
|
|
@@ -35,7 +35,7 @@ exports.getVirtualFilePageConfigValuesAll = getVirtualFilePageConfigValuesAll;
|
|
|
35
35
|
function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAssetsImportedByServer, isDev) {
|
|
36
36
|
const lines = [];
|
|
37
37
|
const importStatements = [];
|
|
38
|
-
const isClientRouting = (0,
|
|
38
|
+
const isClientRouting = (0, getConfigValue_js_1.getConfigValue)(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
|
|
39
39
|
lines.push('export const configValuesImported = [');
|
|
40
40
|
lines.push(getConfigValuesImported(pageConfig, isForClientSide, isClientRouting, importStatements));
|
|
41
41
|
lines.push('];');
|
|
@@ -3,16 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.cleanFilePathUnkown = exports.getFilePathToShowToUserFromUnkown = exports.getModuleFilePath = exports.getFilePathUnresolved = exports.getFilePathResolved = void 0;
|
|
6
|
+
exports.getFilePathAbsoluteUserRootDir = exports.cleanFilePathUnkown = exports.getFilePathToShowToUserFromUnkown = exports.getModuleFilePath = exports.getFilePathUnresolved = exports.getFilePathResolved = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const utils_js_1 = require("../utils.js");
|
|
9
|
-
function getFilePathUnresolved({ importPathAbsolute }) {
|
|
10
|
-
return getFilePath({ importPathAbsolute, filePathAbsoluteUserRootDir: null });
|
|
11
|
-
}
|
|
12
|
-
exports.getFilePathUnresolved = getFilePathUnresolved;
|
|
13
9
|
function getFilePathResolved(args) {
|
|
14
10
|
const { userRootDir } = args;
|
|
15
|
-
const importPathAbsolute = args.importPathAbsolute ?? null;
|
|
16
11
|
let filePathAbsoluteFilesystem;
|
|
17
12
|
let filePathAbsoluteUserRootDir;
|
|
18
13
|
if ('filePathAbsoluteFilesystem' in args) {
|
|
@@ -23,93 +18,99 @@ function getFilePathResolved(args) {
|
|
|
23
18
|
filePathAbsoluteUserRootDir = args.filePathAbsoluteUserRootDir;
|
|
24
19
|
filePathAbsoluteFilesystem = getFilePathAbsoluteUserFilesystem({ filePathAbsoluteUserRootDir, userRootDir });
|
|
25
20
|
}
|
|
26
|
-
let filePath;
|
|
27
|
-
const common = {
|
|
28
|
-
filePathAbsoluteUserRootDir,
|
|
29
|
-
importPathAbsolute,
|
|
30
|
-
userRootDir
|
|
31
|
-
};
|
|
32
|
-
if (importPathAbsolute) {
|
|
33
|
-
filePath = getFilePath({
|
|
34
|
-
...common,
|
|
35
|
-
importPathAbsolute
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
(0, utils_js_1.assert)(filePathAbsoluteUserRootDir);
|
|
40
|
-
filePath = getFilePath({
|
|
41
|
-
...common,
|
|
42
|
-
filePathAbsoluteUserRootDir
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
21
|
(0, utils_js_1.assert)(filePathAbsoluteFilesystem);
|
|
46
|
-
(0, utils_js_1.
|
|
22
|
+
(0, utils_js_1.assertPathFilesystemAbsolute)(filePathAbsoluteFilesystem);
|
|
47
23
|
const filePathToShowToUserResolved = filePathAbsoluteUserRootDir || filePathAbsoluteFilesystem;
|
|
48
24
|
(0, utils_js_1.assert)(filePathToShowToUserResolved);
|
|
25
|
+
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
26
|
+
const fileName = path_1.default.posix.basename(filePathAbsoluteFilesystem);
|
|
49
27
|
const filePathResolved = {
|
|
50
|
-
...
|
|
28
|
+
...getComputedProps(args),
|
|
51
29
|
filePathAbsoluteFilesystem,
|
|
52
|
-
filePathToShowToUserResolved
|
|
30
|
+
filePathToShowToUserResolved,
|
|
31
|
+
fileName
|
|
53
32
|
};
|
|
54
33
|
return filePathResolved;
|
|
55
34
|
}
|
|
56
35
|
exports.getFilePathResolved = getFilePathResolved;
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
36
|
+
function getComputedProps(args) {
|
|
37
|
+
if ('filePathAbsoluteUserRootDir' in args) {
|
|
38
|
+
const importPathAbsolute = args.importPathAbsolute ?? null;
|
|
39
|
+
const { filePathAbsoluteUserRootDir } = args;
|
|
40
|
+
if (importPathAbsolute)
|
|
41
|
+
(0, utils_js_1.assertIsNpmPackageImport)(importPathAbsolute);
|
|
42
|
+
return {
|
|
43
|
+
importPathAbsolute,
|
|
44
|
+
filePathAbsoluteUserRootDir,
|
|
45
|
+
filePathAbsoluteVite: filePathAbsoluteUserRootDir,
|
|
46
|
+
filePathToShowToUser: filePathAbsoluteUserRootDir
|
|
47
|
+
};
|
|
61
48
|
}
|
|
62
49
|
else {
|
|
63
|
-
|
|
64
|
-
filePathAbsoluteVite = args.importPathAbsolute;
|
|
50
|
+
return getComputedPropsImportPathAbsolute(args);
|
|
65
51
|
}
|
|
66
|
-
|
|
67
|
-
|
|
52
|
+
}
|
|
53
|
+
function getComputedPropsImportPathAbsolute(args) {
|
|
54
|
+
const { importPathAbsolute } = args;
|
|
55
|
+
(0, utils_js_1.assertIsNpmPackageImport)(importPathAbsolute);
|
|
68
56
|
return {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
filePathAbsoluteVite,
|
|
72
|
-
filePathToShowToUser
|
|
57
|
+
filePathAbsoluteUserRootDir: null,
|
|
58
|
+
importPathAbsolute,
|
|
59
|
+
filePathAbsoluteVite: importPathAbsolute,
|
|
60
|
+
filePathToShowToUser: importPathAbsolute
|
|
73
61
|
};
|
|
74
62
|
}
|
|
63
|
+
function getFilePathUnresolved(args) {
|
|
64
|
+
return {
|
|
65
|
+
...getComputedPropsImportPathAbsolute(args),
|
|
66
|
+
filePathAbsoluteFilesystem: null
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
exports.getFilePathUnresolved = getFilePathUnresolved;
|
|
75
70
|
function getFilePathAbsoluteUserFilesystem({ filePathAbsoluteUserRootDir, userRootDir }) {
|
|
76
71
|
(0, utils_js_1.assertPosixPath)(filePathAbsoluteUserRootDir);
|
|
77
72
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
78
|
-
(0, utils_js_1.
|
|
73
|
+
(0, utils_js_1.assertPathFilesystemAbsolute)(userRootDir);
|
|
79
74
|
const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, filePathAbsoluteUserRootDir);
|
|
80
|
-
(0, utils_js_1.
|
|
75
|
+
(0, utils_js_1.assertPathFilesystemAbsolute)(userRootDir);
|
|
81
76
|
return filePathAbsoluteFilesystem;
|
|
82
77
|
}
|
|
83
78
|
function getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir }) {
|
|
84
79
|
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
85
80
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
86
|
-
(0, utils_js_1.
|
|
87
|
-
(0, utils_js_1.
|
|
81
|
+
(0, utils_js_1.assertPathFilesystemAbsolute)(filePathAbsoluteFilesystem);
|
|
82
|
+
(0, utils_js_1.assertPathFilesystemAbsolute)(userRootDir);
|
|
88
83
|
const filePathRelative = path_1.default.posix.relative(userRootDir, filePathAbsoluteFilesystem);
|
|
89
84
|
if (!filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
90
85
|
(0, utils_js_1.assert)(filePathRelative.startsWith('../'));
|
|
91
86
|
return null;
|
|
92
87
|
}
|
|
93
|
-
(0, utils_js_1.assert)(!filePathRelative.startsWith('
|
|
88
|
+
(0, utils_js_1.assert)(!filePathRelative.startsWith('/') &&
|
|
89
|
+
/* Not true if filePathRelative starts with a hidden directory (i.e. a directory with a name that starts with `.`)
|
|
90
|
+
!filePathRelative.startsWith('.') &&
|
|
91
|
+
*/
|
|
92
|
+
!filePathRelative.startsWith('./') &&
|
|
93
|
+
!filePathRelative.startsWith('../'));
|
|
94
94
|
const filePathAbsoluteUserRootDir = `/${filePathRelative}`;
|
|
95
95
|
(0, utils_js_1.assert)(filePathAbsoluteUserRootDir === getFilePathAbsoluteUserRootDir2(filePathAbsoluteFilesystem, userRootDir));
|
|
96
96
|
return filePathAbsoluteUserRootDir;
|
|
97
97
|
}
|
|
98
|
+
exports.getFilePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir;
|
|
98
99
|
function getModuleFilePath(moduleId, config) {
|
|
99
100
|
const userRootDir = config.root;
|
|
100
101
|
(0, utils_js_1.assertPosixPath)(moduleId);
|
|
101
102
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
102
103
|
const filePathAbsoluteFilesystem = cleanModuleId(moduleId);
|
|
103
|
-
(0, utils_js_1.
|
|
104
|
-
const
|
|
105
|
-
return
|
|
104
|
+
(0, utils_js_1.assertPathFilesystemAbsolute)(filePathAbsoluteFilesystem);
|
|
105
|
+
const filePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir });
|
|
106
|
+
return filePathAbsoluteUserRootDir || filePathAbsoluteFilesystem;
|
|
106
107
|
}
|
|
107
108
|
exports.getModuleFilePath = getModuleFilePath;
|
|
108
109
|
function getFilePathToShowToUserFromUnkown(
|
|
109
110
|
// We don't have any guarentee about filePath, e.g. about whether is filePathAbsoluteFilesystem or filePathAbsoluteUserRootDir
|
|
110
111
|
filePathUnkown, userRootDir) {
|
|
111
112
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
112
|
-
(0, utils_js_1.
|
|
113
|
+
(0, utils_js_1.assertPathFilesystemAbsolute)(userRootDir);
|
|
113
114
|
filePathUnkown = cleanFilePathUnkown(filePathUnkown);
|
|
114
115
|
if (!filePathUnkown.startsWith(userRootDir)) {
|
|
115
116
|
return filePathUnkown;
|
|
@@ -34,11 +34,11 @@ __exportStar(require("../../utils/trimWithAnsi.js"), exports);
|
|
|
34
34
|
__exportStar(require("../../utils/removeEmptyLines.js"), exports);
|
|
35
35
|
__exportStar(require("../../utils/findFile.js"), exports);
|
|
36
36
|
__exportStar(require("../../utils/getPropAccessNotation.js"), exports);
|
|
37
|
-
__exportStar(require("../../utils/mergeCumulativeValues.js"), exports);
|
|
38
37
|
__exportStar(require("../../utils/deepEqual.js"), exports);
|
|
39
38
|
__exportStar(require("../../utils/assertKeys.js"), exports);
|
|
40
39
|
__exportStar(require("../../utils/injectRollupInputs.js"), exports);
|
|
41
40
|
__exportStar(require("../../utils/humanizeTime.js"), exports);
|
|
42
41
|
__exportStar(require("../../utils/pLimit.js"), exports);
|
|
43
42
|
__exportStar(require("../../utils/assertVersion.js"), exports);
|
|
44
|
-
__exportStar(require("../../utils/
|
|
43
|
+
__exportStar(require("../../utils/assertPathFilesystemAbsolute.js"), exports);
|
|
44
|
+
__exportStar(require("../../utils/isArray.js"), exports);
|